Ignore:
Timestamp:
Jan 29, 2018, 5:57:57 PM (7 years ago)
Author:
alain
Message:

bloup

Location:
trunk/hal/tsar_mips32/core
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/hal/tsar_mips32/core/hal_exception.c

    r416 r425  
    284284        default:                             // this is a kernel error => panic   
    285285        {
    286             printk("\n[PANIC] in %s for thread %x : kernel exception = %x / vaddr = %x\n",
    287             __FUNCTION__ , this->trdid , excp_code , bad_vaddr );
     286            assert( false , __FUNCTION__ , "thread %x / excp_code = %x / vaddr = %x\n",
     287            this->trdid , excp_code , bad_vaddr );
    288288
    289289            return EXCP_KERNEL_PANIC;
     
    297297//////////////////////////////////////////////////////////////////////////////////////////
    298298// @ this     : pointer on faulty thread descriptor.
    299 // @ uzone : pointer on register array.
     299// @ uzone    : pointer on register array.
    300300// @ error    : EXCP_USER_ERROR or EXCP_KERNEL_PANIC
    301301//////////////////////////////////////////////////////////////////////////////////////////
     
    372372    // get pointer on faulty thread uzone
    373373    this  = CURRENT_THREAD;
    374     uzone = (uint32_t *)CURRENT_THREAD->uzone;
     374    uzone = (uint32_t *)CURRENT_THREAD->uzone_current;
    375375
    376376    // get 4 bits XCODE from CP0_CR register
     
    424424        hal_exception_dump( this , uzone , error );
    425425
    426         // FIXME : replace this loop by sys_kill()
    427         while( 1 ) asm volatile ("nop");
    428         // sys_kill( this->process->pid , SIGKILL );
     426        sys_kill( this->process->pid , SIGKILL );
    429427        }
    430428    else if( error == EXCP_KERNEL_PANIC )   // kernel error => kernel panic
    431429    {
    432430        hal_exception_dump( this , uzone , error );
    433         panic( "for thread %x in process %x on core [%x,%d]",
     431
     432        assert( false , __FUNCTION__ , "thread %x in process %x on core [%x,%d]",
    434433        this->trdid , this->process->pid , local_cxy , this->core->lid );
    435434    }
  • trunk/hal/tsar_mips32/core/hal_kentry.S

    r418 r425  
    119119#------------------------------------------------------------------------------------
    120120# This code is executed when the core is already in kernel mode,
    121 # after a syscall, to handle an interrupt.
     121# after a syscall, to handle an interrupt, or to handle a non-fatal exception.
    122122# - save current c2_mode in $26.
    123123# - set MMU OFF.
     
    286286   
    287287#------------------------------------------------------------------------------------
    288 # This code calls the relevant Interrupt / Exception / Syscall handler,
    289 # depending on XCODE in CP0_CR.
    290 # In case of syscall or exception, it set the "uzone" pointer in thread descriptor,
    291 # that is used by the hal_do_syscall() & hal_do_exception() functions.
    292 # WARNING: This "uzone" pointer is NOT modified in case of interrupt,
    293 # because syscalls can be interrupted, and we want preserve this pointer.
    294 
     288# This code handle the uzone pointers stack, and calls the relevant
     289# Interrupt / Exception / Syscall handler, depending on XCODE in CP0_CR.
     290# Both the hal_do_syscall() and the hal_do_exception() functions use
     291# the values saved in the "uzone", but a syscall can be interrupted
     292# by an interrupt, or by a non-fatal exception. Therefore, we need
     293# to handle a two-slots "stack of uzones", implemented in the kernel stack,
     294# using the two "current_uzone" and "previous_uzone" pointers in thread descriptor.
     295# - at kernel_entry, we copy the "current_uzone" pointer to the "previous_uzone"
     296#   slot, and copy the "$29" stack pointer to the "current_uzone" slot.
     297# - at kernel_exit, we simply restore the "previous_uzone" value to the
     298#   "current_uzone" slot.
     299# For a syscall, the hal_do_syscall() function increment the uzone[EPC]
     300# slot and set the return value in the uzone[V0] slot before returning.
     301
     302    # update "current_uzone" and "previous_uzone" pointers
     303        mfc0    $4,     $4,   2             # $4 <= pointer on thread desc
     304    lw      $5,     8($4)               # $5 <= current uzone pointer trom thread
     305    sw      $29,    8($4)               # current uzone pointer <= $29
     306    sw      $5,    12($4)               # previous uzone pointer <= current
     307
     308    # analyse XCODE to call relevant handler
    295309        mfc0    $17,    $13                 # $17 <= CR
    296         andi    $17,    $17,   0x3F         # $17 <= XCODE
     310        andi    $17,    $17,  0x3F          # $17 <= XCODE
    297311        ori         $8,     $0,   0x20
    298312    beq     $8,     $17,  cause_sys     # go to syscall handler
     
    302316
    303317cause_excp:
    304         mfc0    $4,     $4,   2             # get pointer on thread desc
    305     sw      $29,    8($4)               # update uzone pointer in thread desc
     318
    306319        jal     hal_do_exception            # call exception handler
    307320        nop
     
    310323
    311324cause_sys:
    312         mfc0    $4,     $4,   2             # get pointer on thread desc
    313     sw      $29,    8($4)               # update uzone pointer in thread desc
     325
    314326        jal     hal_do_syscall              # call syscall handler                 
    315327    nop
     
    318330       
    319331cause_int:
     332
    320333        jal     hal_do_interrupt            # call interrupt handler
    321334    nop
     
    330343
    331344kentry_exit:
     345
     346    # restore "current_uzone" pointer
     347        mfc0    $4,      $4,   2            # $4 <= pointer on thread desc
     348    lw      $5,   12($4)                # $5 <= previous uzone pointer from thread
     349    sw      $5,    8($4)                # current uzone pointer <= previous
    332350
    333351#----------------------
  • trunk/hal/tsar_mips32/core/hal_special.c

    r407 r425  
    206206void hal_core_sleep()
    207207{
    208         asm volatile ("wait");
     208        while( 1 ) asm volatile ("nop");
    209209}
    210210
  • trunk/hal/tsar_mips32/core/hal_syscall.c

    r418 r425  
    2929#include <hal_kentry.h>
    3030
    31 // @@@
    32 // __attribute__((section(".kdata"))) uint32_t * enter_uzone;
    33 // __attribute__((section(".kdata"))) uint32_t * exit_uzone;
    34 // @@@
    35 
    3631/////////////////////
    3732void hal_do_syscall()
     
    5146    // get pointer on enter_thread uzone
    5247    this        = CURRENT_THREAD;
    53     enter_uzone = (uint32_t *)this->uzone;
     48    enter_uzone = (uint32_t *)this->uzone_current;
     49
     50//printk("\n@@@ enter %s : thread = %x / enter_uzone = %x / EPC = %x\n",
     51//__FUNCTION__ , this , enter_uzone , enter_uzone[UZ_EPC] );
    5452
    5553    // get syscall arguments from uzone
     
    6866                         service_num );
    6967
    70     // get pointer on exit_thread uzone,
     68    // get pointer on exit_thread uzone, because
    7169    // exit_thread can be different from enter_thread
    7270    this       = CURRENT_THREAD;
    73     exit_uzone = (uint32_t *)this->uzone;
     71    exit_uzone = (uint32_t *)this->uzone_current;
    7472
    75 // printk("\n@@@ %s exit : enter_uzone = %x / exit_uzone = %x\n",
    76 // __FUNCTION__ , enter_uzone , exit_uzone );
     73//printk("\n@@@ exit %s : thread = %x / exit_uzone = %x / EPC = %x\n",
     74//__FUNCTION__ , this , exit_uzone , exit_uzone[UZ_EPC] );
    7775
    78     // set syscall return value to uzone
     76    // set return value to uzone
    7977        exit_uzone[UZ_V0] = retval;
    8078
  • trunk/hal/tsar_mips32/core/hal_user.c

    r407 r425  
    3030                             int arg3 )
    3131{
    32     register int reg_num_and_ret __asm__("v0") = service_num;
    33     register int reg_a0          __asm__("a0") = arg0;
    34     register int reg_a1          __asm__("a1") = arg1;
    35     register int reg_a2          __asm__("a2") = arg2;
    36     register int reg_a3          __asm__("a3") = arg3;
     32    register int num_and_ret __asm__("v0") = service_num;
     33    register int a0          __asm__("a0") = arg0;
     34    register int a1          __asm__("a1") = arg1;
     35    register int a2          __asm__("a2") = arg2;
     36    register int a3          __asm__("a3") = arg3;
    3737
    38     __asm__ volatile(
     38    asm volatile(
    3939            "syscall"
    40             : "+r" (reg_num_and_ret),
    41               "+r" (reg_a0),             
    42               "+r" (reg_a1),
    43               "+r" (reg_a2),
    44               "+r" (reg_a3)
    45             :
     40            : "+r" (num_and_ret)
     41            : "r" (a0),             
     42              "r" (a1),
     43              "r" (a2),
     44              "r" (a3)
    4645            : "memory",
    4746              "at",
     
    6059               );
    6160
    62     return (volatile int)reg_num_and_ret;
     61    return (volatile int)num_and_ret;
    6362}
    6463
  • trunk/hal/tsar_mips32/core/hal_uspace.c

    r407 r425  
    2929#include <hal_irqmask.h>
    3030
     31#include <printk.h>
     32#include <thread.h>
     33
    3134///////////////////////////////////////////
    3235void hal_copy_from_uspace( void     * k_dst,
    3336                           void     * u_src,
    34                            uint32_t   size )
     37                           uint32_t   size ) 
    3538{
    3639    uint32_t save_sr;
     
    136139{
    137140    uint32_t save_sr;
    138 
    139141    uint32_t src = (uint32_t)u_src;
    140142    uint32_t dst = (uint32_t)k_dst;
     
    142144    hal_disable_irq( &save_sr );
    143145
    144     // loop on characters while ( (character != NUL) and (count < size )
     146    // loop on characters while ( (character != NUL) and (count < size ) )
    145147    asm volatile(
    146148        ".set noreorder             \n"
     
    148150        "move   $12,   %1           \n"   /* $12 <= u_src                   */
    149151        "move   $13,   %2           \n"   /* $13 <= k_dst                   */
    150         "mfc2   $15,   $1           \n"   /* $15 <= MMU_MODE                */
    151         "ori    $14,   $15,  0x7    \n"   /* $14 <= mode DTLB on            */
     152        "mfc2   $15,   $1           \n"   /* $15 <= mode DTLB and ITLB off  */
     153        "ori    $14,   $15,  0x4    \n"   /* $14 <= mode DTLB on            */
    152154        "1:                         \n"
    153155        "mtc2   $14,   $1                       \n"   /* MMU_MODE <= DTLB ON            */
    154156        "lb     $10,   0($12)       \n"   /* read char from user space      */
    155         "mtc2   $15,   $1                       \n"   /* restore MMU_MODE               */
     157        "mtc2   $15,   $1                       \n"   /* restore DTLB and ITLB off      */
    156158            "sb     $10,   0($13)       \n"   /* store char to kernel space     */
    157         "beq    $13,   $0,   2f     \n"   /* exit if char = 0               */
     159        "beq    $10,   $0,   2f     \n"   /* exit if char = 0               */
    158160        "addi   $11,   $11, -1      \n"   /* decrement count                */
    159161        "addi   $12,   $12,  1      \n"   /* increment u_src pointer        */
     
    178180{
    179181    uint32_t save_sr;
    180 
    181182    uint32_t src = (uint32_t)k_src;
    182183    uint32_t dst = (uint32_t)u_dst;
     
    190191        "move   $12,   %1           \n"   /* $12 <= k_src                   */
    191192        "move   $13,   %2           \n"   /* $13 <= u_dst                   */
    192         "mfc2   $15,   $1           \n"   /* $15 <= MMU_MODE                */
    193         "ori    $14,   $15,  0x7    \n"   /* $14 <= mode DTLB on            */
     193        "mfc2   $15,   $1           \n"   /* $15 <= mode DTLB and ITLB off  */
     194        "ori    $14,   $15,  0x4    \n"   /* $14 <= mode DTLB on            */
    194195        "1:                         \n"
    195196        "lb     $10,   0($12)       \n"   /* read char from kernel space    */
    196197        "mtc2   $14,   $1                       \n"   /* MMU_MODE <= DTLB ON            */
    197198            "sb     $10,   0($13)       \n"   /* store char to user space       */
    198         "mtc2   $15,   $1                       \n"   /* restore MMU_MODE               */
    199         "beq    $13,   $0,   2f     \n"   /* exit if char == 0              */
     199        "mtc2   $15,   $1                       \n"   /* restore DTLB and ITLB off      */
     200        "beq    $10,   $0,   2f     \n"   /* exit if char == 0              */
    200201        "addi   $11,   $11, -1      \n"   /* decrement count                */
    201202        "addi   $12,   $12,  1      \n"   /* increment k_src pointer        */
     
    219220    uint32_t save_sr;
    220221    uint32_t count = 0;
    221 
    222     uint32_t str = (uint32_t)u_str;
     222    uint32_t str   = (uint32_t)u_str;
    223223
    224224    hal_disable_irq( &save_sr );
     
    226226        asm volatile(
    227227        ".set noreorder             \n"
    228         "ori    $13,   %1,   0      \n"   /* $13 <= str                     */
    229         "mfc2   $15,   $1           \n"   /* $15 <= MMU_MODE                */
    230         "ori    $14,   $15,  0x7    \n"   /* $14 <= mode DTLB on            */
    231         "mtc2   $14,   $1                       \n"   /* MMU_MODE <= DTLB ON            */
     228        "move   $13,   %1           \n"   /* $13 <= str                     */
     229        "mfc2   $15,   $1           \n"   /* $15 <= DTLB and ITLB off       */
     230        "ori    $14,   $15,  0x4    \n"   /* $14 <= mode DTLB on            */
    232231        "1:                         \n"
     232        "mtc2   $14,   $1                       \n"   /* set DTLB on                    */
    233233        "lb         $12,   0($13)       \n"   /* read char from user space      */
     234        "mtc2   $15,   $1                       \n"   /* set DTLB off                   */
    234235        "addi   $13,   $13,  1      \n"   /* increment address              */
    235236        "bne    $12,   $0,   1b     \n"   /* loop until NUL found           */
    236237        "addi   %0,    %0,   1      \n"   /* increment count                */
    237         "mtc2   $15,   $1                       \n"   /* restore MMU_MODE               */
    238238        ".set reorder               \n"
    239239        : "+r"(count)
Note: See TracChangeset for help on using the changeset viewer.