2022-09-02 19:09:51 +00:00
|
|
|
#include "lib/string.h"
|
|
|
|
#include "definitions.h"
|
|
|
|
|
|
|
|
#include "prekernel/bootstructure.h"
|
|
|
|
|
|
|
|
#include "drivers/vga/VBE.h"
|
|
|
|
#include "drivers/pit/pit.h"
|
|
|
|
|
|
|
|
#include "memory/PhysicalMemoryManager.h"
|
|
|
|
#include "memory/VirtualMemoryManager.h"
|
|
|
|
#include "memory/KernelHeap.h"
|
|
|
|
#include "memory/gdt/gdtc.h"
|
|
|
|
|
|
|
|
#include "interrupts/idt/idt.h"
|
|
|
|
|
|
|
|
#include "io.h"
|
|
|
|
#include "cpu.h"
|
|
|
|
#include "serial.h"
|
|
|
|
#include "time.h"
|
|
|
|
|
|
|
|
#include "terminal/kterm.h"
|
|
|
|
|
|
|
|
#include "supervisorterminal/superVisorTerminal.h"
|
|
|
|
|
|
|
|
extern "C" void kernel_main ();
|
|
|
|
void ProcessBootInfo();
|
|
|
|
|
|
|
|
extern "C" void kernel_main ()
|
2022-08-22 19:16:34 +00:00
|
|
|
{
|
2022-09-02 19:09:51 +00:00
|
|
|
/*
|
|
|
|
* Show a little banner for cuteness
|
|
|
|
*/
|
|
|
|
printf("|=== BarinkOS ===|\n");
|
|
|
|
startSuperVisorTerminal();
|
|
|
|
}
|
2022-09-01 14:11:35 +00:00
|
|
|
|
2022-08-22 19:16:34 +00:00
|
|
|
|
2022-09-02 19:09:51 +00:00
|
|
|
extern "C" void early_main()
|
|
|
|
{
|
2022-08-17 23:26:49 +00:00
|
|
|
init_serial();
|
2022-09-02 23:00:17 +00:00
|
|
|
|
2022-09-02 19:09:51 +00:00
|
|
|
kterm_init();
|
2022-09-03 15:27:29 +00:00
|
|
|
printf("Allocated blocks: 0x%x \n", GetUsedBlocks());
|
2022-09-02 23:00:17 +00:00
|
|
|
|
2022-09-02 19:09:51 +00:00
|
|
|
initGDT();
|
2022-08-18 22:44:52 +00:00
|
|
|
init_idt();
|
2022-09-02 23:00:17 +00:00
|
|
|
|
2022-08-18 22:44:52 +00:00
|
|
|
// Enable interrupts
|
|
|
|
asm volatile("STI");
|
2022-09-02 19:09:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
initHeap();
|
2022-08-18 23:05:10 +00:00
|
|
|
|
2022-09-03 15:27:29 +00:00
|
|
|
printf("TRY ALLOCATING 4 BYTES\n");
|
|
|
|
uint32_t* MyVariable = (uint32_t*) malloc(4); // allocate 4 bytes using my heap
|
|
|
|
free(MyVariable);
|
|
|
|
|
2022-09-02 19:09:51 +00:00
|
|
|
// test heap allocation
|
2022-09-03 15:27:29 +00:00
|
|
|
|
2022-09-02 19:09:51 +00:00
|
|
|
struct KernelInfo {
|
|
|
|
int bar;
|
|
|
|
bool foo;
|
|
|
|
};
|
2022-08-23 19:35:19 +00:00
|
|
|
|
2022-09-02 19:09:51 +00:00
|
|
|
KernelInfo* MyInfo = (KernelInfo*) malloc(sizeof(KernelInfo));
|
2022-08-23 19:35:19 +00:00
|
|
|
|
2022-09-02 19:09:51 +00:00
|
|
|
MyInfo->bar = 6;
|
|
|
|
MyInfo->foo = false;
|
2022-09-03 15:27:29 +00:00
|
|
|
printf("bar contains %d\n", MyInfo->bar);
|
2022-09-02 19:09:51 +00:00
|
|
|
free(MyInfo);
|
2022-09-03 15:27:29 +00:00
|
|
|
|
|
|
|
|
2022-08-23 19:35:19 +00:00
|
|
|
|
2022-09-02 19:09:51 +00:00
|
|
|
printf("Enable Protected mode and jump to kernel main\n");
|
2022-08-23 19:35:19 +00:00
|
|
|
|
2022-09-02 19:09:51 +00:00
|
|
|
asm volatile("mov %cr0, %eax ");
|
|
|
|
asm volatile("or $1, %eax");
|
|
|
|
asm volatile("mov %eax, %cr0"); // re-enable protected mode ?
|
2022-08-23 19:35:19 +00:00
|
|
|
|
2022-09-02 19:09:51 +00:00
|
|
|
pit_initialise();
|
2021-12-28 18:47:32 +00:00
|
|
|
|
|
|
|
|
2022-09-02 19:09:51 +00:00
|
|
|
kernel_main();
|
|
|
|
|
2022-09-02 23:00:17 +00:00
|
|
|
}
|