/[gxemul]/trunk/src/cpus/cpu_alpha.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/src/cpus/cpu_alpha.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 18 by dpavlin, Mon Oct 8 16:19:11 2007 UTC revision 24 by dpavlin, Mon Oct 8 16:19:56 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   *  Copyright (C) 2005  Anders Gavare.  All rights reserved.   *  Copyright (C) 2005-2006  Anders Gavare.  All rights reserved.
3   *   *
4   *  Redistribution and use in source and binary forms, with or without   *  Redistribution and use in source and binary forms, with or without
5   *  modification, are permitted provided that the following conditions are met:   *  modification, are permitted provided that the following conditions are met:
# Line 25  Line 25 
25   *  SUCH DAMAGE.   *  SUCH DAMAGE.
26   *   *
27   *   *
28   *  $Id: cpu_alpha.c,v 1.2 2005/10/22 17:24:20 debug Exp $   *  $Id: cpu_alpha.c,v 1.16 2006/06/16 18:31:25 debug Exp $
29   *   *
30   *  Alpha CPU emulation.   *  Alpha CPU emulation.
31   *   *
# Line 64  static char *alpha_regname[N_ALPHA_REGS] Line 64  static char *alpha_regname[N_ALPHA_REGS]
64  int alpha_cpu_new(struct cpu *cpu, struct memory *mem,  int alpha_cpu_new(struct cpu *cpu, struct memory *mem,
65          struct machine *machine, int cpu_id, char *cpu_type_name)          struct machine *machine, int cpu_id, char *cpu_type_name)
66  {  {
67          int i;          int i = 0;
68            struct alpha_cpu_type_def cpu_type_defs[] = ALPHA_CPU_TYPE_DEFS;
69    
70          if (strcasecmp(cpu_type_name, "Alpha") != 0)          /*  Scan the cpu_type_defs list for this cpu type:  */
71            while (cpu_type_defs[i].name != NULL) {
72                    if (strcasecmp(cpu_type_defs[i].name, cpu_type_name) == 0) {
73                            break;
74                    }
75                    i++;
76            }
77            if (cpu_type_defs[i].name == NULL)
78                  return 0;                  return 0;
79    
80          cpu->memory_rw = alpha_memory_rw;          cpu->memory_rw = alpha_memory_rw;
81            cpu->translate_address = alpha_translate_address;
82          cpu->update_translation_table = alpha_update_translation_table;          cpu->update_translation_table = alpha_update_translation_table;
83          cpu->invalidate_translation_caches =          cpu->invalidate_translation_caches =
84              alpha_invalidate_translation_caches;              alpha_invalidate_translation_caches;
# Line 81  int alpha_cpu_new(struct cpu *cpu, struc Line 90  int alpha_cpu_new(struct cpu *cpu, struc
90                  debug("%s", cpu->name);                  debug("%s", cpu->name);
91          }          }
92    
         /*  Create the default virtual->physical->host translation:  */  
         cpu->cd.alpha.vph_default_page = malloc(sizeof(struct alpha_vph_page));  
         if (cpu->cd.alpha.vph_default_page == NULL) {  
                 fprintf(stderr, "out of memory in alpha_cpu_new()\n");  
                 exit(1);  
         }  
         memset(cpu->cd.alpha.vph_default_page, 0,  
             sizeof(struct alpha_vph_page));  
         for (i=0; i<ALPHA_LEVEL0; i++)  
                 cpu->cd.alpha.vph_table0[i] = cpu->cd.alpha.vph_table0_kernel[i]  
                     = cpu->cd.alpha.vph_default_page;  
   
93          cpu->cd.alpha.r[ALPHA_SP] = 0xfffffc000000ff00ULL;          cpu->cd.alpha.r[ALPHA_SP] = 0xfffffc000000ff00ULL;
94    
95            alpha_init_64bit_dummy_tables(cpu);
96    
97          return 1;          return 1;
98  }  }
99    
# Line 116  void alpha_cpu_dumpinfo(struct cpu *cpu) Line 115  void alpha_cpu_dumpinfo(struct cpu *cpu)
115   */   */
116  void alpha_cpu_list_available_types(void)  void alpha_cpu_list_available_types(void)
117  {  {
118          /*  TODO  */          int i, j;
119            struct alpha_cpu_type_def tdefs[] = ALPHA_CPU_TYPE_DEFS;
120    
121          debug("Alpha\n");          i = 0;
122            while (tdefs[i].name != NULL) {
123                    debug("%s", tdefs[i].name);
124                    for (j=16 - strlen(tdefs[i].name); j>0; j--)
125                            debug(" ");
126                    i++;
127                    if ((i % 4) == 0 || tdefs[i].name == NULL)
128                            debug("\n");
129            }
130  }  }
131    
132    
# Line 172  void alpha_cpu_register_dump(struct cpu Line 180  void alpha_cpu_register_dump(struct cpu
180          if (gprs) {          if (gprs) {
181                  symbol = get_symbol_name(&cpu->machine->symbol_context,                  symbol = get_symbol_name(&cpu->machine->symbol_context,
182                      cpu->pc, &offset);                      cpu->pc, &offset);
183                  debug("cpu%i:\t pc = 0x%016llx", x, (long long)cpu->pc);                  debug("cpu%i:\t pc = 0x%016"PRIx64, x, (uint64_t) cpu->pc);
184                  debug("  <%s>\n", symbol != NULL? symbol : " no symbol ");                  debug("  <%s>\n", symbol != NULL? symbol : " no symbol ");
185                  for (i=0; i<N_ALPHA_REGS; i++) {                  for (i=0; i<N_ALPHA_REGS; i++) {
186                          int r = (i >> 1) + ((i & 1) << 4);                          int r = (i >> 1) + ((i & 1) << 4);
187                          if ((i % 2) == 0)                          if ((i % 2) == 0)
188                                  debug("cpu%i:\t", x);                                  debug("cpu%i:\t", x);
189                          if (r != ALPHA_ZERO)                          if (r != ALPHA_ZERO)
190                                  debug("%3s = 0x%016llx", alpha_regname[r],                                  debug("%3s = 0x%016"PRIx64, alpha_regname[r],
191                                      (long long)cpu->cd.alpha.r[r]);                                      (uint64_t) cpu->cd.alpha.r[r]);
192                          debug((i % 2) == 1? "\n" : "   ");                          debug((i % 2) == 1? "\n" : "   ");
193                  }                  }
194          }          }
# Line 188  void alpha_cpu_register_dump(struct cpu Line 196  void alpha_cpu_register_dump(struct cpu
196    
197    
198  /*  /*
  *  alpha_cpu_show_full_statistics():  
  *  
  *  Show detailed statistics on opcode usage on each cpu.  
  */  
 void alpha_cpu_show_full_statistics(struct machine *m)  
 {  
         fatal("alpha_cpu_show_full_statistics(): TODO\n");  
 }  
   
   
 /*  
199   *  alpha_cpu_tlbdump():   *  alpha_cpu_tlbdump():
200   *   *
201   *  Called from the debugger to dump the TLB in a readable format.   *  Called from the debugger to dump the TLB in a readable format.
# Line 209  void alpha_cpu_show_full_statistics(stru Line 206  void alpha_cpu_show_full_statistics(stru
206   */   */
207  void alpha_cpu_tlbdump(struct machine *m, int x, int rawflag)  void alpha_cpu_tlbdump(struct machine *m, int x, int rawflag)
208  {  {
209          fatal("alpha_cpu_tlbdump(): TODO\n");  }
210    
211    
212    static void add_response_word(struct cpu *cpu, char *r, uint64_t value,
213            size_t maxlen, int len)
214    {
215            char *format = (len == 4)? "%08"PRIx64 : "%016"PRIx64;
216            if (len == 4)
217                    value &= 0xffffffffULL;
218            if (cpu->byte_order == EMUL_LITTLE_ENDIAN) {
219                    if (len == 4) {
220                            value = ((value & 0xff) << 24) +
221                                    ((value & 0xff00) << 8) +
222                                    ((value & 0xff0000) >> 8) +
223                                    ((value & 0xff000000) >> 24);
224                    } else {
225                            value = ((value & 0xff) << 56) +
226                                    ((value & 0xff00) << 40) +
227                                    ((value & 0xff0000) << 24) +
228                                    ((value & 0xff000000ULL) << 8) +
229                                    ((value & 0xff00000000ULL) >> 8) +
230                                    ((value & 0xff0000000000ULL) >> 24) +
231                                    ((value & 0xff000000000000ULL) >> 40) +
232                                    ((value & 0xff00000000000000ULL) >> 56);
233                    }
234            }
235            snprintf(r + strlen(r), maxlen - strlen(r), format, (uint64_t)value);
236    }
237    
238    
239    /*
240     *  alpha_cpu_gdb_stub():
241     *
242     *  Execute a "remote GDB" command. Returns a newly allocated response string
243     *  on success, NULL on failure.
244     */
245    char *alpha_cpu_gdb_stub(struct cpu *cpu, char *cmd)
246    {
247            if (strcmp(cmd, "g") == 0) {
248                    int i;
249                    char *r;
250                    size_t wlen = cpu->is_32bit?
251                        sizeof(uint32_t) : sizeof(uint64_t);
252                    size_t len = 1 + 76 * wlen;
253                    r = malloc(len);
254                    if (r == NULL) {
255                            fprintf(stderr, "out of memory\n");
256                            exit(1);
257                    }
258                    r[0] = '\0';
259                    for (i=0; i<128; i++)
260                            add_response_word(cpu, r, i, len, wlen);
261                    return r;
262            }
263    
264            if (cmd[0] == 'p') {
265                    int regnr = strtol(cmd + 1, NULL, 16);
266                    size_t wlen = cpu->is_32bit?
267                        sizeof(uint32_t) : sizeof(uint64_t);
268                    size_t len = 2 * wlen + 1;
269                    char *r = malloc(len);
270                    r[0] = '\0';
271                    if (regnr >= 0 && regnr <= 31) {
272                            add_response_word(cpu, r,
273                                cpu->cd.alpha.r[regnr], len, wlen);
274                    } else if (regnr >= 32 && regnr <= 62) {
275                            add_response_word(cpu, r,
276                                cpu->cd.alpha.f[regnr - 32], len, wlen);
277                    } else if (regnr == 0x3f) {
278                            add_response_word(cpu, r, cpu->cd.alpha.fpcr,
279                                len, wlen);
280                    } else if (regnr == 0x40) {
281                            add_response_word(cpu, r, cpu->pc, len, wlen);
282                    } else {
283                            /*  Unimplemented:  */
284                            add_response_word(cpu, r, 0xcc000 + regnr, len, wlen);
285                    }
286                    return r;
287            }
288    
289            fatal("alpha_cpu_gdb_stub(): TODO\n");
290            return NULL;
291  }  }
292    
293    
# Line 268  static void alpha_print_imm16_disp(int i Line 346  static void alpha_print_imm16_disp(int i
346   *  cpu->pc for relative addresses.   *  cpu->pc for relative addresses.
347   */                       */                    
348  int alpha_cpu_disassemble_instr(struct cpu *cpu, unsigned char *ib,  int alpha_cpu_disassemble_instr(struct cpu *cpu, unsigned char *ib,
349          int running, uint64_t dumpaddr, int bintrans)          int running, uint64_t dumpaddr)
350  {  {
351          uint32_t iw;          uint32_t iw;
352          uint64_t offset, tmp;          uint64_t offset, tmp;
# Line 287  int alpha_cpu_disassemble_instr(struct c Line 365  int alpha_cpu_disassemble_instr(struct c
365          if (cpu->machine->ncpus > 1 && running)          if (cpu->machine->ncpus > 1 && running)
366                  debug("cpu%i:\t", cpu->cpu_id);                  debug("cpu%i:\t", cpu->cpu_id);
367    
368          debug("%016llx:  ", (long long)dumpaddr);          debug("%016"PRIx64":  ", (uint64_t) dumpaddr);
369    
370          iw = ib[0] + (ib[1]<<8) + (ib[2]<<16) + (ib[3]<<24);          iw = ib[0] + (ib[1]<<8) + (ib[2]<<16) + (ib[3]<<24);
371          debug("%08x\t", (int)iw);          debug("%08x\t", (int)iw);
# Line 513  int alpha_cpu_disassemble_instr(struct c Line 591  int alpha_cpu_disassemble_instr(struct c
591                  break;                  break;
592          case 0x16:          case 0x16:
593                  switch (func & 0x7ff) {                  switch (func & 0x7ff) {
594                    case 0x02f: mnem = "cvttq/c"; rbrc = 1; break;
595                  case 0x080: mnem = "adds"; break;                  case 0x080: mnem = "adds"; break;
596                  case 0x081: mnem = "subs"; break;                  case 0x081: mnem = "subs"; break;
597                  case 0x082: mnem = "muls"; break;                  case 0x082: mnem = "muls"; break;
598                  case 0x083: mnem = "mult"; break;                  case 0x083: mnem = "XXXx083"; break;
599                  case 0x0a0: mnem = "addt"; break;                  case 0x0a0: mnem = "addt"; break;
600                  case 0x0a1: mnem = "subt"; break;                  case 0x0a1: mnem = "subt"; break;
601                  case 0x0a2: mnem = "mult"; break;                  case 0x0a2: mnem = "mult"; break;
602                  case 0x0a3: mnem = "divt"; break;                  case 0x0a3: mnem = "divt"; break;
603                    case 0x0a5: mnem = "cmpteq"; break;
604                    case 0x0a6: mnem = "cmptlt"; break;
605                    case 0x0a7: mnem = "cmptle"; break;
606                  case 0x0be: mnem = "cvtqt"; rbrc = 1; break;                  case 0x0be: mnem = "cvtqt"; rbrc = 1; break;
607                  default:debug("UNIMPLEMENTED opcode 0x%x func 0x%x\n",                  default:debug("UNIMPLEMENTED opcode 0x%x func 0x%x\n",
608                              opcode, func);                              opcode, func);
# Line 535  int alpha_cpu_disassemble_instr(struct c Line 617  int alpha_cpu_disassemble_instr(struct c
617          case 0x17:          case 0x17:
618                  switch (func & 0x7ff) {                  switch (func & 0x7ff) {
619                  case 0x020: mnem = "fabs"; rbrc = 1; break;                  case 0x020: mnem = "fabs"; rbrc = 1; break;
620                    case 0x021: mnem = "fneg"; rbrc = 1; break;
621                  default:debug("UNIMPLEMENTED opcode 0x%x func 0x%x\n",                  default:debug("UNIMPLEMENTED opcode 0x%x func 0x%x\n",
622                              opcode, func);                              opcode, func);
623                  }                  }
# Line 589  int alpha_cpu_disassemble_instr(struct c Line 672  int alpha_cpu_disassemble_instr(struct c
672                                  debug("jsr");                                  debug("jsr");
673                          debug("\t%s,", alpha_regname[ra]);                          debug("\t%s,", alpha_regname[ra]);
674                          debug("(%s),", alpha_regname[rb]);                          debug("(%s),", alpha_regname[rb]);
675                          debug("0x%llx", (long long)tmp);                          debug("0x%"PRIx64, (uint64_t) tmp);
676                          symbol = get_symbol_name(&cpu->machine->symbol_context,                          symbol = get_symbol_name(&cpu->machine->symbol_context,
677                              tmp, &offset);                              tmp, &offset);
678                          if (symbol != NULL)                          if (symbol != NULL)
# Line 611  int alpha_cpu_disassemble_instr(struct c Line 694  int alpha_cpu_disassemble_instr(struct c
694                  debug("%s\t", opcode==0x30? "br" : "bsr");                  debug("%s\t", opcode==0x30? "br" : "bsr");
695                  if (ra != ALPHA_ZERO)                  if (ra != ALPHA_ZERO)
696                          debug("%s,", alpha_regname[ra]);                          debug("%s,", alpha_regname[ra]);
697                  debug("0x%llx", (long long)tmp);                  debug("0x%"PRIx64, (uint64_t) tmp);
698                  symbol = get_symbol_name(&cpu->machine->symbol_context,                  symbol = get_symbol_name(&cpu->machine->symbol_context,
699                      tmp, &offset);                      tmp, &offset);
700                  if (symbol != NULL)                  if (symbol != NULL)
701                          debug("\t<%s>", symbol);                          debug("\t<%s>", symbol);
702                  debug("\n");                  debug("\n");
703                  break;                  break;
704            case 0x31:
705            case 0x35:
706          case 0x38:          case 0x38:
707          case 0x39:          case 0x39:
708          case 0x3a:          case 0x3a:
# Line 626  int alpha_cpu_disassemble_instr(struct c Line 711  int alpha_cpu_disassemble_instr(struct c
711          case 0x3d:          case 0x3d:
712          case 0x3e:          case 0x3e:
713          case 0x3f:          case 0x3f:
714                    floating = 0;
715                  switch (opcode) {                  switch (opcode) {
716                    case 0x31: mnem = "fbeq"; floating = 1; break;
717                    case 0x35: mnem = "fbne"; floating = 1; break;
718                  case 0x38: mnem = "blbc"; break;                  case 0x38: mnem = "blbc"; break;
719                  case 0x39: mnem = "beq"; break;                  case 0x39: mnem = "beq"; break;
720                  case 0x3a: mnem = "blt"; break;                  case 0x3a: mnem = "blt"; break;
# Line 641  int alpha_cpu_disassemble_instr(struct c Line 729  int alpha_cpu_disassemble_instr(struct c
729                          tmp |= 0xffffffffffe00000ULL;                          tmp |= 0xffffffffffe00000ULL;
730                  tmp <<= 2;                  tmp <<= 2;
731                  tmp += dumpaddr + sizeof(uint32_t);                  tmp += dumpaddr + sizeof(uint32_t);
732                  debug("%s\t%s,", mnem, alpha_regname[ra]);                  debug("%s\t", mnem);
733                  debug("0x%llx", (long long)tmp);                  if (floating)
734                            debug("f%i,", ra);
735                    else
736                            debug("%s,", alpha_regname[ra]);
737                    debug("0x%"PRIx64, (uint64_t) tmp);
738                  symbol = get_symbol_name(&cpu->machine->symbol_context,                  symbol = get_symbol_name(&cpu->machine->symbol_context,
739                      tmp, &offset);                      tmp, &offset);
740                  if (symbol != NULL)                  if (symbol != NULL)

Legend:
Removed from v.18  
changed lines
  Added in v.24

  ViewVC Help
Powered by ViewVC 1.1.26