Changeset 193 for trunk/hal/x86_64/core/hal_context.c
- Timestamp:
- Jul 13, 2017, 9:28:06 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/hal/x86_64/core/hal_context.c
r51 r193 33 33 34 34 #include <hal_context.h> 35 #include <hal_kentry.h> 36 #include <hal_internal.h> 37 #include <hal_segmentation.h> 35 38 36 #include <hal_internal.h> 39 error_t hal_cpu_context_create(struct thread_s *thread) 40 { 41 hal_cpu_context_t *context; 42 kmem_req_t req; 37 43 38 error_t hal_cpu_context_create( struct thread_s * thread ) 39 { 40 x86_panic((char *)__func__); 44 /* allocate memory for cpu_context */ 45 req.type = KMEM_CPU_CTX; 46 req.size = sizeof(hal_cpu_context_t); 47 req.flags = AF_KERNEL | AF_ZERO; 48 49 context = (hal_cpu_context_t *)kmem_alloc(&req); 50 if (context == NULL) 51 return ENOMEM; 52 53 /* set cpu context pointer in thread */ 54 thread->cpu_context = (void*)context; 55 56 /* build the context */ 57 /* tf_gs */ 58 /* tf_fs */ 59 context->tf_es = GDT_FIXED_SEL(GDT_UDATA_SEL, SEL_UPL); 60 context->tf_ds = GDT_FIXED_SEL(GDT_UDATA_SEL, SEL_UPL); 61 context->tf_rip = (uint64_t)thread->entry_func; 62 context->tf_rflags = PSL_USERSET; 63 64 if (thread->type == THREAD_USER) { 65 context->tf_cs = GDT_FIXED_SEL(GDT_UCODE_SEL, SEL_UPL); 66 context->tf_rsp = ((uint64_t)thread->u_stack_base) + 67 thread->u_stack_size; 68 } else { 69 context->tf_cs = GDT_FIXED_SEL(GDT_KCODE_SEL, SEL_KPL); 70 context->tf_rsp = ((uint64_t)thread->k_stack_base) + 71 thread->k_stack_size; 72 } 73 41 74 return 0; 42 75 }
Note: See TracChangeset
for help on using the changeset viewer.