Changes in kernel/arch/amd64/src/asm.S [e98f1c3e:4236b18] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/arch/amd64/src/asm.S
re98f1c3e r4236b18 27 27 */ 28 28 29 #include <abi/asmtool.h>30 29 #include <arch/pm.h> 31 30 #include <arch/mm/page.h> 32 31 #include <arch/istate_struct.h> 33 #include <arch/kseg_struct.h>34 #include <arch/cpu.h>35 #include <arch/smp/apic.h>36 32 37 33 .text 34 .global interrupt_handlers 35 .global syscall_entry 36 .global cpuid 37 .global has_cpuid 38 .global read_efer_flag 39 .global set_efer_flag 40 .global memcpy_from_uspace 41 .global memcpy_to_uspace 42 .global memcpy_from_uspace_failover_address 43 .global memcpy_to_uspace_failover_address 44 .global early_putchar 38 45 39 46 #define MEMCPY_DST %rdi … … 57 64 * 58 65 */ 59 FUNCTION_BEGIN(memcpy_from_uspace) 60 FUNCTION_BEGIN(memcpy_to_uspace) 66 memcpy_from_uspace: 67 memcpy_to_uspace: 61 68 movq MEMCPY_DST, %rax 62 69 … … 74 81 0: 75 82 ret /* return MEMCPY_SRC, success */ 76 FUNCTION_END(memcpy_from_uspace) 77 FUNCTION_END(memcpy_to_uspace) 78 79 SYMBOL(memcpy_from_uspace_failover_address) 80 SYMBOL(memcpy_to_uspace_failover_address) 83 84 memcpy_from_uspace_failover_address: 85 memcpy_to_uspace_failover_address: 81 86 xorl %eax, %eax /* return 0, failure */ 82 87 ret … … 87 92 * 88 93 */ 89 FUNCTION_BEGIN(has_cpuid) 94 has_cpuid: 90 95 /* Load RFLAGS */ 91 96 pushfq … … 94 99 95 100 /* Flip the ID bit */ 96 xorl $RFLAGS_ID, %edx101 btcl $21, %edx 97 102 98 103 /* Store RFLAGS */ … … 103 108 /* Get the ID bit again */ 104 109 popq %rdx 105 andl $ RFLAGS_ID, %eax106 andl $ RFLAGS_ID, %edx110 andl $(1 << 21), %eax 111 andl $(1 << 21), %edx 107 112 108 113 /* 0 if not supported, 1 if supported */ 109 114 xorl %edx, %eax 110 115 ret 111 FUNCTION_END(has_cpuid) 112 113 FUNCTION_BEGIN(cpuid) 116 117 cpuid: 114 118 /* Preserve %rbx across function calls */ 115 119 movq %rbx, %r10 … … 126 130 movq %r10, %rbx 127 131 ret 128 FUNCTION_END(cpuid) 129 130 /** Enable local APIC 131 * 132 * Enable local APIC in MSR. 133 * 134 */ 135 FUNCTION_BEGIN(enable_l_apic_in_msr) 136 movl $AMD_MSR_APIC_BASE, %ecx 132 133 set_efer_flag: 134 movl $0xc0000080, %ecx 137 135 rdmsr 138 orl $(L_APIC_BASE | AMD_APIC_BASE_GE), %eax136 btsl %edi, %eax 139 137 wrmsr 140 138 ret 141 FUNCTION_END(enable_l_apic_in_msr) 139 140 read_efer_flag: 141 movl $0xc0000080, %ecx 142 rdmsr 143 ret 142 144 143 145 /* … … 155 157 156 158 .macro handler i 157 SYMBOL(int_\i) 159 .global int_\i 160 int_\i: 158 161 159 162 /* … … 201 204 202 205 /* 203 * Is this trap from the kernel?204 */205 cmpq $(GDT_SELECTOR(KTEXT_DES)), ISTATE_OFFSET_CS(%rsp)206 jz 0f207 208 /*209 * Switch to kernel FS base.210 */211 swapgs212 movl $AMD_MSR_FS, %ecx213 movl %gs:KSEG_OFFSET_FSBASE, %eax214 movl %gs:KSEG_OFFSET_FSBASE+4, %edx215 wrmsr216 swapgs217 218 /*219 206 * Imitate a regular stack frame linkage. 220 207 * Stop stack traces here if we came from userspace. 221 208 */ 222 0: movl $0x0, %edx 209 xorl %edx, %edx 210 cmpq $(GDT_SELECTOR(KTEXT_DES)), ISTATE_OFFSET_CS(%rsp) 223 211 cmovnzq %rdx, %rbp 224 212 … … 261 249 53,54,55,56,57,58,59,60,61,62,63 262 250 263 SYMBOL(interrupt_handlers) 251 interrupt_handlers: 264 252 .irp cnt, LIST_0_63 265 253 handler \cnt … … 285 273 * 286 274 */ 287 SYMBOL(syscall_entry) 275 syscall_entry: 288 276 /* Switch to hidden %gs */ 289 277 swapgs 290 278 291 movq %rsp, %gs:KSEG_OFFSET_USTACK_RSP /* save this thread's user RSP */ 292 movq %gs:KSEG_OFFSET_KSTACK_RSP, %rsp /* set this thread's kernel RSP */ 293 279 /* 280 * %gs:0 Scratch space for this thread's user RSP 281 * %gs:8 Address to be used as this thread's kernel RSP 282 */ 283 284 movq %rsp, %gs:0 /* save this thread's user RSP */ 285 movq %gs:8, %rsp /* set this thread's kernel RSP */ 286 294 287 /* 295 288 * Note that the space needed for the imitated istate structure has been … … 320 313 321 314 /* 322 * Switch to kernel FS base.323 */324 movl $AMD_MSR_FS, %ecx325 movl %gs:KSEG_OFFSET_FSBASE, %eax326 movl %gs:KSEG_OFFSET_FSBASE+4, %edx327 wrmsr328 movq ISTATE_OFFSET_RDX(%rsp), %rdx /* restore 3rd argument */329 330 /*331 315 * Save the return address and the userspace stack on locations that 332 316 * would normally be taken by them. 333 317 */ 334 movq %gs: KSEG_OFFSET_USTACK_RSP, %rax318 movq %gs:0, %rax 335 319 movq %rax, ISTATE_OFFSET_RSP(%rsp) 336 320 movq %rcx, ISTATE_OFFSET_RIP(%rsp) … … 412 396 * 413 397 */ 414 FUNCTION_BEGIN(early_putchar) 398 early_putchar: 399 415 400 #if ((defined(CONFIG_EGA)) && (!defined(CONFIG_FB))) 416 401 … … 540 525 541 526 ret 542 FUNCTION_END(early_putchar) 527
Note:
See TracChangeset
for help on using the changeset viewer.