Remove PIC functionality from syscall.asm
Makes things easier
This commit is contained in:
parent
23c6223055
commit
df243e668e
@ -11,7 +11,7 @@ section .bss
|
||||
|
||||
curpsp: resw 1
|
||||
|
||||
section .data
|
||||
section .rodata
|
||||
|
||||
stab: ; syscall table
|
||||
; cells: ptr to handler, ptr to sysret
|
||||
@ -47,7 +47,6 @@ absolute 0
|
||||
; saved userdata
|
||||
PSPAX: resw 1
|
||||
PSPCX: resw 1
|
||||
PSPBP: resw 1
|
||||
; SS:SP
|
||||
PSPSP: resw 1
|
||||
PSPSS: resw 1
|
||||
@ -63,59 +62,35 @@ PSPDD: resb 1
|
||||
|
||||
section .text
|
||||
|
||||
; Load current PSP segment into DS
|
||||
; OUT ds PSP segment
|
||||
; ax 0
|
||||
pspds: xor ax, ax
|
||||
mov ds, ax
|
||||
mov ds, [curpsp]
|
||||
ret
|
||||
|
||||
; Get reloc offset into CX
|
||||
reloff: call .l01
|
||||
.l01: pop cx
|
||||
sub cx, .l01
|
||||
ret
|
||||
|
||||
; WARNING: BP, SI and DI are not saved
|
||||
; If kernel code uses them, they need to be saved to the stack
|
||||
int21: push ds
|
||||
; load program PSP and save userdata
|
||||
push ax
|
||||
call pspds
|
||||
pop word [PSPAX]
|
||||
mov ds, [cs:curpsp]
|
||||
pop word [PSPDS]
|
||||
mov [PSPCX], cx
|
||||
mov [PSPBP], bp
|
||||
mov [PSPSS], ss
|
||||
mov [PSPSP], sp
|
||||
mov [PSPDX], dx
|
||||
mov [PSPES], es
|
||||
|
||||
mov [PSPAX], ax
|
||||
mov [PSPCX], cx
|
||||
mov [PSPDX], dx
|
||||
mov [PSPBX], bx
|
||||
|
||||
mov ss, ax
|
||||
mov [PSPSS], ss
|
||||
mov [PSPSP], sp
|
||||
|
||||
xor bx, bx
|
||||
mov ss, bx
|
||||
mov sp, stack
|
||||
; get offset for PIC
|
||||
call reloff
|
||||
; get ptr into syscall table
|
||||
mov al, [PSPAX+1] ; ah is still 0
|
||||
shl ax, 1
|
||||
shl ax, 1
|
||||
add ax, stab
|
||||
add ax, cx
|
||||
mov bx, ax
|
||||
; load sysret ptr
|
||||
mov ax, [cs:bx+2]
|
||||
add ax, cx
|
||||
push ax
|
||||
; load handler ptr
|
||||
mov ax, [cs:bx]
|
||||
add ax, cx
|
||||
push ax
|
||||
; restore user data
|
||||
mov ax, [PSPAX]
|
||||
mov cx, [PSPCX]
|
||||
mov bl, [PSPAX+1] ; bh is still 0
|
||||
shl bx, 1
|
||||
shl bx, 1
|
||||
add bx, stab
|
||||
; load sysret and handler ptr
|
||||
push word [cs:bx+2]
|
||||
push word [cs:bx]
|
||||
; restore user data and launch ret chain
|
||||
mov bx, [PSPBX]
|
||||
mov ds, [PSPDS]
|
||||
; launch ROP chain
|
||||
ret
|
||||
|
||||
err: mov ah, 0xFF
|
||||
@ -123,25 +98,26 @@ err: mov ah, 0xFF
|
||||
|
||||
; sysret handlers
|
||||
; return ES:BX to user
|
||||
sretd: mov ds, [ss:curpsp]
|
||||
sretd: mov ds, [cs:curpsp]
|
||||
jmp sret.l02
|
||||
|
||||
; return BX to user
|
||||
sretw: mov ds, [ss:curpsp]
|
||||
sretw: mov ds, [cs:curpsp]
|
||||
mov es, [PSPES]
|
||||
jmp sret.l02
|
||||
|
||||
; return AL to user
|
||||
sretb: mov ds, [ss:curpsp]
|
||||
sretb: mov ds, [cs:curpsp]
|
||||
mov ah, [PSPAX+1]
|
||||
les bx, [PSPBX]
|
||||
jmp sret.l03
|
||||
|
||||
; return without result
|
||||
sret: mov ds, [ss:curpsp]
|
||||
.l01: les bx, [PSPBX]
|
||||
sret: mov ds, [cs:curpsp]
|
||||
les bx, [PSPBX]
|
||||
.l02: mov ax, [PSPAX]
|
||||
.l03: mov ss, [PSPSS]
|
||||
mov sp, [PSPSP]
|
||||
lds dx, [PSPDX]
|
||||
mov cx, [PSPCX]
|
||||
lds dx, [PSPDX] ; DS last
|
||||
iret
|
||||
|
Loading…
Reference in New Issue
Block a user