Before rewrite
This commit is contained in:
parent
c6e06dad14
commit
f7c4944566
11 changed files with 67 additions and 24 deletions
|
@ -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 $@ $^
|
||||
core.img:
|
||||
$(MAKE) -C stage2
|
||||
mv stage2/core.img .
|
||||
.PHONY: core.img
|
BIN
boot/x86/core.img
Executable file
BIN
boot/x86/core.img
Executable file
Binary file not shown.
BIN
boot/x86/d.img
Normal file
BIN
boot/x86/d.img
Normal file
Binary file not shown.
BIN
boot/x86/disk.img
Normal file
BIN
boot/x86/disk.img
Normal file
Binary file not shown.
BIN
boot/x86/mbrcode.bin
Normal file
BIN
boot/x86/mbrcode.bin
Normal file
Binary file not shown.
12
boot/x86/stage2/Makefile
Normal file
12
boot/x86/stage2/Makefile
Normal file
|
@ -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 $@ $^
|
13
boot/x86/stage2/init.c
Normal file
13
boot/x86/stage2/init.c
Normal file
|
@ -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");
|
||||
}
|
BIN
boot/x86/stage2/init.o
Normal file
BIN
boot/x86/stage2/init.o
Normal file
Binary file not shown.
18
boot/x86/stage2/stage2.ld
Normal file
18
boot/x86/stage2/stage2.ld
Normal file
|
@ -0,0 +1,18 @@
|
|||
OUTPUT_FORMAT(binary);
|
||||
SECTIONS {
|
||||
. = 0x0;
|
||||
.init_text :{
|
||||
*(.init_text);
|
||||
}
|
||||
.text : {
|
||||
*(.text);
|
||||
}
|
||||
.data : {
|
||||
*(.data);
|
||||
*(.rodata);
|
||||
}
|
||||
.bss : {
|
||||
*(.bss);
|
||||
*(.end);
|
||||
}
|
||||
}
|
|
@ -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
|
||||
section .end
|
||||
times 512 hlt
|
BIN
boot/x86/stage2/start.o
Normal file
BIN
boot/x86/stage2/start.o
Normal file
Binary file not shown.
Loading…
Reference in a new issue