2021-07-20 14:35:43 +03:00
|
|
|
extern _GLOBAL_OFFSET_TABLE_
|
|
|
|
|
|
|
|
section .bss
|
|
|
|
|
|
|
|
user_stack:
|
|
|
|
resq 1
|
|
|
|
|
|
|
|
user_cs: resq 1
|
|
|
|
user_ds: resq 1
|
|
|
|
user_es: resq 1
|
|
|
|
user_ss: resq 1
|
|
|
|
|
|
|
|
section .text
|
|
|
|
|
|
|
|
extern term_write
|
|
|
|
extern stivale2_rt_stack
|
2021-08-16 19:02:28 +03:00
|
|
|
extern stivale2_term_callback_ptr
|
|
|
|
|
|
|
|
global stivale2_term_callback
|
|
|
|
stivale2_term_callback:
|
|
|
|
bits 32
|
|
|
|
push ebp
|
|
|
|
mov ebp, esp
|
|
|
|
|
|
|
|
push ebx
|
|
|
|
push esi
|
|
|
|
push edi
|
|
|
|
|
|
|
|
; Go 64
|
|
|
|
push 0x28
|
|
|
|
call .p1
|
|
|
|
.p1:
|
|
|
|
add dword [esp], .mode64 - .p1
|
|
|
|
retfd
|
|
|
|
bits 64
|
|
|
|
.mode64:
|
|
|
|
mov eax, 0x30
|
|
|
|
mov ds, ax
|
|
|
|
mov es, ax
|
|
|
|
mov ss, ax
|
|
|
|
|
|
|
|
mov rdi, [rbp + 8]
|
|
|
|
mov rsi, [rbp + 16]
|
|
|
|
mov rdx, [rbp + 24]
|
|
|
|
mov rcx, [rbp + 32]
|
2022-04-01 11:00:36 +03:00
|
|
|
mov r8, [rbp + 40]
|
2021-08-16 19:02:28 +03:00
|
|
|
|
|
|
|
call .get_got
|
|
|
|
.get_got:
|
|
|
|
pop rax
|
|
|
|
add rax, _GLOBAL_OFFSET_TABLE_ + $$ - .get_got wrt ..gotpc
|
|
|
|
|
|
|
|
mov rbx, rsp
|
|
|
|
mov rsp, [rax + user_stack wrt ..gotoff]
|
|
|
|
call [rax + stivale2_term_callback_ptr wrt ..gotoff]
|
|
|
|
mov rsp, rbx
|
|
|
|
|
|
|
|
; Go 32
|
|
|
|
push 0x18
|
|
|
|
call .p2
|
|
|
|
.p2:
|
|
|
|
add qword [rsp], .mode32 - .p2
|
|
|
|
retfq
|
|
|
|
bits 32
|
|
|
|
.mode32:
|
|
|
|
mov eax, 0x20
|
|
|
|
mov ds, ax
|
|
|
|
mov es, ax
|
|
|
|
mov ss, ax
|
|
|
|
|
|
|
|
pop edi
|
|
|
|
pop esi
|
|
|
|
pop ebx
|
|
|
|
pop ebp
|
|
|
|
|
|
|
|
ret
|
2021-07-20 14:35:43 +03:00
|
|
|
|
|
|
|
bits 64
|
|
|
|
global stivale2_term_write_entry
|
|
|
|
stivale2_term_write_entry:
|
|
|
|
push rbx
|
|
|
|
push rbp
|
|
|
|
push r12
|
|
|
|
push r13
|
|
|
|
push r14
|
|
|
|
push r15
|
|
|
|
|
|
|
|
call .get_got
|
|
|
|
.get_got:
|
|
|
|
pop rbx
|
|
|
|
add ebx, _GLOBAL_OFFSET_TABLE_ + $$ - .get_got wrt ..gotpc
|
|
|
|
|
|
|
|
mov [rbx + user_stack wrt ..gotoff], rsp
|
2021-07-25 16:23:29 +03:00
|
|
|
mov esp, [rbx + stivale2_rt_stack wrt ..gotoff]
|
2021-07-20 14:35:43 +03:00
|
|
|
|
|
|
|
mov word [rbx + user_cs wrt ..gotoff], cs
|
|
|
|
mov word [rbx + user_ds wrt ..gotoff], ds
|
|
|
|
mov word [rbx + user_es wrt ..gotoff], es
|
|
|
|
mov word [rbx + user_ss wrt ..gotoff], ss
|
|
|
|
|
|
|
|
push rsi
|
2021-08-16 19:02:28 +03:00
|
|
|
push rdi
|
2021-07-20 14:35:43 +03:00
|
|
|
|
|
|
|
push 0x18
|
|
|
|
call .p1
|
|
|
|
.p1:
|
2021-08-16 19:02:28 +03:00
|
|
|
add qword [rsp], .mode32 - .p1
|
2021-07-20 14:35:43 +03:00
|
|
|
retfq
|
|
|
|
bits 32
|
|
|
|
.mode32:
|
|
|
|
mov eax, 0x20
|
|
|
|
mov ds, ax
|
|
|
|
mov es, ax
|
|
|
|
mov ss, ax
|
2021-08-16 19:02:28 +03:00
|
|
|
|
2021-07-20 14:35:43 +03:00
|
|
|
call term_write
|
2021-08-16 19:02:28 +03:00
|
|
|
add esp, 16
|
|
|
|
|
2021-07-20 14:35:43 +03:00
|
|
|
push dword [ebx + user_cs wrt ..gotoff]
|
|
|
|
call .p2
|
|
|
|
.p2:
|
2021-08-16 19:02:28 +03:00
|
|
|
add dword [esp], .mode64 - .p2
|
2021-07-20 14:35:43 +03:00
|
|
|
retfd
|
|
|
|
bits 64
|
|
|
|
.mode64:
|
|
|
|
mov ds, word [rbx + user_ds wrt ..gotoff]
|
|
|
|
mov es, word [rbx + user_es wrt ..gotoff]
|
|
|
|
mov ss, word [rbx + user_ss wrt ..gotoff]
|
|
|
|
mov rsp, [rbx + user_stack wrt ..gotoff]
|
|
|
|
|
|
|
|
pop r15
|
|
|
|
pop r14
|
|
|
|
pop r13
|
|
|
|
pop r12
|
|
|
|
pop rbp
|
|
|
|
pop rbx
|
|
|
|
|
|
|
|
ret
|