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

bloup

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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#----------------------
Note: See TracChangeset for help on using the changeset viewer.