Line 39... |
Line 39... |
uint16_t pc; /**< program counter */
|
uint16_t pc; /**< program counter */
|
uint16_t tos; /**< top of stack */
|
uint16_t tos; /**< top of stack */
|
uint16_t rp; /**< return stack pointer */
|
uint16_t rp; /**< return stack pointer */
|
uint16_t sp; /**< variable stack pointer */
|
uint16_t sp; /**< variable stack pointer */
|
bool ie; /**< interrupt enable */
|
bool ie; /**< interrupt enable */
|
|
unsigned time; /**< cycles run for */
|
|
|
break_point_t bp; /**< list of break points */
|
break_point_t bp; /**< list of break points */
|
uint16_t rpm; /**< maximum value of rp ever encountered */
|
uint16_t rpm; /**< maximum value of rp ever encountered */
|
uint16_t spm; /**< maximum value of sp ever encountered */
|
uint16_t spm; /**< maximum value of sp ever encountered */
|
} h2_t; /**< state of the H2 CPU */
|
} h2_t; /**< state of the H2 CPU */
|
Line 57... |
Line 58... |
typedef struct {
|
typedef struct {
|
symbol_type_e type;
|
symbol_type_e type;
|
char *id;
|
char *id;
|
uint16_t value;
|
uint16_t value;
|
bool hidden;
|
bool hidden;
|
|
bool used;
|
} symbol_t;
|
} symbol_t;
|
|
|
typedef struct {
|
typedef struct {
|
size_t length;
|
size_t length;
|
symbol_t **symbols;
|
symbol_t **symbols;
|
Line 196... |
Line 198... |
unsigned width;
|
unsigned width;
|
unsigned size;
|
unsigned size;
|
terminal_state_t state;
|
terminal_state_t state;
|
bool blinks;
|
bool blinks;
|
bool cursor_on;
|
bool cursor_on;
|
vt100_attribute_t attribute;
|
vt100_attribute_t attribute, attribute_saved;
|
vt100_attribute_t attributes[VT100_MAX_SIZE];
|
vt100_attribute_t attributes[VT100_MAX_SIZE];
|
uint8_t m[VT100_MAX_SIZE];
|
uint8_t m[VT100_MAX_SIZE];
|
uint8_t command_index;
|
uint8_t command_index;
|
} vt100_t;
|
} vt100_t;
|
|
|
Line 227... |
Line 229... |
flash_t flash;
|
flash_t flash;
|
|
|
bool wait;
|
bool wait;
|
bool interrupt;
|
bool interrupt;
|
uint8_t interrupt_selector;
|
uint8_t interrupt_selector;
|
|
|
|
uint16_t uart_tx_baud, uart_rx_baud, uart_control;
|
} h2_soc_state_t;
|
} h2_soc_state_t;
|
|
|
typedef uint16_t (*h2_io_get)(h2_soc_state_t *soc, uint16_t addr, bool *debug_on);
|
typedef uint16_t (*h2_io_get)(h2_soc_state_t *soc, uint16_t addr, bool *debug_on);
|
typedef void (*h2_io_set)(h2_soc_state_t *soc, uint16_t addr, uint16_t value, bool *debug_on);
|
typedef void (*h2_io_set)(h2_soc_state_t *soc, uint16_t addr, uint16_t value, bool *debug_on);
|
typedef void (*h2_io_update)(h2_soc_state_t *soc);
|
typedef void (*h2_io_update)(h2_soc_state_t *soc);
|
Line 258... |
Line 262... |
oMemDout = 0x4008,
|
oMemDout = 0x4008,
|
oMemControl = 0x400A,
|
oMemControl = 0x400A,
|
oMemAddrLow = 0x400C,
|
oMemAddrLow = 0x400C,
|
o7SegLED = 0x400E,
|
o7SegLED = 0x400E,
|
oIrcMask = 0x4010,
|
oIrcMask = 0x4010,
|
|
oUartTxBaud = 0x4012,
|
|
oUartRxBaud = 0x4014,
|
|
oUartControl = 0x4016,
|
} h2_output_addr_t;
|
} h2_output_addr_t;
|
|
|
typedef enum {
|
typedef enum {
|
isrEntry,
|
isrEntry,
|
isrRxFifoNotEmpty,
|
isrRxFifoNotEmpty,
|
Line 277... |
Line 284... |
FILE *fopen_or_die(const char *file, const char *mode);
|
FILE *fopen_or_die(const char *file, const char *mode);
|
|
|
h2_t *h2_new(uint16_t start_address);
|
h2_t *h2_new(uint16_t start_address);
|
void h2_free(h2_t *h);
|
void h2_free(h2_t *h);
|
int h2_load(h2_t *h, FILE *hexfile);
|
int h2_load(h2_t *h, FILE *hexfile);
|
int h2_save(h2_t *h, FILE *output, bool full);
|
int h2_save(const h2_t *h, FILE *output, bool full);
|
int h2_run(h2_t *h, h2_io_t *io, FILE *output, unsigned steps, symbol_table_t *symbols, bool run_debugger);
|
int h2_run(h2_t *h, h2_io_t *io, FILE *output, unsigned steps, symbol_table_t *symbols, bool run_debugger, FILE *trace);
|
|
|
uint16_t h2_io_memory_read_operation(h2_soc_state_t *soc);
|
uint16_t h2_io_memory_read_operation(const h2_soc_state_t *soc);
|
void soc_print(FILE *out, h2_soc_state_t *soc);
|
void soc_print(FILE *out, const h2_soc_state_t *soc);
|
h2_soc_state_t *h2_soc_state_new(void);
|
h2_soc_state_t *h2_soc_state_new(void);
|
void h2_soc_state_free(h2_soc_state_t *soc);
|
void h2_soc_state_free(h2_soc_state_t *soc);
|
h2_io_t *h2_io_new(void);
|
h2_io_t *h2_io_new(void);
|
void h2_io_free(h2_io_t *io);
|
void h2_io_free(h2_io_t *io);
|
|
|
int binary_memory_save(FILE *output, uint16_t *p, size_t length);
|
int binary_memory_save(FILE *output, const uint16_t *p, size_t length);
|
int binary_memory_load(FILE *input, uint16_t *p, size_t length);
|
int binary_memory_load(FILE *input, uint16_t *p, size_t length);
|
int nvram_save(h2_io_t *io, const char *name);
|
int nvram_save(h2_io_t *io, const char *name);
|
int nvram_load_and_transfer(h2_io_t *io, const char *name, bool transfer_to_sram);
|
int nvram_load_and_transfer(h2_io_t *io, const char *name, bool transfer_to_sram);
|
|
|
typedef uint8_t fifo_data_t;
|
typedef uint8_t fifo_data_t;
|
Line 303... |
Line 310... |
fifo_data_t *buffer;
|
fifo_data_t *buffer;
|
} fifo_t;
|
} fifo_t;
|
|
|
fifo_t *fifo_new(size_t size);
|
fifo_t *fifo_new(size_t size);
|
void fifo_free(fifo_t *fifo);
|
void fifo_free(fifo_t *fifo);
|
bool fifo_is_full(fifo_t * fifo);
|
bool fifo_is_full(const fifo_t * fifo);
|
bool fifo_is_empty(fifo_t * fifo);
|
bool fifo_is_empty(const fifo_t * fifo);
|
size_t fifo_count(fifo_t * fifo);
|
size_t fifo_count(const fifo_t * fifo);
|
size_t fifo_push(fifo_t * fifo, fifo_data_t data);
|
size_t fifo_push(fifo_t * fifo, fifo_data_t data);
|
size_t fifo_pop(fifo_t * fifo, fifo_data_t * data);
|
size_t fifo_pop(fifo_t * fifo, fifo_data_t * data);
|
|
|
/** @warning LOG_FATAL level kills the program */
|
/** @warning LOG_FATAL level kills the program */
|
#define X_MACRO_LOGGING\
|
#define X_MACRO_LOGGING\
|
Line 327... |
Line 334... |
#undef X
|
#undef X
|
} log_level_e;
|
} log_level_e;
|
|
|
extern log_level_e log_level;
|
extern log_level_e log_level;
|
|
|
|
#ifdef __GNUC__
|
|
#define LOGGER_PRINTF __attribute__((format(printf, 4, 5)))
|
|
#else
|
|
#define LOGGER_PRINTF
|
|
#endif
|
|
|
int logger(log_level_e level, const char *func,
|
int logger(log_level_e level, const char *func,
|
const unsigned line, const char *fmt, ...);
|
const unsigned line, const char *fmt, ...) LOGGER_PRINTF;
|
|
|
#define fatal(FMT, ...) logger(LOG_FATAL, __func__, __LINE__, FMT, ##__VA_ARGS__)
|
#define fatal(...) logger(LOG_FATAL, __func__, __LINE__, __VA_ARGS__)
|
#define error(FMT, ...) logger(LOG_ERROR, __func__, __LINE__, FMT, ##__VA_ARGS__)
|
#define error(...) logger(LOG_ERROR, __func__, __LINE__, __VA_ARGS__)
|
#define warning(FMT, ...) logger(LOG_WARNING, __func__, __LINE__, FMT, ##__VA_ARGS__)
|
#define warning(...) logger(LOG_WARNING, __func__, __LINE__, __VA_ARGS__)
|
#define note(FMT, ...) logger(LOG_NOTE, __func__, __LINE__, FMT, ##__VA_ARGS__)
|
#define note(...) logger(LOG_NOTE, __func__, __LINE__, __VA_ARGS__)
|
#define debug(FMT, ...) logger(LOG_DEBUG, __func__, __LINE__, FMT, ##__VA_ARGS__)
|
#define debug(...) logger(LOG_DEBUG, __func__, __LINE__, __VA_ARGS__)
|
|
|
int memory_load(FILE *input, uint16_t *p, size_t length);
|
int memory_load(FILE *input, uint16_t *p, size_t length);
|
int memory_save(FILE *output, uint16_t *p, size_t length);
|
int memory_save(FILE *output, const uint16_t *p, size_t length);
|
|
|
#define BACKSPACE (8)
|
#define BACKSPACE (8)
|
#define ESCAPE (27)
|
#define ESCAPE (27)
|
#define DELETE (127) /* ASCII delete */
|
#define DELETE (127) /* ASCII delete */
|
|
|