diff --git a/src/sys/include/ubixos/schedule.h b/src/sys/include/ubixos/schedule.h index 2a1fb8c..a247813 100755 --- a/src/sys/include/ubixos/schedule.h +++ b/src/sys/include/ubixos/schedule.h @@ -8,6 +8,9 @@ #ifndef _SCHEDULE_H #define _SCHEDULE_H +#define TIMER_CONST (3579545L/3) +#define TIMER_FREQ(x) (TIMER_CONST/(x)) + #define numTasks 1024 #define RUNABLE 3 #define ACTIVE 2 @@ -76,5 +79,6 @@ void initScheduler(); int findTask(); +void timerInt(); #endif \ No newline at end of file diff --git a/src/sys/include/vmm/memory.h b/src/sys/include/vmm/memory.h new file mode 100755 index 0000000..1cd6113 --- /dev/null +++ b/src/sys/include/vmm/memory.h @@ -0,0 +1,13 @@ +/************************************************************************************** + Copyright (c) 2002 + The UbixOS Project + + $Id$ +**************************************************************************************/ + +#ifndef _MEMORY_H +#define _MEMORY_H + +int countMemory(); + +#endif \ No newline at end of file diff --git a/src/sys/include/vmm/paging.h b/src/sys/include/vmm/paging.h index 7bb75ae..baead82 100755 --- a/src/sys/include/vmm/paging.h +++ b/src/sys/include/vmm/paging.h @@ -8,6 +8,17 @@ #ifndef _PAGING_H #define _PAGING_H +#define pageLength 0x00000400 +#define pageSize 4096 +#define pagePresent 0x00000001 +#define pageWrite 0x00000002 +#define pageUser 0x00000004 +#define pageDefault (pagePresent|pageWrite|pageUser) + +extern unsigned int *pageDirectory; + void initPaging(); +unsigned int allocPage(); +void pageFault(); #endif \ No newline at end of file diff --git a/src/sys/init/main.c b/src/sys/init/main.c index 06ab5f6..9e06a68 100755 --- a/src/sys/init/main.c +++ b/src/sys/init/main.c @@ -8,10 +8,12 @@ #include #include #include +#include #include #include #include #include +#include int main(); @@ -20,7 +22,7 @@ standardDescriptor(0, 0xFFFFF, (dCode + dRead + dBig + dBiglim)), standardDescriptor(0, 0xFFFFF, (dData + dWrite + dBig + dBiglim)), standardDescriptor(0, 0xFFFFF, (dLdt)), - standardDescriptor(1000, (sizeof(struct tssStruct)-1), (dTss)), + standardDescriptor(100000, (sizeof(struct tssStruct)-1), (dTss)), }; struct { @@ -47,14 +49,28 @@ while(1); } +void test() { + while(1) { + kprint("The"); + } + } + +void test2() { + while(1) { + kprint("Ubu"); + } + } + int main() { + initPaging(); //Initialize Paging System clearScreen(); outputVersion(); //Display Version Info - initPaging(); - init8259(); //Initialize PIC initIdt(); //Initialize IDT initKeyboard(); //Initialize Keyboard initScheduler(); //Initialize Scheduler + execThread(test,0xAFFF,"Test Thread"); + execThread(test2,0xBFFF,"Test Thread2"); + enableIrq(0); return(0); } \ No newline at end of file diff --git a/src/sys/kernel/exec.c b/src/sys/kernel/exec.c index 08427e3..59ec830 100755 --- a/src/sys/kernel/exec.c +++ b/src/sys/kernel/exec.c @@ -7,6 +7,7 @@ #include #include +#include void execThread(void (* tproc)(void),int stack,char *descr) { int pid = 0; @@ -18,7 +19,7 @@ taskList[pid].tss.ss1 = 0x10; taskList[pid].tss.esp2 = 0x0; taskList[pid].tss.ss2 = 0x10; -// taskList[pid].tss.cr3 = (unsigned int)pageDir; + taskList[pid].tss.cr3 = (unsigned int)pageDirectory; taskList[pid].tss.eip = (unsigned int)tproc; taskList[pid].tss.eflags = 0x206; taskList[pid].tss.esp = stack; diff --git a/src/sys/kernel/idt.c b/src/sys/kernel/idt.c index 952110a..c595435 100755 --- a/src/sys/kernel/idt.c +++ b/src/sys/kernel/idt.c @@ -24,6 +24,7 @@ for (i=0;i<256;i++) { setVector(intNull, i, dPresent + dInt + dDpl3); } + asm ( "lidt (%0) \n" /* Load the IDT */ "pushfl \n" /* Clear the NT flag */ diff --git a/src/sys/kernel/schedule.c b/src/sys/kernel/schedule.c index 0fddef5..a097284 100755 --- a/src/sys/kernel/schedule.c +++ b/src/sys/kernel/schedule.c @@ -4,21 +4,30 @@ $Id$ **************************************************************************************/ + #include +#include +#include +#include +#include +#include int currentProc; struct taskStruct taskList[numTasks]; struct taskStruct *_current,*_usedMath = 0x0; +extern union descriptorTableunion GDT[7]; + /* Initialize Scheduler */ void initScheduler(void) { - int i; + int i,freq; for (i=0;i= numTasks) { i = -1; } + } + if (proc != -1) { + currentProc = proc; + _current = &taskList[proc]; + taskList[proc].status = ACTIVE; + memAddr = (unsigned int)&taskList[proc].tss; + GDT[4].descriptor.access = 0x89; + GDT[4].descriptor.baseLow = (memAddr & 0xFFFF); + GDT[4].descriptor.baseMed = ((memAddr >> 16) & 0xff); + GDT[4].descriptor.baseHigh = (memAddr >> 24); + asm("ljmp $0x20,$0\n"); + } + } + + +/* Timer Interupt */ +asm ( + ".globl timerInt \n" + "timerInt: \n" + " pusha \n" + " call schedule \n" + " popa \n" + " iret \n" + ); \ No newline at end of file diff --git a/src/sys/kernel/version.c b/src/sys/kernel/version.c index f9ff31c..3e03880 100755 --- a/src/sys/kernel/version.c +++ b/src/sys/kernel/version.c @@ -26,5 +26,5 @@ // 0x0E - Yellow // 0x0F - White kprintf("%zUbixOS v%s\n",0xF1,ubixosVersion); - kprintf("%zCopyright (c) 2002 - The UbixOS Project\n",0xFB); + kprintf("%zCopyright (c) 2002 - The UbixOS Project\n\n",0xFB); } diff --git a/src/sys/vmm/Makefile b/src/sys/vmm/Makefile index f2635ce..2823afa 100755 --- a/src/sys/vmm/Makefile +++ b/src/sys/vmm/Makefile @@ -14,7 +14,7 @@ REMOVE = rm -fr # Objects -OBJS = paging.o +OBJS = memory.o paging.o all: $(OBJS) diff --git a/src/sys/vmm/memory.c b/src/sys/vmm/memory.c new file mode 100755 index 0000000..30c9b4a --- /dev/null +++ b/src/sys/vmm/memory.c @@ -0,0 +1,74 @@ +/************************************************************************************** + Copyright (c) 2002 + The UbixOS Project + + $Id$ +**************************************************************************************/ + +#include +#include + +int countMemory() { + register unsigned long *mem; + unsigned long memCount=-1, tempMemory; + unsigned short memKb=0; + unsigned char irq1State, irq2State; + unsigned long cr0; + + /* Save States Of IRQ 1 & 2 */ + irq1State=inportByte(0x21); + irq2State=inportByte(0xA1); + + /* Shut Off Both IRQS */ + outportByte(0x21, 0xFF); + outportByte(0xA1, 0xFF); + + /* Save CR0 */ + asm( + "movl %%cr0, %%ebx\n" + : "=a"(cr0) + : + : "ebx" + ); + + asm("wbinvd"); + asm( + "movl %%ebx, %%cr0\n" + : + : "a" (cr0 | 0x00000001 | 0x40000000 | 0x20000000) + : "ebx" + ); + + while(memKb<4096 && memCount!=0) { + memKb++; + if (memCount == -1) memCount = 0; + memCount+=1024*1024; + mem=(unsigned long *)memCount; + tempMemory=*mem; + *mem=0x55AA55AA; + asm("":::"memory"); + if (*mem!=0x55AA55AA) { + memCount=0; + } + else { + *mem=0xAA55AA55; + asm("":::"memory"); + if (*mem!=0xAA55AA55) { + memCount=0; + } + } + asm("":::"memory"); + *mem=tempMemory; + } + asm( + "movl %%ebx, %%cr0\n" + : + : "a" (cr0) + : "ebx" + ); + + /* Return IRQ 1 & 2's States */ + outportByte(0x21, irq1State); + outportByte(0xA1, irq2State); + return(memKb<<20); + } \ No newline at end of file diff --git a/src/sys/vmm/paging.c b/src/sys/vmm/paging.c index 5818ece..f6a4b16 100755 --- a/src/sys/vmm/paging.c +++ b/src/sys/vmm/paging.c @@ -5,5 +5,51 @@ $Id$ **************************************************************************************/ +#include + +unsigned int *pageDirectory = 0x0; +int memoryStart = 0x100000; + void initPaging() { + int i = 0; + unsigned int *pageTable; + int freePage = 0x0; + + pageDirectory = (unsigned int*)allocPage(); + for (i=0;i