Implement TABLESWITCH opcode
[jamvm-avr32-jem.git] / src / arch / avr32_jem.h
blob06d01c936298e5ec60c21eec3b65eefd17382889
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 #define ostack_push_u64(base, size, top, data) ({ \
93 *(uint32_t *)(top) = *((uint32_t *)&(data) + 1); \
94 *((uint32_t *)(top) + 1) = *(uint32_t *)&(data); \
95 (top) = (typeof(top))((uint64_t *)(top) + 1); \
96 0; \
99 #define ostack_pop_u64(base, size, top, data) ({ \
100 *((uint32_t *)&(data) + 1) = *((uint32_t *)(top) - 2); \
101 *(uint32_t *)&(data) = *((uint32_t *)(top) - 1 ); \
102 (top) = (typeof(top))((uint64_t *)(top) - 1); \
103 0; \
106 #define ostack_read_u32(base, top, offset, data) ({ \
107 *(data) = *(typeof(data))((top) - (offset) - 1);\
108 0; \
111 #define ostack_push_f32(base, size, top, data) ({ \
112 *(float *)(top) = (data); \
113 (top)++; \
114 0; \
117 #define ostack_pop_f32(base, size, top, data) ({ \
118 (data) = *(float *)--(top); \
119 0; \
122 #define ostack_address(base, size, offset) ((base) + (offset))
124 #define ostack_depth(base, top) ((top) - (base))
126 #else
128 #define ostack_push_u32(base, size, top, data) ({ \
129 if ((size) <= (top) - (base)) \
130 -ENOMEM; \
131 else { \
132 *(top)++ = (data); \
133 0; \
137 #define ostack_pop_u32(base, size, top, data) ({ \
138 if ((top) <= (base)) \
139 -ENOMEM; \
140 else { \
141 (data) = *--(top); \
142 0; \
146 #define ostack_push_u64(base, size, top, data) ({ \
147 if ((size) <= (top) - (base)) \
148 -ENOMEM; \
149 else { \
150 *(uint64_t *)(top) = *(uint64_t *)&(data); \
151 (top) = (typeof(top))((uint64_t *)top + 1); \
152 0; \
156 #define ostack_pop_u64(base, size, top, data) ({ \
157 if ((top) <= (base)) \
158 -ENOMEM; \
159 else { \
160 (top) = (typeof(top))((uint64_t *)(top) - 1); \
161 *(uint64_t *)&(data) = *(uint64_t *)(top); \
162 0; \
166 #define ostack_read_u32(base, top, offset, data) ({ \
167 uint32_t _o = (offset), _t = (top); \
168 if (_o > _t - (base)) \
169 -ENOMEM; \
170 else { \
171 *(data) = *(_t - _o - 1); \
172 0; \
176 #define ostack_address(base, size, offset) ({ \
177 uint32_t _o = (offset); \
178 if (_o >= (size)) \
179 -ENOMEM; \
180 else \
181 (base) + _o; \
184 #define ostack_depth(base, top) ({ \
185 uint32_t _b = (base), _t = (top); \
186 if (_t < _b) \
187 -ENOMEM; \
188 else \
189 _t - _b; \
192 #endif
193 #else
194 #error "Descending Operand Stack not implemented and probably will never be"
195 #endif
197 #endif /*JEM*/
198 #endif /*AVR32_JEM_H_*/