]> cloudbase.mooo.com Git - avrcpm.git/blame - avrcpm/avr/dsk_mgr.asm
* Limit partition, resp. file image size to only 32MB. This frees up 2 bytes per...
[avrcpm.git] / avrcpm / 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
78 andi temp,MMCST_NOINIT & MMCST_NODISK
79 brne mgr_pierr
80
81;Load first sector from MMC (boot sector)
82 ldiw y,0 ; Sector 0
83 movw x,y
84 lcall mmcReadSect
85 tst temp
86 breq mgr_check_bootsektor
87
88mgr_pierr:
89 clr temp
90 ret
91
92mgr_check_bootsektor:
93;Pointer to first table entry
94 ldiw y,hostparttbl
95 ldi temp3,0 ;temp3 holds number of found disks (paritions)
96
97;Test, if it has a valid MBR
98
99 lds temp,hostbuf+510 ;MBR signature (0xAA55) at and of sector?
100 lds temp2,hostbuf+510+1
101 ldi temp4,0xAA
102 cpi temp,0x55
103 cpc temp2,temp4
104 breq mgr_search
105
106;No MBR, no partition table ...
107
108 inc temp3 ;pretend we have one.
109 sts ndisks,temp3
110 ldi temp,high((1<<16) * 128/512)
111 ldi temp2,dskType_CPM
112 std y+0,temp2
113 std y+1,_0 ;start at beginning of card
114 std y+2,_0
115 std y+3,_0
116 std y+4,_0
117 std y+5,_0 ;max CP/M 2.2 disk size
118 std y+6,temp ;
637689de
L
119; std y+7,_0
120; std y+8,_0
92202636
L
121 rjmp mgr_pend
122
123; Search for valid Partitions and ImageFiles
124mgr_search:
125 ldiw z,hostbuf+510-64 ;Point to first byte of partition table
126 ldi temp4,4 ;Partition table has 4 entries.
127
128mgr_ploop:
129
130; Get Partitiontype
131 ldd temp,z+PART_TYPE
132
133; Test for CP/M Partition
134 cpi temp,PARTID_CPM
135 brne mgr_nextp
136
137 rcall cpm_add_partition
138
139 inc temp3
140 sts ndisks,temp3
637689de 141 adiw y,PARTENTRY_SIZE
92202636
L
142 cpi temp3,MAXDISKS
143 breq mgr_pend
144
145mgr_nextp:
146 adiw zl,16
147 dec temp4
148 brne mgr_ploop
149
150#if FAT16_SUPPORT
151
152; Test for FAT16 Partition
153 ldiw z,hostbuf+510-64 ;Point to first byte of partition table
154 ldi temp4,4
155
156mgr_ploop2:
157; Get Partitiontype
158 ldd temp,z+PART_TYPE
159
160; Test for FAT Partition Type 1
161 cpi temp,PARTID1_FAT16
162 breq mgr_fatfound
163
164; Test for FAT Partition Type 2
165 cpi temp,PARTID2_FAT16
166 brne mgr_nextp2
167
168mgr_fatfound:
169 rcall fat_add_partition
170 rcall fat_scan_partition
171 rcall fat_reset_cache
172 rjmp mgr_pend ;Stop after first FAT16 partition found.
173
174mgr_nextp2:
175 adiw zl,16
176 dec temp4
177 brne mgr_ploop2
178#endif
179
180mgr_pend:
181 lds temp,ndisks ;return # of "disks"
182 tst temp
183 ret
184
185
186; ====================================================================
187; Function: Print partition table info
188; ====================================================================
189; Parameters
190; --------------------------------------------------------------------
191; Registers : none
192; Variables : [r] hostparttbl Table with Partitioninformations
193; [r] hostparttbltop Pointer to the Top of the Table
194; --------------------------------------------------------------------
195; Description:
196; ====================================================================
197
198mgr_prnt_parttbl:
199 ldiw z,hostparttbl
200 lds yl,ndisks
201 ldi xh,'A'
202
203pprl:
204 ldd temp ,z+1 ;Get partition start
205 ldd temp2,z+2
206 ldd temp3,z+3
207 ldd temp4,z+4
208
209 printnewline
210
211 cp temp,_0 ;If zero ...
212 cpc temp2,_0
213 cpc temp3,_0
214 cpc temp4,_0
215 breq mgr_prnop ;... no partition table at 0
216
217; Partitiontype examining
218 ldd xl,z+0
637689de 219 andi xl,dskType_MASK
92202636
L
220; CP/M ?
221 cpi xl,dskType_CPM
222 brne mgr_prtb_nocpm
223 rcall mgr_prnt_diskname
224 rcall mgr_prnt_table_cpm
225 rjmp mgr_prnt_size
226
227mgr_prtb_nocpm:
228#if FAT16_SUPPORT
229; FAT16 ?
230 cpi xl,dskType_FAT
231 brne mgr_prtb_nofat
232 rcall mgr_prnt_diskname
233 rcall mgr_prnt_table_fat
234 rjmp mgr_prnt_size
235mgr_prtb_nofat:
236#endif
237#if 0 /* RAMDISK is not on SD card */
238; RAMDISK ?
239 cpi xl,dskType_RAM
240 brne mgr_prnt_err
241 rcall mgr_prnt_diskname
242 rcall mgr_prnt_table_ram
243 rjmp mgr_prnt_size
244#endif
245mgr_prnt_err:
246; Entry Error
247 rcall mgr_prnt_table_err
248 rjmp mgr_prnt_size
249
250mgr_prnop:
251 rcall mgr_prnt_diskname
252 rcall mgr_prnt_image
253
254mgr_prnt_size:
255 lcall print_ultoa
256 printstring ", size: "
257
258 ldd temp ,z+5 ;Get partition size
259 ldd temp2,z+6
637689de
L
260 ldi temp3,0
261 ldi temp4,0
92202636
L
262
263 lsr temp4
264 ror temp3
265 ror temp2
266 ror temp
267 lcall print_ultoa
268 printstring "KB."
269
270mgr_goto_next_part:
271 adiw z,PARTENTRY_SIZE
272 inc xh
273 dec yl
274 brne pprl
275
276mgr_pppre:
277 ret
278
279
92202636
L
280mgr_prnt_diskname:
281 push temp
282 mov temp,xh
283 lcall uartputc
284 ldi temp,':'
285 lcall uartputc
286 pop temp
287 ret
288
289mgr_prnt_table_cpm:
290 printstring "CP/M partition at: "
291 ret
292
293mgr_prnt_table_fat:
294 printstring "FAT16 File-Image at: "
295 ret
296
297mgr_prnt_table_ram:
298 printstring "Ramdisk at: "
299 ret
300
301mgr_prnt_table_err:
302 printstring "Unknown Entry at: "
303 ret
304
305mgr_prnt_image:
306 printstring "Assuming CP/M image at: "
307 ret
308
309