diff --git a/.gitignore b/.gitignore index 41b32c3..1b646bc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,6 @@ *.o -bochslog.txt build/ kernel.elf -os.iso -blankos.iso -real/ +blankos-fat.img i386-elf-7.5.0-Linux-x86_64/ +i386-elf-7.5.0-Linux-x86_64.tar.xz diff --git a/bochsrc.txt b/bochsrc.txt deleted file mode 100644 index 9783490..0000000 --- a/bochsrc.txt +++ /dev/null @@ -1,10 +0,0 @@ -megs: 32 -display_library: x -romimage: file=/usr/share/bochs/BIOS-bochs-legacy -vgaromimage: file=/usr/share/bochs/VGABIOS-lgpl-latest -ata0-master: type=cdrom, path=os.iso, status=inserted -boot: cdrom -log: bochslog.txt -clock: sync=realtime, time0=local -cpu: count=1, ips=1000000 -com1: enabled=1, mode=file, dev=com1.out diff --git a/com1.out b/com1.out deleted file mode 100644 index 10c4e1d..0000000 Binary files a/com1.out and /dev/null differ diff --git a/iso/boot/grub/menu.lst b/iso/boot/grub/menu.lst deleted file mode 100644 index 9a5b08c..0000000 --- a/iso/boot/grub/menu.lst +++ /dev/null @@ -1,5 +0,0 @@ -default=0 -timeout=0 - -title os -kernel /boot/kernel.elf diff --git a/iso/boot/grub/stage2_eltorito b/iso/boot/grub/stage2_eltorito deleted file mode 100644 index 9e1617c..0000000 Binary files a/iso/boot/grub/stage2_eltorito and /dev/null differ diff --git a/iso/boot/kernel.elf b/iso/boot/kernel.elf deleted file mode 100755 index 7663e8c..0000000 Binary files a/iso/boot/kernel.elf and /dev/null differ diff --git a/makefile b/makefile index 0a10ded..2ea730b 100644 --- a/makefile +++ b/makefile @@ -1,5 +1,5 @@ CC = i386-elf-7.5.0-Linux-x86_64/bin/i386-elf-gcc -CFLAGS = -Wall -Wextra -Wno-builtin-declaration-mismatch -c -I src/ +CFLAGS = -g -Wall -Wextra -Wno-builtin-declaration-mismatch -c -I src/ LDFLAGS = -T link.ld -melf_i386 AS = nasm ASFLAGS = -f elf @@ -16,6 +16,9 @@ ASM_SOURCES = $(wildcard $(KERNEL_DIR)/*.s) $(wildcard $(LIBC_DIR)/*.s) $(wildca OBJECTS = $(patsubst $(SRC_DIR)/%, $(OBJ_DIR)/%, $(C_SOURCES:.c=.o) $(ASM_SOURCES:.s=.o)) +TOOLCHAIN_SRC = https://newos.org/toolchains/i386-elf-7.5.0-Linux-x86_64.tar.xz +TOOLCHAIN_FILE = i386-elf-7.5.0-Linux-x86_64.tar.xz + all: $(OBJ_DIR) kernel.elf $(OBJ_DIR): @@ -32,31 +35,17 @@ $(OBJ_DIR)/%.o: $(SRC_DIR)/%.s $(AS) $(ASFLAGS) $< -o $@ toolchain: - wget https://newos.org/toolchains/i386-elf-7.5.0-Linux-x86_64.tar.xz - tar xf i386-elf-7.5.0-Linux-x86_64.tar.xz + wget $(TOOLCHAIN_SRC) + tar xf $(TOOLCHAIN_FILE) -os.iso: kernel.elf - cp kernel.elf iso/boot/kernel.elf - genisoimage -R \ - -b boot/grub/stage2_eltorito \ - -no-emul-boot \ - -boot-load-size 4 \ - -A os \ - -input-charset utf8 \ - -quiet \ - -boot-info-table \ - -o os.iso \ - iso +blankos-fat.img: + sudo ./setup.sh -real: kernel.elf - mkdir -p real/boot/grub - cp kernel.elf real/boot/kernel.elf - cp grub.cfg real/boot/grub/grub.cfg - grub-mkrescue real -o blankos.iso +run: blankos-fat.img + qemu-system-i386 -drive file=blankos-fat.img,format=raw -run: os.iso - bochs -f bochsrc.txt -q +debug: + qemu-system-i386 -s -S -drive file=blankos-fat.img,format=raw clean: - rm -rf $(OBJ_DIR) kernel.elf os.iso blankos.iso real - + rm -rf $(OBJ_DIR) kernel.elf blankos-fat.img $(TOOLCHAIN_FILE) diff --git a/setup.sh b/setup.sh new file mode 100755 index 0000000..2ae0904 --- /dev/null +++ b/setup.sh @@ -0,0 +1,75 @@ +#!/bin/bash + +# A script to create a FAT32 loopback device, place a kernel onto it, and install GRUB. +# Inspired by JakeSteinburger's SpecOS setup script! + +if [ "$EUID" -ne 0 ]; then + echo "Please execute this script with root privileges." + exit +fi + +if [ -f "blankos-fat.img" ]; then + echo "Deleting previous disk image..." + rm blankos-fat.img +fi + +if [ -d "/mnt/blankos" ]; then + echo "Deleting previous mountpoint..." + rm -rf /mnt/blankos +fi + +echo "Creating new mountpoint..." +mkdir /mnt/blankos + +echo "Creating an empty disk image..." +dd if=/dev/zero of=blankos-fat.img bs=512 count=131072 + +echo "Appending a parition to disk image..." +fdisk blankos-fat.img << EOF +n +p +1 + + +a +w +EOF + +echo "Creating loopback devices..." +losetup -fP blankos-fat.img + +# Get first partition loopback +LOOP_DEVICE=$(losetup -l | grep blankos-fat.img | awk '{print $1}') +PARTITION="${LOOP_DEVICE}p1" + +echo "Creating FAT32 partition..." +mkfs.vfat -F 32 $PARTITION + +echo "Mounting partition..." +mount $PARTITION /mnt/blankos + +echo "Installing GRUB on $LOOP_DEVICE" +grub-install --root-directory=/mnt/blankos --target=i386-pc --no-floppy --modules="normal part_msdos fat multiboot" $LOOP_DEVICE + +echo "Copying kernel file and GRUB configuration file..." + +cp kernel.elf /mnt/blankos/boot/ +cp grub.cfg /mnt/blankos/boot/grub/ + +echo "Appending test files..." +mkdir /mnt/blankos/hello +echo "Hello, world from FAT32 text file." > /mnt/blankos/hello/testfile.txt + +# cp program.elf /mnt/blankos/programs/ +# In the future, when the OS can load programs and parse ELF + +echo "Unmounting partition..." +umount /mnt/blankos + +echo "Freeing loopback devices..." +losetup -d $LOOP_DEVICE + +echo "Fixing disk image permissions..." +sudo chmod 666 blankos-fat.img + +echo "The blankos-fat.img disk image is ready for use with QEMU or real hardware." diff --git a/stage2_eltorito b/stage2_eltorito deleted file mode 100644 index 3748c94..0000000 Binary files a/stage2_eltorito and /dev/null differ