📄 mkfs.lst
字号:
ARM COMPILER V2.42, mkfs 27/03/06 10:45:51 PAGE 1
ARM COMPILER V2.42, COMPILATION OF MODULE mkfs
OBJECT MODULE PLACED IN .\obj\mkfs.obj
COMPILER INVOKED BY: C:\Keil\ARM\BIN\CA.exe src\mkfs.c THUMB DEBUG PRINT(.\LST\MKFS.LST) TABS(4) OBJECT(.\obj\mkfs.obj)
stmt level source
1 /*****************************************************************************\
2 * efs - General purpose Embedded Filesystem library *
3 * --------------------- ----------------------------------- *
4 * *
5 * Filename : mkfs.c *
6 * Description : These functions are used for creating an empty filesystem. *
7 * *
8 * This library is free software; you can redistribute it and/or *
9 * modify it under the terms of the GNU Lesser General Public *
10 * License as published by the Free Software Foundation; either *
11 * version 2.1 of the License, or (at your option) any later version. *
12 * *
13 * This library 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 GNU *
16 * Lesser General Public License for more details. *
17 * *
18 * (c)2005 Michael De Nil *
19 * (c)2005 Lennart Yseboodt *
20 \*****************************************************************************/
21
22 /*****************************************************************************/
23 #include "mkfs.h"
24 /*****************************************************************************/
25
26 signed short mkfs_makevfat(Partition *part)
27 {
28 1 unsigned long c,cc,ret;
29 1 unsigned long ns,fs,ds,dc;
30 1 unsigned char buf[512];
31 1
32 1 ns=part->disc->partitions[part->activePartition].numSectors;
33 1
34 1 if( ns < 66581 ){
35 2 DBG((TXT("This is not possible due to insufficient sectors. Sorry\n")));
36 2 return(MKFS_ERR_TOOLITTLESECTORS);
37 2 }
38 1
39 1 ret=0;
40 1
41 1 for(c=1<<6;c>=1;c>>=1){
42 2
43 2 /* First guess */
44 2 ds = ns - 32;
45 2 fs = ((ds/c)+127)/128;
46 2 /* ds was guess too large, so fs is too large now too. */
47 2
48 2 for(cc=0;cc<2;cc++){
49 3
50 3 /* Round 2, error round */
51 3 ds = ns - 32 - 2*fs;
52 3 fs = ((ds/c)+127)/128;
53 3 /* Since fs was too large, ds became too small. So the fs for this small ds is too small as well. */
54 3
55 3 /* Round 3, correction round */
56 3 ds = ns - 32 - 2*fs;
57 3 fs = ((ds/c)+127)/128;
58 3 /* The fs was too small, so ds was too large. The calculated fs should be slightly too large. */
59 3
ARM COMPILER V2.42, mkfs 27/03/06 10:45:51 PAGE 2
60 3 }
61 2
62 2 /* Round 4, finalise */
63 2 ds = ns - 32 - 2*fs;
64 2
65 2 dc = ds / c;
66 2 if(ret<(fs*128-dc)/128)ret=(fs*128-dc)/128;
67 2
68 2 /* Check if with current setting we have a valid fat ? */
69 2
70 2 if(dc >= 65525 + 16){
71 3 break;
72 3 }
73 2 }
74 1
75 1 /* Generate BPB */
76 1 memClr(buf,512);
77 1
78 1 /* Boot code */
79 1 *(buf+0)=0xE9; *(buf+1)=0x00; *(buf+2)=0x00; /* RESET */
80 1
81 1 /* OEM name */
82 1 memCpy("DSCOSMSH",buf+3,8);
83 1
84 1 /* Bytes/Sector */
85 1 *((unsigned short*)(buf+11)) = 512;
86 1
87 1 /* Sectors/Cluster */
88 1 *(buf+13) = c;
89 1
90 1 /* Reserved Sectors */
91 1 *((unsigned short*)(buf+14)) = 32;
92 1
93 1 /* Number of FAT Tables */
94 1 *(buf+16) = 2;
95 1
96 1 /* RootEntryCount */
97 1 *((unsigned short*)(buf+17)) = 0;
98 1
99 1 /* Total Sector Count __16 */
100 1 *((unsigned short*)(buf+19)) = 0;
101 1
102 1 /* Media (crap) */
103 1 *(buf+21) = 0xF8;
104 1
105 1 /* FAT size 16 */
106 1 *((unsigned short*)(buf+22)) = 0;
107 1
108 1 /* Total Sector Count __32 */
109 1 *((unsigned long*)(buf+32)) = ns;
110 1
111 1 /* Fat Size 32 */
112 1 *((unsigned long*)(buf+36)) = fs;
113 1
114 1 /* First Cluster Root Dir */
115 1 *((unsigned long*)(buf+44)) = 2;
116 1
117 1 /* VolumeID */
118 1 *((unsigned long*)(buf+67)) = 0x13371337;
119 1
120 1 /* Volume Label */
121 1 memCpy("DISCOSMASH!",buf+71,11);
122 1
123 1 /* Filesystemtype */
124 1 memCpy("FAT32 ",buf+82,8);
125 1
ARM COMPILER V2.42, mkfs 27/03/06 10:45:51 PAGE 3
126 1 /* Magic */
127 1 *(buf+510) = 0x55; *(buf+511) = 0xAA;
128 1
129 1 part_writeBuf(part,0,buf);
130 1
131 1 memClr(buf,512);
132 1 for(c=32;c<(32+2*fs);c++){
133 2 part_writeBuf(part,c,buf);
134 2 }
135 1 *(((unsigned long*)buf) )=0x0FFFFFF8;
136 1 *(((unsigned long*)buf)+1)=0x0FFFFFFF;
137 1 *(((unsigned long*)buf)+2)=0x0FFFFFF8;
138 1 part_writeBuf(part,32,buf);
139 1 part_writeBuf(part,32+fs,buf);
140 1
141 1 return(0);
142 1 }
ARM COMPILER V2.42, mkfs 27/03/06 10:45:51 PAGE 4
ASSEMBLY LISTING OF GENERATED OBJECT CODE
*** EXTERNALS:
EXTERN CODE16 (lpc2000_debug_printf?T)
EXTERN CODE16 (memCpy?T)
EXTERN CODE16 (memClr?T)
EXTERN CODE16 (part_writeBuf?T)
EXTERN CODE16 (?C?UDIV?T)
*** PUBLICS:
PUBLIC mkfs_makevfat?T
*** DATA SEGMENT '?CON?mkfs':
00000000 ??S_4:
00000000 DB 'FAT32 ',0x00
00000009 ??S_3:
00000009 DB 'DISCOSMASH!',0x00
00000015 ??S_2:
00000015 DB 'DSCOSMSH',0x00
0000001E ??S_1:
0000001E DB 'This is not possible due to insufficie'
00000044 DB 'nt sectors. Sorry',0x0A,0x00
*** CODE SEGMENT '?PR?mkfs_makevfat?T?mkfs':
26: signed short mkfs_makevfat(Partition *part)
00000000 B5F0 PUSH {R4-R7,LR}
00000002 1C05 MOV R5,R0 ; part
00000004 ---- Variable 'part' assigned to Register 'R5' ----
00000004 4800 LDR R0,=0xFFFFFDFC
00000006 4485 ADD R13,R13,R0
00000008 ---- Variable 'c' assigned to Register 'R4' ----
27: {
00000008 ; SCOPE-START
32: ns=part->disc->partitions[part->activePartition].numSectors;
00000008 1C28 MOV R0,R5 ; part
0000000A 7900 LDRB R0,[R0,#0x4]
0000000C 0600 LSL R0,R0,#0x18
0000000E 1600 ASR R0,R0,#0x18
00000010 1C01 MOV R1,R0
00000012 0109 LSL R1,R1,#0x4
00000014 1C28 MOV R0,R5 ; part
00000016 6800 LDR R0,[R0,#0x0] ; part
00000018 1840 ADD R0,R1
0000001A 6947 LDR R7,[R0,#0x14]
0000001C ---- Variable 'ns' assigned to Register 'R7' ----
34: if( ns < 66581 ){
0000001C 1C38 MOV R0,R7 ; ns
0000001E 4800 LDR R1,=0x10415
00000020 4288 CMP R0,R1 ; ns
00000022 D204 BCS L_1 ; T=0x0000002E
35: DBG((TXT("This is not possible due to insufficient sectors. Sorry\n")));
00000024 4800 LDR R0,=??S_1 ; ??S_1
00000026 F7FF BL lpc2000_debug_printf?T ; T=0x0001 (1)
00000028 FFEB BL lpc2000_debug_printf?T ; T=0x0001 (2)
36: return(MKFS_ERR_TOOLITTLESECTORS);
0000002A 2001 MOV R0,#0x1
0000002C E0C5 B L_2 ; T=0x000001BA
37: }
0000002E L_1:
39: ret=0;
0000002E 2000 MOV R0,#0x0
00000030 9000 STR R0,[R13,#0x0] ; ret
41: for(c=1<<6;c>=1;c>>=1){
00000032 2440 MOV R4,#0x40
00000034 L_6:
44: ds = ns - 32;
ARM COMPILER V2.42, mkfs 27/03/06 10:45:51 PAGE 5
00000034 1C3A MOV R2,R7 ; ns
00000036 3A20 SUB R2,#0x20
00000038 ---- Variable 'ds' assigned to Register 'R2' ----
45: fs = ((ds/c)+127)/128;
00000038 1C21 MOV R1,R4 ; c
0000003A 1C10 MOV R0,R2 ; ds
0000003C F7FF BL ?C?UDIV?T ; T=0x0001 (1) ; ?C?UDIV?T
0000003E FFE0 BL ?C?UDIV?T ; T=0x0001 (2) ; ?C?UDIV?T
00000040 1C08 MOV R0,R1
00000042 1C06 MOV R6,R0
00000044 367F ADD R6,#0x7F
00000046 09F6 LSR R6,R6,#0x7
00000048 ---- Variable 'fs' assigned to Register 'R6' ----
48: for(cc=0;cc<2;cc++){
00000048 2300 MOV R3,#0x0
0000004A ---- Variable 'cc' assigned to Register 'R3' ----
0000004A L_11:
51: ds = ns - 32 - 2*fs;
0000004A 1C30 MOV R0,R6 ; fs
0000004C 0040 LSL R0,R0,#0x1 ; fs
0000004E 1C3A MOV R2,R7 ; ns
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -