Files
hmmmm_avr_generic/inc/instr.h
2026-05-07 14:28:30 +03:00

72 lines
1.4 KiB
C

#ifndef __INSTR_H__
#define __INSTR_H__
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include "mem.h"
#ifndef OPCODE_WORDSIZE
#error OPCODE_WORDSIZE must be provided
// #define OPCODE_WORDSIZE 1
#endif
#if OPCODE_WORDSIZE == 1
typedef uint8_t opcode_t;
#elif OPCODE_WORDSIZE == 2
typedef uint16_t opcode_t;
#elif OPCODE_WORDSIZE == 3
typedef uint32_t opcode_t;
#elif OPCODE_WORDSIZE == 4
typedef uint32_t opcode_t;
#else
#error OPCODE_WORDSIZE must be one of 1,2,3,4
#endif
#ifndef PC_WORDSIZE
#error PC_WORDSIZE must be provided
// #define PC_WORDSIZE 1
#endif
#if PC_WORDSIZE == 1
typedef uint8_t prog_counter_t;
#elif PC_WORDSIZE == 2
typedef uint16_t prog_counter_t;
#elif PC_WORDSIZE == 3
typedef uint32_t prog_counter_t;
#elif PC_WORDSIZE == 4
typedef uint32_t prog_counter_t;
#else
#error PC_WORDSIZE must be one of 1,2,3,4
#endif
typedef uint8_t (*instr_h_func)(prog_counter_t*, device_mem_t*);
typedef struct
{
instr_h_func h;
opcode_t base;
opcode_t argsMask;
uint8_t opcodeLen;
} instruction_metadata_t;
instr_h_func* genInstrArray(char* errbuf);
void setOpcodeSizes(uint8_t* opcodeSizes);
opcode_t extractOpcode(device_mem_t* devMem, prog_counter_t programCounter);
#define AVRe 1
#define AVRxm 2
#define AVRxt 3
#define AVRrc 4
#ifndef ARCH
#define ARCH AVRe
#endif
#endif // ifndef __INSTR_H__