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:
|
24
|
30 void init_heap();
|
20
|
31 void* kmalloc(uint64_t size);
|
|
32 void kfree(void* ptr);
|
17
|
33
|
28
|
34 void* kmalloc_int(uint64_t size);
|
|
35
|
25
|
36 // task related functions:
|
|
37 void initialize_tasking();
|
|
38 void new_task();
|
|
39 void task_scheduler();
|
|
40
|
17
|
41 // STDout funcs:
|
9
|
42 void printf(const char* fmt, ... );
|
28
|
43 void memset(void* ptr, uint8_t value, uint64_t num);
|
|
44 void memcpy(void* dst, void* src, uint64_t num);
|
24
|
45 int strncmp(const char* s1, const char* s2, int size);
|
9
|
46
|
17
|
47 // Screen related:
|
9
|
48 void clear_screen();
|
|
49 void init_screen();
|
|
50 void print_string(const char *);
|
24
|
51 void set_cursor(int newrow, int newcol);
|
|
52 void get_cursor(int *therow, int *thecol);
|
|
53 void set_color(int forecolor, int backcolor);
|
9
|
54
|
|
55 // For IO ports:
|
17
|
56 uint8_t inb(uint16_t);
|
|
57 uint16_t inw(uint16_t);
|
|
58 void outb(uint16_t, uint8_t);
|
|
59
|
|
60 // Interrupt functions:
|
|
61 void setupIDT(void);
|
|
62 void PICremap(void);
|
9
|
63
|
14
|
64 // ASM helper:
|
17
|
65 void loadIDT(void);
|
25
|
66 uint64_t read_rip();
|
17
|
67
|
|
68 // Panic exit:
|
14
|
69 void halt(void);
|
24
|
70 void panic(char *msg);
|
26
|
71 void reboot(void);
|
14
|
72
|
17
|
73 // Bochs xchg bx,bx breakpoint:
|
|
74 void magicBochsBreak();
|
|
75
|
9
|
76 // Assembler util functions:
|
|
77 void doCPUID(int eax, int *ebx, int *ecx, int *edx);
|
|
78
|
|
79 // Keyboard driver:
|
|
80 void keyboardDriverUpdate(unsigned char scancode);
|
24
|
81 void getline(char *buffer, int len);
|
|
82
|
|
83 // Timer:
|
9
|
84 void timerDriverUpdate(void);
|
24
|
85 uint64_t getTimeMS();
|
9
|
86
|
|
87 // Memory functions:
|
17
|
88 void mappage(uint64_t address);
|
9
|
89
|
|
90 void loadPageTable(void* tableAddress);
|
|
91
|
12
|
92 // Variable argument list things:
|
|
93 #define va_start(v,l) __builtin_va_start(v,l)
|
|
94 #define va_end(v) __builtin_va_end(v)
|
|
95 #define va_arg(v,l) __builtin_va_arg(v,l)
|
|
96 typedef __builtin_va_list va_list;
|
|
97
|
20
|
98 // Multiboot structs:
|
9
|
99 struct multiboot_aout_symbol_table {
|
|
100 uint32_t tabsize;
|
|
101 uint32_t strsize, addr, reserved;
|
|
102 };
|
|
103
|
|
104 struct multiboot_info {
|
|
105 uint32_t flags; // Multiboot flags / version
|
|
106 uint32_t mem_lower; // available memory from BIOS
|
|
107 uint32_t mem_upper;
|
|
108 uint32_t boot_device;
|
|
109 uint32_t cmdline; // COmmand line
|
|
110 uint32_t mods_count;
|
|
111 uint32_t mods_addr;
|
|
112 union {
|
|
113 struct multiboot_aout_symbol_table aout_sym;
|
|
114 } u;
|
|
115
|
|
116 uint32_t mmap_length;
|
|
117 uint32_t mmap_addr;
|
|
118 };
|
|
119
|
|
120 struct memory_map {
|
|
121 uint32_t size;
|
|
122 uint32_t baselow, basehigh;
|
|
123 uint32_t lenlow, lenhigh;
|
|
124 uint32_t type;
|
|
125 };
|
|
126
|
24
|
127 typedef struct
|
|
128 {
|
9
|
129 char name[32]; // Name of the console
|
|
130 unsigned char screendata[80*25]; // All chars in the console!
|
|
131 } console_t;
|
|
132
|
25
|
133 typedef struct task_t {
|
|
134 struct task_t* next;
|
9
|
135 uint32_t kstack;
|
|
136 uint32_t ustack;
|
|
137
|
25
|
138 uint64_t cr3;
|
|
139 uint64_t rip;
|
|
140 uint64_t rsp;
|
|
141 uint64_t rbp;
|
|
142
|
|
143 uint32_t pid;
|
9
|
144 uint32_t parent;
|
|
145 uint32_t owner;
|
|
146 uint32_t groups;
|
|
147 uint32_t timetorun;
|
|
148 uint32_t sleep;
|
|
149 uint32_t priority;
|
|
150 uint32_t filehandle;
|
|
151 char naam[32];
|
|
152
|
|
153 console_t *console;
|
25
|
154 } task_t;
|
9
|
155
|
28
|
156 // Memory manager functions:
|
|
157 typedef struct
|
|
158 {
|
|
159 // TODO: other members here.
|
|
160 uint64_t frame;
|
|
161 } page_t;
|
|
162
|
9
|
163 #endif
|
|
164
|