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

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