/[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 22 by dpavlin, Mon Oct 8 16:19:37 2007 UTC revision 34 by dpavlin, Mon Oct 8 16:21:17 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   *  Copyright (C) 2005-2006  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.5 2006/01/01 16:08:25 debug Exp $   *  $Id: cpu_alpha.c,v 1.24 2006/12/30 13:30:53 debug Exp $
29   *   *
30   *  Alpha CPU emulation.   *  Alpha CPU emulation.
31   *   *
# Line 44  Line 44 
44  #include "machine.h"  #include "machine.h"
45  #include "memory.h"  #include "memory.h"
46  #include "misc.h"  #include "misc.h"
47    #include "settings.h"
48  #include "symbol.h"  #include "symbol.h"
49    
50  #define DYNTRANS_8K  #define DYNTRANS_8K
# Line 64  static char *alpha_regname[N_ALPHA_REGS] Line 65  static char *alpha_regname[N_ALPHA_REGS]
65  int alpha_cpu_new(struct cpu *cpu, struct memory *mem,  int alpha_cpu_new(struct cpu *cpu, struct memory *mem,
66          struct machine *machine, int cpu_id, char *cpu_type_name)          struct machine *machine, int cpu_id, char *cpu_type_name)
67  {  {
68          int i;          int i = 0;
69            struct alpha_cpu_type_def cpu_type_defs[] = ALPHA_CPU_TYPE_DEFS;
70    
71          if (strcasecmp(cpu_type_name, "Alpha") != 0)          /*  Scan the cpu_type_defs list for this cpu type:  */
72            while (cpu_type_defs[i].name != NULL) {
73                    if (strcasecmp(cpu_type_defs[i].name, cpu_type_name) == 0) {
74                            break;
75                    }
76                    i++;
77            }
78            if (cpu_type_defs[i].name == NULL)
79                  return 0;                  return 0;
80    
81            cpu->is_32bit = 0;
82            cpu->byte_order = EMUL_LITTLE_ENDIAN;
83    
84          cpu->memory_rw = alpha_memory_rw;          cpu->memory_rw = alpha_memory_rw;
85            cpu->run_instr = alpha_run_instr;
86            cpu->translate_v2p = alpha_translate_v2p;
87          cpu->update_translation_table = alpha_update_translation_table;          cpu->update_translation_table = alpha_update_translation_table;
88          cpu->invalidate_translation_caches =          cpu->invalidate_translation_caches =
89              alpha_invalidate_translation_caches;              alpha_invalidate_translation_caches;
90          cpu->invalidate_code_translation = alpha_invalidate_code_translation;          cpu->invalidate_code_translation = alpha_invalidate_code_translation;
91          cpu->is_32bit = 0;  
92            cpu->cd.alpha.cpu_type = cpu_type_defs[i];
93    
94          /*  Only show name and caches etc for CPU nr 0:  */          /*  Only show name and caches etc for CPU nr 0:  */
95          if (cpu_id == 0) {          if (cpu_id == 0) {
96                  debug("%s", cpu->name);                  debug("%s", cpu->name);
97          }          }
98    
         /*  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;  
   
99          cpu->cd.alpha.r[ALPHA_SP] = 0xfffffc000000ff00ULL;          cpu->cd.alpha.r[ALPHA_SP] = 0xfffffc000000ff00ULL;
100    
101            /*  Set up dummy kentry pointers to something which crashes
102                the machine:  */
103            store_32bit_word(cpu, 0x10010, 0x3fffffc);
104            for (i=0; i<N_ALPHA_KENTRY; i++)
105                    cpu->cd.alpha.kentry[i] = 0x10010;
106    
107            /*  Bogus initial context (will be overwritten on first
108                context switch):  */
109            cpu->cd.alpha.ctx = 0x10100;
110    
111            CPU_SETTINGS_ADD_REGISTER64("pc", cpu->pc);
112            for (i=0; i<N_ALPHA_REGS; i++)
113                    CPU_SETTINGS_ADD_REGISTER64(alpha_regname[i],
114                        cpu->cd.alpha.r[i]);
115    
116          return 1;          return 1;
117  }  }
118    
# Line 116  void alpha_cpu_dumpinfo(struct cpu *cpu) Line 134  void alpha_cpu_dumpinfo(struct cpu *cpu)
134   */   */
135  void alpha_cpu_list_available_types(void)  void alpha_cpu_list_available_types(void)
136  {  {
137          /*  TODO  */          int i, j;
138            struct alpha_cpu_type_def tdefs[] = ALPHA_CPU_TYPE_DEFS;
         debug("Alpha\n");  
 }  
   
139    
140  /*          i = 0;
141   *  alpha_cpu_register_match():          while (tdefs[i].name != NULL) {
142   */                  debug("%s", tdefs[i].name);
143  void alpha_cpu_register_match(struct machine *m, char *name,                  for (j=13 - strlen(tdefs[i].name); j>0; j--)
144          int writeflag, uint64_t *valuep, int *match_register)                          debug(" ");
145  {                  i++;
146          int i, cpunr = 0;                  if ((i % 4) == 0 || tdefs[i].name == NULL)
147                            debug("\n");
         /*  CPU number:  */  
   
         /*  TODO  */  
   
         if (strcasecmp(name, "pc") == 0) {  
                 if (writeflag) {  
                         m->cpus[cpunr]->pc = *valuep;  
                 } else  
                         *valuep = m->cpus[cpunr]->pc;  
                 *match_register = 1;  
         }  
   
         /*  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;  
                 }  
148          }          }
149  }  }
150    
# Line 172  void alpha_cpu_register_dump(struct cpu Line 166  void alpha_cpu_register_dump(struct cpu
166          if (gprs) {          if (gprs) {
167                  symbol = get_symbol_name(&cpu->machine->symbol_context,                  symbol = get_symbol_name(&cpu->machine->symbol_context,
168                      cpu->pc, &offset);                      cpu->pc, &offset);
169                  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);
170                  debug("  <%s>\n", symbol != NULL? symbol : " no symbol ");                  debug("  <%s>\n", symbol != NULL? symbol : " no symbol ");
171                  for (i=0; i<N_ALPHA_REGS; i++) {                  for (i=0; i<N_ALPHA_REGS; i++) {
172                          int r = (i >> 1) + ((i & 1) << 4);                          int r = (i >> 1) + ((i & 1) << 4);
173                          if ((i % 2) == 0)                          if ((i % 2) == 0)
174                                  debug("cpu%i:\t", x);                                  debug("cpu%i:\t", x);
175                          if (r != ALPHA_ZERO)                          if (r != ALPHA_ZERO)
176                                  debug("%3s = 0x%016llx", alpha_regname[r],                                  debug("%3s = 0x%016"PRIx64, alpha_regname[r],
177                                      (long long)cpu->cd.alpha.r[r]);                                      (uint64_t) cpu->cd.alpha.r[r]);
178                          debug((i % 2) == 1? "\n" : "   ");                          debug((i % 2) == 1? "\n" : "   ");
179                  }                  }
180          }          }
# Line 188  void alpha_cpu_register_dump(struct cpu Line 182  void alpha_cpu_register_dump(struct cpu
182    
183    
184  /*  /*
185     *  alpha_cpu_tlbdump():
186     *
187     *  Called from the debugger to dump the TLB in a readable format.
188     *  x is the cpu number to dump, or -1 to dump all CPUs.
189     *
190     *  If rawflag is nonzero, then the TLB contents isn't formated nicely,
191     *  just dumped.
192     */
193    void alpha_cpu_tlbdump(struct machine *m, int x, int rawflag)
194    {
195    }
196    
197    
198    static void add_response_word(struct cpu *cpu, char *r, uint64_t value,
199            size_t maxlen, int len)
200    {
201            char *format = (len == 4)? "%08"PRIx64 : "%016"PRIx64;
202            if (len == 4)
203                    value &= 0xffffffffULL;
204            if (cpu->byte_order == EMUL_LITTLE_ENDIAN) {
205                    if (len == 4) {
206                            value = ((value & 0xff) << 24) +
207                                    ((value & 0xff00) << 8) +
208                                    ((value & 0xff0000) >> 8) +
209                                    ((value & 0xff000000) >> 24);
210                    } else {
211                            value = ((value & 0xff) << 56) +
212                                    ((value & 0xff00) << 40) +
213                                    ((value & 0xff0000) << 24) +
214                                    ((value & 0xff000000ULL) << 8) +
215                                    ((value & 0xff00000000ULL) >> 8) +
216                                    ((value & 0xff0000000000ULL) >> 24) +
217                                    ((value & 0xff000000000000ULL) >> 40) +
218                                    ((value & 0xff00000000000000ULL) >> 56);
219                    }
220            }
221            snprintf(r + strlen(r), maxlen - strlen(r), format, (uint64_t)value);
222    }
223    
224    
225    /*
226     *  alpha_cpu_gdb_stub():
227     *
228     *  Execute a "remote GDB" command. Returns a newly allocated response string
229     *  on success, NULL on failure.
230     */
231    char *alpha_cpu_gdb_stub(struct cpu *cpu, char *cmd)
232    {
233            if (strcmp(cmd, "g") == 0) {
234                    int i;
235                    char *r;
236                    size_t wlen = cpu->is_32bit?
237                        sizeof(uint32_t) : sizeof(uint64_t);
238                    size_t len = 1 + 76 * wlen;
239                    r = malloc(len);
240                    if (r == NULL) {
241                            fprintf(stderr, "out of memory\n");
242                            exit(1);
243                    }
244                    r[0] = '\0';
245                    for (i=0; i<128; i++)
246                            add_response_word(cpu, r, i, len, wlen);
247                    return r;
248            }
249    
250            if (cmd[0] == 'p') {
251                    int regnr = strtol(cmd + 1, NULL, 16);
252                    size_t wlen = cpu->is_32bit?
253                        sizeof(uint32_t) : sizeof(uint64_t);
254                    size_t len = 2 * wlen + 1;
255                    char *r = malloc(len);
256                    r[0] = '\0';
257                    if (regnr >= 0 && regnr <= 31) {
258                            add_response_word(cpu, r,
259                                cpu->cd.alpha.r[regnr], len, wlen);
260                    } else if (regnr >= 32 && regnr <= 62) {
261                            add_response_word(cpu, r,
262                                cpu->cd.alpha.f[regnr - 32], len, wlen);
263                    } else if (regnr == 0x3f) {
264                            add_response_word(cpu, r, cpu->cd.alpha.fpcr,
265                                len, wlen);
266                    } else if (regnr == 0x40) {
267                            add_response_word(cpu, r, cpu->pc, len, wlen);
268                    } else {
269                            /*  Unimplemented:  */
270                            add_response_word(cpu, r, 0xcc000 + regnr, len, wlen);
271                    }
272                    return r;
273            }
274    
275            fatal("alpha_cpu_gdb_stub(): TODO\n");
276            return NULL;
277    }
278    
279    
280    /*
281   *  alpha_cpu_interrupt():   *  alpha_cpu_interrupt():
282   */   */
283  int alpha_cpu_interrupt(struct cpu *cpu, uint64_t irq_nr)  int alpha_cpu_interrupt(struct cpu *cpu, uint64_t irq_nr)
# Line 242  static void alpha_print_imm16_disp(int i Line 332  static void alpha_print_imm16_disp(int i
332   *  cpu->pc for relative addresses.   *  cpu->pc for relative addresses.
333   */                       */                    
334  int alpha_cpu_disassemble_instr(struct cpu *cpu, unsigned char *ib,  int alpha_cpu_disassemble_instr(struct cpu *cpu, unsigned char *ib,
335          int running, uint64_t dumpaddr, int bintrans)          int running, uint64_t dumpaddr)
336  {  {
337          uint32_t iw;          uint32_t iw;
338          uint64_t offset, tmp;          uint64_t offset, tmp;
# Line 261  int alpha_cpu_disassemble_instr(struct c Line 351  int alpha_cpu_disassemble_instr(struct c
351          if (cpu->machine->ncpus > 1 && running)          if (cpu->machine->ncpus > 1 && running)
352                  debug("cpu%i:\t", cpu->cpu_id);                  debug("cpu%i:\t", cpu->cpu_id);
353    
354          debug("%016llx:  ", (long long)dumpaddr);          debug("%016"PRIx64":  ", (uint64_t) dumpaddr);
355    
356          iw = ib[0] + (ib[1]<<8) + (ib[2]<<16) + (ib[3]<<24);          iw = ib[0] + (ib[1]<<8) + (ib[2]<<16) + (ib[3]<<24);
357          debug("%08x\t", (int)iw);          debug("%08x\t", (int)iw);
# Line 398  int alpha_cpu_disassemble_instr(struct c Line 488  int alpha_cpu_disassemble_instr(struct c
488                  case 0x061: mnem = "amask"; break;                  case 0x061: mnem = "amask"; break;
489                  case 0x064: mnem = "cmovle"; break;                  case 0x064: mnem = "cmovle"; break;
490                  case 0x066: mnem = "cmovgt"; break;                  case 0x066: mnem = "cmovgt"; break;
491                    case 0x06c: mnem = "implver"; break;
492                  default:debug("UNIMPLEMENTED opcode 0x%x func 0x%x\n",                  default:debug("UNIMPLEMENTED opcode 0x%x func 0x%x\n",
493                              opcode, func);                              opcode, func);
494                  }                  }
# Line 416  int alpha_cpu_disassemble_instr(struct c Line 507  int alpha_cpu_disassemble_instr(struct c
507                          else                          else
508                                  debug("mov\t%s,%s\n", alpha_regname[ra],                                  debug("mov\t%s,%s\n", alpha_regname[ra],
509                                      alpha_regname[rc]);                                      alpha_regname[rc]);
510                    } else if (func == 0x1ec) {
511                            /*  implver  */
512                            debug("%s\t%s\n", mnem, alpha_regname[rc]);
513                  } else if (func & 0x80)                  } else if (func & 0x80)
514                          debug("%s\t%s,0x%x,%s\n", mnem,                          debug("%s\t%s,0x%x,%s\n", mnem,
515                              alpha_regname[ra], (rb << 3) + (func >> 8),                              alpha_regname[ra], (rb << 3) + (func >> 8),
# Line 568  int alpha_cpu_disassemble_instr(struct c Line 662  int alpha_cpu_disassemble_instr(struct c
662                                  debug("jsr");                                  debug("jsr");
663                          debug("\t%s,", alpha_regname[ra]);                          debug("\t%s,", alpha_regname[ra]);
664                          debug("(%s),", alpha_regname[rb]);                          debug("(%s),", alpha_regname[rb]);
665                          debug("0x%llx", (long long)tmp);                          debug("0x%"PRIx64, (uint64_t) tmp);
666                          symbol = get_symbol_name(&cpu->machine->symbol_context,                          symbol = get_symbol_name(&cpu->machine->symbol_context,
667                              tmp, &offset);                              tmp, &offset);
668                          if (symbol != NULL)                          if (symbol != NULL)
# Line 590  int alpha_cpu_disassemble_instr(struct c Line 684  int alpha_cpu_disassemble_instr(struct c
684                  debug("%s\t", opcode==0x30? "br" : "bsr");                  debug("%s\t", opcode==0x30? "br" : "bsr");
685                  if (ra != ALPHA_ZERO)                  if (ra != ALPHA_ZERO)
686                          debug("%s,", alpha_regname[ra]);                          debug("%s,", alpha_regname[ra]);
687                  debug("0x%llx", (long long)tmp);                  debug("0x%"PRIx64, (uint64_t) tmp);
688                  symbol = get_symbol_name(&cpu->machine->symbol_context,                  symbol = get_symbol_name(&cpu->machine->symbol_context,
689                      tmp, &offset);                      tmp, &offset);
690                  if (symbol != NULL)                  if (symbol != NULL)
# Line 630  int alpha_cpu_disassemble_instr(struct c Line 724  int alpha_cpu_disassemble_instr(struct c
724                          debug("f%i,", ra);                          debug("f%i,", ra);
725                  else                  else
726                          debug("%s,", alpha_regname[ra]);                          debug("%s,", alpha_regname[ra]);
727                  debug("0x%llx", (long long)tmp);                  debug("0x%"PRIx64, (uint64_t) tmp);
728                  symbol = get_symbol_name(&cpu->machine->symbol_context,                  symbol = get_symbol_name(&cpu->machine->symbol_context,
729                      tmp, &offset);                      tmp, &offset);
730                  if (symbol != NULL)                  if (symbol != NULL)

Legend:
Removed from v.22  
changed lines
  Added in v.34

  ViewVC Help
Powered by ViewVC 1.1.26