]> cloudbase.mooo.com Git - avrcpm.git/blame - avr/dsk_mgr.asm
* New config option: SRAM_FILL
[avrcpm.git] / avr / dsk_mgr.asm
CommitLineData
92202636
L
1; Various Management functions for the Interaction with the File-
2; systems
3;
4; Copyright (C) 2010 Frank Zoll
5;
6; This file is part of avrcpm.
7;
8; avrcpm is free software: you can redistribute it and/or modify it
9; under the terms of the GNU General Public License as published by
10; the Free Software Foundation, either version 3 of the License, or
11; (at your option) any later version.
12;
13; avrcpm is distributed in the hope that it will be useful,
14; but WITHOUT ANY WARRANTY; without even the implied warranty of
15; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16; GNU General Public License for more details.
17;
18; You should have received a copy of the GNU General Public License
19; along with avrcpm. If not, see <http://www.gnu.org/licenses/>.
20;
21; $Id$
22;
23
24
637689de 25; -------------------------- Defines for the disk management Structures
92202636 26
637689de 27; Partition Table Structures
92202636 28
637689de
L
29#define PART_TYPE 4
30#define PART_START 8
31#define PART_SIZE 12
92202636 32
637689de
L
33/*
34 * Partition table id
35 * (see http://www.win.tue.nl/~aeb/partitions/partition_types-1.html)
36 */
37#define PARTID1_FAT16 0x0E
38#define PARTID2_FAT16 0x06
39#define PARTID_CPM 0x52
40
41
42; ------------------------------------------------ Start of Code Segment
92202636
L
43 .cseg
44
45; ====================================================================
46; Function: Scans a Disk for CP/M Partions
47; ====================================================================
48; Parameters
49; --------------------------------------------------------------------
50;
51; Registers : [w] temp Number of disk images (raw and fat16) found.
52; + 0x80 if sd card changes. (not used, doesn't work)
53; SREG : Z according to temp
54; --------------------------------------------------------------------
55; Description:
56; This Function scans an SD-Cards Boot-Sector for valid Partitions.
57; First all original CP/M Partitions will be usesed as Drives for
58; the CPM-System. Wenn all CP/M Partitions are found, a second
59; scann will be made. In the second Scan, the first FAT16 Partition
60; on the Disk will be used for a detailed analyses. If there
61; are any Files like "cpm_x.img" are found, these Files will be
62; used as Disks by the CP/M- System. ( x must be in the Range A to D )
63; ====================================================================
64mgr_init_partitions:
65
66 sts ndisks,_0 ; Set Number of Disks to 0
67
68; Initialize partition table
69 ldiw y,hostparttbl
70 ldi temp2,PARTENTRY_SIZE*MAXDISKS
71mgr_picl:
72 st y+,_0
73 dec temp2
74 brne mgr_picl
75
76; Start mmc Card interaction
77 lcall mmcInit
dc705dc0 78 andi temp,MMCST_NOINIT | MMCST_NODISK
92202636
L
79 brne mgr_pierr
80
81;Load first sector from MMC (boot sector)
82 ldiw y,0 ; Sector 0
83 movw x,y
02d57479 84 ldiw z,hostbuf
92202636
L
85 lcall mmcReadSect
86 tst temp
87 breq mgr_check_bootsektor
88
89mgr_pierr:
90 clr temp
91 ret
92
93mgr_check_bootsektor:
94;Pointer to first table entry
95 ldiw y,hostparttbl
96 ldi temp3,0 ;temp3 holds number of found disks (paritions)
97
98;Test, if it has a valid MBR
99
100 lds temp,hostbuf+510 ;MBR signature (0xAA55) at and of sector?
92202636 101 cpi temp,0x55
825ecc9d
L
102 lds temp,hostbuf+510+1
103 ldi temp2,0xAA
104 cpc temp,temp2
92202636
L
105 breq mgr_search
106
107;No MBR, no partition table ...
108
ce520bff
L
109#if CPMDSK_SUPPORT
110
92202636
L
111 inc temp3 ;pretend we have one.
112 sts ndisks,temp3
113 ldi temp,high((1<<16) * 128/512)
114 ldi temp2,dskType_CPM
115 std y+0,temp2
116 std y+1,_0 ;start at beginning of card
117 std y+2,_0
118 std y+3,_0
119 std y+4,_0
120 std y+5,_0 ;max CP/M 2.2 disk size
121 std y+6,temp ;
5482d75f
L
122
123 ldi temp3,0
124 rcall dpb_imgdata_get
125
ce520bff
L
126#endif /* CPMDSK_SUPPORT */
127
92202636
L
128 rjmp mgr_pend
129
92202636 130mgr_search:
ce520bff
L
131
132#if CPMDSK_SUPPORT
133
134; Search for valid Partitions and ImageFiles
92202636 135 ldiw z,hostbuf+510-64 ;Point to first byte of partition table
92202636
L
136
137mgr_ploop:
138
139; Get Partitiontype
140 ldd temp,z+PART_TYPE
141
142; Test for CP/M Partition
143 cpi temp,PARTID_CPM
144 brne mgr_nextp
145
5482d75f 146 rcall cpm_add_partition
92202636
L
147 inc temp3
148 sts ndisks,temp3
637689de 149 adiw y,PARTENTRY_SIZE
92202636
L
150 cpi temp3,MAXDISKS
151 breq mgr_pend
152
153mgr_nextp:
5482d75f 154 adiw z,16
825ecc9d 155 cpi zl,low(hostbuf+510) ;End of partition table reached?
92202636 156 brne mgr_ploop
ce520bff 157#endif /* CPMDSK_SUPPORT */
92202636
L
158
159#if FAT16_SUPPORT
160
161; Test for FAT16 Partition
162 ldiw z,hostbuf+510-64 ;Point to first byte of partition table
92202636
L
163
164mgr_ploop2:
165; Get Partitiontype
166 ldd temp,z+PART_TYPE
167
168; Test for FAT Partition Type 1
169 cpi temp,PARTID1_FAT16
170 breq mgr_fatfound
171
172; Test for FAT Partition Type 2
173 cpi temp,PARTID2_FAT16
174 brne mgr_nextp2
175
176mgr_fatfound:
177 rcall fat_add_partition
178 rcall fat_scan_partition
179 rcall fat_reset_cache
180 rjmp mgr_pend ;Stop after first FAT16 partition found.
181
182mgr_nextp2:
183 adiw zl,16
825ecc9d 184 cpi zl,low(hostbuf+510)
92202636 185 brne mgr_ploop2
ce520bff 186#endif /* FAT16_SUPPORT */
92202636
L
187
188mgr_pend:
5482d75f
L
189 clr temp3
190mgr_imgd_lp:
dcd7e502
L
191 lds temp,ndisks
192 cp temp3,temp
5482d75f
L
193 breq mgr_pend2
194 rcall dpb_imgdata_get
195 inc temp3
5482d75f
L
196 rjmp mgr_imgd_lp
197
198mgr_pend2:
199 lds temp,ndisks ;return # of "disks"
92202636
L
200 tst temp
201 ret
202
203
204; ====================================================================
205; Function: Print partition table info
206; ====================================================================
207; Parameters
208; --------------------------------------------------------------------
209; Registers : none
210; Variables : [r] hostparttbl Table with Partitioninformations
211; [r] hostparttbltop Pointer to the Top of the Table
212; --------------------------------------------------------------------
213; Description:
214; ====================================================================
215
216mgr_prnt_parttbl:
ce520bff
L
217 lds yl,ndisks
218 tst yl
219 brne ppr_doit
220 ret
221
222ppr_doit:
dc705dc0
L
223 push r15
224 push r14
92202636 225 ldiw z,hostparttbl
92202636 226 ldi xh,'A'
92202636 227pprl:
92202636
L
228 printnewline
229
825ecc9d
L
230 ldd temp ,z+1 ;Get partition start
231 ldd temp2,z+2
dc705dc0
L
232 ldd r14,z+3
233 ldd r15,z+4
234
ce520bff
L
235; Partitiontype examining
236
237 ldd xl,z+0
238 andi xl,dskType_MASK
239
240#if CPMDSK_SUPPORT
241
dc705dc0
L
242 cp temp,_0 ;If zero ...
243 cpc temp2,_0
244 cpc r14,_0
245 cpc r15,_0
ce520bff 246 brne mgr_prchkcpm ;... no partition table at 0
92202636 247
ce520bff
L
248 rcall mgr_prnt_diskname
249 rcall mgr_prnt_image
250 rjmp mgr_prnt_size
251
252mgr_prchkcpm:
92202636
L
253; CP/M ?
254 cpi xl,dskType_CPM
255 brne mgr_prtb_nocpm
256 rcall mgr_prnt_diskname
257 rcall mgr_prnt_table_cpm
258 rjmp mgr_prnt_size
92202636 259mgr_prtb_nocpm:
ce520bff
L
260#endif
261
92202636
L
262#if FAT16_SUPPORT
263; FAT16 ?
264 cpi xl,dskType_FAT
265 brne mgr_prtb_nofat
266 rcall mgr_prnt_diskname
267 rcall mgr_prnt_table_fat
268 rjmp mgr_prnt_size
269mgr_prtb_nofat:
270#endif
ce520bff 271
92202636 272#if 0 /* RAMDISK is not on SD card */
ce520bff 273#if RAMDISKCNT
92202636
L
274; RAMDISK ?
275 cpi xl,dskType_RAM
ce520bff 276 brne mgr_prnt_noramdisk
92202636
L
277 rcall mgr_prnt_diskname
278 rcall mgr_prnt_table_ram
279 rjmp mgr_prnt_size
ce520bff
L
280mgr_prnt_noramdisk:
281#endif
92202636 282#endif
ce520bff 283
92202636
L
284; Entry Error
285 rcall mgr_prnt_table_err
92202636
L
286
287mgr_prnt_size:
288 lcall print_ultoa
289 printstring ", size: "
290
291 ldd temp ,z+5 ;Get partition size
292 ldd temp2,z+6
825ecc9d
L
293 clr r14
294 clr r15
295 lsr temp2
92202636
L
296 ror temp
297 lcall print_ultoa
298 printstring "KB."
299
300mgr_goto_next_part:
301 adiw z,PARTENTRY_SIZE
302 inc xh
303 dec yl
304 brne pprl
305
306mgr_pppre:
dc705dc0
L
307 pop r14
308 pop r15
92202636
L
309 ret
310
311
92202636
L
312mgr_prnt_diskname:
313 push temp
314 mov temp,xh
315 lcall uartputc
96a054ef 316 printstring ": "
92202636
L
317 pop temp
318 ret
319
ce520bff 320#if CPMDSK_SUPPORT
92202636
L
321mgr_prnt_table_cpm:
322 printstring "CP/M partition at: "
323 ret
324
ce520bff
L
325mgr_prnt_image:
326 printstring "Assuming CP/M image at: "
327 ret
328#endif
329
330#if FAT16_SUPPORT
92202636 331mgr_prnt_table_fat:
96a054ef
L
332 printstring "FAT16 File-Image '"
333 push temp
334 mov temp,r14
335 lcall uartputc
336 clr r14
337 pop temp
338 printstring "' at: "
92202636 339 ret
ce520bff 340#endif
92202636 341
ce520bff 342#if RAMDISKCNT
92202636
L
343mgr_prnt_table_ram:
344 printstring "Ramdisk at: "
345 ret
ce520bff 346#endif
92202636
L
347
348mgr_prnt_table_err:
349 printstring "Unknown Entry at: "
350 ret
351
92202636 352