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

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

  ViewVC Help
Powered by ViewVC 1.1.26