Changeset 2bd4fdf in mainline


Ignore:
Timestamp:
2005-09-06T23:10:17Z (19 years ago)
Author:
Ondrej Palkovsky <ondrap@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0b512a8
Parents:
2c9de7e
Message:

MIPS bug fixes.
Added usermode to MIPS, unfortunately impossible to test until
MM is ready.

Location:
arch
Files:
11 edited
3 moved

Legend:

Unmodified
Added
Removed
  • arch/amd64/src/userspace.c

    r2c9de7e r2bd4fdf  
    5858                          "pushq %%rsi;"
    5959                          "iretq;"
    60                           : : "i" (gdtselector(UDATA_DES) | PL_USER), "i" (USTACK_ADDRESS+(THREAD_STACK_SIZE-1)), "r" (pri), "i" (gdtselector(UTEXT_DES) | PL_USER), "i" (UTEXT_ADDRESS));
     60                          : : "i" (gdtselector(UDATA_DES) | PL_USER), "i" (USTACK_ADDRESS+THREAD_STACK_SIZE), "r" (pri), "i" (gdtselector(UTEXT_DES) | PL_USER), "i" (UTEXT_ADDRESS));
    6161       
    6262        /* Unreachable */
  • arch/mips/Makefile.inc

    r2c9de7e r2bd4fdf  
    2222        arch/start.S \
    2323        arch/context.S \
    24         arch/panic.s \
     24        arch/panic.S \
    2525        arch/mips.c \
    26         arch/dummy.s \
     26        arch/dummy.S \
    2727        arch/putchar.c \
    28         arch/asm.s \
     28        arch/asm.S \
    2929        arch/exception.c \
    3030        arch/interrupt.c \
  • arch/mips/include/asm.h

    r2c9de7e r2bd4fdf  
    3131
    3232#include <arch/types.h>
     33#include <typedefs.h>
    3334#include <config.h>
    3435
     
    5051}
    5152
    52 void cpu_halt(void);
    53 void asm_delay_loop(__u32 t);
    54 
     53extern void cpu_halt(void);
     54extern void asm_delay_loop(__u32 t);
     55extern void userspace_asm(__address ustack);
    5556
    5657#endif
  • arch/mips/include/asm/boot.h

    r2c9de7e r2bd4fdf  
    3333/* Temporary stack size for boot process */
    3434#define TEMP_STACK_SIZE 0x100
    35 #define TEMP_STACK_START 0x80000400
    3635
    3736/* Kernel startup address */
  • arch/mips/include/context.h

    r2c9de7e r2bd4fdf  
    6363#define EOFFSET_GP 104
    6464#define EOFFSET_RA 108
    65 #define EOFFSET_LO 112
    66 #define EOFFSET_HI 116
     65#define EOFFSET_SP 112
    6766
    68 #define REGISTER_SPACE 120
     67#define EOFFSET_LO 116
     68#define EOFFSET_HI 120
     69#define EOFFSET_STATUS 124
     70
     71#define REGISTER_SPACE 128
    6972
    7073/*
  • arch/mips/include/cp0.h

    r2c9de7e r2bd4fdf  
    3636#define cp0_status_erl_error_bit        (1<<2)
    3737#define cp0_status_bev_bootstrap_bit    (1<<22)
     38#define cp0_status_um_bit               (1<<4)
    3839
    3940#define cp0_status_im7_shift            15
  • arch/mips/include/mm/vm.h

    r2c9de7e r2bd4fdf  
    3737#define USER_ADDRESS_SPACE_END_ARCH             (__address) 0x7fffffff 
    3838
    39 #define UTEXT_ADDRESS_ARCH      0x00001000
    40 #define USTACK_ADDRESS_ARCH     (0x7fffffff-(PAGE_SIZE-1))
     39#define UTEXT_ADDRESS_ARCH      0x00004000
     40#define USTACK_ADDRESS_ARCH     (0x80000000-PAGE_SIZE)
    4141#define UDATA_ADDRESS_ARCH      0x01001000
    4242
  • arch/mips/include/thread.h

    r2c9de7e r2bd4fdf  
    3030#define __mips_THREAD_H__
    3131
    32 #define ARCH_THREAD_DATA \
    33         pri_t   saved_pri; \
    34         __u32   saved_epc;
     32#define ARCH_THREAD_DATA  __u32 saved_epc;
    3533
    3634#endif
  • arch/mips/src/dummy.S

    r2c9de7e r2bd4fdf  
    3232.global calibrate_delay_loop
    3333.global asm_delay_loop
    34 .global userspace
    35 .global before_thread_runs_arch
    3634.global dummy
    3735.global fpu_enable
    3836.global fpu_disable
    3937.global fpu_init
    40 
    41 before_thread_runs_arch:
    42 userspace:
     38       
    4339calibrate_delay_loop:
    4440asm_delay_loop:
  • arch/mips/src/exception.c

    r2c9de7e r2bd4fdf  
    4040        __u32 epc;
    4141        __u32 epc_shift = 0;
    42         pri_t pri;
    4342
    4443        ASSERT(CPU != NULL);
     
    5150         */
    5251
    53         pri = cpu_priority_high();
     52        cpu_priority_high();
    5453        epc = cp0_epc_read();
    55         cp0_status_write(cp0_status_read() & ~ cp0_status_exl_exception_bit);
     54        cp0_status_write(cp0_status_read() & ~ (cp0_status_exl_exception_bit |
     55                                                cp0_status_um_bit));
    5656
    5757        if (THREAD) {
    58                 THREAD->saved_pri = pri;
    5958                THREAD->saved_epc = epc;
    6059        }
     
    116115        }
    117116       
    118         if (THREAD) {
    119                 pri = THREAD->saved_pri;
     117        if (THREAD)
    120118                epc = THREAD->saved_epc;
    121         }
    122 
     119       
     120        /* Raise EXL bit before epc_write, so that we support
     121         * properly nested exceptions
     122         */
     123        cp0_status_write(cp0_status_read() | cp0_status_exl_exception_bit);
    123124        cp0_epc_write(epc + epc_shift);
    124         cp0_status_write(cp0_status_read() | cp0_status_exl_exception_bit);
    125         cpu_priority_restore(pri);
    126125}
  • arch/mips/src/mips.c

    r2c9de7e r2bd4fdf  
    3030#include <arch/cp0.h>
    3131#include <arch/exception.h>
     32#include <arch/asm/regname.h>
     33#include <arch/asm.h>
     34#include <mm/vm.h>
     35#include <userspace.h>
    3236
    3337void arch_pre_mm_init(void)
     
    5862{
    5963}
     64
     65void userspace(void)
     66{
     67        /* EXL=1, UM=1, IE=1 */
     68        cp0_status_write(cp0_status_read() | (cp0_status_exl_exception_bit |
     69                                              cp0_status_um_bit |
     70                                              cp0_status_ie_enabled_bit));
     71       
     72        cp0_epc_write(UTEXT_ADDRESS);
     73        userspace_asm(USTACK_ADDRESS+PAGE_SIZE);
     74        while (1)
     75                ;
     76}
     77
     78/* Stack pointer saved when entering user mode */
     79/* TODO: How do we do it on SMP system???? */
     80__address supervisor_sp;
     81
     82void before_thread_runs_arch(void)
     83{
     84        supervisor_sp = (__address) &THREAD->kstack[THREAD_STACK_SIZE-SP_DELTA];
     85}
     86
     87
  • arch/mips/src/start.S

    r2c9de7e r2bd4fdf  
    4444.global cache_error_entry
    4545.global exception_entry
    46 
     46.global userspace_asm
     47
     48# Save registers to space defined by \r
     49# We will change $at on the way
    4750.macro REGISTERS_STORE r
    4851        sw $at,EOFFSET_AT(\r)
     
    6366        sw $t8,EOFFSET_T8(\r)
    6467        sw $t9,EOFFSET_T9(\r)
     68
     69        mflo $at
     70        sw $at, EOFFSET_LO(\r)
     71        mfhi $at
     72        sw $at, EOFFSET_HI(\r)
     73       
    6574        sw $s0,EOFFSET_S0(\r)
    6675        sw $s1,EOFFSET_S1(\r)
     
    7483        sw $gp,EOFFSET_GP(\r)
    7584        sw $ra,EOFFSET_RA(\r)
    76         mflo $k0
    77         mfhi $k1
    78         sw $k0,EOFFSET_LO(\r)
    79         sw $k1,EOFFSET_HI(\r)
     85        sw $sp,EOFFSET_SP(\r)
     86
     87        mfc0 $at, $status
     88        sw $at,EOFFSET_STATUS(\r)
    8089.endm
    8190
    8291.macro REGISTERS_LOAD r
    83         lw $at,EOFFSET_AT(\r)
    8492        lw $v0,EOFFSET_V0(\r)
    8593        lw $v1,EOFFSET_V1(\r)
     
    110118        lw $ra,EOFFSET_RA(\r)
    111119       
    112         lw $k0,EOFFSET_LO(\r)
    113         lw $k1,EOFFSET_HI(\r)
    114         mtlo $k0
    115         mthi $k1
     120        lw $at,EOFFSET_LO(\r)
     121        mtlo $at
     122        lw $at,EOFFSET_HI(\r)
     123        mthi $at
     124
     125        lw $at,EOFFSET_STATUS(\r)
     126        mtc0 $at, $status
     127       
     128        lw $at,EOFFSET_AT(\r)
     129        lw $sp,EOFFSET_SP(\r)
    116130.endm
    117131
    118        
     132# Move kernel stack pointer address to register K0
     133# - if we are in user mode, load the appropriate stack
     134# address
     135.macro KERNEL_STACK_TO_K0
     136        # If we are in user mode
     137        mfc0 $k0, $status
     138        andi $k0, 0x10
     139       
     140        beq $k0, $0, 1f
     141        add $k0, $sp, 0
     142       
     143        # Move $k0 pointer to kernel stack
     144        lui $k0, %hi(supervisor_sp)
     145        ori $k0, %lo(supervisor_sp)
     146        # Move $k0 (superveisor_sp)
     147        lw $k0, 0($k0)
     1481:             
     149.endm
     150               
    119151.org 0x0
    120152tlb_refill_entry:
     
    128160
    129161.org 0x180
     162norm_exception:
     163        j exception_handler
     164        nop     
     165
     166.org 0x200
     167iv_exception:   
     168        j exception_handler
     169        nop     
     170
     171.org KA2PA(KERNEL_STARTUP_ADDRESS)
     172kernel_image_start:
     173        /* Load temporary stack */
     174        lui $sp, %hi(end_stack)
     175        ori $sp, $0, %lo(end_stack)
     176
     177        /* Not sure about this, but might be needed for PIC code???? */
     178        lui $gp, 0x8000
     179       
     180        jal main_bsp
     181        nop
     182
     183
     184        .space TEMP_STACK_SIZE
     185end_stack:     
     186       
     187exception_handler:
    130188exception_entry:
    131 exception_handler:
     189        KERNEL_STACK_TO_K0
     190        sub $k0, REGISTER_SPACE
     191        REGISTERS_STORE $k0
     192        add $sp, $k0, 0
     193
     194        jal exception
     195        nop
     196
     197        REGISTERS_LOAD $sp
     198        # The $sp is automatically restored to former value
     199        eret
     200        nop
     201       
     202tlb_refill_handler:
     203        KERNEL_STACK_TO_K0
     204        sub $k0, REGISTER_SPACE
     205        REGISTERS_STORE $k0
     206        add $sp, $k0, 0
     207
     208        jal tlb_refill
     209        nop
     210
     211        REGISTERS_LOAD $sp
     212
     213        eret
     214        nop
     215
     216cache_error_handler:
     217        KERNEL_STACK_TO_K0
    132218        sub $sp, REGISTER_SPACE
    133219        REGISTERS_STORE $sp
    134 
    135         jal exception
     220        add $sp, $k0, 0
     221
     222        jal cache_error
    136223        nop
    137224
    138225        REGISTERS_LOAD $sp
    139         add $sp, REGISTER_SPACE
    140 
    141         eret
    142         nop
    143 
    144 .org KA2PA(0x80000300)
    145 kernel_image_start:
    146         /* Load temporary stack */
    147         lui $sp, (TEMP_STACK_START + TEMP_STACK_SIZE) >> 16
    148         ori $sp, (TEMP_STACK_START + TEMP_STACK_SIZE) & 0xffff
    149 
    150         /* Not sure about this, but might be needed for PIC code???? */
    151         lui $gp, 0x8000
    152        
    153         jal main_bsp
    154         nop
    155 
    156 .org KA2PA(TEMP_STACK_START)
    157         .space TEMP_STACK_SIZE
    158        
    159 tlb_refill_handler:
    160         sub $sp, REGISTER_SPACE
    161         REGISTERS_STORE $sp
    162 
    163         jal tlb_refill
    164         nop
    165 
    166         REGISTERS_LOAD $sp
    167         add $sp, REGISTER_SPACE
    168 
    169         eret
    170         nop
    171 
    172 cache_error_handler:
    173         sub $sp, REGISTER_SPACE
    174         REGISTERS_STORE $sp
    175 
    176         jal cache_error
    177         nop
    178 
    179         REGISTERS_LOAD $sp
    180         add $sp, REGISTER_SPACE
    181 
    182         eret
    183         nop
     226
     227        eret
     228        nop
     229
     230userspace_asm:
     231        .word 0x29
     232        add $sp, $a0, 0
     233        eret
     234        nop
     235
Note: See TracChangeset for help on using the changeset viewer.