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);
|
14
|
69
|
17
|
70 // Bochs xchg bx,bx breakpoint:
|
|
71 void magicBochsBreak();
|
|
72
|
9
|
73 // Assembler util functions:
|
|
74 void doCPUID(int eax, int *ebx, int *ecx, int *edx);
|
|
75
|
|
76 // Keyboard driver:
|
|
77 void keyboardDriverUpdate(unsigned char scancode);
|
24
|
78 void getline(char *buffer, int len);
|
|
79
|
|
80 // Timer:
|
9
|
81 void timerDriverUpdate(void);
|
24
|
82 uint64_t getTimeMS();
|
9
|
83
|
|
84 // Memory functions:
|
17
|
85 void mappage(uint64_t address);
|
9
|
86
|
|
87 void loadPageTable(void* tableAddress);
|
|
88
|
12
|
89 // Variable argument list things:
|
|
90 #define va_start(v,l) __builtin_va_start(v,l)
|
|
91 #define va_end(v) __builtin_va_end(v)
|
|
92 #define va_arg(v,l) __builtin_va_arg(v,l)
|
|
93 typedef __builtin_va_list va_list;
|
|
94
|
20
|
95 // Multiboot structs:
|
9
|
96 struct multiboot_aout_symbol_table {
|
|
97 uint32_t tabsize;
|
|
98 uint32_t strsize, addr, reserved;
|
|
99 };
|
|
100
|
|
101 struct multiboot_info {
|
|
102 uint32_t flags; // Multiboot flags / version
|
|
103 uint32_t mem_lower; // available memory from BIOS
|
|
104 uint32_t mem_upper;
|
|
105 uint32_t boot_device;
|
|
106 uint32_t cmdline; // COmmand line
|
|
107 uint32_t mods_count;
|
|
108 uint32_t mods_addr;
|
|
109 union {
|
|
110 struct multiboot_aout_symbol_table aout_sym;
|
|
111 } u;
|
|
112
|
|
113 uint32_t mmap_length;
|
|
114 uint32_t mmap_addr;
|
|
115 };
|
|
116
|
|
117 struct memory_map {
|
|
118 uint32_t size;
|
|
119 uint32_t baselow, basehigh;
|
|
120 uint32_t lenlow, lenhigh;
|
|
121 uint32_t type;
|
|
122 };
|
|
123
|
24
|
124 typedef struct
|
|
125 {
|
9
|
126 char name[32]; // Name of the console
|
|
127 unsigned char screendata[80*25]; // All chars in the console!
|
|
128 } console_t;
|
|
129
|
25
|
130 typedef struct task_t {
|
|
131 struct task_t* next;
|
9
|
132 uint32_t kstack;
|
|
133 uint32_t ustack;
|
|
134
|
25
|
135 uint64_t cr3;
|
|
136 uint64_t rip;
|
|
137 uint64_t rsp;
|
|
138 uint64_t rbp;
|
|
139
|
|
140 uint32_t pid;
|
9
|
141 uint32_t parent;
|
|
142 uint32_t owner;
|
|
143 uint32_t groups;
|
|
144 uint32_t timetorun;
|
|
145 uint32_t sleep;
|
|
146 uint32_t priority;
|
|
147 uint32_t filehandle;
|
|
148 char naam[32];
|
|
149
|
|
150 console_t *console;
|
25
|
151 } task_t;
|
9
|
152
|
|
153 #endif
|
|
154
|