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:
|
|
30 void* malloc(uint64_t size);
|
|
31 void free(void* ptr);
|
|
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 int getcs(void);
|
|
73 void loadPageTable(void* tableAddress);
|
|
74 void enablePaging(void);
|
|
75
|
12
|
76 // Variable argument list things:
|
|
77 #define va_start(v,l) __builtin_va_start(v,l)
|
|
78 #define va_end(v) __builtin_va_end(v)
|
|
79 #define va_arg(v,l) __builtin_va_arg(v,l)
|
|
80 typedef __builtin_va_list va_list;
|
|
81
|
9
|
82 struct multiboot_aout_symbol_table {
|
|
83 uint32_t tabsize;
|
|
84 uint32_t strsize, addr, reserved;
|
|
85 };
|
|
86
|
|
87 struct multiboot_info {
|
|
88 uint32_t flags; // Multiboot flags / version
|
|
89 uint32_t mem_lower; // available memory from BIOS
|
|
90 uint32_t mem_upper;
|
|
91 uint32_t boot_device;
|
|
92 uint32_t cmdline; // COmmand line
|
|
93 uint32_t mods_count;
|
|
94 uint32_t mods_addr;
|
|
95 union {
|
|
96 struct multiboot_aout_symbol_table aout_sym;
|
|
97 } u;
|
|
98
|
|
99 uint32_t mmap_length;
|
|
100 uint32_t mmap_addr;
|
|
101 };
|
|
102
|
|
103 struct memory_map {
|
|
104 uint32_t size;
|
|
105 uint32_t baselow, basehigh;
|
|
106 uint32_t lenlow, lenhigh;
|
|
107 uint32_t type;
|
|
108 };
|
|
109
|
|
110 typedef struct {
|
|
111 char name[32]; // Name of the console
|
|
112 unsigned char screendata[80*25]; // All chars in the console!
|
|
113 } console_t;
|
|
114
|
|
115 typedef struct {
|
|
116 uint32_t esp;
|
|
117 uint32_t ss;
|
|
118 uint32_t kstack;
|
|
119 uint32_t ustack;
|
|
120 uint32_t cr3;
|
|
121
|
|
122 uint32_t number;
|
|
123 uint32_t parent;
|
|
124 uint32_t owner;
|
|
125 uint32_t groups;
|
|
126 uint32_t timetorun;
|
|
127 uint32_t sleep;
|
|
128 uint32_t priority;
|
|
129 uint32_t filehandle;
|
|
130 char naam[32];
|
|
131
|
|
132 console_t *console;
|
|
133 } programma_t;
|
|
134
|
|
135 #endif
|
|
136
|