Skip to content

Latest commit

 

History

History
591 lines (344 loc) · 11.4 KB

File metadata and controls

591 lines (344 loc) · 11.4 KB

Machine

#include <machine.hpp>

class Machine

Defined in include/machine.hpp:50

RV64-VM Main machine class.

This class implements RISC-V emulator machine.

List of all members

Name Kind Owner
virtio_count variable Declared here
Machine function Declared here
~Machine function Declared here
start_init function Declared here
end_init function Declared here
run function Declared here
stop function Declared here
reset function Declared here
wait function Declared here
get_mmio function Declared here
get_fdt function Declared here
get_timebase function Declared here
get_mmap function Declared here
get_state function Declared here
get_memory_size function Declared here
get_hart_count function Declared here
get_hart function Declared here
load_vd_image function Declared here
load_bios function Declared here
load_kernel function Declared here
load_dtb function Declared here
get_vd_image function Declared here
set_uart_output function Declared here
get_uart_output function Declared here
MachineState enum Declared here

Public Attributes

Return Name Description
int virtio_count VirtIO devices counter.

virtio_count

int virtio_count = 0

Defined in include/machine.hpp:247

VirtIO devices counter.

Public Methods

Return Name Description
Machine Machine constructor.
~Machine Machine destructor.
void start_init inline Device initialization start.
void end_init inline Device initialization end.
void run Runs machine.
void stop Stops machine.
void reset Resets machines.
void wait Joins machine work thread.
MMIO * get_mmio inline Returns MMIO pointer.
fdt_node * get_fdt inline Returns FDT pointer.
uint64_t get_timebase const inline Returns config specified timer timebase (Hz/S)
MemoryMap * get_mmap inline Returns MemoryMap pointer.
MachineState get_state const inline Returns Machine internal state.
uint64_t get_memory_size const inline Returns config specified RAM size.
uint8_t get_hart_count const inline Returns config specified Hart count.
Hart & get_hart inline Returns specified Hart by index.
bool load_vd_image Loads Image file to VirtIO-Blk.
bool load_bios Loads Firmware file.
bool load_kernel Loads Kernel file.
bool load_dtb Loads DTB file.
FILE * get_vd_image Returns FILE pointer to loaded VirtIO-Blk file.
void set_uart_output Sets UART output stream.
FILE * get_uart_output Returns UART output stream.

Machine

Machine(constMachineConfig & cfg)

Defined in include/machine.hpp:69

Machine constructor.

Creates RISC-V machine

See also: MachineConfig

Parameters

Parameter Type Description
cfg constMachineConfig & Machine configuration

~Machine

~Machine()

Defined in include/machine.hpp:75

Machine destructor.

Destroys RISC-V machine

Note

It is recommended to stop machine before destroy it.


start_init

inline

inline void start_init()

Defined in include/machine.hpp:86

Device initialization start.

Creates FDT Base for all devices In this block you supposed to create all devices you want, or load DTB from file.


end_init

inline

inline void end_init()

Defined in include/machine.hpp:96

Device initialization end.

Writes FDT to memory. This function must be called after you created all devices you wanted.


run

void run()

Defined in include/machine.hpp:105

Runs machine.

Starts all Hart's execution loop.


stop

void stop()

Defined in include/machine.hpp:111

Stops machine.

Sends a signal to machine so it could stop and destroy all harts safely.

Note

In that moment it joins work thread.


reset

void reset()

Defined in include/machine.hpp:117

Resets machines.

Sends a signal to machine so it could safely recreate all HART's.

Warning

Untested, but it is not recommended to first-time start machine with this function.


wait

void wait()

Defined in include/machine.hpp:121

Joins machine work thread.


get_mmio

inline

inline MMIO * get_mmio()

Defined in include/machine.hpp:128

Returns MMIO pointer.

See also: MMIO

Returns

MMIO Pointer


get_fdt

inline

inline fdt_node * get_fdt()

Defined in include/machine.hpp:134

Returns FDT pointer.

See also: libfdt.h

Returns

FDT pointer


get_timebase

const inline

inline uint64_t get_timebase() const

Defined in include/machine.hpp:139

Returns config specified timer timebase (Hz/S)

Returns

Timebase number


get_mmap

inline

inline MemoryMap * get_mmap()

Defined in include/machine.hpp:145

Returns MemoryMap pointer.

See also: MemoryMap

Returns

MemoryMap pointer


get_state

const inline

inline MachineState get_state() const

Defined in include/machine.hpp:152

Returns Machine internal state.

See also: MachineState

Returns

Machine State enum


get_memory_size

const inline

inline uint64_t get_memory_size() const

Defined in include/machine.hpp:157

Returns config specified RAM size.

Returns

Memory Size (bytes)


get_hart_count

const inline

inline uint8_t get_hart_count() const

Defined in include/machine.hpp:163

Returns config specified Hart count.

See also: HART

Returns

HART count


get_hart

inline

inline Hart & get_hart(size_t index)

Defined in include/machine.hpp:170

Returns specified Hart by index.

See also: Hart

Returns

Hart object

Parameters

Parameter Type Description
index size_t HART index (not ID!)

load_vd_image

bool load_vd_image(const std::string & path)

Defined in include/machine.hpp:177

Loads Image file to VirtIO-Blk.

Returns

Success bool

Parameters

Parameter Type Description
path const std::string & Image path

load_bios

bool load_bios(const std::string & path)

Defined in include/machine.hpp:183

Loads Firmware file.

Returns

Success bool

Parameters

Parameter Type Description
path const std::string & Firmware path

load_kernel

bool load_kernel(const std::string & path)

Defined in include/machine.hpp:189

Loads Kernel file.

Returns

Success bool

Parameters

Parameter Type Description
path const std::string & Kernel path

load_dtb

bool load_dtb(const std::string & path)

Defined in include/machine.hpp:197

Loads DTB file.

Loads custom FDT from DTB to memory.

Note

Make sure to set init_fdt in config to false before init!

Returns

Success bool

Parameters

Parameter Type Description
path const std::string & DTB path

get_vd_image

FILE * get_vd_image(int idx)

Defined in include/machine.hpp:203

Returns FILE pointer to loaded VirtIO-Blk file.

Returns

FILE pointer

Parameters

Parameter Type Description
idx int Image index

set_uart_output

void set_uart_output(FILE * stream)

Defined in include/machine.hpp:208

Sets UART output stream.

Parameters

Parameter Type Description
stream FILE * Output stream

get_uart_output

FILE * get_uart_output()

Defined in include/machine.hpp:213

Returns UART output stream.

Returns

Output stream

Public Types

Name Description
MachineState Machine State enum.

MachineState

enum MachineState

Defined in include/machine.hpp:56

Machine State enum.

Value Description
Off
Halted Powered off
Running Awaiting any command
Resetting Self-explanatory