2024-07-11 08:56:52 +02:00
|
|
|
#include <kernel/tty.h>
|
2024-08-05 00:59:07 +02:00
|
|
|
#include <kernel/idt.h>
|
|
|
|
#include <kernel/elf.h>
|
2024-08-09 23:16:20 +02:00
|
|
|
#include <kernel/pic.h>
|
2024-08-10 03:49:28 +02:00
|
|
|
#include <kernel/heap.h>
|
2024-08-22 13:41:51 +02:00
|
|
|
#include <kernel/task.h>
|
2024-11-27 21:57:18 +01:00
|
|
|
#include <kernel/paging.h>
|
2024-08-10 03:49:28 +02:00
|
|
|
|
|
|
|
#include <debugging.h>
|
2024-07-16 22:51:41 +02:00
|
|
|
|
|
|
|
/* Check if the compiler thinks you are targeting the wrong operating system. */
|
|
|
|
#if defined(__linux__)
|
|
|
|
#error "You are not using a cross-compiler, you will most certainly run into trouble"
|
|
|
|
#endif
|
2024-07-11 08:56:52 +02:00
|
|
|
|
2024-08-05 00:59:07 +02:00
|
|
|
uint8_t program[] = {
|
2025-06-27 23:55:47 +02:00
|
|
|
0xcd, 0x80, // int $0x80
|
2025-02-26 01:42:35 +01:00
|
|
|
0xff, 0xe1, // jmp *%ecx
|
2024-08-05 00:59:07 +02:00
|
|
|
};
|
|
|
|
|
2025-06-30 06:17:56 +02:00
|
|
|
uint8_t data[] = "Hello From Userspace\n";
|
|
|
|
|
|
|
|
uint8_t kernel_data[] = "Hello From Kernelspace\n";
|
|
|
|
// uint8_t data[] = {};
|
2024-11-27 21:57:18 +01:00
|
|
|
|
2024-07-11 08:56:52 +02:00
|
|
|
void kernel_main(void)
|
|
|
|
{
|
2024-08-13 15:24:17 +02:00
|
|
|
/* Initialize terminal interface */
|
|
|
|
terminal_initialize();
|
2024-11-27 21:57:18 +01:00
|
|
|
terminal_writestring("Hello from Kernelspace\n");
|
2024-08-05 00:59:07 +02:00
|
|
|
|
|
|
|
idt_init();
|
2024-08-22 13:41:51 +02:00
|
|
|
init_pic();
|
2024-08-10 03:49:28 +02:00
|
|
|
heap_init();
|
|
|
|
|
2024-08-22 13:41:51 +02:00
|
|
|
setup_tasks();
|
2024-11-27 21:57:18 +01:00
|
|
|
setup_paging();
|
2024-08-22 13:41:51 +02:00
|
|
|
|
2025-06-27 23:55:47 +02:00
|
|
|
terminal_writestring("Woaw\n");
|
|
|
|
|
2025-07-01 12:48:05 +02:00
|
|
|
struct Heap_Block* block;
|
|
|
|
void* code_page = alloc_page(1, &block);
|
|
|
|
void* data_page = alloc_page(1, &block);
|
|
|
|
|
|
|
|
set_page_table_entry(0, code_page);
|
|
|
|
set_page_table_entry(0x00400000, data_page);
|
|
|
|
|
|
|
|
*(int*)0 = 1;
|
|
|
|
|
|
|
|
while (true) { }
|
|
|
|
|
|
|
|
/* asm("cli");
|
2024-08-22 13:41:51 +02:00
|
|
|
|
2024-11-27 21:57:18 +01:00
|
|
|
run_program(program, sizeof(program), data, sizeof(data));
|
2024-08-22 13:41:51 +02:00
|
|
|
|
2025-02-25 18:48:58 +01:00
|
|
|
asm("sti");
|
2025-02-26 01:42:35 +01:00
|
|
|
asm("int $0x20");
|
2025-02-25 18:48:58 +01:00
|
|
|
|
2025-06-27 23:55:47 +02:00
|
|
|
int i = 0;
|
2024-08-22 13:41:51 +02:00
|
|
|
while (true) {
|
2025-06-27 23:55:47 +02:00
|
|
|
i += 1;
|
|
|
|
if (i == 1 << 16) {
|
2025-06-30 06:17:56 +02:00
|
|
|
asm("mov %0, %%eax" :: "r" (kernel_data) );
|
|
|
|
asm("mov $0, %ecx");
|
2025-06-30 05:56:03 +02:00
|
|
|
asm("int $0x80");
|
2025-06-27 23:55:47 +02:00
|
|
|
i = 0;
|
|
|
|
}
|
2025-07-01 12:48:05 +02:00
|
|
|
} */
|
2024-07-11 08:56:52 +02:00
|
|
|
}
|