Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 349421
b: refs/heads/master
c: 99f857d
h: refs/heads/master
i:
  349419: acb56b7
v: v3
  • Loading branch information
David Woodhouse authored and H. Peter Anvin committed Jan 28, 2013
1 parent c1ddac9 commit 377917c
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 28 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: b607e2126705ca28ecf21aa051172882bbdaae8a
refs/heads/master: 99f857db8857aff691c51302f93648263ed07eb1
4 changes: 2 additions & 2 deletions trunk/arch/x86/boot/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ GCOV_PROFILE := n
$(obj)/bzImage: asflags-y := $(SVGA_MODE)

quiet_cmd_image = BUILD $@
cmd_image = $(obj)/tools/build $(obj)/setup.bin $(obj)/vmlinux.bin > $@
cmd_image = $(obj)/tools/build $(obj)/setup.bin $(obj)/vmlinux.bin $(obj)/zoffset.h > $@

$(obj)/bzImage: $(obj)/setup.bin $(obj)/vmlinux.bin $(obj)/tools/build FORCE
$(call if_changed,image)
Expand All @@ -92,7 +92,7 @@ targets += voffset.h
$(obj)/voffset.h: vmlinux FORCE
$(call if_changed,voffset)

sed-zoffset := -e 's/^\([0-9a-fA-F]*\) . \(startup_32\|input_data\|_end\|z_.*\)$$/\#define ZO_\2 0x\1/p'
sed-zoffset := -e 's/^\([0-9a-fA-F]*\) . \(startup_32\|startup_64\|efi_pe_entry\|efi_stub_entry\|input_data\|_end\|z_.*\)$$/\#define ZO_\2 0x\1/p'

quiet_cmd_zoffset = ZOFFSET $@
cmd_zoffset = $(NM) $< | sed -n $(sed-zoffset) > $@
Expand Down
6 changes: 3 additions & 3 deletions trunk/arch/x86/boot/compressed/head_32.S
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ ENTRY(startup_32)
#ifdef CONFIG_EFI_STUB
jmp preferred_addr

.balign 0x10
/*
* We don't need the return address, so set up the stack so
* efi_main() can find its arugments.
* efi_main() can find its arguments.
*/
ENTRY(efi_pe_entry)
add $0x4, %esp

call make_boot_params
Expand All @@ -52,7 +52,7 @@ ENTRY(startup_32)
pushl %ecx
sub $0x4, %esp

.org 0x30,0x90
ENTRY(efi_stub_entry)
add $0x4, %esp
call efi_main
cmpl $0, %eax
Expand Down
8 changes: 4 additions & 4 deletions trunk/arch/x86/boot/compressed/head_64.S
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,12 @@ ENTRY(startup_64)
*/
#ifdef CONFIG_EFI_STUB
/*
* The entry point for the PE/COFF executable is 0x210, so only
* legacy boot loaders will execute this jmp.
* The entry point for the PE/COFF executable is efi_pe_entry, so
* only legacy boot loaders will execute this jmp.
*/
jmp preferred_addr

.org 0x210
ENTRY(efi_pe_entry)
mov %rcx, %rdi
mov %rdx, %rsi
pushq %rdi
Expand All @@ -218,7 +218,7 @@ ENTRY(startup_64)
popq %rsi
popq %rdi

.org 0x230,0x90
ENTRY(efi_stub_entry)
call efi_main
movq %rax,%rsi
cmpq $0,%rax
Expand Down
81 changes: 63 additions & 18 deletions trunk/arch/x86/boot/tools/build.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ int is_big_kernel;

#define PECOFF_RELOC_RESERVE 0x20

unsigned long efi_stub_entry;
unsigned long efi_pe_entry;
unsigned long startup_64;

/*----------------------------------------------------------------------*/

static const u32 crctab32[] = {
Expand Down Expand Up @@ -132,7 +136,7 @@ static void die(const char * str, ...)

static void usage(void)
{
die("Usage: build setup system [> image]");
die("Usage: build setup system [zoffset.h] [> image]");
}

#ifdef CONFIG_EFI_STUB
Expand Down Expand Up @@ -206,30 +210,54 @@ static void update_pecoff_text(unsigned int text_start, unsigned int file_sz)
*/
put_unaligned_le32(file_sz - 512, &buf[pe_header + 0x1c]);

#ifdef CONFIG_X86_32
/*
* Address of entry point.
*
* The EFI stub entry point is +16 bytes from the start of
* the .text section.
* Address of entry point for PE/COFF executable
*/
put_unaligned_le32(text_start + 16, &buf[pe_header + 0x28]);
#else
/*
* Address of entry point. startup_32 is at the beginning and
* the 64-bit entry point (startup_64) is always 512 bytes
* after. The EFI stub entry point is 16 bytes after that, as
* the first instruction allows legacy loaders to jump over
* the EFI stub initialisation
*/
put_unaligned_le32(text_start + 528, &buf[pe_header + 0x28]);
#endif /* CONFIG_X86_32 */
put_unaligned_le32(text_start + efi_pe_entry, &buf[pe_header + 0x28]);

update_pecoff_section_header(".text", text_start, text_sz);
}

#endif /* CONFIG_EFI_STUB */


/*
* Parse zoffset.h and find the entry points. We could just #include zoffset.h
* but that would mean tools/build would have to be rebuilt every time. It's
* not as if parsing it is hard...
*/
#define PARSE_ZOFS(p, sym) do { \
if (!strncmp(p, "#define ZO_" #sym " ", 11+sizeof(#sym))) \
sym = strtoul(p + 11 + sizeof(#sym), NULL, 16); \
} while (0)

static void parse_zoffset(char *fname)
{
FILE *file;
char *p;
int c;

file = fopen(fname, "r");
if (!file)
die("Unable to open `%s': %m", fname);
c = fread(buf, 1, sizeof(buf) - 1, file);
if (ferror(file))
die("read-error on `zoffset.h'");
buf[c] = 0;

p = (char *)buf;

while (p && *p) {
PARSE_ZOFS(p, efi_stub_entry);
PARSE_ZOFS(p, efi_pe_entry);
PARSE_ZOFS(p, startup_64);

p = strchr(p, '\n');
while (p && (*p == '\r' || *p == '\n'))
p++;
}
}

int main(int argc, char ** argv)
{
unsigned int i, sz, setup_sectors;
Expand All @@ -241,7 +269,19 @@ int main(int argc, char ** argv)
void *kernel;
u32 crc = 0xffffffffUL;

if (argc != 3)
/* Defaults for old kernel */
#ifdef CONFIG_X86_32
efi_pe_entry = 0x10;
efi_stub_entry = 0x30;
#else
efi_pe_entry = 0x210;
efi_stub_entry = 0x230;
startup_64 = 0x200;
#endif

if (argc == 4)
parse_zoffset(argv[3]);
else if (argc != 3)
usage();

/* Copy the setup code */
Expand Down Expand Up @@ -299,6 +339,11 @@ int main(int argc, char ** argv)

#ifdef CONFIG_EFI_STUB
update_pecoff_text(setup_sectors * 512, sz + i + ((sys_size * 16) - sz));

#ifdef CONFIG_X86_64 /* Yes, this is really how we defined it :( */
efi_stub_entry -= 0x200;
#endif
put_unaligned_le32(efi_stub_entry, &buf[0x264]);
#endif

crc = partial_crc32(buf, i, crc);
Expand Down

0 comments on commit 377917c

Please sign in to comment.