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