144 lines
3.5 KiB
C
144 lines
3.5 KiB
C
//kernel.c
|
|
//08/13/03 Josh Holtrop
|
|
//Holtrop's Operating System
|
|
//Version: 0.12
|
|
//Modified: 12/30/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"
|
|
#include "vfs.h"
|
|
#include "rd.h"
|
|
#include "fat12.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_cr2();
|
|
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);
|
|
extern void strcpy(char *dest, char *src);
|
|
extern void memcpy(void *dest, void *src, dword n);
|
|
extern dword strlen(char *str);
|
|
|
|
#include "fat12.c"
|
|
#include "rd.c"
|
|
#include "vfs.c"
|
|
#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
|
|
vfs_init();
|
|
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, 0x00000077);
|
|
video_drawConsole();
|
|
}
|
|
|
|
printf("HOS 0.13 - 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_megabytes, mm_totalmem);
|
|
printf("Free memory: %u bytes (%u pages)\n", mm_freemem(), mm_freemem()>>12);
|
|
printf("%d/%d/%d\t%d:%d:%d\n", rtc_readMonth(), rtc_readDay(), rtc_readYear(), rtc_readHour(), rtc_readMinute(), rtc_readSecond());
|
|
printf("Root Directory: %s/\n", rootDevice->id);
|
|
|
|
/* int a;
|
|
byte *addr = 0;
|
|
for (a = 0; a < 5; a++)
|
|
{
|
|
byte *app = mm_palloc();
|
|
vmm_map1((dword)addr, (dword)app);
|
|
addr += 4096;
|
|
}
|
|
|
|
addr = vfs_readFile("/bin/hash.hos");
|
|
memcpy(0, addr, 4192);
|
|
asm("call 0");
|
|
free(addr);
|
|
*/
|
|
|
|
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))++;
|
|
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);
|
|
halt();
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|