Browse Source

Miscellaneous efficiency improvements, and extend read_sectors to

handle multiple sectors.
tags/v0.9.3
Michael Brown 17 years ago
parent
commit
839960276d
1 changed files with 63 additions and 45 deletions
  1. 63
    45
      src/arch/i386/prefix/bootpart.S

+ 63
- 45
src/arch/i386/prefix/bootpart.S View File

20
 	movw	$STACK_SEG, %ax
20
 	movw	$STACK_SEG, %ax
21
 	movw	%ax, %ss
21
 	movw	%ax, %ss
22
 	movw	$STACK_SIZE, %sp
22
 	movw	$STACK_SIZE, %sp
23
+
23
 	/* Relocate self to EXEC_SEG */
24
 	/* Relocate self to EXEC_SEG */
24
 	pushw	$BOOT_SEG
25
 	pushw	$BOOT_SEG
25
 	popw	%ds
26
 	popw	%ds
34
 	popw	%es
35
 	popw	%es
35
 	pushw	%cs
36
 	pushw	%cs
36
 	popw	%ds
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
 	/* Read and process root partition table */
49
 	/* Read and process root partition table */
38
 	xorb	%dh, %dh
50
 	xorb	%dh, %dh
39
 	movw	$0x0001, %cx
51
 	movw	$0x0001, %cx
40
 	xorl	%esi, %esi
52
 	xorl	%esi, %esi
41
 	xorl	%edi, %edi
53
 	xorl	%edi, %edi
42
 	call	process_table
54
 	call	process_table
55
+
43
 	/* Print failure message */
56
 	/* Print failure message */
44
 	movw	$10f, %si
57
 	movw	$10f, %si
45
 	movw	$(20f-10f), %cx
58
 	movw	$(20f-10f), %cx
48
 	lodsb
61
 	lodsb
49
 	int	$0x10
62
 	int	$0x10
50
 	loop	1b
63
 	loop	1b
64
+
51
 	/* Boot next device */
65
 	/* Boot next device */
52
 	int	$0x18
66
 	int	$0x18
53
 10:	.ascii	"Could not locate active partition\r\n"
67
 10:	.ascii	"Could not locate active partition\r\n"
69
  */
83
  */
70
 process_table:
84
 process_table:
71
 	pushal
85
 	pushal
72
-	movw	$446, %bx
73
-1:	call	read_sector
86
+	call	read_boot_sector
74
 	jc	99f
87
 	jc	99f
75
-	call	process_partition
88
+	movw	$446, %bx
89
+1:	call	process_partition
76
 	addw	$16, %bx
90
 	addw	$16, %bx
77
 	cmpw	$510, %bx
91
 	cmpw	$510, %bx
78
 	jne	1b
92
 	jne	1b
102
 	/* Check active flag */
116
 	/* Check active flag */
103
 	testb	$0x80, %es:(%bx)
117
 	testb	$0x80, %es:(%bx)
104
 	jz	1f
118
 	jz	1f
105
-	call	read_sector
119
+	call	read_boot_sector
106
 	jc	99f
120
 	jc	99f
107
 	jmp	*%bp
121
 	jmp	*%bp
108
 1:	/* Check for extended partition */
122
 1:	/* Check for extended partition */
115
 	jne	99f
129
 	jne	99f
116
 2:	call	process_table
130
 2:	call	process_table
117
 99:	popal
131
 99:	popal
132
+	/* Reload original partition table */
133
+	call	read_boot_sector
118
 	ret
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
  * Parameters:
139
  * Parameters:
124
  *   %dl	: BIOS drive number
140
  *   %dl	: BIOS drive number
130
  * Returns:
146
  * Returns:
131
  *   CF set on error
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
 read_chs:
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
 	xorw	%bx, %bx
179
 	xorw	%bx, %bx
180
+	movb	$0x02, %ah
142
 	stc
181
 	stc
143
 	int	$0x13
182
 	int	$0x13
144
 	sti
183
 	sti
145
-	jmp	99f
184
+	popal
185
+	ret
186
+
146
 read_lba:
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
 	movl	%edi, (lba_desc + 8)
193
 	movl	%edi, (lba_desc + 8)
194
+	movl	%esi, (lba_desc + 12)
151
 	movw	$lba_desc, %si
195
 	movw	$lba_desc, %si
196
+	movb	$0x42, %ah
152
 	int	$0x13
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
 	ret
199
 	ret
160
 
200
 
161
 lba_desc:
201
 lba_desc:
163
 	.byte	0
203
 	.byte	0
164
 	.word	1
204
 	.word	1
165
 	.word	0x0000
205
 	.word	0x0000
166
-	.word	0x07c0
206
+	.word	0x0000
167
 	.long	0, 0
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…
Cancel
Save