diff --git a/kernel/src/arch/i386/entry-stivale2.c b/kernel/src/arch/i386/entry-stivale2.c index 7c604ea..e480111 100644 --- a/kernel/src/arch/i386/entry-stivale2.c +++ b/kernel/src/arch/i386/entry-stivale2.c @@ -3,6 +3,7 @@ #include #include "../../main.h" +#include void stivale2_main(struct stivale2_struct *info); @@ -23,6 +24,8 @@ struct stivale2_header header2 = { }; void stivale2_main(struct stivale2_struct *info) { + parse_stivale2(info); + char *argv[3] = {"stivale2", info->bootloader_brand, info->bootloader_version}; kmain(3, argv); } diff --git a/kernel/src/arch/x86/stivale2-parse.c b/kernel/src/arch/x86/stivale2-parse.c new file mode 100644 index 0000000..b0b5e92 --- /dev/null +++ b/kernel/src/arch/x86/stivale2-parse.c @@ -0,0 +1,156 @@ +#include +#include + +#include + +void parse_stivale2(struct stivale2_struct *info) { + struct stivale2_tag *tag = (struct stivale2_tag*)(info->tags); + while(tag != 0) { + switch(tag->identifier) { + case STIVALE2_STRUCT_TAG_CMDLINE_ID: { + struct stivale2_struct_tag_cmdline *cmd = (struct stivale2_struct_tag_cmdline*)tag; + printf("cmdline: %s\n", (const char*)cmd->cmdline); + break; + } + case STIVALE2_STRUCT_TAG_MEMMAP_ID: { + struct stivale2_struct_tag_memmap *m = (struct stivale2_struct_tag_memmap *)tag; + printf("Memmap (%d entries):\n", m->entries); + for (size_t i = 0; i < m->entries; i++) { + struct stivale2_mmap_entry me = m->memmap[i]; + printf("\t[%x+%x] %x\n", me.base, me.length, me.type); + } + break; + } + case STIVALE2_STRUCT_TAG_FRAMEBUFFER_ID: { + struct stivale2_struct_tag_framebuffer *f = (struct stivale2_struct_tag_framebuffer *)tag; + printf("Framebuffer tag: %dx%d at %x\n", f->framebuffer_width, f->framebuffer_height, f->framebuffer_addr); + printf("\tPitch: %d\n", f->framebuffer_pitch); + printf("\tBPP: %d\n", f->framebuffer_bpp); + printf("\tMemory model: %d\n", f->memory_model); + printf("\tRed mask size: %d\n", f->red_mask_size); + printf("\tRed mask size: %d\n", f->red_mask_shift); + printf("\tGreen mask size: %d\n", f->green_mask_size); + printf("\tGreen mask size: %d\n", f->green_mask_shift); + printf("\tBlue mask size: %d\n", f->blue_mask_size); + printf("\tBlue mask size: %d\n", f->blue_mask_shift); + break; + } + case STIVALE2_STRUCT_TAG_MODULES_ID: { + struct stivale2_struct_tag_modules *m = (struct stivale2_struct_tag_modules *)tag; + printf("Modules tag (count: %d):", m->module_count); + for (size_t i = 0; i < m->module_count; i++) { + struct stivale2_module *me = &m->modules[i]; + printf("\t[%x+%x] %s", me->begin, me->end, me->string); + } + break; + } + case STIVALE2_STRUCT_TAG_RSDP_ID: { + struct stivale2_struct_tag_rsdp *r = (struct stivale2_struct_tag_rsdp *)tag; + printf("RSDP: %x\n", r->rsdp); + break; + } + case STIVALE2_STRUCT_TAG_EPOCH_ID: { + struct stivale2_struct_tag_epoch *e = (struct stivale2_struct_tag_epoch *)tag; + printf("Epoch: %d\n", e->epoch); + break; + } + case STIVALE2_STRUCT_TAG_FIRMWARE_ID: { + struct stivale2_struct_tag_firmware *f = (struct stivale2_struct_tag_firmware *)tag; + printf("Firmware flags: %x\n", f->flags); + break; + } + case STIVALE2_STRUCT_TAG_SMP_ID: { + struct stivale2_struct_tag_smp *s = (struct stivale2_struct_tag_smp *)tag; + printf("SMP tag (cores: %d, bootstrap: %d, flags: %x)\n", s->cpu_count, s->bsp_lapic_id, s->flags); + for (size_t i = 0; i < s->cpu_count; i++) { + struct stivale2_smp_info *in = &s->smp_info[i]; + printf("\tprocID: %d, lapicID: %d, stack: %x, goto: %x, extra: %x\n", + in->processor_id, in->lapic_id, in->target_stack, in->goto_address, in->extra_argument); + } + break; + } + default: + printf("ERR: Unidentifier tag %x\n", tag->identifier); + } + + tag = (struct stivale2_tag *)tag->next; + } +} + +// void parse_stivale2(struct stivale2_struct *info) { +// struct stivale2_tag *tag = (struct stivale2_tag*)(info->tags); +// while(tag != 0) { +// switch(tag->identifier) { +// case STIVALE2_STRUCT_TAG_CMDLINE_ID: { +// struct stivale2_struct_tag_cmdline *cmd = (struct stivale2_struct_tag_cmdline*)tag; +// printf("cmdline: %s\n", (const char*)cmd->cmdline); +// break; +// } +// case STIVALE2_STRUCT_TAG_MEMMAP_ID: { +// struct stivale2_struct_tag_memmap *m = (struct stivale2_struct_tag_memmap *)tag; +// printf("Memmap (%d entries):\n", m->entries); +// for (size_t i = 0; i < m->entries; i++) { +// struct stivale2_mmap_entry me = m->memmap[i]; +// printf("\t[%x+%x] %x\n", me.base, me.length, me.type); +// } +// break; +// } +// case STIVALE2_STRUCT_TAG_FRAMEBUFFER_ID: { +// struct stivale2_struct_tag_framebuffer *f = (struct stivale2_struct_tag_framebuffer *)tag; +// printf("Framebuffer tag: %dx%d at %x\n", f->framebuffer_width, f->framebuffer_height, f->framebuffer_addr); +// printf("\tPitch: %d\n", f->framebuffer_pitch); +// printf("\tBPP: %d\n", f->framebuffer_bpp); +// printf("\tMemory model: %d\n", f->memory_model); +// printf("\tRed mask size: %d\n", f->red_mask_size); +// printf("\tRed mask size: %d\n", f->red_mask_shift); +// printf("\tGreen mask size: %d\n", f->green_mask_size); +// printf("\tGreen mask size: %d\n", f->green_mask_shift); +// printf("\tBlue mask size: %d\n", f->blue_mask_size); +// printf("\tBlue mask size: %d\n", f->blue_mask_shift); +// break; +// } +// case STIVALE2_STRUCT_TAG_MODULES_ID: { +// struct stivale2_struct_tag_modules *m = (struct stivale2_struct_tag_modules *)tag; +// printf("Modules tag (count: %d):", m->module_count); +// for (size_t i = 0; i < m->module_count; i++) { +// struct stivale2_module me = m->modules[i]; +// printf("\t[%x+%x] %s", me.begin, me.end, me.string); +// } +// break; +// } +// case STIVALE2_STRUCT_TAG_RSDP_ID: { +// struct stivale2_struct_tag_rsdp *r = (struct stivale2_struct_tag_rsdp *)tag; +// puts("RSDP tag:"); +// printf("\tRSDP: %x\n", r->rsdp); +// break; +// } +// case STIVALE2_STRUCT_TAG_EPOCH_ID: { +// struct stivale2_struct_tag_epoch *e = (struct stivale2_struct_tag_epoch *)tag; +// printf("Epoch: %x", e->epoch); +// break; +// } +// case STIVALE2_STRUCT_TAG_FIRMWARE_ID: { +// struct stivale2_struct_tag_firmware *f = (struct stivale2_struct_tag_firmware *)tag; +// printf("Firmware flags: %x\n", f->flags); +// break; +// } +// case STIVALE2_STRUCT_TAG_SMP_ID: { +// struct stivale2_struct_tag_smp *s = (struct stivale2_struct_tag_smp *)tag; +// printf("SMP tag (cores: %d, bootstrap: %d, flags: %x)\n", s->cpu_count, s->bsp_lapic_id, s->flags); +// for (size_t i = 0; i < s->cpu_count; i++) { +// struct stivale2_smp_info *in = &s->smp_info[i]; +// printf("\tProcessor ID: %d\n", in->processor_id); +// printf("\tLAPIC ID: %d\n", in->lapic_id); +// printf("\tTarget Stack: %x\n", in->target_stack); +// printf("\tGOTO Address: %x\n", in->goto_address); +// printf("\tExtra Argument: %x\n", in->extra_argument); +// } +// break; +// } +// default: +// printf("ERR: Unidentifier tag %x\n", tag->identifier); +// } + +// tag = (struct stivale2_tag *)tag->next; +// } +// } diff --git a/kernel/src/arch/x86/stivale2-parse.h b/kernel/src/arch/x86/stivale2-parse.h new file mode 100644 index 0000000..4b6759d --- /dev/null +++ b/kernel/src/arch/x86/stivale2-parse.h @@ -0,0 +1 @@ +void parse_stivale2(struct stivale2_struct *info); diff --git a/kernel/src/arch/x86_64/entry-stivale2.c b/kernel/src/arch/x86_64/entry-stivale2.c index 7dcaae5..e60f1eb 100644 --- a/kernel/src/arch/x86_64/entry-stivale2.c +++ b/kernel/src/arch/x86_64/entry-stivale2.c @@ -3,6 +3,7 @@ #include #include "../../main.h" +#include "arch/x86/stivale2-parse.h" static uint8_t stack[4096] = {0}; void stivale2_main(struct stivale2_struct *info); @@ -24,6 +25,8 @@ struct stivale2_header header2 = { }; void stivale2_main(struct stivale2_struct *info) { + parse_stivale2(info); + char *argv[3] = {"stivale2", info->bootloader_brand, info->bootloader_version}; kmain(3, argv); }