efi: Suspicious size reduction in emalloc

It could happen on 32 bits architecture that the memory size really allocated
could be less than required. On 64 bits, allocate_pages may be called
more times than needed.

This closes bug #39.

Signed-off-by: Sylvain Gault <sylvain.gault@gmail.com>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
pxe: Export the initial stack and PXE(NV) structure, fix pxechn

Export the initial stack and PXE(NV) structure pointers properly, even
for users which need seg:offs.  Use this in pxechn.c rather than the
already-removed INT 22h AX=000Ah call.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Cc: Gene Cumm <gene.cumm@gmail.com>
efi: Fix PE header field rva_and_sizes_nr

The value of the field rva_and_sizes_nr is used by OVMF to check the
consistency of the PE file with respect to the field optional_hdr_sz. It
now have the right value.

Signed-off-by: Sylvain Gault <sylvain.gault@gmail.com>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
efi: Location, size and alignment of .text section

In the generated PE file, the section header for the .text section used
to address more than the whole file. Starting at offset 0 (before the
end of the headers) is illegal and is rejected by OVMF. Giving a size
greater than the actual file size is also illegal and rejected.

Moreover, the body of the PE file have to be aligned to at least 512
bytes. Hence, .text need to be aligned as well.

Signed-off-by: Sylvain Gault <sylvain.gault@gmail.com>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
efi: Remove buggy relocation in PE file

OVMF and probably other UEFI implementation refuse a file with a
relocation entry inside the headers. And since the dummy relocation
wasn't used at all, better remove it.

Moreover, the field base_relocation_table wasn't initialized properly,
leading to unpredictable bugs.

Signed-off-by: Sylvain Gault <sylvain.gault@gmail.com>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
efi: PE file size differ from in-memory size

PE headers code_sz and image_sz indicate more or less, the size of the
file and the size of the in-memory image. They are now given the right
value.

In the ELF format, only the program headers are reliable to determine
the actually needed part of the file and the in-memory size.

The .bss section should always be marked as NOLOAD for ld since its
content shouldn't be included into the binary file.

Signed-off-by: Sylvain Gault <sylvain.gault@gmail.com>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
efi: Useless relocation section in PE file

There is no need to have a relocation section that nothing points at.
The image is still seen as relocatable as long as the Characteristics of
the FileHeader do not say otherwise.

Signed-off-by: Sylvain Gault <sylvain.gault@gmail.com>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>