/[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 28 by dpavlin, Mon Oct 8 16:20:26 2007 UTC revision 38 by dpavlin, Mon Oct 8 16:21:53 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.19 2006/07/20 21:52:59 debug Exp $   *  $Id: cpu_alpha.c,v 1.25 2007/03/26 02:01:35 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 77  int alpha_cpu_new(struct cpu *cpu, struc Line 78  int alpha_cpu_new(struct cpu *cpu, struc
78          if (cpu_type_defs[i].name == NULL)          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;          cpu->run_instr = alpha_run_instr;
86          cpu->translate_v2p = alpha_translate_v2p;          cpu->translate_v2p = alpha_translate_v2p;
# Line 84  int alpha_cpu_new(struct cpu *cpu, struc Line 88  int alpha_cpu_new(struct cpu *cpu, struc
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) {
# Line 93  int alpha_cpu_new(struct cpu *cpu, struc Line 98  int alpha_cpu_new(struct cpu *cpu, struc
98    
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 130  void alpha_cpu_list_available_types(void Line 150  void alpha_cpu_list_available_types(void
150    
151    
152  /*  /*
  *  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:  */  
   
         /*  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;  
                 }  
         }  
 }  
   
   
 /*  
153   *  alpha_cpu_register_dump():   *  alpha_cpu_register_dump():
154   *     *  
155   *  Dump cpu registers in a relatively readable format.   *  Dump cpu registers in a relatively readable format.
# Line 208  void alpha_cpu_tlbdump(struct machine *m Line 195  void alpha_cpu_tlbdump(struct machine *m
195  }  }
196    
197    
 static void add_response_word(struct cpu *cpu, char *r, uint64_t value,  
         size_t maxlen, int len)  
 {  
         char *format = (len == 4)? "%08"PRIx64 : "%016"PRIx64;  
         if (len == 4)  
                 value &= 0xffffffffULL;  
         if (cpu->byte_order == EMUL_LITTLE_ENDIAN) {  
                 if (len == 4) {  
                         value = ((value & 0xff) << 24) +  
                                 ((value & 0xff00) << 8) +  
                                 ((value & 0xff0000) >> 8) +  
                                 ((value & 0xff000000) >> 24);  
                 } else {  
                         value = ((value & 0xff) << 56) +  
                                 ((value & 0xff00) << 40) +  
                                 ((value & 0xff0000) << 24) +  
                                 ((value & 0xff000000ULL) << 8) +  
                                 ((value & 0xff00000000ULL) >> 8) +  
                                 ((value & 0xff0000000000ULL) >> 24) +  
                                 ((value & 0xff000000000000ULL) >> 40) +  
                                 ((value & 0xff00000000000000ULL) >> 56);  
                 }  
         }  
         snprintf(r + strlen(r), maxlen - strlen(r), format, (uint64_t)value);  
 }  
   
   
 /*  
  *  alpha_cpu_gdb_stub():  
  *  
  *  Execute a "remote GDB" command. Returns a newly allocated response string  
  *  on success, NULL on failure.  
  */  
 char *alpha_cpu_gdb_stub(struct cpu *cpu, char *cmd)  
 {  
         if (strcmp(cmd, "g") == 0) {  
                 int i;  
                 char *r;  
                 size_t wlen = cpu->is_32bit?  
                     sizeof(uint32_t) : sizeof(uint64_t);  
                 size_t len = 1 + 76 * wlen;  
                 r = malloc(len);  
                 if (r == NULL) {  
                         fprintf(stderr, "out of memory\n");  
                         exit(1);  
                 }  
                 r[0] = '\0';  
                 for (i=0; i<128; i++)  
                         add_response_word(cpu, r, i, len, wlen);  
                 return r;  
         }  
   
         if (cmd[0] == 'p') {  
                 int regnr = strtol(cmd + 1, NULL, 16);  
                 size_t wlen = cpu->is_32bit?  
                     sizeof(uint32_t) : sizeof(uint64_t);  
                 size_t len = 2 * wlen + 1;  
                 char *r = malloc(len);  
                 r[0] = '\0';  
                 if (regnr >= 0 && regnr <= 31) {  
                         add_response_word(cpu, r,  
                             cpu->cd.alpha.r[regnr], len, wlen);  
                 } else if (regnr >= 32 && regnr <= 62) {  
                         add_response_word(cpu, r,  
                             cpu->cd.alpha.f[regnr - 32], len, wlen);  
                 } else if (regnr == 0x3f) {  
                         add_response_word(cpu, r, cpu->cd.alpha.fpcr,  
                             len, wlen);  
                 } else if (regnr == 0x40) {  
                         add_response_word(cpu, r, cpu->pc, len, wlen);  
                 } else {  
                         /*  Unimplemented:  */  
                         add_response_word(cpu, r, 0xcc000 + regnr, len, wlen);  
                 }  
                 return r;  
         }  
   
         fatal("alpha_cpu_gdb_stub(): TODO\n");  
         return NULL;  
 }  
   
   
 /*  
  *  alpha_cpu_interrupt():  
  */  
 int alpha_cpu_interrupt(struct cpu *cpu, uint64_t irq_nr)  
 {  
         fatal("alpha_cpu_interrupt(): TODO\n");  
         return 0;  
 }  
   
   
 /*  
  *  alpha_cpu_interrupt_ack():  
  */  
 int alpha_cpu_interrupt_ack(struct cpu *cpu, uint64_t irq_nr)  
 {  
         /*  fatal("alpha_cpu_interrupt_ack(): TODO\n");  */  
         return 0;  
 }  
   
   
198  /*  /*
199   *  alpha_print_imm16_disp():   *  alpha_print_imm16_disp():
200   *   *
# Line 501  int alpha_cpu_disassemble_instr(struct c Line 386  int alpha_cpu_disassemble_instr(struct c
386                  case 0x061: mnem = "amask"; break;                  case 0x061: mnem = "amask"; break;
387                  case 0x064: mnem = "cmovle"; break;                  case 0x064: mnem = "cmovle"; break;
388                  case 0x066: mnem = "cmovgt"; break;                  case 0x066: mnem = "cmovgt"; break;
389                    case 0x06c: mnem = "implver"; break;
390                  default:debug("UNIMPLEMENTED opcode 0x%x func 0x%x\n",                  default:debug("UNIMPLEMENTED opcode 0x%x func 0x%x\n",
391                              opcode, func);                              opcode, func);
392                  }                  }
# Line 519  int alpha_cpu_disassemble_instr(struct c Line 405  int alpha_cpu_disassemble_instr(struct c
405                          else                          else
406                                  debug("mov\t%s,%s\n", alpha_regname[ra],                                  debug("mov\t%s,%s\n", alpha_regname[ra],
407                                      alpha_regname[rc]);                                      alpha_regname[rc]);
408                    } else if (func == 0x1ec) {
409                            /*  implver  */
410                            debug("%s\t%s\n", mnem, alpha_regname[rc]);
411                  } else if (func & 0x80)                  } else if (func & 0x80)
412                          debug("%s\t%s,0x%x,%s\n", mnem,                          debug("%s\t%s,0x%x,%s\n", mnem,
413                              alpha_regname[ra], (rb << 3) + (func >> 8),                              alpha_regname[ra], (rb << 3) + (func >> 8),

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

  ViewVC Help
Powered by ViewVC 1.1.26