~maelkum/viuavm

311e0e178f76fae8ab14085387d526bc9280a499 — Marek Marecki 1 year, 6 months ago a128ed3
Basic implementation for AA instruction

It does not check if enough memory is allocated and blindly creates the
pointer. The check is a TODO.
3 files changed, 66 insertions(+), 3 deletions(-)

M new/Makefile
M new/src/vm/ins.cpp
A new/src/vm/ins/aa.cpp
M new/Makefile => new/Makefile +5 -0
@@ 194,12 194,16 @@ $(BUILD)/tools/exec/asm: \
	$(BUILD)/arch/arch.o \
	$(BUILD)/arch/ops.o

VIUA_INSTRUCTION_IMPLS=\
					   $(BUILD)/vm/ins/aa.o

$(BUILD)/tools/exec/vm: \
	$(BUILD)/support/tty.o \
	$(BUILD)/support/string.o \
	$(BUILD)/vm/core.o \
	$(BUILD)/vm/elf.o \
	$(BUILD)/vm/ins.o \
	$(VIUA_INSTRUCTION_IMPLS) \
	$(BUILD)/vm/types.o \
	$(BUILD)/vm/types/traits.o \
	$(BUILD)/runtime/pid.o \


@@ 212,6 216,7 @@ $(BUILD)/tools/exec/repl: \
	$(BUILD)/vm/core.o \
	$(BUILD)/vm/elf.o \
	$(BUILD)/vm/ins.o \
	$(VIUA_INSTRUCTION_IMPLS) \
	$(BUILD)/vm/types.o \
	$(BUILD)/vm/types/traits.o \
	$(BUILD)/support/string.o \

M new/src/vm/ins.cpp => new/src/vm/ins.cpp +0 -3
@@ 2064,9 2064,6 @@ auto execute(LM const op, Stack& stack, ip_type const ip) -> void
            throw abort_execution{ip, "invalid unit in memory instruction: " + std::to_string(unit)};
    }
}
auto execute(AA const, Stack&, ip_type const) -> void
{
}
auto execute(AD const, Stack&, ip_type const) -> void
{
}

A new/src/vm/ins/aa.cpp => new/src/vm/ins/aa.cpp +61 -0
@@ 0,0 1,61 @@
/*
 *  Copyright (C) 2021-2023 Marek Marecki
 *
 *  This file is part of Viua VM.
 *
 *  Viua VM is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Viua VM is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Viua VM.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <endian.h>

#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <optional>
#include <utility>
#include <vector>

#include <viua/arch/arch.h>
#include <viua/support/fdstream.h>
#include <viua/vm/ins.h>


namespace viua {
extern viua::support::fdstream TRACE_STREAM;
}

namespace viua::vm::ins {
using namespace viua::arch::ins;
using viua::vm::Stack;
using ip_type = viua::arch::instruction_type const*;

auto execute(AA const op, Stack& stack, ip_type const ip) -> void
{
    auto const size = get_value(stack, op.instruction.in, ip).get<uint64_t>();
    auto const alignment[[maybe_unused]] = (1 << op.instruction.spec);

    // FIXME Ensure that enough memory is available to satisfy both size and
    // alignment request.

    auto const old_sb = stack.proc->stack_break;
    stack.proc->stack_break += size;
    stack.frames.back().saved.sbrk = stack.proc->stack_break;

    auto& registers = stack.frames.back().registers;
    auto out        = get_proxy(registers, op.instruction.out, ip);
    out = old_sb;
}
}  // namespace viua::vm::ins