Changes in kernel/arch/amd64/src/asm.S [e98f1c3e:45f7449] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/arch/amd64/src/asm.S
re98f1c3e r45f7449 27 27 */ 28 28 29 #include <abi/asmtool.h>30 29 #include <arch/pm.h> 31 30 #include <arch/mm/page.h> 32 #include <arch/istate_struct.h>33 #include <arch/kseg_struct.h>34 #include <arch/cpu.h>35 #include <arch/smp/apic.h>36 31 37 32 .text 33 .global interrupt_handlers 34 .global syscall_entry 35 .global cpuid 36 .global has_cpuid 37 .global read_efer_flag 38 .global set_efer_flag 39 .global memcpy_from_uspace 40 .global memcpy_to_uspace 41 .global memcpy_from_uspace_failover_address 42 .global memcpy_to_uspace_failover_address 43 .global early_putchar 38 44 39 45 #define MEMCPY_DST %rdi … … 57 63 * 58 64 */ 59 FUNCTION_BEGIN(memcpy_from_uspace) 60 FUNCTION_BEGIN(memcpy_to_uspace) 65 memcpy_from_uspace: 66 memcpy_to_uspace: 61 67 movq MEMCPY_DST, %rax 62 68 … … 74 80 0: 75 81 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) 82 83 memcpy_from_uspace_failover_address: 84 memcpy_to_uspace_failover_address: 81 85 xorl %eax, %eax /* return 0, failure */ 82 86 ret … … 87 91 * 88 92 */ 89 FUNCTION_BEGIN(has_cpuid) 93 has_cpuid: 90 94 /* Load RFLAGS */ 91 95 pushfq … … 94 98 95 99 /* Flip the ID bit */ 96 xorl $RFLAGS_ID, %edx100 btcl $21, %edx 97 101 98 102 /* Store RFLAGS */ … … 103 107 /* Get the ID bit again */ 104 108 popq %rdx 105 andl $ RFLAGS_ID, %eax106 andl $ RFLAGS_ID, %edx109 andl $(1 << 21), %eax 110 andl $(1 << 21), %edx 107 111 108 112 /* 0 if not supported, 1 if supported */ 109 113 xorl %edx, %eax 110 114 ret 111 FUNCTION_END(has_cpuid) 112 113 FUNCTION_BEGIN(cpuid) 115 116 cpuid: 114 117 /* Preserve %rbx across function calls */ 115 118 movq %rbx, %r10 … … 126 129 movq %r10, %rbx 127 130 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 131 132 set_efer_flag: 133 movl $0xc0000080, %ecx 137 134 rdmsr 138 orl $(L_APIC_BASE | AMD_APIC_BASE_GE), %eax135 btsl %edi, %eax 139 136 wrmsr 140 137 ret 141 FUNCTION_END(enable_l_apic_in_msr) 138 139 read_efer_flag: 140 movl $0xc0000080, %ecx 141 rdmsr 142 ret 143 144 #define ISTATE_OFFSET_RAX 0 145 #define ISTATE_OFFSET_RBX 8 146 #define ISTATE_OFFSET_RCX 16 147 #define ISTATE_OFFSET_RDX 24 148 #define ISTATE_OFFSET_RSI 32 149 #define ISTATE_OFFSET_RDI 40 150 #define ISTATE_OFFSET_RBP 48 151 #define ISTATE_OFFSET_R8 56 152 #define ISTATE_OFFSET_R9 64 153 #define ISTATE_OFFSET_R10 72 154 #define ISTATE_OFFSET_R11 80 155 #define ISTATE_OFFSET_R12 88 156 #define ISTATE_OFFSET_R13 96 157 #define ISTATE_OFFSET_R14 104 158 #define ISTATE_OFFSET_R15 112 159 #define ISTATE_OFFSET_ALIGNMENT 120 160 #define ISTATE_OFFSET_RBP_FRAME 128 161 #define ISTATE_OFFSET_RIP_FRAME 136 162 #define ISTATE_OFFSET_ERROR_WORD 144 163 #define ISTATE_OFFSET_RIP 152 164 #define ISTATE_OFFSET_CS 160 165 #define ISTATE_OFFSET_RFLAGS 168 166 #define ISTATE_OFFSET_RSP 176 167 #define ISTATE_OFFSET_SS 184 142 168 143 169 /* … … 145 171 * error word. 146 172 */ 147 #define ISTATE_SOFT_SIZE ISTATE_SIZE - (6 * 8)173 #define ISTATE_SOFT_SIZE 144 148 174 149 175 /** … … 155 181 156 182 .macro handler i 157 SYMBOL(int_\i) 183 .global int_\i 184 int_\i: 158 185 159 186 /* … … 201 228 202 229 /* 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 230 * Imitate a regular stack frame linkage. 220 231 * Stop stack traces here if we came from userspace. 221 232 */ 222 0: movl $0x0, %edx 233 xorl %edx, %edx 234 cmpq $(GDT_SELECTOR(KTEXT_DES)), ISTATE_OFFSET_CS(%rsp) 223 235 cmovnzq %rdx, %rbp 224 236 … … 261 273 53,54,55,56,57,58,59,60,61,62,63 262 274 263 SYMBOL(interrupt_handlers) 275 interrupt_handlers: 264 276 .irp cnt, LIST_0_63 265 277 handler \cnt … … 285 297 * 286 298 */ 287 SYMBOL(syscall_entry) 299 syscall_entry: 288 300 /* Switch to hidden %gs */ 289 301 swapgs 290 302 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 303 /* 304 * %gs:0 Scratch space for this thread's user RSP 305 * %gs:8 Address to be used as this thread's kernel RSP 306 */ 307 308 movq %rsp, %gs:0 /* save this thread's user RSP */ 309 movq %gs:8, %rsp /* set this thread's kernel RSP */ 310 294 311 /* 295 312 * Note that the space needed for the imitated istate structure has been … … 320 337 321 338 /* 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 339 * Save the return address and the userspace stack on locations that 332 340 * would normally be taken by them. 333 341 */ 334 movq %gs: KSEG_OFFSET_USTACK_RSP, %rax342 movq %gs:0, %rax 335 343 movq %rax, ISTATE_OFFSET_RSP(%rsp) 336 344 movq %rcx, ISTATE_OFFSET_RIP(%rsp) … … 412 420 * 413 421 */ 414 FUNCTION_BEGIN(early_putchar) 422 early_putchar: 423 415 424 #if ((defined(CONFIG_EGA)) && (!defined(CONFIG_FB))) 416 425 … … 540 549 541 550 ret 542 FUNCTION_END(early_putchar) 551
Note:
See TracChangeset
for help on using the changeset viewer.