1 /* DLIFE Copyright (C) 2000 Richard W.M. Jones <rich@annexia.org>
2 * and other authors listed in the ``AUTHORS'' file.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 * $Id: cell.h,v 1.1 2002/04/05 14:40:25 rich Exp $
28 #ifdef HAVE_SYS_PARAM_H
29 #include <sys/param.h> /* For MAXHOSTNAMELEN. */
41 /* These two parameters define the maximum cell size. The first parameter
42 * is the maximum length of searches permitted by the FINDB/FINDF
43 * commands. It stops those commands from running wild if a label is
44 * missing. The second one limits the maximum cell size that may be
45 * allocated by MALLOC - and hence directly the maximum cell size
46 * overall. There is also a minimum cell size, although we keep this
49 #define FIND_LENGTH_LIMIT 512
50 #define MAX_CELL_SIZE 512
51 #define MIN_CELL_SIZE 10
53 /* The maximum number of errors that a cell may get before we
54 * automatically blow it away (even if the soup isn't full and
55 * doesn't need reaping). This prevents us wasting valuable CPU
56 * time on cells which have gone completely AWOL.
58 #define MAX_ERRORS 100
68 struct cell *next; /* Alive cells are linked thru this list. */
69 struct cell *prev; /* Alive cells are linked thru this list. */
70 struct cell *worse; /* Cells are kept in error order on this list*/
71 struct cell *better; /* Cells are kept in error order on this list*/
72 reg_t a, b, i, p; /* Registers. */
73 reg_t stack[STACK_SIZE]; /* Stack. */
74 int sp; /* Stack pointer. */
75 int errors; /* Cumulative number of errors encountered */
76 enum cell_state state; /* Executing or finding. */
77 int dir; /* [Find] -1 = back, 1 = forwards */
78 int plen; /* [Find] length of pattern */
79 int lim; /* [Find] search limit (counts down to 0) */
80 struct soup_frag *frag; /* Fragment in the soup */
81 struct cell *daughter; /* Daughter (after MALLOC, before DIVIDE) */
82 unsigned long long cycle; /* Number of cycles of runtime. */
83 crc_t crc; /* CRC at birth (after mother's DIVIDE). */
84 crc_t mother_crc; /* CRC of mother. */
85 addr_t fbase; /* Used when saving/loading soup image only. */
90 extern struct cell *cell_malloc (struct state *state,
91 const struct cell *mother,
92 struct soup_frag *daughter_frag);
93 extern void cell_divide (struct state *state,
94 const struct cell *mother,
95 struct cell *daughter);
96 extern void cell_activate (struct state *state,
98 extern void cell_kill (struct state *state,
101 extern void cell_state_load (struct state *state, FILE *fp);
102 extern void cell_state_save (struct state *state, FILE *fp);
104 extern void cell_check (struct state *state);
106 extern void exec_insn (struct state *state, struct cell *cell);
108 extern void run_thread (struct state *state);
110 /* This macro is used to increment the error count in a cell. It
111 * ensures that the cell ``worst-to-best'' list is kept up to date.
113 #define INC_ERRORS(state,cell) do { (cell)->errors++; if ((cell)->worse && (cell)->errors > (cell)->worse->errors) _cell_move_worse ((state), (cell)); } while (0)
115 extern void _cell_move_worse (struct state *state, struct cell *cell);
117 extern struct soup_frag *_cell_get_any_frag (struct state *state);
119 extern void _cell_fixup_soup_ref (struct state *state,
120 addr_t fbase, struct soup_frag *frag);