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

Subversion Repositories eco32

[/] [eco32/] [trunk/] [monitor/] [monitor/] [common/] [dskser.s] - Blame information for rev 241

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

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

powered by: WebSVN 2.1.0

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