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
|
00001 // Intel 8250 serial port (UART). 00002 00003 #include "types.h" 00004 #include "defs.h" 00005 #include "param.h" 00006 #include "traps.h" 00007 #include "spinlock.h" 00008 #include "fs.h" 00009 #include "file.h" 00010 #include "mmu.h" 00011 #include "proc.h" 00012 #include "x86.h" 00013 00014 #define COM1 0x3f8 00015 00016 static int uart; // is there a uart? 00017 00018 void 00019 uartinit(void) 00020 { 00021 char *p; 00022 00023 // Turn off the FIFO 00024 outb(COM1+2, 0); 00025 00026 // 9600 baud, 8 data bits, 1 stop bit, parity off. 00027 outb(COM1+3, 0x80); // Unlock divisor 00028 outb(COM1+0, 115200/9600); 00029 outb(COM1+1, 0); 00030 outb(COM1+3, 0x03); // Lock divisor, 8 data bits. 00031 outb(COM1+4, 0); 00032 outb(COM1+1, 0x01); // Enable receive interrupts. 00033 00034 // If status is 0xFF, no serial port. 00035 if(inb(COM1+5) == 0xFF) 00036 return; 00037 uart = 1; 00038 00039 // Acknowledge pre-existing interrupt conditions; 00040 // enable interrupts. 00041 inb(COM1+2); 00042 inb(COM1+0); 00043 picenable(IRQ_COM1); 00044 ioapicenable(IRQ_COM1, 0); 00045 00046 // Announce that we're here. 00047 for(p="xv6...\n"; *p; p++) 00048 uartputc(*p); 00049 } 00050 00051 void 00052 uartputc(int c) 00053 { 00054 int i; 00055 00056 if(!uart) 00057 return; 00058 for(i = 0; i < 128 && !(inb(COM1+5) & 0x20); i++) 00059 microdelay(10); 00060 outb(COM1+0, c); 00061 } 00062 00063 static int 00064 uartgetc(void) 00065 { 00066 if(!uart) 00067 return -1; 00068 if(!(inb(COM1+5) & 0x01)) 00069 return -1; 00070 return inb(COM1+0); 00071 } 00072 00073 void 00074 uartintr(void) 00075 { 00076 consoleintr(uartgetc); 00077 }