From: John Tsiombikas Date: Wed, 16 Nov 2022 15:19:17 +0000 (+0200) Subject: load stage2 high to leave the low RAM for the kernel X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=eightysix;a=commitdiff_plain;h=be7535b3af9d7ecc5581a7b3d325f5caec87b24f load stage2 high to leave the low RAM for the kernel --- diff --git a/.gitignore b/.gitignore index 3576cff..77c7ebc 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,6 @@ *.swp *.img *.map -dis +dis1 +dis2 *.log diff --git a/Makefile b/Makefile index 0bac632..8e95cce 100644 --- a/Makefile +++ b/Makefile @@ -26,4 +26,5 @@ debug: $(bin) .PHONY: disasm disasm: $(bin) - ndisasm -o 0x7c00 $< >dis + ndisasm -o 0x7c00 $< >dis1 + ndisasm -o 0x80000 -e 512 $< >dis2 diff --git a/boot.ld b/boot.ld index b607e11..99bc701 100644 --- a/boot.ld +++ b/boot.ld @@ -6,10 +6,13 @@ SECTIONS { .bootsect : { * (.bootsect); } + _bootsect_end = .; - . = 0x7e00; + /* load high out of the way, to allow stage2 to load the kernel low */ + . = 0x80000; _stage2_start = .; - .text : { + _stage2_start_seg = _stage2_start >> 4; + .text : AT(_bootsect_end) { * (.startup); * (.text*); } @@ -19,6 +22,7 @@ SECTIONS { } .bss ALIGN(4) (NOLOAD): { _bss_start = .; + _bss_start_off = _bss_start - _stage2_start; * (.bss*); * (COMMON); . = ALIGN(4); @@ -26,4 +30,5 @@ SECTIONS { _bss_size = SIZEOF(.bss); . = ALIGN(4); _stage2_end = .; + _stage2_size = _stage2_end - _stage2_start; }; diff --git a/boot/boot.asm b/boot/boot.asm index 5b82c2d..2b74db8 100644 --- a/boot/boot.asm +++ b/boot/boot.asm @@ -3,10 +3,9 @@ bits 16 section .bootsect -extern _stage2_start -extern _stage2_end +extern _stage2_start_seg +extern _stage2_size -stacktop equ 7b00h boot_driveno equ 7b00h num_read_tries equ 7b06h ; 2 bytes sect_pending equ 7b08h ; 2 bytes @@ -58,12 +57,12 @@ start: xor ax, ax mov ds, ax mov es, ax - mov ss, ax - mov gs, ax - mov fs, ax jmp 00:.setcs .setcs: - mov sp, stacktop + ; put the stack high + mov ax, 0x7f00 + mov ss, ax + xor sp, sp mov [boot_driveno], dl ; query sectors per track @@ -84,20 +83,15 @@ start: mov word [num_heads], 2 .querydone: -; load the rest of the code at 7e00h - mov ax, _stage2_end - sub ax, _stage2_start + ; load the rest of the code high + mov ax, _stage2_size add ax, 511 mov cl, 9 shr ax, cl inc ax mov [sect_pending], ax - mov ax, _stage2_start - shr ax, 1 - shr ax, 1 - shr ax, 1 - shr ax, 1 - mov es, ax ; destination segment 7e0h to allow loading up to 64k + mov ax, _stage2_start_seg + mov es, ax ; destination segment mov word [destptr], 0 mov word [start_sect], 1 ; start from sector 1 to skip boot sector mov word [cur_cyl], 0 @@ -170,10 +164,15 @@ start: add [destptr], ax jnz .rdloop - ; loaded sucessfully, reset es back to 0 and jump -.done: xor ax, ax + ; loaded sucessfully, load segment registers and jump +.done: mov ax, _stage2_start_seg + mov ds, ax mov es, ax - jmp _stage2_start + push ax + xor ax, ax + push ax + retf + .fail: add sp, 2 ; clear num_sect off the stack dec word [num_read_tries] diff --git a/boot/boot2.asm b/boot/boot2.asm index 6837579..c90cef6 100644 --- a/boot/boot2.asm +++ b/boot/boot2.asm @@ -4,15 +4,25 @@ section .startup extern bootmain +extern _stage2_start_seg +extern _bss_start_off +extern _bss_size global _start _start: ; TODO floppy off if necessary - ; TODO zero .bss + + ; zero .bss + mov di, _bss_start_off + mov cx, _bss_size + shr cx, 1 + rep stosw + xor ax, ax + mov es, ax + call bootmain hang: hlt jmp hang - ; vi:set ts=8 sts=8 sw=8 ft=nasm: