1
0
Fork 0
mirror of https://github.com/tailix/kernel.git synced 2025-09-18 22:57:59 -04:00

Some refactoring

This commit is contained in:
Braiden Vasco 2017-11-01 14:45:01 +00:00
parent 2c8e2ae0ed
commit 20d4f7fb95
4 changed files with 25 additions and 24 deletions

View file

@ -24,8 +24,8 @@ stack_top:
.type _start, @function .type _start, @function
_start: _start:
mov $stack_top, %esp mov $stack_top, %esp
push %ebx // unsigned long multiboot_info push %ebx
push %eax // unsigned int multiboot_magic push %eax
call main call main
cli cli
1: 1:

View file

@ -4,22 +4,11 @@
#include "gdt.h" #include "gdt.h"
#include "idt.h" #include "idt.h"
void main(unsigned int multiboot_magic, unsigned long multiboot_info) void main(struct KernelMQ_Multiboot_Info multiboot_info)
{ {
logger_initialize(); logger_initialize();
if (multiboot_magic == KERNELMQ_MULTIBOOT_2_MAGIC) {
logger_info("Loaded with Multiboot-compliant bootloader, specification version 2.");
print_multiboot_info(multiboot_info); print_multiboot_info(multiboot_info);
}
else if (multiboot_magic == KERNELMQ_MULTIBOOT_1_MAGIC) {
logger_fail("Loaded with Multiboot-compliant bootloader, but specification version 1.");
return;
}
else {
logger_fail("Loaded with no Multiboot-compliant bootloader.");
return;
}
logger_info("Kernel initialization started."); logger_info("Kernel initialization started.");

View file

@ -2,21 +2,31 @@
#include "console.h" #include "console.h"
#define MULTIBOOT_1_MAGIC 0x2BADB002
#define MULTIBOOT_2_MAGIC 0x36d76289
static void itoa(char *buf, int base, int d); static void itoa(char *buf, int base, int d);
static void printf(const char *format, ...); static void printf(const char *format, ...);
void print_multiboot_info(unsigned long addr) void print_multiboot_info(struct KernelMQ_Multiboot_Info info)
{ {
struct multiboot_tag *tag; if (info.magic == MULTIBOOT_1_MAGIC) {
printf("Old Multiboot specification does not support modules.");
return;
}
if (addr & 7) if (info.magic != MULTIBOOT_2_MAGIC) {
{ printf("No Multiboot-compliant bootloader is not supported.");
printf("Unaligned mbi: 0x%x\n", addr); return;
}
if (info.addr & 7) {
printf("Unaligned Multiboot information address: 0x%x\n", info.addr);
return; return;
} }
for ( for (
tag = (struct multiboot_tag *) (addr + 8); struct multiboot_tag *tag = (struct multiboot_tag *) (info.addr + 8);
tag->type != MULTIBOOT_TAG_TYPE_END; tag->type != MULTIBOOT_TAG_TYPE_END;
tag = (struct multiboot_tag *) ((multiboot_uint8_t *) tag + ((tag->size + 7) & ~7))) tag = (struct multiboot_tag *) ((multiboot_uint8_t *) tag + ((tag->size + 7) & ~7)))
{ {

View file

@ -5,10 +5,12 @@
extern "C" { extern "C" {
#endif #endif
void print_multiboot_info(unsigned long addr); struct KernelMQ_Multiboot_Info {
unsigned long magic;
unsigned long addr;
};
#define KERNELMQ_MULTIBOOT_1_MAGIC 0x2BADB002 void print_multiboot_info(struct KernelMQ_Multiboot_Info info);
#define KERNELMQ_MULTIBOOT_2_MAGIC 0x36d76289
/* /*
* How many bytes from the start of the file we search for the header. * How many bytes from the start of the file we search for the header.