Skip to contentSkip to conversation

Make boot/i386/pc/boot.S safer to modify

PATCH In review Pavel Roskin 3 participants 15 messages Jul 15, 2009 – Jul 16, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/7 Make boot/i386/pc/boot.S safer to modify

ChangeLog:

* include/grub/i386/pc/boot.h: Sort all offsets. (GRUB_BOOT_MACHINE_KERNEL_ADDRESS): Remove, it's unused. (GRUB_BOOT_MACHINE_KERNEL_SEGMENT): Likewise.
* boot/i386/pc/boot.S: Assert location of every offset listed in include/grub/i386/pc/boot.h.

---
 boot/i386/pc/boot.S         |    8 +++++++-
 include/grub/i386/pc/boot.h |   10 ++--------
 2 files changed, 9 insertions(+), 9 deletions(-)
boot/i386/pc/boot.S +7 -1
index 8d8c27c..fb90947 100644
@@ -65,6 +65,7 @@ start:
 	 * this area.
 	 */
 
+	. = _start + GRUB_BOOT_MACHINE_BPB_START
 	. = _start + 4
 
 	/* scratch space */
@@ -91,14 +92,19 @@ cylinder_start:
 	 * End of BIOS parameter block.
 	 */
 
+	. = _start + GRUB_BOOT_MACHINE_VER_MAJ
 boot_version:
 	.byte	GRUB_BOOT_VERSION_MAJOR, GRUB_BOOT_VERSION_MINOR
 kernel_address:
 	.word	GRUB_BOOT_MACHINE_KERNEL_ADDR
 kernel_segment:
 	.word	GRUB_BOOT_MACHINE_KERNEL_SEG
+
+	. = _start + GRUB_BOOT_MACHINE_KERNEL_SECTOR
 kernel_sector:
 	.long	1, 0
+
+	. = _start + GRUB_BOOT_MACHINE_BOOT_DRIVE
 boot_drive:
 	.byte 0xff	/* the disk to load kernel from */
 			/* 0xff means use the boot drive */
@@ -477,8 +483,8 @@ nt_magic:
 	 *  sneaky, huh?
 	 */
 
-part_start:
 	. = _start + GRUB_BOOT_MACHINE_PART_START
+part_start:
 
 probe_values:
 	.byte	36, 18, 15, 9, 0
include/grub/i386/pc/boot.h +2 -8
index f35cb3a..221ed38 100644
@@ -31,17 +31,11 @@
 /* The offset of the major version.  */
 #define GRUB_BOOT_MACHINE_VER_MAJ	0x3e
 
-/* The offset of BOOT_DRIVE.  */
-#define GRUB_BOOT_MACHINE_BOOT_DRIVE	0x4c
-
-/* The offset of KERNEL_ADDRESS.  */
-#define GRUB_BOOT_MACHINE_KERNEL_ADDRESS	0x40
-
 /* The offset of KERNEL_SECTOR.  */
 #define GRUB_BOOT_MACHINE_KERNEL_SECTOR	0x44
 
-/* The offset of KERNEL_SEGMENT.  */
-#define GRUB_BOOT_MACHINE_KERNEL_SEGMENT	0x42
+/* The offset of BOOT_DRIVE.  */
+#define GRUB_BOOT_MACHINE_BOOT_DRIVE	0x4c
 
 /* The offset of BOOT_DRIVE_CHECK.  */
 #define GRUB_BOOT_MACHINE_DRIVE_CHECK	0x4e
#1 lore raw

PATCH 2/7 Remove unused version information from boot/i386/pc/boot.S

ChangeLog:

* boot/i386/pc/boot.S (boot_version): Remove.
* include/grub/i386/pc/boot.h (GRUB_BOOT_MACHINE_VER_MAJ):
Remove.

---
 boot/i386/pc/boot.S         |    3 ---
 include/grub/i386/pc/boot.h |    3 ---
 2 files changed, 0 insertions(+), 6 deletions(-)
boot/i386/pc/boot.S +0 -3
index fb90947..e5685dc 100644
@@ -92,9 +92,6 @@ cylinder_start:
 	 * End of BIOS parameter block.
 	 */
 
-	. = _start + GRUB_BOOT_MACHINE_VER_MAJ
-boot_version:
-	.byte	GRUB_BOOT_VERSION_MAJOR, GRUB_BOOT_VERSION_MINOR
 kernel_address:
 	.word	GRUB_BOOT_MACHINE_KERNEL_ADDR
 kernel_segment:
include/grub/i386/pc/boot.h +0 -3
index 221ed38..a91f55a 100644
@@ -28,9 +28,6 @@
 /* The offset of the end of BPB (BIOS Parameter Block).  */
 #define GRUB_BOOT_MACHINE_BPB_END	0x3e
 
-/* The offset of the major version.  */
-#define GRUB_BOOT_MACHINE_VER_MAJ	0x3e
-
 /* The offset of KERNEL_SECTOR.  */
 #define GRUB_BOOT_MACHINE_KERNEL_SECTOR	0x44
 
#2 lore raw

PATCH 3/7 Eliminate kernel_segment

In reply to Pavel Roskin

ChangeLog:

	* boot/i386/pc/boot.S (kernel_segment): Remove.
	(copy_buffer): Copy to 0x0000:0x8000, not to 0x0800:0x0000.
---
 boot/i386/pc/boot.S |   12 ++----------
 1 files changed, 2 insertions(+), 10 deletions(-)
boot/i386/pc/boot.S +2 -10
index e5685dc..15d02e5 100644
@@ -94,8 +94,6 @@ cylinder_start:
 
 kernel_address:
 	.word	GRUB_BOOT_MACHINE_KERNEL_ADDR
-kernel_segment:
-	.word	GRUB_BOOT_MACHINE_KERNEL_SEG
 
 	. = _start + GRUB_BOOT_MACHINE_KERNEL_SECTOR
 kernel_sector:
@@ -372,13 +370,6 @@ setup_sectors:
 	movw	%es, %bx
 
 copy_buffer:
-#ifdef APPLE_CC
-	kernel_segment_abs = ABS (kernel_segment)
-	movw	(kernel_segment_abs), %es
-#else
-	movw	ABS(kernel_segment), %es
-#endif
-
 	/*
 	 * We need to save %cx and %si because the startup code in
 	 * kernel uses them without initializing them.
@@ -389,7 +380,8 @@ copy_buffer:
 	movw	$0x100, %cx
 	movw	%bx, %ds
 	xorw	%si, %si
-	xorw	%di, %di
+	movw	$GRUB_BOOT_MACHINE_KERNEL_ADDR, %di
+	movw	%si, %es
 
 	cld
 
#3 lore raw

Re: [PATCH 3/7] Eliminate kernel_segment

Quoted 4 lines · Pavel Roskin

ChangeLog:

	* boot/i386/pc/boot.S (kernel_segment): Remove.
	(copy_buffer): Copy to 0x0000:0x8000, not to 0x0800:0x0000.

This looks like it would set an higher limit to the kernel link address. Are we certain we want this?

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
#4 lore raw

PATCH 4/7 Eliminate kernel_address

In reply to Pavel Roskin

ChangeLog:

* boot/i386/pc/boot.S: Eliminate kernel_address. Add .bss section corresponding to the loader. Use relative jump to the loader.

---
 boot/i386/pc/boot.S |   14 +++++---------
 1 files changed, 5 insertions(+), 9 deletions(-)
boot/i386/pc/boot.S +5 -9
index 15d02e5..9323cb9 100644
@@ -92,9 +92,6 @@ cylinder_start:
 	 * End of BIOS parameter block.
 	 */
 
-kernel_address:
-	.word	GRUB_BOOT_MACHINE_KERNEL_ADDR
-
 	. = _start + GRUB_BOOT_MACHINE_KERNEL_SECTOR
 kernel_sector:
 	.long	1, 0
@@ -392,12 +389,7 @@ copy_buffer:
 	popa
 
 	/* boot kernel */
-#ifdef APPLE_CC
-	kernel_address_abs = ABS (kernel_address)
-	jmp	*(kernel_address_abs)
-#else
-	jmp	*(kernel_address)
-#endif
+	jmp	kernel_entry
 
 /* END OF MAIN LOOP */
 
@@ -532,3 +524,7 @@ fd_probe_error_string:	.asciz "Floppy"
 
 /* the last 2 bytes in the sector 0 contain the signature */
 	.word	GRUB_BOOT_MACHINE_SIGNATURE
+
+	.bss
+	. = . + 0x200
+kernel_entry:
#5 lore raw

Re: [PATCH 4/7] Eliminate kernel_address

Quoted 5 lines · Pavel Roskin

ChangeLog:

* boot/i386/pc/boot.S: Eliminate kernel_address. Add .bss section corresponding to the loader. Use relative jump to the loader.

Nice simplification. But what's this .bss needed for? It doesn't look like a BSS.

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
#6 lore raw

PATCH 5/7 Add newline after "Error" in bootsector

In reply to Pavel Roskin

ChangeLog:

* boot/i386/pc/boot.S (general_error_string): Add DOS newline at the end of "Error" to make the message more readable in qemu.

---
 boot/i386/pc/boot.S |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
boot/i386/pc/boot.S +1 -1
index 9323cb9..e3f5228 100644
@@ -425,7 +425,7 @@ notification_string:	.asciz "GRUB "
 geometry_error_string:	.asciz "Geom"
 hd_probe_error_string:	.asciz "Hard Disk"
 read_error_string:	.asciz "Read"
-general_error_string:	.asciz " Error"
+general_error_string:	.asciz " Error\r\n"
 
 /*
  * message: write the string pointed to by %si
#7 lore raw

PATCH 6/7 Increase BPB size to accommodate FAT32.

In reply to Pavel Roskin

ChangeLog:

* include/grub/i386/pc/boot.h (GRUB_BOOT_MACHINE_BPB_END):
Increase to 0x5a. Adjust other offsets accordingly. Original patch by Yves Blusseau <[email protected]>

---
 include/grub/i386/pc/boot.h |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
include/grub/i386/pc/boot.h +4 -4
index a91f55a..cf73c3a 100644
@@ -26,16 +26,16 @@
 #define GRUB_BOOT_MACHINE_BPB_START	0x3
 
 /* The offset of the end of BPB (BIOS Parameter Block).  */
-#define GRUB_BOOT_MACHINE_BPB_END	0x3e
+#define GRUB_BOOT_MACHINE_BPB_END	0x5a
 
 /* The offset of KERNEL_SECTOR.  */
-#define GRUB_BOOT_MACHINE_KERNEL_SECTOR	0x44
+#define GRUB_BOOT_MACHINE_KERNEL_SECTOR	0x5a
 
 /* The offset of BOOT_DRIVE.  */
-#define GRUB_BOOT_MACHINE_BOOT_DRIVE	0x4c
+#define GRUB_BOOT_MACHINE_BOOT_DRIVE	0x62
 
 /* The offset of BOOT_DRIVE_CHECK.  */
-#define GRUB_BOOT_MACHINE_DRIVE_CHECK	0x4e
+#define GRUB_BOOT_MACHINE_DRIVE_CHECK	0x64
 
 /* The offset of a magic number used by Windows NT.  */
 #define GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC	0x1b8
#8 lore raw

PATCH 7/7 RFC: Use correct addresses, eliminate manual relocations

In reply to Pavel Roskin

ChangeLog:

* boot/i386/pc/boot.S: Declare 0x0-0x7c00 as a discardable .bss segment. Eliminate ABS, rely on the assembler knowing correct addresses. Eliminate .bss segment for the kernel, use direct jump to the kernel address.

---
 boot/i386/pc/boot.S |   72 +++++++++------------------------------------------
 1 files changed, 12 insertions(+), 60 deletions(-)
boot/i386/pc/boot.S +12 -60
index e3f5228..0002773 100644
@@ -24,20 +24,13 @@
  *  defines for the code go here
  */
 
-	/* Absolute addresses
-	   This makes the assembler generate the address without support
-	   from the linker. (ELF can't relocate 16-bit addresses!) */
-#define ABS(x) (x-_start+0x7c00)
-
 	/* Print message string */
-#ifdef APPLE_CC
-#define MSG(x)	x ## _abs = ABS(x); movw $x ## _abs, %si; call message
-#else
-#define MSG(x)	movw $ABS(x), %si; call message
-#endif
+#define MSG(x)	movw $x, %si; call message
 
 	.file	"boot.S"
 
+	.bss
+	. = 0x7c00
 	.text
 
 	/* Tell GAS to generate 16-bit instructions so that this code works
@@ -126,12 +119,7 @@ boot_drive_check:
 	 * ljmp to the next instruction because some bogus BIOSes
 	 * jump to 07C0:0000 instead of 0000:7C00.
 	 */
-#ifdef APPLE_CC
-	real_start_abs = ABS(real_start)
-	ljmp	$0, $(real_start_abs)
-#else
-	ljmp	$0, $ABS(real_start)
-#endif
+	ljmp	$0, $real_start
 
 real_start:
 
@@ -148,12 +136,7 @@ real_start:
 	/*
 	 *  Check if we have a forced disk reference here
 	 */
-#ifdef APPLE_CC
-	boot_drive_abs = ABS (boot_drive)
-	movb    boot_drive_abs, %al
-#else
-	movb   ABS(boot_drive), %al
-#endif
+	movb	boot_drive, %al
 	cmpb	$0xff, %al
 	je	1f
 	movb	%al, %dl
@@ -165,12 +148,7 @@ real_start:
 	MSG(notification_string)
 
 	/* set %si to the disk address packet */
-#ifdef APPLE_CC
-	disk_address_packet_abs = ABS (disk_address_packet)
-	movw	$disk_address_packet_abs, %si
-#else
-	movw	$ABS(disk_address_packet), %si
-#endif
+	movw	$disk_address_packet, %si
 
 	/* do not probe LBA if the drive is a floppy */
 	testb	$GRUB_BOOT_MACHINE_BIOS_HD_FLAG, %dl
@@ -211,18 +189,10 @@ lba_mode:
 	movw	$0x0010, (%si)
 
 	/* the absolute address */
-#ifdef APPLE_CC
-	kernel_sector_abs = ABS (kernel_sector)
-	movl	(kernel_sector_abs), %ebx
-	movl	%ebx, 8(%si)
-	movl	(kernel_sector_abs + 4), %ebx
-	movl	%ebx, 12(%si)
-#else
-	movl	ABS(kernel_sector), %ebx
+	movl	kernel_sector, %ebx
 	movl	%ebx, 8(%si)
-	movl	ABS(kernel_sector + 4), %ebx
+	movl	kernel_sector + 4, %ebx
 	movl	%ebx, 12(%si)
-#endif
 
 	/* the segment of buffer address */
 	movw	$GRUB_BOOT_MACHINE_BUFFER_SEG, 6(%si)
@@ -289,22 +259,13 @@ final_init:
 
 setup_sectors:
 	/* load logical sector start (top half) */
-#ifdef APPLE_CC
-	kernel_sector_abs = ABS (kernel_sector)
-	movl	(kernel_sector_abs + 4), %eax
-#else
-	movl	ABS(kernel_sector + 4), %eax
-#endif
+	movl	kernel_sector + 4, %eax
 
 	orl	%eax, %eax
 	jnz	geometry_error
 
 	/* load logical sector start (bottom half) */
-#ifdef APPLE_CC
-	movl	(kernel_sector_abs), %eax
-#else
-	movl	ABS(kernel_sector), %eax
-#endif
+	movl	kernel_sector, %eax
 
 	/* zero %edx */
 	xorl	%edx, %edx
@@ -389,7 +350,7 @@ copy_buffer:
 	popa
 
 	/* boot kernel */
-	jmp	kernel_entry
+	jmp	GRUB_BOOT_MACHINE_KERNEL_ADDR
 
 /* END OF MAIN LOOP */
 
@@ -475,12 +436,7 @@ floppy_probe:
  *  Perform floppy probe.
  */
 
-#ifdef APPLE_CC
-	probe_values_abs = ABS (probe_values)
-	movw	$(probe_values_abs-1), %si
-#else
-	movw	$ABS(probe_values-1), %si
-#endif
+	movw	$probe_values - 1, %si
 
 probe_loop:
 	/* reset floppy controller INT 13h AH=0 */
@@ -524,7 +480,3 @@ fd_probe_error_string:	.asciz "Floppy"
 
 /* the last 2 bytes in the sector 0 contain the signature */
 	.word	GRUB_BOOT_MACHINE_SIGNATURE
-
-	.bss
-	. = . + 0x200
-kernel_entry:
#9 lore raw

Re: [PATCH 7/7] RFC: Use correct addresses, eliminate manual relocations

Quoted 6 lines · Pavel Roskin

ChangeLog:

* boot/i386/pc/boot.S: Declare 0x0-0x7c00 as a discardable .bss segment. Eliminate ABS, rely on the assembler knowing correct addresses. Eliminate .bss segment for the kernel, use direct jump to the kernel address.

I managed to install a Darwin cross-compiler, and it turn out it won't accept .bss in assembler files. Using real addresses would be very, very nice, but we'll need to find a portable way. Maybe grub-macho2img should be taught to cut away sections filled with zeroes.

So patches 5 and 7 are dropped for now. Patches 1-4 and 6 have been applied. Installation on FAT32 is safe now. The "Hard Disk" message has been preserved, so it can be shortened later if the real need arises.

That said, using direct jump to 0x8000 would save 3 bytes, and then we can save 2 bytes by taking an unconditional jump from the "disk check" code and reverting the logic. And maybe we could save 1 byte by yanking "cli" as writing to %ss disables interrupts until the next instruction.

While testing the patches in qemu, I've seen some error messages and found that they should be followed by a new line, as qemu adds its own error message.

Signature · 2 lines
Regards,
Pavel Roskin
#10 lore raw

Re: [PATCH 7/7] RFC: Use correct addresses, eliminate manual relocations

Quoted 8 lines · Pavel Roskin
Quoted 6 lines · Pavel Roskin

ChangeLog:

      * boot/i386/pc/boot.S: Declare 0x0-0x7c00 as a discardable .bss segment.  Eliminate ABS, rely on the assembler knowing correct addresses.  Eliminate .bss segment for the kernel, use direct jump to the kernel address.

Quoted 5 lines

I managed to install a Darwin cross-compiler, and it turn out it won't accept .bss in assembler files.  Using real addresses would be very, very nice, but we'll need to find a portable way.  Maybe grub-macho2img should be taught to cut away sections filled with zeroes.

AFAIR during compilation process relocation entries are preserved and resolved only in the last step. Now thinking it should work even without .bss. Anyway don't care much about compiling bootsectors under darwin. Apple's CC generates longer opcodes which breaks bootsectors. Untill someone finds a fix darwin users will have to use bootsectors compiled under linux. It's not a huge problem since very few developpers need to modify boot sector

Quoted 6 lines

So patches 5 and 7 are dropped for now.  Patches 1-4 and 6 have been applied.  Installation on FAT32 is safe now.  The "Hard Disk" message has been preserved, so it can be shortened later if the real need arises.

That said, using direct jump to 0x8000 would save 3 bytes

Unfortunately BIOSes loading at 7c0:0 exist

Quoted 3 lines

and then we
can save 2 bytes by taking an unconditional jump from the "disk check" code and reverting the logic.

I don't understand what part of code you mean but as long if it's just revertion of a logic to do the same then it's fine with me

Quoted 2 lines

 And maybe we could save 1 byte by yanking
"cli" as writing to %ss disables interrupts until the next instruction.

I pefer to keep cli because alternative i386 implementations may have bug with it

Quoted 15 lines

While testing the patches in qemu, I've seen some error messages and found that they should be followed by a new line, as qemu adds its own error message.

--
Regards,
Pavel Roskin

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 4 lines
Regards
Vladimir 'phcoder' Serbinenko

Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
#11 lore raw

Re: [PATCH 7/7] RFC: Use correct addresses, eliminate manual relocations

Quoted 7 lines · Vladimir 'phcoder' Serbinenko

AFAIR during compilation process relocation entries are preserved and resolved only in the last step. Now thinking it should work even without .bss. Anyway don't care much about compiling bootsectors under darwin. Apple's CC generates longer opcodes which breaks bootsectors. Untill someone finds a fix darwin users will have to use bootsectors compiled under linux. It's not a huge problem since very few developpers need to modify boot sector

OK, good to know. I'll try to preserve Darwin compatibility though. At least I can test it now.

Quoted 1 line
Quoted 1 line

So patches 5 and 7 are dropped for now.

I meant patches 4 (removal of kernel_address) and 7 (elimination of manual relocations).

Quoted 7 lines

Patches 1-4 and 6 have been

Quoted 5 lines

applied. Installation on FAT32 is safe now. The "Hard Disk" message has been preserved, so it can be shortened later if the real need arises.

That said, using direct jump to 0x8000 would save 3 bytes

Unfortunately BIOSes loading at 7c0:0 exist

I mean we can remove kernel_address (minus 2 bytes) and use "jmp 0x8000" instead of "jmp *(kernel_address)" (3 bytes instead of 4). We are in the correct segment already at that point.

Quoted 5 lines
Quoted 3 lines

and then we
can save 2 bytes by taking an unconditional jump from the "disk check" code and reverting the logic.

I don't understand what part of code you mean but as long if it's just revertion of a logic to do the same then it's fine with me

Well, we cannot "revert the logic", as we don't use grub-setup in grub-mkrescue (perhaps it should be fixed). As it stands now, the bootsector should default to "no drive check".

I have a solution for that, but it turns out that grub-setup is buggy, specifically this code:

if (dest_dev->disk->id & 0x80)

dest_dev->disk->id is just a position of the entry in device.map. Moreover, util/hostdisk.c sets disk->has_partitions to 1 indiscriminately, even for floppies, so we cannot rely on it. I suspect that installation on floppies is broken, as copying the partition table would overwrite the floppy code in the bootsector.

Before this is fixed, it's better to keep the drive check as is.

Quoted 4 lines
Quoted 2 lines

And maybe we could save 1 byte by yanking
"cli" as writing to %ss disables interrupts until the next instruction.

I pefer to keep cli because alternative i386 implementations may have bug with it

OK.

Signature · 2 lines
Regards,
Pavel Roskin
#12 lore raw

Re: [PATCH 7/7] RFC: Use correct addresses, eliminate manual relocations

In reply to Vladimir 'phcoder' Serbinenko

Quoting Vladimir 'phcoder' Serbinenko <[email protected]>:

Sorry for the second reply. I have some new data now.

Quoted 3 lines

AFAIR during compilation process relocation entries are preserved and resolved only in the last step. Now thinking it should work even without .bss.

I wrongly assumed that I need it to eliminate the ABS macro, which is quite intrusive. It turns out ABS can be eliminated without any .bss sections. I have no idea why ABS appeared originally. Maybe some really old tools couldn't deal with the relocations.

Quoted 2 lines

Anyway don't care much about compiling bootsectors under darwin.

We have to care, as we have a lot of preprocessor directives in the bootsector sources, and they stand in the way of other changes. We should either maintain that code or discard it.

Quoted 1 line

Apple's CC generates longer opcodes which breaks bootsectors.

You mean Apple assembler. And I know why it happens. The Apple assembler assumes unknown labels to be global and generates long jumps. I looked at the source and it looks like only labels starting with "L" are considered local.

I prepended "L_" to all labels that are used for jumps, and now the Apple assembler creates exactly the same boot.img as the native Linux assembler.

Quoted 3 lines

Untill someone finds a fix darwin users will have to use bootsectors compiled under linux. It's not a huge problem since very few developpers need to modify boot sector

I think I have a fix. I'll post both patches for boot.S - one to remove Apple preprocessor directives and the other to remove ABS. If both work for everyone (I'm worried about Cygwin), we can go ahead with other files.

By the way, Apple cpp defines __APPLE__ and __APPLE_CC__, so we don't need to define APPLE_CC. But I hope to get rid of APPLE_CC in most places before the rest is converted to __APPLE__.

Signature · 2 lines
Regards,
Pavel Roskin
#13 lore raw

Re: [PATCH 7/7] RFC: Use correct addresses, eliminate manual relocations

Quoted 4 lines · Pavel Roskin

Quoting Vladimir 'phcoder' Serbinenko <[email protected]>:

Sorry for the second reply.  I have some new data now.

Quoted 9 lines
Quoted 3 lines

AFAIR during compilation process relocation entries are preserved and resolved only in the last step. Now thinking it should work even without .bss.

I wrongly assumed that I need it to eliminate the ABS macro, which is quite intrusive.  It turns out ABS can be eliminated without any .bss sections.  I have no idea why ABS appeared originally.  Maybe some really old tools couldn't deal with the relocations.

I'm not sure whether supporting old tools is desirable. On one hand some OSes may have kept old tools for binary compatibility (I think especially about haiku which has plans to add multiboot support) but on the other hand since nobody checks a compilation with old tools is probably broken anyway. What do others think?

Quoted 7 lines
Quoted 2 lines

Anyway don't care much about compiling bootsectors under darwin.

We have to care, as we have a lot of preprocessor directives in the bootsector sources, and they stand in the way of other changes.  We should either maintain that code or discard it.

No that you found a way to compile them I do care. Just after having done all the workarounds and fixes to compile core and modules I recieved an allergy to this toolchain but I will continue to support it even if I won't spend a lot of time on it.

Quoted 10 lines
Quoted 1 line

Apple's CC generates longer opcodes which breaks bootsectors.

You mean Apple assembler.  And I know why it happens.  The Apple assembler assumes unknown labels to be global and generates long jumps.  I looked at the source and it looks like only labels starting with "L" are considered local.

I prepended "L_" to all labels that are used for jumps, and now the Apple assembler creates exactly the same boot.img as the native Linux assembler.

Nice. Now afaik the last barrier to grub-on-darwin to be functional are trampolines.

Quoted 8 lines
Quoted 3 lines

Untill someone finds a fix darwin users will have to use bootsectors compiled under linux. It's not a huge problem since very few developpers need to modify boot sector

I think I have a fix.  I'll post both patches for boot.S - one to remove Apple preprocessor directives and the other to remove ABS.  If both work for everyone (I'm worried about Cygwin), we can go ahead with other files.

I'll check them on my OSes

Quoted 1 line

By the way, Apple cpp defines __APPLE__ and __APPLE_CC__,

Yves Blusseau told me about that just before I went to vacation and so I haven't made use of this info and Yves submitted no patch despite me encouraging him to do so

Quoted 3 lines

so we don't need
to define APPLE_CC.  But I hope to get rid of APPLE_CC in most places before the rest is converted to __APPLE__.

Perhaps in some cases we need something more fine-grained like test if resulting image is Mach-O since mixed toolchains with some Apple and some non-Apple components are possible

Quoted 11 lines

--
Regards,
Pavel Roskin

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 4 lines
Regards
Vladimir 'phcoder' Serbinenko

Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
#14 lore raw
In reply to Pavel Roskin
Quoted 17 lines · Pavel Roskin

ChangeLog:

* include/grub/i386/pc/boot.h: Sort all offsets. (GRUB_BOOT_MACHINE_KERNEL_ADDRESS): Remove, it's unused. (GRUB_BOOT_MACHINE_KERNEL_SEGMENT): Likewise.
* boot/i386/pc/boot.S: Assert location of every offset listed in include/grub/i386/pc/boot.h.

---
 boot/i386/pc/boot.S         |    8 +++++++-
 include/grub/i386/pc/boot.h |   10 ++--------
 2 files changed, 9 insertions(+), 9 deletions(-)
boot/i386/pc/boot.S +0 -0
index 8d8c27c..fb90947 100644

boot/i386/pc/boot.S start: · line 69

Quoted 5 lines
boot/i386/pc/boot.S +1 -0
@@ -65,6 +65,7 @@ start:
 	 * this area.
 	 */
 
+	. = _start + GRUB_BOOT_MACHINE_BPB_START
 	. = _start + 4

Why is this +4 still needed? If it's alignment, I'd make it explicit.

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."