Ignore:
Timestamp:
Dec 5, 2017, 4:20:07 PM (6 years ago)
Author:
alain
Message:

Fix several bugs in the fork() syscall.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/hal/tsar_mips32/core/hal_switch.S

    r407 r408  
    3737hal_do_cpu_switch:
    3838
     39    /* save old thread context */
     40 
    3941    move    $26,   $4                  /* $26 <= ctx_old */
    4042
     
    4951    sw      $6,    6*4($26)         
    5052    sw      $7,    7*4($26)         
    51 
    5253    sw      $8,    8*4($26)         
    5354    sw      $9,    9*4($26)         
     
    5859    sw      $14,  14*4($26)         
    5960    sw      $15,  15*4($26)         
    60 
    6161    sw      $16,  16*4($26)         
    6262    sw      $17,  17*4($26)         
     
    6767    sw      $22,  22*4($26)         
    6868    sw      $23,  23*4($26)         
    69 
    7069    sw      $24,  24*4($26)         
    7170    sw      $25,  25*4($26)         
     
    9190        sw      $27,  33*4($26)           /* save c2_mode to slot 33 */
    9291
    93     sync                           
    94 
     92    /* restore new thread context */
     93 
    9594    move    $26,   $5                  /* $26 <= ctx_new */
    9695
     
    105104    lw      $6,    6*4($26)         
    106105    lw      $7,    7*4($26)         
    107 
    108106    lw      $8,    8*4($26)         
    109107    lw      $9,    9*4($26)         
     
    114112    lw      $14,  14*4($26)         
    115113    lw      $15,  15*4($26)         
    116 
    117114        lw      $16,  16*4($26)         
    118115        lw      $17,  17*4($26)         
     
    123120    lw      $22,  22*4($26)         
    124121    lw      $23,  23*4($26)         
    125 
    126122    lw      $24,  24*4($26)         
    127123    lw      $25,  25*4($26)         
     
    149145    mtc0        $26,  $12                  /* restore c0_sr from slot 34 */
    150146
     147    sync                           
     148
    151149    jr      $31                        /* return to caller */
    152150    nop
    153151
    154152#---------------------------------------------------------------------------------
    155 # The hal_do_cpu_save()function makes the following assumptions:
     153# The hal_do_cpu_save()function makes the following assumption:
    156154# - register $4 contains a pointer on the target thread context.
    157 # - register $5 contains the target thread descriptor pointer.
    158 # - register $6 contains the offset to add to stack pointer.
    159155#---------------------------------------------------------------------------------
    160156hal_do_cpu_save:
    161157
    162     move    $26,  $4                  /* $26 <= context */
    163 
    164     move    $27,  $5
    165         sw      $27,  35*4($26)           /* save child thread to slot 35 */
    166 
    167     add     $27,  $6,  $29
    168     sw      $27,  29*4($26)           /* save (sp_29 + offset) to slot 29 */
    169 
    170     mfc0    $27,  $12               
    171         sw      $27,  34*4($26)           /* save c0_sr to slot 34 */
    172 
    173         mfc2    $27,  $0               
    174         sw      $27,  32*4($26)           /* save c2_ptpr to slot 32 */
    175 
    176         mfc2    $27,  $1               
    177         sw      $27,  33*4($26)           /* save c2_mode to slot 33 */
    178 
    179     mfc0    $27,   $14             
     158    move    $26,  $4                  /* $26 <= &context */
     159
     160    mfc0    $27,  $14               
    180161    sw      $27,   0*4($26)           /* save c0_epc to slot 0 */
    181  
     162
    182163    sw      $1,    1*4($26)         
    183164    sw      $2,    2*4($26)         
     
    187168    sw      $6,    6*4($26)         
    188169    sw      $7,    7*4($26)         
    189 
    190170    sw      $8,    8*4($26)         
    191171    sw      $9,    9*4($26)         
     
    196176    sw      $14,  14*4($26)         
    197177    sw      $15,  15*4($26)         
    198 
    199178    sw      $16,  16*4($26)         
    200179    sw      $17,  17*4($26)         
     
    205184    sw      $22,  22*4($26)         
    206185    sw      $23,  23*4($26)         
    207 
    208186    sw      $24,  24*4($26)         
    209     sw      $25,  25*4($26)         
    210 
     187    sw      $25,  25*4($26)
     188         
    211189    mfhi    $27                     
    212     sw      $27,  26*4($26)           /* save hi to slot 26 */
    213 
     190    sw      $27,  26*4($26)           /* save hi      to slot 26 */
    214191    mflo    $27                     
    215     sw      $27,  27*4($26)           /* save lo to slot 27 */
    216 
    217     sw      $28,  28*4($26)           /* save gp to slot 28 */
    218 
    219     sw      $30,  30*4($26)           /* save s8 to slot 30 */
    220     sw      $31,  31*4($26)           /* save ra to slot 31 */
     192    sw      $27,  27*4($26)           /* save lo      to slot 27 */
     193
     194    sw      $28,  28*4($26)           /* save gp      to slot 28 */
     195    sw      $29,  29*4($26)           /* save sp      to slot 29 */
     196    sw      $30,  30*4($26)           /* save s8      to slot 30 */
     197    sw      $31,  31*4($26)           /* save ra      to slot 31 */
     198
     199        mfc2    $27,  $0               
     200        sw      $27,  32*4($26)           /* save c2_ptpr to slot 32 */
     201        mfc2    $27,  $1               
     202        sw      $27,  33*4($26)           /* save c2_mode to slot 33 */
     203    mfc0    $27,  $12             
     204        sw      $27,  34*4($26)           /* save c0_sr   to slot 34 */
     205    mfc0    $27,  $4, 2             
     206        sw      $27,  35*4($26)           /* save c0_th   to slot 35 */
    221207
    222208    sync
Note: See TracChangeset for help on using the changeset viewer.