Skip to content
This repository was archived by the owner on Jul 3, 2020. It is now read-only.
This repository was archived by the owner on Jul 3, 2020. It is now read-only.

Calling Assembly #139

Open
Open

Description

@RossComputerGuy

I'm trying to execute assembly and I'm having a problem figuring out how to impliment this system call in the NativesObject class. Does anyone know the best way? I think that if I have an enum that has all of the assembly opcodes that I could store them inside of a map so when someone executes the function it would read the map and execute the opcode.

Current Code:

NATIVE_FUNCTION(NativesObject,Assembly) {
  USEARG(0);
  char* cmd = (arg0.As<v8::String>())->Value();
  if(strcmp(cmd,"cli") == 0) {
   asm volatile ("cli");
  } else if(strcmp(cmd,"sti") == 0) {
   asm volatile ("sti");
  } else if(strcmp(cmd,"hlt") == 0) {
   asm volatile ("hlt");
  } else {
   args.GetReturnValue().Set(v8::Boolean::New(iv8,false));
  }
  args.GetReturnValue().Set(v8::Boolean::New(iv8,true));
}

Activity

  1. iefserge commented on Jan 3, 2017

    @iefserge
    Member

    @SpaceboyRoss01 Might be easier to create an ArrayBuffer with x86-64 instructions in js (I think i've seen npm module for this), then pass it to a native function that'll run it. Just curious, what are you trying to do with it? 😃

  2. RossComputerGuy commented on Jan 3, 2017

    @RossComputerGuy
    Author

    I'm going to make some things work better for some drivers.

  3. piranna commented on Jan 3, 2017

    @piranna

    I would not go that way... forget about assembler at all, you can do the same in plain C if you need some performance. So far only needed things to write the drivers in Javascript are bindings for memory access, catch interruptions and read & write on ports, everything else can be done in high-level Javascript.

  4. RossComputerGuy commented on Jan 3, 2017

    @RossComputerGuy
    Author

    How many instructions are in assembly

  5. RossComputerGuy commented on Jan 3, 2017

    @RossComputerGuy
    Author

    I'm trying to get to usermode in javascript

  6. piranna commented on Jan 3, 2017

    @piranna

    How many instructions are in assembly

    It depends of the CPU, but about 200-300 is a rought estimation.

    I'm trying to get to usermode in javascript

    Are you trying to move from ring 0 to ring 3? Why? The purposse of runtime.js is just to have everything in ring 0 for performance and apply a language-based security system...

  7. RossComputerGuy commented on Jan 3, 2017

    @RossComputerGuy
    Author

    I'm also doing this to work on executing binary files

  8. facekapow commented on Jan 3, 2017

    @facekapow
    Contributor

    If it's mainly for performance reasons, you could write the drivers in C or C++ and compile them to WebAssembly via Binaryen. After that you load them by requiring the produced JavaScript file and wrapping the necessary functions so you can call them later.

    You should know that you're going to be left in a mess if you try to do this. It's much cleaner to translate the programs to JavaScript, and also it's much more foolproof (compiling and running binaries on top of runtime.js is going to be very error prone).

    By the way, if all you plan on doing is being able to execute assembly and just loading in programs on top of that, you're going to end up compiling the whole Linux kernel as well, because all programs depend on kernel instructions somewhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions