aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--Makefile10
-rw-r--r--README.md0
-rw-r--r--src/Makefile30
-rw-r--r--src/boot/boot.S27
-rwxr-xr-xsrc/bringellebin0 -> 4204 bytes
-rw-r--r--src/bringelle.c11
-rw-r--r--src/utils/print.c7
-rw-r--r--src/utils/print.h7
-rwxr-xr-xtools/gen_syslinux_floppy.sh62
-rwxr-xr-xtools/load_bringelle.sh36
11 files changed, 191 insertions, 0 deletions
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
--- /dev/null
+++ b/README.md
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 0000000..73de16f
--- /dev/null
+++ b/src/bringelle
Binary files differ
diff --git a/src/bringelle.c b/src/bringelle.c
new file mode 100644
index 0000000..4c8e39f
--- /dev/null
+++ b/src/bringelle.c
@@ -0,0 +1,11 @@
+#include "utils/print.h"
+
+
+
+
+void bringelle(){
+ putchar('L');
+ putchar('L');
+
+ while(1);
+}
diff --git a/src/utils/print.c b/src/utils/print.c
new file mode 100644
index 0000000..c7c94d4
--- /dev/null
+++ b/src/utils/print.c
@@ -0,0 +1,7 @@
+#include "print.h"
+
+
+void putchar(char c){
+ char *video=(char *)0xB8000;
+ video[0]=c;
+}
diff --git a/src/utils/print.h b/src/utils/print.h
new file mode 100644
index 0000000..51ed076
--- /dev/null
+++ b/src/utils/print.h
@@ -0,0 +1,7 @@
+#ifndef PRINT_H
+#define PRINT_H
+
+
+void putchar(char);
+
+#endif
diff --git a/tools/gen_syslinux_floppy.sh b/tools/gen_syslinux_floppy.sh
new file mode 100755
index 0000000..cae607a
--- /dev/null
+++ b/tools/gen_syslinux_floppy.sh
@@ -0,0 +1,62 @@
+#!/usr/bin/env bash
+
+# Ensure to abort on error
+set -e
+
+wai=$(dirname $(readlink -f "$0")) # Current script directory
+outdir="${wai}/../"
+floppy="${outdir}/floppy.img"
+mountp="$(mktemp -d)" # Mount point (where the floppy will be mounted temporally
+sysbios="/usr/lib/syslinux/bios/" # Syslinux bios and ui locations
+
+check_for () {
+ command -v "$1" &>/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" <<EOF
+TIMEOUT 30
+UI vesamenu.c32
+
+MENU TITLE Syslinux
+ LABEL Bringelle
+ KERNEL /boot/bringelle.bs
+EOF
+mv "$cfg" "$mountp/boot/syslinux/syslinux.cfg"
+cp $sysbios/*.c32 $mountp/boot/syslinux/
+sudo extlinux --install $mountp/boot/syslinux
+
+# Umount floppy
+sync
+sudo umount "$mountp"
+rmdir "$mountp"
+
+# Install MBR
+sudo dd bs=440 count=1 conv=notrunc if=$sysbios/gptmbr.bin of=${loop}
+
+# Cleanup
+sudo losetup -D
diff --git a/tools/load_bringelle.sh b/tools/load_bringelle.sh
new file mode 100755
index 0000000..ad360cc
--- /dev/null
+++ b/tools/load_bringelle.sh
@@ -0,0 +1,36 @@
+#!/usr/bin/env bash
+
+# Ensure to abort on error
+set -e
+
+wai=$(dirname $(readlink -f "$0")) # Current script directory
+outdir="${wai}/../"
+floppy="${outdir}/floppy.img"
+mountp="$(mktemp -d)" # Mount point (where the floppy will be mounted temporally
+kernel="${outdir}/src/bringelle"
+
+check_for () {
+ command -v "$1" &>/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
+