Max OS 0.3
Loading...
Searching...
No Matches
kernel.cpp
Go to the documentation of this file.
1
9#include <cstdint>
10#include <common/logger.h>
14#include <drivers/driver.h>
15#include <drivers/video/vesa.h>
16#include <gui/desktop.h>
17#include <processes/scheduler.h>
18#include <system/cpu.h>
19#include <system/syscalls.h>
21#include <memory/physical.h>
22#include <memory/virtual.h>
23#include <filesystem/vfs.h>
25#include <tests/test.h>
26
27using namespace MaxOS;
28using namespace MaxOS::common;
29using namespace MaxOS::drivers;
30using namespace MaxOS::drivers::peripherals;
31using namespace MaxOS::drivers::video;
32using namespace MaxOS::drivers::clock;
33using namespace MaxOS::drivers::console;
34using namespace MaxOS::hardwarecommunication;
35using namespace MaxOS::gui;
36using namespace MaxOS::processes;
37using namespace MaxOS::system;
38using namespace MaxOS::memory;
39using namespace MaxOS::filesystem;
40using namespace MaxOS::tests;
41
42extern "C" void call_constructors();
43extern "C" uint8_t core_boot_info[];
44
48extern "C" [[noreturn]] void core_main() {
49
50 auto info = (core_boot_info_t*) (core_boot_info);
51 info->activated = true;
53
54 // Make sure the correct core is being setup
55 ASSERT(info->id == core->id, "Current setup core isn't the core expected");
56 Logger::DEBUG() << "Core " << core->id << " now in higher half \n";
57
58 // Set up the core
59 core->init();
60 asm("sti");
61
62 // Wait to be scheduled
63 while(true)
64 asm("nop");
65}
66
73extern "C" [[noreturn]] void kernel_main(unsigned long addr, unsigned long magic) {
74
76
79 Logger::INFO() << "MaxOS Booted Successfully\n";
80
81 Logger::HEADER() << "Stage {1}: System Initialisation\n";
82 Multiboot multiboot(addr, magic);
85
86 Logger::HEADER() << "Stage {1.1}: Memory Initialisation\n";
89 MemoryManager memory_manager(&vmm);
90
91 Logger::HEADER() << "Stage {1.2}: Console Initialisation\n";
93 VESABootConsole console(&vesa);
94
95 Logger::HEADER() << "Stage {2}: Hardware Initialisation\n";
97 CPU cpu(&gdt, &multiboot);
98 Clock kernel_clock(&cpu.apic, 1);
100 driver_manager.add_driver(&kernel_clock);
101 driver_manager.find_drivers();
102 uint32_t reset_wait_time = driver_manager.reset_devices();
103
104 Logger::HEADER() << "Stage {3}: Device Finalisation\n";
105 interrupts.activate();
106 kernel_clock.calibrate();
108 driver_manager.initialise_drivers();
109 driver_manager.activate_drivers();
110 cpu.init_cores();
111
112 Logger::HEADER() << "Stage {4}: System Finalisation\n";
113 GlobalScheduler scheduler(multiboot);
116 console.finish();
118
119 // Idle loop (read Idle.md)
120 while(true)
121 asm("hlt");
122
123}
124
A class that handles logging messages to the console and files.
Definition logger.h:44
static Logger DEBUG()
Gets active logger set to DEBUG level.
Definition logger.cpp:193
static Logger INFO()
Gets active logger set to info level.
Definition logger.cpp:171
static Logger HEADER()
Gets active logger set to task level.
Definition logger.cpp:159
Stores the left, top, width and height of a rectangle.
Definition rectangle.h:22
Manages the drivers, handles the adding and removing of drivers.
Definition driver.h:69
A driver for the serial output.
Definition serial.h:24
Driver for the APIC clock.
Definition clock.h:123
Driver for the VESA Console during boot, handles the printing of characters and strings to the screen...
Definition vesaboot.h:30
void finish() const
Cleans up the boot console.
Definition vesaboot.cpp:349
Driver for the VESA video controller, handles the rendering of pixels to the screen using VESA.
Definition vesa.h:26
A resource registry for both Files & Directories.
Definition vfsresource.h:72
Combines all the filesystems across the partitions on each disk into a single filesystems and exposes...
Definition vfs.h:25
Handles all interrupts and passes them to the correct handler.
Definition interrupts.h:84
Handles memory allocation and deallocation.
Manages the physical memory of the system such as what pages are allocated/free and mapping of virtua...
Definition physical.h:108
Manages the virtual memory of the system and provides functions to allocate and free memory in the vi...
Definition virtual.h:96
The global scheduler that manages all processes and threads across all cores.
Definition scheduler.h:26
static void activate()
Activates each core's scheduler.
Manages the CPU and its cores.
Definition cpu.h:253
static Core * executing_core()
Gets the core that is currently executing.
Definition cpu.cpp:623
Sets up the GDT in the CPU.
Definition gdt.h:53
Parses and provides access to Multiboot 2 information.
Definition multiboot.h:518
Provides an API for userspace applications to interact with the kernel.
Definition syscalls.h:58
Defines Central Processing Unit (CPU) structures and functions for managing CPU state and features.
struct PACKED MaxOS::system::CoreBootInfo core_boot_info_t
Alias for CoreBootInfo struct.
Defines a Desktop class for managing the GUI desktop, handling mouse and keyboard events,...
Defines a base Driver class and DriverManager for managing drivers.
Defines a InterruptManager and InterruptHandler for managing hardware and software interrupts.
uint8_t core_boot_info[]
The boot info structure for the core being started.
Definition kernel.cpp:43
void kernel_main(unsigned long addr, unsigned long magic)
The main kernel entry point. Initialises all core systems and starts the scheduler.
Definition kernel.cpp:73
void call_constructors()
Calls the C++ static constructors.
Definition cplusplus.cpp:39
void core_main()
The main entry point for secondary cores. Sets up the core and waits to be scheduled.
Definition kernel.cpp:48
Defines a Logger class for logging messages with different severity levels to multiple output streams...
#define ASSERT(condition, format,...)
If the specified condition is not met then the kernel will crash with the specified message.
Definition logger.h:100
Defines a MemoryManager class for handling memory allocation and deallocation.
Defines a PhysicalMemoryManager class for managing physical memory allocation and deallocation of pag...
Defines a GlobalScheduler and Scheduler for managing processes and threads.
Defines a SerialConsole driver for serial output.
Defines the SyscallManager class for handling system calls from userspace applications.
Defines a basic test class for MaxOS.
Defines a Video Electronics Standards Association (VESA) video driver for handling pixel rendering us...
Defines the VESABootConsole driver for handling console output during boot using an VESA framebuffer.
Defines a Virtual File System (VFS) class for managing multiple filesystems and providing a unified i...
Defines VFSResource classes for wrapping File and Directory objects as Resources in the Virtual File ...
Defines a VirtualMemoryManager class for managing virtual memory allocation and mapping to physical m...