Main Page

- Main Page
- Related Pages
- Files

- File List
- Globals

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

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

Allocate a new AvrCore object.

Definition at line 355 of file avrcore.c.

References avr_core_destroy(), avr_new, class_overload_destroy(), and dev_supp_lookup_device().

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().

Referenced by avr_core_new().

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 flash_get_size().

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.

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

Returns the `VDevice` with the name name.

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

Returns the `VDevice` which handles the address addr.

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

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

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

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

Referenced by avr_core_step().

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.

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

Return the device's sleepmode.

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

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

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

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

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

Get the value of the rampz register.

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

Set the value of the rampz register.

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

Displays all registers.

Definition at line 733 of file avrcore.c.

References display_io_reg_name(), and mem_io_fetch().

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).

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.

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

Pop 1-4 bytes off of the stack.

See stack_pop() for more details.

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.

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).

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.

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

Get the current clock counter.

Referenced by avr_core_run().

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

Increment the clock counter.

Referenced by avr_core_step().

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

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

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

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

Referenced by avr_core_reset().

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

Gets the first pending irq.

Definition at line 846 of file avrcore.c.

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.

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.

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

Removes all irqs from the irq_pending list.

Referenced by avr_core_reset().

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

Inserts a break point.

Definition at line 884 of file avrcore.c.

References flash_read(), and flash_write().

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

Removes a break point.

Definition at line 898 of file avrcore.c.

References flash_write().

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.

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

Enable breakpoints.

Enables all breakpoints that where previous disabled.

Definition at line 968 of file avrcore.c.

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_async_cb_exec(), avr_core_CK_incr(), avr_core_clk_cb_exec(), and avr_core_get_state().

Referenced by 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_CK_get(), avr_core_reset(), avr_core_step(), avr_message, get_program_time(), signal_has_occurred(), signal_watch_start(), and signal_watch_stop().

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.

References avr_core_inst_CKS_set(), avr_core_irq_clear_all(), display_clock(), and mem_reset().

Referenced by avr_core_run().

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_warning, mem_get_vdevice_by_addr(), and port_add_ext_rd_wr().

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

Add a new clock callback to list.

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

Add a new asynchronous callback to list.

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_step().

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

Run all the asynchronous callbacks.

Referenced by avr_core_step().

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.

References flash_dump_core(), and mem_dump_core().

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().

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

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.2 on Mon Aug 18 2014.