diff options
author | Juergen Beisert <jbe@pengutronix.de> | 2010-01-12 11:15:35 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2010-01-14 10:06:15 +0100 |
commit | 5d591e14ef15f28779a9c5aba08549129a29a550 (patch) | |
tree | 2b790198f4e3ceae59ff912b881189f3fc572106 /scripts/setupmbr/arch.h | |
parent | 6dff4e13a15cb806d835919de63c10da2f609932 (diff) | |
download | barebox-5d591e14ef15f28779a9c5aba08549129a29a550.tar.gz barebox-5d591e14ef15f28779a9c5aba08549129a29a550.tar.xz |
Add a tool to activate barebox as a boot loader on x86 architectures
To use barebox as a BIOS based bootloader for x86 architectures, the binary
must be patched to get it bootstrapped at runtime. The 'setupmbr' tool installs
the barebox-binary to the given device node or image file and patch it in
accordance to the needed sector information at runtime.
Signed-off by: Juergen Beisert <jbe@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'scripts/setupmbr/arch.h')
-rw-r--r-- | scripts/setupmbr/arch.h | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/scripts/setupmbr/arch.h b/scripts/setupmbr/arch.h new file mode 100644 index 0000000000..a720dfe95e --- /dev/null +++ b/scripts/setupmbr/arch.h @@ -0,0 +1,55 @@ + +/* we need the one from the host */ +#include <endian.h> +#include <stdint.h> + +/* Byte-orders. */ +#define swap16(x) \ +({ \ + uint16_t _x = (x); \ + (uint16_t) ((_x << 8) | (_x >> 8)); \ +}) + +#define swap32(x) \ +({ \ + uint32_t _x = (x); \ + (uint32_t) ((_x << 24) \ + | ((_x & (uint32_t) 0xFF00UL) << 8) \ + | ((_x & (uint32_t) 0xFF0000UL) >> 8) \ + | (_x >> 24)); \ +}) + +#define swap64(x) \ +({ \ + uint64_t _x = (x); \ + (uint64_t) ((_x << 56) \ + | ((_x & (uint64_t) 0xFF00ULL) << 40) \ + | ((_x & (uint64_t) 0xFF0000ULL) << 24) \ + | ((_x & (uint64_t) 0xFF000000ULL) << 8) \ + | ((_x & (uint64_t) 0xFF00000000ULL) >> 8) \ + | ((_x & (uint64_t) 0xFF0000000000ULL) >> 24) \ + | ((_x & (uint64_t) 0xFF000000000000ULL) >> 40) \ + | (_x >> 56)); \ +}) + +#if __BYTE_ORDER == __BIG_ENDIAN + +/* Our target is a ia32 machine, always little endian */ + +# define host2target_16(x) swap16(x) +# define host2target_32(x) swap32(x) +# define host2target_64(x) swap64(x) +# define target2host_16(x) swap16(x) +# define target2host_32(x) swap32(x) +# define target2host_64(x) swap64(x) + +#else + +# define host2target_16(x) (x) +# define host2target_32(x) (x) +# define host2target_64(x) (x) +# define target2host_16(x) (x) +# define target2host_32(x) (x) +# define target2host_64(x) (x) + +#endif |