Changeset 37b451f7 in mainline


Ignore:
Timestamp:
2006-02-07T02:22:44Z (19 years ago)
Author:
Ondrej Palkovsky <ondrap@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
65640fef
Parents:
dd4d6b0
Message:

Added (finally!) userspace to AMD64.
It does not work on Simics *$U&%&$&*#. Broken simics!!!
There should be probably LEA instead of MOV/ADD, but LEA does not
work in neither qemu nor bochs. Any other simulator to test? :-/

Location:
arch/amd64
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • arch/amd64/include/asm.h

    rdd4d6b0 r37b451f7  
    7373static inline void outb(__u16 port, __u8 val) { __asm__ volatile ("outb %b0, %w1\n" : : "a" (val), "d" (port) ); }
    7474
     75/** Swap Hidden part of GS register with visible one */
     76static inline void swapgs(void) { __asm__ volatile("swapgs"); }
     77
    7578/** Enable interrupts.
    7679 *
  • arch/amd64/include/cpu.h

    rdd4d6b0 r37b451f7  
    4242#define AMD_MSR_LSTAR   0xc0000082
    4343#define AMD_MSR_SFMASK  0xc0000084
     44#define AMD_MSR_GS      0xc0000101
    4445
    4546#ifndef __ASM__
  • arch/amd64/src/asm_utils.S

    rdd4d6b0 r37b451f7  
    193193       
    194194syscall_entry:
    195         # TODO: Switch to kernel stack
     195        # Switch to hidden gs   
     196        swapgs
     197
     198        # TODO: I would like LEA instead of thes 2 instrs,
     199        # why does not it work???
     200        mov %gs:0, %r10     # We have a stack in r10
     201        addq $0x0ff0, %r10
     202       
     203        movq %rsp, 0(%r10)  # Save old stack pointer to stack
     204        movq %r10, %rsp     # Change to new stack
     205        pushq %rcx          # Return address
     206        pushq %r11          # Save flags
     207
     208        # Switch back to remain consistent
     209        swapgs
     210
     211        movq %r9, %rcx      # Exchange last parameter as a third
    196212        call syscall_handler
    197         # Switch back
    198         sysret
     213       
     214        popq %r11
     215        popq %rcx
     216        movq 0(%rsp), %rsp
     217        sysretq
    199218               
    200219.data
  • arch/amd64/src/proc/scheduler.c

    rdd4d6b0 r37b451f7  
    3232#include <arch.h>
    3333#include <arch/context.h>       /* SP_DELTA */
     34#include <arch/asm.h>
    3435
    3536void before_thread_runs_arch(void)
    3637{
    3738        CPU->arch.tss->rsp0 = (__address) &THREAD->kstack[THREAD_STACK_SIZE-SP_DELTA];
     39
     40        /* Syscall support - write thread address to hidden part of gs */
     41        swapgs();
     42        write_msr(AMD_MSR_GS,
     43                  (__u64)&THREAD->kstack);
     44        swapgs();
    3845}
  • arch/amd64/src/syscall.c

    rdd4d6b0 r37b451f7  
    3535
    3636#include <print.h>
     37#include <arch/cpu.h>
    3738
    3839extern void syscall_entry(void);
     
    5556        write_msr(AMD_MSR_LSTAR, (__u64)syscall_entry);
    5657        /* Mask RFLAGS on syscall
    57          * - we do not care what is in the flags field
     58         * - disable interrupts, until we exchange the stack register
     59         *   (mask the IE bit)
    5860         */
    59         write_msr(AMD_MSR_SFMASK, 0);
     61        write_msr(AMD_MSR_SFMASK, 0x200);
    6062}
    6163
     
    6365__native syscall_handler(__native id, __native a1, __native a2, __native a3)
    6466{
     67        interrupts_enable();
    6568        if (id < SYSCALL_END)
    6669                return syscall_table[id](a1,a2,a3);
    6770        else
    6871                panic("Undefined syscall %d", id);
    69        
     72        interrupts_disable();
    7073}
Note: See TracChangeset for help on using the changeset viewer.