2007-07-11 19:18:54 +00:00
|
|
|
/*
|
|
|
|
* header.S
|
|
|
|
*
|
|
|
|
* Copyright (C) 1991, 1992 Linus Torvalds
|
|
|
|
*
|
|
|
|
* Based on bootsect.S and setup.S
|
|
|
|
* modified by more people than can be counted
|
|
|
|
*
|
|
|
|
* Rewritten as a common file by H. Peter Anvin (Apr 2007)
|
|
|
|
*
|
|
|
|
* BIG FAT NOTE: We're in real mode using 64k segments. Therefore segment
|
|
|
|
* addresses must be multiplied by 16 to obtain their respective linear
|
|
|
|
* addresses. To avoid confusion, linear addresses are written using leading
|
|
|
|
* hex while segment addresses are written as segment:offset.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <asm/segment.h>
|
2009-10-17 22:52:28 +00:00
|
|
|
#include <generated/utsrelease.h>
|
2007-07-11 19:18:54 +00:00
|
|
|
#include <asm/boot.h>
|
|
|
|
#include <asm/e820.h>
|
2009-02-13 19:14:01 +00:00
|
|
|
#include <asm/page_types.h>
|
2007-07-11 19:18:54 +00:00
|
|
|
#include <asm/setup.h>
|
2013-01-27 18:43:28 +00:00
|
|
|
#include <asm/bootparam.h>
|
2007-07-11 19:18:54 +00:00
|
|
|
#include "boot.h"
|
2009-05-11 21:21:12 +00:00
|
|
|
#include "voffset.h"
|
|
|
|
#include "zoffset.h"
|
2007-07-11 19:18:54 +00:00
|
|
|
|
|
|
|
BOOTSEG = 0x07C0 /* original address of boot-sector */
|
2009-03-11 17:55:33 +00:00
|
|
|
SYSSEG = 0x1000 /* historical load address >> 4 */
|
2007-07-11 19:18:54 +00:00
|
|
|
|
|
|
|
#ifndef SVGA_MODE
|
|
|
|
#define SVGA_MODE ASK_VGA
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef ROOT_RDONLY
|
|
|
|
#define ROOT_RDONLY 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
.code16
|
|
|
|
.section ".bstext", "ax"
|
|
|
|
|
|
|
|
.global bootsect_start
|
|
|
|
bootsect_start:
|
x86, efi: EFI boot stub support
There is currently a large divide between kernel development and the
development of EFI boot loaders. The idea behind this patch is to give
the kernel developers full control over the EFI boot process. As
H. Peter Anvin put it,
"The 'kernel carries its own stub' approach been very successful in
dealing with BIOS, and would make a lot of sense to me for EFI as
well."
This patch introduces an EFI boot stub that allows an x86 bzImage to
be loaded and executed by EFI firmware. The bzImage appears to the
firmware as an EFI application. Luckily there are enough free bits
within the bzImage header so that it can masquerade as an EFI
application, thereby coercing the EFI firmware into loading it and
jumping to its entry point. The beauty of this masquerading approach
is that both BIOS and EFI boot loaders can still load and run the same
bzImage, thereby allowing a single kernel image to work in any boot
environment.
The EFI boot stub supports multiple initrds, but they must exist on
the same partition as the bzImage. Command-line arguments for the
kernel can be appended after the bzImage name when run from the EFI
shell, e.g.
Shell> bzImage console=ttyS0 root=/dev/sdb initrd=initrd.img
v7:
- Fix checkpatch warnings.
v6:
- Try to allocate initrd memory just below hdr->inird_addr_max.
v5:
- load_options_size is UTF-16, which needs dividing by 2 to convert
to the corresponding ASCII size.
v4:
- Don't read more than image->load_options_size
v3:
- Fix following warnings when compiling CONFIG_EFI_STUB=n
arch/x86/boot/tools/build.c: In function ‘main’:
arch/x86/boot/tools/build.c:138:24: warning: unused variable ‘pe_header’
arch/x86/boot/tools/build.c:138:15: warning: unused variable ‘file_sz’
- As reported by Matthew Garrett, some Apple machines have GOPs that
don't have hardware attached. We need to weed these out by
searching for ones that handle the PCIIO protocol.
- Don't allocate memory if no initrds are on cmdline
- Don't trust image->load_options_size
Maarten Lankhorst noted:
- Don't strip first argument when booted from efibootmgr
- Don't allocate too much memory for cmdline
- Don't update cmdline_size, the kernel considers it read-only
- Don't accept '\n' for initrd names
v2:
- File alignment was too large, was 8192 should be 512. Reported by
Maarten Lankhorst on LKML.
- Added UGA support for graphics
- Use VIDEO_TYPE_EFI instead of hard-coded number.
- Move linelength assignment until after we've assigned depth
- Dynamically fill out AddressOfEntryPoint in tools/build.c
- Don't use magic number for GDT/TSS stuff. Requested by Andi Kleen
- The bzImage may need to be relocated as it may have been loaded at
a high address address by the firmware. This was required to get my
macbook booting because the firmware loaded it at 0x7cxxxxxx, which
triggers this error in decompress_kernel(),
if (heap > ((-__PAGE_OFFSET-(128<<20)-1) & 0x7fffffff))
error("Destination address too large");
Cc: Mike Waychison <mikew@google.com>
Cc: Matthew Garrett <mjg@redhat.com>
Tested-by: Henrik Rydberg <rydberg@euromail.se>
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
Link: http://lkml.kernel.org/r/1321383097.2657.9.camel@mfleming-mobl1.ger.corp.intel.com
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2011-12-12 21:27:52 +00:00
|
|
|
#ifdef CONFIG_EFI_STUB
|
|
|
|
# "MZ", MS-DOS header
|
|
|
|
.byte 0x4d
|
|
|
|
.byte 0x5a
|
|
|
|
#endif
|
2007-07-11 19:18:54 +00:00
|
|
|
|
|
|
|
# Normalize the start address
|
|
|
|
ljmp $BOOTSEG, $start2
|
|
|
|
|
|
|
|
start2:
|
|
|
|
movw %cs, %ax
|
|
|
|
movw %ax, %ds
|
|
|
|
movw %ax, %es
|
|
|
|
movw %ax, %ss
|
|
|
|
xorw %sp, %sp
|
|
|
|
sti
|
|
|
|
cld
|
|
|
|
|
|
|
|
movw $bugger_off_msg, %si
|
|
|
|
|
|
|
|
msg_loop:
|
|
|
|
lodsb
|
|
|
|
andb %al, %al
|
|
|
|
jz bs_die
|
|
|
|
movb $0xe, %ah
|
|
|
|
movw $7, %bx
|
|
|
|
int $0x10
|
|
|
|
jmp msg_loop
|
|
|
|
|
|
|
|
bs_die:
|
|
|
|
# Allow the user to press a key, then reboot
|
|
|
|
xorw %ax, %ax
|
|
|
|
int $0x16
|
|
|
|
int $0x19
|
|
|
|
|
|
|
|
# int 0x19 should never return. In case it does anyway,
|
|
|
|
# invoke the BIOS reset code...
|
|
|
|
ljmp $0xf000,$0xfff0
|
|
|
|
|
x86, efi: EFI boot stub support
There is currently a large divide between kernel development and the
development of EFI boot loaders. The idea behind this patch is to give
the kernel developers full control over the EFI boot process. As
H. Peter Anvin put it,
"The 'kernel carries its own stub' approach been very successful in
dealing with BIOS, and would make a lot of sense to me for EFI as
well."
This patch introduces an EFI boot stub that allows an x86 bzImage to
be loaded and executed by EFI firmware. The bzImage appears to the
firmware as an EFI application. Luckily there are enough free bits
within the bzImage header so that it can masquerade as an EFI
application, thereby coercing the EFI firmware into loading it and
jumping to its entry point. The beauty of this masquerading approach
is that both BIOS and EFI boot loaders can still load and run the same
bzImage, thereby allowing a single kernel image to work in any boot
environment.
The EFI boot stub supports multiple initrds, but they must exist on
the same partition as the bzImage. Command-line arguments for the
kernel can be appended after the bzImage name when run from the EFI
shell, e.g.
Shell> bzImage console=ttyS0 root=/dev/sdb initrd=initrd.img
v7:
- Fix checkpatch warnings.
v6:
- Try to allocate initrd memory just below hdr->inird_addr_max.
v5:
- load_options_size is UTF-16, which needs dividing by 2 to convert
to the corresponding ASCII size.
v4:
- Don't read more than image->load_options_size
v3:
- Fix following warnings when compiling CONFIG_EFI_STUB=n
arch/x86/boot/tools/build.c: In function ‘main’:
arch/x86/boot/tools/build.c:138:24: warning: unused variable ‘pe_header’
arch/x86/boot/tools/build.c:138:15: warning: unused variable ‘file_sz’
- As reported by Matthew Garrett, some Apple machines have GOPs that
don't have hardware attached. We need to weed these out by
searching for ones that handle the PCIIO protocol.
- Don't allocate memory if no initrds are on cmdline
- Don't trust image->load_options_size
Maarten Lankhorst noted:
- Don't strip first argument when booted from efibootmgr
- Don't allocate too much memory for cmdline
- Don't update cmdline_size, the kernel considers it read-only
- Don't accept '\n' for initrd names
v2:
- File alignment was too large, was 8192 should be 512. Reported by
Maarten Lankhorst on LKML.
- Added UGA support for graphics
- Use VIDEO_TYPE_EFI instead of hard-coded number.
- Move linelength assignment until after we've assigned depth
- Dynamically fill out AddressOfEntryPoint in tools/build.c
- Don't use magic number for GDT/TSS stuff. Requested by Andi Kleen
- The bzImage may need to be relocated as it may have been loaded at
a high address address by the firmware. This was required to get my
macbook booting because the firmware loaded it at 0x7cxxxxxx, which
triggers this error in decompress_kernel(),
if (heap > ((-__PAGE_OFFSET-(128<<20)-1) & 0x7fffffff))
error("Destination address too large");
Cc: Mike Waychison <mikew@google.com>
Cc: Matthew Garrett <mjg@redhat.com>
Tested-by: Henrik Rydberg <rydberg@euromail.se>
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
Link: http://lkml.kernel.org/r/1321383097.2657.9.camel@mfleming-mobl1.ger.corp.intel.com
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2011-12-12 21:27:52 +00:00
|
|
|
#ifdef CONFIG_EFI_STUB
|
|
|
|
.org 0x3c
|
|
|
|
#
|
|
|
|
# Offset to the PE header.
|
|
|
|
#
|
|
|
|
.long pe_header
|
|
|
|
#endif /* CONFIG_EFI_STUB */
|
|
|
|
|
2007-07-11 19:18:54 +00:00
|
|
|
.section ".bsdata", "a"
|
|
|
|
bugger_off_msg:
|
2014-07-10 11:26:20 +00:00
|
|
|
.ascii "Use a boot loader.\r\n"
|
2007-07-11 19:18:54 +00:00
|
|
|
.ascii "\n"
|
2014-07-10 11:26:20 +00:00
|
|
|
.ascii "Remove disk and press any key to reboot...\r\n"
|
2007-07-11 19:18:54 +00:00
|
|
|
.byte 0
|
|
|
|
|
x86, efi: EFI boot stub support
There is currently a large divide between kernel development and the
development of EFI boot loaders. The idea behind this patch is to give
the kernel developers full control over the EFI boot process. As
H. Peter Anvin put it,
"The 'kernel carries its own stub' approach been very successful in
dealing with BIOS, and would make a lot of sense to me for EFI as
well."
This patch introduces an EFI boot stub that allows an x86 bzImage to
be loaded and executed by EFI firmware. The bzImage appears to the
firmware as an EFI application. Luckily there are enough free bits
within the bzImage header so that it can masquerade as an EFI
application, thereby coercing the EFI firmware into loading it and
jumping to its entry point. The beauty of this masquerading approach
is that both BIOS and EFI boot loaders can still load and run the same
bzImage, thereby allowing a single kernel image to work in any boot
environment.
The EFI boot stub supports multiple initrds, but they must exist on
the same partition as the bzImage. Command-line arguments for the
kernel can be appended after the bzImage name when run from the EFI
shell, e.g.
Shell> bzImage console=ttyS0 root=/dev/sdb initrd=initrd.img
v7:
- Fix checkpatch warnings.
v6:
- Try to allocate initrd memory just below hdr->inird_addr_max.
v5:
- load_options_size is UTF-16, which needs dividing by 2 to convert
to the corresponding ASCII size.
v4:
- Don't read more than image->load_options_size
v3:
- Fix following warnings when compiling CONFIG_EFI_STUB=n
arch/x86/boot/tools/build.c: In function ‘main’:
arch/x86/boot/tools/build.c:138:24: warning: unused variable ‘pe_header’
arch/x86/boot/tools/build.c:138:15: warning: unused variable ‘file_sz’
- As reported by Matthew Garrett, some Apple machines have GOPs that
don't have hardware attached. We need to weed these out by
searching for ones that handle the PCIIO protocol.
- Don't allocate memory if no initrds are on cmdline
- Don't trust image->load_options_size
Maarten Lankhorst noted:
- Don't strip first argument when booted from efibootmgr
- Don't allocate too much memory for cmdline
- Don't update cmdline_size, the kernel considers it read-only
- Don't accept '\n' for initrd names
v2:
- File alignment was too large, was 8192 should be 512. Reported by
Maarten Lankhorst on LKML.
- Added UGA support for graphics
- Use VIDEO_TYPE_EFI instead of hard-coded number.
- Move linelength assignment until after we've assigned depth
- Dynamically fill out AddressOfEntryPoint in tools/build.c
- Don't use magic number for GDT/TSS stuff. Requested by Andi Kleen
- The bzImage may need to be relocated as it may have been loaded at
a high address address by the firmware. This was required to get my
macbook booting because the firmware loaded it at 0x7cxxxxxx, which
triggers this error in decompress_kernel(),
if (heap > ((-__PAGE_OFFSET-(128<<20)-1) & 0x7fffffff))
error("Destination address too large");
Cc: Mike Waychison <mikew@google.com>
Cc: Matthew Garrett <mjg@redhat.com>
Tested-by: Henrik Rydberg <rydberg@euromail.se>
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
Link: http://lkml.kernel.org/r/1321383097.2657.9.camel@mfleming-mobl1.ger.corp.intel.com
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2011-12-12 21:27:52 +00:00
|
|
|
#ifdef CONFIG_EFI_STUB
|
|
|
|
pe_header:
|
|
|
|
.ascii "PE"
|
|
|
|
.word 0
|
|
|
|
|
|
|
|
coff_header:
|
|
|
|
#ifdef CONFIG_X86_32
|
|
|
|
.word 0x14c # i386
|
|
|
|
#else
|
|
|
|
.word 0x8664 # x86-64
|
|
|
|
#endif
|
2014-07-10 11:26:20 +00:00
|
|
|
.word 4 # nr_sections
|
x86, efi: EFI boot stub support
There is currently a large divide between kernel development and the
development of EFI boot loaders. The idea behind this patch is to give
the kernel developers full control over the EFI boot process. As
H. Peter Anvin put it,
"The 'kernel carries its own stub' approach been very successful in
dealing with BIOS, and would make a lot of sense to me for EFI as
well."
This patch introduces an EFI boot stub that allows an x86 bzImage to
be loaded and executed by EFI firmware. The bzImage appears to the
firmware as an EFI application. Luckily there are enough free bits
within the bzImage header so that it can masquerade as an EFI
application, thereby coercing the EFI firmware into loading it and
jumping to its entry point. The beauty of this masquerading approach
is that both BIOS and EFI boot loaders can still load and run the same
bzImage, thereby allowing a single kernel image to work in any boot
environment.
The EFI boot stub supports multiple initrds, but they must exist on
the same partition as the bzImage. Command-line arguments for the
kernel can be appended after the bzImage name when run from the EFI
shell, e.g.
Shell> bzImage console=ttyS0 root=/dev/sdb initrd=initrd.img
v7:
- Fix checkpatch warnings.
v6:
- Try to allocate initrd memory just below hdr->inird_addr_max.
v5:
- load_options_size is UTF-16, which needs dividing by 2 to convert
to the corresponding ASCII size.
v4:
- Don't read more than image->load_options_size
v3:
- Fix following warnings when compiling CONFIG_EFI_STUB=n
arch/x86/boot/tools/build.c: In function ‘main’:
arch/x86/boot/tools/build.c:138:24: warning: unused variable ‘pe_header’
arch/x86/boot/tools/build.c:138:15: warning: unused variable ‘file_sz’
- As reported by Matthew Garrett, some Apple machines have GOPs that
don't have hardware attached. We need to weed these out by
searching for ones that handle the PCIIO protocol.
- Don't allocate memory if no initrds are on cmdline
- Don't trust image->load_options_size
Maarten Lankhorst noted:
- Don't strip first argument when booted from efibootmgr
- Don't allocate too much memory for cmdline
- Don't update cmdline_size, the kernel considers it read-only
- Don't accept '\n' for initrd names
v2:
- File alignment was too large, was 8192 should be 512. Reported by
Maarten Lankhorst on LKML.
- Added UGA support for graphics
- Use VIDEO_TYPE_EFI instead of hard-coded number.
- Move linelength assignment until after we've assigned depth
- Dynamically fill out AddressOfEntryPoint in tools/build.c
- Don't use magic number for GDT/TSS stuff. Requested by Andi Kleen
- The bzImage may need to be relocated as it may have been loaded at
a high address address by the firmware. This was required to get my
macbook booting because the firmware loaded it at 0x7cxxxxxx, which
triggers this error in decompress_kernel(),
if (heap > ((-__PAGE_OFFSET-(128<<20)-1) & 0x7fffffff))
error("Destination address too large");
Cc: Mike Waychison <mikew@google.com>
Cc: Matthew Garrett <mjg@redhat.com>
Tested-by: Henrik Rydberg <rydberg@euromail.se>
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
Link: http://lkml.kernel.org/r/1321383097.2657.9.camel@mfleming-mobl1.ger.corp.intel.com
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2011-12-12 21:27:52 +00:00
|
|
|
.long 0 # TimeDateStamp
|
|
|
|
.long 0 # PointerToSymbolTable
|
|
|
|
.long 1 # NumberOfSymbols
|
|
|
|
.word section_table - optional_header # SizeOfOptionalHeader
|
|
|
|
#ifdef CONFIG_X86_32
|
|
|
|
.word 0x306 # Characteristics.
|
|
|
|
# IMAGE_FILE_32BIT_MACHINE |
|
|
|
|
# IMAGE_FILE_DEBUG_STRIPPED |
|
|
|
|
# IMAGE_FILE_EXECUTABLE_IMAGE |
|
|
|
|
# IMAGE_FILE_LINE_NUMS_STRIPPED
|
|
|
|
#else
|
|
|
|
.word 0x206 # Characteristics
|
|
|
|
# IMAGE_FILE_DEBUG_STRIPPED |
|
|
|
|
# IMAGE_FILE_EXECUTABLE_IMAGE |
|
|
|
|
# IMAGE_FILE_LINE_NUMS_STRIPPED
|
|
|
|
#endif
|
|
|
|
|
|
|
|
optional_header:
|
|
|
|
#ifdef CONFIG_X86_32
|
|
|
|
.word 0x10b # PE32 format
|
|
|
|
#else
|
|
|
|
.word 0x20b # PE32+ format
|
|
|
|
#endif
|
|
|
|
.byte 0x02 # MajorLinkerVersion
|
|
|
|
.byte 0x14 # MinorLinkerVersion
|
|
|
|
|
|
|
|
# Filled in by build.c
|
|
|
|
.long 0 # SizeOfCode
|
|
|
|
|
|
|
|
.long 0 # SizeOfInitializedData
|
|
|
|
.long 0 # SizeOfUninitializedData
|
|
|
|
|
|
|
|
# Filled in by build.c
|
|
|
|
.long 0x0000 # AddressOfEntryPoint
|
|
|
|
|
2012-03-23 16:35:05 +00:00
|
|
|
.long 0x0200 # BaseOfCode
|
x86, efi: EFI boot stub support
There is currently a large divide between kernel development and the
development of EFI boot loaders. The idea behind this patch is to give
the kernel developers full control over the EFI boot process. As
H. Peter Anvin put it,
"The 'kernel carries its own stub' approach been very successful in
dealing with BIOS, and would make a lot of sense to me for EFI as
well."
This patch introduces an EFI boot stub that allows an x86 bzImage to
be loaded and executed by EFI firmware. The bzImage appears to the
firmware as an EFI application. Luckily there are enough free bits
within the bzImage header so that it can masquerade as an EFI
application, thereby coercing the EFI firmware into loading it and
jumping to its entry point. The beauty of this masquerading approach
is that both BIOS and EFI boot loaders can still load and run the same
bzImage, thereby allowing a single kernel image to work in any boot
environment.
The EFI boot stub supports multiple initrds, but they must exist on
the same partition as the bzImage. Command-line arguments for the
kernel can be appended after the bzImage name when run from the EFI
shell, e.g.
Shell> bzImage console=ttyS0 root=/dev/sdb initrd=initrd.img
v7:
- Fix checkpatch warnings.
v6:
- Try to allocate initrd memory just below hdr->inird_addr_max.
v5:
- load_options_size is UTF-16, which needs dividing by 2 to convert
to the corresponding ASCII size.
v4:
- Don't read more than image->load_options_size
v3:
- Fix following warnings when compiling CONFIG_EFI_STUB=n
arch/x86/boot/tools/build.c: In function ‘main’:
arch/x86/boot/tools/build.c:138:24: warning: unused variable ‘pe_header’
arch/x86/boot/tools/build.c:138:15: warning: unused variable ‘file_sz’
- As reported by Matthew Garrett, some Apple machines have GOPs that
don't have hardware attached. We need to weed these out by
searching for ones that handle the PCIIO protocol.
- Don't allocate memory if no initrds are on cmdline
- Don't trust image->load_options_size
Maarten Lankhorst noted:
- Don't strip first argument when booted from efibootmgr
- Don't allocate too much memory for cmdline
- Don't update cmdline_size, the kernel considers it read-only
- Don't accept '\n' for initrd names
v2:
- File alignment was too large, was 8192 should be 512. Reported by
Maarten Lankhorst on LKML.
- Added UGA support for graphics
- Use VIDEO_TYPE_EFI instead of hard-coded number.
- Move linelength assignment until after we've assigned depth
- Dynamically fill out AddressOfEntryPoint in tools/build.c
- Don't use magic number for GDT/TSS stuff. Requested by Andi Kleen
- The bzImage may need to be relocated as it may have been loaded at
a high address address by the firmware. This was required to get my
macbook booting because the firmware loaded it at 0x7cxxxxxx, which
triggers this error in decompress_kernel(),
if (heap > ((-__PAGE_OFFSET-(128<<20)-1) & 0x7fffffff))
error("Destination address too large");
Cc: Mike Waychison <mikew@google.com>
Cc: Matthew Garrett <mjg@redhat.com>
Tested-by: Henrik Rydberg <rydberg@euromail.se>
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
Link: http://lkml.kernel.org/r/1321383097.2657.9.camel@mfleming-mobl1.ger.corp.intel.com
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2011-12-12 21:27:52 +00:00
|
|
|
#ifdef CONFIG_X86_32
|
|
|
|
.long 0 # data
|
|
|
|
#endif
|
|
|
|
|
|
|
|
extra_header_fields:
|
|
|
|
#ifdef CONFIG_X86_32
|
|
|
|
.long 0 # ImageBase
|
|
|
|
#else
|
|
|
|
.quad 0 # ImageBase
|
|
|
|
#endif
|
2015-08-07 08:36:56 +00:00
|
|
|
.long 0x20 # SectionAlignment
|
2012-06-07 16:05:21 +00:00
|
|
|
.long 0x20 # FileAlignment
|
x86, efi: EFI boot stub support
There is currently a large divide between kernel development and the
development of EFI boot loaders. The idea behind this patch is to give
the kernel developers full control over the EFI boot process. As
H. Peter Anvin put it,
"The 'kernel carries its own stub' approach been very successful in
dealing with BIOS, and would make a lot of sense to me for EFI as
well."
This patch introduces an EFI boot stub that allows an x86 bzImage to
be loaded and executed by EFI firmware. The bzImage appears to the
firmware as an EFI application. Luckily there are enough free bits
within the bzImage header so that it can masquerade as an EFI
application, thereby coercing the EFI firmware into loading it and
jumping to its entry point. The beauty of this masquerading approach
is that both BIOS and EFI boot loaders can still load and run the same
bzImage, thereby allowing a single kernel image to work in any boot
environment.
The EFI boot stub supports multiple initrds, but they must exist on
the same partition as the bzImage. Command-line arguments for the
kernel can be appended after the bzImage name when run from the EFI
shell, e.g.
Shell> bzImage console=ttyS0 root=/dev/sdb initrd=initrd.img
v7:
- Fix checkpatch warnings.
v6:
- Try to allocate initrd memory just below hdr->inird_addr_max.
v5:
- load_options_size is UTF-16, which needs dividing by 2 to convert
to the corresponding ASCII size.
v4:
- Don't read more than image->load_options_size
v3:
- Fix following warnings when compiling CONFIG_EFI_STUB=n
arch/x86/boot/tools/build.c: In function ‘main’:
arch/x86/boot/tools/build.c:138:24: warning: unused variable ‘pe_header’
arch/x86/boot/tools/build.c:138:15: warning: unused variable ‘file_sz’
- As reported by Matthew Garrett, some Apple machines have GOPs that
don't have hardware attached. We need to weed these out by
searching for ones that handle the PCIIO protocol.
- Don't allocate memory if no initrds are on cmdline
- Don't trust image->load_options_size
Maarten Lankhorst noted:
- Don't strip first argument when booted from efibootmgr
- Don't allocate too much memory for cmdline
- Don't update cmdline_size, the kernel considers it read-only
- Don't accept '\n' for initrd names
v2:
- File alignment was too large, was 8192 should be 512. Reported by
Maarten Lankhorst on LKML.
- Added UGA support for graphics
- Use VIDEO_TYPE_EFI instead of hard-coded number.
- Move linelength assignment until after we've assigned depth
- Dynamically fill out AddressOfEntryPoint in tools/build.c
- Don't use magic number for GDT/TSS stuff. Requested by Andi Kleen
- The bzImage may need to be relocated as it may have been loaded at
a high address address by the firmware. This was required to get my
macbook booting because the firmware loaded it at 0x7cxxxxxx, which
triggers this error in decompress_kernel(),
if (heap > ((-__PAGE_OFFSET-(128<<20)-1) & 0x7fffffff))
error("Destination address too large");
Cc: Mike Waychison <mikew@google.com>
Cc: Matthew Garrett <mjg@redhat.com>
Tested-by: Henrik Rydberg <rydberg@euromail.se>
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
Link: http://lkml.kernel.org/r/1321383097.2657.9.camel@mfleming-mobl1.ger.corp.intel.com
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2011-12-12 21:27:52 +00:00
|
|
|
.word 0 # MajorOperatingSystemVersion
|
|
|
|
.word 0 # MinorOperatingSystemVersion
|
|
|
|
.word 0 # MajorImageVersion
|
|
|
|
.word 0 # MinorImageVersion
|
|
|
|
.word 0 # MajorSubsystemVersion
|
|
|
|
.word 0 # MinorSubsystemVersion
|
|
|
|
.long 0 # Win32VersionValue
|
|
|
|
|
|
|
|
#
|
|
|
|
# The size of the bzImage is written in tools/build.c
|
|
|
|
#
|
|
|
|
.long 0 # SizeOfImage
|
|
|
|
|
|
|
|
.long 0x200 # SizeOfHeaders
|
|
|
|
.long 0 # CheckSum
|
|
|
|
.word 0xa # Subsystem (EFI application)
|
|
|
|
.word 0 # DllCharacteristics
|
|
|
|
#ifdef CONFIG_X86_32
|
|
|
|
.long 0 # SizeOfStackReserve
|
|
|
|
.long 0 # SizeOfStackCommit
|
|
|
|
.long 0 # SizeOfHeapReserve
|
|
|
|
.long 0 # SizeOfHeapCommit
|
|
|
|
#else
|
|
|
|
.quad 0 # SizeOfStackReserve
|
|
|
|
.quad 0 # SizeOfStackCommit
|
|
|
|
.quad 0 # SizeOfHeapReserve
|
|
|
|
.quad 0 # SizeOfHeapCommit
|
|
|
|
#endif
|
|
|
|
.long 0 # LoaderFlags
|
2012-03-23 16:35:06 +00:00
|
|
|
.long 0x6 # NumberOfRvaAndSizes
|
x86, efi: EFI boot stub support
There is currently a large divide between kernel development and the
development of EFI boot loaders. The idea behind this patch is to give
the kernel developers full control over the EFI boot process. As
H. Peter Anvin put it,
"The 'kernel carries its own stub' approach been very successful in
dealing with BIOS, and would make a lot of sense to me for EFI as
well."
This patch introduces an EFI boot stub that allows an x86 bzImage to
be loaded and executed by EFI firmware. The bzImage appears to the
firmware as an EFI application. Luckily there are enough free bits
within the bzImage header so that it can masquerade as an EFI
application, thereby coercing the EFI firmware into loading it and
jumping to its entry point. The beauty of this masquerading approach
is that both BIOS and EFI boot loaders can still load and run the same
bzImage, thereby allowing a single kernel image to work in any boot
environment.
The EFI boot stub supports multiple initrds, but they must exist on
the same partition as the bzImage. Command-line arguments for the
kernel can be appended after the bzImage name when run from the EFI
shell, e.g.
Shell> bzImage console=ttyS0 root=/dev/sdb initrd=initrd.img
v7:
- Fix checkpatch warnings.
v6:
- Try to allocate initrd memory just below hdr->inird_addr_max.
v5:
- load_options_size is UTF-16, which needs dividing by 2 to convert
to the corresponding ASCII size.
v4:
- Don't read more than image->load_options_size
v3:
- Fix following warnings when compiling CONFIG_EFI_STUB=n
arch/x86/boot/tools/build.c: In function ‘main’:
arch/x86/boot/tools/build.c:138:24: warning: unused variable ‘pe_header’
arch/x86/boot/tools/build.c:138:15: warning: unused variable ‘file_sz’
- As reported by Matthew Garrett, some Apple machines have GOPs that
don't have hardware attached. We need to weed these out by
searching for ones that handle the PCIIO protocol.
- Don't allocate memory if no initrds are on cmdline
- Don't trust image->load_options_size
Maarten Lankhorst noted:
- Don't strip first argument when booted from efibootmgr
- Don't allocate too much memory for cmdline
- Don't update cmdline_size, the kernel considers it read-only
- Don't accept '\n' for initrd names
v2:
- File alignment was too large, was 8192 should be 512. Reported by
Maarten Lankhorst on LKML.
- Added UGA support for graphics
- Use VIDEO_TYPE_EFI instead of hard-coded number.
- Move linelength assignment until after we've assigned depth
- Dynamically fill out AddressOfEntryPoint in tools/build.c
- Don't use magic number for GDT/TSS stuff. Requested by Andi Kleen
- The bzImage may need to be relocated as it may have been loaded at
a high address address by the firmware. This was required to get my
macbook booting because the firmware loaded it at 0x7cxxxxxx, which
triggers this error in decompress_kernel(),
if (heap > ((-__PAGE_OFFSET-(128<<20)-1) & 0x7fffffff))
error("Destination address too large");
Cc: Mike Waychison <mikew@google.com>
Cc: Matthew Garrett <mjg@redhat.com>
Tested-by: Henrik Rydberg <rydberg@euromail.se>
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
Link: http://lkml.kernel.org/r/1321383097.2657.9.camel@mfleming-mobl1.ger.corp.intel.com
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2011-12-12 21:27:52 +00:00
|
|
|
|
|
|
|
.quad 0 # ExportTable
|
|
|
|
.quad 0 # ImportTable
|
|
|
|
.quad 0 # ResourceTable
|
|
|
|
.quad 0 # ExceptionTable
|
|
|
|
.quad 0 # CertificationTable
|
|
|
|
.quad 0 # BaseRelocationTable
|
|
|
|
|
|
|
|
# Section table
|
|
|
|
section_table:
|
2012-06-07 16:05:21 +00:00
|
|
|
#
|
|
|
|
# The offset & size fields are filled in by build.c.
|
|
|
|
#
|
|
|
|
.ascii ".setup"
|
x86, efi: EFI boot stub support
There is currently a large divide between kernel development and the
development of EFI boot loaders. The idea behind this patch is to give
the kernel developers full control over the EFI boot process. As
H. Peter Anvin put it,
"The 'kernel carries its own stub' approach been very successful in
dealing with BIOS, and would make a lot of sense to me for EFI as
well."
This patch introduces an EFI boot stub that allows an x86 bzImage to
be loaded and executed by EFI firmware. The bzImage appears to the
firmware as an EFI application. Luckily there are enough free bits
within the bzImage header so that it can masquerade as an EFI
application, thereby coercing the EFI firmware into loading it and
jumping to its entry point. The beauty of this masquerading approach
is that both BIOS and EFI boot loaders can still load and run the same
bzImage, thereby allowing a single kernel image to work in any boot
environment.
The EFI boot stub supports multiple initrds, but they must exist on
the same partition as the bzImage. Command-line arguments for the
kernel can be appended after the bzImage name when run from the EFI
shell, e.g.
Shell> bzImage console=ttyS0 root=/dev/sdb initrd=initrd.img
v7:
- Fix checkpatch warnings.
v6:
- Try to allocate initrd memory just below hdr->inird_addr_max.
v5:
- load_options_size is UTF-16, which needs dividing by 2 to convert
to the corresponding ASCII size.
v4:
- Don't read more than image->load_options_size
v3:
- Fix following warnings when compiling CONFIG_EFI_STUB=n
arch/x86/boot/tools/build.c: In function ‘main’:
arch/x86/boot/tools/build.c:138:24: warning: unused variable ‘pe_header’
arch/x86/boot/tools/build.c:138:15: warning: unused variable ‘file_sz’
- As reported by Matthew Garrett, some Apple machines have GOPs that
don't have hardware attached. We need to weed these out by
searching for ones that handle the PCIIO protocol.
- Don't allocate memory if no initrds are on cmdline
- Don't trust image->load_options_size
Maarten Lankhorst noted:
- Don't strip first argument when booted from efibootmgr
- Don't allocate too much memory for cmdline
- Don't update cmdline_size, the kernel considers it read-only
- Don't accept '\n' for initrd names
v2:
- File alignment was too large, was 8192 should be 512. Reported by
Maarten Lankhorst on LKML.
- Added UGA support for graphics
- Use VIDEO_TYPE_EFI instead of hard-coded number.
- Move linelength assignment until after we've assigned depth
- Dynamically fill out AddressOfEntryPoint in tools/build.c
- Don't use magic number for GDT/TSS stuff. Requested by Andi Kleen
- The bzImage may need to be relocated as it may have been loaded at
a high address address by the firmware. This was required to get my
macbook booting because the firmware loaded it at 0x7cxxxxxx, which
triggers this error in decompress_kernel(),
if (heap > ((-__PAGE_OFFSET-(128<<20)-1) & 0x7fffffff))
error("Destination address too large");
Cc: Mike Waychison <mikew@google.com>
Cc: Matthew Garrett <mjg@redhat.com>
Tested-by: Henrik Rydberg <rydberg@euromail.se>
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
Link: http://lkml.kernel.org/r/1321383097.2657.9.camel@mfleming-mobl1.ger.corp.intel.com
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2011-12-12 21:27:52 +00:00
|
|
|
.byte 0
|
|
|
|
.byte 0
|
|
|
|
.long 0
|
|
|
|
.long 0x0 # startup_{32,64}
|
|
|
|
.long 0 # Size of initialized data
|
|
|
|
# on disk
|
|
|
|
.long 0x0 # startup_{32,64}
|
|
|
|
.long 0 # PointerToRelocations
|
|
|
|
.long 0 # PointerToLineNumbers
|
|
|
|
.word 0 # NumberOfRelocations
|
|
|
|
.word 0 # NumberOfLineNumbers
|
|
|
|
.long 0x60500020 # Characteristics (section flags)
|
|
|
|
|
|
|
|
#
|
|
|
|
# The EFI application loader requires a relocation section
|
2012-06-07 16:05:21 +00:00
|
|
|
# because EFI applications must be relocatable. The .reloc
|
|
|
|
# offset & size fields are filled in by build.c.
|
x86, efi: EFI boot stub support
There is currently a large divide between kernel development and the
development of EFI boot loaders. The idea behind this patch is to give
the kernel developers full control over the EFI boot process. As
H. Peter Anvin put it,
"The 'kernel carries its own stub' approach been very successful in
dealing with BIOS, and would make a lot of sense to me for EFI as
well."
This patch introduces an EFI boot stub that allows an x86 bzImage to
be loaded and executed by EFI firmware. The bzImage appears to the
firmware as an EFI application. Luckily there are enough free bits
within the bzImage header so that it can masquerade as an EFI
application, thereby coercing the EFI firmware into loading it and
jumping to its entry point. The beauty of this masquerading approach
is that both BIOS and EFI boot loaders can still load and run the same
bzImage, thereby allowing a single kernel image to work in any boot
environment.
The EFI boot stub supports multiple initrds, but they must exist on
the same partition as the bzImage. Command-line arguments for the
kernel can be appended after the bzImage name when run from the EFI
shell, e.g.
Shell> bzImage console=ttyS0 root=/dev/sdb initrd=initrd.img
v7:
- Fix checkpatch warnings.
v6:
- Try to allocate initrd memory just below hdr->inird_addr_max.
v5:
- load_options_size is UTF-16, which needs dividing by 2 to convert
to the corresponding ASCII size.
v4:
- Don't read more than image->load_options_size
v3:
- Fix following warnings when compiling CONFIG_EFI_STUB=n
arch/x86/boot/tools/build.c: In function ‘main’:
arch/x86/boot/tools/build.c:138:24: warning: unused variable ‘pe_header’
arch/x86/boot/tools/build.c:138:15: warning: unused variable ‘file_sz’
- As reported by Matthew Garrett, some Apple machines have GOPs that
don't have hardware attached. We need to weed these out by
searching for ones that handle the PCIIO protocol.
- Don't allocate memory if no initrds are on cmdline
- Don't trust image->load_options_size
Maarten Lankhorst noted:
- Don't strip first argument when booted from efibootmgr
- Don't allocate too much memory for cmdline
- Don't update cmdline_size, the kernel considers it read-only
- Don't accept '\n' for initrd names
v2:
- File alignment was too large, was 8192 should be 512. Reported by
Maarten Lankhorst on LKML.
- Added UGA support for graphics
- Use VIDEO_TYPE_EFI instead of hard-coded number.
- Move linelength assignment until after we've assigned depth
- Dynamically fill out AddressOfEntryPoint in tools/build.c
- Don't use magic number for GDT/TSS stuff. Requested by Andi Kleen
- The bzImage may need to be relocated as it may have been loaded at
a high address address by the firmware. This was required to get my
macbook booting because the firmware loaded it at 0x7cxxxxxx, which
triggers this error in decompress_kernel(),
if (heap > ((-__PAGE_OFFSET-(128<<20)-1) & 0x7fffffff))
error("Destination address too large");
Cc: Mike Waychison <mikew@google.com>
Cc: Matthew Garrett <mjg@redhat.com>
Tested-by: Henrik Rydberg <rydberg@euromail.se>
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
Link: http://lkml.kernel.org/r/1321383097.2657.9.camel@mfleming-mobl1.ger.corp.intel.com
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2011-12-12 21:27:52 +00:00
|
|
|
#
|
|
|
|
.ascii ".reloc"
|
|
|
|
.byte 0
|
|
|
|
.byte 0
|
2012-03-23 16:35:04 +00:00
|
|
|
.long 0
|
|
|
|
.long 0
|
|
|
|
.long 0 # SizeOfRawData
|
|
|
|
.long 0 # PointerToRawData
|
x86, efi: EFI boot stub support
There is currently a large divide between kernel development and the
development of EFI boot loaders. The idea behind this patch is to give
the kernel developers full control over the EFI boot process. As
H. Peter Anvin put it,
"The 'kernel carries its own stub' approach been very successful in
dealing with BIOS, and would make a lot of sense to me for EFI as
well."
This patch introduces an EFI boot stub that allows an x86 bzImage to
be loaded and executed by EFI firmware. The bzImage appears to the
firmware as an EFI application. Luckily there are enough free bits
within the bzImage header so that it can masquerade as an EFI
application, thereby coercing the EFI firmware into loading it and
jumping to its entry point. The beauty of this masquerading approach
is that both BIOS and EFI boot loaders can still load and run the same
bzImage, thereby allowing a single kernel image to work in any boot
environment.
The EFI boot stub supports multiple initrds, but they must exist on
the same partition as the bzImage. Command-line arguments for the
kernel can be appended after the bzImage name when run from the EFI
shell, e.g.
Shell> bzImage console=ttyS0 root=/dev/sdb initrd=initrd.img
v7:
- Fix checkpatch warnings.
v6:
- Try to allocate initrd memory just below hdr->inird_addr_max.
v5:
- load_options_size is UTF-16, which needs dividing by 2 to convert
to the corresponding ASCII size.
v4:
- Don't read more than image->load_options_size
v3:
- Fix following warnings when compiling CONFIG_EFI_STUB=n
arch/x86/boot/tools/build.c: In function ‘main’:
arch/x86/boot/tools/build.c:138:24: warning: unused variable ‘pe_header’
arch/x86/boot/tools/build.c:138:15: warning: unused variable ‘file_sz’
- As reported by Matthew Garrett, some Apple machines have GOPs that
don't have hardware attached. We need to weed these out by
searching for ones that handle the PCIIO protocol.
- Don't allocate memory if no initrds are on cmdline
- Don't trust image->load_options_size
Maarten Lankhorst noted:
- Don't strip first argument when booted from efibootmgr
- Don't allocate too much memory for cmdline
- Don't update cmdline_size, the kernel considers it read-only
- Don't accept '\n' for initrd names
v2:
- File alignment was too large, was 8192 should be 512. Reported by
Maarten Lankhorst on LKML.
- Added UGA support for graphics
- Use VIDEO_TYPE_EFI instead of hard-coded number.
- Move linelength assignment until after we've assigned depth
- Dynamically fill out AddressOfEntryPoint in tools/build.c
- Don't use magic number for GDT/TSS stuff. Requested by Andi Kleen
- The bzImage may need to be relocated as it may have been loaded at
a high address address by the firmware. This was required to get my
macbook booting because the firmware loaded it at 0x7cxxxxxx, which
triggers this error in decompress_kernel(),
if (heap > ((-__PAGE_OFFSET-(128<<20)-1) & 0x7fffffff))
error("Destination address too large");
Cc: Mike Waychison <mikew@google.com>
Cc: Matthew Garrett <mjg@redhat.com>
Tested-by: Henrik Rydberg <rydberg@euromail.se>
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
Link: http://lkml.kernel.org/r/1321383097.2657.9.camel@mfleming-mobl1.ger.corp.intel.com
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2011-12-12 21:27:52 +00:00
|
|
|
.long 0 # PointerToRelocations
|
|
|
|
.long 0 # PointerToLineNumbers
|
|
|
|
.word 0 # NumberOfRelocations
|
|
|
|
.word 0 # NumberOfLineNumbers
|
|
|
|
.long 0x42100040 # Characteristics (section flags)
|
2012-06-07 16:05:21 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# The offset & size fields are filled in by build.c.
|
|
|
|
#
|
|
|
|
.ascii ".text"
|
|
|
|
.byte 0
|
|
|
|
.byte 0
|
|
|
|
.byte 0
|
|
|
|
.long 0
|
|
|
|
.long 0x0 # startup_{32,64}
|
|
|
|
.long 0 # Size of initialized data
|
|
|
|
# on disk
|
|
|
|
.long 0x0 # startup_{32,64}
|
|
|
|
.long 0 # PointerToRelocations
|
|
|
|
.long 0 # PointerToLineNumbers
|
|
|
|
.word 0 # NumberOfRelocations
|
|
|
|
.word 0 # NumberOfLineNumbers
|
|
|
|
.long 0x60500020 # Characteristics (section flags)
|
|
|
|
|
2014-07-10 11:26:20 +00:00
|
|
|
#
|
|
|
|
# The offset & size fields are filled in by build.c.
|
|
|
|
#
|
|
|
|
.ascii ".bss"
|
|
|
|
.byte 0
|
|
|
|
.byte 0
|
|
|
|
.byte 0
|
|
|
|
.byte 0
|
|
|
|
.long 0
|
|
|
|
.long 0x0
|
|
|
|
.long 0 # Size of initialized data
|
|
|
|
# on disk
|
|
|
|
.long 0x0
|
|
|
|
.long 0 # PointerToRelocations
|
|
|
|
.long 0 # PointerToLineNumbers
|
|
|
|
.word 0 # NumberOfRelocations
|
|
|
|
.word 0 # NumberOfLineNumbers
|
|
|
|
.long 0xc8000080 # Characteristics (section flags)
|
|
|
|
|
x86, efi: EFI boot stub support
There is currently a large divide between kernel development and the
development of EFI boot loaders. The idea behind this patch is to give
the kernel developers full control over the EFI boot process. As
H. Peter Anvin put it,
"The 'kernel carries its own stub' approach been very successful in
dealing with BIOS, and would make a lot of sense to me for EFI as
well."
This patch introduces an EFI boot stub that allows an x86 bzImage to
be loaded and executed by EFI firmware. The bzImage appears to the
firmware as an EFI application. Luckily there are enough free bits
within the bzImage header so that it can masquerade as an EFI
application, thereby coercing the EFI firmware into loading it and
jumping to its entry point. The beauty of this masquerading approach
is that both BIOS and EFI boot loaders can still load and run the same
bzImage, thereby allowing a single kernel image to work in any boot
environment.
The EFI boot stub supports multiple initrds, but they must exist on
the same partition as the bzImage. Command-line arguments for the
kernel can be appended after the bzImage name when run from the EFI
shell, e.g.
Shell> bzImage console=ttyS0 root=/dev/sdb initrd=initrd.img
v7:
- Fix checkpatch warnings.
v6:
- Try to allocate initrd memory just below hdr->inird_addr_max.
v5:
- load_options_size is UTF-16, which needs dividing by 2 to convert
to the corresponding ASCII size.
v4:
- Don't read more than image->load_options_size
v3:
- Fix following warnings when compiling CONFIG_EFI_STUB=n
arch/x86/boot/tools/build.c: In function ‘main’:
arch/x86/boot/tools/build.c:138:24: warning: unused variable ‘pe_header’
arch/x86/boot/tools/build.c:138:15: warning: unused variable ‘file_sz’
- As reported by Matthew Garrett, some Apple machines have GOPs that
don't have hardware attached. We need to weed these out by
searching for ones that handle the PCIIO protocol.
- Don't allocate memory if no initrds are on cmdline
- Don't trust image->load_options_size
Maarten Lankhorst noted:
- Don't strip first argument when booted from efibootmgr
- Don't allocate too much memory for cmdline
- Don't update cmdline_size, the kernel considers it read-only
- Don't accept '\n' for initrd names
v2:
- File alignment was too large, was 8192 should be 512. Reported by
Maarten Lankhorst on LKML.
- Added UGA support for graphics
- Use VIDEO_TYPE_EFI instead of hard-coded number.
- Move linelength assignment until after we've assigned depth
- Dynamically fill out AddressOfEntryPoint in tools/build.c
- Don't use magic number for GDT/TSS stuff. Requested by Andi Kleen
- The bzImage may need to be relocated as it may have been loaded at
a high address address by the firmware. This was required to get my
macbook booting because the firmware loaded it at 0x7cxxxxxx, which
triggers this error in decompress_kernel(),
if (heap > ((-__PAGE_OFFSET-(128<<20)-1) & 0x7fffffff))
error("Destination address too large");
Cc: Mike Waychison <mikew@google.com>
Cc: Matthew Garrett <mjg@redhat.com>
Tested-by: Henrik Rydberg <rydberg@euromail.se>
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
Link: http://lkml.kernel.org/r/1321383097.2657.9.camel@mfleming-mobl1.ger.corp.intel.com
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2011-12-12 21:27:52 +00:00
|
|
|
#endif /* CONFIG_EFI_STUB */
|
2007-07-11 19:18:54 +00:00
|
|
|
|
|
|
|
# Kernel attributes; used by setup. This is part 1 of the
|
|
|
|
# header, from the old boot sector.
|
|
|
|
|
|
|
|
.section ".header", "a"
|
2013-01-27 18:43:28 +00:00
|
|
|
.globl sentinel
|
|
|
|
sentinel: .byte 0xff, 0xff /* Used to detect broken loaders */
|
|
|
|
|
2007-07-11 19:18:54 +00:00
|
|
|
.globl hdr
|
|
|
|
hdr:
|
2009-03-11 17:55:33 +00:00
|
|
|
setup_sects: .byte 0 /* Filled in by build.c */
|
2007-07-11 19:18:54 +00:00
|
|
|
root_flags: .word ROOT_RDONLY
|
2009-03-11 17:55:33 +00:00
|
|
|
syssize: .long 0 /* Filled in by build.c */
|
|
|
|
ram_size: .word 0 /* Obsolete */
|
2007-07-11 19:18:54 +00:00
|
|
|
vid_mode: .word SVGA_MODE
|
2009-03-11 17:55:33 +00:00
|
|
|
root_dev: .word 0 /* Filled in by build.c */
|
2007-07-11 19:18:54 +00:00
|
|
|
boot_flag: .word 0xAA55
|
|
|
|
|
|
|
|
# offset 512, entry point
|
|
|
|
|
|
|
|
.globl _start
|
|
|
|
_start:
|
|
|
|
# Explicitly enter this as bytes, or the assembler
|
|
|
|
# tries to generate a 3-byte jump here, which causes
|
|
|
|
# everything else to push off to the wrong offset.
|
|
|
|
.byte 0xeb # short (2-byte) jump
|
|
|
|
.byte start_of_setup-1f
|
|
|
|
1:
|
|
|
|
|
|
|
|
# Part 2 of the header, from the old setup.S
|
|
|
|
|
|
|
|
.ascii "HdrS" # header signature
|
2014-01-10 18:52:06 +00:00
|
|
|
.word 0x020d # header version number (>= 0x0105)
|
2007-07-11 19:18:54 +00:00
|
|
|
# or else old loadlin-1.5 will fail)
|
|
|
|
.globl realmode_swtch
|
|
|
|
realmode_swtch: .word 0, 0 # default_switch, SETUPSEG
|
2009-03-11 17:55:33 +00:00
|
|
|
start_sys_seg: .word SYSSEG # obsolete and meaningless, but just
|
|
|
|
# in case something decided to "use" it
|
2007-07-11 19:18:54 +00:00
|
|
|
.word kernel_version-512 # pointing to kernel version string
|
|
|
|
# above section of header is compatible
|
|
|
|
# with loadlin-1.5 (header v1.5). Don't
|
|
|
|
# change it.
|
|
|
|
|
2009-03-11 17:55:33 +00:00
|
|
|
type_of_loader: .byte 0 # 0 means ancient bootloader, newer
|
|
|
|
# bootloaders know to change this.
|
2011-08-15 00:02:26 +00:00
|
|
|
# See Documentation/x86/boot.txt for
|
2007-07-11 19:18:54 +00:00
|
|
|
# assigned ids
|
|
|
|
|
|
|
|
# flags, unused bits must be zero (RFU) bit within loadflags
|
|
|
|
loadflags:
|
2013-01-27 18:43:28 +00:00
|
|
|
.byte LOADED_HIGH # The kernel is to be loaded high
|
2007-07-11 19:18:54 +00:00
|
|
|
|
|
|
|
setup_move_size: .word 0x8000 # size to move, when setup is not
|
|
|
|
# loaded at 0x90000. We will move setup
|
|
|
|
# to 0x90000 then just before jumping
|
|
|
|
# into the kernel. However, only the
|
|
|
|
# loader knows how much data behind
|
|
|
|
# us also needs to be loaded.
|
|
|
|
|
|
|
|
code32_start: # here loaders can put a different
|
|
|
|
# start address for 32-bit code.
|
|
|
|
.long 0x100000 # 0x100000 = default for big kernel
|
|
|
|
|
|
|
|
ramdisk_image: .long 0 # address of loaded ramdisk image
|
|
|
|
# Here the loader puts the 32-bit
|
|
|
|
# address where it loaded the image.
|
|
|
|
# This only will be read by the kernel.
|
|
|
|
|
|
|
|
ramdisk_size: .long 0 # its size in bytes
|
|
|
|
|
|
|
|
bootsect_kludge:
|
|
|
|
.long 0 # obsolete
|
|
|
|
|
2007-10-25 23:11:33 +00:00
|
|
|
heap_end_ptr: .word _end+STACK_SIZE-512
|
|
|
|
# (Header version 0x0201 or later)
|
2007-07-11 19:18:54 +00:00
|
|
|
# space from here (exclusive) down to
|
|
|
|
# end of setup code can be used by setup
|
|
|
|
# for local heap purposes.
|
|
|
|
|
2009-05-07 23:54:11 +00:00
|
|
|
ext_loader_ver:
|
|
|
|
.byte 0 # Extended boot loader version
|
|
|
|
ext_loader_type:
|
|
|
|
.byte 0 # Extended boot loader type
|
|
|
|
|
2007-07-11 19:18:54 +00:00
|
|
|
cmd_line_ptr: .long 0 # (Header version 0x0202 or later)
|
|
|
|
# If nonzero, a 32-bit pointer
|
|
|
|
# to the kernel command line.
|
|
|
|
# The command line should be
|
|
|
|
# located between the start of
|
|
|
|
# setup and the end of low
|
|
|
|
# memory (0xa0000), or it may
|
|
|
|
# get overwritten before it
|
|
|
|
# gets read. If this field is
|
|
|
|
# used, there is no longer
|
|
|
|
# anything magical about the
|
|
|
|
# 0x90000 segment; the setup
|
|
|
|
# can be located anywhere in
|
|
|
|
# low memory 0x10000 or higher.
|
|
|
|
|
2014-03-12 14:13:02 +00:00
|
|
|
initrd_addr_max: .long 0x7fffffff
|
2007-07-11 19:18:54 +00:00
|
|
|
# (Header version 0x0203 or later)
|
|
|
|
# The highest safe address for
|
|
|
|
# the contents of an initrd
|
2008-01-30 12:32:51 +00:00
|
|
|
# The current kernel allows up to 4 GB,
|
|
|
|
# but leave it at 2 GB to avoid
|
|
|
|
# possible bootloader bugs.
|
2007-07-11 19:18:54 +00:00
|
|
|
|
|
|
|
kernel_alignment: .long CONFIG_PHYSICAL_ALIGN #physical addr alignment
|
|
|
|
#required for protected mode
|
|
|
|
#kernel
|
|
|
|
#ifdef CONFIG_RELOCATABLE
|
|
|
|
relocatable_kernel: .byte 1
|
|
|
|
#else
|
|
|
|
relocatable_kernel: .byte 0
|
|
|
|
#endif
|
2009-05-11 22:56:08 +00:00
|
|
|
min_alignment: .byte MIN_KERNEL_ALIGN_LG2 # minimum alignment
|
2013-01-27 18:43:28 +00:00
|
|
|
|
|
|
|
xloadflags:
|
|
|
|
#ifdef CONFIG_X86_64
|
|
|
|
# define XLF0 XLF_KERNEL_64 /* 64-bit kernel */
|
|
|
|
#else
|
|
|
|
# define XLF0 0
|
|
|
|
#endif
|
2013-01-29 04:16:44 +00:00
|
|
|
|
2014-06-07 11:26:20 +00:00
|
|
|
#if defined(CONFIG_RELOCATABLE) && defined(CONFIG_X86_64)
|
2013-01-29 04:16:44 +00:00
|
|
|
/* kernel/boot_param/ramdisk could be loaded above 4g */
|
|
|
|
# define XLF1 XLF_CAN_BE_LOADED_ABOVE_4G
|
|
|
|
#else
|
|
|
|
# define XLF1 0
|
|
|
|
#endif
|
|
|
|
|
2013-01-27 18:43:28 +00:00
|
|
|
#ifdef CONFIG_EFI_STUB
|
2014-01-10 18:52:06 +00:00
|
|
|
# ifdef CONFIG_EFI_MIXED
|
|
|
|
# define XLF23 (XLF_EFI_HANDOVER_32|XLF_EFI_HANDOVER_64)
|
2013-01-27 18:43:28 +00:00
|
|
|
# else
|
2014-01-10 18:52:06 +00:00
|
|
|
# ifdef CONFIG_X86_64
|
|
|
|
# define XLF23 XLF_EFI_HANDOVER_64 /* 64-bit EFI handover ok */
|
|
|
|
# else
|
|
|
|
# define XLF23 XLF_EFI_HANDOVER_32 /* 32-bit EFI handover ok */
|
|
|
|
# endif
|
2013-01-27 18:43:28 +00:00
|
|
|
# endif
|
|
|
|
#else
|
|
|
|
# define XLF23 0
|
|
|
|
#endif
|
2013-12-20 10:02:20 +00:00
|
|
|
|
2015-09-09 22:38:55 +00:00
|
|
|
#if defined(CONFIG_X86_64) && defined(CONFIG_EFI) && defined(CONFIG_KEXEC_CORE)
|
2013-12-20 10:02:20 +00:00
|
|
|
# define XLF4 XLF_EFI_KEXEC
|
|
|
|
#else
|
|
|
|
# define XLF4 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
.word XLF0 | XLF1 | XLF23 | XLF4
|
2007-07-11 19:18:54 +00:00
|
|
|
|
|
|
|
cmdline_size: .long COMMAND_LINE_SIZE-1 #length of the command line,
|
|
|
|
#added with boot protocol
|
|
|
|
#version 2.06
|
|
|
|
|
2007-10-21 23:41:35 +00:00
|
|
|
hardware_subarch: .long 0 # subarchitecture, added with 2.07
|
|
|
|
# default to 0 for normal x86 PC
|
|
|
|
|
|
|
|
hardware_subarch_data: .quad 0
|
|
|
|
|
2009-05-11 21:21:12 +00:00
|
|
|
payload_offset: .long ZO_input_data
|
|
|
|
payload_length: .long ZO_z_input_len
|
2008-02-13 20:54:58 +00:00
|
|
|
|
2008-03-28 02:49:44 +00:00
|
|
|
setup_data: .quad 0 # 64-bit physical pointer to
|
|
|
|
# single linked list of
|
|
|
|
# struct setup_data
|
|
|
|
|
2009-05-11 22:56:08 +00:00
|
|
|
pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
|
|
|
|
|
x86/KASLR: Update description for decompressor worst case size
The comment that describes the analysis for the size of the decompressor
code only took gzip into account (there are currently 6 other decompressors
that could be used). The actual z_extract_offset calculation in code was
already handling the correct maximum size, but this documentation hadn't
been updated. This updates the documentation, fixes several typos, moves
the comment to header.S, updates references, and adds a note at the end
of the decompressor include list to remind us about updating the comment
in the future.
(Instead of moving the comment to mkpiggy.c, where the calculation
is currently happening, it is being moved to header.S because
the calculations in mkpiggy.c will be removed in favor of header.S
calculations in a following patch, and it seemed like overkill to move
the giant comment twice, especially when there's already reference to
z_extract_offset in header.S.)
Signed-off-by: Baoquan He <bhe@redhat.com>
[ Rewrote changelog, cleaned up comment style, moved comments around. ]
Signed-off-by: Kees Cook <keescook@chromium.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Borislav Petkov <bp@suse.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: H.J. Lu <hjl.tools@gmail.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Yinghai Lu <yinghai@kernel.org>
Link: http://lkml.kernel.org/r/1461185746-8017-2-git-send-email-keescook@chromium.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-04-20 20:55:42 +00:00
|
|
|
#
|
|
|
|
# Getting to provably safe in-place decompression is hard. Worst case
|
|
|
|
# behaviours need to be analyzed. Here let's take the decompression of
|
|
|
|
# a gzip-compressed kernel as example, to illustrate it:
|
|
|
|
#
|
|
|
|
# The file layout of gzip compressed kernel is:
|
|
|
|
#
|
|
|
|
# magic[2]
|
|
|
|
# method[1]
|
|
|
|
# flags[1]
|
|
|
|
# timestamp[4]
|
|
|
|
# extraflags[1]
|
|
|
|
# os[1]
|
|
|
|
# compressed data blocks[N]
|
|
|
|
# crc[4] orig_len[4]
|
|
|
|
#
|
|
|
|
# ... resulting in +18 bytes overhead of uncompressed data.
|
|
|
|
#
|
|
|
|
# (For more information, please refer to RFC 1951 and RFC 1952.)
|
|
|
|
#
|
|
|
|
# Files divided into blocks
|
|
|
|
# 1 bit (last block flag)
|
|
|
|
# 2 bits (block type)
|
|
|
|
#
|
|
|
|
# 1 block occurs every 32K -1 bytes or when there 50% compression
|
|
|
|
# has been achieved. The smallest block type encoding is always used.
|
|
|
|
#
|
|
|
|
# stored:
|
|
|
|
# 32 bits length in bytes.
|
|
|
|
#
|
|
|
|
# fixed:
|
|
|
|
# magic fixed tree.
|
|
|
|
# symbols.
|
|
|
|
#
|
|
|
|
# dynamic:
|
|
|
|
# dynamic tree encoding.
|
|
|
|
# symbols.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# The buffer for decompression in place is the length of the uncompressed
|
|
|
|
# data, plus a small amount extra to keep the algorithm safe. The
|
|
|
|
# compressed data is placed at the end of the buffer. The output pointer
|
|
|
|
# is placed at the start of the buffer and the input pointer is placed
|
|
|
|
# where the compressed data starts. Problems will occur when the output
|
|
|
|
# pointer overruns the input pointer.
|
|
|
|
#
|
|
|
|
# The output pointer can only overrun the input pointer if the input
|
|
|
|
# pointer is moving faster than the output pointer. A condition only
|
|
|
|
# triggered by data whose compressed form is larger than the uncompressed
|
|
|
|
# form.
|
|
|
|
#
|
|
|
|
# The worst case at the block level is a growth of the compressed data
|
|
|
|
# of 5 bytes per 32767 bytes.
|
|
|
|
#
|
|
|
|
# The worst case internal to a compressed block is very hard to figure.
|
|
|
|
# The worst case can at least be bounded by having one bit that represents
|
|
|
|
# 32764 bytes and then all of the rest of the bytes representing the very
|
|
|
|
# very last byte.
|
|
|
|
#
|
|
|
|
# All of which is enough to compute an amount of extra data that is required
|
|
|
|
# to be safe. To avoid problems at the block level allocating 5 extra bytes
|
|
|
|
# per 32767 bytes of data is sufficient. To avoid problems internal to a
|
|
|
|
# block adding an extra 32767 bytes (the worst case uncompressed block size)
|
|
|
|
# is sufficient, to ensure that in the worst case the decompressed data for
|
|
|
|
# block will stop the byte before the compressed data for a block begins.
|
|
|
|
# To avoid problems with the compressed data's meta information an extra 18
|
|
|
|
# bytes are needed. Leading to the formula:
|
|
|
|
#
|
x86/boot: Calculate decompression size during boot not build
Currently z_extract_offset is calculated in boot/compressed/mkpiggy.c.
This doesn't work well because mkpiggy.c doesn't know the details of the
decompressor in use. As a result, it can only make an estimation, which
has risks:
- output + output_len (VO) could be much bigger than input + input_len
(ZO). In this case, the decompressed kernel plus relocs could overwrite
the decompression code while it is running.
- The head code of ZO could be bigger than z_extract_offset. In this case
an overwrite could happen when the head code is running to move ZO to
the end of buffer. Though currently the size of the head code is very
small it's still a potential risk. Since there is no rule to limit the
size of the head code of ZO, it runs the risk of suddenly becoming a
(hard to find) bug.
Instead, this moves the z_extract_offset calculation into header.S, and
makes adjustments to be sure that the above two cases can never happen,
and further corrects the comments describing the calculations.
Since we have (in the previous patch) made ZO always be located against
the end of decompression buffer, z_extract_offset is only used here to
calculate an appropriate buffer size (INIT_SIZE), and is not longer used
elsewhere. As such, it can be removed from voffset.h.
Additionally clean up #if/#else #define to improve readability.
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Signed-off-by: Baoquan He <bhe@redhat.com>
[ Rewrote the changelog and comments. ]
Signed-off-by: Kees Cook <keescook@chromium.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dave Young <dyoung@redhat.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vivek Goyal <vgoyal@redhat.com>
Cc: lasse.collin@tukaani.org
Link: http://lkml.kernel.org/r/1461888548-32439-4-git-send-email-keescook@chromium.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-04-29 00:09:05 +00:00
|
|
|
# extra_bytes = (uncompressed_size >> 12) + 32768 + 18
|
x86/KASLR: Update description for decompressor worst case size
The comment that describes the analysis for the size of the decompressor
code only took gzip into account (there are currently 6 other decompressors
that could be used). The actual z_extract_offset calculation in code was
already handling the correct maximum size, but this documentation hadn't
been updated. This updates the documentation, fixes several typos, moves
the comment to header.S, updates references, and adds a note at the end
of the decompressor include list to remind us about updating the comment
in the future.
(Instead of moving the comment to mkpiggy.c, where the calculation
is currently happening, it is being moved to header.S because
the calculations in mkpiggy.c will be removed in favor of header.S
calculations in a following patch, and it seemed like overkill to move
the giant comment twice, especially when there's already reference to
z_extract_offset in header.S.)
Signed-off-by: Baoquan He <bhe@redhat.com>
[ Rewrote changelog, cleaned up comment style, moved comments around. ]
Signed-off-by: Kees Cook <keescook@chromium.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Borislav Petkov <bp@suse.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: H.J. Lu <hjl.tools@gmail.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Yinghai Lu <yinghai@kernel.org>
Link: http://lkml.kernel.org/r/1461185746-8017-2-git-send-email-keescook@chromium.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-04-20 20:55:42 +00:00
|
|
|
#
|
|
|
|
# Adding 8 bytes per 32K is a bit excessive but much easier to calculate.
|
|
|
|
# Adding 32768 instead of 32767 just makes for round numbers.
|
|
|
|
#
|
|
|
|
# Above analysis is for decompressing gzip compressed kernel only. Up to
|
|
|
|
# now 6 different decompressor are supported all together. And among them
|
|
|
|
# xz stores data in chunks and has maximum chunk of 64K. Hence safety
|
|
|
|
# margin should be updated to cover all decompressors so that we don't
|
|
|
|
# need to deal with each of them separately. Please check
|
|
|
|
# the description in lib/decompressor_xxx.c for specific information.
|
|
|
|
#
|
|
|
|
# extra_bytes = (uncompressed_size >> 12) + 65536 + 128
|
|
|
|
|
x86/boot: Calculate decompression size during boot not build
Currently z_extract_offset is calculated in boot/compressed/mkpiggy.c.
This doesn't work well because mkpiggy.c doesn't know the details of the
decompressor in use. As a result, it can only make an estimation, which
has risks:
- output + output_len (VO) could be much bigger than input + input_len
(ZO). In this case, the decompressed kernel plus relocs could overwrite
the decompression code while it is running.
- The head code of ZO could be bigger than z_extract_offset. In this case
an overwrite could happen when the head code is running to move ZO to
the end of buffer. Though currently the size of the head code is very
small it's still a potential risk. Since there is no rule to limit the
size of the head code of ZO, it runs the risk of suddenly becoming a
(hard to find) bug.
Instead, this moves the z_extract_offset calculation into header.S, and
makes adjustments to be sure that the above two cases can never happen,
and further corrects the comments describing the calculations.
Since we have (in the previous patch) made ZO always be located against
the end of decompression buffer, z_extract_offset is only used here to
calculate an appropriate buffer size (INIT_SIZE), and is not longer used
elsewhere. As such, it can be removed from voffset.h.
Additionally clean up #if/#else #define to improve readability.
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Signed-off-by: Baoquan He <bhe@redhat.com>
[ Rewrote the changelog and comments. ]
Signed-off-by: Kees Cook <keescook@chromium.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dave Young <dyoung@redhat.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vivek Goyal <vgoyal@redhat.com>
Cc: lasse.collin@tukaani.org
Link: http://lkml.kernel.org/r/1461888548-32439-4-git-send-email-keescook@chromium.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-04-29 00:09:05 +00:00
|
|
|
#define ZO_z_extra_bytes ((ZO_z_output_len >> 12) + 65536 + 128)
|
|
|
|
#if ZO_z_output_len > ZO_z_input_len
|
|
|
|
# define ZO_z_extract_offset (ZO_z_output_len + ZO_z_extra_bytes - \
|
|
|
|
ZO_z_input_len)
|
|
|
|
#else
|
|
|
|
# define ZO_z_extract_offset ZO_z_extra_bytes
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The extract_offset has to be bigger than ZO head section. Otherwise when
|
|
|
|
* the head code is running to move ZO to the end of the buffer, it will
|
|
|
|
* overwrite the head code itself.
|
|
|
|
*/
|
|
|
|
#if (ZO__ehead - ZO_startup_32) > ZO_z_extract_offset
|
|
|
|
# define ZO_z_min_extract_offset ((ZO__ehead - ZO_startup_32 + 4095) & ~4095)
|
|
|
|
#else
|
|
|
|
# define ZO_z_min_extract_offset ((ZO_z_extract_offset + 4095) & ~4095)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_min_extract_offset)
|
|
|
|
|
2009-05-11 22:56:08 +00:00
|
|
|
#define VO_INIT_SIZE (VO__end - VO__text)
|
|
|
|
#if ZO_INIT_SIZE > VO_INIT_SIZE
|
x86/boot: Calculate decompression size during boot not build
Currently z_extract_offset is calculated in boot/compressed/mkpiggy.c.
This doesn't work well because mkpiggy.c doesn't know the details of the
decompressor in use. As a result, it can only make an estimation, which
has risks:
- output + output_len (VO) could be much bigger than input + input_len
(ZO). In this case, the decompressed kernel plus relocs could overwrite
the decompression code while it is running.
- The head code of ZO could be bigger than z_extract_offset. In this case
an overwrite could happen when the head code is running to move ZO to
the end of buffer. Though currently the size of the head code is very
small it's still a potential risk. Since there is no rule to limit the
size of the head code of ZO, it runs the risk of suddenly becoming a
(hard to find) bug.
Instead, this moves the z_extract_offset calculation into header.S, and
makes adjustments to be sure that the above two cases can never happen,
and further corrects the comments describing the calculations.
Since we have (in the previous patch) made ZO always be located against
the end of decompression buffer, z_extract_offset is only used here to
calculate an appropriate buffer size (INIT_SIZE), and is not longer used
elsewhere. As such, it can be removed from voffset.h.
Additionally clean up #if/#else #define to improve readability.
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Signed-off-by: Baoquan He <bhe@redhat.com>
[ Rewrote the changelog and comments. ]
Signed-off-by: Kees Cook <keescook@chromium.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dave Young <dyoung@redhat.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vivek Goyal <vgoyal@redhat.com>
Cc: lasse.collin@tukaani.org
Link: http://lkml.kernel.org/r/1461888548-32439-4-git-send-email-keescook@chromium.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-04-29 00:09:05 +00:00
|
|
|
# define INIT_SIZE ZO_INIT_SIZE
|
2009-05-11 22:56:08 +00:00
|
|
|
#else
|
x86/boot: Calculate decompression size during boot not build
Currently z_extract_offset is calculated in boot/compressed/mkpiggy.c.
This doesn't work well because mkpiggy.c doesn't know the details of the
decompressor in use. As a result, it can only make an estimation, which
has risks:
- output + output_len (VO) could be much bigger than input + input_len
(ZO). In this case, the decompressed kernel plus relocs could overwrite
the decompression code while it is running.
- The head code of ZO could be bigger than z_extract_offset. In this case
an overwrite could happen when the head code is running to move ZO to
the end of buffer. Though currently the size of the head code is very
small it's still a potential risk. Since there is no rule to limit the
size of the head code of ZO, it runs the risk of suddenly becoming a
(hard to find) bug.
Instead, this moves the z_extract_offset calculation into header.S, and
makes adjustments to be sure that the above two cases can never happen,
and further corrects the comments describing the calculations.
Since we have (in the previous patch) made ZO always be located against
the end of decompression buffer, z_extract_offset is only used here to
calculate an appropriate buffer size (INIT_SIZE), and is not longer used
elsewhere. As such, it can be removed from voffset.h.
Additionally clean up #if/#else #define to improve readability.
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Signed-off-by: Baoquan He <bhe@redhat.com>
[ Rewrote the changelog and comments. ]
Signed-off-by: Kees Cook <keescook@chromium.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dave Young <dyoung@redhat.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vivek Goyal <vgoyal@redhat.com>
Cc: lasse.collin@tukaani.org
Link: http://lkml.kernel.org/r/1461888548-32439-4-git-send-email-keescook@chromium.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-04-29 00:09:05 +00:00
|
|
|
# define INIT_SIZE VO_INIT_SIZE
|
2009-05-11 22:56:08 +00:00
|
|
|
#endif
|
x86/boot: Calculate decompression size during boot not build
Currently z_extract_offset is calculated in boot/compressed/mkpiggy.c.
This doesn't work well because mkpiggy.c doesn't know the details of the
decompressor in use. As a result, it can only make an estimation, which
has risks:
- output + output_len (VO) could be much bigger than input + input_len
(ZO). In this case, the decompressed kernel plus relocs could overwrite
the decompression code while it is running.
- The head code of ZO could be bigger than z_extract_offset. In this case
an overwrite could happen when the head code is running to move ZO to
the end of buffer. Though currently the size of the head code is very
small it's still a potential risk. Since there is no rule to limit the
size of the head code of ZO, it runs the risk of suddenly becoming a
(hard to find) bug.
Instead, this moves the z_extract_offset calculation into header.S, and
makes adjustments to be sure that the above two cases can never happen,
and further corrects the comments describing the calculations.
Since we have (in the previous patch) made ZO always be located against
the end of decompression buffer, z_extract_offset is only used here to
calculate an appropriate buffer size (INIT_SIZE), and is not longer used
elsewhere. As such, it can be removed from voffset.h.
Additionally clean up #if/#else #define to improve readability.
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Signed-off-by: Baoquan He <bhe@redhat.com>
[ Rewrote the changelog and comments. ]
Signed-off-by: Kees Cook <keescook@chromium.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dave Young <dyoung@redhat.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vivek Goyal <vgoyal@redhat.com>
Cc: lasse.collin@tukaani.org
Link: http://lkml.kernel.org/r/1461888548-32439-4-git-send-email-keescook@chromium.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-04-29 00:09:05 +00:00
|
|
|
|
2009-05-11 22:56:08 +00:00
|
|
|
init_size: .long INIT_SIZE # kernel initialization size
|
2013-08-01 12:33:26 +00:00
|
|
|
handover_offset: .long 0 # Filled in by build.c
|
2009-05-11 22:56:08 +00:00
|
|
|
|
2007-07-11 19:18:54 +00:00
|
|
|
# End of setup header #####################################################
|
|
|
|
|
2009-04-02 01:08:28 +00:00
|
|
|
.section ".entrytext", "ax"
|
2007-07-11 19:18:54 +00:00
|
|
|
start_of_setup:
|
|
|
|
# Force %es = %ds
|
|
|
|
movw %ds, %ax
|
|
|
|
movw %ax, %es
|
|
|
|
cld
|
|
|
|
|
2007-11-27 11:35:13 +00:00
|
|
|
# Apparently some ancient versions of LILO invoked the kernel with %ss != %ds,
|
|
|
|
# which happened to work by accident for the old code. Recalculate the stack
|
|
|
|
# pointer if %ss is invalid. Otherwise leave it alone, LOADLIN sets up the
|
|
|
|
# stack behind its own code, so we can't blindly put it directly past the heap.
|
2007-10-25 23:11:33 +00:00
|
|
|
|
|
|
|
movw %ss, %dx
|
|
|
|
cmpw %ax, %dx # %ds == %ss?
|
|
|
|
movw %sp, %dx
|
2007-11-27 11:35:13 +00:00
|
|
|
je 2f # -> assume %sp is reasonably set
|
|
|
|
|
|
|
|
# Invalid %ss, make up a new stack
|
|
|
|
movw $_end, %dx
|
|
|
|
testb $CAN_USE_HEAP, loadflags
|
|
|
|
jz 1f
|
|
|
|
movw heap_end_ptr, %dx
|
|
|
|
1: addw $STACK_SIZE, %dx
|
|
|
|
jnc 2f
|
|
|
|
xorw %dx, %dx # Prevent wraparound
|
2007-10-25 23:11:33 +00:00
|
|
|
|
2007-11-27 11:35:13 +00:00
|
|
|
2: # Now %dx should point to the end of our stack space
|
2007-10-25 23:11:33 +00:00
|
|
|
andw $~3, %dx # dword align (might as well...)
|
|
|
|
jnz 3f
|
|
|
|
movw $0xfffc, %dx # Make sure we're not zero
|
2007-11-27 11:35:13 +00:00
|
|
|
3: movw %ax, %ss
|
2007-10-25 23:11:33 +00:00
|
|
|
movzwl %dx, %esp # Clear upper half of %esp
|
|
|
|
sti # Now we should have a working stack
|
|
|
|
|
|
|
|
# We will have entered with %cs = %ds+0x20, normalize %cs so
|
|
|
|
# it is on par with the other segments.
|
|
|
|
pushw %ds
|
|
|
|
pushw $6f
|
|
|
|
lretw
|
|
|
|
6:
|
2007-07-11 19:18:54 +00:00
|
|
|
|
|
|
|
# Check signature at end of setup
|
|
|
|
cmpl $0x5a5aaa55, setup_sig
|
|
|
|
jne setup_bad
|
|
|
|
|
|
|
|
# Zero the bss
|
|
|
|
movw $__bss_start, %di
|
|
|
|
movw $_end+3, %cx
|
|
|
|
xorl %eax, %eax
|
|
|
|
subw %di, %cx
|
|
|
|
shrw $2, %cx
|
|
|
|
rep; stosl
|
|
|
|
|
|
|
|
# Jump to C code (should not return)
|
|
|
|
calll main
|
|
|
|
|
|
|
|
# Setup corrupt somehow...
|
|
|
|
setup_bad:
|
|
|
|
movl $setup_corrupt, %eax
|
|
|
|
calll puts
|
|
|
|
# Fall through...
|
|
|
|
|
|
|
|
.globl die
|
|
|
|
.type die, @function
|
|
|
|
die:
|
|
|
|
hlt
|
|
|
|
jmp die
|
|
|
|
|
2007-09-10 21:39:02 +00:00
|
|
|
.size die, .-die
|
2007-07-11 19:18:54 +00:00
|
|
|
|
|
|
|
.section ".initdata", "a"
|
|
|
|
setup_corrupt:
|
|
|
|
.byte 7
|
2007-07-26 23:10:22 +00:00
|
|
|
.string "No setup signature found...\n"
|