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 <hardwarecommunication/clock.h>
#include <console/serial.h>
#include <console/framebuffer.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>

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 36 of file kernel.cpp.

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}
static LogRecord DEBUG()
Gets the active logger for debug logs.
Definition logger.cpp:204
static void halt()
Halts the CPU indefinitely.
Definition cpu.cpp:275
static Core * executing_core()
Gets the core that is currently executing.
Definition cpu.cpp:660
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:31

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

◆ 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 61 of file kernel.cpp.

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
A class that handles logging messages to the console and files.
Definition logger.h:51
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.
A driver for the serial output.
Definition serial.h:25
Driver for the APIC clock.
Definition clock.h:124
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
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:59
void call_constructors()
Calls the C++ static constructors.
Definition cplusplus.cpp:39

References MaxOS::hardwarecommunication::InterruptManager::activate(), MaxOS::processes::GlobalScheduler::activate(), MaxOS::system::CPU::apic, MaxOS::hardwarecommunication::Clock::calibrate(), call_constructors(), MaxOS::console::FramebufferConsole::finish(), MaxOS::system::Multiboot::framebuffer(), MaxOS::Logger::HEADER(), MaxOS::Logger::INFO(), and MaxOS::system::CPU::init_cores().

Variable Documentation

◆ core_boot_info

uint8_t core_boot_info[]

The boot info structure for the core being started.

Definition at line 31 of file kernel.cpp.

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