Artifact Content
Not logged in

Artifact c22c09b80a674a44f7faccfeceb12e758d3ad94c:


     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  	li	r2,cfdsk0	// starting sector of dsk0 image
    42  	mov	@dev(bp),r0
    43  	jeq	1f
    44  	li	r2,cfdsk1	// starting sector of dsk1 image
    45  1:	mov	@blkno(bp),r1	// requested sector number
    46  	mov	(r2)+,r0	// add start to requested to get
    47  	a	(r2),r1		//   32 bit LBA of req. sector
    48  	jnc     1f
    49  	inc	r0
    50  1:	movb	r1,@cflba1	// move the LBA to the CF Card
    51  	swpb	r1		//    registers and set transfer
    52  	movb	r1,@cflba0	//    length to 1 sector
    53  	andi	r0,0x0fff
    54  	ori	r0,0xe000
    55  	movb	r0,@cflba3
    56  	swpb	r0
    57  	movb	r0,@cflba2
    58  	li	r0,0x0100
    59  	movb	r0,@cfcnt
    60  	b	(r11)
    61  
    62  // Read 512 byte block from the CF Card
    63  rdblock:
    64  1:	movb	@cfstat,r0	// wait card ready
    65  	jlt	1b
    66  	li	r0,RDSECT	// issue read command
    67  	movb	r0,@cfcmd
    68  1:	movb	@cfstat,r0	// wait card ready
    69  	movb	r0,r1
    70  	jlt	1b
    71  	andi	r0,DRQ		// and data ready
    72  	jeq	1b
    73  	andi	r1,ERR		// check for error
    74  	jne	2f
75 li r1,512 76 1: movb @cfdata,(r10)+ 77 dec r1 78 jne 1b
79 b (r11) 80 81 2: movb @cferr,r2 // fetch error code 82 srl r2,8 83 b (r11) 84 85 // read 'wcount' words from 'dev' starting at 'blkno' to 'addr' 86 .globl _cfread 87 _cfread: 88 mov r11,r0 89 bl @csv 90 mov @wcount(bp),r9 91 srl r9,8 92 jeq 2f 93 mov @addr(bp),r10 94 1: bl @seek 95 bl @rdblock 96 jne 2f 97 inc @blkno(bp) 98 dec r9 99 jne 1b 100 clr r2 101 2: b @cret 102 103 // write 512 byte block to the CF Card 104 wrblock: 105 1: movb @cfstat,r0 // wait card ready 106 jlt 1b 107 li r0,WRSECT // issue read command 108 movb r0,@cfcmd 109 1: movb @cfstat,r0 // wait card ready 110 jlt 1b 111 andi r0,DRQ // and data ready 112 jeq 1b 113 li r1,512 114 1: movb (r10)+,@cfdata 115 dec r1 116 jne 1b 117 movb @cfstat,r0 // check for error 118 andi r0,ERR 119 jeq 1f 120 movb @cferr,r2 // fetch error code 121 srl r2,8 122 1: b (r11) 123 124 // write 'wcount' words from 'addr' to 'dev' starting at 'blkno' 125 .globl _cfwrite 126 _cfwrite: 127 mov r11,r0 128 bl @csv 129 mov @wcount(bp),r9 130 srl r9,8 131 jeq 2f 132 mov @addr(bp),r10 133 1: bl @seek 134 bl @wrblock 135 jne 2f 136 inc @blkno(bp) 137 dec r9 138 jne 1b 139 clr r2 140 2: b @cret 141 142 // init CF card, set 8-bit mode 143 .globl _cfinit 144 _cfinit: 145 1: movb @cfstat,r0 146 jlt 1b 147 movb @zero,@cflba3 148 li r0,BYTEMOD 149 movb r0,@cffeat 150 li r0,SETFEAT 151 movb r0,@cfcmd 152 b (r11) 153 154 .data 155 zero: 0 156 157