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