//
// http://www.jamesmolloy.co.uk/tutorial_html/9.-Multitasking.html
//
#include "kernel.h" // general kernel config & includes
#include "console.h" // this will allow us to write to screen
#include "x86.h"
#include "../lib/logger/log.h" // logger facilities
#define FOOLOS_MODULE_NAME "kernel"
// TODO: cleanup . WHHYY can i compile it without the includes!??
///////
// interrupt handler prototypes
// todo: move somewhere else!?
void int_def_handler();
void int_clock_handler();
void int_kb_handler();
void int_floppy_handler();
////////// KERNEL MAIN///// /////
//
uint32_t read_eip();
// just a test handler for software interrupt 88, todo: remove and
// implement some syscalls!
//
void int_test_handler_worker()
{
// this can not be called directly from interrupt handler
// due to optional parameters (...) probably!
panic(FOOLOS_MODULE_NAME,"unhandled EXCEPTION!");
}
void int_test_handler()
{
X86_IRQ_BEGIN
int_test_handler_worker();
sleep(30);
while(1); // hang!
X86_IRQ_END
}
// heart of our operating system.
void kernel_main(uint32_t initial_stack)
{
//
// We want to get output to the screen as fast as possible!
//
// Our Fool-Boot-Loader did set up VESA already for us.
// The desired VESA mode is hardcoded in [boot/mbr.asm].
//
// The [vesa_init(...)] function requires:
//
// * the addresses of the vbeinfo struct
// * the address of the vbemodeinfo struct (for selected mode).
// * the address of our Fool-Font binary data.
//
// The first two paramters are hardcoded in [boot/mbr.asm],
// while the last one is set in the Makefile. The font binary
// is integrated in the kernel image.
//
// this function returns the physical base address of
// our video memory
//
uint32_t vesa_physbase=vesa_init(0x8300,0x8400,0x7200);
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"initial esp: 0x%08X",initial_stack);
//
// PIT config (timer)
timer_init();
// we know that here, the bootloader placed the mamory map!
mem_init(0x7c00+0x400,*((uint16_t *)(0x7c00+0x600)));
// paging (pass the vesa physbase address for identity mapping)
vmem_init(vesa_physbase);
//
// init and interrupt decriptor table
int_init(0x08);
int_install();
// setup custom interrupts
// remember that we shifted all interrupts with the pic by 32
// so clock = 32 (irq 0)
// keyboard = 33 (irq 1)
// floppy = 38 (irq 6)
// etc..
// install PIT interrupt handler
int_install_ir(32, 0b10001110, 0x08,&int_clock_handler);
// install keyboard interrupt handler
int_install_ir(33, 0b10001110, 0x08,&int_kb_handler);
// install floppy interrupt handler
int_install_ir(38, 0b10001110, 0x08,&int_floppy_handler);
// install test software interrupt handler
int_install_ir(88, 0b10001110, 0x08,&int_test_handler);
for(int i=0;i<19;i++)
int_install_ir(i, 0b10001110, 0x08,&int_test_handler);
// now we can enable interrupts back again
int_enable();
// int x=10/0;
// pci
pci_init();
// floppy
floppy_init();
//init shell
shell_init();
/*
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"test mem");
// test a20 disabled / wrap
uint8_t *memtest=0x0;
uint8_t *memtest2=0b10000000000000000000;
*memtest=0xaf;
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"test mem %x",*(memtest2-1));
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"test mem %x",*memtest2);
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"test mem %x",*(memtest2+1));
*/
/* stack pointer test?
uint32_t *esp=0x90000;
for(int i=0;i<10;i++)
{
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"esp: %x",*esp);
esp--;
}
*/
while(1)
{
}
}