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.
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); \
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); \
109 #define ostack_read_u32(base, top, offset, data) ({ \
110 *(data) = *(typeof(data))((top) - (offset) - 1);\
114 #define ostack_push_f32(base, size, top, data) ({ \
115 *(float *)(top) = (data); \
120 #define ostack_pop_f32(base, size, top, data) ({ \
121 (data) = *(float *)--(top); \
125 #define ostack_address(base, size, offset) ((base) + (offset))
127 #define ostack_depth(base, top) ((top) - (base))
131 #define ostack_push_u32(base, size, top, data) ({ \
132 if ((size) <= (top) - (base)) \
140 #define ostack_pop_u32(base, size, top, data) ({ \
141 if ((top) <= (base)) \
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)) \
155 *(uint64_t *)(top) = *(uint64_t *)(data); \
156 (top) = (typeof(top))((uint64_t *)top + 1); \
161 #define ostack_pop_u64(base, size, top, data) ({ \
162 if ((top) <= (base)) \
165 (top) = (typeof(top))((uint64_t *)(top) - 1); \
166 *(uint64_t *)(data) = *(uint64_t *)(top); \
171 #define ostack_read_u32(base, top, offset, data) ({ \
172 uint32_t _o = (offset), _t = (top); \
173 if (_o > _t - (base)) \
176 *(data) = *(_t - _o - 1); \
181 #define ostack_address(base, size, offset) ({ \
182 uint32_t _o = (offset); \
189 #define ostack_depth(base, top) ({ \
190 uint32_t _b = (base), _t = (top); \
199 #error "Descending Operand Stack not implemented and probably will never be"
203 #endif /*AVR32_JEM_H_*/