// kernel.c // Author: Josh Holtrop // Date: 08/13/03 // Holtrop's Operating System - Version 0.13 // Modified: 03/08/04 #include "hos_defines.h" //#DEFINE's for kernel #include "functions.h" //general functions #include "asmfuncs.h" //assembly functions #include "kio.h" //kernel input/output functions #include "mm/mm.h" //physical memory management functions #include "mm/vmm.h" //virtual memory management & paging functions #include "char/keyboard.h" //generic keyboard driver & functions #include "char/mouse.h" //generic ps/2 mouse driver & functions #include "block/fdc.h" //Floppy Disk Controller functions #include "sys/cmos.h" //CMOS interface functions #include "sys/io.h" //port i/o functions #include "sys/pic.h" //Programmable Interrupt Controller functions #include "sys/rtc.h" //Real Time Clock functions #include "video/video.h" //video functions #include "fs/vfs.h" extern "C" { void isr(dword num); void k_init(); dword timer = 0; //Main kernel initialization method void k_init() { // ===== Initialization fdc_sendDOR(0x0C); //turn off floppy motor!! mm_init(); vmm_init(); video_init(); kio_init(); kio_console_cls(); pic_remap(0x20, 0x28); timer_init(); mouse_init(); pic_mask1(0); //unmask IRQ's 0-7 pic_mask2(0); //unmask IRQ's 8-15 enable_ints(); kbd_resetLEDs(); //after enabling interrupts!! if (video_Mode()) { int w = video_getWidth(), h = video_getHeight(); int p = w * h - 1; for (; p >= 0; p--) video_pseti(p, 0x00000075); int x = w >> 1, y = h >> 1, sz = h >> 1; for (p = 0; p <= sz; p += 24) { video_line(x + p, y, x, y + sz - p, 0x0000FF00); video_line(x + p, y, x, y - sz + p, 0x0000FF00); video_line(x - p, y, x, y + sz - p, 0x0000FF00); video_line(x - p, y, x, y - sz + p, 0x0000FF00); } kio_drawConsole(); } printf("HOS 0.14 - Kernel File Size: %uKb Mem Used: %uKb\n", kernel_size()>>10, kernel_size_used()>>10); printf("Memory available to OS: %u MB (%u bytes)\n", mm_getTotalMegs(), mm_getTotalMem()); printf("Free memory: %u bytes (%u pages)\n", mm_freemem(), mm_freemem()>>12); printf("Built on %s at %s\n", __DATE__, __TIME__); printf("%b/%b/%b %b:%b:%b\n", rtc_readMonth(), rtc_readDay(), rtc_readYear(), rtc_readHour(), rtc_readMinute(), rtc_readSecond()); vfs_init(); 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 14: printf("Page fault, CR2 = 0x%x\n", read_cr2()); halt(); break; case 0x20: // IRQ0 - timer interrupt timer++; (*(byte *)(0xc00b8000))++; if (!(timer % 100)) { dword curPos = kio_getCursorPosition(); kio_writeCursorPosition(72); printf("%b:%b:%b\n", rtc_readHour(), rtc_readMinute(), rtc_readSecond()); kio_writeCursorPosition(curPos); } pic_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(); pic_eoi2(); break; default: printf("Interrupt %d (0x%x) Unhandled!!\n", num, num); halt(); break; } } }