diff --git a/README.md b/README.md index 5453062..ce7a580 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ # BlankOS -Rewritten monolithic, ring 0, lower-half, singletasking kernel for the x86 processor architecture, using GRUB 2 as bootloader. Emulation was tested on QEMU using Arch Linux 6.9.7-arch1-1, and on real hardware (UEFI and BIOS). +Rewritten megalithic, ring 0, lower-half, singletasking kernel for the x86 processor architecture (using 32-bit protected mode), with GRUB 2 as bootloader. Emulation was tested on QEMU using Arch Linux 6.9.7-arch1-1, and on real hardware (UEFI and BIOS). The long-term goal of this OS is to be capable of running user programs and having its own complete kernel C library so that users can write their own C programs and expand the system! ## Usage @@ -65,7 +65,7 @@ Two other documents are available to help you understand the project better. One - [X] Kernel-space utilities (shell, simple programs) - [ ] Filesystem (FAT32 or VFS ramdisk) - [ ] Changing the default VGA font -- [ ] Dynamic memory allocator (get memmap from GRUB?) +- [X] Dynamic memory allocator (get memmap from GRUB?) - [ ] Paging/Page Frame Allocation - [ ] TCP/IP Network stack - [ ] Getting to Ring-3 (userspace) diff --git a/grub.cfg b/grub.cfg index f0c868b..a42e11b 100644 --- a/grub.cfg +++ b/grub.cfg @@ -2,5 +2,6 @@ menuentry "Blank OS" { insmod all_video set gfxpayload=1024x768x32 multiboot2 /boot/kernel.elf + module2 /boot/initrd.tar boot } diff --git a/makefile b/makefile index c4b4871..c87007f 100644 --- a/makefile +++ b/makefile @@ -49,12 +49,16 @@ toolchain: wget $(TOOLCHAIN_SRC) tar xf $(TOOLCHAIN_FILE) -iso: kernel.elf +iso: kernel.elf initrd mkdir -p iso/boot/grub cp kernel.elf iso/boot/kernel.elf cp grub.cfg iso/boot/grub/grub.cfg grub-mkrescue iso -o blankos.iso +initrd: + tar -cf $(OBJ_DIR)/initrd.tar -C $(SRC_DIR)/initrd . + cp $(OBJ_DIR)/initrd.tar iso/boot + run: iso qemu-system-i386 -drive file=blankos.iso,format=raw diff --git a/src/initrd/hello.txt b/src/initrd/hello.txt new file mode 100644 index 0000000..d2d7b34 --- /dev/null +++ b/src/initrd/hello.txt @@ -0,0 +1 @@ +hello, ramdisk world! diff --git a/src/kernel/kmain.c b/src/kernel/kmain.c index f6249a4..5482248 100644 --- a/src/kernel/kmain.c +++ b/src/kernel/kmain.c @@ -19,6 +19,7 @@ void kmain(multiboot2_info *mb_info) { multiboot2_tag_framebuffer *fb_info = NULL; struct multiboot_tag_mmap *mmap_tag = NULL; + struct multiboot_tag_module *initrd_module = NULL; uint8_t *tags = mb_info->tags; while (1) { @@ -32,6 +33,9 @@ void kmain(multiboot2_info *mb_info) if (tag_type == MULTIBOOT_TAG_TYPE_MMAP) { mmap_tag = (struct multiboot_tag_mmap*) tags; } + if (tag_type == MULTIBOOT_TAG_TYPE_MODULE) { + initrd_module = (struct multiboot_tag_module*) tags; + } tags += ((tag_size + 7) & ~7); } @@ -42,7 +46,7 @@ void kmain(multiboot2_info *mb_info) serial_printf(3, "Framebuffer Pitch: %u", fb_info->framebuffer_pitch); serial_printf(3, "Framebuffer BPP: %u", fb_info->framebuffer_bpp); - if (fb_info) { + if (fb_info) { // fb setup framebuffer = (uint32_t *)(uintptr_t) fb_info->framebuffer_addr; uint32_t width = fb_info->framebuffer_width; @@ -60,7 +64,7 @@ void kmain(multiboot2_info *mb_info) printf("[kernel] framebuffer discovered at 0x%x\n", fb_info->framebuffer_addr); printf("[kernel] fb0: width=%u, height=%u, pitch=%u, bpp=%u\n", fb_info->framebuffer_width, fb_info->framebuffer_height, fb_info->framebuffer_pitch, fb_info->framebuffer_bpp); - if (mmap_tag) + if (mmap_tag) // memmap debug print { printf("[kernel] found memory map tag by multiboot2\n"); struct multiboot_mmap_entry *mmap = mmap_tag->entries; @@ -84,6 +88,16 @@ void kmain(multiboot2_info *mb_info) } } + if (initrd_module) { + uint32_t initrd_start = initrd_module->mod_start; + uint32_t initrd_end = initrd_module->mod_end; + uint32_t initrd_size = initrd_end - initrd_start; + + printf("[kernel] TAR initrd module found at 0x%x, size=%u bytes\n", initrd_start, initrd_size); + } else { + puts("[kernel] TAR initrd module not found\n"); + } + init_serial(); gdt_install(); idt_install(); @@ -94,7 +108,8 @@ void kmain(multiboot2_info *mb_info) init_alloc(); void* ptr1 = malloc(256); void* ptr2 = malloc(512); - free(ptr2); + printf("[debug] malloc test ptr1=0x%x, ptr2=0x%x\n", ptr1, ptr2); + free(ptr1); free(ptr2); timer_install(); keyboard_install();