Changeset 296426ad in mainline
- Timestamp:
- 2007-11-16T16:17:18Z (17 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 9c2fb97
- Parents:
- e686744c
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/arch/amd64/include/proc/thread.h
re686744c r296426ad 36 36 #define KERN_amd64_THREAD_H_ 37 37 38 /* CAUTION: keep these in sync with low level assembly code in syscall_entry */ 39 #define SYSCALL_USTACK_RSP 0 40 #define SYSCALL_KSTACK_RSP 1 41 38 42 typedef struct { 39 43 unative_t tls; 44 /** User and kernel RSP for syscalls. */ 45 uint64_t syscall_rsp[2]; 40 46 } thread_arch_t; 41 47 -
kernel/arch/amd64/src/asm_utils.S
re686744c r296426ad 221 221 222 222 /* 223 * Choose between version with error code and version without error code. 224 * Both versions have to be of the same size. amd64 assembly is, however, 225 * a little bit tricky. For instance, subq $0x80, %rsp and subq $0x78, %rsp 226 * can result in two instructions with different op-code lengths. 223 * Choose between version with error code and version without error 224 * code. Both versions have to be of the same size. amd64 assembly is, 225 * however, a little bit tricky. For instance, subq $0x80, %rsp and 226 * subq $0x78, %rsp can result in two instructions with different 227 * op-code lengths. 227 228 * Therefore we align the interrupt handlers. 228 229 */ … … 270 271 h_end: 271 272 272 273 ## Low-level syscall handler 274 # 275 # Registers on entry: 276 # 277 # @param rcx Userspace return address. 278 # @param r11 Userspace RLFAGS. 279 # 280 # @param rax Syscall number. 281 # @param rdi 1st syscall argument. 282 # @param rsi 2nd syscall argument. 283 # @param rdx 3rd syscall argument. 284 # @param r10 4th syscall argument. Used instead of RCX because the 285 # SYSCALL instruction clobbers it. 286 # @param r8 5th syscall argument. 287 # @param r9 6th syscall argument. 288 # 289 # @return Return value is in rax. 290 # 273 291 syscall_entry: 274 # Switch to hidden gs 275 swapgs 276 # %gs:0 now points to pointer to stack page 277 mov %gs:0, %r10 # We have a ptr to stack page in r10 278 addq $PAGE_SIZE-16, %r10 # We need some space to store old %sp 279 280 movq %rsp, 0(%r10) # Save old stack pointer to stack 281 movq %r10, %rsp # Change to new stack 282 pushq %rcx # Return address 283 pushq %r11 # Save flags 284 285 # Switch back to remain consistent 286 swapgs 287 292 swapgs # Switch to hidden gs 293 # 294 # %gs:0 Scratch space for this thread's user RSP 295 # %gs:8 Address to be used as this thread's kernel RSP 296 # 297 movq %rsp, %gs:0 # Save this thread's user RSP 298 movq %gs:8, %rsp # Set this thread's kernel RSP 299 swapgs # Switch back to remain consistent 288 300 sti 289 movq %r9, %rcx # Exchange last parameter as a third 290 301 302 pushq %rcx 303 pushq %r11 304 305 movq %r10, %rcx # Copy the 4th argument where it is expected 306 pushq %rax 291 307 call syscall_handler 292 cli # We will be touching stack pointer308 addq $8, %rsp 293 309 294 310 popq %r11 295 311 popq %rcx 296 movq 0(%rsp), %rsp 312 313 cli 314 swapgs 315 movq %gs:0, %rsp # Restore the user RSP 316 swapgs 317 297 318 sysretq 298 299 319 300 320 .data 301 321 .global interrupt_handler_size -
kernel/arch/amd64/src/proc/scheduler.c
re686744c r296426ad 57 57 void before_thread_runs_arch(void) 58 58 { 59 CPU->arch.tss->rsp0 = (uintptr_t) &THREAD->kstack[THREAD_STACK_SIZE-SP_DELTA]; 59 CPU->arch.tss->rsp0 = 60 (uintptr_t) &THREAD->kstack[THREAD_STACK_SIZE - SP_DELTA]; 60 61 61 /* Syscall support - write address of thread stack pointer to 62 * hidden part of gs */ 62 /* 63 * Syscall support. 64 */ 63 65 swapgs(); 64 write_msr(AMD_MSR_GS, (uint 64_t)&THREAD->kstack);66 write_msr(AMD_MSR_GS, (uintptr_t)THREAD->arch.syscall_rsp); 65 67 swapgs(); 66 68 … … 72 74 if (CPU->id < BKPOINTS_MAX) 73 75 breakpoint_add(&((the_t *) THREAD->kstack)->as, 74 BKPOINT_WRITE | BKPOINT_CHECK_ZERO, 75 CPU->id); 76 BKPOINT_WRITE | BKPOINT_CHECK_ZERO, CPU->id); 76 77 #endif 77 78 } -
kernel/arch/amd64/src/proc/thread.c
re686744c r296426ad 42 42 { 43 43 t->arch.tls = 0; 44 t->arch.syscall_rsp[SYSCALL_USTACK_RSP] = 0; 45 /* 46 * Kernel RSP can be precalculated at thread creation time. 47 */ 48 t->arch.syscall_rsp[SYSCALL_KSTACK_RSP] = 49 (uintptr_t)&t->kstack[PAGE_SIZE - sizeof(uint64_t)]; 44 50 } 45 51 -
kernel/arch/amd64/src/syscall.c
re686744c r296426ad 53 53 /* Setup syscall entry address */ 54 54 55 /* This is _mess_ - the 64-bit CS is argument +16,56 * the SS is argument +8. The order is:55 /* This is _mess_ - the 64-bit CS is argument + 16, 56 * the SS is argument + 8. The order is: 57 57 * +0(KDATA_DES), +8(UDATA_DES), +16(UTEXT_DES) 58 58 */ 59 59 write_msr(AMD_MSR_STAR, 60 ((uint64_t)(gdtselector(KDATA_DES) | PL_USER)<<48) \61 | ((uint64_t)(gdtselector(KTEXT_DES) | PL_KERNEL)<<32));60 ((uint64_t)(gdtselector(KDATA_DES) | PL_USER) << 48) | 61 ((uint64_t)(gdtselector(KTEXT_DES) | PL_KERNEL) << 32)); 62 62 write_msr(AMD_MSR_LSTAR, (uint64_t)syscall_entry); 63 63 /* Mask RFLAGS on syscall -
uspace/lib/libc/arch/amd64/src/fibril.S
re686744c r296426ad 81 81 # Set thread local storage 82 82 movq OFFSET_TLS(%rdi), %rdi # Set arg1 to TLS addr 83 movq $1, %r 883 movq $1, %rax # SYS_TLS_SET 84 84 syscall 85 85 -
uspace/lib/libc/arch/amd64/src/syscall.S
re686744c r296426ad 29 29 .text 30 30 31 .globl __syscall 31 .global __syscall 32 33 ## Make a system call. 34 # 35 # @param rdi First argument. 36 # @param rsi Second argument. 37 # @param rdx Third argument. 38 # @param rcx Fourth argument. 39 # @param r8 Fifth argument. 40 # @param r9 Sixth argument. 41 # @param 8(%rsp) Syscall number. 42 # 43 # @return The return value will be stored in RAX. 44 # 45 __syscall: 46 # 47 # Move the syscall number into RAX. 48 movslq 8(%rsp), %rax 32 49 33 34 __syscall: 35 # rcx gets rewritten on syscall 36 movq %rcx, %r9 50 # 51 # Save RCX, the 4th argument, aside because RCX gets rewritten by the 52 # SYSCALL instruction. 53 # 54 movq %rcx, %r10 37 55 syscall 38 56 ret 39 40 .end __syscall 57
Note:
See TracChangeset
for help on using the changeset viewer.