sim_firmware.h Source File

yasimavr: sim_firmware.h Source File
yasimavr
Loading...
Searching...
No Matches
sim_firmware.h
Go to the documentation of this file.
1/*
2 * sim_firmware.h
3 *
4 * Copyright 2021-2026 Clement Savergne <csavergne@yahoo.com>
5
6 This file is part of yasim-avr.
7
8 yasim-avr is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 yasim-avr is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with yasim-avr. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22//=======================================================================================
23
24#ifndef __YASIMAVR_FIRMWARE_H__
25#define __YASIMAVR_FIRMWARE_H__
26
27#include "sim_types.h"
28#include "sim_memory.h"
29#include <map>
30
32
33
34//=======================================================================================
54
55public:
56
57 struct block_view_t {
59 size_t base = 0;
60 };
61
71
72 struct Symbol {
73 size_t addr;
74 size_t size;
75 std::string name;
77 };
78
80 unsigned long frequency;
82 double vcc;
84 double aref;
87
88 Firmware();
89 Firmware(const Firmware& other) = default;
90
91 static Firmware* read_elf(const std::string& filename);
92
93 void add_block(Area area, const block_view_t& block);
94
95 bool has_memory(Area area) const;
96
97 std::vector<Area> memories() const;
98
99 size_t memory_size(Area area) const;
100
101 std::vector<block_view_t> blocks(Area area) const;
102
103 bool load_memory(Area area, NonVolatileMemory& memory) const;
104
105 mem_addr_t datasize() const;
106 mem_addr_t bsssize() const;
107
108 void add_symbol(const Symbol& s);
109 const std::vector<Symbol>& symbols() const;
110
111 Firmware& operator=(const Firmware& other) = default;
112
113private:
114
115 struct block_t {
116 bytes_t bytes;
117 size_t base;
118
119 constexpr block_t(size_t b, size_t n) : bytes(n), base(b) {}
120 };
121
122 std::map<Area, std::vector<block_t>> m_blocks;
123 mem_addr_t m_datasize;
124 mem_addr_t m_bsssize;
125 std::vector<Symbol> m_symbols;
126
127};
128
130{
131 return m_datasize;
132}
133
135{
136 return m_bsssize;
137}
138
139inline const std::vector<Firmware::Symbol>& Firmware::symbols() const
140{
141 return m_symbols;
142}
143
144
146
147#endif //__YASIMAVR_FIRMWARE_H__
Definition sim_firmware.h:53
Firmware & operator=(const Firmware &other)=default
Firmware(const Firmware &other)=default
unsigned long frequency
Main clock frequency in hertz, mandatory to run the simulation.
Definition sim_firmware.h:80
mem_addr_t datasize() const
Definition sim_firmware.h:129
reg_addr_t console_register
I/O register address used for console output.
Definition sim_firmware.h:86
Area
Definition sim_firmware.h:62
@ Area_UserSignatures
Definition sim_firmware.h:69
@ Area_Flash
Definition sim_firmware.h:63
@ Area_Lock
Definition sim_firmware.h:67
@ Area_Fuses
Definition sim_firmware.h:66
@ Area_Signature
Definition sim_firmware.h:68
@ Area_Data
Definition sim_firmware.h:64
@ Area_EEPROM
Definition sim_firmware.h:65
mem_addr_t bsssize() const
Definition sim_firmware.h:134
double aref
Analog reference voltage in volts.
Definition sim_firmware.h:84
const std::vector< Symbol > & symbols() const
Definition sim_firmware.h:139
double vcc
Power supply voltage in volts. If not set, analog peripherals such as ADC are not usable.
Definition sim_firmware.h:82
Non-volatile memory model.
Definition sim_memory.h:42
Representation of a I/O register address, with validity state.
Definition sim_types.h:60
#define YASIMAVR_BEGIN_NAMESPACE
Definition sim_globals.h:58
#define AVR_CORE_PUBLIC_API
Definition sim_globals.h:46
#define YASIMAVR_END_NAMESPACE
Definition sim_globals.h:59
std::vector< uint8_t > bytes_t
Definition sim_types.h:51
unsigned long mem_addr_t
Definition sim_types.h:41
std::span< const uint8_t > bytes_view_t
Definition sim_types.h:52
Definition sim_firmware.h:72
size_t size
Definition sim_firmware.h:74
Area area
Definition sim_firmware.h:76
std::string name
Definition sim_firmware.h:75
size_t addr
Definition sim_firmware.h:73
Definition sim_firmware.h:57
bytes_view_t bytes
Definition sim_firmware.h:58