4 ms·
RISC-V 64-bit Linux in JavaScript
- alpb 10y agoThis was discussed last month. https://news.ycombinator.com/item?id=13210711 https://news.ycombinator.com/item?id=13210711
- bobajeff 10y agoWow, I'm running Linux on top of RISC-V in an emulator in my browser on my phone!
- ramblenode 10y ago~# date Thu Jan 1 00:03:09 UTC 1970
- chris_wot 10y agoSilly question, but is there an x86 instruction set emulator written in JavaScript? Not even Linux, just something that takes x86 instructions into a "virtual CPU" and lets you run the assembly statements?
- kbeckmann 10y agoNot a silly question at all. I would also like to know this. Would be a fun way to play around with assembly without the need of a tool chain etc. Maybe even on your phone while on the train. If this doesn't exist already, I'd be happy to start working on something like this.
- pmjordan 10y agoYou could probably start from here: x86 Linux running in a web browser, also by Fabrice Bellard. http://bellard.org/jslinux/ http://bellard.org/jslinux/
- kyberias 10y agoWell, each and every PC emulator implemented in Javascript contains an x86 instruction emulator. For example: http://copy.sh/v86/ http://copy.sh/v86/ And many others...
- prashnts 10y agoYep, v86 [0] is what you're looking for! There's even a demo with Linux 3. [1] [0] https://github.com/copy/v86 https://github.com/copy/v86 [1] https://copy.sh/v86/?profile=linux3 https://copy.sh/v86/?profile=linux3
- netheril96 10y agoSo, how do you do 64-bit arithmetic in JavaScript? Emulate with two 32-bit number? Won't that be a huge performance bottleneck, one that cannot be optimized by JIT?
- sjrd 10y agoYes, you emulate them with 32-bit numbers. It is a huge performance bottleneck if you do it naively, which most compile-to-JS languages that support 64-bit integers do. Emscripten even has a flag to let you choose between correct-but-slow 64-bit integers and fast-but-incorrect (drops to 53 bits). It is possible to get fast longs in JS, though, if you push your optimizer far enough. This is what we have done in Scala.js. I wrote a paper about this, but it is still under submission so I cannot disclose it just yet. However, I can point to the implementation: * The user-land implementation of `Long`s in Scala.js: https://github.com/scala-js/scala-js/blob/master/library/src/main/scala/scala/scalajs/runtime/RuntimeLong.scala https://github.com/scala-js/scala-js/blob/master/library/src... * The PR that made the performance breakthrough in the optimizer, by stack-allocating all instances of `RuntimeLong`: https://github.com/scala-js/scala-js/pull/2488 https://github.com/scala-js/scala-js/pull/2488
- bogomipz 10y agoI just had to look this up, the limitation is that JS has a max int of 2^53? Do you know what the reasons were for JS not implementing full 2^64? Also I noticed theres a JS C-types that has 64 bit ints, would that not help here?
- anewhnaccount 10y agoAll numbers in Javascript are IEEE 754 64-bit double precision floating point numbers. The significand precision is 53 bits (see here https://en.wikipedia.org/wiki/Double-precision_floating-point_format https://en.wikipedia.org/wiki/Double-precision_floating-poin...).
- bogomipz 10y ago
- Yan_Coutinho 10y agoArchiteture doesn't have kernel memory protection? Seems risky...
- orbifold 10y agoThere is a specification of privileged extensions, I think it was stabilised fairly recently: https://people.eecs.berkeley.edu/~krste/papers/riscv-priv-spec-1.7.pdf https://people.eecs.berkeley.edu/~krste/papers/riscv-priv-sp... The rocket chip generator https://github.com/ucb-bar/rocket-chip https://github.com/ucb-bar/rocket-chip and boom both have support for it, as far as I know.
- bogomipz 10y agoTangentially related this is a great talk about RISC-V architecture: https://www.youtube.com/watch?v=vB0FC1DZqUM&feature=youtu.be https://www.youtube.com/watch?v=vB0FC1DZqUM&feature=youtu.be