Improve syscall entrypoint

This commit is contained in:
Nero 2021-01-13 17:20:49 +00:00
parent 750bfbdc60
commit 4046dd7d6c

View File

@ -32,7 +32,7 @@ stab: ; syscall table
dw err, sret ; return version num dw err, sret ; return version num
dw err, sret ; reset disks dw err, sret ; reset disks
dw setdd, sret ; select disk dw setdd, sret ; select disk
dw err, sretb ; open file dw open, sretb ; open file
.end: .end:
section .text section .text
@ -46,6 +46,8 @@ absolute 0
; saved userdata ; saved userdata
PSPAX: resw 1 PSPAX: resw 1
PSPCX: resw 1
PSPBP: resw 1
; SS:SP ; SS:SP
PSPSP: resw 1 PSPSP: resw 1
PSPSS: resw 1 PSPSS: resw 1
@ -69,11 +71,10 @@ pspds: xor ax, ax
mov ds, [curpsp] mov ds, [curpsp]
ret ret
; Fix CS:AX pointer for reloc ; Get reloc offset into CX
fixax: call .l01 reloff: call .l01
.l01: pop bx .l01: pop cx
sub bx, .l01 sub cx, .l01
add ax, bx
ret ret
int21: push ds int21: push ds
@ -82,6 +83,8 @@ int21: push ds
call pspds call pspds
pop word [PSPAX] pop word [PSPAX]
pop word [PSPDS] pop word [PSPDS]
mov [PSPCX], cx
mov [PSPBP], bp
mov [PSPSS], ss mov [PSPSS], ss
mov [PSPSP], sp mov [PSPSP], sp
mov [PSPDX], dx mov [PSPDX], dx
@ -89,27 +92,28 @@ int21: push ds
mov [PSPBX], bx mov [PSPBX], bx
mov ss, ax mov ss, ax
mov sp, ( stack+stacksize ) mov sp, stack
; get ptr to syscall table ; get offset for PIC
mov al, [PSPAX+1] call reloff
; get ptr into syscall table
mov al, [PSPAX+1] ; ah is still 0
shl ax, 1 shl ax, 1
shl ax, 1 shl ax, 1
add ax, stab add ax, stab
call fixax add ax, cx
mov bx, ax mov bx, ax
; load sysret ptr ; load sysret ptr
push bx
mov ax, [cs:bx+2] mov ax, [cs:bx+2]
call fixax add ax, cx
pop bx
push ax push ax
; load handler ptr ; load handler ptr
mov ax, [cs:bx] mov ax, [cs:bx]
call fixax add ax, cx
push ax push ax
; restore user data ; restore user data
mov bx, [PSPBX]
mov ax, [PSPAX] mov ax, [PSPAX]
mov cx, [PSPCX]
mov bx, [PSPBX]
mov ds, [PSPDS] mov ds, [PSPDS]
; launch ROP chain ; launch ROP chain
ret ret