Browse Source

[bios] Define macros for constructing partition table entries

Signed-off-by: Michael Brown <mcb30@ipxe.org>
master
Michael Brown 4 years ago
parent
commit
49319f1bc9
1 changed files with 37 additions and 10 deletions
  1. 37
    10
      src/arch/x86/prefix/usbdisk.S

+ 37
- 10
src/arch/x86/prefix/usbdisk.S View File

@@ -9,26 +9,53 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
9 9
 #include "mbr.S"
10 10
 
11 11
 /* Partition table: 64 heads, 32 sectors/track (ZIP-drive compatible) */
12
+#define HEADS 64
13
+#define SECTORS 32
14
+#define CYLADDR(cyl) ((((cyl) * HEADS + (((cyl) == 0) & 1)) * SECTORS) * 512)
15
+
16
+#define LOGSTART 0
17
+#define LOGCOUNT 1
18
+#define BOOTSTART 1
19
+#define BOOTCOUNT 2
20
+
21
+	/* Construct a C/H/S address */
22
+	.macro	chs cylinder, head, sector
23
+	.byte	\head
24
+	.byte	(((\cylinder & 0x300) >> 2) | \sector)
25
+	.byte	(\cylinder & 0x0ff)
26
+	.endm
27
+
28
+	/* Construct a linear address */
29
+	.macro	linear cylinders, heads, sectors
30
+	.long	((((\cylinders * HEADS) + \heads) * SECTORS) + \sectors - 1)
31
+	.endm
32
+
33
+	/* Construct a partition table entry */
34
+	.macro	partition bootflag, type, start, count
35
+	.byte	\bootflag
36
+	chs	\start, ((\start == 0) & 1), 1
37
+	.byte	\type
38
+	chs	(\start + \count - 1), (HEADS - 1), SECTORS
39
+	linear	\start, ((\start == 0) & 1), 1
40
+	linear	\count, 0, (1 - (((\start == 0) & 1) * SECTORS))
41
+	.endm
42
+
43
+	/* Partition table */
12 44
 	.org 446
13 45
 	.space 16
14 46
 	.space 16
15 47
 	/* Partition 3: log partition (for CONSOLE_INT13) */
16
-	.byte 0x00, 0x01, 0x01, 0x00
17
-	.byte 0xe0, 0x3f, 0x20, 0x00
18
-	.long 0x00000020
19
-	.long 0x000007e0
48
+	partition 0x00, 0xe0, LOGSTART, LOGCOUNT
20 49
 	/* Partition 4: boot partition */
21
-	.byte 0x80, 0x00, 0x01, 0x01
22
-	.byte 0xeb, 0x3f, 0x20, 0x02
23
-	.long 0x00000800
24
-	.long 0x00001000
50
+	partition 0x80, 0xeb, BOOTSTART, BOOTCOUNT
25 51
 
52
+	/* Disk signature */
26 53
 	.org 510
27 54
 	.byte 0x55, 0xaa
28 55
 
29 56
 /* Skip to start of log partition */
30
-	.org 32 * 512
57
+	.org CYLADDR(LOGSTART)
31 58
 	.ascii "iPXE LOG\n\n"
32 59
 
33 60
 /* Skip to start of boot partition */
34
-	.org 2048 * 512
61
+	.org CYLADDR(BOOTSTART)

Loading…
Cancel
Save