Skip to content
Snippets Groups Projects
c spec idea 2.8 KiB
Newer Older
iftach's avatar
iftach committed
Spec idea:

struct ProcessorState
	Represents a processor; registers and memory.
	Let's keep the PC incremented to the actual value it's supposed to have in a real arm processor (current instruction +8).
		If the first instruction after a jump is another jump (or if the first instruction of a program is a jump) this might cause a problem (?)
		since in an actual execution the offset starts at 0 and moves to +8 after two instructions. decode() should probably account for this.
	IMPLEMENTED
iftach's avatar
iftach committed
	
Remember to check memory's bounds before accessing it!
iftach's avatar
iftach committed
		
main
	uses: loadBinary(...), step(...)

void step(struct ProcessorState *processor)
	Decodes the next instruction and calls the appropriate method to execute it. Handles the PC's offset.
	uses: dataProcessingInstr(...), multiplyInstr(...), dataTransferInstr(...), branchInstr(...)
	
void dataProcessingInstr(struct ProcessorState *processor, int address)
iftach's avatar
iftach committed
	Executes a data processing instruction stored in (*processor).memory[address]
iftach's avatar
iftach committed
	uses: isValidCond(...), barrelShift(...)

void multiplyInstr(struct ProcessorState *processor, int address)
iftach's avatar
iftach committed
	Executes a multiplication instruction stored in (*processor).memory[address]
	uses: isValidCond(...)
iftach's avatar
iftach committed
	
void dataTransferInstr(struct ProcessorState *processor, int address)
iftach's avatar
iftach committed
	Executes a single data transfer instruction stored in (*processor).memory[address]
iftach's avatar
iftach committed
	uses: isValidCond(...), barrelShift(...)

void branchInstr(stuct ProcessorState *processor, int address)
iftach's avatar
iftach committed
	uses: isValidCond(...),
iftach's avatar
iftach committed
	
struct ProcessorState *loadBinary(char* src)
iftach's avatar
iftach committed
	creates a new ProcessorState and loads its memory from a binary file.
iftach's avatar
iftach committed


Helper functions (used in more than one method):


int32_t getBits(int source, int start, int end)
	Reads bits from source in the range [start, end] (inclusive). Returns a uint32_t with the result as its least significant bits.
	(e.g. getBits(8, 2, 3) == 2)
	IMPLEMENTED

int isSet(int source, int index)
	Shorthand for getBits(source, index, index)
	IMPLEMENTED

int validCond(int cond, struct ProcessorState *processor)
	Returns 1 if the condition code 'cond' is satisfied by the processor's current state, and 0 otherwise.
	IMPLEMENTED

int32_t barrelShift(int immediate, int32_t operand, int *carry, struct ProcessorState *processor)
iftach's avatar
iftach committed
	Implements the functionality of the barrel shifter. The carry output is written to (*carry), just in case you need it.
iftach's avatar
iftach committed
	NOTE: for some reason the I bit is used in opposite ways for data processing instructions vs for data transfer instructions. Arbitrarily, let this method
	assume that the data processing instruction interpretation is the right one (so for data transfer instructions just call this method with NOT i).

int32_t *accessMemory(struct ProcessorState *processor, int address)
	Gets an address from memory while ensuring it's not out of bounds
	(use if you want, you can always do bounds checking manually)