1 /* ----------------------------------------------------------------------- *
3 * Copyright 2007 H. Peter Anvin - All Rights Reserved
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, Inc., 53 Temple Place Ste 330,
8 * Boston MA 02111-1307, USA; either version 2 of the License, or
9 * (at your option) any later version; incorporated herein by reference.
11 * ----------------------------------------------------------------------- */
19 * Access functions for littleendian numbers, possibly misaligned.
21 static inline uint8_t get_8(const unsigned char *p
)
23 return *(const uint8_t *)p
;
26 static inline uint16_t get_16(const unsigned char *p
)
28 #if defined(__i386__) || defined(__x86_64__)
29 /* Littleendian and unaligned-capable */
30 return *(const uint16_t *)p
;
32 return (uint16_t)p
[0] + ((uint16_t)p
[1] << 8);
36 static inline uint32_t get_32(const unsigned char *p
)
38 #if defined(__i386__) || defined(__x86_64__)
39 /* Littleendian and unaligned-capable */
40 return *(const uint32_t *)p
;
42 return (uint32_t)p
[0] + ((uint32_t)p
[1] << 8) +
43 ((uint32_t)p
[2] << 16) + ((uint32_t)p
[3] << 24);
47 static inline void set_16(unsigned char *p
, uint16_t v
)
49 #if defined(__i386__) || defined(__x86_64__)
50 /* Littleendian and unaligned-capable */
54 p
[1] = ((v
>> 8) & 0xff);
58 static inline void set_32(unsigned char *p
, uint32_t v
)
60 #if defined(__i386__) || defined(__x86_64__)
61 /* Littleendian and unaligned-capable */
65 p
[1] = ((v
>> 8) & 0xff);
66 p
[2] = ((v
>> 16) & 0xff);
67 p
[3] = ((v
>> 24) & 0xff);
71 #define SECTOR_SHIFT 9 /* 512-byte sectors */
72 #define SECTOR_SIZE (1 << SECTOR_SHIFT)
74 #endif /* SYSLXINT_H */