1/* 2 * Copyright 2012, Alex Smith, alex@alex-smith.me.uk. 3 * Copyright 2003-2007, Axel Dörfler, axeld@pinc-software.de. 4 * Copyright 2012, Rene Gollent, rene@gollent.com. 5 * Distributed under the terms of the MIT License. 6 * 7 * Copyright 2001, Travis Geiselbrecht. All rights reserved. 8 * Copyright 2002, Michael Noisternig. All rights reserved. 9 * Distributed under the terms of the NewOS License. 10 */ 11 12 13#include <asm_defs.h> 14 15#include "asm_offsets.h" 16#include "syscall_numbers.h" 17 18 19.text 20 21 22/* addr_t x86_get_stack_frame(); */ 23FUNCTION(x86_get_stack_frame): 24 mov %rbp, %rax 25 ret 26FUNCTION_END(x86_get_stack_frame) 27 28 29/* void x86_64_thread_entry(); */ 30FUNCTION(x86_64_thread_entry): 31 xorq %rbp, %rbp 32 33 movq %rsp, %rax 34 addq $16, %rsp 35 andq $0xfffffffffffffff0, %rsp 36 subq $8, %rsp 37 38 movq 8(%rax), %rdi 39 jmp *(%rax) 40FUNCTION_END(x86_64_thread_entry) 41 42 43/* thread exit stub */ 44.align 8 45FUNCTION(x86_userspace_thread_exit): 46 movq %rax, %rdi 47 movq $SYSCALL_EXIT_THREAD, %rax 48 syscall 49.align 8 50FUNCTION_END(x86_userspace_thread_exit) 51SYMBOL(x86_end_userspace_thread_exit): 52 53 54null_idt_descr: 55 .word 0 56 .quad 0 57 58FUNCTION(x86_reboot): 59 lidt null_idt_descr 60 int $0 61done: 62 jmp done 63FUNCTION_END(x86_reboot) 64 65 66/*! \fn void arch_debug_call_with_fault_handler(cpu_ent* cpu, 67 jmp_buf jumpBuffer, void (*function)(void*), void* parameter) 68 69 Called by debug_call_with_fault_handler() to do the dirty work of setting 70 the fault handler and calling the function. If the function causes a page 71 fault, the arch_debug_call_with_fault_handler() calls longjmp() with the 72 given \a jumpBuffer. Otherwise it returns normally. 73 74 debug_call_with_fault_handler() has already saved the CPU's fault_handler 75 and fault_handler_stack_pointer and will reset them later, so 76 arch_debug_call_with_fault_handler() doesn't need to care about it. 77 78 \param cpu The \c cpu_ent for the current CPU. 79 \param jumpBuffer Buffer to be used for longjmp(). 80 \param function The function to be called. 81 \param parameter The parameter to be passed to the function to be called. 82*/ 83FUNCTION(arch_debug_call_with_fault_handler): 84 push %rbp 85 movq %rsp, %rbp 86 87 // Preserve the jump buffer address for the fault return. 88 push %rsi 89 90 // Set fault handler address, and fault handler stack pointer address. We 91 // don't need to save the previous values, since that's done by the caller. 92 movq $.L_debug_call_fault_handler, CPU_ENT_fault_handler(%rdi) 93 movq %rbp, CPU_ENT_fault_handler_stack_pointer(%rdi) 94 95 // Call the function. 96 movq %rcx, %rdi 97 call *%rdx 98 99 // Regular return. 100 movq %rbp, %rsp 101 pop %rbp 102 ret 103 104.L_debug_call_fault_handler: 105 // Fault -- return via longjmp(jumpBuffer, 1) 106 movq %rbp, %rsp 107 movq -8(%rsp), %rdi 108 movq $1, %rsi 109 call longjmp 110FUNCTION_END(arch_debug_call_with_fault_handler) 111