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
1 changed files with 55 additions and 10 deletions

View File

@ -1,14 +1,11 @@
cpu 8086 cpu 8086
org 0x7C00 org 0x0700
%include "inc/bpb.asm" %include "inc/bpb.asm"
%include "inc/mbr.asm" %include "inc/mbr.asm"
%include "inc/fcb.asm" %include "inc/fcb.asm"
%include "inc/dpt.asm" %include "inc/dpt.asm"
; kernel stack size in words
%define stacksize 512
init: cli init: cli
xor ax, ax xor ax, ax
mov ds, ax mov ds, ax
@ -16,9 +13,29 @@ init: cli
mov ss, ax mov ss, ax
mov sp, 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 call printf
%defstr VERSIONSTR VERSION db "RDOS ",2,2, 0x0A, 0x0D, 0
db "RDOS ", VERSIONSTR, 0x0A, 0x0D, 0
push dx push dx
call dinit call dinit
@ -26,16 +43,23 @@ init: cli
mov word [0x21*4], int21 mov word [0x21*4], int21
mov word [0x21*4+2], cs 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 cmp dl, 0x80
jc .k jc .k
sub dl, (0x80-2) sub dl, (0x80-2)
.k: call setdd .k: call setdd
mov dl, 0x37
mov ah, 2 mov ah, 2
mov dl, 0x37
int 0x21 int 0x21
mov dx, testfcb
mov ah, 0xF
int 0x21 int 0x21
restart: restart:
@ -54,7 +78,28 @@ testfcb: db 0
db "HELLO ", "COM" db "HELLO ", "COM"
times 30 db 0 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 section .bss
alignb 2 resw 256 ; 512b kern stack
stack: resb stacksize 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 $-$$