Skip to content

Instantly share code, notes, and snippets.

@x56
Created July 13, 2015 06:28
Show Gist options
  • Save x56/4f2dbf2f5b267d939d84 to your computer and use it in GitHub Desktop.
Save x56/4f2dbf2f5b267d939d84 to your computer and use it in GitHub Desktop.
serial_keyboard_init()
/* refer to osfmk/console/serial_general.c */
.globl _cereal64
_cereal64:
/* do the important parts of serial_keyboard_init() */
stp x20, x19, [sp, #-0x20]!
stp x29, x30, [sp, #0x10]
add x29, sp, #0x20
sub sp, sp, #0x10
/* kernel_thread_start_priority(serial_keyboard_start, NULL, MAXPRI_KERNEL, &thread); */
adr x0, L_serial_keyboard_start_ptr
ldr x0, [x0]
mov x1, #0
mov w2, #0x5f
mov x3, sp
bl _kernel_thread_start_priority_stub
/* return 1 if kernel_thread_start_priority() failed */
mov x19, x0
mov x0, #1
cbnz x19, L_return
/* thread_deallocate(thread); */
ldr x0, [sp]
bl _thread_deallocate_stub
/* return 0 on success */
mov x0, #0
L_return:
sub sp, x29, #0x20
ldp x29, x30, [sp, #0x10]
ldp x20, x19, [sp], #0x20
ret
/* kext-ish stubs */
.global _kernel_thread_start_priority_stub
_kernel_thread_start_priority_stub:
adr x16, L_kernel_thread_start_priority_ptr
ldr x16, [x16]
br x16
.global _thread_deallocate_stub
_thread_deallocate_stub:
adr x16, L_thread_deallocate_ptr
ldr x16, [x16]
br x16
/* replace with the appropriate pointers */
/* there are no symbols for these :( */
.align 4
L_serial_keyboard_start_ptr:
.quad 0xCCCCCCCCCCCCCCCC
.align 4
L_kernel_thread_start_priority_ptr:
.quad 0xDDDDDDDDDDDDDDDD
.align 4
L_thread_deallocate_ptr:
.quad 0xEEEEEEEEEEEEEEEE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment