OpenCores
URL https://opencores.org/ocsvn/eco32/eco32/trunk

Subversion Repositories eco32

[/] [eco32/] [tags/] [eco32-0.22/] [monitor/] [monitor-digilent/] [sctio-ser.s] - Blame information for rev 152

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 16 hellwig
;
2
; sctio-ser.s -- disk sector I/O for disk made available by serial interface
3
;
4
 
5
;***************************************************************
6
 
7
        .export sctcapser               ; determine disk capacity
8
        .export sctioser                ; do disk I/O
9
 
10
        .import ser1in
11
        .import ser1out
12
        .import ser1inchk
13
        .import puts
14
 
15
        ; constants for communication with disk server
16
        .set    SYN,0x16                ; to initiate the three-way handshake
17
        .set    ACK,0x06                ; acknowledgement for handshake
18
        .set    RESULT_OK,0x00          ; server successfully executed cmd
19
                                        ; everything else means error
20
 
21
        .set    WAIT_DELAY,800000       ; count for delay loop
22
 
23
;***************************************************************
24
 
25
        .code
26
        .align  4
27
 
28
sctcapser:
29
        sub     $29,$29,16
30
        stw     $16,$29,0
31
        stw     $17,$29,4
32
        stw     $18,$29,8
33
        stw     $31,$29,12
34
        add     $4,$0,trymsg             ; say what we are doing
35
        jal     puts
36
        add     $18,$0,$0         ; capacity == 0 if disk not present
37
        add     $16,$0,10                ; 10 tries to get a connection
38
handshake1:
39
        sub     $16,$16,1
40
        add     $4,$0,SYN
41
        jal     ser1out                 ; send SYN
42
        add     $17,$0,WAIT_DELAY        ; wait for ACK
43
handshake2:
44
        sub     $17,$17,1
45
        jal     ser1inchk
46
        bne     $2,$0,handshake3
47
        bne     $17,$0,handshake2
48
        add     $4,$0,timeoutmsg
49
        jal     puts
50
        bne     $16,$0,handshake1
51
        add     $4,$0,frustratedmsg
52
        jal     puts
53
        j       sctcapx
54
handshake3:
55
        jal     ser1in
56
        add     $8,$0,ACK
57
        bne     $2,$8,sctcapx
58
        ; we got an ACK so we return it
59
        add     $4,$0,ACK
60
        jal     ser1out
61
 
62
        ; ask it for its capacity
63
        add     $4,$0,'c'
64
        jal     ser1out                 ; request
65
        jal     ser1in                  ; first byte of response
66
        bne     $2,$0,sctcapx            ; exit if error
67
 
68
        ; all is well and the server will give us the capacity
69
        add     $16,$0,4         ; 4 bytes to read
70
sctcap1:
71
        sll     $18,$18,8
72
        jal     ser1in
73
        or      $18,$18,$2              ; most significant byte first
74
        sub     $16,$16,1
75
        bne     $16,$0,sctcap1
76
 
77
        ; return value is in $18
78
sctcapx:
79
        add     $2,$0,$18
80
        ldw     $16,$29,0
81
        ldw     $17,$29,4
82
        ldw     $18,$29,8
83
        ldw     $31,$29,12
84
        add     $29,$29,16
85
        jr      $31
86
 
87
        .data
88
        .align  4
89
 
90
trymsg:
91
        .byte   "Trying to connect to disk server..."
92
        .byte   0x0A, 0
93
 
94
timeoutmsg:
95
        .byte   "Request timed out..."
96
        .byte   0x0A, 0
97
 
98
frustratedmsg:
99
        .byte   "Unable to establish connection to disk server."
100
        .byte   0x0A, 0
101
 
102
        .code
103
        .align  4
104
 
105
sctioser:
106
        sub     $29,$29,24
107
        stw     $16,$29,0
108
        stw     $17,$29,4
109
        stw     $18,$29,8
110
        stw     $19,$29,12
111
        stw     $20,$29,16
112
        stw     $31,$29,20
113
        add     $16,$0,$4                ; command
114
        add     $17,$0,$5                ; start at sector
115
        add     $8,$0,0xc0000000
116
        or      $18,$8,$6               ; memory address (logicalized)
117
        add     $19,$0,$7                ; number of sectors
118
 
119
        ; switch over command
120
        add     $8,$0,'r'
121
        beq     $8,$16,sctior           ; read
122
        add     $8,$0,'w'
123
        beq     $8,$16,sctiow           ; write
124
        ; unknown command
125
        add     $2,$0,1                  ; value != 0 signifies error
126
        j       sctiox
127
 
128
        ; read from disk
129
sctior:
130
sctior1:                                ; loop over number of sectors
131
        beq     $19,$0,sctiorsuc ; successful return
132
        sub     $19,$19,1
133
        ; read a sector
134
        add     $4,$0,'r'
135
        jal     ser1out
136
        ; send sector number
137
        add     $20,$0,32                ; 4 bytes
138
sctior2:
139
        sub     $20,$20,8
140
        slr     $4,$17,$20
141
        and     $4,$4,0xff
142
        jal     ser1out
143
        bne     $20,$0,sctior2
144
        add     $17,$17,1
145
        ; get answer
146
        jal     ser1in
147
        bne     $2,$0,sctiox             ; $2 != 0 so we use it as return code
148
        ; read data
149
        add     $20,$0,512
150
sctior3:
151
        sub     $20,$20,1
152
        jal     ser1in
153
        stb     $2,$18,0
154
        add     $18,$18,1
155
        bne     $20,$0,sctior3
156
        j       sctior1
157
sctiorsuc:
158
        add     $2,$0,$0
159
        j       sctiox
160
 
161
        ; write to disk
162
sctiow:
163
sctiow1:                                ; loop over number of sectors
164
        beq     $19,$0,sctiowsuc ; successful return
165
        sub     $19,$19,1
166
        ; write a sector
167
        add     $4,$0,'w'
168
        jal     ser1out
169
        ; send sector number
170
        add     $20,$0,32                ; 4 bytes
171
sctiow2:
172
        sub     $20,$20,8
173
        slr     $4,$17,$20
174
        and     $4,$4,0xff
175
        jal     ser1out
176
        bne     $20,$0,sctiow2
177
        add     $17,$17,1
178
        ; write data
179
        add     $20,$0,512
180
sctiow3:
181
        sub     $20,$20,1
182
        ldbu    $4,$18,0
183
        jal     ser1out
184
        add     $18,$18,1
185
        bne     $20,$0,sctiow3
186
        ; get answer
187
        jal     ser1in
188
        bne     $2,$0,sctiox
189
        j       sctiow1
190
sctiowsuc:
191
        add     $2,$0,$0
192
sctiox:
193
        ldw     $16,$29,0
194
        ldw     $17,$29,4
195
        ldw     $18,$29,8
196
        ldw     $19,$29,12
197
        ldw     $20,$29,16
198
        ldw     $31,$29,20
199
        add     $29,$29,24
200
        jr      $31

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.