diff --git a/src/sys/include/sys/8259.h b/src/sys/include/sys/8259.h new file mode 100644 index 0000000..c907a7e --- /dev/null +++ b/src/sys/include/sys/8259.h @@ -0,0 +1,57 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _8259_H +#define _8259_H + +#include + +#define mPic 0x20 // I/O for master PIC +#define mImr 0x21 // I/O for master IMR +#define sPic 0xA0 // I/O for slave PIC +#define sImr 0xA1 // I/O for slace IMR +#define eoi 0x20 // EOI command +#define icw1 0x11 // Cascade, Edge triggered +#define icw4 0x01 // 8088 mode +#define mVec 0x68 // Vector for master +#define sVec 0x70 // Vector for slave +#define ocw3Irr 0x0A // Read IRR +#define ocw3Isr 0x0B // Read ISR + +int i8259_init(); +void irqEnable(uInt16 irqNo); +void irqDisable(uInt16 irqNo); + +#endif + +/*** + $Log$ + END + ***/ + diff --git a/src/sys/include/ubixos/init.h b/src/sys/include/ubixos/init.h index b71f14c..a3f02ca 100644 --- a/src/sys/include/ubixos/init.h +++ b/src/sys/include/ubixos/init.h @@ -30,6 +30,7 @@ #ifndef _INIT_H #define _INIT_H +#include #include #include @@ -39,6 +40,7 @@ intFunctionPTR init_tasks[] = { static_constructors, + i8259_init, idt_init, vmm_init, }; diff --git a/src/sys/init/main.c b/src/sys/init/main.c index 357f43a..42d4860 100644 --- a/src/sys/init/main.c +++ b/src/sys/init/main.c @@ -87,10 +87,7 @@ kprintf("Error: Initializing System.\n"); } } - - kprintf("NO"); - //test = vmm_findFreePage(1); - kprintf("[0x%X][0x%X]\n",test,test[0]); + while (1) asm("hlt"); return(0x0); diff --git a/src/sys/sys/8259.c b/src/sys/sys/8259.c new file mode 100644 index 0000000..baaeae0 --- /dev/null +++ b/src/sys/sys/8259.c @@ -0,0 +1,106 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include + +static unsigned int irqMask = 0xFFFF; + +/************************************************************************ + + Function: int 8259_init() + + Description: This function will initialize both PICs for all of our IRQs + + Notes: + +************************************************************************/ +int i8259_init() { + outportByte(mPic, icw1); /* Initialize Master PIC */ + outportByte(sPic, icw1); /* Initialize Seconary PIC */ + outportByte(mPic+1, mVec); /* Master Interrup Vector */ + outportByte(sPic+1, sVec); /* Secondary Interrupt Vector */ + outportByte(mPic+1, 1<<2); /* Bitmask for cascade on IRQ 2 */ + outportByte(sPic+1, 2); /* Cascade on IRQ 2 */ + outportByte(mPic+1, icw4); /* Finish Primary Initialization */ + outportByte(sPic+1, icw4); /* Finish Seconary Initialization */ + outportByte(mImr, 0xff); /* Mask All Primary Interrupts */ + outportByte(sImr, 0xff); /* Mask All Seconary Interrupts */ + + /* Print out the system info for this */ + kprintf("pic0 - Port: [0x%X]\n",mPic); + kprintf("pic1 - Port: [0x%X]\n",sPic); + + /* Return so the system knows it went well */ + return(0x0); + } + +/************************************************************************ + + Function: int irqEnable() + + Description: This function is used to turn on an IRQ + + Notes: + +************************************************************************/ +void irqEnable(uInt16 irqNo) { + irqMask &= ~(1 << irqNo); + if (irqNo >= 8) { + irqMask &= ~(1 << 2); + } + outportByte(mPic+1, irqMask & 0xFF); + outportByte(sPic+1, (irqMask >> 8) & 0xFF); + } + +/************************************************************************ + + Function: int irqDisable() + + Description: This function is used to turn off an IRQ + + Notes: + +************************************************************************/ +void irqDisable(uInt16 irqNo) { + irqMask |= (1 << irqNo); + if ((irqMask & 0xFF00)==0xFF00) { + irqMask |= (1 << 2); + } + outportByte(mPic+1, irqMask & 0xFF); + outportByte(sPic+1, (irqMask >> 8) & 0xFF); + } + +/*** + $Log$ + END + ***/ + diff --git a/src/sys/sys/Makefile b/src/sys/sys/Makefile index 37d6099..6b90259 100644 --- a/src/sys/sys/Makefile +++ b/src/sys/sys/Makefile @@ -7,7 +7,7 @@ include ../Makefile.inc # Objects -OBJS = idt.o spinlock.o display.o io.o +OBJS = 8259.o idt.o spinlock.o display.o io.o all: $(OBJS) diff --git a/src/sys/sys/idt.c b/src/sys/sys/idt.c index d52c13a..5fd2ca2 100644 --- a/src/sys/sys/idt.c +++ b/src/sys/sys/idt.c @@ -34,6 +34,26 @@ #define FP_TO_LINEAR(seg, off) ((void*) ((((uInt16) (seg)) << 4) + ((uInt16) (off)))) static void intNull(); +static void int_00(); +static void int_01(); +static void int_02(); +static void int_03(); +static void int_04(); +static void int_05(); +static void int_06(); +static void int_07(); +static void int_08(); +static void int_09(); +static void int_10(); +static void int_11(); +static void int_12(); +static void int_13(); +static void int_14(); +static void int_15(); +static void int_16(); +static void int_17(); +static void int_18(); +static void int_19(); static ubixDescriptorTable(ubixIDT, 256) { }; @@ -73,6 +93,27 @@ : "r" ((char *)&loadidt) ); + setVector(int_00, 0x00, dPresent + dInt + dDpl3); + setVector(int_01, 0x01, dPresent + dInt + dDpl3); + setVector(int_02, 0x02, dPresent + dInt + dDpl3); + setVector(int_03, 0x03, dPresent + dInt + dDpl3); + setVector(int_04, 0x04, dPresent + dInt + dDpl3); + setVector(int_05, 0x05, dPresent + dInt + dDpl3); + setVector(int_06, 0x06, dPresent + dInt + dDpl3); + setVector(int_07, 0x07, dPresent + dInt + dDpl3); + setVector(int_08, 0x08, dPresent + dInt + dDpl3); + setVector(int_09, 0x09, dPresent + dInt + dDpl3); + setVector(int_10, 0x0A, dPresent + dInt + dDpl3); + setVector(int_11, 0x0B, dPresent + dInt + dDpl3); + setVector(int_12, 0x0C, dPresent + dInt + dDpl3); + setVector(int_13, 0x0D, dPresent + dInt + dDpl3); + setVector(int_14, 0x0E, dPresent + dInt + dDpl3); + setVector(int_15, 0x0F, dPresent + dInt + dDpl3); + setVector(int_16, 0x10, dPresent + dInt + dDpl3); + setVector(int_17, 0x11, dPresent + dInt + dDpl3); + setVector(int_18, 0x12, dPresent + dInt + dDpl3); + setVector(int_19, 0x13, dPresent + dInt + dDpl3); + /* Print out information for the IDT */ kprintf("idt0 - Address: [0x%X]\n", &ubixIDT); @@ -115,8 +156,124 @@ /* Null Intterupt Descriptor */ static void intNull() { kprintf("Invalid Interrupt\n"); - while (1); } + +static void int_00() { + kprintf("Divide Error\n"); + while (1) + asm("hlt"); + } + +static void int_01() { + kprintf("Debug\n"); + while (1) + asm("hlt"); + } + +static void int_02() { + kprintf("INT 02\n"); + while (1) + asm("hlt"); + } + +static void int_03() { + kprintf("Breakpoint\n"); + while (1) + asm("hlt"); + } + +static void int_04() { + kprintf("Overflow\n"); + while (1) + asm("hlt"); + } + +static void int_05() { + kprintf("Bound Range Exceeded\n"); + while (1) + asm("hlt"); + } +static void int_06() { + kprintf("Undefined Opcode\n"); + while (1) + asm("hlt"); + } +static void int_07() { + kprintf("Device Not Available\n"); + while (1) + asm("hlt"); + } +static void int_08() { + kprintf("Double Fault\n"); + while (1) + asm("hlt"); + } + +static void int_09() { + kprintf("INT 09\n"); + while (1) + asm("hlt"); + } + +static void int_10() { + kprintf("Invalid TSS\n"); + while (1) + asm("hlt"); + } + +static void int_11() { + kprintf("Not Present\n"); + while (1) + asm("hlt"); + } + +static void int_12() { + kprintf("Stack Segment Fault\n"); + while (1) + asm("hlt"); + } + +static void int_13() { + kprintf("General Protection Fault\n"); + while (1) + asm("hlt"); + } + +static void int_14() { + kprintf("Page Fault\n"); + while (1) + asm("hlt"); + } + +static void int_15() { + kprintf("INT 15\n"); + while (1) + asm("hlt"); + } + +static void int_16() { + kprintf("FPU Math Fault\n"); + while (1) + asm("hlt"); + } + +static void int_17() { + kprintf("Alignment Check\n"); + while (1) + asm("hlt"); + } + +static void int_18() { + kprintf("Machine Fault\n"); + while (1) + asm("hlt"); + } + +static void int_19() { + kprintf("SIMD Math Fault\n"); + while (1) + asm("hlt"); + } /*** END diff --git a/src/sys/vmm/memory.c b/src/sys/vmm/memory.c index ddc01c5..3471ec6 100644 --- a/src/sys/vmm/memory.c +++ b/src/sys/vmm/memory.c @@ -65,14 +65,11 @@ freePages = 0x0; vmm_numPages = 0x0; - kprintf("NO"); /* Count System Memory */ vmm_numPages = vmm_countMemory(); - kprintf("MO"); /* Set Memory Map To Point To First Physical Page That We Will Use */ vmm_memoryMap = (mMap *) 0x100000; - kprintf("FO"); /* Initialize Map Make All Pages Not Available */ for (i = 0x0; i < vmm_numPages; i++) { @@ -82,17 +79,14 @@ vmm_memoryMap[i].pageAddr = i * 0x1000; } - kprintf("HO"); /* Calculate Start Of Free Memory */ memStart = (0x100000 / 0x1000); memStart += (((sizeof(mMap) * vmm_numPages) + (sizeof(mMap) - 1)) / 0x1000); - kprintf("JO"); for (i = memStart; i < vmm_numPages; i++) { vmm_memoryMap[i].status = VMM_MEMAVAIL; freePages++; } - kprintf("SO"); /* Print Out Amount Of Memory */ kprintf("Real Memory: %iKB\n", vmm_numPages * 4);