boucane/src/boot/multiboot2.cc
2021-04-24 10:09:43 +02:00

55 lines
No EOL
1.3 KiB
C++

#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;
}