@@ -58,9 +58,7 @@ inline unit_kind get_unit_kind(unit_id_t unit_id) {
5858
5959// / @brief Retrieve the 'index' part of a unit ID. This could be for example the
6060// / hart ID if the unit refers to a hart.
61- inline uint16_t get_unit_index (unit_id_t unit_id) {
62- return (unit_id & 0xffff );
63- }
61+ inline uint16_t get_unit_index (unit_id_t unit_id) { return (unit_id & 0xffff ); }
6462
6563// / @brief Return a textual representation of the unit ID.
6664std::string format_unit (unit_id_t unit_id);
@@ -145,7 +143,7 @@ class MemoryDeviceBase : public MemoryDevice {
145143// / device's base address. This base address is used to query the memory
146144// / interface for the sub-device which 'lives' at a specified address.
147145class MemoryInterface : public MemoryDevice {
148- public:
146+ public:
149147 // / @brief Query the memory interface for a device at the given address.
150148 // / @param addr Address to query for a device.
151149 // / @param dev_offset On success, offset from the returned device's base
@@ -156,7 +154,7 @@ class MemoryInterface : public MemoryDevice {
156154// / @brief Utility class to help manage a set of devices under the same address
157155// / space. Devices can be added and removed dynamically.
158156class MemoryController : public MemoryInterface {
159- public:
157+ public:
160158 // / @brief Create a new memory controller with no sub-devices.
161159 MemoryController () {}
162160
@@ -169,7 +167,7 @@ class MemoryController : public MemoryInterface {
169167 // / another device is already using the base address.
170168 // / @param addr Base address of the device, i.e. where it will be mapped.
171169 // / @param dev Device to add to map in the memory controller.
172- bool add_device (reg_t addr, MemoryDevice* dev);
170+ bool add_device (reg_t addr, MemoryDevice * dev);
173171
174172 // / @brief Remove (unmap) a device from the memory controller, given its exact
175173 // / base address.
@@ -182,10 +180,10 @@ class MemoryController : public MemoryInterface {
182180 // / region.
183181 // / @param addr Address to use to locate the device.
184182 // / @return Pair of (base address, memory device) on success.
185- std::pair<reg_t , MemoryDevice*> find_device (reg_t addr);
183+ std::pair<reg_t , MemoryDevice *> find_device (reg_t addr);
186184
187185 // / @brief Return a read-only map of the mapped devices.
188- const std::map<reg_t , MemoryDevice*> & get_devices () { return devices; }
186+ const std::map<reg_t , MemoryDevice *> &get_devices () { return devices; }
189187
190188 // / @brief Try to find a device mapped at the given address, which does not
191189 // / need to be the base address but can point anywhere in the device's memory
@@ -218,7 +216,7 @@ class MemoryController : public MemoryInterface {
218216 // / be nullptr.
219217 // / @param unit ID of the execution unit requesting the memory access.
220218 // / @return true on success and false on failure.
221- bool load (reg_t addr, size_t len, uint8_t * bytes, unit_id_t unit) override ;
219+ bool load (reg_t addr, size_t len, uint8_t * bytes, unit_id_t unit) override ;
222220
223221 // / @brief Try to write data to the device. This is equivalent to calling
224222 // / @ref find_device followed by @ref store on the returned device,
@@ -228,7 +226,7 @@ class MemoryController : public MemoryInterface {
228226 // / @param bytes Data to write to the device - must not be nullptr.
229227 // / @param unit ID of the execution unit requesting the memory access.
230228 // / @return true on success and false on failure.
231- bool store (reg_t addr, size_t len, const uint8_t * bytes,
229+ bool store (reg_t addr, size_t len, const uint8_t * bytes,
232230 unit_id_t unit) override ;
233231
234232 // / @brief Try to copy data from one area of memory to another.
@@ -239,16 +237,14 @@ class MemoryController : public MemoryInterface {
239237 // / @return true on success and false on failure.
240238 bool copy (reg_t dst_addr, reg_t src_addr, size_t len, unit_id_t unit);
241239
242- private:
243- std::map<reg_t , MemoryDevice*> devices;
240+ private:
241+ std::map<reg_t , MemoryDevice *> devices;
244242};
245243
246244class RAMDevice : public MemoryDeviceBase {
247245 public:
248- RAMDevice (size_t size);
249- virtual ~RAMDevice () {
250- free (data);
251- }
246+ RAMDevice (size_t size);
247+ virtual ~RAMDevice () { free (data); }
252248
253249 uint8_t *contents () { return data; }
254250 size_t mem_size () const override { return size; }
@@ -262,9 +258,7 @@ class RAMDevice : public MemoryDeviceBase {
262258
263259class ROMDevice : public MemoryDeviceBase {
264260 public:
265- ROMDevice (size_t size) {
266- data.resize (size);
267- }
261+ ROMDevice (size_t size) { data.resize (size); }
268262
269263 uint8_t *contents () { return data.data (); }
270264 size_t mem_size () const override { return data.size (); }
@@ -280,47 +274,47 @@ class ROMDevice : public MemoryDeviceBase {
280274};
281275
282276class HartLocalDevice : public MemoryDeviceBase {
283- public:
277+ public:
284278 HartLocalDevice (size_t size) : size(size) {}
285279 virtual ~HartLocalDevice ();
286280
287281 uint8_t *addr_to_mem (reg_t addr, size_t size, unit_id_t unit_id) override ;
288282
289- uint8_t * mem_contents (unit_id_t unit_id);
283+ uint8_t * mem_contents (unit_id_t unit_id);
290284 size_t mem_size () const override { return size; }
291285
292- private:
286+ private:
293287 size_t size;
294288 std::vector<uint8_t *> hart_contents;
295289};
296290
297291class FileDevice : public MemoryDevice {
298- public:
292+ public:
299293 FileDevice (const char *path);
300294 virtual ~FileDevice ();
301295
302296 bool is_open () const { return fd >= 0 ; }
303297
304298 size_t mem_size () const override ;
305299
306- bool load (reg_t addr, size_t len, uint8_t * bytes, unit_id_t unit_id) override ;
307- bool store (reg_t addr, size_t len, const uint8_t * bytes,
300+ bool load (reg_t addr, size_t len, uint8_t * bytes, unit_id_t unit_id) override ;
301+ bool store (reg_t addr, size_t len, const uint8_t * bytes,
308302 unit_id_t unit_id) override ;
309303
310- private:
304+ private:
311305 int fd;
312306};
313307
314308class BufferDevice : public MemoryDeviceBase {
315- public:
309+ public:
316310 BufferDevice (const void *data, size_t size) : data(data), size(size) {}
317311
318312 size_t mem_size () const override { return size; }
319313
320314 uint8_t *addr_to_mem (reg_t dev_offset, size_t size,
321315 unit_id_t unit_id) override ;
322316
323- private:
317+ private:
324318 const void *data;
325319 size_t size;
326320};
0 commit comments