1 2 " MOV R1, R4\n" // pointer to MBR in R1 3 " BL mbr_read_dryos\n" // total sectors count in R0 before and after call 4 5 // Start of DataGhost's FAT32 autodetection code 6 // Policy: If there is a partition which has type W95 FAT32, use the first one of those for image storage 7 // According to the code below, we can use R1, R2, R3 and R12. 8 // LR wasn't really used anywhere but for storing a part of the partition signature. This is the only thing 9 // that won't work with an offset, but since we can load from LR+offset into LR, we can use this to do that :) 10 " MOV R12, R4\n" // Copy the MBR start address so we have something to work with 11 " MOV LR, R4\n" // Save old offset for MBR signature 12 " MOV R1, #1\n" // Note the current partition number 13 " B dg_sd_fat32_enter\n" // We actually need to check the first partition as well, no increments yet! 14 "dg_sd_fat32:\n" 15 " CMP R1, #4\n" // Did we already see the 4th partition? 16 " BEQ dg_sd_fat32_end\n" // Yes, break. We didn't find anything, so don't change anything. 17 " ADD R12, R12, #0x10\n" // Second partition 18 " ADD R1, R1, #1\n" // Second partition for the loop 19 "dg_sd_fat32_enter:\n" 20 " LDRB R2, [R12, #0x1BE]\n" // Partition status 21 " LDRB R3, [R12, #0x1C2]\n" // Partition type (FAT32 = 0xB) 22 " CMP R3, #0xB\n" // Is this a FAT32 partition? 23 " CMPNE R3, #0xC\n" // Not 0xB, is it 0xC (FAT32 LBA) then? 24 " BNE dg_sd_fat32\n" // No, it isn't. Loop again. 25 " CMP R2, #0x00\n" // It is, check the validity of the partition type 26 " CMPNE R2, #0x80\n" 27 " BNE dg_sd_fat32\n" // Invalid, go to next partition 28 // This partition is valid, it's the first one, bingo! 29 " MOV R4, R12\n" // Move the new MBR offset for the partition detection. 30 31 "dg_sd_fat32_end:\n" 32 // End of DataGhost's FAT32 autodetection code 33