Artifact Content
Not logged in

Artifact ad1f9336c3316aa19de15cf847a3b3c473bbcc1d:


     1  // Driver for the CF Card on the breadboard
     2  
     3  // defines for the CF card registers
     4  	cfregs = 0xfe00
     5  	cfdata = cfregs + 0
     6  	cferr  = cfregs + 1	// rd
     7  	cffeat = cfregs + 1	// wr
     8  	cfcnt  = cfregs + 2
     9  	cflba0 = cfregs + 3
    10  	cflba1 = cfregs + 4
    11  	cflba2 = cfregs + 5
    12  	cflba3 = cfregs + 6
    13  	cfstat = cfregs + 7	// rd
    14  	cfcmd  = cfregs + 7	// wr
    15  
    16  // defines for CF card commands in upper byte
    17  	SETFEAT = 0xef00	// set feature
    18  	RDSECT  = 0x2000	// read sector
    19  	WRSECT  = 0x3000	// write sector
    20  	IDENT   = 0xec00	// identify drive
    21  	BYTEMOD = 0x0100	// 8 bit access mode
    22  	
    23  // defines for status bits
    24  	ERR     = 0x0100	// error condition
    25  	DRQ     = 0x0800	// data request
    26  
    27  // image vectors left behind by boot loader
    28  	cfdsk0	= 0xff00	// base sector of DSK0 image (32 bit)
    29  	cfdsk1  = 0xff04	// base sector of DSK1 image (32 bit)
    30  
    31  // arguments to cf_card_rd, cf_card_wr
    32  	dev	= 22
    33  	blkno	= 24
    34  	addr	= 26
    35  	wcount	= 28
    36  
    37  	.text
    38  
    39  // Seek disk block
    40  seek:
    41  1:	movb	@cfstat,r0	// wait card ready
    42  	jlt	1b
    43  	li	r2,cfdsk0	// starting sector of dsk0 image
    44  	mov	@dev(bp),r0
    45  	jeq	1f
    46  	li	r2,cfdsk1	// starting sector of dsk1 image
    47  1:	mov	@blkno(bp),r1	// requested sector number
    48  	mov	(r2)+,r0	// add start to requested to get
    49  	a	(r2),r1		//   32 bit LBA of req. sector
    50  	jnc     1f
    51  	inc	r0
    52  1:	movb	r1,@cflba1	// move the LBA to the CF Card
    53  	swpb	r1		//    registers and set transfer
    54  	movb	r1,@cflba0	//    length to 1 sector
    55  	andi	r0,0x0fff
    56  	ori	r0,0xe000
    57  	movb	r0,@cflba3
    58  	swpb	r0
    59  	movb	r0,@cflba2
    60  	li	r0,0x0100
    61  	movb	r0,@cfcnt
    62  	b	(r11)
    63  
    64  // Read 512 byte block from the CF Card
    65  rdblock:
    66  1:	movb	@cfstat,r0	// wait card ready
    67  	jlt	1b
    68  	li	r0,RDSECT	// issue read command
    69  	movb	r0,@cfcmd
    70  1:	movb	@cfstat,r0	// wait card ready
    71  	movb	r0,r1
    72  	jlt	1b
    73  	andi	r0,DRQ		// and data ready
    74  	jeq	1b
    75  	andi	r1,ERR		// check for error
    76  	jne	2f
    77  
    78  	li	r12,0x00c0      // DMAC base addr
    79  	tb	31		// DMAC present?
    80  	jne     1f		// -> no
    81  	sbz	30		// set read mode
    82  	ldcr    r10,0		// Do DMA transfer
    83  	ai	r10,512
    84  	jmp	2f
    85  
86 1: li r1,512/4 // CPU transfer 87 1: movb @cfdata,(r10)+ 88 movb @cfdata,(r10)+ 89 movb @cfdata,(r10)+ 90 movb @cfdata,(r10)+ 91 dec r1 92 jne 1b
93 94 2: movb @cferr,r2 // fetch error code 95 srl r2,8 96 b (r11) 97 98 // read 'wcount' words from 'dev' starting at 'blkno' to 'addr' 99 .globl _bkread 100 _bkread: 101 mov r11,r0 102 bl @csv 103 mov @wcount(bp),r9 104 srl r9,8 105 jeq 2f 106 mov @addr(bp),r10 107 1: bl @seek 108 bl @rdblock 109 jne 2f 110 inc @blkno(bp) 111 dec r9 112 jne 1b 113 clr r2 114 2: b @cret 115 116 // write 512 byte block to the CF Card 117 wrblock: 118 1: movb @cfstat,r0 // wait card ready 119 jlt 1b 120 li r0,WRSECT // issue read command 121 movb r0,@cfcmd 122 1: movb @cfstat,r0 // wait card ready 123 jlt 1b 124 andi r0,DRQ // and data ready 125 jeq 1b 126 li r12,0x00c0 // DMAC base address 127 tb 31 // DMAC present? 128 jne 1f // -> no 129 sbo 30 // write mode 130 ldcr r10,0 // start DMA transfer 131 ai r10,512 132 jmp 2f 133 134 1: li r1,512/4 // CPU transfer 135 1: movb (r10)+,@cfdata 136 movb (r10)+,@cfdata 137 movb (r10)+,@cfdata 138 movb (r10)+,@cfdata 139 dec r1 140 jne 1b 141 142 2: movb @cfstat,r0 // check for error 143 andi r0,ERR 144 jeq 1f 145 movb @cferr,r2 // fetch error code 146 srl r2,8 147 1: b (r11) 148 149 // write 'wcount' words from 'addr' to 'dev' starting at 'blkno' 150 .globl _bkwrite 151 _bkwrite: 152 mov r11,r0 153 bl @csv 154 mov @wcount(bp),r9 155 srl r9,8 156 jeq 2f 157 mov @addr(bp),r10 158 1: bl @seek 159 bl @wrblock 160 jne 2f 161 inc @blkno(bp) 162 dec r9 163 jne 1b 164 clr r2 165 2: b @cret 166 167 // init CF card, set 8-bit mode 168 .globl _bkinit 169 _bkinit: 170 1: movb @cfstat,r0 171 jlt 1b 172 movb @zero,@cflba3 173 li r0,BYTEMOD 174 movb r0,@cffeat 175 li r0,SETFEAT 176 movb r0,@cfcmd 177 b (r11) 178 179 .data 180 zero: 0