Fix Java long (64 bit) operations, add missing ones, fix compiler warnings
[jamvm-avr32-jem.git] / src / arch / avr32_jem.h
blob1aacb9cfb4ee4a16eae4119907e9188548d41264
1 /*
2 * Copyright (C) 2003, 2004, 2005, 2006, 2007
3 * Robert Lougher <rob@lougher.org.uk>.
5 * This file is part of JamVM.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2,
10 * or (at your option) any later version.
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.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #ifndef AVR32_JEM_H_
23 #define AVR32_JEM_H_
24 #ifdef JEM
26 #define JEM_TRAP_ENTRIES 25 //our own trap table entries,the first entry is a jump to the proper offset
27 //extern static const void* jem_trap_handlers_0_ENTRY[JEM_TRAP_ENTRIES];
29 //extern char *trap_h;
31 #define __NR_java_settrap 282
33 /**
34 * Called when exit jam vm
35 * TODO:
37 #define DESTORY_JEM_TRAPS
39 enum {
40 JEM_TRAP_HANDLER_FINISH = 1,
41 JEM_TRAP_HANDLER_SYSEX,
42 JEM_TRAP_HANDLER_UNIMPL,
45 struct jem_state {
46 uint32_t jecr;
47 uint32_t trap_pc;
48 uint32_t josp;
49 uint32_t jpc;
50 union ins_operand operand; //point to operands used by next opcode
53 /* #define JEM_DEBUG */
55 #ifdef JEM_DEBUG
56 #define jam_dprintf(arg...) jam_printf(arg)
57 #else
58 #define jam_dprintf(arg...) do {} while (0)
59 #endif
61 #define ostack_push_f32 ostack_push_u32
62 #define ostack_pop_f32 ostack_pop_u32
64 #define OSTACK_ASCENDING
66 #ifdef OSTACK_ASCENDING
68 #define ostack_overflows(base, size, top) ((base) + (size) >= (top))
70 #ifndef OSTACK_DEBUG
72 #define ostack_push_u32(base, size, top, data) ({ \
73 *(typeof(data) *)(top)++ = (data); \
74 0; \
77 #define ostack_pop_u32(base, size, top, data) ({ \
78 (data) = *(typeof(data) *)--(top); \
79 0; \
83 * JEM hardware stores 64-bit values on stack as two 32-bit words: word2 above,
84 * word1 below, where word2 holds high order, and word1 low order bytes. With
85 * stack growing from low to high addresses on a big-endian platform this makes:
86 * w1b3 w1b2 w1b1 w1b0 w2b3 w2b2 w2b1 w2b0
87 * whereas a native 64-bit word is stored as
88 * b7 b6 b5 b4 b3 b2 b1 b0
89 * which means inverted word order. We have to fix it by swapping them.
92 * Prototypes:
93 * int ostack_push_u64(base, size, unsigned int *top, unsigned int *data);
95 #define ostack_push_u64(base, size, top, data) ({ \
96 *(top) = *((data) + 1); \
97 *((top) + 1) = *(data); \
98 top = (typeof(top))((char *)(top) + 8); \
99 0; \
102 #define ostack_pop_u64(base, size, top, data) ({ \
103 *((data) + 1) = *((top) - 2); \
104 *(data) = *((top) - 1 ); \
105 top = (typeof(top))((char *)(top) - 8); \
106 0; \
109 #define ostack_read_u32(base, top, offset, data) ({ \
110 *(data) = *(typeof(data))((top) - (offset) - 1);\
111 0; \
114 #define ostack_push_f32(base, size, top, data) ({ \
115 *(float *)(top) = (data); \
116 (top)++; \
117 0; \
120 #define ostack_pop_f32(base, size, top, data) ({ \
121 (data) = *(float *)--(top); \
122 0; \
125 #define ostack_address(base, size, offset) ((base) + (offset))
127 #define ostack_depth(base, top) ((top) - (base))
129 #else
131 #define ostack_push_u32(base, size, top, data) ({ \
132 if ((size) <= (top) - (base)) \
133 -ENOMEM; \
134 else { \
135 *(top)++ = (data); \
136 0; \
140 #define ostack_pop_u32(base, size, top, data) ({ \
141 if ((top) <= (base)) \
142 -ENOMEM; \
143 else { \
144 (data) = *--(top); \
145 0; \
149 #error FIXME: fix *_u64 ops to swap words as above
151 #define ostack_push_u64(base, size, top, data) ({ \
152 if ((size) <= (top) - (base)) \
153 -ENOMEM; \
154 else { \
155 *(uint64_t *)(top) = *(uint64_t *)(data); \
156 (top) = (typeof(top))((uint64_t *)top + 1); \
157 0; \
161 #define ostack_pop_u64(base, size, top, data) ({ \
162 if ((top) <= (base)) \
163 -ENOMEM; \
164 else { \
165 (top) = (typeof(top))((uint64_t *)(top) - 1); \
166 *(uint64_t *)(data) = *(uint64_t *)(top); \
167 0; \
171 #define ostack_read_u32(base, top, offset, data) ({ \
172 uint32_t _o = (offset), _t = (top); \
173 if (_o > _t - (base)) \
174 -ENOMEM; \
175 else { \
176 *(data) = *(_t - _o - 1); \
177 0; \
181 #define ostack_address(base, size, offset) ({ \
182 uint32_t _o = (offset); \
183 if (_o >= (size)) \
184 -ENOMEM; \
185 else \
186 (base) + _o; \
189 #define ostack_depth(base, top) ({ \
190 uint32_t _b = (base), _t = (top); \
191 if (_t < _b) \
192 -ENOMEM; \
193 else \
194 _t - _b; \
197 #endif
198 #else
199 #error "Descending Operand Stack not implemented and probably will never be"
200 #endif
202 #endif /*JEM*/
203 #endif /*AVR32_JEM_H_*/