100 lines
2.7 KiB
C
100 lines
2.7 KiB
C
// 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 "string/string.h" //string 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/stdfont.h" //Standard font bitmask array
|
|
#include "video/video.h" //video functions
|
|
|
|
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!!
|
|
kio_console_cls();
|
|
video_init();
|
|
mm_init();
|
|
vmm_init();
|
|
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 p = video_getWidth()*video_getHeight()-1;
|
|
for (; p >= 0; p--)
|
|
video_pseti(p, 0x00000075);
|
|
kio_drawConsole();
|
|
}
|
|
|
|
printf("HOS 0.14 - Kernel File Size: %u kb\tData Size: %u bytes\n", kernel_size()>>10, (dword)(&_end)-(dword)(&_code));
|
|
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("%b/%b/%b\t%b:%b:%b\n", rtc_readMonth(), rtc_readDay(), rtc_readYear(), rtc_readHour(), rtc_readMinute(), rtc_readSecond());
|
|
|
|
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))++;
|
|
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;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|