platform/upstream/syslinux.git
12 years agoldlinux: Tag __syslinux_init() as __constructor
Matt Fleming [Mon, 2 Apr 2012 11:53:59 +0000 (12:53 +0100)]
ldlinux: Tag __syslinux_init() as __constructor

We don't need to have control over exactly when __syslinux_init() is
executed, it just needs to be before we call syslinux_get_adv(). Let's
apply the __constructor tag to __syslinux_init() so that it is
executed before we enter ldlinux.c32's main(). This partially reverts
commit 487b67a9ce ("ldlinux: Remove __constructor attribute") because
we can now have __constructor functions in ldlinux.

By not calling __syslinux_init() directly we also avoid the following
build warning,

ldlinux.c: In function ‘main’:
ldlinux.c:131:2: warning: implicit declaration of function ‘__syslinux_init’

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
12 years agoldlinux: parse_kernel_type() parameter should be const
Matt Fleming [Mon, 2 Apr 2012 11:41:50 +0000 (12:41 +0100)]
ldlinux: parse_kernel_type() parameter should be const

Since we always pass a const char * to parse_kernel_type(), change the
type of the parameter accordingly to get rid of the following
warnings,

ldlinux.c:66:3: warning: passing argument 1 of ‘parse_kernel_type’ discards qual
ifiers from pointer target type
ldlinux.c:14:25: note: expected ‘char *’ but argument is of type ‘const char *’
ldlinux.c:80:2: warning: passing argument 1 of ‘parse_kernel_type’ discards qual
ifiers from pointer target type
ldlinux.c:14:25: note: expected ‘char *’ but argument is of type ‘const char *’
ldlinux.c: In function ‘main’:

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
12 years agoldlinux: Include headers for function prototypes
Matt Fleming [Mon, 2 Apr 2012 11:35:33 +0000 (12:35 +0100)]
ldlinux: Include headers for function prototypes

Include the appropriate headers to fix up the following build
warnings,

ldlinux.c: In function ‘parse_kernel_type’:
ldlinux.c:27:2: warning: implicit declaration of function ‘strncmp’
ldlinux.c: In function ‘load_kernel’:
ldlinux.c:64:2: warning: implicit declaration of function ‘find_label’
ldlinux.c:64:5: warning: assignment makes pointer from integer without a cast

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
12 years agoelflink: Add _module_unload() prototype to module.h
Matt Fleming [Mon, 2 Apr 2012 10:50:03 +0000 (11:50 +0100)]
elflink: Add _module_unload() prototype to module.h

Commit 8e0ed96bff7 ("elf: Support __constructor and __destructor")
failed to add a prototype for the newly introduced _module_unload()
function, which resulted in the following build warning being
introduced,

sys/module/exec.c: In function ‘spawn_load’:
sys/module/exec.c:222:3: warning: implicit declaration of function ‘_module_unload’

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
12 years agoelflink: Fix module_load() compiler warnings
Matt Fleming [Mon, 2 Apr 2012 10:24:04 +0000 (11:24 +0100)]
elflink: Fix module_load() compiler warnings

Correct the 'argv' argument to spawn_load() in module_load() and
include the header containing the spawn_load() prototype, thereby
fixing the following warning,

sys/module/elf_module.c: In function ‘module_load’:
sys/module/elf_module.c:534:5: warning: initialization makes integer from pointer without a cast
sys/module/elf_module.c:534:5: warning: initialization makes integer from pointer without a cast
sys/module/elf_module.c:535:5: warning: implicit declaration of function ‘spawn_load’

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
12 years agoelflink: Fix build warnings
Matt Fleming [Mon, 2 Apr 2012 10:07:56 +0000 (11:07 +0100)]
elflink: Fix build warnings

There's a lot of void * arithmetic going on in the ELF code that the
compiler warns about, i.e.

sys/module/common.c: In function ‘check_symbols’:
sys/module/common.c:325:44: warning: pointer of type ‘void *’ used in arithmetic

Cast the void * pointers to char * so that we can do byte arithmetic
on them.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
12 years agoelflink: Delete dump_elf_module()
Matt Fleming [Fri, 30 Mar 2012 14:19:07 +0000 (15:19 +0100)]
elflink: Delete dump_elf_module()

dump_elf_module() doesn't have any callers (it's call site is
commented out in module_load()) and it's definition currently emits
the following build warning,

In file included from exit.c:34:0:
../include/sys/module.h: In function ‘dump_elf_module’:
../include/sys/module.h:123:55: warning: unused parameter ‘module’

Just delete it. If anyone needs a similar function in future it is
trivial to write.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
12 years agosyslinux/idle.c: Fix build warnings from missing prototypes
Matt Fleming [Fri, 30 Mar 2012 13:58:41 +0000 (14:58 +0100)]
syslinux/idle.c: Fix build warnings from missing prototypes

Include core.h to fix the following build warnings,

syslinux/idle.c: In function ‘syslinux_reset_idle’:
syslinux/idle.c:41:5: warning: implicit declaration of function ‘reset_idle’
syslinux/idle.c: In function ‘syslinux_idle’:
syslinux/idle.c:46:5: warning: implicit declaration of function ‘__idle’

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
12 years agosys/fileclose.c: Fix build warning from missing prototype
Matt Fleming [Fri, 30 Mar 2012 12:22:40 +0000 (13:22 +0100)]
sys/fileclose.c: Fix build warning from missing prototype

Include fs.h to avoid the following warning,

sys/fileclose.c: In function ‘__file_close’:
sys/fileclose.c:42:2: warning: implicit declaration of function ‘close_file’

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
12 years agosys/fileread.c: Fix build warning from missing prototype
Matt Fleming [Fri, 30 Mar 2012 12:16:00 +0000 (13:16 +0100)]
sys/fileread.c: Fix build warning from missing prototype

Include the appropriate header to fix the following warning,

sys/fileread.c: In function ‘__file_get_block’:
sys/fileread.c:45:5: warning: implicit declaration of function ‘pmapi_read_file’

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
12 years agosys/open.c: Fix building warnings from missing prototype
Matt Fleming [Fri, 30 Mar 2012 12:09:16 +0000 (13:09 +0100)]
sys/open.c: Fix building warnings from missing prototype

Fix the following warning by including the appropriate header,

sys/open.c: In function ‘open’:
sys/open.c:67:5: warning: implicit declaration of function ‘open_file’

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
12 years agogetcwd.c: Include core_getcwd() prototype
Matt Fleming [Fri, 30 Mar 2012 12:07:12 +0000 (13:07 +0100)]
getcwd.c: Include core_getcwd() prototype

Fix the following warning by including the appropriate header,

getcwd.c: In function ‘getcwd’:
getcwd.c:10:5: warning: implicit declaration of function ‘core_getcwd’
getcwd.c:10:5: warning: return makes pointer from integer without a cast

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
12 years agocore: Partial revert of commit 9333426b and unify lmalloc()
Matt Fleming [Fri, 30 Mar 2012 11:45:33 +0000 (12:45 +0100)]
core: Partial revert of commit 9333426b and unify lmalloc()

The reason behind commit 9333426b ("elflink: fix the global naming for
lmalloc") seems to be that we need to avoid having two 'lmalloc'
symbols, one in the core and one in the com32 library.

Unfortunately, this commit introduced the following warning in
multiple places,

meminfo.c:47:2: warning: implicit declaration of function ‘lmalloc’
meminfo.c:47:9: warning: assignment makes pointer from integer without a cast
meminfo.c:93:5: warning: implicit declaration of function ‘free’
meminfo.c:93:5: warning: incompatible implicit declaration of built-in function ‘free’

Consolidate the implementations of lmalloc() so that it's suitable for
use both in the com32 library code and the core.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
12 years agoRemove core/ui.inc completely from Syslinux
Paulo Alcantara [Wed, 11 Apr 2012 23:39:05 +0000 (20:39 -0300)]
Remove core/ui.inc completely from Syslinux

The old UI used by Syslinux is no longer supported. The 32-bit environment
already provides us an awesome prompt.

All Syslinux variants do not depend on it anymore, thus they were
modified in order to support the new prompt provided by the ELF module
ldlinux.c32.

Signed-off-by: Paulo Alcantara <pcacjr@zytor.com>
12 years agoPXELINUX: call open_config() function before loading 32-bit environment
Paulo Alcantara [Wed, 11 Apr 2012 22:24:19 +0000 (19:24 -0300)]
PXELINUX: call open_config() function before loading 32-bit environment

ldlinux.c32 needs ConfigName variable to be set before jumping to 32-bit
ELF space. As pxe_open_config() is called from open_config() in
core/pxelinux.asm, it will set ConfigName variable accordingly.

Signed-off-by: Paulo Alcantara <pcacjr@zytor.com>
12 years agoPXELINUX: get rid of core/ui.inc file
Paulo Alcantara [Wed, 11 Apr 2012 03:52:50 +0000 (00:52 -0300)]
PXELINUX: get rid of core/ui.inc file

core/ui.inc is no longer used. As it used to contain the boot prompt
code, there is replacement of it, the enter_cmdline() function
(com32/elflink/ldlinux/ldlinux.c). There were some variables declared in
core/ui.inc that are used by core/pxelinux.asm, so those were all moved
out to core/pxelinux.asm as well.

Signed-off-by: Paulo Alcantara <pcacjr@zytor.com>
12 years agoPXELINUX: do not load 32-bit environment twice
Paulo Alcantara [Sun, 8 Apr 2012 19:33:16 +0000 (16:33 -0300)]
PXELINUX: do not load 32-bit environment twice

Calling load_env32() once, it should never return. If it does, then jump
to kaboom.

Signed-off-by: Paulo Alcantara <pcacjr@zytor.com>
12 years agolibinstaller: Avoid using <linux/ext2_fs.h>
H. Peter Anvin [Tue, 27 Mar 2012 05:51:09 +0000 (22:51 -0700)]
libinstaller: Avoid using <linux/ext2_fs.h>

Don't use <linux/ext2_fs.h> if we can avoid it.

The ioctl constants have been globalized and moved to <linux/fs.h>.
Use a private copy of ext2_fs.h from e2fsprogs with the ioctl
constants removed for the data structures.

Do at least attempt backward compatibility for old kernel headers, but
no real hope of proper operation there...

[ Doing this as a cherry-pick to unblock this branch ]

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Resolved Conflicts:

libinstaller/linuxioctl.h

12 years agoMakefile.private: remove obsolete preupload rule syslinux-5.00-pre1
H. Peter Anvin [Tue, 27 Mar 2012 21:47:04 +0000 (14:47 -0700)]
Makefile.private: remove obsolete preupload rule

Remove obsolete preupload rule, already deleted on the master branch.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
12 years agoversion: Bump date to 2012
H. Peter Anvin [Tue, 27 Mar 2012 21:44:23 +0000 (14:44 -0700)]
version: Bump date to 2012

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
12 years agokernel: Support multiple initrds
H. Peter Anvin [Tue, 27 Mar 2012 21:42:51 +0000 (14:42 -0700)]
kernel: Support multiple initrds

Support loading multiple initrd images separated by commas.  It still
doesn't correctly handle a secondary initrd= argument overriding the
first; not clear if that really was a good idea or if they would be
considered additive arguments.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
12 years agoRevert "ldlinux: Disable VGA graphics when loading a kernel"
H. Peter Anvin [Tue, 27 Mar 2012 21:41:55 +0000 (14:41 -0700)]
Revert "ldlinux: Disable VGA graphics when loading a kernel"

This reverts commit 87320b8de8f331b9c1810e98e24426e70b0ae29f.

That commit would change the mode before the kernel was actually
loaded, but would leave the console nonfunctional if it was vesacon.

We may need to do something similar eventually, but that one is not
correct.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
12 years agomenu: Make "menu clear" the default
H. Peter Anvin [Tue, 27 Mar 2012 21:39:46 +0000 (14:39 -0700)]
menu: Make "menu clear" the default

Make "menu clear" the default... it was sort of implicitly so at least
for vesamenu when using the old system, since we would end up zapping
the mode when any output happened, but that no longer is the case.

Also move the cursor to the top of the screen.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
12 years agocore: Abstract search_config() into search_dirs()
Matt Fleming [Tue, 13 Mar 2012 12:23:56 +0000 (12:23 +0000)]
core: Abstract search_config() into search_dirs()

The core currently abuses search_config() in order to locate
ldlinux.c32. The problem with this is that search_config() updates
ConfigName with the realpath of the file on every invocation. If we've
previously set ConfigName search_config() will overwrite this value.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
12 years agomk: Don't link against compiler's version of libgcc
Matt Fleming [Mon, 12 Mar 2012 19:40:33 +0000 (19:40 +0000)]
mk: Don't link against compiler's version of libgcc

Syslinux provides its own copy of libgcc functions in
com32/lib/libgcc, so we don't need to link against the version
provided by the compiler. What's worse, the behaviour is different
between the two versions.

This caused problems, for example, when parsing the TOTALTIMEOUT
config directive in com32/menu because of the following calculation,

totaltimeout = (atoll(skipspace(p + 13)) * CLK_TCK + 9) / 10;

which invokes __divdi3() as provided by libgcc. The results returned
by the Syslinux and compiler's copy of libgcc differ, leading to
differences in behaviour.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
12 years agoldlinux: Don't alloc initramfs unless initrd= is specified
Matt Fleming [Fri, 9 Mar 2012 12:49:50 +0000 (12:49 +0000)]
ldlinux: Don't alloc initramfs unless initrd= is specified

It only makes sense to allocate memory for 'initramfs' if an initrd=
argument was on the command line, otherwise we're wasting memory.

Furthermore needlessly allocating 'initramfs' actually caused old
kernels, such as memtest86, to fail to run because of the following
check in syslinux_boot_kernel(),

    if (initramfs && hdr.version < 0x0200)
        goto bail;              /* initrd/initramfs not supported */

Move the allocation after we've checked for and found an initrd=
argument.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
12 years agoldlinux: Disable VGA graphics when loading a kernel
Matt Fleming [Fri, 9 Mar 2012 10:53:52 +0000 (10:53 +0000)]
ldlinux: Disable VGA graphics when loading a kernel

The state of the graphics hardware is unknown when we're about to load
a new kernel. It could be running in VGA mode, so let's disable VGA
graphics before passing control to the kernel.

The old assembly version of this code made extensive used of
writestr(), which always calls vgaclearmode(). In the C version we're
using printf() and so need to call vgaclearmode() directly. Doing it
directly has the added advantage of documenting exactly where we need
to reset the graphics hardware.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
12 years agoldlinux: Make the default execute type KT_KERNEL
Matt Fleming [Tue, 13 Mar 2012 09:39:14 +0000 (09:39 +0000)]
ldlinux: Make the default execute type KT_KERNEL

Default to trying to boot a linux kernel image, which was the
behaviour of the old asm image file loader.

Note that we don't need to go through __intcall() to load a kernel as
the dynamic linker will fixup any references to the kernel load
functions for us at runtime. Furthermore, modules invoking execute()
could be located anywhere in the 32-bit address space and may not be
able to represent their pointer arguments with SEG() and OFFS(), so
using the comboot API may not even work.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
12 years agoldlinux: Avoid initialised data memory corruption
Matt Fleming [Wed, 7 Mar 2012 15:18:51 +0000 (15:18 +0000)]
ldlinux: Avoid initialised data memory corruption

We can't realloc() 'PATH' because realloc() may just extend the
malloc'd region if the adjacent region is free, as opposed to
allocating a new region and then copying the data. This behaviour is
fine in most circumstances but not with initialised string data, such
as 'PATH'. The reason is that other string data pointers may point to
characters in 'PATH' and if we modify it after realloc()'ing, we'll
appear to corrupt unrelated string data.

For example, the string "/" is used in chdir() and the address of that
string is the last "/" in 'PATH'. If we realloc() and then append
"foo" to 'PATH' the string pointer in chdir() will now point to "/foo".

Initialise 'PATH' at runtime using malloc() and free() to avoid
corrupting string data.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
12 years agoldlinux: chdir to the APPEND str when parsing a CONFIG directive
Matt Fleming [Tue, 13 Mar 2012 10:06:59 +0000 (10:06 +0000)]
ldlinux: chdir to the APPEND str when parsing a CONFIG directive

If an APPEND directive was specified for a CONFIG label then we need
to chdir to that directory after parsing the new config file.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
12 years agocom32: Delete execute.c and use the one from ldlinux
Matt Fleming [Tue, 13 Mar 2012 09:58:26 +0000 (09:58 +0000)]
com32: Delete execute.c and use the one from ldlinux

ldlinux provides us with an execute.c and all the functions that we
need, there's no point in duplicating the code in com32/menu.

Also, the copy in ldlinux doesn't use __com32.cs_bounce. Using
cs_bounce no longer works with dynamic ELF modules because we don't
have such tight control over the address space. Instead, memory must
be allocated dynamically or reserved as part of the object file.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
12 years agoelflink: Don't use strcmp on a non-NUL terminated string
Matt Fleming [Thu, 1 Mar 2012 17:23:57 +0000 (17:23 +0000)]
elflink: Don't use strcmp on a non-NUL terminated string

The syslinux implementation of strcmp() only checks for NUL in the
first argument and will use any NULs in the second argument for
comparison with the corresponding character in the first string. This
caused problems because at the time strcmp() is called 'path' isn't
NUL-terminated. Since we're only checking the first character of
'path' just code it explicitly.

This bug caused some modules not to load when resolving module
dependencies via the ELF DT_NEEDED field because the "." in the PATH
lookup code wouldn't be expanded to the current working directory. For
example, instead of expanding to "/foo/bar" if /foo was the cwd, the
path would be ".bar".

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
12 years agoldlinux: Loading a config file should cause re-initialisation
Matt Fleming [Tue, 13 Mar 2012 09:37:57 +0000 (09:37 +0000)]
ldlinux: Loading a config file should cause re-initialisation

There are a number of initialisation steps that need to be performed
*every* time a config file is loaded. Reload ldlinux.c32 so that we
can re-initialise the environment whenever a new config file is
loaded. This involves unloading all the modules that have been loaded
since ldlinux.c32. Luckily the list of loaded modules is sorted by
load order, which means it's trivial to "pop" them from the front of
the list.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
12 years agoelf: Support __constructor and __destructor
Matt Fleming [Thu, 22 Mar 2012 15:31:43 +0000 (15:31 +0000)]
elf: Support __constructor and __destructor

The old way of specifying functions that need to be run before/after a
main function has never worked for ELF modules. Instead, the only way
to get similiar behaviour was by using the MODULE_INIT() and
MODULE_EXIT() macros, but no one seems to have bothered converting the
old __constructor users over. Anyway, the old way is superior because
it allows multiple functions be specified. Delete the MODULE_* macros
as there's only one user of them in the entire tree.

We can also get rid of the UNKNOWN_MODULE constant because now a
module doesn't need a __module_init_ptr symbol to be classed as a
library - if a module isn't an executable, it's a library, there's no
such thing as an unknown type.

It's no longer necessary to explicitly call
__syslinux_get_ipappend_strings() from ldlinux.c because the
__constructor tag on the version in com32/lib/syslinux will take care
of invoking it before ldlinux.c32's main() is executed.

Also, since we've refactored unload_module() to now run a module's
destructors let's minimise the number of callers by deleting
load_library() and unload_library(), which were only called by the
test module in com32/elflink.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
12 years agocore: Shrink core/ldlinux.sys to be under 64K bytes
Matt Fleming [Tue, 20 Mar 2012 16:27:17 +0000 (16:27 +0000)]
core: Shrink core/ldlinux.sys to be under 64K bytes

It would seem that running from a btrfs file system has been broken
for some time. The reason is that core/ldlinux.sys has grown
substantially, resulting in it weighing in at a whopping 88K bytes and
no longer fitting within the first 64K segment of a btrfs file system.

This huge size stems from the fact that the core links with
libcom32min.a because it requires various symbols contained within
that archive but it includes and exports *all* the symbols from
libcom32min.a. The reasoning behind this design decision is that when
a module is loaded any undefined symbols that are defined in
libcom32min.a can be resolved at runtime by the core, without the
module also needing to statically link against libcom32min.a.
Unfortunately doing this has increased the size of the core beyond
acceptable limits, such that booting from a btrfs file system no
longer works.

This commit links ldlinux.c32 against libcom32min.a so that now
ldlinux.c32 exports all the symbols contained within the
archive. Since we will always load ldlinux.c32 before any other
modules, any undefined symbols will now be resolved by ldlinux.c32
instead of the core. ldlinux.c32 isn't subject to same size
constraints as the core, e.g. fitting within 64K.

Here are the sizes in bytes before and after this commit,

Before:
        33806   com32/elflink/ldlinux/ldlinux.c32
        87749   core/ldlinux.sys

After:
        393871  com32/elflink/ldlinux/ldlinux.c32
        45516   core/ldlinux.sys

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
12 years agoldlinux: Fix detection of function keys
Matt Fleming [Thu, 1 Mar 2012 11:54:13 +0000 (11:54 +0000)]
ldlinux: Fix detection of function keys

__get_key() directly calls getchar() but doesn't properly detect when
a function key such as F1, F2, etc has been entered. Despite the
previous commit to cli.c which read,

    ldlinux: Accept commands from the serial console

    To mimic the old (pre-elflink) command-line interface behaviour let's
    use getchar() instead of reading from stdin. This way, if the user
    types a command on the serial console it will actually be executed.

I can't see how get_key() fails to detect input on the serial
console. So let's revert to calling get_key() because it actually
handles the detection of function keys.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
12 years agocore: Check for func key in getchar()
Matt Fleming [Tue, 28 Feb 2012 21:06:38 +0000 (21:06 +0000)]
core: Check for func key in getchar()

We need to return the value stored in ah after reading from the
keyboard with __intcall(0x16, ...) otherwise we won't properly detect
function keys such as F1, F2, etc.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
12 years agocore: Delete the aux segment
Matt Fleming [Thu, 16 Feb 2012 12:12:50 +0000 (12:12 +0000)]
core: Delete the aux segment

We don't need to use a special aux segment because we can represent
'fontbuf' with OFFS() and SEG(). We're guaranteed to be able to break
the 32-bit pointer up with these macros because we control where in
the address space the core is loaded. (Not all 32-bit pointers can be
represented with OFFS() and SEG(), only addresses in the range
0..0xFFFFF.)

This fixes the breakage that was introduced in commit 14531c47bc95
("core: Delete code that is duplicated in ldlinux").

This allows the default font to be displayed. Previously junk was
being returned in the COMBOOT API call to query the userfont, leading
the caller to believe that a user font was installed even when it
wasn't.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
12 years agocore: Only adjust screen if we're in text mode
Matt Fleming [Tue, 14 Feb 2012 13:34:00 +0000 (13:34 +0000)]
core: Only adjust screen if we're in text mode

A bug was introduced in commit 9f51b69d ("core: Reimplement lots asm
code in C") when converting the old asm comapi_usingvga function into
C. We only want to adjust the screen if we're not using VGA.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
12 years agocom32/menu: vesamenu.c32 and menu.c32 require multiple obj files
Matt Fleming [Mon, 13 Feb 2012 14:27:36 +0000 (14:27 +0000)]
com32/menu: vesamenu.c32 and menu.c32 require multiple obj files

The standard %.c32 rule in mk/elf.mk doesn't work for vesamenu.c32 and
menu.c32 because they need multiple object files to be linked. Replace
the *.elf targets with *.c32 because .c32 *IS* an ELF file now.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
12 years agoldlinux: Parse kernel type for labels
Matt Fleming [Thu, 9 Feb 2012 10:15:38 +0000 (10:15 +0000)]
ldlinux: Parse kernel type for labels

We need to parse the kernel type for labels aswell as things entered
on the cmdline, instead of always passing KT_KERNEL or KT_NONE to
execute(). Move the logic into a new helper function.

This fixes a bug where an incorrect kernel type would be passed to
execute() if anything other than a linux kernel (such as a .bin) was
specified in a LABEL's KERNEL argument, which resulted in the file not
being executed.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
12 years agoldlinux: Initialise 'p' before using it.
Matt Fleming [Thu, 15 Dec 2011 20:47:00 +0000 (20:47 +0000)]
ldlinux: Initialise 'p' before using it.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
12 years agoRevert "core: remove redundant zalloc() definition"
H. Peter Anvin [Thu, 15 Dec 2011 18:47:41 +0000 (10:47 -0800)]
Revert "core: remove redundant zalloc() definition"

This reverts commit 46b993449264a2332427a165b4c77e400a053178.

Build failure was due to a non-clean tree.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
12 years agocore: remove redundant zalloc() definition
H. Peter Anvin [Wed, 14 Dec 2011 22:00:21 +0000 (14:00 -0800)]
core: remove redundant zalloc() definition

Remove a redundant definition of zalloc() which causes a compile
failure.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
12 years agoldlinux: Accept commands from the serial console
Matt Fleming [Fri, 25 Nov 2011 16:22:44 +0000 (16:22 +0000)]
ldlinux: Accept commands from the serial console

To mimic the old (pre-elflink) command-line interface behaviour let's
use getchar() instead of reading from stdin. This way, if the user
types a command on the serial console it will actually be executed.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
12 years agoldlinux: Add eprintf() to print to VGA and serial
Matt Fleming [Fri, 25 Nov 2011 15:54:48 +0000 (15:54 +0000)]
ldlinux: Add eprintf() to print to VGA and serial

printf() is used heavily in the ldlinux code but that only displays
things on the VGA console, not on serial. Introduce eprintf(), which
gives us the benefit of format strings but will also print to both VGA
and serial.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
12 years agoldlinux: Don't return previous command if user pressenter enter
Matt Fleming [Fri, 25 Nov 2011 15:36:55 +0000 (15:36 +0000)]
ldlinux: Don't return previous command if user pressenter enter

If the user presses enter at the command prompt then simply print the
command prompt again on a newline - don't re-execute the previous
command.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
12 years agoelflink: Include '\n' when printing error messages
Matt Fleming [Fri, 25 Nov 2011 15:09:11 +0000 (15:09 +0000)]
elflink: Include '\n' when printing error messages

We need to print a newline character at the end of our error messages
otherwise the syslinux command prompt may overwrite them, making them
impossible to see.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
12 years agoldlinux: Make tab-completion output same as pre-elflink
Matt Fleming [Wed, 9 Nov 2011 13:19:54 +0000 (13:19 +0000)]
ldlinux: Make tab-completion output same as pre-elflink

To maintain compatability with the old pre-elflink command line code,
the list of potential labels should all be printed on one line, not
one per line.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
12 years agocore: Split core console code into separate libs
Matt Fleming [Fri, 4 Nov 2011 15:02:14 +0000 (15:02 +0000)]
core: Split core console code into separate libs

When the console code was written in asm ldlinux.asm, isolinux.asm and
pxelinux.asm simply included the correct console I/O files (rawcon.inc
and plaincon.inc) but now that these files are implemented in C we
need another way to link against the correct functions.

Create separate libraries for linking ldlinux, isolinux and pxelinux
against.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
12 years agopxelinux: Call load_env32()
Matt Fleming [Fri, 4 Nov 2011 14:25:20 +0000 (14:25 +0000)]
pxelinux: Call load_env32()

Execute the elflink environment.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
12 years agocore: Delete code that is duplicated in ldlinux
Matt Fleming [Tue, 24 May 2011 09:45:51 +0000 (10:45 +0100)]
core: Delete code that is duplicated in ldlinux

Lots of code that used to be implemented in the core is now
implemented in ldlinux, but code from core was never deleted. Purge
this code.

Also, move all com32 loading to ldlinux since we need to be able to do
various command line things (which are no longer available in the
core).

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
12 years agocore: Reimplement writestr in C
Matt Fleming [Wed, 19 Oct 2011 09:02:42 +0000 (10:02 +0100)]
core: Reimplement writestr in C

Implement writestr in C instead of asm and move writestr.inc into
modules/ because it's required by modules/ver.asm.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
12 years agocore: Reimplement lots asm code in C
Matt Fleming [Tue, 18 Oct 2011 12:13:06 +0000 (13:13 +0100)]
core: Reimplement lots asm code in C

There is an awful lot of code currently implemented in assembly when
it could just as easily be implemented in C. Having it in C makes it
much easier to share code between the BIOS and forthcoming EFI
firmware backend. The following code fragments have been rewritten,

  - timer initialisation
  - adjust_screen()
  - check_esapes() and mem_init()
  - conio.inc
  - plaincon.inc
  - cleanup.inc
  - serirq.inc
  - font.inc
  - graphics
  - writehex

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
12 years agocom32: Add unhexchar
Matt Fleming [Wed, 18 May 2011 14:55:21 +0000 (15:55 +0100)]
com32: Add unhexchar

Add a C implementation of unhexchar() for use in C code. This
implementation should be an exact duplicate of the old asm version.

Signed-off-by: Matt Fleming <matt.fleming@linux.intel.com>
13 years agoMerge remote-tracking branch 'mfleming/for-hpa/elflink/ldlinux' into elflink
H. Peter Anvin [Thu, 28 Jul 2011 21:02:58 +0000 (14:02 -0700)]
Merge remote-tracking branch 'mfleming/for-hpa/elflink/ldlinux' into elflink

13 years agopxelinux: open_file() returns a non-negative handle
Matt Fleming [Tue, 12 Jul 2011 15:21:37 +0000 (16:21 +0100)]
pxelinux: open_file() returns a non-negative handle

The usage of open_file() is wrong in core/fs/pxe/pxe.c. Any
non-negative return value indicates success, not just a return value
of zero.

This bug was introduced in commit ba4fefa9b52b "core: change
load_config() to open_config()". The bug causes pxelinux to fail to
open configuration files.

Signed-off-by: Matt Fleming <matt.fleming@linux.intel.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
13 years agopxelinux: open_file() returns a non-negative handle
Matt Fleming [Tue, 12 Jul 2011 15:12:48 +0000 (16:12 +0100)]
pxelinux: open_file() returns a non-negative handle

The usage of open_file() is wrong in core/fs/pxe/pxe.c. Any
non-negative return value indicates success, not just a return value
of zero.

This bug was introduced in commit ba4fefa9b52b "core: change
load_config() to open_config()". The bug causes pxelinux to fail to
open configuration files.

Signed-off-by: Matt Fleming <matt.fleming@linux.intel.com>
13 years agocore: Fix ldlinux.c32 failing to load when not installed in "/"
Matt Fleming [Tue, 12 Jul 2011 10:52:05 +0000 (11:52 +0100)]
core: Fix ldlinux.c32 failing to load when not installed in "/"

Currently, if syslinux is installed in a directory other than "/" we
will fail to load ldlinux.c32.

Because we know where we were installed the simplest fix is to chdir()
to the installation directory before attempting to load
ldlinux.c32. This requires us to add "." to PATH so that we look in
the current working directory when loading ELF modules.

Changing to the install directory needs to handled differently for
different file systems, which is the reason behind the new file system
operation, .chdir_start(). Disk-based Syslinux variants should use
generic_chdir_start() to chdir() to CurrentDirName, which is the
installation path. By using this new fs operation, we can load
ldlinux.c32 when we expand the "."  in PATH, without having to search
the entire filesystem for it. However, iso9660 file systems still
require us to search some directories because it has no notion of an
installation directory.

Previously, changing into the install directory was handled when
opening the config file, but because the config file parser is now
part of the ldlinux.c32 ELF module, it needs to be done much earlier.

Reported-by: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: Matt Fleming <matt.fleming@linux.intel.com>
13 years agoMerge branch 'DT_NEEDED-module-deps' into for-hpa/elflink/ldlinux
Matt Fleming [Tue, 7 Jun 2011 19:12:36 +0000 (20:12 +0100)]
Merge branch 'DT_NEEDED-module-deps' into for-hpa/elflink/ldlinux

13 years agoMerge branch 'PATH-based-search' into for-hpa/elflink/ldlinux
Matt Fleming [Tue, 7 Jun 2011 19:12:17 +0000 (20:12 +0100)]
Merge branch 'PATH-based-search' into for-hpa/elflink/ldlinux

Conflicts:
com32/elflink/ldlinux/readconfig.c

13 years agoMerge branch 'fs-config' into for-hpa/elflink/ldlinux
Matt Fleming [Tue, 7 Jun 2011 19:10:59 +0000 (20:10 +0100)]
Merge branch 'fs-config' into for-hpa/elflink/ldlinux

Conflicts:
com32/elflink/ldlinux/readconfig.c

13 years agoMerge branch 'pxelinux' into for-hpa/elflink/ldlinux
Matt Fleming [Tue, 7 Jun 2011 19:06:01 +0000 (20:06 +0100)]
Merge branch 'pxelinux' into for-hpa/elflink/ldlinux

Conflicts:
core/pxelinux.asm

13 years agoldlinux: Support "kbdmap"
Matt Fleming [Fri, 27 May 2011 16:57:32 +0000 (17:57 +0100)]
ldlinux: Support "kbdmap"

Add support to the ldlinux config file parser for the "kbdmap"
directive.

Signed-off-by: Matt Fleming <matt.fleming@linux.intel.com>
13 years agoldlinux: Support "font"
Matt Fleming [Fri, 27 May 2011 16:57:05 +0000 (17:57 +0100)]
ldlinux: Support "font"

Add support for parsing the "font" config directive to ldlinux.

Signed-off-by: Matt Fleming <matt.fleming@linux.intel.com>
13 years agoldlinux: Parse "display" in config files
Matt Fleming [Fri, 27 May 2011 16:49:39 +0000 (17:49 +0100)]
ldlinux: Parse "display" in config files

Teach ldlinux to parse the "display" directive.

Signed-off-by: Matt Fleming <matt.fleming@linux.intel.com>
13 years agoldlinux: Add support for parsing "serial" config directive
Matt Fleming [Fri, 27 May 2011 16:10:32 +0000 (17:10 +0100)]
ldlinux: Add support for parsing "serial" config directive

Signed-off-by: Matt Fleming <matt.fleming@linux.intel.com>
13 years agoldlinux: Use DT_NEEDED for module dependencies
Matt Fleming [Mon, 6 Jun 2011 13:12:45 +0000 (14:12 +0100)]
ldlinux: Use DT_NEEDED for module dependencies

The ELF file format uses DT_NEEDED entries in the dynamic section to
name any shared library dependencies. Instead of rolling our own
dependency logic via the modules.dep file and elf_gen_dep.sh script
use the DT_NEEDED entries.

Signed-off-by: Matt Fleming <matt.fleming@linux.intel.com>
13 years agoldlinux: Use open_config() to open config files
Matt Fleming [Mon, 6 Jun 2011 21:45:33 +0000 (22:45 +0100)]
ldlinux: Use open_config() to open config files

Instead of duplicating the logic for finding config files on different
filesystems in both ldlinux/readconfig.c and core/fs/* use the
open_config() wrapper that calls into the fs-specific open_config().

Signed-off-by: Matt Fleming <matt.fleming@linux.intel.com>
13 years agocore: Return a file descriptor from open_config()
Matt Fleming [Mon, 6 Jun 2011 21:17:03 +0000 (22:17 +0100)]
core: Return a file descriptor from open_config()

Wrap open_config() the same way that open() wraps open_file(). The
only user of open_config() requires access to a file descriptor so it
makes sense to return a file descriptor.

The file handle implementation is a historic piece of code and this
patch tries to hide it as they will likely be removed at a future
point in time. Furthermore, the file handle code is very core-specific
and should not be exposed to any callers of open_config().

Signed-off-by: Matt Fleming <matt.fleming@linux.intel.com>
13 years agocore: open_file() returns a non-negative handle id
Matt Fleming [Mon, 6 Jun 2011 17:19:02 +0000 (18:19 +0100)]
core: open_file() returns a non-negative handle id

We currently only take the success path if open_file() returns 0 but
open_file() returns a handle ID which is a non-negative number.

Signed-off-by: Matt Fleming <matt.fleming@linux.intel.com>
13 years agoldlinux: PATH-based module lookup
Matt Fleming [Mon, 6 Jun 2011 10:09:42 +0000 (11:09 +0100)]
ldlinux: PATH-based module lookup

Add support for specifying directories to search when loading
modules. A new config directive, "PATH", instructs the module loading
code to search the directories listed in a colon-separated list when
loading a module.

Signed-off-by: Matt Fleming <matt.fleming@linux.intel.com>
13 years agocore: change load_config() to open_config()
H. Peter Anvin [Sat, 28 May 2011 00:45:59 +0000 (17:45 -0700)]
core: change load_config() to open_config()

Change load_config() to open_config(), which is a method that works
just like open_file().  This we can use to get the original
configuration file.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
13 years agocore: fix warnings in core/mem/init.c
H. Peter Anvin [Sat, 28 May 2011 00:45:22 +0000 (17:45 -0700)]
core: fix warnings in core/mem/init.c

Fix warnings (that block -Werror) in core/mem/init.c

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
13 years agocore.h: add a few include files needed pretty much everywhere
H. Peter Anvin [Sat, 28 May 2011 00:44:48 +0000 (17:44 -0700)]
core.h: add a few include files needed pretty much everywhere

Some include files we might as well centralize...

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
13 years agocore: Load the 32-bit environment at startup
Matt Fleming [Fri, 27 May 2011 16:09:27 +0000 (17:09 +0100)]
core: Load the 32-bit environment at startup

Do the same as the other Syslinux variants and initialise the 32-bit
environment when we boot.

Signed-off-by: Matt Fleming <matt.fleming@linux.intel.com>
13 years agoldlinux: Add support for parsing pxeretry option
Matt Fleming [Wed, 25 May 2011 22:29:05 +0000 (23:29 +0100)]
ldlinux: Add support for parsing pxeretry option

Signed-off-by: Matt Fleming <matt.fleming@linux.intel.com>
13 years agoldlinux: Initialise ipappend strings
Matt Fleming [Wed, 25 May 2011 19:26:23 +0000 (20:26 +0100)]
ldlinux: Initialise ipappend strings

Previouly __syslinux_get_ipappend_strings() was called as a
__constructor. However, as constructors are executed before we load
any ELF modules we need to explicitly call this function to initialise
the ipappend string.

Signed-off-by: Matt Fleming <matt.fleming@linux.intel.com>
13 years agoldlinux: Fix "prompt" config option parsing
Matt Fleming [Wed, 25 May 2011 14:35:53 +0000 (15:35 +0100)]
ldlinux: Fix "prompt" config option parsing

Previously, we were looking for the value of the prompt option 8
characters after the first 'p', clearly since "prompt" is only 6
characters we should be searching after the sixth character.

I noticed this bug when specifying "prompt 1" in my config file and
Syslinux still tried to boot the default kernel.

Signed-off-by: Matt Fleming <matt.fleming@linux.intel.com>
13 years agoldlinux: Remove __constructor attribute
Matt Fleming [Wed, 25 May 2011 07:45:37 +0000 (08:45 +0100)]
ldlinux: Remove __constructor attribute

The __constructor tag only makes sense in the core as the constructor
functions are executed from load_env32(), before any modules have been
loaded. Therefore, applying __constructor to code inside ldlinux is
pointless as unless the functions are called explicitly, they will
never be executed.

Signed-off-by: Matt Fleming <matt.fleming@linux.intel.com>
13 years agoldlinux: Add support for Auxillary Data Vector
Matt Fleming [Wed, 25 May 2011 07:39:47 +0000 (08:39 +0100)]
ldlinux: Add support for Auxillary Data Vector

Move all the code for the ADV into ldlinux so that it doesn't have any
dependencies on other modules.

We also need a way to initialize the ADV from ldlinux, so add another
vector to the comboot API.

Signed-off-by: Matt Fleming <matt.fleming@linux.intel.com>
13 years agoldlinux: Add localboot support
Matt Fleming [Tue, 24 May 2011 10:54:10 +0000 (11:54 +0100)]
ldlinux: Add localboot support

Add a few tweaks to enable ldlinux to localboot a hard disk. Most of
the support was already there, there were just a few bug fixes in
execute().

Signed-off-by: Matt Fleming <matt.fleming@linux.intel.com>
13 years agoldlinux: Search in isolinux/ directory for config files
Matt Fleming [Tue, 24 May 2011 10:37:49 +0000 (11:37 +0100)]
ldlinux: Search in isolinux/ directory for config files

If we're running from an ISO image we should be looking in the
isolinux/ directory for isolinux.cfg, not in the top-level directory.

Signed-off-by: Matt Fleming <matt.fleming@linux.intel.com>
13 years agohdt: libmenu.a no longer exists
Matt Fleming [Fri, 29 Apr 2011 10:20:11 +0000 (11:20 +0100)]
hdt: libmenu.a no longer exists

Don't link against libmenu.a, it no longer exists as it was removed in
commit 74518b8b691c ("elflink: Make ELF the default object format").

This fixes the following build error,

make[2]: *** No rule to make target `../cmenu/libmenu/libmenu.a', needed by `hdt.c32'.  Stop.

Signed-off-by: Matt Fleming <matt.fleming@linux.intel.com>
13 years agoload_env32 should not include menu.h
H. Peter Anvin [Wed, 27 Apr 2011 21:27:35 +0000 (14:27 -0700)]
load_env32 should not include menu.h

Remove stay #include that does not resolve.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
13 years agoelf_gen_dep.sh: Prioritise symbols exported by core
Matt Fleming [Fri, 15 Apr 2011 20:35:48 +0000 (21:35 +0100)]
elf_gen_dep.sh: Prioritise symbols exported by core

It's possible for multiple modules to export the same symbol. We
always favour the symbols exported from core/ because this means that
modules will have less runtime dependencies.

For example, some symbols required by ldlinux.c32 are exported by both
core/ and libmenu.c32. Because we don't want ldlinux.c32 to have any
dependencies, we need to make sure we resolve to the symbol exported
by core/.

Note that now the order in which we extract global symbols from ELF
files in elf_gen_dep.sh is important, because this dictates our order
of preference and hence core/isolinux.elf and core/pxelinux.elf need
to come first.

Signed-off-by: Matt Fleming <matt.fleming@linux.intel.com>
13 years agoelf_gen_dep.sh: Don't calculate dependencies for whitespace symbols
Matt Fleming [Fri, 15 Apr 2011 20:27:37 +0000 (21:27 +0100)]
elf_gen_dep.sh: Don't calculate dependencies for whitespace symbols

Don't try to resolve dependencies for a symbol whose name is purely
made up of whitespace.

Signed-off-by: Matt Fleming <matt.fleming@linux.intel.com>
13 years agoelflink: Don't require every module to have init/exit functions
Matt Fleming [Fri, 15 Apr 2011 20:10:55 +0000 (21:10 +0100)]
elflink: Don't require every module to have init/exit functions

Don't complain or refuse to load a module if it doesn't contain an
init or exit function, as many of the init/exit functions are in fact
empty.

Signed-off-by: Matt Fleming <matt.fleming@linux.intel.com>
13 years agoelflink: Don't compile in debug output by default
Matt Fleming [Fri, 15 Apr 2011 20:03:51 +0000 (21:03 +0100)]
elflink: Don't compile in debug output by default

Turn off ELF_DEBUG, we really don't need to see the "[ELF] MODULE
UNLOADED" message everytime we finish executing an ELF module.

Signed-off-by: Matt Fleming <matt.fleming@linux.intel.com>
13 years agoelflink: ldlinux should not have any dependencies
Matt Fleming [Tue, 26 Apr 2011 09:02:13 +0000 (10:02 +0100)]
elflink: ldlinux should not have any dependencies

ldlinux currently requires the get_key() symbol, which means it has a
dependency on libutil_com.c32. ldlinux.c32 really should be a
standalone module so let's move get_key.c into ldlinux/.

However, moving get_key.c creates a new problem - native linux
applications such as com32/samples/keytest.c require the get_key()
symbol which is currently exported by libutil_lnx.a. To fix this, we
create a new native linux library that exports any required symbols
from ldlinux. With this change we need to update com32/Makefile so
that we build com32/elfink/ldlinux before com32/samples, and seeing as
ldlinux now has no dependencies, we may as well move it to the front
of $SUBDIRS.

Also, update elf_gen_dep.sh to skip ldlinux.c32 and not search for
dependencies for any of its unresolved symbols. This way, if anyone
inadvertently introduces a dependency that cannot be resolved by the
core, ldlinux.c32 will fail to load at runtime (which guarantees that
the newly introduced dependency won't go unnoticed).

Signed-off-by: Matt Fleming <matt.fleming@linux.intel.com>
13 years agoexit.c: Truncate exit status to uint8_t
Matt Fleming [Fri, 15 Apr 2011 10:48:37 +0000 (11:48 +0100)]
exit.c: Truncate exit status to uint8_t

The valid range for an exit status is 0 - 255, so we need to truncate
the value passed to _exit().

I noticed this when a module was doing _exit(-1), and ended up calling

longjmp(.., 0xffffffff + 1)

which meant that setjmp() in spawn_load() returned 0. Obviously, we
wanted the setjmp() to return 256 (0xff + 1), because the code in
spawn_load() handles the return value like so,

ret_val = setjmp(module->u.x.process_exit);

if (ret_val)
ret_val--;              /* Valid range is 0-255 */
else if (!module->main_func)
ret_val = -1;
else
exit((module->main_func)(argc, argv)); /* Actually run! */

There actually is code in spawn_load() to properly truncate 'ret_val',
but it is applied too late. The truncation needs to happen when we
pass the exit status to longjmp().

Suggested-by: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: Matt Fleming <matt.fleming@linux.intel.com>
13 years agoelflink: Make ELF the default object format
Matt Fleming [Tue, 26 Apr 2011 08:59:53 +0000 (09:59 +0100)]
elflink: Make ELF the default object format

com32/elflink/modules was originally created to house ELF modules and
keep them separate from the COM32 modules as the elflink branch was
being developed. However, this has inadvertently created a maintenance
nightmare because code was copied from elsewhere in the tree into
com32/elflink/modules, resulting in duplication. Bug fixes have been
going into the original code but have not been merged onto the elflink
branch, leaving the duplicate code in com32/elflink/modules buggy.

So let's delete this directory. There really is no reason to keep ELF
and COM32 modules separate because there's no reason to need both
COM32 and ELF modules to coexist. ELF is a far superior object file
format and all modules are not emitted as ELF objects.

Now that we're outputting ELF modules we can use dynamic memory
instead of the cs_bounce bounce buffer.

This commit requires a certain amount of shuffling for some
files. quicksort.c isn't a module and belongs as part of the util
library. cli.h belongs in com32/include so that other modules can make
use of the cli code in ldlinux.c32.

All libraries are now ELF shared libraries which are only loaded to
fixup unresolved symbols for executable modules and renamed from *.a
to *.c32. This reduces the runtime memory footprint because libraries
are only loaded when needed and because every executable no longer
gets its own copy of code/data (as it would if linking with a static
library). Also, remove MINLIBOBJS from libcom32.c32 because it is
already part of libcom32min.a and we don't want to have any duplicate
symbols between the core (which links with libcom32min.a) and
libcom32.c32.

Welcome to the New World Order of ELF modules!

Signed-off-by: Matt Fleming <matt.fleming@linux.intel.com>
13 years agoelflink: Delete core-elf.h
Matt Fleming [Wed, 13 Apr 2011 23:59:12 +0000 (00:59 +0100)]
elflink: Delete core-elf.h

This header file really just duplicates code that is available in
other header files. It has no reason to exist.

Signed-off-by: Matt Fleming <matt.fleming@linux.intel.com>
13 years agocom32: Move menu.h
Matt Fleming [Wed, 13 Apr 2011 23:52:23 +0000 (00:52 +0100)]
com32: Move menu.h

menu.h is required by the menu code in com32/menu and also by
ldlinux. So move it to a more neutral place.

Signed-off-by: Matt Fleming <matt.fleming@linux.intel.com>
13 years agocom32: We only need one refstr.h
Matt Fleming [Wed, 13 Apr 2011 23:50:08 +0000 (00:50 +0100)]
com32: We only need one refstr.h

Delete the duplicate refstr.h and move the remaining copy into
com32/include so that it can be included by both ldlinux and the menu
code.

Signed-off-by: Matt Fleming <matt.fleming@linux.intel.com>
13 years agocmenu: Rename menu.h to cmenu.h
Matt Fleming [Wed, 13 Apr 2011 22:00:16 +0000 (23:00 +0100)]
cmenu: Rename menu.h to cmenu.h

In preparation for moving com32/menu/menu.h to com32/include/ let's
rename com32/cmenu/menu.h. This stops us having two header files named
menu.h which would mean that we'd have to be super careful with our
include paths to ensure we included the correct header.

Signed-off-by: Matt Fleming <matt.fleming@linux.intel.com>
13 years agocom32: Remove klibc.c32
Matt Fleming [Tue, 12 Apr 2011 21:28:57 +0000 (22:28 +0100)]
com32: Remove klibc.c32

We don't need this anymore as it includes DYNOBJS but libcom32.c32
also includes those objects and we can now dynamically load
libcom32.c32 at runtime.

Signed-off-by: Matt Fleming <matt.fleming@linux.intel.com>
13 years agocom32: Put deleted object files back into the Makefile
Matt Fleming [Wed, 13 Apr 2011 11:54:49 +0000 (12:54 +0100)]
com32: Put deleted object files back into the Makefile

For some reason that I can't understand, some object files were
removed from this Makefile in the following commit,

    |commit 0cb6490fa96f752c01bbb9add2c9ca6dbf99ece2
    |Author: Feng Tang <feng.tang@intel.com>
    |Date:   Thu Jun 3 10:48:22 2010 +0800
    |
    |   elflink: start merge with pathbased branch
    |
    |   modify these files to make compile pass
    |
    |       modified:   com32/MCONFIG
    |       modified:   com32/Makefile
    |       modified:   com32/include/klibc/compiler.h
    |       modified:   com32/include/sys/elfcommon.h
    |       modified:   com32/lib/Makefile
    |       modified:   com32/lib/free.c
    |       modified:   com32/lib/malloc.c

However, with this patch things continue to compile correctly so I'm
unsure why they were ever removed. Furthermore, pieces of code in
com32/ refer to symbols defined in these these object files and so
they are required in order to load modules.

These missing object files were discovered when loading libcom32.c32,
which wouldn't load because it was complaining about unresolved
symbols.

The removal of core/strncasecmp.c needs some explanation. There are
currently two identical copies of strncasecmp.c, one in com32/lib and
one in core/, and while the core copy is part of core/libcom32.a, the
copy in com32/lib isn't compiled. Now, because there are no references
to strncasecmp within core/ the symbol isn't pulled in from libcom32.a
and exported as a global symbol by the core. So, if ELF modules have
references to strncasecmp they cannot be resolved at runtime.

To fix this I've included strncasecmp.o in libcom32min.a which
isolinux.elf, ldlinux.elf and pxelinux.elf link against with
--whole-archive, which means that even if there are no references to
strncasecmp within the core, that symbol is still exported.

Signed-off-by: Matt Fleming <matt.fleming@linux.intel.com>
13 years agoelflink: Move more code from core/ into ldlinux
Matt Fleming [Fri, 8 Apr 2011 12:21:51 +0000 (13:21 +0100)]
elflink: Move more code from core/ into ldlinux

ldlinux now contains all the code necessary to load and execute
modules, none is contained in the core.

This change also allows us to change the spawn_load() prototype and to
push the job of processing arguments to executable functions (e.g. the
contents of char *argv[] as passed to a module's main function) into
ldlinux/execute.c instead of doing it in spawn_load(). Moving it into
ldlinux/ makes sense because the only core user of spawn_load() is
load_env32() and we don't require any sort of argument processing in
that path.

Signed-off-by: Matt Fleming <matt.fleming@linux.intel.com>
13 years agoelflink: Remove MODULE_MAIN() from executable ELF modules
Matt Fleming [Thu, 7 Apr 2011 20:02:02 +0000 (21:02 +0100)]
elflink: Remove MODULE_MAIN() from executable ELF modules

To make it easier to move existing COM32 modules over to ELF modules
without having to modify them we need to search for and run their
main() functions when they're loaded instead of requiring their
initial function to be labeled with MODULE_MAIN().

Currently, we require all executable ELF modules to specify their
initial function with the use of the MODULE_MAIN() macro and not via
the traditional method of naming it main(). However, there are weird
restrictions on what functions can be passed to MODULE_MAIN(), for
instance, they must be declared static.

This patch makes life much simpler and allows executable ELF modules
to be loaded without the MODULE_MAIN() wrapper, but rather by naming
their initial function main(). All the modules in com32/modules can
now be run as ELF modules without any modifications.

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