Relocate kernel to 0x0700 and use sections proper

This commit is contained in:
Nero 2021-01-13 17:21:10 +00:00
parent 4046dd7d6c
commit 23c6223055

View File

@ -1,14 +1,11 @@
cpu 8086
org 0x7C00
org 0x0700
%include "inc/bpb.asm"
%include "inc/mbr.asm"
%include "inc/fcb.asm"
%include "inc/dpt.asm"
; kernel stack size in words
%define stacksize 512
init: cli
xor ax, ax
mov ds, ax
@ -16,9 +13,29 @@ init: cli
mov ss, ax
mov sp, ax
mov si, 0x7C00
; relocate to 00700
mov di, text_start
mov cx, text_length + rodata_length + data_length
rep movsb
; clear out bss section
mov cx, bss_length
rep stosb
; jump to copy
call 0:relinit
section .rodata
%define V 0x %+ VERSION
version: dd V
section .text
relinit: ; print banner
push word [version]
push word [version+2]
call printf
%defstr VERSIONSTR VERSION
db "RDOS ", VERSIONSTR, 0x0A, 0x0D, 0
db "RDOS ",2,2, 0x0A, 0x0D, 0
push dx
call dinit
@ -26,16 +43,23 @@ init: cli
mov word [0x21*4], int21
mov word [0x21*4+2], cs
mov word [curpsp], 0x1000
; set current PSP, directly after us
mov ax, stack
mov cl, 4
shr ax, cl
mov word [curpsp], ax
cmp dl, 0x80
jc .k
sub dl, (0x80-2)
.k: call setdd
mov dl, 0x37
mov ah, 2
mov dl, 0x37
int 0x21
mov dx, testfcb
mov ah, 0xF
int 0x21
restart:
@ -54,7 +78,28 @@ testfcb: db 0
db "HELLO ", "COM"
times 30 db 0
section .text
text_start equ $$
text_length equ $-$$
section .rodata
rodata_start equ $$
rodata_length equ $-$$
section .data
data_start equ $$
data_length equ $-$$
section .bss
alignb 2
stack: resb stacksize
resw 256 ; 512b kern stack
alignb 16
stack: ; stack grows into this ^
; this is also the end marker
; programs with their psp start here
bss_start equ $$
bss_length equ $-$$