hos/kernel.c

111 lines
2.6 KiB
C

//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!!
if (videoMode)
{
int p = video_mode.XResolution*video_mode.YResolution-1;
for (; p >= 0; p--)
video_psetp(p, 0x00000044);
video_drawConsole();
}
printf("HOS 0.13 - Kernel Size: %u kb\n", kernel_size()>>10);
printf("Memory available to OS: %u MB (Bytes: %u)\n", mm_megabytes, mm_totalmem);
printf("Free memory: %u bytes (%u pages)\n", mm_freemem(), mm_freemem()>>12);
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;
}
}