2024-03-26 00:07:24 +02:00
|
|
|
# uint64_t read_ip()
|
2024-03-22 14:48:33 +02:00
|
|
|
.global read_ip
|
|
|
|
read_ip:
|
2023-02-02 23:24:12 +02:00
|
|
|
popq %rax
|
|
|
|
jmp *%rax
|
|
|
|
|
2024-04-02 12:34:42 +03:00
|
|
|
# void start_kernel_thread()
|
2024-03-29 18:02:12 +02:00
|
|
|
.global start_kernel_thread
|
|
|
|
start_kernel_thread:
|
2024-04-03 02:23:23 +03:00
|
|
|
call get_thread_start_sp
|
2024-04-02 12:34:42 +03:00
|
|
|
movq %rax, %rsp
|
|
|
|
|
2024-03-29 18:02:12 +02:00
|
|
|
# STACK LAYOUT
|
|
|
|
# on_exit arg
|
|
|
|
# on_exit func
|
|
|
|
# entry arg
|
|
|
|
# entry func
|
2023-02-02 23:24:12 +02:00
|
|
|
|
2024-03-29 18:02:12 +02:00
|
|
|
movq 8(%rsp), %rdi
|
|
|
|
movq 0(%rsp), %rsi
|
2024-04-02 12:34:42 +03:00
|
|
|
sti
|
2024-03-29 18:02:12 +02:00
|
|
|
call *%rsi
|
2023-04-12 17:51:36 +03:00
|
|
|
|
2024-03-29 18:02:12 +02:00
|
|
|
movq 24(%rsp), %rdi
|
|
|
|
movq 16(%rsp), %rsi
|
|
|
|
call *%rsi
|
2024-04-03 00:42:39 +03:00
|
|
|
|
|
|
|
.global start_userspace_thread
|
|
|
|
start_userspace_thread:
|
2024-04-03 02:23:23 +03:00
|
|
|
call get_thread_start_sp
|
2024-04-03 00:42:39 +03:00
|
|
|
movq %rax, %rsp
|
|
|
|
|
|
|
|
# STACK LAYOUT
|
|
|
|
# entry
|
|
|
|
# argc
|
|
|
|
# argv
|
|
|
|
# envp
|
|
|
|
# userspace stack
|
|
|
|
|
|
|
|
call get_userspace_thread_stack_top
|
|
|
|
|
|
|
|
popq %rdi
|
2024-08-28 17:06:32 +03:00
|
|
|
popq %rsi
|
|
|
|
popq %rdx
|
2024-04-03 00:42:39 +03:00
|
|
|
popq %rcx
|
2024-08-28 17:06:32 +03:00
|
|
|
popq %rbx
|
2024-04-03 00:42:39 +03:00
|
|
|
|
|
|
|
pushq $(0x20 | 3)
|
|
|
|
pushq %rax
|
|
|
|
pushq $0x202
|
|
|
|
pushq $(0x18 | 3)
|
2024-08-28 17:06:32 +03:00
|
|
|
pushq %rbx
|
2024-04-03 00:42:39 +03:00
|
|
|
iretq
|