Changeset 335 for trunk/hal/x86_64


Ignore:
Timestamp:
Aug 7, 2017, 11:19:27 AM (7 years ago)
Author:
max@…
Message:

Separate the CPU context from the trap frame.

Location:
trunk/hal/x86_64
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/hal/x86_64/core/hal_context.c

    r311 r335  
    3737error_t hal_cpu_context_create(struct thread_s *thread)
    3838{
    39         hal_cpu_context_t *context;
     39        hal_trapframe_t *tf;
     40        hal_cpu_context_t *ctx;
    4041        kmem_req_t req;
    4142
     
    4546        req.flags = AF_KERNEL | AF_ZERO;
    4647
    47         context = (hal_cpu_context_t *)kmem_alloc(&req);
    48         if (context == NULL)
     48        ctx = (hal_cpu_context_t *)kmem_alloc(&req);
     49        if (ctx == NULL)
    4950                return ENOMEM;
    5051
    5152        /* set cpu context pointer in thread */
    52         thread->cpu_context = (void *)context;
     53        thread->cpu_context = (void *)ctx;
    5354
    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;
    6173
    6274        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) +
    6577                    thread->u_stack_size;
    6678        } 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) +
    6981                    thread->k_stack_size;
    7082        }
     
    7385}
    7486
    75 error_t hal_cpu_context_copy( thread_t * dst,
    76                               thread_t * src )
     87error_t hal_cpu_context_copy(thread_t *dst, thread_t *src)
    7788{
    7889        x86_panic((char *)__func__);
     
    8091}
    8192
    82 void hal_cpu_context_destroy( thread_t * thread )
     93void hal_cpu_context_destroy(thread_t *thread)
     94{
     95        x86_panic((char *)__func__);
     96}
     97
     98void hal_cpu_context_switch(thread_t *old, thread_t *new)
     99{
     100        x86_panic((char *)__func__);
     101}
     102
     103void hal_cpu_context_load( thread_t * thread )
    83104{
    84105        x86_panic((char *)__func__);
     
    103124}
    104125
    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 
    115126void hal_fpu_context_save( thread_t * thread )
    116127{
  • trunk/hal/x86_64/core/hal_exception.c

    r308 r335  
    5959 * Hexception handler.
    6060 */
    61 void hal_exception_entry(hal_cpu_context_t *ctx)
     61void hal_exception_entry(hal_trapframe_t *ctx)
    6262{
    6363        uint64_t excno = ctx->tf_trapno;
  • trunk/hal/x86_64/core/hal_interrupt.c

    r274 r335  
    3737 * Timer interrupt
    3838 */
    39 void hal_timer_intr(hal_cpu_context_t *tf)
     39void hal_timer_intr(hal_trapframe_t *tf)
    4040{
    4141        if (hal_get_gid() != 0) {
     
    5858 * Serial Port (COM1) interrupt
    5959 */
    60 void hal_com1_intr(hal_cpu_context_t *tf)
     60void hal_com1_intr(hal_trapframe_t *tf)
    6161{
    6262        static char prev;
     
    132132 * Keyboard interrupt (8042 PS/2)
    133133 */
    134 void hal_keyboard_intr(hal_cpu_context_t *tf)
     134void hal_keyboard_intr(hal_trapframe_t *tf)
    135135{
    136136        uint64_t val;
  • trunk/hal/x86_64/core/hal_kentry.h

    r308 r335  
    128128
    129129/*
    130  * The x86_64 CPU context.
     130 * The x86_64 CPU trap frame.
    131131 */
    132 typedef struct hal_cpu_context_s {
     132typedef struct hal_trapframe_s {
    133133        /* Pushed by INTR_SAVE_REGS */
    134134        uint64_t tf_rax;
     
    164164        uint64_t tf_rsp;
    165165        uint64_t tf_ss;
     166} hal_trapframe_t;
     167
     168typedef struct hal_cpu_context_s {
     169        uint64_t ctx_rsp0;
     170        uint64_t ctx_rsp;
     171        uint64_t ctx_rbp;
    166172} hal_cpu_context_t;
    167173
  • trunk/hal/x86_64/drivers/ioc_ata.c

    r322 r335  
    226226}
    227227
    228 void ioc_ata_isr(hal_cpu_context_t *ctx)
     228void ioc_ata_isr(hal_trapframe_t *ctx)
    229229{
    230230        x86_printf("rip = %Z\n", ctx->tf_rip);
Note: See TracChangeset for help on using the changeset viewer.