[BACK]Return to pramasm.s CVS log [TXT][DIR] Up to [local] / sys / arch / mac68k / mac68k

Annotation of sys/arch/mac68k/mac68k/pramasm.s, Revision 1.1

1.1     ! nbrk        1: /*     $OpenBSD: pramasm.s,v 1.7 2007/04/10 17:14:42 miod Exp $        */
        !             2: /*     $NetBSD: pramasm.s,v 1.4 1995/09/28 03:15:54 briggs Exp $       */
        !             3:
        !             4: /*
        !             5:  * RTC toolkit version 1.08b, copyright 1995, erik vogan
        !             6:  *
        !             7:  * All rights and privileges to this code hereby donated
        !             8:  * to the ALICE group for use in NetBSD.  see the copyright
        !             9:  * below for more info...
        !            10:  */
        !            11: /*
        !            12:  * Copyright (c) 1995 Erik Vogan
        !            13:  * All rights reserved.
        !            14:  *
        !            15:  * This code is derived from software contributed to the Alice Group
        !            16:  * by Erik Vogan.
        !            17:  *
        !            18:  * Redistribution and use in source and binary forms, with or without
        !            19:  * modification, are permitted provided that the following conditions
        !            20:  * are met:
        !            21:  * 1. Redistributions of source code must retain the above copyright
        !            22:  *    notice, this list of conditions and the following disclaimer.
        !            23:  * 2. Redistributions in binary form must reproduce the above copyright
        !            24:  *    notice, this list of conditions and the following disclaimer in the
        !            25:  *    documentation and/or other materials provided with the distribution.
        !            26:  * 3. All advertising materials mentioning features or use of this software
        !            27:  *    must display the following acknowledgement:
        !            28:  *     This product includes software developed by the Alice Group.
        !            29:  * 4. The names of the Alice Group or any of its members may not be used
        !            30:  *    to endorse or promote products derived from this software without
        !            31:  *    specific prior written permission.
        !            32:  *
        !            33:  * THIS SOFTWARE IS PROVIDED BY THE ALICE GROUP ``AS IS'' AND ANY EXPRESS OR
        !            34:  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
        !            35:  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
        !            36:  * IN NO EVENT SHALL THE ALICE GROUP BE LIABLE FOR ANY DIRECT, INDIRECT,
        !            37:  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
        !            38:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
        !            39:  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
        !            40:  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
        !            41:  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
        !            42:  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
        !            43:  */
        !            44:
        !            45: /*
        !            46:  *  The following are the C interface functions to RTC access functions
        !            47:  * that are defined later in this file.
        !            48:  */
        !            49:
        !            50:                                /* The following routines are the hardware
        !            51:                                 * specific routines for the machines that
        !            52:                                 * use the II-like method to access the PRAM. */
        !            53:
        !            54: /*
        !            55:  *  The following are the C interface functions to RTC access functions
        !            56:  * that are defined later in this file.
        !            57:  */
        !            58:
        !            59:        .text
        !            60:
        !            61:        .even
        !            62:
        !            63: .globl _getPramTimeII
        !            64: _getPramTimeII:
        !            65:        link    a6,#-4          |  create a little home for ourselves
        !            66:        jbsr    _readClock      |  call the routine to read the time
        !            67:        unlk    a6              |  clean up after ourselves
        !            68:        rts                     |  and return to caller
        !            69:
        !            70: .globl _setPramTimeII
        !            71: _setPramTimeII:
        !            72:        link    a6,#-4          |  create a little home for ourselves
        !            73:        movel   a6@(8),d0       |  get the passed in long (seconds since 1904)
        !            74:        jbsr    _writeClock     |  call the routine to write the time
        !            75:        unlk    a6              |  clean up after ourselves
        !            76:        rts                     |  and return to caller
        !            77:
        !            78: /*
        !            79:  *  The following are the RTC access functions used by the interface
        !            80:  * routines, above.
        !            81:  */
        !            82:
        !            83: _readClock:
        !            84:        moveml  #0x7cc0, sp@-   | store off the regs we need
        !            85:        moveq   #00,d0          | zero out our result reg
        !            86: readagan:
        !            87:        moveq   #00,d5          | and our temp result reg
        !            88:        moveq   #03,d4          | set our count down reg to 4
        !            89:        movel   #0x00000081,d1  | read sec byte 0 first
        !            90: getSecb:
        !            91:        bsr     _Transfer       | get that byte
        !            92:        rorl    #8,d5           | shift our time to the right
        !            93:        swap    d1              | we want to access our new data
        !            94:        moveb   d1,d5           | move that byte to the spot we vacated
        !            95:        swap    d1              | return our PRAM command to orig. config
        !            96:        addqb   #4,d1           | increment to the next sec byte
        !            97:        dbf     d4,getSecb      | any more bytes to get ?
        !            98:        cmpl    d5,d0           | same secs value we as we just got ?
        !            99:        beq     gotTime         | we got a good time value
        !           100:        movel   d5,d0           | copy our current time to the compare reg
        !           101:        bra     readagan        | read the time again
        !           102: gotTime:
        !           103:        rorl    #8,d0           | make that last shift to correctly order
        !           104:                                |  time bytes!!!
        !           105:        movel   #0x00d50035,d1  | we have to set the write protect bit
        !           106:                                | so the clock doesn't run down !
        !           107:        bsr     _Transfer       | (so says Apple...)
        !           108:        moveml  sp@+, #0x033e   | restore our regs
        !           109:        rts                     | and return to caller
        !           110:
        !           111: _writeClock:
        !           112:        moveml  #0x78c0, sp@-   | store off the regs we need
        !           113:        moveq   #03,d4          | set our count down reg to 4
        !           114:        movel   #0x00550035,d1  | de-write-protect the PRAM
        !           115:        bsr     _Transfer       | so we can set our value
        !           116:        moveq   #1,d1           | write sec byte 0 first
        !           117: putSecb:
        !           118:        swap    d1              | we want access to data byte of command
        !           119:        moveb   d0,d1           | set our first secs byte
        !           120:        swap    d1              | and return command to orig. config
        !           121:        bsr     _Transfer       | write that byte
        !           122:        rorl    #8,d0           | shift our time to the right
        !           123:        addqb   #4,d1           | increment to the next sec byte
        !           124:        dbf     d4,putSecb      | any more bytes to put ?
        !           125:        movel   #0x00d50035,d1  | we have to set the write protect bit
        !           126:                                | so the clock doesn't run down !
        !           127:        bsr     _Transfer       | (so says Apple...)
        !           128:        moveml  sp@+, #0x031e   | restore our regs
        !           129:        rts                     | and return to caller
        !           130:
        !           131: _Transfer:
        !           132:        movew   sr,sp@-         | store the SR (we'll change it!)
        !           133:        oriw    #0x0700,sr      | disable all interrupts
        !           134:        moveal  _Via1Base,a1    | move VIA1 addr in reference reg
        !           135:        moveq   #0,d2           | zero out d2 (it'll hold VIA1 reg B contents)
        !           136:        moveb   a1@,d2          | and get VIA1 reg B contents
        !           137:        andib   #0xF8,d2        | don't touch any but RTC bits
        !           138:                                | (and zero all those)
        !           139:        movew   d1,d3           | we want to manipulate our command
        !           140:        andiw   #0xFF00,d3      | zero the LSB
        !           141:        beq     oldPRAMc        | do an old PRAM style command
        !           142: xPRAMc:
        !           143:        rorw    #8,d1           | swap the command bytes (1st byte of 2)
        !           144:        bsr     writebyte       | and write the command byte
        !           145:        rorw    #8,d1           | swap the command bytes again (2nd byte of 2)
        !           146:        bsr     writebyte       | write that byte to RTC too
        !           147:        moveq   #0x1F,d3        | r/w bit is $F for an extended command
        !           148:                                | (but command is swapped to MSW!! so add $10)
        !           149:        bra     Rwbrnch         | go figure out if it's a read or a write cmd
        !           150: oldPRAMc:
        !           151:        bsr     writebyte       | only one byte for an old PRAM command
        !           152:        moveq   #0x17,d3        | r/w bit is $7 for and old PRAM command
        !           153:                                | ( command is swapped to MSW, add $10)
        !           154: Rwbrnch:
        !           155:        swap    d1              | better get that (data/dummy) byte ready
        !           156:        btst    d3,d1           | test bit no. d3 of reg d1 (read or write ?)
        !           157:        beq     Wtrue           | 0 = write, 1 = read (branch on write)
        !           158: Rtrue:
        !           159:        bsr     readbyte        | read a byte from the RTC
        !           160:        bra     Cleanup         | and call mom to clean up after us
        !           161: Wtrue:
        !           162:        bsr     writebyte       | write the data to the RTC
        !           163: Cleanup:
        !           164:        swap    d1              | move command to LSW again
        !           165:        bset    #2,a1@          | bring the RTC enable line high (end of xfer)
        !           166:        movew   sp@+,sr         | restore prior interrupt status
        !           167:        rts                     | and return to caller
        !           168:
        !           169: writebyte:
        !           170:        moveq   #7,d3           | set our bit counter to 8
        !           171: wagain:
        !           172:        lsrb    #1,d2           | ditch the old data channel value
        !           173:        roxlb   #1,d1           | and move a new value to X
        !           174:        roxlb   #1,d2           | now move value from X to data channel
        !           175:        moveb   d2,a1@          | set our VIA1 reg B contents to match
        !           176:        bset    #1,a1@          | and finish strobing the clock line
        !           177:        dbf     d3,wagain       | do this until we've sent a whole byte
        !           178:        lsrb    #1,d2           | ditch the data channel value one last time
        !           179:        roxlb   #1,d1           | get rid of the extra X bit we've carried
        !           180:        lslb    #1,d2           | and restore d2 to prior status
        !           181:        rts                     | return to caller
        !           182:
        !           183: readbyte:
        !           184:        moveq   #7,d3           | set our bit counter to 8
        !           185:        bclr    #0,a1@(0x0400)  | set VIA1 reg B data line to input
        !           186: ragain:
        !           187:        bclr    #1,a1@          | strobe the clock line to make
        !           188:        bset    #1,a1@          | the data valid
        !           189:        moveb   a1@,d2          | and get out data byte
        !           190:        lsrb    #1,d2           | get the data channel value to X
        !           191:        roxlb   #1,d1           | and move X to data byte
        !           192:        dbf     d3,ragain       | do this until we've received a whole byte
        !           193:        bset    #0,a1@(0x0400)  | and return RTC data line to output
        !           194:        rts                     | return to caller

CVSweb