- Timestamp:
- Aug 7, 2017, 3:11:45 PM (7 years ago)
- Location:
- trunk/hal/x86_64/core
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/hal/x86_64/core/hal_context.c
r335 r339 39 39 hal_trapframe_t *tf; 40 40 hal_cpu_context_t *ctx; 41 uint64_t kstacktop; 41 42 kmem_req_t req; 43 44 kstacktop = (uint64_t)thread->k_stack_base + thread->k_stack_size; 42 45 43 46 /* allocate memory for cpu_context */ … … 56 59 * Build the context 57 60 */ 58 ctx->ctx_rsp0 = ((uint64_t)thread->k_stack_base) + thread->k_stack_size; 59 ctx->ctx_rsp0 &= ~0xF; 60 /* XXX: ctx_rsp */ 61 ctx->ctx_rsp0 = kstacktop & ~0xF; 62 ctx->ctx_tf = (uint64_t)&ctx->ctx_hidden_tf; 61 63 62 64 /* 63 65 * Build the trap frame 64 66 */ 65 tf = (void *)(((uint64_t)thread->k_stack_base + 66 thread->k_stack_size) & ~0xF); 67 tf = &ctx->ctx_hidden_tf; 67 68 tf->tf_gs = GDT_FIXED_SEL(GDT_UDATA_SEL, SEL_UPL); 68 69 tf->tf_fs = GDT_FIXED_SEL(GDT_UDATA_SEL, SEL_UPL); … … 78 79 } else { 79 80 tf->tf_cs = GDT_FIXED_SEL(GDT_KCODE_SEL, SEL_KPL); 80 tf->tf_rsp = ((uint64_t)thread->k_stack_base) + 81 thread->k_stack_size; 81 tf->tf_rsp = kstacktop; 82 82 } 83 83 … … 99 99 { 100 100 x86_panic((char *)__func__); 101 102 /* Switch the VM space */ 103 // TODO 104 105 /* Switch the CPU context */ 106 cpu_context_switch(old->cpu_context, new->cpu_context); 101 107 } 102 108 -
trunk/hal/x86_64/core/hal_cpu.S
r309 r339 24 24 #include <hal_segmentation.h> 25 25 #include <hal_register.h> 26 #include <hal_kentry.h> 26 27 27 28 ASM_ENTRY(lgdt) … … 181 182 /* -------------------------------------------------------------------------- */ 182 183 184 ASM_ENTRY(cpu_context_switch) 185 pushq %r12 186 pushq %r13 187 188 movq %rdi,%r13 /* oldctx */ 189 movq %rsi,%r12 /* newctx */ 190 191 /* 192 * Save the current stack in %rdx, and switch to the trap frame of 193 * the old thread. 194 */ 195 movq %rsp,%rdx 196 movq CTX_TF(%r13),%rsp 197 addq $TF_SIZE,%rsp /* end of the structure */ 198 199 /* Build the trap frame */ 200 movl %ss,%eax 201 pushq %rax /* tf_ss */ 202 pushq %rdx /* tf_rsp */ 203 pushfq /* tf_rflags */ 204 movl %cs,%eax 205 pushq %rax /* tf_cs */ 206 movabsq $thr_resume,%rax 207 pushq %rax /* tf_rip */ 208 pushq $0 /* tf_err */ 209 pushq $T_ASTFLT /* tf_trapno */ 210 INTR_SAVE_REGS 211 212 /* Switch rsp0 */ 213 movq CTX_RSP0(%r12),%rax 214 movq TLSVAR(RSP0),%rdx 215 movq %rax,(%rdx) 216 217 /* Switch to the new trap frame */ 218 movq CTX_TF(%r12),%rsp 219 220 /* 221 * Restore the context, and jump into the new thread. 222 */ 223 INTR_RESTORE_REGS 224 iretq 225 226 thr_resume: 227 /* 228 * Only pop %r12 and %r13, and return. 229 */ 230 popq %r13 231 popq %r12 232 233 ret 234 235 /* -------------------------------------------------------------------------- */ 236 183 237 ASM_ENTRY(atomic_cas_32) 184 238 movl %esi,%eax -
trunk/hal/x86_64/core/hal_init.c
r323 r339 654 654 cputls->tls_gid = hal_lapic_gid(); 655 655 cputls->tls_lid = lid; 656 /* cputls->tls_rsp0 = (uint64_t)&data->tss.tss_rsp0; */ 656 657 cputls->tls_intr = INTRS_DISABLED; 657 658 -
trunk/hal/x86_64/core/hal_internal.h
r309 r339 61 61 void wbinvd(); 62 62 63 void cpu_context_switch(void *oldctx, void *newctx); 64 63 65 uint32_t atomic_cas_32(volatile uint32_t *ptr, uint32_t exp, uint32_t new); 64 66 uint32_t atomic_add_32(volatile uint32_t *ptr, int32_t incr); -
trunk/hal/x86_64/core/hal_kentry.h
r335 r339 45 45 #define T_USER 0x100 46 46 47 #define CPUVAR(off) %gs:CPU_INFO_ ## off47 #define TLSVAR(off) %gs:TLS_ ## off 48 48 49 49 /* … … 128 128 129 129 /* 130 * The x86_64 CPU trap frame. 130 * The x86_64 CPU trap frame. !!WARNING!! The size of this structure must be 131 * exactly TF_SIZE. 131 132 */ 132 133 typedef struct hal_trapframe_s { … … 168 169 typedef struct hal_cpu_context_s { 169 170 uint64_t ctx_rsp0; 170 uint64_t ctx_ rsp;171 uint64_t ctx_rbp;171 uint64_t ctx_tf; 172 hal_trapframe_t ctx_hidden_tf; 172 173 } hal_cpu_context_t; 173 174 174 175 #else 175 176 176 /* offsets in the trapframe structure */177 /* Offsets in the trapframe structure */ 177 178 #define TF_RAX 0 178 179 #define TF_RBX 8 … … 195 196 #define TF_DS 144 196 197 198 /* Size of the trapframe structure */ 199 #define TF_SIZE 208 200 201 /* Offsets in the context structure */ 202 #define CTX_RSP0 0 203 #define CTX_TF 8 204 197 205 #endif 198 206 -
trunk/hal/x86_64/core/hal_segmentation.h
r336 r339 154 154 uint32_t tls_gid; 155 155 uint32_t tls_lid; 156 uint64_t tls_rsp0; /* pointer for fast access */ 156 157 void *tls_thr; 157 158 reg_t tls_intr; 158 void *tls_tf; 159 void *tls_tf; /* debug only */ 159 160 } __packed; 160 161 typedef struct tls tls_t; … … 169 170 170 171 #endif /* !x86_ASM */ 172 173 /* TLS offsets */ 174 #define TLS_SELF 0 175 #define TLS_GID 8 176 #define TLS_LID 12 177 #define TLS_RSP0 16 171 178 172 179 /* system segments and gate types */
Note: See TracChangeset
for help on using the changeset viewer.