]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - sim/d10v/endian.c
bfd: add stdlib.h when using abort
[thirdparty/binutils-gdb.git] / sim / d10v / endian.c
CommitLineData
c906108c
SS
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#ifndef ENDIAN_INLINE
5#define NO_ENDIAN_INLINE
67954606 6#include "sim-main.h"
c906108c
SS
7#define ENDIAN_INLINE
8#endif
9
10ENDIAN_INLINE uint16
11558abc 11get_word (uint8 *x)
c906108c 12{
c906108c 13 return ((uint16)x[0]<<8) + x[1];
c906108c
SS
14}
15
16ENDIAN_INLINE uint32
11558abc 17get_longword (uint8 *x)
c906108c 18{
c906108c 19 return ((uint32)x[0]<<24) + ((uint32)x[1]<<16) + ((uint32)x[2]<<8) + ((uint32)x[3]);
c906108c
SS
20}
21
22ENDIAN_INLINE int64
11558abc 23get_longlong (uint8 *x)
c906108c
SS
24{
25 uint32 top = get_longword (x);
26 uint32 bottom = get_longword (x+4);
27 return (((int64)top)<<32) | (int64)bottom;
28}
29
30ENDIAN_INLINE void
11558abc 31write_word (uint8 *addr, uint16 data)
c906108c 32{
c906108c
SS
33 addr[0] = (data >> 8) & 0xff;
34 addr[1] = data & 0xff;
c906108c
SS
35}
36
37ENDIAN_INLINE void
11558abc 38write_longword (uint8 *addr, uint32 data)
c906108c 39{
c906108c
SS
40 addr[0] = (data >> 24) & 0xff;
41 addr[1] = (data >> 16) & 0xff;
42 addr[2] = (data >> 8) & 0xff;
43 addr[3] = data & 0xff;
c906108c
SS
44}
45
46ENDIAN_INLINE void
11558abc 47write_longlong (uint8 *addr, int64 data)
c906108c
SS
48{
49 write_longword (addr, (uint32)(data >> 32));
50 write_longword (addr+4, (uint32)data);
51}