grub setup script, and added -march=i386 to CFLAGS
authorJohn Tsiombikas <nuclear@member.fsf.org>
Wed, 9 Jun 2021 11:01:58 +0000 (14:01 +0300)
committerJohn Tsiombikas <nuclear@member.fsf.org>
Wed, 9 Jun 2021 11:01:58 +0000 (14:01 +0300)
.gitignore
sys1/Makefile [new file with mode: 0644]
sys1/RUN [new file with mode: 0755]
sys1/grub.cfg [new file with mode: 0644]
sys1/kern/Makefile
sys1/kern/src/main.c
sys1/mkgrubimage [new file with mode: 0755]

index c7f577c..780ea92 100644 (file)
@@ -4,3 +4,4 @@
 *.elf
 *.map
 *.log
+*.img
diff --git a/sys1/Makefile b/sys1/Makefile
new file mode 100644 (file)
index 0000000..8e938a5
--- /dev/null
@@ -0,0 +1,12 @@
+.PHONY: image
+image: disk.img
+
+disk.img: kern/kern1.elf
+       ./mkgrubimage
+
+kern/kern1.elf:
+       $(MAKE) -C kern
+
+.PHONY: clean
+clean:
+       rm -f disk.img part.img
diff --git a/sys1/RUN b/sys1/RUN
new file mode 100755 (executable)
index 0000000..9b3fe59
--- /dev/null
+++ b/sys1/RUN
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+qemu-system-i386 -hda disk.img -serial file:serial.log
diff --git a/sys1/grub.cfg b/sys1/grub.cfg
new file mode 100644 (file)
index 0000000..fa0b13c
--- /dev/null
@@ -0,0 +1,8 @@
+set default=0
+set timeout=0
+
+menuentry "sys1" {
+       search --set=root --label SYS1ROOT
+       multiboot /boot/kern1.elf
+       boot
+}
index 5ad379f..c9349d9 100644 (file)
@@ -8,7 +8,7 @@ warn = -pedantic -Wall
 dbg = -g
 inc = -Isrc -Isrc/libc
 
-CFLAGS = $(carch) $(warn) $(dbg) $(inc) -fno-pic -ffreestanding -nostdinc \
+CFLAGS = $(carch) -march=i386 $(warn) $(dbg) $(inc) -fno-pic -ffreestanding -nostdinc \
                 -fno-builtin -MMD
 LDFLAGS = $(ldarch) -nostdlib -T kern1.ld -Map kern1.map
 
index 00d3882..44acf3c 100644 (file)
@@ -32,7 +32,7 @@ void kmain(void)
                drawtext(line & 7, row, buf);
 
                for(i=0; i<65536 * 4; i++) {
-                       buf[0] = twirl[(i >> 18) & 3];
+                       buf[0] = twirl[(i >> 15) & 3];
                        buf[1] = 0;
                        vga_setcolor(VGA_WHITE, VGA_BLACK);
                        drawtext(50, row, buf);
diff --git a/sys1/mkgrubimage b/sys1/mkgrubimage
new file mode 100755 (executable)
index 0000000..b97a18a
--- /dev/null
@@ -0,0 +1,41 @@
+#!/bin/sh
+
+SUDO=
+mntpt=/tmp/3sys1mnt
+
+make -C kern || exit 1
+
+echo 'creating partition image: part.img'
+dd if=/dev/zero of=part.img bs=1024 count=63488
+mkfs -t vfat -n SYS1ROOT part.img
+
+echo 'creating disk image: disk.img'
+dd if=/dev/zero of=disk.img bs=1024 count=65536
+echo start=2048 type=c | sfdisk disk.img
+
+echo 'combining images'
+dd if=part.img of=disk.img bs=1024 seek=1024 conv=notrunc
+
+if [ "`id -u`" != 0 ]; then
+       if sudo --version >/dev/null 2>&1; then
+               echo 'will need superuser priviledges for the next part, using sudo'
+               SUDO=sudo
+       else
+               echo 'will need superuser priviledges for the next part, using su'
+               su || exit 1
+       fi
+fi
+
+echo "mounting parition image to $mntpt"
+$SUDO mkdir -p $mntpt
+$SUDO mount -o loop,offset=1M disk.img $mntpt
+$SUDO mkdir -p $mntpt/boot/grub
+echo 'copying grub files'
+$SUDO cp grub.cfg $mntpt/boot/grub
+echo 'copying kernel'
+$SUDO cp kern/kern1.elf $mntpt/boot
+echo 'installing grub'
+$SUDO grub-install --target=i386-pc --boot-directory=$mntpt/boot \
+       --skip-fs-probe --install-modules='part_msdos fat multiboot' \
+       --modules='part_msdos fat multiboot' disk.img
+$SUDO umount $mntpt