Changeset a218709 in mainline for kernel/arch/sparc32/src/trap_table.S


Ignore:
Timestamp:
2013-12-02T23:45:45Z (10 years ago)
Author:
Jakub Klama <jakub.klama@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
2955bb9
Parents:
3bc42bd
Message:

Implement new userspace window trap mechanism, which utilizes MMU probe
to choose between slow (preemptive, involving inserting stack page mapping)
and fast (direct) handlers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/sparc32/src/trap_table.S

    r3bc42bd ra218709  
    2828
    2929#include <arch/trap.h>
     30#include <arch/regwin.h>
    3031
    3132.text
     
    3940.global window_underflow_trap
    4041.global write_to_invalid
     42.global read_from_invalid
     43.global flush_windows
    4144
    4245.macro get_wim_number reg
     
    231234        nop
    232235
     236read_from_invalid:
     237        ! Read value 1
     238        mov %o0, %g7
     239        switch_to_invalid %g3, %g4
     240        st %l5, [%g7]
     241        switch_back %g3, %g4
     242        ! Write value 2
     243        mov %o1, %g7
     244        switch_to_invalid %g3, %g4
     245        st %l6, [%g7]
     246        switch_back %g3, %g4
     247        ! Write value 3
     248        mov %o2, %g7
     249        switch_to_invalid %g3, %g4
     250        st %l7, [%g7]
     251        switch_back %g3, %g4
     252        retl
     253        nop
     254
    233255reset_trap:
    234256        set 0x80000100, %l0
     
    240262        mov %g7, %l0
    241263
    242         /* rotate WIM on bit right, we have 8 windows */
     264        /* Check whether previous mode was usermode */
     265        mov %psr, %l4
     266        and %l4, (1 << 6), %l4
     267        cmp %l4, 0
     268        bne 1f
     269        nop
     270
     271        /* userspace: */
     272        /* time to check whether desired stack page is mapped
     273         * on the MMU. if so, process with saving window directly.
     274         * if not, go to preemptible trap handler */
     275        mov %wim, %g5
     276        mov %g0, %wim
     277        save
     278        mov %sp, %g4
     279        restore
     280        mov %g5, %wim
     281        and %g4, 0xfffff000, %l4
     282        lda [%l4] 0x18, %l4
     283        cmp %l4, 0
     284        bne 1f
     285        nop
     286
     287        /* prepare args for preemptible handler */
     288        mov %g4, %o0
     289        set preemptible_save_uspace, %o2
     290        b preemptible_trap
     291        nop
     292
     293        /* kernel: */
     2941:      /* rotate WIM on bit right, we have 8 windows */
    243295        mov %wim, %l3
    244296        sll %l3, 7, %l4
     
    256308        mov %l7, %g7
    257309
    258         /* Check whether previous mode was usermode */
    259         mov %psr, %l4
    260         and %l4, (1 << 6), %l4
    261         cmp %l4, 0
    262         beq 1f
    263         nop
    264 
    265         /* kernel: */
     310
    266311        /* we should check whether window needs to be saved
    267312         * to kernel stack or uwb
     
    284329        nop
    285330
    286 1:      /* uspace: */
    287         /* set uspace window mark */
    288         mov %psr, %g7
    289         and %g7, 0x7, %g7
    290         or %g7, 0x10, %g7
    291 
     331        /* dump registers to uwb */
    2923322:      save
    293333        std %l0, [%g6 +  0]
     
    330370        mov %g7, %l0
    331371
     372        /* Check whether previous mode was usermode */
     373        mov %psr, %l4
     374        and %l4, (1 << 6), %l4
     375        cmp %l4, 0
     376        bne 1f
     377        nop
     378
     379        /* userspace: */
     380        /* time to check whether desired stack page is mapped
     381         * on the MMU. if so, process with saving window directly.
     382         * if not, go to preemptible trap handler */
     383        mov %wim, %g5
     384        mov %g0, %wim
     385        restore
     386        restore
     387        mov %sp, %g4
     388        save
     389        save
     390        mov %g5, %wim
     391        and %sp, 0xfffff000, %l4
     392        lda [%l4] 0x18, %l4
     393        cmp %l4, 0
     394        bne 1f
     395        nop
     396
     397        /* prepare args for preemptible handler */
     398        mov %g4, %o0
     399        set preemptible_restore_uspace, %o2
     400        b preemptible_trap
     401        nop
     402
    332403        /* rotate WIM on bit LEFT, we have 8 windows */
    333         mov %wim,%l3
     4041:      mov %wim,%l3
    334405        srl %l3,7,%l4
    335406        sll %l3,1,%l3
     
    341412        nop; nop; nop
    342413
    343         /* Check whether previous mode was usermode */
    344         mov %psr, %l4
    345         and %l4, (1 << 6), %l4
    346         cmp %l4, 0
    347         beq 1f
    348         nop
    349 
     414        /* kernel: */
    350415        restore
    351416        restore
     
    365430        nop
    366431
    367 1:      restore
    368         restore
    369         mov %l5, %g5            ! kernel stack pointer
    370         mov %l6, %g6            ! kernel wbuf
    371         mov %l7, %g7
    372         sub %g6, 64, %g6
    373         ldd [%g6 +  0], %l0
    374         ldd [%g6 +  8], %l2
    375         ldd [%g6 + 16], %l4
    376         ldd [%g6 + 24], %l6
    377         ldd [%g6 + 32], %i0
    378         ldd [%g6 + 40], %i2
    379         ldd [%g6 + 48], %i4
    380         ldd [%g6 + 56], %i6
    381 
    3824322:      /* Restore invalid window data */
    383433        restore
     
    397447        jmp %l1
    398448        rett %l2
     449
     450flush_windows:
     451        mov 7, %g1
     4521:      subcc %g1, 1, %g1
     453        bg 1b
     454        save %sp, -64, %sp
     455
     456        mov 7, %g1
     4571:      subcc %g1, 1, %g1
     458        bg 1b
     459        restore
     460
     461        retl
     462        nop
    399463
    400464preemptible_trap:
     
    470534        /* Jump to actual subroutine */
    471535        call %o2
    472         sub %fp, 12, %o1
     536        add %sp, 128, %o1
    473537
    474538        /* Return from handler */
     
    487551        switch_to_invalid %g5, %g6
    488552        clr %l7
     553        mov %l5, %g2
    489554        mov %l6, %g7
    490555        switch_back %g5, %g6
    491556        mov %g7, %g1
     557
     558        /* If trap originated from uspace, restore all windows from UWB */
     559        /* UWB pointer is at %g1 */
     5600:      mov %g0, %wim
     561        clr %g5
     562        andcc %g1, UWB_ALIGNMENT - 1, %g0
     563        bz 0f
     564        nop
     565
     566        restore
     567        sub %g1, 64, %g1
     568        ldd [%g1 +  0], %l0
     569        ldd [%g1 +  8], %l2
     570        ldd [%g1 + 16], %l4
     571        ldd [%g1 + 24], %l6
     572        ldd [%g1 + 32], %i0
     573        ldd [%g1 + 40], %i2
     574        ldd [%g1 + 48], %i4
     575        ldd [%g1 + 56], %i6
     576        inc %g5
     577        and %g5, 0x7, %g5
     578        ba 0b
     579        nop
     580
     581        /* We've restored all uspace windows. Now time to
     582         * fix CWP and WIM
     583         */
     5840:      restore
     585        get_cwp %g7
     586        clr %g5
     587        inc %g5
     588        sll %g5, %g7, %g5
     589
     590        /* Write values to invalid window and switch back */
     591        mov %g2, %l5
     592        mov %g1, %l6
     593        clr %l7
     594        switch_back %g5, %g6
    492595
    493596        /* If next window is invalid, do inline restore */
     
    679782        ld [%sp + 100], %l0
    680783        mov %o0, %i0
     784        mov %psr, %l1
     785        and %l1, 0xf, %l1
     786        and %l0, 0xfffffff0, %l0
     787        or %l0, %l1, %l0
    681788        mov %l0, %psr
    682789        nop
     
    690797        switch_to_invalid %g5, %g6
    691798        clr %l7
     799        mov %l5, %g2
    692800        mov %l6, %g7
    693801        switch_back %g5, %g6
    694802        mov %g7, %g1
     803
     804        /* If trap originated from uspace, restore all windows from UWB */
     805        /* UWB pointer is at %g1 */
     8060:      mov %g0, %wim
     807        clr %g5
     808        andcc %g1, UWB_ALIGNMENT - 1, %g0
     809        bz 0f
     810        nop
     811
     812        restore
     813        sub %g1, 64, %g1
     814        ldd [%g1 +  0], %l0
     815        ldd [%g1 +  8], %l2
     816        ldd [%g1 + 16], %l4
     817        ldd [%g1 + 24], %l6
     818        ldd [%g1 + 32], %i0
     819        ldd [%g1 + 40], %i2
     820        ldd [%g1 + 48], %i4
     821        ldd [%g1 + 56], %i6
     822        inc %g5
     823        and %g5, 0x7, %g5
     824        ba 0b
     825        nop
     826
     827        /* We've restored all uspace windows. Now time to
     828         * fix CWP and WIM
     829         */
     8300:      restore
     831        get_cwp %g7
     832        clr %g5
     833        inc %g5
     834        sll %g5, %g7, %g5
     835
     836        /* Write values to invalid window and switch back */
     837        mov %g2, %l5
     838        mov %g1, %l6
     839        clr %l7
     840        switch_back %g5, %g6
    695841
    696842        /* If next window is invalid, do inline restore */
     
    9291075        SYSCALL(0xae)
    9301076        SYSCALL(0xaf)
     1077        SYSCALL(0xb0)
     1078        SYSCALL(0xb1)
     1079        SYSCALL(0xb2)
     1080        SYSCALL(0xb3)
     1081        SYSCALL(0xb4)
     1082        SYSCALL(0xb5)
     1083        SYSCALL(0xb6)
     1084        SYSCALL(0xb7)
     1085        SYSCALL(0xb8)
     1086        SYSCALL(0xb9)
     1087        SYSCALL(0xba)
     1088        SYSCALL(0xbb)
     1089        SYSCALL(0xbc)
     1090        SYSCALL(0xbd)
     1091        SYSCALL(0xbe)
     1092        SYSCALL(0xbf)
     1093        SYSCALL(0xc0)
     1094        SYSCALL(0xc1)
     1095        SYSCALL(0xc2)
     1096        SYSCALL(0xc3)
     1097        SYSCALL(0xc4)
     1098        SYSCALL(0xc5)
     1099        SYSCALL(0xc6)
     1100        SYSCALL(0xc7)
     1101        SYSCALL(0xc8)
     1102        SYSCALL(0xc9)
     1103        SYSCALL(0xca)
     1104        SYSCALL(0xcb)
     1105        SYSCALL(0xcc)
     1106        SYSCALL(0xcd)
     1107        SYSCALL(0xce)
     1108        SYSCALL(0xcf)
Note: See TracChangeset for help on using the changeset viewer.