On Wed, Dec 25, 2019 at 05:05:11PM +0900, Masanobu SAITOH wrote:
> >> After this change, amd64 kernel does not boot on my HP Spectre x360
> >> 13-inch ae019TU laptop with pure UEFI boot mode.
> I have a UEFI boot machine and it also doesn't boot well.
Please try the attached patch.
It adds the -n flag to ld, which disable auto-alignment of sections
in the file. I undestand alignement is highly desirable for userland
programs that may be mapped from file, but useless for the kernel,
which is just readen once by the bootloader.
Without auto-alignement, the .text segment starts right after the
ELF headers. This means the multiboot header can go in .text and
stay below 32k (as required by the multiboot specification). There
is no need for a multiboot section for that, and therefore no
need to modify the linker script.
A side effect is that the kernel file shrinks of 2 MB, because there
is not an alignement hole between ELF headers and the .text section
anymore.
My patch also enable the MULTIBOOT option so that we can check
nothing gets broken with it. You can also try with the option
disabled, of course.
--
Emmanuel Dreyfus
m...@netbsd.org
? sys/arch/amd64/compile/obj
? sys/arch/amd64/stand/prekern/obj
Index: sys/arch/amd64/amd64/locore.S
===
RCS file: /cvsroot/src/sys/arch/amd64/amd64/locore.S,v
retrieving revision 1.195
diff -U4 -r1.195 locore.S
--- sys/arch/amd64/amd64/locore.S 15 Dec 2019 02:58:21 - 1.195
+++ sys/arch/amd64/amd64/locore.S 26 Dec 2019 16:44:10 -
@@ -431,51 +431,8 @@
.size tmpstk, tmpstk - .
.space 512
tmpstk:
-.section multiboot,"a"
-#if defined(MULTIBOOT)
- .align 8
- .globl Multiboot2_Header
-_C_LABEL(Multiboot2_Header):
- .intMULTIBOOT2_HEADER_MAGIC
- .intMULTIBOOT2_ARCHITECTURE_I386
- .intMultiboot2_Header_end - Multiboot2_Header
- .int-(MULTIBOOT2_HEADER_MAGIC + MULTIBOOT2_ARCHITECTURE_I386 \
- + (Multiboot2_Header_end - Multiboot2_Header))
-
- .int1 /* MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST */
- .int12 /* sizeof(multiboot_header_tag_information_request) */
- /* + sizeof(uint32_t) * requests */
- .int4 /* MULTIBOOT_TAG_TYPE_BASIC_MEMINFO */
- .align 8
-
- .int3 /* MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS */
- .int16 /* sizeof(struct multiboot_tag_efi64) */
- .quad (multiboot2_entry - KERNBASE)
- .align 8
-
- .int9 /* MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64 */
- .int16 /* sizeof(struct multiboot_tag_efi64) */
- .quad (multiboot2_entry - KERNBASE)
- .align 8
-
-#if notyet
- /*
-* Could be used to get an early console for debug,
-* but this is broken.
-*/
- .int7 /* MULTIBOOT_HEADER_TAG_EFI_BS */
- .int8 /* sizeof(struct multiboot_tag) */
- .align 8
-#endif
-
- .int0 /* MULTIBOOT_HEADER_TAG_END */
- .int8 /* sizeof(struct multiboot_tag) */
- .align 8
- .globl Multiboot2_Header_end
-_C_LABEL(Multiboot2_Header_end):
-#endif /* MULTIBOOT */
/*
* Some hackage to deal with 64bit symbols in 32 bit mode.
* This may not be needed if things are cleaned up a little.
@@ -2179,8 +2136,50 @@
SYSCALL_ENTRY syscall,is_svs=0
TEXT_USER_BEGIN
+#if defined(MULTIBOOT)
+ .align 8
+ .globl Multiboot2_Header
+_C_LABEL(Multiboot2_Header):
+ .intMULTIBOOT2_HEADER_MAGIC
+ .intMULTIBOOT2_ARCHITECTURE_I386
+ .intMultiboot2_Header_end - Multiboot2_Header
+ .int-(MULTIBOOT2_HEADER_MAGIC + MULTIBOOT2_ARCHITECTURE_I386 \
+ + (Multiboot2_Header_end - Multiboot2_Header))
+
+ .int1 /* MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST */
+ .int12 /* sizeof(multiboot_header_tag_information_request) */
+ /* + sizeof(uint32_t) * requests */
+ .int4 /* MULTIBOOT_TAG_TYPE_BASIC_MEMINFO */
+ .align 8
+
+ .int3 /* MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS */
+ .int16 /* sizeof(struct multiboot_tag_efi64) */
+ .quad (multiboot2_entry - KERNBASE)
+ .align 8
+
+ .int9 /* MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64 */
+ .int16 /* sizeof(struct multiboot_tag_efi64) */
+ .quad (multiboot2_entry - KERNBASE)
+ .align 8
+
+#if notyet
+ /*
+* Could be used to get an early console for debug,
+* but this is broken.
+*/
+ .int7 /* MULTIBOOT_HEADER_TAG_EFI_BS */
+ .int8 /* sizeof(struct multiboot_tag) */
+ .align 8
+#endif
+
+ .int0 /* MULTIBOOT_HEADER_TAG_END */
+ .int8 /* sizeof(struct multiboot_tag) */
+ .align 8
+ .globl Multiboot2_Hea