/[gxemul]/trunk/src/cpu_x86.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/cpu_x86.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 9 by dpavlin, Mon Oct 8 16:18:11 2007 UTC revision 10 by dpavlin, Mon Oct 8 16:18:27 2007 UTC
# Line 25  Line 25 
25   *  SUCH DAMAGE.   *  SUCH DAMAGE.
26   *   *
27   *   *
28   *  $Id: cpu_x86.c,v 1.161 2005/05/31 06:20:38 debug Exp $   *  $Id: cpu_x86.c,v 1.163 2005/06/26 22:23:42 debug Exp $
29   *   *
30   *  x86 (and amd64) CPU emulation.   *  x86 (and amd64) CPU emulation.
31   *   *
# Line 92  static char *cond_names[N_X86_CONDS] = x Line 92  static char *cond_names[N_X86_CONDS] = x
92   *   *
93   *  Create a new x86 cpu object.   *  Create a new x86 cpu object.
94   */   */
95  struct cpu *x86_cpu_new(struct memory *mem, struct machine *machine,  int x86_cpu_new(struct cpu *cpu, struct memory *mem, struct machine *machine,
96          int cpu_id, char *cpu_type_name)          int cpu_id, char *cpu_type_name)
97  {  {
98          int i = 0;          int i = 0;
         struct cpu *cpu;  
   
         if (cpu_type_name == NULL)  
                 return NULL;  
99    
100          /*  Try to find a match:  */          /*  Try to find a match:  */
101          while (models[i].model_number != 0) {          while (models[i].model_number != 0) {
# Line 109  struct cpu *x86_cpu_new(struct memory *m Line 105  struct cpu *x86_cpu_new(struct memory *m
105          }          }
106    
107          if (models[i].name == NULL)          if (models[i].name == NULL)
108                  return NULL;                  return 0;
   
         cpu = malloc(sizeof(struct cpu));  
         if (cpu == NULL) {  
                 fprintf(stderr, "out of memory\n");  
                 exit(1);  
         }  
109    
110          memset(cpu, 0, sizeof(struct cpu));          cpu->memory_rw  = x86_memory_rw;
111          cpu->memory_rw          = x86_memory_rw;          cpu->byte_order = EMUL_LITTLE_ENDIAN;
         cpu->name               = cpu_type_name;  
         cpu->mem                = mem;  
         cpu->machine            = machine;  
         cpu->cpu_id             = cpu_id;  
         cpu->byte_order         = EMUL_LITTLE_ENDIAN;  
         cpu->bootstrap_cpu_flag = 0;  
         cpu->running            = 0;  
112    
113          cpu->cd.x86.model = models[i];          cpu->cd.x86.model = models[i];
114    
# Line 158  struct cpu *x86_cpu_new(struct memory *m Line 141  struct cpu *x86_cpu_new(struct memory *m
141                  debug("%s", cpu->name);                  debug("%s", cpu->name);
142          }          }
143    
144          return cpu;          return 1;
145  }  }
146    
147    
# Line 1350  static int modrm(struct cpu *cpu, int wr Line 1333  static int modrm(struct cpu *cpu, int wr
1333          case 3:          case 3:
1334                  if (flags & MODRM_EIGHTBIT) {                  if (flags & MODRM_EIGHTBIT) {
1335                          if (disasm) {                          if (disasm) {
1336                                  strcpy(modrm_rm, reg_names_bytes[rm]);                                  strlcpy(modrm_rm, reg_names_bytes[rm],
1337                                        sizeof(modrm_rm));
1338                          } else {                          } else {
1339                                  switch (writeflag) {                                  switch (writeflag) {
1340                                  case MODRM_WRITE_RM:                                  case MODRM_WRITE_RM:
# Line 1375  static int modrm(struct cpu *cpu, int wr Line 1359  static int modrm(struct cpu *cpu, int wr
1359                  } else {                  } else {
1360                          if (disasm) {                          if (disasm) {
1361                                  if (mode == 16 || flags & MODRM_RM_16BIT)                                  if (mode == 16 || flags & MODRM_RM_16BIT)
1362                                          strcpy(modrm_rm, reg_names[rm]);                                          strlcpy(modrm_rm, reg_names[rm],
1363                                                sizeof(modrm_rm));
1364                                  else                                  else
1365                                          sprintf(modrm_rm, "%s%s", e,                                          sprintf(modrm_rm, "%s%s", e,
1366                                              reg_names[rm]);                                              reg_names[rm]);
# Line 1415  static int modrm(struct cpu *cpu, int wr Line 1400  static int modrm(struct cpu *cpu, int wr
1400    
1401          if (flags & MODRM_EIGHTBIT && !(flags & MODRM_R_NONEIGHTBIT)) {          if (flags & MODRM_EIGHTBIT && !(flags & MODRM_R_NONEIGHTBIT)) {
1402                  if (disasm) {                  if (disasm) {
1403                          strcpy(modrm_r, reg_names_bytes[r]);                          strlcpy(modrm_r, reg_names_bytes[r],
1404                                sizeof(modrm_r));
1405                  } else {                  } else {
1406                          switch (writeflag) {                          switch (writeflag) {
1407                          case MODRM_WRITE_R:                          case MODRM_WRITE_R:
# Line 1437  static int modrm(struct cpu *cpu, int wr Line 1423  static int modrm(struct cpu *cpu, int wr
1423          } else {          } else {
1424                  if (disasm) {                  if (disasm) {
1425                          if (flags & MODRM_SEG)                          if (flags & MODRM_SEG)
1426                                  strcpy(modrm_r, seg_names[r]);                                  strlcpy(modrm_r, seg_names[r],
1427                                        sizeof(modrm_r));
1428                          else if (flags & MODRM_CR)                          else if (flags & MODRM_CR)
1429                                  sprintf(modrm_r, "cr%i", r);                                  sprintf(modrm_r, "cr%i", r);
1430                          else if (flags & MODRM_DR)                          else if (flags & MODRM_DR)
# Line 1447  static int modrm(struct cpu *cpu, int wr Line 1434  static int modrm(struct cpu *cpu, int wr
1434                                          sprintf(modrm_r, "%s%s", e,                                          sprintf(modrm_r, "%s%s", e,
1435                                              reg_names[r]);                                              reg_names[r]);
1436                                  else                                  else
1437                                          strcpy(modrm_r, reg_names[r]);                                          strlcpy(modrm_r, reg_names[r],
1438                                                sizeof(modrm_r));
1439                          }                          }
1440                  } else {                  } else {
1441                          switch (writeflag) {                          switch (writeflag) {

Legend:
Removed from v.9  
changed lines
  Added in v.10

  ViewVC Help
Powered by ViewVC 1.1.26