Xv6 with picoc & Linkage editor  v1.0
The project delineate mutual cohesion between c library, linkage editor ( linker), interpreter and operating system by porting the same on xv6 kernel
picirq.c
00001 // Intel 8259A programmable interrupt controllers.
00002 
00003 #include "types.h"
00004 #include "x86.h"
00005 #include "traps.h"
00006 
00007 // I/O Addresses of the two programmable interrupt controllers
00008 #define IO_PIC1         0x20    // Master (IRQs 0-7)
00009 #define IO_PIC2         0xA0    // Slave (IRQs 8-15)
00010 
00011 #define IRQ_SLAVE       2       // IRQ at which slave connects to master
00012 
00013 // Current IRQ mask.
00014 // Initial IRQ mask has interrupt 2 enabled (for slave 8259A).
00015 static ushort irqmask = 0xFFFF & ~(1<<IRQ_SLAVE);
00016 
00017 static void
00018 picsetmask(ushort mask)
00019 {
00020   irqmask = mask;
00021   outb(IO_PIC1+1, mask);
00022   outb(IO_PIC2+1, mask >> 8);
00023 }
00024 
00025 void
00026 picenable(int irq)
00027 {
00028   picsetmask(irqmask & ~(1<<irq));
00029 }
00030 
00031 // Initialize the 8259A interrupt controllers.
00032 void
00033 picinit(void)
00034 {
00035   // mask all interrupts
00036   outb(IO_PIC1+1, 0xFF);
00037   outb(IO_PIC2+1, 0xFF);
00038 
00039   // Set up master (8259A-1)
00040 
00041   // ICW1:  0001g0hi
00042   //    g:  0 = edge triggering, 1 = level triggering
00043   //    h:  0 = cascaded PICs, 1 = master only
00044   //    i:  0 = no ICW4, 1 = ICW4 required
00045   outb(IO_PIC1, 0x11);
00046 
00047   // ICW2:  Vector offset
00048   outb(IO_PIC1+1, T_IRQ0);
00049 
00050   // ICW3:  (master PIC) bit mask of IR lines connected to slaves
00051   //        (slave PIC) 3-bit # of slave's connection to master
00052   outb(IO_PIC1+1, 1<<IRQ_SLAVE);
00053 
00054   // ICW4:  000nbmap
00055   //    n:  1 = special fully nested mode
00056   //    b:  1 = buffered mode
00057   //    m:  0 = slave PIC, 1 = master PIC
00058   //      (ignored when b is 0, as the master/slave role
00059   //      can be hardwired).
00060   //    a:  1 = Automatic EOI mode
00061   //    p:  0 = MCS-80/85 mode, 1 = intel x86 mode
00062   outb(IO_PIC1+1, 0x3);
00063 
00064   // Set up slave (8259A-2)
00065   outb(IO_PIC2, 0x11);                  // ICW1
00066   outb(IO_PIC2+1, T_IRQ0 + 8);      // ICW2
00067   outb(IO_PIC2+1, IRQ_SLAVE);           // ICW3
00068   // NB Automatic EOI mode doesn't tend to work on the slave.
00069   // Linux source code says it's "to be investigated".
00070   outb(IO_PIC2+1, 0x3);                 // ICW4
00071 
00072   // OCW3:  0ef01prs
00073   //   ef:  0x = NOP, 10 = clear specific mask, 11 = set specific mask
00074   //    p:  0 = no polling, 1 = polling mode
00075   //   rs:  0x = NOP, 10 = read IRR, 11 = read ISR
00076   outb(IO_PIC1, 0x68);             // clear specific mask
00077   outb(IO_PIC1, 0x0a);             // read IRR by default
00078 
00079   outb(IO_PIC2, 0x68);             // OCW3
00080   outb(IO_PIC2, 0x0a);             // OCW3
00081 
00082   if(irqmask != 0xFFFF)
00083     picsetmask(irqmask);
00084 }
 All Data Structures