added machine_state_t_exec and fixed some bugs
This commit is contained in:
parent
84ca38924e
commit
d472a14f59
|
@ -271,16 +271,19 @@ char bci_cm_jmp(uint8_t small_arg, machine_state_t state)
|
||||||
// else: do nothing
|
// else: do nothing
|
||||||
char bci_cm_cjmp(uint8_t small_arg, machine_state_t state)
|
char bci_cm_cjmp(uint8_t small_arg, machine_state_t state)
|
||||||
{
|
{
|
||||||
uint16_t arg;
|
uint16_t arg = small_arg;
|
||||||
BCI_CORE_REGISTER_CHECK(small_arg);
|
BCI_CORE_REGISTER_CHECK(small_arg);
|
||||||
|
#ifdef DEBUG
|
||||||
|
printf("MSG: cjmp: arg=0x%x (=0x%x)\n", arg, state->data_reg[arg]);
|
||||||
|
#endif
|
||||||
arg = state->data_reg[arg];
|
arg = state->data_reg[arg];
|
||||||
|
|
||||||
if(state->status_reg)
|
if(state->status_reg)
|
||||||
{
|
{
|
||||||
state->program_counter = arg;
|
state->program_counter = arg;
|
||||||
|
state->status_reg = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
state->status_reg = 0;
|
|
||||||
|
|
||||||
return machine_state_t_default_afterexec(state, 0);
|
return machine_state_t_default_afterexec(state, 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ machine_state_t machine_state_t_new( void * cache_function_data
|
||||||
int i;
|
int i;
|
||||||
for(i = 0; i < BCI_CORE_NUM_REG; i++)
|
for(i = 0; i < BCI_CORE_NUM_REG; i++)
|
||||||
{
|
{
|
||||||
state->data_reg[BCI_CORE_NUM_REG] = 0;
|
state->data_reg[i] = 0;
|
||||||
}
|
}
|
||||||
state->stack = NULL;
|
state->stack = NULL;
|
||||||
|
|
||||||
|
@ -95,6 +95,9 @@ char update_cache(machine_state_t state, uint16_t offset)
|
||||||
|
|
||||||
if(cached != state->cache_size)
|
if(cached != state->cache_size)
|
||||||
{
|
{
|
||||||
|
#ifdef DEBUG
|
||||||
|
printf("ERROR: should have cached %zu words, but got %zu.\n", state->cache_size, cached);
|
||||||
|
#endif
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
state->cache_offset = cache_offset;
|
state->cache_offset = cache_offset;
|
||||||
|
@ -121,6 +124,9 @@ char machine_state_t_get_word(machine_state_t state, uint16_t offset, uint16_t *
|
||||||
{
|
{
|
||||||
if(update_cache(state, offset))
|
if(update_cache(state, offset))
|
||||||
{
|
{
|
||||||
|
#ifdef DEBUG
|
||||||
|
printf("ERROR: failed to update cache\n");
|
||||||
|
#endif
|
||||||
state->error = 0b01000000 | 2;
|
state->error = 0b01000000 | 2;
|
||||||
return 0b01000000 | 2;
|
return 0b01000000 | 2;
|
||||||
}
|
}
|
||||||
|
@ -144,6 +150,12 @@ char machine_state_t_exec_cycle(machine_state_t state)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
printf("MSG: opcode = 0x%x, small_arg = 0x%x\n"
|
||||||
|
, opcode & BCI_CORE_OPCODE_MASK
|
||||||
|
, opcode & BCI_CORE_SMALL_ARG_MASK);
|
||||||
|
#endif
|
||||||
|
|
||||||
bci_core_method_t method = dispatch_tree_t_dispatch(
|
bci_core_method_t method = dispatch_tree_t_dispatch(
|
||||||
state->method_dispatcher
|
state->method_dispatcher
|
||||||
, opcode & BCI_CORE_OPCODE_MASK);
|
, opcode & BCI_CORE_OPCODE_MASK);
|
||||||
|
@ -189,3 +201,17 @@ char machine_state_t_set_mem(machine_state_t state, uint16_t offset, uint16_t da
|
||||||
state->memory[offset] = data;
|
state->memory[offset] = data;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
char machine_state_t_exec(machine_state_t state)
|
||||||
|
{
|
||||||
|
char status = 0;
|
||||||
|
while((!status) && (!state->shutdown_reg))
|
||||||
|
{
|
||||||
|
status = machine_state_t_exec_cycle(state);
|
||||||
|
}
|
||||||
|
state->error = status;
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
|
@ -88,6 +88,16 @@ void machine_state_t_del(machine_state_t state);
|
||||||
* */
|
* */
|
||||||
char machine_state_t_exec_cycle(machine_state_t state);
|
char machine_state_t_exec_cycle(machine_state_t state);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Runs ``machine_state_t_exec_cycle`` until either this function
|
||||||
|
* returns a non-zero value or a non-zero value is stored in
|
||||||
|
* ``state->shutdown_reg``.
|
||||||
|
* Sets ``state->error`` to the last return value of ``machine_state_t_exec_cycle``
|
||||||
|
* and returns it.
|
||||||
|
* */
|
||||||
|
char machine_state_t_exec(machine_state_t state);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Do the default updates on the machine state.
|
* Do the default updates on the machine state.
|
||||||
* This will be basically increasing the program counter.
|
* This will be basically increasing the program counter.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user