aboutsummaryrefslogtreecommitdiff
path: root/src/boot
diff options
context:
space:
mode:
Diffstat (limited to 'src/boot')
-rw-r--r--src/boot/boot.S6
-rw-r--r--src/boot/multiboot2.cc55
-rw-r--r--src/boot/multiboot2.hpp8
3 files changed, 66 insertions, 3 deletions
diff --git a/src/boot/boot.S b/src/boot/boot.S
index d90c4d8..5e4d82c 100644
--- a/src/boot/boot.S
+++ b/src/boot/boot.S
@@ -43,11 +43,11 @@ mb_header_end:
.section .text
.code32 # Require since grub do not enable long mode
-MB_INFO:
- .int 0xABCDEF # Will contains the Multiboot2 information data structure address
+MB_INFO: # Will contains the Multiboot2 information data structure address
+ .long 0x0
_start:
-mov %ebx,(MB_INFO)
+mov %ebx, (MB_INFO)
# Zeroing the .bss section
mov $_bss_start, %eax
mov $_bss_end, %ebx
diff --git a/src/boot/multiboot2.cc b/src/boot/multiboot2.cc
new file mode 100644
index 0000000..b0e8c14
--- /dev/null
+++ b/src/boot/multiboot2.cc
@@ -0,0 +1,55 @@
+#include "multiboot2.hpp"
+#include "libs/string.hpp"
+#include "libs/stdio.hpp"
+
+u32* mb2_find_tag(u32 *mb2_info_addr, char type){
+ u32 size=(u32)mb2_info_addr[0];
+
+ char *location=((char*)mb2_info_addr)+8; // Goto first tag
+ char *start=(char*)mb2_info_addr;
+
+ while((location-start) < size){
+ // Goto next 64bit align address
+ while(((u64)location&0x7) != 0)
+ location++;
+ // Parse type
+ u32 cur_type=((u32*)location)[0];
+ u32 cur_size=((u32*)location)[1];
+
+ if(cur_type==type){
+ return (u32*)location;
+ }
+ location+=cur_size;
+ }
+
+ return 0;
+}
+
+char mb2_find_bootloader_name(u32* mb2_info_addr, char *return_name){
+ u32* addr=mb2_find_tag(mb2_info_addr,2);
+ if(addr){
+ u32 size=addr[1];
+ memcpy(addr+2, return_name, size);
+ return 1;
+ }
+ return 0;
+}
+char mb2_find_new_rsdp(u32* mb2_info_addr, u64 *return_addr, u32 *return_size){
+ u32* addr=mb2_find_tag(mb2_info_addr,15);
+ if(addr){
+ *return_size=addr[1];
+ *return_addr=(u64)addr+2;
+ return 1;
+ }
+ return 0;
+}
+
+char mb2_find_old_rsdp(u32* mb2_info_addr, u64 *return_addr, u32 *return_size){
+ u32* addr=mb2_find_tag(mb2_info_addr,14);
+ if(addr){
+ *return_size=addr[1];
+ *return_addr=(u64)addr+2;
+ return 1;
+ }
+ return 0;
+} \ No newline at end of file
diff --git a/src/boot/multiboot2.hpp b/src/boot/multiboot2.hpp
new file mode 100644
index 0000000..da12e5f
--- /dev/null
+++ b/src/boot/multiboot2.hpp
@@ -0,0 +1,8 @@
+#pragma once
+
+#include "core/types.hpp"
+
+u32* mb2_find_tag(u32 *mb2_info_addr, char type);
+char mb2_find_bootloader_name(u32* mb2_info_addr, char *return_name);
+char mb2_find_new_rsdp(u32* mb2_info_addr, u64 *return_addr, u32 *return_size);
+char mb2_find_old_rsdp(u32* mb2_info_addr, u64 *return_addr, u32 *return_size); \ No newline at end of file