annotate cos/kernel/kernel.h @ 28:47b7df514243

Moved Makefiles
author windel
date Wed, 28 Dec 2011 13:38:43 +0100
parents dcce92b1efbc
children 7e3bdcb391dc
rev   line source
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
1 #ifndef KERNEL_H
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
2 #define KERNEL_H
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
3
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
4 // Include common functions, available to all!
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
5 #define NULL ((void*)0)
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
6
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
7 // Type defs:
17
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
8 typedef unsigned char uint8_t;
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
9 typedef unsigned short uint16_t;
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
10 typedef unsigned int uint32_t;
17
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
11 typedef unsigned long int uint64_t;
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
12
17
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
13 // IDT related structures:
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
14 typedef struct {
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
15 uint16_t baseLow;
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
16 uint16_t selector;
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
17 uint8_t reserved1;
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
18 uint8_t flags;
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
19 uint16_t baseMid;
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
20 uint32_t baseHigh;
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
21 uint32_t reserved2;
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
22 } __attribute__((packed)) IDT_entry;
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
23
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
24 typedef struct {
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
25 uint16_t limit;
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
26 uint64_t base;
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
27 } __attribute__((packed)) idtPointer;
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
28
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
29 // memory alloc functions:
24
d8627924d40d Split up in more files and reboot command
windel
parents: 20
diff changeset
30 void init_heap();
20
b1fed2171e1a Now working with 2 MB pages
windel
parents: 17
diff changeset
31 void* kmalloc(uint64_t size);
b1fed2171e1a Now working with 2 MB pages
windel
parents: 17
diff changeset
32 void kfree(void* ptr);
17
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
33
28
47b7df514243 Moved Makefiles
windel
parents: 26
diff changeset
34 void* kmalloc_int(uint64_t size);
47b7df514243 Moved Makefiles
windel
parents: 26
diff changeset
35
25
d3c4bf3720a3 Beginning of multitasking
windel
parents: 24
diff changeset
36 // task related functions:
d3c4bf3720a3 Beginning of multitasking
windel
parents: 24
diff changeset
37 void initialize_tasking();
d3c4bf3720a3 Beginning of multitasking
windel
parents: 24
diff changeset
38 void new_task();
d3c4bf3720a3 Beginning of multitasking
windel
parents: 24
diff changeset
39 void task_scheduler();
d3c4bf3720a3 Beginning of multitasking
windel
parents: 24
diff changeset
40
17
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
41 // STDout funcs:
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
42 void printf(const char* fmt, ... );
28
47b7df514243 Moved Makefiles
windel
parents: 26
diff changeset
43 void memset(void* ptr, uint8_t value, uint64_t num);
47b7df514243 Moved Makefiles
windel
parents: 26
diff changeset
44 void memcpy(void* dst, void* src, uint64_t num);
24
d8627924d40d Split up in more files and reboot command
windel
parents: 20
diff changeset
45 int strncmp(const char* s1, const char* s2, int size);
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
46
17
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
47 // Screen related:
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
48 void clear_screen();
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
49 void init_screen();
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
50 void print_string(const char *);
24
d8627924d40d Split up in more files and reboot command
windel
parents: 20
diff changeset
51 void set_cursor(int newrow, int newcol);
d8627924d40d Split up in more files and reboot command
windel
parents: 20
diff changeset
52 void get_cursor(int *therow, int *thecol);
d8627924d40d Split up in more files and reboot command
windel
parents: 20
diff changeset
53 void set_color(int forecolor, int backcolor);
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
54
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
55 // For IO ports:
17
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
56 uint8_t inb(uint16_t);
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
57 uint16_t inw(uint16_t);
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
58 void outb(uint16_t, uint8_t);
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
59
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
60 // Interrupt functions:
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
61 void setupIDT(void);
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
62 void PICremap(void);
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
63
14
a58904747019 Added asm interrupt handler things, not yet working
windel
parents: 13
diff changeset
64 // ASM helper:
17
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
65 void loadIDT(void);
25
d3c4bf3720a3 Beginning of multitasking
windel
parents: 24
diff changeset
66 uint64_t read_rip();
17
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
67
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
68 // Panic exit:
14
a58904747019 Added asm interrupt handler things, not yet working
windel
parents: 13
diff changeset
69 void halt(void);
24
d8627924d40d Split up in more files and reboot command
windel
parents: 20
diff changeset
70 void panic(char *msg);
26
dcce92b1efbc Added mm.c
windel
parents: 25
diff changeset
71 void reboot(void);
14
a58904747019 Added asm interrupt handler things, not yet working
windel
parents: 13
diff changeset
72
17
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
73 // Bochs xchg bx,bx breakpoint:
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
74 void magicBochsBreak();
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
75
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
76 // Assembler util functions:
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
77 void doCPUID(int eax, int *ebx, int *ecx, int *edx);
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
78
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
79 // Keyboard driver:
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
80 void keyboardDriverUpdate(unsigned char scancode);
24
d8627924d40d Split up in more files and reboot command
windel
parents: 20
diff changeset
81 void getline(char *buffer, int len);
d8627924d40d Split up in more files and reboot command
windel
parents: 20
diff changeset
82
d8627924d40d Split up in more files and reboot command
windel
parents: 20
diff changeset
83 // Timer:
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
84 void timerDriverUpdate(void);
24
d8627924d40d Split up in more files and reboot command
windel
parents: 20
diff changeset
85 uint64_t getTimeMS();
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
86
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
87 // Memory functions:
17
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
88 void mappage(uint64_t address);
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
89
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
90 void loadPageTable(void* tableAddress);
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
91
12
fcdae30b2782 Fixup of variable argument things
windel
parents: 9
diff changeset
92 // Variable argument list things:
fcdae30b2782 Fixup of variable argument things
windel
parents: 9
diff changeset
93 #define va_start(v,l) __builtin_va_start(v,l)
fcdae30b2782 Fixup of variable argument things
windel
parents: 9
diff changeset
94 #define va_end(v) __builtin_va_end(v)
fcdae30b2782 Fixup of variable argument things
windel
parents: 9
diff changeset
95 #define va_arg(v,l) __builtin_va_arg(v,l)
fcdae30b2782 Fixup of variable argument things
windel
parents: 9
diff changeset
96 typedef __builtin_va_list va_list;
fcdae30b2782 Fixup of variable argument things
windel
parents: 9
diff changeset
97
20
b1fed2171e1a Now working with 2 MB pages
windel
parents: 17
diff changeset
98 // Multiboot structs:
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
99 struct multiboot_aout_symbol_table {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
100 uint32_t tabsize;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
101 uint32_t strsize, addr, reserved;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
102 };
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
103
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
104 struct multiboot_info {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
105 uint32_t flags; // Multiboot flags / version
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
106 uint32_t mem_lower; // available memory from BIOS
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
107 uint32_t mem_upper;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
108 uint32_t boot_device;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
109 uint32_t cmdline; // COmmand line
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
110 uint32_t mods_count;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
111 uint32_t mods_addr;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
112 union {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
113 struct multiboot_aout_symbol_table aout_sym;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
114 } u;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
115
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
116 uint32_t mmap_length;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
117 uint32_t mmap_addr;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
118 };
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
119
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
120 struct memory_map {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
121 uint32_t size;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
122 uint32_t baselow, basehigh;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
123 uint32_t lenlow, lenhigh;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
124 uint32_t type;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
125 };
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
126
24
d8627924d40d Split up in more files and reboot command
windel
parents: 20
diff changeset
127 typedef struct
d8627924d40d Split up in more files and reboot command
windel
parents: 20
diff changeset
128 {
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
129 char name[32]; // Name of the console
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
130 unsigned char screendata[80*25]; // All chars in the console!
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
131 } console_t;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
132
25
d3c4bf3720a3 Beginning of multitasking
windel
parents: 24
diff changeset
133 typedef struct task_t {
d3c4bf3720a3 Beginning of multitasking
windel
parents: 24
diff changeset
134 struct task_t* next;
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
135 uint32_t kstack;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
136 uint32_t ustack;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
137
25
d3c4bf3720a3 Beginning of multitasking
windel
parents: 24
diff changeset
138 uint64_t cr3;
d3c4bf3720a3 Beginning of multitasking
windel
parents: 24
diff changeset
139 uint64_t rip;
d3c4bf3720a3 Beginning of multitasking
windel
parents: 24
diff changeset
140 uint64_t rsp;
d3c4bf3720a3 Beginning of multitasking
windel
parents: 24
diff changeset
141 uint64_t rbp;
d3c4bf3720a3 Beginning of multitasking
windel
parents: 24
diff changeset
142
d3c4bf3720a3 Beginning of multitasking
windel
parents: 24
diff changeset
143 uint32_t pid;
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
144 uint32_t parent;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
145 uint32_t owner;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
146 uint32_t groups;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
147 uint32_t timetorun;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
148 uint32_t sleep;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
149 uint32_t priority;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
150 uint32_t filehandle;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
151 char naam[32];
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
152
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
153 console_t *console;
25
d3c4bf3720a3 Beginning of multitasking
windel
parents: 24
diff changeset
154 } task_t;
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
155
28
47b7df514243 Moved Makefiles
windel
parents: 26
diff changeset
156 // Memory manager functions:
47b7df514243 Moved Makefiles
windel
parents: 26
diff changeset
157 typedef struct
47b7df514243 Moved Makefiles
windel
parents: 26
diff changeset
158 {
47b7df514243 Moved Makefiles
windel
parents: 26
diff changeset
159 // TODO: other members here.
47b7df514243 Moved Makefiles
windel
parents: 26
diff changeset
160 uint64_t frame;
47b7df514243 Moved Makefiles
windel
parents: 26
diff changeset
161 } page_t;
47b7df514243 Moved Makefiles
windel
parents: 26
diff changeset
162
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
163 #endif
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
164