annotate cos/kernel/kernel.h @ 31:88590c42320f

Changed interrupt handler
author windel
date Tue, 10 Jan 2012 20:40:35 +0100
parents 0148f55bfe24
children 3a6a9b929db0
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;
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
14
17
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
15 // IDT related structures:
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
16 typedef struct {
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
17 uint16_t baseLow;
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
18 uint16_t selector;
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
19 uint8_t reserved1;
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
20 uint8_t flags;
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
21 uint16_t baseMid;
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
22 uint32_t baseHigh;
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
23 uint32_t reserved2;
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
24 } __attribute__((packed)) IDT_entry;
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
25
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
26 typedef struct {
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
27 uint16_t limit;
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
28 uint64_t base;
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
29 } __attribute__((packed)) idtPointer;
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
30
20
b1fed2171e1a Now working with 2 MB pages
windel
parents: 17
diff changeset
31 // Multiboot structs:
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
32 struct multiboot_aout_symbol_table {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
33 uint32_t tabsize;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
34 uint32_t strsize, addr, reserved;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
35 };
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
36
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
37 struct multiboot_info {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
38 uint32_t flags; // Multiboot flags / version
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
39 uint32_t mem_lower; // available memory from BIOS
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
40 uint32_t mem_upper;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
41 uint32_t boot_device;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
42 uint32_t cmdline; // COmmand line
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
43 uint32_t mods_count;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
44 uint32_t mods_addr;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
45 union {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
46 struct multiboot_aout_symbol_table aout_sym;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
47 } u;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
48
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
49 uint32_t mmap_length;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
50 uint32_t mmap_addr;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
51 };
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
52
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
53 struct memory_map {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
54 uint32_t size;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
55 uint32_t baselow, basehigh;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
56 uint32_t lenlow, lenhigh;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
57 uint32_t type;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
58 };
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
59
29
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
60 // Memory manager structures:
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
61 typedef struct
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
62 {
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
63 uint64_t present : 1;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
64 uint64_t rw : 1;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
65 uint64_t us : 1; // user or supervisor
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
66 uint64_t pwt : 1; // page level write-through
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
67 uint64_t pcd : 1; // page cache disable
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
68 uint64_t accessed : 1;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
69 uint64_t ignored : 1;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
70 uint64_t ps : 1; // must be 0.
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
71 uint64_t ignored2 : 4;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
72 // 12 bits so far
30
0148f55bfe24 Added static asserts and fixed pages
windel
parents: 29
diff changeset
73 uint64_t address : 40; // address of page directory pointer table.
29
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
74 uint64_t ignored3 : 11;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
75 uint64_t xd : 1; // execute disable
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
76 } PML4E_t; // 64 bits wide, PML4 table must be 4096 byte aligned.
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
77
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 // Must be 12 bits aligned!
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
81 PML4E_t table[512];
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
82 uint64_t physicalAddress; // Physical address of the table above
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
83 } PML4_t;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
84
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
85 typedef struct
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
86 {
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
87 uint64_t present : 1;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
88 uint64_t rw : 1;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
89 uint64_t us : 1; // user or supervisor
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
90 uint64_t pwt : 1; // page level write-through
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
91 uint64_t pcd : 1; // page cache disable
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
92 uint64_t accessed : 1;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
93 uint64_t ignored : 1;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
94 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
95 uint64_t ignored2 : 4;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
96 // 12 bits so far
30
0148f55bfe24 Added static asserts and fixed pages
windel
parents: 29
diff changeset
97 uint64_t address : 40; // address of page directory table.
29
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
98 uint64_t ignored3 : 11;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
99 uint64_t xd : 1; // execute disable
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
100 } 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
101
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
102 // Page directory pointer table:
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
103 typedef struct
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
104 {
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
105 PDPTE_t table[512];
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
106 uint64_t physicalAddress;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
107 } PDPT_t;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
108
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
109 typedef struct
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
110 {
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
111 uint64_t present : 1;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
112 uint64_t rw : 1;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
113 uint64_t us : 1; // user or supervisor
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
114 uint64_t pwt : 1;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
115 uint64_t pcd : 1; // page cache disable
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
116 uint64_t accessed : 1;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
117 uint64_t ignored : 1;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
118 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
119 uint64_t ignored2 : 4;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
120 // 12 bits so far
30
0148f55bfe24 Added static asserts and fixed pages
windel
parents: 29
diff changeset
121 uint64_t address : 40; // address of page table.
29
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
122 uint64_t ignored3 : 11;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
123 uint64_t xd : 1; // execute disable
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
124 } PDE_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 // Page directory:
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
127 typedef struct
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
128 {
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
129 PDE_t table[512];
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
130 uint64_t physicalAddress;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
131 } PD_t;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
132
30
0148f55bfe24 Added static asserts and fixed pages
windel
parents: 29
diff changeset
133
29
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
134 typedef struct
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
135 {
30
0148f55bfe24 Added static asserts and fixed pages
windel
parents: 29
diff changeset
136 unsigned present : 1;
29
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
137 uint64_t rw : 1;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
138 uint64_t us : 1; // user or supervisor
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
139 uint64_t pwt : 1;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
140 uint64_t pcd : 1; // page cache disable
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
141 uint64_t accessed : 1;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
142 uint64_t dirty : 1;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
143 uint64_t pat : 1; // memory type?
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
144 uint64_t g : 1; // Global?
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
145 uint64_t ignored : 3;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
146
30
0148f55bfe24 Added static asserts and fixed pages
windel
parents: 29
diff changeset
147 uint64_t address : 40;
29
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
148 uint64_t ignored2 : 11;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
149 uint64_t xd : 1;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
150 } page_t;
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 _Static_assert(sizeof(page_t) == 8, "sizeof(page_t) != 8");
0148f55bfe24 Added static asserts and fixed pages
windel
parents: 29
diff changeset
153 _Static_assert(sizeof(PDE_t) == 8, "sizeof(PDE_t) != 8");
0148f55bfe24 Added static asserts and fixed pages
windel
parents: 29
diff changeset
154 _Static_assert(sizeof(PDPTE_t) == 8, "sizeof(PDPTE_t) != 8");
0148f55bfe24 Added static asserts and fixed pages
windel
parents: 29
diff changeset
155 _Static_assert(sizeof(PML4E_t) == 8, "sizeof(PML4E_t) != 8");
0148f55bfe24 Added static asserts and fixed pages
windel
parents: 29
diff changeset
156
29
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
157 // Page table:
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
158 typedef struct
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
159 {
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
160 page_t table[512];
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
161 uint64_t physicalAddress;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
162 } PT_t;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
163
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
164 // Make memmap a PML4 type:
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
165 typedef PML4_t memmap_t;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
166
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
167 // Task related types:
24
d8627924d40d Split up in more files and reboot command
windel
parents: 20
diff changeset
168 typedef struct
d8627924d40d Split up in more files and reboot command
windel
parents: 20
diff changeset
169 {
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
170 char name[32]; // Name of the console
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
171 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
172 } console_t;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
173
25
d3c4bf3720a3 Beginning of multitasking
windel
parents: 24
diff changeset
174 typedef struct task_t {
d3c4bf3720a3 Beginning of multitasking
windel
parents: 24
diff changeset
175 struct task_t* next;
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
176 uint32_t kstack;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
177 uint32_t ustack;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
178
29
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
179 // For task switching:
25
d3c4bf3720a3 Beginning of multitasking
windel
parents: 24
diff changeset
180 uint64_t cr3;
d3c4bf3720a3 Beginning of multitasking
windel
parents: 24
diff changeset
181 uint64_t rip;
d3c4bf3720a3 Beginning of multitasking
windel
parents: 24
diff changeset
182 uint64_t rsp;
d3c4bf3720a3 Beginning of multitasking
windel
parents: 24
diff changeset
183 uint64_t rbp;
d3c4bf3720a3 Beginning of multitasking
windel
parents: 24
diff changeset
184
d3c4bf3720a3 Beginning of multitasking
windel
parents: 24
diff changeset
185 uint32_t pid;
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
186 uint32_t parent;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
187 uint32_t owner;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
188 uint32_t groups;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
189 uint32_t timetorun;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
190 uint32_t sleep;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
191 uint32_t priority;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
192 uint32_t filehandle;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
193 char naam[32];
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
194
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
195 console_t *console;
25
d3c4bf3720a3 Beginning of multitasking
windel
parents: 24
diff changeset
196 } task_t;
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
197
29
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
198 // Variable argument list things:
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
199 #define va_start(v,l) __builtin_va_start(v,l)
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
200 #define va_end(v) __builtin_va_end(v)
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
201 #define va_arg(v,l) __builtin_va_arg(v,l)
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
202 typedef __builtin_va_list va_list;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
203
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
204 /* Global variables */
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
205 extern uint64_t kernel_end;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
206 extern uint64_t placement_address;
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
207
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
208 /* Procedures */
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
209
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
210 // memory functions:
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
211 // TODO: remove some redundant API functions:
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
212 void init_heap();
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
213 void init_memory(uint64_t total_mem_size);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
214 page_t* get_page(uint64_t address, memmap_t*);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
215 void* kmalloc(uint64_t size);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
216 void kfree(void* ptr);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
217 void* kmalloc_int(uint64_t size);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
218 void* kmalloc_aligned_int(uint64_t size);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
219 void mappage(uint64_t address);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
220 void loadPageTable(void* tableAddress);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
221 void switch_mapping(memmap_t* mapping);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
222 void enablePaging();
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
223
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
224 // task related functions:
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
225 void initialize_tasking();
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
226 void new_task();
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
227 void task_scheduler();
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
228
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
229 // STDout funcs:
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
230 void printf(const char* fmt, ... );
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
231 void memset(void* ptr, uint8_t value, uint64_t num);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
232 void memcpy(void* dst, void* src, uint64_t num);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
233 int strncmp(const char* s1, const char* s2, int size);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
234
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
235 // Screen related:
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
236 void clear_screen();
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
237 void init_screen();
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
238 void print_string(const char *);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
239 void set_cursor(int newrow, int newcol);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
240 void get_cursor(int *therow, int *thecol);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
241 void set_color(int forecolor, int backcolor);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
242
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
243 // For IO ports:
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
244 uint8_t inb(uint16_t);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
245 uint16_t inw(uint16_t);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
246 void outb(uint16_t, uint8_t);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
247
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
248 // Interrupt functions:
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
249 void setupIDT(void);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
250 void PICremap(void);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
251 void loadIDT(void);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
252
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
253 // ASM helper:
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
254 uint64_t read_rip();
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
255
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
256 // Helpers:
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
257 void halt(void);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
258 void panic(char *msg);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
259 void reboot(void);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
260 void magicBochsBreak();
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
261 void doCPUID(int eax, int *ebx, int *ecx, int *edx);
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 // Keyboard driver:
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
264 void keyboardDriverUpdate(unsigned char scancode);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
265 void getline(char *buffer, int len);
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 // Timer:
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
268 void timerDriverUpdate(void);
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
269 uint64_t getTimeMS();
28
47b7df514243 Moved Makefiles
windel
parents: 26
diff changeset
270
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
271 #endif
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
272