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

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

revision 6 by dpavlin, Mon Oct 8 16:18:11 2007 UTC revision 18 by dpavlin, Mon Oct 8 16:19:11 2007 UTC
# Line 25  Line 25 
25   *  SUCH DAMAGE.   *  SUCH DAMAGE.
26   *     *  
27   *   *
28   *  $Id: dev_8259.c,v 1.9 2005/06/02 17:11:35 debug Exp $   *  $Id: dev_8259.c,v 1.15 2005/10/26 14:37:03 debug Exp $
29   *     *  
30   *  8259 Programmable Interrupt Controller.   *  8259 Programmable Interrupt Controller.
31   *   *
32   *  This is mostly bogus. TODO. See the following URL for more details:   *  See the following URL for more details:
33   *      http://www.nondot.org/sabre/os/files/MiscHW/8259pic.txt   *      http://www.nondot.org/sabre/os/files/MiscHW/8259pic.txt
34   */   */
35    
# Line 48  Line 48 
48    
49  #define DEV_8259_LENGTH         2  #define DEV_8259_LENGTH         2
50    
51    /*  #define DEV_8259_DEBUG  */
52    
53    
54  /*  /*
55   *  dev_8259_access():   *  dev_8259_access():
# Line 58  int dev_8259_access(struct cpu *cpu, str Line 60  int dev_8259_access(struct cpu *cpu, str
60  {  {
61          struct pic8259_data *d = (struct pic8259_data *) extra;          struct pic8259_data *d = (struct pic8259_data *) extra;
62          uint64_t idata = 0, odata = 0;          uint64_t idata = 0, odata = 0;
63            int i;
64    
65            if (writeflag == MEM_WRITE)
66                    idata = memory_readmax64(cpu, data, len);
67    
68          idata = memory_readmax64(cpu, data, len);  #ifdef DEV_8259_DEBUG
69            if (writeflag == MEM_READ)
70                    fatal("[ 8259: read from 0x%x ]\n", (int)relative_addr);
71            else
72                    fatal("[ 8259: write to 0x%x: 0x%x ]\n",
73                        (int)relative_addr, (int)idata);
74    #endif
75    
76          switch (relative_addr) {          switch (relative_addr) {
77          case 0x00:          case 0x00:
# Line 73  int dev_8259_access(struct cpu *cpu, str Line 85  int dev_8259_access(struct cpu *cpu, str
85                                          fatal("[ 8259: WARNING: Bit 2 set ]\n");                                          fatal("[ 8259: WARNING: Bit 2 set ]\n");
86                                  /*  Bit 1: 0=cascade, 1=single  */                                  /*  Bit 1: 0=cascade, 1=single  */
87                                  /*  Bit 0: 1=4th init byte  */                                  /*  Bit 0: 1=4th init byte  */
88                                  if (!(idata & 0x01))                                  /*  This happens on non-x86 systems:
89                                        if (!(idata & 0x01))
90                                          fatal("[ 8259: WARNING: Bit 0 NOT set!"                                          fatal("[ 8259: WARNING: Bit 0 NOT set!"
91                                              "!! ]\n");                                              "!! ]\n");  */
92                                  d->init_state = 1;                                  d->init_state = 1;
93                                  break;                                  break;
94                          }                          }
# Line 94  int dev_8259_access(struct cpu *cpu, str Line 107  int dev_8259_access(struct cpu *cpu, str
107                          case 0x0b:                          case 0x0b:
108                                  d->current_command = 0x0b;                                  d->current_command = 0x0b;
109                                  break;                                  break;
110                            case 0x0c:
111                                    /*  Put Master in Buffered Mode  */
112                                    d->current_command = 0x0c;
113                                    break;
114                          case 0x20:      /*  End Of Interrupt  */                          case 0x20:      /*  End Of Interrupt  */
115                                    /*
116                                     *  TODO: in buffered mode, is this an EOI 0?
117                                     */
118                                  d->irr &= ~d->isr;                                  d->irr &= ~d->isr;
119                                  d->isr = 0;                                  d->isr = 0;
120                                  /*  Recalculate interrupt assertions:  */                                  /*  Recalculate interrupt assertions:  */
121                                  cpu_interrupt(cpu, 16);                                  cpu_interrupt(cpu, d->irq_nr);
122                                  break;                                  break;
123                            case 0x21:      /*  Specific EOI  */
124                            case 0x22:
125                            case 0x23:
126                            case 0x24:
127                            case 0x25:
128                            case 0x26:
129                            case 0x27:
130                          case 0x60:                          case 0x60:
131                          case 0x61:                          case 0x61:
132                          case 0x62:                          case 0x62:
# Line 111  int dev_8259_access(struct cpu *cpu, str Line 138  int dev_8259_access(struct cpu *cpu, str
138                                  d->irr &= ~(1 << (idata & 7));                                  d->irr &= ~(1 << (idata & 7));
139                                  d->isr &= ~(1 << (idata & 7));                                  d->isr &= ~(1 << (idata & 7));
140                                  /*  Recalculate interrupt assertions:  */                                  /*  Recalculate interrupt assertions:  */
141                                  cpu_interrupt(cpu, 16);                                  cpu_interrupt(cpu, d->irq_nr);
142                                  break;                                  break;
143                          case 0x68:      /*  Set Special Mask Mode  */                          case 0x68:      /*  Set Special Mask Mode  */
144                                  /*  TODO  */                                  /*  TODO  */
# Line 139  int dev_8259_access(struct cpu *cpu, str Line 166  int dev_8259_access(struct cpu *cpu, str
166                          case 0x0b:                          case 0x0b:
167                                  odata = d->isr;                                  odata = d->isr;
168                                  break;                                  break;
169                            case 0x0c:
170                                    /*  Buffered mode.  */
171                          default:                          default:
172                                  fatal("[ 8259: unimplemented command 0x%02x"                                  odata = 0x00;
173                                      " while reading ]\n", d->current_command);                                  for (i=0; i<8; i++)
174                                  cpu->running = 0;                                          if ((d->irr >> i) & 1) {
175                                                    odata = 0x80 | i;
176                                                    break;
177                                            }
178                                    break;
179                            /*
180                             *  TODO: The "default" label should really do
181                             *  something like this:
182                             *
183                             *      fatal("[ 8259: unimplemented command 0x%02x"
184                             *          " while reading ]\n", d->current_command);
185                             *      cpu->running = 0;
186                             *
187                             *  but Linux seems to read from the secondary PIC
188                             *  in a manner which works better the way things
189                             *  are coded right now.
190                             */
191                          }                          }
192                  }                  }
193                  break;                  break;
# Line 150  int dev_8259_access(struct cpu *cpu, str Line 195  int dev_8259_access(struct cpu *cpu, str
195                  if (d->init_state > 0) {                  if (d->init_state > 0) {
196                          if (d->init_state == 1) {                          if (d->init_state == 1) {
197                                  d->irq_base = idata & 0xf8;                                  d->irq_base = idata & 0xf8;
198                                  if (idata & 7)                                  /*  This happens on non-x86 machines:
199                                        if (idata & 7)
200                                          fatal("[ 8259: WARNING! Lowest"                                          fatal("[ 8259: WARNING! Lowest"
201                                              " bits in Init Cmd 1 are"                                              " bits in Init Cmd 1 are"
202                                              " non-zero! ]\n");                                              " non-zero! ]\n");  */
203                                  d->init_state = 2;                                  d->init_state = 2;
204                          } else if (d->init_state == 2) {                          } else if (d->init_state == 2) {
205                                  /*  Slave attachment. TODO  */                                  /*  Slave attachment. TODO  */
# Line 174  int dev_8259_access(struct cpu *cpu, str Line 220  int dev_8259_access(struct cpu *cpu, str
220                  if (writeflag == MEM_WRITE) {                  if (writeflag == MEM_WRITE) {
221                          d->ier = idata;                          d->ier = idata;
222                          /*  Recalculate interrupt assertions:  */                          /*  Recalculate interrupt assertions:  */
223                          cpu_interrupt(cpu, 16);                          cpu_interrupt(cpu, d->irq_nr);
224                  } else {                  } else {
225                          odata = d->ier;                          odata = d->ier;
226                  }                  }
# Line 200  int dev_8259_access(struct cpu *cpu, str Line 246  int dev_8259_access(struct cpu *cpu, str
246    
247  /*  /*
248   *  devinit_8259():   *  devinit_8259():
249     *
250     *  Initialize an 8259 PIC. Important notes:
251     *
252     *      x)  Most systems use _TWO_ 8259 PICs. These should be registered
253     *          as separate devices.
254     *
255     *      x)  The irq number specified is the number used to re-calculate
256     *          CPU interrupt assertions.  It is _not_ the irq number at
257     *          which the PIC is connected. (That is left to machine specific
258     *          code in src/machine.c.)
259   */   */
260  int devinit_8259(struct devinit *devinit)  int devinit_8259(struct devinit *devinit)
261  {  {
262          struct pic8259_data *d = malloc(sizeof(struct pic8259_data));          struct pic8259_data *d = malloc(sizeof(struct pic8259_data));
263          char *name2;          char *name2;
264          int nlen = 40;          size_t nlen = strlen(devinit->name) + 20;
265    
266          if (d == NULL) {          if (d == NULL) {
267                  fprintf(stderr, "out of memory\n");                  fprintf(stderr, "out of memory\n");
# Line 216  int devinit_8259(struct devinit *devinit Line 272  int devinit_8259(struct devinit *devinit
272    
273          name2 = malloc(nlen);          name2 = malloc(nlen);
274          snprintf(name2, nlen, "%s", devinit->name);          snprintf(name2, nlen, "%s", devinit->name);
275          if ((devinit->addr & 0xfff) == 0xa0)          if ((devinit->addr & 0xfff) == 0xa0) {
276                  strcat(name2, " [secondary]");                  strlcat(name2, " [secondary]", nlen);
277                    d->irq_base = 8;
278            }
279    
280          memory_device_register(devinit->machine->memory, name2,          memory_device_register(devinit->machine->memory, name2,
281              devinit->addr, DEV_8259_LENGTH, dev_8259_access, (void *)d,              devinit->addr, DEV_8259_LENGTH, dev_8259_access, d,
282              MEM_DEFAULT, NULL);              MEM_DEFAULT, NULL);
283    
284          devinit->return_ptr = d;          devinit->return_ptr = d;

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

  ViewVC Help
Powered by ViewVC 1.1.26