feat: boot sur disque dur par GRUB en multiboot2

This commit is contained in:
Nicolas Hordé 2018-09-27 07:55:24 +02:00
parent 87956a41a3
commit 47e779ea1a
8 changed files with 84 additions and 25 deletions

View File

@ -1,8 +1,8 @@
target remote localhost:1234
set disassembly-flavor intel
set architecture i386
break *0x100000
cont
symbol-file ./system/system.sys
clear *0x100000
break system.c:59
cont
clear system.c:59
display/20i $pc

BIN
final/harddisk.img.xz Normal file

Binary file not shown.

View File

@ -1,14 +1,33 @@
all: cos2000.img
all: harddisk.img.final floppy.img.final
cos2000.img:
(dd if=/dev/zero of=cos2000.img count=2880 bs=512)
(mkfs.msdos -F 12 -n "COS2000" cos2000.img)
harddisk.img.before:
(xz -d -k harddisk.img.xz)
(dd if=harddisk.img of=harddisk.img.part1 skip=63 bs=512)
(dd if=harddisk.img of=harddisk.img.before count=63 bs=512;sync)
(mkdir ./mnt -p)
(fusefat cos2000.img ./mnt -o rw+)
harddisk.img.final: harddisk.img.before
(mount.fuse-ext2 -o rw+ harddisk.img.part1 ./mnt)
(cp ../system/system.sys ./mnt/boot/;sync)
(fusermount ./mnt -u)
(cat harddisk.img.before > harddisk.img.final)
(cat harddisk.img.part1 >> harddisk.img.final;sync)
floppy.img.final:
(dd if=/dev/zero of=floppy.img.final count=2880 bs=512)
(mkfs.msdos -F 12 -n "COS2000" floppy.img.final)
(mkdir ./mnt -p)
(fusefat floppy.img.final ./mnt -o rw+)
(cp ../boot/loader.sys ./mnt/)
(cp ../system/system.sys ./mnt/;sync)
(fusermount ./mnt -u)
(dd if=../boot/boot12.bin of=cos2000.img seek=0 count=1 conv=notrunc;sync)
(dd if=../boot/boot12.bin of=floppy.img.final seek=0 count=1 conv=notrunc;sync)
littleclean:
rm -f *.final
clean:
rm -f *.before
rm -f *.part1
rm -f *.img
rm -f *.final

15
final/makeimage Executable file
View File

@ -0,0 +1,15 @@
#!/bin/bash
dd if=/dev/zero of=cos2000.img count=10 bs=1048576
parted -s -a cylinder cos2000.img mklabel msdos
parted -s -a cylinder cos2000.img mkpart primary ext2 63s 10M
parted -s -a cylinder cos2000.img toggle 1 boot
lo=`losetup -f`
echo ${lo}
losetup -P ${lo} cos2000.img
mkfs.ext2 ${lo}p1
mount ${lo}p1 /mnt
grub-install --no-floppy --install-modules="biosdisk part_msdos ext2 configfile normal multiboot2" --boot-directory=/mnt/boot ${lo} --target=i386-pc
echo -en "set timeout=4\nset default=0\nmenuentry "cos2000" {\nset root=(hd0,1)\nmultiboot2 /boot/system.sys\nboot\n}" > /mnt/boot/grub/grub.cfg
umount /mnt
losetup -d ${lo}
xz -c cos2000.img > cos2000.img.xz

View File

@ -1,10 +1,14 @@
all: makall
makall: boot/boot12.bin lib/libs.o system/system.sys
makall: lib/libs.o system/system.sys final/harddisk.img.final
sync
floppy: boot/boot12.bin final/floppy.img.final
harddisk: final/harddisk.img.final
install:
(sudo apt-get install nasm gcc qemu fusefat cgdb)
(sudo apt-get install nasm gcc qemu fusefat fuseext2 cgdb)
clean:
(cd system; make clean)
@ -13,35 +17,44 @@ clean:
(cd final;make clean)
sync
littleclean:
(cd system; make clean)
(cd boot; make clean)
(cd lib;make clean)
(cd final;make littleclean)
sync
backup: clean
(cd .. ; tar cf - cosc | gzip -f - > backup.tar.gz ; cd cosc)
(cd .. ; tar cf - Source\ C | gzip -f - > backup.tar.gz)
copy:
(cd final; make)
test: all harddisk qemu
test: all copy qemu
retest: littleclean test
retest: clean test
floppytest: floppy qemu-floppy
view:
(hexdump -C ./final/cos2000.img|head -c10000)
(hexdump -C ./final/harddisk.img.final|head -c10000)
debug: debug-system
debug-boot: all copy qemu-debug
debug-boot: all harddisk qemu-debug
(sleep 2;cgdb -x ./debug/boot.txt)
debug-loader: all copy qemu-debug
debug-loader: all harddisk qemu-debug
(sleep 2;cgdb -x ./debug/loader.txt)
debug-system: all copy qemu-debug
debug-system: all harddisk qemu-debug
(sleep 2;cgdb -x ./debug/system.txt)
qemu-debug:
(killall qemu-system-i386;qemu-system-i386 -m 1G -fda ./final/cos2000.img -s -S &)
(killall qemu-system-i386;qemu-system-i386 -m 1G -drive format=raw,file=./final/harddisk.img.final -s -S &)
qemu:
(qemu-system-i386 -m 1G -fda ./final/cos2000.img -s)
(killall qemu-system-i386;qemu-system-i386 -m 1G -drive format=raw,file=./final/harddisk.img.final --enable-kvm -cpu host -s &)
qemu-floppy:
(killall qemu-system-i386;qemu-system-i386 -m 1G -fda ./final/floppy.img.final --enable-kvm -cpu host -s &)
system/system.sys:
(cd system; make)
@ -49,5 +62,11 @@ system/system.sys:
boot/boot12.bin:
(cd boot; make)
final/floppy.img.final:
(cd final; make floppy.img.final)
final/harddisk.img.final:
(cd final; make harddisk.img.final)
lib/libs.o:
(cd lib; make)

View File

@ -7,6 +7,10 @@ ENTRY(mymain)
SECTIONS
{
. = 0x100000;
.boot ALIGN(4) :
{
*(.multiboot)
}
.text ALIGN(16): {
*(.text)
}

View File

@ -1,6 +1,6 @@
GCC=gcc -O0 -g -nostdinc -ffreestanding -fno-builtin -fomit-frame-pointer -Wall -w -I ../include -m32 -c -o
LINK=ld -m elf_i386 -T linker.lds -e main -o
LINK=ld -m elf_i386 -T linker.lds -e main -n -o
all: system.sys
sync

View File

@ -13,6 +13,8 @@
#include "shell.h"
#include "syscall.h"
static u8 __attribute__((section(".multiboot"))) magicmultiboot[28]={0xD6,0x50,0x52,0xE8,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x12,0xaf,0xad,0x17,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00};
static u8 warnmsg[] =
"\033[99C\033[8D\033[37m\033[1m[ \033[36mNON\033[37m ]\033[0m\000";
static u8 okmsg[] =
@ -41,7 +43,7 @@ void error()
int main(void)
{
asm("movl $0x0000FFFF, %esp");
cli();
setvmode(0x02);
/* Efface l'ecran */