📄 bfsa_internal.lst
字号:
\ ??writeFatEntry_0:
\ 00000010 .... LDR R0,??DataTable17 ;; 0xfff7
275
276 if (cluster > BFSA_media.MaxCluster)
\ ??writeFatEntry_1:
\ 00000012 5B69 LDR R3,[R3, #+20]
\ 00000014 9342 CMP R3,R2
\ 00000016 28D3 BCC ??writeFatEntry_2
277 {
278 }
279 else
280 {
281 if (BFSA_media.FATtype == BFSA_FAT12)
\ 00000018 .... LDR R0,??DataTable15 ;; BFSABuffer
\ 0000001A 8023 MOV R3,#+128
\ 0000001C DB00 LSL R3,R3,#+3 ;; #+1024
\ 0000001E 002C CMP R4,#+0
\ 00000020 1ED1 BNE ??writeFatEntry_3
282 {
283 USHORT valueForFATBuff;
284
285 // Divide the cluster number by 2, resulting in an integer quotient
286 // Add the same cluster number to this quotient, producing the offset of the cluster's entry in the FAT.
287 fatOffset = cluster + (cluster / 2);
\ 00000022 5408 LSR R4,R2,#+1
\ 00000024 1419 ADD R4,R2,R4
\ 00000026 2404 LSL R4,R4,#+16
\ 00000028 240C LSR R4,R4,#+16
288
289 // Pb with FAT > buffer of FAT
290 /* if( fatOffset > sizeofBFSA_fatBuff )
291 {
292 // Read next of FAT
293 po_memcpy( BFSA_fatBuff,
294 (void*)(BFSA_media.FATSectStart*BFSA_media.bytesPerSector + (ULONG)FlashBaseAdd+sizeofBFSA_fatBuff ),
295 sizeofBFSA_fatBuff );
296 fatOffset -= sizeofBFSA_fatBuff;
297 }
298 */
299 if( fatOffset < sizeofBFSA_fatBuff )
\ 0000002A 9C42 CMP R4,R3
\ 0000002C 1CD2 BCS ??writeFatEntry_4
300 {
301 // Cluster is ODD or EVEN ?
302 if (cluster & 0x0001)
\ 0000002E 0019 ADD R0,R0,R4
\ 00000030 0378 LDRB R3,[R0, #+0]
\ 00000032 D207 LSL R2,R2,#+31
\ 00000034 03D5 BPL ??writeFatEntry_5
303 {
304 valueForFATBuff = BFSABuffer.BFSA_fatBuff[fatOffset] + BFSABuffer.BFSA_fatBuff[fatOffset+1]*0x100;
305 valueForFATBuff &= 0x000F;
\ 00000036 1A07 LSL R2,R3,#+28
\ 00000038 120F LSR R2,R2,#+28
306 value = value << 4;
\ 0000003A 0901 LSL R1,R1,#+4
\ 0000003C 07E0 B ??writeFatEntry_6
307 }
308 else
309 {
310 valueForFATBuff = BFSABuffer.BFSA_fatBuff[fatOffset] + BFSABuffer.BFSA_fatBuff[fatOffset+1]*0x100;
311 valueForFATBuff &= 0xF000;
\ ??writeFatEntry_5:
\ 0000003E 4278 LDRB R2,[R0, #+1]
\ 00000040 1202 LSL R2,R2,#+8
\ 00000042 9B18 ADD R3,R3,R2
\ 00000044 F022 MOV R2,#+240
\ 00000046 1202 LSL R2,R2,#+8 ;; #+61440
\ 00000048 1A40 AND R2,R3
312 value = value & 0x0FFF;
\ 0000004A 0905 LSL R1,R1,#+20
\ 0000004C 090D LSR R1,R1,#+20
313 }
314
315 BFSABuffer.BFSA_fatBuff[fatOffset] = (value&0x000000FF) | (valueForFATBuff&0x000000FF);
\ ??writeFatEntry_6:
\ 0000004E 141C MOV R4,R2
\ 00000050 0C43 ORR R4,R1
\ 00000052 0470 STRB R4,[R0, #+0]
316 BFSABuffer.BFSA_fatBuff[fatOffset+1] =(char)((value&0x0000FF00)>>8) |((valueForFATBuff&0x0000FF00)>>8);
\ 00000054 0904 LSL R1,R1,#+16
\ 00000056 090E LSR R1,R1,#+24
\ 00000058 120A LSR R2,R2,#+8
\ 0000005A 0A43 ORR R2,R1
\ 0000005C 4270 STRB R2,[R0, #+1]
\ 0000005E 03E0 B ??writeFatEntry_4
317 }
318 }
319 else
320 {
321 if( (cluster*2) < sizeofBFSA_fatBuff )
\ ??writeFatEntry_3:
\ 00000060 5200 LSL R2,R2,#+1
\ 00000062 9A42 CMP R2,R3
\ 00000064 00DA BGE ??writeFatEntry_4
322 {
323 // In a 16-bit FAT, cluster n is represented by the entry at offset n * 2 in the table.
324 *((USHORT*) &BFSABuffer.BFSA_fatBuff[cluster*2]) = value;
\ 00000066 8152 STRH R1,[R0, R2]
325 }
326 }
327 status = BFSA_SUCCESS;
\ ??writeFatEntry_4:
\ 00000068 0020 MOV R0,#+0
328 }
329
330 return( status );
\ ??writeFatEntry_2:
\ 0000006A 10BC POP {R4}
\ 0000006C 02BC POP {R1}
\ 0000006E 0847 BX R1 ;; return
331
332 }
333
334 /*****************************************************************
335 *
336 *
337 * S U B - R O U T I N E : findFreeCluster
338 *
339 *-----------------------------------------------------------------
340 *
341 * int findFreeCluster(void)
342 *
343 * Object :
344 * This function returns the next free cluster from the FAT ,
345 * marks it EOF (0x0FF8 or 0xFFFF8) and fill it with 0.
346 *
347 * Argument:
348 * none.
349 *
350 * Return value :
351 * free cluster if any,
352 * 0 if there is no more free cluster
353 *
354 *****************************************************************/
\ In segment CODE, align 4, keep-with-next
355 USHORT findFreeCluster(void)
356 {
\ findFreeCluster:
\ 00000000 F3B5 PUSH {R0,R1,R4-R7,LR}
357 USHORT _currentCluster;
358 USHORT _freeCluster = 0;
\ 00000002 0024 MOV R4,#+0
359 USHORT _numberFatEntries;
360 UCHAR *_pucCluster = NULL;
361
362 // Compute the number of FAT entries = Number of clusters
363 _numberFatEntries = (BFSA_media.MaxCluster - BFSA_media.ClusterStart);
\ 00000004 .... LDR R5,??DataTable22 ;; BFSA_media
\ 00000006 6869 LDR R0,[R5, #+20]
\ 00000008 298A LDRH R1,[R5, #+16]
\ 0000000A 401A SUB R0,R0,R1
\ 0000000C 0004 LSL R0,R0,#+16
\ 0000000E 000C LSR R0,R0,#+16
\ 00000010 0090 STR R0,[SP, #+0]
364
365 // Find a free cluster in FAT
366 for (_currentCluster = 2; // the 2 first clusters are reserved
\ 00000012 0226 MOV R6,#+2
\ 00000014 06E0 B ??findFreeCluster_0
367 _currentCluster < _numberFatEntries + 2;
368 _currentCluster++)
369 {
370 if (readFatEntry(_currentCluster) == FREE)
371 {
372 unsigned int value;
373 value = 0;
374
375 _freeCluster = _currentCluster;
376
377 // Mark it EOC (0x0FF8 for FAT12 0xFFF8 for FAT16)
378 if( BFSA_SUCCESS != writeFatEntry(_freeCluster,BFSA_media.FATtype == BFSA_FAT12?EOC12:EOC16) )
379 {
380 // Problem
381 _freeCluster = 0;
382 break;
383 }
384 // Fill it by 0
385 _pucCluster = (UCHAR*) (FIRST_SECTOR_DATACLUSTER(_currentCluster) * BFSA_media.bytesPerSector);
386 if (!AT91F_Flash_Write_Address((unsigned int)FlashBaseAdd + (unsigned int)_pucCluster, // Add
387 BFSA_media.bytesPerSector*BFSA_media.SectPerCluster, // Size
388 (unsigned char*) &value, // data
389 TRUE)) // MemSet
390 {
391 // write fail, mark the cluster as bad cluster in fat
392 writeFatEntry(_freeCluster,BFSA_media.FATtype == BFSA_FAT12?BAD12:BAD16);
\ ??findFreeCluster_1:
\ 00000016 .... LDR R1,??DataTable17 ;; 0xfff7
\ ??findFreeCluster_2:
\ 00000018 2004 LSL R0,R4,#+16
\ 0000001A 000C LSR R0,R0,#+16
\ 0000001C ........ BL writeFatEntry
393 TRACE_DEBUG_L( "Bad cluster:%d\n\r",_currentCluster);
394 _freeCluster = 0;
\ 00000020 0024 MOV R4,#+0
\ ??findFreeCluster_3:
\ 00000022 761C ADD R6,R6,#+1
\ ??findFreeCluster_0:
\ 00000024 0098 LDR R0,[SP, #+0]
\ 00000026 0004 LSL R0,R0,#+16
\ 00000028 000C LSR R0,R0,#+16
\ 0000002A 801C ADD R0,R0,#+2
\ 0000002C 8642 CMP R6,R0
\ 0000002E 14DA BGE ??findFreeCluster_4
\ 00000030 3004 LSL R0,R6,#+16
\ 00000032 000C LSR R0,R0,#+16
\ 00000034 ........ BL readFatEntry
\ 00000038 0028 CMP R0,#+0
\ 0000003A F2D1 BNE ??findFreeCluster_3
\ 0000003C 0194 STR R4,[SP, #+4]
\ 0000003E 341C MOV R4,R6
\ 00000040 2878 LDRB R0,[R5, #+0]
\ 00000042 0028 CMP R0,#+0
\ 00000044 01D1 BNE ??findFreeCluster_5
\ 00000046 .... LDR R1,??DataTable25 ;; 0xfff
\ 00000048 00E0 B ??findFreeCluster_6
\ ??findFreeCluster_5:
\ 0000004A .... LDR R1,??DataTable24 ;; 0xffff
\ ??findFreeCluster_6:
\ 0000004C 2004 LSL R0,R4,#+16
\ 0000004E 000C LSR R0,R0,#+16
\ 00000050 ........ BL writeFatEntry
\ 00000054 0028 CMP R0,#+0
\ 00000056 05D0 BEQ ??findFreeCluster_7
\ 00000058 0024 MOV R4,#+0
395 }
396 else
397 {
398 // Cluster found and initialized
399 break;
400 }
401 }
402 }
403
404 return _freeCluster;
\ ??findFreeCluster_4:
\ 0000005A 2004 LSL R0,R4,#+16
\ 0000005C 000C LSR R0,R0,#+16
\ 0000005E FCBC POP {R2-R7}
\ 00000060 02BC POP {R1}
\ 00000062 0847 BX R1 ;; return
\ ??findFreeCluster_7:
\ 00000064 2879 LDRB R0,[R5, #+4]
\ 00000066 6F88 LDRH R7,[R5, #+2]
\ 00000068 0123 MOV R3,#+1
\ 0000006A 01AA ADD R2,SP,#+4
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -