Commit | Line | Data |
---|---|---|
fee8ec00 | 1 | /* Simulation code for the CR16 processor. |
32d0add0 | 2 | Copyright (C) 2008-2015 Free Software Foundation, Inc. |
fee8ec00 SR |
3 | Contributed by M Ranga Swami Reddy <MR.Swami.Reddy@nsc.com> |
4 | ||
5 | This file is part of GDB, the GNU debugger. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
dc3cf14f | 9 | the Free Software Foundation; either version 3, or (at your option) |
fee8ec00 SR |
10 | any later version. |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
ccd2d1c8 SR |
17 | You should have received a copy of the GNU General Public License |
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
fee8ec00 SR |
19 | |
20 | ||
21 | /* If we're being compiled as a .c file, rather than being included in | |
22 | cr16_sim.h, then ENDIAN_INLINE won't be defined yet. */ | |
23 | ||
24 | #ifndef ENDIAN_INLINE | |
25 | #define NO_ENDIAN_INLINE | |
26 | #include "cr16_sim.h" | |
27 | #define ENDIAN_INLINE | |
28 | #endif | |
29 | ||
30 | ENDIAN_INLINE uint16 | |
5aedb83b | 31 | get_word (uint8 *x) |
fee8ec00 SR |
32 | { |
33 | return *(uint16 *)x; | |
34 | } | |
35 | ||
36 | ENDIAN_INLINE uint32 | |
5aedb83b | 37 | get_longword (uint8 *x) |
fee8ec00 SR |
38 | { |
39 | return (((uint32) *(uint16 *)x) << 16) | ((uint32) *(uint16 *)(x+2)); | |
40 | } | |
41 | ||
42 | ENDIAN_INLINE int64 | |
5aedb83b | 43 | get_longlong (uint8 *x) |
fee8ec00 SR |
44 | { |
45 | uint32 top = get_longword (x); | |
46 | uint32 bottom = get_longword (x+4); | |
47 | return (((int64)top)<<32) | (int64)bottom; | |
48 | } | |
49 | ||
50 | ENDIAN_INLINE void | |
5aedb83b | 51 | write_word (uint8 *addr, uint16 data) |
fee8ec00 SR |
52 | { |
53 | addr[1] = (data >> 8) & 0xff; | |
54 | addr[0] = data & 0xff; | |
55 | ||
56 | } | |
57 | ||
58 | ENDIAN_INLINE void | |
5aedb83b | 59 | write_longword (uint8 *addr, uint32 data) |
fee8ec00 SR |
60 | { |
61 | *(uint16 *)(addr + 2) = (uint16)(data >> 16); | |
62 | *(uint16 *)(addr) = (uint16)data; | |
63 | } | |
64 | ||
65 | ENDIAN_INLINE void | |
5aedb83b | 66 | write_longlong (uint8 *addr, int64 data) |
fee8ec00 SR |
67 | { |
68 | write_longword (addr+4, (uint32)(data >> 32)); | |
69 | write_longword (addr, (uint32)data); | |
70 | } |