mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 17:12:43 +00:00 
			
		
		
		
	Kernel: Put code in the aarch64 init.cpp file into the Kernel namespace
This commit is contained in:
		
							parent
							
								
									9282e0db16
								
							
						
					
					
						commit
						18cad73b01
					
				
					 1 changed files with 87 additions and 83 deletions
				
			
		|  | @ -20,9 +20,6 @@ | ||||||
| #include <Kernel/KSyms.h> | #include <Kernel/KSyms.h> | ||||||
| #include <Kernel/Panic.h> | #include <Kernel/Panic.h> | ||||||
| 
 | 
 | ||||||
| static void draw_logo(); |  | ||||||
| static u32 query_firmware_version(); |  | ||||||
| 
 |  | ||||||
| struct TrapFrame { | struct TrapFrame { | ||||||
|     u64 x[31];     // Saved general purpose registers
 |     u64 x[31];     // Saved general purpose registers
 | ||||||
|     u64 spsr_el1;  // Save Processor Status Register, EL1
 |     u64 spsr_el1;  // Save Processor Status Register, EL1
 | ||||||
|  | @ -31,78 +28,7 @@ struct TrapFrame { | ||||||
|     u64 sp_el0;    // EL0 stack pointer
 |     u64 sp_el0;    // EL0 stack pointer
 | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| extern "C" [[noreturn]] void halt(); |  | ||||||
| extern "C" [[noreturn]] void init(); |  | ||||||
| extern "C" void exception_common(TrapFrame const* const trap_frame); | extern "C" void exception_common(TrapFrame const* const trap_frame); | ||||||
| 
 |  | ||||||
| typedef void (*ctor_func_t)(); |  | ||||||
| extern ctor_func_t start_heap_ctors[]; |  | ||||||
| extern ctor_func_t end_heap_ctors[]; |  | ||||||
| extern ctor_func_t start_ctors[]; |  | ||||||
| extern ctor_func_t end_ctors[]; |  | ||||||
| 
 |  | ||||||
| ALWAYS_INLINE static Kernel::Processor& bootstrap_processor() |  | ||||||
| { |  | ||||||
|     alignas(Kernel::Processor) static u8 bootstrap_processor_storage[sizeof(Kernel::Processor)]; |  | ||||||
|     return (Kernel::Processor&)bootstrap_processor_storage; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| extern "C" [[noreturn]] void init() |  | ||||||
| { |  | ||||||
|     dbgln("Welcome to Serenity OS!"); |  | ||||||
|     dbgln("Imagine this being your ideal operating system."); |  | ||||||
|     dbgln("Observed deviations from that ideal are shortcomings of your imagination."); |  | ||||||
|     dbgln(); |  | ||||||
| 
 |  | ||||||
|     new (&bootstrap_processor()) Kernel::Processor(); |  | ||||||
|     bootstrap_processor().initialize(0); |  | ||||||
| 
 |  | ||||||
|     // We call the constructors of kmalloc.cpp separately, because other constructors in the Kernel
 |  | ||||||
|     // might rely on being able to call new/kmalloc in the constructor. We do have to run the
 |  | ||||||
|     // kmalloc constructors, because kmalloc_init relies on that.
 |  | ||||||
|     for (ctor_func_t* ctor = start_heap_ctors; ctor < end_heap_ctors; ctor++) |  | ||||||
|         (*ctor)(); |  | ||||||
|     kmalloc_init(); |  | ||||||
| 
 |  | ||||||
|     for (ctor_func_t* ctor = start_ctors; ctor < end_ctors; ctor++) |  | ||||||
|         (*ctor)(); |  | ||||||
| 
 |  | ||||||
|     Kernel::load_kernel_symbol_table(); |  | ||||||
| 
 |  | ||||||
|     auto firmware_version = query_firmware_version(); |  | ||||||
|     dbgln("Firmware version: {}", firmware_version); |  | ||||||
| 
 |  | ||||||
|     dbgln("Initialize MMU"); |  | ||||||
|     Kernel::init_prekernel_page_tables(); |  | ||||||
| 
 |  | ||||||
|     auto& framebuffer = Kernel::Framebuffer::the(); |  | ||||||
|     if (framebuffer.initialized()) { |  | ||||||
|         draw_logo(); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     dbgln("Enter loop"); |  | ||||||
| 
 |  | ||||||
|     auto& timer = Kernel::Timer::the(); |  | ||||||
|     u64 start_musec = 0; |  | ||||||
|     for (;;) { |  | ||||||
|         u64 now_musec; |  | ||||||
|         while ((now_musec = timer.microseconds_since_boot()) - start_musec < 1'000'000) |  | ||||||
|             ; |  | ||||||
|         start_musec = now_musec; |  | ||||||
|         dbgln("Timer: {}", now_musec); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| // FIXME: Share this with the Intel Prekernel.
 |  | ||||||
| extern size_t __stack_chk_guard; |  | ||||||
| size_t __stack_chk_guard; |  | ||||||
| extern "C" [[noreturn]] void __stack_chk_fail(); |  | ||||||
| 
 |  | ||||||
| void __stack_chk_fail() |  | ||||||
| { |  | ||||||
|     Kernel::Processor::halt(); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| extern "C" void exception_common(TrapFrame const* const trap_frame) | extern "C" void exception_common(TrapFrame const* const trap_frame) | ||||||
| { | { | ||||||
|     constexpr bool print_stack_frame = true; |     constexpr bool print_stack_frame = true; | ||||||
|  | @ -122,12 +48,88 @@ extern "C" void exception_common(TrapFrame const* const trap_frame) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| class QueryFirmwareVersionMboxMessage : Kernel::Mailbox::Message { | typedef void (*ctor_func_t)(); | ||||||
|  | extern ctor_func_t start_heap_ctors[]; | ||||||
|  | extern ctor_func_t end_heap_ctors[]; | ||||||
|  | extern ctor_func_t start_ctors[]; | ||||||
|  | extern ctor_func_t end_ctors[]; | ||||||
|  | 
 | ||||||
|  | // FIXME: Share this with the Intel Prekernel.
 | ||||||
|  | extern size_t __stack_chk_guard; | ||||||
|  | size_t __stack_chk_guard; | ||||||
|  | extern "C" [[noreturn]] void __stack_chk_fail(); | ||||||
|  | 
 | ||||||
|  | void __stack_chk_fail() | ||||||
|  | { | ||||||
|  |     Kernel::Processor::halt(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | namespace Kernel { | ||||||
|  | 
 | ||||||
|  | static void draw_logo(); | ||||||
|  | static u32 query_firmware_version(); | ||||||
|  | 
 | ||||||
|  | extern "C" [[noreturn]] void halt(); | ||||||
|  | extern "C" [[noreturn]] void init(); | ||||||
|  | 
 | ||||||
|  | ALWAYS_INLINE static Processor& bootstrap_processor() | ||||||
|  | { | ||||||
|  |     alignas(Processor) static u8 bootstrap_processor_storage[sizeof(Processor)]; | ||||||
|  |     return (Processor&)bootstrap_processor_storage; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | extern "C" [[noreturn]] void init() | ||||||
|  | { | ||||||
|  |     dbgln("Welcome to Serenity OS!"); | ||||||
|  |     dbgln("Imagine this being your ideal operating system."); | ||||||
|  |     dbgln("Observed deviations from that ideal are shortcomings of your imagination."); | ||||||
|  |     dbgln(); | ||||||
|  | 
 | ||||||
|  |     new (&bootstrap_processor()) Processor(); | ||||||
|  |     bootstrap_processor().initialize(0); | ||||||
|  | 
 | ||||||
|  |     // We call the constructors of kmalloc.cpp separately, because other constructors in the Kernel
 | ||||||
|  |     // might rely on being able to call new/kmalloc in the constructor. We do have to run the
 | ||||||
|  |     // kmalloc constructors, because kmalloc_init relies on that.
 | ||||||
|  |     for (ctor_func_t* ctor = start_heap_ctors; ctor < end_heap_ctors; ctor++) | ||||||
|  |         (*ctor)(); | ||||||
|  |     kmalloc_init(); | ||||||
|  | 
 | ||||||
|  |     for (ctor_func_t* ctor = start_ctors; ctor < end_ctors; ctor++) | ||||||
|  |         (*ctor)(); | ||||||
|  | 
 | ||||||
|  |     load_kernel_symbol_table(); | ||||||
|  | 
 | ||||||
|  |     auto firmware_version = query_firmware_version(); | ||||||
|  |     dbgln("Firmware version: {}", firmware_version); | ||||||
|  | 
 | ||||||
|  |     dbgln("Initialize MMU"); | ||||||
|  |     init_prekernel_page_tables(); | ||||||
|  | 
 | ||||||
|  |     auto& framebuffer = Framebuffer::the(); | ||||||
|  |     if (framebuffer.initialized()) { | ||||||
|  |         draw_logo(); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     dbgln("Enter loop"); | ||||||
|  | 
 | ||||||
|  |     auto& timer = Timer::the(); | ||||||
|  |     u64 start_musec = 0; | ||||||
|  |     for (;;) { | ||||||
|  |         u64 now_musec; | ||||||
|  |         while ((now_musec = timer.microseconds_since_boot()) - start_musec < 1'000'000) | ||||||
|  |             ; | ||||||
|  |         start_musec = now_musec; | ||||||
|  |         dbgln("Timer: {}", now_musec); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | class QueryFirmwareVersionMboxMessage : Mailbox::Message { | ||||||
| public: | public: | ||||||
|     u32 version; |     u32 version; | ||||||
| 
 | 
 | ||||||
|     QueryFirmwareVersionMboxMessage() |     QueryFirmwareVersionMboxMessage() | ||||||
|         : Kernel::Mailbox::Message(0x0000'0001, 4) |         : Mailbox::Message(0x0000'0001, 4) | ||||||
|     { |     { | ||||||
|         version = 0; |         version = 0; | ||||||
|     } |     } | ||||||
|  | @ -136,12 +138,12 @@ public: | ||||||
| static u32 query_firmware_version() | static u32 query_firmware_version() | ||||||
| { | { | ||||||
|     struct __attribute__((aligned(16))) { |     struct __attribute__((aligned(16))) { | ||||||
|         Kernel::Mailbox::MessageHeader header; |         Mailbox::MessageHeader header; | ||||||
|         QueryFirmwareVersionMboxMessage query_firmware_version; |         QueryFirmwareVersionMboxMessage query_firmware_version; | ||||||
|         Kernel::Mailbox::MessageTail tail; |         Mailbox::MessageTail tail; | ||||||
|     } message_queue; |     } message_queue; | ||||||
| 
 | 
 | ||||||
|     if (!Kernel::Mailbox::the().send_queue(&message_queue, sizeof(message_queue))) { |     if (!Mailbox::the().send_queue(&message_queue, sizeof(message_queue))) { | ||||||
|         return 0xffff'ffff; |         return 0xffff'ffff; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -153,7 +155,7 @@ extern "C" const u32 serenity_boot_logo_size; | ||||||
| 
 | 
 | ||||||
| static void draw_logo() | static void draw_logo() | ||||||
| { | { | ||||||
|     Kernel::BootPPMParser logo_parser(reinterpret_cast<u8 const*>(&serenity_boot_logo_start), serenity_boot_logo_size); |     BootPPMParser logo_parser(reinterpret_cast<u8 const*>(&serenity_boot_logo_start), serenity_boot_logo_size); | ||||||
|     if (!logo_parser.parse()) { |     if (!logo_parser.parse()) { | ||||||
|         dbgln("Failed to parse boot logo."); |         dbgln("Failed to parse boot logo."); | ||||||
|         return; |         return; | ||||||
|  | @ -161,7 +163,7 @@ static void draw_logo() | ||||||
| 
 | 
 | ||||||
|     dbgln("Boot logo size: {} ({} x {})", serenity_boot_logo_size, logo_parser.image.width, logo_parser.image.height); |     dbgln("Boot logo size: {} ({} x {})", serenity_boot_logo_size, logo_parser.image.width, logo_parser.image.height); | ||||||
| 
 | 
 | ||||||
|     auto& framebuffer = Kernel::Framebuffer::the(); |     auto& framebuffer = Framebuffer::the(); | ||||||
|     auto fb_ptr = framebuffer.gpu_buffer(); |     auto fb_ptr = framebuffer.gpu_buffer(); | ||||||
|     auto image_left = (framebuffer.width() - logo_parser.image.width) / 2; |     auto image_left = (framebuffer.width() - logo_parser.image.width) / 2; | ||||||
|     auto image_right = image_left + logo_parser.image.width; |     auto image_right = image_left + logo_parser.image.width; | ||||||
|  | @ -173,12 +175,12 @@ static void draw_logo() | ||||||
|         for (u32 x = 0; x < framebuffer.width(); x++) { |         for (u32 x = 0; x < framebuffer.width(); x++) { | ||||||
|             if (x >= image_left && x < image_right && y >= image_top && y < image_bottom) { |             if (x >= image_left && x < image_right && y >= image_top && y < image_bottom) { | ||||||
|                 switch (framebuffer.pixel_order()) { |                 switch (framebuffer.pixel_order()) { | ||||||
|                 case Kernel::Framebuffer::PixelOrder::RGB: |                 case Framebuffer::PixelOrder::RGB: | ||||||
|                     fb_ptr[0] = logo_pixels[0]; |                     fb_ptr[0] = logo_pixels[0]; | ||||||
|                     fb_ptr[1] = logo_pixels[1]; |                     fb_ptr[1] = logo_pixels[1]; | ||||||
|                     fb_ptr[2] = logo_pixels[2]; |                     fb_ptr[2] = logo_pixels[2]; | ||||||
|                     break; |                     break; | ||||||
|                 case Kernel::Framebuffer::PixelOrder::BGR: |                 case Framebuffer::PixelOrder::BGR: | ||||||
|                     fb_ptr[0] = logo_pixels[2]; |                     fb_ptr[0] = logo_pixels[2]; | ||||||
|                     fb_ptr[1] = logo_pixels[1]; |                     fb_ptr[1] = logo_pixels[1]; | ||||||
|                     fb_ptr[2] = logo_pixels[0]; |                     fb_ptr[2] = logo_pixels[0]; | ||||||
|  | @ -201,3 +203,5 @@ static void draw_logo() | ||||||
|         fb_ptr += framebuffer.pitch() - framebuffer.width() * 4; |         fb_ptr += framebuffer.pitch() - framebuffer.width() * 4; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Timon Kruiper
						Timon Kruiper