Ignore:
Timestamp:
Nov 7, 2017, 3:08:12 PM (6 years ago)
Author:
alain
Message:

First implementation of fork/exec.

File:
1 edited

Legend:

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

    r406 r407  
    2222 */
    2323
    24 #---------------------------------------------------------------------------------
    25 # This code makes the following assumptions:
     24    .section   .switch , "ax" , @progbits
     25
     26    .global  hal_do_cpu_switch
     27    .global  hal_do_cpu_save
     28
     29    .set     noat
     30    .set     noreorder
     31
     32#---------------------------------------------------------------------------------
     33# The hal_do_cpu_switch() function makes the following assumptions:
    2634# - register $4 contains a pointer on the old thread context.
    2735# - register $5 contains a pointer on the new thread context.
    28 # When the switch is completed, it jumps to address contained in register $31
    29 # of the new context.
    30 #---------------------------------------------------------------------------------
    31 
    32     .section   .switch , "ax" , @progbits
    33 
    34     .ent     hal_do_switch
    35     .global  hal_do_switch
    36 
    37     .set     noat
    38     .set     noreorder
    39 
    40 hal_do_switch:
     36#---------------------------------------------------------------------------------
     37hal_do_cpu_switch:
    4138
    4239    move    $26,   $4                  /* $26 <= ctx_old */
     
    133130    mthi    $27                        /* restore hi from slot 26 */
    134131    lw      $27,  27*4($26)         
    135     mtlo    $27                        /* restote lo from slot 27 */
     132    mtlo    $27                        /* restore lo from slot 27 */
    136133
    137134        lw      $28,  28*4($26)         
    138135        lw      $29,  29*4($26)         
    139136        lw      $30,  30*4($26)         
    140         lw      $31,  31*4($26)         
    141 
    142         lw      $27,  32*4($26)            /* $27 <= c2_ptpr */
     137        lw      $31,  31*4($26)            /* restore ra from slot 31 */
     138
     139        lw      $27,  32*4($26)
    143140        mtc2    $27,  $0                   /* restore c2_ptpr from slot 32 */
    144141
    145         lw      $27,  35*4($26)            /* $27 <= c0_th */     
     142        lw      $27,  35*4($26)     
    146143    mtc0        $27,  $4, 2                /* restore c0_th from slot 35 */
    147144
    148         lw      $27,  33*4($26)            /* $27 <= c2_mode */
    149         lw      $26,  34*4($26)            /* $26 <= c0_sr */
     145        lw      $27,  33*4($26)
     146        lw      $26,  34*4($26)
    150147
    151148        mtc2    $27,  $1                   /* restore c2_mode from slot 33 */
     
    155152    nop
    156153
     154#---------------------------------------------------------------------------------
     155# The hal_do_cpu_save()function makes the following assumptions:
     156# - 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.
     159#---------------------------------------------------------------------------------
     160hal_do_cpu_save:
     161
     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             
     180    sw      $27,   0*4($26)           /* save c0_epc to slot 0 */
     181 
     182    sw      $1,    1*4($26)         
     183    sw      $2,    2*4($26)         
     184    sw      $3,    3*4($26)         
     185    sw      $4,    4*4($26)         
     186    sw      $5,    5*4($26)         
     187    sw      $6,    6*4($26)         
     188    sw      $7,    7*4($26)         
     189
     190    sw      $8,    8*4($26)         
     191    sw      $9,    9*4($26)         
     192    sw      $10,  10*4($26)         
     193    sw      $11,  11*4($26)         
     194    sw      $12,  12*4($26)         
     195    sw      $13,  13*4($26)         
     196    sw      $14,  14*4($26)         
     197    sw      $15,  15*4($26)         
     198
     199    sw      $16,  16*4($26)         
     200    sw      $17,  17*4($26)         
     201    sw      $18,  18*4($26)         
     202    sw      $19,  19*4($26)         
     203    sw      $20,  20*4($26)         
     204    sw      $21,  21*4($26)         
     205    sw      $22,  22*4($26)         
     206    sw      $23,  23*4($26)         
     207
     208    sw      $24,  24*4($26)         
     209    sw      $25,  25*4($26)         
     210
     211    mfhi    $27                     
     212    sw      $27,  26*4($26)           /* save hi to slot 26 */
     213
     214    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 */
     221
     222    sync
     223
     224    jr      $31                       /* return to caller */
     225    nop
     226
    157227        .set reorder                   
    158228    .set at                         
    159229
    160     .end hal_do_switch
    161 
Note: See TracChangeset for help on using the changeset viewer.