Annotation of cci/d/event/prvins_evt.s, revision 1.1.1.2

1.1       root        1:  #
                      2:  #     privileged instructions event test
                      3:  #
                      4:  #
                      5:  #     halt ,ldpxtx,svpctx,mtpr,mfpr in user mode
                      6:  #
                      7:  #     *** WARNING :
                      8:  #     halt instruction in user mode better create privileged instr
                      9:  #     fault, otherwise expect unpredictable results.
                     10:  #
                     11:  #     R7 = PC that failed
                     12:  #     R0 = error code
                     13:  #          1 : Failed to REI to user
                     14:  #          2 : Expected fault didnot happen
                     15:  #          3 : Error in PC pushed on the stack
                     16:  #              R1 = actual,  R2 = expected
                     17:  #          4 : Error in PSL pushed on the stack
                     18:  #              R1 = actual,  R2 = expected
                     19:  #          5 : Error in current PSL after taking fault
                     20:  #              R1 = actual,  R2 = expected
                     21:  #
                     22: 
                     23: 
                     24:        .globl  _prv_evt
                     25: _prv_evt:
                     26:        .word   0x1fff
                     27:        mtpr    $31,$IPL                /* Set IPL to HIGH              */
                     28:        movab   (sp),_savvec0           /* Save current SP              */
                     29:        mtpr    _savvec0,$ISP           /* Set ISP to current SP        */
1.1.1.2 ! root       30:        mfpr    $KSP,_savvec9           /* Save kernal stack pointer    */
        !            31:        mfpr    $USP,_savveca           /* Save user stack pointer      */
1.1       root       32:        movl    _scb+PINSTVEC,_savvec2  /* Save priv. inst. fault vector */
                     33:        movab   vecvec4,_scb+PINSTVEC   /* Sew new vector               */
                     34: #
                     35: #      go to User mode
                     36: #
                     37: umode:
                     38:        movl    $0x01000000,-(sp)       /* Set PSL on stack; User mode  */
                     39:        movab   ldctx,-(sp)             /* Set PC for REI               */
                     40:        clrl    r5                      /* R5 used as flags to be       */
                     41:                                        /* checked in event handler     */
                     42:        rei                     /* REI to User mode                     */
                     43:        movl    $1,r0           /* REI failed ! R0 = error code         */
                     44:        jmp     *badrtn
                     45: #
                     46: #      We are now in User mode ; try to execute LDPCTX in User mode
                     47: #
                     48: ldctx:
                     49:        movab   svctx,rtnxt     /* Set return address for fault handler */
                     50:        movab   ldpc,exp_pc     /* Set expected PC                      */
                     51:        movl    exp_pc,r7
                     52:        movpsl  r3              /* R3 = current PSL                     */
                     53: ldpc:  ldpctx                  /* Should cause priv. inst. fault       */
                     54:        incl    r5              /* Should never come here; set flag     */
                     55:        movl    $2,r0           /* Expected fault did not happen !!     */
                     56:        jmp     *badrtn                 /* R0 = error code                      */
                     57: #
                     58: #      Come back here from event handler
                     59: #      still in User mode; try to execute SVPCTX in User mode
                     60: #
                     61: svctx:
                     62:        movab   prvmt,rtnxt     /* Set return address for fault handler */
                     63:        movab   svpc,exp_pc     /* Set expected PC                      */
                     64:        movl    exp_pc,r7
                     65:        movpsl  r3              /* R3 = current PSL                     */
                     66: svpc:  ldpctx                  /* Should cause priv. inst. fault       */
                     67:        incl    r5              /* Should never come here; set flag     */
                     68:        movl    $2,r0           /* Expected fault did not happen !!     */
                     69:        jmp     *badrtn                 /* R0 = error code                      */
                     70: #
                     71: #      Come back here from event handler
                     72: #      still in User mode; try to execute MTPR in User mode
                     73: #
                     74: prvmt:
                     75:        movab   prvmf,rtnxt     /* Set return address for fault handler */
                     76:        movab   pmtpr,exp_pc    /* Set expected PC                      */
                     77:        movl    exp_pc,r7
                     78:        movpsl  r3              /* R3 = current PSL                     */
                     79: pmtpr: mtpr    _pcb0,$PCBB     /* Try MTPR instruction                 */
                     80:        incl    r5              /* Should never come here; set flag     */
                     81:        movl    $2,r0           /* Expected fault did not happen !!     */
                     82:        jmp     *badrtn                 /* R0 = error code                      */
                     83: #
                     84: #      Come back here from event handler
                     85: #      still in User mode; try to execute MFPR in User mode
                     86: #
                     87: prvmf:
                     88:        movab   prvhlt,rtnxt    /* Set return address for fault handler */
                     89:        movab   pmfpr,exp_pc    /* Set expected PC                      */
                     90:        movl    exp_pc,r7
                     91:        movpsl  r3      
                     92: pmfpr: mfpr    $PCBB,r8        /* Try MFPR                             */
                     93:        incl    r5              /* Should never come here; set flag     */
                     94:        movl    $2,r0           /* Expected fault did not happen !!     */
                     95:        jmp     *badrtn                 /* R0 = error code                      */
                     96: #
                     97: #      Come back here from event handler
                     98: #      still in User mode; try to execute HALT in User mode
                     99: #
                    100: prvhlt:
                    101:        clrl    rtnxt           /* Last test : return                   */
                    102:        movab   phlt,exp_pc     /* Set expected PC                      */
                    103:        movl    exp_pc,r7
                    104:        movpsl  r3      
                    105: phlt:
1.1.1.2 ! root      106:        halt                    /* Try HALT instruction                 */
1.1       root      107:        incl    r5              /* Should never come here; set flag     */
                    108:        movl    $2,r0           /* Expected fault did not happen !!     */
                    109:        jmp     *badrtn         /* R0 = error code                      */
                    110: #
                    111: #      Event handler for privilege inst. fault
                    112: #
                    113:        .align  2
                    114: vecvec4:
                    115:        cmpl    $0,r5           /* Check flag; no fault in User mode ? */
                    116:        beql    1f              /* If yes fall thru else skip           */
                    117:        jmp     *badrtn                 /* Error : no fault in User mode        */
                    118: #
                    119: #      Check parameters pushed on stack
                    120: #      
                    121: 1:
                    122:        movl    (sp)+,r1        /* R1 = actual PC pop from stack        */
                    123:        movl    exp_pc,r2       /* R2 = expected PC                     */
                    124:        cmpl    r1,r2
                    125:        beql    1f
                    126:        movl    $3,r0           /* R0 = error code; wrong PC on stack   */
                    127:        jmp     *badrtn                 /* R1 = actual; R2 = expected           */
                    128: 
                    129: 1:     movl    (sp)+,r1        /* R1 = actual PSL pop from stack       */
                    130:        andl2   $0xffffff00,r1  /* mask out PSW flags                   */
                    131:        movl    $0x01000000,r2  /* R2 = expected PSl                    */
                    132:        cmpl    r1,r2
                    133:        beql    1f
                    134:        movl    $4,r0           /* R0 = error code; wrong PSL on stack  */
                    135:        jmp     *badrtn                 /* R1= actual; R2 = expected            */
                    136: 
                    137: 1:     movpsl  r1              /* R1 = current PSL (afer fault)        */
                    138:        andl2   $0x051f0000,r1  /* Mask out PSW flags                   */
                    139:        movl    $0,r2           /* R2 = expected current PSL            */
                    140:        cmpl    r1,r2
                    141:        beql    nxt
                    142:        movl    $5,r0           /* R0 = error code; wrong current PSL   */
                    143:        jmp     *badrtn                 /* R1 = actual; R2 = expected           */
                    144: #
                    145: #      All checked out; get ready to return to test or monitor
                    146: #
                    147: nxt:
                    148:        movl    rtnxt,r9        /* R9 = return address                  */
                    149:        cmpl    $0,r9           /* last test ?                          */      
                    150:        jeql    lastst          /* If yes then get out                  */
                    151:        movl    $0x01000000,-(sp)       /* Push PSL, PC on stack for REI */
                    152:        movl    r9,-(sp)                /* to return                    */
                    153:        rei
                    154:        halt                    /* Should never come here */
                    155: 
                    156: lastst:                                        /* All done,return to monitor   */
                    157:        movl    _savvec2,_scb+PINSTVEC
1.1.1.2 ! root      158:        mtpr    _savvec0,$ISP           /* restore interrupt stack pointer */
        !           159:        mtpr    _savvec9,$KSP           /* restore interrupt kernal pointer */
        !           160:        mtpr    _savveca,$USP           /* restore interrupt user pointer */
1.1       root      161:        pushl   $0                      /* Push dummy PC, PSL on stack  */
                    162:        pushl   $0                      /* We are now still on Kernel stack */
                    163:        mtpr    $31,$IPL
                    164:        svpctx                          /* This will switch back to ISP */
                    165: nxtpc:
                    166:        ret
                    167: 
                    168:        .align  2
                    169: rtnxt: .long   0       /* Contain return address from fault handler */
                    170: exp_pc: .long  0       /* Contain expected PC to be checked in fault handler */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.