annotate cos/kernel/kernel.h @ 37:5c20bd53cccd

Cleanup
author windel
date Mon, 16 Jan 2012 21:38:55 +0100
parents 8012221dd740
children 24ce177e01e8
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
29
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
7 /* Types */
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
8
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
9 // Type defs:
17
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
10 typedef unsigned char uint8_t;
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
11 typedef unsigned short uint16_t;
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
12 typedef unsigned int uint32_t;
17
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
13 typedef unsigned long int uint64_t;
34
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 32
diff changeset
14 typedef long int int64_t;
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 32
diff changeset
15
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 32
diff changeset
16 _Static_assert(sizeof(uint8_t) == 1, "sizeof(uint8_t) != 1");
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 32
diff changeset
17 _Static_assert(sizeof(uint16_t) == 2, "sizeof(uint16_t) != 2");
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 32
diff changeset
18 _Static_assert(sizeof(uint32_t) == 4, "sizeof(uint32_t) != 4");
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 32
diff changeset
19 _Static_assert(sizeof(uint64_t) == 8, "sizeof(uint64_t) != 8");
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 32
diff changeset
20 _Static_assert(sizeof(int64_t) == 8, "sizeof(int64_t) != 8");
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
21
17
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
22 // IDT related structures:
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
23 typedef struct {
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
24 uint16_t baseLow;
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
25 uint16_t selector;
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
26 uint8_t reserved1;
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
27 uint8_t flags;
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
28 uint16_t baseMid;
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
29 uint32_t baseHigh;
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
30 uint32_t reserved2;
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
31 } __attribute__((packed)) IDT_entry;
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
32
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
33 typedef struct {
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
34 uint16_t limit;
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
35 uint64_t base;
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
36 } __attribute__((packed)) idtPointer;
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
37
20
b1fed2171e1a Now working with 2 MB pages
windel
parents: 17
diff changeset
38 // Multiboot structs:
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
39 struct multiboot_aout_symbol_table {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
40 uint32_t tabsize;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
41 uint32_t strsize, addr, reserved;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
42 };
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
43
32
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
44 typedef struct multiboot_info_tag
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
45 {
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
46 uint32_t flags; // Multiboot flags / version
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
47 uint32_t mem_lower; // available memory from BIOS
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
48 uint32_t mem_upper;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
49 uint32_t boot_device;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
50 uint32_t cmdline; // COmmand line
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
51 uint32_t mods_count;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
52 uint32_t mods_addr;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
53 union {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
54 struct multiboot_aout_symbol_table aout_sym;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
55 } u;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
56
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
57 uint32_t mmap_length;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
58 uint32_t mmap_addr;
32
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
59 } multiboot_info_t;
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
60
32
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
61 typedef struct memory_map_tag
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
62 {
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
63 uint32_t size;
32
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
64 uint64_t base;
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
65 uint64_t length;
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
66 uint32_t type;
32
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
67 } __attribute__((packed)) multiboot_memory_map_t;
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
68
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
69 typedef struct
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
70 {
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
71 uint32_t mod_start;
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
72 uint32_t mod_end;
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
73 uint32_t cmdline;
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
74 uint32_t pad;
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
75 } multiboot_module_t;
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
76
29
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
77 // Memory manager structures:
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
78 typedef struct
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
79 {
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
80 uint64_t present : 1;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
81 uint64_t rw : 1;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
82 uint64_t us : 1; // user or supervisor
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
83 uint64_t pwt : 1; // page level write-through
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
84 uint64_t pcd : 1; // page cache disable
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
85 uint64_t accessed : 1;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
86 uint64_t ignored : 1;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
87 uint64_t ps : 1; // must be 0.
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
88 uint64_t ignored2 : 4;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
89 // 12 bits so far
30
0148f55bfe24 Added static asserts and fixed pages
windel
parents: 29
diff changeset
90 uint64_t address : 40; // address of page directory pointer table.
29
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
91 uint64_t ignored3 : 11;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
92 uint64_t xd : 1; // execute disable
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
93 } PML4E_t; // 64 bits wide, PML4 table must be 4096 byte aligned.
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
94
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
95 typedef struct
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
96 {
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
97 // Must be 12 bits aligned!
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
98 PML4E_t table[512];
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
99 uint64_t physicalAddress; // Physical address of the table above
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
100 } PML4_t;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
101
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
102 typedef struct
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
103 {
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
104 uint64_t present : 1;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
105 uint64_t rw : 1;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
106 uint64_t us : 1; // user or supervisor
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
107 uint64_t pwt : 1; // page level write-through
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
108 uint64_t pcd : 1; // page cache disable
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
109 uint64_t accessed : 1;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
110 uint64_t ignored : 1;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
111 uint64_t ps : 1; // page size, must be 0, otherwise maps a 1 GB page.
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
112 uint64_t ignored2 : 4;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
113 // 12 bits so far
30
0148f55bfe24 Added static asserts and fixed pages
windel
parents: 29
diff changeset
114 uint64_t address : 40; // address of page directory table.
29
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
115 uint64_t ignored3 : 11;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
116 uint64_t xd : 1; // execute disable
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
117 } PDPTE_t; // Page directory pointer table entry, 64 bits wide. 4-kB aligned.
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
118
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
119 // Page directory pointer table:
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
120 typedef struct
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
121 {
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
122 PDPTE_t table[512];
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
123 uint64_t physicalAddress;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
124 } PDPT_t;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
125
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
126 typedef struct
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
127 {
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
128 uint64_t present : 1;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
129 uint64_t rw : 1;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
130 uint64_t us : 1; // user or supervisor
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
131 uint64_t pwt : 1;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
132 uint64_t pcd : 1; // page cache disable
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
133 uint64_t accessed : 1;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
134 uint64_t ignored : 1;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
135 uint64_t ps : 1; // page size, must be 0, otherwise maps a 2-MB page.
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
136 uint64_t ignored2 : 4;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
137 // 12 bits so far
30
0148f55bfe24 Added static asserts and fixed pages
windel
parents: 29
diff changeset
138 uint64_t address : 40; // address of page table.
29
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
139 uint64_t ignored3 : 11;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
140 uint64_t xd : 1; // execute disable
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
141 } PDE_t;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
142
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
143 // Page directory:
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
144 typedef struct
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
145 {
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
146 PDE_t table[512];
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
147 uint64_t physicalAddress;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
148 } PD_t;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
149
30
0148f55bfe24 Added static asserts and fixed pages
windel
parents: 29
diff changeset
150
29
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
151 typedef struct
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
152 {
30
0148f55bfe24 Added static asserts and fixed pages
windel
parents: 29
diff changeset
153 unsigned present : 1;
29
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
154 uint64_t rw : 1;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
155 uint64_t us : 1; // user or supervisor
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
156 uint64_t pwt : 1;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
157 uint64_t pcd : 1; // page cache disable
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
158 uint64_t accessed : 1;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
159 uint64_t dirty : 1;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
160 uint64_t pat : 1; // memory type?
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
161 uint64_t g : 1; // Global?
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
162 uint64_t ignored : 3;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
163
30
0148f55bfe24 Added static asserts and fixed pages
windel
parents: 29
diff changeset
164 uint64_t address : 40;
29
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
165 uint64_t ignored2 : 11;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
166 uint64_t xd : 1;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
167 } page_t;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
168
30
0148f55bfe24 Added static asserts and fixed pages
windel
parents: 29
diff changeset
169 _Static_assert(sizeof(page_t) == 8, "sizeof(page_t) != 8");
0148f55bfe24 Added static asserts and fixed pages
windel
parents: 29
diff changeset
170 _Static_assert(sizeof(PDE_t) == 8, "sizeof(PDE_t) != 8");
0148f55bfe24 Added static asserts and fixed pages
windel
parents: 29
diff changeset
171 _Static_assert(sizeof(PDPTE_t) == 8, "sizeof(PDPTE_t) != 8");
0148f55bfe24 Added static asserts and fixed pages
windel
parents: 29
diff changeset
172 _Static_assert(sizeof(PML4E_t) == 8, "sizeof(PML4E_t) != 8");
0148f55bfe24 Added static asserts and fixed pages
windel
parents: 29
diff changeset
173
29
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
174 // Page table:
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
175 typedef struct
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
176 {
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
177 page_t table[512];
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
178 uint64_t physicalAddress;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
179 } PT_t;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
180
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
181 // Make memmap a PML4 type:
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
182 typedef PML4_t memmap_t;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
183
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
184 // Task related types:
24
d8627924d40d Split up in more files and reboot command
windel
parents: 20
diff changeset
185 typedef struct
d8627924d40d Split up in more files and reboot command
windel
parents: 20
diff changeset
186 {
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
187 char name[32]; // Name of the console
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
188 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
189 } console_t;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
190
25
d3c4bf3720a3 Beginning of multitasking
windel
parents: 24
diff changeset
191 typedef struct task_t {
d3c4bf3720a3 Beginning of multitasking
windel
parents: 24
diff changeset
192 struct task_t* next;
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
193 uint32_t kstack;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
194 uint32_t ustack;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
195
29
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
196 // For task switching:
25
d3c4bf3720a3 Beginning of multitasking
windel
parents: 24
diff changeset
197 uint64_t cr3;
d3c4bf3720a3 Beginning of multitasking
windel
parents: 24
diff changeset
198 uint64_t rip;
d3c4bf3720a3 Beginning of multitasking
windel
parents: 24
diff changeset
199 uint64_t rsp;
d3c4bf3720a3 Beginning of multitasking
windel
parents: 24
diff changeset
200 uint64_t rbp;
d3c4bf3720a3 Beginning of multitasking
windel
parents: 24
diff changeset
201
d3c4bf3720a3 Beginning of multitasking
windel
parents: 24
diff changeset
202 uint32_t pid;
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
203 uint32_t parent;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
204 uint32_t owner;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
205 uint32_t groups;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
206 uint32_t timetorun;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
207 uint32_t sleep;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
208 uint32_t priority;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
209 uint32_t filehandle;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
210 char naam[32];
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
211
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
212 console_t *console;
25
d3c4bf3720a3 Beginning of multitasking
windel
parents: 24
diff changeset
213 } task_t;
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
214
32
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
215 /* Filesystem related types: */
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
216 struct fs_node_tag;
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
217 struct fs_dirent_tag;
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
218
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
219 typedef uint64_t (*read_type_t)(struct fs_node_tag*, uint64_t, uint64_t, uint8_t*);
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
220 typedef uint64_t (*write_type_t)(struct fs_node_tag*, uint64_t, uint64_t, uint8_t*);
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
221 typedef void (*open_type_t)(struct fs_node_tag*);
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
222 typedef void (*close_type_t)(struct fs_node_tag*);
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
223 typedef struct fs_dirent_tag* (*readdir_type_t)(struct fs_node_tag*, int);
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
224
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
225 typedef struct fs_node_tag
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
226 {
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
227 char name[129];
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
228 uint64_t flags;
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
229 uint64_t length;
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
230 uint64_t inode;
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
231 // Accessor functions:
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
232 read_type_t read;
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
233 write_type_t write;
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
234 open_type_t open;
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
235 close_type_t close;
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
236 readdir_type_t readdir;
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
237 } fs_node_t;
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
238
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
239 typedef struct fs_dirent_tag
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
240 {
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
241 char name[65];
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
242 uint64_t inode;
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
243 } fs_dirent_t;
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
244
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
245 #define FS_FILE 0x1
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
246 #define FS_DIRECTORY 0x2
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
247
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
248 uint64_t read_fs(fs_node_t *node, uint64_t offset, uint64_t size, uint8_t *buffer);
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
249 uint64_t write_fs(fs_node_t *node, uint64_t offset, uint64_t size, uint8_t *buffer);
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
250 void open_fs(fs_node_t *node);
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
251 void close_fs(fs_node_t *node);
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
252 fs_dirent_t* readdir_fs(fs_node_t *node, int i);
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
253
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
254 // Initial ramdisk functions:
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
255 fs_node_t* initialize_initrd(uint64_t location);
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
256
29
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
257 // Variable argument list things:
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
258 #define va_start(v,l) __builtin_va_start(v,l)
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
259 #define va_end(v) __builtin_va_end(v)
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
260 #define va_arg(v,l) __builtin_va_arg(v,l)
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
261 typedef __builtin_va_list va_list;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
262
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
263 /* Global variables */
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
264 extern uint64_t kernel_end;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
265 extern uint64_t placement_address;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
266
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
267 /* Procedures */
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
268
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
269 // memory functions:
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
270 // TODO: remove some redundant API functions:
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
271 void init_heap();
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
272 void init_memory(uint64_t total_mem_size);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
273 page_t* get_page(uint64_t address, memmap_t*);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
274 void* kmalloc(uint64_t size);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
275 void kfree(void* ptr);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
276 void* kmalloc_int(uint64_t size);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
277 void* kmalloc_aligned_int(uint64_t size);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
278 void mappage(uint64_t address);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
279 void loadPageTable(void* tableAddress);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
280 void switch_mapping(memmap_t* mapping);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
281 void enablePaging();
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
282
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
283 // task related functions:
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
284 void initialize_tasking();
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
285 void new_task();
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
286 void task_scheduler();
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
287
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
288 // STDout funcs:
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
289 void printf(const char* fmt, ... );
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
290 void memset(void* ptr, uint8_t value, uint64_t num);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
291 void memcpy(void* dst, void* src, uint64_t num);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
292 int strncmp(const char* s1, const char* s2, int size);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
293
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
294 // Screen related:
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
295 void clear_screen();
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
296 void init_screen();
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
297 void print_string(const char *);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
298 void set_cursor(int newrow, int newcol);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
299 void get_cursor(int *therow, int *thecol);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
300 void set_color(int forecolor, int backcolor);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
301
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
302 // For IO ports:
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
303 uint8_t inb(uint16_t);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
304 uint16_t inw(uint16_t);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
305 void outb(uint16_t, uint8_t);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
306
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
307 // Interrupt functions:
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
308 void setupIDT(void);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
309 void PICremap(void);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
310 void loadIDT(void);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
311
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
312 // ASM helper:
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
313 uint64_t read_rip();
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
314
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
315 // Helpers:
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
316 void halt(void);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
317 void panic(char *msg);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
318 void reboot(void);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
319 void magicBochsBreak();
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
320 void doCPUID(int eax, int *ebx, int *ecx, int *edx);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
321
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
322 // Keyboard driver:
32
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
323 void keyboardDriverUpdate(void);
29
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
324 void getline(char *buffer, int len);
34
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 32
diff changeset
325 void keyboard_init(void);
29
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
326
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
327 // Timer:
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
328 void timerDriverUpdate(void);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
329 uint64_t getTimeMS();
34
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 32
diff changeset
330 void timer_init(void);
28
47b7df514243 Moved Makefiles
windel
parents: 26
diff changeset
331
37
5c20bd53cccd Cleanup
windel
parents: 34
diff changeset
332 // Multiboot:
5c20bd53cccd Cleanup
windel
parents: 34
diff changeset
333 extern uint64_t available_memory;
5c20bd53cccd Cleanup
windel
parents: 34
diff changeset
334 extern uint64_t ramdisk_location;
5c20bd53cccd Cleanup
windel
parents: 34
diff changeset
335 void read_multiboot_info(void);
5c20bd53cccd Cleanup
windel
parents: 34
diff changeset
336
5c20bd53cccd Cleanup
windel
parents: 34
diff changeset
337 // Shell
5c20bd53cccd Cleanup
windel
parents: 34
diff changeset
338 void shell(void);
5c20bd53cccd Cleanup
windel
parents: 34
diff changeset
339
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
340 #endif
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
341