diff --git a/Makefile b/Makefile index 80e85d9..a07c5c0 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ include build_scripts/config.mk .PHONY: all floppy_image kernel bootloader clean always tools_fat -all: floppy_image tools_fat +all: image include build_scripts/toolchain.mk # oldnum = cat version @@ -11,17 +11,20 @@ include build_scripts/toolchain.mk # export newnum # -# Floppy image +# Image # -floppy_image: $(BUILD_DIR)/main_floppy.img +image: $(BUILD_DIR)/main.img -$(BUILD_DIR)/main_floppy.img: bootloader kernel - dd if=/dev/zero of=$(BUILD_DIR)/main_floppy.img bs=512 count=2880 - mkfs.fat -F 12 -n "NANITE" $(BUILD_DIR)/main_floppy.img - mmd -i $(BUILD_DIR)/main_floppy.img "::boot" - mmd -i $(BUILD_DIR)/main_floppy.img "::misc" - mmd -i $(BUILD_DIR)/main_floppy.img "::misc/src" - mcopy -s -i $(BUILD_DIR)/main_floppy.img src/* "::misc/src" +$(BUILD_DIR)/main.img: bootloader kernel + dd if=/dev/zero of=$(BUILD_DIR)/main.img bs=512 count=20000 + mkfs.ext2 $(BUILD_DIR)/main.img + e2mkdir $(BUILD_DIR)/main.img:boot + e2mkdir $(BUILD_DIR)/main.img:misc + e2mkdir $(BUILD_DIR)/main.img:misc/src + e2mkdir $(BUILD_DIR)/main.img:boot/grub +# e2cp -v -s src/ -d $(BUILD_DIR)/main.img:misc/src really, really, really slow... + e2cp grub/* $(BUILD_DIR)/main.img:boot/grub + mkdir -p $(BUILD_DIR)/mnt # # Kernel diff --git a/README.md b/README.md index 93dc7a6..e798db4 100644 --- a/README.md +++ b/README.md @@ -6,15 +6,14 @@ ![repo size](https://img.shields.io/github/repo-size/PKM74/Nanite) ![license](https://img.shields.io/github/license/PKM74/Nanite) -Very small OS that can run on X86 Hardware. -Designed to run from just one 1.44MB floppy disk, ATA support coming soon! (TM) +A Very small OS that can run on X86 Hardware. Good luck figuring out the spagetti code i write... (sorry not sorry ;D) -Designed for older computers such as a Pentium (i586) Class Machine. I would recomend atleast a Pentium 2 Class System or higher however. +Designed for older computers such as a Pentium (i586) Class Machine. I however would recomend atleast a Pentium 2 Class System or higher. ## Features -- Support for the GNU GRUB Bootloader +- Support for the GNU GRUB 2 Bootloader and Multiboot V2 - Custom Theme for GRUB (Coming Soon!) - Basic Memory Paging - Support for Floppy Disk Drives (FDDs) @@ -32,11 +31,11 @@ To write to a disk, use `./write.sh` WARNING: **is hard coded to /dev/sdb** (sor You could also run `make all` but the scripts a bit better tbh, it even automates starting QEMU. ### Build Requirements -- mtools - make - gcc (or really any C compiler) - nasm -- grub +- grub2 +- e2tools ## How is Testing Done Testing is mostly done with QEMU These days, but I do sometimes pull out my Dell Latitude D610 to test on (for anyone wondering its completely maxed out. [2GB of ram Pentium M @ 2.23GHz]) diff --git a/build.sh b/build.sh index f5fd9cb..fb93164 100755 --- a/build.sh +++ b/build.sh @@ -31,6 +31,33 @@ make -s echo --------- echo Finished! echo --------- +read -p "Do you want to make to make image bootable? [Requires sudo] (y/n) " yn +case $yn in + y) + echo ---------------- + echo Installing GRUB! + echo ---------------- + + sudo losetup -d /dev/loop500 + sudo losetup /dev/loop500 build/main.img + sudo grub-install \ + --modules="part_msdos" \ + --boot-directory=build/mnt/boot \ + --target=i386-pc \ + --bootloader-id=GRUB \ + /dev/loop500 -v + sudo losetup -d /dev/loop500 + + ;; + n ) echo exiting...; + exit;; + * ) echo invalid response; + exit 1;; +esac +echo --------- +echo Finished! +echo --------- + read -p "Do you want to Start QEMU? (y/n) " yn case $yn in @@ -44,7 +71,7 @@ case $yn in -serial chardev:serial1 \ -audiodev pa,id=speaker \ -machine pcspk-audiodev=speaker \ - -fda build/main_floppy.img \ + -hda build/main.img \ -m size=512M echo -------- echo Finshed! diff --git a/src/kernel/boot.asm b/src/kernel/boot.asm new file mode 100644 index 0000000..8848492 --- /dev/null +++ b/src/kernel/boot.asm @@ -0,0 +1,50 @@ +;/////////////////////; +;Nanite OS ; +;COPYRIGHT (C) 2024 ; +;Tyler McGurrin ; +;/////////////////////; +[bits 32] +section .entry + +extern __bss_start +extern __end + +extern start +global entry + +; My Life is totally funnnn +global entry +entry: + ; 6 - setup segment registers + mov ax, 0x10 + mov ds, ax + mov ss, ax + mov al, 0 + cld + rep stosb + + ; clear BSS (uninit data) + mov edi, __bss_start + mov ecx, __end + sub ecx, edi + + + xor edx, edx + push edx + call start + + cli + hlt + +section .multiboot_header +header_start: + dd 0xe85250d6 ; magic number + dd 0 ; protected mode code + dd header_end - header_start ; header length + dd 0x100000000 - (0xe85250d6 + 0 + (header_end - header_start)) ; checksum + + ; required end tag + dw 0 ; type + dw 0 ; flags + dd 8 ; size +header_end: \ No newline at end of file diff --git a/src/kernel/linker.ld b/src/kernel/linker.ld index fa612c1..f56ca4a 100644 --- a/src/kernel/linker.ld +++ b/src/kernel/linker.ld @@ -1,4 +1,4 @@ -ENTRY(start) +ENTRY(entry) OUTPUT_FORMAT("binary") phys = 0x00100000; @@ -7,7 +7,7 @@ SECTIONS . = phys; .entry : { __entry_start = .; *(.entry) } - .text : { __text_start = .; *(.text) } + .text : { __text_start = ALIGN(8); KEEP(*(multiboot_header)) *(.text) } .data : { __data_start = .; *(.data) } .rodata : { __rodata_start = .; *(.rodata) } .bss : { __bss_start = .; *(.bss) } diff --git a/src/kernel/main.c b/src/kernel/main.c index 0f80db7..8b0dabd 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -21,9 +21,6 @@ #include #include -extern uint8_t __bss_start; -extern uint8_t __end; - uint16_t DEBUG_COM_PORT = COM1_PORT; void __attribute__((section(".entry"))) start() { diff --git a/src/kernel/version.h b/src/kernel/version.h index c7d891b..3332737 100644 --- a/src/kernel/version.h +++ b/src/kernel/version.h @@ -6,4 +6,4 @@ #pragma once #define LOGO " _ _____ _ __________________\n / | / / | / | / / _/_ __/ ____/\n / |/ / /| | / |/ // / / / / __/ \n / /| / ___ |/ /| // / / / / /___ \n/_/ |_/_/ |_/_/ |_/___/ /_/ /_____/ \n" -#define VERSION "RD-00037" \ No newline at end of file +#define VERSION "RD-00038" \ No newline at end of file