diff options
-rw-r--r-- | biosdecode.c | 16 | ||||
-rw-r--r-- | dmidecode.c | 54 | ||||
-rw-r--r-- | ownership.c | 2 | ||||
-rw-r--r-- | types.h | 55 |
4 files changed, 55 insertions, 72 deletions
diff --git a/biosdecode.c b/biosdecode.c index ceed04a..5b161d1 100644 --- a/biosdecode.c +++ b/biosdecode.c @@ -63,22 +63,6 @@ #include "types.h" #include "util.h" -#ifdef BIGENDIAN -typedef struct { - u32 h; - u32 l; -} u64; -#else /* BIGENDIAN */ -typedef struct { - u32 l; - u32 h; -} u64; -#endif /* BIGENDIAN */ - -#define WORD(x) (*(const u16 *)(x)) -#define DWORD(x) (*(const u32 *)(x)) -#define QWORD(x) (*(const u64 *)(x)) - struct bios_entry { const char *anchor; off_t low_address; diff --git a/dmidecode.c b/dmidecode.c index c6a2959..cb9318b 100644 --- a/dmidecode.c +++ b/dmidecode.c @@ -69,60 +69,6 @@ static const char *out_of_spec = "<OUT OF SPEC>"; static const char *bad_index = "<BAD INDEX>"; -/* - * The specification isn't very clear on endianness problems, so we better - * have macros for these. It also helps us solve problems on systems that - * don't support non-aligned memory access. This isn't a big issue IMHO, - * since SMBIOS/DMI is intended mainly for Intel and compatible systems, - * which are little-endian and support non-aligned memory access. Anyway, - * you may use the following defines to control the way it works: - * - Define BIGENDIAN on big-endian systems. - * - Define ALIGNMENT_WORKAROUND if your system doesn't support - * non-aligned memory access. In this case, we use a slower, but safer, - * memory access method. - * You most probably will have to define none or the two of them. - */ - -#ifdef BIGENDIAN -typedef struct { - u32 h; - u32 l; -} u64; -#else -typedef struct { - u32 l; - u32 h; -} u64; -#endif - -#ifdef ALIGNMENT_WORKAROUND -static u64 U64(u32 low, u32 high) -{ - u64 self; - - self.l=low; - self.h=high; - - return self; -} -#endif - -#ifdef ALIGNMENT_WORKAROUND -# ifdef BIGENDIAN -# define WORD(x) (u16)((x)[1]+((x)[0]<<8)) -# define DWORD(x) (u32)((x)[3]+((x)[2]<<8)+((x)[1]<<16)+((x)[0]<<24)) -# define QWORD(x) (U64(DWORD(x+4), DWORD(x))) -# else /* BIGENDIAN */ -# define WORD(x) (u16)((x)[0]+((x)[1]<<8)) -# define DWORD(x) (u32)((x)[0]+((x)[1]<<8)+((x)[2]<<16)+((x)[3]<<24)) -# define QWORD(x) (U64(DWORD(x), DWORD(x+4))) -# endif /* BIGENDIAN */ -#else /* ALIGNMENT_WORKAROUND */ -#define WORD(x) (u16)(*(u16 *)(x)) -#define DWORD(x) (u32)(*(u32 *)(x)) -#define QWORD(x) (*(u64 *)(x)) -#endif /* ALIGNMENT_WORKAROUND */ - struct dmi_header { u8 type; diff --git a/ownership.c b/ownership.c index c8022b8..2d41a23 100644 --- a/ownership.c +++ b/ownership.c @@ -40,8 +40,6 @@ #include "types.h" #include "util.h" -#define DWORD(x) (*(const u32 *)(x)) - static void ownership(int fd, u32 base, const char *pname, const char *devmem) { u8 *buf; @@ -1,7 +1,62 @@ #ifndef TYPES_H #define TYPES_H + typedef unsigned char u8; typedef unsigned short u16; typedef signed short i16; typedef unsigned int u32; + +/* + * These macros help us solve problems on systems that don't support + * non-aligned memory access. This isn't a big issue IMHO, since the tools + * in this package are intended mainly for Intel and compatible systems, + * which are little-endian and support non-aligned memory access. Anyway, + * you may use the following defines to control the way it works: + * - Define BIGENDIAN on big-endian systems. + * - Define ALIGNMENT_WORKAROUND if your system doesn't support + * non-aligned memory access. In this case, we use a slower, but safer, + * memory access method. + * You most probably will have to define none or the two of them. + */ + +#ifdef BIGENDIAN +typedef struct { + u32 h; + u32 l; +} u64; +#else +typedef struct { + u32 l; + u32 h; +} u64; +#endif + +#ifdef ALIGNMENT_WORKAROUND +static u64 U64(u32 low, u32 high) +{ + u64 self; + + self.l=low; + self.h=high; + + return self; +} +#endif + +#ifdef ALIGNMENT_WORKAROUND +# ifdef BIGENDIAN +# define WORD(x) (u16)((x)[1]+((x)[0]<<8)) +# define DWORD(x) (u32)((x)[3]+((x)[2]<<8)+((x)[1]<<16)+((x)[0]<<24)) +# define QWORD(x) (U64(DWORD(x+4), DWORD(x))) +# else /* BIGENDIAN */ +# define WORD(x) (u16)((x)[0]+((x)[1]<<8)) +# define DWORD(x) (u32)((x)[0]+((x)[1]<<8)+((x)[2]<<16)+((x)[3]<<24)) +# define QWORD(x) (U64(DWORD(x), DWORD(x+4))) +# endif /* BIGENDIAN */ +#else /* ALIGNMENT_WORKAROUND */ +#define WORD(x) (u16)(*(const u16 *)(x)) +#define DWORD(x) (u32)(*(const u32 *)(x)) +#define QWORD(x) (*(const u64 *)(x)) +#endif /* ALIGNMENT_WORKAROUND */ + #endif |