aboutsummaryrefslogtreecommitdiff
path: root/src/boot
diff options
context:
space:
mode:
Diffstat (limited to 'src/boot')
-rw-r--r--src/boot/multiboot.c54
-rw-r--r--src/boot/multiboot.h41
2 files changed, 95 insertions, 0 deletions
diff --git a/src/boot/multiboot.c b/src/boot/multiboot.c
new file mode 100644
index 0000000..0309eb0
--- /dev/null
+++ b/src/boot/multiboot.c
@@ -0,0 +1,54 @@
+#include "multiboot.h"
+#include "utils/mem.h"
+
+/// See boot.S
+extern u8* MB_INFO;
+
+char mb_load_tag(char **data, char type){
+ char *c_info_size=MB_INFO;
+ char *c_tag_type=c_info_size+8;
+ char *c_tag_size=c_info_size+12;
+
+ int max_size=*((int*)c_info_size);
+ while(((int)c_tag_type-(int)MB_INFO)<max_size){
+ int tag_type=*((int*)c_tag_type);
+ int tag_size=*((int*)c_tag_size);
+ if(tag_type==type){
+ *data=c_tag_type;
+ return 0;
+ }
+
+ c_tag_type=c_tag_type+tag_size+4;
+ // Skip padding for 64 bits
+ int p=c_tag_type;
+ while((p & 0x7) != 0)
+ p++;
+ // Assign address after padding
+ c_tag_type=p;
+ c_tag_size=c_tag_type+4;
+
+ }
+ return 1;
+}
+char mb_load_bl_name(MBI_TAG_BL_NAME *data){
+ char *to_load;
+ if(!mb_load_tag(&to_load,2)){
+ memcpy(to_load,data,8);
+ to_load+=8;
+ data->name=to_load;
+ return 0;
+ }
+ return 1;
+}
+
+char mb_load_fb(MBI_TAG_FB *data){
+ char *to_load;
+ if(!mb_load_tag(&to_load,8)){
+ asm("mov %0, %%ecx;aa:;jmp aa;"::"r"(to_load));
+ memcpy(to_load,data,8);
+ to_load+=8;
+ memcpy(to_load,&(data->framebuffer_addr),8);
+ return 0;
+ }
+ return 1;
+}
diff --git a/src/boot/multiboot.h b/src/boot/multiboot.h
new file mode 100644
index 0000000..010f60b
--- /dev/null
+++ b/src/boot/multiboot.h
@@ -0,0 +1,41 @@
+#ifndef MULTIBOOT_H
+#define MULTIBOOT_H
+
+#include "utils/types.h"
+
+typedef struct MBI_TAG_HEADER {
+ u32 type;
+ u32 size;
+} __attribute__((packed)) MBI_TAG_HEADER;
+
+typedef struct MBI_TAG_BL_NAME {
+ MBI_TAG_HEADER header;
+ u8 *name;
+} __attribute__((packed)) MBI_TAG_BL_NAME;
+
+typedef struct MBI_TAG_FB {
+ MBI_TAG_HEADER header;
+ u64 framebuffer_addr;
+ u32 framebuffer_pitch;
+ u32 framebuffer_width;
+ u32 framebuffer_height;
+ u8 framebuffer_bpp;
+ u8 framebuffer_type;
+ u8 reserved;
+ u8 *color_infos;
+}__attribute__((packed)) MBI_TAG_FB;
+
+/**
+ * Parse Bootloader boot information structure
+ */
+char mb_load_tag(char **data, char type);
+/**
+ * Search for Bootloader name
+ */
+char mb_load_bl_name(MBI_TAG_BL_NAME *data);
+/**
+ * Search for FrameBuffer structure (TODO: Finish)
+ */
+char mb_load_fb(MBI_TAG_FB *data);
+
+#endif \ No newline at end of file