/[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 26 by dpavlin, Mon Oct 8 16:20:10 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.17 2006/06/24 21:47:23 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_v2p = alpha_translate_v2p;
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          return 1;          return 1;
# Line 116  void alpha_cpu_dumpinfo(struct cpu *cpu) Line 113  void alpha_cpu_dumpinfo(struct cpu *cpu)
113   */   */
114  void alpha_cpu_list_available_types(void)  void alpha_cpu_list_available_types(void)
115  {  {
116          /*  TODO  */          int i, j;
117            struct alpha_cpu_type_def tdefs[] = ALPHA_CPU_TYPE_DEFS;
118    
119          debug("Alpha\n");          i = 0;
120            while (tdefs[i].name != NULL) {
121                    debug("%s", tdefs[i].name);
122                    for (j=16 - strlen(tdefs[i].name); j>0; j--)
123                            debug(" ");
124                    i++;
125                    if ((i % 4) == 0 || tdefs[i].name == NULL)
126                            debug("\n");
127            }
128  }  }
129    
130    
# Line 172  void alpha_cpu_register_dump(struct cpu Line 178  void alpha_cpu_register_dump(struct cpu
178          if (gprs) {          if (gprs) {
179                  symbol = get_symbol_name(&cpu->machine->symbol_context,                  symbol = get_symbol_name(&cpu->machine->symbol_context,
180                      cpu->pc, &offset);                      cpu->pc, &offset);
181                  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);
182                  debug("  <%s>\n", symbol != NULL? symbol : " no symbol ");                  debug("  <%s>\n", symbol != NULL? symbol : " no symbol ");
183                  for (i=0; i<N_ALPHA_REGS; i++) {                  for (i=0; i<N_ALPHA_REGS; i++) {
184                          int r = (i >> 1) + ((i & 1) << 4);                          int r = (i >> 1) + ((i & 1) << 4);
185                          if ((i % 2) == 0)                          if ((i % 2) == 0)
186                                  debug("cpu%i:\t", x);                                  debug("cpu%i:\t", x);
187                          if (r != ALPHA_ZERO)                          if (r != ALPHA_ZERO)
188                                  debug("%3s = 0x%016llx", alpha_regname[r],                                  debug("%3s = 0x%016"PRIx64, alpha_regname[r],
189                                      (long long)cpu->cd.alpha.r[r]);                                      (uint64_t) cpu->cd.alpha.r[r]);
190                          debug((i % 2) == 1? "\n" : "   ");                          debug((i % 2) == 1? "\n" : "   ");
191                  }                  }
192          }          }
# Line 188  void alpha_cpu_register_dump(struct cpu Line 194  void alpha_cpu_register_dump(struct cpu
194    
195    
196  /*  /*
  *  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");  
 }  
   
   
 /*  
197   *  alpha_cpu_tlbdump():   *  alpha_cpu_tlbdump():
198   *   *
199   *  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 204  void alpha_cpu_show_full_statistics(stru
204   */   */
205  void alpha_cpu_tlbdump(struct machine *m, int x, int rawflag)  void alpha_cpu_tlbdump(struct machine *m, int x, int rawflag)
206  {  {
207          fatal("alpha_cpu_tlbdump(): TODO\n");  }
208    
209    
210    static void add_response_word(struct cpu *cpu, char *r, uint64_t value,
211            size_t maxlen, int len)
212    {
213            char *format = (len == 4)? "%08"PRIx64 : "%016"PRIx64;
214            if (len == 4)
215                    value &= 0xffffffffULL;
216            if (cpu->byte_order == EMUL_LITTLE_ENDIAN) {
217                    if (len == 4) {
218                            value = ((value & 0xff) << 24) +
219                                    ((value & 0xff00) << 8) +
220                                    ((value & 0xff0000) >> 8) +
221                                    ((value & 0xff000000) >> 24);
222                    } else {
223                            value = ((value & 0xff) << 56) +
224                                    ((value & 0xff00) << 40) +
225                                    ((value & 0xff0000) << 24) +
226                                    ((value & 0xff000000ULL) << 8) +
227                                    ((value & 0xff00000000ULL) >> 8) +
228                                    ((value & 0xff0000000000ULL) >> 24) +
229                                    ((value & 0xff000000000000ULL) >> 40) +
230                                    ((value & 0xff00000000000000ULL) >> 56);
231                    }
232            }
233            snprintf(r + strlen(r), maxlen - strlen(r), format, (uint64_t)value);
234    }
235    
236    
237    /*
238     *  alpha_cpu_gdb_stub():
239     *
240     *  Execute a "remote GDB" command. Returns a newly allocated response string
241     *  on success, NULL on failure.
242     */
243    char *alpha_cpu_gdb_stub(struct cpu *cpu, char *cmd)
244    {
245            if (strcmp(cmd, "g") == 0) {
246                    int i;
247                    char *r;
248                    size_t wlen = cpu->is_32bit?
249                        sizeof(uint32_t) : sizeof(uint64_t);
250                    size_t len = 1 + 76 * wlen;
251                    r = malloc(len);
252                    if (r == NULL) {
253                            fprintf(stderr, "out of memory\n");
254                            exit(1);
255                    }
256                    r[0] = '\0';
257                    for (i=0; i<128; i++)
258                            add_response_word(cpu, r, i, len, wlen);
259                    return r;
260            }
261    
262            if (cmd[0] == 'p') {
263                    int regnr = strtol(cmd + 1, NULL, 16);
264                    size_t wlen = cpu->is_32bit?
265                        sizeof(uint32_t) : sizeof(uint64_t);
266                    size_t len = 2 * wlen + 1;
267                    char *r = malloc(len);
268                    r[0] = '\0';
269                    if (regnr >= 0 && regnr <= 31) {
270                            add_response_word(cpu, r,
271                                cpu->cd.alpha.r[regnr], len, wlen);
272                    } else if (regnr >= 32 && regnr <= 62) {
273                            add_response_word(cpu, r,
274                                cpu->cd.alpha.f[regnr - 32], len, wlen);
275                    } else if (regnr == 0x3f) {
276                            add_response_word(cpu, r, cpu->cd.alpha.fpcr,
277                                len, wlen);
278                    } else if (regnr == 0x40) {
279                            add_response_word(cpu, r, cpu->pc, len, wlen);
280                    } else {
281                            /*  Unimplemented:  */
282                            add_response_word(cpu, r, 0xcc000 + regnr, len, wlen);
283                    }
284                    return r;
285            }
286    
287            fatal("alpha_cpu_gdb_stub(): TODO\n");
288            return NULL;
289  }  }
290    
291    
# Line 268  static void alpha_print_imm16_disp(int i Line 344  static void alpha_print_imm16_disp(int i
344   *  cpu->pc for relative addresses.   *  cpu->pc for relative addresses.
345   */                       */                    
346  int alpha_cpu_disassemble_instr(struct cpu *cpu, unsigned char *ib,  int alpha_cpu_disassemble_instr(struct cpu *cpu, unsigned char *ib,
347          int running, uint64_t dumpaddr, int bintrans)          int running, uint64_t dumpaddr)
348  {  {
349          uint32_t iw;          uint32_t iw;
350          uint64_t offset, tmp;          uint64_t offset, tmp;
# Line 287  int alpha_cpu_disassemble_instr(struct c Line 363  int alpha_cpu_disassemble_instr(struct c
363          if (cpu->machine->ncpus > 1 && running)          if (cpu->machine->ncpus > 1 && running)
364                  debug("cpu%i:\t", cpu->cpu_id);                  debug("cpu%i:\t", cpu->cpu_id);
365    
366          debug("%016llx:  ", (long long)dumpaddr);          debug("%016"PRIx64":  ", (uint64_t) dumpaddr);
367    
368          iw = ib[0] + (ib[1]<<8) + (ib[2]<<16) + (ib[3]<<24);          iw = ib[0] + (ib[1]<<8) + (ib[2]<<16) + (ib[3]<<24);
369          debug("%08x\t", (int)iw);          debug("%08x\t", (int)iw);
# Line 513  int alpha_cpu_disassemble_instr(struct c Line 589  int alpha_cpu_disassemble_instr(struct c
589                  break;                  break;
590          case 0x16:          case 0x16:
591                  switch (func & 0x7ff) {                  switch (func & 0x7ff) {
592                    case 0x02f: mnem = "cvttq/c"; rbrc = 1; break;
593                  case 0x080: mnem = "adds"; break;                  case 0x080: mnem = "adds"; break;
594                  case 0x081: mnem = "subs"; break;                  case 0x081: mnem = "subs"; break;
595                  case 0x082: mnem = "muls"; break;                  case 0x082: mnem = "muls"; break;
596                  case 0x083: mnem = "mult"; break;                  case 0x083: mnem = "XXXx083"; break;
597                  case 0x0a0: mnem = "addt"; break;                  case 0x0a0: mnem = "addt"; break;
598                  case 0x0a1: mnem = "subt"; break;                  case 0x0a1: mnem = "subt"; break;
599                  case 0x0a2: mnem = "mult"; break;                  case 0x0a2: mnem = "mult"; break;
600                  case 0x0a3: mnem = "divt"; break;                  case 0x0a3: mnem = "divt"; break;
601                    case 0x0a5: mnem = "cmpteq"; break;
602                    case 0x0a6: mnem = "cmptlt"; break;
603                    case 0x0a7: mnem = "cmptle"; break;
604                  case 0x0be: mnem = "cvtqt"; rbrc = 1; break;                  case 0x0be: mnem = "cvtqt"; rbrc = 1; break;
605                  default:debug("UNIMPLEMENTED opcode 0x%x func 0x%x\n",                  default:debug("UNIMPLEMENTED opcode 0x%x func 0x%x\n",
606                              opcode, func);                              opcode, func);
# Line 535  int alpha_cpu_disassemble_instr(struct c Line 615  int alpha_cpu_disassemble_instr(struct c
615          case 0x17:          case 0x17:
616                  switch (func & 0x7ff) {                  switch (func & 0x7ff) {
617                  case 0x020: mnem = "fabs"; rbrc = 1; break;                  case 0x020: mnem = "fabs"; rbrc = 1; break;
618                    case 0x021: mnem = "fneg"; rbrc = 1; break;
619                  default:debug("UNIMPLEMENTED opcode 0x%x func 0x%x\n",                  default:debug("UNIMPLEMENTED opcode 0x%x func 0x%x\n",
620                              opcode, func);                              opcode, func);
621                  }                  }
# Line 589  int alpha_cpu_disassemble_instr(struct c Line 670  int alpha_cpu_disassemble_instr(struct c
670                                  debug("jsr");                                  debug("jsr");
671                          debug("\t%s,", alpha_regname[ra]);                          debug("\t%s,", alpha_regname[ra]);
672                          debug("(%s),", alpha_regname[rb]);                          debug("(%s),", alpha_regname[rb]);
673                          debug("0x%llx", (long long)tmp);                          debug("0x%"PRIx64, (uint64_t) tmp);
674                          symbol = get_symbol_name(&cpu->machine->symbol_context,                          symbol = get_symbol_name(&cpu->machine->symbol_context,
675                              tmp, &offset);                              tmp, &offset);
676                          if (symbol != NULL)                          if (symbol != NULL)
# Line 611  int alpha_cpu_disassemble_instr(struct c Line 692  int alpha_cpu_disassemble_instr(struct c
692                  debug("%s\t", opcode==0x30? "br" : "bsr");                  debug("%s\t", opcode==0x30? "br" : "bsr");
693                  if (ra != ALPHA_ZERO)                  if (ra != ALPHA_ZERO)
694                          debug("%s,", alpha_regname[ra]);                          debug("%s,", alpha_regname[ra]);
695                  debug("0x%llx", (long long)tmp);                  debug("0x%"PRIx64, (uint64_t) tmp);
696                  symbol = get_symbol_name(&cpu->machine->symbol_context,                  symbol = get_symbol_name(&cpu->machine->symbol_context,
697                      tmp, &offset);                      tmp, &offset);
698                  if (symbol != NULL)                  if (symbol != NULL)
699                          debug("\t<%s>", symbol);                          debug("\t<%s>", symbol);
700                  debug("\n");                  debug("\n");
701                  break;                  break;
702            case 0x31:
703            case 0x35:
704          case 0x38:          case 0x38:
705          case 0x39:          case 0x39:
706          case 0x3a:          case 0x3a:
# Line 626  int alpha_cpu_disassemble_instr(struct c Line 709  int alpha_cpu_disassemble_instr(struct c
709          case 0x3d:          case 0x3d:
710          case 0x3e:          case 0x3e:
711          case 0x3f:          case 0x3f:
712                    floating = 0;
713                  switch (opcode) {                  switch (opcode) {
714                    case 0x31: mnem = "fbeq"; floating = 1; break;
715                    case 0x35: mnem = "fbne"; floating = 1; break;
716                  case 0x38: mnem = "blbc"; break;                  case 0x38: mnem = "blbc"; break;
717                  case 0x39: mnem = "beq"; break;                  case 0x39: mnem = "beq"; break;
718                  case 0x3a: mnem = "blt"; break;                  case 0x3a: mnem = "blt"; break;
# Line 641  int alpha_cpu_disassemble_instr(struct c Line 727  int alpha_cpu_disassemble_instr(struct c
727                          tmp |= 0xffffffffffe00000ULL;                          tmp |= 0xffffffffffe00000ULL;
728                  tmp <<= 2;                  tmp <<= 2;
729                  tmp += dumpaddr + sizeof(uint32_t);                  tmp += dumpaddr + sizeof(uint32_t);
730                  debug("%s\t%s,", mnem, alpha_regname[ra]);                  debug("%s\t", mnem);
731                  debug("0x%llx", (long long)tmp);                  if (floating)
732                            debug("f%i,", ra);
733                    else
734                            debug("%s,", alpha_regname[ra]);
735                    debug("0x%"PRIx64, (uint64_t) tmp);
736                  symbol = get_symbol_name(&cpu->machine->symbol_context,                  symbol = get_symbol_name(&cpu->machine->symbol_context,
737                      tmp, &offset);                      tmp, &offset);
738                  if (symbol != NULL)                  if (symbol != NULL)

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

  ViewVC Help
Powered by ViewVC 1.1.26