From 092c5d520de99599af55bf3c4b823fa1f8c947df Mon Sep 17 00:00:00 2001 From: Nigel Date: Sat, 23 Oct 2021 12:26:15 +0100 Subject: [PATCH] Added option to create an iso --- .gitignore | 5 +++ Makefile | 23 +++++++++--- src/grub.cfg | 3 ++ src/kernel/bootcheck.h | 73 +++++++++++++++++++++++++++++++++++++ src/kernel/kernel.cpp | 81 ++++++------------------------------------ src/kernel/kernel.h | 3 ++ 6 files changed, 114 insertions(+), 74 deletions(-) create mode 100644 src/grub.cfg create mode 100644 src/kernel/bootcheck.h diff --git a/.gitignore b/.gitignore index a897a63..3ac905f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,8 @@ build CON .vscode +isodir/ +root/ +*.iso +*.img + diff --git a/Makefile b/Makefile index 56af78b..79558ac 100644 --- a/Makefile +++ b/Makefile @@ -19,12 +19,27 @@ OBJ_LINK_LIST = $(CRTI_OBJ) $(CRTBEGIN_OBJ) $(OFILES) $(CRTEND_OBJ) $(CRTN_OBJ) INTERNAL_OBJS = $(CRTI_OBJ) $(OFILES) $(CRTN_OBJ) -all: clean build +all: clean build clean_up -build: build_kernel run +build: build_kernel -run: - $(EMULATOR) -kernel $(BUILD_DIR)/myos.bin -serial file:CON -vga std -monitor stdio -display gtk -m 2G -cpu core2duo -drive file=demodisk.img + + +clean_iso: + if [[ -a isodir/* ]] ; then rm isodir/* -d ; fi + if [ -f barinkOS.iso ] ; then rm barinkOS.iso ; fi + +iso: clean_iso build + mkdir -p isodir/boot/grub + cp build/myos.bin isodir/boot/myos.bin + cp src/grub.cfg isodir/boot/grub/grub.cfg + grub-mkrescue -o barinkOS.iso isodir + +clean_up: + rm build/*.o + +test: + $(EMULATOR) -kernel $(BUILD_DIR)/myos.bin -serial file:CON -vga std -monitor stdio -display gtk -m 2G -cpu core2duo build_kernel: $(OBJ_LINK_LIST) diff --git a/src/grub.cfg b/src/grub.cfg new file mode 100644 index 0000000..40431b9 --- /dev/null +++ b/src/grub.cfg @@ -0,0 +1,3 @@ +menuentry "BarinkOS"{ + multiboot /boot/myos.bin +} diff --git a/src/kernel/bootcheck.h b/src/kernel/bootcheck.h new file mode 100644 index 0000000..21268c0 --- /dev/null +++ b/src/kernel/bootcheck.h @@ -0,0 +1,73 @@ +#pragma once +#include "multiboot.h" +#define CHECK_FLAG(flags, bit) ((flags) & (1 <<(bit))) + +extern "C" { + #include "arch/i386/tty/kterm.h" +} + + + +void CheckMBT ( multiboot_info_t* mbt ){ + /* Set MBI to the addresss of the multiboot information structure*/ + multiboot_info_t * mbi = (multiboot_info_t *) mbt; + + /* Print out the flags */ + printf("flags = 0x%x\n", (unsigned) mbi->flags); + + /* Are mem_* valid? */ + if ( CHECK_FLAG(mbi->flags,0)){ + printf("mem_lower = %uKB, mem_upper = %uKB\n"); + } + + /* is boot device valid ? */ + if (CHECK_FLAG (mbi->flags, 1)){ + printf("boot_device = 0x0%x\n", (unsigned) mbi->boot_device); + } + + /* is the command line passed? */ + if (CHECK_FLAG ( mbi->flags,2)){ + printf("cmdline = %s\n", (char *) mbi->cmdline); + } + + /* Are mods_* valid? */ + if(CHECK_FLAG ( mbi->flags, 3)){ + multiboot_module_t *mod; + int i; + + printf("mods count = %d, mods_addr = 0x%x\n", (int) mbi->mods_count, (int) mbi->mods_addr); + + for(i = 0, mod = (multiboot_module_t *) mbi->mods_addr; i < mbi->mods_count; i++ , mod++){ + printf(" mod start = 0x%x, mod_end = 0x%x, cmdline = %s\n", (unsigned) mod->mod_start, (unsigned) mod->mod_end, (char*) mod->cmdline); + } + } + + /* Bits 4 and 5 are mutually exclusive! */ + if (CHECK_FLAG (mbi->flags, 4) && CHECK_FLAG(mbi->flags, 5)){ + printf("Both bits 4 and 5 are set.\n"); + return; + } + + /* Is the symbol table of a.out valid? */ + if (CHECK_FLAG(mbi->flags, 4)){ + multiboot_aout_symbol_table_t *multiboot_aout_sym = &(mbi->u.aout_sym); + + printf( "multiboot_aout_symbol_table: tabsize = 0x%0x, strsize = 0x%x, addr = 0x%x\n", + (unsigned) multiboot_aout_sym->tabsize, + (unsigned) multiboot_aout_sym->strsize, + (unsigned) multiboot_aout_sym->addr); + + } + + /* Is the section header table of ELF valid? */ + if (CHECK_FLAG(mbi->flags, 5)){ + multiboot_elf_section_header_table_t *multiboot_elf_sec = &(mbi->u.elf_sec); + + printf("multiboot_elf_sec: num = %u, size = 0x%x, addr = 0x%x, shnd = 0x%x\n", + (unsigned) multiboot_elf_sec->num, (unsigned) multiboot_elf_sec->size, + (unsigned) multiboot_elf_sec->addr, (unsigned) multiboot_elf_sec->shndx); + + } + + +} \ No newline at end of file diff --git a/src/kernel/kernel.cpp b/src/kernel/kernel.cpp index df18683..6fee847 100644 --- a/src/kernel/kernel.cpp +++ b/src/kernel/kernel.cpp @@ -1,92 +1,33 @@ #include "kernel.h" - +#include "arch/i386/gdt/gdtc.h" extern "C" { - multiboot_info_t *mbi; void early_main(unsigned long magic, unsigned long addr){ - /** initialize terminal interface */ kterm_init(); - - - + if (magic != MULTIBOOT_BOOTLOADER_MAGIC){ - printf("Invalid magic number: 0x%x\n", (unsigned) magic); + printf("Invalid magic number: 0x%x\n", magic); return; } - /* Set MBI to the addresss of the multiboot information structure*/ - mbi = (multiboot_info_t *) addr; + CheckMBT( (multiboot_info_t *) addr); - /* Print out the flags */ - printf("flags = 0x%x\n", (unsigned) mbi->flags); - /* Are mem_* valid? */ - if ( CHECK_FLAG(mbi->flags,0)){ - printf("mem_lower = %uKB, mem_upper = %uKB\n"); - } - - /* is boot device valid ? */ - if (CHECK_FLAG (mbi->flags, 1)){ - printf("boot_device = 0x0%x\n", (unsigned) mbi->boot_device); - } - - /* is the command line passed? */ - if (CHECK_FLAG ( mbi->flags,2)){ - printf("cmdline = %s\n", (char *) mbi->cmdline); - } - - /* Are mods_* valid? */ - if(CHECK_FLAG ( mbi->flags, 3)){ - multiboot_module_t *mod; - int i; - - printf("mods count = %d, mods_addr = 0x%x\n", (int) mbi->mods_count, (int) mbi->mods_addr); - - for(i = 0, mod = (multiboot_module_t *) mbi->mods_addr; i < mbi->mods_count; i++ , mod++){ - printf(" mod start = 0x%x, mod_end = 0x%x, cmdline = %s\n", (unsigned) mod->mod_start, (unsigned) mod->mod_end, (char*) mod->cmdline); - } - } - - /* Bits 4 and 5 are mutually exclusive! */ - if (CHECK_FLAG (mbi->flags, 4) && CHECK_FLAG(mbi->flags, 5)){ - printf("Both bits 4 and 5 are set.\n"); - return; - } - - /* Is the symbol table of a.out valid? */ - if (CHECK_FLAG(mbi->flags, 4)){ - multiboot_aout_symbol_table_t *multiboot_aout_sym = &(mbi->u.aout_sym); - - printf( "multiboot_aout_symbol_table: tabsize = 0x%0x, strsize = 0x%x, addr = 0x%x\n", - (unsigned) multiboot_aout_sym->tabsize, - (unsigned) multiboot_aout_sym->strsize, - (unsigned) multiboot_aout_sym->addr); - - } - - /* Is the section header table of ELF valid? */ - if (CHECK_FLAG(mbi->flags, 5)){ - multiboot_elf_section_header_table_t *multiboot_elf_sec = &(mbi->u.elf_sec); - - printf("multiboot_elf_sec: num = %u, size = 0x%x, addr = 0x%x, shnd = 0x%x\n", - (unsigned) multiboot_elf_sec->num, (unsigned) multiboot_elf_sec->size, - (unsigned) multiboot_elf_sec->addr, (unsigned) multiboot_elf_sec->shndx); - - } + multiboot_info_t* mbt = (multiboot_info_t*) addr; + // Map the kernel + //initPhysicalMemoryManager(); // AAAAAH memory map, Yes please! /* Are mmap_* valid? */ - if (CHECK_FLAG(mbi->flags, 6)){ - multiboot_memory_map_t *mmap; + if (CHECK_FLAG(mbt->flags, 6)){ + multiboot_memory_map_t *mmap = (multiboot_memory_map_t*) mbt->mmap_addr; printf("mmap_addr = 0x%x, mmap_length = 0x%x\n", - (unsigned) mbi->mmap_addr, (unsigned) mbi->mmap_length); + (unsigned) mbt->mmap_addr, (unsigned) mbt->mmap_length); - for (mmap = (multiboot_memory_map_t *) mbi->mmap_addr; - (unsigned long) mmap < mbi->mmap_addr + mbi->mmap_length; - mmap = (multiboot_memory_map_t *) ((unsigned long) mmap + mmap->size + sizeof(mmap->size))){ + for (mmap; (unsigned long) mmap < mbt->mmap_addr + mbt->mmap_length; mmap = (multiboot_memory_map_t *) ((unsigned long) mmap + mmap->size + sizeof(mmap->size))){ printf( "size = 0x%x, base_addr = 0x%x%08x, length = 0x%x%08x, type = 0x%x\n", diff --git a/src/kernel/kernel.h b/src/kernel/kernel.h index b9b22bf..51fcb9a 100644 --- a/src/kernel/kernel.h +++ b/src/kernel/kernel.h @@ -2,10 +2,13 @@ extern "C" { #include "../libc/include/string.h" #include "arch/i386/tty/kterm.h" + #include "pmm.h" } #include "multiboot.h" +#include "bootcheck.h" #include "arch/i386/idt/idt.h" + #include "MMU.h" #include "io.h" #include "time.h"