# 2.11BSD#431 - /usr/src/sys/pdp/toy.s

##### Functions

    TOYCSR            X
    _gettoy           X
    _tm2t             X
    _toyclk           X

       1: / April 9, 2000 - modified to probe for the TOY clock rather than checking
       2: /	the cpu type for 93 or 94.
       3:
       4: / the notes say that the TOY clock uses 24 hour time, but then later on
       5: / mention flags dealing with AM/PM...  So, code is present but disabled
       6: / to handle 12 hour time.  If this code is needed change the 0 below to
       7: / a 1.
       8:
       9: toy24=0
      10:
      11: / extraneous flag bit possible in the day field.  this "should never
      12: / happen", but if it does change the 0 to a 1 below.
      13:
      14: dayflags=0
      15:
      16:         .globl  TOYCSR
      17: TOYCSR  = 177526
      18:
      19:         .globl  _toyclk, nofault
      20:         .text
      21: _toyclk:
      22:         jsr     r5,csv                  / callable from C, save regs
      23:         sub     $8.,sp                  / need 8 byte scratch area
      24: tdata = -20
      25:         clr     -(sp)
      26:         mov     $1f, nofault            / catch trap if no toy clock
      27:         tst     *$TOYCSR
      28:         inc     (sp)
      29: 1:
      30:         clr     nofault                 / done with trap catcher
      31:         tst     (sp)+                   / did we see a toy clock?
      32:         beq     err                     / no, go return "error"
      33:         jsr     pc,initoy               / initialize the clock for reading
      34:         mov     r5,(sp)
      35:         add     $tdata,(sp)             / pointer to scratch area
      36:         jsr     pc,_gettoy              / read the toy clock
      37:         mov     (sp),r2                 / pointer to scratch area
      38:         mov     $8.,r3                  / number of bytes of clock data
      39: 2:
      40:         clr     r1
      41:         bisb    (r2),r1                 / fetch byte of clock data (!sign ext)
      42: .if     toy24
      43:         cmp     r3,$5                   / are we on the hours field?
      44:         bne     3f                      / no - br
      45:         bic     $240,r1                 / clear am/pm flags
      46: 3:
      47: .endif
      48:         jsr     pc,bcd                  / convert 2 nybbles bcd to binary
      49: .if     toy24
      50:         cmp     r3,$5                   / hours field?
      51:         bne     4f                      / no - skip am/pm stuff
      52:         tstb    (r2)                    / $200 = am/pm in use
      53:         bpl     4f                      / not am/pm, skip it
      54:         cmp     r1,$12.                 / exactly 12?
      55:         bne     5f                      / no - br
      56:         clr     r1                      / make midnight
      57: 5:
      58:         bitb    $40,(r2)                / PM?
      59:         beq     4f                      / no  - br
      60:         add     $12.,r1                 / convert to 24 hour time
      61: .endif
      62: 4:
      63:         movb    r1,(r2)+                / store converted/correct binary value
      64:         sob     r3,2b                   / continue on for rest of the bytes
      65:         sub     $7,r2                   / back up to seconds field
      66: .if     dayflags
      67:         bicb    $177770,4(r2)           / clear possible excess bits in day
      68: .endif
      69:         mov     $bounds,r3              / do bounds checking now, not 100ths
      70: 1:
      71:         movb    (r2)+,r1                / get byte of clock data
      72:         cmpb    r1,(r3)+                / below lo bound?
      73:         blo     err                     / yes - br
      74:         cmpb    r1,(r3)+                / above hi bound
      75:         bhi     err                     / yes - br
      76:         cmp     r3,$bounds+14.          / at end (7 limits * 2 bytes per = 14)?
      77:         blo     1b                      / no - br
      78:         sub     $8.,r2                  / back to seconds field
      79:         movb    7(r2),r0                / fetch the year of century
      80:         cmp     r0,$90.                 / are we a "90s" system?
      81:         bhis    1f                      / yep - br
      82:         add     $100.,r0                / next century for years 00 - 89
      83: 1:
      84:         movb    r0,7(r2)                / store fixed up year
      85:         decb    6(r2)                   / convert 1-12 month to 0-11
      86:         mov     r2,(sp)                 / pointer to the toy clock data
      87:         jsr     pc,_tm2t                / convert to a 32bit # of seconds time
      88:         br      ret
      89: err:
      90:         clr     r0                      / a double precision value
      91:         clr     r1                      / of 0 signals an error
      92: ret:
      93:         jmp     cret                    / return
      94:         .data
      95: bounds:
      96:         .byte   0,59.                   / seconds lo,hi
      97:         .byte   0,59.                   / minutes lo,hi
      98:         .byte   0,23.                   / hours lo,hi
      99:         .byte   0,7                     / day of week lo,hi
     100:         .byte   1,31.                   / day of month lo,hi
     101:         .byte   1,12.                   / month of year lo,hi
     102:         .byte   0,99.                   / year of century lo,hi
     103:         .text
     104: initoy:
     105:         tst     *$TOYCSR                / strobe the clock register
     106:         clr     -(sp)                   / save previous high byte of register
     107:         movb    *$TOYCSR+1,(sp)         / only bit 8 belongs to TOY!
     108:         bic     $1,(sp)                 / make sure bit 8 (TOY bit) is clear
     109:         mov     $2,r2                   / number of double words to send clock
     110: 1:
     111:         mov     $35305,r0               / first word of recognition code
     112:         jsr     pc,toyload              / send it to clock
     113:         mov     $56243,r0               / second word
     114:         jsr     pc,toyload              / send it
     115:         sob     r2,1b                   / do the whole thing twice
     116:         tst     (sp)+                   / clean stack
     117:         rts     pc
     118:
     119: / send contents of r0 to the TOY.  2(sp) has the old bits 9-15, bit 8
     120: / has been cleared.
     121:
     122: toyload:
     123:         mov     $16.,r1                 / number of bits to send
     124: 1:
     125:         mov     r0,r3                   / scratch copy
     126:         bic     $177776,r3              / clear all but bit being sent
     127:         bis     2(sp),r3                / merge in old_csr_bits
     128:         movb    r3,*$TOYCSR+1           / send bit to clock
     129:         asr     r0                      / shift pattern down
     130:         sob     r1,1b                   / do all 16 bits in the word
     131:         rts     pc
     132:
     133:         .globl  _gettoy
     134: _gettoy:                                / (void)gettoy(&char[8]);
     135:         jsr     r5,csv                  / C callable
     136:         mov     4(r5),r2                / buffer address
     137:         mov     $4,r3                   / number of words in buffer
     138: 1:
     139:         mov     $16.,r4                 / number of bits in word
     140: 2:
     141:         movb    *$TOYCSR+1,r0           / low bit of top byte is a clock bit
     142:         asr     r0                      / put it in carry
     143:         ror     r1                      / ripple in at top end of r1
     144:         sob     r4,2b                   / do all 16 bits
     145:         mov     r1,(r2)+                / store the word in the buffer
     146:         sob     r3,1b                   / do all 4 words
     147:         jmp     cret                    / and return
     148:
     149: bcd:
     150:         clr     r0
     151:         div     $16.,r0
     152:         mov     r1,-(sp)
     153:         mov     r0,r1
     154:         mul     $10.,r1
     155:         add     (sp)+,r1
     156:         rts     pc
     157:
     158:         .globl  _tm2t
     159: _tm2t:
     160:         jsr     r5,csv
     161:         mov     4(r5),r4
     162:         movb    1(r4),r1
     163:         mov     r1,-(sp)
     164:         clr     -(sp)
     165:         movb    2(r4),r0
     166:         mul     $74,r0
     167:         mov     r1,-(sp)
     168:         mov     r0,-(sp)
     169:         mov     $7020,-(sp)
     170:         sxt     -(sp)
     171:         movb    3(r4),r1
     172:         mov     r1,-(sp)
     173:         clr     -(sp)
     174:         jsr     pc,lmul
     175:         add     $10,sp
     176:         mov     r1,-(sp)
     177:         mov     r0,-(sp)
     178:         mov     $50600,-(sp)
     179:         mov     $1,-(sp)
     180:         mov     r4,-(sp)
     181:         jsr     pc,_ndays               / return value in r1
     182:         tst     (sp)+
     183:         dec     r1
     184:         mov     r1,-(sp)
     185:         sxt     -(sp)
     186:         jsr     pc,lmul
     187:         add     $10,sp
     188:         add     (sp)+,r0
     189:         add     (sp)+,r1
     190:         adc     r0
     191:         add     (sp)+,r0
     192:         add     (sp)+,r1
     193:         adc     r0
     194:         add     (sp)+,r0
     195:         add     (sp)+,r1
     196:         adc     r0
     197:         jmp     cret
     198:
     199: _leap:                          / r2 = year number, r1 clobbered
     200:         mov     r2,r1
     201:         add     $3554,r1
     202:         sxt     r0
     203:         div     $620,r0
     204:         tst     r1
     205:         bne     2f
     206:         br      3f
     207: 1:
     208:         clr     r0              / return false
     209:         br      4f
     210: 2:
     211:         mov     r2,r1
     212:         sxt     r0
     213:         div     $144,r0
     214:         tst     r1
     215:         jeq     1b
     216:         bit     $3,r2
     217:         jne     1b
     218: 3:
     219:         mov     $1,r0           / return true
     220: 4:
     221:         rts     pc
     222:         .data
     223: mdays:
     224:         .byte 37,34,37,36,37,36,37,37,36,37,36,37,0
     225:         .even
     226:         .text
     227: _ndays:
     228:         jsr     r5,csv
     229:         mov     4(r5),r0
     230:         movb    5(r0),r4
     231:         mov     $106,r2
     232:         jbr     3f
     233: 1:
     234:         add     $555,r4
     235:         jsr     pc,*$_leap              / r2 has year in it already
     236:         add     r0,r4
     237:         inc     r2
     238: 3:
     239:         mov     4(r5),r0
     240:         movb    7(r0),r0
     241:         cmp     r2,r0
     242:         jlt     1b
     243:         clr     r3
     244:         jbr     8f
     245: 4:
     246:         clr     r0
     247:         cmp     $1,r3
     248:         jne     5f
     249:         jsr     pc,*$_leap      / r2 has year
     250: 5:
     251:         movb    mdays(r3),r1
     252:         add     r1,r0
     253:         add     r0,r4
     254:         inc     r3
     255: 8:
     256:         mov     4(r5),r0
     257:         movb    6(r0),r0
     258:         cmp     r3,r0
     259:         jlt     4b
     260:         mov     r4,r1           / return value in r1 not r0
     261:         jmp     cret

#### Defined functions

TOYCSR declared in line 16; defined in line 17; used 6 times

- in line 16, 27, 105-107(2), 128, 141

_gettoy declared in line 133; defined in line 134; used 2 times

- in line 36, 133

_leap defined in line 199; used 2 times

- in line 235, 249

_ndays defined in line 227; used 1 times

- in line 181

_tm2t declared in line 158; defined in line 159; used 2 times

- in line 87, 158

_toyclk declared in line 19; defined in line 21; used 3 times

- in line 19
- in /usr/src/sys/sys/init_main.c line 62, 198

bcd defined in line 149; used 1 times

- in line 48

dayflags defined in line 14; used 1 times

- in line 66

err defined in line 89; used 3 times

- in line 32, 73-75(2)

initoy defined in line 104; used 1 times

- in line 33

ret defined in line 92; used 1 times

- in line 88

tdata defined in line 24; used 1 times

- in line 35

toy24 defined in line 9; used 2 times

- in line 42, 49

toyload defined in line 122; used 2 times

- in line 112-114(2)

#### Defined variables

bounds defined in line 95; used 2 times

- in line 69, 76

mdays defined in line 223; used 1 times

- in line 251

Last modified: 2000-04-09 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 680 |