ref: cd5cef000fc6decd40fc25d8a1760cf58884547c
parent: e3e57027803f617d43d0a2ca74279c58b402bf87
author: cinap_lenrek <cinap_lenrek@centraldogma>
date: Mon Jun 13 01:34:19 EDT 2011
pbs: dont rely on chainloader to hand us a partition table and properly get the partition offset from nhidden in the fat header, add compare after mul because MUL doesnt set ZF but makes it undefined!
--- a/sys/src/boot/pc/pbs.s
+++ b/sys/src/boot/pc/pbs.s
@@ -36,8 +36,10 @@
TEXT _bigvolsize(SB), $0
BYTE $0x00; BYTE $0x00; BYTE $0x00; BYTE $0x00;
/* FAT32 structure, starting @0x24 */
-TEXT _fatsz32(SB), $0
- BYTE $0x00; BYTE $0x00; BYTE $0x00; BYTE $0x00
+TEXT _fatsz32lo(SB), $0
+ BYTE $0x00; BYTE $0x00
+TEXT _fatsz32hi(SB), $0
+ BYTE $0x00; BYTE $0x00
TEXT _extflags(SB), $0
BYTE $0x00; BYTE $0x00
TEXT _fsver(SB), $0
@@ -76,7 +78,6 @@
MTSR(rAX, rES)
LWI(0x100, rCX)
- MW(rSI,rBX) /* address of partition record -> rBX */
LWI(RELOC, rSI)
MW(rSI, rSP)
LWI(_magic(SB), rDI)
@@ -83,7 +84,6 @@
CLD
REP; MOVSL /* MOV DS:[(E)SI] -> ES:[(E)DI] */
- PUSHA
MW(rSP, rBP)
PUSHR(rCX)
@@ -96,40 +96,42 @@
TEXT start16(SB), $0
STI
+
LWI(hello(SB), rSI)
CALL16(print16(SB))
- PUSHR(rDX)
- PUSHR(rBX)
+ PUSHR(rDX) /* drive */
- LB(_nfats(SB), rCL) /* # of fats */
- LW(_fatsize(SB), rAX) /* fat size */
- MUL(rCX) /* DX:AX = #sectors */
- JNE _fatszok /* zero? it's FAT32 */
+ CLR(rDX)
+ LW(_fatsize(SB), rAX)
+ CLR(rCX)
+ LB(_nfats(SB), rCL)
+ MUL(rCX)
+ OR(rCX, rCX)
+ JNE _fatszok /* zero? it's FAT32 */
- LW(_fatsz32+2(SB), rBX) /* hi word */
- IMUL(rCX, rBX) /* ... in sectors */
- LW(_fatsz32(SB), rAX) /* lo word */
- MUL(rCX) /* ... in sectors */
- ADD(rBX, rDX) /* DX:AX = #sectors */
+ LW(_fatsz32hi(SB), rBX)
+ IMUL(rCX, rBX)
+ LW(_fatsz32lo(SB), rAX)
+ MUL(rCX)
+ ADD(rBX, rDX)
_fatszok:
- POPR(rBX) /* address of partition record */
-
- LXW(8, xBX, rCX) /* lo partition LBA */
+ LW(_nhiddenlo(SB), rCX)
ADD(rCX, rAX)
- LXW(10, xBX, rCX) /* hi partition LBA */
+ LW(_nhiddenhi(SB), rCX)
ADC(rCX, rDX)
CLR(rBX)
- LW(_nresrv(SB), rCX) /* # of reserved */
+ LW(_nresrv(SB), rCX)
ADD(rCX, rAX)
ADC(rDX, rBX)
- SW(rAX, _volid(SB)) /* save for later use */
- SW(rDX, _volid+2(SB))
- POPR(rDX)
+ SW(rAX, _volid(SB)) /* save for later use */
+ SW(rBX, _volid+2(SB))
+ POPR(rDX) /* drive */
+
PUSHR(rBP)
LW(_sectsize(SB), rCX)
SUB(rCX, rSP)
@@ -164,7 +166,7 @@
JMP _nextsect
_found:
- PUSHR(rDX)
+ PUSHR(rDX) /* drive */
CLR(rBX)
@@ -208,7 +210,7 @@
MW(rAX, rCX)
POPR(rBX)
POPR(rAX)
- POPR(rDX)
+ POPR(rDX) /* drive */
LWI(RELOC, rSI)
PUSHR(rSI)