dis1
dis2
*.log
-bootldr
+86kern
+csrc = $(wildcard src/*.c)
+ssrc = $(wildcard src/*.asm)
+obj = $(csrc:.c=.o) $(ssrc:.asm=.o)
+dep = $(csrc:.c=.d)
+
disk_numsec = 720
#disk_numsec = 2880
-bin = bootldr
-img = bootldr.img
+bin = 86kern
+img = 86kern.img
CC = ia16-elf-gcc
LD = ia16-elf-ld
-CFLAGS = -march=i8088 -mtune=i8088
+CFLAGS = -march=i8088 -mtune=i8088 -MMD
$(img): $(bin)
dd if=/dev/zero of=$@ bs=512 count=$(disk_numsec)
dd if=$< of=$@ bs=512 conv=notrunc
-$(bin): boot/boot.o boot/boot2.o boot/main.o
- $(LD) -T boot.ld -Map boot.map -o $@ $^
+$(bin): $(obj)
+ $(LD) -T kern.ld -Map kern.map -o $@ $(obj)
+
+-include $(dep)
%.o: %.asm
nasm -o $@ -f elf $<
.PHONY: clean
clean:
- rm -f boot/*.o $(bin)
+ rm -f $(obj) $(bin)
+
+.PHONY: cleandep
+cleandep:
+ rm -f $(dep)
.PHONY: run
.PHONY: disasm
disasm: $(bin)
ndisasm -o 0x7c00 $< >dis1
- ndisasm -o 0x80000 -e 512 $< >dis2
+ ndisasm -o 0x98000 -e 512 $< >dis2
}
_bootsect_end = .;
- /* load high out of the way, to allow stage2 to load the kernel low */
- . = 0x80000;
- _stage2_start = .;
- _stage2_start_seg = _stage2_start >> 4;
+ /* load high out of the way, to leave the rest of RAM for userland
+ * reserving the top 32kb for the kernel for now
+ */
+ . = 0x98000;
+ _kern_start = .;
+ _kern_start_seg = _kern_start >> 4;
.text : AT(_bootsect_end) {
* (.startup);
* (.text*);
}
.bss ALIGN(4) (NOLOAD): {
_bss_start = .;
- _bss_start_off = _bss_start - _stage2_start;
+ _bss_start_off = _bss_start - _kern_start;
* (.bss*);
* (COMMON);
. = ALIGN(4);
}
_bss_size = SIZEOF(.bss);
. = ALIGN(4);
- _stage2_end = .;
- _stage2_size = _stage2_end - _stage2_start;
+ _kern_end = .;
+ _kern_size = _kern_end - _kern_start;
};
bits 16
section .bootsect
-extern _stage2_start_seg
-extern _stage2_size
+extern _kern_start_seg
+extern _kern_size
boot_driveno equ 7b00h
num_read_tries equ 7b06h ; 2 bytes
db 0 ; 25h: winnt flags
db 28h ; 26h: signature(?)
dd 0 ; 27h: volume serial number
- db "80 SIX BOOT"; 2bh: volume label, 11 bytes
+ db "86BOOT "; 2bh: volume label, 11 bytes
db "FAT12 " ; 36h: filesystem id, 8 bytes
start:
xor ax, ax
mov ds, ax
mov es, ax
+ mov ss, ax
jmp 00:.setcs
.setcs:
- ; put the stack high
- mov ax, 0x7f00
- mov ss, ax
- xor sp, sp
+ mov sp, 0x7b00 ; temp stack below our vars
mov [boot_driveno], dl
; query sectors per track
.querydone:
; load the rest of the code high
- mov ax, _stage2_size
+ mov ax, _kern_size
add ax, 511
mov cl, 9
shr ax, cl
inc ax
mov [sect_pending], ax
- mov ax, _stage2_start_seg
+ mov ax, _kern_start_seg
mov es, ax ; destination segment
mov word [destptr], 0
mov word [start_sect], 1 ; start from sector 1 to skip boot sector
jnz .rdloop
; loaded sucessfully, load segment registers and jump
-.done: mov ax, _stage2_start_seg
+.done: mov ax, _kern_start_seg
mov ds, ax
mov es, ax
push ax
str_rdtrack2 db " from ",0
str_rdtrack3 db "/",0
-str_load_fail db "Failed to load 2nd stage!",0
+str_load_fail db "Failed to load kernel!",0
str_newline db 13,10,0
times 510-($-$$) db 0
-void bootmain(void)
+void kmain(void)
{
int i, j;
unsigned short __far *vmem = (void __far*)0xb8000000ul;
bits 16
section .startup
-extern bootmain
-extern _stage2_start_seg
+; memory reserved at the top of RAM for the kernel stack
+STACKSZ equ 4096
+
+extern kmain
extern _bss_start_off
extern _bss_size
_start:
; TODO floppy off if necessary
+ ; move stack to the top of RAM (TODO: detect and avoid Ext. BIOS data area)
+ mov ax, (0xa0000 - STACKSZ) >> 4
+ mov ss, ax
+ mov sp, STACKSZ
+
; zero .bss
mov di, _bss_start_off
mov cx, _bss_size
xor ax, ax
mov es, ax
- call bootmain
+ call kmain
hang: hlt
jmp hang