diff --git a/boot/x86/Makefile b/boot/x86/Makefile index 5b1f0b5..b924710 100644 --- a/boot/x86/Makefile +++ b/boot/x86/Makefile @@ -1,7 +1,9 @@ all: mbrcode.bin core.img - + cat mbrcode.bin core.img > disk.img mbrcode.bin: stage1.S nasm -f bin -o $@ $^ -core.img: stage2/start.S - nasm -f bin -o $@ $^ \ No newline at end of file +core.img: + $(MAKE) -C stage2 + mv stage2/core.img . +.PHONY: core.img \ No newline at end of file diff --git a/boot/x86/core.img b/boot/x86/core.img new file mode 100755 index 0000000..b1d75ec Binary files /dev/null and b/boot/x86/core.img differ diff --git a/boot/x86/d.img b/boot/x86/d.img new file mode 100644 index 0000000..d70c88f Binary files /dev/null and b/boot/x86/d.img differ diff --git a/boot/x86/disk.img b/boot/x86/disk.img new file mode 100644 index 0000000..b8efb0d Binary files /dev/null and b/boot/x86/disk.img differ diff --git a/boot/x86/mbrcode.bin b/boot/x86/mbrcode.bin new file mode 100644 index 0000000..3f76c06 Binary files /dev/null and b/boot/x86/mbrcode.bin differ diff --git a/boot/x86/stage2/Makefile b/boot/x86/stage2/Makefile new file mode 100644 index 0000000..be7f338 --- /dev/null +++ b/boot/x86/stage2/Makefile @@ -0,0 +1,12 @@ +CC=/opt/bin/i686-mtgos-gcc +LD=/opt/bin/i686-mtgos-ld +CFLAGS16=-m16 +ASFLAGS=-f elf +core.img: start.o init.o + $(LD) -T stage2.ld -o core.img start.o init.o + +%.o: %.c + $(CC) $(CFLAGS16) -o $@ $^ + +%.o: %.S + nasm $(ASFLAGS) -o $@ $^ \ No newline at end of file diff --git a/boot/x86/stage2/init.c b/boot/x86/stage2/init.c new file mode 100644 index 0000000..aae8bf7 --- /dev/null +++ b/boot/x86/stage2/init.c @@ -0,0 +1,13 @@ +void putstring(short); +void main() { + putstring((short)"Hello, C!\r\n"); + putstring((short)"Goodbye, C!\r\n"); + putstring((short)"Hello, C!\r\n"); + putstring((short)"Goodbye, C!\r\n"); + putstring((short)"Hello, C!\r\n"); + putstring((short)"Goodbye, C!\r\n"); + putstring((short)"Hello, C!\r\n"); + putstring((short)"Goodbye, C!\r\n"); + putstring((short)"Hello, C!\r\n"); + putstring((short)"Goodbye, C!\r\n"); +} \ No newline at end of file diff --git a/boot/x86/stage2/init.o b/boot/x86/stage2/init.o new file mode 100644 index 0000000..727e456 Binary files /dev/null and b/boot/x86/stage2/init.o differ diff --git a/boot/x86/stage2/stage2.ld b/boot/x86/stage2/stage2.ld new file mode 100644 index 0000000..fa14f34 --- /dev/null +++ b/boot/x86/stage2/stage2.ld @@ -0,0 +1,18 @@ +OUTPUT_FORMAT(binary); +SECTIONS { + . = 0x0; + .init_text :{ + *(.init_text); + } + .text : { + *(.text); + } + .data : { + *(.data); + *(.rodata); + } + .bss : { + *(.bss); + *(.end); + } +} \ No newline at end of file diff --git a/boot/x86/stage2/start.S b/boot/x86/stage2/start.S index 1793ad7..c69b13f 100644 --- a/boot/x86/stage2/start.S +++ b/boot/x86/stage2/start.S @@ -1,5 +1,5 @@ -org 0x0000 bits 16 +section .init_text start: mov ax, 0x1000 ; update segment registers mov ds, ax @@ -13,27 +13,10 @@ start: mov si, unrealstart call putstr cli - push ds - lgdt [gdtinfo] - mov eax, cr0 - or al, 1 - mov cr0, eax ;Activate pmode -bits 32 - jmp $+2 ;Pls don't crash 386/486 - mov bx, 0x08 - mov ds, bx - and al, 0xFE - mov cr0, eax ; Turn off pmode -bits 16 - pop ds - sti - mov ax, 0 - mov fs, ax - mov bx, 0x0f01 - mov eax, 0x0B8000 - mov word [fs:eax], bx mov si, smiley call putstr +extern main + call main jmp $ bootmsg db "Loaded MTGosloader. Checking for any open A20 gates...",13,10,0 a20open db "It seems that A20 is already activated... Weird",13,10,0 @@ -45,6 +28,19 @@ a20success db "Successfully opened the A20 gate!",13,10,0 unrealstart db "Trying to init unreal mode",13,10,0 smiley db "Do you see a smiley in the top-left corner?",13,10,0 bootdrv db 0 +global putstring + +putstring: + push bp + mov bp, sp + push si + push bx + mov si, [bp+4] + call putstr + pop bx + pop si + pop bp + ret putstr: lodsb or al, al @@ -193,6 +189,8 @@ gdtinfo: dd gdt ;start of table gdt dd 0,0 ; entry 0 is always unused +flatcode db 0xff, 0xff, 0, 0, 0, 10011010b, 10001111b, 0 flatdesc db 0xff, 0xff, 0, 0, 0, 10010010b, 11001111b, 0 gdt_end: -times 5120-($-$$) hlt \ No newline at end of file +section .end +times 512 hlt \ No newline at end of file diff --git a/boot/x86/stage2/start.o b/boot/x86/stage2/start.o new file mode 100644 index 0000000..d17172b Binary files /dev/null and b/boot/x86/stage2/start.o differ