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

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

revision 16 by dpavlin, Mon Oct 8 16:19:01 2007 UTC revision 34 by dpavlin, Mon Oct 8 16:21:17 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: dev_pccmos.c,v 1.7 2005/10/09 22:21:31 debug Exp $   *  $Id: dev_pccmos.c,v 1.28 2007/02/10 14:04:51 debug Exp $
29   *     *  
30   *  PC CMOS/RTC device.   *  PC CMOS/RTC device (ISA ports 0x70 and 0x71).
31   *   *
32   *  The main point of this device is to be a "PC style wrapper" for accessing   *  The main point of this device is to be a "PC style wrapper" for accessing
33   *  the MC146818 (the RTC). In most other respects, this device is bogus, and   *  the MC146818 (the RTC). In most other respects, this device is bogus, and
# Line 56  struct pccmos_data { Line 56  struct pccmos_data {
56  };  };
57    
58    
59  /*  DEVICE_ACCESS(pccmos)
  *  dev_pccmos_access():  
  */  
 int dev_pccmos_access(struct cpu *cpu, struct memory *mem,  
         uint64_t relative_addr, unsigned char *data, size_t len,  
         int writeflag, void *extra)  
60  {  {
61          struct pccmos_data *d = (struct pccmos_data *) extra;          struct pccmos_data *d = (struct pccmos_data *) extra;
62          uint64_t idata = 0, odata = 0;          uint64_t idata = 0, odata = 0;
63          unsigned char b;          unsigned char b = 0;
64            int r = 1;
65    
66          b = idata = memory_readmax64(cpu, data, len);          if (writeflag == MEM_WRITE)
67                    b = idata = memory_readmax64(cpu, data, len);
68    
69          /*          /*
70           *  Accesses to CMOS register 0 .. 0xd are rerouted to the           *  Accesses to CMOS register 0 .. 0xd are rerouted to the
# Line 78  int dev_pccmos_access(struct cpu *cpu, s Line 75  int dev_pccmos_access(struct cpu *cpu, s
75                  if (writeflag == MEM_WRITE) {                  if (writeflag == MEM_WRITE) {
76                          d->select = idata;                          d->select = idata;
77                          if (idata <= 0x0d) {                          if (idata <= 0x0d) {
78                                  cpu->memory_rw(cpu, cpu->mem,                                  r = cpu->memory_rw(cpu, cpu->mem,
79                                      PCCMOS_MC146818_FAKE_ADDR, &b, 1,                                      PCCMOS_MC146818_FAKE_ADDR, &b, 1,
80                                      MEM_WRITE, PHYSICAL);                                      MEM_WRITE, PHYSICAL);
81                          }                          }
# Line 87  int dev_pccmos_access(struct cpu *cpu, s Line 84  int dev_pccmos_access(struct cpu *cpu, s
84          } else {          } else {
85                  if (d->select <= 0x0d) {                  if (d->select <= 0x0d) {
86                          if (writeflag == MEM_WRITE) {                          if (writeflag == MEM_WRITE) {
87                                  cpu->memory_rw(cpu, cpu->mem,                                  r = cpu->memory_rw(cpu, cpu->mem,
88                                      PCCMOS_MC146818_FAKE_ADDR + 1, &b, 1,                                      PCCMOS_MC146818_FAKE_ADDR + 1, &b, 1,
89                                      MEM_WRITE, PHYSICAL);                                      MEM_WRITE, PHYSICAL);
90                          } else {                          } else {
91                                  cpu->memory_rw(cpu, cpu->mem,                                  r = cpu->memory_rw(cpu, cpu->mem,
92                                      PCCMOS_MC146818_FAKE_ADDR + 1, &b, 1,                                      PCCMOS_MC146818_FAKE_ADDR + 1, &b, 1,
93                                      MEM_READ, PHYSICAL);                                      MEM_READ, PHYSICAL);
94                                  odata = b;                                  odata = b;
# Line 104  int dev_pccmos_access(struct cpu *cpu, s Line 101  int dev_pccmos_access(struct cpu *cpu, s
101                  }                  }
102          }          }
103    
104            if (r == 0)
105                    fatal("[ pccmos: memory_rw() error! ]\n");
106    
107          if (writeflag == MEM_READ)          if (writeflag == MEM_READ)
108                  memory_writemax64(cpu, data, len, odata);                  memory_writemax64(cpu, data, len, odata);
109    
# Line 111  int dev_pccmos_access(struct cpu *cpu, s Line 111  int dev_pccmos_access(struct cpu *cpu, s
111  }  }
112    
113    
114  /*  DEVINIT(pccmos)
  *  devinit_pccmos():  
  */  
 int devinit_pccmos(struct devinit *devinit)  
115  {  {
116          struct pccmos_data *d = malloc(sizeof(struct pccmos_data));          struct pccmos_data *d = malloc(sizeof(struct pccmos_data));
117          int irq_nr, type = MC146818_PC_CMOS, len = DEV_PCCMOS_LENGTH;          int type = MC146818_PC_CMOS, len = DEV_PCCMOS_LENGTH;
118    
119          if (d == NULL) {          if (d == NULL) {
120                  fprintf(stderr, "out of memory\n");                  fprintf(stderr, "out of memory\n");
# Line 125  int devinit_pccmos(struct devinit *devin Line 122  int devinit_pccmos(struct devinit *devin
122          }          }
123          memset(d, 0, sizeof(struct pccmos_data));          memset(d, 0, sizeof(struct pccmos_data));
124    
         /*  
          *  Different machines use different IRQ schemes.  
          */  
125          switch (devinit->machine->machine_type) {          switch (devinit->machine->machine_type) {
126          case MACHINE_CATS:          case MACHINE_CATS:
127                  irq_nr = 32 + 8;          case MACHINE_NETWINDER:
128                  type = MC146818_CATS;                  type = MC146818_CATS;
129                  d->ram[0x48] = 20;              /*  century  */                  d->ram[0x48] = 20;              /*  century  */
130                  len = DEV_PCCMOS_LENGTH * 2;                  len = DEV_PCCMOS_LENGTH * 2;
131                  break;                  break;
132          case MACHINE_X86:          case MACHINE_ALGOR:
133                  irq_nr = 16;    /*  "No" irq  */                  type = MC146818_ALGOR;
134                    break;
135            case MACHINE_ARC:
136                    fatal("\nARC pccmos: TODO\n\n");
137                    type = MC146818_ALGOR;
138                    break;
139            case MACHINE_EVBMIPS:
140                    /*  Malta etc.  */
141                    type = MC146818_ALGOR;
142                    break;
143            case MACHINE_QEMU_MIPS:
144            case MACHINE_COBALT:
145            case MACHINE_BEBOX:
146            case MACHINE_PREP:
147            case MACHINE_MVMEPPC:
148            case MACHINE_SHARK:
149            case MACHINE_IYONIX:
150            case MACHINE_ALPHA:
151                  break;                  break;
152          default:fatal("devinit_pccmos(): unimplemented machine type"          default:fatal("devinit_pccmos(): unimplemented machine type"
153                      " %i\n", devinit->machine->machine_type);                      " %i\n", devinit->machine->machine_type);
# Line 145  int devinit_pccmos(struct devinit *devin Line 156  int devinit_pccmos(struct devinit *devin
156    
157          memory_device_register(devinit->machine->memory, devinit->name,          memory_device_register(devinit->machine->memory, devinit->name,
158              devinit->addr, len, dev_pccmos_access, (void *)d,              devinit->addr, len, dev_pccmos_access, (void *)d,
159              MEM_DEFAULT, NULL);              DM_DEFAULT, NULL);
160    
161          dev_mc146818_init(devinit->machine, devinit->machine->memory,          dev_mc146818_init(devinit->machine, devinit->machine->memory,
162              PCCMOS_MC146818_FAKE_ADDR, irq_nr, type, 1);              PCCMOS_MC146818_FAKE_ADDR, devinit->interrupt_path, type, 1);
163    
164          return 1;          return 1;
165  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.26