2020-04-10 17:00:26 +02:00
|
|
|
cpu 8086
|
2020-04-18 22:59:46 +02:00
|
|
|
org 0x500
|
|
|
|
jmp init
|
2020-04-15 00:17:58 +02:00
|
|
|
|
|
|
|
%include "inc/bpb.asm"
|
|
|
|
|
|
|
|
banner: db "rdos", 0xA, 0xD, 0
|
|
|
|
|
|
|
|
; syscalls push a register set to stack
|
|
|
|
; this is for accessing it
|
|
|
|
rsdssi: equ 0x08
|
|
|
|
rsesdi: equ 0x0C
|
|
|
|
rsbp: equ 0x10
|
|
|
|
rslpad: equ 0x12
|
|
|
|
rscsip: equ 0x14
|
|
|
|
rsflag: equ 0x18
|
|
|
|
|
|
|
|
lpads: times 0x30 call entry
|
|
|
|
|
|
|
|
entry: push bp
|
|
|
|
; BX+0C: ES:DI
|
|
|
|
push es
|
|
|
|
push di
|
|
|
|
; BX+08: DS:SI
|
|
|
|
push ds
|
|
|
|
push si
|
|
|
|
; BX+00: AX,CX,DX,BX
|
|
|
|
push bx
|
|
|
|
push dx
|
|
|
|
push cx
|
2020-04-10 17:00:26 +02:00
|
|
|
push ax
|
|
|
|
|
|
|
|
mov ax, ss
|
2020-04-15 00:17:58 +02:00
|
|
|
mov es, ax
|
|
|
|
mov bx, sp
|
2020-04-10 17:00:26 +02:00
|
|
|
|
2020-04-15 00:17:58 +02:00
|
|
|
; This needs to be done when coming from userspace
|
|
|
|
mov ax, cs
|
2020-04-10 17:00:26 +02:00
|
|
|
mov ss, ax
|
2020-04-15 00:17:58 +02:00
|
|
|
xor sp, sp
|
2020-04-10 17:00:26 +02:00
|
|
|
|
2020-04-15 00:17:58 +02:00
|
|
|
; Jump back to userspace
|
|
|
|
ujump: cli
|
|
|
|
mov ax, es
|
2020-04-10 17:00:26 +02:00
|
|
|
mov ss, ax
|
2020-04-15 00:17:58 +02:00
|
|
|
mov sp, bx
|
2020-04-10 17:00:26 +02:00
|
|
|
|
2020-04-15 00:17:58 +02:00
|
|
|
; Pop whole registerset
|
|
|
|
; base registers
|
2020-04-10 17:00:26 +02:00
|
|
|
pop ax
|
2020-04-15 00:17:58 +02:00
|
|
|
pop cx
|
|
|
|
pop dx
|
|
|
|
pop bx
|
|
|
|
; string ptrs
|
|
|
|
pop si
|
|
|
|
pop ds
|
|
|
|
pop di
|
|
|
|
pop es
|
|
|
|
; BP is special
|
2020-04-10 17:00:26 +02:00
|
|
|
pop bp
|
2020-04-15 00:17:58 +02:00
|
|
|
; skip landing pad number
|
|
|
|
add sp, 2
|
|
|
|
; pop IP, CS and flags
|
2020-04-10 17:00:26 +02:00
|
|
|
iret
|
|
|
|
|
2020-04-15 00:17:58 +02:00
|
|
|
; Processes register set DS:BX as syscall
|
|
|
|
scall: ; Clear status flags
|
|
|
|
and byte [bx+rsflag], 0
|
2020-04-10 17:00:26 +02:00
|
|
|
ret
|
|
|
|
|
2020-04-15 00:17:58 +02:00
|
|
|
; No such subfunction
|
|
|
|
sferr: ; set carry
|
|
|
|
or byte [bx+rsflag], 1
|
2020-04-13 15:53:21 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
; Subfunction table
|
|
|
|
sftab: dw sferr, sferr, sferr, sferr
|
|
|
|
dw sferr, sferr, sferr, sferr
|
|
|
|
dw sferr, sferr, sferr, sferr
|
|
|
|
dw sferr, sferr, sferr, sferr
|
2020-04-13 18:03:54 +02:00
|
|
|
; 10
|
2020-04-13 15:53:21 +02:00
|
|
|
dw sferr, sferr, sferr, sferr
|
|
|
|
dw sferr, sferr, sferr, sferr
|
|
|
|
dw sferr, sferr, sferr, sferr
|
|
|
|
dw sferr, sferr, sferr, sferr
|
2020-04-13 18:03:54 +02:00
|
|
|
; 20
|
2020-04-13 15:53:21 +02:00
|
|
|
dw sferr, sferr, sferr, sferr
|
|
|
|
dw sferr, setint, sferr, sferr
|
|
|
|
dw sferr, sferr, sferr, sferr
|
|
|
|
dw sferr, sferr, sferr, sferr
|
2020-04-13 18:03:54 +02:00
|
|
|
; 30
|
2020-04-13 15:53:21 +02:00
|
|
|
dw sferr, sferr, sferr, sferr
|
2020-04-13 18:03:54 +02:00
|
|
|
dw sferr, getint, sferr, sferr
|
2020-04-13 15:53:21 +02:00
|
|
|
dw sferr, sferr, sferr, sferr
|
|
|
|
dw sferr, sferr, sferr, sferr
|
|
|
|
|
2020-04-13 18:03:54 +02:00
|
|
|
; DOS 2+ - GET INTERRUPT VECTOR
|
|
|
|
; IN al interrupt number
|
|
|
|
; OUT es:bx current interrupt handler
|
2020-04-18 23:44:16 +02:00
|
|
|
getint: xor bx, bx
|
2020-04-13 18:03:54 +02:00
|
|
|
; BX=AL*4
|
2020-04-18 23:44:16 +02:00
|
|
|
mov bl, al
|
|
|
|
add bl, bl
|
|
|
|
add bl, bl
|
|
|
|
; load vector into ES:BX
|
|
|
|
les bx, [cs:bx]
|
2020-04-13 18:03:54 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
; DOS 25h: Set interrupt vector
|
|
|
|
; IN al interrupt number
|
|
|
|
; ds:dx entry point
|
2020-04-18 23:44:16 +02:00
|
|
|
setint: push bx
|
2020-04-13 18:03:54 +02:00
|
|
|
xor bx, bx
|
|
|
|
; BX=AL*4
|
2020-04-18 23:44:16 +02:00
|
|
|
mov bl, al
|
|
|
|
add bl, bl
|
|
|
|
add bl, bl
|
|
|
|
; save DS:DX into vector
|
|
|
|
mov [cs:bx], dx
|
|
|
|
mov [cs:bx+2], ds
|
2020-04-13 15:53:21 +02:00
|
|
|
pop bx
|
2020-04-10 17:00:26 +02:00
|
|
|
ret
|
|
|
|
|
2020-04-15 00:17:58 +02:00
|
|
|
bpb: times bpb_len db 0
|
|
|
|
drvnum: db 0
|
|
|
|
align 4
|
2020-04-15 23:51:07 +02:00
|
|
|
drvoff: dd 0 ; partition offset
|
|
|
|
drvpos: dd 0 ; absolute physical sector number
|
2020-04-15 00:17:58 +02:00
|
|
|
buffer: times 512 db 0
|
|
|
|
|
2020-04-16 23:04:06 +02:00
|
|
|
; Convert between drive number and BIOS dl
|
|
|
|
; Bidirectional mapping
|
|
|
|
; 0 <-> 0, 1 <-> 1, 2 <-> 0x80, 3 <-> 0x81
|
|
|
|
dnconv: mov cx, 7
|
|
|
|
ror dx, 1
|
|
|
|
rol dl, 1
|
|
|
|
dncl: rcl dl, 1
|
|
|
|
rcr dh, 1
|
|
|
|
loop dncl
|
|
|
|
xchg dh, dl
|
2020-04-15 00:17:58 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
; Set sector number
|
|
|
|
seek: mov [drvpos], ax
|
|
|
|
mov [drvpos+2], dx
|
|
|
|
ret
|
|
|
|
|
|
|
|
; Read sector from disk
|
|
|
|
read: ; this uses the EBIOS extensions
|
|
|
|
|
|
|
|
; qword sector number
|
|
|
|
xor ax, ax
|
|
|
|
push ax
|
|
|
|
push ax
|
2020-04-16 23:04:06 +02:00
|
|
|
mov ax, [cs:drvpos+2]
|
2020-04-15 00:17:58 +02:00
|
|
|
push ax
|
2020-04-16 23:04:06 +02:00
|
|
|
mov ax, [cs:drvpos]
|
2020-04-15 00:17:58 +02:00
|
|
|
push ax
|
|
|
|
|
|
|
|
; dword target buffer
|
|
|
|
mov ax, buffer
|
|
|
|
push cs
|
|
|
|
push ax
|
|
|
|
|
|
|
|
; word number of sectors
|
|
|
|
mov ax, 1
|
|
|
|
push ax
|
|
|
|
|
|
|
|
; size & passing
|
|
|
|
mov di, 0x10
|
|
|
|
push di
|
|
|
|
|
|
|
|
mov si, sp
|
|
|
|
mov ah, 0x42
|
2020-04-16 23:04:06 +02:00
|
|
|
mov dl, [cs:drvnum]
|
2020-04-15 00:17:58 +02:00
|
|
|
call dnconv
|
|
|
|
stc
|
|
|
|
int 0x13
|
|
|
|
|
|
|
|
add sp, di
|
|
|
|
ret
|
|
|
|
|
2020-04-16 23:04:06 +02:00
|
|
|
; Select active drive
|
|
|
|
; IN dl drive number A=0, B=1, C=2, ...
|
|
|
|
select: mov [cs:drvnum], dl
|
|
|
|
ret
|
|
|
|
push es
|
|
|
|
xor ax, ax
|
|
|
|
push cs
|
|
|
|
pop es
|
|
|
|
mov si, drvoff
|
|
|
|
stosw
|
|
|
|
stosw
|
|
|
|
stosw
|
|
|
|
stosw
|
|
|
|
pop es
|
|
|
|
call read
|
|
|
|
; load bpb from buffer to bpb
|
|
|
|
ldbpb: push ds
|
|
|
|
push es
|
|
|
|
mov ax, cs
|
|
|
|
mov ds, ax
|
|
|
|
mov es, ax
|
|
|
|
mov si, buffer+0x0B
|
|
|
|
mov di, bpb
|
|
|
|
mov cx, bpb_len
|
|
|
|
rep movsb
|
|
|
|
pop es
|
|
|
|
pop ds
|
2020-04-15 00:17:58 +02:00
|
|
|
ret
|
2020-04-10 17:00:26 +02:00
|
|
|
|
2020-04-18 22:59:46 +02:00
|
|
|
main: mov si, banner
|
2020-03-25 21:56:00 +01:00
|
|
|
mov ah, 0x0e
|
|
|
|
xor bx, bx
|
|
|
|
loop: lodsb
|
|
|
|
test al, al
|
|
|
|
jz end
|
|
|
|
int 0x10
|
|
|
|
jmp loop
|
|
|
|
end: hlt
|
|
|
|
jmp end
|
|
|
|
|
2020-04-18 22:59:46 +02:00
|
|
|
init: cli
|
|
|
|
xor ax, ax
|
|
|
|
mov ds, ax
|
|
|
|
mov es, ax
|
|
|
|
mov ss, ax
|
|
|
|
xor sp, sp
|
|
|
|
|
|
|
|
mov si, 0x7C00
|
|
|
|
mov di, $$
|
|
|
|
mov cx, (init-$$)
|
|
|
|
rep movsb
|
|
|
|
|
|
|
|
call dnconv
|
|
|
|
call select
|
|
|
|
|
|
|
|
jmp 0:main
|