Skip to content

Commit

Permalink
Add dnomem device (see PR #45)
Browse files Browse the repository at this point in the history
The dnomem device represents a memory region where any
reads or writes terminates with simulation failure.

The device is meant as a debugging aid to ensure our code is
not accessing non-existent memory.
  • Loading branch information
vhotspur authored Sep 25, 2023
2 parents aae5e00 + 14a838f commit 20b8812
Show file tree
Hide file tree
Showing 28 changed files with 557 additions and 2 deletions.
76 changes: 76 additions & 0 deletions doc/reference/devices.rst
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,82 @@ All attempts to write into read-only memory are silently ignored.
No-access memory ``dnomem``
---------------------------

The ``dnomem`` device represents a memory region where any reads or writes
terminates with simulation failure.

The device is meant as a debugging aid to ensure our code is not accessing
non-existent memory.

The device operates in three modes. In the default ``warn`` mode, attempts
to access are printed to console but the simulation continues.
In ``break`` mode, the simulation is switched to interactive mode after each
access.
And in ``halt`` mode, the simulation is immediately terminated.

It is possible to dump registers of the CPU that caused the violation
automatically by setting ``rd yes``.


Initialization parameters: ``address`` ``size``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

``address``
Starting physical address of the memory block.
``size``
Memory size.

Commands
^^^^^^^^

``help [cmd]``
Print a help on the command specified or a list of available commands.
``info``
Print the device information (block address, size and mode)
``mode``
Set device mode (either ``warn``, ``halt`` or ``break``).
``rd``
Whether to dump registers on violation (``yes`` or ``no``).


Examples
^^^^^^^^

In the following example, the ``add`` command creates a protected memory
region ``nomem`` starting at the physical address 0x08000000.
The size of the region is set to 4 KB.

.. code:: msim
[msim] add dnomem nomem 0x08000000 0x1000
[msim]
All attempts to read/write into this memory are reported.

.. code:: asm
la $a0, 0x88000004
lw $a1, 0($a0)
/* <msim> Alert: Ignoring READ (at 0x008000004, 0x4 inside nomem). */
If we configure the device to ``mode`` ``halt``, the simulation is halted upon
reaching the ``lw`` instruction. By using ``nomem rd yes``, registers are
dumped before the machine is halted.

.. code:: msim
[msim] nomem rd yes
[msim] nomem mode halt
[msim]
# la $a0, 0x88000004
# lw $a1, 0($a0)
# <msim> Alert: Halting after forbidden READ (at 0x008000004, 0x4 inside nomem).
Character output device ``dprinter``
------------------------------------

Expand Down
1 change: 1 addition & 0 deletions src/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ SOURCES = \
device/drvcpu.c \
device/dcycle.c \
device/dkeyboard.c \
device/dnomem.c \
device/dorder.c \
device/dprinter.c \
device/dtime.c \
Expand Down
4 changes: 3 additions & 1 deletion src/device/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "drvcpu.h"
#include "dcycle.h"
#include "dkeyboard.h"
#include "dnomem.h"
#include "dorder.h"
#include "ddisk.h"
#include "dprinter.h"
Expand All @@ -34,7 +35,7 @@
#include "../fault.h"

/** Count of device types */
#define DEVICE_TYPE_COUNT 10
#define DEVICE_TYPE_COUNT 11

/* Implemented peripheral list */
const device_type_t *device_types[DEVICE_TYPE_COUNT] = {
Expand All @@ -46,6 +47,7 @@ const device_type_t *device_types[DEVICE_TYPE_COUNT] = {
&dprinter,
&dorder,
&dkeyboard,
&dnomem,
&ddisk,
&dtime
};
Expand Down
Loading

0 comments on commit 20b8812

Please # to comment.