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>
13#include <console/serial.h>
14#include <console/framebuffer.h>
15#include <processes/scheduler.h>
16#include <system/cpu.h>
17#include <system/syscalls.h>
19#include <memory/physical.h>
20#include <memory/virtual.h>
21
22using namespace MaxOS;
23using namespace MaxOS::common;
24using namespace MaxOS::console;
25using namespace MaxOS::hardwarecommunication;
26using namespace MaxOS::processes;
27using namespace MaxOS::system;
28using namespace MaxOS::memory;
29
30extern "C" void call_constructors();
31extern "C" uint8_t core_boot_info[];
32
36extern "C" [[noreturn]] void core_main()
37{
38 auto info = (core_boot_info_t*)(core_boot_info);
39 info->activated = true;
40 auto core = CPU::executing_core();
41
42 // Make sure the correct core is being setup
43 ASSERT(info->id == core->id, "Current setup core isn't the core expected");
44 Logger::DEBUG() << "Core " << core->id << " now in higher half \n";
45
46 // Set up the core
47 core->init();
48 asm("sti");
49
50 // Wait to be scheduled
51 while (true)
52 CPU::halt();
53}
54
61extern "C" [[noreturn]] void kernel_main(unsigned long addr, unsigned long magic)
62{
64
65 Logger logger;
66 SerialConsole serial_console(&logger);
67 Logger::INFO() << "MaxOS Booted Successfully\n";
68
69 Logger::HEADER() << "Stage {1}: System Initialisation\n";
70 Multiboot multiboot(addr, magic);
72 InterruptManager interrupts;
73 ExceptionHandlers exceptions;
74
75 Logger::HEADER() << "Stage {1.1}: Memory Initialisation\n";
76 PhysicalMemoryManager pmm(&multiboot);
78 MemoryManager memory_manager(&vmm);
79
80 Logger::HEADER() << "Stage {1.2}: Console Initialisation\n";
81 FramebufferConsole console(multiboot.framebuffer());
82
83 Logger::HEADER() << "Stage {2}: Hardware Initialisation\n";
84 CPU cpu(&gdt, &multiboot);
85 Clock kernel_clock(&cpu.apic, 1);
86 interrupts.activate();
87 kernel_clock.calibrate();
88 cpu.init_cores();
89
90 Logger::HEADER() << "Stage {3}: Userspace Initialisation\n";
91 SyscallManager syscalls;
92 GlobalScheduler scheduler(multiboot);
93 console.finish();
95
96 // Idle loop (read Idle.md)
97 while (true)
98 asm("hlt");
99
100} // I use maxos btw
101
115// Finish LibDriver
116//
117// init flow:
118// % parse multiboot for init program, fileserver and ramdisk
119// % schedule init program and fileserver
120// % init program tells fileserver to load & parse ramdisk
121// % init (via fileserver) reads ramdisk and starts all under "run/*" (driver manager, disks)
122// = = =
123// % - DM scans via selectors and builds list of initial devices
124// % - DM trys to init those devices (early ret, no fs)
125// % - DM loop:
126// % - handle rpc calls (new devices added (ie from usb), device messages such as init suc/fail)
127// % - - try init devices that havent been started
128// = = =
129// % - FS loop:
130// % - - handle rpc calls (io [x], dm event: new disk [ ])
131// - - - try parse new disk
132// = = =
133// % - DSK instance get info (args, fail then req from manager)
134// % - DSK init
135// % - DSK tell DM init done
136// % - DSK run server()
137// = = =
138// - any future steps
139// % mark self as unschedulable forever
A class that handles logging messages to the console and files.
Definition logger.h:51
static LogRecord DEBUG()
Gets the active logger for debug logs.
Definition logger.cpp:204
static LogRecord HEADER()
Gets the active logger for headers.
Definition logger.cpp:231
static LogRecord INFO()
Gets the active logger for info logs.
Definition logger.cpp:195
Handles the printing of characters and strings to the screen using a framebuffer.
void finish() const
Cleans up the boot console.
A driver for the serial output.
Definition serial.h:25
Driver for the APIC clock.
Definition clock.h:124
void calibrate(uint64_t ms_per_tick=1)
Configures the APIC clock to fire an interrupt at a specified interval in milliseconds.
Definition clock.cpp:118
Holds and instantiates the CPU exception handlers.
Definition interrupts.h:176
Handles all interrupts and passes them to the correct handler.
Definition interrupts.h:200
void activate()
Activates the interrupt manager and starts interrupts (also deactivates the current interrupt manager...
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:107
Manages the virtual memory of the system and provides functions to allocate and free memory in the vi...
Definition virtual.h:104
The global scheduler that manages all processes and threads across all cores.
Definition scheduler.h:28
static void activate()
Activates each core's scheduler.
Definition scheduler.cpp:95
Manages the CPU and its cores.
Definition cpu.h:256
static void halt()
Halts the CPU indefinitely.
Definition cpu.cpp:275
void init_cores()
Wake up all the cores.
Definition cpu.cpp:588
hardwarecommunication::AdvancedProgrammableInterruptController apic
The APIC interface for the CPU.
Definition cpu.h:264
static Core * executing_core()
Gets the core that is currently executing.
Definition cpu.cpp:660
Sets up the GDT in the CPU.
Definition gdt.h:53
Parses and provides access to Multiboot 2 information.
Definition multiboot.h:518
multiboot_tag_framebuffer * framebuffer()
Get the framebuffer tag.
Provides an API for userspace applications to interact with the kernel.
Definition syscalls.h:59
Defines drivers for the Programmable Interval Timer (PIT) and APIC Clock.
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 the VESABootConsole driver for handling console output during boot using an VESA framebuffer.
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:31
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:61
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:36
Defines a Logger class for logging messages with different severity levels to multiple output streams...
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 VirtualMemoryManager class for managing virtual memory allocation and mapping to physical m...