2022-07-18 09:59:04 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <kernel/tty.h>
|
2022-07-18 18:14:20 +03:00
|
|
|
#include <kernel/gdt.h>
|
2022-07-18 22:37:43 +03:00
|
|
|
#include <kernel/paging.h>
|
2022-07-19 17:01:31 +03:00
|
|
|
#include <kernel/pic.h>
|
2022-07-18 22:37:43 +03:00
|
|
|
|
|
|
|
#define PAGE_ENTRIES 1024
|
|
|
|
#define PAGE_SIZE 4 * PAGE_ENTRIES
|
|
|
|
|
|
|
|
void paging_init() {
|
|
|
|
uint32_t page_dir[PAGE_ENTRIES] __attribute__((aligned(PAGE_SIZE)));
|
|
|
|
for(int i = 0; i < PAGE_ENTRIES; i++) {
|
|
|
|
// Supervisor: only kernel-mode can access
|
|
|
|
// Write Enabled: Can be both read and written to
|
|
|
|
// Not Present: Page table not present
|
|
|
|
page_dir[i] = 0x00000002;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t first_page_table[PAGE_ENTRIES] __attribute__((aligned(PAGE_SIZE)));
|
|
|
|
for(unsigned int i = 0; i < PAGE_ENTRIES; i++) {
|
|
|
|
// As the address is page aligned, it will leave 12 bits zeroed,
|
|
|
|
// which are used by the attributes.
|
|
|
|
first_page_table[i] = (i * 0x1000) | 3; // attr: supervisor, r/w, present
|
|
|
|
}
|
|
|
|
|
|
|
|
page_dir[0] = ((unsigned int)first_page_table) | 3; //attr: supervisor, r/w, present
|
|
|
|
|
|
|
|
load_page_dir(page_dir);
|
|
|
|
enable_paging();
|
|
|
|
}
|
2022-07-18 09:59:04 +03:00
|
|
|
|
|
|
|
void kernel_main(void) {
|
2022-07-18 22:37:43 +03:00
|
|
|
paging_init();
|
|
|
|
printf("Hello, kernel World!\n");
|
|
|
|
printf("String test: %s\n", "HELLOOOOO");
|
|
|
|
printf("Float test: %.10f\n", 0.123456789);
|
|
|
|
printf("Int test: %d\n", 747474);
|
|
|
|
printf("Hex test: 0x%x\n", 0xDEADBEEF);
|
2022-07-18 16:42:25 +03:00
|
|
|
printf("And now for 0.1 + 0.2...... which is: %.17f\n", 0.1 + 0.2);
|
2022-07-19 17:01:31 +03:00
|
|
|
|
|
|
|
unsigned char c, cold;
|
|
|
|
for(;;){
|
|
|
|
cold = c;
|
|
|
|
c = inb(0x60);
|
|
|
|
if (cold != c)
|
|
|
|
putchar(c);
|
|
|
|
outb(0x20, 0x20);
|
|
|
|
}
|
|
|
|
|
2022-07-19 10:45:38 +03:00
|
|
|
asm("cli; hlt");
|
2022-07-18 09:59:04 +03:00
|
|
|
}
|