103 Commits
Author SHA1 Message Date
Michael Brown e103495563 [release] Update version to 0.9.7 for release 2009-03-02 02:23:42 +00:00
Michael Brown 518cd2f192 [release] Remove obsolete VERSION file 2009-03-02 02:19:07 +00:00
Thomas Miletich afe59d4636 [sundance] Add reset completion check
Following the example of the Linux driver, we add a check and delay to
make sure that the NIC has finished resetting before the driver issues
any additional commands.

Signed-off-by: Marty Connor <mdc@etherboot.org>
2009-02-27 13:52:03 -05:00
Michael Brown b9d791f4d1 [infiniband] Kill off obsolete mlx_ipoib directory
This directory contains the old Etherboot implementation of IPoIB boot
from Mellanox, which has long been obsoleted by gPXE's own
implementation.
2009-02-25 05:07:41 +00:00
Michael Brown 4f3bab1a55 [image] Allow for zero embedded images
Having a default script containing

  #!gpxe
  autoboot

can cause problems when entering commands to load and start a kernel
manually; the default script image will still be present when the
kernel is started and so will be treated as an initrd.  It is possible
to work around this by typing "imgfree" before any other commands, but
this is counter-intuitive.

Fix by allowing the embedded image list to be empty (in which case we
just call autoboot()), and making this the default.

Reported by alkisg@gmail.com.
2009-02-24 05:57:56 +00:00
Shao Miller 43834f5d25 [image] Added "chain" command to fetch, load, and execute image
The "chain" command combines the functions of "imgfetch", "imgload",
and "boot".

    chain http://etherboot.org/gtest/gtest.gpxe

is equivalent to:

    kernel http://etherboot.org/gtest/gtest.gpxe
    boot
2009-02-24 05:28:14 +00:00
Michael Brown 784d3f336e [pxe] Set %ax to zero on entry to PXE NBP
This is not strictly an entry requirement, but it does mean that a PXE
NBP returning without setting %ax will appear to have returned
success.
2009-02-23 08:43:27 +00:00
H. Peter Anvin 6a3f5d6db7 [pxeprefix] Search for the PXE entry points through all methods
Search for the PXE entry points (via the !PXE or PXENV+ structures)
through all known combinations of search methods.  Furthermore, if we
find a PXENV+ structure, attempt to use it to find the !PXE structure
if at all possible.
2009-02-23 02:53:38 +00:00
Michael Brown 4dd746a725 [iscsi] Include credentials in iBFT only if used during iSCSI login
Avoid passing credentials in the iBFT that were available but not
required for login.  This works around a problem in the Microsoft
iSCSI initiator, which will refuse to initiate sessions if the CHAP
password is fewer than 12 characters, even if the target ends up not
asking for CHAP authentication.
2009-02-20 21:41:00 +00:00
Michael Brown 78d426d196 [scsi] Fix DBG() message reporting of error number 2009-02-19 10:37:30 +00:00
Michael Brown 9937bf13c9 [crypto] Allow creation of arbitrary CBC cipher algorithms using CBC_CIPHER()
Given any block cipher, a corresponding CBC mode of behaviour for the
cipher can be created using the CBC_CIPHER() macro.
2009-02-19 01:53:25 +00:00
Michael Brown e950dc04ba [crypto] Add our own general-purpose cipher-block chaining routines 2009-02-19 01:23:50 +00:00
Michael Brown b4d3d686cc [crypto] Change cipher_{en,de}crypt() to void functions
It is a programming error, not a runtime error, if we attempt to use
block ciphers with an incorrect blocksize, so use an assert() rather
than an error status return.
2009-02-19 00:06:41 +00:00
Michael Brown a3219b24a8 [crypto] Split crypto_algorithm into {digest,cipher,pubkey}_algorithm
The various types of cryptographic algorithm are fundamentally
different, and it was probably a mistake to try to handle them via a
single common type.

pubkey_algorithm is a placeholder type for now.
2009-02-18 22:17:41 +00:00
Michael Brown 5de8305feb [crypto] Move AES_convert_key() hack into axtls_aes.c
Although the nature of the hack is essentially unchanged, this allows
us to remove the hardcoded assumption in tls.c that the RX cipher is
AES.
2009-02-18 21:33:54 +00:00
Michael Brown 991f907d5b [crypto] Rename aes_algorithm to aes_cbc_algorithm 2009-02-18 21:28:46 +00:00
H. Peter Anvin aaa26f3bd3 [pxe] Initialize EDX on PXE NBP entry and INT 1Ah
The PXE 1.x spec specifies that on NBP entry or on return from INT
1Ah AX=5650h, EDX shall point to the physical address of the PXENV+
structure.  The PXE 2.x spec drops this requirement, simply stating
that EDX is clobbered.  Given the principle "be conservative in what
you send, liberal in what you accept", however, we should implement
this anyway.
2009-02-18 18:13:20 +00:00
Michael Brown b5577553e5 [pxeprefix] Add .kkpxe image type and ability to return via PXE stack
Certain combinations of PXE stack and BIOS result in a broken INT 18
call, which will leave the system displaying a "PRESS ANY KEY TO
REBOOT" message instead of proceeding to the next boot device.  On
these systems, returning via the PXE stack is the only way to continue
to the next boot device.  Returning via the PXE stack works only if we
haven't already blown away the PXE base code in pxeprefix.S.

In most circumstances, we do want to blow away the PXE base code.
Base memory is a limited resource, and it is desirable to reclaim as
much as possible.  When we perform an iSCSI boot, we need to place the
iBFT above the 512kB mark, because otherwise it may not be detected by
the loaded OS; this may not be possible if the PXE base code is still
occupying that memory.

Introduce a new prefix type .kkpxe which will preserve both the PXE
base code and the UNDI driver (as compared to .kpxe, which preserves
the UNDI driver but uninstalls the PXE base code).  This prefix type
can be used on systems that are known to experience the specific
problem of INT 18 being broken, or in builds (such as gpxelinux.0) for
which it is particularly important to know that returning to the BIOS
will work.

Written by H. Peter Anvin <hpa@zytor.com> and Stefan Hajnoczi
<stefanha@gmail.com>, minor structural alterations by Michael Brown
<mcb30@etherboot.org>.
2009-02-18 18:12:32 +00:00
Michael Brown dd44a7c314 [i386] Kill off obsolete boot1a.s file 2009-02-18 04:48:30 +00:00
Michael Brown 7b1a5a7997 [dhcp] Use a default user-class of "gPXE"
This change makes it possible to break the PXE-chaining infinite loop
even when restricted to a Windows DHCP server.
2009-02-17 22:03:28 +00:00
Michael Brown 3206e470d0 [image] Redact password from URIs displayed by imgfetch() 2009-02-17 12:10:35 +00:00
Michael Brown 6de4db5da0 [login] Add "login" command and UI 2009-02-17 12:02:16 +00:00
Michael Brown bea828b9ed [settings] Allow store_setting() to access the root settings block 2009-02-17 11:57:31 +00:00
Michael Brown 54840039f6 [http] Send authentication information whenever username is present
Send authentication information if the username is present, even if
the password is empty.
2009-02-17 11:56:27 +00:00
Michael Brown 67ee41ad6d [editbox] Allow for password widgets that do not display their contents 2009-02-17 11:55:55 +00:00
Michael Brown cff419148c [pxe] Allow Escape to abort PXE menu selections
Other vendor PXE stacks tend to allow the Escape key to be used to
abort menu selection.  Allow Escape (as well as Ctrl-C) to abort
selection.
2009-02-17 07:35:57 +00:00
Michael Brown 06b5132fdc [icmp] Add support for responding to pings 2009-02-17 06:59:15 +00:00
Daniel Verkamp dbbd81c140 [comboot] Implement INT 22h AX=001Bh (Cleanup, shuffle, and boot to real mode) 2009-02-17 03:52:44 +00:00
Michael Brown 5026a35fef [comboot] Restore the real-mode stack pointer on exit from a COMBOOT image
COMBOOT images use INTs to issue API calls; these end up making calls
into gPXE from real mode, and so temporarily change the real-mode
stack pointer.  When our COMBOOT code uses a longjmp() to implement
the various "exit COMBOOT image" API calls, this leaves the real-mode
stack pointer stuck with its temporary value, which causes problems if
we eventually try to exit out of gPXE back to the BIOS.

Fix by adding rmsetjmp() and rmlongjmp() calls (analogous to
sigsetjmp()/siglongjmp()); these save and restore the additional state
needed for real-mode calls to function correctly.
2009-02-17 03:38:40 +00:00
Michael Brown 7f903f03af [comboot] Unhook interrupt vectors after returning from a COMBOOT image 2009-02-17 02:03:16 +00:00
Michael Brown 14eafc5b8d [comboot] Fix reference counting on replacement images
When chaining COMBOOT images, the old images now get freed correctly.
2009-02-17 01:45:12 +00:00
Michael Brown 8904cd55f1 [comboot] Allow for tail recursion of COMBOOT images
Multi-level menus via COMBOOT rely on the COMBOOT program being able
to exit and invoke a new COMBOOT program (the next menu).  This works,
but rapidly (within about five iterations) runs out of space in gPXE's
internal stack, since each new image is executed in a new function
context.

Fix by allowing tail recursion between images; an image can now
specify a replacement image for itself, and image_exec() will perform
the necessary tail recursion.
2009-02-17 00:47:35 +00:00
Michael Brown 349868b8fd [uri] Allow use of relative URIs when calling churi() 2009-02-16 04:56:55 +00:00
Michael Brown 7bc4093e1a [build] Cope with oddities in the Fedora 10 assembler
The version of the GNU assembler shipped with Fedora 10
(2.18.50.0.9-8.fc10) complains about character literals in some of our
assembly code.  Changing $'x' to $( 'x' ) seems to fix the problem.
Yes, the whitespace is required; using just $('x') does not work.

Reported by Kevin O'Connor <kevin@koconnor.net>.
2009-02-16 03:53:25 +00:00
Michael Brown b08e255ef1 [build] Fix building on gcc 3
GCC did not support #pragma GCC visibility until version 4.0.
2009-02-16 02:15:17 +00:00
Michael Brown 78a57a6f76 [build] Allow NO_WERROR=1 to inhibit --fatal-warnings as well as -Werror 2009-02-16 01:06:40 +00:00
Michael Brown 24e948f030 [image] Avoid claiming zero-length images as valid
Both the script and PXE images types will claim a zero-length image.
Inhibit this to avoid end-user surprises.
2009-02-16 00:30:48 +00:00
Michael Brown 076154a1c6 [image] Allow multiple embedded images
This patch extends the embedded image feature to allow multiple
embedded images instead of just one.

gPXE now always boots the first embedded image on startup instead of
doing the hardcoded DHCP boot (aka autoboot).

Based heavily upon a patch by Stefan Hajnoczi <stefanha@gmail.com>.
2009-02-16 00:30:36 +00:00
Michael Brown f16668dd60 [romprefix] Update ROM checksum even if PMM allocation fails
There are code paths other than PMM allocation that can result in our
changing the ROM checksum.  For example, we attempt to update our
product string to incorporate the PCI bus:dev.fn number.  In a system
that does not support PMM, we could therefore end up with an incorrect
checksum.

Fix by attempting to update the checksum unconditionally.
2009-02-15 11:44:21 +00:00
Michael Brown 79867d34ee [build] Treat warnings as errors in assembly files
Add --fatal-warnings to ASFLAGS; this is the equivalent of -Werror in
CFLAGS (which we have used since July 2007).
2009-02-15 11:05:00 +00:00
Michael Brown c9e5b12473 [i386] Add explicit flags and type on all .section declarations
Try to avoid future problems caused by implicit section flags and/or
type information by instituting a policy that all .section
declarations must explicitly state the flags and type.

Most of this change was achieved using

    perl -pi \
      -e 's/".text"$/".text", "ax", \@progbits/ ; ' \
      -e 's/".text16"$/".text16", "ax", \@progbits/ ; ' \
      -e 's/".text16.null"$/".text16.null", "ax", \@progbits/ ; ' \
      -e 's/".text16.data"$/".text16.data", "aw", \@progbits/ ; ' \
      -e 's/".data"$/".data", "aw", \@progbits/ ; ' \
      -e 's/".data16"$/".data16", "aw", \@progbits/ ; ' \
      -e 's/".bss"$/".bss", "aw", \@nobits/ ; ' \
      -e 's/".bss16"$/".bss16", "aw", \@nobits/ ; ' \
      -e 's/".prefix"$/".prefix", "ax", \@progbits/ ; ' \
      -e 's/".prefix.lib"$/".prefix.lib", "awx", \@progbits/ ; ' \
      -e 's/".prefix.data"$/".prefix.data", "aw", \@progbits/ ; ' \
      -e 's/".weak"$/".weak", "a", \@nobits/ ; ' \
      `git grep -l '\.section'`
2009-02-15 10:59:53 +00:00
Michael Brown ce2aa66d39 [i386] Add explicit ""aw", @nobits" declarations to stack sections
As reported by Stefan, commit 13d09e6 ("[i386] Simplify linker script
and standardise linker-defined symbol names") breaks gdb, readelf and
associated utilities.

This is caused by the .stack section overwriting a block in the middle
of the .debug_info section (despite being included in the
.bss.textdata section in the output file, which apparently has the
correct attributes for a .bss section).

Fixed by adding explicit flags and type to the stack section
declaration.
2009-02-15 10:02:26 +00:00
Michael Brown 8ae1cac050 [xfer] Make consistent assumptions that xfer metadata can never be NULL
The documentation in xfer.h and xfer.c does not say that the metadata
parameter is optional in calls such as xfer_deliver_iob_meta() and the
deliver_iob() method.  However, some code in net/ is prepared to
accept a NULL pointer, and xfer_deliver_as_iob() passes a NULL pointer
directly to the deliver_iob() method.

Fix this mess of conflicting assumptions by making everything assume
that the metadata parameter is mandatory, and fixing
xfer_deliver_as_iob() to pass in a dummy metadata structure (as is
already done in xfer_deliver_iob()).
2009-02-15 08:44:22 +00:00
Michael Brown 46da51703a [umalloc] Avoid problems when _textdata_memsz is a multiple of 4kB
If it happens that _textdata_memsz ends up being an exact multiple of
4kB, then this will cause the .textdata section (after relocation) to
start on a page boundary.  This means that the hidden memory region
(which is rounded down to the nearest page boundary) will start
exactly at virtual address 0, i.e. UNULL.  This means that
init_eheap() will erroneously assume that it has failed to allocate a
an external heap, since it typically ends up choosing the area that
lies immediately below .textdata, which in this case will be the
region with top==UNULL.

A subsequent error is that memtop_urealloc() passes through the error
return status -ENOMEM to the caller, which (rightly) assumes that the
result represents a valid userptr_t address.

Fixed by using alternative tests for heap non-existence, and by
returning UNULL in case of an error from init_eheap().
2009-02-15 07:56:16 +00:00
Michael Brown 816a32aaee [http] Allow for URI encodings within username and password 2009-02-13 16:26:43 +00:00
Michael Brown ef70f87997 [http] Add support for HTTP Basic authentication 2009-02-13 15:43:17 +00:00
Michael Brown d900ae05d7 [base64] Add base64 encoding functions 2009-02-13 14:54:13 +00:00
Michael Brown 4e6b62c946 [settings] Handle errors in fetchf_uristring()
fetchf_uristring() was failing to handle error values from
fetch_setting(), resulting in its attempting to allocate extremely
large temporary buffers on the stack (and so overrunning the stack and
locking up the machine).

Problem reported by Shao Miller <Shao.Miller@yrdsb.edu.on.ca>.
2009-02-12 09:16:53 +00:00
Michael Brown 8e960eb67c [tls] Use our own ASN.1 routines for certificate parsing
Use our own, more robust, ASN.1 parsing routines to extract the RSA
public key from a server certificate.  Remove the now-unused AXTLS
ASN.1 parser.
2009-02-10 18:30:17 +00:00
Michael Brown 5a99c586cf [crypto] Remove unused files 2009-02-10 15:47:44 +00:00
Itay Gazit 750c19466a [mtnic] Add multiport support and some minor fixes
Signed-off-by: Michael Brown <mcb30@etherboot.org>
2009-02-09 12:43:44 +00:00
Thomas Miletich e9c10ca158 [sundance] Added NIC variant
This previously unsupported NIC variant was was found to work using
the current driver:

     PCI_ROM(0x13f0, 0x0200, "ip100a", "IC+ IP100A"),

Signed-off-by: Marty Connor <mdc@etherboot.org>
2009-02-06 08:41:02 -05:00
Michael Brown 56066a6085 [pxe] Display the "Press F8" prompt rather than displaying menu with timeout
The PXE spec dictates the rather ugly feature that we have to present
a DHCP-specified prompt string to the user, then wait to see if they
press F8 before displaying the menu.

This seems to me to be a significant retrograde step from the current
situation of displaying the menu with the timeout counting down
against the default selected boot option, but apparently the lack of
the "Press F8" prompt causes some confusion.
2009-02-05 19:29:16 +00:00
Michael Brown 881f1f59ef [pxe] Obey lists of PXE Boot Servers and associated Discovery Control bits
Various combinations of options 43.6, 43.7 and 43.8 dictate which
servers we send Boot Server Discovery requests to, and which servers
we should accept responses from.  Obey these options, and remove the
explicit specification of a single Boot Server from start_pxebs() and
dependent functions.
2009-02-05 09:34:32 +00:00
Michael Brown ff2b308506 [pxe] Skip PXE boot server discovery if directed to do so
Option 43.6 can direct us to skip PXE boot server discovery and just
perform a standard DHCP filename boot.
2009-02-05 09:34:05 +00:00
Michael Brown 4b276b8df9 [pxe] Fall back to broadcast if no boot server multicast address exists
fetch_ipv4_setting() will zero its IPv4 address argument if no such
setting exists, rather than leaving it untouched.
2009-02-03 02:44:15 +00:00
Michael Brown dbe84c5aad [iobuf] Add iob_disown() and use it where it simplifies code
There are many functions that take ownership of the I/O buffer they
are passed as a parameter.  The caller should not retain a pointer to
the I/O buffer.  Use iob_disown() to automatically nullify the
caller's pointer, e.g.:

    xfer_deliver_iob ( xfer, iob_disown ( iobuf ) );

This will ensure that iobuf is set to NULL for any code after the call
to xfer_deliver_iob().

iob_disown() is currently used only in places where it simplifies the
code, by avoiding an extra line explicitly setting the I/O buffer
pointer to NULL.  It should ideally be used with each call to any
function that takes ownership of an I/O buffer.  (The SSA
optimisations will ensure that use of iob_disown() gets optimised away
in cases where the caller makes no further use of the I/O buffer
pointer anyway.)

If gcc ever introduces an __attribute__((free)), indicating that use
of a function argument after a function call should generate a
warning, then we should use this to identify all applicable function
call sites, and add iob_disown() as necessary.
2009-02-01 20:16:10 +00:00
Michael Brown 0171098212 [contrib] Update qemu documentation 2009-02-01 20:16:10 +00:00
Michael Brown 4502c04360 [dhcp] Send user class in DHCP requests 2009-02-01 20:06:09 +00:00
Michael Brown 6711ce18a7 [tftp] Guard against invalid data block numbers
A TFTP DATA packet with a block number of zero (representing a
negative offset within the file) could potentially cause problems.
Fixed by explicitly rejecting such packets.

Identified by Stefan Hajnoczi <stefanha@gmail.com>.
2009-02-01 13:07:17 +00:00
Michael Brown e65afc4b10 [dhcp] Split PXE menuing code out of dhcp.c
The DHCP client code now implements only the mechanism of the DHCP and
PXE Boot Server protocols.  Boot Server Discovery can be initiated
manually using the "pxebs" command.  The menuing code is separated out
into a user-level function on a par with boot_root_path(), and is
entered in preference to a normal filename boot if the DHCP vendor
class is "PXEClient" and the PXE boot menu option exists.
2009-02-01 01:21:40 +00:00
Michael Brown d2b0081740 [settings] Avoid duplicate settings block names
Automatically unregister any settings with the same name (and position
within the settings tree) as a newly registered settings block.

This functionality is generalised out from dhcp.c.
2009-01-31 07:32:20 +00:00
Michael Brown b111bdfb00 [scsi] Cope with targets that send multiple CHECK CONDITIONS at power-on
Some targets send a spurious CHECK CONDITION message in response to
the first SCSI command.  We issue (and ignore the status of) an
arbitary harmless SCSI command (a READ CAPACITY (10)) in order to draw
out this response.

The Solaris Comstar target seems to send more than one spurious CHECK
CONDITION response.  Attempt up to SCSI_MAX_DUMMY_READ_CAP dummy READ
CAPACITY (10) commands before assuming that error responses are
meaningful.

Problem reported by Kristof Van Doorsselaere <kvandoor@aserver.com>
and Shiva Shankar <802.11e@gmail.com>.
2009-01-30 13:32:53 +00:00
Michael Brown 52c596bafb [ui] Allow Ctrl-C to cancel wait for net device link-up
This really ought to be handled via monojob.c and the usual Ctrl-C
mechanism that handles cancelling DHCP or file downloads.
2009-01-27 20:09:50 +00:00
Stefan Hajnoczi d10a7e7739 [dns] Append local domain to relative names
Try to qualify relative names in the DNS resolver using the DHCP Domain
Name.  For example:

  DHCP Domain Name: etherboot.org
  (Relative) Name: www

yields:

  www.etherboot.org

Only names with no dots ('.') will be modified.  A name with one or more
dots is unchanged.
2009-01-27 19:26:12 +00:00
Michael Brown a128973ecb [settings] Add fetch_string_setting_copy() 2009-01-27 19:13:47 +00:00
Michael Brown 1284773363 [tftp] Temporary fix for conveying TFTP block size to callers
pxe_tftp.c assumes that the first seek on its data-transfer interface
represents the block size.  Apart from being an ugly hack, this will
also screw up file size calculation for files smaller than one block.

The proper solution would be to extend the data-transfer interface to
support the reporting of stat()-like data.  This is not going to
happen until the cost of adding interface methods is reduced (a fix I
have planned since June 2008).

In the meantime, abuse the xfer_window() method to return the block
size, since it is not being used for anything else and is vaguely
justifiable.

Astonishingly, having returned the incorrect TFTP blocksize via
PXENV_TFTP_OPEN for almost a year seems not to have affected any of
the test cases run during that time; this bug was found only when
someone tried running the heavily-patched version of pxegrub found in
OpenSolaris.
2009-01-27 15:47:00 +00:00
Michael Brown 027c72e0d0 [dhcp] Include support for PXE boot menus
PXE dictates a mechanism for boot menuing, involving prompting the
user with a variable message, waiting for a predefined keypress,
displaying a boot menu, and waiting for a selection.

This breaks the currently desirable abstraction that DHCP is a process
that can happen in the background without any user interaction.
2009-01-25 21:16:47 +00:00
Michael Brown f1d17ae2be [bios] Add F8 function key as a recognised BIOS keycode 2009-01-25 21:12:48 +00:00
Michael Brown ce9690ca39 [console] Allow KEY_xxx constants to cover F8 function key
F8 is represented by the ANSI escape sequence "^[[19~", which is not
representable as a KEY_xxx constant using the current encoding scheme.
Adapt the encoding scheme to allow F8 to be represented, since PXE
requires that we may need to prompt the user to press F8.
2009-01-25 21:10:48 +00:00
Michael Brown 3f814f08e5 [dhcp] Clarify language surrounding ProxyDHCP
Remove the lazy assumption that ProxyDHCP == "DHCP with option 60 set
to PXEClient", and explicitly separate the notion of ProxyDHCP from
the notion of packets containing PXE options.
2009-01-23 01:47:33 +00:00
Michael Brown 773d9631ef [dhcp] Handle missing ProxyDHCP servers
It is possible to configure a DHCP server to hand out PXE options
without a ProxyDHCP server present.  This requires setting option 60
to "PXEClient", which will cause gPXE to attempt ProxyDHCP.

We assume in several places that dhcp->proxydhcpack is set to the
DHCPACK packet containing option 60 set to "PXEClient".  When we
transition into ProxyDHCPREQUEST, set dhcp->proxydhcpack=dhcp->dhcpack
so that this assumption holds true.

We ought to rename several references to "proxydhcp" to something more
accurate, such as "pxedhcp".  Treating a single DHCP response as
potentially both DHCPOFFER and ProxyDHCPOFFER does make the code
smaller, but the variable names get confusing.
2009-01-23 01:32:04 +00:00
Michael Brown 76d05a4da0 [dhcp] Pass PXE boot menu item to PXE Boot Server
Pick out the first boot menu item from the boot menu (option 43.9) and
pass it to the boot server as the boot menu item (option 43.71).

Also improve DHCP debug messages to include more details of the
packets being transmitted.
2009-01-23 01:13:50 +00:00
Michael Brown cf53998901 [tcp] Always set PUSH flag on TCP transmissions
Apparently this can cause a major speedup on some iSCSI targets, which
will otherwise wait for a timer to expire before responding.  It
doesn't seem to hurt other simple TCP test cases (e.g. HTTP
downloads).

Problem and solution identified by Shiva Shankar <802.11e@gmail.com>
2009-01-21 04:22:34 +00:00
Michael Brown 6941793416 [dhcp] Add preliminary support for PXE Boot Servers
Some PXE configurations require us to perform a third DHCP transaction
(in addition to the real DHCP transaction and the ProxyDHCP
transaction) in order to retrieve information from a "Boot Server".

This is an experimental implementation, since the actual behaviour is
not well specified in the PXE spec.
2009-01-21 03:43:26 +00:00
Michael Brown d230b53df2 [tcpip] Allow for transmission to multicast IPv4 addresses
When sending to a multicast address, it may be necessary to specify
the source address explicitly, since the multicast destination address
does not provide enough information to deduce the source address via
the miniroute table.

Allow the source address specified via the data-xfer metadata to be
passed down through the TCP/IP stack to the IPv4 layer, which can use
it as a default source address.
2009-01-21 03:40:39 +00:00
Michael Brown b4a95a8974 [ethernet] Fix eth_mc_hash() return status
eth_mc_hash() was missing a return within a switch statement, and so
always falling through to the default case and returning failure.
2009-01-21 03:38:25 +00:00
Michael Brown 7be5fa82e3 [dhcp] Centralise DHCP successful state transitions
Move all the DHCP state transition logic into a single function
dhcp_next_state().  This will make it easier to add support for PXE
Boot Servers, since it abstracts away the difference between "mark
DHCP as complete" and "transition to boot server discovery".
2009-01-21 01:31:52 +00:00
Michael Brown d7de30e5e4 [dhcp] Allow for missing server ID in ProxyDHCPACK
The Linux PXE server (http://www.kano.org.uk/projects/pxe) does not
set the server identifier in its ProxyDHCP responses.  If the server
ID is missing, do not treat this as an error.

This resolves the "vague and unsettling memory" mentioned in commit
fdb8481d ("[dhcp] Verify server identifier on ProxyDHCPACKs").

Note that we already accept ProxyDHCPOFFERs without a server
identifier; they get treated as potential BOOTP packets.
2009-01-21 00:55:42 +00:00
Michael Brown 08f6d22410 [efi] Expose both GUIDs for the EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL
At some point, it seems that someone decided to change the GUID for
the EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL.  Current EFI builds
ignore the older GUID, older EFI builds ignore the newer GUID, so we
have to expose both.
2009-01-12 20:53:38 +00:00
Michael Brown aa86afe890 [efi] Add an EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL interface
This allegedly optional interface seems to be compulsory if you want
EFI's PXE code to bother trying to use your network interface.
2009-01-12 19:11:30 +00:00
Michael Brown cced04ef3b [efi] Provide component name protocol and device path protocol interfaces
Include a minimal component name protocol so that the driver name
shows up as something other than "<UNKNOWN>" in the driver list, and a
device path protocol so that the network interface shows up as a
separate device in the device list, rather than being attached
directly to the PCI device.

Incidentally, the EFI component name protocol reaches new depths for
signal-to-noise ratio in program code.  A typical instance within the
EFI development kit will use an additional 300 lines of code to
provide slightly less functionality than GNU gettext achieves with
three additional characters.
2009-01-12 19:10:53 +00:00
Michael Brown 8fd81349b3 [efi] Ensure EFI ROM checksum is zero
The UEFI specification does not mention ROM checksums, and reassigns
the field typically used as a checksum byte.  The UEFI shell
"loadpcirom" utility does not verify ROM checksums, but it seems that
some UEFI BIOSes do.
2009-01-09 20:52:26 +00:00
Michael Brown 48b2f70ee4 [util] Tidy up output of disrom.pl 2009-01-09 19:38:53 +00:00
Michael Brown ba1016f378 [dhcp] Include gPXE version number within DHCP request 2009-01-08 08:39:05 +00:00
Michael Brown 3e220aa73e [main] Print an "initialising devices" banner
Some devices take a very long time to initialise.  This can make it
difficult to visually distinguish between the error cases of failing
to start executing C code and failing to initialise a device.

Add a "gPXE initialising devices..." message.  The trailing ellipsis
indicates to the user that this may take some time, and the presence
of the message indicates to the developer that relocation etc. all
succeeded.
2009-01-08 03:48:30 +00:00
Michael Brown fb72336fe6 [efi] Add efirom utility and .efirom image format 2009-01-08 02:19:18 +00:00
Michael Brown 765efac771 [efi] Allow for .efidrv images as well as .efi images
Merge in the changes that allow for building EFI driver images (that
can be loaded using the EFI shell's "load" command) as well as EFI
applications.
2009-01-07 23:43:26 +00:00
Michael Brown 314779eb36 [efi] Use elf2efi utility in place of efilink
elf2efi converts a suitable ELF executable (containing relocation
information, and with appropriate virtual addresses) into an EFI
executable.  It is less tightly coupled with the gPXE build process
and, in particular, does not require the use of a hand-crafted PE
image header in efiprefix.S.

elf2efi correctly handles .bss sections, which significantly reduces
the size of the gPXE EFI executable.
2009-01-07 22:59:05 +00:00
Michael Brown 85e5e25c52 [build] Avoid strict-aliasing warnings when building with gcc 4.4
Conventional usage of the various struct sockaddr_xxx types involves
liberal use of casting, which tends to trigger strict-aliasing
warnings from gcc.  Avoid these now and in future by marking all the
relevant types with __attribute__((may_alias)).
2009-01-05 19:20:26 -08:00
Michael Brown 21cfab4fb8 [efi] Inhibit harmless ld warning on unresolved symbol check
The check for unresolved symbols does not explicitly specify an output
architecture format, and so causes a warning when building an i386 EFI
binary on an x86_64 platform.  This warning is harmless, and
specifying the output architecture in multiple places is cumbersome,
so just inhibit the warning.
2009-01-05 12:54:40 -08:00
Michael Brown 53a7dd26cd [infiniband] Call ib_open() only when opening the IPoIB net device
Defer the call to ib_open() until we want to actually open the device,
rather than when the device is registered.
2009-01-02 21:04:31 +00:00
Marty Connor 8674bc05a0 [pcbios] Add additional sanity check for bogus e820 map
At POST time some BIOSes return invalid e820 maps even though
they indicate that the data is valid.  We add a check that the first
region returned by e820 is RAM type and declare the map to be invalid
if it is not.

This extends the sanity checks from 8b20e5d ("[pcbios] Sanity-check
the INT15,e820 and INT15,e801 memory maps").
2008-12-18 17:28:57 +00:00
Michael Brown 57bbf0ec98 [etherfabric] Make use of pci_bar_start() 64-bit clean
Driver was storing the result of pci_bar_start() and pci_bar_size() in
an int, rather than an unsigned long.

(Bug was introduced in the vendor's tree in commit eac85cd "Port
etherfabric driver to net_device api".)
2008-12-12 19:18:04 +00:00
Michael Brown 1941c933f8 [pci] Enable memory cycles in adjust_pci_device()
adjust_pci_device() has historically enabled bus-mastering and I/O
cycles, but has never previously needed to enable memory cycles.  Some
EFI systems seem not to enable memory cycles by default, so add that
to the list of PCI command register bits that we force on.
2008-12-12 19:15:00 +00:00
Marty Connor 1206999288 [e1000] Use PCI_BASE_ADDRESS_* symbols instead of integers
When compiling for the Linux kernel, PCI_BASE_ADDRESS_0 == 0, and
PCI_BASE_ADDRESS_1 == 1.  This is not so when compiling for gPXE.  We
must use the symbolic names rather than integers to get the correct
values.

Bug identified and patch supplied by:

   George Chou <george.chou@advantech.com>
2008-12-05 16:35:33 +00:00
Michael Brown ce0a0ccf5c [x86_64] Add support for compilation as an x86_64 binary
Currently the only supported platform for x86_64 is EFI.

Building an EFI64 gPXE requires a version of gcc that supports
__attribute__((ms_abi)).  This currently means a development build of
gcc; the feature should be present when gcc 4.4 is released.

In the meantime; you can grab a suitable gcc tree from

  git://git.etherboot.org/scm/people/mcb30/gcc/.git
2008-12-05 00:06:27 +00:00
Michael Brown b0d2c9a4d5 [hermon] Fix permissions broken in 3a799e9 ("Add PCI ID for ConnectX QDR card")
The patch file supplied for commit 3a799e9 ("[hermon] Add PCI ID for
ConnectX QDR card") accidentally marked drivers/infiniband/hermon.c as
being executable.
2008-12-04 23:27:21 +00:00
Michael Brown 29480dd715 [efi] Use EFI-native mechanism for accessing SMBIOS table
EFI provides a copy of the SMBIOS table accessible via the EFI system
table, which we should use instead of manually scanning through the
F000:0000 segment.
2008-12-04 23:19:12 +00:00
Michael Brown 045a22764a [efi] Allow use of EFI configuration tables
EFI passes in copies of SMBIOS and other system configuration tables
via the EFI system table.  Allow configuration tables to be requested
using a mechanism similar to the current method for requesting EFI
protocols.
2008-12-04 23:18:32 +00:00
Michael Brown 3a799e99ca [hermon] Add PCI ID for ConnectX QDR card
Patch provided by Itay Gazit <itaygazit@gmail.com>.
2008-12-04 20:48:53 +00:00
Michael Brown 4d7c650164 [romprefix] Change from opt-in to opt-out when booting via INT19
On non-BBS systems, we have to hook INT 19 in order to be able to boot
from the gPXE ROM at all.  However, doing this unconditionally will
prevent the user from booting via any other devices.

Previously, the INT 19 entry point would prompt the user to press B in
order to boot from gPXE, which makes it impossible to perform an
unattended network boot.  We now prompt the user to press N to skip
booting from gPXE, which allows for unattended operation.

This should be a better match for most real-world scenarios.  Most
modern systems support BBS and so are unaffected by this change.  Very
old (non-BBS) systems tend not to have PXE ROMs by default anyway; if
the user has added a gPXE ROM then they probably do want to boot from
the network.  Newer non-BBS systems are essentially limited to IBM
servers, which will recapture the INT 19 vector anyway and implement
their own boot-ordering selection mechanism.
2008-12-04 16:46:16 +00:00
Marty Connor 708e6e0613 [release] Update version to 0.9.6+ post release 2008-11-23 17:01:17 -05:00
239 changed files with 8516 additions and 22942 deletions
-1
View File
@@ -1 +0,0 @@
0.9.6 2008-11-23
+11 -18
View File
@@ -1,5 +1,5 @@
Running Etherboot within qemu
=============================
Running gPXE within qemu
========================
Michael Brown <mbrown@fensystems.co.uk>
@@ -9,13 +9,10 @@ To get qemu running is fairly simple:
make
2. Get the qemu source code:
cvs -d:pserver:anonymous@cvs.savannah.nongnu.org:/sources/qemu \
login
cvs -d:pserver:anonymous@cvs.savannah.nongnu.org:/sources/qemu \
co qemu
svn co svn://svn.savannah.nongnu.org/qemu/trunk qemu
2a. Patch the qemu code. There is currently a bug that causes qemu to
execute Etherboot incredibly slowly. The bug seems to be related
execute gPXE incredibly slowly. The bug seems to be related
to the relative prioritisation of CPU and I/O operations within
qemu. This patch (which I found via Google) isn't a proper fix,
but it does work around the problem:
@@ -23,13 +20,9 @@ To get qemu running is fairly simple:
3. Configure qemu with
pushd qemu
./configure --enable-system
./configure --target-list=i386-softmmu,x86_64-softmmu
popd
Note that qemu will not compile with gcc4; if your system's
default compiler is gcc4 then specify the path to gcc3 using
e.g. --cc=gcc-3.3.6
4. Build qemu:
make -C qemu
@@ -44,7 +37,7 @@ To get qemu running is fairly simple:
range dynamic-bootp 10.254.254.1 10.254.254.1;
}
You will also need to add in any of your usual declarations for
Etherboot, e.g. 'filename "vmlinuz.ltsp";'. Note that this setup
gPXE, e.g. 'filename "vmlinuz.ltsp";'. Note that this setup
assumes that your DHCP server, TFTP server etc. all live on the
machine you are using for running qemu. If not, then you're on
your own.
@@ -52,7 +45,7 @@ To get qemu running is fairly simple:
7. As root, restart dhcpd
/etc/init.d/dhcpd restart
8. Build Etherboot floppy disk images and pad to 1.44MB
8. Build gPXE floppy disk images and pad to 1.44MB
pushd ../../src
make bin/rtl8139.pdsk
popd
@@ -62,8 +55,8 @@ To get qemu running is fairly simple:
-net nic,model=rtl8139 -net tap,ifname=tap0 \
-boot a -fda ../../src/bin/rtl8139.pdsk
You should see qemu start up, load up Etherboot and attempt to boot
from the network.
You should see qemu start up, load up gPXE and attempt to boot from
the network.
@@ -71,8 +64,8 @@ Serial console
==============
You can use the program "serial-console" to obtain a virtual serial
console for Etherboot running within qemu. Run "./serial-console" on
a spare tty (e.g. a separate xterm window) before starting qemu, and
console for gPXE running within qemu. Run "./serial-console" on a
spare tty (e.g. a separate xterm window) before starting qemu, and
ensure that you have enabled CONSOLE_SERIAL in config.h.
When serial-console starts, it will print out the message "Slave pty
+4
View File
@@ -0,0 +1,4 @@
#!gpxe
dhcp net0
imgload img1
boot img1
+8
View File
@@ -0,0 +1,8 @@
#!gpxe
ifopen net0
set net0/ip 10.0.2.15
set net0/netmask 255.255.255.0
set net0/gateway 10.0.2.2
set net0/dns 10.0.2.3
kernel http://etherboot.org/gtest/gtest.gpxe
boot gtest.gpxe
+7 -4
View File
@@ -37,7 +37,9 @@ SYMCHECK := $(PERL) ./util/symcheck.pl
SORTOBJDUMP := $(PERL) ./util/sortobjdump.pl
NRV2B := ./util/nrv2b
ZBIN := ./util/zbin
EFILINK := ./util/efilink
ELF2EFI32 := ./util/elf2efi32
ELF2EFI64 := ./util/elf2efi64
EFIROM := ./util/efirom
DOXYGEN := doxygen
###############################################################################
@@ -58,7 +60,7 @@ SRCDIRS += drivers/block
SRCDIRS += drivers/nvs
SRCDIRS += drivers/bitbash
SRCDIRS += drivers/infiniband
SRCDIRS += interface/pxe interface/efi
SRCDIRS += interface/pxe interface/efi interface/smbios
SRCDIRS += tests
SRCDIRS += crypto crypto/axtls crypto/matrixssl
SRCDIRS += hci hci/commands hci/tui
@@ -115,12 +117,13 @@ install :
#
VERSION_MAJOR = 0
VERSION_MINOR = 9
VERSION_PATCH = 6
EXTRAVERSION =
VERSION_PATCH = 7
EXTRAVERSION =
MM_VERSION = $(VERSION_MAJOR).$(VERSION_MINOR)
VERSION = $(MM_VERSION).$(VERSION_PATCH)$(EXTRAVERSION)
CFLAGS += -DVERSION_MAJOR=$(VERSION_MAJOR) \
-DVERSION_MINOR=$(VERSION_MINOR) \
-DVERSION_PATCH=$(VERSION_PATCH) \
-DVERSION=\"$(VERSION)\"
IDENT = '$(@F) $(VERSION) (GPL) etherboot.org'
version :
+48 -15
View File
@@ -85,6 +85,13 @@ VERYCLEANUP += .toolcheck
# Check for various tool workarounds
#
# Make syntax does not allow use of comma or space in certain places.
# This ugly workaround is suggested in the manual.
#
COMMA := ,
EMPTY :=
SPACE := $(EMPTY) $(EMPTY)
# Check for an old version of gas (binutils 2.9.1)
#
OLDGAS := $(shell $(AS) --version | grep -q '2\.9\.1' && $(ECHO) -DGAS291)
@@ -279,14 +286,11 @@ CFLAGS += $(EXTRA_CFLAGS)
ASFLAGS += $(EXTRA_ASFLAGS)
LDFLAGS += $(EXTRA_LDFLAGS)
# Embedded image, if present
#
EMBEDDED_IMAGE = /dev/null
# Inhibit -Werror if NO_WERROR is specified on make command line
#
ifneq ($(NO_WERROR),1)
CFLAGS += -Werror
ASFLAGS += --fatal-warnings
endif
# compiler.h is needed for our linking and debugging system
@@ -405,13 +409,31 @@ drivers :
roms :
@$(ECHO) $(ROMS)
# Embedded binary
$(BIN)/embedimg.bin: $(EMBEDDED_IMAGE)
$(QM)$(ECHO) " [COPY] $@"
$(Q)$(CP) -f $(EMBEDDED_IMAGE) $@
# List of embedded images included in the last build of embedded.o.
# This is needed in order to correctly rebuild embedded.o whenever the
# list of objects changes.
#
EMBEDDED_LIST := $(BIN)/.embedded.list
ifeq ($(wildcard $(EMBEDDED_LIST)),)
EMBEDDED_LIST_IMAGE :=
else
EMBEDDED_LIST_IMAGE := $(shell cat $(EMBEDDED_LIST))
endif
ifneq ($(EMBEDDED_LIST_IMAGE),$(EMBEDDED_IMAGE))
$(shell $(ECHO) "$(EMBEDDED_IMAGE)" > $(EMBEDDED_LIST))
endif
$(BIN)/embed.o: $(BIN)/embedimg.bin
CFLAGS_embed = -DEMBEDIMG=\"$(BIN)/embedimg.bin\"
$(EMBEDDED_LIST) :
VERYCLEANUP += $(EMBEDDED_LIST)
EMBEDDED_FILES := $(subst $(COMMA), ,$(EMBEDDED_IMAGE))
EMBED_ALL := $(foreach i,$(shell seq 1 $(words $(EMBEDDED_FILES))),\
EMBED ( $(i), \"$(word $(i), $(EMBEDDED_FILES))\",\
\"$(notdir $(word $(i),$(EMBEDDED_FILES)))\" ))
$(BIN)/embedded.o : $(EMBEDDED_FILES) $(EMBEDDED_LIST)
CFLAGS_embedded = -DEMBED_ALL="$(EMBED_ALL)"
# Generate the NIC file from the parsed source files. The NIC file is
# only for rom-o-matic.
@@ -490,7 +512,6 @@ TGT_MAKEROM_FLAGS = $(strip $(MAKEROM_FLAGS_$(TGT_ROM_NAME)) \
# Calculate list of debugging versions of objects to be included in
# the target.
#
COMMA := ,
DEBUG_LIST = $(subst $(COMMA), ,$(DEBUG))
DEBUG_OBJ_LEVEL = $(firstword $(word 2,$(subst :, ,$(1))) 1)
DEBUG_OBJ_BASE = $(word 1,$(subst :, ,$(1))).dbg$(call DEBUG_OBJ_LEVEL,$(1))
@@ -703,12 +724,24 @@ CLEANUP += $(ZBIN)
###############################################################################
#
# The EFI custom linker
# The EFI image converter
#
$(EFILINK) : util/efilink.c $(MAKEDEPS)
$(ELF2EFI32) : util/elf2efi.c $(MAKEDEPS)
$(QM)$(ECHO) " [HOSTCC] $@"
$(Q)$(HOST_CC) -O2 -o $@ $< -lbfd -liberty
CLEANUP += $(EFILINK)
$(Q)$(HOST_CC) -DMDE_CPU_IA32 -idirafter include -O2 \
-o $@ $< -lbfd -liberty
CLEANUP += $(ELF2EFI32)
$(ELF2EFI64) : util/elf2efi.c $(MAKEDEPS)
$(QM)$(ECHO) " [HOSTCC] $@"
$(Q)$(HOST_CC) -DMDE_CPU_X64 -idirafter include -O2 \
-o $@ $< -lbfd -liberty
CLEANUP += $(ELF2EFI64)
$(EFIROM) : util/efirom.c $(MAKEDEPS)
$(QM)$(ECHO) " [HOSTCC] $@"
$(Q)$(HOST_CC) -idirafter include -O2 -o $@ $<
CLEANUP += $(EFIROM)
###############################################################################
#
+5 -1
View File
@@ -68,7 +68,6 @@ SRCDIRS += arch/i386/drivers/net
SRCDIRS += arch/i386/interface/pcbios
SRCDIRS += arch/i386/interface/pxe
SRCDIRS += arch/i386/interface/syslinux
SRCDIRS += arch/i386/interface/efi
# The various xxx_loader.c files are #included into core/loader.c and
# should not be compiled directly.
@@ -82,6 +81,11 @@ NON_AUTO_SRCS += arch/i386/core/wince_loader.c
OBJS_unnrv2b = unnrv2b unnrv2b16
CFLAGS_unnrv2b16 = -DCODE16
# Include common x86 Makefile
#
MAKEDEPS += arch/x86/Makefile
include arch/x86/Makefile
# Include platform-specific Makefile
#
MAKEDEPS += arch/i386/Makefile.$(PLATFORM)
+5 -19
View File
@@ -1,24 +1,10 @@
# -*- makefile -*- : Force emacs to use Makefile mode
# The EFI linker script
# Specify EFI image builder
#
LDSCRIPT = arch/i386/scripts/efi.lds
ELF2EFI = $(ELF2EFI32)
# Use a relocatable link; we perform final relocations in the efilink utility.
# Include generic EFI Makefile
#
LDFLAGS += -r -d -S
# Media types.
#
NON_AUTO_MEDIA += efi
# Rule for building EFI files
#
$(BIN)/%.efi.tmp-reloc : $(BIN)/%.efi.tmp $(EFILINK)
$(QM)$(ECHO) " [EFILINK] $@"
$(Q)$(LD) -e 0 -o /dev/null $< # Check for unresolved symbols
$(Q)$(EFILINK) $< $@
$(BIN)/%.efi : $(BIN)/%.efi.tmp-reloc
$(QM)$(ECHO) " [FINISH] $@"
$(Q)$(OBJCOPY) -Obinary $< $@
MAKEDEPS += arch/x86/Makefile.efi
include arch/x86/Makefile.efi
+1
View File
@@ -13,6 +13,7 @@ LDFLAGS += -N --no-check-sections
MEDIA += rom
MEDIA += pxe
MEDIA += kpxe
MEDIA += kkpxe
MEDIA += elf
MEDIA += elfd
MEDIA += lmelf
+3 -3
View File
@@ -11,7 +11,7 @@
* Interrupt Descriptor Table
****************************************************************************
*/
.section ".data16"
.section ".data16", "aw", @progbits
.globl idtr
idtr:
idt_limit:
@@ -68,7 +68,7 @@ idt_fixed:
* Destroys %ax, %bx, and %di.
****************************************************************************
*/
.section ".text16"
.section ".text16", "ax", @progbits
.code16
.globl idt_init
idt_init:
@@ -100,7 +100,7 @@ idt_init:
* Interrupt handlers
****************************************************************************
*/
.section ".text"
.section ".text", "ax", @progbits
.code32
/* POSIX signal numbers for reporting traps to GDB */
+1 -1
View File
@@ -4,7 +4,7 @@
* Internal stack
****************************************************************************
*/
.section ".stack"
.section ".stack", "aw", @nobits
.align 8
.globl _stack
_stack:
+1 -1
View File
@@ -4,7 +4,7 @@
* Internal stack
****************************************************************************
*/
.section ".stack16"
.section ".stack16", "aw", @nobits
.align 8
.globl _stack16
_stack16:
+2 -4
View File
@@ -10,11 +10,9 @@
.text
.arch i386
.section ".text16", "ax", @progbits
.section ".data16", "aw", @progbits
.code16
.section ".text16"
.section ".text16", "ax", @progbits
.globl undiisr
undiisr:
@@ -75,7 +73,7 @@ exit: /* Restore registers and return */
popw %ds
iret
.section ".data16"
.section ".data16", "aw", @progbits
undinet_params:
status: .word 0
funcflag: .word 0
+35 -23
View File
@@ -482,8 +482,7 @@ static void undinet_poll ( struct net_device *netdev ) {
undi_isr.Frame.offset, frag_len );
if ( iob_len ( iobuf ) == len ) {
/* Whole packet received; deliver it */
netdev_rx ( netdev, iobuf );
iobuf = NULL;
netdev_rx ( netdev, iob_disown ( iobuf ) );
/* Etherboot 5.4 fails to return all packets
* under mild load; pretend it retriggered.
*/
@@ -670,15 +669,19 @@ int undinet_probe ( struct undi_device *undi ) {
undi->flags |= UNDI_FL_STARTED;
/* Bring up UNDI stack */
memset ( &undi_startup, 0, sizeof ( undi_startup ) );
if ( ( rc = undinet_call ( undinic, PXENV_UNDI_STARTUP, &undi_startup,
sizeof ( undi_startup ) ) ) != 0 )
goto err_undi_startup;
memset ( &undi_initialize, 0, sizeof ( undi_initialize ) );
if ( ( rc = undinet_call ( undinic, PXENV_UNDI_INITIALIZE,
&undi_initialize,
sizeof ( undi_initialize ) ) ) != 0 )
goto err_undi_initialize;
if ( ! ( undi->flags & UNDI_FL_INITIALIZED ) ) {
memset ( &undi_startup, 0, sizeof ( undi_startup ) );
if ( ( rc = undinet_call ( undinic, PXENV_UNDI_STARTUP,
&undi_startup,
sizeof ( undi_startup ) ) ) != 0 )
goto err_undi_startup;
memset ( &undi_initialize, 0, sizeof ( undi_initialize ) );
if ( ( rc = undinet_call ( undinic, PXENV_UNDI_INITIALIZE,
&undi_initialize,
sizeof ( undi_initialize ))) != 0 )
goto err_undi_initialize;
}
undi->flags |= UNDI_FL_INITIALIZED;
/* Get device information */
memset ( &undi_info, 0, sizeof ( undi_info ) );
@@ -732,11 +735,13 @@ int undinet_probe ( struct undi_device *undi ) {
memset ( &undi_cleanup, 0, sizeof ( undi_cleanup ) );
undinet_call ( undinic, PXENV_UNDI_CLEANUP, &undi_cleanup,
sizeof ( undi_cleanup ) );
undi->flags &= ~UNDI_FL_INITIALIZED;
err_undi_startup:
/* Unhook UNDI stack */
memset ( &stop_undi, 0, sizeof ( stop_undi ) );
undinet_call ( undinic, PXENV_STOP_UNDI, &stop_undi,
sizeof ( stop_undi ) );
undi->flags &= ~UNDI_FL_STARTED;
err_start_undi:
netdev_nullify ( netdev );
netdev_put ( netdev );
@@ -759,19 +764,26 @@ void undinet_remove ( struct undi_device *undi ) {
/* Unregister net device */
unregister_netdev ( netdev );
/* Shut down UNDI stack */
memset ( &undi_shutdown, 0, sizeof ( undi_shutdown ) );
undinet_call ( undinic, PXENV_UNDI_SHUTDOWN, &undi_shutdown,
sizeof ( undi_shutdown ) );
memset ( &undi_cleanup, 0, sizeof ( undi_cleanup ) );
undinet_call ( undinic, PXENV_UNDI_CLEANUP, &undi_cleanup,
sizeof ( undi_cleanup ) );
/* If we are preparing for an OS boot, or if we cannot exit
* via the PXE stack, then shut down the PXE stack.
*/
if ( ! ( undi->flags & UNDI_FL_KEEP_ALL ) ) {
/* Unhook UNDI stack */
memset ( &stop_undi, 0, sizeof ( stop_undi ) );
undinet_call ( undinic, PXENV_STOP_UNDI, &stop_undi,
sizeof ( stop_undi ) );
undi->flags &= ~UNDI_FL_STARTED;
/* Shut down UNDI stack */
memset ( &undi_shutdown, 0, sizeof ( undi_shutdown ) );
undinet_call ( undinic, PXENV_UNDI_SHUTDOWN, &undi_shutdown,
sizeof ( undi_shutdown ) );
memset ( &undi_cleanup, 0, sizeof ( undi_cleanup ) );
undinet_call ( undinic, PXENV_UNDI_CLEANUP, &undi_cleanup,
sizeof ( undi_cleanup ) );
undi->flags &= ~UNDI_FL_INITIALIZED;
/* Unhook UNDI stack */
memset ( &stop_undi, 0, sizeof ( stop_undi ) );
undinet_call ( undinic, PXENV_STOP_UNDI, &stop_undi,
sizeof ( stop_undi ) );
undi->flags &= ~UNDI_FL_STARTED;
}
/* Clear entry point */
memset ( &undinet_entry_point, 0, sizeof ( undinet_entry_point ) );
+18
View File
@@ -20,6 +20,7 @@
#include <stdlib.h>
#include <string.h>
#include <gpxe/device.h>
#include <gpxe/init.h>
#include <undi.h>
#include <undinet.h>
#include <undipreload.h>
@@ -107,3 +108,20 @@ struct root_device undi_root_device __root_device = {
.dev = { .name = "UNDI" },
.driver = &undi_root_driver,
};
/**
* Prepare for exit
*
* @v flags Shutdown flags
*/
static void undionly_shutdown ( int flags ) {
/* If we are shutting down to boot an OS, clear the "keep PXE
* stack" flag.
*/
if ( flags & SHUTDOWN_BOOT )
preloaded_undi.flags &= ~UNDI_FL_KEEP_ALL;
}
struct startup_fn startup_undionly __startup_fn ( STARTUP_LATE ) = {
.shutdown = undionly_shutdown,
};
+3 -1
View File
@@ -193,13 +193,14 @@ static const char *ansi_input = "";
* dense range, so subtracting a constant and treating them as offsets
* into an array works efficiently.
*/
#define BIOS_KEY_MIN 0x47
#define BIOS_KEY_MIN 0x42
/** Offset into list of interesting BIOS scancodes */
#define BIOS_KEY(scancode) ( (scancode) - BIOS_KEY_MIN )
/** Mapping from BIOS scan codes to ANSI escape sequences */
static const char *ansi_sequences[] = {
[ BIOS_KEY ( 0x42 ) ] = "[19~", /* F8 (required for PXE) */
[ BIOS_KEY ( 0x47 ) ] = "[H", /* Home */
[ BIOS_KEY ( 0x48 ) ] = "[A", /* Up arrow */
[ BIOS_KEY ( 0x4b ) ] = "[D", /* Left arrow */
@@ -222,6 +223,7 @@ static const char * scancode_to_ansi_seq ( unsigned int scancode ) {
sizeof ( ansi_sequences[0] ) ) ) {
return ansi_sequences[bios_key];
}
DBG ( "Unrecognised BIOS scancode %02x\n", scancode );
return NULL;
}
+18 -21
View File
@@ -18,9 +18,6 @@
.text
.arch i386
.section ".text16", "ax", @progbits
.section ".data16", "aw", @progbits
.section ".text16.data", "aw", @progbits
.code16
#define SMAP 0x534d4150
@@ -62,7 +59,7 @@
*
****************************************************************************
*/
.section ".data16"
.section ".data16", "aw", @progbits
.align 16
.globl hidemem_base
.globl hidemem_umalloc
@@ -94,7 +91,7 @@ memory_windows_end:
* %ecx:%ebx Length of windowed region
****************************************************************************
*/
.section ".text16"
.section ".text16", "ax", @progbits
window_region:
/* Convert (start,len) to (start, end) */
addl %eax, %ebx
@@ -132,7 +129,7 @@ window_region:
* %ax Modified memory above 1M in 1kB blocks
****************************************************************************
*/
.section ".text16"
.section ".text16", "ax", @progbits
patch_1m:
pushal
/* Convert to (start,len) format and call truncate */
@@ -162,7 +159,7 @@ patch_1m:
* %bx Modified memory above 16M in 64kB blocks
****************************************************************************
*/
.section ".text16"
.section ".text16", "ax", @progbits
patch_16m:
pushal
/* Convert to (start,len) format and call truncate */
@@ -193,7 +190,7 @@ patch_16m:
* %bx Modified memory above 16MB, in 64kB blocks
****************************************************************************
*/
.section ".text16"
.section ".text16", "ax", @progbits
patch_1m_16m:
call patch_1m
call patch_16m
@@ -219,7 +216,7 @@ patch_1m_16m:
*
****************************************************************************
*/
.section ".text16"
.section ".text16", "ax", @progbits
get_underlying_e820:
/* If the requested region is in the cache, return it */
@@ -308,22 +305,22 @@ get_underlying_e820:
jmp get_underlying_e820
.size get_underlying_e820, . - get_underlying_e820
.section ".data16"
.section ".data16", "aw", @progbits
underlying_e820_index:
.word 0xffff /* Initialise to an invalid value */
.size underlying_e820_index, . - underlying_e820_index
.section ".bss16"
.section ".bss16", "aw", @nobits
underlying_e820_ebx:
.long 0
.size underlying_e820_ebx, . - underlying_e820_ebx
.section ".bss16"
.section ".bss16", "aw", @nobits
underlying_e820_cache:
.space E820MAXSIZE
.size underlying_e820_cache, . - underlying_e820_cache
.section ".bss16"
.section ".bss16", "aw", @nobits
underlying_e820_cache_size:
.long 0
.size underlying_e820_cache_size, . - underlying_e820_cache_size
@@ -342,7 +339,7 @@ underlying_e820_cache_size:
*
****************************************************************************
*/
.section ".text16"
.section ".text16", "ax", @progbits
get_windowed_e820:
/* Preserve registers */
@@ -417,7 +414,7 @@ get_windowed_e820:
*
****************************************************************************
*/
.section ".text16"
.section ".text16", "ax", @progbits
get_nonempty_e820:
/* Record entry parameters */
@@ -462,7 +459,7 @@ get_nonempty_e820:
*
****************************************************************************
*/
.section ".text16"
.section ".text16", "ax", @progbits
get_mangled_e820:
/* Get a nonempty region */
@@ -496,7 +493,7 @@ get_mangled_e820:
* INT 15,e820 handler
****************************************************************************
*/
.section ".text16"
.section ".text16", "ax", @progbits
int15_e820:
pushw %ds
pushw %cs:rm_ds
@@ -510,7 +507,7 @@ int15_e820:
* INT 15,e801 handler
****************************************************************************
*/
.section ".text16"
.section ".text16", "ax", @progbits
int15_e801:
/* Call previous handler */
pushfw
@@ -536,7 +533,7 @@ int15_e801:
* INT 15,88 handler
****************************************************************************
*/
.section ".text16"
.section ".text16", "ax", @progbits
int15_88:
/* Call previous handler */
pushfw
@@ -557,7 +554,7 @@ int15_88:
* INT 15 handler
****************************************************************************
*/
.section ".text16"
.section ".text16", "ax", @progbits
.globl int15
int15:
/* See if we want to intercept this call */
@@ -580,7 +577,7 @@ int15:
ljmp *%cs:int15_vector
.size int15, . - int15
.section ".text16.data"
.section ".text16.data", "aw", @progbits
.globl int15_vector
int15_vector:
.long 0
+7
View File
@@ -201,6 +201,13 @@ static int meme820 ( struct memory_map *memmap ) {
break;
}
/* If first region is not RAM, assume map is invalid */
if ( ( memmap->count == 0 ) &&
( e820buf.type != E820_TYPE_RAM ) ) {
DBG ( "INT 15,e820 failed, first entry not RAM\n" );
return -EINVAL;
}
DBG ( "INT 15,e820 region [%llx,%llx) type %d",
e820buf.start, ( e820buf.start + e820buf.len ),
( int ) e820buf.type );
+26 -18
View File
@@ -52,7 +52,7 @@ static int com32_exec ( struct image *image ) {
int state;
uint32_t avail_mem_top;
state = setjmp ( comboot_return );
state = rmsetjmp ( comboot_return );
switch ( state ) {
case 0: /* First time through; invoke COM32 program */
@@ -70,20 +70,20 @@ static int com32_exec ( struct image *image ) {
}
DBGC ( image, "COM32 %p: available memory top = 0x%x\n",
image, (int)avail_mem_top );
image, avail_mem_top );
assert ( avail_mem_top != 0 );
com32_external_esp = phys_to_virt ( avail_mem_top );
/* Hook COMBOOT API interrupts */
hook_comboot_interrupts( );
hook_comboot_interrupts();
/* Temporarily de-register image, so that a "boot" command
* doesn't throw us into an execution loop. Hold a reference
* to avoid the image's being freed.
/* Unregister image, so that a "boot" command doesn't
* throw us into an execution loop. We never
* reregister ourselves; COMBOOT images expect to be
* removed on exit.
*/
image_get ( image );
unregister_image ( image );
__asm__ __volatile__ (
@@ -111,25 +111,33 @@ static int com32_exec ( struct image *image ) {
/* %6 */ "r" ( COM32_START_PHYS )
:
"memory" );
DBGC ( image, "COM32 %p: returned\n", image );
break;
case COMBOOT_RETURN_RUN_KERNEL:
DBGC ( image, "COM32 %p: returned to run kernel...\n", image );
comboot_run_kernel ( );
case COMBOOT_EXIT:
DBGC ( image, "COM32 %p: exited\n", image );
break;
case COMBOOT_RETURN_EXIT:
case COMBOOT_EXIT_RUN_KERNEL:
DBGC ( image, "COM32 %p: exited to run kernel %p\n",
image, comboot_replacement_image );
image->replacement = comboot_replacement_image;
comboot_replacement_image = NULL;
image_autoload ( image->replacement );
break;
case COMBOOT_EXIT_COMMAND:
DBGC ( image, "COM32 %p: exited after executing command\n",
image );
break;
default:
assert ( 0 );
break;
}
comboot_force_text_mode ( );
DBGC ( image, "COM32 %p returned\n", image );
/* Re-register image and return */
register_image ( image );
image_put ( image );
unhook_comboot_interrupts();
comboot_force_text_mode();
return 0;
}
+26 -18
View File
@@ -133,7 +133,7 @@ static int comboot_exec ( struct image *image ) {
userptr_t seg_userptr = real_to_user ( COMBOOT_PSP_SEG, 0 );
int state;
state = setjmp ( comboot_return );
state = rmsetjmp ( comboot_return );
switch ( state ) {
case 0: /* First time through; invoke COMBOOT program */
@@ -142,16 +142,16 @@ static int comboot_exec ( struct image *image ) {
comboot_init_psp ( image, seg_userptr );
/* Hook COMBOOT API interrupts */
hook_comboot_interrupts ( );
hook_comboot_interrupts();
DBGC ( image, "executing 16-bit COMBOOT image at %4x:0100\n",
COMBOOT_PSP_SEG );
COMBOOT_PSP_SEG );
/* Temporarily de-register image, so that a "boot" command
* doesn't throw us into an execution loop. Hold a reference
* to avoid the image's being freed.
/* Unregister image, so that a "boot" command doesn't
* throw us into an execution loop. We never
* reregister ourselves; COMBOOT images expect to be
* removed on exit.
*/
image_get ( image );
unregister_image ( image );
/* Store stack segment at 0x38 and stack pointer at 0x3A
@@ -180,26 +180,34 @@ static int comboot_exec ( struct image *image ) {
"xorw %%bp, %%bp\n\t"
"lret\n\t" )
: : "r" ( COMBOOT_PSP_SEG ) : "eax" );
DBGC ( image, "COMBOOT %p: returned\n", image );
break;
case COMBOOT_RETURN_RUN_KERNEL:
DBGC ( image, "COMBOOT %p: returned to run kernel...\n", image );
comboot_run_kernel ( );
case COMBOOT_EXIT:
DBGC ( image, "COMBOOT %p: exited\n", image );
break;
case COMBOOT_RETURN_EXIT:
case COMBOOT_EXIT_RUN_KERNEL:
DBGC ( image, "COMBOOT %p: exited to run kernel %p\n",
image, comboot_replacement_image );
image->replacement = comboot_replacement_image;
comboot_replacement_image = NULL;
image_autoload ( image->replacement );
break;
case COMBOOT_EXIT_COMMAND:
DBGC ( image, "COMBOOT %p: exited after executing command\n",
image );
break;
default:
assert ( 0 );
break;
}
comboot_force_text_mode ( );
unhook_comboot_interrupts();
comboot_force_text_mode();
DBGC ( image, "COMBOOT %p returned\n", image );
/* Re-register image and return */
register_image ( image );
image_put ( image );
return 0;
}
+6
View File
@@ -88,6 +88,12 @@ int pxe_load ( struct image *image ) {
if ( filesz > ( 0xa0000 - 0x7c00 ) )
return -ENOEXEC;
/* Rejecting zero-length images is also useful, since these
* end up looking to the user like bugs in gPXE.
*/
if ( ! filesz )
return -ENOEXEC;
/* There are no signature checks for PXE; we will accept anything */
if ( ! image->type )
image->type = &pxe_image_type;
+5 -40
View File
@@ -2,7 +2,7 @@
#define ETHERBOOT_BITS_BYTESWAP_H
static inline __attribute__ ((always_inline, const)) uint16_t
__i386_bswap_16(uint16_t x)
__bswap_variable_16(uint16_t x)
{
__asm__("xchgb %b0,%h0\n\t"
: "=q" (x)
@@ -11,7 +11,7 @@ __i386_bswap_16(uint16_t x)
}
static inline __attribute__ ((always_inline, const)) uint32_t
__i386_bswap_32(uint32_t x)
__bswap_variable_32(uint32_t x)
{
__asm__("xchgb %b0,%h0\n\t"
"rorl $16,%0\n\t"
@@ -22,7 +22,7 @@ __i386_bswap_32(uint32_t x)
}
static inline __attribute__ ((always_inline, const)) uint64_t
__i386_bswap_64(uint64_t x)
__bswap_variable_64(uint64_t x)
{
union {
uint64_t qword;
@@ -30,47 +30,12 @@ __i386_bswap_64(uint64_t x)
} u;
u.qword = x;
u.dword[0] = __i386_bswap_32(u.dword[0]);
u.dword[1] = __i386_bswap_32(u.dword[1]);
u.dword[0] = __bswap_variable_32(u.dword[0]);
u.dword[1] = __bswap_variable_32(u.dword[1]);
__asm__("xchgl %0,%1"
: "=r" ( u.dword[0] ), "=r" ( u.dword[1] )
: "0" ( u.dword[0] ), "1" ( u.dword[1] ) );
return u.qword;
}
#define __bswap_constant_16(x) \
((uint16_t)((((uint16_t)(x) & 0x00ff) << 8) | \
(((uint16_t)(x) & 0xff00) >> 8)))
#define __bswap_constant_32(x) \
((uint32_t)((((uint32_t)(x) & 0x000000ffU) << 24) | \
(((uint32_t)(x) & 0x0000ff00U) << 8) | \
(((uint32_t)(x) & 0x00ff0000U) >> 8) | \
(((uint32_t)(x) & 0xff000000U) >> 24)))
#define __bswap_constant_64(x) \
((uint64_t)((((uint64_t)(x) & 0x00000000000000ffULL) << 56) | \
(((uint64_t)(x) & 0x000000000000ff00ULL) << 40) | \
(((uint64_t)(x) & 0x0000000000ff0000ULL) << 24) | \
(((uint64_t)(x) & 0x00000000ff000000ULL) << 8) | \
(((uint64_t)(x) & 0x000000ff00000000ULL) >> 8) | \
(((uint64_t)(x) & 0x0000ff0000000000ULL) >> 24) | \
(((uint64_t)(x) & 0x00ff000000000000ULL) >> 40) | \
(((uint64_t)(x) & 0xff00000000000000ULL) >> 56)))
#define __bswap_16(x) \
((uint16_t)(__builtin_constant_p(x) ? \
__bswap_constant_16(x) : \
__i386_bswap_16(x)))
#define __bswap_32(x) \
((uint32_t)(__builtin_constant_p(x) ? \
__bswap_constant_32(x) : \
__i386_bswap_32(x)))
#define __bswap_64(x) \
((uint64_t)(__builtin_constant_p(x) ? \
__bswap_constant_64(x) : \
__i386_bswap_64(x)))
#endif /* ETHERBOOT_BITS_BYTESWAP_H */
+2 -2
View File
@@ -9,10 +9,9 @@
#define ERRFILE_memtop_umalloc ( ERRFILE_ARCH | ERRFILE_CORE | 0x00000000 )
#define ERRFILE_memmap ( ERRFILE_ARCH | ERRFILE_CORE | 0x00010000 )
#define ERRFILE_pnpbios ( ERRFILE_ARCH | ERRFILE_CORE | 0x00020000 )
#define ERRFILE_smbios ( ERRFILE_ARCH | ERRFILE_CORE | 0x00030000 )
#define ERRFILE_bios_smbios ( ERRFILE_ARCH | ERRFILE_CORE | 0x00030000 )
#define ERRFILE_biosint ( ERRFILE_ARCH | ERRFILE_CORE | 0x00040000 )
#define ERRFILE_int13 ( ERRFILE_ARCH | ERRFILE_CORE | 0x00050000 )
#define ERRFILE_smbios_settings ( ERRFILE_ARCH | ERRFILE_CORE | 0x00060000 )
#define ERRFILE_bootsector ( ERRFILE_ARCH | ERRFILE_IMAGE | 0x00000000 )
#define ERRFILE_bzimage ( ERRFILE_ARCH | ERRFILE_IMAGE | 0x00010000 )
@@ -24,6 +23,7 @@
#define ERRFILE_comboot ( ERRFILE_ARCH | ERRFILE_IMAGE | 0x00070000 )
#define ERRFILE_com32 ( ERRFILE_ARCH | ERRFILE_IMAGE | 0x00080000 )
#define ERRFILE_comboot_resolv ( ERRFILE_ARCH | ERRFILE_IMAGE | 0x00090000 )
#define ERRFILE_comboot_call ( ERRFILE_ARCH | ERRFILE_IMAGE | 0x000a0000 )
#define ERRFILE_undi ( ERRFILE_ARCH | ERRFILE_NET | 0x00000000 )
#define ERRFILE_undiload ( ERRFILE_ARCH | ERRFILE_NET | 0x00010000 )
+12
View File
@@ -0,0 +1,12 @@
#ifndef _BITS_SMBIOS_H
#define _BITS_SMBIOS_H
/** @file
*
* i386-specific SMBIOS API implementations
*
*/
#include <gpxe/bios_smbios.h>
#endif /* _BITS_SMBIOS_H */
+2 -2
View File
@@ -1,8 +1,8 @@
#ifndef _BITS_STDINT_H
#define _BITS_STDINT_H
typedef typeof(sizeof(int)) size_t;
typedef signed long ssize_t;
typedef unsigned int size_t;
typedef signed int ssize_t;
typedef signed long off_t;
typedef unsigned char uint8_t;
+41 -10
View File
@@ -57,6 +57,40 @@ typedef struct {
com32_reg32_t eflags; /* Offset 40 */
} com32sys_t;
typedef struct {
uint32_t eax; /* Offset 0 */
uint32_t ecx; /* Offset 4 */
uint32_t edx; /* Offset 8 */
uint32_t ebx; /* Offset 12 */
uint32_t esp; /* Offset 16 */
uint32_t ebp; /* Offset 20 */
uint32_t esi; /* Offset 24 */
uint32_t edi; /* Offset 28 */
uint32_t eip; /* Offset 32 */
} syslinux_pm_regs;
typedef struct {
uint16_t es; /* Offset 0 */
uint16_t _unused_cs; /* Offset 2 */
uint16_t ds; /* Offset 4 */
uint16_t ss; /* Offset 6 */
uint16_t fs; /* Offset 8 */
uint16_t gs; /* Offset 10 */
uint32_t eax; /* Offset 12 */
uint32_t ecx; /* Offset 16 */
uint32_t edx; /* Offset 20 */
uint32_t ebx; /* Offset 24 */
uint32_t esp; /* Offset 28 */
uint32_t ebp; /* Offset 32 */
uint32_t esi; /* Offset 36 */
uint32_t edi; /* Offset 40 */
uint16_t ip; /* Offset 44 */
uint16_t cs; /* Offset 46 */
} syslinux_rm_regs;
typedef struct {
uint32_t dest;
uint32_t src;
@@ -64,6 +98,7 @@ typedef struct {
} comboot_shuffle_descriptor;
extern void hook_comboot_interrupts ( );
extern void unhook_comboot_interrupts ( );
/* These are not the correct prototypes, but it doens't matter,
* as we only ever get the address of these functions;
@@ -77,20 +112,16 @@ extern void com32_cfarcall_wrapper ( );
extern int comboot_resolv ( const char *name, struct in_addr *address );
/* setjmp/longjmp context buffer used to return after loading an image */
extern jmp_buf comboot_return;
extern rmjmp_buf comboot_return;
/* Command line to execute when returning via comboot_return
* with COMBOOT_RETURN_RUN_KERNEL
*/
extern char *comboot_kernel_cmdline;
/* Execute comboot_image_cmdline */
extern void comboot_run_kernel ( );
/* Replacement image when exiting with COMBOOT_EXIT_RUN_KERNEL */
extern struct image *comboot_replacement_image;
extern void *com32_external_esp;
#define COMBOOT_RETURN_EXIT 1
#define COMBOOT_RETURN_RUN_KERNEL 2
#define COMBOOT_EXIT 1
#define COMBOOT_EXIT_RUN_KERNEL 2
#define COMBOOT_EXIT_COMMAND 3
extern void comboot_force_text_mode ( void );
+16
View File
@@ -0,0 +1,16 @@
#ifndef _GPXE_BIOS_SMBIOS_H
#define _GPXE_BIOS_SMBIOS_H
/** @file
*
* Standard PC-BIOS SMBIOS interface
*
*/
#ifdef SMBIOS_PCBIOS
#define SMBIOS_PREFIX_pcbios
#else
#define SMBIOS_PREFIX_pcbios __pcbios_
#endif
#endif /* _GPXE_BIOS_SMBIOS_H */
+31 -5
View File
@@ -1,12 +1,38 @@
#ifndef ETHERBOOT_SETJMP_H
#define ETHERBOOT_SETJMP_H
#include <stdint.h>
#include <realmode.h>
/* Define a type for use by setjmp and longjmp */
#define JBLEN 6
typedef unsigned long jmp_buf[JBLEN];
/** A jump buffer */
typedef struct {
uint32_t retaddr;
uint32_t ebx;
uint32_t esp;
uint32_t ebp;
uint32_t esi;
uint32_t edi;
} jmp_buf[1];
extern int __asmcall setjmp (jmp_buf env);
extern void __asmcall longjmp (jmp_buf env, int val);
/** A real-mode-extended jump buffer */
typedef struct {
jmp_buf env;
uint16_t rm_ss;
uint16_t rm_sp;
} rmjmp_buf[1];
extern int __asmcall setjmp ( jmp_buf env );
extern void __asmcall longjmp ( jmp_buf env, int val );
#define rmsetjmp( _env ) ( { \
(_env)->rm_ss = rm_ss; \
(_env)->rm_sp = rm_sp; \
setjmp ( (_env)->env ); } ) \
#define rmlongjmp( _env, _val ) do { \
rm_ss = (_env)->rm_ss; \
rm_sp = (_env)->rm_sp; \
longjmp ( (_env)->env, (_val) ); \
} while ( 0 )
#endif /* ETHERBOOT_SETJMP_H */
-60
View File
@@ -1,60 +0,0 @@
#ifndef _SMBIOS_H
#define _SMBIOS_H
/** @file
*
* System Management BIOS
*/
#include <stdint.h>
/** An SMBIOS structure header */
struct smbios_header {
/** Type */
uint8_t type;
/** Length */
uint8_t len;
/** Handle */
uint16_t handle;
} __attribute__ (( packed ));
/** SMBIOS structure descriptor */
struct smbios_structure {
/** Copy of SMBIOS structure header */
struct smbios_header header;
/** Offset of structure within SMBIOS */
size_t offset;
/** Length of strings section */
size_t strings_len;
};
/** SMBIOS system information structure */
struct smbios_system_information {
/** SMBIOS structure header */
struct smbios_header header;
/** Manufacturer string */
uint8_t manufacturer;
/** Product string */
uint8_t product;
/** Version string */
uint8_t version;
/** Serial number string */
uint8_t serial;
/** UUID */
uint8_t uuid[16];
/** Wake-up type */
uint8_t wakeup;
} __attribute__ (( packed ));
/** SMBIOS system information structure type */
#define SMBIOS_TYPE_SYSTEM_INFORMATION 1
extern int find_smbios_structure ( unsigned int type,
struct smbios_structure *structure );
extern int read_smbios_structure ( struct smbios_structure *structure,
void *data, size_t len );
extern int read_smbios_string ( struct smbios_structure *structure,
unsigned int index,
void *data, size_t len );
#endif /* _SMBIOS_H */
+6
View File
@@ -95,4 +95,10 @@ static inline void * undi_get_drvdata ( struct undi_device *undi ) {
/** UNDI flag: START_UNDI has been called */
#define UNDI_FL_STARTED 0x0001
/** UNDI flag: UNDI_STARTUP and UNDI_INITIALIZE have been called */
#define UNDI_FL_INITIALIZED 0x0002
/** UNDI flag: keep stack resident */
#define UNDI_FL_KEEP_ALL 0x0004
#endif /* _UNDI_H */
@@ -0,0 +1,84 @@
/*
* Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stdint.h>
#include <string.h>
#include <errno.h>
#include <assert.h>
#include <gpxe/uaccess.h>
#include <gpxe/smbios.h>
#include <realmode.h>
#include <pnpbios.h>
/** @file
*
* System Management BIOS
*
*/
/**
* Find SMBIOS
*
* @v smbios SMBIOS entry point descriptor structure to fill in
* @ret rc Return status code
*/
static int bios_find_smbios ( struct smbios *smbios ) {
union {
struct smbios_entry entry;
uint8_t bytes[256]; /* 256 is maximum length possible */
} u;
static unsigned int offset = 0;
size_t len;
unsigned int i;
uint8_t sum;
/* Try to find SMBIOS */
for ( ; offset < 0x10000 ; offset += 0x10 ) {
/* Read start of header and verify signature */
copy_from_real ( &u.entry, BIOS_SEG, offset,
sizeof ( u.entry ));
if ( u.entry.signature != SMBIOS_SIGNATURE )
continue;
/* Read whole header and verify checksum */
len = u.entry.len;
copy_from_real ( &u.bytes, BIOS_SEG, offset, len );
for ( i = 0 , sum = 0 ; i < len ; i++ ) {
sum += u.bytes[i];
}
if ( sum != 0 ) {
DBG ( "SMBIOS at %04x:%04x has bad checksum %02x\n",
BIOS_SEG, offset, sum );
continue;
}
/* Fill result structure */
DBG ( "Found SMBIOS v%d.%d entry point at %04x:%04x\n",
u.entry.major, u.entry.minor, BIOS_SEG, offset );
smbios->address = phys_to_user ( u.entry.smbios_address );
smbios->len = u.entry.smbios_len;
smbios->count = u.entry.smbios_count;
return 0;
}
DBG ( "No SMBIOS found\n" );
return -ENODEV;
}
PROVIDE_SMBIOS ( pcbios, find_smbios, bios_find_smbios );
+53 -3
View File
@@ -136,6 +136,17 @@ static void ibft_set_ipaddr_option ( struct ibft_ipaddr *ipaddr,
ibft_set_ipaddr ( ipaddr, in );
}
/**
* Read IP address from iBFT (for debugging)
*
* @v strings iBFT string block descriptor
* @v string String field
* @ret ipaddr IP address string
*/
static const char * ibft_ipaddr ( struct ibft_ipaddr *ipaddr ) {
return inet_ntoa ( ipaddr->in );
}
/**
* Allocate a string within iBFT
*
@@ -214,6 +225,18 @@ static int ibft_set_string_option ( struct ibft_string_block *strings,
return 0;
}
/**
* Read string from iBFT (for debugging)
*
* @v strings iBFT string block descriptor
* @v string String field
* @ret data String content (or "<empty>")
*/
static const char * ibft_string ( struct ibft_string_block *strings,
struct ibft_string *string ) {
return ( ( ( char * ) strings->table ) + string->offset );
}
/**
* Fill in NIC portion of iBFT
*
@@ -231,11 +254,16 @@ static int ibft_fill_nic ( struct ibft_nic *nic,
/* Extract values from DHCP configuration */
ibft_set_ipaddr_option ( &nic->ip_address, &ip_setting );
DBG ( "iBFT NIC IP = %s\n", ibft_ipaddr ( &nic->ip_address ) );
ibft_set_ipaddr_option ( &nic->gateway, &gateway_setting );
DBG ( "iBFT NIC gateway = %s\n", ibft_ipaddr ( &nic->gateway ) );
ibft_set_ipaddr_option ( &nic->dns[0], &dns_setting );
DBG ( "iBFT NIC DNS = %s\n", ibft_ipaddr ( &nic->dns[0] ) );
if ( ( rc = ibft_set_string_option ( strings, &nic->hostname,
&hostname_setting ) ) != 0 )
return rc;
DBG ( "iBFT NIC hostname = %s\n",
ibft_string ( strings, &nic->hostname ) );
/* Derive subnet mask prefix from subnet mask */
fetch_ipv4_setting ( NULL, &netmask_setting, &netmask_addr );
@@ -245,11 +273,15 @@ static int ibft_fill_nic ( struct ibft_nic *nic,
netmask_addr.s_addr >>= 1;
}
nic->subnet_mask_prefix = netmask_count;
DBG ( "iBFT NIC subnet = /%d\n", nic->subnet_mask_prefix );
/* Extract values from net-device configuration */
memcpy ( nic->mac_address, netdev->ll_addr,
sizeof ( nic->mac_address ) );
DBG ( "iBFT NIC MAC = %s\n",
netdev->ll_protocol->ntoa ( nic->mac_address ) );
nic->pci_bus_dev_func = netdev->dev->desc.location;
DBG ( "iBFT NIC PCI = %04x\n", nic->pci_bus_dev_func );
return 0;
}
@@ -269,6 +301,8 @@ static int ibft_fill_initiator ( struct ibft_initiator *initiator,
if ( ( rc = ibft_set_string ( strings, &initiator->initiator_name,
initiator_iqn ) ) != 0 )
return rc;
DBG ( "iBFT initiator hostname = %s\n",
ibft_string ( strings, &initiator->initiator_name ) );
return 0;
}
@@ -286,17 +320,23 @@ static int ibft_fill_target_chap ( struct ibft_target *target,
struct iscsi_session *iscsi ) {
int rc;
if ( ! iscsi->initiator_username )
if ( ! ( iscsi->status & ISCSI_STATUS_AUTH_FORWARD_REQUIRED ) )
return 0;
assert ( iscsi->initiator_username );
assert ( iscsi->initiator_password );
target->chap_type = IBFT_CHAP_ONE_WAY;
if ( ( rc = ibft_set_string ( strings, &target->chap_name,
iscsi->initiator_username ) ) != 0 )
return rc;
DBG ( "iBFT target username = %s\n",
ibft_string ( strings, &target->chap_name ) );
if ( ( rc = ibft_set_string ( strings, &target->chap_secret,
iscsi->initiator_password ) ) != 0 )
return rc;
DBG ( "iBFT target password = <redacted>\n" );
return 0;
}
@@ -313,19 +353,25 @@ static int ibft_fill_target_reverse_chap ( struct ibft_target *target,
struct iscsi_session *iscsi ) {
int rc;
if ( ! iscsi->target_username )
if ( ! ( iscsi->status & ISCSI_STATUS_AUTH_REVERSE_REQUIRED ) )
return 0;
assert ( iscsi->target_password );
assert ( iscsi->initiator_username );
assert ( iscsi->initiator_password );
assert ( iscsi->target_username );
assert ( iscsi->target_password );
target->chap_type = IBFT_CHAP_MUTUAL;
if ( ( rc = ibft_set_string ( strings, &target->reverse_chap_name,
iscsi->target_username ) ) != 0 )
return rc;
DBG ( "iBFT target reverse username = %s\n",
ibft_string ( strings, &target->chap_name ) );
if ( ( rc = ibft_set_string ( strings, &target->reverse_chap_secret,
iscsi->target_password ) ) != 0 )
return rc;
DBG ( "iBFT target reverse password = <redacted>\n" );
return 0;
}
@@ -346,10 +392,14 @@ static int ibft_fill_target ( struct ibft_target *target,
/* Fill in Target values */
ibft_set_ipaddr ( &target->ip_address, sin_target->sin_addr );
DBG ( "iBFT target IP = %s\n", ibft_ipaddr ( &target->ip_address ) );
target->socket = ntohs ( sin_target->sin_port );
DBG ( "iBFT target port = %d\n", target->socket );
if ( ( rc = ibft_set_string ( strings, &target->target_name,
iscsi->target_iqn ) ) != 0 )
return rc;
DBG ( "iBFT target name = %s\n",
ibft_string ( strings, &target->target_name ) );
if ( ( rc = ibft_fill_target_chap ( target, strings, iscsi ) ) != 0 )
return rc;
if ( ( rc = ibft_fill_target_reverse_chap ( target, strings,
@@ -92,7 +92,7 @@ static int init_eheap ( void ) {
}
}
if ( ! top ) {
if ( ! heap_size ) {
DBG ( "No external heap available\n" );
return -ENOMEM;
}
@@ -139,9 +139,9 @@ static userptr_t memtop_urealloc ( userptr_t ptr, size_t new_size ) {
int rc;
/* Initialise external memory allocator if necessary */
if ( ! top ) {
if ( bottom == top ) {
if ( ( rc = init_eheap() ) != 0 )
return rc;
return UNULL;
}
/* Get block properties into extmem */
+11 -9
View File
@@ -433,22 +433,24 @@ void pxe_init_structures ( void ) {
* @ret rc Return status code
*/
int pxe_start_nbp ( void ) {
int discard_b, discard_c;
int discard_b, discard_c, discard_d, discard_D;
uint16_t rc;
/* Far call to PXE NBP */
__asm__ __volatile__ ( REAL_CODE ( "pushw %%cx\n\t"
"pushw %%ax\n\t"
"movw %%cx, %%es\n\t"
__asm__ __volatile__ ( REAL_CODE ( "movw %%cx, %%es\n\t"
"pushw %%es\n\t"
"pushw %%di\n\t"
"sti\n\t"
"lcall $0, $0x7c00\n\t"
"addw $4, %%sp\n\t" )
: "=a" ( rc ), "=b" ( discard_b ),
"=c" ( discard_c )
: "a" ( __from_text16 ( &ppxe ) ),
"b" ( __from_text16 ( &pxenv ) ),
"c" ( rm_cs )
: "edx", "esi", "edi", "ebp", "memory" );
"=c" ( discard_c ), "=d" ( discard_d ),
"=D" ( discard_D )
: "a" ( 0 ), "b" ( __from_text16 ( &pxenv ) ),
"c" ( rm_cs ),
"d" ( virt_to_phys ( &pxenv ) ),
"D" ( __from_text16 ( &ppxe ) )
: "esi", "ebp", "memory" );
return rc;
}
+14 -13
View File
@@ -18,15 +18,12 @@
*/
.arch i386
.section ".text16", "awx", @progbits
.section ".text16.data", "aw", @progbits
.section ".data16", "aw", @progbits
/****************************************************************************
* !PXE structure
****************************************************************************
*/
.section ".text16.data"
.section ".text16.data", "aw", @progbits
.globl ppxe
.align 16
ppxe:
@@ -56,7 +53,7 @@ pxe_segments:
.size ppxe, . - ppxe
/* Define undiheader=0 as a weak symbol for non-ROM builds */
.section ".weak"
.section ".weak", "a", @nobits
.weak undiheader
undiheader:
@@ -64,7 +61,7 @@ undiheader:
* PXENV+ structure
****************************************************************************
*/
.section ".text16.data"
.section ".text16.data", "aw", @progbits
.globl pxenv
.align 16
pxenv:
@@ -108,12 +105,12 @@ pxenv:
* somebody at Wyse has difficulty distinguishing between the
* words "may" and "must"...
*/
.section ".text16.null"
.section ".text16.null", "ax", @progbits
.code16
pxenv_null_entry:
jmp pxenv_entry
.section ".text16"
.section ".text16", "ax", @progbits
.code16
pxenv_entry:
pushl $pxe_api_call
@@ -137,7 +134,7 @@ pxenv_entry:
* none
****************************************************************************
*/
.section ".text16"
.section ".text16", "ax", @progbits
.code16
pxe_entry:
pxe_entry_sp:
@@ -181,12 +178,13 @@ pxe_entry_common:
* Returns:
* %ax : 0x564e
* %es:bx : Far pointer to the PXENV+ structure
* %edx : Physical address of the PXENV+ structure
* CF cleared
* Corrupts:
* none
****************************************************************************
*/
.section ".text16"
.section ".text16", "ax", @progbits
.code16
.globl pxe_int_1a
pxe_int_1a:
@@ -194,9 +192,12 @@ pxe_int_1a:
cmpw $0x5650, %ax
jne 1f
/* INT 1A,5650 - PXE installation check */
pushw %cs
popw %es
xorl %edx, %edx
movw %cs, %dx
movw %dx, %es
movw $pxenv, %bx
shll $4, %edx
addl $pxenv, %edx
movw $0x564e, %ax
popfw
clc
@@ -205,6 +206,6 @@ pxe_int_1a:
popfw
ljmp *%cs:pxe_int_1a_vector
.section ".text16.data"
.section ".text16.data", "aw", @progbits
.globl pxe_int_1a_vector
pxe_int_1a_vector: .long 0
+1 -1
View File
@@ -82,7 +82,7 @@ struct pxe_dhcp_packet_creator {
static struct pxe_dhcp_packet_creator pxe_dhcp_packet_creators[] = {
[CACHED_INFO_DHCPDISCOVER] = { create_fakedhcpdiscover },
[CACHED_INFO_DHCPACK] = { create_fakedhcpack },
[CACHED_INFO_BINL] = { create_fakeproxydhcpack },
[CACHED_INFO_BINL] = { create_fakepxebsack },
};
/* The case in which the caller doesn't supply a buffer is really
+4 -7
View File
@@ -113,12 +113,6 @@ static int pxe_tftp_xfer_deliver_iob ( struct xfer_interface *xfer __unused,
/* Calculate new buffer position */
pxe_tftp.offset += len;
/* Mildly ugly hack; assume that the first non-zero seek
* indicates the block size.
*/
if ( pxe_tftp.blksize == 0 )
pxe_tftp.blksize = pxe_tftp.offset;
/* Record maximum offset as the file size */
if ( pxe_tftp.max_offset < pxe_tftp.offset )
pxe_tftp.max_offset = pxe_tftp.offset;
@@ -265,10 +259,12 @@ PXENV_EXIT_t pxenv_tftp_open ( struct s_PXENV_TFTP_OPEN *tftp_open ) {
/* Wait for OACK to arrive so that we have the block size */
while ( ( ( rc = pxe_tftp.rc ) == -EINPROGRESS ) &&
( pxe_tftp.blksize == 0 ) ) {
( pxe_tftp.max_offset == 0 ) ) {
step();
}
pxe_tftp.blksize = xfer_window ( &pxe_tftp.xfer );
tftp_open->PacketSize = pxe_tftp.blksize;
DBG ( " blksize=%d", tftp_open->PacketSize );
/* EINPROGRESS is normal; we don't wait for the whole transfer */
if ( rc == -EINPROGRESS )
@@ -571,6 +567,7 @@ PXENV_EXIT_t pxenv_tftp_get_fsize ( struct s_PXENV_TFTP_GET_FSIZE
step();
}
tftp_get_fsize->FileSize = pxe_tftp.max_offset;
DBG ( " fsize=%d", tftp_get_fsize->FileSize );
/* EINPROGRESS is normal; we don't wait for the whole transfer */
if ( rc == -EINPROGRESS )
+160 -65
View File
@@ -35,6 +35,8 @@
#include <gpxe/process.h>
#include <gpxe/serial.h>
#include <gpxe/init.h>
#include <gpxe/image.h>
#include <usr/imgmgmt.h>
/** The "SYSLINUX" version string */
static char __data16_array ( syslinux_version, [] ) = "gPXE " VERSION;
@@ -51,6 +53,14 @@ static char __data16_array ( syslinux_configuration_file, [] ) = "";
static uint8_t __data16 ( comboot_feature_flags ) = COMBOOT_FEATURE_IDLE_LOOP;
#define comboot_feature_flags __use_data16 ( comboot_feature_flags )
typedef union {
syslinux_pm_regs pm; syslinux_rm_regs rm;
} syslinux_regs;
/** Initial register values for INT 22h AX=1Ah and 1Bh */
static syslinux_regs __text16 ( comboot_initial_regs );
#define comboot_initial_regs __use_text16 ( comboot_initial_regs )
static struct segoff __text16 ( int20_vector );
#define int20_vector __use_text16 ( int20_vector )
@@ -65,12 +75,10 @@ extern void int21_wrapper ( void );
extern void int22_wrapper ( void );
/* setjmp/longjmp context buffer used to return after loading an image */
jmp_buf comboot_return;
rmjmp_buf comboot_return;
/* Command line to execute when returning via comboot_return
* with COMBOOT_RETURN_RUN_KERNEL
*/
char *comboot_kernel_cmdline;
/* Replacement image when exiting with COMBOOT_EXIT_RUN_KERNEL */
struct image *comboot_replacement_image;
/* Mode flags set by INT 22h AX=0017h */
static uint16_t comboot_graphics_mode = 0;
@@ -154,58 +162,80 @@ void comboot_force_text_mode ( void ) {
/**
* Run the kernel specified in comboot_kernel_cmdline
* Fetch kernel and optional initrd
*/
void comboot_run_kernel ( )
{
char *initrd;
comboot_force_text_mode ( );
DBG ( "COMBOOT: executing image '%s'\n", comboot_kernel_cmdline );
static int comboot_fetch_kernel ( char *kernel_file, char *cmdline ) {
struct image *kernel = NULL;
struct image *initrd = NULL;
char *initrd_file;
int rc;
/* Find initrd= parameter, if any */
if ( ( initrd = strstr ( comboot_kernel_cmdline, "initrd=" ) ) ) {
char old_char = '\0';
char *initrd_end = strchr( initrd, ' ' );
if ( ( initrd_file = strstr ( cmdline, "initrd=" ) ) != NULL ) {
char *initrd_end;
/* Replace space after end of parameter
* with a nul terminator if this is not
* the last parameter
*/
if ( initrd_end ) {
old_char = *initrd_end;
/* skip "initrd=" */
initrd_file += 7;
/* Find terminating space, if any, and replace with NUL */
initrd_end = strchr ( initrd_file, ' ' );
if ( initrd_end )
*initrd_end = '\0';
DBG ( "COMBOOT: fetching initrd '%s'\n", initrd_file );
/* Allocate and fetch initrd */
initrd = alloc_image();
if ( ! initrd ) {
DBG ( "COMBOOT: could not allocate initrd\n" );
rc = -ENOMEM;
goto out;
}
if ( ( rc = imgfetch ( initrd, initrd_file,
register_image ) ) != 0 ) {
DBG ( "COMBOOT: could not fetch initrd: %s\n",
strerror ( rc ) );
goto out;
}
/* Replace = with space to get 'initrd filename'
* command suitable for system()
*/
initrd[6] = ' ';
DBG( "COMBOOT: loading initrd '%s'\n", initrd );
system ( initrd );
/* Restore space after parameter */
if ( initrd_end ) {
*initrd_end = old_char;
}
/* Restore = */
initrd[6] = '=';
/* Restore space after initrd name, if applicable */
if ( initrd_end )
*initrd_end = ' ';
}
/* Load kernel */
DBG ( "COMBOOT: loading kernel '%s'\n", comboot_kernel_cmdline );
system ( comboot_kernel_cmdline );
DBG ( "COMBOOT: fetching kernel '%s'\n", kernel_file );
free ( comboot_kernel_cmdline );
/* Allocate and fetch kernel */
kernel = alloc_image();
if ( ! kernel ) {
DBG ( "COMBOOT: could not allocate kernel\n" );
rc = -ENOMEM;
goto out;
}
if ( ( rc = imgfetch ( kernel, kernel_file,
register_image ) ) != 0 ) {
DBG ( "COMBOOT: could not fetch kernel: %s\n",
strerror ( rc ) );
goto out;
}
if ( ( rc = image_set_cmdline ( kernel, cmdline ) ) != 0 ) {
DBG ( "COMBOOT: could not set kernel command line: %s\n",
strerror ( rc ) );
goto out;
}
/* Boot */
system ( "boot" );
/* Store kernel as replacement image */
assert ( comboot_replacement_image == NULL );
comboot_replacement_image = image_get ( kernel );
DBG ( "COMBOOT: back from executing command\n" );
out:
/* Drop image references unconditionally; either we want to
* discard them, or they have been registered and we should
* drop out local reference.
*/
image_put ( kernel );
image_put ( initrd );
return rc;
}
@@ -213,7 +243,7 @@ void comboot_run_kernel ( )
* Terminate program interrupt handler
*/
static __asmcall void int20 ( struct i386_all_regs *ix86 __unused ) {
longjmp ( comboot_return, COMBOOT_RETURN_EXIT );
rmlongjmp ( comboot_return, COMBOOT_EXIT );
}
@@ -226,7 +256,7 @@ static __asmcall void int21 ( struct i386_all_regs *ix86 ) {
switch ( ix86->regs.ah ) {
case 0x00:
case 0x4C: /* Terminate program */
longjmp ( comboot_return, COMBOOT_RETURN_EXIT );
rmlongjmp ( comboot_return, COMBOOT_EXIT );
break;
case 0x01: /* Get Key with Echo */
@@ -294,7 +324,7 @@ static __asmcall void int22 ( struct i386_all_regs *ix86 ) {
case 0x0001: /* Get Version */
/* Number of INT 22h API functions available */
ix86->regs.ax = 0x0018;
ix86->regs.ax = 0x001B;
/* SYSLINUX version number */
ix86->regs.ch = 0; /* major */
@@ -323,17 +353,15 @@ static __asmcall void int22 ( struct i386_all_regs *ix86 ) {
char cmd[len + 1];
copy_from_user ( cmd, cmd_u, 0, len + 1 );
DBG ( "COMBOOT: executing command '%s'\n", cmd );
comboot_kernel_cmdline = strdup ( cmd );
DBG ( "COMBOOT: returning to run image...\n" );
longjmp ( comboot_return, COMBOOT_RETURN_RUN_KERNEL );
system ( cmd );
DBG ( "COMBOOT: exiting after executing command...\n" );
rmlongjmp ( comboot_return, COMBOOT_EXIT_COMMAND );
}
break;
case 0x0004: /* Run default command */
/* FIXME: just exit for now */
longjmp ( comboot_return, COMBOOT_RETURN_EXIT );
rmlongjmp ( comboot_return, COMBOOT_EXIT_COMMAND );
break;
case 0x0005: /* Force text mode */
@@ -518,21 +546,21 @@ static __asmcall void int22 ( struct i386_all_regs *ix86 ) {
userptr_t cmd_u = real_to_user ( ix86->segs.es, ix86->regs.bx );
int file_len = strlen_user ( file_u, 0 );
int cmd_len = strlen_user ( cmd_u, 0 );
char file[file_len + 1 + cmd_len + 7 + 1];
char file[file_len + 1];
char cmd[cmd_len + 1];
memcpy( file, "kernel ", 7 );
copy_from_user ( file + 7, file_u, 0, file_len + 1 );
copy_from_user ( file, file_u, 0, file_len + 1 );
copy_from_user ( cmd, cmd_u, 0, cmd_len + 1 );
strcat ( file, " " );
strcat ( file, cmd );
DBG ( "COMBOOT: run kernel image '%s'\n", file );
comboot_kernel_cmdline = strdup ( file );
DBG ( "COMBOOT: returning to run image...\n" );
longjmp ( comboot_return, COMBOOT_RETURN_RUN_KERNEL );
DBG ( "COMBOOT: run kernel %s %s\n", file, cmd );
comboot_fetch_kernel ( file, cmd );
/* Technically, we should return if we
* couldn't load the kernel, but it's not safe
* to do that since we have just overwritten
* part of the COMBOOT program's memory space.
*/
DBG ( "COMBOOT: exiting to run kernel...\n" );
rmlongjmp ( comboot_return, COMBOOT_EXIT_RUN_KERNEL );
}
break;
@@ -549,6 +577,58 @@ static __asmcall void int22 ( struct i386_all_regs *ix86 ) {
ix86->flags &= ~CF;
break;
case 0x001B: /* Cleanup, shuffle and boot to real mode */
if ( ix86->regs.cx > COMBOOT_MAX_SHUFFLE_DESCRIPTORS )
break;
/* Perform final cleanup */
shutdown ( SHUTDOWN_BOOT );
/* Perform sequence of copies */
shuffle ( ix86->segs.es, ix86->regs.di, ix86->regs.cx );
/* Copy initial register values to .text16 */
memcpy_user ( real_to_user ( rm_cs, (unsigned) __from_text16 ( &comboot_initial_regs ) ), 0,
real_to_user ( ix86->segs.ds, ix86->regs.si ), 0,
sizeof(syslinux_rm_regs) );
/* Load initial register values */
__asm__ __volatile__ (
REAL_CODE (
/* Point SS:SP at the register value structure */
"pushw %%cs\n\t"
"popw %%ss\n\t"
"movw $comboot_initial_regs, %%sp\n\t"
/* Segment registers */
"popw %%es\n\t"
"popw %%ax\n\t" /* Skip CS */
"popw %%ds\n\t"
"popw %%ax\n\t" /* Skip SS for now */
"popw %%fs\n\t"
"popw %%gs\n\t"
/* GP registers */
"popl %%eax\n\t"
"popl %%ecx\n\t"
"popl %%edx\n\t"
"popl %%ebx\n\t"
"popl %%ebp\n\t" /* Skip ESP for now */
"popl %%ebp\n\t"
"popl %%esi\n\t"
"popl %%edi\n\t"
/* Load correct SS:ESP */
"movw $(comboot_initial_regs + 6), %%sp\n\t"
"popw %%ss\n\t"
"movl %%cs:(comboot_initial_regs + 28), %%esp\n\t"
"ljmp *%%cs:(comboot_initial_regs + 44)\n\t"
)
: : );
break;
default:
DBG ( "COMBOOT unknown int22 function %04x\n", ix86->regs.ax );
break;
@@ -596,3 +676,18 @@ void hook_comboot_interrupts ( ) {
hook_bios_interrupt ( 0x22, ( unsigned int ) int22_wrapper,
&int22_vector );
}
/**
* Unhook BIOS interrupts related to COMBOOT API (INT 20h, 21h, 22h)
*/
void unhook_comboot_interrupts ( ) {
unhook_bios_interrupt ( 0x20, ( unsigned int ) int20_wrapper,
&int20_vector );
unhook_bios_interrupt ( 0x21, ( unsigned int ) int21_wrapper,
&int21_vector );
unhook_bios_interrupt ( 0x22, ( unsigned int ) int22_wrapper,
&int22_vector );
}
-410
View File
@@ -1,410 +0,0 @@
# This code is no longer used in Etherboot. It is not maintained and
# may not work.
#
# Copyright (c) 1998 Robert Nordier
# All rights reserved.
# Very small bootrom changes by Luigi Rizzo
# <comment author="Luigi Rizzo">
# I recently had the problem of downloading the etherboot code
# from a hard disk partition instead of a floppy, and noticed that
# floppyload.S does not do the job. With a bit of hacking to
# the FreeBSD's boot1.s code, I managed to obtain a boot sector
# which works both for floppies and hard disks -- basically you
# do something like
#
# cat boot1a bin32/<yourcard>.lzrom > /dev/ad0s4
#
# (or whatever is the HD partition you are using, I am using slice
# 4 on FreeBSD) and you are up and running.
# Then with "fdisk" you have to mark your partition as having type "1"
# (which is listed as DOS-- but basically it must be something matching
# the variable PRT_BSD in the assembly source below).
# </comment>
#
# Redistribution and use in source and binary forms are freely
# permitted provided that the above copyright notice and this
# paragraph and the following disclaimer are duplicated in all
# such forms.
#
# This software is provided "AS IS" and without any express or
# implied warranties, including, without limitation, the implied
# warranties of merchantability and fitness for a particular
# purpose.
#
# Makefile:
#boot1a: boot1a.out
# objcopy -S -O binary boot1a.out boot1a
#
#boot1a.out: boot1a.o
# ld -nostdlib -static -N -e start -Ttext 0x7c00 -o boot1a.out boot1a.o
#
#boot1a.o: boot1a.s
# as --defsym FLAGS=0x80 boot1a.s -o boot1a.o
#
#
# $FreeBSD: src/sys/boot/i386/boot2/boot1.s,v 1.10.2.2 2000/07/07 21:12:32 jhb Exp $
# Memory Locations
.set MEM_REL,0x700 # Relocation address
.set MEM_ARG,0x900 # Arguments
.set MEM_ORG,0x7c00 # Origin
.set MEM_BUF,0x8c00 # Load area
.set MEM_BTX,0x9000 # BTX start
.set MEM_JMP,0x9010 # BTX entry point
.set MEM_USR,0xa000 # Client start
.set BDA_BOOT,0x472 # Boot howto flag
# Partition Constants
.set PRT_OFF,0x1be # Partition offset
.set PRT_NUM,0x4 # Partitions
.set PRT_BSD,0x1 # Partition type
# Flag Bits
.set FL_PACKET,0x80 # Packet mode
# Misc. Constants
.set SIZ_PAG,0x1000 # Page size
.set SIZ_SEC,0x200 # Sector size
.globl start
.globl xread
.code16
start: jmp main # Start recognizably
.org 0x4,0x90
#
# Trampoline used by boot2 to call read to read data from the disk via
# the BIOS. Call with:
#
# %cx:%ax - long - LBA to read in
# %es:(%bx) - caddr_t - buffer to read data into
# %dl - byte - drive to read from
# %dh - byte - num sectors to read
#
xread: push %ss # Address
pop %ds # data
#
# Setup an EDD disk packet and pass it to read
#
xread.1: # Starting
pushl $0x0 # absolute
push %cx # block
push %ax # number
push %es # Address of
push %bx # transfer buffer
xor %ax,%ax # Number of
movb %dh,%al # blocks to
push %ax # transfer
push $0x10 # Size of packet
mov %sp,%bp # Packet pointer
callw read # Read from disk
lea 0x10(%bp),%sp # Clear stack
lret # To far caller
#
# Load the rest of boot2 and BTX up, copy the parts to the right locations,
# and start it all up.
#
#
# Setup the segment registers to flat addressing (segment 0) and setup the
# stack to end just below the start of our code.
#
main: cld # String ops inc
xor %cx,%cx # Zero
mov %cx,%es # Address
mov %cx,%ds # data
mov %cx,%ss # Set up
mov $start,%sp # stack
#
# Relocate ourself to MEM_REL. Since %cx == 0, the inc %ch sets
# %cx == 0x100.
#
mov %sp,%si # Source
mov $MEM_REL,%di # Destination
incb %ch # Word count
rep # Copy
movsw # code
#
# If we are on a hard drive, then load the MBR and look for the first
# FreeBSD slice. We use the fake partition entry below that points to
# the MBR when we call nread. The first pass looks for the first active
# FreeBSD slice. The second pass looks for the first non-active FreeBSD
# slice if the first one fails.
#
mov $part4,%si # Partition
cmpb $0x80,%dl # Hard drive?
jb main.4 # No
movb $0x1,%dh # Block count
callw nread # Read MBR
mov $0x1,%cx # Two passes
main.1: mov $MEM_BUF+PRT_OFF,%si # Partition table
movb $0x1,%dh # Partition
main.2: cmpb $PRT_BSD,0x4(%si) # Our partition type?
jne main.3 # No
jcxz main.5 # If second pass
testb $0x80,(%si) # Active?
jnz main.5 # Yes
main.3: add $0x10,%si # Next entry
incb %dh # Partition
cmpb $0x1+PRT_NUM,%dh # In table?
jb main.2 # Yes
dec %cx # Do two
jcxz main.1 # passes
#
# If we get here, we didn't find any FreeBSD slices at all, so print an
# error message and die.
#
booterror: mov $msg_part,%si # Message
jmp error # Error
#
# Floppies use partition 0 of drive 0.
#
main.4: xor %dx,%dx # Partition:drive
#
# Ok, we have a slice and drive in %dx now, so use that to locate and load
# boot2. %si references the start of the slice we are looking for, so go
# ahead and load up the first 16 sectors (boot1 + boot2) from that. When
# we read it in, we conveniently use 0x8c00 as our transfer buffer. Thus,
# boot1 ends up at 0x8c00, and boot2 starts at 0x8c00 + 0x200 = 0x8e00.
# The first part of boot2 is the disklabel, which is 0x200 bytes long.
# The second part is BTX, which is thus loaded into 0x9000, which is where
# it also runs from. The boot2.bin binary starts right after the end of
# BTX, so we have to figure out where the start of it is and then move the
# binary to 0xb000. Normally, BTX clients start at MEM_USR, or 0xa000, but
# when we use btxld create boot2, we use an entry point of 0x1000. That
# entry point is relative to MEM_USR; thus boot2.bin starts at 0xb000.
#
main.5: mov %dx,MEM_ARG # Save args
movb $0x2,%dh # Sector count
mov $0x7e00, %bx
callw nreadbx # Read disk
movb $0x40,%dh # Sector count
movb %dh, %al
callw puthex
mov $0x7e00, %bx
callw nreadbx # Read disk
push %si
mov $msg_r1,%si
callw putstr
pop %si
lcall $0x800,$0 # enter the rom code
int $0x19
msg_r1: .asciz " done\r\n"
.if 0
mov $MEM_BTX,%bx # BTX
mov 0xa(%bx),%si # Get BTX length and set
add %bx,%si # %si to start of boot2.bin
mov $MEM_USR+SIZ_PAG,%di # Client page 1
mov $MEM_BTX+0xe*SIZ_SEC,%cx # Byte
sub %si,%cx # count
rep # Relocate
movsb # client
sub %di,%cx # Byte count
xorb %al,%al # Zero assumed bss from
rep # the end of boot2.bin
stosb # up to 0x10000
callw seta20 # Enable A20
jmp start+MEM_JMP-MEM_ORG # Start BTX
#
# Enable A20 so we can access memory above 1 meg.
#
seta20: cli # Disable interrupts
seta20.1: inb $0x64,%al # Get status
testb $0x2,%al # Busy?
jnz seta20.1 # Yes
movb $0xd1,%al # Command: Write
outb %al,$0x64 # output port
seta20.2: inb $0x64,%al # Get status
testb $0x2,%al # Busy?
jnz seta20.2 # Yes
movb $0xdf,%al # Enable
outb %al,$0x60 # A20
sti # Enable interrupts
retw # To caller
.endif
#
# Trampoline used to call read from within boot1.
#
nread: mov $MEM_BUF,%bx # Transfer buffer
nreadbx: # same but address is in bx
mov 0x8(%si),%ax # Get
mov 0xa(%si),%cx # LBA
push %bx
push %ax
callw putword
pop %ax
pop %bx
push %cs # Read from
callw xread.1 # disk
jnc return # If success, return
mov $msg_read,%si # Otherwise, set the error
# message and fall through to
# the error routine
#
# Print out the error message pointed to by %ds:(%si) followed
# by a prompt, wait for a keypress, and then reboot the machine.
#
error: callw putstr # Display message
mov $prompt,%si # Display
callw putstr # prompt
xorb %ah,%ah # BIOS: Get
int $0x16 # keypress
movw $0x1234, BDA_BOOT # Do a warm boot
ljmp $0xffff,$0x0 # reboot the machine
#
# Display a null-terminated string using the BIOS output.
#
putstr.0: call putchar
putstr: lodsb # Get char
testb %al,%al # End of string?
jne putstr.0 # No
retw
putword: push %ax
movb $'.', %al
callw putchar
movb %ah, %al
callw puthex
pop %ax
puthex: push %ax
shr $4, %al
callw putdigit
pop %ax
putdigit:
andb $0xf, %al
addb $0x30, %al
cmpb $0x39, %al
jbe putchar
addb $7, %al
putchar: push %ax
mov $0x7,%bx
movb $0xe,%ah
int $0x10
pop %ax
retw
#
# Overused return code. ereturn is used to return an error from the
# read function. Since we assume putstr succeeds, we (ab)use the
# same code when we return from putstr.
#
ereturn: movb $0x1,%ah # Invalid
stc # argument
return: retw # To caller
#
# Reads sectors from the disk. If EDD is enabled, then check if it is
# installed and use it if it is. If it is not installed or not enabled, then
# fall back to using CHS. Since we use a LBA, if we are using CHS, we have to
# fetch the drive parameters from the BIOS and divide it out ourselves.
# Call with:
#
# %dl - byte - drive number
# stack - 10 bytes - EDD Packet
#
read: push %dx # Save
movb $0x8,%ah # BIOS: Get drive
int $0x13 # parameters
movb %dh,%ch # Max head number
pop %dx # Restore
jc return # If error
andb $0x3f,%cl # Sectors per track
jz ereturn # If zero
cli # Disable interrupts
mov 0x8(%bp),%eax # Get LBA
push %dx # Save
movzbl %cl,%ebx # Divide by
xor %edx,%edx # sectors
div %ebx # per track
movb %ch,%bl # Max head number
movb %dl,%ch # Sector number
inc %bx # Divide by
xorb %dl,%dl # number
div %ebx # of heads
movb %dl,%bh # Head number
pop %dx # Restore
cmpl $0x3ff,%eax # Cylinder number supportable?
sti # Enable interrupts
ja read.7 # No, try EDD
xchgb %al,%ah # Set up cylinder
rorb $0x2,%al # number
orb %ch,%al # Merge
inc %ax # sector
xchg %ax,%cx # number
movb %bh,%dh # Head number
subb %ah,%al # Sectors this track
mov 0x2(%bp),%ah # Blocks to read
cmpb %ah,%al # To read
jb read.2 # this
movb %ah,%al # track
read.2: mov $0x5,%di # Try count
read.3: les 0x4(%bp),%bx # Transfer buffer
push %ax # Save
movb $0x2,%ah # BIOS: Read
int $0x13 # from disk
pop %bx # Restore
jnc read.4 # If success
dec %di # Retry?
jz read.6 # No
xorb %ah,%ah # BIOS: Reset
int $0x13 # disk system
xchg %bx,%ax # Block count
jmp read.3 # Continue
read.4: movzbw %bl,%ax # Sectors read
add %ax,0x8(%bp) # Adjust
jnc read.5 # LBA,
incw 0xa(%bp) # transfer
read.5: shlb %bl # buffer
add %bl,0x5(%bp) # pointer,
sub %al,0x2(%bp) # block count
ja read # If not done
read.6: retw # To caller
read.7: testb $FL_PACKET,%cs:MEM_REL+flags-start # LBA support enabled?
jz ereturn # No, so return an error
mov $0x55aa,%bx # Magic
push %dx # Save
movb $0x41,%ah # BIOS: Check
int $0x13 # extensions present
pop %dx # Restore
jc return # If error, return an error
cmp $0xaa55,%bx # Magic?
jne ereturn # No, so return an error
testb $0x1,%cl # Packet interface?
jz ereturn # No, so return an error
mov %bp,%si # Disk packet
movb $0x42,%ah # BIOS: Extended
int $0x13 # read
retw # To caller
# Messages
msg_read: .asciz "Rd"
msg_part: .asciz "Boot"
prompt: .asciz " err\r\n"
flags: .byte FLAGS # Flags
.org PRT_OFF,0x90
# Partition table
.fill 0x30,0x1,0x0
part4: .byte 0x80
.byte 0x00 # start head
.byte 0x01 # start sector (6 bits) + start cyl (2 bit)
.byte 0x00 # start cyl (low 8 bits)
.byte 0x1 # part.type
.byte 0xff # end head
.byte 0xff # end sect (6) + end_cyl(2)
.byte 0xff # end cyl
.byte 0x00, 0x00, 0x00, 0x00 # explicit start
.byte 0x50, 0xc3, 0x00, 0x00 # 50000 sectors long, bleh
.word 0xaa55 # Magic number
-175
View File
@@ -1,175 +0,0 @@
.text
.code32
.arch i386
.section ".prefix", "a", @progbits
.org 0x00
/* DOS (.com) header
*
* EFI executables seem to leave most of this empty
*/
mzhdr:
.ascii "MZ" /* Magic number */
.word 0 /* Bytes on last page of file */
.word 0 /* Pages in file */
.word 0 /* Relocations */
.word 0 /* Size of header in paragraphs */
.word 0 /* Minimum extra paragraphs needed */
.word 0 /* Maximum extra paragraphs needed */
.word 0 /* Initial (relative) SS value */
.word 0 /* Initial SP value */
.word 0 /* "Checksum" */
.word 0 /* Initial IP value */
.word 0 /* Initial (relative) CS value */
.word 0 /* File address of relocation table */
.word 0 /* Ovesrlay number */
.word 0, 0, 0, 0 /* Reserved words */
.word 0 /* OEM identifier (for e_oeminfo) */
.word 0 /* OEM information; e_oemid specific */
.word 0, 0, 0, 0, 0 /* Reserved words */
.word 0, 0, 0, 0, 0 /* Reserved words */
.long pehdr_lma /* File address of new exe header */
.size mzhdr, . - mzhdr
/* PE header */
.org 0xc0 /* For compatibility with MS toolchain */
pehdr:
.ascii "PE\0\0" /* Magic number */
.word 0x014c /* CPU architecture: i386 */
.word num_pe_sections /* Number of sections */
.long 0x10d1a884 /* Timestamp */
.long 0 /* Symbol table */
.long 0 /* Number of symbols */
.word opthdr_size /* Size of optional header */
.word 0x2102 /* Characteristics */
.size pehdr, . - pehdr
.equ pehdr_lma, pehdr - mzhdr
/* "Optional" header */
opthdr:
.word 0x010b /* Magic number */
.byte 0 /* Linker major version number */
.byte 0 /* Linker minor version number */
.long _text_filesz /* Size of text section */
.long _data_filesz /* Size of data section */
.long _bss_filesz /* Size of bss section */
.long efi_entry_lma /* Entry point */
.long _text_lma /* Text section start RVA */
.long _data_lma /* Data section start RVA */
.long 0 /* Image base address */
.long _max_align /* Section alignment */
.long _max_align /* File alignment */
.word 0 /* Operating system major version number */
.word 0 /* Operating system minor version number */
.word 0 /* Image major version number */
.word 0 /* Image minor version number */
.word 0 /* Subsystem major version number */
.word 0 /* Subsystem minor version number */
.long 0 /* Reserved */
.long _filesz /* Total image size */
.long _prefix_filesz /* Total header size */
.long 0 /* "Checksum" */
.word 0x0a /* Subsystem: EFI */
.word 0 /* DLL characteristics */
.long 0 /* Size of stack reserve */
.long 0 /* Size of stack commit */
.long 0 /* Size of heap reserve */
.long 0 /* Size of heap commit */
.long 0 /* Loader flags */
.long 16 /* Number of data directory entries */
.long 0, 0 /* Export directory */
.long 0, 0 /* Import directory */
.long 0, 0 /* Resource directory */
.long 0, 0 /* Exception directory */
.long 0, 0 /* Security directory */
.long _reloc_lma, _reloc_filesz /* Base relocation directory */
.long debugdir_lma, debugdir_size /* Debug directory */
.long 0, 0 /* Description directory */
.long 0, 0 /* Special directory */
.long 0, 0 /* Thread storage directory */
.long 0, 0 /* Load configuration directory */
.long 0, 0 /* Bound import directory */
.long 0, 0 /* Import address table directory */
.long 0, 0 /* Delay import directory */
.long 0, 0 /* Reserved */
.long 0, 0 /* Reserved */
.size opthdr, . - opthdr
.equ opthdr_size, . - opthdr
/* PE sections */
pe_sections:
text_section:
.asciz ".text" /* Section name */
.align 8
.long _text_filesz /* Section size */
.long _text_lma /* Relative Virtual Address */
.long _text_filesz /* Section size (rounded up) */
.long _text_lma /* Pointer to raw data */
.long 0 /* Link-time relocations */
.long 0 /* Line numbers */
.word 0 /* Number of link-time relocations */
.word 0 /* Number of line numbers */
.long 0x68000020 /* Characteristics */
rodata_section:
.asciz ".rodata" /* Section name */
.align 8
.long _rodata_filesz /* Section size */
.long _rodata_lma /* Relative Virtual Address */
.long _rodata_filesz /* Section size (rounded up) */
.long _rodata_lma /* Pointer to raw data */
.long 0 /* Link-time relocations */
.long 0 /* Line numbers */
.word 0 /* Number of link-time relocations */
.word 0 /* Number of line numbers */
.long 0x48000040 /* Characteristics */
data_section:
.asciz ".data" /* Section name */
.align 8
.long _data_filesz /* Section size */
.long _data_lma /* Relative Virtual Address */
.long _data_filesz /* Section size (rounded up) */
.long _data_lma /* Pointer to raw data */
.long 0 /* Link-time relocations */
.long 0 /* Line numbers */
.word 0 /* Number of link-time relocations */
.word 0 /* Number of line numbers */
.long 0xc8000040 /* Characteristics */
reloc_section:
.asciz ".reloc" /* Section name */
.align 8
.long _reloc_filesz /* Section size */
.long _reloc_lma /* Relative Virtual Address */
.long _reloc_filesz /* Section size (rounded up) */
.long _reloc_lma /* Pointer to raw data */
.long 0 /* Link-time relocations */
.long 0 /* Line numbers */
.word 0 /* Number of link-time relocations */
.word 0 /* Number of line numbers */
.long 0x42000040 /* Characteristics */
pe_sections_end:
.size pe_sections, . - pe_sections
.equ num_pe_sections, ( ( . - pe_sections ) / 0x28 )
/* Debug directory */
.section ".rodata"
.globl debugdir
debugdir:
.long 0 /* Characteristics */
.long 0x10d1a884 /* Timestamp */
.word 0 /* Major version */
.word 0 /* Minor version */
.long 0x02 /* RSDS? */
.long codeview_rsds_size /* Size of data */
.long codeview_rsds_lma /* RVA */
.long codeview_rsds_lma /* File offset */
.size debugdir, . - debugdir
.equ debugdir_size, . - debugdir
/* Codeview structure */
.globl codeview_rsds
codeview_rsds:
.ascii "RSDS" /* Magic number */
.long 0, 0, 0, 0, 0 /* Unused by EFI */
.asciz "efiprefix.pdb"
.size codeview_rsds, . - codeview_rsds
.equ codeview_rsds_size, . - codeview_rsds
+8
View File
@@ -0,0 +1,8 @@
/*****************************************************************************
* PXE prefix that keeps the whole PXE stack present
*****************************************************************************
*/
#define PXELOADER_KEEP_UNDI
#define PXELOADER_KEEP_PXE
#include "pxeprefix.S"
+22 -24
View File
@@ -18,8 +18,6 @@
*/
.arch i386
.section ".prefix.lib", "awx", @progbits
.section ".data16", "aw", @progbits
/**
* High memory temporary load address
@@ -53,7 +51,7 @@
* %ds:di : next character in output buffer (if applicable)
*****************************************************************************
*/
.section ".prefix.lib"
.section ".prefix.lib", "awx", @progbits
.code16
.globl print_character
print_character:
@@ -93,7 +91,7 @@ print_character:
* %ds:di : next character in output buffer (if applicable)
*****************************************************************************
*/
.section ".prefix.lib"
.section ".prefix.lib", "awx", @progbits
.code16
.globl print_message
print_message:
@@ -123,7 +121,7 @@ print_message:
* %ds:di : next character in output buffer (if applicable)
*****************************************************************************
*/
.section ".prefix.lib"
.section ".prefix.lib", "awx", @progbits
.code16
.globl print_hex_dword
print_hex_dword:
@@ -171,7 +169,7 @@ print_hex_nibble:
* %ds:di : next character in output buffer (if applicable)
*****************************************************************************
*/
.section ".prefix.lib"
.section ".prefix.lib", "awx", @progbits
.code16
.globl print_pci_busdevfn
print_pci_busdevfn:
@@ -181,14 +179,14 @@ print_pci_busdevfn:
xchgb %al, %ah
call print_hex_byte
/* Print ":" */
movb $':', %al
movb $( ':' ), %al
call print_character
/* Print device */
movb %ah, %al
shrb $3, %al
call print_hex_byte
/* Print "." */
movb $'.', %al
movb $( '.' ), %al
call print_character
/* Print function */
movb %ah, %al
@@ -208,7 +206,7 @@ print_pci_busdevfn:
* %ds:di : next character in output buffer (if applicable)
*****************************************************************************
*/
.section ".prefix.lib"
.section ".prefix.lib", "awx", @progbits
.code16
.globl print_kill_line
print_kill_line:
@@ -216,15 +214,15 @@ print_kill_line:
pushw %ax
pushw %cx
/* Print CR */
movb $'\r', %al
movb $( '\r' ), %al
call print_character
/* Print 79 spaces */
movb $' ', %al
movb $( ' ' ), %al
movw $79, %cx
1: call print_character
loop 1b
/* Print CR */
movb $'\r', %al
movb $( '\r' ), %al
call print_character
/* Restore registers and return */
popw %cx
@@ -256,7 +254,7 @@ print_kill_line:
#ifndef KEEP_IT_REAL
/* GDT for protected-mode calls */
.section ".prefix.lib"
.section ".prefix.lib", "awx", @progbits
.align 16
pm_call_vars:
gdt:
@@ -279,7 +277,7 @@ gdt_end:
.equ gdt_length, . - gdt
.size gdt, . - gdt
.section ".prefix.lib"
.section ".prefix.lib", "awx", @progbits
.align 16
pm_saved_gdt:
.long 0, 0
@@ -288,7 +286,7 @@ pm_saved_gdt:
.equ pm_call_vars_size, . - pm_call_vars
#define PM_CALL_VAR(x) ( -pm_call_vars_size + ( (x) - pm_call_vars ) )
.section ".prefix.lib"
.section ".prefix.lib", "awx", @progbits
.code16
pm_call:
/* Preserve registers, flags, and RM return point */
@@ -411,7 +409,7 @@ set_seg_base:
* None
****************************************************************************
*/
.section ".prefix.lib"
.section ".prefix.lib", "awx", @progbits
.code16
copy_bytes:
pushl %ecx
@@ -436,7 +434,7 @@ copy_bytes:
* none
****************************************************************************
*/
.section ".prefix.lib"
.section ".prefix.lib", "awx", @progbits
.code16
install_block:
@@ -533,7 +531,7 @@ install_block:
* none
****************************************************************************
*/
.section ".prefix.lib"
.section ".prefix.lib", "awx", @progbits
.code16
.globl alloc_basemem
alloc_basemem:
@@ -581,7 +579,7 @@ alloc_basemem:
* none
****************************************************************************
*/
.section ".text16"
.section ".text16", "ax", @progbits
.code16
.globl free_basemem
free_basemem:
@@ -613,7 +611,7 @@ free_basemem:
ret
.size free_basemem, . - free_basemem
.section ".text16.data"
.section ".text16.data", "aw", @progbits
.globl hooked_bios_interrupts
hooked_bios_interrupts:
.word 0
@@ -633,7 +631,7 @@ hooked_bios_interrupts:
* none
****************************************************************************
*/
.section ".prefix.lib"
.section ".prefix.lib", "awx", @progbits
.code16
.globl install
install:
@@ -668,7 +666,7 @@ install:
* none
****************************************************************************
*/
.section ".prefix.lib"
.section ".prefix.lib", "awx", @progbits
.code16
.globl install_prealloc
install_prealloc:
@@ -750,7 +748,7 @@ install_prealloc:
.size install_prealloc, . - install_prealloc
/* Vectors for far calls to .text16 functions */
.section ".data16"
.section ".data16", "aw", @progbits
#ifdef KEEP_IT_REAL
init_libkir_vector:
.word init_libkir
@@ -781,7 +779,7 @@ prot_call_vector:
* none
****************************************************************************
*/
.section ".text16"
.section ".text16", "ax", @progbits
.code16
.globl uninstall
uninstall:
+1 -3
View File
@@ -1,9 +1,7 @@
.text
.arch i386
.section ".prefix", "ax", @progbits
.section ".prefix.data", "aw", @progbits
.code16
.section ".prefix"
.section ".prefix", "ax", @progbits
.org 0
nbi_header:
+174 -68
View File
@@ -6,54 +6,103 @@
.text
.arch i386
.org 0
.section ".prefix", "ax", @progbits
.section ".prefix.data", "aw", @progbits
.code16
#include <undi.h>
#define STACK_MAGIC ( 'L' + ( 'R' << 8 ) + ( 'E' << 16 ) + ( 'T' << 24 ) )
/*****************************************************************************
* Entry point: set operating context, print welcome message
*****************************************************************************
*/
.section ".prefix"
/* Set up our non-stack segment registers */
.section ".prefix", "ax", @progbits
jmp $0x7c0, $1f
1: movw %cs, %ax
1:
/* Preserve registers for possible return to PXE */
pushfl
pushal
pushw %gs
pushw %fs
pushw %es
pushw %ds
/* Store magic word on PXE stack and remember PXE %ss:esp */
pushl $STACK_MAGIC
movw %ss, %cs:pxe_ss
movl %esp, %cs:pxe_esp
/* Set up segments */
movw %cs, %ax
movw %ax, %ds
movw $0x40, %ax /* BIOS data segment access */
movw %ax, %fs
/* Record PXENV+ and !PXE nominal addresses */
movw %es, %ax /* PXENV+ address */
movw %ax, pxenv_segment
movw %bx, pxenv_offset
popl %eax /* Discard return address */
popl ppxe_segoff /* !PXE address */
/* Set up stack just below 0x7c00 */
xorw %ax, %ax
movw %ax, %ss
movw $0x7c00, %sp
movl $0x7c00, %esp
/* Clear direction flag, for the sake of sanity */
cld
/* Print welcome message */
movw $10f, %si
xorw %di, %di
call print_message
.section ".prefix.data"
.section ".prefix.data", "aw", @progbits
10: .asciz "PXE->EB:"
.previous
/*****************************************************************************
* Verify PXENV+ structure and record parameters of interest
* Find us a usable !PXE or PXENV+ entry point
*****************************************************************************
*/
detect_pxenv:
/* Signature check */
les pxenv_segoff, %bx
cmpl $0x4e455850, %es:(%bx) /* 'PXEN' signature */
jne no_pxenv
cmpw $0x2b56, %es:4(%bx) /* 'V+' signature */
jne no_pxenv
detect_pxe:
/* Plan A: !PXE pointer from the stack */
lgsl pxe_esp, %ebp /* %gs:%bp -> original stack */
lesw %gs:52(%bp), %bx
call is_valid_ppxe
je have_ppxe
/* Plan B: PXENV+ pointer from initial ES:BX */
movw %gs:32(%bp),%bx
movw %gs:8(%bp),%es
call is_valid_pxenv
je have_pxenv
/* Plan C: PXENV+ structure via INT 1Ah */
movw $0x5650, %ax
int $0x1a
jc 1f
cmpw $0x564e, %ax
jne 1f
call is_valid_pxenv
je have_pxenv
1:
/* Plan D: scan base memory for !PXE */
call memory_scan_ppxe
je have_ppxe
/* Plan E: scan base memory for PXENV+ */
call memory_scan_pxenv
jne stack_not_found
have_pxenv:
movw %bx, pxenv_offset
movw %es, pxenv_segment
cmpw $0x201, %es:6(%bx) /* API version >= 2.01 */
jb 1f
cmpb $0x2c, %es:8(%bx) /* ... and structure long enough */
jb 2f
lesw %es:0x28(%bx), %bx /* Find !PXE from PXENV+ */
call is_valid_ppxe
je have_ppxe
2:
call memory_scan_ppxe /* We are *supposed* to have !PXE... */
je have_ppxe
1:
lesw pxenv_segoff, %bx /* Nope, we're stuck with PXENV+ */
/* Record entry point and UNDI segments */
pushl %es:0x0a(%bx) /* Entry point */
popl entry_segoff
@@ -63,36 +112,22 @@ detect_pxenv:
pushw %es:0x20(%bx) /* UNDI data segment */
pushw %es:0x22(%bx) /* UNDI data size */
popl undi_data_segoff
/* Print "PXENV+ at <address>" */
movw $10f, %si
call print_message
call print_segoff
movb $',', %al
movb $( ',' ), %al
call print_character
jmp 99f
.section ".prefix.data"
jmp check_have_stack
.section ".prefix.data", "aw", @progbits
10: .asciz " PXENV+ at "
.previous
no_pxenv:
xorl %eax, %eax
movl %eax, pxenv_segoff
99:
/*****************************************************************************
* Verify !PXE structure and record parameters of interest
*****************************************************************************
*/
detect_ppxe:
/* Signature check */
les ppxe_segoff, %bx
cmpl $0x45585021, %es:(%bx) /* '!PXE' signature */
jne no_ppxe
/* Record structure address, entry point, and UNDI segments */
pushw %es
popw ppxe_segment
have_ppxe:
movw %bx, ppxe_offset
movw %es, ppxe_segment
pushl %es:0x10(%bx) /* Entry point */
popl entry_segoff
pushw %es:0x30(%bx) /* UNDI code segment */
@@ -105,19 +140,62 @@ detect_ppxe:
movw $10f, %si
call print_message
call print_segoff
movb $',', %al
movb $( ',' ), %al
call print_character
jmp 99f
.section ".prefix.data"
jmp check_have_stack
.section ".prefix.data", "aw", @progbits
10: .asciz " !PXE at "
.previous
no_ppxe:
xorl %eax, %eax
movl %eax, ppxe_segoff
is_valid_ppxe:
cmpl $0x45585021, %es:(%bx)
jne 1f
movzbw %es:4(%bx), %cx
cmpw $0x58, %cx
jae is_valid_checksum
1:
ret
is_valid_pxenv:
cmpl $0x4e455850, %es:(%bx)
jne 1b
cmpw $0x2b56, %es:4(%bx)
jne 1b
movzbw %es:8(%bx), %cx
cmpw $0x28, %cx
jb 1b
is_valid_checksum:
pushw %ax
movw %bx, %si
xorw %ax, %ax
2:
es lodsb
addb %al, %ah
loopw 2b
popw %ax
ret
99:
memory_scan_ppxe:
movw $is_valid_ppxe, %dx
jmp memory_scan_common
memory_scan_pxenv:
movw $is_valid_pxenv, %dx
memory_scan_common:
movw %fs:(0x13), %ax
shlw $6, %ax
decw %ax
1: incw %ax
cmpw $( 0xa000 - 1 ), %ax
ja 2f
movw %ax, %es
xorw %bx, %bx
call *%dx
jne 1b
2: ret
/*****************************************************************************
* Sanity check: we must have an entry point
*****************************************************************************
@@ -128,10 +206,11 @@ check_have_stack:
testl %eax, %eax
jnz 99f
/* No entry point: print message and skip everything else */
stack_not_found:
movw $10f, %si
call print_message
jmp finished
.section ".prefix.data"
.section ".prefix.data", "aw", @progbits
10: .asciz " No PXE stack found!\n"
.previous
99:
@@ -169,7 +248,7 @@ print_structure_information:
call print_message
les entry_segoff, %bx
call print_segoff
.section ".prefix.data"
.section ".prefix.data", "aw", @progbits
10: .asciz " entry point at "
.previous
/* Print UNDI code segment */
@@ -177,7 +256,7 @@ print_structure_information:
call print_message
les undi_code_segoff, %bx
call print_segoff
.section ".prefix.data"
.section ".prefix.data", "aw", @progbits
10: .asciz "\n UNDI code segment "
.previous
/* Print UNDI data segment */
@@ -185,7 +264,7 @@ print_structure_information:
call print_message
les undi_data_segoff, %bx
call print_segoff
.section ".prefix.data"
.section ".prefix.data", "aw", @progbits
10: .asciz ", data segment "
.previous
/* Print UNDI memory usage */
@@ -193,13 +272,13 @@ print_structure_information:
call print_message
movw undi_fbms_start, %ax
call print_word
movb $'-', %al
movb $( '-' ), %al
call print_character
movw undi_fbms_end, %ax
call print_word
movw $20f, %si
call print_message
.section ".prefix.data"
.section ".prefix.data", "aw", @progbits
10: .asciz " ("
20: .asciz "kB)\n"
.previous
@@ -233,7 +312,7 @@ pci_physical_device:
movb $0x0a, %al
call print_character
jmp 99f
.section ".prefix.data"
.section ".prefix.data", "aw", @progbits
10: .asciz " UNDI device is PCI "
.previous
@@ -241,7 +320,7 @@ no_physical_device:
/* No device found, or device type not understood */
movw $10f, %si
call print_message
.section ".prefix.data"
.section ".prefix.data", "aw", @progbits
10: .asciz " Unable to determine UNDI physical device\n"
.previous
@@ -251,6 +330,7 @@ no_physical_device:
* Leave NIC in a safe state
*****************************************************************************
*/
#ifndef PXELOADER_KEEP_PXE
shutdown_nic:
/* Issue PXENV_UNDI_SHUTDOWN */
movw $PXENV_UNDI_SHUTDOWN, %bx
@@ -258,11 +338,6 @@ shutdown_nic:
jnc 1f
call print_pxe_error
1:
/*****************************************************************************
* Unload PXE base code
*****************************************************************************
*/
unload_base_code:
/* Issue PXENV_UNLOAD_STACK */
movw $PXENV_UNLOAD_STACK, %bx
@@ -275,6 +350,8 @@ unload_base_code:
movw %fs:(0x13), %bx
call free_basemem
99:
andw $~( UNDI_FL_INITIALIZED | UNDI_FL_KEEP_ALL ), flags
#endif /* PXELOADER_KEEP_PXE */
/*****************************************************************************
* Unload UNDI driver
@@ -308,7 +385,7 @@ print_free_basemem:
call print_word
movw $20f, %si
call print_message
.section ".prefix.data"
.section ".prefix.data", "aw", @progbits
10: .asciz " "
20: .asciz "kB free base memory after PXE unload\n"
.previous
@@ -336,7 +413,7 @@ print_segoff:
/* Print "<segment>:offset" */
movw %es, %ax
call print_hex_word
movb $':', %al
movb $( ':' ), %al
call print_character
movw %bx, %ax
call print_hex_word
@@ -503,7 +580,7 @@ print_pxe_error:
call print_message
popw %si
ret
.section ".prefix.data"
.section ".prefix.data", "aw", @progbits
10: .asciz " UNDI API call "
20: .asciz " failed: status code "
30: .asciz "\n"
@@ -513,6 +590,10 @@ print_pxe_error:
* PXE data structures
*****************************************************************************
*/
.section ".prefix.data"
pxe_esp: .long 0
pxe_ss: .word 0
pxe_parameter_structure: .fill 20
@@ -549,14 +630,16 @@ isapnp_read_port: .word UNDI_NO_ISAPNP_READ_PORT
pci_vendor: .word 0
pci_device: .word 0
flags: .word UNDI_FL_STARTED
flags:
.word ( UNDI_FL_INITIALIZED | UNDI_FL_STARTED | UNDI_FL_KEEP_ALL )
.equ undi_device_size, ( . - undi_device )
/*****************************************************************************
* Run gPXE main code
*****************************************************************************
*/
*/
.section ".prefix"
run_gpxe:
/* Install gPXE */
call install
@@ -574,6 +657,10 @@ run_gpxe:
rep movsb
#endif
/* Retrieve PXE %ss:esp */
movw pxe_ss, %di
movl pxe_esp, %ebp
/* Jump to .text16 segment with %ds pointing to .data16 */
movw %bx, %ds
pushw %ax
@@ -590,6 +677,25 @@ run_gpxe:
/* Uninstall gPXE */
call uninstall
/* Boot next device */
/* Restore PXE stack */
movw %di, %ss
movl %ebp, %esp
/* Check PXE stack magic */
popl %eax
cmpl $STACK_MAGIC, %eax
jne 1f
/* PXE stack OK: return to caller */
popw %ds
popw %es
popw %fs
popw %gs
popal
popfl
xorw %ax, %ax /* Return success */
lret
1: /* PXE stack corrupt or removed: use INT 18 */
int $0x18
.previous
+21 -19
View File
@@ -175,10 +175,10 @@ init:
/* Fill in product name string, if possible */
movw $prodstr_pci_id, %di
call print_pci_busdevfn
movb $' ', prodstr_separator
movb $( ' ' ), prodstr_separator
/* Print segment address */
movb $' ', %al
movb $( ' ' ), %al
xorw %di, %di
call print_character
movw %cs, %ax
@@ -201,7 +201,7 @@ init:
call print_message
movb %bh, %al
call print_hex_nibble
movb $'.', %al
movb $( '.' ), %al
call print_character
movb %bl, %al
call print_hex_byte
@@ -224,7 +224,7 @@ init:
cmpw %bx, %ax
jbe 1f
pci3_insane: /* PCI 3.0 with insane %gs value: print error and ignore %gs */
movb $'!', %al
movb $( '!' ), %al
call print_character
movw %gs, %ax
call print_hex_word
@@ -332,7 +332,7 @@ got_pmm: /* PMM allocation succeeded */
movw %dx, %ax
xorw %di, %di
call print_hex_word
movb $'@', %al
movb $( '@' ), %al
call print_character
movw %si, %ax
call print_hex_byte
@@ -345,26 +345,28 @@ got_pmm: /* PMM allocation succeeded */
shll $9, %ecx
addr32 rep movsb /* PMM presence implies flat real mode */
movl %edi, decompress_to
/* Shrink ROM and update checksum */
xorw %bx, %bx
xorw %si, %si
movw $_prefix_memsz_sect, %cx
movb %cl, romheader_size
shlw $9, %cx
1: lodsb
addb %al, %bl
loop 1b
subb %bl, checksum
/* Shrink ROM */
movb $_prefix_memsz_sect, romheader_size
pmm_fail:
/* Restore upper register halves */
popal
no_pmm:
/* Update checksum */
xorw %bx, %bx
xorw %si, %si
movzbw romheader_size, %cx
shlw $9, %cx
1: lodsb
addb %al, %bl
loop 1b
subb %bl, checksum
/* Copy self to option ROM space. Required for PCI3.0, which
* loads us to a temporary location in low memory. Will be a
* no-op for lower PCI versions.
*/
movb $' ', %al
movb $( ' ' ), %al
xorw %di, %di
call print_character
movw %gs, %ax
@@ -512,7 +514,7 @@ int19_entry:
call print_message
movw $int19_message_dots, %si
call print_message
movw $0xdf42, %bx
movw $0xdf4e, %bx
call wait_for_key
pushf
xorw %di, %di
@@ -520,7 +522,7 @@ int19_entry:
movw $int19_message_done, %si
call print_message
popf
jnz 1f
jz 1f
/* Leave keypress in buffer and start gPXE. The keypress will
* cause the usual initial Ctrl-B prompt to be skipped.
*/
@@ -539,7 +541,7 @@ orig_int19:
.size orig_int19, . - orig_int19
int19_message_prompt:
.asciz "Press B to boot from "
.asciz "Press N to skip booting from "
.size int19_message_prompt, . - int19_message_prompt
int19_message_dots:
.asciz "..."
-180
View File
@@ -1,180 +0,0 @@
/* -*- sh -*- */
/*
* Linker script for EFI images
*
*/
EXTERN ( efi_entry )
SECTIONS {
/* The file starts at a virtual address of zero, and sections are
* contiguous. Each section is aligned to at least _max_align,
* which defaults to 32. Load addresses are equal to virtual
* addresses.
*/
. = 0;
PROVIDE ( _max_align = 32 );
/*
* The prefix
*
*/
.prefix : {
_prefix = .;
*(.prefix)
*(.prefix.*)
_mprefix = .;
} .bss.prefix (NOLOAD) : {
_eprefix = .;
}
_prefix_filesz = ABSOLUTE ( _mprefix - _prefix );
_prefix_memsz = ABSOLUTE ( _eprefix - _prefix );
/*
* The text section
*
*/
. = ALIGN ( _max_align );
.text : {
_text = .;
*(.text)
*(.text.*)
_mtext = .;
} .bss.text (NOLOAD) : {
_etext = .;
}
_text_filesz = ABSOLUTE ( _mtext - _text );
_text_memsz = ABSOLUTE ( _etext - _text );
/*
* The rodata section
*
*/
. = ALIGN ( _max_align );
.rodata : {
_rodata = .;
*(.rodata)
*(.rodata.*)
_mrodata = .;
} .bss.rodata (NOLOAD) : {
_erodata = .;
}
_rodata_filesz = ABSOLUTE ( _mrodata - _rodata );
_rodata_memsz = ABSOLUTE ( _erodata - _rodata );
/*
* The data section
*
*/
. = ALIGN ( _max_align );
.data : {
_data = .;
*(.data)
*(.data.*)
*(SORT(.tbl.*)) /* Various tables. See include/tables.h */
/* EFI seems to not support proper bss sections */
*(.bss)
*(.bss.*)
*(COMMON)
*(.stack)
*(.stack.*)
_mdata = .;
} .bss.data (NOLOAD) : {
_edata = .;
}
_data_filesz = ABSOLUTE ( _mdata - _data );
_data_memsz = ABSOLUTE ( _edata - _data );
/*
* The bss section
*
*/
. = ALIGN ( _max_align );
.bss : {
_bss = .;
/* EFI seems to not support proper bss sections */
_mbss = .;
} .bss.bss (NOLOAD) : {
_ebss = .;
}
_bss_filesz = ABSOLUTE ( _mbss - _bss );
_bss_memsz = ABSOLUTE ( _ebss - _bss );
/*
* The reloc section
*
*/
. = ALIGN ( _max_align );
.reloc : {
_reloc = .;
/* Provide some dummy contents to force ld to include this
* section. It will be created by the efilink utility.
*/
. += 1;
_mreloc = .;
} .bss.reloc (NOLOAD) : {
_ereloc = .;
}
_reloc_filesz = ABSOLUTE ( _mreloc - _reloc );
_reloc_memsz = ABSOLUTE ( _ereloc - _reloc );
_filesz = ABSOLUTE ( . );
/*
* Weak symbols that need zero values if not otherwise defined
*
*/
.weak 0x0 : {
_weak = .;
*(.weak)
_eweak = .;
}
_assert = ASSERT ( ( _weak == _eweak ), ".weak is non-zero length" );
/*
* Dispose of the comment and note sections to make the link map
* easier to read
*
*/
/DISCARD/ : {
*(.comment)
*(.comment.*)
*(.note)
*(.note.*)
*(.eh_frame)
*(.eh_frame.*)
*(.rel)
*(.rel.*)
}
/*
* Load address calculations.
*
*/
_prefix_lma = ABSOLUTE ( _prefix );
_text_lma = ABSOLUTE ( _text );
_rodata_lma = ABSOLUTE ( _rodata );
_data_lma = ABSOLUTE ( _data );
_bss_lma = ABSOLUTE ( _bss );
_reloc_lma = ABSOLUTE ( _reloc );
/*
* Load addresses required by the prefix
*
*/
efi_entry_lma = ABSOLUTE ( efi_entry );
debugdir_lma = ABSOLUTE ( debugdir );
codeview_rsds_lma = ABSOLUTE ( codeview_rsds );
}
+20 -23
View File
@@ -19,9 +19,6 @@
#define SIZEOF_I386_ALL_REGS ( SIZEOF_REAL_MODE_REGS + SIZEOF_I386_FLAGS )
.arch i386
.section ".text16", "ax", @progbits
.section ".text16.data", "aw", @progbits
.section ".data16", "aw", @progbits
/****************************************************************************
* Global descriptor table
@@ -47,7 +44,7 @@
#else
#define RM_LIMIT_16_19__AVL__SIZE__GRANULARITY 0x00
#endif
.section ".data16"
.section ".data16", "aw", @progbits
.align 16
gdt:
gdtr: /* The first GDT entry is unused, the GDTR can fit here. */
@@ -99,7 +96,7 @@ gdt_end:
* %edi : Physical base of protected-mode code (virt_offset)
****************************************************************************
*/
.section ".text16"
.section ".text16", "ax", @progbits
.code16
.globl init_librm
init_librm:
@@ -149,7 +146,7 @@ init_librm:
popl %eax
lret
.section ".text16"
.section ".text16", "ax", @progbits
.code16
.weak idt_init
set_seg_base:
@@ -177,7 +174,7 @@ idt_init: /* Reuse the return opcode here */
*
****************************************************************************
*/
.section ".text16"
.section ".text16", "ax", @progbits
.code16
real_to_prot:
/* Make sure we have our data segment available */
@@ -209,7 +206,7 @@ real_to_prot:
orb $CR0_PE, %al
movl %eax, %cr0
data32 ljmp $VIRTUAL_CS, $1f
.section ".text"
.section ".text", "ax", @progbits
.code32
1:
/* Set up protected-mode data segments and stack pointer */
@@ -240,7 +237,7 @@ real_to_prot:
ret
/* Default IDTR with no interrupts */
.section ".data16"
.section ".data16", "aw", @progbits
.weak idtr
idtr:
rm_idtr:
@@ -266,7 +263,7 @@ rm_idtr:
*
****************************************************************************
*/
.section ".text"
.section ".text", "ax", @progbits
.code32
prot_to_real:
/* Add return address to data to be moved to RM stack */
@@ -296,7 +293,7 @@ prot_to_real:
movw %ax, %gs
movw %ax, %ss
ljmp $REAL_CS, $1f
.section ".text16"
.section ".text16", "ax", @progbits
.code16
1:
/* Switch to real mode */
@@ -328,13 +325,13 @@ p2r_jump_target:
* rather than .data16 because code needs to be able to locate
* the data segment.
*/
.section ".data16"
.section ".data16", "aw", @progbits
p2r_jump_vector:
.word p2r_jump_target
.globl rm_cs
rm_cs: .word 0
.globl rm_ds
.section ".text16.data"
.section ".text16.data", "aw", @progbits
rm_ds: .word 0
/****************************************************************************
@@ -378,7 +375,7 @@ rm_ds: .word 0
#define PC_OFFSET_FUNCTION ( PC_OFFSET_RETADDR + 4 )
#define PC_OFFSET_END ( PC_OFFSET_FUNCTION + 4 )
.section ".text16"
.section ".text16", "ax", @progbits
.code16
.globl prot_call
prot_call:
@@ -403,7 +400,7 @@ prot_call:
movl $PC_OFFSET_END, %ecx
pushl $1f
jmp real_to_prot
.section ".text"
.section ".text", "ax", @progbits
.code32
1:
/* Set up environment expected by C code */
@@ -419,7 +416,7 @@ prot_call:
movl $PC_OFFSET_END, %ecx
pushl $1f
jmp prot_to_real
.section ".text16"
.section ".text16", "ax", @progbits
.code16
1:
/* Reload GDT and IDT, restore registers and flags and return */
@@ -475,7 +472,7 @@ prot_call:
#define RC_OFFSET_FUNCTION ( RC_OFFSET_RETADDR + 4 )
#define RC_OFFSET_END ( RC_OFFSET_FUNCTION + 4 )
.section ".text"
.section ".text", "ax", @progbits
.code32
.globl real_call
real_call:
@@ -487,7 +484,7 @@ real_call:
movl $( RC_OFFSET_RETADDR + 4 /* function pointer copy */ ), %ecx
pushl $1f
jmp prot_to_real
.section ".text16"
.section ".text16", "ax", @progbits
.code16
1:
/* Call real-mode function */
@@ -503,7 +500,7 @@ real_call:
movl $RC_OFFSET_RETADDR, %ecx
pushl $1f
jmp real_to_prot
.section ".text"
.section ".text", "ax", @progbits
.code32
1:
/* Restore registers and return */
@@ -514,7 +511,7 @@ real_call:
/* Function vector, used because "call xx(%sp)" is not a valid
* 16-bit expression.
*/
.section ".data16"
.section ".data16", "aw", @progbits
rc_function: .word 0, 0
/****************************************************************************
@@ -551,7 +548,7 @@ rc_function: .word 0, 0
* to us.
****************************************************************************
*/
.section ".data"
.section ".data", "aw", @progbits
.globl rm_sp
rm_sp: .word 0
.globl rm_ss
@@ -567,13 +564,13 @@ pm_esp: .long _estack
****************************************************************************
*/
/* Internal copies, created by init_librm (which runs in real mode) */
.section ".data16"
.section ".data16", "aw", @progbits
_virt_offset: .long 0
_text16: .long 0
_data16: .long 0
/* Externally-visible copies, created by real_to_prot */
.section ".data"
.section ".data", "aw", @progbits
.globl virt_offset
virt_offset: .long 0
.globl text16
+9
View File
@@ -0,0 +1,9 @@
# Include common x86 headers
#
CFLAGS += -Iarch/x86/include
# x86-specific directories containing source files
#
SRCDIRS += arch/x86/core
SRCDIRS += arch/x86/interface/efi
SRCDIRS += arch/x86/prefix
+28
View File
@@ -0,0 +1,28 @@
# -*- makefile -*- : Force emacs to use Makefile mode
# The EFI linker script
#
LDSCRIPT = arch/x86/scripts/efi.lds
# Retain relocation information for elf2efi
#
LDFLAGS += -q -S
# Media types.
#
NON_AUTO_MEDIA += efi
NON_AUTO_MEDIA += efidrv
# Rules for building EFI files
#
$(BIN)/%.efi : $(BIN)/%.efi.tmp $(ELF2EFI)
$(QM)$(ECHO) " [FINISH] $@"
$(Q)$(ELF2EFI) --subsystem=10 $< $@
$(BIN)/%.efidrv : $(BIN)/%.efidrv.tmp $(ELF2EFI)
$(QM)$(ECHO) " [FINISH] $@"
$(Q)$(ELF2EFI) --subsystem=11 $< $@
$(BIN)/%.efirom : $(BIN)/%.efidrv $(EFIROM)
$(QM)$(ECHO) " [FINISH] $@"
$(Q)$(EFIROM) -v $(TGT_PCI_VENDOR) -d $(TGT_PCI_DEVICE) $< $@
@@ -16,6 +16,7 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <gpxe/io.h>
#include <gpxe/pci.h>
/** @file
@@ -32,9 +32,7 @@
* @v len Length
* @ret dest Destination address
*/
__attribute__ (( regparm ( 3 ) )) void * __memcpy ( void *dest,
const void *src,
size_t len ) {
void * __memcpy ( void *dest, const void *src, size_t len ) {
void *edi = dest;
const void *esi = src;
int discard_ecx;
@@ -23,9 +23,7 @@
#define __HAVE_ARCH_MEMCPY
extern __attribute__ (( regparm ( 3 ) )) void * __memcpy ( void *dest,
const void *src,
size_t len );
extern void * __memcpy ( void *dest, const void *src, size_t len );
#if 0
static inline __attribute__ (( always_inline )) void *
+44
View File
@@ -0,0 +1,44 @@
/*
* Copyright (C) 2009 Michael Brown <mbrown@fensystems.co.uk>.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stdlib.h>
#include <gpxe/init.h>
#include <gpxe/efi/efi.h>
/**
* EFI entry point
*
* @v image_handle Image handle
* @v systab System table
* @ret efirc EFI return status code
*/
EFI_STATUS EFIAPI _start ( EFI_HANDLE image_handle,
EFI_SYSTEM_TABLE *systab ) {
EFI_STATUS efirc;
/* Initialise EFI environment */
if ( ( efirc = efi_init ( image_handle, systab ) ) != 0 )
return efirc;
/* Initialise gPXE environment */
initialise();
startup();
/* Install SNP driver and return */
return RC_TO_EFIRC ( efi_snp_install () );
}
+39
View File
@@ -0,0 +1,39 @@
/*
* Copyright (C) 2009 Michael Brown <mbrown@fensystems.co.uk>.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stdlib.h>
#include <gpxe/efi/efi.h>
/**
* EFI entry point
*
* @v image_handle Image handle
* @v systab System table
* @ret efirc EFI return status code
*/
EFI_STATUS EFIAPI _start ( EFI_HANDLE image_handle,
EFI_SYSTEM_TABLE *systab ) {
EFI_STATUS efirc;
/* Initialise EFI environment */
if ( ( efirc = efi_init ( image_handle, systab ) ) != 0 )
return efirc;
/* Call to main() */
return RC_TO_EFIRC ( main () );
}
+105
View File
@@ -0,0 +1,105 @@
/* -*- sh -*- */
/*
* Linker script for EFI images
*
*/
ENTRY ( _start )
SECTIONS {
/* The file starts at a virtual address of zero, and sections are
* contiguous. Each section is aligned to at least _max_align,
* which defaults to 32. Load addresses are equal to virtual
* addresses.
*/
_max_align = 32;
/* Allow plenty of space for file headers */
. = 0x1000;
/*
* The text section
*
*/
. = ALIGN ( _max_align );
.text : {
_text = .;
*(.text)
*(.text.*)
_etext = .;
}
/*
* The rodata section
*
*/
. = ALIGN ( _max_align );
.rodata : {
_rodata = .;
*(.rodata)
*(.rodata.*)
_erodata = .;
}
/*
* The data section
*
*/
. = ALIGN ( _max_align );
.data : {
_data = .;
*(.data)
*(.data.*)
*(SORT(.tbl.*)) /* Various tables. See include/tables.h */
_edata = .;
}
/*
* The bss section
*
*/
. = ALIGN ( _max_align );
.bss : {
_bss = .;
*(.bss)
*(.bss.*)
*(COMMON)
_ebss = .;
}
/*
* Weak symbols that need zero values if not otherwise defined
*
*/
.weak 0x0 : {
_weak = .;
*(.weak)
_eweak = .;
}
_assert = ASSERT ( ( _weak == _eweak ), ".weak is non-zero length" );
/*
* Dispose of the comment and note sections to make the link map
* easier to read
*
*/
/DISCARD/ : {
*(.comment)
*(.comment.*)
*(.note)
*(.note.*)
*(.eh_frame)
*(.eh_frame.*)
*(.rel)
*(.rel.*)
}
}
+41
View File
@@ -0,0 +1,41 @@
# Code size reduction.
#
CFLAGS += -fstrength-reduce -fomit-frame-pointer
# Code size reduction. gcc3 needs a different syntax to gcc2 if you
# want to avoid spurious warnings.
#
CFLAGS += -falign-jumps=1 -falign-loops=1 -falign-functions=1
# Use %rip-relative addressing wherever possible.
#
CFLAGS += -fpie
# Force 64-bit code
#
CFLAGS += -m64
ASFLAGS += --64
LDFLAGS += -m elf_x86_64
# EFI requires -fshort-wchar, and nothing else currently uses wchar_t
#
CFLAGS += -fshort-wchar
# We need to undefine the default macro "i386" when compiling .S
# files, otherwise ".arch i386" translates to ".arch 1"...
#
CFLAGS += -Ui386
# x86_64-specific directories containing source files
#
SRCDIRS += arch/x86_64/prefix
# Include common x86 Makefile
#
MAKEDEPS += arch/x86/Makefile
include arch/x86/Makefile
# Include platform-specific Makefile
#
MAKEDEPS += arch/x86_64/Makefile.$(PLATFORM)
include arch/x86_64/Makefile.$(PLATFORM)
+14
View File
@@ -0,0 +1,14 @@
# -*- makefile -*- : Force emacs to use Makefile mode
# EFI probably doesn't guarantee us a red zone, so let's not rely on it.
#
CFLAGS += -mno-red-zone
# Specify EFI image builder
#
ELF2EFI = $(ELF2EFI64)
# Include generic EFI Makefile
#
MAKEDEPS += arch/x86/Makefile.efi
include arch/x86/Makefile.efi
+22
View File
@@ -0,0 +1,22 @@
#ifndef _BITS_BYTESWAP_H
#define _BITS_BYTESWAP_H
static inline __attribute__ (( always_inline, const )) uint16_t
__bswap_variable_16 ( uint16_t x ) {
__asm__ ( "xchgb %b0,%h0" : "=Q" ( x ) : "0" ( x ) );
return x;
}
static inline __attribute__ (( always_inline, const )) uint32_t
__bswap_variable_32 ( uint32_t x ) {
__asm__ ( "bswapl %k0" : "=r" ( x ) : "0" ( x ) );
return x;
}
static inline __attribute__ (( always_inline, const )) uint64_t
__bswap_variable_64 ( uint64_t x ) {
__asm__ ( "bswapq %q0" : "=r" ( x ) : "0" ( x ) );
return x;
}
#endif /* _BITS_BYTESWAP_H */
+14
View File
@@ -0,0 +1,14 @@
#ifndef _BITS_COMPILER_H
#define _BITS_COMPILER_H
#ifndef ASSEMBLY
/** Declare a function with standard calling conventions */
#define __asmcall __attribute__ (( regparm(0) ))
/** Declare a function with libgcc implicit linkage */
#define __libgcc
#endif /* ASSEMBLY */
#endif /* _BITS_COMPILER_H */
+6
View File
@@ -0,0 +1,6 @@
#ifndef ETHERBOOT_BITS_ENDIAN_H
#define ETHERBOOT_BITS_ENDIAN_H
#define __BYTE_ORDER __LITTLE_ENDIAN
#endif /* ETHERBOOT_BITS_ENDIAN_H */
+11
View File
@@ -0,0 +1,11 @@
#ifndef _BITS_ERRFILE_H
#define _BITS_ERRFILE_H
/**
* @addtogroup errfile Error file identifiers
* @{
*/
/** @} */
#endif /* _BITS_ERRFILE_H */
+10
View File
@@ -0,0 +1,10 @@
#ifndef _BITS_IO_H
#define _BITS_IO_H
/** @file
*
* x86_64-specific I/O API implementations
*
*/
#endif /* _BITS_IO_H */
+12
View File
@@ -0,0 +1,12 @@
#ifndef _BITS_NAP_H
#define _BITS_NAP_H
/** @file
*
* x86_64-specific CPU sleeping API implementations
*
*/
#include <gpxe/efi/efix86_nap.h>
#endif /* _BITS_MAP_H */
+10
View File
@@ -0,0 +1,10 @@
#ifndef _BITS_SMBIOS_H
#define _BITS_SMBIOS_H
/** @file
*
* i386-specific SMBIOS API implementations
*
*/
#endif /* _BITS_SMBIOS_H */
+21
View File
@@ -0,0 +1,21 @@
#ifndef _BITS_STDINT_H
#define _BITS_STDINT_H
typedef unsigned long size_t;
typedef signed long ssize_t;
typedef signed long off_t;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long long uint64_t;
typedef signed char int8_t;
typedef signed short int16_t;
typedef signed int int32_t;
typedef signed long long int64_t;
typedef unsigned long physaddr_t;
typedef unsigned long intptr_t;
#endif /* _BITS_STDINT_H */
+10
View File
@@ -0,0 +1,10 @@
#ifndef _BITS_TIMER_H
#define _BITS_TIMER_H
/** @file
*
* x86_64-specific timer API implementations
*
*/
#endif /* _BITS_TIMER_H */
+10
View File
@@ -0,0 +1,10 @@
#ifndef _BITS_UACCESS_H
#define _BITS_UACCESS_H
/** @file
*
* x86_64-specific user access API implementations
*
*/
#endif /* _BITS_UACCESS_H */
+10
View File
@@ -0,0 +1,10 @@
#ifndef _BITS_UMALLOC_H
#define _BITS_UMALLOC_H
/** @file
*
* x86_64-specific user memory allocation API implementations
*
*/
#endif /* _BITS_UMALLOC_H */
+51
View File
@@ -0,0 +1,51 @@
#ifndef GDBMACH_H
#define GDBMACH_H
/** @file
*
* GDB architecture specifics
*
* This file declares functions for manipulating the machine state and
* debugging context.
*
*/
#include <stdint.h>
typedef unsigned long gdbreg_t;
/* The register snapshot, this must be in sync with interrupt handler and the
* GDB protocol. */
enum {
// STUB: don't expect this to work!
GDBMACH_EIP,
GDBMACH_EFLAGS,
GDBMACH_NREGS,
GDBMACH_SIZEOF_REGS = GDBMACH_NREGS * sizeof ( gdbreg_t )
};
/* Breakpoint types */
enum {
GDBMACH_BPMEM,
GDBMACH_BPHW,
GDBMACH_WATCH,
GDBMACH_RWATCH,
GDBMACH_AWATCH,
};
static inline void gdbmach_set_pc ( gdbreg_t *regs, gdbreg_t pc ) {
regs [ GDBMACH_EIP ] = pc;
}
static inline void gdbmach_set_single_step ( gdbreg_t *regs, int step ) {
regs [ GDBMACH_EFLAGS ] &= ~( 1 << 8 ); /* Trace Flag (TF) */
regs [ GDBMACH_EFLAGS ] |= ( step << 8 );
}
static inline void gdbmach_breakpoint ( void ) {
__asm__ __volatile__ ( "int $3\n" );
}
extern int gdbmach_set_breakpoint ( int type, unsigned long addr, size_t len, int enable );
#endif /* GDBMACH_H */
+59
View File
@@ -0,0 +1,59 @@
#ifndef LIMITS_H
#define LIMITS_H 1
/* Number of bits in a `char' */
#define CHAR_BIT 8
/* Minimum and maximum values a `signed char' can hold */
#define SCHAR_MIN (-128)
#define SCHAR_MAX 127
/* Maximum value an `unsigned char' can hold. (Minimum is 0.) */
#define UCHAR_MAX 255
/* Minimum and maximum values a `char' can hold */
#define CHAR_MIN SCHAR_MIN
#define CHAR_MAX SCHAR_MAX
/* Minimum and maximum values a `signed short int' can hold */
#define SHRT_MIN (-32768)
#define SHRT_MAX 32767
/* Maximum value an `unsigned short' can hold. (Minimum is 0.) */
#define USHRT_MAX 65535
/* Minimum and maximum values a `signed int' can hold */
#define INT_MIN (-INT_MAX - 1)
#define INT_MAX 2147483647
/* Maximum value an `unsigned int' can hold. (Minimum is 0.) */
#define UINT_MAX 4294967295U
/* Minimum and maximum values a `signed int' can hold */
#define INT_MAX 2147483647
#define INT_MIN (-INT_MAX - 1)
/* Maximum value an `unsigned int' can hold. (Minimum is 0.) */
#define UINT_MAX 4294967295U
/* Minimum and maximum values a `signed long' can hold */
#define LONG_MAX 9223372036854775807L
#define LONG_MIN (-LONG_MAX - 1L)
/* Maximum value an `unsigned long' can hold. (Minimum is 0.) */
#define ULONG_MAX 18446744073709551615UL
/* Minimum and maximum values a `signed long long' can hold */
#define LLONG_MAX 9223372036854775807LL
#define LLONG_MIN (-LONG_MAX - 1LL)
/* Maximum value an `unsigned long long' can hold. (Minimum is 0.) */
#define ULLONG_MAX 18446744073709551615ULL
#endif /* LIMITS_H */
+1
View File
@@ -14,6 +14,7 @@
#define TIMER_EFI
#define NAP_EFIX86
#define UMALLOC_EFI
#define SMBIOS_EFI
#define IMAGE_EFI /* EFI image support */
+1
View File
@@ -14,6 +14,7 @@
#define CONSOLE_PCBIOS
#define NAP_PCBIOS
#define UMALLOC_MEMTOP
#define SMBIOS_PCBIOS
#define IMAGE_ELF /* ELF image support */
#define IMAGE_MULTIBOOT /* MultiBoot image support */
+1
View File
@@ -100,6 +100,7 @@
#define IMAGE_CMD /* Image management commands */
#define DHCP_CMD /* DHCP management commands */
#define SANBOOT_CMD /* SAN boot commands */
#define LOGIN_CMD /* Login command */
/*
* Obscure configuration options
+66
View File
@@ -0,0 +1,66 @@
/*
* Copyright (C) 2009 Michael Brown <mbrown@fensystems.co.uk>.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stdint.h>
#include <string.h>
#include <assert.h>
#include <gpxe/base64.h>
/** @file
*
* Base64 encoding
*
*/
static const char base64[64] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
/**
* Base64-encode a string
*
* @v raw Raw string
* @v encoded Buffer for encoded string
*
* The buffer must be the correct length for the encoded string. Use
* something like
*
* char buf[ base64_encoded_len ( strlen ( raw ) ) + 1 ];
*
* (the +1 is for the terminating NUL) to provide a buffer of the
* correct size.
*/
void base64_encode ( const char *raw, char *encoded ) {
const uint8_t *raw_bytes = ( ( const uint8_t * ) raw );
uint8_t *encoded_bytes = ( ( uint8_t * ) encoded );
size_t raw_bit_len = ( 8 * strlen ( raw ) );
unsigned int bit;
unsigned int tmp;
for ( bit = 0 ; bit < raw_bit_len ; bit += 6 ) {
tmp = ( ( raw_bytes[ bit / 8 ] << ( bit % 8 ) ) |
( raw_bytes[ bit / 8 + 1 ] >> ( 8 - ( bit % 8 ) ) ) );
tmp = ( ( tmp >> 2 ) & 0x3f );
*(encoded_bytes++) = base64[tmp];
}
for ( ; ( bit % 8 ) != 0 ; bit += 6 )
*(encoded_bytes++) = '=';
*(encoded_bytes++) = '\0';
DBG ( "Base64-encoded \"%s\" as \"%s\"\n", raw, encoded );
assert ( strlen ( encoded ) == base64_encoded_len ( strlen ( raw ) ) );
}
+4
View File
@@ -193,6 +193,9 @@ REQUIRE_OBJECT ( dhcp_cmd );
#ifdef SANBOOT_CMD
REQUIRE_OBJECT ( sanboot_cmd );
#endif
#ifdef LOGIN_CMD
REQUIRE_OBJECT ( login_cmd );
#endif
/*
* Drag in miscellaneous objects
@@ -218,3 +221,4 @@ REQUIRE_OBJECT ( gdbstub_cmd );
*
*/
REQUIRE_OBJECT ( device );
REQUIRE_OBJECT ( embedded );
+4 -1
View File
@@ -36,6 +36,9 @@ struct uri *cwuri = NULL;
* @v uri New working URI, or NULL
*/
void churi ( struct uri *uri ) {
struct uri *new_uri;
new_uri = resolve_uri ( cwuri, uri );
uri_put ( cwuri );
cwuri = uri_get ( uri );
cwuri = new_uri;
}
+8 -6
View File
@@ -16,6 +16,7 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <ctype.h>
#include <console.h>
#include <gpxe/process.h>
#include <gpxe/keys.h>
@@ -59,21 +60,22 @@ static int getchar_timeout ( unsigned long timeout ) {
*/
int getkey ( void ) {
int character;
int key;
unsigned int n = 0;
character = getchar();
if ( character != ESC )
return character;
key = 0;
while ( ( character = getchar_timeout ( GETKEY_TIMEOUT ) ) >= 0 ) {
if ( character == '[' )
continue;
if ( ! key )
key = KEY_ANSI ( character );
if ( isdigit ( character ) ) {
n = ( ( n * 10 ) + ( character - '0' ) );
continue;
}
if ( character >= 0x40 )
break;
return KEY_ANSI ( n, character );
}
return ( key ? key : ESC );
return ESC;
}
+26 -3
View File
@@ -53,6 +53,7 @@ static void free_image ( struct refcnt *refcnt ) {
uri_put ( image->uri );
ufree ( image->data );
image_put ( image->replacement );
free ( image );
DBGC ( image, "IMAGE %p freed\n", image );
}
@@ -142,9 +143,9 @@ int register_image ( struct image *image ) {
* @v image Executable/loadable image
*/
void unregister_image ( struct image *image ) {
DBGC ( image, "IMAGE %p unregistered\n", image );
list_del ( &image->list );
image_put ( image );
DBGC ( image, "IMAGE %p unregistered\n", image );
}
/**
@@ -237,6 +238,7 @@ int image_autoload ( struct image *image ) {
* @ret rc Return status code
*/
int image_exec ( struct image *image ) {
struct image *replacement;
struct uri *old_cwuri;
int rc;
@@ -257,18 +259,39 @@ int image_exec ( struct image *image ) {
old_cwuri = uri_get ( cwuri );
churi ( image->uri );
/* Take out a temporary reference to the image. This allows
* the image to unregister itself if necessary, without
* automatically freeing itself.
*/
image_get ( image );
/* Try executing the image */
if ( ( rc = image->type->exec ( image ) ) != 0 ) {
DBGC ( image, "IMAGE %p could not execute: %s\n",
image, strerror ( rc ) );
goto done;
/* Do not return yet; we still have clean-up to do */
}
done:
/* Pick up replacement image before we drop the original
* image's temporary reference.
*/
replacement = image->replacement;
/* Drop temporary reference to the original image */
image_put ( image );
/* Reset current working directory */
churi ( old_cwuri );
uri_put ( old_cwuri );
/* Tail-recurse into replacement image, if one exists */
if ( replacement ) {
DBGC ( image, "IMAGE %p replacing self with IMAGE %p\n",
image, replacement );
if ( ( rc = image_exec ( replacement ) ) != 0 )
return rc;
}
return rc;
}
+18 -4
View File
@@ -19,6 +19,7 @@ Literature dealing with the network protocols:
#include <gpxe/features.h>
#include <gpxe/shell.h>
#include <gpxe/shell_banner.h>
#include <gpxe/image.h>
#include <usr/autoboot.h>
#include <config/general.h>
@@ -36,6 +37,10 @@ static struct feature features_end[0] __table_end ( struct feature, features );
*/
__asmcall int main ( void ) {
struct feature *feature;
struct image *image;
/* Some devices take an unreasonably long time to initialise */
printf ( PRODUCT_SHORT_NAME " initialising devices...\n" );
initialise();
startup();
@@ -65,11 +70,20 @@ __asmcall int main ( void ) {
/* User wants shell; just give them a shell */
shell();
} else {
/* User doesn't want shell; try booting. If booting
* fails, offer a second chance to enter the shell for
* diagnostics.
/* User doesn't want shell; load and execute the first
* image, or autoboot() if we have no images. If
* booting fails for any reason, offer a second chance
* to enter the shell for diagnostics.
*/
autoboot();
if ( have_images() ) {
for_each_image ( image ) {
image_exec ( image );
break;
}
} else {
autoboot();
}
if ( shell_banner() )
shell();
}
+44 -4
View File
@@ -183,12 +183,17 @@ static void reprioritise_settings ( struct settings *settings ) {
* @ret rc Return status code
*/
int register_settings ( struct settings *settings, struct settings *parent ) {
struct settings *old_settings;
/* NULL parent => add to settings root */
assert ( settings != NULL );
if ( parent == NULL )
parent = &settings_root;
/* Remove any existing settings with the same name */
if ( ( old_settings = find_child_settings ( parent, settings->name ) ))
unregister_settings ( old_settings );
/* Add to list of settings */
ref_get ( settings->refcnt );
ref_get ( parent->refcnt );
@@ -279,7 +284,7 @@ struct settings * find_settings ( const char *name ) {
/**
* Store value of setting
*
* @v settings Settings block
* @v settings Settings block, or NULL
* @v setting Setting to store
* @v data Setting data, or NULL to clear setting
* @v len Length of setting data
@@ -289,9 +294,9 @@ int store_setting ( struct settings *settings, struct setting *setting,
const void *data, size_t len ) {
int rc;
/* Sanity check */
/* NULL settings implies storing into the global settings root */
if ( ! settings )
return -ENODEV;
settings = &settings_root;
/* Store setting */
if ( ( rc = settings->op->store ( settings, setting,
@@ -389,6 +394,38 @@ int fetch_string_setting ( struct settings *settings, struct setting *setting,
( ( len > 0 ) ? ( len - 1 ) : 0 ) );
}
/**
* Fetch value of string setting
*
* @v settings Settings block, or NULL to search all blocks
* @v setting Setting to fetch
* @v data Buffer to allocate and fill with setting string data
* @ret len Length of string setting, or negative error
*
* The resulting string is guaranteed to be correctly NUL-terminated.
* The returned length will be the length of the underlying setting
* data. The caller is responsible for eventually freeing the
* allocated buffer.
*/
int fetch_string_setting_copy ( struct settings *settings,
struct setting *setting,
char **data ) {
int len;
int check_len;
len = fetch_setting_len ( settings, setting );
if ( len < 0 )
return len;
*data = malloc ( len + 1 );
if ( ! *data )
return -ENOMEM;
fetch_string_setting ( settings, setting, *data, ( len + 1 ) );
assert ( check_len == len );
return len;
}
/**
* Fetch value of IPv4 address setting
*
@@ -788,12 +825,15 @@ static int storef_uristring ( struct settings *settings,
static int fetchf_uristring ( struct settings *settings,
struct setting *setting,
char *buf, size_t len ) {
size_t raw_len;
ssize_t raw_len;
/* We need to always retrieve the full raw string to know the
* length of the encoded string.
*/
raw_len = fetch_setting ( settings, setting, NULL, 0 );
if ( raw_len < 0 )
return raw_len;
{
char raw_buf[ raw_len + 1 ];
+9 -2
View File
@@ -27,6 +27,14 @@
*
*/
/**
* Dummy transfer metadata
*
* This gets passed to xfer_interface::deliver_iob() and equivalents
* when no metadata is available.
*/
static struct xfer_metadata dummy_metadata;
/**
* Close data transfer interface
*
@@ -159,7 +167,6 @@ int xfer_deliver_iob_meta ( struct xfer_interface *xfer,
*/
int xfer_deliver_iob ( struct xfer_interface *xfer,
struct io_buffer *iobuf ) {
static struct xfer_metadata dummy_metadata;
return xfer_deliver_iob_meta ( xfer, iobuf, &dummy_metadata );
}
@@ -366,7 +373,7 @@ int xfer_deliver_as_iob ( struct xfer_interface *xfer,
return -ENOMEM;
memcpy ( iob_put ( iobuf, len ), data, len );
return xfer->op->deliver_iob ( xfer, iobuf, NULL );
return xfer->op->deliver_iob ( xfer, iobuf, &dummy_metadata );
}
/**
+18 -13
View File
@@ -32,7 +32,7 @@
*
* @v cursor ASN.1 object cursor
* @v type Expected type
* @ret len Length of object body, or -1 on error
* @ret len Length of object body, or negative error
*
* The object cursor will be updated to point to the start of the
* object body (i.e. the first byte following the length byte(s)), and
@@ -44,29 +44,32 @@
* the cursor will be invalidated and a negative value will be
* returned.
*/
static int asn1_start_object ( struct asn1_cursor *cursor,
static int asn1_start ( struct asn1_cursor *cursor,
unsigned int type ) {
unsigned int len_len;
unsigned int len;
int rc;
/* Sanity check */
if ( cursor->len < 2 /* Tag byte and first length byte */ ) {
if ( cursor->len )
DBGC ( cursor, "ASN1 %p too short\n", cursor );
rc = -EINVAL;
goto notfound;
}
/* Check the tag byte */
if ( cursor->data[0] != type ) {
if ( *( ( uint8_t * ) cursor->data ) != type ) {
DBGC ( cursor, "ASN1 %p type mismatch (expected %d, got %d)\n",
cursor, type, cursor->data[0] );
cursor, type, *( ( uint8_t * ) cursor->data ) );
rc = -ENXIO;
goto notfound;
}
cursor->data++;
cursor->len--;
/* Extract length of the length field and sanity check */
len_len = cursor->data[0];
len_len = *( ( uint8_t * ) cursor->data );
if ( len_len & 0x80 ) {
len_len = ( len_len & 0x7f );
cursor->data++;
@@ -77,19 +80,21 @@ static int asn1_start_object ( struct asn1_cursor *cursor,
if ( cursor->len < len_len ) {
DBGC ( cursor, "ASN1 %p bad length field length %d (max "
"%zd)\n", cursor, len_len, cursor->len );
rc = -EINVAL;
goto notfound;
}
/* Extract the length and sanity check */
for ( len = 0 ; len_len ; len_len-- ) {
len <<= 8;
len |= cursor->data[0];
len |= *( ( uint8_t * ) cursor->data );
cursor->data++;
cursor->len--;
}
if ( cursor->len < len ) {
DBGC ( cursor, "ASN1 %p bad length %d (max %zd)\n",
cursor, len, cursor->len );
rc = -EINVAL;
goto notfound;
}
@@ -98,7 +103,7 @@ static int asn1_start_object ( struct asn1_cursor *cursor,
notfound:
cursor->data = NULL;
cursor->len = 0;
return -1;
return rc;
}
/**
@@ -112,12 +117,12 @@ static int asn1_start_object ( struct asn1_cursor *cursor,
* current ASN.1 object. If any error occurs, the object cursor will
* be invalidated.
*/
int asn1_enter_object ( struct asn1_cursor *cursor, unsigned int type ) {
int asn1_enter ( struct asn1_cursor *cursor, unsigned int type ) {
int len;
len = asn1_start_object ( cursor, type );
len = asn1_start ( cursor, type );
if ( len < 0 )
return -ENOENT;
return len;
cursor->len = len;
DBGC ( cursor, "ASN1 %p entered object type %02x (len %x)\n",
@@ -137,12 +142,12 @@ int asn1_enter_object ( struct asn1_cursor *cursor, unsigned int type ) {
* object. If any error occurs, the object cursor will be
* invalidated.
*/
int asn1_skip_object ( struct asn1_cursor *cursor, unsigned int type ) {
int asn1_skip ( struct asn1_cursor *cursor, unsigned int type ) {
int len;
len = asn1_start_object ( cursor, type );
len = asn1_start ( cursor, type );
if ( len < 0 )
return -ENOENT;
return len;
cursor->data += len;
cursor->len -= len;
+4 -6
View File
@@ -152,10 +152,6 @@ static const unsigned char Rcon[30]=
0xb3,0x7d,0xfa,0xef,0xc5,0x91,
};
/* ----- static functions ----- */
static void AES_encrypt(const AES_CTX *ctx, uint32_t *data);
static void AES_decrypt(const AES_CTX *ctx, uint32_t *data);
/* Perform doubling in Galois Field GF(2^8) using the irreducible polynomial
x^8+x^4+x^3+x+1 */
static unsigned char AES_xtime(uint32_t x)
@@ -257,6 +253,7 @@ void AES_convert_key(AES_CTX *ctx)
}
}
#if 0
/**
* Encrypt a byte sequence (with a block size 16) using the AES cipher.
*/
@@ -358,11 +355,12 @@ void AES_cbc_decrypt(AES_CTX *ctx, const uint8_t *msg, uint8_t *out, int length)
l2n(xor2, iv);
l2n(xor3, iv);
}
#endif
/**
* Encrypt a single block (16 bytes) of data
*/
static void AES_encrypt(const AES_CTX *ctx, uint32_t *data)
void AES_encrypt(const AES_CTX *ctx, uint32_t *data)
{
/* To make this code smaller, generate the sbox entries on the fly.
* This will have a really heavy effect upon performance.
@@ -418,7 +416,7 @@ static void AES_encrypt(const AES_CTX *ctx, uint32_t *data)
/**
* Decrypt a single block (16 bytes) of data
*/
static void AES_decrypt(const AES_CTX *ctx, uint32_t *data)
void AES_decrypt(const AES_CTX *ctx, uint32_t *data)
{
uint32_t tmp[4];
uint32_t xt0,xt1,xt2,xt3,xt4,xt5,xt6;
-867
View File
@@ -1,867 +0,0 @@
/*
* Copyright(C) 2006 Cameron Rich
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
* @file asn1.c
*
* Some primitive asn methods for extraction rsa modulus information. It also
* is used for retrieving information from X.509 certificates.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "crypto.h"
#define SIG_OID_PREFIX_SIZE 8
#define SIG_TYPE_MD2 0x02
#define SIG_TYPE_MD5 0x04
#define SIG_TYPE_SHA1 0x05
/* Must be an RSA algorithm with either SHA1 or MD5 for verifying to work */
static const uint8_t sig_oid_prefix[SIG_OID_PREFIX_SIZE] =
{
0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01
};
/* CN, O, OU */
static const uint8_t g_dn_types[] = { 3, 10, 11 };
static int get_asn1_length(const uint8_t *buf, int *offset)
{
int len, i;
if (!(buf[*offset] & 0x80)) /* short form */
{
len = buf[(*offset)++];
}
else /* long form */
{
int length_bytes = buf[(*offset)++]&0x7f;
len = 0;
for (i = 0; i < length_bytes; i++)
{
len <<= 8;
len += buf[(*offset)++];
}
}
return len;
}
/**
* Skip the ASN1.1 object type and its length. Get ready to read the object's
* data.
*/
int asn1_next_obj(const uint8_t *buf, int *offset, int obj_type)
{
if (buf[*offset] != obj_type)
return X509_NOT_OK;
(*offset)++;
return get_asn1_length(buf, offset);
}
/**
* Skip over an ASN.1 object type completely. Get ready to read the next
* object.
*/
int asn1_skip_obj(const uint8_t *buf, int *offset, int obj_type)
{
int len;
if (buf[*offset] != obj_type)
return X509_NOT_OK;
(*offset)++;
len = get_asn1_length(buf, offset);
*offset += len;
return 0;
}
/**
* Read an integer value for ASN.1 data
* Note: This function allocates memory which must be freed by the user.
*/
int asn1_get_int(const uint8_t *buf, int *offset, uint8_t **object)
{
int len;
if ((len = asn1_next_obj(buf, offset, ASN1_INTEGER)) < 0)
goto end_int_array;
*object = (uint8_t *)malloc(len);
memcpy(*object, &buf[*offset], len);
*offset += len;
end_int_array:
return len;
}
#if 0
/**
* Get all the RSA private key specifics from an ASN.1 encoded file
*/
int asn1_get_private_key(const uint8_t *buf, int len, RSA_CTX **rsa_ctx)
{
int offset = 7;
uint8_t *modulus, *priv_exp, *pub_exp;
int mod_len, priv_len, pub_len;
#ifdef CONFIG_BIGINT_CRT
uint8_t *p, *q, *dP, *dQ, *qInv;
int p_len, q_len, dP_len, dQ_len, qInv_len;
#endif
/* not in der format */
if (buf[0] != ASN1_SEQUENCE) /* basic sanity check */
{
#ifdef CONFIG_SSL_FULL_MODE
printf("Error: This is not a valid ASN.1 file\n");
#endif
return X509_INVALID_PRIV_KEY;
}
/* initialise the RNG */
RNG_initialize(buf, len);
mod_len = asn1_get_int(buf, &offset, &modulus);
pub_len = asn1_get_int(buf, &offset, &pub_exp);
priv_len = asn1_get_int(buf, &offset, &priv_exp);
if (mod_len <= 0 || pub_len <= 0 || priv_len <= 0)
return X509_INVALID_PRIV_KEY;
#ifdef CONFIG_BIGINT_CRT
p_len = asn1_get_int(buf, &offset, &p);
q_len = asn1_get_int(buf, &offset, &q);
dP_len = asn1_get_int(buf, &offset, &dP);
dQ_len = asn1_get_int(buf, &offset, &dQ);
qInv_len = asn1_get_int(buf, &offset, &qInv);
if (p_len <= 0 || q_len <= 0 || dP_len <= 0 || dQ_len <= 0 || qInv_len <= 0)
return X509_INVALID_PRIV_KEY;
RSA_priv_key_new(rsa_ctx,
modulus, mod_len, pub_exp, pub_len, priv_exp, priv_len,
p, p_len, q, p_len, dP, dP_len, dQ, dQ_len, qInv, qInv_len);
free(p);
free(q);
free(dP);
free(dQ);
free(qInv);
#else
RSA_priv_key_new(rsa_ctx,
modulus, mod_len, pub_exp, pub_len, priv_exp, priv_len);
#endif
free(modulus);
free(priv_exp);
free(pub_exp);
return X509_OK;
}
/**
* Get the time of a certificate. Ignore hours/minutes/seconds.
*/
static int asn1_get_utc_time(const uint8_t *buf, int *offset, time_t *t)
{
int ret = X509_NOT_OK, len, t_offset;
struct tm tm;
if (buf[(*offset)++] != ASN1_UTC_TIME)
goto end_utc_time;
len = get_asn1_length(buf, offset);
t_offset = *offset;
memset(&tm, 0, sizeof(struct tm));
tm.tm_year = (buf[t_offset] - '0')*10 + (buf[t_offset+1] - '0');
if (tm.tm_year <= 50) /* 1951-2050 thing */
{
tm.tm_year += 100;
}
tm.tm_mon = (buf[t_offset+2] - '0')*10 + (buf[t_offset+3] - '0') - 1;
tm.tm_mday = (buf[t_offset+4] - '0')*10 + (buf[t_offset+5] - '0');
*t = mktime(&tm);
*offset += len;
ret = X509_OK;
end_utc_time:
return ret;
}
/**
* Get the version type of a certificate (which we don't actually care about)
*/
static int asn1_version(const uint8_t *cert, int *offset, X509_CTX *x509_ctx)
{
int ret = X509_NOT_OK;
(*offset) += 2; /* get past explicit tag */
if (asn1_skip_obj(cert, offset, ASN1_INTEGER))
goto end_version;
ret = X509_OK;
end_version:
return ret;
}
/**
* Retrieve the notbefore and notafter certificate times.
*/
static int asn1_validity(const uint8_t *cert, int *offset, X509_CTX *x509_ctx)
{
return (asn1_next_obj(cert, offset, ASN1_SEQUENCE) < 0 ||
asn1_get_utc_time(cert, offset, &x509_ctx->not_before) ||
asn1_get_utc_time(cert, offset, &x509_ctx->not_after));
}
/**
* Get the components of a distinguished name
*/
static int asn1_get_oid_x520(const uint8_t *buf, int *offset)
{
int dn_type = 0;
int len;
if ((len = asn1_next_obj(buf, offset, ASN1_OID)) < 0)
goto end_oid;
/* expect a sequence of 2.5.4.[x] where x is a one of distinguished name
components we are interested in. */
if (len == 3 && buf[(*offset)++] == 0x55 && buf[(*offset)++] == 0x04)
dn_type = buf[(*offset)++];
else
{
*offset += len; /* skip over it */
}
end_oid:
return dn_type;
}
/**
* Obtain an ASN.1 printable string type.
*/
static int asn1_get_printable_str(const uint8_t *buf, int *offset, char **str)
{
int len = X509_NOT_OK;
/* some certs have this awful crud in them for some reason */
if (buf[*offset] != ASN1_PRINTABLE_STR &&
buf[*offset] != ASN1_TELETEX_STR && buf[*offset] != ASN1_IA5_STR)
goto end_pnt_str;
(*offset)++;
len = get_asn1_length(buf, offset);
*str = (char *)malloc(len+1); /* allow for null */
memcpy(*str, &buf[*offset], len);
(*str)[len] = 0; /* null terminate */
*offset += len;
end_pnt_str:
return len;
}
/**
* Get the subject name (or the issuer) of a certificate.
*/
static int asn1_name(const uint8_t *cert, int *offset, char *dn[])
{
int ret = X509_NOT_OK;
int dn_type;
char *tmp = NULL;
if (asn1_next_obj(cert, offset, ASN1_SEQUENCE) < 0)
goto end_name;
while (asn1_next_obj(cert, offset, ASN1_SET) >= 0)
{
int i, found = 0;
if (asn1_next_obj(cert, offset, ASN1_SEQUENCE) < 0 ||
(dn_type = asn1_get_oid_x520(cert, offset)) < 0)
goto end_name;
if (asn1_get_printable_str(cert, offset, &tmp) < 0)
{
free(tmp);
goto end_name;
}
/* find the distinguished named type */
for (i = 0; i < X509_NUM_DN_TYPES; i++)
{
if (dn_type == g_dn_types[i])
{
if (dn[i] == NULL)
{
dn[i] = tmp;
found = 1;
break;
}
}
}
if (found == 0) /* not found so get rid of it */
{
free(tmp);
}
}
ret = X509_OK;
end_name:
return ret;
}
/**
* Read the modulus and public exponent of a certificate.
*/
static int asn1_public_key(const uint8_t *cert, int *offset, X509_CTX *x509_ctx)
{
int ret = X509_NOT_OK, mod_len, pub_len;
uint8_t *modulus, *pub_exp;
if (asn1_next_obj(cert, offset, ASN1_SEQUENCE) < 0 ||
asn1_skip_obj(cert, offset, ASN1_SEQUENCE) ||
asn1_next_obj(cert, offset, ASN1_BIT_STRING) < 0)
goto end_pub_key;
(*offset)++;
if (asn1_next_obj(cert, offset, ASN1_SEQUENCE) < 0)
goto end_pub_key;
mod_len = asn1_get_int(cert, offset, &modulus);
pub_len = asn1_get_int(cert, offset, &pub_exp);
RSA_pub_key_new(&x509_ctx->rsa_ctx, modulus, mod_len, pub_exp, pub_len);
free(modulus);
free(pub_exp);
ret = X509_OK;
end_pub_key:
return ret;
}
#ifdef CONFIG_SSL_CERT_VERIFICATION
/**
* Read the signature of the certificate.
*/
static int asn1_signature(const uint8_t *cert, int *offset, X509_CTX *x509_ctx)
{
int ret = X509_NOT_OK;
if (cert[(*offset)++] != ASN1_BIT_STRING)
goto end_sig;
x509_ctx->sig_len = get_asn1_length(cert, offset);
x509_ctx->signature = (uint8_t *)malloc(x509_ctx->sig_len);
memcpy(x509_ctx->signature, &cert[*offset], x509_ctx->sig_len);
*offset += x509_ctx->sig_len;
ret = X509_OK;
end_sig:
return ret;
}
/*
* Compare 2 distinguished name components for equality
* @return 0 if a match
*/
static int asn1_compare_dn_comp(const char *dn1, const char *dn2)
{
int ret = 1;
if ((dn1 && dn2 == NULL) || (dn1 == NULL && dn2)) goto err_no_match;
ret = (dn1 && dn2) ? strcmp(dn1, dn2) : 0;
err_no_match:
return ret;
}
/**
* Clean up all of the CA certificates.
*/
void remove_ca_certs(CA_CERT_CTX *ca_cert_ctx)
{
int i = 0;
while (i < CONFIG_X509_MAX_CA_CERTS && ca_cert_ctx->cert[i])
{
x509_free(ca_cert_ctx->cert[i]);
ca_cert_ctx->cert[i++] = NULL;
}
free(ca_cert_ctx);
}
/*
* Compare 2 distinguished names for equality
* @return 0 if a match
*/
static int asn1_compare_dn(char * const dn1[], char * const dn2[])
{
int i;
for (i = 0; i < X509_NUM_DN_TYPES; i++)
{
if (asn1_compare_dn_comp(dn1[i], dn2[i]))
{
return 1;
}
}
return 0; /* all good */
}
/**
* Retrieve the signature from a certificate.
*/
const uint8_t *x509_get_signature(const uint8_t *asn1_sig, int *len)
{
int offset = 0;
const uint8_t *ptr = NULL;
if (asn1_next_obj(asn1_sig, &offset, ASN1_SEQUENCE) < 0 ||
asn1_skip_obj(asn1_sig, &offset, ASN1_SEQUENCE))
goto end_get_sig;
if (asn1_sig[offset++] != ASN1_OCTET_STRING)
goto end_get_sig;
*len = get_asn1_length(asn1_sig, &offset);
ptr = &asn1_sig[offset]; /* all ok */
end_get_sig:
return ptr;
}
#endif
/**
* Read the signature type of the certificate. We only support RSA-MD5 and
* RSA-SHA1 signature types.
*/
static int asn1_signature_type(const uint8_t *cert,
int *offset, X509_CTX *x509_ctx)
{
int ret = X509_NOT_OK, len;
if (cert[(*offset)++] != ASN1_OID)
goto end_check_sig;
len = get_asn1_length(cert, offset);
if (memcmp(sig_oid_prefix, &cert[*offset], SIG_OID_PREFIX_SIZE))
goto end_check_sig; /* unrecognised cert type */
x509_ctx->sig_type = cert[*offset + SIG_OID_PREFIX_SIZE];
*offset += len;
if (asn1_skip_obj(cert, offset, ASN1_NULL))
goto end_check_sig;
ret = X509_OK;
end_check_sig:
return ret;
}
/**
* Construct a new x509 object.
* @return 0 if ok. < 0 if there was a problem.
*/
int x509_new(const uint8_t *cert, int *len, X509_CTX **ctx)
{
int begin_tbs, end_tbs;
int ret = X509_NOT_OK, offset = 0, cert_size = 0;
X509_CTX *x509_ctx;
BI_CTX *bi_ctx;
*ctx = (X509_CTX *)calloc(1, sizeof(X509_CTX));
x509_ctx = *ctx;
/* get the certificate size */
asn1_skip_obj(cert, &cert_size, ASN1_SEQUENCE);
if (asn1_next_obj(cert, &offset, ASN1_SEQUENCE) < 0)
goto end_cert;
begin_tbs = offset; /* start of the tbs */
end_tbs = begin_tbs; /* work out the end of the tbs */
asn1_skip_obj(cert, &end_tbs, ASN1_SEQUENCE);
if (asn1_next_obj(cert, &offset, ASN1_SEQUENCE) < 0)
goto end_cert;
if (cert[offset] == ASN1_EXPLICIT_TAG) /* optional version */
{
if (asn1_version(cert, &offset, x509_ctx))
goto end_cert;
}
if (asn1_skip_obj(cert, &offset, ASN1_INTEGER) || /* serial number */
asn1_next_obj(cert, &offset, ASN1_SEQUENCE) < 0)
goto end_cert;
/* make sure the signature is ok */
if (asn1_signature_type(cert, &offset, x509_ctx))
{
ret = X509_VFY_ERROR_UNSUPPORTED_DIGEST;
goto end_cert;
}
if (asn1_name(cert, &offset, x509_ctx->ca_cert_dn) ||
asn1_validity(cert, &offset, x509_ctx) ||
asn1_name(cert, &offset, x509_ctx->cert_dn) ||
asn1_public_key(cert, &offset, x509_ctx))
goto end_cert;
bi_ctx = x509_ctx->rsa_ctx->bi_ctx;
#ifdef CONFIG_SSL_CERT_VERIFICATION /* only care if doing verification */
/* use the appropriate signature algorithm (either SHA1 or MD5) */
if (x509_ctx->sig_type == SIG_TYPE_MD5)
{
MD5_CTX md5_ctx;
uint8_t md5_dgst[MD5_SIZE];
MD5Init(&md5_ctx);
MD5Update(&md5_ctx, &cert[begin_tbs], end_tbs-begin_tbs);
MD5Final(&md5_ctx, md5_dgst);
x509_ctx->digest = bi_import(bi_ctx, md5_dgst, MD5_SIZE);
}
else if (x509_ctx->sig_type == SIG_TYPE_SHA1)
{
SHA1_CTX sha_ctx;
uint8_t sha_dgst[SHA1_SIZE];
SHA1Init(&sha_ctx);
SHA1Update(&sha_ctx, &cert[begin_tbs], end_tbs-begin_tbs);
SHA1Final(&sha_ctx, sha_dgst);
x509_ctx->digest = bi_import(bi_ctx, sha_dgst, SHA1_SIZE);
}
offset = end_tbs; /* skip the v3 data */
if (asn1_skip_obj(cert, &offset, ASN1_SEQUENCE) ||
asn1_signature(cert, &offset, x509_ctx))
goto end_cert;
#endif
if (len)
{
*len = cert_size;
}
ret = X509_OK;
end_cert:
#ifdef CONFIG_SSL_FULL_MODE
if (ret)
{
printf("Error: Invalid X509 ASN.1 file\n");
}
#endif
return ret;
}
/**
* Free an X.509 object's resources.
*/
void x509_free(X509_CTX *x509_ctx)
{
X509_CTX *next;
int i;
if (x509_ctx == NULL) /* if already null, then don't bother */
return;
for (i = 0; i < X509_NUM_DN_TYPES; i++)
{
free(x509_ctx->ca_cert_dn[i]);
free(x509_ctx->cert_dn[i]);
}
free(x509_ctx->signature);
#ifdef CONFIG_SSL_CERT_VERIFICATION
if (x509_ctx->digest)
{
bi_free(x509_ctx->rsa_ctx->bi_ctx, x509_ctx->digest);
}
#endif
RSA_free(x509_ctx->rsa_ctx);
next = x509_ctx->next;
free(x509_ctx);
x509_free(next); /* clear the chain */
}
#ifdef CONFIG_SSL_CERT_VERIFICATION
/**
* Do some basic checks on the certificate chain.
*
* Certificate verification consists of a number of checks:
* - A root certificate exists in the certificate store.
* - The date of the certificate is after the start date.
* - The date of the certificate is before the finish date.
* - The certificate chain is valid.
* - That the certificate(s) are not self-signed.
* - The signature of the certificate is valid.
*/
int x509_verify(const CA_CERT_CTX *ca_cert_ctx, const X509_CTX *cert)
{
int ret = X509_OK, i = 0;
bigint *cert_sig;
X509_CTX *next_cert = NULL;
BI_CTX *ctx;
bigint *mod, *expn;
struct timeval tv;
int match_ca_cert = 0;
if (cert == NULL || ca_cert_ctx == NULL)
{
ret = X509_VFY_ERROR_NO_TRUSTED_CERT;
goto end_verify;
}
/* last cert in the chain - look for a trusted cert */
if (cert->next == NULL)
{
while (i < CONFIG_X509_MAX_CA_CERTS && ca_cert_ctx->cert[i])
{
if (asn1_compare_dn(cert->ca_cert_dn,
ca_cert_ctx->cert[i]->cert_dn) == 0)
{
match_ca_cert = 1;
break;
}
i++;
}
if (i < CONFIG_X509_MAX_CA_CERTS && ca_cert_ctx->cert[i])
{
next_cert = ca_cert_ctx->cert[i];
}
else /* trusted cert not found */
{
ret = X509_VFY_ERROR_NO_TRUSTED_CERT;
goto end_verify;
}
}
else
{
next_cert = cert->next;
}
gettimeofday(&tv, NULL);
/* check the not before date */
if (tv.tv_sec < cert->not_before)
{
ret = X509_VFY_ERROR_NOT_YET_VALID;
goto end_verify;
}
/* check the not after date */
if (tv.tv_sec > cert->not_after)
{
ret = X509_VFY_ERROR_EXPIRED;
goto end_verify;
}
/* check the chain integrity */
if (asn1_compare_dn(cert->ca_cert_dn, next_cert->cert_dn))
{
ret = X509_VFY_ERROR_INVALID_CHAIN;
goto end_verify;
}
/* check for self-signing */
if (!match_ca_cert && asn1_compare_dn(cert->ca_cert_dn, cert->cert_dn) == 0)
{
ret = X509_VFY_ERROR_SELF_SIGNED;
goto end_verify;
}
/* check the signature */
ctx = cert->rsa_ctx->bi_ctx;
mod = next_cert->rsa_ctx->m;
expn = next_cert->rsa_ctx->e;
cert_sig = RSA_sign_verify(ctx, cert->signature, cert->sig_len,
bi_clone(ctx, mod), bi_clone(ctx, expn));
if (cert_sig)
{
ret = cert->digest ? /* check the signature */
bi_compare(cert_sig, cert->digest) :
X509_VFY_ERROR_UNSUPPORTED_DIGEST;
bi_free(ctx, cert_sig);
if (ret)
goto end_verify;
}
else
{
ret = X509_VFY_ERROR_BAD_SIGNATURE;
goto end_verify;
}
/* go down the certificate chain using recursion. */
if (ret == 0 && cert->next)
{
ret = x509_verify(ca_cert_ctx, next_cert);
}
end_verify:
return ret;
}
#endif
#if defined (CONFIG_SSL_FULL_MODE)
/**
* Used for diagnostics.
*/
void x509_print(CA_CERT_CTX *ca_cert_ctx, const X509_CTX *cert)
{
if (cert == NULL)
return;
printf("---------------- CERT DEBUG ----------------\n");
printf("* CA Cert Distinguished Name\n");
if (cert->ca_cert_dn[X509_COMMON_NAME])
{
printf("Common Name (CN):\t%s\n", cert->ca_cert_dn[X509_COMMON_NAME]);
}
if (cert->ca_cert_dn[X509_ORGANIZATION])
{
printf("Organization (O):\t%s\n", cert->ca_cert_dn[X509_ORGANIZATION]);
}
if (cert->ca_cert_dn[X509_ORGANIZATIONAL_TYPE])
{
printf("Organizational Unit (OU): %s\n",
cert->ca_cert_dn[X509_ORGANIZATIONAL_TYPE]);
}
printf("* Cert Distinguished Name\n");
if (cert->cert_dn[X509_COMMON_NAME])
{
printf("Common Name (CN):\t%s\n", cert->cert_dn[X509_COMMON_NAME]);
}
if (cert->cert_dn[X509_ORGANIZATION])
{
printf("Organization (O):\t%s\n", cert->cert_dn[X509_ORGANIZATION]);
}
if (cert->cert_dn[X509_ORGANIZATIONAL_TYPE])
{
printf("Organizational Unit (OU): %s\n",
cert->cert_dn[X509_ORGANIZATIONAL_TYPE]);
}
printf("Not Before:\t\t%s", ctime(&cert->not_before));
printf("Not After:\t\t%s", ctime(&cert->not_after));
printf("RSA bitsize:\t\t%d\n", cert->rsa_ctx->num_octets*8);
printf("Sig Type:\t\t");
switch (cert->sig_type)
{
case SIG_TYPE_MD5:
printf("MD5\n");
break;
case SIG_TYPE_SHA1:
printf("SHA1\n");
break;
case SIG_TYPE_MD2:
printf("MD2\n");
break;
default:
printf("Unrecognized: %d\n", cert->sig_type);
break;
}
printf("Verify:\t\t\t");
if (ca_cert_ctx)
{
x509_display_error(x509_verify(ca_cert_ctx, cert));
}
printf("\n");
#if 0
print_blob("Signature", cert->signature, cert->sig_len);
bi_print("Modulus", cert->rsa_ctx->m);
bi_print("Pub Exp", cert->rsa_ctx->e);
#endif
if (ca_cert_ctx)
{
x509_print(ca_cert_ctx, cert->next);
}
}
void x509_display_error(int error)
{
switch (error)
{
case X509_NOT_OK:
printf("X509 not ok");
break;
case X509_VFY_ERROR_NO_TRUSTED_CERT:
printf("No trusted cert is available");
break;
case X509_VFY_ERROR_BAD_SIGNATURE:
printf("Bad signature");
break;
case X509_VFY_ERROR_NOT_YET_VALID:
printf("Cert is not yet valid");
break;
case X509_VFY_ERROR_EXPIRED:
printf("Cert has expired");
break;
case X509_VFY_ERROR_SELF_SIGNED:
printf("Cert is self-signed");
break;
case X509_VFY_ERROR_INVALID_CHAIN:
printf("Chain is invalid (check order of certs)");
break;
case X509_VFY_ERROR_UNSUPPORTED_DIGEST:
printf("Unsupported digest");
break;
case X509_INVALID_PRIV_KEY:
printf("Invalid private key");
break;
}
}
#endif /* CONFIG_SSL_FULL_MODE */
#endif
+2
View File
@@ -55,6 +55,8 @@ void AES_cbc_encrypt(AES_CTX *ctx, const uint8_t *msg,
uint8_t *out, int length);
void AES_cbc_decrypt(AES_CTX *ks, const uint8_t *in, uint8_t *out, int length);
void AES_convert_key(AES_CTX *ctx);
void AES_encrypt(const AES_CTX *ctx, uint32_t *data);
void AES_decrypt(const AES_CTX *ctx, uint32_t *data);
/**************************************************************************
* RC4 declarations
+134 -21
View File
@@ -1,12 +1,58 @@
#include "crypto/axtls/crypto.h"
/*
* Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <string.h>
#include <errno.h>
#include <byteswap.h>
#include <gpxe/crypto.h>
#include <gpxe/cbc.h>
#include <gpxe/aes.h>
#include "crypto/axtls/crypto.h"
/** @file
*
* AES algorithm
*
*/
/** Basic AES blocksize */
#define AES_BLOCKSIZE 16
/** AES context */
struct aes_context {
/** AES context for AXTLS */
AES_CTX axtls_ctx;
/** Cipher is being used for decrypting */
int decrypting;
};
/**
* Set key
*
* @v ctx Context
* @v key Key
* @v keylen Key length
* @ret rc Return status code
*/
static int aes_setkey ( void *ctx, const void *key, size_t keylen ) {
AES_CTX *aesctx = ctx;
struct aes_context *aes_ctx = ctx;
AES_MODE mode;
void *iv;
switch ( keylen ) {
case ( 128 / 8 ):
@@ -19,36 +65,103 @@ static int aes_setkey ( void *ctx, const void *key, size_t keylen ) {
return -EINVAL;
}
AES_set_key ( aesctx, key, aesctx->iv, mode );
/* IV is not a relevant concept at this stage; use a dummy
* value that will have no side-effects.
*/
iv = &aes_ctx->axtls_ctx.iv;
AES_set_key ( &aes_ctx->axtls_ctx, key, iv, mode );
aes_ctx->decrypting = 0;
return 0;
}
static void aes_setiv ( void *ctx, const void *iv ) {
AES_CTX *aesctx = ctx;
memcpy ( aesctx->iv, iv, sizeof ( aesctx->iv ) );
/**
* Set initialisation vector
*
* @v ctx Context
* @v iv Initialisation vector
*/
static void aes_setiv ( void *ctx __unused, const void *iv __unused ) {
/* Nothing to do */
}
static void aes_encrypt ( void *ctx, const void *data, void *dst,
/**
* Call AXTLS' AES_encrypt() or AES_decrypt() functions
*
* @v axtls_ctx AXTLS AES context
* @v src Data to process
* @v dst Buffer for output
* @v func AXTLS AES function to call
*/
static void aes_call_axtls ( AES_CTX *axtls_ctx, const void *src, void *dst,
void ( * func ) ( const AES_CTX *axtls_ctx,
uint32_t *data ) ){
const uint32_t *srcl = src;
uint32_t *dstl = dst;
unsigned int i;
/* AXTLS' AES_encrypt() and AES_decrypt() functions both
* expect to deal with an array of four dwords in host-endian
* order.
*/
for ( i = 0 ; i < 4 ; i++ )
dstl[i] = ntohl ( srcl[i] );
func ( axtls_ctx, dstl );
for ( i = 0 ; i < 4 ; i++ )
dstl[i] = htonl ( dstl[i] );
}
/**
* Encrypt data
*
* @v ctx Context
* @v src Data to encrypt
* @v dst Buffer for encrypted data
* @v len Length of data
*/
static void aes_encrypt ( void *ctx, const void *src, void *dst,
size_t len ) {
AES_CTX *aesctx = ctx;
struct aes_context *aes_ctx = ctx;
AES_cbc_encrypt ( aesctx, data, dst, len );
assert ( len == AES_BLOCKSIZE );
if ( aes_ctx->decrypting )
assert ( 0 );
aes_call_axtls ( &aes_ctx->axtls_ctx, src, dst, AES_encrypt );
}
static void aes_decrypt ( void *ctx, const void *data, void *dst,
/**
* Decrypt data
*
* @v ctx Context
* @v src Data to decrypt
* @v dst Buffer for decrypted data
* @v len Length of data
*/
static void aes_decrypt ( void *ctx, const void *src, void *dst,
size_t len ) {
AES_CTX *aesctx = ctx;
struct aes_context *aes_ctx = ctx;
AES_cbc_decrypt ( aesctx, data, dst, len );
assert ( len == AES_BLOCKSIZE );
if ( ! aes_ctx->decrypting ) {
AES_convert_key ( &aes_ctx->axtls_ctx );
aes_ctx->decrypting = 1;
}
aes_call_axtls ( &aes_ctx->axtls_ctx, src, dst, AES_decrypt );
}
struct crypto_algorithm aes_algorithm = {
.name = "aes",
.ctxsize = sizeof ( AES_CTX ),
.blocksize = 16,
.setkey = aes_setkey,
.setiv = aes_setiv,
.encode = aes_encrypt,
.decode = aes_decrypt,
/** Basic AES algorithm */
static struct cipher_algorithm aes_algorithm = {
.name = "aes",
.ctxsize = sizeof ( struct aes_context ),
.blocksize = AES_BLOCKSIZE,
.setkey = aes_setkey,
.setiv = aes_setiv,
.encrypt = aes_encrypt,
.decrypt = aes_decrypt,
};
/* AES with cipher-block chaining */
CBC_CIPHER ( aes_cbc, aes_cbc_algorithm,
aes_algorithm, struct aes_context, AES_BLOCKSIZE );
+3 -4
View File
@@ -6,8 +6,7 @@ static void sha1_init ( void *ctx ) {
SHA1Init ( ctx );
}
static void sha1_update ( void *ctx, const void *data, void *dst __unused,
size_t len ) {
static void sha1_update ( void *ctx, const void *data, size_t len ) {
SHA1Update ( ctx, data, len );
}
@@ -15,12 +14,12 @@ static void sha1_final ( void *ctx, void *out ) {
SHA1Final ( ctx, out );
}
struct crypto_algorithm sha1_algorithm = {
struct digest_algorithm sha1_algorithm = {
.name = "sha1",
.ctxsize = SHA1_CTX_SIZE,
.blocksize = 64,
.digestsize = SHA1_DIGEST_SIZE,
.init = sha1_init,
.encode = sha1_update,
.update = sha1_update,
.final = sha1_final,
};
+99
View File
@@ -0,0 +1,99 @@
/*
* Copyright (C) 2009 Michael Brown <mbrown@fensystems.co.uk>.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <string.h>
#include <assert.h>
#include <gpxe/crypto.h>
#include <gpxe/cbc.h>
/** @file
*
* Cipher-block chaining
*
*/
/**
* XOR data blocks
*
* @v src Input data
* @v dst Second input data and output data buffer
* @v len Length of data
*/
static void cbc_xor ( const void *src, void *dst, size_t len ) {
const uint32_t *srcl = src;
uint32_t *dstl = dst;
unsigned int i;
/* Assume that block sizes will always be dword-aligned, for speed */
assert ( ( len % sizeof ( *srcl ) ) == 0 );
for ( i = 0 ; i < ( len / sizeof ( *srcl ) ) ; i++ )
dstl[i] ^= srcl[i];
}
/**
* Encrypt data
*
* @v ctx Context
* @v src Data to encrypt
* @v dst Buffer for encrypted data
* @v len Length of data
* @v raw_cipher Underlying cipher algorithm
* @v cbc_ctx CBC context
*/
void cbc_encrypt ( void *ctx, const void *src, void *dst, size_t len,
struct cipher_algorithm *raw_cipher, void *cbc_ctx ) {
size_t blocksize = raw_cipher->blocksize;
assert ( ( len % blocksize ) == 0 );
while ( len ) {
cbc_xor ( src, cbc_ctx, blocksize );
cipher_encrypt ( raw_cipher, ctx, cbc_ctx, dst, blocksize );
memcpy ( cbc_ctx, dst, blocksize );
dst += blocksize;
src += blocksize;
len -= blocksize;
}
}
/**
* Decrypt data
*
* @v ctx Context
* @v src Data to decrypt
* @v dst Buffer for decrypted data
* @v len Length of data
* @v raw_cipher Underlying cipher algorithm
* @v cbc_ctx CBC context
*/
void cbc_decrypt ( void *ctx, const void *src, void *dst, size_t len,
struct cipher_algorithm *raw_cipher, void *cbc_ctx ) {
size_t blocksize = raw_cipher->blocksize;
assert ( ( len % blocksize ) == 0 );
while ( len ) {
cipher_decrypt ( raw_cipher, ctx, src, dst, blocksize );
cbc_xor ( cbc_ctx, dst, blocksize );
memcpy ( cbc_ctx, src, blocksize );
dst += blocksize;
src += blocksize;
len -= blocksize;
}
}
+1 -1
View File
@@ -42,7 +42,7 @@
* eventually be freed by a call to chap_finish().
*/
int chap_init ( struct chap_response *chap,
struct crypto_algorithm *digest ) {
struct digest_algorithm *digest ) {
size_t state_len;
void *state;
-24
View File
@@ -1,24 +0,0 @@
#include <stdint.h>
#include <errno.h>
#include <gpxe/crypto.h>
int cipher_encrypt ( struct crypto_algorithm *crypto,
void *ctx, const void *src, void *dst,
size_t len ) {
if ( ( len & ( crypto->blocksize - 1 ) ) ) {
return -EINVAL;
}
crypto->encode ( ctx, src, dst, len );
return 0;
}
int cipher_decrypt ( struct crypto_algorithm *crypto,
void *ctx, const void *src, void *dst,
size_t len ) {
if ( ( len & ( crypto->blocksize - 1 ) ) ) {
return -EINVAL;
}
crypto->decode ( ctx, src, dst, len );
return 0;
}
-120
View File
@@ -1,120 +0,0 @@
#ifndef _MATRIXSSL_CRYPTOLAYER_H
#define _MATRIXSSL_CRYPTOLAYER_H
/** @file
*
* Compatibility layer for MatrixSSL
*
*/
#include <stdint.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <assert.h>
#include <byteswap.h>
#include <gpxe/rotate.h>
#include <gpxe/crypto.h>
/* Drag in pscrypto.h */
typedef uint64_t ulong64;
typedef void psPool_t;
#define SMALL_CODE
#define USE_INT64
#define USE_RSA
#define USE_RSA_PUBLIC_ENCRYPT
#define CRYPT
#include "matrixssl/pscrypto.h"
#define SMALL_CODE
#undef CLEAN_STACK
#define sslAssert( ... ) assert ( __VA_ARGS__ )
static inline __attribute__ (( always_inline )) void * __malloc
psMalloc ( psPool_t *pool __unused, size_t len ) {
return malloc ( len );
}
static inline __attribute__ (( always_inline )) void *
psRealloc ( void *ptr, size_t len ) {
return realloc ( ptr, len );
}
static inline __attribute__ (( always_inline )) void psFree ( void *ptr ) {
free ( ptr );
}
#define matrixStrDebugMsg( ... ) DBG ( __VA_ARGS__ )
#define matrixIntDebugMsg( ... ) DBG ( __VA_ARGS__ )
/* Use our standard cpu_to_leXX etc. macros */
#undef LOAD32L
#define LOAD32L( cpu32, ptr ) do { \
uint32_t *le32 = ( ( uint32_t * ) ptr ); \
cpu32 = le32_to_cpu ( *le32 ); \
} while ( 0 )
#undef LOAD32H
#define LOAD32H( cpu32, ptr ) do { \
uint32_t *be32 = ( ( uint32_t * ) ptr ); \
cpu32 = be32_to_cpu ( *be32 ); \
} while ( 0 )
#undef LOAD64L
#define LOAD64L( cpu64, ptr ) do { \
uint64_t *le64 = ( ( uint64_t * ) ptr ); \
cpu64 = le64_to_cpu ( *le64 ); \
} while ( 0 )
#undef LOAD64H
#define LOAD64H( cpu64, ptr ) do { \
uint64_t *be64 = ( ( uint64_t * ) ptr ); \
cpu64 = be64_to_cpu ( *be64 ); \
} while ( 0 )
#undef STORE32L
#define STORE32L( cpu32, ptr ) do { \
uint32_t *le32 = ( ( uint32_t * ) ptr ); \
*le32 = cpu_to_le32 ( cpu32 ); \
} while ( 0 )
#undef STORE32H
#define STORE32H( cpu32, ptr ) do { \
uint32_t *be32 = ( ( uint32_t * ) ptr ); \
*be32 = cpu_to_be32 ( cpu32 ); \
} while ( 0 )
#undef STORE64L
#define STORE64L( cpu64, ptr ) do { \
uint64_t *le64 = ( ( uint64_t * ) ptr ); \
*le64 = cpu_to_le64 ( cpu64 ); \
} while ( 0 )
#undef STORE64H
#define STORE64H( cpu64, ptr ) do { \
uint64_t *be64 = ( ( uint64_t * ) ptr ); \
*be64 = cpu_to_be64 ( cpu64 ); \
} while ( 0 )
/* Use rolXX etc. from bitops.h */
#undef ROL
#define ROL( data, rotation ) rol32 ( (data), (rotation) )
#undef ROLc
#define ROLc( data, rotation ) rol32 ( (data), (rotation) )
#undef ROR
#define ROR( data, rotation ) ror32 ( (data), (rotation) )
#undef RORc
#define RORc( data, rotation ) ror32 ( (data), (rotation) )
#undef ROL64
#define ROL64( data, rotation ) rol64 ( (data), (rotation) )
#undef ROL64c
#define ROL64c( data, rotation ) rol64 ( (data), (rotation) )
#undef ROR64
#define ROR64( data, rotation ) ror64 ( (data), (rotation) )
#undef ROR64c
#define ROR64c( data, rotation ) ror64 ( (data), (rotation) )
#endif /* _MATRIXSSL_CRYPTOLAYER_H */
+44 -28
View File
@@ -25,45 +25,61 @@
#include <string.h>
#include <gpxe/crypto.h>
static void null_init ( void *ctx __unused ) {
static void digest_null_init ( void *ctx __unused ) {
/* Do nothing */
}
static int null_setkey ( void *ctx __unused, const void *key __unused,
size_t keylen __unused ) {
/* Do nothing */
return 0;
}
static void null_setiv ( void *ctx __unused, const void *iv __unused ) {
static void digest_null_update ( void *ctx __unused, const void *src __unused,
size_t len __unused ) {
/* Do nothing */
}
static void null_encode ( void *ctx __unused, const void *src,
void *dst, size_t len ) {
if ( dst )
memcpy ( dst, src, len );
}
static void null_decode ( void *ctx __unused, const void *src,
void *dst, size_t len ) {
if ( dst )
memcpy ( dst, src, len );
}
static void null_final ( void *ctx __unused, void *out __unused ) {
static void digest_null_final ( void *ctx __unused, void *out __unused ) {
/* Do nothing */
}
struct crypto_algorithm crypto_null = {
struct digest_algorithm digest_null = {
.name = "null",
.ctxsize = 0,
.blocksize = 1,
.digestsize = 0,
.init = null_init,
.setkey = null_setkey,
.setiv = null_setiv,
.encode = null_encode,
.decode = null_decode,
.final = null_final,
.init = digest_null_init,
.update = digest_null_update,
.final = digest_null_final,
};
static int cipher_null_setkey ( void *ctx __unused, const void *key __unused,
size_t keylen __unused ) {
/* Do nothing */
return 0;
}
static void cipher_null_setiv ( void *ctx __unused,
const void *iv __unused ) {
/* Do nothing */
}
static void cipher_null_encrypt ( void *ctx __unused, const void *src,
void *dst, size_t len ) {
memcpy ( dst, src, len );
}
static void cipher_null_decrypt ( void *ctx __unused, const void *src,
void *dst, size_t len ) {
memcpy ( dst, src, len );
}
struct cipher_algorithm cipher_null = {
.name = "null",
.ctxsize = 0,
.blocksize = 1,
.setkey = cipher_null_setkey,
.setiv = cipher_null_setiv,
.encrypt = cipher_null_encrypt,
.decrypt = cipher_null_decrypt,
};
struct pubkey_algorithm pubkey_null = {
.name = "null",
.ctxsize = 0,
};
-86
View File
@@ -1,86 +0,0 @@
/* mcb - this file breaks the build process; temporarily deactivating */
#if 0
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include "ssl.h"
int main(int argc, char *argv[])
{
SSL_t ssl;
int sockfd, portno, rc;
struct sockaddr_in serv_addr;
struct hostent *server;
portno = 443;
sockfd = socket(AF_INET,SOCK_STREAM,0);
if(sockfd<0){
fprintf(stderr,"Error creating socket\n");
exit(sockfd);
}
server = gethostbyname(argv[1]);
if(server==NULL){
fprintf(stderr,"Error looking up host %s\n",argv[1]);
exit(1);
}
/**
*matrixSslOpen()
*matrixSslReadKeys()
**/
printf("Calling CreateSSLHello()\n");
rc = CreateSSLHello(&ssl);
printf("Finished calling CreateSSLHello()\n");
bzero((char *) &serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
bcopy((char *)server->h_addr,(char *)&serv_addr.sin_addr.s_addr,server->h_length);
serv_addr.sin_port = htons(portno);
if(connect(sockfd,(struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0){
fprintf(stderr,"ERROR connecting to server\n");
exit(1);
}
PrintSSLPacket(&ssl);
printf("Write ssl.buffer\n");
write(sockfd,ssl.buffer,ssl.length);
printf("Finished writing\n");
ssl.length = read(sockfd,ssl.buffer,ssl.max_size);
ReadSSLHello(&ssl);
/**
*matrixSslNewSession()
*matrixSslSetCetValidator()
*encodeSslHandshake()
*write handshake buffer
*readSslResponse() <-+
|
*read return code |-- similar/same function??
|
*sslEncode() |
*sslDecode() <-------+
*encodeSslCloseAlert()
*write close alert buffer
**/
close(sockfd);
/**
*sslClose()
* -free connection
* -free keys
* -close pki interface
**/
return 0;
}
#endif
+3 -3
View File
@@ -35,7 +35,7 @@
* @v key Key
* @v key_len Length of key
*/
static void hmac_reduce_key ( struct crypto_algorithm *digest,
static void hmac_reduce_key ( struct digest_algorithm *digest,
void *key, size_t *key_len ) {
uint8_t digest_ctx[digest->ctxsize];
@@ -58,7 +58,7 @@ static void hmac_reduce_key ( struct crypto_algorithm *digest,
* will be replaced with its own digest, and key_len will be updated
* accordingly).
*/
void hmac_init ( struct crypto_algorithm *digest, void *digest_ctx,
void hmac_init ( struct digest_algorithm *digest, void *digest_ctx,
void *key, size_t *key_len ) {
unsigned char k_ipad[digest->blocksize];
unsigned int i;
@@ -93,7 +93,7 @@ void hmac_init ( struct crypto_algorithm *digest, void *digest_ctx,
* will be replaced with its own digest, and key_len will be updated
* accordingly).
*/
void hmac_final ( struct crypto_algorithm *digest, void *digest_ctx,
void hmac_final ( struct digest_algorithm *digest, void *digest_ctx,
void *key, size_t *key_len, void *hmac ) {
unsigned char k_opad[digest->blocksize];
unsigned int i;
-487
View File
@@ -1,487 +0,0 @@
/*
* mpi.h
* Release $Name$
*
* multiple-precision integer library
*/
/*
* Copyright (c) PeerSec Networks, 2002-2006. All Rights Reserved.
* The latest version of this code is available at http://www.matrixssl.org
*
* This software is open source; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This General Public License does NOT permit incorporating this software
* into proprietary programs. If you are unable to comply with the GPL, a
* commercial license for this software may be purchased from PeerSec Networks
* at http://www.peersec.com
*
* This program is distributed in WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* http://www.gnu.org/copyleft/gpl.html
*/
/******************************************************************************/
#ifndef _h_MPI
#define _h_MPI
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <limits.h>
#undef MIN
#define MIN(x,y) ((x)<(y)?(x):(y))
#undef MAX
#define MAX(x,y) ((x)>(y)?(x):(y))
#ifdef __cplusplus
extern "C" {
/*
C++ compilers don't like assigning void * to mp_digit *
*/
#define OPT_CAST(x) (x *)
#else
/*
C on the other hand doesn't care
*/
#define OPT_CAST(x)
#endif /* __cplusplus */
/******************************************************************************/
/*
some default configurations.
A "mp_digit" must be able to hold DIGIT_BIT + 1 bits
A "mp_word" must be able to hold 2*DIGIT_BIT + 1 bits
At the very least a mp_digit must be able to hold 7 bits
[any size beyond that is ok provided it doesn't overflow the data type]
*/
#ifdef MP_8BIT
typedef unsigned char mp_digit;
typedef unsigned short mp_word;
#elif defined(MP_16BIT)
typedef unsigned short mp_digit;
typedef unsigned long mp_word;
#elif defined(MP_64BIT)
/*
for GCC only on supported platforms
*/
#ifndef CRYPT
typedef unsigned long long ulong64;
typedef signed long long long64;
#endif /* CRYPT */
typedef ulong64 mp_digit;
typedef unsigned long mp_word __attribute__ ((mode(TI)));
#define DIGIT_BIT 60
#else /* MP_8BIT */
/*
this is the default case, 28-bit digits
*/
#ifndef CRYPT
#if defined(_MSC_VER) || defined(__BORLANDC__)
typedef unsigned __int64 ulong64;
typedef signed __int64 long64;
#else
typedef unsigned long long ulong64;
typedef signed long long long64;
#endif
#endif /* CRYPT */
typedef unsigned long mp_digit;
typedef ulong64 mp_word;
#ifdef MP_31BIT
/*
this is an extension that uses 31-bit digits
*/
#define DIGIT_BIT 31
#else /* MP_31BIT */
/*
default case is 28-bit digits, defines MP_28BIT as a handy macro to test
*/
#define DIGIT_BIT 28
#define MP_28BIT
#endif /* MP_31BIT */
#endif /* MP_8BIT */
/*
otherwise the bits per digit is calculated automatically from the size of
a mp_digit
*/
#ifndef DIGIT_BIT
#define DIGIT_BIT ((int32)((CHAR_BIT * sizeof(mp_digit) - 1))) /* bits per digit */
#endif /* DIGIT_BIT */
#define MP_DIGIT_BIT DIGIT_BIT
#define MP_MASK ((((mp_digit)1)<<((mp_digit)DIGIT_BIT))-((mp_digit)1))
#define MP_DIGIT_MAX MP_MASK
/******************************************************************************/
/*
equalities
*/
#define MP_LT -1 /* less than */
#define MP_EQ 0 /* equal to */
#define MP_GT 1 /* greater than */
#define MP_ZPOS 0 /* positive integer */
#define MP_NEG 1 /* negative */
#define MP_OKAY 0 /* ok result */
#define MP_MEM -2 /* out of mem */
#define MP_VAL -3 /* invalid input */
#define MP_RANGE MP_VAL
#define MP_YES 1 /* yes response */
#define MP_NO 0 /* no response */
typedef int32 mp_err;
/******************************************************************************/
/*
various build options
*/
#define MP_PREC 64 /* default digits of precision */
/*
define this to use lower memory usage routines (exptmods mostly)
*/
#define MP_LOW_MEM
/*
size of comba arrays, should be at least
2 * 2**(BITS_PER_WORD - BITS_PER_DIGIT*2)
*/
#define MP_WARRAY (1 << (sizeof(mp_word) * CHAR_BIT - 2 * DIGIT_BIT + 1))
typedef struct {
int32 used, alloc, sign;
mp_digit *dp;
} mp_int;
#define USED(m) ((m)->used)
#define DIGIT(m,k) ((m)->dp[(k)])
#define SIGN(m) ((m)->sign)
/******************************************************************************/
/*
init and deinit bignum functions
*/
/*
init a bignum
*/
extern int32 mp_init(psPool_t *pool, mp_int *a);
/*
free a bignum
*/
extern void mp_clear(mp_int *a);
/*
init a series of arguments
*/
extern int32 _mp_init_multi(psPool_t *pool, mp_int *mp0, mp_int *mp1, mp_int *mp2,
mp_int *mp3, mp_int *mp4, mp_int *mp5, mp_int *mp6,
mp_int *mp7);
/*
clear a series of arguments
*/
extern void _mp_clear_multi(mp_int *mp0, mp_int *mp1, mp_int *mp2, mp_int *mp3,
mp_int *mp4, mp_int *mp5, mp_int *mp6, mp_int *mp7);
/*
exchange two ints
*/
extern void mp_exch(mp_int *a, mp_int *b);
/*
shrink ram required for a bignum
*/
extern int32 mp_shrink(mp_int *a);
/*
grow an int32 to a given size
*/
extern int32 mp_grow(mp_int *a, int32 size);
/*
init to a given number of digits
*/
extern int32 mp_init_size(psPool_t *pool, mp_int *a, int32 size);
/******************************************************************************/
/*
Basic Manipulations
*/
#define mp_iszero(a) (((a)->used == 0) ? MP_YES : MP_NO)
#define mp_iseven(a) (((a)->used > 0 && (((a)->dp[0] & 1) == 0)) ? MP_YES : MP_NO)
#define mp_isodd(a) (((a)->used > 0 && (((a)->dp[0] & 1) == 1)) ? MP_YES : MP_NO)
extern int32 mp_add_d (mp_int * a, mp_digit b, mp_int * c);
extern int32 mp_sub_d (mp_int * a, mp_digit b, mp_int * c);
/*
set to zero
*/
extern void mp_zero(mp_int *a);
/*
set to a digit
*/
extern void mp_set(mp_int *a, mp_digit b);
/*
copy, b = a
*/
extern int32 mp_copy(mp_int *a, mp_int *b);
/*
inits and copies, a = b
*/
extern int32 mp_init_copy(psPool_t *pool, mp_int *a, mp_int *b);
/*
trim unused digits
*/
extern void mp_clamp(mp_int *a);
/******************************************************************************/
/*
digit manipulation
*/
/*
right shift by "b" digits
*/
extern void mp_rshd(mp_int *a, int32 b);
/*
left shift by "b" digits
*/
extern int32 mp_lshd(mp_int *a, int32 b);
/*
c = a / 2**b
*/
extern int32 mp_div_2d(psPool_t *pool, mp_int *a, int32 b, mp_int *c, mp_int *d);
/*
b = a/2
*/
extern int32 mp_div_2(mp_int *a, mp_int *b);
/*
c = a * 2**b
*/
extern int32 mp_mul_2d(mp_int *a, int32 b, mp_int *c);
/*
c = a mod 2**d
*/
extern int32 mp_mod_2d(mp_int *a, int32 b, mp_int *c);
/*
computes a = 2**b
*/
extern int32 mp_2expt(mp_int *a, int32 b);
/******************************************************************************/
/*
Basic arithmetic
*/
/*
b = |a|
*/
extern int32 mp_abs(mp_int *a, mp_int *b);
/*
compare a to b
*/
extern int32 mp_cmp(mp_int *a, mp_int *b);
/*
compare |a| to |b|
*/
extern int32 mp_cmp_mag(mp_int *a, mp_int *b);
/*
c = a + b
*/
extern int32 mp_add(mp_int *a, mp_int *b, mp_int *c);
/*
c = a - b
*/
extern int32 mp_sub(mp_int *a, mp_int *b, mp_int *c);
/*
c = a * b
b = a*a
*/
/* STEVE - moved mp_mul out of SLOW case */
extern int32 mp_mul(psPool_t *pool, mp_int *a, mp_int *b, mp_int *c);
#ifdef USE_SMALL_WORD
extern int32 mp_sqr(psPool_t *pool, mp_int *a, mp_int *b);
#endif
/*
a/b => cb + d == a
*/
extern int32 mp_div(psPool_t *pool, mp_int *a, mp_int *b, mp_int *c, mp_int *d);
/*
c = a mod b, 0 <= c < b
*/
extern int32 mp_mod(psPool_t *pool, mp_int *a, mp_int *b, mp_int *c);
/******************************************************************************/
/*
single digit functions
*/
/*
compare against a single digit
*/
extern int32 mp_cmp_d(mp_int *a, mp_digit b);
/*
c = a * b
*/
extern int32 mp_mul_d(mp_int *a, mp_digit b, mp_int *c);
/******************************************************************************/
/*
number theory
*/
/*
d = a + b (mod c)
*/
extern int32 mp_addmod(psPool_t *pool, mp_int *a, mp_int *b, mp_int *c, mp_int *d);
/*
d = a * b (mod c)
*/
extern int32 mp_mulmod(psPool_t *pool, mp_int *a, mp_int *b, mp_int *c, mp_int *d);
/*
c = 1/a (mod b)
*/
#ifdef USE_SMALL_WORD
extern int32 mp_invmod(psPool_t *pool, mp_int *a, mp_int *b, mp_int *c);
#endif
/*
setups the montgomery reduction
*/
extern int32 mp_montgomery_setup(mp_int *a, mp_digit *mp);
/*
computes a = B**n mod b without division or multiplication useful for
normalizing numbers in a Montgomery system.
*/
extern int32 mp_montgomery_calc_normalization(mp_int *a, mp_int *b);
/*
computes x/R == x (mod N) via Montgomery Reduction
*/
#ifdef USE_SMALL_WORD
extern int32 mp_montgomery_reduce(mp_int *a, mp_int *m, mp_digit mp);
#endif
/*
d = a**b (mod c)
*/
/* TODO - we never define this */
extern int32 mp_exptmod(psPool_t *pool, mp_int *a, mp_int *b, mp_int *c, mp_int *d);
/******************************************************************************/
/*
If we're using 1024 or 2048 bit keys and 28 bit digits, we only need the
fast_ versions of these functions, removing the others to save space.
Otherwise, we include the slow versions as well and which version to use
is done at runtime.
*/
#ifdef USE_SMALL_WORD
extern int32 s_mp_mul_digs(psPool_t *pool, mp_int *a, mp_int *b, mp_int *c,
int32 digs);
extern int32 s_mp_sqr(psPool_t *pool, mp_int *a, mp_int *b);
#else
#define mp_montgomery_reduce fast_mp_montgomery_reduce
#define mp_sqr fast_s_mp_sqr
#if STEVE
#define mp_mul(P, A, B, C) fast_s_mp_mul_digs(P, A, B, C, (A)->used + (B)->used + 1)
#endif
#define s_mp_mul_digs fast_s_mp_mul_digs
#define mp_invmod fast_mp_invmod
#endif
/******************************************************************************/
/*
radix conversion
*/
extern int32 mp_count_bits(mp_int *a);
extern int32 mp_unsigned_bin_size(mp_int *a);
extern int32 mp_read_unsigned_bin(mp_int *a, unsigned char *b, int32 c);
extern int32 mp_to_unsigned_bin(psPool_t *pool, mp_int *a, unsigned char *b);
extern int32 mp_signed_bin_size(mp_int *a);
/*
lowlevel functions, do not call!
*/
#if STEVE
#ifdef USE_SMALL_WORD
#define s_mp_mul(P, A, B, C) s_mp_mul_digs(P, A, B, C, (A)->used + (B)->used + 1)
#else
#define s_mp_mul(P, A, B, C) sslAssert();
#endif
#endif /* STEVE */
/* define this in all cases for now STEVE */
#define s_mp_mul(P, A, B, C) s_mp_mul_digs(P, A, B, C, (A)->used + (B)->used + 1)
/*
b = a*2
*/
extern int32 mp_mul_2(mp_int *a, mp_int *b);
extern int32 s_mp_add(mp_int *a, mp_int *b, mp_int *c);
extern int32 s_mp_sub(mp_int *a, mp_int *b, mp_int *c);
extern int32 fast_s_mp_mul_digs(psPool_t *pool, mp_int *a, mp_int *b, mp_int *c,
int32 digs);
extern int32 fast_s_mp_sqr(psPool_t *pool, mp_int *a, mp_int *b);
extern int32 fast_mp_invmod(psPool_t *pool, mp_int *a, mp_int *b, mp_int *c);
extern int32 fast_mp_montgomery_reduce(mp_int *a, mp_int *m, mp_digit mp);
extern void bn_reverse(unsigned char *s, int32 len);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* _h_MPI */

Some files were not shown because too many files have changed in this diff Show More