/[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 44 by dpavlin, Mon Oct 8 16:22:56 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   *  Copyright (C) 2005  Anders Gavare.  All rights reserved.   *  Copyright (C) 2005-2007  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.29 2007/06/28 13:36:46 debug Exp $
29   *   *
30   *  Alpha CPU emulation.   *  Alpha CPU emulation.
31   *   *
# Line 41  Line 41 
41  #include <ctype.h>  #include <ctype.h>
42    
43  #include "cpu.h"  #include "cpu.h"
44    #include "interrupt.h"
45  #include "machine.h"  #include "machine.h"
46  #include "memory.h"  #include "memory.h"
47  #include "misc.h"  #include "misc.h"
48    #include "settings.h"
49  #include "symbol.h"  #include "symbol.h"
50    
51  #define DYNTRANS_8K  #define DYNTRANS_8K
# Line 54  Line 56 
56  /*  Alpha symbolic register names:  */  /*  Alpha symbolic register names:  */
57  static char *alpha_regname[N_ALPHA_REGS] = ALPHA_REG_NAMES;  static char *alpha_regname[N_ALPHA_REGS] = ALPHA_REG_NAMES;
58    
59    void alpha_irq_interrupt_assert(struct interrupt *interrupt);
60    void alpha_irq_interrupt_deassert(struct interrupt *interrupt);
61    
62    
63  /*  /*
64   *  alpha_cpu_new():   *  alpha_cpu_new():
# Line 64  static char *alpha_regname[N_ALPHA_REGS] Line 69  static char *alpha_regname[N_ALPHA_REGS]
69  int alpha_cpu_new(struct cpu *cpu, struct memory *mem,  int alpha_cpu_new(struct cpu *cpu, struct memory *mem,
70          struct machine *machine, int cpu_id, char *cpu_type_name)          struct machine *machine, int cpu_id, char *cpu_type_name)
71  {  {
72          int i;          int i = 0;
73            struct alpha_cpu_type_def cpu_type_defs[] = ALPHA_CPU_TYPE_DEFS;
74    
75          if (strcasecmp(cpu_type_name, "Alpha") != 0)          /*  Scan the cpu_type_defs list for this cpu type:  */
76            while (cpu_type_defs[i].name != NULL) {
77                    if (strcasecmp(cpu_type_defs[i].name, cpu_type_name) == 0) {
78                            break;
79                    }
80                    i++;
81            }
82            if (cpu_type_defs[i].name == NULL)
83                  return 0;                  return 0;
84    
85            cpu->is_32bit = 0;
86            cpu->byte_order = EMUL_LITTLE_ENDIAN;
87    
88          cpu->memory_rw = alpha_memory_rw;          cpu->memory_rw = alpha_memory_rw;
89            cpu->run_instr = alpha_run_instr;
90            cpu->translate_v2p = alpha_translate_v2p;
91          cpu->update_translation_table = alpha_update_translation_table;          cpu->update_translation_table = alpha_update_translation_table;
92          cpu->invalidate_translation_caches =          cpu->invalidate_translation_caches =
93              alpha_invalidate_translation_caches;              alpha_invalidate_translation_caches;
94          cpu->invalidate_code_translation = alpha_invalidate_code_translation;          cpu->invalidate_code_translation = alpha_invalidate_code_translation;
95          cpu->is_32bit = 0;  
96            cpu->cd.alpha.cpu_type = cpu_type_defs[i];
97    
98          /*  Only show name and caches etc for CPU nr 0:  */          /*  Only show name and caches etc for CPU nr 0:  */
99          if (cpu_id == 0) {          if (cpu_id == 0) {
100                  debug("%s", cpu->name);                  debug("%s", cpu->name);
101          }          }
102    
         /*  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;  
   
103          cpu->cd.alpha.r[ALPHA_SP] = 0xfffffc000000ff00ULL;          cpu->cd.alpha.r[ALPHA_SP] = 0xfffffc000000ff00ULL;
104    
105            /*  Set up dummy kentry pointers to something which crashes
106                the machine:  */
107            store_32bit_word(cpu, 0x10010, 0x3fffffc);
108            for (i=0; i<N_ALPHA_KENTRY; i++)
109                    cpu->cd.alpha.kentry[i] = 0x10010;
110    
111            /*  Bogus initial context (will be overwritten on first
112                context switch):  */
113            cpu->cd.alpha.ctx = 0x10100;
114    
115            CPU_SETTINGS_ADD_REGISTER64("pc", cpu->pc);
116            for (i=0; i<N_ALPHA_REGS; i++)
117                    CPU_SETTINGS_ADD_REGISTER64(alpha_regname[i],
118                        cpu->cd.alpha.r[i]);
119    
120            /*  Register the CPU interrupt pin:  */
121            {
122                    struct interrupt template;
123    
124                    memset(&template, 0, sizeof(template));
125                    template.line = 0;
126                    template.name = cpu->path;
127                    template.extra = cpu;
128                    template.interrupt_assert = alpha_irq_interrupt_assert;
129                    template.interrupt_deassert = alpha_irq_interrupt_deassert;
130                    interrupt_handler_register(&template);
131            }
132    
133          return 1;          return 1;
134  }  }
135    
# Line 116  void alpha_cpu_dumpinfo(struct cpu *cpu) Line 151  void alpha_cpu_dumpinfo(struct cpu *cpu)
151   */   */
152  void alpha_cpu_list_available_types(void)  void alpha_cpu_list_available_types(void)
153  {  {
154          /*  TODO  */          int i, j;
155            struct alpha_cpu_type_def tdefs[] = ALPHA_CPU_TYPE_DEFS;
         debug("Alpha\n");  
 }  
   
   
 /*  
  *  alpha_cpu_register_match():  
  */  
 void alpha_cpu_register_match(struct machine *m, char *name,  
         int writeflag, uint64_t *valuep, int *match_register)  
 {  
         int i, cpunr = 0;  
   
         /*  CPU number:  */  
156    
157          /*  TODO  */          i = 0;
158            while (tdefs[i].name != NULL) {
159          if (strcasecmp(name, "pc") == 0) {                  debug("%s", tdefs[i].name);
160                  if (writeflag) {                  for (j=13 - strlen(tdefs[i].name); j>0; j--)
161                          m->cpus[cpunr]->pc = *valuep;                          debug(" ");
162                  } else                  i++;
163                          *valuep = m->cpus[cpunr]->pc;                  if ((i % 4) == 0 || tdefs[i].name == NULL)
164                  *match_register = 1;                          debug("\n");
         }  
   
         /*  Register names:  */  
         for (i=0; i<N_ALPHA_REGS; i++) {  
                 if (strcasecmp(name, alpha_regname[i]) == 0) {  
                         if (writeflag)  
                                 m->cpus[cpunr]->cd.alpha.r[i] = *valuep;  
                         else  
                                 *valuep = m->cpus[cpunr]->cd.alpha.r[i];  
                         *match_register = 1;  
                 }  
165          }          }
166  }  }
167    
# Line 172  void alpha_cpu_register_dump(struct cpu Line 183  void alpha_cpu_register_dump(struct cpu
183          if (gprs) {          if (gprs) {
184                  symbol = get_symbol_name(&cpu->machine->symbol_context,                  symbol = get_symbol_name(&cpu->machine->symbol_context,
185                      cpu->pc, &offset);                      cpu->pc, &offset);
186                  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);
187                  debug("  <%s>\n", symbol != NULL? symbol : " no symbol ");                  debug("  <%s>\n", symbol != NULL? symbol : " no symbol ");
188                  for (i=0; i<N_ALPHA_REGS; i++) {                  for (i=0; i<N_ALPHA_REGS; i++) {
189                          int r = (i >> 1) + ((i & 1) << 4);                          int r = (i >> 1) + ((i & 1) << 4);
190                          if ((i % 2) == 0)                          if ((i % 2) == 0)
191                                  debug("cpu%i:\t", x);                                  debug("cpu%i:\t", x);
192                          if (r != ALPHA_ZERO)                          if (r != ALPHA_ZERO)
193                                  debug("%3s = 0x%016llx", alpha_regname[r],                                  debug("%3s = 0x%016"PRIx64, alpha_regname[r],
194                                      (long long)cpu->cd.alpha.r[r]);                                      (uint64_t) cpu->cd.alpha.r[r]);
195                          debug((i % 2) == 1? "\n" : "   ");                          debug((i % 2) == 1? "\n" : "   ");
196                  }                  }
197          }          }
# Line 188  void alpha_cpu_register_dump(struct cpu Line 199  void alpha_cpu_register_dump(struct cpu
199    
200    
201  /*  /*
  *  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");  
 }  
   
   
 /*  
202   *  alpha_cpu_tlbdump():   *  alpha_cpu_tlbdump():
203   *   *
204   *  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 209  void alpha_cpu_show_full_statistics(stru
209   */   */
210  void alpha_cpu_tlbdump(struct machine *m, int x, int rawflag)  void alpha_cpu_tlbdump(struct machine *m, int x, int rawflag)
211  {  {
         fatal("alpha_cpu_tlbdump(): TODO\n");  
212  }  }
213    
214    
215  /*  /*
216   *  alpha_cpu_interrupt():   *  alpha_irq_interrupt_assert():
217     *  alpha_irq_interrupt_deassert():
218   */   */
219  int alpha_cpu_interrupt(struct cpu *cpu, uint64_t irq_nr)  void alpha_irq_interrupt_assert(struct interrupt *interrupt)
220  {  {
221          fatal("alpha_cpu_interrupt(): TODO\n");          struct cpu *cpu = (struct cpu *) interrupt->extra;
222          return 0;          cpu->cd.alpha.irq_asserted = 1;
223  }  }
224    void alpha_irq_interrupt_deassert(struct interrupt *interrupt)
   
 /*  
  *  alpha_cpu_interrupt_ack():  
  */  
 int alpha_cpu_interrupt_ack(struct cpu *cpu, uint64_t irq_nr)  
225  {  {
226          /*  fatal("alpha_cpu_interrupt_ack(): TODO\n");  */          struct cpu *cpu = (struct cpu *) interrupt->extra;
227          return 0;          cpu->cd.alpha.irq_asserted = 0;
228  }  }
229    
230    
# Line 268  static void alpha_print_imm16_disp(int i Line 263  static void alpha_print_imm16_disp(int i
263   *  cpu->pc for relative addresses.   *  cpu->pc for relative addresses.
264   */                       */                    
265  int alpha_cpu_disassemble_instr(struct cpu *cpu, unsigned char *ib,  int alpha_cpu_disassemble_instr(struct cpu *cpu, unsigned char *ib,
266          int running, uint64_t dumpaddr, int bintrans)          int running, uint64_t dumpaddr)
267  {  {
268          uint32_t iw;          uint32_t iw;
269          uint64_t offset, tmp;          uint64_t offset, tmp;
# Line 287  int alpha_cpu_disassemble_instr(struct c Line 282  int alpha_cpu_disassemble_instr(struct c
282          if (cpu->machine->ncpus > 1 && running)          if (cpu->machine->ncpus > 1 && running)
283                  debug("cpu%i:\t", cpu->cpu_id);                  debug("cpu%i:\t", cpu->cpu_id);
284    
285          debug("%016llx:  ", (long long)dumpaddr);          debug("%016"PRIx64":  ", (uint64_t) dumpaddr);
286    
287          iw = ib[0] + (ib[1]<<8) + (ib[2]<<16) + (ib[3]<<24);          iw = ib[0] + (ib[1]<<8) + (ib[2]<<16) + (ib[3]<<24);
288          debug("%08x\t", (int)iw);          debug("%08x\t", (int)iw);
# Line 424  int alpha_cpu_disassemble_instr(struct c Line 419  int alpha_cpu_disassemble_instr(struct c
419                  case 0x061: mnem = "amask"; break;                  case 0x061: mnem = "amask"; break;
420                  case 0x064: mnem = "cmovle"; break;                  case 0x064: mnem = "cmovle"; break;
421                  case 0x066: mnem = "cmovgt"; break;                  case 0x066: mnem = "cmovgt"; break;
422                    case 0x06c: mnem = "implver"; break;
423                  default:debug("UNIMPLEMENTED opcode 0x%x func 0x%x\n",                  default:debug("UNIMPLEMENTED opcode 0x%x func 0x%x\n",
424                              opcode, func);                              opcode, func);
425                  }                  }
# Line 442  int alpha_cpu_disassemble_instr(struct c Line 438  int alpha_cpu_disassemble_instr(struct c
438                          else                          else
439                                  debug("mov\t%s,%s\n", alpha_regname[ra],                                  debug("mov\t%s,%s\n", alpha_regname[ra],
440                                      alpha_regname[rc]);                                      alpha_regname[rc]);
441                    } else if (func == 0x1ec) {
442                            /*  implver  */
443                            debug("%s\t%s\n", mnem, alpha_regname[rc]);
444                  } else if (func & 0x80)                  } else if (func & 0x80)
445                          debug("%s\t%s,0x%x,%s\n", mnem,                          debug("%s\t%s,0x%x,%s\n", mnem,
446                              alpha_regname[ra], (rb << 3) + (func >> 8),                              alpha_regname[ra], (rb << 3) + (func >> 8),
# Line 513  int alpha_cpu_disassemble_instr(struct c Line 512  int alpha_cpu_disassemble_instr(struct c
512                  break;                  break;
513          case 0x16:          case 0x16:
514                  switch (func & 0x7ff) {                  switch (func & 0x7ff) {
515                    case 0x02f: mnem = "cvttq/c"; rbrc = 1; break;
516                  case 0x080: mnem = "adds"; break;                  case 0x080: mnem = "adds"; break;
517                  case 0x081: mnem = "subs"; break;                  case 0x081: mnem = "subs"; break;
518                  case 0x082: mnem = "muls"; break;                  case 0x082: mnem = "muls"; break;
519                  case 0x083: mnem = "mult"; break;                  case 0x083: mnem = "XXXx083"; break;
520                  case 0x0a0: mnem = "addt"; break;                  case 0x0a0: mnem = "addt"; break;
521                  case 0x0a1: mnem = "subt"; break;                  case 0x0a1: mnem = "subt"; break;
522                  case 0x0a2: mnem = "mult"; break;                  case 0x0a2: mnem = "mult"; break;
523                  case 0x0a3: mnem = "divt"; break;                  case 0x0a3: mnem = "divt"; break;
524                    case 0x0a5: mnem = "cmpteq"; break;
525                    case 0x0a6: mnem = "cmptlt"; break;
526                    case 0x0a7: mnem = "cmptle"; break;
527                  case 0x0be: mnem = "cvtqt"; rbrc = 1; break;                  case 0x0be: mnem = "cvtqt"; rbrc = 1; break;
528                  default:debug("UNIMPLEMENTED opcode 0x%x func 0x%x\n",                  default:debug("UNIMPLEMENTED opcode 0x%x func 0x%x\n",
529                              opcode, func);                              opcode, func);
# Line 535  int alpha_cpu_disassemble_instr(struct c Line 538  int alpha_cpu_disassemble_instr(struct c
538          case 0x17:          case 0x17:
539                  switch (func & 0x7ff) {                  switch (func & 0x7ff) {
540                  case 0x020: mnem = "fabs"; rbrc = 1; break;                  case 0x020: mnem = "fabs"; rbrc = 1; break;
541                    case 0x021: mnem = "fneg"; rbrc = 1; break;
542                  default:debug("UNIMPLEMENTED opcode 0x%x func 0x%x\n",                  default:debug("UNIMPLEMENTED opcode 0x%x func 0x%x\n",
543                              opcode, func);                              opcode, func);
544                  }                  }
# Line 589  int alpha_cpu_disassemble_instr(struct c Line 593  int alpha_cpu_disassemble_instr(struct c
593                                  debug("jsr");                                  debug("jsr");
594                          debug("\t%s,", alpha_regname[ra]);                          debug("\t%s,", alpha_regname[ra]);
595                          debug("(%s),", alpha_regname[rb]);                          debug("(%s),", alpha_regname[rb]);
596                          debug("0x%llx", (long long)tmp);                          debug("0x%"PRIx64, (uint64_t) tmp);
597                          symbol = get_symbol_name(&cpu->machine->symbol_context,                          symbol = get_symbol_name(&cpu->machine->symbol_context,
598                              tmp, &offset);                              tmp, &offset);
599                          if (symbol != NULL)                          if (symbol != NULL)
# Line 611  int alpha_cpu_disassemble_instr(struct c Line 615  int alpha_cpu_disassemble_instr(struct c
615                  debug("%s\t", opcode==0x30? "br" : "bsr");                  debug("%s\t", opcode==0x30? "br" : "bsr");
616                  if (ra != ALPHA_ZERO)                  if (ra != ALPHA_ZERO)
617                          debug("%s,", alpha_regname[ra]);                          debug("%s,", alpha_regname[ra]);
618                  debug("0x%llx", (long long)tmp);                  debug("0x%"PRIx64, (uint64_t) tmp);
619                  symbol = get_symbol_name(&cpu->machine->symbol_context,                  symbol = get_symbol_name(&cpu->machine->symbol_context,
620                      tmp, &offset);                      tmp, &offset);
621                  if (symbol != NULL)                  if (symbol != NULL)
622                          debug("\t<%s>", symbol);                          debug("\t<%s>", symbol);
623                  debug("\n");                  debug("\n");
624                  break;                  break;
625            case 0x31:
626            case 0x35:
627          case 0x38:          case 0x38:
628          case 0x39:          case 0x39:
629          case 0x3a:          case 0x3a:
# Line 626  int alpha_cpu_disassemble_instr(struct c Line 632  int alpha_cpu_disassemble_instr(struct c
632          case 0x3d:          case 0x3d:
633          case 0x3e:          case 0x3e:
634          case 0x3f:          case 0x3f:
635                    floating = 0;
636                  switch (opcode) {                  switch (opcode) {
637                    case 0x31: mnem = "fbeq"; floating = 1; break;
638                    case 0x35: mnem = "fbne"; floating = 1; break;
639                  case 0x38: mnem = "blbc"; break;                  case 0x38: mnem = "blbc"; break;
640                  case 0x39: mnem = "beq"; break;                  case 0x39: mnem = "beq"; break;
641                  case 0x3a: mnem = "blt"; break;                  case 0x3a: mnem = "blt"; break;
# Line 641  int alpha_cpu_disassemble_instr(struct c Line 650  int alpha_cpu_disassemble_instr(struct c
650                          tmp |= 0xffffffffffe00000ULL;                          tmp |= 0xffffffffffe00000ULL;
651                  tmp <<= 2;                  tmp <<= 2;
652                  tmp += dumpaddr + sizeof(uint32_t);                  tmp += dumpaddr + sizeof(uint32_t);
653                  debug("%s\t%s,", mnem, alpha_regname[ra]);                  debug("%s\t", mnem);
654                  debug("0x%llx", (long long)tmp);                  if (floating)
655                            debug("f%i,", ra);
656                    else
657                            debug("%s,", alpha_regname[ra]);
658                    debug("0x%"PRIx64, (uint64_t) tmp);
659                  symbol = get_symbol_name(&cpu->machine->symbol_context,                  symbol = get_symbol_name(&cpu->machine->symbol_context,
660                      tmp, &offset);                      tmp, &offset);
661                  if (symbol != NULL)                  if (symbol != NULL)
# Line 659  int alpha_cpu_disassemble_instr(struct c Line 672  int alpha_cpu_disassemble_instr(struct c
672  #define MEMORY_RW       alpha_userland_memory_rw  #define MEMORY_RW       alpha_userland_memory_rw
673  #define MEM_ALPHA  #define MEM_ALPHA
674  #define MEM_USERLAND  #define MEM_USERLAND
675  #include "../memory_rw.c"  #include "memory_rw.c"
676  #undef MEM_USERLAND  #undef MEM_USERLAND
677  #undef MEM_ALPHA  #undef MEM_ALPHA
678  #undef MEMORY_RW  #undef MEMORY_RW

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

  ViewVC Help
Powered by ViewVC 1.1.26