Giter Site home page Giter Site logo

scsvm's Introduction

Hi. Iโ€™m Ryan. I spend a lot of time working on hobby projects and I'm currently in the process of learning the Rust programming language.

scsvm's People

Contributors

sciguyryan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

scsvm's Issues

Ensure stack pointer register is correctly updated and initialized

Ensure that the stack pointer is correctly updated when executing instructions and ensure that the stack pointer is correctly initialized.

As it currently stands:

  • the two push instructions (PSH_LIT and PSH_REG) do not update the stack pointer register at all
  • the stack pointer is not reset in Cpu.Reset at all (though it is initialized in VirtualMachine.LoadAndInitialize)

Ensure that IP register is checked after ExecuteInstruction

SCSVM/VM/VM/CPU.cs

Lines 447 to 456 in 319bacf

if (ExecuteInstruction(ins, asmIns))
{
SetHaltedState(true);
}
// Have we executed everything that needs to be executed?
if (pos >= _maxExecutableBound)
{
SetHaltedState(true);
}

While implementing the RET instruction I noticed that the IP register needs to be checked after executing the instruction. The reason for which is outlined below.

Currently the "pos" variable is checked and that is not updated to reflect any changes that may have occurred when executing an instruction. The RET instruction, for example, will restore the IP register to the value it had when it was called. The new IP register value will be ignored when the final should halt check takes place.

Change the access permissions of the stack memory region to R, PW

Change the access permissions of the stack memory region to public read, private write.

Reading this memory region from user code will be use useful when handling arguments passed to subroutines. Specifically it will allow us to avoid having to manipulate the stack when calling a subroutine.

For example.

push $0x321     ; Arg 3
push $0x123     ; Arg 2
push $0x213     ; Arg 1
push $0x3       ; 3 arguments
call @TESTER:
hlt
@TESTER:
pop R1
pop R2
pop R3
ret

In this example upon entering the @tester subroutine the stack would look something like this:

[0x321]
[0x123]
[0x213]
[0x3]
[R1]
[etc.]
[R8]
[IP]

From the perspective of the subroutine the top of the stack does not contain the arguments.

This can be resolved in one of two ways.

  1. Allow the stack memory region to be read directly.
  2. Shuffle the stack so that the arguments are at the top of the stack when the subroutine is executed.

The former seems like a cleaner and simpler way of doing this.

Setting values within this memory region directly should still be disallowed from user code and will still require system-level permissions.

A big thanks to @wearereasonablepeople for helping me wrap my head around this.

Support Compiler Directives (Pseudo-Instructions)

Support compiler directives similar to those shown here:

https://www.nasm.us/doc/nasmdoc3.html

This will require some extensive changes to the compiler and infrastructure.

  1. This will require the removal of the CanBindToArgument checks and code since virtually any argument can have a directive bound to it. This will make some of the code simpler to work with.
  2. This will require loading the whole binary file into the virtual machine as opposed to just the code section.
    2a. This will require changing the entry point IP for the program to ensure that it points to the correct place within the binary file.
  3. The compiler might have to do an additional label substitution pass if the values are simply substituted by the existing mechanisms.

I will update this list as more things come to mind.

Change the access permissions of the Frame Pointer (FP) register to R, PW

Change the access permissions of the Frame Pointer (FP) register to public read, private write.

Reading this register in user code will be use useful when handling arguments passed to subroutines.

Setting the value of the register will still need to be done via system-level code as changing the value could cause severe breakage.

Implement memory breakpoints

Implement memory breakpoints that work akin to the current CPU breakpoints.

This may have some performance overheads, so this will need to be checked also.

Fix register argument validity check in ASM parser

Currently the following string is accepted as valid by the ASM parser:

mov $0xA, 53

The issue here is that Enum.TryParse will correctly parse 53 as a valid value for the Registers type. I have no idea why this happens. The simplest solution is to switch the check to a hash set lookup instead.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.