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.
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
34 * Called when exit jam vm
37 #define DESTORY_JEM_TRAPS
40 JEM_TRAP_HANDLER_FINISH
= 1,
41 JEM_TRAP_HANDLER_SYSEX
,
42 JEM_TRAP_HANDLER_UNIMPL
,
50 union ins_operand operand
; //point to operands used by next opcode
53 /* #define JEM_DEBUG */
56 #define jam_dprintf(arg...) jam_printf(arg)
58 #define jam_dprintf(arg...) do {} while (0)
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))
72 #define ostack_push_u32(base, size, top, data) ({ \
73 *(typeof(data) *)(top)++ = (data); \
77 #define ostack_pop_u32(base, size, top, data) ({ \
78 (data) = *(typeof(data) *)--(top); \
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); \
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); \
106 #define ostack_read_u32(base, top, offset, data) ({ \
107 *(data) = *(typeof(data))((top) - (offset) - 1);\
111 #define ostack_push_f32(base, size, top, data) ({ \
112 *(float *)(top) = (data); \
117 #define ostack_pop_f32(base, size, top, data) ({ \
118 (data) = *(float *)--(top); \
122 #define ostack_address(base, size, offset) ((base) + (offset))
124 #define ostack_depth(base, top) ((top) - (base))
128 #define ostack_push_u32(base, size, top, data) ({ \
129 if ((size) <= (top) - (base)) \
137 #define ostack_pop_u32(base, size, top, data) ({ \
138 if ((top) <= (base)) \
146 #define ostack_push_u64(base, size, top, data) ({ \
147 if ((size) <= (top) - (base)) \
150 *(uint64_t *)(top) = *(uint64_t *)&(data); \
151 (top) = (typeof(top))((uint64_t *)top + 1); \
156 #define ostack_pop_u64(base, size, top, data) ({ \
157 if ((top) <= (base)) \
160 (top) = (typeof(top))((uint64_t *)(top) - 1); \
161 *(uint64_t *)&(data) = *(uint64_t *)(top); \
166 #define ostack_read_u32(base, top, offset, data) ({ \
167 uint32_t _o = (offset), _t = (top); \
168 if (_o > _t - (base)) \
171 *(data) = *(_t - _o - 1); \
176 #define ostack_address(base, size, offset) ({ \
177 uint32_t _o = (offset); \
184 #define ostack_depth(base, top) ({ \
185 uint32_t _b = (base), _t = (top); \
194 #error "Descending Operand Stack not implemented and probably will never be"
198 #endif /*AVR32_JEM_H_*/