From 2514893136d2653c8c090383dc23b12b7394edef Mon Sep 17 00:00:00 2001 From: "Chloe M." Date: Sun, 24 May 2026 17:08:15 -0500 Subject: [PATCH] mvm: Add state management groundwork Signed-off-by: Chloe M. --- mvm/core/state_subr.c | 42 ++++++++++++++++++++++++++++++++++++++++ mvm/include/mvm/common.h | 12 ++++++++++++ mvm/include/mvm/state.h | 41 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 mvm/core/state_subr.c create mode 100644 mvm/include/mvm/common.h create mode 100644 mvm/include/mvm/state.h diff --git a/mvm/core/state_subr.c b/mvm/core/state_subr.c new file mode 100644 index 0000000..35d52ca --- /dev/null +++ b/mvm/core/state_subr.c @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2026 Mirocom Laboratories and MSP engineers. + * All Rights Reserved. + */ + +#include +#include +#include +#include "mvm/state.h" +#include "mvm/common.h" + +int +mvm_state_init(struct mvm_state *state) +{ + if (state == NULL) { + errno = EINVAL; + return -1; + } + + if (bus_ctl_init(&state->busctl) < 0) { + errno = EIO; + return -1; + } + + if (mvm_rom_init(&state->bootrom, MVM_BOOTROM_SIZE) < 0) { + errno = EIO; + return -1; + } + + return 0; +} + +void +mvm_state_free(struct mvm_state *state) +{ + if (state == NULL) { + return; + } + + bus_ctl_free(&state->busctl); + mvm_rom_free(&state->bootrom); +} diff --git a/mvm/include/mvm/common.h b/mvm/include/mvm/common.h new file mode 100644 index 0000000..36be3cb --- /dev/null +++ b/mvm/include/mvm/common.h @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2026 Mirocom Laboratories and MSP engineers. + * All Rights Reserved. + */ + +#ifndef MVM_COMMON_H +#define MVM_COMMON_H 1 + +/* Maximum boot ROM capacity */ +#define MVM_BOOTROM_SIZE 1024 + +#endif /* !MVM_COMMON_H */ diff --git a/mvm/include/mvm/state.h b/mvm/include/mvm/state.h new file mode 100644 index 0000000..98363b1 --- /dev/null +++ b/mvm/include/mvm/state.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2026 Mirocom Laboratories and MSP engineers. + * All Rights Reserved. + */ + +#ifndef MVM_STATE_H +#define MVM_STATE_H 1 + +#include +#include +#include "mvm/rom.h" +#include "mvm/bus.h" + +/* + * Represents the virtual machine state + * + * @busctl: Bus controller + * @bootrom: Boot rom + */ +struct mvm_state { + struct mvm_bus_ctl busctl; + struct mvm_rom bootrom; +}; + +/* + * Initialize the virtual machine state + * + * @state: State machine to initialize + * + * Returns zero on success + */ +int mvm_state_init(struct mvm_state *state); + +/* + * Release a state and its associated resources from memory + * + * @state: State to deallocate. + */ +void mvm_state_free(struct mvm_state *state); + +#endif /* !MVM_STATE_H */