xref: /netbsd-src/external/gpl3/gdb/dist/sim/d10v/endian.c (revision 2a9ac006fc2a82cb2082b71083430235e8210ae2)
1 /* If we're being compiled as a .c file, rather than being included in
2    d10v-sim.h, then ENDIAN_INLINE won't be defined yet.  */
3 
4 /* This must come before any other includes.  */
5 #include "defs.h"
6 
7 #ifndef ENDIAN_INLINE
8 #define NO_ENDIAN_INLINE
9 #include "sim-main.h"
10 #define ENDIAN_INLINE
11 #endif
12 
13 #include "d10v-sim.h"
14 
15 ENDIAN_INLINE uint16_t
16 get_word (const uint8_t *x)
17 {
18   return ((uint16_t)x[0]<<8) + x[1];
19 }
20 
21 ENDIAN_INLINE uint32_t
22 get_longword (const uint8_t *x)
23 {
24   return ((uint32_t)x[0]<<24) + ((uint32_t)x[1]<<16) + ((uint32_t)x[2]<<8) + ((uint32_t)x[3]);
25 }
26 
27 ENDIAN_INLINE int64_t
28 get_longlong (const uint8_t *x)
29 {
30   uint32_t top = get_longword (x);
31   uint32_t bottom = get_longword (x+4);
32   return (((int64_t)top)<<32) | (int64_t)bottom;
33 }
34 
35 ENDIAN_INLINE void
36 write_word (uint8_t *addr, uint16_t data)
37 {
38   addr[0] = (data >> 8) & 0xff;
39   addr[1] = data & 0xff;
40 }
41 
42 ENDIAN_INLINE void
43 write_longword (uint8_t *addr, uint32_t data)
44 {
45   addr[0] = (data >> 24) & 0xff;
46   addr[1] = (data >> 16) & 0xff;
47   addr[2] = (data >> 8) & 0xff;
48   addr[3] = data & 0xff;
49 }
50 
51 ENDIAN_INLINE void
52 write_longlong (uint8_t *addr, int64_t data)
53 {
54   write_longword (addr, (uint32_t)(data >> 32));
55   write_longword (addr+4, (uint32_t)data);
56 }
57