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

Calling Assembly #139

Open
RossComputerGuy opened this issue Jan 3, 2017 · 8 comments
Open

Calling Assembly #139

RossComputerGuy opened this issue Jan 3, 2017 · 8 comments

Comments

@RossComputerGuy
Copy link

RossComputerGuy commented Jan 3, 2017

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));
}
@iefserge
Copy link
Member

iefserge commented Jan 3, 2017

@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? 😃

@RossComputerGuy
Copy link
Author

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

@piranna
Copy link

piranna commented Jan 3, 2017

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.

@RossComputerGuy
Copy link
Author

How many instructions are in assembly

@RossComputerGuy
Copy link
Author

I'm trying to get to usermode in javascript

@piranna
Copy link

piranna commented Jan 3, 2017

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...

@RossComputerGuy
Copy link
Author

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

@facekapow
Copy link
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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants