efi: Support booting 32-bit kernels from 64-bit EFI

The default scheme for booting Linux kernels should be to switch to
32-bit protected mode and jump to the start of the kernel image. The
kernel has always had the know-how to switch 64-bit capable CPUs into
64-bit mode if necessary. By using this scheme, we can transparently
boot either 32-bit or 64-bit kernels.

This change necessitated moving kernel_jump() to a .S file for both i386
and x86-64. Writing inline assembly is fun for about 5 minutes, but then
becomes monstrously tedious.

Cc: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
conio: Fix pollchar() for serial console

The check of the LSR value was inverted. This resulted in pollchar()
always claiming that there was data to be read from the serial console.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
load_linux: Add dprintf statements to aid debugging

It's useful to know why a kernel is failing to load. Sprinkle some
dprintf() statements with informative messages.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
load_linux: validate sanity of 'initrd_addr_max'

Some kernel headers have bogus 'initrd_addr_max' fields. This field
should never be zero. Set it to the old upper limit if unspecified.
Failure to set a non-zero value for the field results in a bogus
'memlimit' value, thereby unnecessarily reserving part of the memmap.

Cc: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
doc/ & txt/: Spelling fix

Also add octal note.

Reported-By: Ady <ady-sf@hotmail.com>
Signed-off-by: Gene Cumm <gene.cumm@gmail.com>
core: we only need one reset_idle()

We don't need both an assembly version of reset_idle and an
implementation in C. Having these two functions has led to a bug where
we may idle with interrupts disabled because an 'sti' is only performed
in the assembly version. This lead to a hang waiting for user input.

Cc: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
Merge branch 'doc-for-mfleming' of git://github.com/geneC/syslinux into elflink

Pull doc/ and txt/ spelling corrections from Gene Cumm,

* 'doc-for-mfleming' of git://github.com/geneC/syslinux:
  doc/ & txt/: Spelling fix
idle: enable interrupts before idling

Users are *still* reporting executing __idle() with interrupts disabled,
which ultimately leads to a hang. Just enable them explicitly before
idling.

Cc: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
idle: Consolidate idle implementations

Duplicate code is bad. Move all the idle code to C and delete the old
assembly stuff.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
Merge branch 'idle' into elflink
firmware: s/set_mode/text_mode/

We only ever use ->set_mode() to transition into text mode, so rename it
to something more suitable and drop the unused 'mode' argument.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
efi: workaround upstream gnu-efi compiler warnings

/usr/local/include/efi/efiapi.h:663:5: warning: function declaration isn’t a prototype [-Wstrict-prototypes]

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
efi: use unsigned long to represent addresses

This fixes a valid compiler warning on 64-bit about "cast from pointer
to integer of different size".

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
Merge tag 'syslinux-5.11-pre4' into firmware

syslinux-5.11-pre4
NEWS: Add entries for 6.01

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
mk: include $(GCCWARN) when building ELF objects

It's currently impossible to turn on dprintf() statements in
com32/modules because $(GCCWARN) isn't used as part of $(CFLAGS).

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
debug.c32: Dynamically enable/disable debug code at runtime

It's useful to be able to enable (and disable) debug code at runtime,
particularly for allowing users that are unable to build their own
Syslinux releases the chance to provide useful debugging output.

For example, say a user reports trouble with their PXE stack but doesn't
have a development environment setup to turn on the debug code
themselves. With this change you can simply request that they do,

    debug.c32 -e pxe_call unload_pxe open_file

to enable the debug in those functions. By only turning on code in
specific functions we reduce the chance of disrupting the buggy
behaviour and improve the signal to noise ratio for print statements.

To disable debug code use the -d flag,

    debug.c32 -d pxe_call

To use this new feature simply do,

    if (syslinux_debug_enabled) {
        debug1();
        debug2();
        ....
    }

from within the function you wish to add debug code. Note that this
feature is not limited to print statements - you can put any code within
the conditional, such as verifying a checksum or checking for memory
leaks.

The plan is to leave the dynamic debug code built in for all prereleases
and to turn it off for final releases.

People may still want to build with all dprintf() statements enabled,
and so a new symbol, DYNAMIC_DEBUG, was introduced rather than
repurposing the old DEBUG, DEBUG_STDIO and DEBUG_PORT symbols.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
mk: enable dynamic debug support

This will probably be disabled for releases, but it's definitely
worthwhile having enabled for all prereleases.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
Merge branch 'dynamic-debug' into elflink
efi: try harder to boot non-relocatable kernels

We don't absolutely need a kernel to be built with CONFIG_RELOCATABLE=y
in order to boot it. We can try and place the kernel image as its
preferred address, and if that fails and the image isn't relocatable,
then we can bail.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>