//kernel.c //08/13/03 Josh Holtrop //Holtrop's Operating System //Version: 0.12 //Modified: 11/12/03 #include "k_defines.h" //#DEFINE's for kernel #include "functions.h" //general functions #include "video.h" //video functions #include "mm.h" //physical memory management functions #include "vmm.h" //virtual memory management & paging functions #include "keyboard.h" //generic keyboard driver & functions #include "mouse.h" //generic ps/2 mouse driver & functions #include "fdc.h" //Floppy Disk Controller functions #include "stdfont.h" //Standard font bitmask array #include "kio.h" void isr(dword num); void k_init(); /* These functions are defined in asmfuncs.asm */ extern dword write_cr0(dword cr0); extern dword read_cr0(); extern dword write_cr3(dword cr3); extern dword read_cr3(); extern void writeCursorPosition(dword pos); extern dword getCursorPosition(); extern void console_scroll(); extern void console_cls(); extern int puts(char *str); extern int putDec(int number); extern int putDecu(dword number); #include "kio.c" #include "fdc.c" #include "mouse.c" #include "keyboard.c" #include "mm.c" #include "vmm.c" #include "functions.c" #include "video.c" dword timer = 0; //Main kernel initialization method void k_init() { // ===== Initialization fdc_sendDOR(0x0C); //turn off floppy motor!! console_cls(); video_init(); mm_init(); vmm_init(); remap_pics(0x20, 0x28); init_timer(); mouse_init(); pic1_mask(0); //unmask IRQ's 0-7 pic2_mask(0); //unmask IRQ's 8-15 enable_ints(); kbd_resetLEDs(); //after enabling interrupts!! printf("HOS 0.12 - Kernel Size: %u kb\n", kernel_size()/1024); printf("Memory available to OS: %u MB (Bytes: %u)\n", mm_megabytes, mm_totalmem); printf("Free memory: %u bytes\t %u pages\n", mm_freemem(), mm_freemem()>>12); if (videoMode) { dword p; for (p = 0; p < video_mode.XResolution*video_mode.YResolution; p++) video_psetp(p, 0x00000055); } dword callnum = 0; dword fa = 0; dword la; dword addr; for (;;) { la = addr; addr = (dword)mm_palloc(); if (fa == 0) fa = addr; // printf("addr = 0x%x\tcallnum = %u\tfree pages = %u\n", addr, callnum, mm_freemem()>>12); if (!addr) break; callnum++; } printf("#calls = %u\t", callnum); printf("mm_freemem() = %d (0x%x, %x)\n", mm_freemem(), mm_freemem(), mm_freemem()); callnum = 0; addr = fa; for (;;) { mm_pfree(addr); addr += 4096; callnum++; if (addr > la) break; } printf("#calls = %u\t", callnum); printf("mm_freemem() = %d (0x%x, %x)\n", mm_freemem(), mm_freemem(), mm_freemem()); dword key = 0; for (;;) { key = kbdWaitKey(); if ((key & 0xFF) > 2) //key is not a control key putc(key); } } // main Interrupt Service Routine - handles all interrupts unless caught by kernel.asm void isr(dword num) { switch(num) { case 0x20: // IRQ0 - timer interrupt timer++; (*(byte *)(0xc00b8000))++; eoi(); break; case 0x21: // IRQ1 - keyboard interrupt isr_keyboard(); //isr_keybard() takes care of calling eoi() break; case 0x2C: // IRQ12 - PS/2 mouse isr_mouse(); eoi2(); break; default: printf("Interrupt %d (0x%x) Unhandled!!\n", num, num); break; } }