9
|
1 #ifndef KERNEL_H
|
|
2 #define KERNEL_H
|
|
3
|
|
4 // Include common functions, available to all!
|
|
5 #define NULL ((void*)0)
|
|
6
|
|
7 // Type defs:
|
17
|
8 typedef unsigned char uint8_t;
|
|
9 typedef unsigned short uint16_t;
|
9
|
10 typedef unsigned int uint32_t;
|
17
|
11 typedef unsigned long int uint64_t;
|
9
|
12
|
17
|
13 // IDT related structures:
|
|
14 typedef struct {
|
|
15 uint16_t baseLow;
|
|
16 uint16_t selector;
|
|
17 uint8_t reserved1;
|
|
18 uint8_t flags;
|
|
19 uint16_t baseMid;
|
|
20 uint32_t baseHigh;
|
|
21 uint32_t reserved2;
|
|
22 } __attribute__((packed)) IDT_entry;
|
|
23
|
|
24 typedef struct {
|
|
25 uint16_t limit;
|
|
26 uint64_t base;
|
|
27 } __attribute__((packed)) idtPointer;
|
|
28
|
|
29 // memory alloc functions:
|
20
|
30 void* kmalloc(uint64_t size);
|
|
31 void kfree(void* ptr);
|
17
|
32
|
|
33 // STDout funcs:
|
9
|
34 void printf(const char* fmt, ... );
|
|
35 void memset(void* ptr, uint32_t value, uint32_t num);
|
|
36 void memcpy(void* dst, void* src, uint32_t num);
|
|
37
|
17
|
38 // Screen related:
|
9
|
39 void clear_screen();
|
|
40 void init_screen();
|
|
41 void print_string(const char *);
|
|
42
|
|
43 // For IO ports:
|
17
|
44 uint8_t inb(uint16_t);
|
|
45 uint16_t inw(uint16_t);
|
|
46 void outb(uint16_t, uint8_t);
|
|
47
|
|
48 // Interrupt functions:
|
|
49 void setupIDT(void);
|
|
50 void PICremap(void);
|
9
|
51
|
14
|
52 // ASM helper:
|
17
|
53 void loadIDT(void);
|
|
54
|
|
55 // Panic exit:
|
14
|
56 void halt(void);
|
|
57
|
17
|
58 // Bochs xchg bx,bx breakpoint:
|
|
59 void magicBochsBreak();
|
|
60
|
9
|
61 // Assembler util functions:
|
|
62 void doCPUID(int eax, int *ebx, int *ecx, int *edx);
|
|
63
|
|
64 // Keyboard driver:
|
|
65 void keyboardDriverUpdate(unsigned char scancode);
|
|
66 void timerDriverUpdate(void);
|
|
67
|
|
68 // Memory functions:
|
17
|
69 void mappage(uint64_t address);
|
9
|
70
|
|
71 int querymode(void);
|
|
72 void loadPageTable(void* tableAddress);
|
|
73
|
12
|
74 // Variable argument list things:
|
|
75 #define va_start(v,l) __builtin_va_start(v,l)
|
|
76 #define va_end(v) __builtin_va_end(v)
|
|
77 #define va_arg(v,l) __builtin_va_arg(v,l)
|
|
78 typedef __builtin_va_list va_list;
|
|
79
|
20
|
80 // Multiboot structs:
|
9
|
81 struct multiboot_aout_symbol_table {
|
|
82 uint32_t tabsize;
|
|
83 uint32_t strsize, addr, reserved;
|
|
84 };
|
|
85
|
|
86 struct multiboot_info {
|
|
87 uint32_t flags; // Multiboot flags / version
|
|
88 uint32_t mem_lower; // available memory from BIOS
|
|
89 uint32_t mem_upper;
|
|
90 uint32_t boot_device;
|
|
91 uint32_t cmdline; // COmmand line
|
|
92 uint32_t mods_count;
|
|
93 uint32_t mods_addr;
|
|
94 union {
|
|
95 struct multiboot_aout_symbol_table aout_sym;
|
|
96 } u;
|
|
97
|
|
98 uint32_t mmap_length;
|
|
99 uint32_t mmap_addr;
|
|
100 };
|
|
101
|
|
102 struct memory_map {
|
|
103 uint32_t size;
|
|
104 uint32_t baselow, basehigh;
|
|
105 uint32_t lenlow, lenhigh;
|
|
106 uint32_t type;
|
|
107 };
|
|
108
|
|
109 typedef struct {
|
|
110 char name[32]; // Name of the console
|
|
111 unsigned char screendata[80*25]; // All chars in the console!
|
|
112 } console_t;
|
|
113
|
|
114 typedef struct {
|
|
115 uint32_t esp;
|
|
116 uint32_t ss;
|
|
117 uint32_t kstack;
|
|
118 uint32_t ustack;
|
|
119 uint32_t cr3;
|
|
120
|
|
121 uint32_t number;
|
|
122 uint32_t parent;
|
|
123 uint32_t owner;
|
|
124 uint32_t groups;
|
|
125 uint32_t timetorun;
|
|
126 uint32_t sleep;
|
|
127 uint32_t priority;
|
|
128 uint32_t filehandle;
|
|
129 char naam[32];
|
|
130
|
|
131 console_t *console;
|
|
132 } programma_t;
|
|
133
|
|
134 #endif
|
|
135
|