Main Page

Macros | Functions | Variables
avrcore.c File Reference

Go to the source code of this file.

## Macros
#define | BREAK_OPCODE 0x9598

## Functions
void | avr_core_dump_core (AvrCore *core, FILE *f_core)
int | avr_core_load_program (AvrCore *core, char *file, int format)
int | avr_core_load_eeprom (AvrCore *core, char *file, int format)
AvrCore handling methods
AvrCore * | avr_core_new (char *dev_name)
void | avr_core_destroy (void *core)
void | avr_core_get_sizes (AvrCore *core, int *flash, int *sram, int *sram_start, int *eeprom)
void | avr_core_attach_vdev (AvrCore *core, uint16_t addr, char *name, VDevice *vdev, int flags, uint8_t reset_value, uint8_t rd_mask, uint8_t wr_mask)
VDevice * | avr_core_get_vdev_by_name (AvrCore *core, char *name)
VDevice * | avr_core_get_vdev_by_addr (AvrCore *core, int addr)
void | avr_core_set_state (AvrCore *core, StateType state)
int | avr_core_get_state (AvrCore *core)
void | avr_core_set_sleep_mode (AvrCore *core, int sleep_mode)
int | avr_core_get_sleep_mode (AvrCore *core)
Program Memory Space Access Methods
Data Memory Space Access Methods
Status Register Access Methods
int | avr_core_sreg_get_bit (AvrCore *core, int b)
void | avr_core_sreg_set_bit (AvrCore *core, int b, int v)
RAMPZ access methods
uint8_t | avr_core_rampz_get (AvrCore *core)
void | avr_core_rampz_set (AvrCore *core, uint8_t v)
Direct I/O Register Access Methods
IO Registers are mapped in memory directly after the 32 (0x20) general registers.
void | avr_core_io_display_names (AvrCore *core)
uint8_t | avr_core_io_read (AvrCore *core, int reg)
void | avr_core_io_write (AvrCore *core, int reg, uint8_t val)
Stack Methods
uint32_t | avr_core_stack_pop (AvrCore *core, int bytes)
void | avr_core_stack_push (AvrCore *core, int bytes, uint32_t val)
Program Counter Methods
int32_t | avr_core_PC_size (AvrCore *core)
void | avr_core_PC_incr (AvrCore *core, int val)
Methods for accessing CK and instruction Clocks
uint64_t | avr_core_CK_get (AvrCore *core)
void | avr_core_CK_incr (AvrCore *core)
int | avr_core_inst_CKS_get (AvrCore *core)
void | avr_core_inst_CKS_set (AvrCore *core, int val)
Interrupt Access Methods.
IntVect * | avr_core_irq_get_pending (AvrCore *core)
void | avr_core_irq_raise (AvrCore *core, unsigned int irq)
void | avr_core_irq_clear (AvrCore *core, IntVect *irq)
void | avr_core_irq_clear_all (AvrCore *core)
Break point access methods.
void | avr_core_insert_breakpoint (AvrCore *core, int pc)
void | avr_core_remove_breakpoint (AvrCore *core, int pc)
void | avr_core_disable_breakpoints (AvrCore *core)
void | avr_core_enable_breakpoints (AvrCore *core)
Program control methods
int | avr_core_step (AvrCore *core)
void | avr_core_run (AvrCore *core)
void | avr_core_reset (AvrCore *core)
Callback Handling Methods
void | avr_core_add_ext_rd_wr (AvrCore *core, int addr, PortFP_ExtRd ext_rd, PortFP_ExtWr ext_wr)
void | avr_core_clk_cb_add (AvrCore *core, CallBack *cb)
void | avr_core_async_cb_add (AvrCore *core, CallBack *cb)
void | avr_core_clk_cb_exec (AvrCore *core)
void | avr_core_async_cb_exec (AvrCore *core)

## Variables
int | global_debug_inst_output = 0

## Detailed Description

Module for the core AvrCore object, which is the AVR CPU to be simulated.

Definition in file avrcore.c.

## Function Documentation

## § avr_core_new()

AvrCore* avr_core_new | ( | char * | dev_name | ) |

Allocate a new AvrCore object.

Definition at line 355 of file avrcore.c.

References avr_new, and dev_supp_lookup_device().

## § avr_core_destroy()

void avr_core_destroy | ( | void * | core | ) |

Destructor for the AvrCore class.

Not to be called directly, except by a derived class. Called via class_unref.

Definition at line 549 of file avrcore.c.

References class_destroy(), class_unref(), and dlist_delete_all().

## § avr_core_get_sizes()

void avr_core_get_sizes | ( | AvrCore * | core,
|  | int * | flash,
|  | int * | sram,
|  | int * | sram_start,
|  | int * | eeprom
| ) |  |

Query the sizes of the 3 memory spaces: flash, sram, and eeprom.

Definition at line 572 of file avrcore.c.

References avr_core_attach_vdev(), avr_core_get_sleep_mode(), avr_core_get_state(), avr_core_get_vdev_by_addr(), avr_core_get_vdev_by_name(), avr_core_set_sleep_mode(), avr_core_set_state(), and flash_get_size().

## § avr_core_attach_vdev()

void avr_core_attach_vdev | ( | AvrCore * | core,
|  | uint16_t | addr,
|  | char * | name,
|  | VDevice * | vdev,
|  | int | flags,
|  | uint8_t | reset_value,
|  | uint8_t | rd_mask,
|  | uint8_t | wr_mask
| ) |  |

Attach a virtual device into the Memory.

Referenced by avr_core_get_sizes().

## § avr_core_get_vdev_by_name()

VDevice* avr_core_get_vdev_by_name | ( | AvrCore * | core,
|  | char * | name
| ) |  |

Returns the `VDevice` with the name name.

Referenced by avr_core_get_sizes().

## § avr_core_get_vdev_by_addr()

VDevice* avr_core_get_vdev_by_addr | ( | AvrCore * | core,
|  | int | addr
| ) |  |

Returns the `VDevice` which handles the address addr.

Referenced by avr_core_get_sizes().

## § avr_core_set_state()

void avr_core_set_state | ( | AvrCore * | core,
|  | StateType | state
| ) |  |

Sets the device's state (running, stopped, breakpoint, sleep).

Referenced by avr_core_get_sizes().

## § avr_core_get_state()

int avr_core_get_state | ( | AvrCore * | core | ) |

Returns the device's state (running, stopped, breakpoint, sleep).

Referenced by avr_core_get_sizes(), and avr_core_step().

## § avr_core_set_sleep_mode()

void avr_core_set_sleep_mode | ( | AvrCore * | core,
|  | int | sleep_mode
| ) |  |

Sets the device to a sleep state.

Parameters

  core | Pointer to the core.
  sleep_mode | The BITNUMBER of the sleepstate.

Referenced by avr_core_get_sizes().

## § avr_core_get_sleep_mode()

int avr_core_get_sleep_mode | ( | AvrCore * | core | ) |

Return the device's sleepmode.

Referenced by avr_core_get_sizes().

## § avr_core_sreg_get_bit()

int avr_core_sreg_get_bit | ( | AvrCore * | core,
|  | int | b
| ) |  |

Get the value of bit `b` of the status register.

## § avr_core_sreg_set_bit()

void avr_core_sreg_set_bit | ( | AvrCore * | core,
|  | int | b,
|  | int | v
| ) |  |

Set the value of bit `b` of the status register.

## § avr_core_rampz_get()

uint8_t avr_core_rampz_get | ( | AvrCore * | core | ) |

Get the value of the rampz register.

## § avr_core_rampz_set()

void avr_core_rampz_set | ( | AvrCore * | core,
|  | uint8_t | v
| ) |  |

Set the value of the rampz register.

## § avr_core_io_display_names()

void avr_core_io_display_names | ( | AvrCore * | core | ) |

Displays all registers.

Definition at line 733 of file avrcore.c.

References avr_core_io_read(), avr_core_io_write(), display_io_reg_name(), and mem_io_fetch().

## § avr_core_io_read()

uint8_t avr_core_io_read | ( | AvrCore * | core,
|  | int | reg
| ) |  |

Reads the value of a register.

Parameters

  core | Pointer to the core.
  reg | The registers address. This address is counted above the beginning of the registers memory block (0x20).

Referenced by avr_core_io_display_names().

## § avr_core_io_write()

void avr_core_io_write | ( | AvrCore * | core,
|  | int | reg,
|  | uint8_t | val
| ) |  |

Writes the value of a register. See avr_core_io_read() for a discussion of reg.

Referenced by avr_core_io_display_names().

## § avr_core_stack_pop()

uint32_t avr_core_stack_pop | ( | AvrCore * | core,
|  | int | bytes
| ) |  |

Pop 1-4 bytes off of the stack.

See stack_pop() for more details.

## § avr_core_stack_push()

void avr_core_stack_push | ( | AvrCore * | core,
|  | int | bytes,
|  | uint32_t | val
| ) |  |

Push 1-4 bytes onto the stack.

See stack_push() for more details.

## § avr_core_PC_size()

int32_t avr_core_PC_size | ( | AvrCore * | core | ) |

Returns the size of the Program Counter in bytes.

Most devices have a 16-bit PC (2 bytes), but some larger ones (e.g. mega256), have a 22-bit PC (3 bytes).

## § avr_core_PC_incr()

void avr_core_PC_incr | ( | AvrCore * | core,
|  | int | val
| ) |  |

Increment the Program Counter by val.

val can be either positive or negative.

If the result of the incrememt is outside the valid range for PC, it is adjusted to fall in the valid range. This allows addresses to wrap around the end of the insn space.

## § avr_core_CK_get()

uint64_t avr_core_CK_get | ( | AvrCore * | core | ) |

Get the current clock counter.

## § avr_core_CK_incr()

void avr_core_CK_incr | ( | AvrCore * | core | ) |

Increment the clock counter.

## § avr_core_inst_CKS_get()

int avr_core_inst_CKS_get | ( | AvrCore * | core | ) |

Get the number of clock cycles remaining for the currently executing instruction.

## § avr_core_inst_CKS_set()

void avr_core_inst_CKS_set | ( | AvrCore * | core,
|  | int | val
| ) |  |

Set the number of clock cycles for the instruction being executed.

## § avr_core_irq_get_pending()

IntVect* avr_core_irq_get_pending | ( | AvrCore * | core | ) |

Gets the first pending irq.

Definition at line 846 of file avrcore.c.

## § avr_core_irq_raise()

void avr_core_irq_raise | ( | AvrCore * | core,
|  | unsigned int | irq
| ) |  |

Raises an irq by adding it's data to the irq_pending list.

Definition at line 854 of file avrcore.c.

References avr_message.

## § avr_core_irq_clear()

void avr_core_irq_clear | ( | AvrCore * | core,
|  | IntVect * | irq
| ) |  |

Calls the interrupt's callback to clear the flag.

Definition at line 867 of file avrcore.c.

## § avr_core_irq_clear_all()

void avr_core_irq_clear_all | ( | AvrCore * | core | ) |

Removes all irqs from the irq_pending list.

## § avr_core_insert_breakpoint()

void avr_core_insert_breakpoint | ( | AvrCore * | core,
|  | int | pc
| ) |  |

Inserts a break point.

Definition at line 884 of file avrcore.c.

References flash_read().

## § avr_core_remove_breakpoint()

void avr_core_remove_breakpoint | ( | AvrCore * | core,
|  | int | pc
| ) |  |

Removes a break point.

Definition at line 898 of file avrcore.c.

## § avr_core_disable_breakpoints()

void avr_core_disable_breakpoints | ( | AvrCore * | core | ) |

Disable breakpoints.

Disables all breakpoints that where set using avr_core_insert_breakpoint(). The breakpoints are not removed from the breakpoint list.

Definition at line 955 of file avrcore.c.

## § avr_core_enable_breakpoints()

void avr_core_enable_breakpoints | ( | AvrCore * | core | ) |

Enable breakpoints.

Enables all breakpoints that where previous disabled.

Definition at line 968 of file avrcore.c.

## § avr_core_step()

int avr_core_step | ( | AvrCore * | core | ) |

Process a single program instruction, all side effects and peripheral stimulii.

Executes instructions, calls callbacks, and checks for interrupts.

Definition at line 1093 of file avrcore.c.

References avr_core_get_state().

Referenced by avr_core_run().

## § avr_core_run()

void avr_core_run | ( | AvrCore * | core | ) |

Start the processing of instructions by the simulator.

The simulated device will run until one of the following occurs:

- The state of the core is no longer STATE_RUNNING.
- The simulator receives a SIGINT signal.
- A breakpoint is reached (currently causes core to stop running).
- A fatal internal error occurs.

Note
  When running simulavr in gdb server mode, this function is not used. The avr_core_step() function is called repeatedly in a loop when the continue command is issued from gdb. As such, the functionality in this loop should be kept to a minimum.

Todo:
  Should add some basic breakpoint handling here. Maybe allow continuing, and simple breakpoint management (disable, delete, set)

Definition at line 1150 of file avrcore.c.

References avr_core_reset(), avr_core_step(), avr_message, get_program_time(), signal_has_occurred(), signal_watch_start(), and signal_watch_stop().

## § avr_core_reset()

void avr_core_reset | ( | AvrCore * | core | ) |

Sets the simulated CPU back to its initial state.

Zeroes out PC, IRQ's, clock, and memory.

Definition at line 1204 of file avrcore.c.

Referenced by avr_core_run().

## § avr_core_add_ext_rd_wr()

void avr_core_add_ext_rd_wr | ( | AvrCore * | core,
|  | int | addr,
|  | PortFP_ExtRd | ext_rd,
|  | PortFP_ExtWr | ext_wr
| ) |  |

For adding external read and write callback functions.

rd and wr should come in pairs, but it is safe to add empty function via passing a NULL pointer for either function.

Parameters

  core | A pointer to an AvrCore object.
  port_id | The ID for handling the simulavr inheritance model.
  ext_rd | Function for the device core to call when it needs to communicate with the external world via I/O Ports.
  ext_wr | Function for the device core to call when it needs to communicate with the external world via I/O Ports.

Definition at line 1244 of file avrcore.c.

References avr_core_async_cb_add(), avr_core_async_cb_exec(), avr_core_clk_cb_add(), avr_core_clk_cb_exec(), avr_warning, mem_get_vdevice_by_addr(), and port_add_ext_rd_wr().

## § avr_core_clk_cb_add()

void avr_core_clk_cb_add | ( | AvrCore * | core,
|  | CallBack * | cb
| ) |  |

Add a new clock callback to list.

Referenced by avr_core_add_ext_rd_wr().

## § avr_core_async_cb_add()

void avr_core_async_cb_add | ( | AvrCore * | core,
|  | CallBack * | cb
| ) |  |

Add a new asynchronous callback to list.

Referenced by avr_core_add_ext_rd_wr().

## § avr_core_clk_cb_exec()

void avr_core_clk_cb_exec | ( | AvrCore * | core | ) |

Run all the callbacks in the list.

If a callback returns non-zero (true), then it is done with it's job and wishes to be removed from the list.

The time argument has dual meaning. If the callback list is for the clock callbacks, time is the value of the CK clock counter. If the callback list is for the asynchronous callback, time is the number of milliseconds from some unknown, arbitrary time on the host system.

Referenced by avr_core_add_ext_rd_wr().

## § avr_core_async_cb_exec()

void avr_core_async_cb_exec | ( | AvrCore * | core | ) |

Run all the asynchronous callbacks.

Referenced by avr_core_add_ext_rd_wr().

## § avr_core_dump_core()

void avr_core_dump_core | ( | AvrCore * | core,
|  | FILE * | f_core
| ) |  |

Dump the contents of the entire CPU core.

Parameters

  core | A pointer to an AvrCore object.
  f_core | An open file descriptor.

Definition at line 1294 of file avrcore.c.

## § avr_core_load_program()

int avr_core_load_program | ( | AvrCore * | core,
|  | char * | file,
|  | int | format
| ) |  |

Load a program from an input file.

Definition at line 1307 of file avrcore.c.

References flash_load_from_file().

## § avr_core_load_eeprom()

int avr_core_load_eeprom | ( | AvrCore * | core,
|  | char * | file,
|  | int | format
| ) |  |

Load a program from an input file.

Definition at line 1314 of file avrcore.c.

References mem_get_vdevice_by_name().

## Variable Documentation

## § global_debug_inst_output

int global_debug_inst_output = 0

Flag for enabling output of instruction debug messages.

Definition at line 64 of file avrcore.c.

Automatically generated by Doxygen 1.8.12 on Sun Apr 2 2017.