summaryrefslogtreecommitdiff
path: root/kernel/kernel.c
blob: 05a4f9fb88792a7d9c5e50f5e1e7c205d466813c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include "kernel.h"	// general kernel config & includes
#include "console.h"	// this will allow us to write to screen
#include "x86.h"

// TODO: cleanup . how can i compile it without the includes!??

///////

void int_def_handler();
void int_clock_handler();
void int_kb_handler();
void int_floppy_handler();

////////// KERNEL MAIN///// /////
//

// test handler
void int_test_handler()
{
    X86_IRQ_BEGIN

    scr_put_string("inside software interrupt handler 88");
    sleep(30);

    X86_IRQ_END

}

void kernel_main()
{

    // clear console
    scr_clear();

    // hello message
    scr_put_string_nl(KERNEL_HELLO_MESSAGE);
    scr_put_string_nl("");
    
    //pit config
    //timer_init();

    // we know that here the bootloader placed the mamory map!
    mem_init(0x7c00+0x400,*((uint16_t *)(0x7c00+0x600)));
    //mem_init(0x9000);

    // we know that here the bootloader placed the mamory map!
    vmem_init();

    // 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);

    // now we can enable interrupts back again
    int_enable();
    scr_put_string_nl("interrupts: Interrupts are up and running");

    // pci
    pci_init();

    // vesa init
    vesa_init(0x8300,0x8400);

    // floppy
    floppy_init();
    scr_put_string_nl("");


    //init shell
    shell_init();

    // kernel main loop
    uint8_t t=0;
    uint8_t o=0;
    
//    while(1)
 //   {
    //}

    //uint8_t rawfont[]={0xff,0xff,0xc3,0xc3,0xff,0xff,0xc3,0xc3};
    //uint8_t rawfont[]={0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xff,0xff,};
    uint8_t *rawfont=0xb000; // here the floppy_init puts first sector
				// after 0x8000 (font data :)) 

    PutString(rawfont,"Welcome to Fool OS 001",10,10,0xff00);
    PutString(rawfont,"Welcome to Fool OS 001",20,20,0xf00);
    PutString(rawfont,"Welcome to Fool OS 001",30,30,0xfff00);


    while(1); // never ending loop

 
}