X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/fe8ab488e9161c46dd9885d58fc52996dc0249ff..d9a64523371fa019c4575bb400cbbc3a50ac9903:/osfmk/x86_64/locore.s diff --git a/osfmk/x86_64/locore.s b/osfmk/x86_64/locore.s index ca044a570..d88f2a08a 100644 --- a/osfmk/x86_64/locore.s +++ b/osfmk/x86_64/locore.s @@ -54,7 +54,7 @@ * the rights to redistribute these changes. */ -#include +#include #include #include @@ -62,6 +62,7 @@ #include #include #include +#include #include #include #include @@ -71,8 +72,6 @@ #define _ARCH_I386_ASM_HELP_H_ /* Prevent inclusion of user header */ #include -#include - /* * Fault recovery. */ @@ -81,7 +80,6 @@ #define RECOVERY_SECTION .section __VECTORS, __recover #else #define RECOVERY_SECTION .text -#define RECOVERY_SECTION .text #endif #define RECOVER_TABLE_START \ @@ -160,14 +158,28 @@ wrmsr_fail: movl $1, %eax ret +#if DEBUG +#ifndef TERI +#define TERI 1 +#endif +#endif + +#if TERI +.globl EXT(thread_exception_return_internal) +#else .globl EXT(thread_exception_return) +#endif .globl EXT(thread_bootstrap_return) LEXT(thread_bootstrap_return) #if CONFIG_DTRACE call EXT(dtrace_thread_bootstrap) #endif +#if TERI +LEXT(thread_exception_return_internal) +#else LEXT(thread_exception_return) +#endif cli xorl %ecx, %ecx /* don't check if we're in the PFZ */ jmp EXT(return_from_trap) @@ -176,22 +188,21 @@ LEXT(thread_exception_return) * Copyin/out from user/kernel address space. * rdi: source address * rsi: destination address - * rdx: byte count + * rdx: byte count (in fact, always < 64MB -- see copyio) */ Entry(_bcopy) -// TODO not pop regs; movq; think about 32 bit or 64 bit byte count - xchgq %rdi, %rsi /* source %rsi, dest %rdi */ + xchg %rdi, %rsi /* source %rsi, dest %rdi */ cld /* count up */ - movl %edx,%ecx /* move by longwords first */ - shrl $3,%ecx + mov %rdx, %rcx /* move by longwords first */ + shr $3, %rcx RECOVERY_SECTION RECOVER(_bcopy_fail) rep movsq /* move longwords */ - movl %edx,%ecx /* now move remaining bytes */ - andl $7,%ecx + movl %edx, %ecx /* now move remaining bytes */ + andl $7, %ecx RECOVERY_SECTION RECOVER(_bcopy_fail) rep @@ -307,9 +318,53 @@ _bcopystr_fail: movl $(EFAULT),%eax /* return error for failure */ ret +/* + * Copyin 32 or 64 bit aligned word as a single transaction + * rdi: source address (user) + * rsi: destination address (kernel) + * rdx: size (4 or 8) + */ +Entry(_copyin_word) + pushq %rbp /* Save registers */ + movq %rsp, %rbp + cmpl $0x4, %edx /* If size = 4 */ + je L_copyin_word_4 /* handle 32-bit load */ + movl $(EINVAL), %eax /* Set up error status */ + cmpl $0x8, %edx /* If size != 8 */ + jne L_copyin_word_exit /* exit with error */ + RECOVERY_SECTION + RECOVER(L_copyin_word_fail) /* Set up recovery handler for next instruction*/ + movq (%rdi), %rax /* Load quad from user */ + jmp L_copyin_word_store +L_copyin_word_4: + RECOVERY_SECTION + RECOVER(L_copyin_word_fail) /* Set up recovery handler for next instruction */ + movl (%rdi), %eax /* Load long from user */ +L_copyin_word_store: + movq %rax, (%rsi) /* Store to kernel */ + xorl %eax, %eax /* Return success */ +L_copyin_word_exit: + popq %rbp /* Restore registers */ + retq /* Return */ + +L_copyin_word_fail: + movl $(EFAULT), %eax /* Return error for failure */ + popq %rbp /* Restore registers */ + retq /* Return */ + + /* * Done with recovery table. */ RECOVERY_SECTION RECOVER_TABLE_END + +/* + * Vector here on any exception at startup prior to switching to + * the kernel's idle page-tables and installing the kernel master IDT. + */ +Entry(vstart_trap_handler) + POSTCODE(BOOT_TRAP_HLT) + hlt +