瀏覽代碼

Miscellaneous efficiency improvements, and extend read_sectors to

handle multiple sectors.
tags/v0.9.3
Michael Brown 17 年之前
父節點
當前提交
839960276d
共有 1 個檔案被更改,包括 63 行新增45 行删除
  1. 63
    45
      src/arch/i386/prefix/bootpart.S

+ 63
- 45
src/arch/i386/prefix/bootpart.S 查看文件

@@ -20,6 +20,7 @@ find_active_partition:
20 20
 	movw	$STACK_SEG, %ax
21 21
 	movw	%ax, %ss
22 22
 	movw	$STACK_SIZE, %sp
23
+
23 24
 	/* Relocate self to EXEC_SEG */
24 25
 	pushw	$BOOT_SEG
25 26
 	popw	%ds
@@ -34,12 +35,24 @@ find_active_partition:
34 35
 	popw	%es
35 36
 	pushw	%cs
36 37
 	popw	%ds
38
+
39
+	/* Check for LBA extensions */
40
+	movb	$0x41, %ah
41
+	movw	$0x55aa, %bx
42
+	stc
43
+	int	$0x13
44
+	jc	1f
45
+	cmpw	$0xaa55, %bx
46
+	jne	1f
47
+	movw	$read_lba, read_sector
48
+1:	
37 49
 	/* Read and process root partition table */
38 50
 	xorb	%dh, %dh
39 51
 	movw	$0x0001, %cx
40 52
 	xorl	%esi, %esi
41 53
 	xorl	%edi, %edi
42 54
 	call	process_table
55
+
43 56
 	/* Print failure message */
44 57
 	movw	$10f, %si
45 58
 	movw	$(20f-10f), %cx
@@ -48,6 +61,7 @@ find_active_partition:
48 61
 	lodsb
49 62
 	int	$0x10
50 63
 	loop	1b
64
+
51 65
 	/* Boot next device */
52 66
 	int	$0x18
53 67
 10:	.ascii	"Could not locate active partition\r\n"
@@ -69,10 +83,10 @@ find_active_partition:
69 83
  */
70 84
 process_table:
71 85
 	pushal
72
-	movw	$446, %bx
73
-1:	call	read_sector
86
+	call	read_boot_sector
74 87
 	jc	99f
75
-	call	process_partition
88
+	movw	$446, %bx
89
+1:	call	process_partition
76 90
 	addw	$16, %bx
77 91
 	cmpw	$510, %bx
78 92
 	jne	1b
@@ -102,7 +116,7 @@ process_partition:
102 116
 	/* Check active flag */
103 117
 	testb	$0x80, %es:(%bx)
104 118
 	jz	1f
105
-	call	read_sector
119
+	call	read_boot_sector
106 120
 	jc	99f
107 121
 	jmp	*%bp
108 122
 1:	/* Check for extended partition */
@@ -115,10 +129,12 @@ process_partition:
115 129
 	jne	99f
116 130
 2:	call	process_table
117 131
 99:	popal
132
+	/* Reload original partition table */
133
+	call	read_boot_sector
118 134
 	ret
119 135
 
120 136
 /*
121
- * Read single sector to 0000:7c00 and verify 0x55aa signature
137
+ * Read single sector to %es:0000 and verify 0x55aa signature
122 138
  *
123 139
  * Parameters:
124 140
  *   %dl	: BIOS drive number
@@ -130,32 +146,56 @@ process_partition:
130 146
  * Returns:
131 147
  *   CF set on error
132 148
  */
133
-read_sector:
134
-	pushal
135
-	/* Check for LBA extensions */
136
-	call	check_lba
137
-	jnc	read_lba
149
+read_boot_sector:
150
+	pushw	%ax
151
+	movw	$1, %ax
152
+	call	*read_sector
153
+	jc	99f
154
+	cmpw	$0xaa55, %es:(510)
155
+	je	99f
156
+	stc	
157
+99:	popw	%ax
158
+	ret
159
+	
160
+/*
161
+ * Read single sector to %es:0000 and verify 0x55aa signature
162
+ *
163
+ * Parameters:
164
+ *   %dl	: BIOS drive number
165
+ *   %dh	: Head
166
+ *   %cl	: Sector (bits 0-5), high two bits of cylinder (bits 6-7)
167
+ *   %ch	: Low eight bits of cylinder
168
+ *   %esi:%edi	: LBA address
169
+ *   %ax	: Number of sectors (max 127)
170
+ *
171
+ * Returns:
172
+ *   CF set on error
173
+ */
174
+read_sector:	.word	read_chs
175
+
138 176
 read_chs:
139
-	/* Read sector using C/H/S address */
140
-	movw	$0x0201, %ax
177
+	/* Read sectors using C/H/S address */
178
+	pushal
141 179
 	xorw	%bx, %bx
180
+	movb	$0x02, %ah
142 181
 	stc
143 182
 	int	$0x13
144 183
 	sti
145
-	jmp	99f
184
+	popal
185
+	ret
186
+
146 187
 read_lba:
147
-	/* Read sector using LBA address */
148
-	movb	$0x42, %ah
149
-	movl	%esi, (lba_desc + 12)
188
+	/* Read sectors using LBA address */
189
+	pushal
190
+	movw	%ax, (lba_desc + 2)
191
+	pushw	%es
192
+	popw	(lba_desc + 6)
150 193
 	movl	%edi, (lba_desc + 8)
194
+	movl	%esi, (lba_desc + 12)
151 195
 	movw	$lba_desc, %si
196
+	movb	$0x42, %ah
152 197
 	int	$0x13
153
-99:	/* Check for 55aa signature */
154
-	jc	99f
155
-	cmpw	$0xaa55, %es:(510)
156
-	je	99f
157
-	stc
158
-99:	popal
198
+	popal
159 199
 	ret
160 200
 
161 201
 lba_desc:
@@ -163,27 +203,5 @@ lba_desc:
163 203
 	.byte	0
164 204
 	.word	1
165 205
 	.word	0x0000
166
-	.word	0x07c0
206
+	.word	0x0000
167 207
 	.long	0, 0
168
-
169
-/*
170
- * Check for LBA extensions
171
- *	
172
- * Parameters:
173
- *   %dl	: BIOS drive number
174
- *
175
- * Returns:
176
- *   CF clear if LBA extensions supported
177
- */
178
-check_lba:
179
-	pushal
180
-	movb	$0x41, %ah
181
-	movw	$0x55aa, %bx
182
-	stc
183
-	int	$0x13
184
-	jc	99f
185
-	cmpw	$0xaa55, %bx
186
-	je	99f
187
-	stc
188
-99:	popal
189
-	ret

Loading…
取消
儲存