Max OS 0.3
Loading...
Searching...
No Matches
kernel.cpp File Reference

The main kernel entry point for the bsp and other cores. Handles initialisation of all core systems. More...

#include <cstdint>
#include <common/logger.h>
#include <hardwarecommunication/interrupts.h>
#include <drivers/console/serial.h>
#include <drivers/console/vesaboot.h>
#include <drivers/driver.h>
#include <drivers/video/vesa.h>
#include <gui/desktop.h>
#include <processes/scheduler.h>
#include <system/cpu.h>
#include <system/syscalls.h>
#include <memory/memorymanagement.h>
#include <memory/physical.h>
#include <memory/virtual.h>
#include <filesystem/vfs.h>
#include <filesystem/vfsresource.h>
#include <tests/test.h>

Go to the source code of this file.

Functions

void call_constructors ()
 Calls the C++ static constructors.
 
void core_main ()
 The main entry point for secondary cores. Sets up the core and waits to be scheduled.
 
void kernel_main (unsigned long addr, unsigned long magic)
 The main kernel entry point. Initialises all core systems and starts the scheduler.
 

Variables

uint8_t core_boot_info []
 The boot info structure for the core being started.
 

Detailed Description

The main kernel entry point for the bsp and other cores. Handles initialisation of all core systems.

Date
2022
Author
Max Tyson

Definition in file kernel.cpp.

Function Documentation

◆ call_constructors()

void call_constructors ( )

Calls the C++ static constructors.

Calls the C++ static constructors.

Definition at line 39 of file cplusplus.cpp.

39 {
40 // Loop through and initialise all the global constructorsu
41 for (constructor* i = &start_ctors; i != &end_ctors; i++)
42 (*i)();
43}
constructor start_ctors
Pointer to the start of the constructors section.
Definition cplusplus.cpp:33
constructor end_ctors
Pointer to the end of the constructors section.
Definition cplusplus.cpp:34

References end_ctors, and start_ctors.

Referenced by kernel_main().

◆ core_main()

void core_main ( )

The main entry point for secondary cores. Sets up the core and waits to be scheduled.

Definition at line 48 of file kernel.cpp.

48 {
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}
static Logger DEBUG()
Gets active logger set to DEBUG level.
Definition logger.cpp:193
Stores the left, top, width and height of a rectangle.
Definition rectangle.h:22
static Core * executing_core()
Gets the core that is currently executing.
Definition cpu.cpp:623
struct PACKED MaxOS::system::CoreBootInfo core_boot_info_t
Alias for CoreBootInfo struct.
uint8_t core_boot_info[]
The boot info structure for the core being started.
Definition kernel.cpp:43
#define ASSERT(condition, format,...)
If the specified condition is not met then the kernel will crash with the specified message.
Definition logger.h:100

References ASSERT, core_boot_info, MaxOS::Logger::DEBUG(), and MaxOS::system::CPU::executing_core().

◆ kernel_main()

void kernel_main ( unsigned long  addr,
unsigned long  magic 
)

The main kernel entry point. Initialises all core systems and starts the scheduler.

Parameters
addrThe address of the multiboot info struct
magicThe multiboot magic number

Definition at line 73 of file kernel.cpp.

73 {
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}
A class that handles logging messages to the console and files.
Definition logger.h:44
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
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
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
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
void call_constructors()
Calls the C++ static constructors.
Definition cplusplus.cpp:39

References MaxOS::processes::GlobalScheduler::activate(), call_constructors(), MaxOS::drivers::console::VESABootConsole::finish(), MaxOS::Logger::HEADER(), and MaxOS::Logger::INFO().

Variable Documentation

◆ core_boot_info

uint8_t core_boot_info[]

The boot info structure for the core being started.

Definition at line 43 of file kernel.cpp.

Referenced by core_main(), MaxOS::system::CPU::init_cores(), and MaxOS::system::Core::wake_up().