/* image.c -- the StarForth nucleus, as its host knows it. See image.h. * * Nothing here uses the C library: the bare-metal kernel links this file. */ #include "v4/image.h" int v4_image_born(v4_node *n, v4_exec_state *es, v4_heat *h, const v4_image *im, unsigned char *disk, unsigned blocks) { if (im->cell_bits != (unsigned)V4_CELL_BITS || im->node_words != (unsigned)V4_NODE_WORDS || im->data_ring != (unsigned)V4_DATA_RING || im->ret_ring != (unsigned)V4_RET_RING) return 0; v4_node_born(n, im->port); v4_exec_reset(es); v4_heat_reset(h); v4_node_console_attach(n, im->console_tx); v4_node_console_input_attach(n, im->console_rx, im->console_status); v4_node_stack_regs_attach(n, im->dstack_reg, im->rstack_reg); v4_node_error_attach(n, im->node_error); v4_node_fault_attach(n, im->fault_table); if (disk && blocks) v4_node_storage_attach(n, im->storage_reg, disk, blocks); return 1; } int v4_image_waiting(const v4_node *n, const v4_image *im) { return n->input_pos == n->input_len && n->p >= im->key_start && n->p < im->key_end; } void v4_image_seal(v4_node *n, const v4_image *im) { n->mem[im->boot_cells] = n->mem[im->dp]; n->mem[im->boot_cells + 1] = n->mem[im->latest]; n->mem[im->fence] = (n->mem[im->dp] + 3) / 4; }