From 2a99c6259d54e6b5278b49ee248ba2ac66a7a56a Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Sun, 4 Apr 2021 11:19:55 +0200 Subject: [PATCH] Create repository --- .gitignore | 1 + Makefile | 10 ++++++ README.md | 0 src/Makefile | 30 +++++++++++++++++ src/boot/boot.S | 27 +++++++++++++++ src/bringelle | Bin 0 -> 4204 bytes src/bringelle.c | 11 +++++++ src/utils/print.c | 7 ++++ src/utils/print.h | 7 ++++ tools/gen_syslinux_floppy.sh | 62 +++++++++++++++++++++++++++++++++++ tools/load_bringelle.sh | 36 ++++++++++++++++++++ 11 files changed, 191 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 README.md create mode 100644 src/Makefile create mode 100644 src/boot/boot.S create mode 100755 src/bringelle create mode 100644 src/bringelle.c create mode 100644 src/utils/print.c create mode 100644 src/utils/print.h create mode 100755 tools/gen_syslinux_floppy.sh create mode 100755 tools/load_bringelle.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b70202b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +**/*.o diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..2838cbe --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ + + +all: + @printf "Usage:\n" + @printf "%25s %s\n" "Compile kernel:" "make kernel" + +qemu: + make -C src/ + qemu-system-i386 -kernel src/bringelle + diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000..0dee4ff --- /dev/null +++ b/src/Makefile @@ -0,0 +1,30 @@ +EXEC := bringelle +CC := gcc -c -m32 -fno-pie -fno-builtin + +UTILS_SRC := $(wildcard utils/*.c) + +all: $(EXEC) + +$(EXEC): boot.o utils.o bringelle.o + for obj in $^ ;\ + do \ + objcopy --remove-section .note.gnu.property $${obj} ; \ + done + ld -Ttext=0x00100000 -melf_i386 -nostdlib --oformat=binary -o bringelle $^ + +bringelle.o: bringelle.c + $(CC) $^ + +utils.o: $(UTILS_SRC) + $(CC) $^ -o $@ + +boot.o: ./boot/boot.S + as --32 -o $@ $^ -mx86-used-note=no + +clean: + - rm $(EXEC) + - rm ./*.o + +.PHONY: clean + + diff --git a/src/boot/boot.S b/src/boot/boot.S new file mode 100644 index 0000000..746f858 --- /dev/null +++ b/src/boot/boot.S @@ -0,0 +1,27 @@ +.extern bringelle +.globl _start +.text + +.set MB_MAGIC, 0x1BADB002 +.set MB_FLAGS, 0x00010000 +.set MB_CHECKSUM, -(MB_MAGIC+MB_FLAGS) +.set MB_HEADER_ADDR, mb_header +.set MB_LOAD_ADDR, mb_header +.set MB_LOAD_END_ADDR, 0x0 +.set MB_BSS_END_ADDR, 0x0 +.set MB_ENTRY_ADDR, _start + +mb_header: +.align 4 +.long MB_MAGIC +.long MB_FLAGS +.long MB_CHECKSUM +.long MB_HEADER_ADDR +.long MB_LOAD_ADDR +.long MB_LOAD_END_ADDR +.long MB_BSS_END_ADDR +.long MB_ENTRY_ADDR + +_start: + call bringelle + diff --git a/src/bringelle b/src/bringelle new file mode 100755 index 0000000000000000000000000000000000000000..73de16fb1a0639dd5516e6dbbd26b6be2b599655 GIT binary patch literal 4204 zcmZSDuvVIZfsx^#f8Y}a1_1^L22wzv0OY@r2QorCpEkb{>2~GlaD8*!^$$Y>H$%7U zAO3BjZ#o1foIDJc=4gJyljZZ`;{X5un~w-UI7c9y*Z;uAjS{0FFd71*Aut*OqaiRF z0;3@?8UmvsFd71*Aut*OqaiRF0s|BRB2ar7tAZF9Yd9FCd01FF7#SF3fZ`y``r-e7 l&=3HFBOgaAlM^p%^iiM+1_oUEB%u1/dev/null || { echo "Command $1 not found!"; exit 1; } +} + +check_for parted +check_for losetup +check_for extlinux +check_for mkfs.ext4 +[ -d "$sysbios" ] || { echo "Syslinux bios \"$sysbios\" not found!"; exit 1; } + +# Create drive +dd if=/dev/zero of=${floppy} bs=512 count=50000 # Change count to change floppy size :) +parted -s $floppy mklabel gpt +parted -s $floppy mkpart linux ext4 0 100% +parted -s $floppy set 1 legacy_boot on # Require for syslinux according to https://wiki.gentoo.org/wiki/Syslinux#GPT + +# Initiate loop devices +loop=$(sudo losetup -f) +part="${loop}p1" # Disk partition +sudo losetup -Pf $floppy + +# Prepare disk partition +sudo mkfs.ext4 $part +sudo mount $part "$mountp" +sudo mkdir -p $mountp/boot/syslinux/ + +# Configuring syslinux +sudo chown -R loic $mountp/boot/ +cfg=$(mktemp) +cat > "$cfg" </dev/null || { echo "Command $1 not found!"; exit 1; } +} + +check_for losetup +[ ! -e "$floppy" ] && { echo "Floppy drive \"$floppy\" not found!"; exit 1; } +[ ! -e "$kernel" ] && { echo "Kernel \"$kernel\" not found!"; exit 1; } + +# Initiate loop devices +loop=$(sudo losetup -f) +part="${loop}p1" # Disk partition +sudo losetup -Pf $floppy + +# Prepare disk partition +sudo mount $part "$mountp" +cp $kernel $mountp/boot/bringelle.bs + +# Umount floppy +sync +sudo umount "$mountp" +rmdir "$mountp" + +# Cleanup +sudo losetup -D +