From 311e0e178f76fae8ab14085387d526bc9280a499 Mon Sep 17 00:00:00 2001 From: Marek Marecki Date: Fri, 26 May 2023 01:35:02 +0200 Subject: [PATCH] Basic implementation for AA instruction It does not check if enough memory is allocated and blindly creates the pointer. The check is a TODO. --- new/Makefile | 5 ++++ new/src/vm/ins.cpp | 3 --- new/src/vm/ins/aa.cpp | 61 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 new/src/vm/ins/aa.cpp diff --git a/new/Makefile b/new/Makefile index cd55407d6..91bd7a368 100644 --- a/new/Makefile +++ b/new/Makefile @@ -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 \ diff --git a/new/src/vm/ins.cpp b/new/src/vm/ins.cpp index 5d8ea78fa..2188eac57 100644 --- a/new/src/vm/ins.cpp +++ b/new/src/vm/ins.cpp @@ -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 { } diff --git a/new/src/vm/ins/aa.cpp b/new/src/vm/ins/aa.cpp new file mode 100644 index 000000000..2e124bdb4 --- /dev/null +++ b/new/src/vm/ins/aa.cpp @@ -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 . + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + + +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(); + 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 -- 2.38.5