w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

obx.h
Go to the documentation of this file.
1 /*
2  * obx.h
3  *
4  * This file is part of the Oxford Oberon-2 compiler
5  * Copyright (c) 2006--2016 J. M. Spivey
6  * All rights reserved
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright notice,
12  * this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright notice,
14  * this list of conditions and the following disclaimer in the documentation
15  * and/or other materials provided with the distribution.
16  * 3. The name of the author may not be used to endorse or promote products
17  * derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef _OBX_H
32 #define _OBX_H 1
33 
34 #ifdef TRACE
35 #define DEBUG 1
36 #endif
37 
38 #include "config.h"
39 #include <stdio.h>
40 #include "obcommon.h"
41 
42 #define SLIMIT 256 /* Min stack space space left (bytes) */
43 
44 typedef union value value;
45 
46 typedef value *primitive(value *sp);
47 
48 typedef uint32_t word;
50 
51 union value {
52  int i;
53  float f;
55 };
56 
57 #define valptr(v) ptrcast(value, (v).a)
58 #define pointer(v) ptrcast(void, (v).a)
59 
60 #ifdef SEGMEM
61 
62 #define SEGBITS 20
63 #define SEGMENT (1 << SEGBITS)
64 #define SEGMASK ((1 << SEGBITS)-1)
65 #define NSEGMENTS 4096
66 
67 #define stkaddr(p) (stack_vbase + ((uchar *) (p) - stack))
68 #define dsegaddr(p) (data_vbase + ((uchar *) (p) - dmem))
69 #define ptrcast(t, a) ((t *) physmap(a))
70 
71 extern void *segmap[];
73 
74 #define physmap(a) \
75  ((void *) ((char *) segmap[(a) >> SEGBITS] + ((a) & SEGMASK)))
76 
77 /*
78 static inline void *physmap(unsigned a) {
79  return (char *) segmap[a >> SEGBITS] + (a & SEGMASK);
80 }
81 */
82 
83 #else
84 
85 #define pun_memory(p) ((word) (ptrtype) (p))
86 #define stkaddr(p) pun_memory(p)
87 #define dsegaddr(p) pun_memory(p)
88 #define ptrcast(t, a) ((t *) (ptrtype) (a))
89 
90 #endif
91 
92 #define codeaddr(p) ((p) - imem)
93 #define codeptr(v) (imem + (v))
94 
95 typedef struct _proc *proc;
96 typedef struct _module *module;
97 typedef struct _arc *arc;
98 
99 #ifdef PROFILE
100 typedef uint64_t counter;
101 #endif
102 
103 struct _proc {
104  const char *p_name; /* Procedure name */
105  word p_addr; /* Address of descriptor in data space */
106 #ifdef PROFILE
107  int p_index; /* Position in listing */
108  unsigned p_calls; /* Call count */
109  unsigned p_rec; /* Call count for recursion */
110  counter p_self; /* Tick count for self */
111  counter p_child; /* Tick count for children */
112  arc p_parents; /* List of callers */
113  arc p_children; /* List of procs we call */
114 #endif
115 };
116 
117 struct _module {
118  char *m_name; /* Layout must match proc */
120  int m_length;
121 #ifdef PROFILE
122  int m_nlines;
123  unsigned *m_lcount;
124 #endif
125 };
126 
127 
128 /* Global variables */
129 EXTERN uchar *imem, *dmem; /* Instruction and data memory arrays */
130 EXTERN uchar *stack; /* Program stack */
131 EXTERN int code_size; /* Size of program code */
132 EXTERN int stack_size; /* Size of main stack */
133 EXTERN char *libpath; /* Path to dynamic library */
134 EXTERN value *entry; /* Program entry point */
135 EXTERN value *gcmap; /* Global pointer map */
137 #ifdef USE_FFI
138 EXTERN word dynstub;
139 #endif
140 
141 #define interpreted(p) ((p)[CP_PRIM].a == interpreter)
142 
143 #ifndef M64X32
144 #define primcall(p, sp) ((primitive *) p[CP_PRIM].a)(sp)
145 #else
146 #ifdef JIT
147 #define primcall(p, sp) (ptrcast(primitive, p[CP_PRIM].a))(sp)
148 #else
149 #define primcall(p, sp) (*ptrcast(primitive *, p[CP_PRIM].a))(sp)
150 #endif
151 #endif
152 
153 #define get1(p) ((int) ((signed char) (p)[0]))
154 #define get2(p) ((int) ((short) (((p)[1]<<8) + (p)[0])))
155 
159 
160 extern struct primdef {
161  char *p_name;
164 
165 EXTERN int level; /* Recursion level in bytecode interp. */
166 #ifdef OBXDEB
167 EXTERN value *prim_bp; /* Base pointer during primitive call */
168 #endif
169 
170 EXTERN int dflag;
172 #ifdef PROFILE
173 EXTERN mybool lflag;
174 #endif
175 #ifdef TRACE
176 EXTERN int qflag;
177 #endif
178 #ifdef OBXDEB
179 EXTERN char *debug_socket;
180 #endif
181 
182 
183 /* profile.c */
184 #ifdef PROFILE
185 void prof_enter(word p, counter ticks, int why);
186 void prof_exit(word p, counter ticks);
187 void prof_init(void);
188 void prof_reset(proc p);
189 void profile(FILE *fp);
190 
191 #define PROF_CALL 1
192 #define PROF_TAIL 2
193 #define PROF_PRIM 3
194 #endif
195 
196 /* interp.c */
198 
199 /* xmain.c */
200 EXTERN int saved_argc;
201 EXTERN char **saved_argv;
202 
203 void xmain_exit(int status);
204 void error_exit(int status);
205 
206 /* support.c */
207 int ob_div(int a, int b);
208 int ob_mod(int a, int b);
209 
210 void int_div(value *sp);
211 void int_mod(value *sp);
212 
213 void long_add(value *sp);
214 void long_sub(value *sp);
215 void long_mul(value *sp);
216 void long_div(value *sp);
217 void long_mod(value *sp);
218 void long_neg(value *sp);
219 void long_cmp(value *sp);
220 void long_flo(value *sp);
221 void long_ext(value *sp);
222 void long_zcheck(value *sp);
223 
224 void flo_add(value *sp);
225 void flo_sub(value *sp);
226 void flo_mul(value *sp);
227 void flo_div(value *sp);
228 void flo_neg(value *sp);
229 void flo_float(value *sp);
230 void flo_fix(value *sp);
231 void flo_cmpl(value *sp);
232 void flo_cmpg(value *sp);
233 void flo_trunc(value *sp);
234 void dbl_add(value *sp);
235 void dbl_sub(value *sp);
236 void dbl_mul(value *sp);
237 void dbl_div(value *sp);
238 void dbl_neg(value *sp);
239 void dbl_float(value *sp);
240 void dbl_fix(value *sp);
241 void dbl_cmpl(value *sp);
242 void dbl_cmpg(value *sp);
243 void dbl_widen(value *sp);
244 void flo_zcheck(value *sp);
245 void dbl_zcheck(value *sp);
246 
248 
249 /* load_file -- load a file of object code */
250 void load_file(FILE *bfp);
251 void load_image(void);
252 
253 void make_module(char *name, word addr, int chsum, int nlines);
254 void make_proc(char *name, word addr);
255 void make_symbol(const char *kind, char *name, word addr);
256 void fix_sizes(int dseg);
257 
258 void panic(const char *, ...);
259 void obcopy(char *dst, int dlen, const char *src, int slen, value *bp);
260 
261 void error_stop(const char *msg, int val, int line, value *bp, uchar *pc);
262 void runtime_error(int num, int line, value *bp, uchar *pc);
263 void rterror(int num, int line, value *bp);
264 void stkoflo(value *bp);
265 #define liberror(msg) error_stop(msg, 0, 0, bp, NULL)
266 
267 proc find_symbol(word p, proc *table, int nelem);
268 #define find_proc(cp) find_symbol(cp, proctab, nprocs)
269 #define find_module(cp) ((module) find_symbol(cp, (proc *) modtab, nmods))
270 
271 #ifdef TRACE
272 char *fmt_inst(uchar *pc);
273 void dump(void);
274 const char *prim_name(value *p);
275 #endif
276 
277 #ifdef UNALIGNED_MEM
278 #define get_double(v) (* (double *) (v))
279 #define put_double(v, x) (* (double *) (v) = (x))
280 #define get_long(v) (* (longint *) (v))
281 #define put_long(v, x) (* (longint *) (v) = (x))
282 #else
283 double get_double(value *v);
284 void put_double(value *v, double x);
286 void put_long(value *v, longint w);
287 #endif
288 
289 double flo_conv(int);
290 double flo_convq(longint);
291 
292 
293 /* gc.c */
294 
295 /* scratch_alloc -- allocate memory that will not be freed */
296 void *scratch_alloc(unsigned bytes);
297 
298 #ifdef USE_BOEHM
299 /* scratch_alloc_atomic -- allocate memory that will not contain pointers */
300 void *scratch_alloc_atomic(unsigned bytes);
301 #else
302 #define scratch_alloc_atomic(bytes) scratch_alloc(bytes)
303 #endif
304 
305 #ifdef SEGMEM
306 
307 word virtual_alloc(unsigned bytes);
308 word map_segment(void *base, unsigned length);
309 #define virtual_alloc_atomic(bytes) virtual_alloc(bytes)
310 
311 #else
312 
313 #define virtual_alloc(bytes) pun_memory(scratch_alloc(bytes))
314 #define virtual_alloc_atomic(bytes) pun_memory(scratch_alloc_atomic(bytes))
315 
316 #endif
317 
318 /* gc_alloc -- allocate an object on the managed heap */
319 word gc_alloc(unsigned size, value *sp);
320 
321 /* gc_collect -- run the garbage collector */
323 
324 /* gc_heap_size -- return size of heap */
325 int gc_heap_size(void);
326 
327 extern mybool gcflag;
328 void gc_init(void);
329 void gc_dump(void);
330 
331 /* debug.c */
332 #ifdef OBXDEB
333 extern mybool one_shot;
334 extern mybool intflag;
335 
336 void debug_init(void);
337 void debug_message(char *fmt, ...);
338 void debug_break(value *cp, value *bp, uchar *pc, char *fmt, ...);
339 #endif
340 
341 /* jit.c */
342 #ifdef JIT
343 void jit_compile(value *cp);
344 value *jit_trap(value *cp);
345 #endif
346 
347 #ifdef __cplusplus
348 #define PRIMDEF extern "C"
349 #else
350 #define PRIMDEF
351 #endif
352 
353 #ifdef NEED_FPINIT
354 /* On x86, each primitive re-initialises the FP unit, so that values
355  left behind in registers by the caller do not cause stack overflow. */
356 #define FPINIT asm ("fninit")
357 #else
358 #define FPINIT
359 #endif
360 
361 #endif
bp
Definition: action.c:1035
cp
Definition: action.c:1035
#define name
static two_halves prim[2100+1]
Definition: aptex.h:393
#define b
Definition: jpegint.h:372
long pc
Definition: disdvi.c:114
int w
Definition: dviconv.c:26
int v
Definition: dviconv.c:10
#define a(n)
Definition: gpos-common.c:148
int base
Definition: gsftopk.c:1502
#define slen
Definition: hpcdtoppm.c:1329
int kind
Definition: image.c:8980
#define EXTERN(type)
Definition: jmorecfg.h:190
unsigned char uchar
Definition: unzcrash.c:37
small capitals from c petite p
Definition: afcover.h:72
unsigned int uint32_t
Definition: stdint.h:80
unsigned int uintptr_t
Definition: stdint.h:119
unsigned __int64 uint64_t
Definition: stdint.h:90
int num
Definition: disdvi.c:621
void dump(const char *start, const char *end)
Definition: pdfparse.c:74
#define length(c)
Definition: ctangleboot.c:65
float x
Definition: cordic.py:15
int64_t longint
Definition: obcommon.h:61
int mybool
Definition: obcommon.h:37
module * modtab
void flo_float(value *sp)
Definition: support.c:136
primitive dltrap
Definition: obx.h:197
void dbl_float(value *sp)
Definition: support.c:169
void rterror(int num, int line, value *bp)
Definition: xmain.c:257
void flo_div(value *sp)
Definition: support.c:134
void long_neg(value *sp)
Definition: support.c:111
int dflag
word wrap_prim(primitive *prim)
Definition: xmain.c:627
void error_stop(const char *msg, int val, int line, value *bp, uchar *pc)
Definition: xmain.c:222
void make_proc(char *name, word addr)
Definition: xmain.c:103
uint32_t word
Definition: obx.h:48
void flo_cmpg(value *sp)
Definition: support.c:144
void make_symbol(const char *kind, char *name, word addr)
Definition: xmain.c:125
void long_flo(value *sp)
Definition: support.c:94
value * primitive(value *sp)
Definition: obx.h:46
struct primdef primtab[]
int nsyms
Definition: obx.h:156
int ob_div(int a, int b)
int gc_heap_size(void)
Definition: gc.c:1313
struct _module * module
Definition: obx.h:96
word virtual_alloc(unsigned bytes)
Definition: gc.c:321
void dbl_add(value *sp)
Definition: support.c:149
void panic(const char *,...)
Definition: error.c:149
double flo_conv(int)
Definition: support.c:212
void load_file(FILE *bfp)
value * entry
Definition: pdfdoc.c:64
void dbl_cmpl(value *sp)
Definition: support.c:177
void flo_mul(value *sp)
Definition: support.c:133
uintptr_t ptrtype
Definition: obx.h:49
word dyntrap
Definition: obx.h:136
void error_exit(int status)
Definition: xmain.c:504
void stkoflo(value *bp)
Definition: xmain.c:262
primitive interp
Definition: obx.h:197
mybool gcflag
Definition: gc.c:790
int ob_mod(int a, int b)
struct _arc * arc
Definition: obx.h:97
void flo_zcheck(value *sp)
Definition: support.c:195
word gc_alloc(unsigned size, value *sp)
Definition: gc.c:812
void flo_fix(value *sp)
Definition: support.c:137
int saved_argc
void long_mod(value *sp)
Definition: support.c:87
proc * proctab
void flo_cmpl(value *sp)
Definition: support.c:139
void load_image(void)
Definition: loader.c:304
int code_size
void flo_trunc(value *sp)
Definition: support.c:191
void long_ext(value *sp)
Definition: support.c:120
void flo_neg(value *sp)
Definition: support.c:135
void dbl_widen(value *sp)
Definition: support.c:187
void * scratch_alloc(unsigned bytes)
Definition: gc.c:289
primitive dlstub
Definition: obx.h:197
void flo_sub(value *sp)
Definition: support.c:132
char ** saved_argv
void gc_dump(void)
Definition: gc.c:1189
void long_div(value *sp)
Definition: support.c:79
void fix_sizes(int dseg)
Definition: xmain.c:132
void dbl_neg(value *sp)
Definition: support.c:165
void long_add(value *sp)
Definition: support.c:99
void dbl_cmpg(value *sp)
Definition: support.c:182
void long_mul(value *sp)
Definition: support.c:107
void xmain_exit(int status)
Definition: xmain.c:492
uchar * stack
Definition: dvistuff.c:185
uchar * dmem
Definition: obx.h:129
void runtime_error(int num, int line, value *bp, uchar *pc)
Definition: xmain.c:252
uchar * imem
char * libpath
void make_module(char *name, word addr, int chsum, int nlines)
Definition: xmain.c:79
value * gcmap
struct _proc * proc
Definition: obx.h:95
word map_segment(void *base, unsigned length)
Definition: gc.c:300
void flo_add(value *sp)
Definition: support.c:131
word data_vbase
Definition: obx.h:72
void obcopy(char *dst, int dlen, const char *src, int slen, value *bp)
Definition: support.c:222
void dbl_div(value *sp)
Definition: support.c:161
word stack_vbase
int stack_size
Definition: mainbody.c:257
void dbl_mul(value *sp)
Definition: support.c:157
int level
Definition: afm2pl.c:1694
void long_cmp(value *sp)
Definition: support.c:115
proc find_symbol(word p, proc *table, int nelem)
Definition: support.c:266
void long_sub(value *sp)
Definition: support.c:103
void put_double(value *v, double x)
Definition: support.c:243
void * segmap[]
Definition: gc.c:296
int nprocs
Definition: obx.h:156
void long_zcheck(value *sp)
Definition: support.c:124
double get_double(value *v)
Definition: support.c:236
void dbl_sub(value *sp)
Definition: support.c:153
void int_mod(value *sp)
Definition: support.c:72
void put_long(value *v, longint w)
Definition: support.c:257
void dbl_zcheck(value *sp)
Definition: support.c:200
#define scratch_alloc_atomic(bytes)
Definition: obx.h:302
value * gc_collect(value *sp)
Definition: gc.c:1249
int nmods
double flo_convq(longint)
Definition: support.c:216
mybool gflag
void int_div(value *sp)
Definition: support.c:64
word interpreter
longint get_long(value *v)
Definition: support.c:250
void gc_init(void)
Definition: gc.c:1287
void dbl_fix(value *sp)
Definition: support.c:173
static GfxLCMSProfilePtr profile
Definition: pdftocairo.cc:243
unsigned short word
Definition: picttoppm.c:64
#define fp
static int size
Definition: ppmlabel.c:24
static long bytes
Definition: psutil.c:35
#define status
Definition: obx.h:117
char * m_name
Definition: obx.h:118
word m_addr
Definition: obx.h:119
int m_length
Definition: obx.h:120
Definition: obx.h:103
const char * p_name
Definition: obx.h:104
word p_addr
Definition: obx.h:105
Definition: sed.h:84
Definition: bdf.c:133
Definition: texview.c:48
Definition: obx.h:160
char * p_name
Definition: obx.h:161
primitive * p_prim
Definition: obx.h:162
Definition: table.h:30
Definition: strexpr.c:21
#define FILE
Definition: t1stdio.h:34
char fmt[256]
Definition: tex4ht.c:3925
static struct count_rec * counter
Definition: tex4ht.c:1052
#define sp
Definition: stack.c:11
Definition: obx.h:51
word a
Definition: obx.h:54
float f
Definition: obx.h:53
int i
Definition: obx.h:52
#define ticks
Definition: utmscale.cpp:16