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