Ignore:
Timestamp:
Aug 7, 2017, 3:11:45 PM (7 years ago)
Author:
max@…
Message:

Add support for context switch - not tested yet, due to some other bugs in
the mapper. This cswitch is similar to that of TSAR.

File:
1 edited

Legend:

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

    r335 r339  
    3939        hal_trapframe_t *tf;
    4040        hal_cpu_context_t *ctx;
     41        uint64_t kstacktop;
    4142        kmem_req_t req;
     43
     44        kstacktop = (uint64_t)thread->k_stack_base + thread->k_stack_size;
    4245
    4346        /* allocate memory for cpu_context */
     
    5659         * Build the context
    5760         */
    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;
    6163
    6264        /*
    6365         * Build the trap frame
    6466         */
    65         tf = (void *)(((uint64_t)thread->k_stack_base +
    66             thread->k_stack_size) & ~0xF);
     67        tf = &ctx->ctx_hidden_tf;
    6768        tf->tf_gs = GDT_FIXED_SEL(GDT_UDATA_SEL, SEL_UPL);
    6869        tf->tf_fs = GDT_FIXED_SEL(GDT_UDATA_SEL, SEL_UPL);
     
    7879        } else {
    7980                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;
    8282        }
    8383
     
    9999{
    100100        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);
    101107}
    102108
Note: See TracChangeset for help on using the changeset viewer.