Improve ordering of binary data in kernel

This commit is contained in:
Nero 2020-07-04 10:35:38 +02:00
parent f9b180ea57
commit 5382edc2ae

View File

@ -1,31 +1,69 @@
cpu 8086 cpu 8086
org 0x500 org 0x500
jmp 0:(init+0x7C00-$$)
%include "kernel/fd.asm" %include "inc/bpb.asm"
%include "kernel/con.asm" %include "inc/mbr.asm"
%include "inc/bpb.asm"
%include "inc/mbr.asm"
; Far call via interrupt vector ; kernel stack size in words
%macro intcall 1 %define stacksize 512
call far [cs:%1*4]
%endmacro
; Far jump via interrupt vector init: cli
%macro intjmp 1 xor ax, ax
jmp far [cs:%1*4] mov ds, ax
%endmacro mov es, ax
mov ss, ax
mov sp, ( stack+stacksize )
; stack size ; relocate
%define stacks 512 mov si, 0x7C00
mov di, $$
mov cx, (_end-$$)
rep movsb
jmp 0:main
main: ; zero out first 64kb except our code
; bss and boot sector area gets cleared by this
mov cx, di
neg cx
xor ax, ax
rep stosb
; install interrupt vectors
mov si, vects
mov di, (0x20*4)
mov cx, 0x0A
intlp: movsw
mov ax, cs
stosw
loop intlp
; file descriptor 0 = CON
mov word [fd_table], con_ftab
; print banner
mov dx, banner
mov cx, 13
mov bx, 0
call fd_write
call dnconv
mov al, dl
call select
call load_bpb
loop: int 0x28
jmp loop
section .data
banner: db "rdos loaded", 0xA, 0xD, '$' banner: db "rdos loaded", 0xA, 0xD, '$'
section .text
; Alias for Int 21h,AH=0h ; Alias for Int 21h,AH=0h
int20h: xor ah, ah int20h: xor ah, ah
; allow extenders to get away with only hooking 21h jmp far [cs:0x21*4]
intjmp 0x21
int21h: ; inside of kernel, direction always goes up int21h: ; inside of kernel, direction always goes up
; the iret will restore it to the user value later ; the iret will restore it to the user value later
@ -53,6 +91,8 @@ iretfl: push ax
iret: iret iret: iret
retf: retf retf: retf
section .data
; Subfunction ptr ; Subfunction ptr
; this is used as extra register in int21h ; this is used as extra register in int21h
sfptr: dw 0 sfptr: dw 0
@ -78,6 +118,8 @@ sftab: dw sferr, getc, putc, sferr
dw sferr, sferr, sferr, sferr dw sferr, sferr, sferr, sferr
dw sferr, sferr, sferr, sferr dw sferr, sferr, sferr, sferr
section .text
; OUT al character read ; OUT al character read
getc: xor ax, ax getc: xor ax, ax
int 0x16 int 0x16
@ -195,59 +237,20 @@ fputc: push ax
pop ax pop ax
iret iret
%include "kernel/fd.asm"
%include "kernel/con.asm"
%include "kernel/diskio.asm" %include "kernel/diskio.asm"
%include "kernel/fat.asm" %include "kernel/fat.asm"
section .data
vects: dw int20h, int21h, retf, retf vects: dw int20h, int21h, retf, retf
dw retf, retf, retf, int20h dw retf, retf, retf, int20h
dw idle, fputc dw idle, fputc
main: ; zero out first 64kb except our code _end: dw 0x55AA, 0x55AA
; bss and boot sector area gets cleared by this
mov di, init
mov cx, di
neg cx
xor ax, ax
rep movsb
; install interrupt vectors
mov si, vects
mov di, (0x20*4)
mov cx, 0x0A
intlp: movsw
mov ax, cs
stosw
loop intlp
; print banner
mov dx, banner
mov cx, 13
mov bx, 0
call con_write
call dnconv
mov al, dl
call select
call load_bpb
loop: int 0x28
jmp loop
init: cli
xor ax, ax
mov ds, ax
mov es, ax
mov ss, ax
mov sp, ( stack+stacks )
; relocate
mov si, 0x7C00
mov di, $$
mov cx, (init-$$)
rep movsb
jmp 0:main
section .bss section .bss
; stack to be used during init and disk i/o ; stack to be used during init and disk i/o
stack: resw stacks stack: resw stacksize