Updated kernel and programs so that the segment in which programs are loaded and executed from is no longer fixed and is specified by the kernel

This commit is contained in:
Xnoe 2021-08-31 12:15:23 +01:00
parent 514f07e009
commit d9cc9a2fb6
Signed by: xnoe
GPG Key ID: 45AC398F44F0DAFE
3 changed files with 35 additions and 12 deletions

View File

@ -1,14 +1,20 @@
mov ax, 3000h push bp
mov bp, sp
mov ax, [bp + 6]
mov ds, ax mov ds, ax
mov si, hello_world_str mov si, hello_world_str
mov ah, 01h mov ah, 01h
int 22h int 22h
pop bp
retf retf
hello_world_str db "Hello, World!", 13, 10, 13, 10, 0 hello_world_str db "Hello, World!", 13, 10, 13, 10, 0
new_line db 13, 10, 0 new_line db 13, 10, 0
buffer: buffer:
times 32 db 0 times 32 db 0
program_segment dw 0

View File

@ -92,15 +92,22 @@ clear_loop:
cmp ax, 0 cmp ax, 0
je handle_error je handle_error
; If the file exists load it at 3000h:0 ; Define the segment where we will load our programs
program_segment equ 4000h
; If the file exists load it at program_segment:0
push ax push ax
push 0 push 0
push 3000h push program_segment
call load_file call load_file
; Make a call to 3000h:0 ; Let programs know what segment they're loaded at
call 3000h:0 push program_segment
; Make a call to program_segment:0
call program_segment:0
; We've now returned. ; We've now returned.
; Clean up pushed segment
pop ax

View File

@ -1,5 +1,9 @@
mov ax, 3000h push bp
mov bp, sp
mov ax, [bp+6]
mov ds, ax mov ds, ax
mov word [program_segment], ax
mov si, filename mov si, filename
mov ah, 4 mov ah, 4
@ -10,18 +14,22 @@
mov si, ax mov si, ax
mov di, 0 mov di, 0
mov bx, 4000h mov bx, word [program_segment]
add bx, 1000h
mov ah, 3 mov ah, 3
int 22h int 22h
mov ax, 4000h push word [program_segment]
mov ax, word [program_segment]
add ax, 1000h
mov ds, ax mov ds, ax
mov si, 0 mov si, 0
mov ah, 1 mov ah, 1
int 22h int 22h
mov ax, 2000h pop ax
mov ds, ax mov ds, ax
jmp exit jmp exit
error: error:
@ -30,7 +38,9 @@ error:
int 22h int 22h
exit: exit:
retf pop bp
retf
filename db "HELLO TXT" filename db "HELLO TXT"
err_msg db "HELLO.TXT Missing!" err_msg db "HELLO.TXT Missing!"
program_segment dw 0