709 Commits
Author SHA1 Message Date
Marty Connor f28b9cfb65 [release] Update version to 0.9.9 for release 2009-10-21 15:05:47 -04:00
Joshua Oreman 0677a383e0 [zbin] Fix 64-bit compilation warnings for util/zbin.c
Recent gcc versions generate more warnings when compiling util/zbin.c
on a 64-bit system:

util/zbin.c: In function `read_file':
util/zbin.c:85: warning: format `%d' expects type `int', but
                argument 3 has type `size_t'
util/zbin.c:91: warning: format `%d' expects type `int', but
                argument 3 has type `size_t'
util/zbin.c: In function `read_zinfo_file':
util/zbin.c:119: warning: format `%d' expects type `int', but
                 argument 4 has type `size_t'
util/zbin.c: In function `alloc_output_file':
util/zbin.c:134: warning: format `%d' expects type `int', but
                 argument 3 has type `size_t'
util/zbin.c: In function `process_zinfo_add':
util/zbin.c:244: warning: format `%d' expects type `int', but
                 argument 3 has type `size_t'
util/zbin.c:266: warning: format `%d' expects type `int', but
                 argument 7 has type `size_t'
util/zbin.c:286: warning: format `%#x' expects type `unsigned int',
                 but argument 7 has type `size_t'
util/zbin.c: In function `write_output_file':
util/zbin.c:348: warning: format `%d' expects type `int', but
                 argument 3 has type `size_t'

This patch eliminates these warnings.

Signed-off-by: Marty Connor <mdc@etherboot.org>
2009-10-20 16:57:54 -04:00
Marty Connor 15b46c5763 [util] Change gensdsk file permissions to include execute
src/util/gensdsk is a shell script and should have execute permission.

Reported-by: sobtwmxt sobtwmxt@sdf.lonestar.org
2009-10-20 10:07:50 -04:00
Shao Miller 389eefd0cd [sis190] Fix for gcc-3.3.3 compilation
gcc 3.3.3 gave the following error when compiling sis190.c

drivers/net/sis190.c: In function 'sis190_get_mac_addr_from_apc':
drivers/net/sis190.c:966: warning: 'isa_bridge' might be used
uninitialized in this function
make: *** [bin/sis190.o] Error 1

This patch allows error-free compilation.

Signed-off-by: Marty Connor <mdc@etherboot.org>
2009-10-17 22:03:03 -04:00
Thomas Miletich 78e54426c0 [zbin] Fix compilation warnings for util/zbin.c
Recent gcc versions generate warnings when compiling util/zbin.c
( tested with gcc-4.3.3 ):

util/zbin.c: In function ‘process_zinfo_pack’:
util/zbin.c:200: warning: format ‘%#zx’ expects type ‘size_t’, but argument 6
has type ‘long unsigned int’
util/zbin.c: In function ‘process_zinfo_add’:
util/zbin.c:257: warning: format ‘%#lx’ expects type ‘long unsigned int’, but
argument 4 has type ‘int’
util/zbin.c:266: warning: format ‘%#lx’ expects type ‘long unsigned int’, but
argument 4 has type ‘int’
util/zbin.c:266: warning: format ‘%d’ expects type ‘int’, but argument 8 has
type ‘long unsigned int’
util/zbin.c:286: warning: format ‘%#lx’ expects type ‘long unsigned int’, but
argument 6 has type ‘int’
util/zbin.c:286: warning: format ‘%#lx’ expects type ‘long unsigned int’, but
argument 7 has type ‘size_t’

This patch eliminates these warnings.

Tested with gcc-4.3.3 on Ubuntu 9.04 and gcc-4.1.2 on Debian Etch.

Signed-off-by: Marty Connor <mdc@etherboot.org>
2009-10-17 13:56:03 -04:00
Joshua Oreman 7296f1f21c [ath5k] Save proper cacheline size when fixing PCI configuration
Some BIOSes set the PCI cacheline size to zero for the card; the ath5k
driver fixes it to a reasonable in PCI config space, but failed to
correct the internal value it had already read. This resulted in
divide-by-zero errors when cacheline-aligning various data structures.

Fix by setting the internal cachelsz to a sane value at the same time
as we write that value to PCI config space.

Signed-off-by: Marty Connor <mdc@etherboot.org>
2009-10-16 20:25:17 -04:00
Joshua Oreman 489bd2f396 [ath5k] Update for changes in kernel 2.6.31
This adds basic rfkill support for enabling the wireless card on certain
laptops, and changes miscellaneous other details that may help in obscure
cases.

Also change the error handling to not report CRC errors, which due to the
basic facts of wireless may happen even more frequently than valid packets.

Signed-off-by: Marty Connor <mdc@etherboot.org>
2009-10-16 20:22:41 -04:00
Michael Brown 224ef7f483 [infiniband] Send CM requests to target node's GSI rather than SM's GSI 2009-10-16 23:03:47 +01:00
Thomas Miletich 251926f631 [sis190] Add sis190/191 ethernet driver
Tested-by: Paul Hackett <paulfxhackett@gmail.com>
Signed-off-by: Marty Connor <mdc@etherboot.org>
2009-10-16 14:56:34 -04:00
Simon Horman 04cb1cde5c [e1000] Add 82576 support
Add the 82576 to the e1000 driver.

- Examining the Linux 2.6.30-rc4 igb driver, which supports this card and;
- Information available in the Intel® 82576 Gigabit Ethernet
  Controller Datasheet v2.1, which is available from Intel's web site.

I only have a dual-ported card with Copper PHY, so any code paths relating
to Fibre haven't been tested. Also, I have only tested using auto-negotiation
of speed and duplex, and no flow control.  Other code paths relating to
those settings also have not been exercised.

Signed-off-by: Simon Horman <horms@verge.net.au>
Sponsored-by: Thomas Miletich <thomas.miletich@gmail.com>
Modified-by: Thomas Miletich <thomas.miletich@gmail.com>
Modified-by: Marty Connor <mdc@etherboot.org>
Signed-off-by: Marty Connor <mdc@etherboot.org>
2009-10-16 13:35:28 -04:00
Joshua Oreman db3e054fe5 [atl1e] Add Attansic L1E gigabit Ethernet driver
Signed-off-by: Marty Connor <mdc@etherboot.org>
2009-10-16 12:41:16 -04:00
Thomas Miletich d07f79de35 [sis900] Enable interrupts to allow UNDI to work
Enable interrupts in sis900_irq(). Doing so allows some programs using
gPXE's UNDI interface to work properly, including Symantec Ghost.

Tested-by: Hubert Mercier <hubert.mercier@unilim.fr>
Signed-off-by: Marty Connor <mdc@etherboot.org>
2009-10-15 15:32:51 -04:00
Stefan Hajnoczi 0ea6e5c221 [util] Make mtools check detect new versions
The mtools version check does not handle GNU mtools 4.0.10.  This commit
makes the pattern more general so it matches older mtools as well as the
newer "mtools (GNU mtools) 4.0.10" string.

Signed-off-by: Stefan Hajnoczi <stefanha@gmail.com>
Signed-off-by: Marty Connor <mdc@etherboot.org>
2009-10-15 14:54:30 -04:00
Joshua Oreman b0b0b8f65c [modrom] Avoid clobbering near jump with checksum
A jump instruction starts at the third byte of an option ROM image, and
it is required that the bytes in the whole image add up to zero. To
achieve this, a checksum byte is usually placed after the jump. The jump
can be either a short jump (2 bytes, EB xx) or a near jump (3 bytes,
E9 xx xx). gPXE's romprefix.S uses a near jump, but modrom.pl assumed
a short jump, and clobbered the high byte of the offset. This caused
modrom-modified gPXE ROM images to crash the system during POST.

Fix by making modrom.pl place the checksum at byte 6, like makerom.pl does.

Signed-off-by: Marty Connor <mdc@etherboot.org>
2009-10-15 14:47:54 -04:00
Joshua Oreman 3fa2779208 [build] Fix DEBUG builds for filenames with hyphens
Debug builds for filenames with hyphens such as:

     $ make bin/via-rhine.dsk DEBUG=via-rhine

fail with:

     [BUILD] bin/via-rhine.dbg1.o
     <command-line>: error: missing whitespace after the macro name
     make: *** [bin/via-rhine.dbg1.o] Error 1

This is because "-" is not a legal character in C identifiers, and
gcc rejects "-Ddebug_via-rhine=1" as an argument.

Signed-off-by: Daniel Verkamp <daniel@drv.nu>
Signed-off-by: Joshua Oreman <oremanj@rwcr.net>
Signed-off-by: Marty Connor <mdc@etherboot.org>
2009-10-15 14:07:20 -04:00
Thomas Miletich 584e378241 [3c90x] Fix a3c90x_close() and a3c90x_remove() methods.
Both methods disabled packet tx and rx just to have it enabled again
by calling a3c90x_reset().
Fixed by disabling tx and rx after the call to a3c90x_reset().

Tested by booting Ubuntu intrepid(8.10) directly from gPXE and pxelinux.
Tested on 3c905, 3c905B, 3c905C.

Signed-off-by: Marty Connor <mdc@etherboot.org>
2009-10-15 13:06:01 -04:00
Marty Connor 1bb420448c [release] Update version to 0.9.8+ post release 2009-10-14 14:24:49 -04:00
Marty Connor ec5863a7f5 [release] Update version to 0.9.8 for release 2009-10-14 12:12:40 -04:00
Michael Brown 9f7141a1ce [hermon] Reset device during probe()
Some systems will retry their boot sequence in the event of a boot
failure.  On these systems, the second and subsequent boot attempts
will fail to initialise the Hermon HCA.

Fix by resetting the HCA during probe().  This incurs a one-second
cost, but there seems to be no viable alternative.

Originally-fixed-by: Itay Gazit <itaygazit@gmail.com>
2009-10-14 02:11:16 +01:00
Michael Brown 4175b778c2 [pci] Add generic configuration space backup/restore facility
Some devices can only be reset via a mechanism that also resets the
card's PCI core, thus necessitating a backup and restore of all or
part of the PCI configuration space across a reset.
2009-10-14 02:06:23 +01:00
Michael Brown c9c411286a [job] Report progress of downloader jobs via job_progress() 2009-08-31 19:33:55 +01:00
Michael Brown 0fc13add31 [job] Add missing job_progress() interface method 2009-08-31 19:33:05 +01:00
Joshua Oreman d7dfc9572e [ath5k] Remove spurious debugging check
Signed-off-by: Marty Connor <mdc@etherboot.org>
2009-08-17 19:10:53 -04:00
Michael Brown a7290a970c [802.11] Support multicast hashing
802.11 multicast hashing is the same as standard Ethernet hashing, so
just expose and use eth_mc_hash().

Signed-off-by: Joshua Oreman <oremanj@rwcr.net>
2009-08-12 00:54:29 +01:00
Joshua Oreman 2310c30d1c [802.11] Properly initialize autoassociation process
The recent change to process_add() to detect duplicate process
additions relies on the fact that all processes will be initialized
using process_init_stopped() before being passed to that function.
The autoassociation process was not initialized in this fashion, so
process_add() erroneously detected it as a duplicate.

Fix by using process_init_stopped() to initialize the autoassociation
process instead of setting the step member directly.

Signed-off-by: Michael Brown <mcb30@etherboot.org>
2009-08-12 00:31:34 +01:00
Michael Brown 444d5550a7 [dhcp] Fall back to using the hardware address to populate the chaddr field
For IPoIB, the chaddr field is too small (16 bytes) to contain the
20-byte IPoIB link-layer address.  RFC4390 mandates that we should
pass an empty chaddr field and rely on the DHCP client identifier
instead.  This has many problems, not least of which is that a client
identifier containing an IPoIB link-layer address is not very useful
from the point of view of creating DHCP reservations, since the QPN
component is assigned at runtime and may vary between boots.

Leave the DHCP client identifier as-is, to avoid breaking existing
setups as far as possible, but expose the real hardware address (the
port GUID) via the DHCP chaddr field, using the broadcast flag to
instruct the DHCP server not to use this chaddr value as a link-layer
address.

This makes it possible (at least with ISC dhcpd) to create DHCP
reservations using host declarations such as:

    host duckling {
        fixed-address 10.252.252.99;
        hardware unknown-32 00:02:c9:02:00:25:a1:b5;
    }
2009-08-12 00:27:08 +01:00
Michael Brown 4eab5bc8ca [netdevice] Allow the hardware and link-layer addresses to differ in size
IPoIB has a 20-byte link-layer address, of which only eight bytes
represent anything relating to a "hardware address".

The PXE and EFI SNP APIs expect the permanent address to be the same
size as the link-layer address, so fill in the "permanent address"
field with the initial link layer address (as generated by
register_netdev() based upon the real hardware address).
2009-08-12 00:23:38 +01:00
Michael Brown 37a0aab4ff [netdevice] Separate out the concept of hardware and link-layer addresses
The hardware address is an intrinsic property of the hardware, while
the link-layer address can be changed at runtime.  This separation is
exposed via APIs such as PXE and EFI, but is currently elided by gPXE.

Expose the hardware and link-layer addresses as separate properties
within a net device.  Drivers should now fill in hw_addr, which will
be used to initialise ll_addr at the time of calling
register_netdev().
2009-08-12 00:19:14 +01:00
Michael Brown b3db99a38d [doc] Expand scope of doxygen-generated documentation 2009-08-11 15:14:36 +01:00
Joshua Oreman d5d68b2e31 [zbin] Change fixup semantics to support ROMs over 128k uncompressed
The option ROM header contains a one-byte field indicating the number
of 512-byte sectors in the ROM image.  Currently it is linked to
contain the number of uncompressed sectors, with an instruction to the
compressor to correct it.  This causes link failure when the
uncompressed size of the ROM image is over 128k.

Fix by replacing the SUBx compressor fixup with an ADDx fixup that
adds the total compressed output length, scaled as requested, to an
addend stored in the field where the final length value will be
placed.  This is similar to the behavior of ELF relocations, and
ensures that an overflow error will not be generated unless the
compressed size is still too large for the field.

This also allows us to do away with the _filesz_pgh and _filesz_sect
calculations exported by the linker script.

Output tested bitwise identical to the old SUBx mechanism on hd, dsk,
lkrn, and rom prefixes, on both 32-bit and 64-bit processors.

Modified-by: Michael Brown <mcb30@etherboot.org>
Signed-off-by: Michael Brown <mcb30@etherboot.org>
2009-08-11 12:59:26 +01:00
Michael Brown 487347a0cd [doc] Update doxygen.cfg to match version running on rom.etherboot.org 2009-08-11 07:02:05 -04:00
Michael Brown e5f14e5a32 [infiniband] Add support for the SRP Boot Firmware Table
The SRP Boot Firmware Table serves a similar role to the iSCSI and AoE
Boot Firmware Tables; it provides information required by the loaded
OS in order to establish a connection back to the SRP boot device.
2009-08-10 22:32:47 +01:00
Michael Brown 0ff5c456cb [infiniband] Disambiguate CM connection rejection reasons
There is diagnostic value in being able to disambiguate between the
various reasons why an IB CM has rejected a connection attempt.  In
particular, reason 8 "invalid service ID" can be used to identify an
incorrect SRP service_id root-path component, and reason 28 "consumer
reject" corresponds to a genuine SRP login rejection IU, which can be
passed up to the SRP layer.

For rejection reasons other than "consumer reject", we should not pass
through the private data, since it is most likely generated by the CM
without any protocol-specific knowledge.
2009-08-10 22:31:55 +01:00
Michael Brown 965a0f7a75 [infiniband] Allow SRP reconnection attempts even after reporting failures
With iSCSI, connection attempts are expensive; it may take many
seconds to determine that a connection will fail.  SRP connection
attempts are much less expensive, so we may as well avoid the
"optimisation" of declaring a state of permanent failure after a
certain number of attempts.  This allows a gPXE SRP initiator to
resume operations after an arbitrary amount of SRP target downtime.
2009-08-10 22:30:56 +01:00
Michael Brown a0d337912e [infiniband] Generate more specific errors in response to failure MADs
Generate errors within individual MAD transaction consumers such as
ib_pathrec.c and ib_mcast.c, rather than within ib_mi.c.  This allows
for more meaningful error messages to eventually be displayed to the
user.
2009-08-10 22:30:06 +01:00
Michael Brown 0c30dc6bc5 [infiniband] Add support for SRP over Infiniband
SRP is the SCSI RDMA Protocol.  It allows for a method of SAN booting
whereby the target is responsible for reading and writing data using
Remote DMA directly to the initiator's memory.  The software initiator
merely sends and receives SCSI commands; it never has to touch the
actual data.
2009-08-10 22:27:33 +01:00
Michael Brown 8de49af0d2 [infiniband] Add last_opened_ibdev(), analogous to last_opened_netdev()
The minimal-surprise behaviour, when no explicit SRP initiator device
is specified, will probably be to use the most recently opened
Infiniband device.  This matches our behaviour with using the most
recently opened net device for PXE, iSCSI, AoE, NBI, etc.
2009-08-10 22:25:57 +01:00
Michael Brown 419243e7f1 [infiniband] Add find_ibdev() 2009-08-10 22:25:02 +01:00
Michael Brown 4be11f523c [infiniband] Add a "communication-managed reliable connection" protocol
SRP over Infiniband uses a protocol whereby data is sent via a
combination of the CM private data fields and the RC queue pair
itself.  This seems sufficiently generic that it's worth having
available as a separate protocol.
2009-08-10 22:23:28 +01:00
Michael Brown 1175f0cf29 [hermon] Reduce the RC ACK timeout
The ACK timeout determines how long we take to notice a failed
Reliable Connection.  Reducing it from the arbitrary value of 19 down
to 14 reduces the individual ACK timeout from around 2.1s to 67ms;
this in turn reduces the time to tear down and re-establish a broken
SRP session from around 30s to around 1s.
2009-08-10 22:22:42 +01:00
Michael Brown 0b1222f233 [hermon] Randomise the high-order bits of queue pair numbers
The Infiniband Communication Manager will refuse to establish a
connection if it believes the connection is already established.
There is no immediately obvious way to ask it to tear down the
existing connection and replace it; to issue a DREP we would need to
know the local and remote communication IDs used for the previous
connection setup.

We can work around this by randomising the high-order bits of the
queue pair number; these have no significance to the hardware, but are
sufficient to convince the IB CM that this is a different connection.
2009-08-10 22:19:39 +01:00
Michael Brown cf716a0ce6 [scsi] Make LUN a property of the SCSI backend only
Nothing within the SCSI core actually refers to the LUN, so we can
simplify matters by treating it as purely a property of the backend.
2009-08-10 19:31:45 +01:00
Michael Brown d944794680 [scsi] Generalise iscsi_parse_lun() to scsi_parse_lun() 2009-08-10 19:30:41 +01:00
Michael Brown 976f12c501 [scsi] Generalise iscsi_detached_command() to scsi_detached_command() 2009-08-10 19:29:40 +01:00
Michael Brown 04878ef745 [process] Make it safe to call process_add() multiple times 2009-08-10 19:27:24 +01:00
Michael Brown 46073f1239 [infiniband] Handle duplicate Communication Management REPs
We will terminate our transaction as soon as we receive the first CM
REP, since that provides all the state that we need.  However, the
peer may resend the REP if it didn't see our RTU, and if we don't
respond with another RTU we risk being disconnected.  (This protocol
appears not to handle retries gracefully.)

Fix by adding a management agent that will listen for these duplicate
REPs and send back an RTU.
2009-08-09 01:31:07 +01:00
Joshua Oreman ce68f587e2 [ath5k] Add support for non-802.11n Atheros wireless NICs
Signed-off-by: Michael Brown <mcb30@etherboot.org>
2009-08-09 00:16:13 +01:00
Joshua Oreman 3f274a6950 [legal] Add MIT licence declaration
Signed-off-by: Michael Brown <mcb30@etherboot.org>
2009-08-09 00:13:29 +01:00
Joshua Oreman fc9750a68d [802.11] Fix memory leak on unsuccessful probes
When a probe found no results, the list head of beacons would not be
freed, leaking 16 bytes of memory per probe.

Signed-off-by: Michael Brown <mcb30@etherboot.org>
2009-08-09 00:12:53 +01:00
Joshua Oreman 0b3c88e035 [802.11] Fix maximum packet length
Previously the maximum packet length was computed using an erroneous
understanding of the role of the MIC field in TKIP-encrypted packets.
The field is actually considered to be part of the MSDU (encrypted and
fragmented data), not the MPDU (container for each encrypted
fragment). As such its size does not contribute to cryptographic
overhead outside the data field's size limitations. The net result is
that the previous maximum packet length value was 4 bytes too long;
fix it to the correct value of 2352.

Signed-off-by: Michael Brown <mcb30@etherboot.org>
2009-08-09 00:12:04 +01:00
Joshua Oreman 1e810bebe9 [802.11] Set channels early on to avoid tuning to an undefined channel
Some cards (such as ath5k) always need to tune to a particular channel
when they are reset; the reset may happen upon open(), which is before
the channels array would be set up (in prepare_probe()). Avoid tuning
the card to an inconsistent state by copying the hardware
supported-channels array to the 802.11 device's allowable-channels
array even before channels are "properly" set up.

Signed-off-by: Michael Brown <mcb30@etherboot.org>
2009-08-09 00:11:33 +01:00
Joshua Oreman f128a6db21 [802.11] Enhance support for driver PHY differences
The prior net80211 model of physical-layer behavior for drivers was
overly simplistic and limited the drivers that could be written.  To
be more flexible, split the driver-provided list of supported rates by
band, and add a means for specifying a list of supported channels.
Allow drivers to specify a hardware channel value that will be tied to
uses of the channel.

Expose net80211_duration() to drivers, and make the rate it uses in
its computations configurable, so that it can be used in calculating
durations that must be set in hardware for ACK and CTS packets. Add
net80211_cts_duration() for the common case of calculating the
duration for a CTS packet.

Signed-off-by: Michael Brown <mcb30@etherboot.org>
2009-08-09 00:11:26 +01:00
vibi sreenivasan e6e30618c2 [geniso] Emit proper error message for incorrect location of ISOLINUX_BIN
If isolinux.bin is not installed in the expected location the error
message shown is slightly misleading.

Signed-off-by: Vibi Sreenivasan <vibi_sreenivasan@cms.com>
Signed-off-by: Michael Brown <mcb30@etherboot.org>
2009-08-09 00:05:49 +01:00
Michael Brown 34bfc04e4c [infiniband] Update all other MAD users to use a management interface 2009-08-08 23:56:28 +01:00
Michael Brown 44251ebb9a [infiniband] Update subnet management agent to use a management interface 2009-08-08 23:55:29 +01:00
Michael Brown 0e07516f62 [infiniband] Add the concept of a management interface
A management interface is the component through which both local and
remote management agents are accessed.

This new implementation of a management interface allows for the user
to react to timed-out transactions, and also allows for cancellation
of in-progress transactions.
2009-08-08 23:51:27 +01:00
Michael Brown 18bcdfb1cc [hermon] Allow for multiple calls to ib_modify_qp() 2009-08-08 23:49:59 +01:00
Michael Brown 7a3a159af5 [romprefix] Cope with PnP BIOSes that fail to set %es:%di on entry
Some BIOSes support the BIOS Boot Specification (BBS) but fail to set
%es:%di correctly when calling the option ROM initialisation entry
point.  This causes gPXE to identify the BIOS as non-PnP (and so
non-BBS), leaving the user unable to control the boot order.

Fix by scanning for the $PnP signature ourselves, rather than relying
on the BIOS having passed in %es:%di correctly.

Tested-by: Helmut Adrigan <helmut.adrigan@chello.at>
2009-08-08 15:32:28 +01:00
Michael Brown ad66465b3c [hermon] Add support for multiple ports and detecting non-IB ports
Originally-fixed-by: Itay Gazit <itaygazit@gmail.com>
2009-08-06 01:55:38 +01:00
Michael Brown b0c563824b [infiniband] Change IB_{QPN,QKEY,QPT} names from {SMA,GMA} to {SMI,GSI}
The IBA specification refers to management "interfaces" and "agents".
The interface is the component that connects to the queue pair and
sends and receives MADs; the agent is the component that constructs
the reply to the MAD.

Rename the IB_{QPN,QKEY,QPT} constants as a first step towards making
this separation in gPXE.
2009-08-06 01:24:18 +01:00
Michael Brown 1f7d550246 [build] Mark __intel_new_proc_init with __libgcc rather than cdecl
The function __intel_new_proc_init() (called implicitly when building
using icc) is marked with __attribute__((cdecl)).  This breaks
building on x86_64, where cdecl is meaningless.

Fix by replacing with the existing __libgcc macro, which is already
defined to be "__attribute__((cdecl))" for i386 builds and empty for
x86_64 builds.
2009-08-03 15:56:10 +01:00
Joshua Oreman 70f47e675e [sky2] Add support for Marvell Yukon-II gigabit Ethernet cards
Signed-off-by: Michael Brown <mcb30@etherboot.org>
2009-08-03 00:27:16 +01:00
Joshua Oreman 993f8ba9bc [pci] Add definitions for Advanced Error Reporting registers
Signed-off-by: Michael Brown <mcb30@etherboot.org>
2009-08-03 00:22:28 +01:00
H. Peter Anvin 5e1aa70301 [legal] Add the MIT and ISC licenses to licence.pl
The MIT and ISC licenses are legally equivalent to the bsd2 license,
but with slightly different verbiage.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: Michael Brown <mcb30@etherboot.org>
2009-08-02 23:30:38 +01:00
H. Peter Anvin 193d545903 [pxe] Dual-license pxe_api.h under the MIT license
pxe_api.h is just a description of API functions, it's actively
undesirable to have more implementations than necessary.  Allowing it
under the MIT license lets the Syslinux libraries use it.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: Michael Brown <mcb30@etherboot.org>
2009-08-02 23:29:06 +01:00
Joshua Oreman bba00b0c13 [config] Enable PXE commands by default only on pcbios architecture
The commands bring in UNDI and thus real-mode code, so they cannot be
used on EFI.

Signed-off-by: Michael Brown <mcb30@etherboot.org>
2009-08-02 23:19:40 +01:00
Michael Brown 2b9f7f042c [pxe] Avoid printf format warning on some compilers
Tested-by: Joshua Oreman <oremanj@xenon.get-linux.org>
2009-08-02 22:45:24 +01:00
Michael Brown 5552a1b202 [tcp] Avoid printf format warnings on some compilers
In several places, we currently use size_t to represent a difference
between TCP sequence numbers.  This can cause compiler warnings
relating to printf format specifiers, since the result of
(uint32_t+size_t) may be an unsigned long on some compilers.

Fix by using uint32_t for all variables that represent a difference
between TCP sequence numbers.

Tested-by: Joshua Oreman <oremanj@xenon.get-linux.org>
2009-08-02 22:44:57 +01:00
Michael Brown f42b2932f8 [build] Allow safe concurrent builds of .iso, .liso and .sdsk targets
The geniso, genliso and gensdsk scripts contain hard-coded temporary
directory names, and so could potentially collide with each other when
run as part of a concurrent build (e.g. "make -j 4").

Fix by using mktemp to generate suitable temporary directory names.
2009-08-02 11:17:02 +01:00
Michael Brown b570c2efd8 [build] Make .liso image generation silent unless errors occur 2009-08-02 11:09:08 +01:00
Marty Connor 96f4f96540 [build] Add syslinux floppy image type .sdsk
We add a syslinux floppy disk type using parts of the genliso script.
This floppy image cat be dd'ed to a physical floppy or used in
instances where a virtual floppy with an mountable DOS filesystem is
useful.

We also modify the genliso script to only generate .liso images
rather than creating images depending on how it is called.

Signed-off-by: Michael Brown <mcb30@etherboot.org>
2009-08-02 11:04:13 +01:00
Joshua Oreman 14ae602ef0 [rtl818x] Add driver for Realtek 8180/8185 wireless cards 2009-08-01 19:02:48 +01:00
Joshua Oreman ce64398f87 [802.11] Add support for 802.11 devices with software MAC layer
This is required for all modern 802.11 devices, and allows drivers
to be written for them with minimally more effort than is required
for a wired NIC.

Signed-off-by: Michael Brown <mcb30@etherboot.org>
Modified-by: Michael Brown <mcb30@etherboot.org>
2009-08-01 19:00:32 +01:00
Michael Brown bb2cf3c8d7 [hermon] Add support for RC queue pairs 2009-07-17 23:06:35 +01:00
Michael Brown cd5a21359c [hermon] Allow software GMA to receive packets destined for QP1
The Linux IB Communication Manager will always send MADs to QP1,
rather than back to the originating QP.  On Hermon, QP1 is by default
handled by the embedded firmware.  We can change this, but the cost is
that we have to handle both QP0 and QP1 (i.e. we have to provide SMA
as well as GMA service in software), and we have to use MLX queues
rather than standard UD queues (i.e. we have to construct the UD
datagrams by hand).

There doesn't seem to be any viable way around this situation, ugly
though it is.
2009-07-17 23:06:35 +01:00
Michael Brown de50a19ae3 [hermon] Disable debugging around mapping of firmware tables 2009-07-17 23:06:35 +01:00
Michael Brown dd2788594b [hermon] Remove an unnecessary check for GID-less transmissions 2009-07-17 23:06:35 +01:00
Michael Brown cc2e767b5a [infiniband] Add Communication Manager (CM)
The Communication Manager is responsible for handling the setup and
teardown of RC connections.
2009-07-17 23:06:35 +01:00
Michael Brown c939bc57ff [infiniband] Add infrastructure for RC queue pairs
Queue pairs are now assumed to be created in the INIT state, with a
call to ib_modify_qp() required to bring the queue pair to the RTS
state.

ib_modify_qp() no longer takes a modification list; callers should
modify the relevant queue pair parameters (e.g. qkey) directly and
then call ib_modify_qp() to synchronise the changes to the hardware.

The packet sequence number is now a property of the queue pair, rather
than of the device.

Each queue pair may have an associated address vector.  For RC queue
pairs, this is the address vector that will be programmed in to the
hardware as the remote address.  For UD queue pairs, it will be used
as the default address vector if none is supplied to ib_post_send().
2009-07-17 23:06:35 +01:00
Michael Brown ea6eb7f7ed [infiniband] Pass a generic MAD to ib_set_port_info() 2009-07-17 23:06:35 +01:00
Michael Brown 0095e18d4c [infiniband] Expose supported and enabled link speeds and widths 2009-07-17 23:06:35 +01:00
Michael Brown 773028d34e [infiniband] Allow MAD handlers to indicate response via return value
Now that MAD handlers no longer return a status code, we can allow
them to return a pointer to a MAD structure if and only if they want
to send a response.  This provides a more natural and flexible
approach than using a "response method" field within the handler's
descriptor.
2009-07-17 23:06:35 +01:00
Michael Brown 94876f4bb6 [infiniband] Remove the return status code from MAD handlers
MAD handlers have to set the status fields within the MAD itself
anyway, in order to provide a meaningful response MAD; the additional
gPXE return status code is just noise.

Note that we probably don't need to ever explicitly set the status to
IB_MGMT_STATUS_OK, since it should already have this value from the
request.  (By not explicitly setting the status in this way, we can
safely have ib_sma_set_xxx() call ib_sma_get_xxx() in order to
generate the GetResponse MAD without worrying that ib_sma_get_xxx()
will clear any error status set by ib_sma_set_xxx().)
2009-07-17 23:06:35 +01:00
Michael Brown f1d92fa886 [infiniband] Allow external QPN to differ from real QPN
Most IB hardware seems not to allow allocation of the genuine QPNs 0
and 1, so allow for the externally-visible QPN (as constructed and
parsed by ib_packet, where used) to differ from the real
hardware-allocated QPN.
2009-07-17 23:06:34 +01:00
Michael Brown 92cf240020 [infiniband] Always create an SMA and a GMA 2009-07-17 23:06:34 +01:00
Michael Brown 80c41b90d2 [infiniband] Add notion of a queue pair type 2009-07-17 23:06:34 +01:00
Michael Brown 3f4972db9a [infiniband] Allow completion queue operations to be optional
The send completion handler typically will just free the I/O buffer,
so allow this common case to be handled by the Infiniband core.
2009-07-17 23:06:34 +01:00
Michael Brown 0582a84e66 [infiniband] Improve ib_packet debugging messages 2009-07-17 23:06:34 +01:00
Michael Brown 47c4aaa9e2 [ipoib] Attempt the broadcast group join only if the link is up
Attempting the broadcast group join while the link is down is
harmless, but can generate annoying volumes of debug messages.
2009-07-17 23:06:34 +01:00
Michael Brown 165074c188 [infiniband] Implement SMA as an instance of a GMA
The GMA code was based upon the SMA code.  We can save space by making
the SMA simply an instance of the GMA.
2009-07-17 23:06:34 +01:00
Michael Brown 8a852280eb [infiniband] Pass GMA as a parameter to GMA MAD handlers 2009-07-17 23:06:34 +01:00
Michael Brown cb9ef4dee2 [ipoib] Remove the queue set abstraction
Now that IPoIB has to deal with only one set of queues, the queue set
abstraction becomes merely an inconvenient wrapper.
2009-07-17 23:06:34 +01:00
Michael Brown 63c112ed38 [ipoib] Kill off the now-unused IPoIB metadata queue set
All packets handled by the metadata queue set now go via the GMA.
2009-07-17 23:06:34 +01:00
Michael Brown 0fbf2f6bda [infiniband] Provide a general mechanism for multicast group joins
Generalise out the multicast group membership record code from IPoIB.
2009-07-17 23:06:34 +01:00
Michael Brown 3c77fe73a5 [infiniband] Allow for sending MADs via GMA without retransmission 2009-07-17 23:06:34 +01:00
Michael Brown b4155c4ab5 [infiniband] Make qkey and rate optional parameters to ib_post_send()
The queue key is stored as a property of the queue pair, and so can
optionally be added by the Infiniband core at the time of calling
ib_post_send(), rather than always having to be specified by the
caller.

This allows IPoIB to avoid explicitly keeping track of the data queue
key.
2009-07-17 23:06:33 +01:00
Michael Brown 8aa2591c06 [ipoib] Clarify new role of IPoIB peer cache as for MAC addresses only
Now that path record lookups are handled entirely via
ib_resolve_path(), the only role of the IPoIB peer cache is as a
lookup table for MAC addresses.  Update the code structure and
comments to reflect this.
2009-07-17 23:06:33 +01:00
Michael Brown 06ad481904 [ipoib] Expose the real broadcast MAC
The IPoIB broadcast MAC address varies according to the partition key.
Now that the broadcast MAC address is a property of the network device
rather than of the link layer, we can expose this real MAC address
directly.

The broadcast LID is now identified via a path record lookup; this is
marginally inefficient (since it was present in the MCMemberRecord
GetResponse), but avoids the need to special-case broadcasts when
constructing the address vector in ipoib_transmit().
2009-07-17 23:06:33 +01:00
Michael Brown 4d0029611f [ipoib] Use Infiniband broadcast QPN in IPoIB broadcast MAC address
Remove the special handling of the IPoIB broadcast QPN.
2009-07-17 23:06:33 +01:00
Michael Brown d6b47871de [infiniband] Provide a general mechanism for path record lookups
Generalise out the path record lookup code from IPoIB.
2009-07-17 23:06:33 +01:00
Michael Brown 1d8c85d112 [infiniband] Create a general management agent
Generalise the subnet management agent into a general management agent
capable of sending and responding to MADs, including support for
retransmissions as necessary.
2009-07-17 23:06:33 +01:00
Michael Brown 365b8db5cf [infiniband] Centralise SMA and GMA queue constants 2009-07-17 23:06:33 +01:00
Michael Brown 887d296b88 [infiniband] Poll completion queues automatically
Currently, all Infiniband users must create a process for polling
their completion queues (or rely on a regular hook such as
netdev_poll() in ipoib.c).

Move instead to a model whereby the Infiniband core maintains a single
process calling ib_poll_eq(), and polling the event queue triggers
polls of the applicable completion queues.  (At present, the
Infiniband core simply polls all of the device's completion queues.)
Polling a completion queue will now implicitly refill all attached
receive work queues; this is analogous to the way that netdev_poll()
implicitly refills the RX ring.

Infiniband users no longer need to create a process just to poll their
completion queues and refill their receive rings.
2009-07-17 23:06:33 +01:00
Michael Brown 1f5c0239b4 [infiniband] Centralise assumption of 2048-byte payloads
IPoIB and the SMA have separate constants for the packet size to be
used to I/O buffer allocations.  Merge these into the single
IB_MAX_PAYLOAD_SIZE constant.

(Various other points in the Infiniband stack have hard-coded
assumptions of a 2048-byte payload; we don't currently support
variable MTUs.)
2009-07-17 23:06:33 +01:00
Michael Brown 7ba33f7826 [infiniband] Provide ib_get_hca_info() as a commonly-available function 2009-07-17 23:06:33 +01:00
Michael Brown b25a4b6c8a [infiniband] Split queue set functionality out of ipoib.c to ib_qset.c 2009-07-17 23:06:33 +01:00
Michael Brown 8868956268 [infiniband] Move non-driver-specific code to net/infiniband 2009-07-17 23:04:07 +01:00
Michael Brown d09290161e [netdevice] Make ll_broadcast per-netdevice rather than per-ll_protocol
IPoIB has a link-layer broadcast address that varies according to the
partition key.  We currently go through several contortions to pretend
that the link-layer address is a fixed constant; by making the
broadcast address a property of the network device rather than the
link-layer protocol it will be possible to simplify IPoIB's broadcast
handling.
2009-07-17 23:02:48 +01:00
Michael Brown 54ec3673cc [ata] Make ATA command issuing partially asynchronous
Move the icky call to step() from aoe.c to ata.c; this takes it at
least one step further away from where it really doesn't belong.

Unfortunately, AoE has the ugly aoe_discover() mechanism which means
that we still have a step() loop in aoe.c for now; this needs to be
replaced at some future point.
2009-07-17 23:01:20 +01:00
Michael Brown acfd7cc609 [scsi] Improve SCSI debugging 2009-07-17 23:00:46 +01:00
Michael Brown 1d8d8ef2c8 [scsi] Make SCSI command issuing partially asynchronous
Move the icky call to step() from iscsi.c to scsi.c; this takes it at
least one step further away from where it really doesn't belong.
2009-07-17 23:00:09 +01:00
Michael Brown 51172783e2 [debug] Use a delimiter to break up DBG_HD() output
Reading sixteen columns of hex digits can be difficult; include a "-"
character to split the output into two groups of eight columns.
2009-07-17 22:58:44 +01:00
Michael Brown b7e93a6a55 [xfer] Always nullify interface while sending close() message
Objects typically call xfer_close() as part of their response to a
close() message.  If the initiating object has already nullified the
xfer interface then this isn't a problem, but it can lead to
unexpected behaviour when the initiating object is aiming to reuse the
connection and so does not nullify the interface.

Fix by always temporarily nullifying the interface during xfer_close()
(as was already being done by xfer_vreopen() in order to work around
this specific problem).

Reported-by: infernix <infernix@infernix.net>
Tested-by: infernix <infernix@infernix.net>
2009-07-06 16:16:59 +01:00
Michael Brown 546cc62394 [pxe] Add startpxe and stoppxe commands
These commands can be used to activate or deactivate the PXE API (on a
specifiable network interface).

This is currently of limited use, since most image formats will call
shutdown() before booting the image, meaning that the underlying net
device gets shut down during remove_devices() anyway.
2009-06-28 20:50:23 +01:00
Michael Brown 76c915d5bd [ifmgmt] Move ifmgmt_cmd.h to include/hci 2009-06-28 20:28:38 +01:00
Michael Brown 6e564323e0 [ifmgmt] Optimise prototype for ifcommon_exec()
ifcommon_exec() was long-ago marked as __attribute__((regparm(2))) in
order to minimise the size of functions that call into it.  Since
then, gPXE has added -mregparm=3 as a general compilation option, and
this "optimisation" is now counter-productive.

Change (and simplify) the prototype to minimise code size given the
current compilation conditions.
2009-06-28 20:24:54 +01:00
Michael Brown ee1d315ac0 [pxe] Check for unhookable interrupts in PXENV_STOP_UNDI
PXENV_STOP_UNDI should return PXENV_STATUS_KEEP_UNDI if the UNDI
cannot be safely unloaded (e.g. due to interrupt vectors that could
not be unhooked).
2009-06-28 20:12:16 +01:00
Michael Brown 07b5be3341 [pxe] Create pxe_[de]activate() wrapper functions
Merge the pxe_set_netdev()+pxe_[un]hook_int1a() pattern into a single
pxe_[de]activate() call.
2009-06-28 20:11:32 +01:00
Michael Brown c2965b0fe7 [pxe] Make pxe_init_structures() an initialisation function
pxe_init_structures() fills in the fields of the !PXE and PXENV+
structures that aren't known until gPXE starts up.  Once gPXE is
started, these values will never change.

Make pxe_init_structures() an initialisation function so that PXE
users don't have to worry about calling it.
2009-06-28 19:40:16 +01:00
Michael Brown c26a38b313 [pxe] Update UNDI transmit count before transmitting packet
It is possible that the UNDI ISR may be triggered before netdev_tx()
returns control to pxenv_undi_transmit().  This means that
pxenv_undi_isr() may see a zero undi_tx_count, and so not check for TX
completions.  This is not a significant problem, since it will check
for TX completions on the next call to pxenv_undi_isr() anyway; it
just means that the NBP will see a spurious IRQ that was apparently
caused by nothing.

Fix by updating the undi_tx_count before calling netdev_tx(), so that
pxenv_undi_isr() can decrement it and report the TX completion.
2009-06-27 16:36:21 +01:00
Michael Brown f186ada2d3 [pxe] Implement PXENV_UNDI_{GET,SET}_MCAST_ADDRESS
Symantec Ghost requires working multicast support.  gPXE configures
all (sufficiently supported) network adapters into "receive all
multicasts" mode, which means that PXENV_UNDI_SET_MCAST_ADDRESS is
actually a no-op, but the current implementation returns
PXENV_STATUS_UNSUPPORTED instead.

Fix by making PXENV_UNDI_SET_MCAST_ADDRESS return success.  For good
measure, also implement PXENV_UNDI_GET_MCAST_ADDRESS, since the
relevant functionality is now exposed by the net device core.

Note that this will silently fail if the gPXE driver for the NIC being
used fails to configure the NIC in "receive all multicasts" mode.
2009-06-27 15:46:06 +01:00
Michael Brown 9580f9d5cd [pxe] Improve pxe_undi debug messages
The PXE debugging messages have remained pretty much unaltered since
Etherboot 5.4, and are now difficult to read in comparison to most of
the rest of gPXE.

Bring the pxe_undi debug messages up to normal gPXE standards.
2009-06-27 14:43:10 +01:00
Joshua Oreman 15ce2fb851 [hci] Expose ifcommon_exec() in a local header so wireless commands can use it
This keeps code size down, since the wireless interface management
commands have the same command-line interface and overall structure as
the wired commands.

Signed-off-by: Michael Brown <mcb30@etherboot.org>
2009-06-24 13:23:41 +01:00
Joshua Oreman 6254998327 [dhcp] Await link-up before starting DHCP
Modified-by: Michael Brown <mcb30@etherboot.org>
Signed-off-by: Michael Brown <mcb30@etherboot.org>
2009-06-24 13:18:31 +01:00
Joshua Oreman 4125216a2f [ifmgmt] Move link-up status messages from autoboot() to iflinkwait()
With the addition of link status codes, we can now display a detailed
error indication if iflinkwait() fails.

Putting the error output in iflinkwait avoids code duplication, and
gains symmetry with the other interface management routines; ifopen()
already prints an error directly if it cannot open its interface.

Modified-by: Michael Brown <mcb30@etherboot.org>
Signed-off-by: Michael Brown <mcb30@etherboot.org>
2009-06-24 13:15:27 +01:00
Michael Brown a310d00d37 [netdevice] Add mechanism for reporting detailed link status codes
Expand the NETDEV_LINK_UP bit into a link_rc status code field,
allowing specific reasons for link failure to be reported via
"ifstat".

Originally-authored-by: Joshua Oreman <oremanj@rwcr.net>
2009-06-24 13:04:36 +01:00
Daniel Verkamp cb9700ef6f [comboot] Implement INT 22h AX=000Bh (Get Serial Console Configuration)
Signed-off-by: Michael Brown <mcb30@etherboot.org>
2009-06-23 23:09:01 +01:00
Michael Brown 4fe1e08a60 [pxe] Fix interoperability with the Symantec (undipd) DOS UNDI driver
The Symantec UNDI DOS driver fails when run on top of gPXE because we
return our interface type as "gPXE" rather than one of the predefined
NDIS interface type strings.

Fix by returning the standard "DIX+802.3" string; this isn't
necessarily always accurate, but it's highly unlikely that anything
trying to use the UNDI API would understand our IPoIB link-layer
pseudo-header anyway.
2009-06-23 22:56:21 +01:00
Michael Brown 0b922595fe [pxe] Fix interoperability with the Intel DOS UNDI driver
The Intel DOS UNDI driver fails when run on top of gPXE because we do
not fill in the ServiceFlags field in PXENV_UNDI_GET_IFACE_INFO.

Fix by filling in the ServiceFlags field with reasonable values
indicating our approximate feature capabilities.
2009-06-23 22:42:55 +01:00
Michael Brown 4f881ae352 [pxe] Fix interoperability with the 3Com DOS UNDI driver
The 3Com DOS UNDI driver fails when run on top of gPXE for two
reasons: firstly because PXENV_UNDI_SET_PACKET_FILTER is unsupported,
and secondly because gPXE enters the NBP without enabling interrupts
on the NIC, and the 3Com driver never calls PXENV_UNDI_OPEN.

Fix by always returning success from PXENV_UNDI_SET_PACKET_FILTER
(which is no worse than the current situation, since we already ignore
the receive packet filter in PXENV_UNDI_OPEN), and by forcibly
enabling interrupts on the NIC within PXENV_UNDI_TRANSMIT.  The latter
is something of a hack, but avoids the need to implement a complete
base-code ISR that we would otherwise need if we were to enter the NBP
with interrupts enabled.
2009-06-23 21:54:50 +01:00
Michael Brown ded4d3a703 [rtl8139] Split debug messages into DBGLVL_LOG and DBGLVL_EXTRA 2009-06-23 20:41:44 +01:00
Michael Brown 198ae0a131 [undi] Include PXENV_GET_IFACE_INFO's ServiceFlags in debug output 2009-06-23 19:26:07 +01:00
Michael Brown 5e1ef98469 [e1000] Ensure descriptor is fully written before sending packet
Reported-by: Mark McLoughlin <markmc@redhat.com>
2009-06-23 18:36:01 +01:00
Michael Brown 58f60df66c [tcp] Avoid rewinding sequence numbers on receiving old duplicate ACKs
Commit 558c1a4 ("[tcp] Improve robustness in the presence of duplicated
received packets") introduced a regression in that an old duplicate
ACK received while in the ESTABLISHED state would pass through normal
ACK processing, including updating tcp->snd_seq.

Fix by ensuring that ACK processing ignores all duplicate ACKs.
2009-06-23 16:10:34 +01:00
Michael Brown 99e64f5806 [tcp] Attempt to catch all possible error cases with debug messages
All TCP errors or unusual events should now generate a debugging
message at DBGLVL_LOG, with enough information (SEQ and ACK numbers)
to be able to identify the corresponding packet (or missing packet) in
a network trace from the remote end.
2009-06-23 14:28:00 +01:00
Michael Brown f4605970f4 [tcp] Include current sequence numbers in "timer expired" messages 2009-06-23 14:03:09 +01:00
Michael Brown a2f753ba64 [tcp] Move high-frequency debug messages to DBGLVL_EXTRA
This makes it possible to leave TCP debugging enabled in order to see
interesting TCP events, without flooding the console with at least one
message per packet.
2009-06-23 13:35:45 +01:00
Joshua Oreman f8448735b0 [image] Modify imgfree command to accept an argument
This resolves potential difficulties occurring when more than one script
is used. Total cost: 88 bytes uncompressed.

Signed-off-by: Michael Brown <mcb30@etherboot.org>
2009-06-23 10:53:33 +01:00
Joshua Oreman 254bdc2a8e [netdevice] Adjust maximum link-layer header length for 802.11
Signed-off-by: Michael Brown <mcb30@etherboot.org>
2009-06-23 10:49:50 +01:00
Joshua Oreman eb3ca2a36f [netdevice] Add netdev argument to link-layer push and pull handlers
In order to construct outgoing link-layer frames or parse incoming
ones properly, some protocols (such as 802.11) need more state than is
available in the existing variables passed to the link-layer protocol
handlers. To remedy this, add struct net_device *netdev as the first
argument to each of these functions, so that more information can be
fetched from the link layer-private part of the network device.

Updated all three call sites (netdevice.c, efi_snp.c, pxe_undi.c) and
both implementations (ethernet.c, ipoib.c) of ll_protocol to use the
new argument.

Signed-off-by: Michael Brown <mcb30@etherboot.org>
2009-06-23 10:41:57 +01:00
Joshua Oreman 743ebc2f4b [nvs] Add init function for Atmel 93C66 EEPROM
The 93C66 is identical to the 93C56 in programming interface and
addressing, but twice as large in data storage (4096 bits). It's
used in some RTL8185 wireless cards.

Signed-off-by: Michael Brown <mcb30@etherboot.org>
2009-06-23 10:33:10 +01:00
Michael Brown 558c1a45fe [tcp] Improve robustness in the presence of duplicated received packets
gPXE responds to duplicated ACKs with an immediate retransmission,
which can lead to a sorceror's apprentice syndrome.  It also responds
to out-of-range (or old duplicate) ACKs with a RST, which can cause
valid connections to be dropped.

Fix the sorceror's apprentice syndrome by leaving the retransmission
timer running (and so inhibiting the immediate retransmission) when we
receive a potential duplicate ACK.  This seems to match the behaviour
of Linux observed via wireshark traces.

Fix the RST issue by sending RST only on out-of-range ACKs that occur
before the connection is fully established, as per RFC 793.

These problems were exposed during development of the 802.11 wireless
link layer; the 802.11 protocol has a failure mode that can easily
cause duplicated packets.  The fixes were tested in a controlled way
by faking large numbers of duplicated packets in the rtl8139 driver.

Originally-fixed-by: Joshua Oreman <oremanj@rwcr.net>
2009-06-23 09:40:26 +01:00
Shao Miller 68973f1c49 [settings] Fix setting_cmp() to handle nameless settings
setting_cmp() compares by option tag and then by name.  Empty names
will always match, which gives us a false positive.

Fix by explicitly checking for empty names.

Modified-by: Michael Brown <mcb30@etherboot.org>
Signed-off-by: Michael Brown <mcb30@etherboot.org>
2009-06-13 12:04:08 +01:00
Michael Brown edfbd4e4fa [netdevice] Fix incorrect value for MAX_LL_HEADER_LEN
MAX_LL_HEADER_LEN is erroneously set to 6 rather than 14, resulting
in possible data corruption whenever we send an ARP packet.

Fix value and add a comment explaining why MAX_LL_ADDR_LEN is greater
than MAX_LL_HEADER_LEN.

Reported-by: Joshua Oreman <oremanj@rwcr.net>
2009-06-05 01:07:27 +01:00
Michael Brown 4c5f00f879 [script] Allow for DOS-style line endings in scripts
Windows text editors such as Notepad tend to use CRLF line endings,
which breaks gPXE's signature detection for script images.  Since
scripts are usually very small, they end up falling back to being
detected as valid PXE executable images (since there are no signature
checks for PXE executables).  Executing text files as x86 machine code
tends not to work well.

Fix by allowing for any isspace() character to terminate the "#!gpxe"
signature, and by ensuring that CR characters get stripped during
command line parsing.

Suggested-by: Shao Miller <Shao.Miller@yrdsb.edu.on.ca>
2009-06-03 10:13:29 +01:00
Michael Brown 5e51aaccaa [misc] Remove long-obsolete header files dating from Etherboot 5.4 2009-06-03 10:09:28 +01:00
Michael Brown a5cd8d1772 [misc] Fix source files erroneously marked as executable 2009-06-02 11:26:09 +01:00
Michael Brown 92a9978b44 [spi] Add address-length autodetection to the SPI bit-bashing code
Several SPI chips will respond to an SPI read command with a dummy
zero bit immediately prior to the first real data bit.  This can be
used to autodetect the address length, provided that the command
length and data length are already known, and that the MISO data line
is tied high.

Tested-by: Thomas Miletich <thomas.miletich@gmail.com>
Debugged-by: Thomas Miletich <thomas.miletich@gmail.com>
2009-05-28 19:32:03 +01:00
Michael Brown 8afafb6532 [build] Add -fno-dwarf2-cfi-asm to CFLAGS if supported by the gcc in use
gcc 4.4 defaults to using .cfi assembler directives for debugging
information, which causes unneeded .eh_frame sections to be generated.
These sections are already stripped out by our linker script, so don't
affect the final build, but do distort the output of "size" when run
on individual .o files; the .eh_frame size is included within the size
reported for .text.  This makes it difficult to accurately judge the
effects of source code changes upon object code size.

Fix by adding -fno-dwarf2-cfi-asm to CFLAGS if we detect that this
option is supported by the gcc that we are compiling with.

Tested-by: Daniel Verkamp <daniel@drv.nu>
2009-05-27 02:30:46 +01:00
Daniel Verkamp e47869995f [comboot] Implement stub calls for auxiliary data vector handling
Signed-off-by: Michael Brown <mcb30@etherboot.org>
2009-05-26 11:43:02 +01:00
Daniel Verkamp 1f80b2dcd5 [ethernet] Add MII link status functions from Linux
Signed-off-by: Michael Brown <mcb30@etherboot.org>
2009-05-26 11:37:46 +01:00
Daniel Verkamp b8469eddaa [ethernet] Update mii.h and use it in drivers that had a private copy
Signed-off-by: Michael Brown <mcb30@etherboot.org>
2009-05-26 11:30:31 +01:00
Daniel Verkamp 005fce0258 [ethernet] Move struct mii_if_info to mii.h
Signed-off-by: Michael Brown <mcb30@etherboot.org>
2009-05-26 11:27:55 +01:00
Michael Brown 3c06277bbb [settings] Allow for arbitrarily-named settings
This provides a mechanism for using arbitrarily-named variables within
gPXE, using the existing syntax for settings.
2009-05-26 11:05:58 +01:00
Michael Brown 822b3b53f4 [multiboot] Include argv[0] as part of "command line"
Grub will include the module name as part of the command line, and
some multiboot kernels expect this to be done.
2009-05-26 06:58:53 +01:00
Michael Brown c345336435 [dhcp] Choose ProxyDHCP port based on presence of PXE options
If the ProxyDHCPOFFER already includes PXE options (i.e. option 60 is
set to "PXEClient" and option 43 is present) then assume that the
ProxyDHCPREQUEST can be sent to port 67, rather than port 4011.  This
is a reasonable assumption, since in that case the ProxyDHCP server
has already demonstrated by responding to the DHCPDISCOVER that it is
listening on port 67.  (If the ProxyDHCP server were not listening on
port 67, then the standard DHCP server would have been configured to
respond with option 60 set to "PXEClient" but no option 43 present.)

The PXE specification is ambiguous on this point; the specified
behaviour covers only the cases in which option 43 is *not* present in
the ProxyDHCPOFFER.  In these cases, we will continue to send the
ProxyDHCPREQUEST to port 4011.

This change is required in order to allow us to interoperate with
dnsmasq, which listens only on port 67.  (dnsmasq relies on
unspecified behaviour of the Intel PXE stack, which it seems will
retain the ProxyDHCPOFFER as an options source and never issue a
ProxyDHCPREQUEST, thereby enabling dnsmasq to omit listening on port
4011.)
2009-05-22 05:42:57 +01:00
Thomas Miletich f51d61371f [serial] Define constants for serial port I/O addresses
Tested with COM1 and COM2.

Signed-off-by: Michael Brown <mcb30@etherboot.org>
2009-05-21 10:04:12 +01:00
Michael Brown 1958974d0a [tftp] Process OACKs even if malformed
IBM Tivoli PXE Server 5.1.0.3 is reported to send trailing garbage
bytes at the end of the OACK packet, which causes gPXE to reject the
packet and abort the TFTP transfer.

Work around the problem by processing as much as possible of the OACK,
and treating name/value parsing errors as non-fatal.

Reported-by: Shao Miller <Shao.Miller@yrdsb.edu.on.ca>
2009-05-20 10:04:50 +01:00
Michael Brown c5a88ed553 [settings] Fix erroneous bit-masking in fetch_uintz_setting() 2009-05-20 08:55:48 +01:00
Michael Brown 3961c1ca02 [dhcp] Send broadcast PXE boot server discovery requests to port 67
We currently send all boot server discovery requests to port 4011.
Section 2.2.1 of the PXE spec states that boot server discovery
packets should be "sent broadcast (port 67), multicast (port 4011), or
unicast (port 4011)".  Adjust our behaviour so that any boot server
discovery packets that are sent to the broadcast address are directed
to port 67 rather than port 4011.

This is required for operation with dnsmasq as a PXE server, since
dnsmasq listens only on port 67, and relies upon this (specified)
behaviour.

This change may break some setups using the (itself very broken) Linux
PXE server from kano.org.uk.  This server will, in its default
configuration, listen only on port 4011.  It never constructs a boot
server list (PXE_BOOT_SERVERS, option 43.8), and uses the wrong
definitions for the discovery control bits (PXE_DISCOVERY_CONTROL,
option 43.6).  The upshot is that it will always instruct the client
to perform multicast and broadcast discovery only.  In setups lacking
a valid multicast route on the server side, this used to work because
gPXE would eventually give up on the (non-responsive) multicast
address and send a broadcast request to port 4011, which the Linux PXE
server would respond to.  Now that gPXE correctly sends this broadcast
request to port 67 instead, it is never seen by the Linux PXE server,
and the boot fails.  The fix is to either (a) set up a multicast route
correctly on the server side before starting the PXE server, or (b)
edit /etc/pxe.conf to contain the server's unicast address in the
"multicast_address" field (a hack that happens to work).

Suggested-by: Simon Kelley <simon@thekelleys.org.uk>
2009-05-20 08:47:39 +01:00
Michael Brown 9119b0c8af [dhcp] Perform ProxyDHCP only if we do not already have PXE options
This prevents gPXE from wasting time attempting to contact a ProxyDHCP
server on port 4011 if the DHCP response already contains the relevant
PXE options.  This behaviour is hinted at (though not explicitly
specified) in the PXE spec, and seems to match what the Intel client
does.

Suggested-by: Simon Kelley <simon@thekelleys.org.uk>
2009-05-20 07:56:29 +01:00
Michael Brown f4bf4e69f7 [legal] Add FILE_LICENCE declaration to romprefix.S 2009-05-18 09:33:36 +01:00
Michael Brown c44a193d0d [legal] Add a selection of FILE_LICENCE declarations
Add FILE_LICENCE declarations to almost all files that make up the
various standard builds of gPXE.
2009-05-18 08:33:25 +01:00
Michael Brown 41307f2874 [legal] Add licence.pl and %.licence make target
It is now possible to run e.g.

  make bin/rtl8139.dsk.licence

in order to see a licensing assessment for any given gPXE build.  The
assessment will either produce a single overall licence for the build
(based on combining all the licences used within the source files for
that build), or will exit with an error stating why a licence
assessment is not possible (for example, if there are files involved
that do not yet contain an explicit FILE_LICENCE() declaration).
2009-05-18 08:29:24 +01:00
Michael Brown a525fb7782 [legal] Add mechanism for explicit per-file licence declarations
For partly historical reasons, various files in the gPXE source tree
are licensed under different, though compatible, terms.  Most of the
code is licensed under GPLv2 with the "or later" clause, but there are
exceptions such as:

  The string.h file, which derives from Linux and is licensed as
  Public Domain.

  The EFI header files, which are taken from the EDK2 source tree and
  are licensed under BSD.

  The 3c90x driver, which has a custom GPL-like licence text.

Introduce a FILE_LICENCE() macro to make licensing more explicit.
This macro should be applied exactly once to each source (.c, .S or
.h) file.  It will cause a corresponding zero-sized common symbol to
be added to any .o files generated from that source file (and hence to
any final gPXE binaries generated from that source file).  Determining
the applicable licences to generated files can then be done using e.g.

  $ objdump -t bin/process.o | grep __licence
  00000000       O *COM*  00000001 .hidden __licence_gpl2_or_later

indicating that bin/process.o is covered entirely by the GPLv2
with the "or later" clause, or

  $ objdump -t bin/rtl8139.dsk.tmp | grep __licence
  00033e8c g     O .bss.textdata  00000000 .hidden __licence_gpl2_only
  00033e8c g     O .bss.textdata  00000000 .hidden __licence_gpl2_or_later
  00033e8c g     O .bss.textdata  00000000 .hidden __licence_public_domain

indicating that bin/rtl8139.dsk includes both code licensed under
GPLv2 (both with and without the "or later" clause) and code licensed
as Public Domain.

Determining the result of licence combinations is currently left as an
exercise for the reader.
2009-05-18 08:26:08 +01:00
Michael Brown a13fc96cb3 [legacy] Remove long-obsolete old dhcp.h file 2009-05-18 08:24:45 +01:00
Michael Brown 4188d51753 [pxeprefix] Work around bug in Etherboot 5.4 when loading undionly.kpxe
Etherboot 5.4 erroneously treats PXENV_UNLOAD_STACK as the "final
shutdown" call, and unhooks INT15.  When using gPXE's undionly.kpxe,
this results in gPXE overwriting the portion of Etherboot located in
high memory, because it is no longer hidden from the system memory map
at the time that gPXE loads.

Work around this by explicitly testing for Etherboot as the underlying
PXE stack (as is already done in undinet.c) and skipping the call to
PXENV_UNLOAD_STACK if necessary.
2009-04-30 04:48:28 +01:00
Michael Brown 7c47ebd65c [build] Add {PROVIDE,REQUIRE}_SYMBOL macros and tidy up compiler.h 2009-04-27 14:04:35 +01:00
Michael Brown 6e764282dd [i386] Remove long-obsolete realmode.c file 2009-04-26 06:41:54 +01:00
Michael Brown bb06fc17cc [i386] Remove long-obsolete callbacks_arch.h file 2009-04-26 06:38:36 +01:00
Stefan Hajnoczi 9b964dec36 [build] Fix signed/unsigned division in util/zbin.c
Commit b149a99 ([build] Round up SUBx deltas) introduced a
signed/unsigned issue that affects gPXE images built on 32-bit hosts.
The zbin fixup utility performed an unsigned division, which led to
.usb images with an incorrect number of sectors to load.

The issue snuck by on 64-bit hosts since uint32_t is promoted to long.
On 32-bit hosts it is promoted to unsigned long.

Modified-by: Michael Brown <mcb30@etherboot.org>
Signed-off-by: Michael Brown <mcb30@etherboot.org>
2009-04-26 05:48:15 +01:00
Michael Brown 4b8e021161 [elf] Work around entry point bug in NetBSD kernels
NetBSD kernels are multiboot ELF kernels with an entry point
incorrectly specified as a virtual address rather than a physical
address.

Work around this by looking for the segment that could plausibly
contain the entry point address (interpreted as either a physical or
virtual address), and using that to determine the eventual physical
entry point.

In the event of any ambiguity, precedence is given to interpretation
of the entry point as a physical address.
2009-04-24 03:42:34 +01:00
Michael Brown e960fac8d0 [multiboot] Work around raw-flag bug in Solaris kernels
Solaris kernels are multiboot images with the "raw" flag set,
indicating that the loader should use the raw address fields within
the multiboot header rather than looking for an ELF header.  However,
the Solaris kernel contains garbage data in the raw address fields,
and requires us to use the ELF header instead.

Work around this by always using the ELF header if present.  This
renders the "raw" flag somewhat redundant.
2009-04-24 03:19:47 +01:00
Michael Brown ad027e41e5 [doc] Remove obsolete README.pixify 2009-04-18 17:10:00 +01:00
Michael Brown a1eb4ffdf7 [build] Automatically sort the list of constituent object sizes 2009-04-18 16:20:03 +01:00
Michael Brown ead44dba89 [build] Provide mechanism for listing constituent object sizes
You can now type e.g.

  make bin/rtl8139.rom.sizes

in order to see the (uncompressed) sizes of all of the object files
linked in to bin/rtl8139.rom.  This should make it easier to identify
relevant code bloat.
2009-04-18 15:56:29 +01:00
Michael Brown 3d6b8a67f2 [build] Remove obsolete linker script files 2009-04-17 14:09:14 +01:00
Michael Brown f721067d35 [build] Kill off the multiple-object-per-source-file mechanism
Now that there are no remaining multiple-object source files, kill off
the mechanism in order to simplify the Makefile.
2009-04-17 13:43:35 +01:00
Michael Brown a63ef9207d [build] Kill off the last multiple-object source file
The build mechanism currently allows for multiple objects per source
file.  The only remaining user of this is unnrv2b.S.  Replace this
usage with a separate unnrv2b16.S wrapper file, as is currently used
for e.g. pxeprefix.S and kpxeprefix.S.
2009-04-17 13:38:18 +01:00
Michael Brown f79608b376 [build] Provide mechanism for listing per-target source files
You can now type e.g.

  make bin/rtl8139.rom.deps

to see a list of the source files included in the build of
bin/rtl8139.rom.  This is intended to assist with copyright vetting.

Other new debugging targets include

  make bin/rtl8139.rom.objs

to see a list of object files linked in to bin/rtl8139.rom, and

  make bin/rtl8139.rom.nodeps

to see a list of the source files that are *not* required for the
build of bin/rtl8139.rom.
2009-04-17 12:38:44 +01:00
Michael Brown b4a87daeb9 [build] Simplify use of Getopt::Long in padimg.pl
Sometimes it's just so much fun doing things the complicated way that
you forget to check the man page for the existence of a simpler
syntax.
2009-04-16 06:13:09 +01:00
Michael Brown 7aee624881 [build] Reinstate the .pdsk padded-floppy image format
Some utilities that expect a floppy disk image (e.g. iLO?) may test
for a file of the correct size.  Reinstate the .pdsk image format in
order to provide this if needed.
2009-04-16 06:01:07 +01:00
Michael Brown 7741546a40 [build] Pad .rom, .dsk, and .hd images to 512-byte boundaries
QEMU will silently round down a disk or ROM image file to the nearest
512 bytes.  Fix by always padding .rom, .dsk and .hd images to the
nearest 512-byte boundary.

Originally-fixed-by: Stefan Hajnoczi <stefanha@gmail.com>
2009-04-16 03:15:08 +01:00
Michael Brown b363d19a16 [dhcp] Accept filename via DHCP option 67 as well as BOOTP filename field
Allow options with dedicated BOOTP fields to fall back to using the
equivalent DHCP option if the relevant field is empty.
2009-04-15 21:08:02 +01:00
Timothy Stack cc4363acca [smbios] Add asset tag setting
Add SMBIOS asset tag as a named setting.

Signed-off-by: Michael Brown <mcb30@etherboot.org>
2009-04-15 17:23:18 +01:00
Stefan Hajnoczi 38a1d0fe3f [gdb] Allow resynchronisation with gdb
This replaces the gdbstub's polite NAK behavior with retransmission of
the current outstanding reply packet.  It solves situations where gdb
and gPXE's gdbstub get out of sync due to the lack of flow control in
the gdb protocol spec.

Signed-off-by: Michael Brown <mcb30@etherboot.org>
2009-04-15 17:18:14 +01:00
Stefan Hajnoczi b149a99302 [build] Round up SUBx deltas
The zbin compressor fixup utility rounds down file sizes before
calculating their difference.  This produces incorrect values and may
cause truncated gPXE images to be loaded at boot.

The following example explains the problem:
ilen    = 48 bytes     (uncompressed input file)
olen    = 17 bytes     (compressed output file)
divisor = 16 bytes     (paragraph granularity)
fixmeup = 3 paragraphs (value to fix up)

olen / divisor - ilen / divisor
= 1 - 3
= -2 paragraphs  (old delta calculation)

( align ( olen, divisor ) - align ( ilen, divisor ) ) / divisor
= 2 - 3
= -1 paragraphs  (new delta calculation)

If we perform the SUBx operation with old delta:
fixmeup + -2 = 1 paragraph gets loaded by the prefix

With the new delta:
fixmeup + -1 = 2 paragraphs get loaded by the prefix

The old delta calculation removes the last paragraph; the prefix will
load a truncated copy of gPXE into memory.  We need to load 2
paragraphs since olen is 17 bytes.  Loading only 1 paragraph (16
bytes) would truncate the last byte.

Signed-off-by: Michael Brown <mcb30@etherboot.org>
2009-04-15 16:14:47 +01:00
H. Peter Anvin f44205b9ea [pcbios] Don't use "lret $2" to return from an interrupt
Using "lret $2" to return from an interrupt causes interrupts to be
disabled in the calling program, since the INT instruction will have
disabled interrupts.  Instead, patch CF on the stack and use iret to
return.

Interestingly, the original PC BIOS had this bug in at least one
place.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: Michael Brown <mcb30@etherboot.org>
2009-04-15 15:45:27 +01:00
Michael Brown dc387547a3 [build] Don't assume the existence of "seq"
The "seq" command is GNU-specific; a BSD userland will not have it.
Use POSIX-conforming "awk" instead.

Reported-by: Joshua Oreman <oremanj@rwcr.net>
Suggested-by: Stefan Hajnoczi <stefanha@gmail.com>
2009-03-31 11:06:35 +01:00
Michael Brown 3dd7ce1c26 [efi] Allow building with non-system libbfd
On Mac OS X, it is necessary to build binutils manually; the system
does not provide bfd.h or the libbfd or libiberty libraries.

Originally-fixed-by: Joshua Oreman <oremanj@rwcr.net>
2009-03-31 09:36:08 +01:00
Michael Brown 7266aceb39 [efi] Fix compilation on Mac OS X.
The Mac compiler treats "#pragma pack()" as gcc's "#pragma pack(pop)",
and so dies if the pragma pack stack is empty.  Adding a "#pragma
pack(1)" immediately beforehand is enough to keep the Mac compiler
happy.

The combination of "#pragma pack(1)", "#pragma pack()" won't actually
achieve anything on a Mac, but it will at least build.  (With gcc, the
"#pragma pack()" overrides any previous pragmas, so is still useful.)

Suggested-by: Joshua Oreman <oremanj@rwcr.net>
2009-03-31 07:39:20 +01:00
Joshua Oreman 820b11dc0a [build] Use __SIZE_TYPE__ macro in definition of size_t
This is required in order to build on Mac OS X.

Modified-by: Michael Brown <mcb30@etherboot.org>
Signed-off-by: Michael Brown <mcb30@etherboot.org>
2009-03-31 07:21:07 +01:00
Joshua Oreman 210bc9e9ba [3c90x] Add missing size_t format specifier
Signed-off-by: Michael Brown <mcb30@etherboot.org>
2009-03-31 07:10:40 +01:00
Michael Brown bbd274a1d6 [efi] Use POSIX version of basename() in elf2efi.c
This is required in order to build on Mac OS X.

Suggested-by: Joshua Oreman <oremanj@rwcr.net>
2009-03-31 07:07:44 +01:00
Michael Brown e3b9e3d04b [build] Add --divide to ASFLAGS if supported by the assembler
Some builds of the GNU assembler will treat a '/' character as a
comment delimiter.  Adding "--divide" will cause it to be treated as a
division operator, as we expect.  The "--divide" option is not
available in all gas versions, so apply it only conditionally.

Suggested-by: Joshua Oreman <oremanj@rwcr.net>
2009-03-31 07:02:17 +01:00
Michael Brown b0c818d7b5 [int13] Improve debugging messages 2009-03-31 06:26:51 +01:00
Michael Brown f7d2168c8e [segment] Add "Requested memory not available" error message
prep_segment() can sometimes fail because an image requests memory
that is already in use by gPXE.  This will happen if
e.g. undionly.kpxe is used to boot memtest86; the memtest86 image is
an old-format kernel that needs to be loaded at 9000:0000, but this
area of memory may well already be in use by the underlying PXE stack.

Add a human-friendly error message, so that the cause is more
immediately visible.
2009-03-31 04:38:48 +01:00
Michael Brown edea441ad5 [resolv] Simplify xfer_redirect() logic
Now that we have xfer_vreopen() as the default .vredirect handler,
sending redirection events can become simpler.
2009-03-30 15:23:57 +01:00
Michael Brown 272e6ddc30 [http] Support HTTP redirection 2009-03-30 13:28:33 +01:00
Michael Brown 323cdf8c4c [xfer] Implement xfer_vreopen() to properly handle redirections
When handling a redirection event, we need to close the existing
connection before opening the new connection.
2009-03-30 13:24:56 +01:00
Michael Brown abc13af070 [bzimage] Support old (pre-2.00 bootloader) Linux kernel formats
This allows gPXE to load memtest86, which is packaged as an old kernel.

Split all code that directly touches the kernel headers out into
bzimage_parse_header() and bzimage_update_header(), to reduce code
size and offset the cost of supporting older kernels.

Total cost of this feature: 11 bytes (uncompressed).
2009-03-30 11:42:19 +01:00
Michael Brown a436dc4014 [build] Avoid always rebuilding bin/embedded.o
bin/embedded.o has a build dependency on bin/.embedded.list, which
gets generated automatically by the Makefile.  However, if the
EMBEDDED_IMAGE list is empty, bin/.embedded.list will never be
created, and so bin/embedded.o will be rebuilt every time due to a
missing dependency.

Fix by forcing bin/.embedded.list to be created even if the list is
empty.
2009-03-27 04:47:20 +00:00
Daniel Verkamp a323a85d9b [digest] md5sum and sha1sum commands
Modified-by: Michael Brown <mcb30@etherboot.org>
Signed-off-by: Michael Brown <mcb30@etherboot.org>
2009-03-27 04:29:54 +00:00
Michael Brown f3335b83d4 [netdevice] Add debug message for unknown network-layer protocols
Suggested-by: Bill Lortz <Bill.Lortz@premier.org>
2009-03-26 16:14:24 +00:00
Michael Brown 5538a38b9c [pcnet32] Fix received packet corruption
The pcnet32 driver mismanages its RX buffers, with the result that
packets get corrupted if more than one packet arrives between calls to
poll().

Originally-fixed-by: Bill Lortz <Bill.Lortz@premier.org>
Reviewed-by: Stefan Hajnoczi <stefanha@gmail.com>
Tested-by: Stefan Hajnoczi <stefanha@gmail.com>
2009-03-26 15:44:59 +00:00
Thomas Miletich 03ff8cd3e2 [forcedeth] Add support for newer forcedeth NICs
Also adds the MAC_ADDR_CORRECT flag, to indicate whether or not the
MAC address needs to be fixed up by the driver.

Signed-off-by: Michael Brown <mcb30@etherboot.org>
2009-03-26 10:26:55 +00:00
Thomas Miletich 3da6f1c7bd [pci] Add driver_data field to struct pci_device_id
Modified-by: Michael Brown <mcb30@etherboot.org>
Signed-off-by: Michael Brown <mcb30@etherboot.org>
2009-03-26 10:22:15 +00:00
Shao Miller 87b494bbab [time] Add the sleep command
Reviewed-by: Stefan Hajnoczi <stefanha@gmail.com>
Reviewed-by: Thomas Miletich <thomas.miletich@gmail.com>
Modified-by: Michael Brown <mcb30@etherboot.org>
Signed-off-by: Michael Brown <mcb30@etherboot.org>
2009-03-26 10:06:04 +00:00
Michael Brown 5bd32315d0 [settings] Fix broken assertion in fetch_string_setting_copy()
Reported-by: Stefan Hajnoczi <stefanha@gmail.com>
2009-03-26 09:50:52 +00:00
Michael Brown 1c67623e37 [build] Enable building with the Intel C compiler (icc) 2009-03-26 07:27:19 +00:00
Marty Connor 16aa435567 [3c90x] Remove src/drivers/3c90x.txt
Most of the 3c90x.txt file is obsolete.  The content from the file has
been placed here:

   http://etherboot.org/wiki/appnotes/3c90x_issues
2009-03-13 12:05:12 -04:00
Thomas Miletich 90c01ef1e4 [3c90x] 3c90x driver rewrite using gPXE API
This is a major rewrite of the legacy etherboot 3c90x driver using the
gPXE API for much improved performance over the legacy driver it
replaces.

This driver has been tested on 3c905, 3c905B, and 3c905C cards.

Reviewed-by: Stefan Hajnoczi <stefanha@gmail.com>
Reviewed-by: Marty Connor <mdc@etherboot.org>
Tested-by: Marty Connor <mdc@etherboot.org>
Tested-by: Daniel Verkamp <daniel@drv.nu>

Signed-off-by: Marty Connor <mdc@etherboot.org>
2009-03-13 11:54:39 -04:00
Michael Brown 3c68ff99ea [tables] Incorporate table data type information into table definition
Eliminate the potential for mismatches between table names and the
table entry data type by incorporating the data type into the
definition of the table, rather than specifying it explicitly in each
table accessor method.
2009-03-13 02:10:21 +00:00
Michael Brown 1266d7902b [tables] Redefine methods for accessing linker tables
Intel's C compiler (icc) chokes on the zero-length arrays that we
currently use as part of the mechanism for accessing linker table
entries.  Abstract away the zero-length arrays, to make a port to icc
easier.

Introduce macros such as for_each_table_entry() to simplify the common
case of iterating over all entries in a linker table.

Represent table names as #defined string constants rather than
unquoted literals; this avoids visual confusion between table names
and C variable or type names, and also allows us to force a
compilation error in the event of incorrect table names.
2009-03-13 02:06:30 +00:00
Michael Brown 3ed468e0c5 [tcp] Avoid setting PSH flag when SYN flag is set
Some firewall devices seem to regard SYN,PSH as an invalid flag
combination and reject the packet.  Fix by setting PSH only if SYN is
not set.

Reported-by: DSE Incorporated <dseinc@gmail.com>
2009-03-10 08:15:47 +00:00
Daniel Verkamp 4397a2a4ca [time] Add the time command
Signed-off-by: Michael Brown <mcb30@etherboot.org>
2009-03-06 15:02:41 +00:00
H. Peter Anvin f3d09b5c79 [pxeprefix] Merge common code between !PXE and PXENV+
The parsing of the !PXE and PXENV+ structures share a fair bit of
code; merge the common code to save a few bytes.

Signed-off-by: Michael Brown <mcb30@etherboot.org>
2009-03-06 14:51:50 +00:00
Michael Brown ec24672db7 [settings] Allow for autovivification of settings blocks
Allow for settings blocks to be created on demand.  This allows for
constructions such as

  set defaults/filename http://bootserver/bootfile
  set defaults/priority 0xff
  dhcp net0
  chain ${filename}

which will boot from the DHCP-provided filename, or from
"http://bootserver/bootfile" if the DHCP server does not provide a
filename.

(Note that "priority" gets interpreted as a signed integer, so setting
"defaults/priority" to 0xff will cause the "defaults" settings block
to have an effective priority of -1.)
2009-03-06 14:40:44 +00:00
Michael Brown f95c919741 [release] Update version to 0.9.7+ post release 2009-03-02 02:29:20 +00:00
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
Marty Connor 74b7bc0954 [release] Update version to 0.9.6 for release 2008-11-23 16:44:45 -05:00
Pantelis Koukousoulas 7166bc7b2d [b44] Add driver for Broadcom bcm44xx cards
This driver is based on Stefan Hajnoczi's summer work, which
is in turn based on version 1.01 of the linux b44 driver.
I just assembled the pieces and fixed/added a few pieces
here and there to make it work for my hardware.

The most major limitation is that this driver won't work
on systems with >1GB RAM due to the card not having enough
address bits for that and gPXE not working around this
limitation.

Still, other than that the driver works well enough for
at least 2 users :) and the above limitation can always
be fixed when somebody wants it bad enough :)

Signed-off-by: Pantelis Koukousoulas <pktoss@gmail.com>
2008-11-21 23:22:50 +00:00
Michael Brown e78bcb6175 [netdevice] Kill off the various guess_boot_netdev() functions
Remove the assortment of miscellaneous hacks to guess the "network
boot device", and replace them each with a call to last_opened_netdev().

It still isn't guaranteed correct, but it won't be any worse than
before, and it will at least be consistent.
2008-11-21 20:34:42 +00:00
Michael Brown 02a0215873 [netdevice] Provide function to retrieve the most recently opened net device
There are currently four places within the codebase that use a
heuristic to guess the "boot network device", with varying degrees of
success.  Add a feature to the net device core to maintain a list of
open network devices, in order of opening, and provide a function
last_opened_netdev() to retrieve the most recently opened net device.
This should do a better job than the current assortment of
guess_boot_netdev() functions.
2008-11-21 20:34:02 +00:00
Michael Brown 8e8a348fd4 [pxe] Select the correct network device on multiport cards
When trying to find the "first open network device", it helps to
actually check the NETDEV_OPEN flag.
2008-11-21 19:45:05 +00:00
Michael Brown 246ddf5ee4 [aoe] Use an AoE config query to identify the target MAC address
The AoE spec does not specify that the source MAC address of a
received packet actually matches the MAC address of the AoE target.
In principle an AoE server can respond to an AoE request on any
interface available to it, which may not be an address configured to
accept AoE requests.

This issue is resolved by implementing AoE device discovery.  The
purpose of AoE discovery is to find out which addresses an AoE target
can use for requests.  An AoE configuration command is sent when the
AoE attach is attempted.  The AoE target must respond to that
configuration query from an interface that can accept requests.

Based on a patch from Ryan Thomas <ryan@coraid.com>
2008-11-19 21:42:33 +00:00
Laurent Vivier a2686a55c4 [blockdev] Move block device operations to structure block_device_operations
Signed-off-by: Laurent Vivier <Laurent.Vivier@bull.net>
2008-11-19 20:04:43 +00:00
Laurent Vivier b48f37e69a [virtio] Split virtio-net.c into several files.
Signed-off-by: Laurent Vivier <Laurent.Vivier@bull.net>
2008-11-19 19:58:51 +00:00
Laurent Vivier 14a739ba6a [virtio] Consolidate virtio-net static data into a struct vring_virtqueue
Signed-off-by: Laurent Vivier <Laurent.Vivier@bull.net>
2008-11-19 19:55:54 +00:00
Laurent Vivier d3d8f20626 [virtio] Remove dependency on nic for virtio PCI functions
Signed-off-by: Laurent Vivier <Laurent.Vivier@bull.net>
2008-11-19 19:51:38 +00:00
Laurent Vivier fc49421c7e [virtio] Consolidate vring_get_buf() by using a buffer list to add to the vring
Signed-off-by: Laurent Vivier <Laurent.Vivier@bull.net>
2008-11-19 19:50:51 +00:00
Laurent Vivier 5dd5107976 [virtio] Move virtio-pci.h and virtio-ring.h to include/gpxe
Signed-off-by: Laurent Vivier <Laurent.Vivier@bull.net>
2008-11-19 19:48:30 +00:00
Michael Brown 0ebbbb95fa [x86_64] Fix assorted 64-bit compilation errors and warnings
Remove various 32-bit assumptions scattered throughout the codebase.
The code is still not necessarily 64-bit clean, but will at least
compile.
2008-11-19 19:33:05 +00:00
Michael Brown 7d36a1b7b0 [build] Explicitly link efilink against -liberty
On some systems, libbfd is supplied only as a static library; linking
will fail unless -liberty is also specified.
2008-11-19 19:24:48 +00:00
Michael Brown 3f85626fa9 [efi] Add efi_strerror()
EFI_STATUS is defined as an INTN, which maps to UINT32 (i.e. unsigned
int) on i386 and UINT64 (i.e. unsigned long) on x86_64.  This would
require a cast each time the error status is printed.

Add efi_strerror() to avoid this ickiness and simultaneously enable
prettier reporting of EFI status codes.
2008-11-19 19:22:49 +00:00
Michael Brown d9b3d09910 [i386] Move iSCSI and AoE boot code to arch/i386/interface/pcbios 2008-11-19 19:20:45 +00:00
Michael Brown b59e0cc56e [i386] Change [u]int32_t to [unsigned] int, rather than [unsigned] long
This brings us in to line with Linux definitions, and also simplifies
adding x86_64 support since both platforms have 2-byte shorts, 4-byte
ints and 8-byte long longs.
2008-11-19 19:15:44 +00:00
Michael Brown 849e4b12d6 [libgcc] Make __libgcc architecture-specific 2008-11-19 19:14:24 +00:00
Michael Brown dc60c24146 [i386] Rename __cdecl to __asmcall
__cdecl is a misleading name, since it currently encapsulates both
cdecl and regparm(0) attributes.  Rename to __asmcall.
2008-11-19 19:12:53 +00:00
Michael Brown 446b6d5fdd [pxe] Move all PXE files to arch/i386
The initial PXE implementation in Etherboot had the goal of being
architecture-agnostic, but this goal has not been realised.
2008-11-18 22:27:02 +00:00
Michael Brown fca2dcabb8 [elf] Kill off unused <bits/elf.h> and <bits/elf_x.h> header files 2008-11-18 22:16:15 +00:00
Michael Brown ab96932ab3 [efi] Update to latest UEFI headers 2008-11-18 21:54:51 +00:00
Michael Brown 0a8a17e669 [i386] Free allocated base memory on exit, if possible
Code paths that automatically allocate memory from the FBMS at 40:13
should also free it, if possible.

Freeing this memory will not be possible if either

  1. The FBMS has been modified since our allocation, or

  2. We have not been able to unhook one or more BIOS interrupt vectors.
2008-11-18 19:43:13 +00:00
Marty Connor 85f82f09e9 [r8169] New rtl8169 family driver
This is a completely rewritten version of the rtl8169 family driver
using the gPXE driver API.
2008-11-18 04:04:07 +00:00
Michael Brown cc93556725 [build] Fix calculation of _filesz
_filesz was incorrectly forced to be aligned up to MAX_ALIGN.  In a
non-compressed build, this would cause a build failure unless _filesz
happened to already be aligned to MAX_ALIGN.
2008-11-17 19:58:02 -08:00
Michael Brown c661945e82 [build] Discard junk sections created by newer gcc versions 2008-11-18 03:46:27 +00:00
Michael Brown 54fbd11221 [build] Keep gcc 4.4 happy
gcc 4.4 adds another few warnings, and also seems to complain if we
place %ebp in the clobber list for any inline asm.
2008-11-18 01:52:40 +00:00
Michael Brown 464bf35cc0 [linda] Add missing copyright notices 2008-11-18 00:14:10 +00:00
Michael Brown 8a80e7ace1 [linda] Purge references to 8051 2008-11-17 23:55:43 +00:00
Michael Brown 1b3edd9e11 [infiniband] Respect hop pointer when building directed route SMP return path
The return path in directed route SMPs lists the egress ports in order
from SM to node, rather than from node to SM.

To write to the correct offset within the return path, we need to
parse the hop pointer.  This is held within the class-specific data
portion of the MAD header, which was previously unused by us and
defined to be a uint16_t.  Define this field to be a union type; this
requires some rearrangement of ib_mad.h and corresponding changes to
ipoib.c.
2008-11-12 15:35:45 +00:00
Michael Brown 2ca2607b1b [romprefix] Use smaller PMM allocations if possible
The only way that PMM allows us to request a block in a region with
A20=0 is to ask for a block with an alignment of 2MB.  Due to the PMM
API design, the only way we can do this is to ask for a block with a
size of 2MB.

Unfortunately, some BIOSes will hit problems if we allocate a 2MB
block.  In particular, it may not be possible to enter the BIOS setup
screen; the BIOS setup code attempts a PMM allocation, fails, and
hangs the machine.

We now try allocating only as much as we need via PMM.  If the
allocated block has A20=1, we free the allocated block, double the
allocation size, and try again.  Repeat until either we obtain a block
with A20=0 or allocation fails.  (This is guaranteed to terminate by
the time we reach an allocation size of 2MB.)
2008-11-11 20:00:13 +00:00
Michael Brown 125c6d66a8 [linda] Add support for QLogic 7220-based Infiniband HCAs
These cards very nearly support our current IB Verbs model.  There is
one minor difference: multicast packets will always be delivered by
the hardware to QP0, so the driver has to redirect them to the
appropriate QP.  This means that QP owners may see receive completions
for buffers that they never posted.  Nothing in our current codebase
will break because of this.
2008-11-11 05:58:47 +00:00
Michael Brown 9e5fd8ec59 [infiniband] Add raw packet parser and constructor
This can be used with cards that require the driver to construct and
parse packet headers manually.  Headers are optionally handled
out-of-line from the packet payload, since some such cards will split
received headers into a separate ring buffer.
2008-11-11 05:31:19 +00:00
Michael Brown c0ec00f47f [infiniband] Add a standalone subnet management agent
This generic SMA code can be used for any cards that do not provide
firmware-based embedded SMAs.
2008-11-11 05:31:18 +00:00
Michael Brown 9a35830d1f [ipoib] Kill off the IPoIB pseudo-header
Some Infiniband cards will not be as accommodating as the Arbel and
Hermon cards in providing enough space for us to push a fake extra
header at the start of the received packet.  We must therefore make do
with squeezing enough information to identify source and destination
addresses into the two bytes of padding within a genuine IPoIB
link-layer header.
2008-11-11 05:31:08 +00:00
Michael Brown 663904a7bc [infiniband] Split subnet management agent client out into ib_smc.c
Not all Infiniband cards have embedded subnet management agents.
Split out the code that communicates with such an embedded SMA into a
separate ib_smc.c file, and have drivers call ib_smc_update()
explicitly when they suspect that the answers given by the embedded
SMA may have changed.
2008-11-11 05:31:07 +00:00
Michael Brown 830e19eb54 [infiniband] Pass address vector in receive completions
Receive completion handlers now get passed an address vector
containing the information extracted from the packet headers
(including the GRH, if present), and only the payload remains in the
I/O buffer.

This breaks the symmetry between transmit and receive completions, so
remove the ib_completer_t type and use an ib_completion_queue_operations
structure instead.

Rename the "destination QPN" and "destination LID" fields in struct
ib_address_vector to reflect its new dual usage.

Since the ib_completion structure now contains only an IB status code,
("syndrome") replace it with a generic gPXE integer status code.
2008-11-11 05:31:07 +00:00
Michael Brown 0de5f7af6d [infiniband] Maintain queue fill level as a property of a work queue
Both queue owners and drivers often need to keep track of the fill
level, so let's make it a generic property.
2008-11-11 05:31:06 +00:00
Michael Brown d9751edafa [infiniband] Flush uncompleted work queue entries at QP teardown
Avoid leaking I/O buffers in ib_destroy_qp() by completing any
outstanding work queue entries with a generic error code.  This
requires the completion handlers to be available to ib_destroy_qp(),
which is done by making them static configuration parameters of the CQ
(set by ib_create_cq()) rather than being provided on each call to
ib_poll_cq().

This mimics the functionality of netdev_{tx,rx}_flush().  The netdev
flush functions would previously have been catching any I/O buffers
leaked by the IPoIB data queue (though not by the IPoIB metadata
queue).
2008-11-11 05:31:06 +00:00
Pantelis Koukousoulas dd34500188 [ne2k_isa] Restore support for ne2k isa cards
Add the simplified ne2k_isa driver.  It is just a selective copy+paste
of the relevant parts from ns8390.c plus a little trivial hacking to
make it actually work.

It is true that the code is pretty ugly, but:
  a) ns8390.c is worse
  b) It is only 372 lines and no #ifdefs
  c) It works both in qemu/bochs and in real hardware
     and we all know it is easier to cleanup working code

Hope someone will find the time to rewrite this driver properly,
but until then at least for me this is an ok solution.

Signed-off-by: Pantelis Koukousoulas <pktoss@gmail.com>
2008-11-08 13:01:20 +00:00
Pantelis Koukousoulas 180d99fc22 [isa] Fix a small typo in isa.c.
With this patch ISA drivers actually get probed so they have a fair
chance of working now.

Signed-off-by: Pantelis Koukousoulas <pktoss@gmail.com>
2008-11-08 12:54:18 +00:00
Michael Brown 9a52ba0cfa [netdevice] Retain and report detailed error breakdowns
netdev_rx_err() and netdev_tx_complete_err() get passed the error
code, but currently use it only in debug messages.

Retain error numbers and frequencey counts for up to
NETDEV_MAX_UNIQUE_ERRORS (4) different errors for each of TX and RX.
This allows the "ifstat" command to report the reasons for TX/RX
errors in most cases, even in non-debug builds.
2008-11-08 05:30:30 +00:00
Michael Brown 46f43d8ea7 [phantom] Do not halt PEGs on driver shutdown
Halting the PEGs breaks platforms where there is sideband access to
the NIC (e.g. HP machines using iLO).  (We have to retain the
unhalting code because on some other platforms (e.g. IBM blades with
BOFM) the pre-PXE firmware must halt the PEGs to avoid issues with the
BIOS rereading via the expansion ROM BAR.)
2008-11-08 05:10:23 +00:00
Michael Brown 43aa69d7b3 [aoe] Start retry timer before potential temporary transmission failure
The retry timer needs to be running as soon as we know that we are
trying to transmit a command.  If transmission fails because of a
temporary error condition, then the timer will allow us to retry the
transmission later.
2008-11-08 04:36:42 +00:00
Michael Brown ed196a3ed2 [settings] Ensure fetch_string_setting() returns a NUL-terminated string
This fixes a regression introduced in commit 612f4e7:

  [settings] Avoid returning uninitialised data on error in fetch_xxx_setting()

in which the memset() was moved from fetch_string_setting() to
fetch_setting(), in order that it would be useful for non-string
setting types.  However, this neglects to take into account the fact
that fetch_string_setting() shrinks its buffer by one byte (to allow
for the NUL) before calling fetch_setting().

Restore the memset() in fetch_string_setting(), so that the
terminating NUL is guaranteed to actually be a NUL.
2008-11-07 03:48:29 +00:00
Michael Brown 29e6f9835e [i386] Add data32 prefixes to all lgdt/lidt instructions
With a 16-bit operand, lgdt/lidt will load only a 24-bit base address,
ignoring the high-order bits.  This meant that we could fail to fully
restore the GDT across a call into gPXE, if the GDT happened to be
located above the 16MB mark.

Not all of our lgdt/lidt instructions require a data32 prefix (for
example, reloading the real-mode IDT can never require a 32-bit base
address), but by adding them everywhere we will hopefully not forget
the necessary ones in future.
2008-11-07 03:48:25 +00:00
Michael Brown aa95744915 [phantom] Allow for PXE boot to be enabled/disabled on a per-port basis
This is something of an ugly hack to accommodate an OEM requirement.
The NIC has only one expansion ROM BAR, rather than one per port.  To
allow individual ports to be selectively enabled/disabled for PXE boot
(as required), we must therefore leave the expansion ROM always
enabled, and place the per-port enable/disable logic within the gPXE
driver.
2008-11-01 01:55:13 +00:00
Michael Brown 5e6b82104d [romprefix] Add vendor branding facilities and guidelines
Some hardware vendors have been known to remove all gPXE-related
branding from ROMs that they build.  While this is not prohibited by
the GPL, it is a little impolite.

Add a facility for adding branding messages via two #defines
(PRODUCT_NAME and PRODUCT_SHORT_NAME) in config/general.h.  This
should accommodate all known OEM-mandated branding requirements.
Vendors with branding requirements that cannot be satisfied by using
PRODUCT_NAME and/or PRODUCT_SHORT_NAME should contact us so that we
can extended this facility as necessary.
2008-10-31 19:10:28 +00:00
Michael Brown 32bc76f902 [phantom] Assume one net device per PCI function
The Phantom firmware selectively disables PCI functions based on the
board type, with the end result that we see one PCI function for each
network port.  This allows us to eliminate the code for reading from
flash and, more importantly, removes knowledge of the board type magic
number from the gPXE driver.
2008-10-31 01:55:58 +00:00
Michael Brown 467c4f77c3 [hacks] Improve the guess_boot_netdev() logic
This function is a major kludge, but can be made slightly more
accurate by ignoring net devices that aren't open.  Eventually it
needs to be removed entirely.
2008-10-31 01:51:26 +00:00
Michael Brown 0a6c66a830 [settings] Add the notion of a "tag magic" to numbered settings
Settings can be constructed using a dotted-decimal notation, to allow
for access to unnamed settings.  The default interpretation is as a
DHCP option number (with encapsulated options represented as
"<encapsulating option>.<encapsulated option>".

In several contexts (e.g. SMBIOS, Phantom CLP), it is useful to
interpret the dotted-decimal notation as referring to non-DHCP
options.  In this case, it becomes necessary for these contexts to
ignore standard DHCP options, otherwise we end up trying to, for
example, retrieve the boot filename from SMBIOS.

Allow settings blocks to specify a "tag magic".  When dotted-decimal
notation is used to construct a setting, the tag magic value of the
originating settings block will be ORed in to the tag number.
Store/fetch methods can then check for the magic number before
interpreting arbitrarily-numbered settings.
2008-10-30 21:47:14 +00:00
Michael Brown 621101c36a [romprefix] Further sanity checks for the PCI 3 runtime segment address
This extends the sanity checks on the runtime segment address provided
in %bx, first implemented in commit 5600955.

We now allow the ROM to be placed anywhere above a000:0000 (rather
than c000:0000, as before), since this is the region allowed by the
PCI 3 spec.  If the BIOS asks us to place the runtime image such that
it would overlap with the init-time image (which is explicitly
prohibited by the PCI 3 spec), then we assume that the BIOS is faulty
and ignore the provided runtime segment address.

Testing on a SuperMicro BIOS providing overlapping segment addresses
shows that ignoring the provided runtime segment address is safe to do
in these circumstances.
2008-10-29 01:16:52 +00:00
Michael Brown 1bc2adea9a [phantom] Add CLP settings interface
This interface provides access to firmware settings (e.g. MAC address)
that will apply to all drivers loaded for the duration of the current
system boot.
2008-10-28 18:49:58 +00:00
Michael Brown 664f4cf365 [phantom] Unhalt/halt all PEGs during driver startup/shutdown
A hardware bug means that reads through the expansion ROM BAR can
return corrupted data if the PEGs are running.  This breaks platforms
that re-read the expansion ROM after invoking gPXE code, such as IBM
blade servers.

Halt PEGs during driver shutdown, and unhalt PEGs during driver
startup if we detect that this is not the first startup since
power-on.
2008-10-28 18:47:44 +00:00
Michael Brown df033de24f [phantom] Add line count limit to phantom_dmesg()
The Phantom firmware debug logs can be extremely long, so add the
ability to restrict the output to the last N lines.
2008-10-28 18:47:00 +00:00
Michael Brown 7a4c129af7 [ioapi] Fix broken implementation of insX() in the x86 I/O API 2008-10-27 00:29:16 +00:00
Michael Brown 3fe6bede74 [uri] Avoid interpreting DOS-style path names as opaque URIs
A DOS-style full path name such as "C:\Program Files\tftpboot\nbp.0"
satisfies the syntax requirements for a URI with a scheme of "C" and
an opaque portion of "\Program Files\tftpboot\nbp.0".

Add a check in parse_uri() to ignore schemes that are apparently only
a single character long; this avoids interpreting DOS-style paths in
this way, and shouldn't affect any practical URI scheme.
2008-10-24 04:08:43 +01:00
Michael Brown d4c8273569 [phantom] Change register space abstraction to match other drivers
Most other Phantom drivers define a register space in terms of a 64M
virtual address space.  While this doesn't map in any meaningful way
to the actual addresses used on the latest cards, it makes maintenance
easier if we do the same.
2008-10-24 03:52:17 +01:00
Michael Brown bcc70d6b99 [pcbios] Guard against register corruption in INT 15,e820 implementations
Someone at Dell must have a full-time job designing ways to screw up
implementations of INT 15,e820.  This latest gem is courtesy of a Dell
Xanadu system, which arbitrarily decides to obliterate the contents of
%esi.

Preserve %esi, %edi and %ebp across calls to INT 15,e820, in case
someone tries a variation on this trick in future.
2008-10-23 04:20:45 +01:00
Michael Brown 612f4e7a99 [settings] Avoid returning uninitialised data on error in fetch_xxx_setting()
Callers (e.g. usr/autoboot.c) may not check the return values from
fetch_xxx_setting(), assuming that in error cases the returned setting
value will be "empty" (for some sensible value of "empty").

In particular, if the DHCP server did not specify a next-server
address, this would result in gPXE using uninitialised data for the
TFTP server IP address.
2008-10-22 22:07:13 +01:00
Michael Brown cbf9003d66 [tftp] Add EUNIQ_xx values to differentiate the many EINVAL errors 2008-10-21 23:00:13 +01:00
Michael Brown 85f09b5fc0 [tg3] Add PCI ID for BCM5786
Contributed by Steve Cayford <cayfo001@umn.edu>
2008-10-21 22:31:10 +01:00
Michael Brown 22979c511e [contrib] Add patch to enable writable ROM images in bochs
Some of the gPXE romprefix.S code attempts to write to the ROM image,
as allowed by the PCI spec.  We do gracefully handle the case of
read-only ROM images (for ISA ROMs and for normal bochs/qemu
operation), but it can be handy to be able to use bochs to debug the
code paths that depend on writable ROM images.
2008-10-21 20:49:10 +01:00
Michael Brown d9c38d14d6 [build] Fix building on FreeBSD
FreeBSD requires the object format to be specified as elf_i386_fbsd,
rather than elf_i386.

Based on a patch from Eygene Ryabinkin <rea-fbsd@codelabs.ru>
2008-10-17 18:24:04 +01:00
Michael Brown 5600955bdd [romprefix] Sanity-check the runtime segment address for PCI 3
Some PCI 3 BIOSes seem to provide a garbage value in %bx, which should
contain the runtime segment address.  Perform a basic sanity check: we
reject the segment if it is below the start of option ROM space.  If
the sanity check fails, we assume that the BIOS was not expecting us
to be a PCI 3 ROM, and we just leave our image in situ.
2008-10-17 18:12:24 +01:00
Michael Brown 7982e79d3c [build] Use ".bss.*" names for uninitialised-data sections
The section name seems to have significance for some versions of
binutils.

There is no way to instruct gcc that sections such as .bss16 contain
uninitialised data; it will emit them with contents explicitly set to
zero.  We therefore have to rely on the linker script to force these
sections to become uninitialised-data sections.  We do this by marking
them as NOLOAD; this seems to be the closest semantic equivalent in the
linker script language.

However, this gets ignored by some versions of ld (including 2.17 as
shipped with Debian Etch), which mark the resulting sections with
(CONTENTS,ALLOC,LOAD,DATA).  Combined with the fact that this version of
ld seems to ignore the specified LMA for these sections, this means that
they end up overlapping other sections, and so parts of .prefix (for
example) get obliterated by .data16's bss section.

Rename the .bss sections from .section_bss to .bss.section; this seems to
cause these versions of ld to treat them as uninitialised data.
2008-10-17 03:12:11 +01:00
Michael Brown 04f3206581 [build] Fix building on Ubuntu 8.04
Not fully understood, but it seems that the LMA of bss sections matters
for some newer binutils builds.  Force all bss sections to have an LMA
at the end of the file, so that they don't interfere with other
sections.

The symptom was that objcopy -O binary -j .zinfo would extract the
.zinfo section from bin/xxx.tmp as a blob of the correct length, but
with zero contents.  This would then cause the [ZBIN] stage of the
build to fail.

Also explicitly state that .zinfo(.*) sections have @progbits, in case
some future assembler or linker variant decides to omit them.
2008-10-17 01:55:58 +01:00
Michael Brown 58dd6e04c5 [etherfabric] Merge changes from vendor tree
Also clean up minor errors in the use of debug macros.
2008-10-17 01:51:41 +01:00
Eduardo Habkost 744b98d273 virtio-net: Fix kick/wait logic
The virtnet_transmit() logic for waiting the packet to be transmitted is
reversed: we can't wait the packet to be transmitted if we didn't kick()
the ring yet. The vring_more_used() while loop logic is reversed also,
that explains why the code works today.

The current code risks trying to free a buffer from the used ring
when none was available, that will happen most times because KVM
doesn't handle the packet immediately on kick(). Luckily it was working
because it was unlikely to have a buffer still queued for transmit when
virtnet_transmit() was called.

Also, adds a BUG_ON() to vring_get_buf(), to catch cases where we try
to free a buffer from the used ring when there was none available.

Patch for Etherboot. gPXE has the same problem on the code, but I hadn't
a chance to test gPXE using virtio-net yet.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@gmail.com>
2008-10-16 20:32:56 +01:00
Michael Brown c99b16c974 [efi] Add basic implementation of EFI SIMPLE_NETWORK_PROTOCOL
This implementation is tested and working, but not currently tied in
to the EFI build.
2008-10-16 05:38:23 +01:00
Michael Brown 3a505dfc35 [netdevice] Change link-layer push() and pull() methods to take raw types
EFI requires us to be able to specify the source address for
individual transmitted packets, and to be able to extract the
destination address on received packets.

Take advantage of this to rationalise the push() and pull() methods so
that push() takes a (dest,source,proto) tuple and pull() returns a
(dest,source,proto) tuple.
2008-10-16 05:13:40 +01:00
Michael Brown 6b9cc25556 [netdevice] Split multicast hashing out into an mc_hash method
Multicast hashing is an ugly overlap between network and link layers.
EFI requires us to provide access to this functionality, so move it
out of ipv4.c and expose it as a method of the link layer.
2008-10-16 05:12:56 +01:00
Michael Brown 832668105e [netdevice] Add maximum packet length as a net device property
Currently this length is set at device allocation time, and is never
changed.
2008-10-16 05:11:47 +01:00
Michael Brown 64e5ca0582 [efi] Fix linker script for ld 2.17.50.0.9
Some versions of ld choke on the "AT ( _xxx_lma )" in efi.lds with an
error saying "nonconstant expression for load base".  Since these were
only explicitly setting the LMA to the address that it would have had
anyway, they can be safely omitted.
2008-10-13 10:41:38 +01:00
Michael Brown 81d92c6d34 [efi] Add EFI image format and basic runtime environment
We have EFI APIs for CPU I/O, PCI I/O, timers, console I/O, user
access and user memory allocation.

EFI executables are created using the vanilla GNU toolchain, with the
EXE header handcrafted in assembly and relocations generated by a
custom efilink utility.
2008-10-13 10:24:14 +01:00
Michael Brown 54c024e0af [sanboot] Quick and dirty hack to make SAN boot protocols selectable 2008-10-13 10:05:51 +01:00
Michael Brown d4e152e766 [config] Make the default image type selection platform-dependent 2008-10-13 09:37:51 +01:00
Michael Brown 07e8f18f33 [monojob] Release reference on completed job
monojob_wait() was holding a reference to the completed job, meaning that
various objects would not be freed until the next job was plugged in to
the monojob interface.
2008-10-13 05:34:08 +01:00
Michael Brown 831e4cfc27 [umalloc] Formalise the user memory allocation API 2008-10-13 05:33:14 +01:00
Michael Brown 6554b79ff9 [uaccess] Formalise the uaccess API
The userptr_t is now the fundamental type that gets used for conversions.
For example, virt_to_phys() is implemented in terms of virt_to_user() and
user_to_phys().
2008-10-13 04:10:34 +01:00
Michael Brown 667819becc [timer] Remove now-obsolete references to TIMER_BIOS and TIMER_RDTSC 2008-10-13 00:23:18 +01:00
Michael Brown c0835339d0 [nap] Formalise the CPU sleeping API 2008-10-12 23:36:53 +01:00
Michael Brown 658c6dba59 [monojob] Allow for extremely slow system timers
The EFI timer runs at one tick per second, so using ">" rather than ">="
results in a two-second gap between dots.
2008-10-12 21:30:37 +01:00
Michael Brown 16f1e35775 [timer] Formalise the timer API
We now have two implementations for the timer API: one using the
time-of-day counter at 40:70 and one using RDTSC.  Both make use of
timer2_udelay().
2008-10-12 20:22:02 +01:00
Michael Brown e6f276ece3 [process] Add DBG2() messages to help track down frozen processes 2008-10-12 15:11:29 +01:00
Michael Brown f945d6d201 [retry] Use a separate flag to indicate that a retry timer is running
Using start==0 to indicate a stopped timer is dangerous, because 0 is a
valid value for the current tick counter.
2008-10-12 15:11:20 +01:00
Michael Brown 941b4c2adb [commands] Fix config command to accept zero arguments 2008-10-12 15:11:10 +01:00
Michael Brown 8a4ccebec9 [pci] Formalise the PCI I/O API 2008-10-12 12:54:12 +01:00
Michael Brown fd67452807 [legacy] Add missing #include <gpxe/io.h> 2008-10-12 12:52:56 +01:00
Michael Brown e226a8d8d9 [phantom] Add missing #include <gpxe/io.h> 2008-10-12 12:52:47 +01:00
Michael Brown 8c7deba349 [config] Split console configuration out to config/console.h 2008-10-12 02:30:31 +01:00
Michael Brown aef6d0df5c [ioapi] Absorb virt_to_phys() and phys_to_virt() into the I/O API 2008-10-12 02:15:34 +01:00
Michael Brown 992bbf309c [i386] Remove obsolete functions from virtaddr.h
The copy_{to,from}_phys() functions were obsoleted long ago by
copy_{to,from}_user().

relocate_to() also disappeared some time ago.
2008-10-12 02:14:26 +01:00
Michael Brown 8e38669d54 [rtl8139] Add missing #include <string.h> 2008-10-12 02:14:16 +01:00
Michael Brown a1e11a6beb [natsemi] Add missing #include <string.h> 2008-10-12 02:14:10 +01:00
Michael Brown 1641b5d39b [e1000] Add missing #include <string.h> 2008-10-12 02:14:05 +01:00
Michael Brown ee2df1d6d6 [ioapi] Remove old io.h file and switch all users over to <gpxe/io.h> 2008-10-12 01:06:27 +01:00
Michael Brown 8956a36be5 [ioapi] Formalise the I/O API as used in i386-pcbios 2008-10-12 01:03:17 +01:00
Michael Brown b40b4f2dbf [cs89x0] Simplify obscure loop syntax 2008-10-12 00:54:58 +01:00
Michael Brown 0b5c39d167 [e1000] Fix dubious syntax in e1000 I/O wrapper macros 2008-10-12 00:54:44 +01:00
Michael Brown 2e812235f4 [makefile] Add -Wformat-nonliteral as an extra warning category
-Wformat-nonliteral is not enabled by -Wall and needs to be explicitly
 specified.

Modified the few files that use nonliteral format strings to work with
this new setting in place.

Inspired by a patch from Carl Karsten <carl@personnelware.com> and an
identical patch from Rorschach <r0rschach@lavabit.com>.
2008-10-10 18:41:24 +01:00
Michael Brown ac663cf509 [efi] Add EFI headers from the EFI Development Kit (edk2)
The intention is to include near-verbatim copies of the EFI headers
required by gPXE.  This is achieved using the import.pl script in
src/include/gpxe/efi.

Note that import.pl will modify any #include lines in each imported
header to reflect its new location within the gPXE tree.  It will also
tidy up the file by removing carriage return characters and trailing
whitespace.
2008-10-10 04:04:07 +01:00
Michael Brown 13d09e6719 [i386] Simplify linker script and standardise linker-defined symbol names
Reduce the number of sections within the linker script to match the
number of practical sections within the output file.

Define _section, _msection, _esection, _section_filesz, _section_memsz,
and _section_lma for each section, replacing the mixture of symbols that
previously existed.

In particular, replace _text and _end with _textdata and _etextdata, to
make it explicit within code that uses these symbols that the .text and
.data sections are always treated as a single contiguous block.
2008-10-10 03:59:57 +01:00
Michael Brown 3029eb0e84 [makefile] Reduce verbosity of various NON_AUTO_MEDIA rules 2008-10-10 03:57:31 +01:00
Michael Brown 5c695db474 [makefile] Split platform-dependent portions out of arch/i386/Makefile 2008-10-10 03:45:34 +01:00
Michael Brown 98abd48a26 [makefile] Inhibit warnings if AUTO_DEPS or MEDIA_DEPS are empty lists 2008-10-10 03:42:56 +01:00
Michael Brown 3f80f9e1a6 [makefile] Add missing dependency on arch/$(ARCH)/Makefile to MAKEDEPS 2008-10-10 03:42:37 +01:00
Michael Brown cdd619d11f [util] Don't die on undefined symbols in sortobjdump.pl
Undefined symbols shouldn't reach sortobjdump.pl, but if they do then it
is not a helpful place to report the error.
2008-10-10 03:42:22 +01:00
Michael Brown 96ea558e98 [util] Add optional debug messages to zbin.c 2008-10-10 03:42:08 +01:00
Michael Brown e817a347fb [makefile] Split config.h out into config/*.h and kill off mkconfig.pl 2008-10-08 02:17:32 +01:00
Michael Brown a2588547f9 [makefile] Add support for multiple build platforms
Allow for the build CPU architecture and platform to be specified as part
of the make command goals.  For example:

  make bin/rtl8139.rom      # Standard i386 PC-BIOS build

  make bin-efi/rtl8139.efi  # i386 EFI build

The generic syntax is "bin[-[arch-]platform]", with the default
architecture being "i386" (regardless of the host architecture) and the
default platform being "pcbios".

Non-path targets such as "srcs" can be specified using e.g.

  make bin-efi srcs

Note that this changeset is merely Makefile restructuring to allow the
build architecture and platform to be determined by the make command
goals, and to export these to compiled code via the ARCH and PLATFORM
defines.  It doesn't actually introduce any new build platforms.
2008-10-08 02:17:25 +01:00
Michael Brown f0b942ef42 [makefile] Kill off arch/$(ARCH)/Config
The arch/i386/Config file has long been marked as deprecated.  Move all
the pertinent bits to arch/i386/Makefile instead and remove
arch/i386/Config.
2008-10-07 22:46:43 +01:00
Michael Brown 160b950af8 [libc] Define wchar_t in a gcc-compatible way
gcc defines the magic __WCHAR_TYPE__ macro, in order to convey
information about whether or not the user selected -fshort-wchar.
2008-10-07 22:27:55 +01:00
Michael Brown 19a0452205 [libc] Add function declaration for main() in stdlib.h 2008-10-07 22:04:50 +01:00
Michael Brown 521549d900 [crypto] Rename <gpxe/bitops.h> to <gpxe/rotate.h> 2008-10-01 19:24:56 +01:00
Michael Brown 9dccbc0af2 [i2c] Generalise i2c bit-bashing support to addressless devices
Some devices (e.g. the Atmel AT24C11) have no concept of a device
address; they respond to every device address and use this value as
the word address.  Some other devices use part of the device address
field to extend the word address field.

Generalise the i2c bit-bashing support to handle this by defining the
device address length and word address length as properties of an i2c
device.  The word address is assumed to overflow into the device
address field if the address used exceeds the width of the word
address field.

Also add a bus reset mechanism.  i2c chips don't usually have a reset
line, so rebooting the host will not clear any bizarre state that the
chip may be in.  We reset the bus by clocking SCL until we see SDA
high, at which point we know we can generate a start condition and
have it seen by all devices.  We then generate a stop condition to
leave the bus in a known state prior to use.

Finally, add some extra debugging messages to i2c_bit.c.
2008-10-01 19:24:56 +01:00
Michael Brown 91802c6e85 [makefile] Fix -fno-stack-protector test on older versions of gcc
Some older versions of gcc don't complain about unknown compiler flags
unless you ask them to actually compile; asking them to merely
preprocess won't trigger the error.

Fix the -fno-stack-protector test by making it attempt to compile an
empty file, rather than preprocess an empty file.
2008-10-01 19:24:56 +01:00
Michael Brown afe1323c76 [compiler] Allow for selective disabling of debug levels at runtime
The usefulness of DBGLVL_IO is limited by the fact that many cards
require large numbers of uninteresting I/O reads/writes at device
probe time, typically when driving a bit-bashing I2C/SPI bus to read
the MAC address.

This patch adds the DBG_DISABLE() and DBG_ENABLE() macros, which can
be used to temporarily disable and re-enable selected debug levels.
Note that debug levels must still be enabled in the build in order to
function at all: you can't use DBG_ENABLE(DBGLVL_IO) in an object
built with DEBUG=object:1 and expect it to do anything.
2008-10-01 19:24:56 +01:00
Michael Brown 9b01a9fd9c [compiler] Add __always_inline macro 2008-10-01 19:24:56 +01:00
Marty Connor 60c3b69c31 [release] Update version to 0.9.5+ post release 2008-10-01 13:46:16 -04:00
Marty Connor 8c3e95ce42 [release] Update version to 0.9.5 for release 2008-10-01 13:38:45 -04:00
Michael Brown df02c54f86 [arbel] Fix off-by-one error in the failure path in arbel_probe() 2008-10-01 08:11:03 +01:00
Michael Brown 76f6cad8af [hermon] Fix off-by-one error in the failure path in hermon_probe() 2008-10-01 08:10:50 +01:00
H. Peter Anvin e899f100ca [makefile] Quote argument to sed containing []
[] are shell metacharacters, and they can get confused by files in the
local directory.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-09-30 21:54:41 +01:00
H. Peter Anvin e8b6077566 [makefile] Avoid using ?=
?= in a Makefile means that that variable can be overridden by the
environment.  This is confusing to users, especially with a generic
name like "ARCH".

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-09-30 21:53:34 +01:00
Michael Brown 6f87d622e1 [tg3] Add PCI ID
Reported working by Martin Kreiner <m.kreiner@levigo.de>
2008-09-29 16:00:09 +01:00
Michael Brown 1dda75c9cd [pcbios] Allow for larger-than-20-byte buffers in e820mangler.S
Although the E820 API allows for a caller to provide only a 20-byte
buffer, there exists at least one combination (HP BIOS, 32-bit WinPE)
that relies on information found only in the "extended attributes"
field, which requires a 24-byte buffer.

Allow for up to a 64-byte E820 buffer, in the hope of coping with
future idiocies like this one.
2008-09-29 05:11:51 +01:00
Michael Brown 040f7cdf3a [pcbios] Print INT 15,E820 extended attributes, if present
The ACPI specification defines an additional 4-byte field at offset 20
for an E820 memory map entry.  This field is presumably optional,
since generally E820 gets given only a 20-byte buffer to fill.
However, the bits of this optional field are defined as:

  bit 0 : region is enabled
  bit 1 : region is non-volatile memory rather than RAM

so it seems as though callers that pass in only a 20-byte buffer may
be missing out on some rather important information.
2008-09-29 03:55:13 +01:00
Michael Brown 0015601f0b [gdb] Fix a compiler warning that shows up only when assertions are enabled
gcc should (I think) be warning about this anyway, but seems to do so
only when assertions are enabled for this object.
2008-09-29 01:00:14 +01:00
Michael Brown 50dc9344b7 [pcbios] Save/restore %es in INT 15,e820
Our INT 15,e820 code was setting %es=%ss (as part of the "look ahead
in the memory map" logic), but failing to restore %es afterwards.
This is a serious bug, but wasn't affecting many platforms because
almost all callers seem to set %es=%ss anyway.
2008-09-29 00:36:11 +01:00
Michael Brown e3c5507178 [i386] Add dump_regs() debug call
Use as "call dump_regs" from any real-mode code within .text16.
Should preserve all registers and flags.
2008-09-28 23:06:53 +01:00
Michael Brown 39047c5636 [hermon] Allocate only as much memory as is needed for ICM and ICM AUX
Use individual page mappings rather than a single whole-region
mapping, to avoid the waste of memory that occurs due to the
constraint that each mapped block must be aligned on its own size.
2008-09-28 20:43:18 +01:00
Michael Brown 2d41dead08 [iscsi] Fix LUN parsing in the iSCSI root-path 2008-09-27 23:53:31 +01:00
Marty Connor 6eaefa16a8 [release] Update version post release to 0.9.4+ 2008-09-26 16:05:55 -04:00
Marty Connor 601d244a8e [release] Update version information for 0.9.4 release 2008-09-26 15:14:34 -04:00
Michael Brown 6936c40fef [settings] Allow for setting fetchers to fail in fetchf_hex() 2008-09-26 03:39:35 +01:00
Michael Brown e2d5788716 [settings] Expose MAC address setting for general use 2008-09-26 03:39:17 +01:00
Michael Brown 9d72636da1 [romprefix] Fully clear the "Press B to boot..." message when INT19 is used 2008-09-26 01:36:22 +01:00
Michael Brown 3392cfa7df [pcbios] Fetch INT 15,e820 entry directly into our e820 cache
Some BIOSes require us to pass in not only the continuation value (in
%ebx) as returned by the previous call to INT 15,e820 but also the
unmodified buffer (at %es:%di) as returned by the previous call to INT
15,e820.  Apparently, someone thought it would be a worthwhile
optimisation to fill in only the low dword of the "length" field and
the low byte of the "type field", assuming that the buffer would
remain unaltered from the previous call.

This problem was being triggered by the "peek ahead" logic in
get_mangled_e820(), which would read the next entry into a temporary
buffer in order to be able to guarantee terminating the map with
%ebx=0 rather than CF=1.  (Terminating with CF=1 upsets some Windows
flavours, despite being documented legal behaviour.)

Work around this problem by always fetching directly into our e820
cache; that way we can guarantee that the underlying call always sees
the previous buffer contents (and the same buffer address).
2008-09-25 18:52:49 +01:00
Michael Brown fa880ec70a [arbel] Allocate sufficient space for firmware buffer
We were accidentally allocating only half the required amount of
memory (given the alignment method) for the firmware buffer, leading
to conflicts between the firmware buffer and gPXE code/data segments.
2008-09-25 07:23:34 +01:00
Michael Brown b45b39260c [hermon] Allocate sufficient space for firmware buffer
We were accidentally allocating only half the required amount of
memory (given the alignment method) for the firmware buffer, leading
to conflicts between the firmware buffer and gPXE code/data segments.
2008-09-25 07:22:06 +01:00
Michael Brown c24bc349ea [pcbios] Add facility for testing arbitrary E820 memory maps
We seem to be having issues with various E820 memory maps.  These
problems are often difficult to reproduce, requiring access to the
specific system exhibiting the problem.

Add a facility for hooking in a fake E820 map generator, using an
arbitrary map defined in a C array, solely in order to be able to test
the map-mangling code against arbitrary E820 maps.
2008-09-25 03:34:26 +01:00
Michael Brown 9c71949d1f [crypto] Remove spurious #include "config.h" 2008-09-25 01:55:48 +01:00
Michael Brown 539f94b980 [romprefix] Allow BANNER_TIMEOUT to control banners in romprefix.S
In particular, allow BANNER_TIMEOUT=0 to inhibit the prompt banners
altogether.

Ironically, this request comes from the same OEM that originally
required the prompts to be present during POST.
2008-09-25 01:53:42 +01:00
Michael Brown aa8d972581 [dhcp] Accept BOOTP as well as DHCP 2008-09-25 01:35:15 +01:00
Michael Brown fed106b7fb [pxe] Enable interrupts before starting PXE NBP execution
Based on a patch provided by XenSource for Etherboot 5.4.
2008-09-24 21:23:50 +01:00
Michael Brown 887d77c27a [pcbios] Inhibit INT 15 memory map hiding on brain-dead BIOSes
Some really moronic BIOSes bring up the PXE stack via the UNDI loader
entry point during POST, and then don't bother to unload it before
overwriting the code and data segments.  If this happens, we really
don't want to leave INT 15 hooked, because that will cause any loaded
OS to die horribly as soon as it attempts to fetch the system memory
map.

We use a heuristic to detect whether or not we are being loaded at the
top of free base memory.  If we determine that we are being loaded at
some other arbitrary location in base memory, then we assume that it's
not safe to hook INT 15.
2008-09-24 18:33:31 +01:00
Michael Brown 35b7658877 [settings] Add the uristring setting type
This allows settings to be expanded in a way that is safe to include
within a URI string, such as

  kernel http://10.0.0.1/boot.php?mf=${manufacturer:uristring}

where the ${manufacturer} setting may contain characters that are not
permitted (or have reserved purposes) within a URI.

Since whitespace characters will be URI-encoded (e.g. "%20" for a
space character), this also works around the problem that spaces
within an expanded setting would cause the shell to split command-line
arguments incorrectly.
2008-09-24 07:22:42 +01:00
Michael Brown b350b10b35 [uri] Add uri_encode() and uri_decode() functions for URI character encoding 2008-09-24 07:21:47 +01:00
Michael Brown 9d44a06188 [romprefix] If we hook INT 19, prompt before attempting boot
On non-BBS systems we hook INT 19, since there is no other way we can
guarantee gaining control of the flow of execution.  If we end up
doing this, prompt the user before attempting boot, since forcibly
capturing INT 19 is rather antisocial.
2008-09-24 00:53:40 +01:00
Michael Brown 4011f9d956 [phantom] Skip command PEG initialisation if PEG is already running
It is possible for the BIOS to use the UNDI API to bring up the NIC
prior to system boot.  If this happens, UNM_NIC_REG_CMDPEG_STATE will
contain the value 0xf00f (UNM_NIC_REG_CMDPEG_STATE_INITIALIZE_ACK),
and we should skip initialising the command PEG.
2008-09-23 23:36:55 +01:00
Michael Brown 8b20e5d2b7 [pcbios] Sanity-check the INT15,e820 and INT15,e801 memory maps
Some systems seem to report insane memory maps (particularly at POST
time).  Detect and work around some of the common failure cases.
2008-09-23 23:35:19 +01:00
Michael Brown e13d793160 [phantom] Omit an initialisation step now performed by the firmware
The firmware will now determine the right port mode on all cards, so
the PXE driver doesn't have to set it.  (Setting the port mode
apparently breaks some newer cards.)
2008-09-23 23:11:05 +01:00
Michael Brown a2f9bf70d7 [pxe] Display PXE_LOADER debug message after call to initialise()
At least one Dell system calls the UNDI loader entry point with the
BIOS console disabled.  The serial console is active only after a call
to initialise(), so move the debug message in undi_loader() so that it
can be displayed via the serial console.
2008-09-23 04:15:56 +01:00
Michael Brown ca0b0f0616 [relocate] Guard against systems that report empty memory regions
If the INT 15,e820 memory map reports a region [0,0), this confuses
the "truncate to even megabytes" logic, which ends up rounding the
region 'down' to [0,fff00000).

Fix by ensuring that the region's end address is at least 1, before we
subtract 1 to obtain the "last byte in region" address.
2008-09-23 01:13:28 +01:00
Michael Brown 0fd1e54026 [memmap] Allow for 4GB+ systems in debug message
INT 15,e801 is capable of returning a memory range that extends to
4GB, so allow for this in the debug message that shows the data
returned by INT 15,e801.
2008-09-23 00:58:12 +01:00
Michael Brown 0e408658b9 [iscsi] Change default initiator name prefix to "iqn.2000-01.org.etherboot:"
The domain etherboot.org was actually registered on 2000-01-09, not
2000-09-01.  (To put it another way, it was registered on 1/9/2000 (US
date format) rather than 1/9/2000 (sensible date format); this may
illuminate the cause of the error.)

"iqn.2000-09.org.etherboot:" is still valid as per RFC3720, but may be
surprising to users, so change it to something less unexpected.

Thanks to the anonymous contributor for pointing this one out.
2008-09-19 17:46:07 +01:00
Michael Brown 6df82b1a9d [undi] Scan for UNDI ROMs on 512-byte boundaries rather than 2kB boundaries
Apparently some BIOSes will place option ROMs on 512-byte boundaries.
While this is against specification, it doesn't actually hurt
anything, so we may as well increase our scan granularity to 512
bytes.

Contributed by Luca <lucarx76@gmail.com>
2008-09-12 03:10:27 +01:00
Michael Brown 8223084afc [util] Disable automatic CR->LF conversion in serial-console utility
DUET (the EFI test environment) seems not to handle LF, so inhibit the
CR->LF conversion that the pty does for us by default.  This doesn't
affect operation of gPXE, which will happily accept either CR or LF.
2008-09-07 22:08:40 +01:00
Michael Brown 18aa0e79d2 [pcbios] Add extra debugging messages relating to the system memory map 2008-09-07 21:38:41 +01:00
Michael Brown a30c70727a [contrib] Bring bochs/qemu READMEs up to date with latest upstream code 2008-09-07 11:31:42 +01:00
Michael Brown c0beec8baf [pxe] Add a dummy PXENV+ entry point at UNDI_CS:0000
Wyse Streaming Manager server (WLDRM13.BIN) assumes that the PXENV+
entry point is at UNDI_CS:0000; apparently, somebody at Wyse has
difficulty distinguishing between the words "may" and "must"...

Add a dummy entry point at UNDI_CS:0000, which just jumps to the
correct entry point.
2008-09-06 03:19:03 +01:00
Michael Brown 2e03610c0d [multiboot] Allow for unspecified {load,bss}_end_addr for raw images
The multiboot specification states that, for raw images, if
load_end_addr is zero then it should be interpreted as meaning "use
the entire file", and if bss_end_addr is zero it should be interpreted
as meaning "no bss".
2008-09-06 01:57:52 +01:00
Eygene Ryabinkin 6de45ad4ae [util] Avoid calling fclose(NULL) in zbin.c
Must check that argument to a fclose() is not NULL -- we can get to the
'err' label when file was not opened.  fclose(NULL) is known to produce
core dump on some platforms and we don't want zbin to fail so loudly.

Signed-off-by: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
2008-09-04 11:29:37 +01:00
Eygene Ryabinkin 99251f5b32 [libprefix] Add addr32 prefix required by older assemblers
Explicitly state that we are using 32-bit addressing in 16-bit code.

GNU as 2.15 (FreeBSD/amd64 7-STABLE) got confused that 32-bit registers
are used in the code that was declared as 16-bit.  Add explicit modifier
'addr32' to make assembler happy.

Signed-off-by: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
2008-09-04 11:27:20 +01:00
Daniel Verkamp e8b22f203f [comboot] Add COMBOOT and COM32 support 2008-08-28 23:52:19 +01:00
Daniel Verkamp aa28544373 [librm] Add rm stack copying functions 2008-08-28 23:09:08 +01:00
Daniel Verkamp 2539f5fa4a [librm] Make rm_sp and rm_ss globals again 2008-08-28 22:50:55 +01:00
Daniel Verkamp 179fa70d34 [libc] Mark setjmp and longjmp as __cdecl 2008-08-28 22:50:39 +01:00
Michael Brown fc0c40a5b0 [pxe] Fill in UNDIROMID pointer in !PXE structure
IBM's iSCSI Firmware Initiator checks the UNDIROMID pointer in the
!PXE structure that gets created by the UNDI loader.  We didn't
previously fill this value in.
2008-08-28 00:11:45 +01:00
Michael Brown 32e34683c0 [romprefix] Add UNDI ROMID structure bus type field
The IBM iSCSI Firmware Initiator complains that we don't have a bus
type field in the UNDI ROMID structure, so include one.
2008-08-27 22:08:57 +01:00
Michael Brown cb6fea0690 [phantom] Fix P3 B1 silicon bug workaround
Commit f58cc3f introduced a temporary workaround for a bug in current
prototype silicon, but failed to apply it to all eight PCI functions
within the device.
2008-08-27 21:25:06 +01:00
Michael Brown bd5189a96d [util] Fix interpretation of short jumps in Option::ROM
Option::ROM was assuming that ROM images using a short jump
instruction for the init entry point would have a zero byte at offset
5; this is not necessarily true.
2008-08-27 20:36:30 +01:00
Michael Brown d5732b0272 [romprefix] Preserve %edi when issuing INT 1A,B101
INT 1A,B101 (get PCI BIOS version) will overwrite %edi.
2008-08-26 05:03:19 +01:00
Michael Brown 07581d3faa [phantom] Remove comment that no longer matches reality 2008-08-26 04:45:31 +01:00
Michael Brown de7be480d6 [romprefix] Add more diagnostic messages to ROM prefix
Include PMM allocation result in POST banner.

Include full product string in "starting execution" message.

Also mark ourselves as supporting DDIM in PnP header, for
completeness.
2008-08-25 23:36:24 +01:00
Michael Brown f58cc3fca8 [phantom] Temporary workaround for bug in prototype (P3 B1) silicon 2008-08-25 23:25:33 +01:00
Michael Brown d5e07dfe92 [romprefix] Fix regression in UNDI loader
Commit 12f203c introduced a bug that caused the UNDI loader to attempt
to load the UNDI code and data segments to incorrect addresses.
2008-08-22 23:58:46 +01:00
Michael Brown 82baea0a4b [romprefix] On a PCI3.0, non-BBS system, use the correct %cs for INT19
On a system that doesn't support BBS, we end up hooking INT19 to gain
control of the boot process.  If the system is PCI3.0, we must take
care to use the runtime value for %cs, rather than the POST-time
value, otherwise we end up pointing INT19 to the temporary option ROM
POST scratch area.
2008-08-22 03:01:46 +01:00
Michael Brown 4815188dfc [elf] Add execution entry point debug messages for elf/multiboot images 2008-08-22 02:12:44 +01:00
Michael Brown 0ffc3f6285 [pxe] Add extra debug messages to the PXE UDP API calls 2008-08-21 16:52:08 +01:00
Michael Brown 2090aade04 [pxe] Fix broadcast transmissions via PXENV_UDP_WRITE
pxenv_udp_write() needs to specify a net device, otherwise ipv4 is
unable to route broadcast transmissions.
2008-08-21 16:50:51 +01:00
Michael Brown 30fb3b3810 [undi] Fill in ProtType correctly in PXENV_UNDI_ISR
Determine the network-layer packet type and fill it in for UNDI
clients.  This is required by some NBPs such as emBoot's winBoot/i.

This change requires refactoring the link-layer portions of the
gPXE netdevice API, so that it becomes possible to strip the
link-layer header without passing the packet up the network stack.
2008-08-20 03:21:37 +01:00
Michael Brown f6f6f626f7 [undi] Work around broken UNDI polling behaviour in winBoot/i
Some dumb NBPs (e.g. emBoot's winBoot/i) never call PXENV_UNDI_ISR
with FuncFlag=PXENV_UNDI_ISR_START; they just sit in a tight polling
loop merrily violating the PXE spec with repeated calls to
PXENV_UNDI_ISR_IN_PROCESS.  Force a extra calls to netdev_poll() to
cope with these out-of-spec clients.
2008-08-20 02:02:51 +01:00
Michael Brown 0c7618771e [smbios] Print SMBIOS version number in debugging messages 2008-08-19 22:01:38 +01:00
Michael Brown 320b072c7a [pcbios] Support arbitrary splits of the e820 memory map
Allow for an arbitrary number of splits of the system memory map via
INT 15,e820.

Features of the new map-mangling algorithm include:

  Supports random access to e820 map entries.

  Requires only sequential access support from the underlying e820
  map, even if our caller uses random access.

  Empty regions will always be stripped.

  Always terminates with %ebx=0, even if the underlying map terminates
  with CF=1.

  Allows for an arbitrary number of hidden regions, with underlying
  regions split into as many subregions as necessary.

Total size increase to achieve this is 193 bytes.
2008-08-18 07:17:41 +01:00
Michael Brown 9737095d49 [pcbios] Prepare for multiple splits of hidden e820 memory regions
Define a list of N allowed memory regions, and split each underlying
e820 region into up to N subregions.  Strip resulting empty regions
out of the map, avoiding using the "return with CF set to strip last
empty region" trick, because it seems that bootmgr.exe in Win2k8 gets
upset if the memory map is terminated with CF set.

This is an intermediate checkin that defines a single allowed memory
region covering the entire 64-bit address space, and uses the existing
map-mangling code on top of the new region-splitting code.  This
sanitises the memory map to the point that Win2k8 is able to boot even
on a system that defines a final zero-length region at the 4GB mark.

I'm checking this in because it may be useful for future debugging
efforts to be able to run with the existing and known-working map
mangling code together with the map sanitisation capabilities of the
new map mangling code.
2008-08-18 01:01:45 +01:00
Michael Brown 23bca8f9d8 [util] Allow Option::ROM to understand and modify initialisation entry point
Add support for manipulating the jump instruction that forms the
option ROM initialisation entry point, so that mergerom.pl can treat
it just like other entry points.

Add support for merging the initialisation entry point (and IBM BOFM
table) to mergerom.pl; this is another slightly icky but unfortunately
necessary GPL vs. NDA workaround.  When mergerom.pl replaces an entry
point in the original ROM, it now fills in the corresponding entry
point in the merged ROM with the original value; this allows (for
example) a merged initialisation entry point to do some processing and
then jump back to the original entry point.
2008-08-15 04:10:35 +01:00
Michael Brown 8f8f5acf09 [settings] Avoid overwriting the start of .text in fetch_string_setting()
fetch_string_setting() was subtracting one from the length of the
to-be-NUL-terminated buffer in order to obtain the length of the
unterminated buffer to be passed to fetch_setting().  This works
extremely well unless the length of the to-be-NUL-terminated buffer is
zero, at which point we end up giving fetch_setting() a buffer of
length -1UL, thereby inviting it to overwrite as much memory as it
wants...
2008-08-14 03:03:53 +01:00
Michael Brown a1d0f6ed2e [dhcp] Do not restrict minimum retry time for ProxyDHCPREQUEST
The ProxyDHCPREQUEST is a unicast packet, so the first request will
almost always be lost due to not having the IP address in the ARP
cache.  If the minimum retry time is set to one second (as per commit
ff2b6a5), then ProxyDHCP will time out and give up before managing to
successfully transmit a request.

The DHCP timers need to be reworked anyway, so this mild hack is
acceptable for now.
2008-08-13 21:51:53 +01:00
Andrew Schran ff2b6a512d [retry] Added configurable timeouts to retry timer
New min_timeout and max_timeout fields in struct retry_timer allow
users of this timer to set their own desired minimum and maximum
timeouts, without being constrained to a single global minimum and
maximum. Users of the timer can still elect to use the default global
values by leaving the min_timeout and max_timeout fields as 0.
2008-08-12 01:05:26 +01:00
Michael Brown 5d4839b577 [iSCSI] Add support for mutual CHAP
Allow initiator to verify target authentication using CHAP.
2008-08-11 03:43:12 +01:00
Michael Brown 7ad2f652b4 [libc] Add missing __attribute__ (( format ( printf ) )) to ssnprintf() 2008-08-11 02:31:14 +01:00
Michael Brown 8332ddf556 [romprefix] Fix ROM image copy on PCI 3.0 BIOSes
Add the missing instructions to the code path that I never tested due
to not having a PCI 3.0 system available.

(D'oh)
2008-08-05 23:18:07 +01:00
Michael Brown f178436bb1 [pxe] If no ProxyDHCPACK exists, use DHCPACK for the fake ProxyDHCPACK packet
WinPE seems to have a bug that causes it to always use the TFTP server
IP address and filename from the ProxyDHCPACK packet, even if the
ProxyDHCPACK packet doesn't exist.  This causes it to end up
attempting to fetch a file such as

  tftp://0.0.0.0/bootmgr.exe

If we don't have a ProxyDHCPACK to use, we pretend that it was a copy
of the DHCPACK packet.  This works around the problem, and hopefully
won't surprise any NBPs.
2008-08-02 03:03:42 +01:00
Michael Brown ed73d53503 [dhcp] Work around a bug in Altiris RDP
Altiris erroneously cares about the ordering of DHCP options, and will
get confused if we don't construct them in the order it expects.

This is observed (so far) only when attempting to deploy 64-bit Win2k3.
2008-08-01 21:49:11 +01:00
Stefan Hajnoczi 50babca5da [virtio] Add legacy driver for KVM virtio-net
This patch adds support for the virtio-net adapter provided by KVM.

Written by Laurent Vivier <Laurent.Vivier@bull.net> for Etherboot.
Wrapped as legacy driver for gPXE by Stefan Hajnoczi
<stefanha@gmail.com>.
2008-08-01 16:55:49 +01:00
Michael Brown 481a21798d [autoboot] Retain initial-slash (if present) when constructing TFTP URIs
When we boot from a DHCP-supplied filename, we previously relied on
the fact that the current working URI is set to tftp://[next-server]/
in order to resolve the filename into a full tftp:// URI.  However,
this process will eliminate the distinction between filenames with and
without initial slashes:

 cwuri="tftp://10.0.0.1/" filename="vmlinuz"  => URI="tftp://10.0.0.1/vmlinuz"
 cwuri="tftp://10.0.0.1/" filename="/vmlinuz" => URI="tftp://10.0.0.1/vmlinuz"

This distinction is important for some TFTP servers.  We now
explicitly construct a string of the form

 "tftp://[next-server]/filename"

so that a filename with an initial slash will result in a URI
containing a double-slash, e.g.

 "tftp://10.0.0.1//vmlinuz"

The TFTP code always strips a single initial slash, and so ends up
presenting the correct path to the server.

URIs entered explicitly by users at the command line must include a
double slash if they want an initial slash presented to the TFTP
server:

  "kernel tftp://10.0.0.1/vmlinuz"  => filename="vmlinuz"
  "kernel tftp://10.0.0.1//vmlinuz" => filename="/vmlinuz"
2008-07-31 16:55:46 +01:00
Michael Brown 193426d960 [cleanup] Remove obsolete README.cvs file 2008-07-31 16:24:16 +01:00
Michael Brown 12a37ab99e [util] Add mergerom.pl
This utility is required as a workaround for legal restrictions on
including GPL and non-GPL code within the same expansion ROM image.

While this is not encouraged, we are prepared to accept that
concatenation of ROM images and updating of the ROM header data
structures can be classed as "mere aggregation" within the terms of
the GPL.

If in any doubt, assume that you cannot include GPL and non-GPL code
within the same expansion ROM image.  Contact the Etherboot team for
clarification on your specific circumstances.
2008-07-31 06:28:46 +01:00
Michael Brown 6f73bb5e00 [util] Add Option::ROM library and rewrite disrom.pl to use it.
The Option::ROM module provides an easy way to read and edit fields
within option ROM headers.
2008-07-31 05:30:04 +01:00
Sergey Vlasov e6cd16946a [ftp] Terminate processing after receiving an error
When an error reply (not 1xx, 2xx or 3xx) was received, ftp_reply()
invoked ftp_done() to close connections, but did not return, and the
rest of code in this function could try to send commands to the closed
control connection.

Signed-off-by: Sergey Vlasov <vsu@altlinux.ru>
2008-07-30 20:27:09 +01:00
Michael Brown 8f4c2b4a4c [ftp] Cope with RETR completion prior to all data received
Based on a patch contributed by Sergey Vlasov <vsu@altlinux.ru> :

  In my testing with "qemu -net user" the 226 response to RETR was
  often received earlier than final packets of the data connection;
  this caused the received file to become truncated without any error
  indication.  Fix this by adding an intermediate state FTP_TRANSFER
  between FTP_RETR and FTP_QUIT, so that the transfer is considered to
  be complete only when both the end of data connection is encountered
  and the final reply to the RETR command is received.
2008-07-30 20:22:49 +01:00
Michael Brown fe1f017bde [romprefix] Update PCI ROM structure to PCI 3.0 2008-07-30 19:57:46 +01:00
Stefan Hajnoczi 4cc786de81 [prefix] Reasonable value for lkrn initrd_addr_max
H. Peter Anvin <hpa@zytor.com> sent word that Sergey Vlasov
<vsu@altlinux.ru> discovered gPXE lkrn images fail to load in SYSLINUX
3.70 because we have initrd_addr_max zeroed.  This patch sets the same
value as the Linux kernel.

Also change the header jmp instruction to use a hardcoded opcode value
like Linux does.  Just in case the assembler decides to use a three-byte
instruction instead of the desired two-byte jmp.
2008-07-30 19:45:48 +01:00
Michael Brown 594c672b75 [smbios] Add named settings for manufacturer, product name, and serial no. 2008-07-27 01:18:55 +01:00
Michael Brown 34a06b6ba7 [cmdline] Add setting expansion using ${...} syntax
Allow settings to be expanded in arbitrary commands, such as

  kernel http://10.0.0.1/boot.php?uuid=${uuid}

Also add the "echo" command, as being the easiest way to test this
features.
2008-07-27 01:08:20 +01:00
Michael Brown 702e0be44e [ui] Add progress dots while waiting on any foreground job
Print one dot per second while waiting in monojob.c (e.g. for DHCP,
for file downloads, etc.), to inform user that the system has not
locked up.

Patch contributed by Andrew Schran <aschran@google.com>, minor
modification by me.
2008-07-24 20:08:31 +01:00
Michael Brown 764e2cc68c [cmdline] Minor tidy-ups to shell_banner.c 2008-07-24 20:00:43 +01:00
Andrew Schran 833447392d [cmdline] Added configurable shell banner timeout
This change allows the time for which shell banners are displayed to
be configured in the config.h file.  The ability to access the shell
can also be effectively disabled by setting this timeout to zero.
2008-07-24 19:59:12 +01:00
Andrew Schran 6b58992318 [tg3] Added support for tg3-5754.
In tg3_chip_reset(), the PCI_EXPRESS change is taken from the Linux
tg3 driver. I am not sure what exactly it does (it is not documented
in the Linux driver), but it is necessary for the NIC to work
correctly.
2008-07-24 19:55:53 +01:00
Michael Brown c302eeda5a [makefile] Suppress "No such file or directory" warnings at start of build
Use "-include" rather than "include" for the generated Makefile
fragments, in order to suppress the long list of warnings that
otherwise appears at the start of a clean build.

Contributed by Edward Waugh <ewaugh@netxen.com>
2008-07-24 19:45:35 +01:00
Michael Brown f493283c74 [phantom] Add new board type 2008-07-24 19:40:10 +01:00
Michael Brown 03c80c12b8 [iSCSI] Support Windows Server 2008 direct iSCSI installation
Add yet another ugly hack to iscsiboot.c, this time to allow the user to
inhibit the shutdown/removal of the iSCSI INT13 device (and the network
devices, since they are required for the iSCSI device to function).

On the plus side, the fact that shutdown() now takes flags to
differentiate between shutdown-for-exit and shutdown-for-boot means that
another ugly hack (to allow returning via the PXE stack on BIOSes that
have broken INT 18 calls) will be easier.

I feel dirty.
2008-07-17 17:45:17 +01:00
Michael Brown 4e033c774b [phantom] Guard against partially-written status descriptors
Conjecture: The hardware issues 64-bit DMA writes of status descriptors,
which some PCI bridges seem to split into two 32-bit writes in reverse
order (i.e. dword 1 first).  This means that we sometimes observe a
partial status descriptor.  Add an explicit check to ensure that the
descriptor is complete before processing it.

Also ensure that the RDS consumer counter is incremented only when we
know that we have actually consumed an RX descriptor.
2008-07-17 15:45:40 +01:00
Michael Brown bb41ec385c [int13] Pairwise swap drive numbers, instead of shifting all drive numbers
Shifting all INT13 drive numbers causes problems on systems that use a
sparse drive number space (e.g. qemu BIOS, which uses 0xe0 for the CD-ROM
drive).

The strategy now is:

  Each drive is assigned a "natural" drive number, being the next
  available drive number in the system (based on the BIOS drive count).

  Each drive is accessed using its specified drive number.  If the
  specified drive number is -1, the natural drive number will be used.

  Accesses to the specified drive number will be delivered to the
  emulated drive, masking out any preexisting drive using this number.

  Accesses to the natural drive number, if different, will be remapped to
  the masked-out drive.

The overall upshot is that, for examples:

  System has no drives.  Emulated INT13 drive gets natural number 0x80
  and specified number 0x80.  Accesses to drive 0x80 go to the emulated
  drive, and there is no remapping.

  System has one drive.  Emulated INT13 drive gets natural number 0x81
  and specified number 0x80.  Accesses to drive 0x80 go to the emulated
  drive.  Accesses to drive 0x81 get remapped to the original drive 0x80.
2008-07-15 23:19:59 +01:00
Michael Brown 21e9e801e2 [udp] Avoid reusing auto-allocated ports after connection close.
This duplicates a fix made to tcp.c in commit
d5735c631c.
2008-07-10 04:21:10 +01:00
Michael Brown 6f39dfe6c0 [dhcp] Verify DHCP server source port
Verifying server ID and DHCP transaction ID is insufficient to
differentiate between DHCPACK and ProxyDHCPACK when the DHCP server and
Proxy DHCP server are the same machine.
2008-07-10 04:11:09 +01:00
Andrew Schran 34c1a5b91d [forcedeth] Add support for PCI ID 10de:0373 2008-07-10 01:19:08 +01:00
Michael Brown 997bccc64e [hermon] Add support for MT26418 device
PCI ID supplied (and tested) by Frederic
Temporelli <frederic.temporelli@bull.net>
2008-07-09 00:53:38 +01:00
Michael Brown d474386336 [phantom] Remove warning relating to now-fixed firmware bug 2008-07-08 22:37:36 +01:00
Michael Brown 22d00797f1 [phantom] Add NetXen dual copyright 2008-07-08 22:36:07 +01:00
Michael Brown 4f05d2fca7 [phantom] Initialise RCVPEG before reading MAC addresses 2008-07-08 20:59:33 +01:00
Michael Brown 0436e417bc [image] Fail "imgexec"/"boot" if the image to execute is ambiguous
If there is more than one loaded image, refuse to automatically select
the image to execute.  There are at least two possible cases, with
different "correct" answers:

1. User loads image A by mistake, then loads image B and types "boot".
   User wants to execute image B.

2. User loads image A, then loads image B (which patches image A), then
   types "boot".  User wants to execute image A.

If a user actually wants to load multiple images, they must explicitly
specify which image is to be executed.
2008-07-08 03:50:44 +01:00
Michael Brown 4f2861a376 [image] Revert "clear LOADED flag" patch
Clearing the LOADED flag actually prevents users from doing clever things
such as loading an image, then loading a patch image, then executing the
first image.  (image_exec() checks for IMAGE_LOADED, so this sequence of
operations will fail if the LOADED flag gets cleared.)

This reverts commit 14c080020f.
2008-07-08 03:15:02 +01:00
Michael Brown 14c080020f [image] Clear LOADED flag on all other images when loading a new image
Loading an image may overwrite part or all of any previously-loaded
images, so we should clear the LOADED flag for all images prior to
attempting to load a new image.
2008-07-08 03:03:48 +01:00
Michael Brown 4847d97372 [settings] Allow "config" command to access root settings block 2008-07-08 02:10:18 +01:00
Michael Brown dbe9269f3a [bzimage] Kill off the initrd image type
We can just treat all non-kernel images as initrds, which matches our
behaviour for multiboot kernels.  This allows us to eliminate initrd as
an image type, and treat the "initrd" command as just another synonym for
"imgfetch".
2008-07-08 01:30:11 +01:00
Michael Brown 2df682c5be [dhcp] Allow DHCP non-option settings to be cleared
dhcppkt_store() is supposed to clear the setting if passed NULL for the
setting data.  In the case of fixed-location fields (e.g. client IP
address), this requires setting the content of the field to all-zeros.
2008-07-08 01:13:59 +01:00
Michael Brown 3ad348e55a [phantom] Add support for NetXen Phantom NICs 2008-07-04 19:38:14 -07:00
Michael Brown 227bb05a50 [tftp] Strip the initial '/' to keep Windows TFTP servers happy. 2008-07-02 15:01:25 -07:00
Michael Brown 4fbbf651d7 [i386] Change semantics of __from_data16 and __from_text16
__from_data16 and __from_text16 now take a pointer to a
.data16/.text16 variable, and return the real-mode offset within the
appropriate segment.  This matches the use case for every occurrence
of these macros, and prevents potential future bugs such as that fixed
in commit d51d80f.  (The bug arose essentially because "&pointer" is
still syntactically valid.)
2008-06-30 18:52:13 -07:00
Michael Brown d51d80f785 [pxe] Fix a typo in PXENV_GET_CACHED_INFO that broke Altiris
__from_data16 takes the value pointed to, rather than the pointer
itself.  This was silently causing gPXE to return a dud buffer pointer
when the caller did not supply a buffer for PXENV_GET_CACHED_INFO.
2008-06-30 18:35:51 -07:00
Michael Brown fdb8481de1 [dhcp] Verify server identifier on ProxyDHCPACKs
Perform the same test for a matching DHCP_SERVER_IDENTIFIER on
ProxyDHCPACKs as we do for DHCPACKs.  Otherwise, a retransmitted
DHCPACK can end up being treated as the ProxyDHCPACK.

I have a vague and unsettling memory that this test was deliberately
omitted, but I can't remember why, and can't find anything in the VC
logs.
2008-06-30 17:56:37 -07:00
H. Peter Anvin 25450dc59c [Config] remove src/Config
Remove src/Config as it has no more users, and conflicts with
src/config on case-deficient filesystems.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-06-30 12:26:13 -07:00
H. Peter Anvin 1152b78ec1 [ns8390] Use stub files instead of src/Config
ns8390.c can produce four different drivers (one PCI, three ISA.)  The
ISA driver requires setting a few macros; do that by setting defines
in stub files instead of using src/Config.

Currently, all the ISA drivers are broken (they were not enabled by
default), so #if 0 them out.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-06-30 12:26:12 -07:00
Stefan Hajnoczi 1719b105cd [lkrnprefix] Make gPXE .lkrn images conform to the zImage 2.07 format 2008-06-30 19:53:28 +01:00
Stefan Hajnoczi ce51128534 [bzImage] Support loading zImage kernels
zImage kernels require the real-mode portion to be loaded at 9000:0000
rather than 1000:0000.
2008-06-30 19:51:41 +01:00
Stefan Hajnoczi e9e1da131a [GDB] Provide functions to manually enter GDB stub. 2008-06-30 19:19:48 +01:00
Stefan Hajnoczi 7eb555a8ae [GDB] Obey flow control when GDB connects. 2008-06-30 19:19:48 +01:00
Stefan Hajnoczi fe79edfc3d [GDB] Remove unused DR6 debug register variable 2008-06-30 19:19:48 +01:00
Stefan Hajnoczi 578b056730 [GDB] UDP clean up and add netdev refcnt 2008-06-30 19:19:48 +01:00
Stefan Hajnoczi 3715c8c721 [GDB] Zero-extend 16-bit segment registers
When the 16-bit segment registers are accessed using 32-bit instructions
the high order bytes are undefined on older CPUs.  We now explicitly
zero the high order bytes when snapshotting the CPU state.  This ensures
that the GDB stub reports consistent values for the segment registers.
2008-06-30 19:19:48 +01:00
Stefan Hajnoczi 5504fa9047 [GDB] Add copyright header for gdbmach.c 2008-06-30 19:19:48 +01:00
Stefan Hajnoczi 19386ec2c8 [GDB] Add watch and rwatch hardware watchpoints 2008-06-30 19:19:48 +01:00
Stefan Hajnoczi 6e670b5f38 [GDB] Remote debugging over UDP
This commit implements GDB over UDP.  Using UDP is more complex than
serial and has required some restructuring.

The GDB stub is now built using one or both of GDBSERIAL and GDBUDP
config.h options.

To enter the debugger, execute the gPXE shell command:
gdbstub <transport> [<options>...]

Where <transport> is "serial" or "udp".  For "udp", the name of a
configured network device is required:
gdbstub udp net0

The GDB stub listens on UDP port 43770 by default.
2008-06-30 19:19:48 +01:00
Stefan Hajnoczi 9ec3ff95f0 [GDB] Atomic read/write for device memory 2008-06-30 19:19:48 +01:00
Stefan Hajnoczi 59b5465b30 [GDB] Handle kill and detach packets.
This commit also includes a test to ensure that single stepping works,
since continue, kill, detach, and single step all share code.
2008-06-30 19:19:48 +01:00
Michael Brown 27731d975e [romprefix] Fix PMM detection start address
Commit fd0aef9 introduced a typo that caused PMM detection to start at
paragraph 0xe00 rather than 0xe000.  (Detection would still work, since it
would scan until it ran out of base memory, but it would end up scanning
an unnecessarily large portion of base memory.)

Spotted by Sebastian Herbszt <herbszt@gmx.de>.
2008-06-28 23:18:11 +01:00
Michael Brown 4c75e9ded4 [nvs] Add support for ST M25P32 SPI flash devices 2008-06-27 14:39:25 -07:00
Michael Brown 2596a9aa9c [misc] Fix building on OpenBSD
OpenBSD throws compiler warnings that we can't reproduce on Linux, for
some reason.

Original patch from Dewey Hylton <dewey@hyltown.com>.
2008-06-27 22:35:26 +01:00
H. Peter Anvin b7882065f5 [a20] Send a null command to the KBC after changing A20
Send a null command, specifically "pulse outputs" with no outputs
selected, to the KBC after changing A20.  This was apparently done by DOS,
presumably as a synchronization hack, and the authors of the UHCI spec
thought it was inherent.  Therefore, there are systems out there (e.g. HP
DL360 G5) which will stop responsing to "legacy USB" unless they see the
null command, 0xFF, written to port 0x64 at the end of the A20 toggling
sequence.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-06-27 22:29:13 +01:00
Michael Brown 2b9e7a4767 [libc] Remove unused le32_to_cpup(x) and cpu_to_le16p() macros
If we ever need these macros, they should be defined in
include/{big,little}_bswap.h, and the whole family should be defined.
2008-06-27 22:12:44 +01:00
Steven Walter 14fe4d4ba5 [tg3] Recognize the BCM5789
Add an entry to tg3_nics for the BCM5789

Signed-off-by: Steven Walter <stevenrwalter@gmail.com>
2008-06-27 22:12:43 +01:00
Michael Brown ddf5c8d4d3 [cmdline] Fix image command-line construction for zero-length argument lists
This fixes a bug introduced in commit 4c85017.
2008-06-27 21:50:18 +01:00
Michael Brown 0ea821c7b7 [script] Remove arbitrary limit on script line lengths 2008-06-18 00:43:58 +01:00
Michael Brown 0d91c37ce5 [legacy] Align legacy drivers' __shared data to the maximum possible
Some drivers that still use the legacy-driver wrapper (tg3 in particular)
apparently do not specify their alignment constraints properly.  This
hack forces any __shared data to be maximally aligned.

Note that this provides only 16-byte alignment; it is not possible to
request alignment to any greater than 16 bytes using
__attribute__((aligned)), since the relocation code will preserve only 16
byte alignment (and operation under -DKEEP_IT_REAL cannot preserve more
that 16 byte alignment).

Idea proposed by Tim Hockin <thockin@google.com>
2008-06-14 20:01:14 +01:00
Michael Brown cd0e9bcd22 [prefix] When we have to hook INT 19, chain to original handler if possible
When the BIOS doesn't support BBS, hooking INT 19 is the only way to add
ourselves as a boot device.  If we have to do this, we should at least
try to chain to the original INT 19 vector if our boot fails.

Idea suggested by Andrew Schran <aschran@google.com>
2008-06-14 13:49:26 +01:00
Stefan Hajnoczi a71b4df1c9 [via-rhine] Fix erroneous uses of memory I/O instead of port I/O 2008-06-12 15:21:42 +01:00
Michael Brown 31c6df5365 [cleanup] Remove long-obsolete gpxe/async.h header file 2008-06-12 13:15:53 +01:00
Michael Brown ac28d054c8 [bzimage] Support kernel command lines of greater than 256 characters
2.6.22+ kernels have an extra field in the bzimage_header structure to
indicate the maximum permitted command-line length.  Use this if it is
available.
2008-06-12 02:19:10 +01:00
Michael Brown 4c85017968 [cmdline] Remove arbitrary limit on the length of image command lines 2008-06-12 02:12:10 +01:00
Michael Brown 031b30898a [smbios] Fix SMBIOS string fetching
A bug in read_smbios_string() was causing the starting offset of the
SMBIOS structure to be added twice, resulting in completely the wrong
strings being returned.

Bug identified by Martin Herweg <m.herweg@gmx.de>
2008-06-11 13:43:58 +01:00
Michael Brown c3811d4a13 [slam] Add support for SLAM window lengths of greater than one packet
Add the definition of SLAM_MAX_BLOCKS_PER_NACK, which is roughly
equivalent to a TCP window size; it represents the maximum number of
packets that will be requested in a single NACK.

Note that, to keep the code size down, we still limit ourselves to
requesting only a single range per NACK; if the missing-block list is
discontiguous then we may request fewer than SLAM_MAX_BLOCKS_PER_NACK
blocks.
2008-06-11 13:16:02 +01:00
Michael Brown 50810955e9 [console] Call cpu_nap() only if there is no input waiting
Avoid calling cpu_nap() until after we have determined that there is
no input ready to read.  This avoids delaying for one timer interrupt
(~50ms) in the case of

  if ( iskey() )
     char = getkey()

which happens to be present in monojob.c, which is where we spend most
of our time looping (e.g. during any download).

This should eliminate the irritating tendency of gPXE to lose
keypresses.

Discovered on a Dell system where the serial port seems to send in a
constant stream of 0xff characters; this wouldn't be a problem in
itself except that each one triggers the 50ms delay (as mentioned
above), which really kills performance.
2008-06-11 12:06:10 +01:00
Michael Brown 5d36ec6721 [slam] Implement SLAM flow control
On any fast network, or with any driver that may drop packets
(e.g. Infiniband, which has very small RX rings), the traditional
usage of the SLAM protocol will result in enormous numbers of packet
drops and a consequent large number of retransmissions.

By adapting the client behaviour, we can force the server to act more
like a multicast TFTP server, with flow control provided by a single
master client.

This behaviour should interoperate with any traditional SLAM client
(e.g. Etherboot 5.4) on the network.  The SLAM protocol isn't actually
documented anywhere, so it's hard to define either behaviour as
compliant or otherwise.
2008-06-11 09:41:31 +01:00
Michael Brown 32e8ab4df0 [retry] Add start_timer_fixed()
Allow for timers to be started with fixed timeouts.
2008-06-11 09:37:58 +01:00
Michael Brown 3a2c8a2690 [dhcp] Do not transition to DHCPREQUEST without a valid DHCPOFFER
A missing test for dhcp->dhcpoffer in dhcp_timer_expired() was causing
the client to transition to DHCPREQUEST after timing out on waiting
for ProxyDHCP even if no DHCPOFFERs had been received.
2008-06-11 06:20:49 +01:00
Michael Brown 2456b9b4ba [slam] Request all remaining blocks if we run out of space for the blocklist
In a SLAM NACK packet, if we run out of space to represent the
missing-block list, then indicate all remaining blocks as missing.
This avoids the need to wait for the one-second timeout before
receiving the blocks that otherwise wouldn't have been requested due
to running out of space.
2008-06-10 12:36:39 +01:00
Michael Brown 1e5c2d48cb [slam] Speed up NACK transmission by restricting the block-list length
Shorter NACK packets take less time to construct and spew out less
debug output, and there's a limit to how useful it is to send a
complete missing-block list anyway; if the loss rate is high then
we're going to have to retransmit an updated missing-block list
anyway.

Also add pretty debugging output to show the list of requested blocks.
2008-06-10 11:23:34 +01:00
Michael Brown 81d92d5181 [slam] Fix multicast address parsing
slam_parse_multicast_address() was failing to strip the initial "/"
from the URI path.
2008-06-10 10:04:02 +01:00
Michael Brown 798ddf884f [undi] Ask for promiscuous packet reception when using UNDI driver
We never set up specific multicast filters; native drivers will ask
the card to receive all multicast packets.  The only way to achieve
this via the UNDI API is to enable promiscuous mode.
2008-06-10 08:56:44 +01:00
Michael Brown 72c1bb8224 [slam] Add Scalable Local Area Multicast (SLAM) protocol support
Tested against the mini-slamd server located in contrib/mini-slamd
with a single client, on a lossy network.
2008-06-10 00:04:19 +01:00
Michael Brown aa160211c2 [udp] Verify local socket address (if specified) for UDP sockets
UDP sockets can be used for multicast, at which point it becomes
plausible that we could receive packets that aren't destined for us
but that still match on a port number.
2008-06-10 00:01:29 +01:00
Michael Brown 77a5cc6b13 [ELF] Add ability to boot ELF images generated by wraplinux and mkelfImage
Delete ELF as a generic image type.  The method for invoking an
ELF-based image (as well as any tables that must be set up to allow it
to boot) will always depend on the specific architecture.  core/elf.c
now only provides the elf_load() function, to avoid duplicating
functionality between ELF-based image types.

Add arch/i386/image/elfboot.c, to handle the generic case of 32-bit
x86 ELF images.  We don't currently set up any multiboot tables, ELF
notes, etc.  This seems to be sufficient for loading kernels generated
using both wraplinux and coreboot's mkelfImage.

Note that while Etherboot 5.4 allowed ELF images to return, we don't.
There is no callback mechanism for the loaded image to shut down gPXE,
which means that we have to shut down before invoking the image.  This
means that we lose device state, protection against being trampled on,
etc.  It is not safe to continue afterwards.
2008-06-09 13:50:00 +01:00
Marty Connor fe3162ab1c [Makefile] Add $(BIN)/undionly.kpxe as default build target 2008-06-09 08:44:11 -04:00
Marty Connor db5f64ecdc [Makefile] Add "+" to end of version string for git-generated images
This "+" should be removed when a tarball release is done.
2008-06-06 16:40:16 -04:00
Michael Brown b5215803f0 [Makefile] Use .PRECIOUS instead of .SECONDARY for bin/%.tmp targets
Revert "Use .SECONDARY instead of .PRECIOUS for bin/%.tmp targets."

This reverts commit de29e5a39c.

.SECONDARY doesn't seem to work properly with the target patterns of
implicit rules.  In particular, a "make clean ; make bin/rtl8139.dsk"
will correctly leave the bin/rtl8139.dsk.tmp file present when .PRECIOUS
is used, but not when .SECONDARY is used.

This is slightly irritating since we don't want the
"do-not-delete-if-interrupted" semantics of .PRECIOUS, but it seems to be
the best compromise.
2008-06-06 14:25:25 +01:00
Michael Brown 5102033215 [DHCP] Add "dhcp-server" setting to help end-user diagnostics 2008-06-05 15:43:34 +01:00
Stefan Hajnoczi 4180815a90 [GDB] Test suite for the GDB stub 2008-06-05 00:45:51 +01:00
Stefan Hajnoczi 04bc50f025 [GDB] Add GDB stub for remote debugging
See http://etherboot.org/wiki/dev/gdbstub for documentation.
2008-06-05 00:45:50 +01:00
Stefan Hajnoczi 831db76ff7 [Serial] Split serial console from serial driver 2008-06-05 00:45:43 +01:00
Stefan Hajnoczi f866b17998 [util] config-local.h to avoid accidental commits
During development it is often handy to change the config.h options from
their defaults, for example to enable debugging features.

To prevent accidental commits of debugging config.h changes, mdc
suggested having a config-local.h that is excluded from source control.
This file acts as a temporary config.h and can override any of the
defaults.

This commit is an attempt to implement the config-local.h feature.

The config.h file now has the following as its last line:
/* @TRYSOURCE config-local.h */

The @TRYSOURCE directive causes config-local.h to be included at that
point in the file.  If config-local.h does not exist, no error will be
printed and parsing will continue as normal.  Therefore, mkconfig.pl is
"trying" to "source" config-local.h.
2008-06-05 00:45:33 +01:00
Stefan Hajnoczi 842165ef76 [GDBSYM] Remove unused gdbsym.c
The GDBSYM config.h option was an attempt at QEMU GDB debugging.  I have
removed the code since it is unused and may confuse people wanting to
use the GDB stub.
2008-06-05 00:45:32 +01:00
Michael Brown 1a68d3fef3 [TCP] Avoid shrinking TCP window
Maintain state for the advertised window length, and only ever increase
it (instead of calculating it afresh on each transmit).  This avoids
triggering "treason uncloaked" messages on Linux peers.

Respond to zero-length TCP keepalives (i.e. empty data packets
transmitted outside the window).  Even if the peer wouldn't otherwise
expect an ACK (because its packet consumed no sequence space), force an
ACK if it was outside the window.

We don't yet generate TCP keepalives.  It could be done, but it's unclear
what benefit this would have.  (Linux, for example, doesn't start sending
keepalives until the connection has been idle for two hours.)
2008-06-05 00:28:17 +01:00
Michael Brown d615b00443 [embed] Add missing register_image() to image/embedded.c
When the embedded image is a script, the unregister_image() performed by
image/script.c corrupts memory, since image/embedded.c omitted the call
to register_image().

This is the first bug fixed using Stefan Hajnoczi's gdb stub for gPXE.
2008-06-04 00:02:23 +01:00
Michael Brown 75965c9c6e [iSCSI] Produce meaningful errors on login failure
Return the most appropriate of EACCES, EPERM, ENODEV, ENOTSUP, EIO or
EINVAL depending on the exact error returned by the target, rather than
just always returning EPERM.

Also, ensure that error strings exist for these errors.
2008-06-03 23:47:20 +01:00
Michael Brown c899bdc5a8 [Makefile] Remove obsolete SRCDIRS 2008-05-23 02:35:20 +01:00
Michael Brown 7cd08434ea [prefix] Prompt for entering gPXE shell during POST
The ROM prefix now prompts the user to enter the gPXE shell during POST;
this allows for configuring gPXE without needing to attempt to boot from
it.  (It also slows down system boot by three seconds per gPXE ROM, but
hey.)

This is apparently a certain OEM's requirement for option ROMs.
2008-05-22 15:14:33 +01:00
Michael Brown fd0aef9ee1 [prefix] Add PCI bus:dev.fn to ROM product string
This allows multiple gPXE ROMs in a system to be disambiguated at boot
time; the PCI ID will show up in the boot menu for a BBS-compliant BIOS.
2008-05-21 18:43:58 +01:00
Stefan Hajnoczi f3aef4d98d [Contribs] Fix multi-line POSIX errno definitions. 2008-05-20 20:29:33 +01:00
Stefan Hajnoczi 711a59cf03 [Contribs] Fix parsing bug in errcode.py
Make sure parser doesn't choke on line with space at end.
2008-05-20 20:29:24 +01:00
Stefan Hajnoczi f43a7e349a [Contribs] Add simple IRC bot for looking up error codes. 2008-05-20 20:28:57 +01:00
Stefan Hajnoczi fbf9295cbb [Contribs] Add README, license text, and invert error code dictionaries. 2008-05-20 20:28:48 +01:00
Stefan Hajnoczi ce298a9628 [Contribs] Add a web interface for looking up error codes.
Add a PHP script to act as a web interface for looking up error codes.
2008-05-20 20:27:52 +01:00
Stefan Hajnoczi 43b04236ec [Contribs] Add command-line utility for looking up gPXE error codes. 2008-05-20 20:26:44 +01:00
Michael Brown 30cd348689 [SMBIOS] Interpret UUIDs as being in network-endian order
Various specification documents disagree about the byte ordering of
UUIDs.  However, SMBIOS seems to use the standard in which everything is
in network-endian order.

This doesn't affect anything sent on the wire; only what gets printed on
the screen when the "uuid" variable is displayed.
2008-05-20 18:41:36 +01:00
Michael Brown 7d01bf663e [libc] Fix isdigit(), islower() and isupper().
From: Stefan Hajnoczi <stefanha@gmail.com>
2008-05-19 16:34:17 +01:00
Michael Brown 78281b09e6 [tg3] Add support for tg3-5721
From: Daniel Mealha Cabrita <dancab@utfpr.edu.br>

I've added tg3-5721 support for gPXE, the patch (against gpxe-0.9.3) is
attached to this message.

This chipset is present in HP ML150 G2 servers (possibly other HP machines
as well).
2008-05-19 16:22:13 +01:00
Michael Brown 1dcc60e5ad [IPv4] Fix multicast address checking
From: Viswanath Krishnamurthy <viswa.krish@gmail.com>

The current ipv4 incorrectly checks the IP address for multicast address.
This causes valid IPv4 unicast address to be trated as multicast address

For e.g if the PXE/tftp server IP address is 192.168.4.XXX where XXX is
224 or greater, it gets treated as multicast address and a ethernet
multicast address is sent out on the wire causing timeouts
2008-05-19 16:19:46 +01:00
Michael Brown 00ed567069 [iSCSI] Offer CHAP authentication only if we have a username and password
Some EMC targets will fail if we advertise that we can authenticate with
CHAP, but the target is configured to allow unauthenticated access to that
target.  We advertise AuthMethod=CHAP,None; the target should (I think)
select AuthMethod=None for unprotected targets.  IETD does this, but an
EMC Celerra NS83 doesn't.

Fix by offering only AuthMethod=None if the user hasn't supplied a
username and password; this means that we won't be offering CHAP
authentication unless the user is expecting to use it (in which case the
target is presumably configured appropriately).

Many thanks to Alessandro Iurlano <alessandro.iurlano@gmail.com> for
reporting and helping to diagnose this problem.
2008-04-24 13:48:29 +01:00
Michael Brown eec9814a0e [Makefile] Quick hack: always define pci_{vendor,device}_id
ROMs will refuse to build unless pci_vendor_id and pci_device_id are
defined.  We probably ought to fix up the Makefile (and the ROM prefix) so
that they're required only for PCI ROMs, but this will do for now.
2008-04-23 16:24:00 +01:00
Michael Brown 3430226d40 [MTNIC] Minor cleanups of vendor-provided driver for Mellanox 10GigE cards
Drivers are not allowed to call printf().  Converted eprintf() to DBG(),
and removed spurious startup banner.

Fixed hardcoded inclusion of little_bswap.h

Use EIO rather than 1 as an error number.
2008-04-22 17:50:30 +01:00
Michael Brown 1ba959c6b3 [NETDEV] Add notion of link state
Add ability for network devices to flag link up/down state to the
networking core.

Autobooting code will now wait for link-up before attempting DHCP.

IPoIB reflects the Infiniband link state as the network device link state
(which is not strictly correct; we also need a succesful IPoIB IPv4
broadcast group join), but is probably more informative.
2008-04-22 17:40:50 +01:00
Michael Brown d72bf13b78 [Infiniband] Fix event queue doorbell ringing on Arbel 2008-04-22 02:18:32 +01:00
Michael Brown c9fb012d4f [Infiniband] Add multiport support for Arbel cards 2008-04-22 01:37:00 +01:00
Michael Brown 35a5836677 [Infiniband] Move event-queue process from driver to Infiniband core 2008-04-21 13:23:11 +01:00
Michael Brown e55bab3ce3 [Hermon] Fix event queue doorbells.
Event queue doorbells must use UAR pages 0-127 depending on event queue
number; other doorbells must use pages 128+ (and we choose to use page
128).
2008-04-18 05:33:39 +01:00
Michael Brown a176a24ac0 [Infiniband] Add preliminary multiple port support for Hermon cards
Infiniband devices no longer block waiting for link-up in
register_ibdev().

Hermon driver needs to create an event queue and poll for link-up events.

Infiniband core needs to reread MAD parameters when link state changes.

IPoIB needs to cope with Infiniband link parameters being only partially
available at probe and open time.
2008-04-18 02:50:48 +01:00
Michael Brown 3475b693b7 [HCI] Display "Not an executable image" when appropriate
PXE is a catch-all image format with no signature checks.  If an
unsupported image file is loaded, it will be treated as a PXE image.  In
most cases, the image will be too large to be loaded as a PXE image (which
has to fit in base memory), so the error returned to the user will be that
the segment could not fit within the memory region.

Add an explicit check to pxe_image.c to reject images larger than base
memory with ENOEXEC.

Add ENOEXEC to the error string table.
2008-04-08 16:28:00 +01:00
Marty Connor fbb6a3fd65 [Drivers-r8169] Add support for newer rtl8169 variants from Hilko Bengen
03-19-2008, Hilko Bengen, Cleanups and fixes for newer cards
(successfully tested with 8110SC-d onboard NIC)
2008-03-31 09:14:23 -04:00
H. Peter Anvin b107637008 [http] gPXE is a HTTP/1.0 client, not a HTTP/1.1 client
gPXE is not compliant with the HTTP/1.1 specification (RFC 2616),
since it lacks support for "Transfer-Encoding: chunked".  gPXE is,
however, compliant with the HTTP/1.0 specification (RFC 1945), which
does not require "Transfer-Encoding: chunked" to be supported.

The only HTTP/1.1 feature that gPXE uses is the "Host:" header, but
servers universally accept that one from HTTP/1.0 clients as an
optional extension (it is obligatory for HTTP/1.1).  gPXE does not,
for example, appear to support connection caching.  Advertising as a
HTTP/1.0 client will typically make the server close the connection
immediately upon sending the last data, which is actually beneficial
if we aren't going to keep the connection alive anyway.
2008-03-31 05:01:08 -07:00
Michael Brown feade5da6e [Settings] Expose SMBIOS via settings API
In particular, expose the system UUID as a setting ("smbios/uuid").
2008-03-28 15:35:06 +00:00
Michael Brown aa74a7d53c [DHCP] Add support for ProxyDHCP requests
The PXE spec is (as usual) unclear on precisely when ProxyDHCPREQUESTs
should be issued.  We adapt the following, slightly paranoid approach:

  If an offer contains an IP address, then it is a normal DHCPOFFER.

  If an offer contains an option #60 "PXEClient", then it is a
  ProxyDHCPOFFER.  Note that the same packet can be both a normal
  DHCPOFFER and a ProxyDHCPOFFER.

  After receiving the normal DHCPACK, if we have received a
  ProxyDHCPOFFER, we unicast a ProxyDHCPREQUEST back to the ProxyDHCP
  server on port 4011.  If we time out waiting for a ProxyDHCPACK, we
  treat this as a non-fatal error.
2008-03-27 16:45:15 +00:00
Michael Brown af466aedf1 [Settings] find_child_settings() accepts a NULL parent 2008-03-27 06:07:19 +00:00
Michael Brown 7a4e212fe2 [DHCP] Treat empty fields in DHCP packets as non-existent.
This avoids confusing other code by insisting that we have e.g. a
filename consisting of 128 zero bytes.
2008-03-27 06:06:36 +00:00
Michael Brown 978996cdae [usr] Offer user a second chance to enter the shell on boot failure 2008-03-26 23:16:20 +00:00
Michael Brown 4b267ed713 [libc] Whitespace cleanup in errno.h 2008-03-26 22:57:25 +00:00
H. Peter Anvin d810dc5be2 [PXEXT] Update documentation
Add documentation for the FILE_EXEC and FILE_CHECK_API extension
calls, and update the documentation for the FILE_READ call.
2008-03-26 15:14:55 -07:00
H. Peter Anvin 61ee294875 [PXEXT] Change the PXE return code for EWOULDBLOCK
Change the PXE return code for EWOULDBLOCK from PXENV_STATUS_FAILURE
to PXENV_STATUS_TFTP_OPEN.  This code is only used by the FILE_READ
PXEXT call, and is necessary to distinguish "error" from "no data" in
that call.

(The only other nonblocking call is UDP_READ, where the caller doesn't
care about the distinction, however, gPXE doesn't use EWOULDBLOCK
internally to represent this condition in that code.)
2008-03-26 15:12:19 -07:00
H. Peter Anvin d62e89d776 [PXEXT] Add FILE_API_CHECK API function
Add FILE_API_CHECK to the PXEXT API so the NBP can query the
availability and status of the API.
2008-03-26 15:10:56 -07:00
Michael Brown 83617e5b1c [DHCP] Save precious packet-aligned memory by copying DHCP responses
Copy DHCP responses to a standard malloc()ed buffer, rather than
retaining the I/O buffer that they arrived in.
2008-03-26 12:25:59 +00:00
Michael Brown 96edbd128f [PXEXT] Avoid queueing zero-length buffers in posix_io.c
read_user() assumes that zero-length buffers don't exist, and optimises
around this.
2008-03-25 21:10:21 +00:00
Michael Brown 92d15eff30 [Settings] Remove assumption that all settings have DHCP tag values
Allow for settings to be described by something other than a DHCP option
tag if desirable.  Currently used only for the MAC address setting.

Separate out fake DHCP packet creation code from dhcp.c to fakedhcp.c.

Remove notion of settings from dhcppkt.c.

Rationalise dhcp.c to use settings API only for final registration of the
DHCP options, rather than using {store,fetch}_setting throughout.
2008-03-25 20:46:16 +00:00
Michael Brown ee5bdb0d75 [PXEXT] Avoid returning a false EOF when we have an empty buffer queued 2008-03-25 20:29:42 +00:00
Michael Brown 7234f91bf8 [DHCP] Fix DHCP state confusion.
DHCP code was using an incorrect check for whether to construct a
DHCPDISCOVER or DHCPREQUEST packet.
2008-03-25 16:38:01 +00:00
Michael Brown 8f00c84828 [Settings] Add named setting for next-server
It's probably easier to have a named setting for next-server, rather
than to explain to people why they need to pretend it is option 175.3.
2008-03-24 00:48:06 +00:00
Michael Brown c06e6d0635 [Makefile] Use -MM instead of -M in dependency generation
Using -MM strips out any system header files from the dependency list,
which means that we could safely use an external stdarg.h if we wanted
to.
2008-03-24 00:28:55 +00:00
Michael Brown dbf8a02e8f [libc] Use __builtin_va_list et al in stdarg.h
The home-grown versions don't work properly for static variadic
functions, when gcc can choose to use a non-standard calling convention.
2008-03-24 00:23:11 +00:00
Michael Brown 23e077666b [Settings] copy_settings() should not fail if some settings are missing! 2008-03-23 23:28:21 +00:00
Michael Brown 978865da2f [IPv4] Use default netmasks when no subnet mask is specified. 2008-03-23 22:20:47 +00:00
Michael Brown 2af6c8d130 [IPv4] Tidy up some header files. 2008-03-23 22:05:47 +00:00
Michael Brown ee4206a8a7 [DHCP] Fix up fake-packet creation as used by PXENV_GET_CACHED_INFO
Add dedicated functions create_dhcpdiscover(), create_dhcpack() and
create_proxydhcpack() for use by external code such as the PXE preboot
code.

Register ProxyDHCP options under the global scope "proxydhcp".

Unregister previously-acquired DHCP and ProxyDHCP settings when DHCP
succeeds.
2008-03-23 21:58:05 +00:00
Marty Connor 1741e3e761 [DHCP] FIXME: quick temporary settings fix, needs update for new API 2008-03-21 23:37:02 -04:00
Michael Brown 8fceee785f Merge branch 'master' of rom.etherboot.org:/pub/scm/gpxe 2008-03-22 00:50:06 +00:00
Michael Brown 65c0974d1f [Settings] Bugfix: store_setting() now applies changes even on root block 2008-03-22 00:40:33 +00:00
Michael Brown e5cea13e51 [Settings] Implement simple_settings backed with extensible DHCP options 2008-03-22 00:31:08 +00:00
Michael Brown a462c96ffc [Settings] DHCP is now working using the new settings API. 2008-03-21 22:55:59 +00:00
Michael Brown 8afb36c3bc [Settings] Migrate DHCP and NVO code to the new settings API (untested) 2008-03-21 22:15:31 +00:00
Michael Brown bb32b8999c [DHCP] Kill off some no-longer-used DHCP functions 2008-03-21 00:50:12 +00:00
Michael Brown a9b62cfe8c [Settings] Use a settings applicator in ibft.c 2008-03-21 00:49:44 +00:00
Michael Brown 1edbcd4246 [Settings] Use a settings applicator to set the default TFTP URI. 2008-03-21 00:26:29 +00:00
Michael Brown 720e256c50 [Misc] Kill off long-redundant tests/dhcptest.c 2008-03-21 00:07:36 +00:00
Michael Brown 0fbe484566 [IPv4] Add a config option for IPv4
IPv4 may not always be dragged into the link, so add a specific
configuration option for it.
2008-03-21 00:06:28 +00:00
Michael Brown aec9b8a41b [Settings] Use a settings applicator to configure IPv4 routes. 2008-03-21 00:01:27 +00:00
Michael Brown eae6ac3d0b [Settings] Convert code in src/usr to use settings API. 2008-03-20 23:42:11 +00:00
Michael Brown cf03304620 [Settings] Introduce settings applicators.
Convert DHCP option applicators in dns.c and iscsi.c to settings
applicators.

Kill off DHCP option applicators.
2008-03-20 23:15:48 +00:00
Michael Brown acfa14423e [Settings] Add per-netdevice settings block
Add a configuration settings block for each net device.  This will
provide the parent scope for settings applicable only to that network
device (e.g. non-volatile options stored on the NIC, options obtained via
DHCP, etc.).

Expose the MAC address as a setting.
2008-03-20 21:06:53 +00:00
Michael Brown 260b93bb72 [Settings] Add settings hierarchy
Add the notion of the settings hierarchy, complete with
register/unregister routines.

Rename set->store and get->fetch to avoid naming conflicts with get/put
as used in reference counting.
2008-03-20 21:01:32 +00:00
Michael Brown a48b4d9948 [Settings] Start revamping the configuration settings API.
Add the concept of an abstract configuration setting, comprising a (DHCP)
tag value and an associated byte sequence.

Add the concept of a settings namespace.

Add functions for extracting string, IPv4 address, and signed and
unsigned integer values from configuration settings (analogous to
dhcp_snprintf(), dhcp_ipv4_option(), etc.).

Update functions for parsing and formatting named/typed options to work
with new settings API.

Update NVO commands and config UI to use new settings API.
2008-03-20 04:06:07 +00:00
Marty Connor e97ae4a788 ]Drivers] Update licensing for cs89x0.[ch] and cs89x0.txt
Russ Nelson sent an email requesting the license change to
GPL Version 2.
2008-03-18 22:31:26 -04:00
Michael Brown 7067142fb4 [Contribs] Add updated wake-on-LAN patch from Bill <level42@sympatico.ca> 2008-03-19 01:08:38 +00:00
Michael Brown af1c6b869c [Settings] Allow named settings to have their type specified explicitly
Allow setting names such as "ip:hex".
2008-03-18 15:51:03 +00:00
Michael Brown 070cbebc26 [Timers] Initialise timers on first use
Timers are sometimes required before the call to initialise(), so we
cannot rely on initialise() to set up the timers before use.

Also fix a potential integer overflow issue in generic_currticks_udelay()
2008-03-18 15:23:10 +00:00
Michael Brown 2652abdc5f [Timers] Miscellaneous timer system fixes
Add missing comments to timer code.

Lock system if no suitable timer source is found.

Fix initialisation order so that timers are initialised before code that
needs to use them.
2008-03-18 14:48:28 +00:00
Michael Brown 03398e3389 [Settings] Allow encapsulated options to be specified as named settings
Allow encapsulated options to be specified as e.g. "175.3".  As a
side-effect, change the separator character for the type field from "." to
":"; for example, the IP address pseudo-option is now "175.3:ipv4".
2008-03-18 04:13:11 +00:00
Michael Brown e2613e8896 [Settings] Add int16, int32 and hex-string configuration setting types
Add parse and display routines for 16-bit and 32-bit integer configuration
settings.

Add parse and display routines for hex-string configuration settings.

Assume hex-string as a configuration setting type if no type is explicitly
specified.
2008-03-18 03:23:36 +00:00
Michael Brown 6fe585642a [libc] Fix a validation bug in strtoul()
strtoul() was accepting the characters immediately above ASCII 0..9 as
valid hex digits, due to a missing comparison.
2008-03-18 03:14:05 +00:00
Michael Brown 5a08b434c7 [Settings] show_setting() functions return snprintf()-style length.
show_setting() and related functions now return an "actual length" in the
style of snprintf().  This is to allow consumers to allocate buffers large
enough to hold the formatted setting.
2008-03-18 00:48:23 +00:00
Michael Brown 08b19abf94 Merge branch 'pxerom-pmm' 2008-03-11 16:11:51 +00:00
Michael Brown 66d9a411f7 [PXE] PMM now tested and working
Minor bugfix: 4 x 2 = 8, not 16
2008-03-11 16:08:04 +00:00
Michael Brown 3bf7105cab [prefix] Cope with image source addresses outside base memory
When PMM is used, the gPXE image source will no longer be in base memory.
Decompression of .text16 and .data16 can therefore no longer be done in
real mode.
2008-03-11 13:26:46 +00:00
Michael Brown 9c86a39551 [PXE] Improve PnP/BBS detection
Use BBS installation check to see if we need to hook INT19 even on a PnP
BIOS.

Verify that $PnP signature is paragraph-aligned; bochs/qemu BIOS provides
a dummy $PnP signature with no valid entry point, and deliberately
unaligns the signature to indicate that it is not properly valid.

Print message if INT19 is hooked.

Attempt to use PMM even if BBS check failed.
2008-03-11 12:04:38 +00:00
Michael Brown 297002d7bd [prefix] Add printing functions to libprefix.S
Move the printing functions from pxeprefix.S into libprefix.S, so they
are available for debug from any prefix.
2008-03-11 11:32:19 +00:00
Michael Brown 3e781eb87f Merge branch 'xl0-timer' 2008-03-10 13:02:53 +00:00
Michael Brown 1dd3f88964 [PXE] Work around a buffer-size bug in WinPE
WinPE's pxeboot.n12 takes the BufferLimit returned by gPXE (indicating
the size of gPXE's internal DHCP packet buffers) and erroneously passes
it in as BufferSize (indicating the size of pxeboot.n12's DHCP packet
buffer).  If these don't match, then pxeboot.n12 ends up instructing gPXE
to overwrite parts of its data segment.

Change gPXE's internal DHCP packet buffers to be exactly
sizeof(BOOTPLAYER_t) bytes to work around this problem.
2008-03-10 11:46:55 +00:00
Michael Brown 12f203c606 [PXE] Add PMM support to romprefix.S (untested)
ROM initialisation vector now attempts to allocate a 2MB block using
PMM.  If successful, it copies the ROM image to this block, then
shrinks the ROM image to allow for more option ROMs.  If unsuccessful,
it leaves the ROM as-is.

ROM BEV now attempts to return to the BIOS, resorting to INT 18 only
if the BIOS stack has been corrupted.
2008-03-09 22:13:07 +00:00
Michael Brown fad35829eb [Makefile] Use bin/VVVVDDDD.rom instead of bin/pci_VVVV_DDDD.rom
The generate-by-PCI-device-ID rules (bin/pci_VVVV_DDDD.rom) are generally
used for building actual ROM images to be burned, and the burning
utilities generally run under some DOS variant.  Change the filename from
pci_VVVV_DDDD.rom to VVVVDDDD.rom so that it is compatible with the DOS
8.3-character filename limit.
2008-03-06 15:37:34 +00:00
Michael Brown 06e8a70488 [tg3] Added device ID for rebranded HP card. 2008-03-06 13:19:42 +00:00
Alexey Zaytsev 8de54ef9aa Use plain C in timer_rdtsc for division instead of inline asssembly.
This also fixes a bug in rdtsc_currticks when the result did not fix in %eax

Signed-off-by: Alexey Zaytsev <zaytsev.a@protei.ru>
2008-03-06 16:06:58 +03:00
Michael Brown b62f2325ba [PXEXT] Add PXENV_FILE_EXEC call to PXE extensions API.
This allows pxelinux to execute arbitrary gPXE commands.  This is
remarkably unsafe (not least because some of the commands will assume
full ownership of memory and do nasty things like edit the e820 map
underneath the calling pxelinux), but it does allow access to the
"sanboot" command.
2008-03-04 18:16:30 +00:00
Michael Brown b08a6f5300 [Command] Add "sanboot" command. 2008-03-04 17:59:26 +00:00
Michael Brown 4704abbc50 [Timers] Move TIMER_BIOS and TIMER_RDTSC to their own config.h section. 2008-03-02 02:33:54 +00:00
Michael Brown 3dd897f986 [Timers] Do not enable serial console by default; this change should not
be propagated to master.
2008-03-02 02:32:12 +00:00
Alexey Zaytsev 1935439f86 fix the rdtsc namimg 2008-03-02 05:19:29 +03:00
Alexey Zaytsev 379c37bafb Cleanups
Replace a printf with a DBG in timer_rtdsc.c
Replace a printf in timer.c with assert
Return proper error codes from timer drivers

Signed-off-by: Alexey Zaytsev <alexey.zaytsev@gmail.com>
2008-03-02 04:36:50 +03:00
Alexey Zaytsev a1572e0ab0 Modify gPXE core and drivers to work with the new timer subsystem
Signed-off-by: Alexey Zaytsev <alexey.zaytsev@gmail.com>
2008-03-02 03:41:10 +03:00
Alexey Zaytsev 4006d229e5 Introduce the new timer subsystem.
Timer subsystem initialization code in core/timer.c

	Split the BIOS and RTDSC timer drivers from i386_timer.c

	Split arch/i386/firmware/pcbios/bios.c into the RTSDC
	timer driver and arch/i386/core/nap.c

	Split the headers properly:
		include/unistd.h - delay functions to be used by the
					gPXE core and drivers.

		include/gpxe/timer.h - the fimer subsystem interface
					to be used by the timer drivers
					and currticks() to be used by
					the code gPXE subsystems.

		include/latch.h	- removed
		include/timer.h - scheduled for removal. Some driver
					are using currticks, which is
					only for core subsystems.

Signed-off-by: Alexey Zaytsev <alexey.zaytsev@gmail.com>
2008-03-02 03:15:07 +03:00
Michael Brown 844828cb15 [DHCP] Fix RFC4390 client identifier constructions.
RFC 4390 provides for the DHCP client identifier to contain the link-layer
hardware type and MAC address when the MAC address exceeds 16 bytes.
However, the hardware type field is only 8 bits; we were assuming 16 bits.
2008-02-27 16:55:46 +00:00
Michael Brown bc3f0a25c6 [Infiniband] Add preliminary support for multi-port devices.
Arbel and Hermon cards both have multiple ports.  Add the
infrastructure required to register each port as a separate IB
device.  Don't yet register more than one port, since registration
will currently fail unless a valid link is detected.

Use ib_*_{set,get}_{drv,owner}data wrappers to access driver- and
owner-private data on Infiniband structures.
2008-02-27 13:59:56 +00:00
Michael Brown 6570203571 [Infiniband] Centralise MAD operations
Pull out common code for handling management datagrams from arbel.c
and hermon.c into infiniband.c.

Add port number to struct ib_device.

Add open(), close() and mad() methods to struct ib_device_operations.
2008-02-26 22:56:19 +00:00
Michael Brown 03d1fc1da3 [Hermon] Donate joint copyright on Hermon driver to Mellanox. 2008-02-23 11:05:46 +00:00
Michael Brown 396dc6e797 [Hermon] Add driver for Mellanox Hermon (ConnectX) cards. 2008-02-23 10:51:38 +00:00
Michael Brown ea5ad4be91 [Infiniband] Fix typo in debug statement 2008-02-23 10:48:18 +00:00
Michael Brown 563955ce37 [Infiniband] Add missing list_del()s in ib_create_qp() failure path. 2008-02-23 10:48:10 +00:00
Michael Brown 604c934981 Add DBGLVL_IO to trace all memory-mapped I/O. 2008-02-21 12:44:09 +00:00
Michael Brown b87904ab20 Remove reference to COFF support. I can find no trace of ever having supported it. 2008-02-21 04:11:56 +00:00
827 changed files with 112712 additions and 37642 deletions
-1
View File
@@ -1 +0,0 @@
0.9.3 2008-02-14
+4 -3
View File
@@ -25,9 +25,10 @@ To get bochs running is fairly simple:
3. Configure bochs with
pushd bochs
./configure --enable-all-optimisations --enable-pci --enable-pnic \
--enable-debugger --enable-magic-breakpoints \
--enable-disasm --enable-show-ips --enable-ne2000
./configure --enable-all-optimisations --enable-show-ips \
--enable-cpu-level=6 \
--enable-pci --enable-pnic --enable-ne2000 \
--enable-debugger --enable-disasm
popd
4. Build bochs:
+13 -21
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,19 +45,18 @@ 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
make bin/rtl8139.dsk
popd
9. Start qemu
export SDL_VIDEO_X11_DGAMOUSE=0
./qemu/i386-softmmu/qemu -L qemu/pc-bios \
-net nic,model=rtl8139 -net tap,ifname=tap0 \
-boot a -fda ../../src/bin/rtl8139.pdsk
-boot a -fda ../../src/bin/rtl8139.dsk
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.
@@ -72,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
+20
View File
@@ -0,0 +1,20 @@
Index: memory/memory.cc
===================================================================
RCS file: /cvsroot/bochs/bochs/memory/memory.cc,v
retrieving revision 1.71
diff -u -r1.71 memory.cc
--- memory/memory.cc 18 Oct 2008 18:10:14 -0000 1.71
+++ memory/memory.cc 21 Oct 2008 19:47:07 -0000
@@ -172,7 +172,11 @@
break;
case 0x0: // Writes to ROM, Inhibit
- BX_DEBUG(("Write to ROM ignored: address 0x" FMT_PHY_ADDRX ", data %02x", a20addr, *data_ptr));
+ if ((a20addr & 0xfffe0000) == 0x000e0000) {
+ BX_DEBUG(("Write to ROM ignored: address 0x" FMT_PHY_ADDRX ", data %02x", a20addr, *data_ptr));
+ } else {
+ BX_MEM_THIS rom[(a20addr & EXROM_MASK) + BIOSROMSZ] = *data_ptr;
+ }
break;
default:
+2 -2
View File
@@ -224,8 +224,8 @@ if ( -t STDIN ) {
$restore_termios = POSIX::Termios->new;
$termios->getattr ( fileno(STDIN) );
$restore_termios->getattr ( fileno(STDIN) );
$termios->setlflag ( $termios->getlflag &
~(ICANON) & ~(ECHO) );
$termios->setlflag ( $termios->getlflag & ~(ICANON) & ~(ECHO) );
$termios->setiflag ( $termios->getiflag & ~(ICRNL) );
$termios->setattr ( fileno(STDIN), TCSANOW );
}
+35
View File
@@ -0,0 +1,35 @@
Error Code Lookup for gPXE
==========================
This program looks up gPXE error codes so you can locate the line of source
code which produced the error.
Setup
-----
You must run:
./build_errcodedb.py >errcodedb.py
This extracts error code definitions from the gPXE source code and produces a
"database" which is used by the main program.
Once you have done this errcode.py and errcodedb.py are the only files you
need. They are now independent of the gPXE source code and can be moved
anywhere.
[OPTIONAL]
A PHP script is provided as a web interface. First edit errcode.php to point
$ERRCODE_PATH to the errcode.py script. Then move errcode.php to a location
visible from your web server.
[OPTIONAL]
A simple IRC bot is provided. Edit gpxebot.py to fill in the IRC details.
Usage
-----
Looking up error codes on the command-line:
./errcode.py 0x12345678
Further information
-------------------
See http://etherboot.org/.
Released under the GPL and written by Stefan Hajnoczi <stefanha@gmail.com>.
+93
View File
@@ -0,0 +1,93 @@
#!/usr/bin/env python
# Copyright (C) 2008 Stefan Hajnoczi <stefanha@gmail.com>.
#
# 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.
import sys
import re
pxenv_status_files = ('../../src/include/errno.h', )
errfile_files = ('../../src/include/gpxe/errfile.h',
'../../src/arch/i386/include/bits/errfile.h')
posix_errno_files = ('../../src/include/errno.h', )
PXENV_STATUS_RE = re.compile(r'^#define\s+(PXENV_STATUS_[^\s]+)\s+(.+)$', re.M)
ERRFILE_RE = re.compile(r'^#define\s+(ERRFILE_[^\s]+)\s+(.+)$', re.M)
POSIX_ERRNO_RE = re.compile(r'^#define\s+(E[A-Z0-9]+)\s+(?:\\\n)?.*(0x[0-9a-f]+).*$', re.M)
def err(msg):
sys.stderr.write('%s: %s\n' % (sys.argv[0], msg))
sys.exit(1)
def to_pxenv_status(errno):
return errno & 0xff
def to_errfile(errno):
return (errno >> 13) & 0x7ff
def to_posix_errno(errno):
return (errno >> 24) & 0x7f
def load_header_file(filename, regexp):
defines = {}
data = open(filename, 'r').read()
for m in regexp.finditer(data):
key, val = m.groups()
defines[key] = val
return defines
def evaluate(defines, expr):
pyexpr = ''
for token in expr.split():
if token in '()':
pass
elif token.startswith('/*') or token.startswith('//'):
break
elif token.startswith('0x') or token == '|':
pyexpr += token
else:
if token in defines:
pyexpr += '0x%x' % defines[token]
else:
return -1
if not re.match(r'^[0-9a-zA-Z_|]+$', pyexpr):
err('invalid expression')
return eval(pyexpr)
def build(filenames, regexp, selector):
unevaluated = {}
for filename in filenames:
unevaluated.update(load_header_file(filename, regexp))
evaluated = {}
changed = True
while changed:
changed = False
for key in list(unevaluated.keys()):
val = evaluate(evaluated, unevaluated[key])
if val != -1:
del unevaluated[key]
evaluated[key] = val
changed = True
if unevaluated:
err('unable to evaluate all #defines')
lookup = {}
for key, val in evaluated.iteritems():
lookup[selector(val)] = key
return lookup
print 'pxenv_status =', repr(build(pxenv_status_files, PXENV_STATUS_RE, to_pxenv_status))
print 'errfile =', repr(build(errfile_files, ERRFILE_RE, to_errfile))
print 'posix_errno =', repr(build(posix_errno_files, POSIX_ERRNO_RE, to_posix_errno))
+83
View File
@@ -0,0 +1,83 @@
<?
/*
* Copyright (C) 2008 Stefan Hajnoczi <stefanha@gmail.com>.
*
* 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.
*/
// The path to the errcode.py script.
$ERRCODE_PATH = './errcode.py';
?>
<html>
<head>
<title>gPXE Error Code Lookup</title>
<style>
body, pre, div, form, p, h2, b, tt {
padding: 0;
border: 0;
margin: 0;
}
body {
padding: 0.5em;
width: 750px;
font-family: sans-serif;
}
pre {
margin: 0.2em;
padding: 0.1em;
background-color: #ddd;
}
form {
margin: 0.2em;
}
div {
margin: 0.2em;
padding: 0.4em;
border: 1px dashed black;
}
</style>
</head>
<body>
<?
if (!empty($_REQUEST['e']) && preg_match('/^(0x)?[0-9a-f]{8}$/', $_REQUEST['e'])) {
?>
<pre>
<?
system($ERRCODE_PATH . " " . $_REQUEST['e']);
?>
</pre>
<?
}
?>
<form action="" method="post">
<label for="e">Error code:</label>
<input type="text" name="e" id="e" value="0x12345678"></input>
<input type="submit" value="Lookup"></input>
</form>
<div>
<h2>Hint:</h2>
<p>
Firefox users can right-click on the <b>Error code</b>
text box and select <b>Add a Keyword for this Search...</b>.
Set <b>name</b> to <tt>gPXE Error Code Lookup</tt> and
<b>keyword</b> to <tt>gxpe</tt> Then you can look up error
codes by typing something like the following in your address
bar: <tt>gpxe 0x3c018003</tt>
<p>
</div>
</body>
</html>
+78
View File
@@ -0,0 +1,78 @@
#!/usr/bin/env python
# Copyright (C) 2008 Stefan Hajnoczi <stefanha@gmail.com>.
#
# 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.
import sys
try:
import errcodedb
except ImportError:
sys.stderr.write('Please run this first: ./build_errcodedb.py >errcodedb.py\n')
sys.exit(1)
def to_pxenv_status(errno):
return errno & 0xff
def to_uniq(errno):
return (errno >> 8) & 0x1f
def to_errfile(errno):
return (errno >> 13) & 0x7ff
def to_posix_errno(errno):
return (errno >> 24) & 0x7f
def lookup_errno_component(defines, component):
if component in defines:
return defines[component]
else:
return '0x%x' % component
class Errcode(object):
def __init__(self, errno):
self.pxenv_status = to_pxenv_status(errno)
self.uniq = to_uniq(errno)
self.errfile = to_errfile(errno)
self.posix_errno = to_posix_errno(errno)
def rawstr(self):
return 'pxenv_status=0x%x uniq=%d errfile=0x%x posix_errno=0x%x' % (self.pxenv_status, self.uniq, self.errfile, self.posix_errno)
def prettystr(self):
return 'pxenv_status=%s uniq=%d errfile=%s posix_errno=%s' % (
lookup_errno_component(errcodedb.pxenv_status, self.pxenv_status),
self.uniq,
lookup_errno_component(errcodedb.errfile, self.errfile),
lookup_errno_component(errcodedb.posix_errno, self.posix_errno)
)
def __str__(self):
return self.prettystr()
def usage():
sys.stderr.write('usage: %s ERROR_NUMBER\n' % sys.argv[0])
sys.exit(1)
if __name__ == '__main__':
if len(sys.argv) != 2:
usage()
try:
errno = int(sys.argv[1], 16)
except ValueError:
usage()
print Errcode(errno)
sys.exit(0)
+124
View File
@@ -0,0 +1,124 @@
#!/usr/bin/env python
# Copyright (C) 2008 Stefan Hajnoczi <stefanha@gmail.com>.
#
# 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.
import re
import socket
import errcode
HOST = 'irc.freenode.net'
PORT = 6667
NICK = 'gpxebot'
CHAN = '#etherboot'
NICKSERV_PASSWORD = None
IDENT = 'gpxebot'
REALNAME = 'gPXE bot'
ERRCODE_RE = re.compile(r'(errcode|Error)\s+((0x)?[0-9a-fA-F]{8})')
NO_ARGS = -1
handlers = {}
def nick_from_mask(mask):
return (mask.find('!') > -1 and mask.split('!', 1)[0]) or mask
def autojoin():
del handlers['376']
if NICKSERV_PASSWORD:
pmsg('nickserv', 'identify %s' % NICKSERV_PASSWORD)
if CHAN:
cmd('JOIN %s' % CHAN)
def ping(_, arg):
cmd('PONG %s' % arg)
def privmsg(_, target, msg):
if target == CHAN:
replyto = target
if msg.find(NICK) == -1:
return
elif target == NICK:
replyto = nick_from_mask(who)
m = ERRCODE_RE.search(msg)
if m:
try:
pmsg(replyto, str(errcode.Errcode(int(m.groups()[1], 16))))
except ValueError:
pass
if msg.find('help') > -1:
pmsg(replyto, 'I look up gPXE error codes. Message me like this:')
pmsg(replyto, 'errcode 0x12345678 OR Error 0x12345678')
def add_handler(command, handler, nargs):
handlers[command] = (handler, nargs)
def cmd(msg):
sock.sendall('%s\r\n' % msg)
def pmsg(target, msg):
cmd('PRIVMSG %s :%s' % (target, msg))
def dispatch(args):
command = args[0]
if command in handlers:
h = handlers[command]
if h[1] == NO_ARGS:
h[0]()
elif len(args) == h[1]:
h[0](*args)
def parse(line):
if line[0] == ':':
who, line = line.split(None, 1)
who = who[1:]
else:
who = None
args = []
while line and line[0] != ':' and line.find(' ') != -1:
fields = line.split(None, 1)
if len(fields) == 1:
fields.append(None)
arg, line = fields
args.append(arg)
if line:
if line[0] == ':':
args.append(line[1:])
else:
args.append(line)
return who, args
add_handler('376', autojoin, NO_ARGS)
add_handler('PING', ping, 2)
add_handler('PRIVMSG', privmsg, 3)
sock = socket.socket()
sock.connect((HOST, PORT))
cmd('NICK %s' % NICK)
cmd('USER %s none none :%s' % (IDENT, REALNAME))
rbuf = ''
while True:
r = sock.recv(4096)
if not r:
break
rbuf += r
while rbuf.find('\r\n') != -1:
line, rbuf = rbuf.split('\r\n', 1)
if not line:
continue
who, args = parse(line)
dispatch(args)
+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
-37
View File
@@ -1,37 +0,0 @@
## Makefile for use with gnu make and MinGW32 gnu gcc
TARGET=wol
CC=gcc
LD=gcc
CPPFLAGS= -Wall -O2
LFLAGS= -s
#LIBFILES= -lwsock
#LIBPATH= -L/usr/lib
ICON=$(TARGET).ico
OBJS=$(TARGET).o
RESF=$(TARGET).rc
#RESNAME=$(TARGET).res
#BINNAME=$(TARGET).exe
BINNAME=$(TARGET)
$(BINNAME): $(OBJS) $(RESNAME)
$(LD) $(LFLAGS) -o $@ $^ $(LIBPATH) $(LIBFILES)
%.res:%.rc
windres -I rc -O coff -i $< -o $@
%.rc:Makefile
@echo 100 ICON "$(ICON)" > $@
dist:$(BINNAME)
rm -f $(OBJS) $(RESNAME) $(RESF)
clean:
rm -f $(OBJS) $(RESNAME) $(RESF)
rm -f $(BINNAME)
+40 -3
View File
@@ -1,3 +1,40 @@
Here are two programs to send Wake-On-LAN packets to a dormant workstation
using the WOL feature. Please contact the respective authors for any
queries.
From level42@sympatico.ca Tue Mar 18 04:35:31 2008
Date: Mon, 17 Mar 2008 23:47:39 -0400
From: Bill <level42@sympatico.ca>
To: etherboot-developers@lists.sourceforge.net
Subject: [Etherboot-developers] WOL Routine
Attached is a WOL routine that can be used to wake a remote server from
gpxe. I put wol.c in src/usr and wol.h in src/include/usr. This is really
in improved replacement of that in contrib\wakeonlan\wakeserver.patch. This
version will no longer work since the eth_transmit routine no longer works
with the newer driver arhitecture such as the e1000 driver.
Please consider adding it to gpxe preferrably in the main src directory or
in the contrib directory.
Thank you
[ Part 2, Text/PLAIN (Name: "wol.c") 109 lines. ]
[ Unable to print this part. ]
[ Part 3, Text/PLAIN (Name: "wol.h") 12 lines. ]
[ Unable to print this part. ]
[ Part 4: "Attached Text" ]
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
[ Part 5: "Attached Text" ]
_______________________________________________
Etherboot-developers mailing list
Etherboot-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/etherboot-developers
-9
View File
@@ -1,9 +0,0 @@
# maclist - mac addresses for wakeonlan
00:BA:BE:FA:CE:00 mainframe
00:11:22:33:44:5A maschine1
00:11:22:33:44:B5 maschine2
00:11:22:33:44:5C maschine3
0A:BB:CC:DD:EE:F9 macintosh
1A:BB:CC:DD:E6:FF
3A:BB:CC:DD:EE:F5 testpc
3A:BB:CC:DD:EE:F6 123.45.6.7
-172
View File
@@ -1,172 +0,0 @@
#!/perl/bin/perl -w
# Magic Packet for the Web
# Perl version by ken.yap@acm.org after DOS/Windows C version posted by
# Steve_Marfisi@3com.com on the Netboot mailing list
# modified to work with web by G. Knauf <info@gknw.de>
# Released under GNU Public License
#
use CGI qw(:standard); # import shortcuts
use Socket;
$ver = 'v0.52 &copy; gk 2003-Apr-24 11:00:00';
# Defaults - Modify to point to the location of your mac file
$www = "$ENV{'DOCUMENT_ROOT'}/perldemo";
$maclist = "$www/maclist.txt";
# Defaults - Modify to fit to your network
$defbc = '255.255.255.255';
$port = 60000;
MAIN:
{
# Read in all the variables set by the form
if (param()) {
&process_form();
} else {
&print_form();
}
}
sub process_form {
# Print the header
print header();
print start_html("Mp-Form - send Magic Packets");
# If defined new mac save it
if (defined(param("mac"))) {
print h1("Result of adding an entry to the maclist");
print '<HR><H3><TT>';
&add_entry();
print '</TT></H3><HR>';
print '<FORM method="POST"><input type="submit" value="ok"></FORM>';
} else {
# send magic packets to selected macs
print h1("Result of sending magic packets to multiple PCs");
print '<HR><H3><TT>';
if (param("all")) {
&process_file(S);
} else {
for (param()) {
my ($brc,$mac) = split(/-/,param($_));
&send_broadcast_packet(inet_aton($brc),$mac);
}
}
print '</TT></H3><HR>';
print '<FORM><input type="button" value="back" onClick="history.back()"></FORM>';
}
# Close the document cleanly.
print end_html;
}
sub print_form {
# Print the header
print header();
print start_html("Mp-Form - send Magic Packets");
print h1("Form for sending magic packets to multiple PCs");
print <<ENDOFTEXT;
<HR>
<FORM method="POST">
<H2>Select the destination mac addresses:</H2>
<TABLE BORDER COLS=3 WIDTH="80%">
<TR>
<TD><CENTER><B><FONT SIZE="+1">Broadcast address</FONT></B></CENTER></TD>
<TD><CENTER><B><FONT SIZE="+1">MAC address</FONT></B></CENTER></TD>
<TD><CENTER><B><FONT SIZE="+1">Name</FONT></B></CENTER></TD>
<TD><CENTER><B><FONT SIZE="+1"><input type=checkbox name="all" value="all">Select all</FONT></B></CENTER></TD>
</TR>
ENDOFTEXT
# build up table with mac addresses
&process_file(R);
# print rest of the form
print <<ENDOFTEXT;
</TABLE>
<P><B><FONT SIZE="+1">
Press <input type="submit" value="wakeup"> to send the magic packets to your selections.
Press <input type="reset" value="clear"> to reset the form.
</FONT></B>
</FORM>
<HR>
<FORM method="POST">
<H2>Enter new destination mac address:</H2>
<B><FONT SIZE="+1">Broadcast: </FONT></B><input name="brc" size="15" maxlength="15" value="$defbc">
<B><FONT SIZE="+1">MAC: </FONT></B><input name="mac" size="17" maxlength="17">
<B><FONT SIZE="+1">Name: </FONT></B><input name="ip" size="40" maxlength="40">
<P><B><FONT SIZE="+1">
Press <input type="submit" value="save"> to add the entry to your maclist.
Press <input type="reset" value="clear"> to reset the form.
</FONT></B>
</FORM>
<HR>
$ver
ENDOFTEXT
# Close the document cleanly.
print end_html;
}
sub send_broadcast_packet {
my ($nbc,$mac) = @_;
if ($mac !~ /^[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}$/i) {
print "Malformed MAC address $mac<BR>\n";
return;
}
printf("Sending wakeup packet to %04X:%08X-%s<BR>\n", $port, unpack('N',$nbc), $mac);
# Remove colons
$mac =~ tr/://d;
# Magic packet is 6 bytes of FF followed by the MAC address 16 times
$magic = ("\xff" x 6) . (pack('H12', $mac) x 16);
# Create socket
socket(S, PF_INET, SOCK_DGRAM, getprotobyname('udp')) or die "socket: $!\n";
# Enable broadcast
setsockopt(S, SOL_SOCKET, SO_BROADCAST, 1) or die "setsockopt: $!\n";
# Send the wakeup packet
defined(send(S, $magic, 0, sockaddr_in($port, $nbc))) or print "send: $!\n";
close(S);
}
sub process_file {
unless (open(F, $maclist)) {
print "Error reading $maclist: $!\n";
} else {
while (<F>) {
next if (/^\s*#|^\s*;/); # skip comments
my ($mac, $ip) = split;
next if (!defined($mac) or $mac eq '');
$mac = uc($mac);
my $bc = $defbc;
($bc,$mac) = split(/-/,$mac) if ($mac =~ /-/);
my $nbc = inet_aton($bc);
if ($_[0] eq 'S') {
&send_broadcast_packet($nbc, $mac);
} else {
my $hbc = sprintf("0x%08X", unpack('N',$nbc));
print "<TD WIDTH=20%><CENTER><TT>$hbc</TT></CENTER></TD>";
print "<TD WIDTH=30%><CENTER><TT>$mac</TT></CENTER></TD>";
$ip = '&nbsp;' if (!defined($ip) or $ip eq '');
print "<TD WIDTH=30%><CENTER><TT>$ip</TT></CENTER></TD>";
print "<TD WIDTH=20%><CENTER><input type=checkbox name=mac$. value=$hbc-$mac><TT>WakeUp</TT></CENTER></TD></TR>\n";
}
}
close(F);
}
}
sub add_entry {
if (param("brc") !~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/i) {
print "Malformed broadcast address ",param("brc"),"\n";
return;
}
if (param("mac") !~ /^[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}$/i) {
print "Malformed MAC address ",param("mac"),"\n";
return;
}
unless (open(F, ">> $maclist")) {
print "Error writing $maclist: $!\n";
} else {
#my $nbc = inet_aton(param("brc"));
#my $hbc = sprintf("0x%8X", unpack('N',$nbc));
#print F $hbc."-".uc(param("mac"))." ".param("ip")."\n";
print F param("brc")."-".uc(param("mac"))." ".param("ip")."\n";
close(F);
print "Saved entry to maclist: ".param("brc")."-".uc(param("mac"))." ".param("ip")."\n";
}
}
-26
View File
@@ -1,26 +0,0 @@
mp-form.pl - Send magic packets with your web server
This is my trial of waking up PCs with a form via web server.
The perl script reads in a text file which contains lines of the form
aa:bb:cc:dd:ee:ff 12.34.56.78 or
aa:bb:cc:dd:ee:ff foo.bar.com
aa:bb:cc:dd:ee:ff
The script is based on wake.pl by Ken Yap who is also the author of the Etherboot package.
The script uses CGI.pm to parse form input and Socket.pm to send the magic packets, both
modules should belong to your perl distribution. The script runs with linux as well as
with NT, with NetWare you have to use the Socket.NLP from recent Perl build #334, with
Perl build #333 and earlier I got an error from the Socket.pm.
This script uses only broadcast so you don't need root rights to use it.
To install the script copy it to your ../cgi-bin directory. Then for Linux do a chmod 755
to the script. Modify the lines which point to the location of the maclist. If you do not
have a maclist, the form could save new entries to a list (with unix perhaps you have to
create an empty file). Check also the first line of mp-form.pl and modify it to point to
your perl5 location. For NetWare copy the script to /novonyx/suitespot/docs/perlroot.
Older version: If you have problems running the script with CGI.pm you could try the older
version mp-form1.pl which uses cgi-lib.pl to parse form input. You can get cgi-lib.pl
from http://cgi-lib.berkeley.edu/. With NetWare you should also use mp-form1.pl as using
CGI.pm consumes much memory. The older version is also included in the zip archive.
Homepage of the script: http://www.gknw.de/mpform.html
-171
View File
@@ -1,171 +0,0 @@
#!/usr/bin/perl -w
# Magic Packet for the Web
# Perl version by ken.yap@acm.org after DOS/Windows C version posted by
# Steve_Marfisi@3com.com on the Netboot mailing list
# modified to work with web by G. Knauf <info@gknw.de>
# Released under GNU Public License
#
require "cgi-lib.pl";
use Socket;
$ver = 'v0.52 &copy; gk 2003-Apr-24 11:00:00';
# Defaults - Modify to point to the location of your mac file
$www = "$ENV{'DOCUMENT_ROOT'}/perldemo";
$maclist = "$www/maclist.txt";
# Defaults - Modify to fit to your network
$defbc = '255.255.255.255';
$port = 60000;
MAIN:
{
# Read in all the variables set by the form
if (&ReadParse(*input)) {
&process_form();
} else {
&print_form();
}
}
sub process_form {
# Print the header
print &PrintHeader();
# If defined new mac save it
if (defined($input{'mac'})) {
print &HtmlTop("Result of adding an entry to the maclist");
print '<HR><H3><TT>';
&add_entry;
print '</TT></H3><HR>';
print '<FORM method="POST"><input type=submit value="ok"></FORM>';
} else {
# send magic packets to selected macs
print &HtmlTop("Result of sending magic packets to multiple PCs");
print '<HR><H3><TT>';
if (defined($input{'all'})) {
&process_file(S);
} else {
foreach $x (keys %input) {
my ($brc,$mac) = split(/-/,$input{$x});
&send_broadcast_packet(inet_aton($brc),$mac);
}
}
print '</TT></H3><HR>';
print '<form><input type=button value="back" onClick="history.back()"></FORM>';
}
# Close the document cleanly.
print &HtmlBot;
exit;
}
sub print_form {
print &PrintHeader();
print &HtmlTop("Form for sending magic packets to multiple PCs");
# Print out the body of the form
print <<ENDOFTEXT;
<HR>
<FORM method="POST">
<H2> Select the destination mac addresses: </H2>
<TABLE BORDER COLS=3 WIDTH="80%">
<TR>
<TD><CENTER><B><FONT SIZE="+1">Broadcast address</FONT></B></CENTER></TD>
<TD><CENTER><B><FONT SIZE="+1">MAC address</FONT></B></CENTER></TD>
<TD><CENTER><B><FONT SIZE="+1">Name</FONT></B></CENTER></TD>
<TD><CENTER><B><FONT SIZE="+1"><input type=checkbox name="all" value="all">Select all</FONT></B></CENTER></TD>
</TR>
ENDOFTEXT
# build up table with mac addresses
&process_file;
# print rest of the form
print <<ENDOFTEXT;
</TABLE>
<P><B><FONT SIZE="+1">
Press <input type="submit" value="wakeup"> to send the magic packets to your selections.
Press <input type="reset" value="clear"> to reset the form.
</FONT></B>
</FORM>
<HR>
<FORM method="POST">
<H2>Enter new destination mac address:</H2>
<B><FONT SIZE="+1">Broadcast: </FONT></B><input name="brc" size="15" maxlength="15" value="$defbc">
<B><FONT SIZE="+1">MAC: </FONT></B><input name="mac" size=17 maxlength=17>
<B><FONT SIZE="+1">Name: </FONT></B><input name="ip" size=40 maxlength=40>
<P><B><FONT SIZE="+1">
Press <input type="submit" value="save"> to add the entry to your maclist.
Press <input type="reset" value="clear"> to reset the form.
</FONT></B>
</FORM>
<HR>
$ver
ENDOFTEXT
# Close the document cleanly.
print &HtmlBot;
}
sub send_broadcast_packet {
my ($nbc,$mac) = @_;
if ($mac !~ /^[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}$/i) {
print "Malformed MAC address $mac<BR>\n";
return;
}
printf("Sending wakeup packet to %04X:%08X-%s<BR>\n", $port, unpack('N',$nbc), $mac);
# Remove colons
$mac =~ tr/://d;
# Magic packet is 6 bytes of FF followed by the MAC address 16 times
$magic = ("\xff" x 6) . (pack('H12', $mac) x 16);
# Create socket
socket(S, PF_INET, SOCK_DGRAM, getprotobyname('udp')) or die "socket: $!\n";
# Enable broadcast
setsockopt(S, SOL_SOCKET, SO_BROADCAST, 1) or die "setsockopt: $!\n";
# Send the wakeup packet
defined(send(S, $magic, 0, sockaddr_in($port, $nbc))) or print "send: $!\n";
close(S);
}
sub process_file {
unless (open(F, $maclist)) {
print "Error reading $maclist: $!\n";
} else {
while (<F>) {
next if (/^\s*#|^\s*;/); # skip comments
my ($mac, $ip) = split;
next if (!defined($mac) or $mac eq '');
$mac = uc($mac);
my $bc = $defbc;
($bc,$mac) = split(/-/,$mac) if ($mac =~ /-/);
my $nbc = inet_aton($bc);
if ($_[0] eq 'S') {
&send_broadcast_packet($nbc, $mac);
} else {
my $hbc = sprintf("0x%08X", unpack('N',$nbc));
print "<TD WIDTH=20%><CENTER><TT>$hbc</TT></CENTER></TD>";
print "<TD WIDTH=30%><CENTER><TT>$mac</TT></CENTER></TD>";
$ip = '&nbsp;' if (!defined($ip) or $ip eq '');
print "<TD WIDTH=30%><CENTER><TT>$ip</TT></CENTER></TD>";
print "<TD WIDTH=20%><CENTER><input type=checkbox name=mac$. value=$hbc-$mac><TT>WakeUp</TT></CENTER></TD></TR>\n";
}
}
close(F);
}
}
sub add_entry {
if (param("brc") !~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/i) {
print "Malformed broadcast address ",param("brc"),"\n";
return;
}
if (param("mac") !~ /^[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}$/i) {
print "Malformed MAC address ",param("mac"),"\n";
return;
}
unless (open(F, ">> $maclist")) {
print "Error writing $maclist: $!\n";
} else {
#my $nbc = inet_aton(param("brc"));
#my $hbc = sprintf("0x%8X", unpack('N',$nbc));
#print F $hbc."-".uc(param("mac"))." ".param("ip")."\n";
print F param("brc")."-".uc(param("mac"))." ".param("ip")."\n";
close(F);
print "Saved entry to maclist: ".param("brc")."-".uc(param("mac"))." ".param("ip")."\n";
}
}
-35
View File
@@ -1,35 +0,0 @@
mp-form.pl - Send magic packets with your web server
This is my trial of waking up PCs with a form via web server.
The perl script reads in a text file which contains lines of the form
aa:bb:cc:dd:ee:ff 12.34.56.78 or
aa:bb:cc:dd:ee:ff foo.bar.com
aa:bb:cc:dd:ee:ff
optional a broadcast address mask can be prefixed:
192.168.1.255-aa:bb:cc:dd:ee:ff
The script is based on wake.pl by Ken Yap who is also the author of the Etherboot package.
The script uses CGI.pm to parse form input and Socket.pm to send the magic packets, both
modules should belong to your perl distribution. The script runs with linux as well as
with NT, with NetWare you have to use the Socket.NLP from recent Perl build #334, with
Perl build #333 and earlier I got an error from the Socket.pm. You should also update
your Perl to minimum #331 from CPAN: http://www.cpan.org/ports/index.html#netware.
This script uses only broadcast so you don't need root rights to use it.
To install the script copy it to your ../cgi-bin directory. Then for Linux do a chmod 755
to the script. Modify the lines which point to the location of the maclist. If you do not
have a maclist, the form could save new entries to a list (with unix perhaps you have to
create an empty file). Check also the first line of mp-form.pl and modify it to point to
your perl5 location. For NetWare copy the script to /novonyx/suitespot/docs/perlroot.
Older version: If you have problems running the script with CGI.pm you could try the older
version mp-form1.pl which uses cgi-lib.pl to parse form input. You can get cgi-lib.pl
from http://cgi-lib.berkeley.edu/. With NetWare you should also use mp-form1.pl as using
CGI.pm consumes much memory. The older version is also included in the zip archive.
A modified version of the original script is now also included which runs with older
Getopt::Std.pm as shipped with NetWare. This script you could use from command line
or from cron. With NetWare copy the script to /perl/scripts; then call from console with:
perl wakeup.pl <parameters>.
Homepage of the script: http://www.gknw.de/mpform.html
-116
View File
@@ -1,116 +0,0 @@
#!/usr/bin/perl -w
#
# If called as wake.pl -f file it reads lines of the form
#
# aa:bb:cc:dd:ee;ff 12.34.56.78 or
# aa:bb:cc:dd:ee:ff foo.bar.com
# aa:bb:cc:dd:ee:ff
#
# which are MAC addresses and hostnames of NICs to send a wakeup packet.
# In the first two cases, unicast is used (and root permission may be
# required if the ARP cache needs to be injected with a mapping).
# In the third case, broadcast is used, and anybody can run the command.
# Comments in the file start with #.
#
# Or MAC addresses can be specified on the command line
#
# wake.pl aa.bb.cc.dd.ee.ff
#
# Or both can be used:
#
# wake.pl -f addresses.cfg 11:22:33:44:55:66
#
# This program may have to be run with superuser privilege because it
# may need to inject an ARP entry into the cache.
# Be careful, you could corrupt valid entries if those NICs are
# already active.
#
# Perl version by ken_yap@users.sourceforge.net after DOS/Windows C version posted by
# Steve_Marfisi@3com.com on the Netboot mailing list
# Released under GNU Public License, 2000-01-08
# Added switch -q for quiet mode, changed Getopt usage to work with older versions,
# added switch -u for unicast mode, now default is always broadcast mode,
# added switch -s for seach pattern so you could filter entries from file.
# Guenter.Knauf@dialup.soco.de, 2000-10-14
#
use Getopt::Std;
use Socket;
getopts('quf:s:');
if (defined($opt_f)) {
unless (open(F, $opt_f)) {
print STDERR "open: $opt_f: $!\n";
} else {
while (<F>) {
next if /^\s*#/; # skip comments
($mac, $ip) = split;
next if !defined($mac) or $mac eq '';
next if defined($opt_s) and (!/$opt_s/);
if (!defined($ip) or $ip eq '' or !$opt_u) {
&send_broadcast_packet($mac);
} else {
&send_unicast_packet($mac, $ip);
}
}
close(F);
}
}
while (@ARGV) {
send_broadcast_packet(shift(@ARGV));
}
sub send_broadcast_packet {
($mac) = @_;
if ($mac !~ /^[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}$/i) {
print STDERR "Malformed MAC address $mac\n";
return;
}
# Remove colons
$mac =~ tr/://d;
# Magic packet is 6 bytes of FF followed by the MAC address 16 times
$magic = ("\xff" x 6) . (pack('H12', $mac) x 16);
# Create socket
socket(S, PF_INET, SOCK_DGRAM, getprotobyname('udp'))
or die "socket: $!\n";
# Enable broadcast
setsockopt(S, SOL_SOCKET, SO_BROADCAST, 1)
or die "setsockopt: $!\n";
# Send the wakeup packet
if (!$opt_q) {
print "Sending wakeup packet to MAC address $mac";
print " ($ip)" if (defined($ip));
print "\n";
}
defined(send(S, $magic, 0, sockaddr_in(0x2fff, INADDR_BROADCAST)))
or print STDERR "send: $!\n";
close(S);
}
sub send_unicast_packet {
($mac, $ip) = @_;
if (!defined($iaddr = inet_aton($ip))) {
print STDERR "Cannot resolve $ip\n";
return;
}
if ($mac !~ /^[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}$/i) {
print STDERR "Malformed MAC address $mac\n";
return;
}
# Inject entry into ARP table, in case it's not there already
system("arp -s $ip $mac") == 0
or print STDERR "Warning: arp command failed, you need to be root\n";
# Remove colons
$mac =~ tr/://d;
# Magic packet is 6 bytes of FF followed by the MAC address 16 times
$magic = ("\xff" x 6) . (pack('H12', $mac) x 16);
# Create socket
socket(S, PF_INET, SOCK_DGRAM, getprotobyname('udp'))
or die "socket: $!\n";
# Send the wakeup packet
print "Sending wakeup packet to $ip at MAC address $mac\n" if (!$opt_q);
defined(send(S, $magic, 0, sockaddr_in(0x2fff, $iaddr)))
or print STDERR "send: $!\n";
close(S);
}
-179
View File
@@ -1,179 +0,0 @@
To: etherboot-developers@lists.sourceforge.net
X-face: #Qvg5o3u!)WoVDDi4-bFy`fl@""4^pm68%_,`puon{0Q6lQ-O,)3D.J.":A&^,#4O2vc8`?
3^1lhBh=EQH,"Qq*e1vY":she&t^8:!&Fb32Ed:nM2Y<E9|i[+z20G?CO=E=-IWv;bL"=Y`+`q,ML6
,!Me?==j&In1
Mime-Version: 1.0
Content-Type: multipart/mixed ;
boundary="==_Exmh_-19971541890"
From: Tilmann Bubeck <bubeck@think-at-work.de>
Message-Id: <20010219195622.C97A84ABD8@chaos.think-at-work.de>
Subject: [Etherboot-developers] Wake-on-LAN patch
Sender: etherboot-developers-admin@lists.sourceforge.net
Errors-To: etherboot-developers-admin@lists.sourceforge.net
X-BeenThere: etherboot-developers@lists.sourceforge.net
X-Mailman-Version: 2.0
Precedence: bulk
List-Help: <mailto:etherboot-developers-request@lists.sourceforge.net?subject=help>
List-Post: <mailto:etherboot-developers@lists.sourceforge.net>
List-Subscribe: <http://lists.sourceforge.net/lists/listinfo/etherboot-developers>,
<mailto:etherboot-developers-request@lists.sourceforge.net?subject=subscribe>
List-Id: Discussion list for Etherboot developers <etherboot-developers.lists.sourceforge.net>
List-Unsubscribe: <http://lists.sourceforge.net/lists/listinfo/etherboot-developers>,
<mailto:etherboot-developers-request@lists.sourceforge.net?subject=unsubscribe>
List-Archive: <http://lists.sourceforge.net/archives//etherboot-developers/>
Date: Mon, 19 Feb 2001 20:56:22 +0100
Status: RO
Content-Length: 5351
Lines: 152
This is a multipart MIME message.
--==_Exmh_-19971541890
Content-Type: text/plain; charset=us-ascii
Hello!
please find enclosed a patch to optionally enable etherboot to start the
server it is booting from by sending a magic wake-on-lan packet to the
sleeping server first.
This is very important for an etherboot-server, which is not running all the
time and is not easily accessible from the etherboot machine (e.g. because it
is installed in the basement of the house and one must climb several stairs to
switch the server on...)
Are the authors of etherboot willing to accept this patch for inclusion?
Please note, that the wake-on-lan code is only compiled in, when setting
appropriate flags in src/Config.
If you don't want to include the patch, should I change anything of the
implementation or do you dislike the idea at all?
Thanks!
Till
+-------+--------------------------------------------------------------+
| | dr. tilmann bubeck think@work it consulting |
| | professional services |
| think | cell.: +49 172 8842972 widmaierstrasse 58 |
| @work | fax : +49 711 7227734 70567 stuttgart |
| | email: bubeck@think-at-work.de http://www.think-at-work.de |
+-------+ -------------------------------------------------------------+
--==_Exmh_-19971541890
Content-Type: application/x-patch ; name="etherboot-4.7.17-wol.patch"
Content-Description: etherboot-4.7.17-wol.patch
Content-Disposition: attachment; filename="etherboot-4.7.17-wol.patch"
diff -r -u etherboot-4.7.17/src/Config etherboot-4.7.17-wol/src/Config
--- etherboot-4.7.17/src/Config Sat Jan 6 16:25:23 2001
+++ etherboot-4.7.17-wol/src/Config Mon Feb 19 20:28:00 2001
@@ -113,6 +113,16 @@
# -DINTERNAL_BOOTP_DATA
# - define if the area 0x93C00-0x93FFF is not available
# for use for bootpd_data by the loader for some reason
+# -DWAKEUP_SERVER
+# - define this for sending a Wake-On-LAN (WOL)
+# "Magic Packet" to a sleeping server, before trying
+# a etherboot. Useful if your server is soft-off all
+# the time and must be switched on when booting a
+# client. Define SERVER_MAC with the MAC address of the
+# server to wakeup. CAUTION! This MAC address is
+# stored in the rom image. The rom is therefore not
+# generic anymore but tailored for a specific
+# server!
# These default settings compile Etherboot with a small number of options.
# You may wish to enable more of the features if the size of your ROM allows.
@@ -142,6 +152,10 @@
# These flags affect the loader that is prepended to the Etherboot image
LCONFIG+= -DMOVEROM
+
+# Include code for sending a Wake-On-LAN (WOL) "Magic Packet" to a sleeping
+# server, before trying a etherboot.
+CFLAGS32+= -DWAKEUP_SERVER -DSERVER_MAC=0x00,0x01,0x02,0xDA,0xDF,0x77
# you should normally not need to change these
RM= rm -f
diff -r -u etherboot-4.7.17/src/main.c etherboot-4.7.17-wol/src/main.c
--- etherboot-4.7.17/src/main.c Fri Jan 5 12:45:29 2001
+++ etherboot-4.7.17-wol/src/main.c Thu Feb 8 20:46:59 2001
@@ -137,6 +137,7 @@
* declarations, but in this case I like to see main() as the first
* routine.
*/
+static void wakeup_server(void) ;
static int bootp(void);
static int rarp(void);
static void load(void);
@@ -217,6 +218,11 @@
rfc951_sleep(++card_retries);
}
#endif
+
+#ifdef WAKEUP_SERVER
+ wakeup_server();
+#endif
+
while (1) {
/* -1: timeout or ESC
-2: error return from loader
@@ -650,6 +656,46 @@
return (0);
}
#endif /* DOWNLOAD_PROTO_TFTP */
+
+#ifdef WAKEUP_SERVER
+#ifndef SERVER_MAC
+#error "Please define SERVER_MAC to the MAC address of the sleeping server"
+#endif
+
+/**************************************************************************
+WOL - Wake up a sleeping server by transmitting a Wake-On-LAN (WOL) "Magic
+ Packet", used for restarting machines that have been soft-powered-down
+ (ACPI D3-warm state). It currently generates the standard AMD Magic
+ Packet format.
+**************************************************************************/
+static void wakeup_server(void)
+{
+ unsigned char data[100];
+ int i, len, retry;
+ char server_adr[] = { SERVER_MAC };
+ unsigned long time;
+
+ /* build "Magic Packet" */
+ len = 0;
+ data[len++] = 0xff;
+ data[len++] = 0xff;
+ data[len++] = 0xff;
+ data[len++] = 0xff;
+ data[len++] = 0xff;
+ data[len++] = 0xff;
+ for ( i = 0; i < 16; i++ ) {
+ memcpy(&data[len], server_adr, 6);
+ len += 6;
+ }
+
+ printf("Sending Wake-On-LAN (WOL) \"Magic Packet\" to server %b:%b:%b:%b:%b:%b...",
+ server_adr[0], server_adr[1], server_adr[2],
+ server_adr[3], server_adr[4], server_adr[5]);
+
+ eth_transmit(broadcast, 0x0842, len, data);
+ printf("done\n");
+}
+#endif
#ifdef RARP_NOT_BOOTP
/**************************************************************************
--==_Exmh_-19971541890--
_______________________________________________
Etherboot-developers mailing list
Etherboot-developers@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/etherboot-developers
-86
View File
@@ -1,86 +0,0 @@
#!/usr/bin/perl
#!/usr/bin/perl -w
#
# If called as wakeup.pl -f file it reads lines of the form
#
# aa:bb:cc:dd:ee;ff 12.34.56.78 or
# aa:bb:cc:dd:ee:ff foo.bar.com
# aa:bb:cc:dd:ee:ff
#
# which are MAC addresses and hostnames of NICs to send a wakeup packet.
# Broadcast is used to send the magic packets, so anybody can run the command.
# Notice that many routers do NOT forward broadcasts automatically!!
# Comments in the file start with #.
#
# Or MAC addresses can be specified on the command line
#
# wakeup.pl aa.bb.cc.dd.ee.ff
#
# Or both can be used:
#
# wakeup.pl -f addresses.cfg 11:22:33:44:55:66
#
# Use option -b to specify broadcast mask.
# Use option -d for screen output.
#
# Perl version by ken.yap@acm.org after DOS/Windows C version posted by
# Steve_Marfisi@3com.com on the Netboot mailing list
# Released under GNU Public License, 2000-01-08
# Modified for use with NetWare by gk@gknw.de, 2000-09-18
# With NetWare you have to use Socket.NLP from NetWare Perl #334 or higher!
# You could download Socket.NLP #334 from: http://www.gknw.de/mpform.html
#
use Getopt::Std;
use Socket;
getopts('b:df:p:q');
$brc = $opt_b || '255.255.255.255';
$port = $opt_p || 60000;
die "Malformed broadcast address: $brc!\n" if ($brc !~ /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$)/);
if (defined($opt_f)) {
unless (open(F, $opt_f)) {
print "open: $opt_f: $!\n";
} else {
print "Using file $opt_f...\n" if ($opt_d);
while (<F>) {
next if /^\s*#/; # skip comments
my ($mac, $ip) = split;
next if !defined($mac) or $mac eq '';
&send_broadcast_packet($mac,$ip);
}
close(F);
}
}
while (@ARGV) {
send_broadcast_packet(shift(@ARGV));
}
sub send_broadcast_packet {
my ($mac,$ip) = @_;
if ($mac =~ /-/) {
($bc,$mac) = split(/-/,$mac);
} else {
$bc = $brc;
}
if ($mac !~ /^[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}$/i) {
print "Malformed MAC address $mac\n";
return;
}
my $nbc = inet_aton($bc);
# Remove colons
$mac =~ tr/://d;
# Magic packet is 6 bytes of FF followed by the MAC address 16 times
$magic = ("\xff" x 6) . (pack('H12', $mac) x 16);
# Create socket
socket(S, PF_INET, SOCK_DGRAM, getprotobyname('udp')) or die "socket: $!\n";
# Enable broadcast
setsockopt(S, SOL_SOCKET, SO_BROADCAST, 1) or die "setsockopt: $!\n";
# Send the wakeup packet
printf("$0: Sending wakeup packet to %04X:%08X-%s %s\n",$port,unpack('N',$nbc),uc($mac),$ip) if ($opt_d);
defined(send(S, $magic, 0, sockaddr_in($port, $nbc)))
or print "send: $!\n";
close(S);
}
-9
View File
@@ -1,9 +0,0 @@
# maclist - mac addresses for wakeonlan
00:BA:BE:FA:CE:00 mainframe
00:11:22:33:44:5A maschine1
00:11:22:33:44:B5 maschine2
00:11:22:33:44:5C maschine3
0A:BB:CC:DD:EE:F9 macintosh
1A:BB:CC:DD:E6:FF
3A:BB:CC:DD:EE:F5 testpc
3A:BB:CC:DD:EE:F6 123.45.6.7
+90 -356
View File
@@ -1,374 +1,108 @@
/*****************************************************************************
/*
* Copyright (C) 2008 William Stewart.
*
* wol.c - Wake-On-LAN utility to wake a networked PC
* 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.
*
* by R. Edwards (bob@cs.anu.edu.au), January 2000
* (in_ether routine adapted from net-tools-1.51/lib/ether.c by
* Fred N. van Kempen)
* added file input, some minor changes for compiling for NetWare
* added switches -q and -d=<ms>, added Win32 target support
* by G. Knauf (gk@gknw.de), 30-Jan-2001
* added switches -b=<bcast> and -p=<port>
* by G. Knauf (gk@gknw.de), 10-Okt-2001
* added OS/2 target support
* by G. Knauf (gk@gknw.de), 24-May-2002
* 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.
*
* This utility allows a PC with WOL configured to be powered on by
* sending a "Magic Packet" to it's network adaptor (see:
* http://www.amd.com/products/npd/overview/20212.html).
* Only the ethernet dest address needs to be given to make this work.
* Current version uses a UDP broadcast to send out the Magic Packet.
*
* compile with: gcc -Wall -o wol wol.c
* with Solaris: (g)cc -o wol wol.c -lsocket -lnsl
* with MingW32: gcc -Wall -o wol wol.c -lwsock32
*
* usage: wol <dest address>
* where <dest address> is in [ddd.ddd.ddd.ddd-]xx:xx:xx:xx:xx:xx format.
* or: wol [-q] [-b=<bcast>] [-p=<port>] [-d=<ms>] -f=<File name>
* where <File name> is a file containing one dest address per line,
* optional followed by a hostname or ip separated by a blank.
* -b sets optional broadcast address, -p sets optional port,
* -q supresses output, -d=<ms> delays ms milliseconds between sending.
*
* Released under GNU Public License January, 2000.
* 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.
*/
#define VERSION "1.12.2 (c) G.Knauf http://www.gknw.de/"
#include <errno.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#ifdef WATTCP
#define strncasecmp strnicmp
#include <ctype.h>
#include <dos.h>
#include <tcp.h>
#else
#ifdef WIN32 /* Win32 platform */
#define USE_WINSOCKAPI
#define delay Sleep
#if (defined(__LCC__) || defined(__BORLANDC__))
#define strncasecmp strnicmp
#else
#define strncasecmp _strnicmp
#endif
#elif defined(N_PLAT_NLM) /* NetWare platform */
#ifdef __NOVELL_LIBC__
#include <ctype.h>
#else
extern int isdigit(int c); /* no ctype.h for NW3.x */
#include <nwthread.h>
#define strncasecmp strnicmp
#endif
#elif defined(__OS2__) /* OS/2 platform */
#ifdef __EMX__
#define strncasecmp strnicmp
#endif
extern int DosSleep(long t);
#define delay DosSleep
#else /* all other platforms */
#define delay(t) usleep(t*1000)
#endif
#ifndef N_PLAT_NLM /* ! NetWare platform */
#include <ctype.h>
#endif
#ifndef WIN32 /* ! Win32 platform */
#include <unistd.h>
#endif
#ifdef USE_WINSOCKAPI /* Winsock2 platforms */
#ifdef N_PLAT_NLM /* NetWare platform */
#include <ws2nlm.h>
#else
#include <winsock.h>
#endif
#define close(s) { \
closesocket(s); \
WSACleanup(); \
}
#else /* Socket platforms */
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#if defined(__OS2__) && !defined(__EMX__)
#include <utils.h>
#else
#include <arpa/inet.h>
#endif
#endif
#include <errno.h>
#include <byteswap.h>
#include <gpxe/features.h>
#include <gpxe/netdevice.h>
#include <gpxe/if_ether.h>
#include <gpxe/iobuf.h>
#include <usr/ifmgmt.h>
#include <usr/wol.h>
#include <timer.h>
#endif
/** @file
*
* Wake on lan
*
*/
static int read_file (char *destfile);
static int in_ether (char *bufp, unsigned char *addr);
static int send_wol (char *dest, char *host);
/**
* Boot from a network device
*
* @v netdev Network device
* @ret rc Return status code
*/
#define WOL_MSG_LEN (6 + 16*6)
void wakeup_server(char *server_adr)
{
int rc, i,j;
unsigned char *buf;
uint8_t eth_broadcast[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
unsigned int len;
struct io_buffer *iobuf;
struct ethhdr *ethhdr;
struct net_device *netdev;
for_each_netdev ( netdev ) {
break;
}
char *progname;
int quiet = 0;
int twait = 0;
unsigned int port = 60000;
unsigned long bcast = 0xffffffff;
int main (int argc, char *argv[]) {
int cmdindx = 0;
progname = argv[0];
if (argc > 1) {
/* parse input parameters */
for (argc--, argv++; *argv; argc--, argv++) {
char *bp;
char *ep;
if (strncasecmp (*argv, "-", 1) == 0) {
if (strncasecmp (*argv, "-F=", 3) == 0) {
bp = *argv + 3;
read_file (bp);
} else if (strncasecmp (*argv, "-B=", 3) == 0) {
bp = *argv + 3;
bcast = inet_addr(bp);
if (bcast == -1) {
fprintf (stderr, "%s: expected address argument at %s\n", progname, *argv);
exit (1);
}
} else if (strncasecmp (*argv, "-D=", 3) == 0) {
bp = *argv + 3;
twait = strtol (bp, &ep, 0);
if (ep == bp || *ep != '\0') {
fprintf (stderr, "%s: expected integer argument at %s\n", progname, *argv);
exit (1);
}
} else if (strncasecmp (*argv, "-P=", 3) == 0) {
bp = *argv + 3;
port = strtol (bp, &ep, 0);
if (ep == bp || *ep != '\0') {
fprintf (stderr, "%s: expected integer argument at %s\n", progname, *argv);
exit (1);
}
} else if (strncasecmp (*argv, "-Q", 2) == 0) {
quiet = 1;
} else if (strncasecmp (*argv, "-V", 2) == 0) {
fprintf (stderr, "\r%s Version %s\n", progname, VERSION);
exit (0);
} else {
fprintf (stderr, "\r%s: invalid or unknown option %s\n", progname, *argv);
exit (1);
}
} else {
send_wol (*argv, "");
}
cmdindx++;
if (netdev == NULL)
{
printf("Could not find netdev\n");
return;
}
return (0);
} else {
/* No arguments given -> usage message */
fprintf (stderr, "\rUsage: %s [-q] [-b=<bcast>] [-p=<port>] [-d=<ms>] -f=<file> | <dest>\n", progname);
fprintf (stderr, " need at least hardware address or file option\n");
return (-1);
}
}
/* Open device and display device status */
if ( (ifopen ( netdev ) ) != 0 )
{
printf("Could not open netdev\n");
return;
}
/* Create outgoing I/O buffer */
iobuf = alloc_iob ((ETH_HLEN + WOL_MSG_LEN)*2);
if (!iobuf)
{
printf("Could not allocate iob\n");
return;
}
ethhdr = iob_put(iobuf, sizeof(*ethhdr));
/* Build Ethernet header */
memcpy (ethhdr->h_dest, eth_broadcast, ETH_ALEN );
memcpy (ethhdr->h_source, netdev->ll_addr, ETH_ALEN );
ethhdr->h_protocol = htons (0x0842);
buf = iob_put (iobuf, WOL_MSG_LEN);
static int in_ether (char *bufp, unsigned char *addr) {
char c, *orig;
int i;
unsigned char *ptr = addr;
unsigned val;
i = 0;
orig = bufp;
while ((*bufp != '\0') && (i < 6)) {
val = 0;
c = *bufp++;
if (isdigit(c))
val = c - '0';
else if (c >= 'a' && c <= 'f')
val = c - 'a' + 10;
else if (c >= 'A' && c <= 'F')
val = c - 'A' + 10;
else {
#ifdef DEBUG
fprintf (stderr, "\rin_ether(%s): invalid ether address!\n", orig);
#endif
errno = EINVAL;
return (-1);
}
val <<= 4;
c = *bufp;
if (isdigit(c))
val |= c - '0';
else if (c >= 'a' && c <= 'f')
val |= c - 'a' + 10;
else if (c >= 'A' && c <= 'F')
val |= c - 'A' + 10;
else if (c == ':' || c == 0)
val >>= 4;
else {
#ifdef DEBUG
fprintf (stderr, "\rin_ether(%s): invalid ether address!\n", orig);
#endif
errno = EINVAL;
return (-1);
}
if (c != 0)
bufp++;
*ptr++ = (unsigned char) (val & 0377);
i++;
/* We might get a semicolon here - not required. */
if (*bufp == ':') {
if (i == 6) {
; /* nothing */
}
bufp++;
}
}
if (bufp - orig != 17) {
return (-1);
} else {
return (0);
}
} /* in_ether */
static int read_file (char *destfile) {
FILE *pfile = NULL;
char dest[64];
char host[32];
char buffer[512];
pfile = fopen (destfile, "r+");
if (pfile) {
while (fgets (buffer, 511, pfile) != NULL) {
if (buffer[0] != '#' && buffer[0] != ';') {
dest[0] = host[0] = '\0';
sscanf (buffer, "%s %s", dest, host);
send_wol (dest, host);
}
}
fclose (pfile);
return (0);
} else {
fprintf (stderr, "\r%s: destfile '%s' not found\n", progname, destfile);
return (-1);
}
}
static int send_wol (char *dest, char *host) {
int i, j;
int packet;
struct sockaddr_in sap;
unsigned char ethaddr[8];
unsigned char *ptr;
unsigned char buf [128];
unsigned long bc;
char mask[32];
char *tmp;
#ifdef USE_WINSOCKAPI
WORD wVersionRequested;
WSADATA wsaData;
int err;
#endif
#ifdef WATTCP
static udp_Socket sock;
udp_Socket *s;
#else
int optval = 1;
#endif
/* Fetch the broascast address if present. */
if ((tmp = strstr(dest,"-"))) {
printf("found: %s\n", tmp);
tmp[0] = 32;
sscanf (dest, "%s %s", mask, dest);
bc = inet_addr(mask);
printf("bc: string %s address %08lX\n", mask, bc);
if (bc == -1) {
fprintf (stderr, "\r%s: expected address argument at %s\n", progname, mask);
return (-1);
}
} else
bc = bcast;
/* Fetch the hardware address. */
if (in_ether (dest, ethaddr) < 0) {
fprintf (stderr, "\r%s: invalid hardware address\n", progname);
return (-1);
}
#ifdef USE_WINSOCKAPI
/* I would like to have Socket Vers. 1.1 */
wVersionRequested = MAKEWORD(1, 1);
err = WSAStartup (wVersionRequested, &wsaData);
if (err != 0) {
fprintf (stderr, "\r%s: couldn't init Winsock Version 1.1\n", progname);
WSACleanup ();
return (-1);
}
#endif
/* setup the packet socket */
#ifdef WATTCP
sock_init();
s = &sock;
if (!udp_open( s, 0, bc, port, NULL )) {
#else
if ((packet = socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
#endif
fprintf (stderr, "\r%s: socket failed\n", progname);
#ifdef USE_WINSOCKAPI
WSACleanup ();
#endif
return (-1);
}
#ifndef WATTCP
/* Set socket options */
if (setsockopt (packet, SOL_SOCKET, SO_BROADCAST, (char *)&optval, sizeof (optval)) < 0) {
fprintf (stderr, "\r%s: setsocket failed %s\n", progname, strerror (errno));
close (packet);
return (-1);
}
/* Set up broadcast address */
sap.sin_family = AF_INET;
sap.sin_addr.s_addr = bc; /* broadcast address */
sap.sin_port = htons(port);
#endif
/* Build the message to send - 6 x 0xff then 16 x dest address */
ptr = buf;
for (i = 0; i < 6; i++)
*ptr++ = 0xff;
for (j = 0; j < 16; j++)
/* Build the message to send - 6 x 0xff then 16 x dest address */
len =0;
for (i = 0; i < 6; i++)
*ptr++ = ethaddr [i];
buf[len++] = 0xff;
for (j = 0; j < 16; j++)
for (i = 0; i < 6; i++)
buf[len++] = server_adr[i];
/* Send the packet out */
#ifdef WATTCP
sock_write( s, buf, 102 );
sock_close( s );
#else
if (sendto (packet, (char *)buf, 102, 0, (struct sockaddr *)&sap, sizeof (sap)) < 0) {
fprintf (stderr, "\r%s: sendto failed, %s\n", progname, strerror(errno));
close (packet);
return (-1);
}
close (packet);
#endif
if (!quiet) fprintf (stderr, "\r%s: packet sent to %04X:%08lX-%s %s\n",
progname, port, (unsigned long)htonl(bc), dest, host);
if (twait > 0 ) {
delay (twait);
}
return (0);
rc = netdev_tx (netdev, iobuf);
if (rc !=0)
printf("Failed to transmit WOL packet\n");
/* Give the controller a chance to send it before checking */
mdelay(100);
netdev_poll(netdev);
}
+12
View File
@@ -0,0 +1,12 @@
#ifndef _USR_WOL_H
#define _USR_WOL_H
/** @file
*
* Wakeon lan
*
*/
extern void wakeup_server(char *);
#endif /* _USR_WOL_H */
+1
View File
@@ -2,3 +2,4 @@
.echocheck
TAGS*
bin*
config-local.h
-381
View File
@@ -1,381 +0,0 @@
##############################################################################
##############################################################################
#
# IMPORTANT!
#
# The use of this file to set options that affect only single object
# files is deprecated, because changing anything in this file results
# in a complete rebuild, which is slow. All options are gradually
# being migrated to config.h, which does not suffer from this problem.
#
# Only options that affect the entire build (e.g. overriding the $(CC)
# Makefile variable) should be placed in here.
#
##############################################################################
##############################################################################
#
# Config for Etherboot/32
#
#
# Do not delete the tag OptionDescription and /OptionDescription
# It is used to automatically generate the documentation.
#
# @OptionDescription@
# User interaction options:
#
# -DASK_BOOT=n
# Ask "Boot from (N)etwork ... or (Q)uit? "
# at startup, timeout after n seconds (0 = no timeout).
# If unset or negative, don't ask and boot immediately
# using the default.
# -DBOOT_FIRST
# -DBOOT_SECOND
# -DBOOT_THIRD
# On timeout or Return key from previous
# question, selects the order to try to boot from
# various devices.
# (alternatives: BOOT_NIC, BOOT_DISK,
# BOOT_FLOPPY, BOOT_NOTHING)
# See etherboot.h for prompt and answer strings.
# BOOT_DISK and BOOT_FLOPPY work only where a driver
# exists, e.g. in LinuxBIOS.
# They have no effect on PCBIOS.
# -DBOOT_INDEX The device to boot from 0 == any device.
# 1 == The first nic found.
# 2 == The second nic found
# ...
# BOOT_INDEX only applies to the BOOT_FIRST. BOOT_SECOND
# and BOOT_THIRD search through all of the boot devices.
# -DBAR_PROGRESS
# Use rotating bar instead of sequential dots
# to indicate an IP packet transmitted.
#
# Boot order options:
#
# -DBOOT_CLASS_FIRST
# -DBOOT_CLASS_SECOND
# -DBOOT_CLASS_THIRD
# Select the priority of the boot classes
# Valid values are:
# BOOT_NIC
# BOOT_DISK
# BOOT_FLOPPY
# BOOT_DISK and BOOT_FLOPPY work only where a driver exists,
# e.g. in LinuxBIOS. They have no effect on PCBIOS.
#
# Boot autoconfiguration protocol options:
#
# -DALTERNATE_DHCP_PORTS_1067_1068
# Use ports 1067 and 1068 for DHCP instead of 67 and 68.
# As these ports are non-standard, you need to configure
# your DHCP server to use them. This option gets around
# existing DHCP servers which cannot be touched, for
# one reason or another, at the cost of non-standard
# boot images.
# -DNO_DHCP_SUPPORT
# Use BOOTP instead of DHCP.
# -DRARP_NOT_BOOTP
# Use RARP instead of BOOTP/DHCP.
# -DREQUIRE_VCI_ETHERBOOT
# Require an encapsulated Vendor Class Identifier
# of "Etherboot" in the DHCP reply
# Requires DHCP support.
# -DDHCP_CLIENT_ID=\"Identifier\"
# -DDHCP_CLIENT_ID_LEN=<Client ID length in octets>
# -DDHCP_CLIENT_ID_TYPE=<Client ID type>
# Specify a RFC2132 Client Identifier option, length and type.
# Requires DHCP support.
# -DDHCP_USER_CLASS=\"UserClass\"
# -DDHCP_USER_CLASS_LEN=<User Class length in octets>
# Specify a RFC3004 User Class option and length. Use this
# option to set a UC (or multiple UCs) rather than munge the
# client Vendor Class ID.
# Requires DHCP support.
# -DALLOW_ONLY_ENCAPSULATED
# Ignore Etherboot-specific options that are not within
# the Etherboot encapsulated options field. This option
# should be enabled unless you have a legacy DHCP server
# configuration from the bad old days before the use of
# encapsulated Etherboot options.
# -DDEFAULT_BOOTFILE=\"default_bootfile_name\"
# Define a default bootfile for the case where your DHCP
# server does not provide the information. Example:
# -DDEFAULT_BOOTFILE="tftp:///tftpboot/kernel"
# If you do not specify this option, then DHCP offers that
# do not specify bootfiles will be ignored.
#
# NIC tuning parameters:
#
# -DALLMULTI
# Turns on multicast reception in the NICs.
#
# Boot tuning parameters:
#
# -DCONGESTED
# Turns on packet retransmission. Use it on a
# congested network, where the normal operation
# can't boot the image.
# -DBACKOFF_LIMIT
# Sets the maximum RFC951 backoff exponent to n.
# Do not set this unreasonably low, because on networks
# with many machines they can saturate the link
# (the delay corresponding to the exponent is a random
# time in the range 0..3.5*2^n seconds). Use 5 for a
# VERY small network (max. 2 minutes delay), 7 for a
# medium sized network (max. 7.5 minutes delay) or 10
# for a really huge network with many clients, frequent
# congestions (max. 1 hour delay). On average the
# delay time will be half the maximum value. If in
# doubt about the consequences, use a larger value.
# Also keep in mind that the number of retransmissions
# is not changed by this setting, so the default of 20
# may no longer be appropriate. You might need to set
# MAX_ARP_RETRIES, MAX_BOOTP_RETRIES, MAX_TFTP_RETRIES
# and MAX_RPC_RETRIES to a larger value.
# -DTIMEOUT=n
# Use with care!! See above.
# Sets the base of RFC2131 sleep interval to n.
# This can be used with -DBACKOFF_LIMIT=0 to get a small
# and constant (predictable) retry interval for embedded
# devices. This is to achieve short boot delays if both
# the DHCP Server and the embedded device will be powered
# on the same time. Otherwise if the DHCP server is ready
# the client could sleep the next exponentially timeout,
# e.g. 70 seconds or more. This is not what you want.
# n should be a multiple of TICKS_PER_SEC (18).
#
# Boot device options:
#
# -DTRY_FLOPPY_FIRST
# If > 0, tries that many times to read the boot
# sector from a floppy drive before booting from
# ROM. If successful, does a local boot.
# It assumes the floppy is bootable.
# -DEXIT_IF_NO_OFFER
# If no IP offer is obtained, exit and
# let the BIOS continue.
# The accessibility of the TFTP server has no effect,
# so configure your DHCP/BOOTP server properly.
# You should probably reduce MAX_BOOTP_RETRIES
# to a small number like 3.
#
# Boot image options:
#
# -DFREEBSD_KERNEL_ENV
# Pass in FreeBSD kernel environment
# -DAOUT_LYNX_KDI
# Add Lynx a.out KDI support
# -DMULTICAST_LEVEL1
# Support for sending multicast packets
# -DMULTICAST_LEVEL2
# Support for receiving multicast packets
#
# Interface export options:
#
# -DPXE_EXPORT
# Export a PXE API interface. This is work in
# progress. Note that you won't be able to load
# PXE NBPs unless you also use -DPXE_IMAGE.
# -DPXE_STRICT
# Strict(er) compliance with the PXE
# specification as published by Intel. This may
# or may not be a good thing depending on your
# view of the spec...
# -DPXE_DHCP_STRICT
# Strict compliance of the DHCP request packets
# with the PXE specification as published by
# Intel. This may or may not be a good thing
# depending on your view of whether requesting
# vendor options which don't actually exist is
# pointless or not. You probably want this
# option if you intend to use Windows RIS or
# similar.
#
# Obscure options you probably don't need to touch:
#
# -DZPXE_SUFFIX_STRIP
# If the last 5 characters of the filename passed to Etherboot is
# ".zpxe" then strip it off. This is useful in cases where a DHCP server
# is not able to be configured to support conditionals. The way it works
# is that the DHCP server is configured with a filename like
# "foo.nbi.zpxe" so that when PXE asks for a filename it gets that, and
# loads Etherboot from that file. Etherboot then starts up and once
# again asks the DHCP server for a filename and once again gets
# foo.nbi.zpxe, but with this option turned on loads "foo.nbi" instead.
# This allows people to use Etherboot who might not otherwise be able to
# because their DHCP servers won't let them.
#
# -DPOWERSAVE
# Halt the processor when waiting for keyboard input
# which saves power while waiting for user interaction.
# Good for compute clusters and VMware emulation.
# But may not work for all CPUs.
#
# @/OptionDescription@
# These default settings compile Etherboot with a small number of options.
# You may wish to enable more of the features if the size of your ROM allows.
# For prompting and default on timeout
# CFLAGS+= -DASK_BOOT=3 -DBOOT_FIRST=BOOT_NIC
# If you would like to attempt to boot from other devices as well as the network.
# CFLAGS+= -DBOOT_SECOND=BOOT_FLOPPY
# CFLAGS+= -DBOOT_THIRD=BOOT_DISK
# CFLAGS+= -DBOOT_INDEX=0
# If you prefer the old style rotating bar progress display
# CFLAGS+= -DBAR_PROGRESS
# Show size indicator
# CFLAGS+= -DSIZEINDICATOR
# Enabling this creates non-standard images which use ports 1067 and 1068
# for DHCP/BOOTP
# CFLAGS+= -DALTERNATE_DHCP_PORTS_1067_1068
# Enabling this makes the boot ROM require a Vendor Class Identifier
# of "Etherboot" in the Vendor Encapsulated Options
# This can be used to reject replies from servers other than the one
# we want to give out addresses to us, but it will prevent Etherboot
# from getting an IP lease until you have configured DHCPD correctly
# CFLAGS+= -DREQUIRE_VCI_ETHERBOOT
# EXPERIMENTAL! Set DHCP_CLIENT_ID to create a Client Identifier (DHCP
# option 61, see RFC2132 section 9.14) when Etherboot sends the DHCP
# DISCOVER and REQUEST packets. This ID must UNIQUELY identify each
# client on your local network. Set DHCP_CLIENT_ID_TYPE to the
# appropriate hardware type as described in RFC2132 / RFC1700; this
# almost certainly means using '1' if the Client ID is an Ethernet MAC
# address and '0' otherwise. Set DHCP_CLIENT_ID_LEN to the length of
# the Client ID in octets (this is not a null terminated C string, do
# NOT add 1 for a terminator and do NOT add an extra 1 for the
# hardware type octet). Note that to identify your client using the
# normal default MAC address of your NIC, you do NOT need to set this
# option, as the MAC address is automatically used in the
# hwtype/chaddr field; note also that this field only sets the DHCP
# option: it does NOT change the MAC address used by the client.
# CFLAGS+= -DDHCP_CLIENT_ID="'C','L','I','E','N','T','0','0','1'" \
# -DDHCP_CLIENT_ID_LEN=9 -DDHCP_CLIENT_ID_TYPE=0
# CFLAGS+= -DDHCP_CLIENT_ID="0xDE,0xAD,0xBE,0xEF,0xDE,0xAD" \
# -DDHCP_CLIENT_ID_LEN=6 -DDHCP_CLIENT_ID_TYPE=1
# EXPERIMENTAL! Set DHCP_USER_CLASS to create a User Class option (see
# RFC3004) when Etherboot sends the DHCP DISCOVER and REQUEST packets.
# This can be used for classification of clients, typically so that a
# DHCP server can send an appropriately tailored reply. Normally, a
# string identifies a class of to which this client instance belongs
# which is useful in your network, such as a department ('FINANCE' or
# 'MARKETING') or hardware type ('THINCLIENT' or 'KIOSK'). Set
# DHCP_USER_CLASS_LEN to the length of DHCP_USER_CLASS in octets.
# This is NOT a null terminated C string, do NOT add 1 for a
# terminator. RFC3004 advises how to lay out multiple User Class
# options by using an octet for the length of each string, as in this
# example. It is, of course, up to the server to parse this.
# CFLAGS+= -DDHCP_USER_CLASS="'T','E','S','T','C','L','A','S','S'" \
# -DDHCP_USER_CLASS_LEN=9
# CFLAGS+= -DDHCP_USER_CLASS="5,'A','L','P','H','A',4,'B','E','T','A'" \
# -DDHCP_USER_CLASS_LEN=11
# Enabling this causes Etherboot to ignore Etherboot-specific options
# that are not within an Etherboot encapsulated options field.
# This option should be enabled unless you have a legacy DHCP server
# configuration from the bad old days before the use of
# encapsulated Etherboot options.
# CFLAGS+= -DALLOW_ONLY_ENCAPSULATED
# Disable DHCP support
# CFLAGS+= -DNO_DHCP_SUPPORT
# Specify a default bootfile to be used if the DHCP server does not
# provide the information. If you do not specify this option, then
# DHCP offers that do not contain bootfiles will be ignored.
# CFLAGS+= -DDEFAULT_BOOTFILE=\"tftp:///tftpboot/kernel\"
# Limit the delay on packet loss/congestion to a more bearable value. See
# description above. If unset, do not limit the delay between resend.
# CFLAGS+= -DBACKOFF_LIMIT=5 -DCONGESTED
# More optional features
# CFLAGS+= -DTRY_FLOPPY_FIRST=4
# CFLAGS+= -DEXIT_IF_NO_OFFER
# Multicast Support
# CFLAGS+= -DALLMULTI -DMULTICAST_LEVEL1 -DMULTICAST_LEVEL2
# Etherboot as a PXE network protocol ROM
# CFLAGS+= -DPXE_IMAGE -DPXE_EXPORT
# Etherboot stricter as a PXE network protocol ROM
# CFLAGS+= -DPXE_DHCP_STRICT
# Support for PXE emulation. Works only with FreeBSD to load the kernel
# via pxeboot, use only with DOWNLOAD_PROTO_NFS
# CFLAGS+= -DFREEBSD_PXEEMU
# Garbage from Makefile.main temporarily placed here until a home can
# be found for it.
# NS8390 options:
# -DINCLUDE_NE - Include NE1000/NE2000 support
# -DNE_SCAN=list - Probe for NE base address using list of
# comma separated hex addresses
# -DINCLUDE_3C503 - Include 3c503 support
# -DT503_SHMEM - Use 3c503 shared memory mode (off by default)
# -DINCLUDE_WD - Include Western Digital/SMC support
# -DWD_DEFAULT_MEM- Default memory location for WD/SMC cards
# -DWD_790_PIO - Read/write to WD/SMC 790 cards in PIO mode (default
# is to use shared memory) Try this if you get "Bogus
# packet, ignoring" messages, common on ISA/PCI hybrid
# systems.
# -DCOMPEX_RL2000_FIX
#
# If you have a Compex RL2000 PCI 32-bit (11F6:1401),
# and the bootrom hangs in "Probing...[NE*000/PCI]",
# try enabling this fix... it worked for me :).
# In the first packet write somehow it somehow doesn't
# get back the expected data so it is stuck in a loop.
# I didn't bother to investigate what or why because it works
# when I interrupt the loop if it takes more then COMPEX_RL2000_TRIES.
# The code will notify if it does a abort.
# SomniOne - somnione@gmx.net
#
# 3C90X options:
# Warning Warning Warning
# If you use any of the XCVR options below, please do not complain about
# the behaviour with Linux drivers to the kernel developers. You are
# on your own if you do this. Please read 3c90x.txt to understand
# what they do. If you don't understand them, ask for help on the
# Etherboot mailing list. And please document what you did to the NIC
# on the NIC so that people after you won't get nasty surprises.
#
# -DCFG_3C90X_PRESERVE_XCVR - Reset the transceiver type to the value it
# had initially just before the loaded code is started.
# -DCFG_3C90X_XCVR - Hardcode the tranceiver type Etherboot uses.
# -DCFG_3C90X_BOOTROM_FIX - If you have a 3c905B with buggy ROM
# interface, setting this option might "fix" it. Use
# with caution and read the docs in 3c90x.txt!
#
# See the documentation file 3c90x.txt for more details.
#
# CS89X0 (optional) options:
# -DISA_PROBE_ADDRS=list
# Probe for CS89x0 base address using list of
# comma separated hex addresses; increasing the
# address by one (0x300 -> 0x301) will force a
# more aggressive probing algorithm. This might
# be neccessary after a soft-reset of the NIC.
CFLAGS_3c503 = -DINCLUDE_3C503 # -DT503_SHMEM
CFLAGS_ne = -DINCLUDE_NE -DNE_SCAN=0x300,0x280,0x320,0x340,0x380
CFLAGS_ns8390 = -DINCLUDE_NS8390 # NE2000/PCI!
CFLAGS_wd = -DINCLUDE_WD -DWD_DEFAULT_MEM=0xCC000
+88 -129
View File
@@ -1,19 +1,17 @@
# Location to place generated files
###############################################################################
#
BIN := bin
# Initialise variables that get added to throughout the various Makefiles
# Initialise various variables
#
MAKEDEPS := Makefile .toolcheck .echocheck
SRCDIRS :=
SRCS :=
NON_AUTO_SRCS :=
DRIVERS :=
ROMS :=
MEDIA :=
NON_AUTO_MEDIA :=
# Locations of utilities
CLEANUP :=
CFLAGS :=
ASFLAGS :=
LDFLAGS :=
MAKEDEPS := Makefile
###############################################################################
#
# Locations of tools
#
HOST_CC := gcc
RM := rm -f
@@ -24,7 +22,7 @@ ECHO := echo
PRINTF := printf
PERL := /usr/bin/perl
CC := $(CROSS_COMPILE)gcc
CPP := $(CROSS_COMPILE)gcc -E -Wp,-Wall
CPP := $(CC) -E
AS := $(CROSS_COMPILE)as
LD := $(CROSS_COMPILE)ld
SIZE := $(CROSS_COMPILE)size
@@ -35,129 +33,41 @@ NM := $(CROSS_COMPILE)nm
OBJDUMP := $(CROSS_COMPILE)objdump
PARSEROM := $(PERL) ./util/parserom.pl
MAKEROM := $(PERL) ./util/makerom.pl
MKCONFIG := $(PERL) ./util/mkconfig.pl
SYMCHECK := $(PERL) ./util/symcheck.pl
SORTOBJDUMP := $(PERL) ./util/sortobjdump.pl
PADIMG := $(PERL) ./util/padimg.pl
LICENCE := $(PERL) ./util/licence.pl
NRV2B := ./util/nrv2b
ZBIN := ./util/zbin
ELF2EFI32 := ./util/elf2efi32
ELF2EFI64 := ./util/elf2efi64
EFIROM := ./util/efirom
ICCFIX := ./util/iccfix
DOXYGEN := doxygen
BINUTILS_DIR := /usr
BFD_DIR := $(BINUTILS_DIR)
# If invoked with no build target, print out a helpfully suggestive
# message.
###############################################################################
#
noargs : blib $(BIN)/NIC $(BIN)/gpxe.dsk $(BIN)/gpxe.iso $(BIN)/gpxe.usb
@$(ECHO) '==========================================================='
@$(ECHO)
@$(ECHO) 'To create a bootable floppy, type'
@$(ECHO) ' cat $(BIN)/gpxe.dsk > /dev/fd0'
@$(ECHO) 'where /dev/fd0 is your floppy drive. This will erase any'
@$(ECHO) 'data already on the disk.'
@$(ECHO)
@$(ECHO) 'To create a bootable USB key, type'
@$(ECHO) ' cat $(BIN)/gpxe.usb > /dev/sdX'
@$(ECHO) 'where /dev/sdX is your USB key, and is *not* a real hard'
@$(ECHO) 'disk on your system. This will erase any data already on'
@$(ECHO) 'the USB key.'
@$(ECHO)
@$(ECHO) 'To create a bootable CD-ROM, burn the ISO image '
@$(ECHO) '$(BIN)/gpxe.iso to a blank CD-ROM.'
@$(ECHO)
@$(ECHO) 'These images contain drivers for all supported cards. You'
@$(ECHO) 'can build more customised images, and ROM images, using'
@$(ECHO) ' make bin/<rom-name>.<output-format>'
@$(ECHO)
@$(ECHO) '==========================================================='
# Grab the central Config file.
#
MAKEDEPS += Config
include Config
# If no architecture is specified in Config or on the command-line,
# use that of the build machine.
#
ARCH ?= $(shell uname -m | sed -e s,i[3456789]86,i386,)
# handle x86_64 like i386, but set -m32 option for 32bit code only
ifeq ($(ARCH),x86_64)
ARCH := i386
CFLAGS += -m32
ASFLAGS += --32
LDFLAGS += -m elf_i386
endif
# Drag in architecture-specific Config
#
MAKEDEPS += arch/$(ARCH)/Config
include arch/$(ARCH)/Config
# Common flags
#
CFLAGS += -I include -I arch/$(ARCH)/include -I . -DARCH=$(ARCH)
CFLAGS += -Os -ffreestanding
CFLAGS += -Wall -W
CFLAGS += -g
CFLAGS += $(EXTRA_CFLAGS)
ASFLAGS += $(EXTRA_ASFLAGS)
LDFLAGS += $(EXTRA_LDFLAGS)
# Embedded image, if present
#
EMBEDDED_IMAGE ?= /dev/null
ifneq ($(NO_WERROR),1)
CFLAGS += -Werror
endif
# CFLAGS for specific object types
#
CFLAGS_c +=
CFLAGS_S += -DASSEMBLY
# Base object name of the current target
#
OBJECT = $(firstword $(subst ., ,$(@F)))
# CFLAGS for specific object files. You can define
# e.g. CFLAGS_rtl8139, and have those flags automatically used when
# compiling bin/rtl8139.o.
#
OBJ_CFLAGS = $(CFLAGS_$(OBJECT)) -DOBJECT=$(subst -,_,$(OBJECT))
$(BIN)/%.flags :
@$(ECHO) $(OBJ_CFLAGS)
# Rules for specific object types.
#
COMPILE_c = $(CC) $(CFLAGS) $(CFLAGS_c) $(OBJ_CFLAGS)
RULE_c = $(Q)$(COMPILE_c) -c $< -o $@
RULE_c_to_dbg%.o = $(Q)$(COMPILE_c) -Ddebug_$(OBJECT)=$* -c $< -o $@
RULE_c_to_c = $(Q)$(COMPILE_c) -E -c $< > $@
RULE_c_to_s = $(Q)$(COMPILE_c) -S -g0 -c $< -o $@
PREPROCESS_S = $(CPP) $(CFLAGS) $(CFLAGS_S) $(OBJ_CFLAGS)
ASSEMBLE_S = $(AS) $(ASFLAGS)
RULE_S = $(Q)$(PREPROCESS_S) $< | $(ASSEMBLE_S) -o $@
RULE_S_to_s = $(Q)$(PREPROCESS_S) $< > $@
DEBUG_TARGETS += dbg%.o c s
# SRCDIRS lists all directories containing source files.
#
SRCDIRS :=
SRCDIRS += libgcc
SRCDIRS += core
SRCDIRS += proto
SRCDIRS += net net/tcp net/udp
SRCDIRS += net net/tcp net/udp net/infiniband net/80211
SRCDIRS += image
SRCDIRS += drivers/bus
SRCDIRS += drivers/net
SRCDIRS += drivers/net/e1000
SRCDIRS += drivers/net/phantom
SRCDIRS += drivers/net/rtl818x
SRCDIRS += drivers/net/ath5k
SRCDIRS += drivers/block
SRCDIRS += drivers/scsi
SRCDIRS += drivers/ata
SRCDIRS += drivers/nvs
SRCDIRS += drivers/bitbash
SRCDIRS += drivers/infiniband
SRCDIRS += interface/pxe
SRCDIRS += interface/pxe interface/efi interface/smbios
SRCDIRS += tests
SRCDIRS += crypto crypto/axtls crypto/matrixssl
SRCDIRS += hci hci/commands hci/tui
@@ -167,25 +77,74 @@ SRCDIRS += usr
# NON_AUTO_SRCS lists files that are excluded from the normal
# automatic build system.
#
NON_AUTO_SRCS += core/elf_loader.c
NON_AUTO_SRCS :=
NON_AUTO_SRCS += drivers/net/prism2.c
# Rules for finalising files. TGT_MAKEROM_FLAGS is defined as part of
# the automatic build system and varies by target; it includes the
# "-p 0x1234,0x5678" string to set the PCI IDs.
# INCDIRS lists the include path
#
FINALISE_rom = $(MAKEROM) $(MAKEROM_FLAGS) $(TGT_MAKEROM_FLAGS) \
-i$(IDENT) -s 0 $@
INCDIRS :=
INCDIRS += include .
# Some ROMs require specific flags to be passed to makerom.pl
###############################################################################
#
MAKEROM_FLAGS_3c503 = -3
# Default build target: build the most common targets and print out a
# helpfully suggestive message
#
all : bin/blib.a bin/gpxe.dsk bin/gpxe.iso bin/gpxe.usb bin/undionly.kpxe
@$(ECHO) '==========================================================='
@$(ECHO)
@$(ECHO) 'To create a bootable floppy, type'
@$(ECHO) ' cat bin/gpxe.dsk > /dev/fd0'
@$(ECHO) 'where /dev/fd0 is your floppy drive. This will erase any'
@$(ECHO) 'data already on the disk.'
@$(ECHO)
@$(ECHO) 'To create a bootable USB key, type'
@$(ECHO) ' cat bin/gpxe.usb > /dev/sdX'
@$(ECHO) 'where /dev/sdX is your USB key, and is *not* a real hard'
@$(ECHO) 'disk on your system. This will erase any data already on'
@$(ECHO) 'the USB key.'
@$(ECHO)
@$(ECHO) 'To create a bootable CD-ROM, burn the ISO image '
@$(ECHO) 'bin/gpxe.iso to a blank CD-ROM.'
@$(ECHO)
@$(ECHO) 'These images contain drivers for all supported cards. You'
@$(ECHO) 'can build more customised images, and ROM images, using'
@$(ECHO) ' make bin/<rom-name>.<output-format>'
@$(ECHO)
@$(ECHO) '==========================================================='
# Drag in architecture-specific Makefile
###############################################################################
#
# Build targets that do nothing but might be tried by users
#
configure :
@$(ECHO) "No configuration needed."
install :
@$(ECHO) "No installation required."
###############################################################################
#
# Version number calculations
#
VERSION_MAJOR = 0
VERSION_MINOR = 9
VERSION_PATCH = 9
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 :
@$(ECHO) $(VERSION)
###############################################################################
#
# Drag in the bulk of the build system
#
MAKEDEPS += arch/$(ARCH)/Makefile
include arch/$(ARCH)/Makefile
# Drag in the automatic build system and other housekeeping functions
MAKEDEPS += Makefile.housekeeping
include Makefile.housekeeping
+547 -149
View File
@@ -1,50 +1,10 @@
# -*- makefile -*- : Force emacs to use Makefile mode
#
# This file contains various boring housekeeping functions that would
# otherwise seriously clutter up the main Makefile.
# Objects to be removed by "make clean"
###############################################################################
#
CLEANUP := $(BIN)/*.* # *.* to avoid catching the "CVS" directory
# Version number calculations
#
VERSION_MAJOR = 0
VERSION_MINOR = 9
VERSION_PATCH = 3
EXTRAVERSION =
MM_VERSION = $(VERSION_MAJOR).$(VERSION_MINOR)
VERSION = $(MM_VERSION).$(VERSION_PATCH)$(EXTRAVERSION)
CFLAGS += -DVERSION_MAJOR=$(VERSION_MAJOR) \
-DVERSION_MINOR=$(VERSION_MINOR) \
-DVERSION=\"$(VERSION)\"
IDENT = '$(@F) $(VERSION) (GPL) etherboot.org'
version :
@$(ECHO) $(VERSION)
configure :
@$(ECHO) "No configuration needed."
install :
@$(ECHO) "No installation required. Generated images will be placed in the" $(BIN) "directory."
# Check for tools that can cause failed builds
#
.toolcheck : Makefile Config
@if $(CC) -v 2>&1 | grep -is 'gcc version 2\.96' > /dev/null; then \
$(ECHO) 'gcc 2.96 is unsuitable for compiling Etherboot'; \
$(ECHO) 'Use gcc 2.95 or gcc 3.x instead'; \
exit 1; \
fi
@if [ `perl -e 'use bytes; print chr(255)' | wc -c` = 2 ]; then \
$(ECHO) 'Your Perl version has a Unicode handling bug'; \
$(ECHO) 'Execute this command before compiling Etherboot:'; \
$(ECHO) 'export LANG=$${LANG%.UTF-8}'; \
exit 1; \
fi
@$(TOUCH) $@
VERYCLEANUP += .toolcheck
# Find a usable "echo -e" substitute.
#
TAB := $(shell $(PRINTF) '\t')
@@ -58,16 +18,16 @@ ECHO_E_BIN_ECHO_TAB := $(shell $(ECHO_E_BIN_ECHO) '\t')
ECHO_E_BIN_ECHO_E_TAB := $(shell $(ECHO_E_BIN_ECHO_E) '\t')
ifeq ($(ECHO_E_ECHO_TAB),$(TAB))
ECHO_E ?= $(ECHO_E_ECHO)
ECHO_E := $(ECHO_E_ECHO)
endif
ifeq ($(ECHO_E_ECHO_E_TAB),$(TAB))
ECHO_E ?= $(ECHO_E_ECHO_E)
ECHO_E := $(ECHO_E_ECHO_E)
endif
ifeq ($(ECHO_E_BIN_ECHO_TAB),$(TAB))
ECHO_E ?= $(ECHO_E_BIN_ECHO)
ECHO_E := $(ECHO_E_BIN_ECHO)
endif
ifeq ($(ECHO_E_BIN_ECHO_E_TAB),$(TAB))
ECHO_E ?= $(ECHO_E_BIN_ECHO_E)
ECHO_E := $(ECHO_E_BIN_ECHO_E)
endif
.echocheck :
@@ -86,20 +46,75 @@ else
@$(ECHO) "No usable \"echo -e\" substitute found"
@exit 1
endif
MAKEDEPS += .echocheck
VERYCLEANUP += .echocheck
echo :
@$(ECHO) "Using \"$(ECHO_E)\" for \"echo -e\""
# Build verbosity
###############################################################################
#
ifeq ($(V),1)
Q =
QM = @\#
# Generate a usable "seq" substitute
#
define seq
$(shell awk 'BEGIN { for ( i = $(1) ; i <= $(2) ; i++ ) print i }')
endef
###############################################################################
#
# Determine host OS
#
HOST_OS := $(shell uname -s)
hostos :
@$(ECHO) $(HOST_OS)
###############################################################################
#
# Determine compiler
CCDEFS := $(shell $(CC) -E -x c -c /dev/null -dM | cut -d" " -f2)
ccdefs:
@$(ECHO) $(CCDEFS)
ifeq ($(filter __ICC,$(CCDEFS)),__ICC)
CCTYPE := icc
else
Q = @
QM = @
CCTYPE := gcc
endif
cctype:
@$(ECHO) $(CCTYPE)
###############################################################################
#
# Check for tools that can cause failed builds
#
.toolcheck :
@if $(CC) -v 2>&1 | grep -is 'gcc version 2\.96' > /dev/null; then \
$(ECHO) 'gcc 2.96 is unsuitable for compiling Etherboot'; \
$(ECHO) 'Use gcc 2.95 or gcc 3.x instead'; \
exit 1; \
fi
@if [ `perl -e 'use bytes; print chr(255)' | wc -c` = 2 ]; then \
$(ECHO) 'Your Perl version has a Unicode handling bug'; \
$(ECHO) 'Execute this command before compiling Etherboot:'; \
$(ECHO) 'export LANG=$${LANG%.UTF-8}'; \
exit 1; \
fi
@$(TOUCH) $@
MAKEDEPS += .toolcheck
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)
#
@@ -112,18 +127,179 @@ oldgas :
# default, even when -ffreestanding is specified. We therefore need
# to disable -fstack-protector if the compiler supports it.
#
SP_TEST = $(CC) -fno-stack-protector -x c -E - < /dev/null >/dev/null 2>&1
ifeq ($(CCTYPE),gcc)
SP_TEST = $(CC) -fno-stack-protector -x c -c /dev/null \
-o /dev/null >/dev/null 2>&1
SP_FLAGS := $(shell $(SP_TEST) && $(ECHO) '-fno-stack-protector')
CFLAGS += $(SP_FLAGS)
endif
# compiler.h is needed for our linking and debugging system
# gcc 4.4 generates .eh_frame sections by default, which distort the
# output of "size". Inhibit this.
#
CFLAGS += -include compiler.h
ifeq ($(CCTYPE),gcc)
CFI_TEST = $(CC) -fno-dwarf2-cfi-asm -x c -c /dev/null \
-o /dev/null >/dev/null 2>&1
CFI_FLAGS := $(shell $(CFI_TEST) && $(ECHO) '-fno-dwarf2-cfi-asm')
CFLAGS += $(CFI_FLAGS)
endif
# config/%.h files are generated from config.h using mkconfig.pl
config/%.h : config.h
$(MKCONFIG) $<
CLEANUP += config/*.h
# Some versions of gas choke on division operators, treating them as
# comment markers. Specifying --divide will work around this problem,
# but isn't available on older gas versions.
#
DIVIDE_TEST = $(AS) --divide /dev/null -o /dev/null 2>/dev/null
DIVIDE_FLAGS := $(shell $(DIVIDE_TEST) && $(ECHO) '--divide')
ASFLAGS += $(DIVIDE_FLAGS)
###############################################################################
#
# Build verbosity
#
ifeq ($(V),1)
Q :=
QM := @\#
else
Q := @
QM := @
endif
###############################################################################
#
# Set BIN according to whatever was specified on the command line as
# the build target.
#
# Determine how many different BIN directories are mentioned in the
# make goals.
#
BIN_GOALS := $(filter bin/% bin-%,$(MAKECMDGOALS))
BIN_GOAL_BINS := $(foreach BG,$(BIN_GOALS),$(firstword $(subst /, ,$(BG))))
NUM_BINS := $(words $(sort $(BIN_GOAL_BINS)))
ifeq ($(NUM_BINS),0)
# No BIN directory was specified. Set BIN to "bin" as a sensible
# default.
BIN := bin
else # NUM_BINS == 0
ifeq ($(NUM_BINS),1)
# If exactly one BIN directory was specified, set BIN to match this
# directory.
#
BIN := $(firstword $(BIN_GOAL_BINS))
else # NUM_BINS == 1
# More than one BIN directory was specified. We cannot handle the
# latter case within a single make invocation, so set up recursive
# targets for each BIN directory.
#
# Leave $(BIN) undefined. This has implications for any target that
# depends on $(BIN); such targets should be made conditional upon the
# existence of $(BIN).
#
$(BIN_GOALS) : % : BIN_RECURSE
$(Q)$(MAKE) --no-print-directory BIN=$(firstword $(subst /, ,$@)) $@
.PHONY : BIN_RECURSE
endif # NUM_BINS == 1
endif # NUM_BINS == 0
ifdef BIN
# Create $(BIN) directory if it doesn't exist yet
#
ifeq ($(wildcard $(BIN)),)
$(shell $(MKDIR) -p $(BIN))
endif
# Target to allow e.g. "make bin-efi arch"
#
$(BIN) :
@# Do nothing, silently
.PHONY : $(BIN)
# Remove everything in $(BIN) for a "make clean"
#
CLEANUP += $(BIN)/*.* # Avoid picking up directories
endif # defined(BIN)
# Determine whether or not we need to include the dependency files
#
NO_DEP_TARGETS := $(BIN) clean veryclean
ifeq ($(MAKECMDGOALS),)
NEED_DEPS := 1
endif
ifneq ($(strip $(filter-out $(NO_DEP_TARGETS),$(MAKECMDGOALS))),)
NEED_DEPS := 1
endif
###############################################################################
#
# Select build architecture and platform based on $(BIN)
#
# BIN has the form bin[-[arch-]platform]
ARCHS := $(patsubst arch/%,%,$(wildcard arch/*))
PLATFORMS := $(patsubst config/defaults/%.h,%,\
$(wildcard config/defaults/*.h))
archs :
@$(ECHO) $(ARCHS)
platforms :
@$(ECHO) $(PLATFORMS)
ifdef BIN
# Determine architecture portion of $(BIN), if present
BIN_ARCH := $(strip $(foreach A,$(ARCHS),\
$(patsubst bin-$(A)-%,$(A),\
$(filter bin-$(A)-%,$(BIN)))))
# Determine platform portion of $(BIN), if present
ifeq ($(BIN_ARCH),)
BIN_PLATFORM := $(patsubst bin-%,%,$(filter bin-%,$(BIN)))
else
BIN_PLATFORM := $(patsubst bin-$(BIN_ARCH)-%,%,$(BIN))
endif
# Determine build architecture
DEFAULT_ARCH := i386
ARCH := $(firstword $(BIN_ARCH) $(DEFAULT_ARCH))
CFLAGS += -DARCH=$(ARCH)
arch :
@$(ECHO) $(ARCH)
.PHONY : arch
# Determine build platform
DEFAULT_PLATFORM := pcbios
PLATFORM := $(firstword $(BIN_PLATFORM) $(DEFAULT_PLATFORM))
CFLAGS += -DPLATFORM=$(PLATFORM)
platform :
@$(ECHO) $(PLATFORM)
endif # defined(BIN)
# Include architecture-specific Makefile
ifdef ARCH
MAKEDEPS += arch/$(ARCH)/Makefile
include arch/$(ARCH)/Makefile
endif
# Include architecture-specific include path
ifdef ARCH
INCDIRS += arch/$(ARCH)/include
endif
###############################################################################
#
# Source file handling
# SRCDIRS lists all directories containing source files.
srcdirs :
@@ -144,6 +320,107 @@ AUTO_SRCS = $(filter-out $(NON_AUTO_SRCS),$(SRCS))
autosrcs :
@$(ECHO) $(AUTO_SRCS)
# Just about everything else in this section depends upon having
# $(BIN) set
ifdef BIN
# INCDIRS lists the include path
incdirs :
@$(ECHO) $(INCDIRS)
# Common flags
#
CFLAGS += $(foreach INC,$(INCDIRS),-I$(INC))
CFLAGS += -Os
CFLAGS += -g
ifeq ($(CCTYPE),gcc)
CFLAGS += -ffreestanding
CFLAGS += -Wall -W -Wformat-nonliteral
endif
ifeq ($(CCTYPE),icc)
CFLAGS += -fno-builtin
CFLAGS += -no-ip
CFLAGS += -no-gcc
CFLAGS += -diag-disable 111 # Unreachable code
CFLAGS += -diag-disable 128 # Unreachable loop
CFLAGS += -diag-disable 170 # Array boundary checks
CFLAGS += -diag-disable 177 # Unused functions
CFLAGS += -diag-disable 181 # printf() format checks
CFLAGS += -diag-disable 188 # enum strictness
CFLAGS += -diag-disable 193 # Undefined preprocessor identifiers
CFLAGS += -diag-disable 280 # switch ( constant )
CFLAGS += -diag-disable 310 # K&R parameter lists
CFLAGS += -diag-disable 424 # Extra semicolon
CFLAGS += -diag-disable 589 # Declarations mid-code
CFLAGS += -diag-disable 593 # Unused variables
CFLAGS += -diag-disable 810 # Casting ints to smaller ints
CFLAGS += -diag-disable 981 # Sequence point violations
CFLAGS += -diag-disable 1292 # Ignored attributes
CFLAGS += -diag-disable 1338 # void pointer arithmetic
CFLAGS += -diag-disable 1361 # Variable-length arrays
CFLAGS += -diag-disable 1418 # Missing prototypes
CFLAGS += -diag-disable 1419 # Missing prototypes
CFLAGS += -diag-disable 1599 # Hidden variables
CFLAGS += -Wall -Wmissing-declarations
endif
CFLAGS += $(EXTRA_CFLAGS)
ASFLAGS += $(EXTRA_ASFLAGS)
LDFLAGS += $(EXTRA_LDFLAGS)
# 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
#
CFLAGS += -include compiler.h
# CFLAGS for specific object types
#
CFLAGS_c +=
CFLAGS_S += -DASSEMBLY
# Base object name of the current target
#
OBJECT = $(firstword $(subst ., ,$(@F)))
# CFLAGS for specific object files. You can define
# e.g. CFLAGS_rtl8139, and have those flags automatically used when
# compiling bin/rtl8139.o.
#
OBJ_CFLAGS = $(CFLAGS_$(OBJECT)) -DOBJECT=$(subst -,_,$(OBJECT))
$(BIN)/%.flags :
@$(ECHO) $(OBJ_CFLAGS)
# ICC requires postprocessing objects to fix up table alignments
#
ifeq ($(CCTYPE),icc)
POST_O = && $(ICCFIX) $@
POST_O_DEPS := $(ICCFIX)
else
POST_O :=
POST_O_DEPS :=
endif
# Rules for specific object types.
#
COMPILE_c = $(CC) $(CFLAGS) $(CFLAGS_c) $(OBJ_CFLAGS)
RULE_c = $(Q)$(COMPILE_c) -c $< -o $@ $(POST_O)
RULE_c_to_dbg%.o = $(Q)$(COMPILE_c) -Ddebug_$(subst -,_,$(OBJECT))=$* -c $< -o $@ $(POST_O)
RULE_c_to_c = $(Q)$(COMPILE_c) -E -c $< > $@
RULE_c_to_s = $(Q)$(COMPILE_c) -S -g0 -c $< -o $@
PREPROCESS_S = $(CPP) $(CFLAGS) $(CFLAGS_S) $(OBJ_CFLAGS)
ASSEMBLE_S = $(AS) $(ASFLAGS)
RULE_S = $(Q)$(PREPROCESS_S) $< | $(ASSEMBLE_S) -o $@
RULE_S_to_s = $(Q)$(PREPROCESS_S) $< > $@
DEBUG_TARGETS += dbg%.o c s
# We automatically generate rules for any file mentioned in AUTO_SRCS
# using the following set of templates. It would be cleaner to use
# $(eval ...), but this function exists only in GNU make >= 3.80.
@@ -157,43 +434,29 @@ autosrcs :
#
define src_template
@$(ECHO) "Generating Makefile rules for $(1)"
@$(ECHO) " [DEPS] $(1)"
@$(MKDIR) -p $(dir $(2))
@$(RM) $(2)
@$(TOUCH) $(2)
$(foreach OBJ,$(if $(OBJS_$(4)),$(OBJS_$(4)),$(4)), \
$(call obj_template,$(1),$(2),$(3),$(OBJ)))
@$(PARSEROM) $(1) >> $(2)
endef
# obj_template : generate Makefile rules for a given resultant object
# of a particular source file. (We can have multiple objects per
# source file via the OBJS_xxx list.)
#
# $(1) is the full path to the source file (e.g. "drivers/net/rtl8139.c")
# $(2) is the full path to the .d file (e.g. "bin/deps/drivers/net/rtl8139.d")
# $(3) is the source type (e.g. "c")
# $(4) is the object name (e.g. "rtl8139")
#
define obj_template
@$(CPP) $(CFLAGS) $(CFLAGS_$(3)) $(CFLAGS_$(4)) -DOBJECT=$(4) \
-Wno-error -M $(1) -MT "$(4)_DEPS" -MG -MP | \
sed 's/_DEPS\s*:/_DEPS =/' >> $(2)
@$(ECHO_E) '\n$$(BIN)/$(4).o : $(1) $$(MAKEDEPS) $$($(4)_DEPS)' \
'\n\t$$(QM)$(ECHO) " [BUILD] $$@"\n' \
-Wno-error -MM $(1) -MG -MP | \
sed 's/\.o\s*:/_DEPS =/' >> $(2)
@$(ECHO_E) '\n$$(BIN)/$(4).o :' \
'$(1) $$(MAKEDEPS) $$(POST_O_DEPS) $$($(4)_DEPS)' \
'\n\t$$(QM)$(ECHO) " [BUILD] $$@"' \
'\n\t$$(RULE_$(3))\n' \
'\nBOBJS += $$(BIN)/$(4).o\n' \
$(foreach TGT,$(DEBUG_TARGETS), \
$(if $(RULE_$(3)_to_$(TGT)), \
'\n$$(BIN)/$(4).$(TGT) : $(1) $$(MAKEDEPS) $$($(4)_DEPS)' \
'\n\t$$(QM)$(ECHO) " [BUILD] $$@"\n' \
'\n$$(BIN)/$(4).$(TGT) :' \
'$(1) $$(MAKEDEPS) $$(POST_O_DEPS) $$($(4)_DEPS)' \
'\n\t$$(QM)$(ECHO) " [BUILD] $$@"' \
'\n\t$$(RULE_$(3)_to_$(TGT))\n' \
'\n$(TGT)_OBJS += $$(BIN)/$(4).$(TGT)\n' ) ) \
'\n$(2) : $$($(4)_DEPS)\n' \
'\nTAGS : $$($(4)_DEPS)\n' \
>> $(2)
@$(PARSEROM) $(1) >> $(2)
endef
@@ -205,7 +468,11 @@ $(BIN)/deps/%.d : % $(MAKEDEPS) $(PARSEROM)
# Calculate and include the list of Makefile rules files
#
AUTO_DEPS = $(patsubst %,$(BIN)/deps/%.d,$(AUTO_SRCS))
include $(AUTO_DEPS)
ifdef NEED_DEPS
ifneq ($(AUTO_DEPS),)
-include $(AUTO_DEPS)
endif
endif
autodeps :
@$(ECHO) $(AUTO_DEPS)
VERYCLEANUP += $(BIN)/deps
@@ -220,13 +487,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 := <invalid>
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,$(call 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.
@@ -237,7 +522,7 @@ $(BIN)/NIC : $(AUTO_DEPS)
'it is only for rom-o-matic' >> $@
@$(ECHO) >> $@
@perl -ne 'chomp; print "$$1\n" if /\# NIC\t(.*)$$/' $^ >> $@
CLEANUP += $(BIN)/NIC
CLEANUP += $(BIN)/NIC # Doesn't match the $(BIN)/*.* pattern
# Analyse a target name (e.g. "bin/dfe538--prism2_pci.zrom.tmp") and
# derive the variables:
@@ -278,8 +563,8 @@ TGT_PCI_DEVICE = $(PCI_DEVICE_$(TGT_ROM_NAME))
#
TGT_LD_DRIVERS = $(subst -,_,$(patsubst %,obj_%,$(TGT_DRIVERS)))
TGT_LD_PREFIX = obj_$(TGT_PREFIX)prefix
TGT_LD_IDS = $(if $(TGT_PCI_VENDOR),pci_vendor_id=$(TGT_PCI_VENDOR)) \
$(if $(TGT_PCI_DEVICE),pci_device_id=$(TGT_PCI_DEVICE))
TGT_LD_IDS = pci_vendor_id=$(firstword $(TGT_PCI_VENDOR) 0) \
pci_device_id=$(firstword $(TGT_PCI_DEVICE) 0)
# Calculate linker flags based on link-time options for the current
# target type (e.g. "bin/dfe538--prism2_pci.zrom.tmp") and derive the
@@ -305,7 +590,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))
@@ -342,8 +626,13 @@ $(BIN)/%.info :
# in order to correctly rebuild blib whenever the list of objects
# changes.
#
BLIB_LIST = $(BIN)/.blib.list
ifneq ($(shell cat $(BLIB_LIST)),$(BLIB_OBJS))
BLIB_LIST := $(BIN)/.blib.list
ifeq ($(wildcard $(BLIB_LIST)),)
BLIB_LIST_OBJS := <invalid>
else
BLIB_LIST_OBJS := $(shell cat $(BLIB_LIST))
endif
ifneq ($(BLIB_LIST_OBJS),$(BLIB_OBJS))
$(shell $(ECHO) "$(BLIB_OBJS)" > $(BLIB_LIST))
endif
@@ -371,13 +660,62 @@ $(BIN)/%.tmp : $(BLIB) $(MAKEDEPS) $(LDSCRIPT)
$(Q)$(OBJDUMP) -ht $@ | $(SORTOBJDUMP) >> $(BIN)/$*.tmp.map
# Keep intermediate object file (useful for debugging)
.SECONDARY : $(BIN)/%.tmp
.PRECIOUS : $(BIN)/%.tmp
# Show a linker map for the specified target
#
$(BIN)/%.map : $(BIN)/%.tmp
@less $(BIN)/$*.tmp.map
# Get objects list for the specified target
#
define objs_list
$(sort $(foreach OBJ_SYMBOL,\
$(filter obj_%,$(shell $(NM) $(1) | cut -d" " -f3)),\
$(patsubst obj_%,%,$(OBJ_SYMBOL))))
endef
$(BIN)/%.objs : $(BIN)/%.tmp
$(Q)$(ECHO) $(call objs_list,$<)
$(BIN)/%.sizes : $(BIN)/%.tmp
$(Q)$(SIZE) -t $(foreach OBJ,$(call objs_list,$<),$(BIN)/$(OBJ).o) | \
sort -g
# Get dependency list for the specified target
#
define deps_list
$(sort $(foreach OBJ,$(call objs_list,$(1)),$($(OBJ)_DEPS)))
endef
$(BIN)/%.deps : $(BIN)/%.tmp
$(Q)$(ECHO) $(call deps_list,$<)
# Get unneeded source files for the specified target
#
define nodeps_list
$(sort $(filter-out $(call deps_list,$(1)),\
$(foreach BOBJ,$(BOBJS),\
$($(basename $(notdir $(BOBJ)))_DEPS))))
endef
$(BIN)/%.nodeps : $(BIN)/%.tmp
$(Q)$(ECHO) $(call nodeps_list,$<)
# Get licensing verdict for the specified target
#
define unlicensed_deps_list
$(shell grep -L FILE_LICENCE $(call deps_list,$(1)))
endef
define licence_list
$(patsubst __licence_%,%,\
$(filter __licence_%,$(shell $(NM) $(1) | cut -d" " -f3)))
endef
$(BIN)/%.licence : $(BIN)/%.tmp
$(QM)$(ECHO) " [LICENCE] $@"
$(Q)$(if $(strip $(call unlicensed_deps_list,$<)),\
echo -n "Unable to determine licence because the following " ;\
echo "files are missing a licence declaration:" ;\
echo $(call unlicensed_deps_list,$<);\
exit 1,\
$(LICENCE) $(call licence_list,$<))
# Extract compression information from intermediate object file
#
$(BIN)/%.zinfo : $(BIN)/%.tmp
@@ -396,10 +734,6 @@ $(BIN)/%.zbin : $(BIN)/%.bin $(BIN)/%.zinfo $(ZBIN)
$(QM)$(ECHO) " [ZBIN] $@"
$(Q)$(ZBIN) $(BIN)/$*.bin $(BIN)/$*.zinfo > $@
# Build bochs symbol table
$(BIN)/%.bxs : $(BIN)/%.tmp
$(NM) $< | cut -d" " -f1,3 > $@
# Rules for each media format. These are generated and placed in an
# external Makefile fragment. We could do this via $(eval ...), but
# that would require make >= 3.80.
@@ -435,13 +769,14 @@ automedia :
#
define media_template
@$(ECHO) "Generating Makefile rules for $(1) media"
@$(ECHO) " [MEDIADEPS] $(1)"
@$(MKDIR) -p $(dir $(2))
@$(RM) $(2)
@$(TOUCH) $(2)
@$(ECHO_E) '$$(BIN)/%.$(1) : $$(BIN)/%.$(1).zbin' \
'\n\t$$(QM)$(ECHO) " [FINISH] $$@"' \
'\n\t$$(Q)$$(CP) $$< $$@' \
'\n\t$$(Q)$$(PAD_$(1))' \
'\n\t$$(Q)$$(FINALISE_$(1))' \
> $(2)
@@ -459,7 +794,20 @@ $(BIN)/deps/%.media.d : $(MAKEDEPS)
MEDIA_DEPS = $(patsubst %,$(BIN)/deps/%.media.d,$(AUTO_MEDIA))
mediadeps :
@$(ECHO) $(MEDIA_DEPS)
include $(MEDIA_DEPS)
ifdef NEED_DEPS
ifneq ($(MEDIA_DEPS),)
-include $(MEDIA_DEPS)
endif
endif
# Wrap up binary blobs (for embedded images)
#
$(BIN)/%.o : payload/%.img
$(QM)echo " [WRAP] $@"
$(Q)$(LD) -b binary -r -o $@ $< --undefined obj_payload \
--defsym obj_$*=0
BOBJS += $(patsubst payload/%.img,$(BIN)/%.o,$(wildcard payload/*.img))
# The "allXXXs" targets for each suffix
#
@@ -472,15 +820,23 @@ allpxes allisos alldsks : all%s : $(foreach DRIVER,$(DRIVERS),$(BIN)/$(DRIVER).%
$(BIN)/etherboot.% : $(BIN)/gpxe.%
ln -sf $(notdir $<) $@
# Wrap up binary blobs
endif # defined(BIN)
###############################################################################
#
$(BIN)/%.o : payload/%.img
$(QM)echo " [WRAP] $@"
$(Q)$(LD) -b binary -r -o $@ $< --undefined obj_payload \
--defsym obj_$*=0
# Rules for finalising files. TGT_MAKEROM_FLAGS is defined as part of
# the automatic build system and varies by target; it includes the
# "-p 0x1234,0x5678" string to set the PCI IDs.
#
FINALISE_rom = $(MAKEROM) $(MAKEROM_FLAGS) $(TGT_MAKEROM_FLAGS) \
-i$(IDENT) -s 0 $@
BOBJS += $(patsubst payload/%.img,$(BIN)/%.o,$(wildcard payload/*.img))
# Some ROMs require specific flags to be passed to makerom.pl
#
MAKEROM_FLAGS_3c503 = -3
###############################################################################
#
# The compression utilities
#
$(NRV2B) : util/nrv2b.c $(MAKEDEPS)
@@ -494,6 +850,40 @@ $(ZBIN) : util/zbin.c util/nrv2b.c $(MAKEDEPS)
$(Q)$(HOST_CC) -O2 -o $@ $<
CLEANUP += $(ZBIN)
###############################################################################
#
# The EFI image converter
#
ELF2EFI_CFLAGS := -I$(BINUTILS_DIR)/include -I$(BFD_DIR)/include \
-idirafter include -L$(BINUTILS_DIR)/lib -L$(BFD_DIR)/lib \
-lbfd -liberty -lz
$(ELF2EFI32) : util/elf2efi.c $(MAKEDEPS)
$(QM)$(ECHO) " [HOSTCC] $@"
$(Q)$(HOST_CC) $(ELF2EFI_CFLAGS) -DMDE_CPU_IA32 -O2 -o $@ $<
CLEANUP += $(ELF2EFI32)
$(ELF2EFI64) : util/elf2efi.c $(MAKEDEPS)
$(QM)$(ECHO) " [HOSTCC] $@"
$(Q)$(HOST_CC) $(ELF2EFI_CFLAGS) -DMDE_CPU_X64 -O2 -o $@ $<
CLEANUP += $(ELF2EFI64)
$(EFIROM) : util/efirom.c $(MAKEDEPS)
$(QM)$(ECHO) " [HOSTCC] $@"
$(Q)$(HOST_CC) -idirafter include -O2 -o $@ $<
CLEANUP += $(EFIROM)
###############################################################################
#
# The ICC fixup utility
#
$(ICCFIX) : util/iccfix.c $(MAKEDEPS)
$(QM)$(ECHO) " [HOSTCC] $@"
$(Q)$(HOST_CC) -idirafter include -O2 -o $@ $<
CLEANUP += $(ICCFIX)
###############################################################################
#
# Auto-incrementing build serial number. Append "bs" to your list of
# build targets to get a serial number printed at the end of the
# build. Enable -DBUILD_SERIAL in order to see it when the code runs.
@@ -517,27 +907,30 @@ bs : $(BUILDSERIAL_NOW)
@$(ECHO) $$(( $(shell cat $<) + 1 )) > $(BUILDSERIAL_NEXT)
@$(ECHO) "Build serial number is $(shell cat $<)"
# List of available architectures
###############################################################################
#
ARCHS = $(filter-out CVS,$(patsubst arch/%,%,$(wildcard arch/*)))
archs :
@$(ECHO) $(ARCHS)
OTHER_ARCHS = $(filter-out $(ARCH),$(ARCHS))
otherarchs :
@$(ECHO) $(OTHER_ARCHS)
# Build the TAGS file for emacs
# Build the TAGS file(s) for emacs
#
TAGS : TAGS.$(ARCH)
TAGS :
ctags -e -R -f $@ --exclude=bin
TAGS.$(ARCH) :
ctags -e -R -f $@ --exclude=bin \
$(foreach ARCH,$(OTHER_ARCHS),--exclude=arch/$(ARCH))
CLEANUP += TAGS*
CLEANUP += TAGS
###############################################################################
#
# Force rebuild for any given target
#
%.rebuild :
rm -f $*
$(Q)$(MAKE) $*
###############################################################################
#
# Symbol table checks
#
ifdef BIN
SYMTAB = $(BIN)/symtab
$(SYMTAB) : $(BLIB)
$(OBJDUMP) -w -t $< > $@
@@ -547,29 +940,46 @@ CLEANUP += $(BIN)/symtab
symcheck : $(SYMTAB)
$(SYMCHECK) $<
# Force rebuild for any given target
#
$(BIN)/%.rebuild :
rm -f $(BIN)/$*
$(MAKE) $(MAKEFLAGS) $(BIN)/$*
endif # defined(BIN)
###############################################################################
#
# Build bochs symbol table
#
ifdef BIN
$(BIN)/%.bxs : $(BIN)/%.tmp
$(NM) $< | cut -d" " -f1,3 > $@
endif # defined(BIN)
###############################################################################
#
# Documentation
#
ifdef BIN
$(BIN)/doxygen.cfg : doxygen.cfg $(MAKEDEPS)
$(PERL) -pe 's{\@SRCDIRS\@}{$(SRCDIRS)}; ' \
$(Q)$(PERL) -pe 's{\@SRCDIRS\@}{$(SRCDIRS)}; ' \
-e 's{\@INCDIRS\@}{$(filter-out .,$(INCDIRS))}; ' \
-e 's{\@BIN\@}{$(BIN)}; ' \
-e 's{\@ARCH\@}{$(ARCH)}; ' \
$< > $@
$(BIN)/doc : $(BIN)/doxygen.cfg
$(DOXYGEN) $<
$(Q)$(DOXYGEN) $<
.PHONY : $(BIN)/doc
VERYCLEANUP += $(BIN)/doc
doc : $(BIN)/doc
doc-clean :
$(Q)$(RM) -r $(BIN)/doc
VERYCLEANUP += $(BIN)/doc
docview :
@[ -f $(BIN)/doc/html/index.html ] || $(MAKE) $(BIN)/doc
@if [ -n "$$BROWSER" ] ; then \
@@ -578,6 +988,10 @@ docview :
$(ECHO) "Documentation index in $(BIN)/doc/html/index.html" ; \
fi
endif # defined(BIN)
###############################################################################
#
# Clean-up
#
clean :
@@ -585,19 +999,3 @@ clean :
veryclean : clean
$(RM) -r $(VERYCLEANUP)
# Make clean tarballs for release
tarball : ../VERSION
($(ECHO) -n $(VERSION) ''; date -u +'%Y-%m-%d') > ../VERSION
$(RM) -r /tmp/$(USER)/gpxe-$(VERSION)
mkdir -p /tmp/$(USER)/gpxe-$(VERSION)
cp -rP .. /tmp/$(USER)/gpxe-$(VERSION)
( cd /tmp/$(USER)/gpxe-$(VERSION)/src ; $(MAKE) veryclean ; $(RM) -r bin/deps )
( cd /tmp/$(USER); tar cf /tmp/$(USER)/gpxe-$(VERSION).tar --exclude ".git*" --exclude "#*" \
--exclude "*~" gpxe-$(VERSION) )
bzip2 -9 < /tmp/$(USER)/gpxe-$(VERSION).tar > /tmp/$(USER)/gpxe-$(VERSION).tar.bz2
gzip -9 < /tmp/$(USER)/gpxe-$(VERSION).tar > /tmp/$(USER)/gpxe-$(VERSION).tar.gz
$(RM) -r /tmp/$(USER)/gpxe-$(VERSION)
$(RM) /tmp/$(USER)/gpxe-$(VERSION).tar
( cd /tmp/$(USER) ; tar -zxf /tmp/$(USER)/gpxe-$(VERSION).tar.gz )
-65
View File
@@ -1,65 +0,0 @@
Changes should be committed to the CVS HEAD only when they are in a
working state. The definition of "working" is somewhat liquid; a good
guiding principle is that anyone checking out HEAD should receive a
checkout of working software.
When you want to work on changes that are likely to temporarily break
large swathes of code, you should probably work on a private branch.
Since CVS branching and merging is something of a black art, here are
some simple step-by-step instructions for creating and using a branch.
To create your private branch:
# Get most up-to-date tree before branching
cvs update
# Create a branch called "my-branch"
cvs tag -b my-branch
# Switch working copy to the "my-branch" branch
cvs update -r my-branch
At this point you'll be on a branch called "my-branch". Any changes
you make will not affect people working on HEAD, or on other branches.
Use name for your branch that is both descriptive and unique.
Starting the branch name with your SourceForge username
(e.g. "mcb30-realmode-redesign") is a good idea.
When you want to merge the changes on your branch back into HEAD, do
the following:
# Ensure there are no not-yet-checked-in modifications in your tree)
cvs -q update
# Tag the merge point in the "my-branch" branch
cvs tag -c my-branch-merge-1
# Switch working copy back to HEAD
cvs update -A
# Merge changes from the branch
cvs update -j my-branch
# Commit merged changes to HEAD
cvs commit
If you then want to continue working further on the "my-branch" branch,
do the following
# Switch working copy back to the "my-branch" branch
cvs update -r my-branch
and then when you want to merge some more changes back to HEAD:
# Ensure there are no not-yet-checked-in modifications in your tree)
cvs -q update
# Tag the merge point in the "my-branch" branch
cvs tag -c my-branch-merge-2
# Switch working copy back to HEAD
cvs update -A
# Merge changes from the branch
cvs update -j my-branch-merge-1 -j my-branch
# Commit merged changes to HEAD
cvs commit
Note that the format of the "merge changes from the branch" command has
changed, because this time you need to only merge changes since the last
merge point.
When you have finished with your branch and merged all the changes
back to HEAD, simply stop using the branch.
-90
View File
@@ -1,90 +0,0 @@
This file documents the driver changes needed to support use as part
of a PXE stack.
PROPER WAY
==========
1. The probe() routine.
There are three additional fields that need to be filled in the nic
structure: ioaddr, irqno and irq.
ioaddr is the base I/O address and seems to be for information only;
no use will be made of this value other than displaying it on the
screen.
irqno must be the IRQ number for the NIC. For PCI NICs this can
simply be copied from pci->irq.
irq is a function pointer, like poll and transmit. It must point to
the driver's irq() function.
2. The poll() routine.
This must take an additional parameter: "int retrieve". Calling
poll() with retrieve!=0 should function exactly as before. Calling
poll() with retrieve==0 indicates that poll() should check for the
presence of a packet to read, but must *not* read the packet. The
packet will be read by a subsequent call to poll() with retrieve!=0.
The easiest way to implement this is to insert the line
if ( ! retrieve ) return 1;
between the "is there a packet ready" and the "fetch packet" parts of
the existing poll() routine.
Care must be taken that a call to poll() with retrieve==0 does not
clear the NIC's "packet ready" status indicator, otherwise the
subsequent call to poll() with retrieve!=0 will fail because it will
think that there is no packet to read.
poll() should also acknowledge and clear the NIC's "packet received"
interrupt. It does not need to worry about enabling/disabling
interrupts; this is taken care of by calls to the driver's irq()
routine.
Etherboot will forcibly regenerate an interrupt if a packet remains
pending after all interrupts have been acknowledged. You can
therefore get away with having poll() just acknolwedge and clear all
NIC interrupts, without particularly worrying about exactly when this
should be done.
3. The irq() routine.
This is a new routine, with prototype
void DRIVER_irq ( struct nic *nic, irq_action_t action );
"action" takes one of three possible values: ENABLE, DISABLE or FORCE.
ENABLE and DISABLE mean to enable/disable the NIC's "packet received"
interrupt. FORCE means that the NIC should be forced to generate a
fake "packet received" interrupt.
If you are unable to implement FORCE, your NIC will not work when
being driven via the UNDI interface under heavy network traffic
conditions. Since Etherboot's UNDI driver (make bin/undi.zpxe) is the
only program known to use this interface, it probably doesn't really
matter.
QUICK AND DIRTY WAY
===================
It is possible to use the system timer interrupt (IRQ 0) rather than a
genuine NIC interrupt. Since there is a constant stream of timer
interrupts, the net upshot is a whole load of spurious "NIC"
interrupts that have no effect other than to cause unnecessary PXE API
calls. It's inefficient but it works.
To achieve this, simply set nic->irqno=0 in probe() and point nic->irq
to a dummy routine that does nothing. Add the line
if ( ! retrieve ) return 1;
at the beginning of poll(), to prevent the packet being read (and
discarded) when poll() is called with retrieve==0;
UNCONVERTED DRIVERS
===================
Drivers that have not yet been converted should continue to function
when not used as part of a PXE stack, although there will be a
harmless compile-time warning about assignment from an incompatible
pointer type in the probe() function, since the prototype for the
poll() function is missing the "int retrieve" parameter.
-148
View File
@@ -1,148 +0,0 @@
# -*- makefile -*-
##############################################################################
##############################################################################
#
# IMPORTANT!
#
# The use of this file to set options that affect only single object
# files is deprecated, because changing anything in this file results
# in a complete rebuild, which is slow. All options are gradually
# being migrated to config.h, which does not suffer from this problem.
#
# Only options that affect the entire build (e.g. overriding the $(CC)
# Makefile variable) should be placed in here.
#
##############################################################################
##############################################################################
# Config for i386 Etherboot
#
# Do not delete the tag OptionDescription and /OptionDescription
# It is used to automatically generate the documentation.
#
# @OptionDescrition@
#
# BIOS interface options:
#
# -DPCBIOS
# Compile in support for the normal pcbios
# -DLINUXBIOS
# Compile in support for LinuxBIOS
# -DBBS_BUT_NOT_PNP_COMPLIANT
# Some BIOSes claim to be PNP but they don't conform
# to the BBS spec which specifies that ES:DI must
# point to the string $PnP on entry. This option
# works around those. This option must be added to
# LCONFIG.
# -DNO_DELAYED_INT
# Take control as soon as BIOS detects the ROM.
# Normally hooks onto INT18H or INT19H. Use only if you
# have a very non-conformant BIOS as it bypasses
# BIOS initialisation of devices. This only works for
# legacy ROMs, i.e. PCI_PNP_HEADER not defined.
# This option was formerly called NOINT19H.
# -DBOOT_INT18H
# Etherboot normally hooks onto INT19H for legacy ROMs.
# You can choose to hook onto INT18H (BASIC interpreter
# entry point) instead. This entry point is used when
# all boot devices have been exhausted. This option must
# be added to LCONFIG.
# -DCONFIG_PCI_DIRECT
# Define this for PCI BIOSes that do not implement
# BIOS32 or not correctly. Normally not needed.
# Only works for BIOSes of a certain era.
# -DCONFIG_TSC_CURRTICKS
# Uses the processor time stamp counter instead of reading
# the BIOS time counter. This allows Etherboot to work
# even without a BIOS. This only works on late model
# 486s and above.
# -DCONFIG_NO_TIMER2
# Some systems do not have timer2 implemented.
# If you have a RTC this will allow you to roughly calibrate
# it using outb instructions.
#
# Extended cpu options
# -DCONFIG_X86_64
# Compile in support for booting x86_64 64bit binaries.
#
# PXE loader options:
#
# -DPXELOADER_KEEP_ALL
# Prevent PXE loader (prefix) from unloading the
# PXE stack. You will want to use this if, for
# example, you are booting via PXE-on-floppy.
# You may want to use it under certain
# circumstances when using the Etherboot UNDI
# driver; these are complex and best practice is
# not yet established.
#
# Obscure options you probably don't need to touch:
#
# -DIGNORE_E820_MAP
# Ignore the memory map returned by the E820 BIOS
# call. May be necessary on some buggy BIOSes.
# -DT503_AUI
# Use AUI by default on 3c503 cards.
# -DFLATTEN_REAL_MODE
# Use 4GB segment limits when calling out to or
# returning to real-mode code. This is necessary to
# work around some buggy code (e.g. OpenBSD's pxeboot)
# that uses flat real-mode without being sufficiently
# paranoid about the volatility of its segment limits.
#
# @/OptionDescription@
# BIOS select don't change unless you know what you are doing
# CFLAGS+= -DPCBIOS
# Compile in k8/hammer support
# CFLAGS+= -DCONFIG_X86_64
# Options to make a version of Etherboot that will work under linuxBIOS.
# CFLAGS+= -DLINUXBIOS -DCONFIG_TSC_CURRTICKS -DCONSOLE_SERIAL -DCOMCONSOLE=0x3f8 -DCOMPRESERVE -DCONFIG_PCI_DIRECT -DELF_IMAGE
# These options affect the loader that is prepended to the Etherboot image
# LCONFIG+= -DBBS_BUT_NOT_PNP_COMPLIANT
# LCONFIG+= -DBOOT_INT18H
# Produce code that will work with OpenBSD's pxeboot
# CFLAGS+= -DFLATTEN_REAL_MODE
CFLAGS+= -fstrength-reduce -fomit-frame-pointer -march=i386
# Squeeze the code in as little space as possible.
# gcc3 needs a different syntax to gcc2 if you want to avoid spurious warnings.
GCC_VERSION = $(subst ., ,$(shell $(CC) -dumpversion))
GCC_MAJORVERSION = $(firstword $(GCC_VERSION))
ifeq ($(GCC_MAJORVERSION),2)
CFLAGS+= -malign-jumps=1 -malign-loops=1 -malign-functions=1
else
CFLAGS+= -falign-jumps=1 -falign-loops=1 -falign-functions=1
endif
# this is almost always a win. the kernel uses it, too.
CFLAGS+= -mpreferred-stack-boundary=2
# use regparm for all functions - C functions called from assembly (or
# vice versa) need __cdecl now
CFLAGS+= -mregparm=3
# use -mrtd (same __cdecl requirements as above)
CFLAGS+= -mrtd
# this is the logical complement to -mregparm=3.
# it doesn't currently buy us anything, but if anything ever tries
# to return small structures, let's be prepared
CFLAGS+= -freg-struct-return
LDFLAGS+= -N --no-check-sections
ifeq "$(shell uname -s)" "FreeBSD"
CFLAGS+= -DIMAGE_FREEBSD -DELF_IMAGE -DAOUT_IMAGE
endif
# An alternate location for isolinux.bin can be set here
# ISOLINUX_BIN=/path/to/isolinux.bin
+82 -72
View File
@@ -1,3 +1,72 @@
# Force i386-only instructions
#
CFLAGS += -march=i386
# Code size reduction.
#
CFLAGS += -fomit-frame-pointer
# Code size reduction.
#
ifeq ($(CCTYPE),gcc)
CFLAGS += -fstrength-reduce
endif
# Code size reduction. gcc3 needs a different syntax to gcc2 if you
# want to avoid spurious warnings.
#
ifeq ($(CCTYPE),gcc)
GCC_VERSION := $(subst ., ,$(shell $(CC) -dumpversion))
GCC_MAJOR := $(firstword $(GCC_VERSION))
ifeq ($(GCC_MAJOR),2)
CFLAGS += -malign-jumps=1 -malign-loops=1 -malign-functions=1
else
CFLAGS += -falign-jumps=1 -falign-loops=1 -falign-functions=1
endif # gcc2
endif # gcc
# Code size reduction. This is almost always a win. The kernel uses
# it, too.
#
ifeq ($(CCTYPE),gcc)
CFLAGS += -mpreferred-stack-boundary=2
endif
# Code size reduction. Use regparm for all functions - C functions
# called from assembly (or vice versa) need __asmcall now
#
CFLAGS += -mregparm=3
# Code size reduction. Use -mrtd (same __asmcall requirements as above)
ifeq ($(CCTYPE),gcc)
CFLAGS += -mrtd
endif
# Code size reduction. This is the logical complement to -mregparm=3.
# It doesn't currently buy us anything, but if anything ever tries to
# return small structures, let's be prepared
#
CFLAGS += -freg-struct-return
# Force 32-bit code even on an x86-64 machine
#
CFLAGS += -m32
ASFLAGS += --32
ifeq ($(HOST_OS),FreeBSD)
LDFLAGS += -m elf_i386_fbsd
else
LDFLAGS += -m elf_i386
endif
# 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
# Locations of utilities
#
ISOLINUX_BIN = /usr/lib/syslinux/isolinux.bin
@@ -7,11 +76,12 @@ ISOLINUX_BIN = /usr/lib/syslinux/isolinux.bin
SRCDIRS += arch/i386/core arch/i386/transitions arch/i386/prefix
SRCDIRS += arch/i386/firmware/pcbios
SRCDIRS += arch/i386/image
SRCDIRS += arch/i386/drivers/bus
SRCDIRS += arch/i386/drivers
SRCDIRS += arch/i386/drivers/net
SRCDIRS += arch/i386/drivers/disk
SRCDIRS += arch/i386/interface/pcbios
SRCDIRS += arch/i386/interface/pxe
SRCDIRS += arch/i386/interface/syslinux
SRCDIRS += arch/i386/hci/commands
# The various xxx_loader.c files are #included into core/loader.c and
# should not be compiled directly.
@@ -20,87 +90,27 @@ NON_AUTO_SRCS += arch/i386/core/aout_loader.c
NON_AUTO_SRCS += arch/i386/core/freebsd_loader.c
NON_AUTO_SRCS += arch/i386/core/wince_loader.c
# unnrv2b.S is used to generate a 16-bit as well as a 32-bit object.
# Include common x86 Makefile
#
OBJS_unnrv2b = unnrv2b unnrv2b16
CFLAGS_unnrv2b16 = -DCODE16
MAKEDEPS += arch/x86/Makefile
include arch/x86/Makefile
# We need to undefine the default macro "i386" when compiling .S
# files, otherwise ".arch i386" translates to ".arch 1"...
# Include platform-specific Makefile
#
CFLAGS_S += -Ui386
# The i386 linker script
#
LDSCRIPT = arch/i386/scripts/i386.lds
# Media types.
#
MEDIA += rom
MEDIA += pxe
MEDIA += kpxe
MEDIA += elf
MEDIA += elfd
MEDIA += lmelf
MEDIA += lmelfd
MEDIA += lkrn
MEDIA += bImage
MEDIA += dsk
MEDIA += nbi
MEDIA += hd
MEDIA += raw
MEDIA += com
MEDIA += exe
# Special target for building Master Boot Record binary
$(BIN)/mbr.bin : $(BIN)/mbr.o
$(OBJCOPY) -O binary $< $@
MAKEDEPS += arch/i386/Makefile.$(PLATFORM)
include arch/i386/Makefile.$(PLATFORM)
# Some suffixes (e.g. %.fd0) are generated directly from other
# finished files (e.g. %.dsk), rather than having their own prefix.
# rule to write disk images to /dev/fd0
NON_AUTO_MEDIA += fd0
NON_AUTO_MEDIA += fd0
%fd0 : %dsk
dd if=$< bs=512 conv=sync of=/dev/fd0
sync
# rule to create padded disk images
NON_AUTO_MEDIA += pdsk
%pdsk : %dsk
cp $< $@
$(PERL) ./util/dskpad.pl $@
# rule to make a non-emulation ISO boot image
NON_AUTO_MEDIA += iso
%iso: %lkrn util/geniso
ISOLINUX_BIN=$(ISOLINUX_BIN) bash util/geniso $@ $<
# rule to make a floppy emulation ISO boot image
NON_AUTO_MEDIA += liso
%liso: %lkrn util/genliso
bash util/genliso $@ $<
# rule to make a USB disk image
$(BIN)/usbdisk.bin : $(BIN)/usbdisk.o
$(OBJCOPY) -O binary $< $@
NON_AUTO_MEDIA += usb
%usb: $(BIN)/usbdisk.bin %hd
cat $^ > $@
$(QM)$(ECHO) " [DD] $@"
$(Q)dd if=$< bs=512 conv=sync of=/dev/fd0
$(Q)sync
# Add NON_AUTO_MEDIA to the media list, so that they show up in the
# output of "make"
#
MEDIA += $(NON_AUTO_MEDIA)
# Shortcut to allow typing just
# make bin-kir/%
# rather than
# make -f arch/i386/kir-Makefile bin-kir/%
# for building a KEEP_IT_REAL flavour.
#
$(BIN)-kir/% : kir-target
$(MAKE) -f arch/i386/kir-Makefile $(MAKECMDGOALS)
.PHONY : kir-target
+10
View File
@@ -0,0 +1,10 @@
# -*- makefile -*- : Force emacs to use Makefile mode
# Specify EFI image builder
#
ELF2EFI = $(ELF2EFI32)
# Include generic EFI Makefile
#
MAKEDEPS += arch/x86/Makefile.efi
include arch/x86/Makefile.efi
+73
View File
@@ -0,0 +1,73 @@
# -*- makefile -*- : Force emacs to use Makefile mode
# The i386 linker script
#
LDSCRIPT = arch/i386/scripts/i386.lds
# Stop ld from complaining about our customised linker script
#
LDFLAGS += -N --no-check-sections
# Media types.
#
MEDIA += rom
MEDIA += pxe
MEDIA += kpxe
MEDIA += kkpxe
MEDIA += elf
MEDIA += elfd
MEDIA += lmelf
MEDIA += lmelfd
MEDIA += lkrn
MEDIA += bImage
MEDIA += dsk
MEDIA += nbi
MEDIA += hd
MEDIA += raw
MEDIA += com
MEDIA += exe
# Padding rules
#
PAD_rom = $(PADIMG) --blksize=512 --byte=0xff $@
PAD_dsk = $(PADIMG) --blksize=512 $@
PAD_hd = $(PADIMG) --blksize=512 $@
# rule to make a non-emulation ISO boot image
NON_AUTO_MEDIA += iso
%iso: %lkrn util/geniso
$(QM)$(ECHO) " [GENISO] $@"
$(Q)ISOLINUX_BIN=$(ISOLINUX_BIN) bash util/geniso $@ $<
# rule to make a floppy emulation ISO boot image
NON_AUTO_MEDIA += liso
%liso: %lkrn util/genliso
$(QM)$(ECHO) " [GENLISO] $@"
$(Q)bash util/genliso $@ $<
# rule to make a syslinux floppy image (mountable, bootable)
NON_AUTO_MEDIA += sdsk
%sdsk: %lkrn util/gensdsk
$(QM)$(ECHO) " [GENSDSK] $@"
$(Q)bash util/gensdsk $@ $<
# Special target for building Master Boot Record binary
$(BIN)/mbr.bin : $(BIN)/mbr.o
$(QM)$(ECHO) " [OBJCOPY] $@"
$(Q)$(OBJCOPY) -O binary $< $@
# rule to make a USB disk image
$(BIN)/usbdisk.bin : $(BIN)/usbdisk.o
$(QM)$(ECHO) " [OBJCOPY] $@"
$(Q)$(OBJCOPY) -O binary $< $@
NON_AUTO_MEDIA += usb
%usb: $(BIN)/usbdisk.bin %hd
$(QM)$(ECHO) " [FINISH] $@"
$(Q)cat $^ > $@
# Padded floppy image (e.g. for iLO)
NON_AUTO_MEDIA += pdsk
%pdsk : %dsk
$(Q)cp $< $@
$(Q)$(PADIMG) --blksize=1474560 $@
+2
View File
@@ -16,6 +16,8 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
FILE_LICENCE ( GPL2_OR_LATER );
/**
* @file
*
+23
View File
@@ -0,0 +1,23 @@
#include <stdio.h>
#include <realmode.h>
void __asmcall _dump_regs ( struct i386_all_regs *ix86 ) {
__asm__ __volatile__ (
TEXT16_CODE ( ".globl dump_regs\n\t"
"\ndump_regs:\n\t"
"pushl $_dump_regs\n\t"
"pushw %%cs\n\t"
"call prot_call\n\t"
"addr32 leal 4(%%esp), %%esp\n\t"
"ret\n\t" ) : : );
printf ( "EAX=%08x EBX=%08x ECX=%08x EDX=%08x\n"
"ESI=%08x EDI=%08x EBP=%08x ESP=%08x\n"
"CS=%04x SS=%04x DS=%04x ES=%04x FS=%04x GS=%04x\n",
ix86->regs.eax, ix86->regs.ebx, ix86->regs.ecx,
ix86->regs.edx, ix86->regs.esi, ix86->regs.edi,
ix86->regs.ebp, ix86->regs.esp,
ix86->segs.cs, ix86->segs.ss, ix86->segs.ds,
ix86->segs.es, ix86->segs.fs, ix86->segs.gs );
}
-100
View File
@@ -1,100 +0,0 @@
OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
OUTPUT_ARCH(i386)
ENTRY(_prefix_start)
SECTIONS {
/* Prefix */
.prefix : {
_verbatim_start = . ;
_prefix_start = . ;
*(.prefix)
. = ALIGN(16);
_prefix_end = . ;
} = 0x9090
_prefix_size = _prefix_end - _prefix_start;
.text.nocompress : {
*(.prefix.udata)
} = 0x9090
decompress_to = . ;
.prefix.zdata : {
_compressed = . ;
*(.prefix.zdata)
_compressed_end = . ;
}
_compressed_size = _compressed_end - _compressed;
. = ALIGN(16);
_verbatim_end = . ;
/* Size of the core of etherboot in memory */
_base_size = _end - _text;
/* _prefix_size is the length of the non-core etherboot prefix */
_prefix_size = _prefix_end - _prefix_start;
/* _verbatim_size is the actual amount that has to be copied to base memory */
_verbatim_size = _verbatim_end - _verbatim_start;
/* _image_size is the amount of base memory needed to run */
_image_size = _base_size + _prefix_size;
/* Standard sizes rounded up to paragraphs */
_prefix_size_pgh = (_prefix_size + 15) / 16;
_verbatim_size_pgh = (_verbatim_size + 15) / 16;
_image_size_pgh = (_image_size + 15) / 16 ;
/* Standard sizes in sectors */
_prefix_size_sct = (_prefix_size + 511) / 512;
_verbatim_size_sct = (_verbatim_size + 511) / 512;
_image_size_sct = (_image_size + 511) / 512;
/* Symbol offsets and sizes for the exe prefix */
_exe_hdr_size = 32;
_exe_size = _verbatim_size; /* Should this be - 32 to exclude the header? */
_exe_size_tail = (_exe_size) % 512;
_exe_size_pages = ((_exe_size) + 511) / 512;
_exe_bss_size = ((_image_size - _verbatim_size) + 15) / 16;
_exe_ss_offset = (_stack_offset + _prefix_size - _exe_hdr_size + 15) / 16 ;
/* This is where we copy the compressed image before decompression.
* Prepare to decompress in place. The end mark is about 8.25 bytes long,
* and the worst case symbol is about 16.5 bytes long. Therefore
* We need to reserve at least 25 bytes of slack here.
* Currently I reserve 2048 bytes of just slack to be safe :)
* 2048 bytes easily falls within the BSS (the defualt stack is 4096 bytes)
* so we really are decompressing in place.
*
* Hmm. I missed a trick. In the very worst case (no compression)
* the encoded data is 9/8 the size as it started out so to be completely
* safe I need to be 1/8 of the uncompressed code size past the end.
* This will still fit compfortably into our bss in any conceivable scenario.
*/
_compressed_copy = _edata + _prefix_size - _compressed_size +
/* The amount to overflow _edata */
MAX( ((_edata - _text + 7) / 8) , 2016 ) + 32;
_assert = ASSERT( ( _compressed_copy - _prefix_size ) < _ebss , "Cannot decompress in place" ) ;
decompress = DEFINED(decompress) ? decompress : 0;
/DISCARD/ : {
*(.comment)
*(.note)
}
/* Symbols used by the prefixes whose addresses are inconvinient
* to compute, at runtime in the code.
*/
image_basemem_size = DEFINED(image_basemem_size)? image_basemem_size : 65536;
image_basemem = DEFINED(image_basemem)? image_basemem : 65536;
_prefix_real_to_prot = _real_to_prot + _prefix_size ;
_prefix_prot_to_real = _prot_to_real + _prefix_size ;
_prefix_image_basemem_size = image_basemem_size + _prefix_size ;
_prefix_image_basemem = image_basemem + _prefix_size ;
_prefix_rm_in_call = _rm_in_call + _prefix_size ;
_prefix_in_call = _in_call + _prefix_size ;
_prefix_rom = rom + _prefix_size ;
_prefix_rm_etherboot_location = rm_etherboot_location + _prefix_size ;
_prefix_stack_end = _stack_end + _prefix_size ;
}
+215
View File
@@ -0,0 +1,215 @@
/*
* Interrupt Descriptor Table (IDT) setup and interrupt handlers for GDB stub.
*/
#include <librm.h>
#define SIZEOF_I386_REGS 32
#define SIZEOF_I386_FLAGS 4
/****************************************************************************
* Interrupt Descriptor Table
****************************************************************************
*/
.section ".data16", "aw", @progbits
.globl idtr
idtr:
idt_limit:
.word idt_length - 1
idt_base:
.long 0
/* IDT entries have the following format:
* offset_lo, segment selector, flags, offset_hi
*
* Since it is not possible to specify relocations in arbitrary
* expressions like (int_overflow & 0xffff), we initialise the
* IDT with entries in an incorrect format.
*
* The entries are shuffled into the correct format in init_librm().
*/
#define IDT_ENTRY_EMPTY(name) .word 0, 0, 0, 0
#define IDT_ENTRY_PRESENT(name) \
.long int_##name; \
.word 0x8e00, VIRTUAL_CS
.align 16
idt:
IDT_ENTRY_PRESENT(divide_error)
IDT_ENTRY_PRESENT(debug_trap)
IDT_ENTRY_EMPTY(non_maskable_interrupt)
IDT_ENTRY_PRESENT(breakpoint)
IDT_ENTRY_PRESENT(overflow)
IDT_ENTRY_PRESENT(bound_range_exceeded)
IDT_ENTRY_PRESENT(invalid_opcode)
IDT_ENTRY_EMPTY(device_not_available)
IDT_ENTRY_PRESENT(double_fault)
IDT_ENTRY_EMPTY(coprocessor_segment_overrun)
IDT_ENTRY_PRESENT(invalid_tss)
IDT_ENTRY_PRESENT(segment_not_present)
IDT_ENTRY_PRESENT(stack_segment_fault)
IDT_ENTRY_PRESENT(general_protection)
IDT_ENTRY_PRESENT(page_fault)
idt_end:
.equ idt_length, idt_end - idt
/* The IDT entries are fixed up (once) in init_librm() */
idt_fixed:
.byte 0
/****************************************************************************
* idt_init (real-mode near call, 16-bit real-mode near return address)
*
* Initialise the IDT, called from init_librm.
*
* Parameters:
* %eax : IDT base address
*
* Destroys %ax, %bx, and %di.
****************************************************************************
*/
.section ".text16", "ax", @progbits
.code16
.globl idt_init
idt_init:
movl %eax, idt_base
addl $idt, idt_base
/* IDT entries are only fixed up once */
movb idt_fixed, %al
orb %al, %al
jnz 2f
movb $1, idt_fixed
/* Shuffle IDT entries into the correct format */
movb $(idt_length / 8), %al
movw $idt, %bx
or %al, %al
jz 2f
1:
movw 2(%bx), %di
xchg %di, 6(%bx)
movw %di, 2(%bx)
addw $8, %bx
dec %al
jnz 1b
2:
ret
/****************************************************************************
* Interrupt handlers
****************************************************************************
*/
.section ".text", "ax", @progbits
.code32
/* POSIX signal numbers for reporting traps to GDB */
#define SIGILL 4
#define SIGTRAP 5
#define SIGBUS 7
#define SIGFPE 8
#define SIGSEGV 11
#define SIGSTKFLT 16
int_divide_error:
pushl $SIGFPE
jmp do_interrupt
int_debug_trap:
int_breakpoint:
pushl $SIGTRAP
jmp do_interrupt
int_overflow:
int_bound_range_exceeded:
pushl $SIGSTKFLT
jmp do_interrupt
int_invalid_opcode:
pushl $SIGILL
jmp do_interrupt
int_double_fault:
movl $SIGBUS, (%esp)
jmp do_interrupt
int_invalid_tss:
int_segment_not_present:
int_stack_segment_fault:
int_general_protection:
int_page_fault:
movl $SIGSEGV, (%esp)
jmp do_interrupt
/* When invoked, the stack contains: eflags, cs, eip, signo. */
#define IH_OFFSET_GDB_REGS ( 0 )
#define IH_OFFSET_GDB_EIP ( IH_OFFSET_GDB_REGS + SIZEOF_I386_REGS )
#define IH_OFFSET_GDB_EFLAGS ( IH_OFFSET_GDB_EIP + 4 )
#define IH_OFFSET_GDB_SEG_REGS ( IH_OFFSET_GDB_EFLAGS + SIZEOF_I386_FLAGS )
#define IH_OFFSET_GDB_END ( IH_OFFSET_GDB_SEG_REGS + 6 * 4 )
#define IH_OFFSET_SIGNO ( IH_OFFSET_GDB_END )
#define IH_OFFSET_OLD_EIP ( IH_OFFSET_SIGNO + 4 )
#define IH_OFFSET_OLD_CS ( IH_OFFSET_OLD_EIP + 4 )
#define IH_OFFSET_OLD_EFLAGS ( IH_OFFSET_OLD_CS + 4 )
#define IH_OFFSET_END ( IH_OFFSET_OLD_EFLAGS + 4 )
/* We also access the stack whilst still storing or restoring
* the register snapshot. Since ESP is in flux, we need
* special offsets.
*/
#define IH_OFFSET_FLUX_OLD_CS ( IH_OFFSET_OLD_CS - 44 )
#define IH_OFFSET_FLUX_OLD_EFLAGS ( IH_OFFSET_OLD_EFLAGS - 40 )
#define IH_OFFSET_FLUX_OLD_EIP ( IH_OFFSET_OLD_EIP - 36 )
#define IH_OFFSET_FLUX_END ( IH_OFFSET_END - 20 )
do_interrupt:
/* Store CPU state in GDB register snapshot */
pushw $0
pushw %gs
pushw $0
pushw %fs
pushw $0
pushw %es
pushw $0
pushw %ds
pushw $0
pushw %ss
pushw $0
pushw IH_OFFSET_FLUX_OLD_CS + 2(%esp)
pushl IH_OFFSET_FLUX_OLD_EFLAGS(%esp)
pushl IH_OFFSET_FLUX_OLD_EIP(%esp)
pushl %edi
pushl %esi
pushl %ebp
leal IH_OFFSET_FLUX_END(%esp), %edi
pushl %edi /* old ESP */
pushl %ebx
pushl %edx
pushl %ecx
pushl %eax
/* Call GDB stub exception handler */
pushl %esp
pushl (IH_OFFSET_SIGNO + 4)(%esp)
call gdbmach_handler
addl $8, %esp
/* Restore CPU state from GDB register snapshot */
popl %eax
popl %ecx
popl %edx
popl %ebx
addl $4, %esp /* Changing ESP currently not supported */
popl %ebp
popl %esi
popl %edi
popl IH_OFFSET_FLUX_OLD_EIP(%esp)
popl IH_OFFSET_FLUX_OLD_EFLAGS(%esp)
popl IH_OFFSET_FLUX_OLD_CS(%esp)
popl %ss
popl %ds
popl %es
popl %fs
popl %gs
addl $4, %esp /* drop signo */
iret
+149
View File
@@ -0,0 +1,149 @@
/*
* Copyright (C) 2008 Stefan Hajnoczi <stefanha@gmail.com>.
*
* 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 <stddef.h>
#include <stdio.h>
#include <assert.h>
#include <gpxe/uaccess.h>
#include <gpxe/gdbstub.h>
#include <gdbmach.h>
/** @file
*
* GDB architecture-specific bits for i386
*
*/
enum {
DR7_CLEAR = 0x00000400, /* disable hardware breakpoints */
DR6_CLEAR = 0xffff0ff0, /* clear breakpoint status */
};
/** Hardware breakpoint, fields stored in x86 bit pattern form */
struct hwbp {
int type; /* type (1=write watchpoint, 3=access watchpoint) */
unsigned long addr; /* linear address */
size_t len; /* length (0=1-byte, 1=2-byte, 3=4-byte) */
int enabled;
};
static struct hwbp hwbps [ 4 ];
static gdbreg_t dr7 = DR7_CLEAR;
static struct hwbp *gdbmach_find_hwbp ( int type, unsigned long addr, size_t len ) {
struct hwbp *available = NULL;
unsigned int i;
for ( i = 0; i < sizeof hwbps / sizeof hwbps [ 0 ]; i++ ) {
if ( hwbps [ i ].type == type && hwbps [ i ].addr == addr && hwbps [ i ].len == len ) {
return &hwbps [ i ];
}
if ( !hwbps [ i ].enabled ) {
available = &hwbps [ i ];
}
}
return available;
}
static void gdbmach_commit_hwbp ( struct hwbp *bp ) {
unsigned int regnum = bp - hwbps;
/* Set breakpoint address */
assert ( regnum < ( sizeof hwbps / sizeof hwbps [ 0 ] ) );
switch ( regnum ) {
case 0:
__asm__ __volatile__ ( "movl %0, %%dr0\n" : : "r" ( bp->addr ) );
break;
case 1:
__asm__ __volatile__ ( "movl %0, %%dr1\n" : : "r" ( bp->addr ) );
break;
case 2:
__asm__ __volatile__ ( "movl %0, %%dr2\n" : : "r" ( bp->addr ) );
break;
case 3:
__asm__ __volatile__ ( "movl %0, %%dr3\n" : : "r" ( bp->addr ) );
break;
}
/* Set type */
dr7 &= ~( 0x3 << ( 16 + 4 * regnum ) );
dr7 |= bp->type << ( 16 + 4 * regnum );
/* Set length */
dr7 &= ~( 0x3 << ( 18 + 4 * regnum ) );
dr7 |= bp->len << ( 18 + 4 * regnum );
/* Set/clear local enable bit */
dr7 &= ~( 0x3 << 2 * regnum );
dr7 |= bp->enabled << 2 * regnum;
}
int gdbmach_set_breakpoint ( int type, unsigned long addr, size_t len, int enable ) {
struct hwbp *bp;
/* Check and convert breakpoint type to x86 type */
switch ( type ) {
case GDBMACH_WATCH:
type = 0x1;
break;
case GDBMACH_AWATCH:
type = 0x3;
break;
default:
return 0; /* unsupported breakpoint type */
}
/* Only lengths 1, 2, and 4 are supported */
if ( len != 2 && len != 4 ) {
len = 1;
}
len--; /* convert to x86 breakpoint length bit pattern */
/* Calculate linear address by adding segment base */
addr += virt_offset;
/* Set up the breakpoint */
bp = gdbmach_find_hwbp ( type, addr, len );
if ( !bp ) {
return 0; /* ran out of hardware breakpoints */
}
bp->type = type;
bp->addr = addr;
bp->len = len;
bp->enabled = enable;
gdbmach_commit_hwbp ( bp );
return 1;
}
static void gdbmach_disable_hwbps ( void ) {
/* Store and clear hardware breakpoints */
__asm__ __volatile__ ( "movl %0, %%dr7\n" : : "r" ( DR7_CLEAR ) );
}
static void gdbmach_enable_hwbps ( void ) {
/* Clear breakpoint status register */
__asm__ __volatile__ ( "movl %0, %%dr6\n" : : "r" ( DR6_CLEAR ) );
/* Restore hardware breakpoints */
__asm__ __volatile__ ( "movl %0, %%dr7\n" : : "r" ( dr7 ) );
}
__asmcall void gdbmach_handler ( int signo, gdbreg_t *regs ) {
gdbmach_disable_hwbps();
gdbstub_handler ( signo, regs );
gdbmach_enable_hwbps();
}
-33
View File
@@ -1,33 +0,0 @@
#include <stdio.h>
#include <gpxe/init.h>
#include <console.h>
#include <realmode.h>
extern char __text[];
extern char __rodata[];
extern char __data[];
extern char __bss[];
extern char __text16[];
extern char __data16[];
static void gdb_symbol_line ( void ) {
printf ( "Commands to start up gdb:\n\n" );
printf ( "gdb\n" );
printf ( "target remote localhost:1234\n" );
printf ( "set confirm off\n" );
printf ( "add-symbol-file symbols %#lx", virt_to_phys ( __text ) );
printf ( " -s .rodata %#lx", virt_to_phys ( __rodata ) );
printf ( " -s .data %#lx", virt_to_phys ( __data ) );
printf ( " -s .bss %#lx", virt_to_phys ( __bss ) );
printf ( " -s .text16 %#x", ( ( rm_cs << 4 ) + (int)__text16 ) );
printf ( " -s .data16 %#x", ( ( rm_ds << 4 ) + (int)__data16 ) );
printf ( "\n" );
printf ( "add-symbol-file symbols 0\n" );
printf ( "set confirm on\n" );
getkey();
}
struct startup_fn gdb_startup_fn __startup_fn ( STARTUP_NORMAL ) = {
.startup = gdb_symbol_line,
};
-196
View File
@@ -1,196 +0,0 @@
/* A couple of routines to implement a low-overhead timer for drivers */
/*
* 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, or (at
* your option) any later version.
*/
#include "timer.h"
#include "latch.h"
#include <io.h>
#include <gpxe/init.h>
void __load_timer2(unsigned int ticks)
{
/*
* Now let's take care of PPC channel 2
*
* Set the Gate high, program PPC channel 2 for mode 0,
* (interrupt on terminal count mode), binary count,
* load 5 * LATCH count, (LSB and MSB) to begin countdown.
*
* Note some implementations have a bug where the high bits byte
* of channel 2 is ignored.
*/
/* Set up the timer gate, turn off the speaker */
/* Set the Gate high, disable speaker */
outb((inb(PPC_PORTB) & ~PPCB_SPKR) | PPCB_T2GATE, PPC_PORTB);
/* binary, mode 0, LSB/MSB, Ch 2 */
outb(TIMER2_SEL|WORD_ACCESS|MODE0|BINARY_COUNT, TIMER_MODE_PORT);
/* LSB of ticks */
outb(ticks & 0xFF, TIMER2_PORT);
/* MSB of ticks */
outb(ticks >> 8, TIMER2_PORT);
}
static int __timer2_running(void)
{
return ((inb(PPC_PORTB) & PPCB_T2OUT) == 0);
}
#if !defined(CONFIG_TSC_CURRTICKS)
static void setup_timers(void)
{
return;
}
void load_timer2(unsigned int ticks)
{
return __load_timer2(ticks);
}
int timer2_running(void)
{
return __timer2_running();
}
void ndelay(unsigned int nsecs)
{
waiton_timer2((nsecs * CLOCK_TICK_RATE)/1000000000);
}
void udelay(unsigned int usecs)
{
waiton_timer2((usecs * TICKS_PER_MS)/1000);
}
#endif /* !defined(CONFIG_TSC_CURRTICKS) */
#if defined(CONFIG_TSC_CURRTICKS)
#define rdtsc(low,high) \
__asm__ __volatile__("rdtsc" : "=a" (low), "=d" (high))
#define rdtscll(val) \
__asm__ __volatile__ ("rdtsc" : "=A" (val))
/* Number of clock ticks to time with the rtc */
#define LATCH 0xFF
#define LATCHES_PER_SEC ((CLOCK_TICK_RATE + (LATCH/2))/LATCH)
#define TICKS_PER_LATCH ((LATCHES_PER_SEC + (TICKS_PER_SEC/2))/TICKS_PER_SEC)
static void sleep_latch(void)
{
__load_timer2(LATCH);
while(__timer2_running());
}
/* ------ Calibrate the TSC -------
* Time how long it takes to excute a loop that runs in known time.
* And find the convertion needed to get to CLOCK_TICK_RATE
*/
static unsigned long long calibrate_tsc(void)
{
unsigned long startlow, starthigh;
unsigned long endlow, endhigh;
rdtsc(startlow,starthigh);
sleep_latch();
rdtsc(endlow,endhigh);
/* 64-bit subtract - gcc just messes up with long longs */
__asm__("subl %2,%0\n\t"
"sbbl %3,%1"
:"=a" (endlow), "=d" (endhigh)
:"g" (startlow), "g" (starthigh),
"0" (endlow), "1" (endhigh));
/* Error: ECPUTOOFAST */
if (endhigh)
goto bad_ctc;
endlow *= TICKS_PER_LATCH;
return endlow;
/*
* The CTC wasn't reliable: we got a hit on the very first read,
* or the CPU was so fast/slow that the quotient wouldn't fit in
* 32 bits..
*/
bad_ctc:
printf("bad_ctc\n");
return 0;
}
static unsigned long clocks_per_tick;
static void setup_timers(void)
{
if (!clocks_per_tick) {
clocks_per_tick = calibrate_tsc();
/* Display the CPU Mhz to easily test if the calibration was bad */
printf("CPU %ld Mhz\n", (clocks_per_tick/1000 * TICKS_PER_SEC)/1000);
}
}
unsigned long currticks(void)
{
unsigned long clocks_high, clocks_low;
unsigned long currticks;
/* Read the Time Stamp Counter */
rdtsc(clocks_low, clocks_high);
/* currticks = clocks / clocks_per_tick; */
__asm__("divl %1"
:"=a" (currticks)
:"r" (clocks_per_tick), "0" (clocks_low), "d" (clocks_high));
return currticks;
}
static unsigned long long timer_timeout;
static int __timer_running(void)
{
unsigned long long now;
rdtscll(now);
return now < timer_timeout;
}
void udelay(unsigned int usecs)
{
unsigned long long now;
rdtscll(now);
timer_timeout = now + usecs * ((clocks_per_tick * TICKS_PER_SEC)/(1000*1000));
while(__timer_running());
}
void ndelay(unsigned int nsecs)
{
unsigned long long now;
rdtscll(now);
timer_timeout = now + nsecs * ((clocks_per_tick * TICKS_PER_SEC)/(1000*1000*1000));
while(__timer_running());
}
void load_timer2(unsigned int timer2_ticks)
{
unsigned long long now;
unsigned long clocks;
rdtscll(now);
clocks = timer2_ticks * ((clocks_per_tick * TICKS_PER_SEC)/CLOCK_TICK_RATE);
timer_timeout = now + clocks;
}
int timer2_running(void)
{
return __timer_running();
}
#endif /* RTC_CURRTICKS */
struct init_fn timer_init_fn __init_fn ( INIT_NORMAL ) = {
.initialise = setup_timers,
};
+3
View File
@@ -16,6 +16,9 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
FILE_LICENCE ( GPL2_OR_LATER );
#include <gpxe/io.h>
#include <pic8259.h>
/** @file
-8
View File
@@ -1,8 +0,0 @@
OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
OUTPUT_ARCH(i386)
SECTIONS {
.prefix.udata : {
*(*)
}
}
-8
View File
@@ -1,8 +0,0 @@
OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
OUTPUT_ARCH(i386)
SECTIONS {
.prefix.zdata : {
*(*)
}
}
+89
View File
@@ -0,0 +1,89 @@
/*
* Copyright (C) 2008 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.
*/
FILE_LICENCE ( GPL2_OR_LATER );
/** @file
*
* RDTSC timer
*
*/
#include <assert.h>
#include <gpxe/timer.h>
#include <gpxe/timer2.h>
/**
* Number of TSC ticks per microsecond
*
* This is calibrated on the first use of the timer.
*/
static unsigned long rdtsc_ticks_per_usec;
/**
* Delay for a fixed number of microseconds
*
* @v usecs Number of microseconds for which to delay
*/
static void rdtsc_udelay ( unsigned long usecs ) {
unsigned long start;
unsigned long elapsed;
/* Sanity guard, since we may divide by this */
if ( ! usecs )
usecs = 1;
start = currticks();
if ( rdtsc_ticks_per_usec ) {
/* Already calibrated; busy-wait until done */
do {
elapsed = ( currticks() - start );
} while ( elapsed < ( usecs * rdtsc_ticks_per_usec ) );
} else {
/* Not yet calibrated; use timer2 and calibrate
* based on result.
*/
timer2_udelay ( usecs );
elapsed = ( currticks() - start );
rdtsc_ticks_per_usec = ( elapsed / usecs );
DBG ( "RDTSC timer calibrated: %ld ticks in %ld usecs "
"(%ld MHz)\n", elapsed, usecs,
( rdtsc_ticks_per_usec << TSC_SHIFT ) );
}
}
/**
* Get number of ticks per second
*
* @ret ticks_per_sec Number of ticks per second
*/
static unsigned long rdtsc_ticks_per_sec ( void ) {
/* Calibrate timer, if not already done */
if ( ! rdtsc_ticks_per_usec )
udelay ( 1 );
/* Sanity check */
assert ( rdtsc_ticks_per_usec != 0 );
return ( rdtsc_ticks_per_usec * 1000 * 1000 );
}
PROVIDE_TIMER ( rdtsc, udelay, rdtsc_udelay );
PROVIDE_TIMER_INLINE ( rdtsc, currticks );
PROVIDE_TIMER ( rdtsc, ticks_per_sec, rdtsc_ticks_per_sec );
-23
View File
@@ -1,23 +0,0 @@
/* Real-mode interface: C portions.
*
* Initial version by Michael Brown <mbrown@fensystems.co.uk>, January 2004.
*/
#include "realmode.h"
/*
* Copy data to/from base memory.
*
*/
#ifdef KEEP_IT_REAL
void memcpy_to_real ( segoff_t dest, void *src, size_t n ) {
}
void memcpy_from_real ( void *dest, segoff_t src, size_t n ) {
}
#endif /* KEEP_IT_REAL */
+18 -11
View File
@@ -1,4 +1,4 @@
#include <io.h>
#include <gpxe/io.h>
#include <registers.h>
#include <gpxe/memmap.h>
@@ -9,6 +9,8 @@
*
*/
FILE_LICENCE ( GPL2_OR_LATER );
/*
* The linker passes in the symbol _max_align, which is the alignment
* that we must preserve, in bytes.
@@ -18,8 +20,8 @@ extern char _max_align[];
#define max_align ( ( unsigned int ) _max_align )
/* Linker symbols */
extern char _text[];
extern char _end[];
extern char _textdata[];
extern char _etextdata[];
/* within 1MB of 4GB is too close.
* MAX_ADDR is the maximum address we can easily do DMA to.
@@ -39,7 +41,7 @@ extern char _end[];
* address space, and returns the physical address of the new location
* to the prefix in %edi.
*/
__cdecl void relocate ( struct i386_all_regs *ix86 ) {
__asmcall void relocate ( struct i386_all_regs *ix86 ) {
struct memory_map memmap;
unsigned long start, end, size, padded_size;
unsigned long new_start, new_end;
@@ -47,8 +49,8 @@ __cdecl void relocate ( struct i386_all_regs *ix86 ) {
/* Get memory map and current location */
get_memmap ( &memmap );
start = virt_to_phys ( _text );
end = virt_to_phys ( _end );
start = virt_to_phys ( _textdata );
end = virt_to_phys ( _etextdata );
size = ( end - start );
padded_size = ( size + max_align - 1 );
@@ -93,11 +95,16 @@ __cdecl void relocate ( struct i386_all_regs *ix86 ) {
/* If last byte that might be used (r_end-1)
* is in an odd megabyte, round down r_end to
* the top of the next even megabyte.
*
* Make sure that we don't accidentally wrap
* r_end below 0.
*/
r_end = ( r_end - 1 ) & ~0xfffff;
DBG ( "...end truncated to %lx "
"(avoid ending in odd megabyte)\n",
r_end );
if ( r_end >= 1 ) {
r_end = ( r_end - 1 ) & ~0xfffff;
DBG ( "...end truncated to %lx "
"(avoid ending in odd megabyte)\n",
r_end );
}
} else if ( ( r_end - size ) & 0x100000 ) {
/* If the last byte that might be used
* (r_end-1) is in an even megabyte, but the
@@ -108,7 +115,7 @@ __cdecl void relocate ( struct i386_all_regs *ix86 ) {
* Make sure that we don't accidentally wrap
* r_end below 0.
*/
if ( r_end > 0x100000 ) {
if ( r_end >= 0x100000 ) {
r_end = ( r_end - 0x100000 ) & ~0xfffff;
DBG ( "...end truncated to %lx "
"(avoid starting in odd megabyte)\n",
+2
View File
@@ -1,5 +1,7 @@
/* setjmp and longjmp. Use of these functions is deprecated. */
FILE_LICENCE ( GPL2_OR_LATER )
.text
.arch i386
.code32
+3 -1
View File
@@ -1,10 +1,12 @@
FILE_LICENCE ( GPL2_OR_LATER )
.arch i386
/****************************************************************************
* Internal stack
****************************************************************************
*/
.section ".stack"
.section ".stack", "aw", @nobits
.align 8
.globl _stack
_stack:
+3 -1
View File
@@ -1,10 +1,12 @@
FILE_LICENCE ( GPL2_OR_LATER )
.arch i386
/****************************************************************************
* Internal stack
****************************************************************************
*/
.section ".stack16"
.section ".stack16", "aw", @nobits
.align 8
.globl _stack16
_stack16:
-8
View File
@@ -1,8 +0,0 @@
/* When linking with an uncompressed image, these symbols are not
* defined so we provide them here.
*/
__decompressor_uncompressed = 0 ;
__decompressor__start = 0 ;
INCLUDE arch/i386/core/start16z.lds
-65
View File
@@ -1,65 +0,0 @@
OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
OUTPUT_ARCH(i386)
/* Linker-generated symbols are prefixed with a double underscore.
* Decompressor symbols are prefixed with __decompressor_. All other
* symbols are the same as in the original object file, i.e. the
* runtime addresses.
*/
ENTRY(_start16)
SECTIONS {
.text : {
*(.text)
}
.payload : {
__payload_start = .;
*(.data)
__payload_end = .;
}
/* _payload_size is the size of the binary image appended to
* start16, in bytes.
*/
__payload_size = __payload_end - __payload_start ;
/* _size is the size of the runtime image
* (start32 + the C code), in bytes.
*/
__size = _end - _start ;
/* _decompressor_size is the size of the decompressor, in
* bytes. For a non-compressed image, start16.lds sets
* _decompressor_uncompressed = _decompressor__start = 0.
*/
__decompressor_size = __decompressor_uncompressed - __decompressor__start ;
/* image__size is the total size of the image, after
* decompression and including the decompressor if applicable.
* It is therefore the amount of memory that start16's payload
* needs in order to execute, in bytes.
*/
__image_size = __size + __decompressor_size ;
/* Amount to add to runtime symbols to obtain the offset of
* that symbol within the image.
*/
__offset_adjust = __decompressor_size - _start ;
/* Calculations for the stack
*/
__stack_size = _estack - _stack ;
__offset_stack = _stack + __offset_adjust ;
/* Some symbols will be larger than 16 bits but guaranteed to
* be multiples of 16. We calculate them in paragraphs and
* export these symbols which can be used in 16-bit code
* without risk of overflow.
*/
__image_size_pgh = ( __image_size / 16 );
__start_pgh = ( _start / 16 );
__decompressor_size_pgh = ( __decompressor_size / 16 );
__offset_stack_pgh = ( __offset_stack / 16 );
}
-325
View File
@@ -1,325 +0,0 @@
#include "virtaddr.h"
.equ MSR_K6_EFER, 0xC0000080
.equ EFER_LME, 0x00000100
.equ X86_CR4_PAE, 0x00000020
.equ CR0_PG, 0x80000000
#ifdef GAS291
#define DATA32 data32;
#define ADDR32 addr32;
#define LJMPI(x) ljmp x
#else
#define DATA32 data32
#define ADDR32 addr32
/* newer GAS295 require #define LJMPI(x) ljmp *x */
#define LJMPI(x) ljmp x
#endif
/*
* NOTE: if you write a subroutine that is called from C code (gcc/egcs),
* then you only have to take care of %ebx, %esi, %edi and %ebp. These
* registers must not be altered under any circumstance. All other registers
* may be clobbered without any negative side effects. If you don't follow
* this rule then you'll run into strange effects that only occur on some
* gcc versions (because the register allocator may use different registers).
*
* All the data32 prefixes for the ljmp instructions are necessary, because
* the assembler emits code with a relocation address of 0. This means that
* all destinations are initially negative, which the assembler doesn't grok,
* because for some reason negative numbers don't fit into 16 bits. The addr32
* prefixes are there for the same reasons, because otherwise the memory
* references are only 16 bit wide. Theoretically they are all superfluous.
* One last note about prefixes: the data32 prefixes on all call _real_to_prot
* instructions could be removed if the _real_to_prot function is changed to
* deal correctly with 16 bit return addresses. I tried it, but failed.
*/
.text
.arch i386
.code32
/* This is a struct os_entry_regs */
.globl os_regs
os_regs: .space 56
/**************************************************************************
XSTART32 - Transfer control to the kernel just loaded
**************************************************************************/
.globl xstart32
xstart32:
/* Save the callee save registers */
movl %ebp, os_regs + 32
movl %esi, os_regs + 36
movl %edi, os_regs + 40
movl %ebx, os_regs + 44
/* save the return address */
popl %eax
movl %eax, os_regs + 48
/* save the stack pointer */
movl %esp, os_regs + 52
/* Get the new destination address */
popl %ecx
/* Store the physical address of xend on the stack */
movl $xend32, %ebx
addl virt_offset, %ebx
pushl %ebx
/* Store the destination address on the stack */
pushl $PHYSICAL_CS
pushl %ecx
/* Cache virt_offset */
movl virt_offset, %ebp
/* Switch to using physical addresses */
call _virt_to_phys
/* Save the target stack pointer */
movl %esp, os_regs + 12(%ebp)
leal os_regs(%ebp), %esp
/* Store the pointer to os_regs */
movl %esp, os_regs_ptr(%ebp)
/* Load my new registers */
popal
movl (-32 + 12)(%esp), %esp
/* Jump to the new kernel
* The lret switches to a flat code segment
*/
lret
.balign 4
.globl xend32
xend32:
/* Fixup %eflags */
nop
cli
cld
/* Load %esp with &os_regs + virt_offset */
.byte 0xbc /* movl $0, %esp */
os_regs_ptr:
.long 0
/* Save the result registers */
addl $32, %esp
pushal
/* Compute virt_offset */
movl %esp, %ebp
subl $os_regs, %ebp
/* Load the stack pointer and convert it to physical address */
movl 52(%esp), %esp
addl %ebp, %esp
/* Enable the virtual addresses */
leal _phys_to_virt(%ebp), %eax
call *%eax
/* Restore the callee save registers */
movl os_regs + 32, %ebp
movl os_regs + 36, %esi
movl os_regs + 40, %edi
movl os_regs + 44, %ebx
movl os_regs + 48, %edx
movl os_regs + 52, %esp
/* Get the C return value */
movl os_regs + 28, %eax
jmpl *%edx
#ifdef CONFIG_X86_64
.arch sledgehammer
/**************************************************************************
XSTART_lm - Transfer control to the kernel just loaded in long mode
**************************************************************************/
.globl xstart_lm
xstart_lm:
/* Save the callee save registers */
pushl %ebp
pushl %esi
pushl %edi
pushl %ebx
/* Cache virt_offset && (virt_offset & 0xfffff000) */
movl virt_offset, %ebp
movl %ebp, %ebx
andl $0xfffff000, %ebx
/* Switch to using physical addresses */
call _virt_to_phys
/* Initialize the page tables */
/* Level 4 */
leal 0x23 + pgt_level3(%ebx), %eax
leal pgt_level4(%ebx), %edi
movl %eax, (%edi)
/* Level 3 */
leal 0x23 + pgt_level2(%ebx), %eax
leal pgt_level3(%ebx), %edi
movl %eax, 0x00(%edi)
addl $4096, %eax
movl %eax, 0x08(%edi)
addl $4096, %eax
movl %eax, 0x10(%edi)
addl $4096, %eax
movl %eax, 0x18(%edi)
/* Level 2 */
movl $0xe3, %eax
leal pgt_level2(%ebx), %edi
leal 16384(%edi), %esi
pgt_level2_loop:
movl %eax, (%edi)
addl $8, %edi
addl $0x200000, %eax
cmp %esi, %edi
jne pgt_level2_loop
/* Point at the x86_64 page tables */
leal pgt_level4(%ebx), %edi
movl %edi, %cr3
/* Setup for the return from 64bit mode */
/* 64bit align the stack */
movl %esp, %ebx /* original stack pointer + 16 */
andl $0xfffffff8, %esp
/* Save original stack pointer + 16 */
pushl %ebx
/* Save virt_offset */
pushl %ebp
/* Setup for the jmp to 64bit long mode */
leal start_lm(%ebp), %eax
movl %eax, 0x00 + start_lm_addr(%ebp)
movl $LM_CODE_SEG, %eax
movl %eax, 0x04 + start_lm_addr(%ebp)
/* Setup for the jump out of 64bit long mode */
leal end_lm(%ebp), %eax
movl %eax, 0x00 + end_lm_addr(%ebp)
movl $FLAT_CODE_SEG, %eax
movl %eax, 0x04 + end_lm_addr(%ebp)
/* Enable PAE mode */
movl %cr4, %eax
orl $X86_CR4_PAE, %eax
movl %eax, %cr4
/* Enable long mode */
movl $MSR_K6_EFER, %ecx
rdmsr
orl $EFER_LME, %eax
wrmsr
/* Start paging, entering 32bit compatiblity mode */
movl %cr0, %eax
orl $CR0_PG, %eax
movl %eax, %cr0
/* Enter 64bit long mode */
ljmp *start_lm_addr(%ebp)
.code64
start_lm:
/* Load 64bit data segments */
movl $LM_DATA_SEG, %eax
movl %eax, %ds
movl %eax, %es
movl %eax, %ss
andq $0xffffffff, %rbx
/* Get the address to jump to */
movl 20(%rbx), %edx
andq $0xffffffff, %rdx
/* Get the argument pointer */
movl 24(%rbx), %ebx
andq $0xffffffff, %rbx
/* Jump to the 64bit code */
call *%rdx
/* Preserve the result */
movl %eax, %edx
/* Fixup %eflags */
cli
cld
/* Switch to 32bit compatibility mode */
ljmp *end_lm_addr(%rip)
.code32
end_lm:
/* Disable paging */
movl %cr0, %eax
andl $~CR0_PG, %eax
movl %eax, %cr0
/* Disable long mode */
movl $MSR_K6_EFER, %ecx
rdmsr
andl $~EFER_LME, %eax
wrmsr
/* Disable PAE */
movl %cr4, %eax
andl $~X86_CR4_PAE, %eax
movl %eax, %cr4
/* Compute virt_offset */
popl %ebp
/* Compute the original stack pointer + 16 */
popl %ebx
movl %ebx, %esp
/* Enable the virtual addresses */
leal _phys_to_virt(%ebp), %eax
call *%eax
/* Restore the callee save registers */
popl %ebx
popl %esi
popl %edi
popl %ebp
/* Get the C return value */
movl %edx, %eax
/* Return */
ret
.arch i386
#endif /* CONFIG_X86_64 */
#ifdef CONFIG_X86_64
.section ".bss"
.p2align 12
/* Include a dummy space in case we are loaded badly aligned */
.space 4096
/* Reserve enough space for a page table convering 4GB with 2MB pages */
pgt_level4:
.space 4096
pgt_level3:
.space 4096
pgt_level2:
.space 16384
start_lm_addr:
.space 8
end_lm_addr:
.space 8
#endif
+87
View File
@@ -0,0 +1,87 @@
/*
* arch/i386/core/i386_timer.c
*
* Use the "System Timer 2" to implement the udelay callback in
* the BIOS timer driver. Also used to calibrate the clock rate
* in the RTDSC timer driver.
*
* 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, or (at
* your option) any later version.
*/
FILE_LICENCE ( GPL2_OR_LATER );
#include <stddef.h>
#include <gpxe/timer2.h>
#include <gpxe/io.h>
/* Timers tick over at this rate */
#define TIMER2_TICKS_PER_SEC 1193180U
/* Parallel Peripheral Controller Port B */
#define PPC_PORTB 0x61
/* Meaning of the port bits */
#define PPCB_T2OUT 0x20 /* Bit 5 */
#define PPCB_SPKR 0x02 /* Bit 1 */
#define PPCB_T2GATE 0x01 /* Bit 0 */
/* Ports for the 8254 timer chip */
#define TIMER2_PORT 0x42
#define TIMER_MODE_PORT 0x43
/* Meaning of the mode bits */
#define TIMER0_SEL 0x00
#define TIMER1_SEL 0x40
#define TIMER2_SEL 0x80
#define READBACK_SEL 0xC0
#define LATCH_COUNT 0x00
#define LOBYTE_ACCESS 0x10
#define HIBYTE_ACCESS 0x20
#define WORD_ACCESS 0x30
#define MODE0 0x00
#define MODE1 0x02
#define MODE2 0x04
#define MODE3 0x06
#define MODE4 0x08
#define MODE5 0x0A
#define BINARY_COUNT 0x00
#define BCD_COUNT 0x01
static void load_timer2 ( unsigned int ticks ) {
/*
* Now let's take care of PPC channel 2
*
* Set the Gate high, program PPC channel 2 for mode 0,
* (interrupt on terminal count mode), binary count,
* load 5 * LATCH count, (LSB and MSB) to begin countdown.
*
* Note some implementations have a bug where the high bits byte
* of channel 2 is ignored.
*/
/* Set up the timer gate, turn off the speaker */
/* Set the Gate high, disable speaker */
outb((inb(PPC_PORTB) & ~PPCB_SPKR) | PPCB_T2GATE, PPC_PORTB);
/* binary, mode 0, LSB/MSB, Ch 2 */
outb(TIMER2_SEL|WORD_ACCESS|MODE0|BINARY_COUNT, TIMER_MODE_PORT);
/* LSB of ticks */
outb(ticks & 0xFF, TIMER2_PORT);
/* MSB of ticks */
outb(ticks >> 8, TIMER2_PORT);
}
static int timer2_running ( void ) {
return ((inb(PPC_PORTB) & PPCB_T2OUT) == 0);
}
void timer2_udelay ( unsigned long usecs ) {
load_timer2 ( ( usecs * TIMER2_TICKS_PER_SEC ) / ( 1000 * 1000 ) );
while (timer2_running()) {
/* Do nothing */
}
}
+1 -1
View File
@@ -7,7 +7,7 @@
#include "stddef.h"
#include "string.h"
#include "io.h"
#include <gpxe/io.h>
#include "console.h"
#include <gpxe/init.h>
#include "vga.h"
+3 -1
View File
@@ -4,7 +4,9 @@
*
*/
#include "virtaddr.h"
FILE_LICENCE ( GPL2_OR_LATER )
#include "librm.h"
.arch i386
.text
+96
View File
@@ -0,0 +1,96 @@
/*
* Copyright (C) 2008 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.
*/
FILE_LICENCE ( GPL2_OR_LATER );
#include <gpxe/io.h>
#include <gpxe/x86_io.h>
/** @file
*
* gPXE I/O API for x86
*
*/
/**
* Read 64-bit qword from memory-mapped device
*
* @v io_addr I/O address
* @ret data Value read
*
* This routine uses MMX instructions.
*/
static uint64_t x86_readq ( volatile uint64_t *io_addr ) {
uint64_t data;
__asm__ __volatile__ ( "pushl %%edx\n\t"
"pushl %%eax\n\t"
"movq (%1), %%mm0\n\t"
"movq %%mm0, (%%esp)\n\t"
"popl %%eax\n\t"
"popl %%edx\n\t"
"emms\n\t"
: "=A" ( data ) : "r" ( io_addr ) );
return data;
}
/**
* Write 64-bit qword to memory-mapped device
*
* @v data Value to write
* @v io_addr I/O address
*
* This routine uses MMX instructions.
*/
static void x86_writeq ( uint64_t data, volatile uint64_t *io_addr ) {
__asm__ __volatile__ ( "pushl %%edx\n\t"
"pushl %%eax\n\t"
"movq (%%esp), %%mm0\n\t"
"movq %%mm0, (%1)\n\t"
"popl %%eax\n\t"
"popl %%edx\n\t"
"emms\n\t"
: : "A" ( data ), "r" ( io_addr ) );
}
PROVIDE_IOAPI_INLINE ( x86, phys_to_bus );
PROVIDE_IOAPI_INLINE ( x86, bus_to_phys );
PROVIDE_IOAPI_INLINE ( x86, ioremap );
PROVIDE_IOAPI_INLINE ( x86, iounmap );
PROVIDE_IOAPI_INLINE ( x86, io_to_bus );
PROVIDE_IOAPI_INLINE ( x86, readb );
PROVIDE_IOAPI_INLINE ( x86, readw );
PROVIDE_IOAPI_INLINE ( x86, readl );
PROVIDE_IOAPI ( x86, readq, x86_readq );
PROVIDE_IOAPI_INLINE ( x86, writeb );
PROVIDE_IOAPI_INLINE ( x86, writew );
PROVIDE_IOAPI_INLINE ( x86, writel );
PROVIDE_IOAPI ( x86, writeq, x86_writeq );
PROVIDE_IOAPI_INLINE ( x86, inb );
PROVIDE_IOAPI_INLINE ( x86, inw );
PROVIDE_IOAPI_INLINE ( x86, inl );
PROVIDE_IOAPI_INLINE ( x86, outb );
PROVIDE_IOAPI_INLINE ( x86, outw );
PROVIDE_IOAPI_INLINE ( x86, outl );
PROVIDE_IOAPI_INLINE ( x86, insb );
PROVIDE_IOAPI_INLINE ( x86, insw );
PROVIDE_IOAPI_INLINE ( x86, insl );
PROVIDE_IOAPI_INLINE ( x86, outsb );
PROVIDE_IOAPI_INLINE ( x86, outsw );
PROVIDE_IOAPI_INLINE ( x86, outsl );
PROVIDE_IOAPI_INLINE ( x86, iodelay );
PROVIDE_IOAPI_INLINE ( x86, mb );
+3 -1
View File
@@ -16,6 +16,8 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
FILE_LICENCE ( GPL2_OR_LATER );
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
@@ -135,7 +137,7 @@ static void undipci_remove ( struct pci_device *pci ) {
}
static struct pci_device_id undipci_nics[] = {
PCI_ROM ( 0xffff, 0xffff, "undipci", "UNDI (PCI)" ),
PCI_ROM ( 0xffff, 0xffff, "undipci", "UNDI (PCI)", 0 ),
};
struct pci_driver undipci_driver __pci_driver = {
+4 -4
View File
@@ -1,3 +1,5 @@
FILE_LICENCE ( GPL2_OR_LATER )
#define PXENV_UNDI_ISR 0x0014
#define PXENV_UNDI_ISR_IN_START 1
#define PXENV_UNDI_ISR_OUT_OURS 0
@@ -10,11 +12,9 @@
.text
.arch i386
.section ".text16", "ax", @progbits
.section ".data16", "aw", @progbits
.code16
.section ".text16"
.section ".text16", "ax", @progbits
.globl undiisr
undiisr:
@@ -75,7 +75,7 @@ exit: /* Restore registers and return */
popw %ds
iret
.section ".data16"
.section ".data16", "aw", @progbits
undinet_params:
status: .word 0
funcflag: .word 0
+4 -3
View File
@@ -16,6 +16,8 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
FILE_LICENCE ( GPL2_OR_LATER );
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
@@ -90,11 +92,10 @@ int undi_load ( struct undi_device *undi, struct undi_rom *undirom ) {
undi_loader_entry = undirom->loader_entry;
__asm__ __volatile__ ( REAL_CODE ( "pushw %%ds\n\t"
"pushw %%ax\n\t"
"lcall *%c2\n\t"
"lcall *undi_loader_entry\n\t"
"addw $4, %%sp\n\t" )
: "=a" ( exit )
: "a" ( & __from_data16 ( undi_loader ) ),
"p" ( & __from_data16 ( undi_loader_entry ) )
: "a" ( __from_data16 ( &undi_loader ) )
: "ebx", "ecx", "edx", "esi", "edi", "ebp" );
/* UNDI API calls may rudely change the status of A20 and not
+59 -40
View File
@@ -16,6 +16,8 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
FILE_LICENCE ( GPL2_OR_LATER );
#include <string.h>
#include <pxe.h>
#include <realmode.h>
@@ -23,6 +25,7 @@
#include <biosint.h>
#include <pnpbios.h>
#include <basemem_packet.h>
#include <gpxe/io.h>
#include <gpxe/iobuf.h>
#include <gpxe/netdevice.h>
#include <gpxe/if_ether.h>
@@ -172,13 +175,12 @@ static int undinet_call ( struct undi_nic *undinic, unsigned int function,
__asm__ __volatile__ ( REAL_CODE ( "pushw %%es\n\t"
"pushw %%di\n\t"
"pushw %%bx\n\t"
"lcall *%c3\n\t"
"lcall *undinet_entry_point\n\t"
"addw $6, %%sp\n\t" )
: "=a" ( exit ), "=b" ( discard_b ),
"=D" ( discard_D )
: "p" ( &__from_data16 ( undinet_entry_point )),
"b" ( function ),
"D" ( &__from_data16 ( undinet_params ) )
: "b" ( function ),
"D" ( __from_data16 ( &undinet_params ) )
: "ecx", "edx", "esi", "ebp" );
/* UNDI API calls may rudely change the status of A20 and not
@@ -211,7 +213,7 @@ static int undinet_call ( struct undi_nic *undinic, unsigned int function,
if ( rc != 0 ) {
SEGOFF16_t rm_params = {
.segment = rm_ds,
.offset = (intptr_t) &__from_data16 ( undinet_params ),
.offset = __from_data16 ( &undinet_params ),
};
DBGC ( undinic, "UNDINIC %p %s failed: %s\n", undinic,
@@ -357,17 +359,14 @@ static int undinet_transmit ( struct net_device *netdev,
/* Create PXENV_UNDI_TRANSMIT data structure */
memset ( &undi_transmit, 0, sizeof ( undi_transmit ) );
undi_transmit.DestAddr.segment = rm_ds;
undi_transmit.DestAddr.offset
= ( ( unsigned ) & __from_data16 ( undinet_tbd ) );
undi_transmit.DestAddr.offset = __from_data16 ( &undinet_tbd );
undi_transmit.TBD.segment = rm_ds;
undi_transmit.TBD.offset
= ( ( unsigned ) & __from_data16 ( undinet_tbd ) );
undi_transmit.TBD.offset = __from_data16 ( &undinet_tbd );
/* Create PXENV_UNDI_TBD data structure */
undinet_tbd.ImmedLength = len;
undinet_tbd.Xmit.segment = rm_ds;
undinet_tbd.Xmit.offset
= ( ( unsigned ) & __from_data16 ( basemem_packet ) );
undinet_tbd.Xmit.offset = __from_data16 ( basemem_packet );
/* Issue PXE API call */
if ( ( rc = undinet_call ( undinic, PXENV_UNDI_TRANSMIT,
@@ -484,8 +483,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.
*/
@@ -543,9 +541,13 @@ static int undinet_open ( struct net_device *netdev ) {
undinet_call ( undinic, PXENV_UNDI_SET_STATION_ADDRESS,
&undi_set_address, sizeof ( undi_set_address ) );
/* Open NIC */
/* Open NIC. We ask for promiscuous operation, since it's the
* only way to ask for all multicast addresses. On any
* switched network, it shouldn't really make a difference to
* performance.
*/
memset ( &undi_open, 0, sizeof ( undi_open ) );
undi_open.PktFilter = ( FLTR_DIRECTED | FLTR_BRDCST );
undi_open.PktFilter = ( FLTR_DIRECTED | FLTR_BRDCST | FLTR_PRMSCS );
if ( ( rc = undinet_call ( undinic, PXENV_UNDI_OPEN, &undi_open,
sizeof ( undi_open ) ) ) != 0 )
goto err;
@@ -668,22 +670,26 @@ 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 ) );
if ( ( rc = undinet_call ( undinic, PXENV_UNDI_GET_INFORMATION,
&undi_info, sizeof ( undi_info ) ) ) != 0 )
goto err_undi_get_information;
memcpy ( netdev->ll_addr, undi_info.PermNodeAddress, ETH_ALEN );
memcpy ( netdev->hw_addr, undi_info.PermNodeAddress, ETH_ALEN );
undinic->irq = undi_info.IntNumber;
if ( undinic->irq > IRQ_MAX ) {
DBGC ( undinic, "UNDINIC %p invalid IRQ %d\n",
@@ -691,7 +697,7 @@ int undinet_probe ( struct undi_device *undi ) {
goto err_bad_irq;
}
DBGC ( undinic, "UNDINIC %p is %s on IRQ %d\n",
undinic, eth_ntoa ( netdev->ll_addr ), undinic->irq );
undinic, eth_ntoa ( netdev->hw_addr ), undinic->irq );
/* Get interface information */
memset ( &undi_iface, 0, sizeof ( undi_iface ) );
@@ -699,8 +705,9 @@ int undinet_probe ( struct undi_device *undi ) {
&undi_iface,
sizeof ( undi_iface ) ) ) != 0 )
goto err_undi_get_iface_info;
DBGC ( undinic, "UNDINIC %p has type %s and link speed %ld\n",
undinic, undi_iface.IfaceType, undi_iface.LinkSpeed );
DBGC ( undinic, "UNDINIC %p has type %s, speed %d, flags %08x\n",
undinic, undi_iface.IfaceType, undi_iface.LinkSpeed,
undi_iface.ServiceFlags );
if ( strncmp ( ( ( char * ) undi_iface.IfaceType ), "Etherboot",
sizeof ( undi_iface.IfaceType ) ) == 0 ) {
DBGC ( undinic, "UNDINIC %p Etherboot 5.4 workaround enabled\n",
@@ -708,6 +715,9 @@ int undinet_probe ( struct undi_device *undi ) {
undinic->hacks |= UNDI_HACK_EB54;
}
/* Mark as link up; we don't handle link state */
netdev_link_up ( netdev );
/* Register network device */
if ( ( rc = register_netdev ( netdev ) ) != 0 )
goto err_register;
@@ -727,11 +737,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 );
@@ -754,19 +766,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 ) );
+20
View File
@@ -16,10 +16,13 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
FILE_LICENCE ( GPL2_OR_LATER );
#include <stdint.h>
#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 +110,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,
};
+2
View File
@@ -16,6 +16,8 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
FILE_LICENCE ( GPL2_OR_LATER );
#include <realmode.h>
#include <undipreload.h>
+6 -4
View File
@@ -16,6 +16,8 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
FILE_LICENCE ( GPL2_OR_LATER );
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
@@ -52,7 +54,7 @@ static int undirom_parse_pxeromid ( struct undi_rom *undirom,
sizeof ( undi_rom_id ) );
if ( undi_rom_id.Signature != UNDI_ROM_ID_SIGNATURE ) {
DBGC ( undirom, "UNDIROM %p has bad PXE ROM ID signature "
"%08lx\n", undirom, undi_rom_id.Signature );
"%08x\n", undirom, undi_rom_id.Signature );
return -EINVAL;
}
@@ -94,7 +96,7 @@ static int undirom_parse_pcirheader ( struct undi_rom *undirom,
sizeof ( pcir_header ) );
if ( pcir_header.signature != PCIR_SIGNATURE ) {
DBGC ( undirom, "UNDIROM %p has bad PCI expansion header "
"signature %08lx\n", undirom, pcir_header.signature );
"signature %08x\n", undirom, pcir_header.signature );
return -EINVAL;
}
@@ -188,9 +190,9 @@ static void undirom_probe_all_roms ( void ) {
DBG ( "Scanning for PXE expansion ROMs\n" );
/* Scan through expansion ROM region at 2kB intervals */
/* Scan through expansion ROM region at 512 byte intervals */
for ( rom_segment = 0xc000 ; rom_segment < 0x10000 ;
rom_segment += 0x80 ) {
rom_segment += 0x20 ) {
undirom_probe ( rom_segment );
}
+2
View File
@@ -16,6 +16,8 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
FILE_LICENCE ( GPL2_OR_LATER );
#include <stdint.h>
#include <realmode.h>
#include <bios.h>
-55
View File
@@ -1,55 +0,0 @@
/* Etherboot routines for PCBIOS firmware.
*
* Body of routines taken from old pcbios.S
*/
#include <stdint.h>
#include <realmode.h>
#include <bios.h>
#define CF ( 1 << 0 )
/**************************************************************************
CURRTICKS - Get Time
Use direct memory access to BIOS variables, longword 0040:006C (ticks
today) and byte 0040:0070 (midnight crossover flag) instead of calling
timeofday BIOS interrupt.
**************************************************************************/
#if defined(CONFIG_TSC_CURRTICKS)
#undef CONFIG_BIOS_CURRTICKS
#else
#define CONFIG_BIOS_CURRTICKS 1
#endif
#if defined(CONFIG_BIOS_CURRTICKS)
unsigned long currticks ( void ) {
static uint32_t days = 0;
uint32_t ticks;
uint8_t midnight;
/* Re-enable interrupts so that the timer interrupt can occur
*/
__asm__ __volatile__ ( REAL_CODE ( "sti\n\t"
"nop\n\t"
"nop\n\t"
"cli\n\t" ) : : );
get_real ( ticks, BDA_SEG, 0x006c );
get_real ( midnight, BDA_SEG, 0x0070 );
if ( midnight ) {
midnight = 0;
put_real ( midnight, BDA_SEG, 0x0070 );
days += 0x1800b0;
}
return ( days + ticks );
}
#endif /* CONFIG_BIOS_CURRTICKS */
/**************************************************************************
CPU_NAP - Save power by halting the CPU until the next interrupt
**************************************************************************/
void cpu_nap ( void ) {
__asm__ __volatile__ ( REAL_CODE ( "sti\n\t"
"hlt\n\t"
"cli\n\t" ) : : );
}
+5 -1
View File
@@ -16,6 +16,8 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
FILE_LICENCE ( GPL2_OR_LATER );
#include <assert.h>
#include <realmode.h>
#include <console.h>
@@ -193,13 +195,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 +225,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;
}
+380 -258
View File
@@ -15,170 +15,112 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
FILE_LICENCE ( GPL2_OR_LATER )
.text
.arch i386
.section ".text16", "ax", @progbits
.section ".data16", "aw", @progbits
.section ".text16.data", "aw", @progbits
.code16
#define SMAP 0x534d4150
/****************************************************************************
* Check for overlap
/* Most documentation refers to the E820 buffer as being 20 bytes, and
* the API makes it perfectly legitimate to pass only a 20-byte buffer
* and expect to get valid data. However, some morons at ACPI decided
* to extend the data structure by adding an extra "extended
* attributes" field and by including critical information within this
* field, such as whether or not the region is enabled. A caller who
* passes in only a 20-byte buffer therefore risks getting very, very
* misleading information.
*
* Parameters:
* %edx:%eax Region start
* %ecx:%ebx Region end
* %si Pointer to hidden region descriptor
* Returns:
* CF set Region overlaps
* CF clear No overlap
****************************************************************************
*/
.section ".text16"
check_overlap:
/* If start >= hidden_end, there is no overlap. */
testl %edx, %edx
jnz no_overlap
cmpl 4(%si), %eax
jae no_overlap
/* If end <= hidden_start, there is no overlap; equivalently,
* if end > hidden_start, there is overlap.
*/
testl %ecx, %ecx
jnz overlap
cmpl 0(%si), %ebx
ja overlap
no_overlap:
clc
ret
overlap:
stc
ret
.size check_overlap, . - check_overlap
* I have personally witnessed an HP BIOS that returns a value of
* 0x0009 in the extended attributes field. If we don't pass this
* value through to the caller, 32-bit WinPE will die, usually with a
* PAGE_FAULT_IN_NONPAGED_AREA blue screen of death.
*
* Allow a ridiculously large maximum value (64 bytes) for the E820
* buffer as a guard against insufficiently creative idiots in the
* future.
*/
#define E820MAXSIZE 64
/****************************************************************************
* Check for overflow/underflow
*
* Parameters:
* %edx:%eax Region start
* %ecx:%ebx Region end
* Returns:
* CF set start < end
* CF clear start >= end
* Allowed memory windows
*
* There are two ways to view this list. The first is as a list of
* (non-overlapping) allowed memory regions, sorted by increasing
* address. The second is as a list of (non-overlapping) hidden
* memory regions, again sorted by increasing address. The second
* view is offset by half an entry from the first: think about this
* for a moment and it should make sense.
*
* xxx_memory_window is used to indicate an "allowed region"
* structure, hidden_xxx_memory is used to indicate a "hidden region"
* structure. Each structure is 16 bytes in length.
*
****************************************************************************
*/
.section ".text16"
check_overflow:
pushl %ecx
pushl %ebx
subl %eax, %ebx
sbbl %edx, %ecx
popl %ebx
popl %ecx
ret
.size check_overflow, . - check_overflow
/****************************************************************************
* Truncate towards start of region
*
* Parameters:
* %edx:%eax Region start
* %ecx:%ebx Region end
* %si Pointer to hidden region descriptor
* Returns:
* %edx:%eax Modified region start
* %ecx:%ebx Modified region end
* CF set Region was truncated
* CF clear Region was not truncated
****************************************************************************
*/
.section ".text16"
truncate_to_start:
/* If overlaps, set region end = hidden region start */
call check_overlap
jnc 99f
movl 0(%si), %ebx
xorl %ecx, %ecx
/* If region end < region start, set region end = region start */
call check_overflow
jnc 1f
movl %eax, %ebx
movl %edx, %ecx
1: stc
99: ret
.size truncate_to_start, . - truncate_to_start
.section ".data16", "aw", @progbits
.align 16
.globl hidemem_base
.globl hidemem_umalloc
.globl hidemem_textdata
memory_windows:
base_memory_window: .long 0x00000000, 0x00000000 /* Start of memory */
hidemem_base: .long 0x000a0000, 0x00000000 /* Changes at runtime */
ext_memory_window: .long 0x000a0000, 0x00000000 /* 640kB mark */
hidemem_umalloc: .long 0xffffffff, 0xffffffff /* Changes at runtime */
.long 0xffffffff, 0xffffffff /* Changes at runtime */
hidemem_textdata: .long 0xffffffff, 0xffffffff /* Changes at runtime */
.long 0xffffffff, 0xffffffff /* Changes at runtime */
.long 0xffffffff, 0xffffffff /* End of memory */
memory_windows_end:
/****************************************************************************
* Truncate towards end of region
* Truncate region to memory window
*
* Parameters:
* %edx:%eax Region start
* %ecx:%ebx Region end
* %si Pointer to hidden region descriptor
* %edx:%eax Start of region
* %ecx:%ebx Length of region
* %si Memory window
* Returns:
* %edx:%eax Modified region start
* %ecx:%ebx Modified region end
* CF set Region was truncated
* CF clear Region was not truncated
* %edx:%eax Start of windowed region
* %ecx:%ebx Length of windowed region
****************************************************************************
*/
.section ".text16"
truncate_to_end:
/* If overlaps, set region start = hidden region end */
call check_overlap
jnc 99f
movl 4(%si), %eax
xorl %edx, %edx
/* If region start > region end, set region start = region end */
call check_overflow
jnc 1f
movl %ebx, %eax
movl %ecx, %edx
1: stc
99: ret
.size truncate_to_end, . - truncate_to_end
/****************************************************************************
* Truncate region
*
* Parameters:
* %edx:%eax Region start
* %ecx:%ebx Region length (*not* region end)
* %bp truncate_to_start or truncate_to_end
* Returns:
* %edx:%eax Modified region start
* %ecx:%ebx Modified region length
* CF set Region was truncated
* CF clear Region was not truncated
****************************************************************************
*/
.section ".text16"
truncate:
pushw %si
pushfw
/* Convert (start,len) to (start,end) */
.section ".text16", "ax", @progbits
window_region:
/* Convert (start,len) to (start, end) */
addl %eax, %ebx
adcl %edx, %ecx
/* Hide all hidden regions, truncating as directed */
movw $hidden_regions, %si
1: call *%bp
jnc 2f
popfw /* If CF was set, set stored CF in flags word on stack */
stc
pushfw
2: addw $8, %si
cmpl $0, 0(%si)
jne 1b
/* Convert modified (start,end) back to (start,len) */
/* Truncate to window start */
cmpl 4(%si), %edx
jne 1f
cmpl 0(%si), %eax
1: jae 2f
movl 4(%si), %edx
movl 0(%si), %eax
2: /* Truncate to window end */
cmpl 12(%si), %ecx
jne 1f
cmpl 8(%si), %ebx
1: jbe 2f
movl 12(%si), %ecx
movl 8(%si), %ebx
2: /* Convert (start, end) back to (start, len) */
subl %eax, %ebx
sbbl %edx, %ecx
popfw
popw %si
/* If length is <0, set length to 0 */
jae 1f
xorl %ebx, %ebx
xorl %ecx, %ecx
ret
.size truncate, . - truncate
.size window_region, . - window_region
/****************************************************************************
* Patch "memory above 1MB" figure
@@ -187,21 +129,19 @@ truncate:
* %ax Memory above 1MB, in 1kB blocks
* Returns:
* %ax Modified memory above 1M in 1kB blocks
* CF set Region was truncated
* CF clear Region was not truncated
****************************************************************************
*/
.section ".text16"
.section ".text16", "ax", @progbits
patch_1m:
pushal
/* Convert to (start,len) format and call truncate */
movw $truncate_to_start, %bp
xorl %ecx, %ecx
movzwl %ax, %ebx
shll $10, %ebx
xorl %edx, %edx
movl $0x100000, %eax
call truncate
movw $ext_memory_window, %si
call window_region
/* Convert back to "memory above 1MB" format and return via %ax */
pushfw
shrl $10, %ebx
@@ -219,20 +159,18 @@ patch_1m:
* %bx Memory above 16MB, in 64kB blocks
* Returns:
* %bx Modified memory above 16M in 64kB blocks
* CF set Region was truncated
* CF clear Region was not truncated
****************************************************************************
*/
.section ".text16"
.section ".text16", "ax", @progbits
patch_16m:
pushal
/* Convert to (start,len) format and call truncate */
movw $truncate_to_start, %bp
xorl %ecx, %ecx
shll $16, %ebx
xorl %edx, %edx
movl $0x1000000, %eax
call truncate
movw $ext_memory_window, %si
call window_region
/* Convert back to "memory above 16MB" format and return via %bx */
pushfw
shrl $16, %ebx
@@ -252,156 +190,344 @@ patch_16m:
* Returns:
* %ax Modified memory between 1MB and 16MB, in 1kB blocks
* %bx Modified memory above 16MB, in 64kB blocks
* CF set Region was truncated
* CF clear Region was not truncated
****************************************************************************
*/
.section ".text16"
.section ".text16", "ax", @progbits
patch_1m_16m:
call patch_1m
jc 1f
call patch_16m
ret
1: /* 1m region was truncated; kill the 16m region */
/* If 1M region is no longer full-length, kill off the 16M region */
cmpw $( 15 * 1024 ), %ax
je 1f
xorw %bx, %bx
ret
1: ret
.size patch_1m_16m, . - patch_1m_16m
/****************************************************************************
* Patch E820 memory map entry
* Get underlying e820 memory region to underlying_e820 buffer
*
* Parameters:
* %es:di Pointer to E820 memory map descriptor
* %bp truncate_to_start or truncate_to_end
* As for INT 15,e820
* Returns:
* %es:di Pointer to now-modified E820 memory map descriptor
* CF set Region was truncated
* CF clear Region was not truncated
* As for INT 15,e820
*
* Wraps the underlying INT 15,e820 call so that the continuation
* value (%ebx) is a 16-bit simple sequence counter (with the high 16
* bits ignored), and termination is always via CF=1 rather than
* %ebx=0.
*
****************************************************************************
*/
.section ".text16"
patch_e820:
.section ".text16", "ax", @progbits
get_underlying_e820:
/* If the requested region is in the cache, return it */
cmpw %bx, underlying_e820_index
jne 2f
pushw %di
pushw %si
movw $underlying_e820_cache, %si
cmpl underlying_e820_cache_size, %ecx
jbe 1f
movl underlying_e820_cache_size, %ecx
1: pushl %ecx
rep movsb
popl %ecx
popw %si
popw %di
incw %bx
movl %edx, %eax
ret
2:
/* If the requested region is earlier than the cached region,
* invalidate the cache.
*/
cmpw %bx, underlying_e820_index
jbe 1f
movw $0xffff, underlying_e820_index
1:
/* If the cache is invalid, reset the underlying %ebx */
cmpw $0xffff, underlying_e820_index
jne 1f
andl $0, underlying_e820_ebx
1:
/* If the cache is valid but the continuation value is zero,
* this means that the previous underlying call returned with
* %ebx=0. Return with CF=1 in this case.
*/
cmpw $0xffff, underlying_e820_index
je 1f
cmpl $0, underlying_e820_ebx
jne 1f
stc
ret
1:
/* Get the next region into the cache */
pushl %eax
pushl %ebx
pushl %ecx
pushl %edx
pushl %esi /* Some implementations corrupt %esi, so we */
pushl %edi /* preserve %esi, %edi and %ebp to be paranoid */
pushl %ebp
pushw %es
pushw %ds
popw %es
movw $underlying_e820_cache, %di
cmpl $E820MAXSIZE, %ecx
jbe 1f
movl $E820MAXSIZE, %ecx
1: movl underlying_e820_ebx, %ebx
stc
pushfw
lcall *%cs:int15_vector
popw %es
popl %ebp
popl %edi
popl %esi
/* Check for error return from underlying e820 call */
jc 2f /* CF set: error */
cmpl $SMAP, %eax
je 3f /* 'SMAP' missing: error */
2: /* An error occurred: return values returned by underlying e820 call */
stc /* Force CF set if SMAP was missing */
addr32 leal 16(%esp), %esp /* avoid changing other flags */
ret
3: /* No error occurred */
movl %ebx, underlying_e820_ebx
movl %ecx, underlying_e820_cache_size
popl %edx
popl %ecx
popl %ebx
popl %eax
/* Mark cache as containing this result */
incw underlying_e820_index
/* Loop until found */
jmp get_underlying_e820
.size get_underlying_e820, . - get_underlying_e820
.section ".data16", "aw", @progbits
underlying_e820_index:
.word 0xffff /* Initialise to an invalid value */
.size underlying_e820_index, . - underlying_e820_index
.section ".bss16", "aw", @nobits
underlying_e820_ebx:
.long 0
.size underlying_e820_ebx, . - underlying_e820_ebx
.section ".bss16", "aw", @nobits
underlying_e820_cache:
.space E820MAXSIZE
.size underlying_e820_cache, . - underlying_e820_cache
.section ".bss16", "aw", @nobits
underlying_e820_cache_size:
.long 0
.size underlying_e820_cache_size, . - underlying_e820_cache_size
/****************************************************************************
* Get windowed e820 region, without empty region stripping
*
* Parameters:
* As for INT 15,e820
* Returns:
* As for INT 15,e820
*
* Wraps the underlying INT 15,e820 call so that each underlying
* region is returned N times, windowed to fit within N visible-memory
* windows. Termination is always via CF=1.
*
****************************************************************************
*/
.section ".text16", "ax", @progbits
get_windowed_e820:
/* Preserve registers */
pushl %esi
pushw %bp
/* Split %ebx into %si:%bx, store original %bx in %bp */
pushl %ebx
popw %bp
popw %si
/* %si == 0 => start of memory_windows list */
testw %si, %si
jne 1f
movw $memory_windows, %si
1:
/* Get (cached) underlying e820 region to buffer */
call get_underlying_e820
jc 99f /* Abort on error */
/* Preserve registers */
pushal
/* start => %edx:%eax, len => %ecx:%ebx */
movl %es:0(%di), %eax
movl %es:4(%di), %edx
movl %es:8(%di), %ebx
movl %es:12(%di), %ecx
call truncate
/* Truncate region to current window */
call window_region
1: /* Store modified values in e820 map entry */
movl %eax, %es:0(%di)
movl %edx, %es:4(%di)
movl %ebx, %es:8(%di)
movl %ecx, %es:12(%di)
/* Restore registers */
popal
/* Derive continuation value for next call */
addw $16, %si
cmpw $memory_windows_end, %si
jne 1f
/* End of memory windows: reset %si and allow %bx to continue */
xorw %si, %si
jmp 2f
1: /* More memory windows to go: restore original %bx */
movw %bp, %bx
2: /* Construct %ebx from %si:%bx */
pushw %si
pushw %bx
popl %ebx
98: /* Clear CF */
clc
99: /* Restore registers and return */
popw %bp
popl %esi
ret
.size patch_e820, . - patch_e820
.size get_windowed_e820, . - get_windowed_e820
/****************************************************************************
* Split E820 memory map entry if necessary
* Get windowed e820 region, with empty region stripping
*
* Parameters:
* As for INT 15,e820
* Returns:
* As for INT 15,e820
*
* Calls the underlying INT 15,e820 and returns a modified memory map.
* Regions will be split around any hidden regions.
* Wraps the underlying INT 15,e820 call so that each underlying
* region is returned up to N times, windowed to fit within N
* visible-memory windows. Empty windows are never returned.
* Termination is always via CF=1.
*
****************************************************************************
*/
.section ".text16"
split_e820:
pushw %si
pushw %bp
/* Caller's %bx => %si, real %ebx to %ebx, call previous handler */
pushfw
movw %bx, %si
testl %ebx, %ebx
jnz 1f
movl %ebx, %cs:real_ebx
1: movl %cs:real_ebx, %ebx
lcall *%cs:int15_vector
pushfw
/* Edit result */
pushw %ds
pushw %cs:rm_ds
popw %ds
movw $truncate_to_start, %bp
incw %si
jns 2f
movw $truncate_to_end, %bp
2: call patch_e820
jnc 3f
xorw $0x8000, %si
3: testw %si, %si
js 4f
movl %ebx, %cs:real_ebx
testl %ebx, %ebx
jz 5f
4: movw %si, %bx
5: popw %ds
/* Restore flags returned by previous handler and return */
popfw
popw %bp
popw %si
ret
.size split_e820, . - split_e820
.section ".text16", "ax", @progbits
get_nonempty_e820:
.section ".text16.data"
real_ebx:
.long 0
.size real_ebx, . - real_ebx
/* Record entry parameters */
pushl %eax
pushl %ecx
pushl %edx
/* Get next windowed region */
call get_windowed_e820
jc 99f /* abort on error */
/* If region is non-empty, finish here */
cmpl $0, %es:8(%di)
jne 98f
cmpl $0, %es:12(%di)
jne 98f
/* Region was empty: restore entry parameters and go to next region */
popl %edx
popl %ecx
popl %eax
jmp get_nonempty_e820
98: /* Clear CF */
clc
99: /* Return values from underlying call */
addr32 leal 12(%esp), %esp /* avoid changing flags */
ret
.size get_nonempty_e820, . - get_nonempty_e820
/****************************************************************************
* Get mangled e820 region, with empty region stripping
*
* Parameters:
* As for INT 15,e820
* Returns:
* As for INT 15,e820
*
* Wraps the underlying INT 15,e820 call so that underlying regions
* are windowed to the allowed memory regions. Empty regions are
* stripped from the map. Termination is always via %ebx=0.
*
****************************************************************************
*/
.section ".text16", "ax", @progbits
get_mangled_e820:
/* Get a nonempty region */
call get_nonempty_e820
jc 99f /* Abort on error */
/* Peek ahead to see if there are any further nonempty regions */
pushal
pushw %es
movw %sp, %bp
subw %cx, %sp
movl $0xe820, %eax
movl $SMAP, %edx
pushw %ss
popw %es
movw %sp, %di
call get_nonempty_e820
movw %bp, %sp
popw %es
popal
jnc 99f /* There are further nonempty regions */
/* No futher nonempty regions: zero %ebx and clear CF */
xorl %ebx, %ebx
99: /* Return */
ret
.size get_mangled_e820, . - get_mangled_e820
/****************************************************************************
* Set/clear CF on the stack as appropriate, assumes stack is as it should
* be immediately before IRET
****************************************************************************
*/
patch_cf:
pushw %bp
movw %sp, %bp
setc 8(%bp) /* Set/reset CF; clears PF, AF, ZF, SF */
popw %bp
ret
/****************************************************************************
* INT 15,e820 handler
****************************************************************************
*/
.section ".text16"
.section ".text16", "ax", @progbits
int15_e820:
pushl %eax
pushl %ecx
pushl %edx
call split_e820
pushfw
/* If we've hit an error, exit immediately */
jc 99f
/* If region is non-empty, return this region */
pushl %eax
movl %es:8(%di), %eax
orl %es:12(%di), %eax
popl %eax
jnz 99f
/* Region is empty. If this is not the end of the map,
* skip over this region.
*/
testl %ebx, %ebx
jz 1f
popfw
popl %edx
popl %ecx
popl %eax
jmp int15_e820
1: /* Region is empty and this is the end of the map. Return
* with CF set to avoid placing an empty region at the end of
* the map.
*/
popfw
stc
pushfw
99: /* Restore flags from original INT 15,e820 call and return */
popfw
addr32 leal 12(%esp), %esp /* avoid changing flags */
lret $2
pushw %ds
pushw %cs:rm_ds
popw %ds
call get_mangled_e820
popw %ds
call patch_cf
iret
.size int15_e820, . - int15_e820
/****************************************************************************
* INT 15,e801 handler
****************************************************************************
*/
.section ".text16"
.section ".text16", "ax", @progbits
int15_e801:
/* Call previous handler */
pushfw
lcall *%cs:int15_vector
pushfw
call patch_cf
/* Edit result */
pushw %ds
pushw %cs:rm_ds
@@ -413,37 +539,33 @@ int15_e801:
xchgw %ax, %cx
xchgw %bx, %dx
popw %ds
/* Restore flags returned by previous handler and return */
popfw
lret $2
iret
.size int15_e801, . - int15_e801
/****************************************************************************
* INT 15,88 handler
****************************************************************************
*/
.section ".text16"
.section ".text16", "ax", @progbits
int15_88:
/* Call previous handler */
pushfw
lcall *%cs:int15_vector
pushfw
call patch_cf
/* Edit result */
pushw %ds
pushw %cs:rm_ds
popw %ds
call patch_1m
popw %ds
/* Restore flags returned by previous handler and return */
popfw
lret $2
iret
.size int15_88, . - int15_88
/****************************************************************************
* INT 15 handler
****************************************************************************
*/
.section ".text16"
.section ".text16", "ax", @progbits
.globl int15
int15:
/* See if we want to intercept this call */
@@ -466,7 +588,7 @@ int15:
ljmp *%cs:int15_vector
.size int15, . - int15
.section ".text16.data"
.section ".text16.data", "aw", @progbits
.globl int15_vector
int15_vector:
.long 0
+93
View File
@@ -0,0 +1,93 @@
/* Copyright (C) 2008 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.
*/
FILE_LICENCE ( GPL2_OR_LATER );
#include <realmode.h>
#include <biosint.h>
/** Assembly routine in inline asm */
extern void int15_fakee820();
/** Original INT 15 handler */
static struct segoff __text16 ( real_int15_vector );
#define real_int15_vector __use_text16 ( real_int15_vector )
/** An INT 15,e820 memory map entry */
struct e820_entry {
/** Start of region */
uint64_t start;
/** Length of region */
uint64_t len;
/** Type of region */
uint32_t type;
} __attribute__ (( packed ));
#define E820_TYPE_RAM 1 /**< Normal memory */
#define E820_TYPE_RSVD 2 /**< Reserved and unavailable */
#define E820_TYPE_ACPI 3 /**< ACPI reclaim memory */
#define E820_TYPE_NVS 4 /**< ACPI NVS memory */
/** Fake e820 map */
static struct e820_entry __text16_array ( e820map, [] ) __used = {
{ 0x00000000ULL, ( 0x000a0000ULL - 0x00000000ULL ), E820_TYPE_RAM },
{ 0x00100000ULL, ( 0xcfb50000ULL - 0x00100000ULL ), E820_TYPE_RAM },
{ 0xcfb50000ULL, ( 0xcfb64000ULL - 0xcfb50000ULL ), E820_TYPE_RSVD },
{ 0xcfb64000ULL, ( 0xcfb66000ULL - 0xcfb64000ULL ), E820_TYPE_RSVD },
{ 0xcfb66000ULL, ( 0xcfb85c00ULL - 0xcfb66000ULL ), E820_TYPE_ACPI },
{ 0xcfb85c00ULL, ( 0xd0000000ULL - 0xcfb85c00ULL ), E820_TYPE_RSVD },
{ 0xe0000000ULL, ( 0xf0000000ULL - 0xe0000000ULL ), E820_TYPE_RSVD },
{ 0xfe000000ULL, (0x100000000ULL - 0xfe000000ULL ), E820_TYPE_RSVD },
{0x100000000ULL, (0x230000000ULL -0x100000000ULL ), E820_TYPE_RAM },
};
#define e820map __use_text16 ( e820map )
void fake_e820 ( void ) {
__asm__ __volatile__ (
TEXT16_CODE ( "\nint15_fakee820:\n\t"
"pushfw\n\t"
"cmpl $0xe820, %%eax\n\t"
"jne 99f\n\t"
"cmpl $0x534d4150, %%edx\n\t"
"jne 99f\n\t"
"pushaw\n\t"
"movw %%sp, %%bp\n\t"
"andb $~0x01, 22(%%bp)\n\t" /* Clear return CF */
"leaw e820map(%%bx), %%si\n\t"
"cs rep movsb\n\t"
"popaw\n\t"
"movl %%edx, %%eax\n\t"
"addl $20, %%ebx\n\t"
"cmpl %0, %%ebx\n\t"
"jne 1f\n\t"
"xorl %%ebx,%%ebx\n\t"
"\n1:\n\t"
"popfw\n\t"
"iret\n\t"
"\n99:\n\t"
"popfw\n\t"
"ljmp *%%cs:real_int15_vector\n\t" )
: : "i" ( sizeof ( e820map ) ) );
hook_bios_interrupt ( 0x15, ( unsigned int ) int15_fakee820,
&real_int15_vector );
}
void unfake_e820 ( void ) {
unhook_bios_interrupt ( 0x15, ( unsigned int ) int15_fakee820,
&real_int15_vector );
}
+15 -10
View File
@@ -1,8 +1,10 @@
FILE_LICENCE ( GPL2_OR_LATER );
#include <stdio.h>
#include "realmode.h"
#include "timer.h"
#include "latch.h"
#include "bios.h"
#include <realmode.h>
#include <bios.h>
#include <gpxe/io.h>
#include <gpxe/timer.h>
#define K_RDWR 0x60 /* keyboard data & cmds (read/write) */
#define K_STATUS 0x64 /* keyboard status */
@@ -13,6 +15,7 @@
#define KC_CMD_WIN 0xd0 /* read output port */
#define KC_CMD_WOUT 0xd1 /* write output port */
#define KC_CMD_NULL 0xff /* null command ("pulse nothing") */
#define KB_SET_A20 0xdf /* enable A20,
enable output buffer full interrupt
enable data line
@@ -48,9 +51,9 @@ static void empty_8042 ( void ) {
time = currticks() + TICKS_PER_SEC; /* max wait of 1 second */
while ( ( inb ( K_CMD ) & ( K_IBUF_FUL | K_OBUF_FUL ) ) &&
currticks() < time ) {
SLOW_DOWN_IO;
( void ) inb ( K_RDWR );
SLOW_DOWN_IO;
iodelay();
( void ) inb_p ( K_RDWR );
iodelay();
}
}
@@ -77,7 +80,7 @@ static int gateA20_is_set ( int retries ) {
/* Avoid false negatives */
test_pattern++;
SLOW_DOWN_IO;
iodelay();
/* Always retry at least once, to avoid false negatives */
} while ( retries-- >= 0 );
@@ -131,6 +134,8 @@ void gateA20_set ( void ) {
empty_8042();
outb ( KB_SET_A20, K_RDWR );
empty_8042();
outb ( KC_CMD_NULL, K_CMD );
empty_8042();
if ( gateA20_is_set ( A20_KBC_RETRIES ) ) {
DBG ( "Enabled gate A20 using "
"keyboard controller\n" );
@@ -143,9 +148,9 @@ void gateA20_set ( void ) {
scp_a = inb ( SCP_A );
scp_a &= ~0x01; /* Avoid triggering a reset */
scp_a |= 0x02; /* Enable A20 */
SLOW_DOWN_IO;
iodelay();
outb ( scp_a, SCP_A );
SLOW_DOWN_IO;
iodelay();
if ( gateA20_is_set ( A20_SCPA_RETRIES ) ) {
DBG ( "Enabled gate A20 using "
"Fast Gate A20\n" );
+101 -37
View File
@@ -15,17 +15,25 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
FILE_LICENCE ( GPL2_OR_LATER );
#include <assert.h>
#include <realmode.h>
#include <biosint.h>
#include <basemem.h>
#include <fakee820.h>
#include <gpxe/init.h>
#include <gpxe/memmap.h>
#include <gpxe/hidemem.h>
/** Set to true if you want to test a fake E820 map */
#define FAKE_E820 0
/** Alignment for hidden memory regions */
#define ALIGN_HIDDEN 4096 /* 4kB page alignment should be enough */
/**
* A hidden region of Etherboot
* A hidden region of gPXE
*
* This represents a region that will be edited out of the system's
* memory map.
@@ -34,24 +42,23 @@
* changed.
*/
struct hidden_region {
/* Physical start address */
physaddr_t start;
/* Physical end address */
physaddr_t end;
/** Physical start address */
uint64_t start;
/** Physical end address */
uint64_t end;
};
/**
* List of hidden regions
*
* Must be terminated by a zero entry.
*/
struct hidden_region __data16_array ( hidden_regions, [] ) = {
[TEXT] = { 0, 0 },
[BASEMEM] = { ( 640 * 1024 ), ( 640 * 1024 ) },
[EXTMEM] = { 0, 0 },
{ 0, 0, } /* Terminator */
};
#define hidden_regions __use_data16 ( hidden_regions )
/** Hidden base memory */
extern struct hidden_region __data16 ( hidemem_base );
#define hidemem_base __use_data16 ( hidemem_base )
/** Hidden umalloc memory */
extern struct hidden_region __data16 ( hidemem_umalloc );
#define hidemem_umalloc __use_data16 ( hidemem_umalloc )
/** Hidden text memory */
extern struct hidden_region __data16 ( hidemem_textdata );
#define hidemem_textdata __use_data16 ( hidemem_textdata )
/** Assembly routine in e820mangler.S */
extern void int15();
@@ -60,14 +67,23 @@ extern void int15();
extern struct segoff __text16 ( int15_vector );
#define int15_vector __use_text16 ( int15_vector )
/* The linker defines these symbols for us */
extern char _textdata[];
extern char _etextdata[];
extern char _text16_memsz[];
#define _text16_memsz ( ( unsigned int ) _text16_memsz )
extern char _data16_memsz[];
#define _data16_memsz ( ( unsigned int ) _data16_memsz )
/**
* Hide region of memory from system memory map
*
* @v region Hidden memory region
* @v start Start of region
* @v end End of region
*/
void hide_region ( unsigned int region_id, physaddr_t start, physaddr_t end ) {
struct hidden_region *region = &hidden_regions[region_id];
static void hide_region ( struct hidden_region *region,
physaddr_t start, physaddr_t end ) {
/* Some operating systems get a nasty shock if a region of the
* E820 map seems to start on a non-page boundary. Make life
@@ -76,21 +92,7 @@ void hide_region ( unsigned int region_id, physaddr_t start, physaddr_t end ) {
region->start = ( start & ~( ALIGN_HIDDEN - 1 ) );
region->end = ( ( end + ALIGN_HIDDEN - 1 ) & ~( ALIGN_HIDDEN - 1 ) );
DBG ( "Hiding region %d [%lx,%lx)\n",
region_id, region->start, region->end );
}
/**
* Hide Etherboot text
*
*/
static void hide_text ( void ) {
/* The linker defines these symbols for us */
extern char _text[];
extern char _end[];
hide_region ( TEXT, virt_to_phys ( _text ), virt_to_phys ( _end ) );
DBG ( "Hiding region [%llx,%llx)\n", region->start, region->end );
}
/**
@@ -102,7 +104,25 @@ void hide_basemem ( void ) {
* hide_region(), because we don't want this rounded to the
* nearest page boundary.
*/
hidden_regions[BASEMEM].start = ( get_fbms() * 1024 );
hidemem_base.start = ( get_fbms() * 1024 );
}
/**
* Hide umalloc() region
*
*/
void hide_umalloc ( physaddr_t start, physaddr_t end ) {
assert ( end <= virt_to_phys ( _textdata ) );
hide_region ( &hidemem_umalloc, start, end );
}
/**
* Hide .text and .data
*
*/
void hide_textdata ( void ) {
hide_region ( &hidemem_textdata, virt_to_phys ( _textdata ),
virt_to_phys ( _etextdata ) );
}
/**
@@ -112,14 +132,54 @@ void hide_basemem ( void ) {
* returned by the BIOS.
*/
static void hide_etherboot ( void ) {
struct memory_map memmap;
unsigned int rm_ds_top;
unsigned int rm_cs_top;
unsigned int fbms;
/* Dump memory map before mangling */
DBG ( "Hiding gPXE from system memory map\n" );
get_memmap ( &memmap );
/* Hook in fake E820 map, if we're testing one */
if ( FAKE_E820 ) {
DBG ( "Hooking in fake E820 map\n" );
fake_e820();
get_memmap ( &memmap );
}
/* Initialise the hidden regions */
hide_text();
hide_basemem();
hide_umalloc ( virt_to_phys ( _textdata ), virt_to_phys ( _textdata ) );
hide_textdata();
/* Some really moronic BIOSes bring up the PXE stack via the
* UNDI loader entry point and then don't bother to unload it
* before overwriting the code and data segments. If this
* happens, we really don't want to leave INT 15 hooked,
* because that will cause any loaded OS to die horribly as
* soon as it attempts to fetch the system memory map.
*
* We use a heuristic to guess whether or not we are being
* loaded sensibly.
*/
rm_cs_top = ( ( ( rm_cs << 4 ) + _text16_memsz + 1024 - 1 ) >> 10 );
rm_ds_top = ( ( ( rm_ds << 4 ) + _data16_memsz + 1024 - 1 ) >> 10 );
fbms = get_fbms();
if ( ( rm_cs_top < fbms ) && ( rm_ds_top < fbms ) ) {
DBG ( "Detected potentially unsafe UNDI load at CS=%04x "
"DS=%04x FBMS=%dkB\n", rm_cs, rm_ds, fbms );
DBG ( "Disabling INT 15 memory hiding\n" );
return;
}
/* Hook INT 15 */
hook_bios_interrupt ( 0x15, ( unsigned int ) int15,
&int15_vector );
/* Dump memory map after mangling */
DBG ( "Hidden gPXE from system memory map\n" );
get_memmap ( &memmap );
}
/**
@@ -128,7 +188,7 @@ static void hide_etherboot ( void ) {
* Uninstalls the INT 15 handler installed by hide_etherboot(), if
* possible.
*/
static void unhide_etherboot ( void ) {
static void unhide_etherboot ( int flags __unused ) {
/* If we have more than one hooked interrupt at this point, it
* means that some other vector is still hooked, in which case
@@ -147,6 +207,10 @@ static void unhide_etherboot ( void ) {
*/
unhook_bios_interrupt ( 0x15, ( unsigned int ) int15,
&int15_vector );
/* Unhook fake E820 map, if used */
if ( FAKE_E820 )
unfake_e820();
}
/** Hide Etherboot startup function */
+104 -13
View File
@@ -16,6 +16,8 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
FILE_LICENCE ( GPL2_OR_LATER );
#include <stdint.h>
#include <errno.h>
#include <realmode.h>
@@ -41,6 +43,8 @@ struct e820_entry {
uint64_t len;
/** Type of region */
uint32_t type;
/** Extended attributes (optional) */
uint32_t attrs;
} __attribute__ (( packed ));
#define E820_TYPE_RAM 1 /**< Normal memory */
@@ -48,6 +52,12 @@ struct e820_entry {
#define E820_TYPE_ACPI 3 /**< ACPI reclaim memory */
#define E820_TYPE_NVS 4 /**< ACPI NVS memory */
#define E820_ATTR_ENABLED 0x00000001UL
#define E820_ATTR_NONVOLATILE 0x00000002UL
#define E820_ATTR_UNKNOWN 0xfffffffcUL
#define E820_MIN_SIZE 20
/** Buffer for INT 15,e820 calls */
static struct e820_entry __bss16 ( e820buf );
#define e820buf __use_data16 ( e820buf )
@@ -86,8 +96,20 @@ static unsigned int extmemsize_e801 ( void ) {
}
extmem = ( extmem_1m_to_16m_k + ( extmem_16m_plus_64k * 64 ) );
DBG ( "INT 15,e801 extended memory size %d+64*%d=%d kB\n",
extmem_1m_to_16m_k, extmem_16m_plus_64k, extmem );
DBG ( "INT 15,e801 extended memory size %d+64*%d=%d kB "
"[100000,%llx)\n", extmem_1m_to_16m_k, extmem_16m_plus_64k,
extmem, ( 0x100000 + ( ( ( uint64_t ) extmem ) * 1024 ) ) );
/* Sanity check. Some BIOSes report the entire 4GB address
* space as available, which cannot be correct (since that
* would leave no address space available for 32-bit PCI
* BARs).
*/
if ( extmem == ( 0x400000 - 0x400 ) ) {
DBG ( "INT 15,e801 reported whole 4GB; assuming insane\n" );
return 0;
}
return extmem;
}
@@ -103,7 +125,8 @@ static unsigned int extmemsize_88 ( void ) {
__asm__ __volatile__ ( REAL_CODE ( "int $0x15" )
: "=a" ( extmem ) : "a" ( 0x8800 ) );
DBG ( "INT 15,88 extended memory size %d kB\n", extmem );
DBG ( "INT 15,88 extended memory size %d kB [100000, %x)\n",
extmem, ( 0x100000 + ( extmem * 1024 ) ) );
return extmem;
}
@@ -135,39 +158,84 @@ static int meme820 ( struct memory_map *memmap ) {
struct memory_region *region = memmap->regions;
uint32_t next = 0;
uint32_t smap;
size_t size;
unsigned int flags;
unsigned int discard_c, discard_d, discard_D;
unsigned int discard_D;
/* Clear the E820 buffer. Do this once before starting,
* rather than on each call; some BIOSes rely on the contents
* being preserved between calls.
*/
memset ( &e820buf, 0, sizeof ( e820buf ) );
do {
__asm__ __volatile__ ( REAL_CODE ( "stc\n\t"
/* Some BIOSes corrupt %esi for fun. Guard against
* this by telling gcc that all non-output registers
* may be corrupted.
*/
__asm__ __volatile__ ( REAL_CODE ( "pushl %%ebp\n\t"
"stc\n\t"
"int $0x15\n\t"
"pushfw\n\t"
"popw %w0\n\t" )
: "=r" ( flags ), "=a" ( smap ),
"=b" ( next ), "=D" ( discard_D ),
"=c" ( discard_c ), "=d" ( discard_d )
"popw %%dx\n\t"
"popl %%ebp\n\t" )
: "=a" ( smap ), "=b" ( next ),
"=c" ( size ), "=d" ( flags ),
"=D" ( discard_D )
: "a" ( 0xe820 ), "b" ( next ),
"D" ( &__from_data16 ( e820buf ) ),
"D" ( __from_data16 ( &e820buf ) ),
"c" ( sizeof ( e820buf ) ),
"d" ( SMAP )
: "memory" );
: "esi", "memory" );
if ( smap != SMAP ) {
DBG ( "INT 15,e820 failed SMAP signature check\n" );
return -ENOTSUP;
}
if ( size < E820_MIN_SIZE ) {
DBG ( "INT 15,e820 returned only %zd bytes\n", size );
return -EINVAL;
}
if ( flags & CF ) {
DBG ( "INT 15,e820 terminated on CF set\n" );
break;
}
DBG ( "INT 15,e820 region [%llx,%llx) type %d\n",
/* 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 );
if ( size > offsetof ( typeof ( e820buf ), attrs ) ) {
DBG ( " (%s", ( ( e820buf.attrs & E820_ATTR_ENABLED )
? "enabled" : "disabled" ) );
if ( e820buf.attrs & E820_ATTR_NONVOLATILE )
DBG ( ", non-volatile" );
if ( e820buf.attrs & E820_ATTR_UNKNOWN )
DBG ( ", other [%08x]", e820buf.attrs );
DBG ( ")" );
}
DBG ( "\n" );
/* Discard non-RAM regions */
if ( e820buf.type != E820_TYPE_RAM )
continue;
/* Check extended attributes, if present */
if ( size > offsetof ( typeof ( e820buf ), attrs ) ) {
if ( ! ( e820buf.attrs & E820_ATTR_ENABLED ) )
continue;
if ( e820buf.attrs & E820_ATTR_NONVOLATILE )
continue;
}
region->start = e820buf.start;
region->end = e820buf.start + e820buf.len;
region++;
@@ -184,6 +252,28 @@ static int meme820 ( struct memory_map *memmap ) {
}
} while ( next != 0 );
/* Sanity checks. Some BIOSes report complete garbage via INT
* 15,e820 (especially at POST time), despite passing the
* signature checks. We currently check for a base memory
* region (starting at 0) and at least one high memory region
* (starting at 0x100000).
*/
if ( memmap->count < 2 ) {
DBG ( "INT 15,e820 returned only %d regions; assuming "
"insane\n", memmap->count );
return -EINVAL;
}
if ( memmap->regions[0].start != 0 ) {
DBG ( "INT 15,e820 region 0 starts at %llx (expected 0); "
"assuming insane\n", memmap->regions[0].start );
return -EINVAL;
}
if ( memmap->regions[1].start != 0x100000 ) {
DBG ( "INT 15,e820 region 1 starts at %llx (expected 100000); "
"assuming insane\n", memmap->regions[0].start );
return -EINVAL;
}
return 0;
}
@@ -203,7 +293,8 @@ void get_memmap ( struct memory_map *memmap ) {
/* Get base and extended memory sizes */
basemem = basememsize();
DBG ( "FBMS base memory size %d kB\n", basemem );
DBG ( "FBMS base memory size %d kB [0,%x)\n",
basemem, ( basemem * 1024 ) );
extmem = extmemsize();
/* Try INT 15,e820 first */
+2
View File
@@ -16,6 +16,8 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
FILE_LICENCE ( GPL2_OR_LATER );
#include <stdint.h>
#include <string.h>
#include <errno.h>
-323
View File
@@ -1,323 +0,0 @@
/*
* 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 <stdio.h>
#include <errno.h>
#include <gpxe/uaccess.h>
#include <gpxe/uuid.h>
#include <realmode.h>
#include <pnpbios.h>
#include <smbios.h>
/** @file
*
* System Management BIOS
*
*/
/** Signature for SMBIOS entry point */
#define SMBIOS_SIGNATURE \
( ( '_' << 0 ) + ( 'S' << 8 ) + ( 'M' << 16 ) + ( '_' << 24 ) )
/**
* SMBIOS entry point
*
* This is the single table which describes the list of SMBIOS
* structures. It is located by scanning through the BIOS segment.
*/
struct smbios_entry {
/** Signature
*
* Must be equal to SMBIOS_SIGNATURE
*/
uint32_t signature;
/** Checksum */
uint8_t checksum;
/** Length */
uint8_t length;
/** Major version */
uint8_t major;
/** Minor version */
uint8_t minor;
/** Maximum structure size */
uint16_t max;
/** Entry point revision */
uint8_t revision;
/** Formatted area */
uint8_t formatted[5];
/** DMI Signature */
uint8_t dmi_signature[5];
/** DMI checksum */
uint8_t dmi_checksum;
/** Structure table length */
uint16_t smbios_length;
/** Structure table address */
physaddr_t smbios_address;
/** Number of SMBIOS structures */
uint16_t smbios_count;
/** BCD revision */
uint8_t bcd_revision;
} __attribute__ (( packed ));
/**
* SMBIOS entry point descriptor
*
* This contains the information from the SMBIOS entry point that we
* care about.
*/
struct smbios {
/** Start of SMBIOS structures */
userptr_t address;
/** Length of SMBIOS structures */
size_t length;
/** Number of SMBIOS structures */
unsigned int count;
};
/**
* SMBIOS strings descriptor
*
* This is returned as part of the search for an SMBIOS structure, and
* contains the information needed for extracting the strings within
* the "unformatted" portion of the structure.
*/
struct smbios_strings {
/** Start of strings data */
userptr_t data;
/** Length of strings data */
size_t length;
};
/**
* Find SMBIOS
*
* @ret smbios SMBIOS entry point descriptor, or NULL if not found
*/
static struct smbios * find_smbios ( void ) {
static struct smbios smbios = {
.address = UNULL,
};
union {
struct smbios_entry entry;
uint8_t bytes[256]; /* 256 is maximum length possible */
} u;
unsigned int offset;
size_t len;
unsigned int i;
uint8_t sum;
/* Return cached result if available */
if ( smbios.address != UNULL )
return &smbios;
/* Try to find SMBIOS */
for ( offset = 0 ; 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.length;
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 entry point at %04x:%04x\n",
BIOS_SEG, offset );
smbios.address = phys_to_user ( u.entry.smbios_address );
smbios.length = u.entry.smbios_length;
smbios.count = u.entry.smbios_count;
return &smbios;
}
DBG ( "No SMBIOS found\n" );
return NULL;
}
/**
* Find SMBIOS strings terminator
*
* @v smbios SMBIOS entry point descriptor
* @v offset Offset to start of strings
* @ret offset Offset to strings terminator, or 0 if not found
*/
static size_t find_strings_terminator ( struct smbios *smbios,
size_t offset ) {
size_t max_offset = ( smbios->length - 2 );
uint16_t nulnul;
for ( ; offset <= max_offset ; offset++ ) {
copy_from_user ( &nulnul, smbios->address, offset, 2 );
if ( nulnul == 0 )
return ( offset + 1 );
}
return 0;
}
/**
* Find specific structure type within SMBIOS
*
* @v type Structure type to search for
* @v structure Buffer to fill in with structure
* @v length Length of buffer
* @v strings Strings descriptor to fill in, or NULL
* @ret rc Return status code
*/
int find_smbios_structure ( unsigned int type, void *structure,
size_t length, struct smbios_strings *strings ) {
struct smbios *smbios;
struct smbios_header header;
struct smbios_strings temp_strings;
unsigned int count = 0;
size_t offset = 0;
size_t strings_offset;
size_t terminator_offset;
/* Locate SMBIOS entry point */
if ( ! ( smbios = find_smbios() ) )
return -ENOENT;
/* Ensure that we have a usable strings descriptor buffer */
if ( ! strings )
strings = &temp_strings;
/* Scan through list of structures */
while ( ( ( offset + sizeof ( header ) ) < smbios->length ) &&
( count < smbios->count ) ) {
/* Read next SMBIOS structure header */
copy_from_user ( &header, smbios->address, offset,
sizeof ( header ) );
/* Determine start and extent of strings block */
strings_offset = ( offset + header.length );
if ( strings_offset > smbios->length ) {
DBG ( "SMBIOS structure at offset %zx with length "
"%x extends beyond SMBIOS\n", offset,
header.length );
return -ENOENT;
}
terminator_offset =
find_strings_terminator ( smbios, strings_offset );
if ( ! terminator_offset ) {
DBG ( "SMBIOS structure at offset %zx has "
"unterminated strings section\n", offset );
return -ENOENT;
}
strings->data = userptr_add ( smbios->address,
strings_offset );
strings->length = ( terminator_offset - strings_offset );
DBG ( "SMBIOS structure at offset %zx has type %d, "
"length %x, strings length %zx\n",
offset, header.type, header.length, strings->length );
/* If this is the structure we want, return */
if ( header.type == type ) {
if ( length > header.length )
length = header.length;
copy_from_user ( structure, smbios->address,
offset, length );
return 0;
}
/* Move to next SMBIOS structure */
offset = ( terminator_offset + 1 );
count++;
}
DBG ( "SMBIOS structure type %d not found\n", type );
return -ENOENT;
}
/**
* Find indexed string within SMBIOS structure
*
* @v strings SMBIOS strings descriptor
* @v index String index
* @v buffer Buffer for string
* @v length Length of string buffer
* @ret rc Return status code
*/
int find_smbios_string ( struct smbios_strings *strings, unsigned int index,
char *buffer, size_t length ) {
size_t offset = 0;
size_t string_len;
/* Zero buffer. This ensures that a valid NUL terminator is
* always present (unless length==0).
*/
memset ( buffer, 0, length );
/* String numbers start at 1 (0 is used to indicate "no string") */
if ( ! index )
return 0;
while ( offset < strings->length ) {
/* Get string length. This is known safe, since the
* smbios_strings struct is constructed so as to
* always end on a string boundary.
*/
string_len = strlen_user ( strings->data, offset );
if ( --index == 0 ) {
/* Copy string, truncating as necessary. */
if ( string_len >= length )
string_len = ( length - 1 );
copy_from_user ( buffer, strings->data,
offset, string_len );
return 0;
}
offset += ( string_len + 1 );
}
DBG ( "SMBIOS string index %d not found\n", index );
return -ENOENT;
}
/**
* Get UUID from SMBIOS
*
* @v uuid UUID to fill in
* @ret rc Return status code
*/
int smbios_get_uuid ( union uuid *uuid ) {
struct smbios_system_information sysinfo;
int rc;
if ( ( rc = find_smbios_structure ( SMBIOS_TYPE_SYSTEM_INFORMATION,
&sysinfo, sizeof ( sysinfo ),
NULL ) ) != 0 )
return rc;
memcpy ( uuid, sysinfo.uuid, sizeof ( *uuid ) );
DBG ( "SMBIOS found UUID %s\n", uuid_ntoa ( uuid ) );
return 0;
}
+33
View File
@@ -0,0 +1,33 @@
#include <gpxe/netdevice.h>
#include <gpxe/command.h>
#include <hci/ifmgmt_cmd.h>
#include <pxe_call.h>
FILE_LICENCE ( GPL2_OR_LATER );
static int startpxe_payload ( struct net_device *netdev ) {
if ( netdev->state & NETDEV_OPEN )
pxe_activate ( netdev );
return 0;
}
static int startpxe_exec ( int argc, char **argv ) {
return ifcommon_exec ( argc, argv, startpxe_payload,
"Activate PXE on" );
}
static int stoppxe_exec ( int argc __unused, char **argv __unused ) {
pxe_deactivate();
return 0;
}
struct command pxe_commands[] __command = {
{
.name = "startpxe",
.exec = startpxe_exec,
},
{
.name = "stoppxe",
.exec = stoppxe_exec,
},
};
+2
View File
@@ -16,6 +16,8 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
FILE_LICENCE ( GPL2_OR_LATER );
/**
* @file
*
+238 -244
View File
@@ -16,6 +16,8 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
FILE_LICENCE ( GPL2_OR_LATER );
/**
* @file
*
@@ -34,7 +36,6 @@
#include <gpxe/image.h>
#include <gpxe/segment.h>
#include <gpxe/init.h>
#include <gpxe/initrd.h>
#include <gpxe/cpio.h>
#include <gpxe/features.h>
@@ -43,9 +44,11 @@ FEATURE ( FEATURE_IMAGE, "bzImage", DHCP_EB_FEATURE_BZIMAGE, 1 );
struct image_type bzimage_image_type __image_type ( PROBE_NORMAL );
/**
* bzImage load context
* bzImage context
*/
struct bzimage_load_context {
struct bzimage_context {
/** Boot protocol version */
unsigned int version;
/** Real-mode kernel portion load segment address */
unsigned int rm_kernel_seg;
/** Real-mode kernel portion load address */
@@ -56,26 +59,14 @@ struct bzimage_load_context {
size_t rm_heap;
/** Command line (offset from rm_kernel) */
size_t rm_cmdline;
/** Command line maximum length */
size_t cmdline_size;
/** Real-mode kernel portion total memory size */
size_t rm_memsz;
/** Non-real-mode kernel portion load address */
userptr_t pm_kernel;
/** Non-real-mode kernel portion file and memory size */
size_t pm_sz;
};
/**
* bzImage execution context
*/
struct bzimage_exec_context {
/** Real-mode kernel portion load segment address */
unsigned int rm_kernel_seg;
/** Real-mode kernel portion load address */
userptr_t rm_kernel;
/** Real-mode heap top (offset from rm_kernel) */
size_t rm_heap;
/** Command line (offset from rm_kernel) */
size_t rm_cmdline;
/** Video mode */
unsigned int vid_mode;
/** Memory limit */
@@ -84,18 +75,178 @@ struct bzimage_exec_context {
physaddr_t ramdisk_image;
/** Initrd size */
physaddr_t ramdisk_size;
/** Command line magic block */
struct bzimage_cmdline cmdline_magic;
/** bzImage header */
struct bzimage_header bzhdr;
};
/**
* Parse bzImage header
*
* @v image bzImage file
* @v bzimg bzImage context
* @v src bzImage to parse
* @ret rc Return status code
*/
static int bzimage_parse_header ( struct image *image,
struct bzimage_context *bzimg,
userptr_t src ) {
unsigned int syssize;
int is_bzimage;
/* Sanity check */
if ( image->len < ( BZI_HDR_OFFSET + sizeof ( bzimg->bzhdr ) ) ) {
DBGC ( image, "bzImage %p too short for kernel header\n",
image );
return -ENOEXEC;
}
/* Read in header structures */
memset ( bzimg, 0, sizeof ( *bzimg ) );
copy_from_user ( &bzimg->cmdline_magic, src, BZI_CMDLINE_OFFSET,
sizeof ( bzimg->cmdline_magic ) );
copy_from_user ( &bzimg->bzhdr, src, BZI_HDR_OFFSET,
sizeof ( bzimg->bzhdr ) );
/* Calculate size of real-mode portion */
bzimg->rm_filesz =
( ( bzimg->bzhdr.setup_sects ? bzimg->bzhdr.setup_sects : 4 ) + 1 ) << 9;
if ( bzimg->rm_filesz > image->len ) {
DBGC ( image, "bzImage %p too short for %zd byte of setup\n",
image, bzimg->rm_filesz );
return -ENOEXEC;
}
bzimg->rm_memsz = BZI_ASSUMED_RM_SIZE;
/* Calculate size of protected-mode portion */
bzimg->pm_sz = ( image->len - bzimg->rm_filesz );
syssize = ( ( bzimg->pm_sz + 15 ) / 16 );
/* Check for signatures and determine version */
if ( bzimg->bzhdr.boot_flag != BZI_BOOT_FLAG ) {
DBGC ( image, "bzImage %p missing 55AA signature\n", image );
return -ENOEXEC;
}
if ( bzimg->bzhdr.header == BZI_SIGNATURE ) {
/* 2.00+ */
bzimg->version = bzimg->bzhdr.version;
} else {
/* Pre-2.00. Check that the syssize field is correct,
* as a guard against accepting arbitrary binary data,
* since the 55AA check is pretty lax. Note that the
* syssize field is unreliable for protocols between
* 2.00 and 2.03 inclusive, so we should not always
* check this field.
*/
bzimg->version = 0x0100;
if ( bzimg->bzhdr.syssize != syssize ) {
DBGC ( image, "bzImage %p bad syssize %x (expected "
"%x)\n", image, bzimg->bzhdr.syssize, syssize );
return -ENOEXEC;
}
}
/* Determine image type */
is_bzimage = ( ( bzimg->version >= 0x0200 ) ?
( bzimg->bzhdr.loadflags & BZI_LOAD_HIGH ) : 0 );
/* Calculate load address of real-mode portion */
bzimg->rm_kernel_seg = ( is_bzimage ? 0x1000 : 0x9000 );
bzimg->rm_kernel = real_to_user ( bzimg->rm_kernel_seg, 0 );
/* Allow space for the stack and heap */
bzimg->rm_memsz += BZI_STACK_SIZE;
bzimg->rm_heap = bzimg->rm_memsz;
/* Allow space for the command line */
bzimg->rm_cmdline = bzimg->rm_memsz;
bzimg->rm_memsz += BZI_CMDLINE_SIZE;
/* Calculate load address of protected-mode portion */
bzimg->pm_kernel = phys_to_user ( is_bzimage ? BZI_LOAD_HIGH_ADDR
: BZI_LOAD_LOW_ADDR );
/* Extract video mode */
bzimg->vid_mode = bzimg->bzhdr.vid_mode;
/* Extract memory limit */
bzimg->mem_limit = ( ( bzimg->version >= 0x0203 ) ?
bzimg->bzhdr.initrd_addr_max : BZI_INITRD_MAX );
/* Extract command line size */
bzimg->cmdline_size = ( ( bzimg->version >= 0x0206 ) ?
bzimg->bzhdr.cmdline_size : BZI_CMDLINE_SIZE );
DBGC ( image, "bzImage %p version %04x RM %#lx+%#zx PM %#lx+%#zx "
"cmdlen %zd\n", image, bzimg->version,
user_to_phys ( bzimg->rm_kernel, 0 ), bzimg->rm_filesz,
user_to_phys ( bzimg->pm_kernel, 0 ), bzimg->pm_sz,
bzimg->cmdline_size );
return 0;
}
/**
* Update bzImage header in loaded kernel
*
* @v image bzImage file
* @v bzimg bzImage context
* @v dst bzImage to update
*/
static void bzimage_update_header ( struct image *image,
struct bzimage_context *bzimg,
userptr_t dst ) {
/* Set loader type */
if ( bzimg->version >= 0x0200 )
bzimg->bzhdr.type_of_loader = BZI_LOADER_TYPE_GPXE;
/* Set heap end pointer */
if ( bzimg->version >= 0x0201 ) {
bzimg->bzhdr.heap_end_ptr = ( bzimg->rm_heap - 0x200 );
bzimg->bzhdr.loadflags |= BZI_CAN_USE_HEAP;
}
/* Set command line */
if ( bzimg->version >= 0x0202 ) {
bzimg->bzhdr.cmd_line_ptr = user_to_phys ( bzimg->rm_kernel,
bzimg->rm_cmdline );
} else {
bzimg->cmdline_magic.magic = BZI_CMDLINE_MAGIC;
bzimg->cmdline_magic.offset = bzimg->rm_cmdline;
bzimg->bzhdr.setup_move_size = bzimg->rm_memsz;
}
/* Set video mode */
bzimg->bzhdr.vid_mode = bzimg->vid_mode;
/* Set initrd address */
if ( bzimg->version >= 0x0200 ) {
bzimg->bzhdr.ramdisk_image = bzimg->ramdisk_image;
bzimg->bzhdr.ramdisk_size = bzimg->ramdisk_size;
}
/* Write out header structures */
copy_to_user ( dst, BZI_CMDLINE_OFFSET, &bzimg->cmdline_magic,
sizeof ( bzimg->cmdline_magic ) );
copy_to_user ( dst, BZI_HDR_OFFSET, &bzimg->bzhdr,
sizeof ( bzimg->bzhdr ) );
DBGC ( image, "bzImage %p vidmode %d\n", image, bzimg->vid_mode );
}
/**
* Parse kernel command line for bootloader parameters
*
* @v image bzImage file
* @v exec_ctx Execution context
* @v bzimg bzImage context
* @v cmdline Kernel command line
* @ret rc Return status code
*/
static int bzimage_parse_cmdline ( struct image *image,
struct bzimage_exec_context *exec_ctx,
struct bzimage_context *bzimg,
const char *cmdline ) {
char *vga;
char *mem;
@@ -104,13 +255,13 @@ static int bzimage_parse_cmdline ( struct image *image,
if ( ( vga = strstr ( cmdline, "vga=" ) ) ) {
vga += 4;
if ( strcmp ( vga, "normal" ) == 0 ) {
exec_ctx->vid_mode = BZI_VID_MODE_NORMAL;
bzimg->vid_mode = BZI_VID_MODE_NORMAL;
} else if ( strcmp ( vga, "ext" ) == 0 ) {
exec_ctx->vid_mode = BZI_VID_MODE_EXT;
bzimg->vid_mode = BZI_VID_MODE_EXT;
} else if ( strcmp ( vga, "ask" ) == 0 ) {
exec_ctx->vid_mode = BZI_VID_MODE_ASK;
bzimg->vid_mode = BZI_VID_MODE_ASK;
} else {
exec_ctx->vid_mode = strtoul ( vga, &vga, 0 );
bzimg->vid_mode = strtoul ( vga, &vga, 0 );
if ( *vga && ( *vga != ' ' ) ) {
DBGC ( image, "bzImage %p strange \"vga=\""
"terminator '%c'\n", image, *vga );
@@ -121,17 +272,17 @@ static int bzimage_parse_cmdline ( struct image *image,
/* Look for "mem=" */
if ( ( mem = strstr ( cmdline, "mem=" ) ) ) {
mem += 4;
exec_ctx->mem_limit = strtoul ( mem, &mem, 0 );
bzimg->mem_limit = strtoul ( mem, &mem, 0 );
switch ( *mem ) {
case 'G':
case 'g':
exec_ctx->mem_limit <<= 10;
bzimg->mem_limit <<= 10;
case 'M':
case 'm':
exec_ctx->mem_limit <<= 10;
bzimg->mem_limit <<= 10;
case 'K':
case 'k':
exec_ctx->mem_limit <<= 10;
bzimg->mem_limit <<= 10;
break;
case '\0':
case ' ':
@@ -141,7 +292,7 @@ static int bzimage_parse_cmdline ( struct image *image,
"terminator '%c'\n", image, *mem );
break;
}
exec_ctx->mem_limit -= 1;
bzimg->mem_limit -= 1;
}
return 0;
@@ -151,20 +302,20 @@ static int bzimage_parse_cmdline ( struct image *image,
* Set command line
*
* @v image bzImage image
* @v exec_ctx Execution context
* @v bzimg bzImage context
* @v cmdline Kernel command line
* @ret rc Return status code
*/
static int bzimage_set_cmdline ( struct image *image,
struct bzimage_exec_context *exec_ctx,
struct bzimage_context *bzimg,
const char *cmdline ) {
size_t cmdline_len;
/* Copy command line down to real-mode portion */
cmdline_len = ( strlen ( cmdline ) + 1 );
if ( cmdline_len > BZI_CMDLINE_SIZE )
cmdline_len = BZI_CMDLINE_SIZE;
copy_to_user ( exec_ctx->rm_kernel, exec_ctx->rm_cmdline,
if ( cmdline_len > bzimg->cmdline_size )
cmdline_len = bzimg->cmdline_size;
copy_to_user ( bzimg->rm_kernel, bzimg->rm_cmdline,
cmdline, cmdline_len );
DBGC ( image, "bzImage %p command line \"%s\"\n", image, cmdline );
@@ -186,8 +337,8 @@ static size_t bzimage_load_initrd ( struct image *image,
struct cpio_header cpio;
size_t offset = 0;
/* Ignore images which aren't initrds */
if ( initrd->type != &initrd_image_type )
/* Do not include kernel image itself as an initrd */
if ( initrd == image )
return 0;
/* Create cpio header before non-prebuilt images */
@@ -216,14 +367,16 @@ static size_t bzimage_load_initrd ( struct image *image,
}
/* Copy in initrd image body */
if ( address )
memcpy_user ( address, offset, initrd->data, 0, initrd->len );
offset += initrd->len;
if ( address ) {
DBGC ( image, "bzImage %p has initrd %p at [%lx,%lx)\n",
image, initrd, address, ( address + offset ) );
memcpy_user ( address, offset, initrd->data, 0,
initrd->len );
image, initrd, user_to_phys ( address, 0 ),
user_to_phys ( address, offset ) );
}
offset += initrd->len;
/* Round up to 4-byte boundary */
offset = ( ( offset + 0x03 ) & ~0x03 );
return offset;
}
@@ -232,20 +385,19 @@ static size_t bzimage_load_initrd ( struct image *image,
* Load initrds, if any
*
* @v image bzImage image
* @v exec_ctx Execution context
* @v bzimg bzImage context
* @ret rc Return status code
*/
static int bzimage_load_initrds ( struct image *image,
struct bzimage_exec_context *exec_ctx ) {
struct bzimage_context *bzimg ) {
struct image *initrd;
size_t total_len = 0;
physaddr_t address;
int rc;
/* Add up length of all initrd images */
for_each_image ( initrd ) {
for_each_image ( initrd )
total_len += bzimage_load_initrd ( image, initrd, UNULL );
}
/* Give up if no initrd images found */
if ( ! total_len )
@@ -267,7 +419,7 @@ static int bzimage_load_initrds ( struct image *image,
return -ENOBUFS;
}
/* Check that we are within the kernel's range */
if ( ( address + total_len - 1 ) > exec_ctx->mem_limit )
if ( ( address + total_len - 1 ) > bzimg->mem_limit )
continue;
/* Prepare and verify segment */
if ( ( rc = prep_segment ( phys_to_user ( address ), 0,
@@ -278,8 +430,8 @@ static int bzimage_load_initrds ( struct image *image,
}
/* Record initrd location */
exec_ctx->ramdisk_image = address;
exec_ctx->ramdisk_size = total_len;
bzimg->ramdisk_image = address;
bzimg->ramdisk_size = total_len;
/* Construct initrd */
DBGC ( image, "bzImage %p constructing initrd at [%lx,%lx)\n",
@@ -299,54 +451,37 @@ static int bzimage_load_initrds ( struct image *image,
* @ret rc Return status code
*/
static int bzimage_exec ( struct image *image ) {
struct bzimage_exec_context exec_ctx;
struct bzimage_header bzhdr;
struct bzimage_context bzimg;
const char *cmdline = ( image->cmdline ? image->cmdline : "" );
int rc;
/* Initialise context */
memset ( &exec_ctx, 0, sizeof ( exec_ctx ) );
/* Retrieve kernel header */
exec_ctx.rm_kernel_seg = image->priv.ul;
exec_ctx.rm_kernel = real_to_user ( exec_ctx.rm_kernel_seg, 0 );
copy_from_user ( &bzhdr, exec_ctx.rm_kernel, BZI_HDR_OFFSET,
sizeof ( bzhdr ) );
exec_ctx.rm_cmdline = exec_ctx.rm_heap =
( bzhdr.heap_end_ptr + 0x200 );
exec_ctx.vid_mode = bzhdr.vid_mode;
if ( bzhdr.version >= 0x0203 ) {
exec_ctx.mem_limit = bzhdr.initrd_addr_max;
} else {
exec_ctx.mem_limit = BZI_INITRD_MAX;
}
/* Read and parse header from loaded kernel */
if ( ( rc = bzimage_parse_header ( image, &bzimg,
image->priv.user ) ) != 0 )
return rc;
assert ( bzimg.rm_kernel == image->priv.user );
/* Parse command line for bootloader parameters */
if ( ( rc = bzimage_parse_cmdline ( image, &exec_ctx, cmdline ) ) != 0)
if ( ( rc = bzimage_parse_cmdline ( image, &bzimg, cmdline ) ) != 0)
return rc;
/* Store command line */
if ( ( rc = bzimage_set_cmdline ( image, &exec_ctx, cmdline ) ) != 0 )
if ( ( rc = bzimage_set_cmdline ( image, &bzimg, cmdline ) ) != 0 )
return rc;
/* Load any initrds */
if ( ( rc = bzimage_load_initrds ( image, &exec_ctx ) ) != 0 )
if ( ( rc = bzimage_load_initrds ( image, &bzimg ) ) != 0 )
return rc;
/* Update and store kernel header */
bzhdr.vid_mode = exec_ctx.vid_mode;
bzhdr.ramdisk_image = exec_ctx.ramdisk_image;
bzhdr.ramdisk_size = exec_ctx.ramdisk_size;
copy_to_user ( exec_ctx.rm_kernel, BZI_HDR_OFFSET, &bzhdr,
sizeof ( bzhdr ) );
/* Update kernel header */
bzimage_update_header ( image, &bzimg, bzimg.rm_kernel );
/* Prepare for exiting */
shutdown();
shutdown ( SHUTDOWN_BOOT );
DBGC ( image, "bzImage %p jumping to RM kernel at %04x:0000 "
"(stack %04x:%04zx)\n", image,
( exec_ctx.rm_kernel_seg + 0x20 ),
exec_ctx.rm_kernel_seg, exec_ctx.rm_heap );
"(stack %04x:%04zx)\n", image, ( bzimg.rm_kernel_seg + 0x20 ),
bzimg.rm_kernel_seg, bzimg.rm_heap );
/* Jump to the kernel */
__asm__ __volatile__ ( REAL_CODE ( "movw %w0, %%ds\n\t"
@@ -358,9 +493,9 @@ static int bzimage_exec ( struct image *image ) {
"pushw %w2\n\t"
"pushw $0\n\t"
"lret\n\t" )
: : "r" ( exec_ctx.rm_kernel_seg ),
"r" ( exec_ctx.rm_heap ),
"r" ( exec_ctx.rm_kernel_seg + 0x20 ) );
: : "r" ( bzimg.rm_kernel_seg ),
"r" ( bzimg.rm_heap ),
"r" ( bzimg.rm_kernel_seg + 0x20 ) );
/* There is no way for the image to return, since we provide
* no return address.
@@ -370,155 +505,6 @@ static int bzimage_exec ( struct image *image ) {
return -ECANCELED; /* -EIMPOSSIBLE */
}
/**
* Load and parse bzImage header
*
* @v image bzImage file
* @v load_ctx Load context
* @v bzhdr Buffer for bzImage header
* @ret rc Return status code
*/
static int bzimage_load_header ( struct image *image,
struct bzimage_load_context *load_ctx,
struct bzimage_header *bzhdr ) {
/* Sanity check */
if ( image->len < ( BZI_HDR_OFFSET + sizeof ( *bzhdr ) ) ) {
DBGC ( image, "bzImage %p too short for kernel header\n",
image );
return -ENOEXEC;
}
/* Read and verify header */
copy_from_user ( bzhdr, image->data, BZI_HDR_OFFSET,
sizeof ( *bzhdr ) );
if ( bzhdr->header != BZI_SIGNATURE ) {
DBGC ( image, "bzImage %p bad signature %08lx\n",
image, bzhdr->header );
return -ENOEXEC;
}
/* We don't support ancient kernels */
if ( bzhdr->version < 0x0200 ) {
DBGC ( image, "bzImage %p version %04x not supported\n",
image, bzhdr->version );
return -ENOTSUP;
}
/* Calculate load address and size of real-mode portion */
load_ctx->rm_kernel_seg = 0x1000; /* place RM kernel at 1000:0000 */
load_ctx->rm_kernel = real_to_user ( load_ctx->rm_kernel_seg, 0 );
load_ctx->rm_filesz =
( ( bzhdr->setup_sects ? bzhdr->setup_sects : 4 ) + 1 ) << 9;
load_ctx->rm_memsz = BZI_ASSUMED_RM_SIZE;
if ( load_ctx->rm_filesz > image->len ) {
DBGC ( image, "bzImage %p too short for %zd byte of setup\n",
image, load_ctx->rm_filesz );
return -ENOEXEC;
}
/* Calculate load address and size of non-real-mode portion */
load_ctx->pm_kernel = ( ( bzhdr->loadflags & BZI_LOAD_HIGH ) ?
phys_to_user ( BZI_LOAD_HIGH_ADDR ) :
phys_to_user ( BZI_LOAD_LOW_ADDR ) );
load_ctx->pm_sz = ( image->len - load_ctx->rm_filesz );
DBGC ( image, "bzImage %p version %04x RM %#zx bytes PM %#zx bytes\n",
image, bzhdr->version, load_ctx->rm_filesz, load_ctx->pm_sz );
return 0;
}
/**
* Load real-mode portion of bzImage
*
* @v image bzImage file
* @v load_ctx Load context
* @ret rc Return status code
*/
static int bzimage_load_real ( struct image *image,
struct bzimage_load_context *load_ctx ) {
int rc;
/* Allow space for the stack and heap */
load_ctx->rm_memsz += BZI_STACK_SIZE;
load_ctx->rm_heap = load_ctx->rm_memsz;
/* Allow space for the command line */
load_ctx->rm_cmdline = load_ctx->rm_memsz;
load_ctx->rm_memsz += BZI_CMDLINE_SIZE;
/* Prepare, verify, and load the real-mode segment */
if ( ( rc = prep_segment ( load_ctx->rm_kernel, load_ctx->rm_filesz,
load_ctx->rm_memsz ) ) != 0 ) {
DBGC ( image, "bzImage %p could not prepare RM segment: %s\n",
image, strerror ( rc ) );
return rc;
}
memcpy_user ( load_ctx->rm_kernel, 0, image->data, 0,
load_ctx->rm_filesz );
return 0;
}
/**
* Load non-real-mode portion of bzImage
*
* @v image bzImage file
* @v load_ctx Load context
* @ret rc Return status code
*/
static int bzimage_load_non_real ( struct image *image,
struct bzimage_load_context *load_ctx ) {
int rc;
/* Prepare, verify and load the non-real-mode segment */
if ( ( rc = prep_segment ( load_ctx->pm_kernel, load_ctx->pm_sz,
load_ctx->pm_sz ) ) != 0 ) {
DBGC ( image, "bzImage %p could not prepare PM segment: %s\n",
image, strerror ( rc ) );
return rc;
}
memcpy_user ( load_ctx->pm_kernel, 0, image->data, load_ctx->rm_filesz,
load_ctx->pm_sz );
return 0;
}
/**
* Update and store bzImage header
*
* @v image bzImage file
* @v load_ctx Load context
* @v bzhdr Original bzImage header
* @ret rc Return status code
*/
static int bzimage_write_header ( struct image *image __unused,
struct bzimage_load_context *load_ctx,
struct bzimage_header *bzhdr ) {
struct bzimage_cmdline cmdline;
/* Update the header and copy it into the loaded kernel */
bzhdr->type_of_loader = BZI_LOADER_TYPE_GPXE;
if ( bzhdr->version >= 0x0201 ) {
bzhdr->heap_end_ptr = ( load_ctx->rm_heap - 0x200 );
bzhdr->loadflags |= BZI_CAN_USE_HEAP;
}
if ( bzhdr->version >= 0x0202 ) {
bzhdr->cmd_line_ptr = user_to_phys ( load_ctx->rm_kernel,
load_ctx->rm_cmdline );
} else {
cmdline.magic = BZI_CMDLINE_MAGIC;
cmdline.offset = load_ctx->rm_cmdline;
copy_to_user ( load_ctx->rm_kernel, BZI_CMDLINE_OFFSET,
&cmdline, sizeof ( cmdline ) );
bzhdr->setup_move_size = load_ctx->rm_memsz;
}
copy_to_user ( load_ctx->rm_kernel, BZI_HDR_OFFSET,
bzhdr, sizeof ( *bzhdr ) );
return 0;
}
/**
* Load bzImage image into memory
*
@@ -526,35 +512,43 @@ static int bzimage_write_header ( struct image *image __unused,
* @ret rc Return status code
*/
int bzimage_load ( struct image *image ) {
struct bzimage_load_context load_ctx;
struct bzimage_header bzhdr;
struct bzimage_context bzimg;
int rc;
/* Initialise context */
memset ( &load_ctx, 0, sizeof ( load_ctx ) );
/* Load and verify header */
if ( ( rc = bzimage_load_header ( image, &load_ctx, &bzhdr ) ) != 0 )
/* Read and parse header from image */
if ( ( rc = bzimage_parse_header ( image, &bzimg,
image->data ) ) != 0 )
return rc;
/* This is a bzImage image, valid or otherwise */
if ( ! image->type )
image->type = &bzimage_image_type;
/* Load real-mode portion */
if ( ( rc = bzimage_load_real ( image, &load_ctx ) ) != 0 )
/* Prepare segments */
if ( ( rc = prep_segment ( bzimg.rm_kernel, bzimg.rm_filesz,
bzimg.rm_memsz ) ) != 0 ) {
DBGC ( image, "bzImage %p could not prepare RM segment: %s\n",
image, strerror ( rc ) );
return rc;
}
if ( ( rc = prep_segment ( bzimg.pm_kernel, bzimg.pm_sz,
bzimg.pm_sz ) ) != 0 ) {
DBGC ( image, "bzImage %p could not prepare PM segment: %s\n",
image, strerror ( rc ) );
return rc;
}
/* Load non-real-mode portion */
if ( ( rc = bzimage_load_non_real ( image, &load_ctx ) ) != 0 )
return rc;
/* Load segments */
memcpy_user ( bzimg.rm_kernel, 0, image->data,
0, bzimg.rm_filesz );
memcpy_user ( bzimg.pm_kernel, 0, image->data,
bzimg.rm_filesz, bzimg.pm_sz );
/* Update and write out header */
if ( ( rc = bzimage_write_header ( image, &load_ctx, &bzhdr ) ) != 0 )
return rc;
bzimage_update_header ( image, &bzimg, bzimg.rm_kernel );
/* Record real-mode segment in image private data field */
image->priv.ul = load_ctx.rm_kernel_seg;
image->priv.user = bzimg.rm_kernel;
return 0;
}
+285
View File
@@ -0,0 +1,285 @@
/*
* Copyright (C) 2008 Daniel Verkamp <daniel@drv.nu>.
*
* 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.
*/
/**
* @file
*
* SYSLINUX COM32 image format
*
*/
FILE_LICENCE ( GPL2_OR_LATER );
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <errno.h>
#include <assert.h>
#include <realmode.h>
#include <basemem.h>
#include <comboot.h>
#include <gpxe/uaccess.h>
#include <gpxe/image.h>
#include <gpxe/segment.h>
#include <gpxe/init.h>
#include <gpxe/memmap.h>
struct image_type com32_image_type __image_type ( PROBE_NORMAL );
/**
* Execute COMBOOT image
*
* @v image COM32 image
* @ret rc Return status code
*/
static int com32_exec ( struct image *image ) {
struct memory_map memmap;
unsigned int i;
int state;
uint32_t avail_mem_top;
state = rmsetjmp ( comboot_return );
switch ( state ) {
case 0: /* First time through; invoke COM32 program */
/* Get memory map */
get_memmap ( &memmap );
/* Find end of block covering COM32 image loading area */
for ( i = 0, avail_mem_top = 0 ; i < memmap.count ; i++ ) {
if ( (memmap.regions[i].start <= COM32_START_PHYS) &&
(memmap.regions[i].end > COM32_START_PHYS + image->len) ) {
avail_mem_top = memmap.regions[i].end;
break;
}
}
DBGC ( image, "COM32 %p: available memory top = 0x%x\n",
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();
/* 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.
*/
unregister_image ( image );
__asm__ __volatile__ (
"movl %%esp, (com32_internal_esp)\n\t" /* Save internal virtual address space ESP */
"movl (com32_external_esp), %%esp\n\t" /* Switch to COM32 ESP (top of available memory) */
"call _virt_to_phys\n\t" /* Switch to flat physical address space */
"pushl %0\n\t" /* Pointer to CDECL helper function */
"pushl %1\n\t" /* Pointer to FAR call helper function */
"pushl %2\n\t" /* Size of low memory bounce buffer */
"pushl %3\n\t" /* Pointer to low memory bounce buffer */
"pushl %4\n\t" /* Pointer to INT call helper function */
"pushl %5\n\t" /* Pointer to the command line arguments */
"pushl $6\n\t" /* Number of additional arguments */
"call *%6\n\t" /* Execute image */
"call _phys_to_virt\n\t" /* Switch back to internal virtual address space */
"movl (com32_internal_esp), %%esp\n\t" /* Switch back to internal stack */
:
:
/* %0 */ "r" ( virt_to_phys ( com32_cfarcall_wrapper ) ),
/* %1 */ "r" ( virt_to_phys ( com32_farcall_wrapper ) ),
/* %2 */ "r" ( get_fbms() * 1024 - (COM32_BOUNCE_SEG << 4) ),
/* %3 */ "i" ( COM32_BOUNCE_SEG << 4 ),
/* %4 */ "r" ( virt_to_phys ( com32_intcall_wrapper ) ),
/* %5 */ "r" ( virt_to_phys ( image->cmdline ) ),
/* %6 */ "r" ( COM32_START_PHYS )
:
"memory" );
DBGC ( image, "COM32 %p: returned\n", image );
break;
case COMBOOT_EXIT:
DBGC ( image, "COM32 %p: exited\n", image );
break;
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;
}
unhook_comboot_interrupts();
comboot_force_text_mode();
return 0;
}
/**
* Check image name extension
*
* @v image COM32 image
* @ret rc Return status code
*/
static int com32_identify ( struct image *image ) {
const char *ext;
static const uint8_t magic[] = { 0xB8, 0xFF, 0x4C, 0xCD, 0x21 };
uint8_t buf[5];
if ( image->len >= 5 ) {
/* Check for magic number
* mov eax,21cd4cffh
* B8 FF 4C CD 21
*/
copy_from_user ( buf, image->data, 0, sizeof(buf) );
if ( ! memcmp ( buf, magic, sizeof(buf) ) ) {
DBGC ( image, "COM32 %p: found magic number\n",
image );
return 0;
}
}
/* Magic number not found; check filename extension */
ext = strrchr( image->name, '.' );
if ( ! ext ) {
DBGC ( image, "COM32 %p: no extension\n",
image );
return -ENOEXEC;
}
++ext;
if ( strcasecmp( ext, "c32" ) ) {
DBGC ( image, "COM32 %p: unrecognized extension %s\n",
image, ext );
return -ENOEXEC;
}
return 0;
}
/**
* Load COM32 image into memory
* @v image COM32 image
* @ret rc Return status code
*/
static int comboot_load_image ( struct image *image ) {
size_t filesz, memsz;
userptr_t buffer;
int rc;
filesz = image->len;
memsz = filesz;
buffer = phys_to_user ( COM32_START_PHYS );
if ( ( rc = prep_segment ( buffer, filesz, memsz ) ) != 0 ) {
DBGC ( image, "COM32 %p: could not prepare segment: %s\n",
image, strerror ( rc ) );
return rc;
}
/* Copy image to segment */
memcpy_user ( buffer, 0, image->data, 0, filesz );
return 0;
}
/**
* Prepare COM32 low memory bounce buffer
* @v image COM32 image
* @ret rc Return status code
*/
static int comboot_prepare_bounce_buffer ( struct image * image ) {
unsigned int seg;
userptr_t seg_userptr;
size_t filesz, memsz;
int rc;
seg = COM32_BOUNCE_SEG;
seg_userptr = real_to_user ( seg, 0 );
/* Ensure the entire 64k segment is free */
memsz = 0xFFFF;
filesz = 0;
/* Prepare, verify, and load the real-mode segment */
if ( ( rc = prep_segment ( seg_userptr, filesz, memsz ) ) != 0 ) {
DBGC ( image, "COM32 %p: could not prepare bounce buffer segment: %s\n",
image, strerror ( rc ) );
return rc;
}
return 0;
}
/**
* Load COM32 image into memory
*
* @v image COM32 image
* @ret rc Return status code
*/
static int com32_load ( struct image *image ) {
int rc;
DBGC ( image, "COM32 %p: name '%s', cmdline '%s'\n",
image, image->name, image->cmdline );
/* Check if this is a COMBOOT image */
if ( ( rc = com32_identify ( image ) ) != 0 ) {
return rc;
}
/* This is a COM32 image, valid or otherwise */
if ( ! image->type )
image->type = &com32_image_type;
/* Load image */
if ( ( rc = comboot_load_image ( image ) ) != 0 ) {
return rc;
}
/* Prepare bounce buffer segment */
if ( ( rc = comboot_prepare_bounce_buffer ( image ) ) != 0 ) {
return rc;
}
return 0;
}
/** SYSLINUX COM32 image type */
struct image_type com32_image_type __image_type ( PROBE_NORMAL ) = {
.name = "COM32",
.load = com32_load,
.exec = com32_exec,
};
+322
View File
@@ -0,0 +1,322 @@
/*
* Copyright (C) 2008 Daniel Verkamp <daniel@drv.nu>.
*
* 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.
*/
/**
* @file
*
* SYSLINUX COMBOOT (16-bit) image format
*
*/
FILE_LICENCE ( GPL2_OR_LATER );
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <errno.h>
#include <assert.h>
#include <realmode.h>
#include <basemem.h>
#include <comboot.h>
#include <gpxe/uaccess.h>
#include <gpxe/image.h>
#include <gpxe/segment.h>
#include <gpxe/init.h>
#include <gpxe/features.h>
FEATURE ( FEATURE_IMAGE, "COMBOOT", DHCP_EB_FEATURE_COMBOOT, 1 );
struct image_type comboot_image_type __image_type ( PROBE_NORMAL );
/**
* COMBOOT PSP, copied to offset 0 of code segment
*/
struct comboot_psp {
/** INT 20 instruction, executed if COMBOOT image returns with RET */
uint16_t int20;
/** Segment of first non-free paragraph of memory */
uint16_t first_non_free_para;
};
/** Offset in PSP of command line */
#define COMBOOT_PSP_CMDLINE_OFFSET 0x81
/** Maximum length of command line in PSP
* (127 bytes minus space and CR) */
#define COMBOOT_MAX_CMDLINE_LEN 125
/**
* Copy command line to PSP
*
* @v image COMBOOT image
*/
static void comboot_copy_cmdline ( struct image * image, userptr_t seg_userptr ) {
const char *cmdline = ( image->cmdline ? image->cmdline : "" );
int cmdline_len = strlen ( cmdline );
if( cmdline_len > COMBOOT_MAX_CMDLINE_LEN )
cmdline_len = COMBOOT_MAX_CMDLINE_LEN;
uint8_t len_byte = cmdline_len;
char spc = ' ', cr = '\r';
/* Copy length to byte before command line */
copy_to_user ( seg_userptr, COMBOOT_PSP_CMDLINE_OFFSET - 1,
&len_byte, 1 );
/* Command line starts with space */
copy_to_user ( seg_userptr,
COMBOOT_PSP_CMDLINE_OFFSET,
&spc, 1 );
/* Copy command line */
copy_to_user ( seg_userptr,
COMBOOT_PSP_CMDLINE_OFFSET + 1,
cmdline, cmdline_len );
/* Command line ends with CR */
copy_to_user ( seg_userptr,
COMBOOT_PSP_CMDLINE_OFFSET + cmdline_len + 1,
&cr, 1 );
}
/**
* Initialize PSP
*
* @v image COMBOOT image
* @v seg_userptr segment to initialize
*/
static void comboot_init_psp ( struct image * image, userptr_t seg_userptr ) {
struct comboot_psp psp;
/* Fill PSP */
/* INT 20h instruction, byte order reversed */
psp.int20 = 0x20CD;
/* get_fbms() returns BIOS free base memory counter, which is in
* kilobytes; x * 1024 / 16 == x * 64 == x << 6 */
psp.first_non_free_para = get_fbms() << 6;
DBGC ( image, "COMBOOT %p: first non-free paragraph = 0x%x\n",
image, psp.first_non_free_para );
/* Copy the PSP to offset 0 of segment.
* The rest of the PSP was already zeroed by
* comboot_prepare_segment. */
copy_to_user ( seg_userptr, 0, &psp, sizeof( psp ) );
/* Copy the command line to the PSP */
comboot_copy_cmdline ( image, seg_userptr );
}
/**
* Execute COMBOOT image
*
* @v image COMBOOT image
* @ret rc Return status code
*/
static int comboot_exec ( struct image *image ) {
userptr_t seg_userptr = real_to_user ( COMBOOT_PSP_SEG, 0 );
int state;
state = rmsetjmp ( comboot_return );
switch ( state ) {
case 0: /* First time through; invoke COMBOOT program */
/* Initialize PSP */
comboot_init_psp ( image, seg_userptr );
/* Hook COMBOOT API interrupts */
hook_comboot_interrupts();
DBGC ( image, "executing 16-bit COMBOOT image at %4x:0100\n",
COMBOOT_PSP_SEG );
/* 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.
*/
unregister_image ( image );
/* Store stack segment at 0x38 and stack pointer at 0x3A
* in the PSP and jump to the image */
__asm__ __volatile__ (
REAL_CODE ( /* Save return address with segment on old stack */
"popw %%ax\n\t"
"pushw %%cs\n\t"
"pushw %%ax\n\t"
/* Set DS=ES=segment with image */
"movw %w0, %%ds\n\t"
"movw %w0, %%es\n\t"
/* Set SS:SP to new stack (end of image segment) */
"movw %w0, %%ss\n\t"
"xor %%sp, %%sp\n\t"
"pushw $0\n\t"
"pushw %w0\n\t"
"pushw $0x100\n\t"
/* Zero registers (some COM files assume GP regs are 0) */
"xorw %%ax, %%ax\n\t"
"xorw %%bx, %%bx\n\t"
"xorw %%cx, %%cx\n\t"
"xorw %%dx, %%dx\n\t"
"xorw %%si, %%si\n\t"
"xorw %%di, %%di\n\t"
"xorw %%bp, %%bp\n\t"
"lret\n\t" )
: : "r" ( COMBOOT_PSP_SEG ) : "eax" );
DBGC ( image, "COMBOOT %p: returned\n", image );
break;
case COMBOOT_EXIT:
DBGC ( image, "COMBOOT %p: exited\n", image );
break;
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;
}
unhook_comboot_interrupts();
comboot_force_text_mode();
return 0;
}
/**
* Check image name extension
*
* @v image COMBOOT image
* @ret rc Return status code
*/
static int comboot_identify ( struct image *image ) {
const char *ext;
ext = strrchr( image->name, '.' );
if ( ! ext ) {
DBGC ( image, "COMBOOT %p: no extension\n",
image );
return -ENOEXEC;
}
++ext;
if ( strcasecmp( ext, "com" ) && strcasecmp( ext, "cbt" ) ) {
DBGC ( image, "COMBOOT %p: unrecognized extension %s\n",
image, ext );
return -ENOEXEC;
}
return 0;
}
/**
* Load COMBOOT image into memory, preparing a segment and returning it
* @v image COMBOOT image
* @ret rc Return status code
*/
static int comboot_prepare_segment ( struct image *image )
{
userptr_t seg_userptr;
size_t filesz, memsz;
int rc;
/* Load image in segment */
seg_userptr = real_to_user ( COMBOOT_PSP_SEG, 0 );
/* Allow etra 0x100 bytes before image for PSP */
filesz = image->len + 0x100;
/* Ensure the entire 64k segment is free */
memsz = 0xFFFF;
/* Prepare, verify, and load the real-mode segment */
if ( ( rc = prep_segment ( seg_userptr, filesz, memsz ) ) != 0 ) {
DBGC ( image, "COMBOOT %p: could not prepare segment: %s\n",
image, strerror ( rc ) );
return rc;
}
/* Zero PSP */
memset_user ( seg_userptr, 0, 0, 0x100 );
/* Copy image to segment:0100 */
memcpy_user ( seg_userptr, 0x100, image->data, 0, image->len );
return 0;
}
/**
* Load COMBOOT image into memory
*
* @v image COMBOOT image
* @ret rc Return status code
*/
static int comboot_load ( struct image *image ) {
int rc;
DBGC ( image, "COMBOOT %p: name '%s'\n",
image, image->name );
/* Check if this is a COMBOOT image */
if ( ( rc = comboot_identify ( image ) ) != 0 ) {
return rc;
}
/* This is a 16-bit COMBOOT image, valid or otherwise */
if ( ! image->type )
image->type = &comboot_image_type;
/* Sanity check for filesize */
if( image->len >= 0xFF00 ) {
DBGC( image, "COMBOOT %p: image too large\n",
image );
return -ENOEXEC;
}
/* Prepare segment and load image */
if ( ( rc = comboot_prepare_segment ( image ) ) != 0 ) {
return rc;
}
return 0;
}
/** SYSLINUX COMBOOT (16-bit) image type */
struct image_type comboot_image_type __image_type ( PROBE_NORMAL ) = {
.name = "COMBOOT",
.load = comboot_load,
.exec = comboot_exec,
};
+113
View File
@@ -0,0 +1,113 @@
/*
* Copyright (C) 2008 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.
*/
FILE_LICENCE ( GPL2_OR_LATER );
#include <errno.h>
#include <elf.h>
#include <gpxe/image.h>
#include <gpxe/elf.h>
#include <gpxe/features.h>
#include <gpxe/init.h>
/**
* @file
*
* ELF bootable image
*
*/
FEATURE ( FEATURE_IMAGE, "ELF", DHCP_EB_FEATURE_ELF, 1 );
struct image_type elfboot_image_type __image_type ( PROBE_NORMAL );
/**
* Execute ELF image
*
* @v image ELF image
* @ret rc Return status code
*/
static int elfboot_exec ( struct image *image ) {
physaddr_t entry = image->priv.phys;
/* An ELF image has no callback interface, so we need to shut
* down before invoking it.
*/
shutdown ( SHUTDOWN_BOOT );
/* Jump to OS with flat physical addressing */
DBGC ( image, "ELF %p starting execution at %lx\n", image, entry );
__asm__ __volatile__ ( PHYS_CODE ( "call *%%edi\n\t" )
: : "D" ( entry )
: "eax", "ebx", "ecx", "edx", "esi", "ebp",
"memory" );
DBGC ( image, "ELF %p returned\n", image );
/* It isn't safe to continue after calling shutdown() */
while ( 1 ) {}
return -ECANCELED; /* -EIMPOSSIBLE, anyone? */
}
/**
* Load ELF image into memory
*
* @v image ELF file
* @ret rc Return status code
*/
static int elfboot_load ( struct image *image ) {
Elf32_Ehdr ehdr;
static const uint8_t e_ident[] = {
[EI_MAG0] = ELFMAG0,
[EI_MAG1] = ELFMAG1,
[EI_MAG2] = ELFMAG2,
[EI_MAG3] = ELFMAG3,
[EI_CLASS] = ELFCLASS32,
[EI_DATA] = ELFDATA2LSB,
[EI_VERSION] = EV_CURRENT,
};
int rc;
/* Read ELF header */
copy_from_user ( &ehdr, image->data, 0, sizeof ( ehdr ) );
if ( memcmp ( ehdr.e_ident, e_ident, sizeof ( e_ident ) ) != 0 ) {
DBG ( "Invalid ELF identifier\n" );
return -ENOEXEC;
}
/* This is an ELF image, valid or otherwise */
if ( ! image->type )
image->type = &elfboot_image_type;
/* Load the image using core ELF support */
if ( ( rc = elf_load ( image ) ) != 0 ) {
DBGC ( image, "ELF %p could not load: %s\n",
image, strerror ( rc ) );
return rc;
}
return 0;
}
/** ELF image type */
struct image_type elfboot_image_type __image_type ( PROBE_NORMAL ) = {
.name = "ELF",
.load = elfboot_load,
.exec = elfboot_exec,
};
+2
View File
@@ -16,6 +16,8 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
FILE_LICENCE ( GPL2_OR_LATER );
/**
* @file
*
+38 -21
View File
@@ -16,6 +16,8 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
FILE_LICENCE ( GPL2_OR_LATER );
/**
* @file
*
@@ -139,10 +141,11 @@ static void multiboot_build_memmap ( struct image *image,
/**
* Add command line in base memory
*
* @v imgname Image name
* @v cmdline Command line
* @ret physaddr Physical address of command line
*/
physaddr_t multiboot_add_cmdline ( const char *cmdline ) {
physaddr_t multiboot_add_cmdline ( const char *imgname, const char *cmdline ) {
char *mb_cmdline;
if ( ! cmdline )
@@ -153,7 +156,7 @@ physaddr_t multiboot_add_cmdline ( const char *cmdline ) {
mb_cmdline_offset +=
( snprintf ( mb_cmdline,
( sizeof ( mb_cmdlines ) - mb_cmdline_offset ),
"%s", cmdline ) + 1 );
"%s %s", imgname, cmdline ) + 1 );
/* Truncate to terminating NUL in buffer if necessary */
if ( mb_cmdline_offset > sizeof ( mb_cmdlines ) )
@@ -208,8 +211,8 @@ multiboot_build_module_list ( struct image *image,
( ( count - insert ) * sizeof ( *module ) ) );
module->mod_start = start;
module->mod_end = end;
module->string =
multiboot_add_cmdline ( module_image->cmdline );
module->string = multiboot_add_cmdline ( module_image->name,
module_image->cmdline );
module->reserved = 0;
/* We promise to page-align modules */
@@ -220,7 +223,7 @@ multiboot_build_module_list ( struct image *image,
/* Dump module configuration */
for ( i = 0 ; i < count ; i++ ) {
DBGC ( image, "MULTIBOOT %p module %d is [%lx,%lx)\n",
DBGC ( image, "MULTIBOOT %p module %d is [%x,%x)\n",
image, i, modules[i].mod_start,
modules[i].mod_end );
}
@@ -267,7 +270,7 @@ static int multiboot_exec ( struct image *image ) {
multiboot_build_memmap ( image, &mbinfo, mbmemmap,
( sizeof(mbmemmap) / sizeof(mbmemmap[0]) ) );
mb_cmdline_offset = 0;
mbinfo.cmdline = multiboot_add_cmdline ( image->cmdline );
mbinfo.cmdline = multiboot_add_cmdline ( image->name, image->cmdline );
mbinfo.mods_count = multiboot_build_module_list ( image, mbmodules,
( sizeof(mbmodules) / sizeof(mbmodules[0]) ) );
mbinfo.mods_addr = virt_to_phys ( mbmodules );
@@ -277,14 +280,18 @@ static int multiboot_exec ( struct image *image ) {
/* Multiboot images may not return and have no callback
* interface, so shut everything down prior to booting the OS.
*/
shutdown();
shutdown ( SHUTDOWN_BOOT );
/* Jump to OS with flat physical addressing */
__asm__ __volatile__ ( PHYS_CODE ( "call *%%edi\n\t" )
DBGC ( image, "MULTIBOOT %p starting execution at %lx\n",
image, entry );
__asm__ __volatile__ ( PHYS_CODE ( "pushl %%ebp\n\t"
"call *%%edi\n\t"
"popl %%ebp\n\t" )
: : "a" ( MULTIBOOT_BOOTLOADER_MAGIC ),
"b" ( virt_to_phys ( &mbinfo ) ),
"D" ( entry )
: "ecx", "edx", "esi", "ebp", "memory" );
: "ecx", "edx", "esi", "memory" );
DBGC ( image, "MULTIBOOT %p returned\n", image );
@@ -356,10 +363,20 @@ static int multiboot_load_raw ( struct image *image,
userptr_t buffer;
int rc;
/* Sanity check */
if ( ! ( hdr->mb.flags & MB_FLAG_RAW ) ) {
DBGC ( image, "MULTIBOOT %p is not flagged as a raw image\n",
image );
return -EINVAL;
}
/* Verify and prepare segment */
offset = ( hdr->offset - hdr->mb.header_addr + hdr->mb.load_addr );
filesz = ( hdr->mb.load_end_addr - hdr->mb.load_addr );
memsz = ( hdr->mb.bss_end_addr - hdr->mb.load_addr );
filesz = ( hdr->mb.load_end_addr ?
( hdr->mb.load_end_addr - hdr->mb.load_addr ) :
( image->len - offset ) );
memsz = ( hdr->mb.bss_end_addr ?
( hdr->mb.bss_end_addr - hdr->mb.load_addr ) : filesz );
buffer = phys_to_user ( hdr->mb.load_addr );
if ( ( rc = prep_segment ( buffer, filesz, memsz ) ) != 0 ) {
DBGC ( image, "MULTIBOOT %p could not prepare segment: %s\n",
@@ -411,7 +428,7 @@ static int multiboot_load ( struct image *image ) {
image );
return rc;
}
DBGC ( image, "MULTIBOOT %p found header with flags %08lx\n",
DBGC ( image, "MULTIBOOT %p found header with flags %08x\n",
image, hdr.mb.flags );
/* This is a multiboot image, valid or otherwise */
@@ -420,19 +437,19 @@ static int multiboot_load ( struct image *image ) {
/* Abort if we detect flags that we cannot support */
if ( hdr.mb.flags & MB_UNSUPPORTED_FLAGS ) {
DBGC ( image, "MULTIBOOT %p flags %08lx not supported\n",
DBGC ( image, "MULTIBOOT %p flags %08x not supported\n",
image, ( hdr.mb.flags & MB_UNSUPPORTED_FLAGS ) );
return -ENOTSUP;
}
/* Load the actual image */
if ( hdr.mb.flags & MB_FLAG_RAW ) {
if ( ( rc = multiboot_load_raw ( image, &hdr ) ) != 0 )
return rc;
} else {
if ( ( rc = multiboot_load_elf ( image ) ) != 0 )
return rc;
}
/* There is technically a bit MB_FLAG_RAW to indicate whether
* this is an ELF or a raw image. In practice, grub will use
* the ELF header if present, and Solaris relies on this
* behaviour.
*/
if ( ( ( rc = multiboot_load_elf ( image ) ) != 0 ) &&
( ( rc = multiboot_load_raw ( image, &hdr ) ) != 0 ) )
return rc;
return 0;
}
+5 -24
View File
@@ -8,7 +8,7 @@
#include <gpxe/segment.h>
#include <gpxe/init.h>
#include <gpxe/netdevice.h>
#include <gpxe/dhcp.h>
#include <gpxe/fakedhcp.h>
#include <gpxe/image.h>
#include <gpxe/features.h>
@@ -366,22 +366,6 @@ static int nbi_boot32 ( struct image *image, struct imgheader *imgheader ) {
return rc;
}
/**
* Guess boot network device
*
* @ret netdev Boot network device
*/
static struct net_device * guess_boot_netdev ( void ) {
struct net_device *boot_netdev;
/* Just use the first network device */
for_each_netdev ( boot_netdev ) {
return boot_netdev;
}
return NULL;
}
/**
* Prepare DHCP parameter block for NBI image
*
@@ -389,21 +373,18 @@ static struct net_device * guess_boot_netdev ( void ) {
* @ret rc Return status code
*/
static int nbi_prepare_dhcp ( struct image *image ) {
struct dhcp_packet dhcppkt;
struct net_device *boot_netdev;
int rc;
boot_netdev = guess_boot_netdev();
boot_netdev = last_opened_netdev();
if ( ! boot_netdev ) {
DBGC ( image, "NBI %p could not identify a network device\n",
image );
return -ENODEV;
}
if ( ( rc = create_dhcp_response ( boot_netdev, DHCPACK, NULL,
basemem_packet,
sizeof ( basemem_packet ),
&dhcppkt ) ) != 0 ) {
if ( ( rc = create_fakedhcpack ( boot_netdev, basemem_packet,
sizeof ( basemem_packet ) ) ) != 0 ) {
DBGC ( image, "NBI %p failed to build DHCP packet\n", image );
return rc;
}
@@ -432,7 +413,7 @@ static int nbi_exec ( struct image *image ) {
/* Shut down now if NBI image will not return */
may_return = NBI_PROGRAM_RETURNS ( imgheader.flags );
if ( ! may_return )
shutdown();
shutdown ( SHUTDOWN_BOOT );
/* Execute NBI image */
if ( NBI_LINEAR_EXEC_ADDR ( imgheader.flags ) ) {
+22 -14
View File
@@ -16,6 +16,8 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
FILE_LICENCE ( GPL2_OR_LATER );
/**
* @file
*
@@ -45,29 +47,21 @@ static int pxe_exec ( struct image *image ) {
struct net_device *netdev;
int rc;
/* Ensure that PXE stack is ready to use */
pxe_init_structures();
pxe_hook_int1a();
/* Arbitrarily pick the first open network device to use for PXE */
for_each_netdev ( netdev ) {
pxe_set_netdev ( netdev );
break;
}
/* Many things will break if pxe_netdev is NULL */
if ( ! pxe_netdev ) {
/* Arbitrarily pick the most recently opened network device */
if ( ( netdev = last_opened_netdev() ) == NULL ) {
DBGC ( image, "IMAGE %p could not locate PXE net device\n",
image );
return -ENODEV;
}
/* Activate PXE */
pxe_activate ( netdev );
/* Start PXE NBP */
rc = pxe_start_nbp();
/* Deactivate PXE */
pxe_set_netdev ( NULL );
pxe_unhook_int1a();
pxe_deactivate();
return rc;
}
@@ -84,6 +78,20 @@ int pxe_load ( struct image *image ) {
size_t memsz = image->len;
int rc;
/* Images too large to fit in base memory cannot be PXE
* images. We include this check to help prevent unrecognised
* images from being marked as PXE images, since PXE images
* have no signature we can check against.
*/
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;
+2
View File
@@ -7,6 +7,8 @@
*
*/
FILE_LICENCE ( GPL2_OR_LATER );
#include <stdint.h>
#include <realmode.h>
#include <bios.h>
+2
View File
@@ -1,6 +1,8 @@
#ifndef BASEMEM_PACKET_H
#define BASEMEM_PACKET_H
FILE_LICENCE ( GPL2_OR_LATER );
#include <realmode.h>
/** Maximum length of base memory packet buffer */
+2 -3
View File
@@ -1,11 +1,10 @@
#ifndef BIOS_H
#define BIOS_H
FILE_LICENCE ( GPL2_OR_LATER );
#define BDA_SEG 0x0040
#define BDA_FBMS 0x0013
#define BDA_NUM_DRIVES 0x0075
extern unsigned long currticks ( void );
extern void cpu_nap ( void );
#endif /* BIOS_H */
+16 -1
View File
@@ -6,9 +6,24 @@
*
*/
FILE_LICENCE ( GPL2_OR_LATER );
#include <realmode.h>
struct segoff;
extern int hooked_bios_interrupts;
/**
* Hooked interrupt count
*
* At exit, after unhooking all possible interrupts, this counter
* should be examined. If it is non-zero, it means that we failed to
* unhook at least one interrupt vector, and so must not free up the
* memory we are using. (Note that this also implies that we should
* re-hook INT 15 in order to hide ourselves from the memory map).
*/
extern uint16_t __text16 ( hooked_bios_interrupts );
#define hooked_bios_interrupts __use_text16 ( hooked_bios_interrupts )
extern void hook_bios_interrupt ( unsigned int interrupt, unsigned int handler,
struct segoff *chain_vector );
extern int unhook_bios_interrupt ( unsigned int interrupt,
+7 -40
View File
@@ -1,8 +1,10 @@
#ifndef ETHERBOOT_BITS_BYTESWAP_H
#define ETHERBOOT_BITS_BYTESWAP_H
FILE_LICENCE ( GPL2_OR_LATER );
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 +13,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 +24,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 +32,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 */
+27
View File
@@ -0,0 +1,27 @@
#ifndef _BITS_COMPILER_H
#define _BITS_COMPILER_H
FILE_LICENCE ( GPL2_OR_LATER );
#ifndef ASSEMBLY
/** Declare a function with standard calling conventions */
#define __asmcall __attribute__ (( cdecl, regparm(0) ))
/**
* Declare a function with libgcc implicit linkage
*
* It seems as though gcc expects its implicit arithmetic functions to
* be cdecl, even if -mrtd is specified. This is somewhat
* inconsistent; for example, if -mregparm=3 is used then the implicit
* functions do become regparm(3).
*
* The implicit calls to memcpy() and memset() which gcc can generate
* do not seem to have this inconsistency; -mregparm and -mrtd affect
* them in the same way as any other function.
*/
#define __libgcc __attribute__ (( cdecl ))
#endif /* ASSEMBLY */
#endif /* _BITS_COMPILER_H */
-91
View File
@@ -1,91 +0,0 @@
#ifndef I386_BITS_ELF_H
#define I386_BITS_ELF_H
#include "cpu.h"
#ifdef CONFIG_X86_64
/* ELF Defines for the 64bit version of the current architecture */
#define EM_CURRENT_64 EM_X86_64
#define EM_CURRENT_64_PRESENT ( \
CPU_FEATURE_P(cpu_info.x86_capability, LM) && \
CPU_FEATURE_P(cpu_info.x86_capability, PAE) && \
CPU_FEATURE_P(cpu_info.x86_capability, PSE))
#define ELF_CHECK_X86_64_ARCH(x) \
(EM_CURRENT_64_PRESENT && ((x).e_machine == EM_X86_64))
#define __unused_i386
#else
#define ELF_CHECK_X86_64_ARCH(x) 0
#define __unused_i386 __unused
#endif
/* ELF Defines for the current architecture */
#define EM_CURRENT EM_386
#define ELFDATA_CURRENT ELFDATA2LSB
#define ELF_CHECK_I386_ARCH(x) \
(((x).e_machine == EM_386) || ((x).e_machine == EM_486))
#define ELF_CHECK_ARCH(x) \
((ELF_CHECK_I386_ARCH(x) || ELF_CHECK_X86_64_ARCH(x)) && \
((x).e_entry <= 0xffffffffUL))
#ifdef IMAGE_FREEBSD
/*
* FreeBSD has this rather strange "feature" of its design.
* At some point in its evolution, FreeBSD started to rely
* externally on private/static/debug internal symbol information.
* That is, some of the interfaces that software uses to access
* and work with the FreeBSD kernel are made available not
* via the shared library symbol information (the .DYNAMIC section)
* but rather the debug symbols. This means that any symbol, not
* just publicly defined symbols can be (and are) used by system
* tools to make the system work. (such as top, swapinfo, swapon,
* etc)
*
* Even worse, however, is the fact that standard ELF loaders do
* not know how to load the symbols since they are not within
* an ELF PT_LOAD section. The kernel needs these symbols to
* operate so the following changes/additions to the boot
* loading of EtherBoot have been made to get the kernel to load.
* All of the changes are within IMAGE_FREEBSD such that the
* extra/changed code only compiles when FREEBSD support is
* enabled.
*/
/*
* Section header for FreeBSD (debug symbol kludge!) support
*/
typedef struct {
Elf32_Word sh_name; /* Section name (index into the
section header string table). */
Elf32_Word sh_type; /* Section type. */
Elf32_Word sh_flags; /* Section flags. */
Elf32_Addr sh_addr; /* Address in memory image. */
Elf32_Off sh_offset; /* Offset in file. */
Elf32_Size sh_size; /* Size in bytes. */
Elf32_Word sh_link; /* Index of a related section. */
Elf32_Word sh_info; /* Depends on section type. */
Elf32_Size sh_addralign; /* Alignment in bytes. */
Elf32_Size sh_entsize; /* Size of each entry in section. */
} Elf32_Shdr;
/* sh_type */
#define SHT_SYMTAB 2 /* symbol table section */
#define SHT_STRTAB 3 /* string table section */
/*
* Module information subtypes (for the metadata that we need to build)
*/
#define MODINFO_END 0x0000 /* End of list */
#define MODINFO_NAME 0x0001 /* Name of module (string) */
#define MODINFO_TYPE 0x0002 /* Type of module (string) */
#define MODINFO_METADATA 0x8000 /* Module-specfic */
#define MODINFOMD_SSYM 0x0003 /* start of symbols */
#define MODINFOMD_ESYM 0x0004 /* end of symbols */
#endif /* IMAGE_FREEBSD */
#endif /* I386_BITS_ELF_H */
-5
View File
@@ -1,5 +0,0 @@
#define ARCH_ELF_CLASS ELFCLASS32
#define ARCH_ELF_DATA ELFDATA2LSB
#define ARCH_ELF_MACHINE_OK(x) ((x)==EM_386 || (x)==EM_486)
typedef Elf32_Ehdr Elf_ehdr;
typedef Elf32_Phdr Elf_phdr;
+2 -3
View File
@@ -1,9 +1,8 @@
#ifndef ETHERBOOT_BITS_ENDIAN_H
#define ETHERBOOT_BITS_ENDIAN_H
FILE_LICENCE ( GPL2_OR_LATER );
#define __BYTE_ORDER __LITTLE_ENDIAN
#define le32_to_cpup(x) (*(uint32_t *)(x))
#define cpu_to_le16p(x) (*(uint16_t*)(x))
#endif /* ETHERBOOT_BITS_ENDIAN_H */
+12 -2
View File
@@ -1,15 +1,17 @@
#ifndef _BITS_ERRFILE_H
#define _BITS_ERRFILE_H
FILE_LICENCE ( GPL2_OR_LATER );
/**
* @addtogroup errfile Error file identifiers
* @{
*/
#define ERRFILE_umalloc ( ERRFILE_ARCH | ERRFILE_CORE | 0x00000000 )
#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 )
@@ -19,6 +21,11 @@
#define ERRFILE_multiboot ( ERRFILE_ARCH | ERRFILE_IMAGE | 0x00030000 )
#define ERRFILE_nbi ( ERRFILE_ARCH | ERRFILE_IMAGE | 0x00040000 )
#define ERRFILE_pxe_image ( ERRFILE_ARCH | ERRFILE_IMAGE | 0x00050000 )
#define ERRFILE_elfboot ( ERRFILE_ARCH | ERRFILE_IMAGE | 0x00060000 )
#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 )
@@ -26,6 +33,9 @@
#define ERRFILE_undionly ( ERRFILE_ARCH | ERRFILE_NET | 0x00030000 )
#define ERRFILE_undirom ( ERRFILE_ARCH | ERRFILE_NET | 0x00040000 )
#define ERRFILE_timer_rdtsc ( ERRFILE_ARCH | ERRFILE_DRIVER | 0x00000000 )
#define ERRFILE_timer_bios ( ERRFILE_ARCH | ERRFILE_DRIVER | 0x00010000 )
/** @} */
#endif /* _BITS_ERRFILE_H */
+14
View File
@@ -0,0 +1,14 @@
#ifndef _BITS_IO_H
#define _BITS_IO_H
/** @file
*
* i386-specific I/O API implementations
*
*/
FILE_LICENCE ( GPL2_OR_LATER );
#include <gpxe/x86_io.h>
#endif /* _BITS_IO_H */
+15
View File
@@ -0,0 +1,15 @@
#ifndef _BITS_NAP_H
#define _BITS_NAP_H
/** @file
*
* i386-specific CPU sleeping API implementations
*
*/
FILE_LICENCE ( GPL2_OR_LATER );
#include <gpxe/bios_nap.h>
#include <gpxe/efi/efix86_nap.h>
#endif /* _BITS_MAP_H */
+14
View File
@@ -0,0 +1,14 @@
#ifndef _BITS_SMBIOS_H
#define _BITS_SMBIOS_H
/** @file
*
* i386-specific SMBIOS API implementations
*
*/
FILE_LICENCE ( GPL2_OR_LATER );
#include <gpxe/bios_smbios.h>
#endif /* _BITS_SMBIOS_H */
+5 -3
View File
@@ -1,18 +1,20 @@
#ifndef _BITS_STDINT_H
#define _BITS_STDINT_H
typedef typeof(sizeof(int)) size_t;
FILE_LICENCE ( GPL2_OR_LATER );
typedef __SIZE_TYPE__ size_t;
typedef signed long ssize_t;
typedef signed long off_t;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned long uint32_t;
typedef unsigned int uint32_t;
typedef unsigned long long uint64_t;
typedef signed char int8_t;
typedef signed short int16_t;
typedef signed long int32_t;
typedef signed int int32_t;
typedef signed long long int64_t;
typedef unsigned long physaddr_t;
+15
View File
@@ -0,0 +1,15 @@
#ifndef _BITS_TIMER_H
#define _BITS_TIMER_H
/** @file
*
* i386-specific timer API implementations
*
*/
FILE_LICENCE ( GPL2_OR_LATER );
#include <gpxe/bios_timer.h>
#include <gpxe/rdtsc_timer.h>
#endif /* _BITS_TIMER_H */

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