/* DLIFE Copyright (C) 2000 Richard W.M. Jones * and other authors listed in the ``AUTHORS'' file. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id: cell.h,v 1.1 2002/04/05 14:40:25 rich Exp $ */ #ifndef cell_h #define cell_h #include "config.h" #include #ifdef HAVE_SYS_PARAM_H #include /* For MAXHOSTNAMELEN. */ #endif #include "types.h" #include "dlink.h" #include "state.h" #include "crc.h" struct soup_frag; #define STACK_SIZE 16 /* These two parameters define the maximum cell size. The first parameter * is the maximum length of searches permitted by the FINDB/FINDF * commands. It stops those commands from running wild if a label is * missing. The second one limits the maximum cell size that may be * allocated by MALLOC - and hence directly the maximum cell size * overall. There is also a minimum cell size, although we keep this * small. */ #define FIND_LENGTH_LIMIT 512 #define MAX_CELL_SIZE 512 #define MIN_CELL_SIZE 10 /* The maximum number of errors that a cell may get before we * automatically blow it away (even if the soup isn't full and * doesn't need reaping). This prevents us wasting valuable CPU * time on cells which have gone completely AWOL. */ #define MAX_ERRORS 100 enum cell_state { state_exec, state_find }; struct cell { struct cell *next; /* Alive cells are linked thru this list. */ struct cell *prev; /* Alive cells are linked thru this list. */ struct cell *worse; /* Cells are kept in error order on this list*/ struct cell *better; /* Cells are kept in error order on this list*/ reg_t a, b, i, p; /* Registers. */ reg_t stack[STACK_SIZE]; /* Stack. */ int sp; /* Stack pointer. */ int errors; /* Cumulative number of errors encountered */ enum cell_state state; /* Executing or finding. */ int dir; /* [Find] -1 = back, 1 = forwards */ int plen; /* [Find] length of pattern */ int lim; /* [Find] search limit (counts down to 0) */ struct soup_frag *frag; /* Fragment in the soup */ struct cell *daughter; /* Daughter (after MALLOC, before DIVIDE) */ unsigned long long cycle; /* Number of cycles of runtime. */ crc_t crc; /* CRC at birth (after mother's DIVIDE). */ crc_t mother_crc; /* CRC of mother. */ addr_t fbase; /* Used when saving/loading soup image only. */ }; extern int verbose; extern struct cell *cell_malloc (struct state *state, const struct cell *mother, struct soup_frag *daughter_frag); extern void cell_divide (struct state *state, const struct cell *mother, struct cell *daughter); extern void cell_activate (struct state *state, struct cell *cell); extern void cell_kill (struct state *state, struct cell *cell); extern void cell_state_load (struct state *state, FILE *fp); extern void cell_state_save (struct state *state, FILE *fp); extern void cell_check (struct state *state); extern void exec_insn (struct state *state, struct cell *cell); extern void run_thread (struct state *state); /* This macro is used to increment the error count in a cell. It * ensures that the cell ``worst-to-best'' list is kept up to date. */ #define INC_ERRORS(state,cell) do { (cell)->errors++; if ((cell)->worse && (cell)->errors > (cell)->worse->errors) _cell_move_worse ((state), (cell)); } while (0) extern void _cell_move_worse (struct state *state, struct cell *cell); extern struct soup_frag *_cell_get_any_frag (struct state *state); extern void _cell_fixup_soup_ref (struct state *state, addr_t fbase, struct soup_frag *frag); #endif /* cell_h */