annotate keiko/exec.h @ 1:b5139af1a420 tip basis

Fixed permissions on compile scripts
author Mike Spivey <mike@cs.ox.ac.uk>
date Fri, 13 Oct 2017 17:27:58 +0100
parents bfdcc3820b32
children
rev   line source
0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
1 /*
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
2 * exec.h
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
3 *
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
4 * This file is part of the Oxford Oberon-2 compiler
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
5 * Copyright (c) 2006--2016 J. M. Spivey
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
6 * All rights reserved
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
7 *
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
8 * Redistribution and use in source and binary forms, with or without
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
9 * modification, are permitted provided that the following conditions are met:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
10 *
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
11 * 1. Redistributions of source code must retain the above copyright notice,
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
12 * this list of conditions and the following disclaimer.
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
13 * 2. Redistributions in binary form must reproduce the above copyright notice,
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
14 * this list of conditions and the following disclaimer in the documentation
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
15 * and/or other materials provided with the distribution.
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
16 * 3. The name of the author may not be used to endorse or promote products
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
17 * derived from this software without specific prior written permission.
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
18 *
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
25 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
27 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
28 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
29 */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
30
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
31 /*
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
32 The binary file output by the linker and input by the run-time
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
33 interpreter consists of several segments followed by a trailer that
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
34 describes the layout of the segments. The segments may be preceded
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
35 by a block of arbitrary data, but they must appear in the following order:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
36
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
37 CODE, DATA, RELOC, SYMTAB
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
38
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
39 By using a trailer rather than a header, we allow for a binary file
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
40 also to be a valid file in another format that uses a header -- like
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
41 the executable format of most operating systems including various
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
42 Unixes and MS--DOS. In that format, our code is just junk beyond the
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
43 end of the file, and it is usually ignored. So we can make
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
44 self-contained executables by concatenating the interpreter with the
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
45 code for a program. This idea was stolen from CAML Light.
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
46 */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
47
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
48 /* Codes for the segments: they must appear in the object file
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
49 in this order */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
50 #define NSEGS 4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
51 #define S_CODE 0 /* Bytecode */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
52 #define S_DATA 1 /* Initialized data */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
53 #define S_BSS 2 /* Below stack storage */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
54 #define S_STACK 3 /* Stack */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
55
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
56 typedef uchar word4[4];
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
57
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
58 typedef struct {
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
59 word4 magic; /* Magic number 'OBCX' */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
60 word4 sig; /* Signature */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
61 word4 primsig; /* Checksum of primitives */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
62 word4 start; /* Offset of data start from end of file */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
63 word4 entry; /* Entry point */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
64 word4 gcmap; /* Global pointer map */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
65 word4 libdir; /* Location of dynamic libraries */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
66 word4 segment[NSEGS]; /* Segment sizes */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
67 word4 nprocs, nmods, nsyms; /* No. of procs, modules, symbols */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
68 } trailer;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
69
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
70
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
71 /* Layout of relocation data */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
72 #define WORD_SIZE 4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
73 #define CODES_PER_WORD 16
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
74 #define BITS_PER_CODE 2
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
75 #define CODE_MASK ((1 << BITS_PER_CODE) - 1)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
76
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
77 #define reloc_bits(buf, i) (buf[(i)/CODES_PER_WORD] >> \
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
78 ((i) % CODES_PER_WORD * BITS_PER_CODE) & CODE_MASK)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
79
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
80 /* Relocation codes */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
81 #define R_WORD 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
82 #define R_DATA 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
83 #define R_CODE 2
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
84 #define R_SUBR 3
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
85
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
86 /* Symbol tags */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
87 #define X_NONE 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
88 #define X_MODULE 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
89 #define X_PROC 2
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
90 #define X_DATA 3
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
91 #define X_LINE 4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
92 #define X_SYM 5
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
93
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
94 /* Fixed primitives */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
95 #define INTERP 0 /* Index of interpreter as primitive */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
96 #define DLTRAP 1 /* Index of dynlink trap */