Annotation of researchv10no/sys/ml/access.s, revision 1.1.1.1

1.1       root        1:        .text
                      2: 
                      3: #
                      4: # badaddr(addr, len)
                      5: #      see if access addr with a len type instruction causes a machine check
                      6: #      len is length of access (1=byte, 2=short, 4=long)
                      7: #
                      8:        .globl  _badaddr
                      9: _badaddr:
                     10:        .word   0
                     11:        movl    $1,r0
                     12:        mfpr    $IPL,r1
                     13:        mtpr    $0x16,$IPL      # low enough for very urgent interrupts
                     14:        movl    4(ap),r3
                     15:        movl    8(ap),r4
                     16:        movl    _nofault,r2
                     17:        movab   2f,_nofault
                     18:        bbc     $0,r4,1f; tstb  (r3)
                     19: 1:     bbc     $1,r4,1f; tstw  (r3)
                     20: 1:     bbc     $2,r4,1f; tstl  (r3)
                     21: 1:
                     22:        movl    $10,r3
                     23: 0:     sobgtr  r3,0b           # pause to allow error interrupt
                     24:        clrl    r0              # made it w/o machine checks
                     25: 2:     movl    r2,_nofault
                     26:        mtpr    r1,$IPL
                     27:        ret
                     28: 
                     29: #
                     30: # Check address.
                     31: # Given virtual address, byte count, and rw flag
                     32: # returns 0 on no access.
                     33: #
                     34: _useracc:      .globl  _useracc
                     35:        .word   0x0
                     36:        movl    4(ap),r0                # get va
                     37:        movl    8(ap),r1                # count
                     38:        tstl    12(ap)                  # test for read access ?
                     39:        bneq    userar                  # yes
                     40:        cmpl    $NBPG,r1                        # can we do it in one probe ?
                     41:        bgeq    uaw2                    # yes
                     42: uaw1:
                     43:        probew  $3,$NBPG,(r0)
                     44:        beql    uaerr                   # no access
                     45:        addl2   $NBPG,r0
                     46:        acbl    $NBPG+1,$-NBPG,r1,uaw1
                     47: uaw2:
                     48:        probew  $3,r1,(r0)
                     49:        beql    uaerr
                     50:        movl    $1,r0
                     51:        ret
                     52: 
                     53: userar:
                     54:        cmpl    $NBPG,r1
                     55:        bgeq    uar2
                     56: uar1:
                     57:        prober  $3,$NBPG,(r0)
                     58:        beql    uaerr
                     59:        addl2   $NBPG,r0
                     60:        acbl    $NBPG+1,$-NBPG,r1,uar1
                     61: uar2:
                     62:        prober  $3,r1,(r0)
                     63:        beql    uaerr
                     64:        movl    $1,r0
                     65:        ret
                     66: uaerr:
                     67:        clrl    r0
                     68:        ret
                     69: 
                     70: #
                     71: # kernacc - check for kernel access privileges
                     72: #
                     73: # We can't use the probe instruction directly because
                     74: # it ors together current and previous mode.
                     75: #
                     76:        .globl  _kernacc
                     77: _kernacc:
                     78:        .word   0x0
                     79:        movl    4(ap),r0        # virtual address
                     80:        bbcc    $31,r0,kacc1
                     81:        bbs     $30,r0,kacerr
                     82:        mfpr    $SBR,r2         # address and length of page table (system)
                     83:        bbss    $31,r2,0f; 0:
                     84:        mfpr    $SLR,r3
                     85:        brb     kacc2
                     86: kacc1:
                     87:        bbsc    $30,r0,kacc3
                     88:        mfpr    $P0BR,r2        # user P0
                     89:        mfpr    $P0LR,r3
                     90:        brb     kacc2
                     91: kacc3:
                     92:        mfpr    $P1BR,r2        # user P1 (stack)
                     93:        mfpr    $P1LR,r3
                     94: kacc2:
                     95:        addl3   8(ap),r0,r1     # ending virtual address
                     96:        addl2   $NBPG-1,r1
                     97:        ashl    $-PGSHIFT,r0,r0
                     98:        ashl    $-PGSHIFT,r1,r1
                     99:        bbs     $31,4(ap),kacc6
                    100:        bbc     $30,4(ap),kacc6
                    101:        cmpl    r0,r3           # user stack
                    102:        blss    kacerr          # address too low
                    103:        brb     kacc4
                    104: kacc6:
                    105:        cmpl    r1,r3           # compare last page to P0LR or SLR
                    106:        bgtr    kacerr          # address too high
                    107: kacc4: 
                    108:        movl    (r2)[r0],r3
                    109:        bbc     $31,4(ap),kacc4a
                    110:        bbc     $31,r3,kacerr   # valid bit is off
                    111: kacc4a:
                    112:        cmpzv   $27,$4,r3,$1    # check protection code
                    113:        bleq    kacerr          # no access allowed
                    114:        tstb    12(ap)
                    115:        bneq    kacc5           # only check read access
                    116:        cmpzv   $27,$2,r3,$3    # check low 2 bits of prot code
                    117:        beql    kacerr          # no write access
                    118: kacc5:
                    119:        aoblss  r1,r0,kacc4     # next page
                    120:        movl    $1,r0           # no errors
                    121:        ret
                    122: kacerr:
                    123:        clrl    r0              # error
                    124:        ret

unix.superglobalmegacorp.com

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