SimAVR
AVR Simulator
sim_core.c File Reference
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "logging.h"
#include "avr_flash.h"
#include "avr_watchdog.h"
#include "sim_avr.h"
#include "sim_core.h"
#include "sim_gdb.h"
Include dependency graph for sim_core.c:

Macros

#define T(w)
 
#define REG_TOUCH(a, r)
 
#define STATE(_f, args...)
 
#define SREG()
 
#define get_d5(o)   const uint8_t d = (o >> 4) & 0x1f;
 
#define get_vd5(o)
 
#define get_r5(o)   const uint8_t r = ((o >> 5) & 0x10) | (o & 0xf);
 
#define get_d5_a6(o)
 
#define get_vd5_s3(o)
 
#define get_vd5_s3_mask(o)
 
#define get_vd5_vr5(o)
 
#define get_d5_vr5(o)
 
#define get_h4_k8(o)
 
#define get_vh4_k8(o)
 
#define get_d5_q6(o)
 
#define get_io5(o)   const uint8_t io = ((o >> 3) & 0x1f) + 32;
 
#define get_io5_b3(o)
 
#define get_io5_b3mask(o)
 
#define get_o12(op)   const int16_t o = ((int16_t)((op << 4) & 0xffff)) >> 3;
 
#define get_vp2_k6(o)
 
#define get_sreg_bit(o)   const uint8_t b = (o >> 4) & 7;
 
#define TRACE_JUMP()
 
#define STACK_FRAME_PUSH()
 
#define STACK_FRAME_POP()
 

Functions

static uint16_t _avr_read_instruction (avr_t *avr, avr_flashaddr_t pc)
 Read the instruction in flash memory at given pc. More...
 
void crash (avr_t *avr)
 
void avr_core_watch_write (avr_t *avr, uint16_t addr, uint8_t v)
 These are accessors for avr->data but allows watchpoints to be set for gdb IO modules use that to set values to registers, and the AVR core decoder uses that to register "public" read by instructions. More...
 
uint8_t avr_core_watch_read (avr_t *avr, uint16_t addr)
 
static void _avr_set_r (avr_t *avr, uint16_t r, uint8_t v)
 
uint16_t _avr_sp_get (avr_t *avr)
 Stack pointer access. More...
 
void _avr_sp_set (avr_t *avr, uint16_t sp)
 
static void _avr_set_ram (avr_t *avr, uint16_t addr, uint8_t v)
 Set any address to a value; split between registers and SRAM. More...
 
static uint8_t _avr_get_ram (avr_t *avr, uint16_t addr)
 Get a value from SRAM. More...
 
static void _avr_push8 (avr_t *avr, uint16_t v)
 Stack push accessors. More...
 
static uint8_t _avr_pop8 (avr_t *avr)
 
int _avr_push_addr (avr_t *avr, avr_flashaddr_t addr)
 
avr_flashaddr_t _avr_pop_addr (avr_t *avr)
 
const char * avr_regname (uint8_t reg)
 
static void _avr_invalid_opcode (avr_t *avr)
 Called when an invalid opcode is decoded. More...
 
static void _avr_flags_zns (struct avr_t *avr, uint8_t res)
 
static void _avr_flags_zns16 (struct avr_t *avr, uint16_t res)
 
static void _avr_flags_add_zns (struct avr_t *avr, uint8_t res, uint8_t rd, uint8_t rr)
 
static void _avr_flags_sub_zns (struct avr_t *avr, uint8_t res, uint8_t rd, uint8_t rr)
 
static void _avr_flags_Rzns (struct avr_t *avr, uint8_t res)
 
static void _avr_flags_sub_Rzns (struct avr_t *avr, uint8_t res, uint8_t rd, uint8_t rr)
 
static void _avr_flags_zcvs (struct avr_t *avr, uint8_t res, uint8_t vr)
 
static void _avr_flags_zcnvs (struct avr_t *avr, uint8_t res, uint8_t vr)
 
static void _avr_flags_znv0s (struct avr_t *avr, uint8_t res)
 
static int _avr_is_instruction_32_bits (avr_t *avr, avr_flashaddr_t pc)
 
avr_flashaddr_t avr_run_one (avr_t *avr)
 Instruction decoder, run ONE instruction. More...
 

Variables

const char * _sreg_bit_name = "cznvshti"
 
const char * reg_names [255]
 "Pretty" register names More...
 

Macro Definition Documentation

#define get_d5 (   o)    const uint8_t d = (o >> 4) & 0x1f;
#define get_d5_a6 (   o)
Value:
get_d5(o); \
const uint8_t A = ((((o >> 9) & 3) << 4) | ((o) & 0xf)) + 32;
#define get_d5(o)
Definition: sim_core.c:463
#define get_d5_q6 (   o)
Value:
get_d5(o) \
const uint8_t q = ((o & 0x2000) >> 8) | ((o & 0x0c00) >> 7) | (o & 0x7);
#define get_d5(o)
Definition: sim_core.c:463
#define get_d5_vr5 (   o)
Value:
get_d5(o); \
get_r5(o); \
const uint8_t vr = avr->data[r];
uint8_t * data
SRAM memory, starting by the general purpose registers, and IO registers.
Definition: sim_avr.h:265
avr_t * avr
Definition: run_avr.c:54
#define get_r5(o)
Definition: sim_core.c:470
#define get_d5(o)
Definition: sim_core.c:463
#define get_h4_k8 (   o)
Value:
const uint8_t h = 16 + ((o >> 4) & 0xf); \
const uint8_t k = ((o & 0x0f00) >> 4) | (o & 0xf);
#define get_io5 (   o)    const uint8_t io = ((o >> 3) & 0x1f) + 32;
#define get_io5_b3 (   o)
Value:
get_io5(o); \
const uint8_t b = o & 0x7;
#define get_io5(o)
Definition: sim_core.c:507
#define get_io5_b3mask (   o)
Value:
get_io5(o); \
const uint8_t mask = 1 << (o & 0x7);
#define get_io5(o)
Definition: sim_core.c:507
#define get_o12 (   op)    const int16_t o = ((int16_t)((op << 4) & 0xffff)) >> 3;
#define get_r5 (   o)    const uint8_t r = ((o >> 5) & 0x10) | (o & 0xf);
#define get_sreg_bit (   o)    const uint8_t b = (o >> 4) & 7;
#define get_vd5 (   o)
Value:
get_d5(o) \
const uint8_t vd = avr->data[d];
uint8_t * data
SRAM memory, starting by the general purpose registers, and IO registers.
Definition: sim_avr.h:265
avr_t * avr
Definition: run_avr.c:54
#define get_d5(o)
Definition: sim_core.c:463
#define get_vd5_s3 (   o)
Value:
get_vd5(o); \
const uint8_t s = o & 7;
#define get_vd5(o)
Definition: sim_core.c:466
#define get_vd5_s3_mask (   o)
Value:
const uint8_t mask = 1 << s;
#define get_vd5_s3(o)
Definition: sim_core.c:477
#define get_vd5_vr5 (   o)
Value:
get_r5(o); \
get_d5(o); \
const uint8_t vd = avr->data[d], vr = avr->data[r];
uint8_t * data
SRAM memory, starting by the general purpose registers, and IO registers.
Definition: sim_avr.h:265
avr_t * avr
Definition: run_avr.c:54
#define get_r5(o)
Definition: sim_core.c:470
#define get_d5(o)
Definition: sim_core.c:463
#define get_vh4_k8 (   o)
Value:
const uint8_t vh = avr->data[h];
#define get_h4_k8(o)
Definition: sim_core.c:495
uint8_t * data
SRAM memory, starting by the general purpose registers, and IO registers.
Definition: sim_avr.h:265
avr_t * avr
Definition: run_avr.c:54
#define get_vp2_k6 (   o)
Value:
const uint8_t p = 24 + ((o >> 3) & 0x6); \
const uint8_t k = ((o & 0x00c0) >> 2) | (o & 0xf); \
const uint16_t vp = avr->data[p] | (avr->data[p + 1] << 8);
uint8_t * data
SRAM memory, starting by the general purpose registers, and IO registers.
Definition: sim_avr.h:265
avr_t * avr
Definition: run_avr.c:54
#define REG_TOUCH (   a,
 
)
#define SREG ( )
#define STACK_FRAME_POP ( )
#define STACK_FRAME_PUSH ( )
#define STATE (   _f,
  args... 
)
#define T (   w)
#define TRACE_JUMP ( )

Function Documentation

static void _avr_flags_add_zns ( struct avr_t avr,
uint8_t  res,
uint8_t  rd,
uint8_t  rr 
)
static

Here is the call graph for this function:

Here is the caller graph for this function:

static void _avr_flags_Rzns ( struct avr_t avr,
uint8_t  res 
)
static

Here is the caller graph for this function:

static void _avr_flags_sub_Rzns ( struct avr_t avr,
uint8_t  res,
uint8_t  rd,
uint8_t  rr 
)
static

Here is the call graph for this function:

Here is the caller graph for this function:

static void _avr_flags_sub_zns ( struct avr_t avr,
uint8_t  res,
uint8_t  rd,
uint8_t  rr 
)
static

Here is the call graph for this function:

Here is the caller graph for this function:

static void _avr_flags_zcnvs ( struct avr_t avr,
uint8_t  res,
uint8_t  vr 
)
static

Here is the caller graph for this function:

static void _avr_flags_zcvs ( struct avr_t avr,
uint8_t  res,
uint8_t  vr 
)
static

Here is the caller graph for this function:

static void _avr_flags_zns ( struct avr_t avr,
uint8_t  res 
)
static

Here is the caller graph for this function:

static void _avr_flags_zns16 ( struct avr_t avr,
uint16_t  res 
)
static

Here is the caller graph for this function:

static void _avr_flags_znv0s ( struct avr_t avr,
uint8_t  res 
)
static

Here is the call graph for this function:

Here is the caller graph for this function:

static uint8_t _avr_get_ram ( avr_t avr,
uint16_t  addr 
)
inlinestatic

Get a value from SRAM.

Here is the call graph for this function:

Here is the caller graph for this function:

static void _avr_invalid_opcode ( avr_t avr)
static

Called when an invalid opcode is decoded.

Here is the call graph for this function:

Here is the caller graph for this function:

static int _avr_is_instruction_32_bits ( avr_t avr,
avr_flashaddr_t  pc 
)
inlinestatic

Here is the call graph for this function:

Here is the caller graph for this function:

static uint8_t _avr_pop8 ( avr_t avr)
inlinestatic

Here is the call graph for this function:

Here is the caller graph for this function:

avr_flashaddr_t _avr_pop_addr ( avr_t avr)

Here is the call graph for this function:

Here is the caller graph for this function:

static void _avr_push8 ( avr_t avr,
uint16_t  v 
)
inlinestatic

Stack push accessors.

Here is the call graph for this function:

Here is the caller graph for this function:

static uint16_t _avr_read_instruction ( avr_t avr,
avr_flashaddr_t  pc 
)
inlinestatic

Read the instruction in flash memory at given pc.

Here is the caller graph for this function:

static void _avr_set_r ( avr_t avr,
uint16_t  r,
uint8_t  v 
)
inlinestatic

Here is the call graph for this function:

Here is the caller graph for this function:

static void _avr_set_ram ( avr_t avr,
uint16_t  addr,
uint8_t  v 
)
inlinestatic

Set any address to a value; split between registers and SRAM.

Here is the call graph for this function:

Here is the caller graph for this function:

const char* avr_regname ( uint8_t  reg)

Here is the caller graph for this function:

void crash ( avr_t avr)

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

const char* _sreg_bit_name = "cznvshti"
const char* reg_names[255]
Initial value:
= {
[R_XH] = "XH", [R_XL] = "XL",
[R_YH] = "YH", [R_YL] = "YL",
[R_ZH] = "ZH", [R_ZL] = "ZL",
[R_SPH] = "SPH", [R_SPL] = "SPL",
[R_SREG] = "SREG",
}
Definition: sim_avr.h:78
Definition: sim_avr.h:78
16 bits register pairs
Definition: sim_avr.h:78
Definition: sim_avr.h:78
stack pointer
Definition: sim_avr.h:80
Definition: sim_avr.h:80
real SREG
Definition: sim_avr.h:82
Definition: sim_avr.h:78
Definition: sim_avr.h:78

"Pretty" register names