annotate cos/kernel/kernel.h @ 219:1fa3e0050b49

Expanded ad hoc code generator
author Windel Bouwman
date Sat, 06 Jul 2013 12:38:09 +0200
parents 35cc54e078dd
children
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
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
150 typedef struct
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
151 {
30
0148f55bfe24 Added static asserts and fixed pages
windel
parents: 29
diff changeset
152 unsigned present : 1;
29
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
153 uint64_t rw : 1;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
154 uint64_t us : 1; // user or supervisor
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
155 uint64_t pwt : 1;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
156 uint64_t pcd : 1; // page cache disable
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
157 uint64_t accessed : 1;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
158 uint64_t dirty : 1;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
159 uint64_t pat : 1; // memory type?
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
160 uint64_t g : 1; // Global?
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
161 uint64_t ignored : 3;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
162
30
0148f55bfe24 Added static asserts and fixed pages
windel
parents: 29
diff changeset
163 uint64_t address : 40;
29
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
164 uint64_t ignored2 : 11;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
165 uint64_t xd : 1;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
166 } page_t;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
167
30
0148f55bfe24 Added static asserts and fixed pages
windel
parents: 29
diff changeset
168 _Static_assert(sizeof(page_t) == 8, "sizeof(page_t) != 8");
0148f55bfe24 Added static asserts and fixed pages
windel
parents: 29
diff changeset
169 _Static_assert(sizeof(PDE_t) == 8, "sizeof(PDE_t) != 8");
0148f55bfe24 Added static asserts and fixed pages
windel
parents: 29
diff changeset
170 _Static_assert(sizeof(PDPTE_t) == 8, "sizeof(PDPTE_t) != 8");
0148f55bfe24 Added static asserts and fixed pages
windel
parents: 29
diff changeset
171 _Static_assert(sizeof(PML4E_t) == 8, "sizeof(PML4E_t) != 8");
0148f55bfe24 Added static asserts and fixed pages
windel
parents: 29
diff changeset
172
29
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
173 // Page table:
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
174 typedef struct
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
175 {
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
176 page_t table[512];
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
177 uint64_t physicalAddress;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
178 } PT_t;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
179
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
180 // Make memmap a PML4 type:
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
181 typedef PML4_t memmap_t;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
182
40
24ce177e01e8 Added more malloc stuff. Added mem usage
windel
parents: 37
diff changeset
183 // Malloc related functions
24ce177e01e8 Added more malloc stuff. Added mem usage
windel
parents: 37
diff changeset
184 typedef struct {
24ce177e01e8 Added more malloc stuff. Added mem usage
windel
parents: 37
diff changeset
185 uint64_t magic;
24ce177e01e8 Added more malloc stuff. Added mem usage
windel
parents: 37
diff changeset
186 uint64_t state;
24ce177e01e8 Added more malloc stuff. Added mem usage
windel
parents: 37
diff changeset
187 uint64_t size;
24ce177e01e8 Added more malloc stuff. Added mem usage
windel
parents: 37
diff changeset
188 } heap_header_t;
24ce177e01e8 Added more malloc stuff. Added mem usage
windel
parents: 37
diff changeset
189
24ce177e01e8 Added more malloc stuff. Added mem usage
windel
parents: 37
diff changeset
190 typedef struct
24ce177e01e8 Added more malloc stuff. Added mem usage
windel
parents: 37
diff changeset
191 {
24ce177e01e8 Added more malloc stuff. Added mem usage
windel
parents: 37
diff changeset
192 heap_header_t *first_block;
24ce177e01e8 Added more malloc stuff. Added mem usage
windel
parents: 37
diff changeset
193 uint64_t start_address;
24ce177e01e8 Added more malloc stuff. Added mem usage
windel
parents: 37
diff changeset
194 uint64_t end_address;
24ce177e01e8 Added more malloc stuff. Added mem usage
windel
parents: 37
diff changeset
195 } heap_t;
24ce177e01e8 Added more malloc stuff. Added mem usage
windel
parents: 37
diff changeset
196
29
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
197 // Task related types:
24
d8627924d40d Split up in more files and reboot command
windel
parents: 20
diff changeset
198 typedef struct
d8627924d40d Split up in more files and reboot command
windel
parents: 20
diff changeset
199 {
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
200 char name[32]; // Name of the console
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
201 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
202 } console_t;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
203
25
d3c4bf3720a3 Beginning of multitasking
windel
parents: 24
diff changeset
204 typedef struct task_t {
d3c4bf3720a3 Beginning of multitasking
windel
parents: 24
diff changeset
205 struct task_t* next;
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
206 uint32_t kstack;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
207 uint32_t ustack;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
208
29
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
209 // For task switching:
25
d3c4bf3720a3 Beginning of multitasking
windel
parents: 24
diff changeset
210 uint64_t cr3;
d3c4bf3720a3 Beginning of multitasking
windel
parents: 24
diff changeset
211 uint64_t rip;
d3c4bf3720a3 Beginning of multitasking
windel
parents: 24
diff changeset
212 uint64_t rsp;
d3c4bf3720a3 Beginning of multitasking
windel
parents: 24
diff changeset
213 uint64_t rbp;
d3c4bf3720a3 Beginning of multitasking
windel
parents: 24
diff changeset
214
d3c4bf3720a3 Beginning of multitasking
windel
parents: 24
diff changeset
215 uint32_t pid;
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
216 uint32_t parent;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
217 uint32_t owner;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
218 uint32_t groups;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
219 uint32_t timetorun;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
220 uint32_t sleep;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
221 uint32_t priority;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
222 uint32_t filehandle;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
223 char naam[32];
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
224
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
225 console_t *console;
25
d3c4bf3720a3 Beginning of multitasking
windel
parents: 24
diff changeset
226 } task_t;
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
227
32
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
228 /* Filesystem related types: */
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
229 struct fs_node_tag;
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
230 struct fs_dirent_tag;
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
231
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
232 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
233 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
234 typedef void (*open_type_t)(struct fs_node_tag*);
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
235 typedef void (*close_type_t)(struct fs_node_tag*);
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
236 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
237
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
238 typedef struct fs_node_tag
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
239 {
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
240 char name[129];
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
241 uint64_t flags;
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
242 uint64_t length;
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
243 uint64_t inode;
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
244 // Accessor functions:
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
245 read_type_t read;
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
246 write_type_t write;
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
247 open_type_t open;
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
248 close_type_t close;
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
249 readdir_type_t readdir;
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
250 } fs_node_t;
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
251
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
252 typedef struct fs_dirent_tag
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 char name[65];
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
255 uint64_t inode;
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
256 } fs_dirent_t;
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
257
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
258 #define FS_FILE 0x1
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
259 #define FS_DIRECTORY 0x2
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
260
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
261 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
262 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
263 void open_fs(fs_node_t *node);
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
264 void close_fs(fs_node_t *node);
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
265 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
266
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
267 // Initial ramdisk functions:
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
268 fs_node_t* initialize_initrd(uint64_t location);
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
269
41
35cc54e078dd Added memory functions
windel
parents: 40
diff changeset
270 void load_ramdisk(void);
35cc54e078dd Added memory functions
windel
parents: 40
diff changeset
271
29
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
272 // Variable argument list things:
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
273 #define va_start(v,l) __builtin_va_start(v,l)
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
274 #define va_end(v) __builtin_va_end(v)
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
275 #define va_arg(v,l) __builtin_va_arg(v,l)
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
276 typedef __builtin_va_list va_list;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
277
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
278 /* Global variables */
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
279 extern uint64_t kernel_end;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
280 extern uint64_t placement_address;
40
24ce177e01e8 Added more malloc stuff. Added mem usage
windel
parents: 37
diff changeset
281 extern memmap_t* kernel_map;
29
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 /* Procedures */
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
284
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
285 // memory functions:
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
286 // TODO: remove some redundant API functions:
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
287 void init_memory(uint64_t total_mem_size);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
288 page_t* get_page(uint64_t address, memmap_t*);
40
24ce177e01e8 Added more malloc stuff. Added mem usage
windel
parents: 37
diff changeset
289 void alloc_frame(page_t *page);
29
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
290 void loadPageTable(void* tableAddress);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
291 void switch_mapping(memmap_t* mapping);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
292 void enablePaging();
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
293
40
24ce177e01e8 Added more malloc stuff. Added mem usage
windel
parents: 37
diff changeset
294 // Malloc related:
24ce177e01e8 Added more malloc stuff. Added mem usage
windel
parents: 37
diff changeset
295 void* kmalloc(uint64_t size);
24ce177e01e8 Added more malloc stuff. Added mem usage
windel
parents: 37
diff changeset
296 void* kmalloc_a(uint64_t size); // Aligned on a 4 KiB page.
24ce177e01e8 Added more malloc stuff. Added mem usage
windel
parents: 37
diff changeset
297 void kfree(void* ptr);
24ce177e01e8 Added more malloc stuff. Added mem usage
windel
parents: 37
diff changeset
298 heap_t* create_heap(uint64_t location, uint64_t size);
24ce177e01e8 Added more malloc stuff. Added mem usage
windel
parents: 37
diff changeset
299
29
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
300 // task related functions:
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
301 void initialize_tasking();
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
302 void new_task();
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
303 void task_scheduler();
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
304
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
305 // STDout funcs:
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
306 void printf(const char* fmt, ... );
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
307 void memset(void* ptr, uint8_t value, uint64_t num);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
308 void memcpy(void* dst, void* src, uint64_t num);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
309 int strncmp(const char* s1, const char* s2, int size);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
310
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
311 // Screen related:
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
312 void clear_screen();
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
313 void init_screen();
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
314 void print_string(const char *);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
315 void set_cursor(int newrow, int newcol);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
316 void get_cursor(int *therow, int *thecol);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
317 void set_color(int forecolor, int backcolor);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
318
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
319 // For IO ports:
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
320 uint8_t inb(uint16_t);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
321 uint16_t inw(uint16_t);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
322 void outb(uint16_t, uint8_t);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
323
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
324 // Interrupt functions:
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
325 void setupIDT(void);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
326 void PICremap(void);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
327 void loadIDT(void);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
328
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
329 // ASM helper:
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
330 uint64_t read_rip();
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
331
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
332 // Helpers:
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
333 void halt(void);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
334 void panic(char *msg);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
335 void reboot(void);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
336 void magicBochsBreak();
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
337 void doCPUID(int eax, int *ebx, int *ecx, int *edx);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
338
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
339 // Keyboard driver:
32
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 30
diff changeset
340 void keyboardDriverUpdate(void);
29
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
341 void getline(char *buffer, int len);
34
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 32
diff changeset
342 void keyboard_init(void);
29
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
343
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
344 // Timer:
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
345 void timerDriverUpdate(void);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
346 uint64_t getTimeMS();
34
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 32
diff changeset
347 void timer_init(void);
28
47b7df514243 Moved Makefiles
windel
parents: 26
diff changeset
348
37
5c20bd53cccd Cleanup
windel
parents: 34
diff changeset
349 // Multiboot:
5c20bd53cccd Cleanup
windel
parents: 34
diff changeset
350 extern uint64_t available_memory;
5c20bd53cccd Cleanup
windel
parents: 34
diff changeset
351 extern uint64_t ramdisk_location;
5c20bd53cccd Cleanup
windel
parents: 34
diff changeset
352 void read_multiboot_info(void);
5c20bd53cccd Cleanup
windel
parents: 34
diff changeset
353
5c20bd53cccd Cleanup
windel
parents: 34
diff changeset
354 // Shell
5c20bd53cccd Cleanup
windel
parents: 34
diff changeset
355 void shell(void);
5c20bd53cccd Cleanup
windel
parents: 34
diff changeset
356
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
357 #endif
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
358