Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f611540
Add basic skeleton for netcard device
Jan 10, 2025
0cd2e5e
NIC: basic commands WIP
Feb 24, 2025
31be9ca
Netcard prepare DMA tranfer
Feb 24, 2025
4ea0954
Bugfix netcard buffer size
Feb 25, 2025
599b1e2
Network card add send packet
Feb 26, 2025
ce7b6b7
Acknowledge interrupt, reuse sockets
Mar 1, 2025
d2431be
Receive packet WIP
Mar 3, 2025
de83bc7
Bugfix status and packet receive
Mar 5, 2025
7fca8e1
Signal when failed to send packet
Mar 7, 2025
04efd4f
Complete data receiving
Apr 1, 2025
48d2190
Add dnetcard to doc
Apr 7, 2025
866d62b
Improve naming
Apr 7, 2025
9bf8e96
Prepare for listening on port
Apr 7, 2025
00740a4
Improve accept
Apr 7, 2025
9aa7fca
Change ip packet size from 65k to 1500
Jun 10, 2025
bf2b007
Allow netcard to listen locally or publicly
Jun 10, 2025
16ff432
Correctly close connections
Jun 13, 2025
237385f
Allow to listen on multiple ports
Jun 13, 2025
48245fd
Add network device configurable IP address
Jun 13, 2025
c85d4f2
Add test-os for device testing
Jun 25, 2025
2e7f11c
Prepare for testing network device
Jun 25, 2025
eb6ed3a
Prepare for multiple protocols
Jun 27, 2025
1542c17
Implement UDP
Jun 29, 2025
aed70cb
Add dnetcard registers test, fix offset
Jul 5, 2025
c192701
Add more dnetcard tests
Jul 7, 2025
4fb958d
Add device tests to all tests
Jul 8, 2025
359bca2
Add verbose mode for networking card
Jul 8, 2025
bd90bb9
Update documentation for network card
Jul 8, 2025
d732985
Bugfix unit-test compilation
Jul 14, 2025
ea54d45
Bugfix rebase
PeterHero Feb 19, 2026
410bcb2
Add dependencies for device tests
PeterHero Feb 19, 2026
4b19295
Fix format
PeterHero Feb 19, 2026
1cb0f52
Fix format
PeterHero Feb 19, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ jobs:
curl -L -o libpcut.deb https://github.com/vhotspur/pcut/releases/download/v0.0.1/libpcut_0.0.1_amd64.deb
sudo apt-get install ./libpcut.deb

sudo wget "https://d3s.mff.cuni.cz/f/teaching/nswi200/202526/pkg/ubuntu-24.04/mffd3s-binutils-riscv32-unknown-elf_2.45_amd64.deb"
sudo apt-get install ./mffd3s-binutils-riscv32-unknown-elf_2.45_amd64.deb
sudo wget "https://d3s.mff.cuni.cz/f/teaching/nswi200/202526/pkg/ubuntu-24.04/mffd3s-gcc-riscv32-unknown-elf_15.2.0_amd64.deb"
sudo apt-get install ./mffd3s-gcc-riscv32-unknown-elf_15.2.0_amd64.deb

- name: configure
run: ./configure

Expand Down
1 change: 1 addition & 0 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ distclean: clean
test:
make -C . rvtest
bats tests/system/
make -C tests/devices test

rvtest:
@echo "\nUnit tests:"
Expand Down
115 changes: 115 additions & 0 deletions doc/reference/devices.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1019,3 +1019,118 @@ Commands
Print a help on the command specified or a list of available commands.
``info``
Print configuration information (number of columns, number of rows, assigned register address).




Network card device ``dnetcard``
-----------------------------------

The device simulates a network card that has ability to send and receive packets
using DMA for data transfers between the card and memory.

Network card has optional logs which can be turned on using `verbose` variable: ``set verbose``.
This helps to detect some mistakes as connection failure with TCP.

Both DMA buffers have size of 1500, because that is a common MTU.

Supported protocols are UDP and simplified TCP. UDP protocol is fully supported.
Simplified TCP means, that the device sends only TCP data packets to/from the guest.
If the guest initiates a connection by sending a packet to a new address,
the device starts a connection which can be used to transfer the data.
If the connection can not be established, then both TX and ERR interrupts are raised signaling an error with sending packet.
Other features of the TCP protocol are not supported.

Initialization parameters: ``address`` ``intno``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

``address``
Physical address of the networking card register.
``intno``
DMA Interrupt number.

Registers
^^^^^^^^^

.. csv-table:: ``dnetcard`` programming registers
:header: Offset, Size, Name, Operation, Description
:widths: auto

"+0",4,"TX buffer address (lower 32 bits)",read,"Get the current physical address of the TX DMA buffer (lower 32 bits)"
,,,write,"Set the physical address of the TX DMA buffer (lower 32 bits)

* performing a send operation will send IP packet stored in this buffer
"
"+4",4,"TX buffer address (higher 4 bits)","read/write","Higher 4 bits for TX DMA physical address. See description of TX buffer address (lower 32 bits) for further details."
"+8",4,"RX buffer address (lower 32 bits)",read,"Get the current physical address of the RX DMA buffer (lower 32 bits)"
,,,write,"Set the physical address of the RX DMA buffer (lower 32 bits)

* performing a receive operationg will receive incoming IP packet into this buffer
* writing to this buffer while receiving is enabled results in an error
"
"+12",4,"RX buffer address (higher 4 bits)","read/write","Higher 4 bits for RX DMA physical address. See description of RX buffer address (lower 32 bits) for further details."
"+16",4,"status/command",read,"
Get a bitfield representing the current status of the device:

.. csv-table::
:header: 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5,4,3,2,1,0

r1,e_i,rx_i,tx_i,rec,r0

``r0``, ``r1``
(reserved)
``e_i``
0: no error

1: error interrupt pending because the previous operation cause an error

when combined with tx_i: dnetcard could not send IP packet (used in simplified TCP)
``rx_i``
0: no error

1: rx interrupt pending because received packet in RX buffer

data receiving is set off so that new RX address can be set
``tx_i``
0: no error

1: tx interrupt pending because finished sending packet from TX buffer
``rec``
0: dnetcard does not receive any data

1: dnetcard is ready for receiving
"
,,,write,"
Set a bitfield representing requested operation:

.. csv-table::
:header: 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5,4,3,2,1,0

r0,e_ack,rx_ack,tx_ack,rec,s

``r0``
(reserved)
``e_ack``
if set to 1 then the error interrupt is deasserted
``rx_ack``
if set to 1 then the rx interrupt is deasserted
``tx_ack``
if set to 1 then the tx interrupt is deasserted
``rec``
if set to 1 then dnetcard receving is switched (on/off depeding on previous state)
``s``
if set to 1 then a send operation is initiated (reading the data from TX DMA buffer)
"
"+20",4,"IP address","read/write","IP address assigned to the device by the guest. It must be set before the device can be used. This address must be used in outgoing packets and will be used in incoming packets."

Commands
^^^^^^^^

``help [cmd]``
Print a help on the command specified or a list of available commands.
``info``
Print the device information.
``stat``
Print device statistics.
``listen <port> <protocol - STCP or UDP> [<visibility - local (default) or public>]``
Listen on port with specified protocol. If listenning locally (default), MSIM listens on localhost. If listenning publicly, MSIM listens on some IP address of the host.
2 changes: 2 additions & 0 deletions doc/reference/internal_variables.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Following internal variables are available:

``trace``
Enable trace mode
``verbose``
Enable verbose mode for devices e.g. dnetcard
``iaddr``
Enable addresses in disassembler
``iopc``
Expand Down
1 change: 1 addition & 0 deletions src/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ SOURCES = \
device/dcycle.c \
device/dkeyboard.c \
device/dlcd.c \
device/dnetcard.c \
device/dnomem.c \
device/dorder.c \
device/dprinter.c \
Expand Down
6 changes: 4 additions & 2 deletions src/device/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "device.h"
#include "dkeyboard.h"
#include "dlcd.h"
#include "dnetcard.h"
#include "dnomem.h"
#include "dorder.h"
#include "dprinter.h"
Expand All @@ -42,7 +43,7 @@
#undef XLEN

/** Count of device types */
#define DEVICE_TYPE_COUNT 13
#define DEVICE_TYPE_COUNT 14

/* Implemented peripheral list */
const device_type_t *device_types[DEVICE_TYPE_COUNT] = {
Expand All @@ -58,7 +59,8 @@ const device_type_t *device_types[DEVICE_TYPE_COUNT] = {
&dnomem,
&ddisk,
&dtime,
&dlcd
&dlcd,
&dnetcard
};

/* List of all devices */
Expand Down
Loading