Changeset 193 for trunk


Ignore:
Timestamp:
Jul 13, 2017, 9:28:06 AM (7 years ago)
Author:
max@…
Message:

build the context

Location:
trunk/hal/x86_64/core
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/hal/x86_64/core/hal_boot.S

    r145 r193  
    2626#include <hal_multiboot.h>
    2727#include <hal_register.h>
     28#include <hal_kentry.h>
    2829#include <hal_segmentation.h>
    2930
  • trunk/hal/x86_64/core/hal_boot.h

    r147 r193  
    3939
    4040/* -------------------------------------------------------------------------- */
    41 
    42 #define PSL_MBO         0x00000002
    4341
    4442#define STKPAGES        4
  • trunk/hal/x86_64/core/hal_context.c

    r51 r193  
    3333
    3434#include <hal_context.h>
     35#include <hal_kentry.h>
     36#include <hal_internal.h>
     37#include <hal_segmentation.h>
    3538
    36 #include <hal_internal.h>
     39error_t hal_cpu_context_create(struct thread_s *thread)
     40{
     41        hal_cpu_context_t *context;
     42        kmem_req_t req;
    3743
    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
    4174        return 0;
    4275}
  • trunk/hal/x86_64/core/hal_interrupt.c

    r168 r193  
    3636 * Timer interrupt
    3737 */
    38 void hal_timer_intr(struct trapframe *tf)
     38void hal_timer_intr(hal_cpu_context_t *tf)
    3939{
    4040        x86_printf("-> got timer: rip=%Z (th=%Z)\n", tf->tf_rip,
     
    4848 * Serial Port (COM1) interrupt
    4949 */
    50 void hal_com1_intr(struct trapframe *tf)
     50void hal_com1_intr(hal_cpu_context_t *tf)
    5151{
    5252        static char prev;
     
    122122 * Keyboard interrupt (8042 PS/2)
    123123 */
    124 void hal_keyboard_intr(struct trapframe *tf)
     124void hal_keyboard_intr(hal_cpu_context_t *tf)
    125125{
    126126        uint64_t val;
  • trunk/hal/x86_64/core/hal_kentry.h

    r146 r193  
    4949#define TF_REGSIZE      (19 * 8)
    5050
     51#define PSL_I           0x00000200
     52#define PSL_MBO         0x00000002
     53#define PSL_USERSET     (PSL_MBO | PSL_I)
     54
    5155#define INTR_SAVE_REGS  \
    5256        subq    $TF_REGSIZE,%rsp        ; \
     
    98102
    99103/*
    100  * The x86_64 trap frame.
     104 * The x86_64 CPU context.
    101105 */
    102 struct trapframe {
     106typedef struct hal_cpu_context_s {
    103107        /* Pushed by INTR_SAVE_REGS */
    104108        uint64_t tf_rax;
     
    125129        uint64_t tf_trapno;
    126130
    127         /* These are pushed for a trap */
     131        /* Pushed by the hardware if trap */
    128132        uint64_t tf_err;
    129133        uint64_t tf_rip;
     
    131135        uint64_t tf_rflags;
    132136
    133         /* These are always pushed */
     137        /* Always pushed by the hardware */
    134138        uint64_t tf_rsp;
    135139        uint64_t tf_ss;
    136 };
     140} hal_cpu_context_t;
    137141
    138142/*
Note: See TracChangeset for help on using the changeset viewer.