Changeset 335 for trunk/hal/x86_64/core/hal_context.c
- Timestamp:
- Aug 7, 2017, 11:19:27 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/hal/x86_64/core/hal_context.c
r311 r335 37 37 error_t hal_cpu_context_create(struct thread_s *thread) 38 38 { 39 hal_cpu_context_t *context; 39 hal_trapframe_t *tf; 40 hal_cpu_context_t *ctx; 40 41 kmem_req_t req; 41 42 … … 45 46 req.flags = AF_KERNEL | AF_ZERO; 46 47 47 c ontext= (hal_cpu_context_t *)kmem_alloc(&req);48 if (c ontext== NULL)48 ctx = (hal_cpu_context_t *)kmem_alloc(&req); 49 if (ctx == NULL) 49 50 return ENOMEM; 50 51 51 52 /* set cpu context pointer in thread */ 52 thread->cpu_context = (void *)c ontext;53 thread->cpu_context = (void *)ctx; 53 54 54 /* build the context */ 55 /* tf_gs */ 56 /* tf_fs */ 57 context->tf_es = GDT_FIXED_SEL(GDT_UDATA_SEL, SEL_UPL); 58 context->tf_ds = GDT_FIXED_SEL(GDT_UDATA_SEL, SEL_UPL); 59 context->tf_rip = (uint64_t)thread->entry_func; 60 context->tf_rflags = PSL_USERSET; 55 /* 56 * Build the context 57 */ 58 ctx->ctx_rsp0 = ((uint64_t)thread->k_stack_base) + thread->k_stack_size; 59 ctx->ctx_rsp0 &= ~0xF; 60 /* XXX: ctx_rsp */ 61 62 /* 63 * Build the trap frame 64 */ 65 tf = (void *)(((uint64_t)thread->k_stack_base + 66 thread->k_stack_size) & ~0xF); 67 tf->tf_gs = GDT_FIXED_SEL(GDT_UDATA_SEL, SEL_UPL); 68 tf->tf_fs = GDT_FIXED_SEL(GDT_UDATA_SEL, SEL_UPL); 69 tf->tf_es = GDT_FIXED_SEL(GDT_UDATA_SEL, SEL_UPL); 70 tf->tf_ds = GDT_FIXED_SEL(GDT_UDATA_SEL, SEL_UPL); 71 tf->tf_rip = (uint64_t)thread->entry_func; 72 tf->tf_rflags = PSL_USERSET; 61 73 62 74 if (thread->type == THREAD_USER) { 63 context->tf_cs = GDT_FIXED_SEL(GDT_UCODE_SEL, SEL_UPL);64 context->tf_rsp = ((uint64_t)thread->u_stack_base) +75 tf->tf_cs = GDT_FIXED_SEL(GDT_UCODE_SEL, SEL_UPL); 76 tf->tf_rsp = ((uint64_t)thread->u_stack_base) + 65 77 thread->u_stack_size; 66 78 } else { 67 context->tf_cs = GDT_FIXED_SEL(GDT_KCODE_SEL, SEL_KPL);68 context->tf_rsp = ((uint64_t)thread->k_stack_base) +79 tf->tf_cs = GDT_FIXED_SEL(GDT_KCODE_SEL, SEL_KPL); 80 tf->tf_rsp = ((uint64_t)thread->k_stack_base) + 69 81 thread->k_stack_size; 70 82 } … … 73 85 } 74 86 75 error_t hal_cpu_context_copy( thread_t * dst, 76 thread_t * src ) 87 error_t hal_cpu_context_copy(thread_t *dst, thread_t *src) 77 88 { 78 89 x86_panic((char *)__func__); … … 80 91 } 81 92 82 void hal_cpu_context_destroy( thread_t * thread ) 93 void hal_cpu_context_destroy(thread_t *thread) 94 { 95 x86_panic((char *)__func__); 96 } 97 98 void hal_cpu_context_switch(thread_t *old, thread_t *new) 99 { 100 x86_panic((char *)__func__); 101 } 102 103 void hal_cpu_context_load( thread_t * thread ) 83 104 { 84 105 x86_panic((char *)__func__); … … 103 124 } 104 125 105 void hal_cpu_context_switch( thread_t * old , thread_t * new )106 {107 x86_panic((char *)__func__);108 }109 110 void hal_cpu_context_load( thread_t * thread )111 {112 x86_panic((char *)__func__);113 }114 115 126 void hal_fpu_context_save( thread_t * thread ) 116 127 {
Note: See TracChangeset
for help on using the changeset viewer.