jor1k Documentation
repository·master·Indexed 23 days ago
https://github.com/s-macke/jor1kjor1k is a JavaScript-based OpenRISC 1000 emulator capable of running Linux and other operating systems like RTEMS directly in a web browser. It provides a CPU facade supporting multiple implementations including safe, dynamic, asm.js, WebAssembly, and multi-core SMP. The library also includes a RISC-V CPU implementation and tools for hardware emulation, state inspection, and instruction execution within a browser environment.
What's inside jor1k
- jor1k is an OpenRISC 1000 emulator written in JavaScript that runs Linux. It is designed to run in almost any modern web browser, allowing for hardware emulation and OS execution directly in a web environment.
Explore jor1k demos
masterYou can interact with the emulator through various pre-configured demos:
- Main Demo: The primary entry point for the emulator.
- C Code Execution: Specialized demos that allow you to edit, compile, and run C code directly in your browser.
- Symmetric Multiprocessing (SMP): Demonstrations of multi-core support with 2, 4, 8, or 16 cores (note that stability may decrease as core count increases).
- RTEMS: A demo running the Real Time Operating System (RTEMS).
- RISC-V Implementation: A demo of the RISC-V CPU implementation. To use it, wait for the first message to appear in the terminal, then select
bblfrom the dropdown menu.
Download files or blobs using download()
masterThe
downloadfunction allows you to trigger a browser download for various data types, including strings, Blobs, Files, or dataURLs. It handles cross-browser compatibility, including legacy support for IE10+ and Safari.Arguments
data: The content to download. Can be astring,Blob,File, or adataURLstring.strFileName(optional): The name to be assigned to the downloaded file. Defaults to `
Inspect CPU state with toString()
masterTheCPUclass provides atoString()method that returns a formatted string representing the current state of the machine. This includes the Program Counter (PC), the contents of the general-purpose registers (r0-r31), and specific Control and Status Register (CSR) values likemstatus,mcause,mbadaddress, andmepc.Initialize the RISC-V CPU with the CPU class
masterThe
CPUclass acts as a facade for different RISC-V CPU implementations. To use it, instantiate theCPUclass with the required hardware abstractions (ram,htif,heap) and then call the asynchronous.Init()method to load the specific implementation.Supported
cpunamevalues:"safe": UsesSafeCPUimplementation."asm": UsesFastCPUimplementation."wasm": Uses a WebAssembly-based implementation (requiresriscv.wasmto be fetchable).
Note: The
CPUclass forwards several methods to the underlying implementation, includingReset,Step,RaiseInterrupt,AnalyzeImage,GetTicks,GetTimeToNextInterrupt,ProgressTime, andClearInterrupt.Initialize the OpenRISC 1000 CPU emulator
masterTo use the OpenRISC 1000 emulator, instantiate the
CPUclass and call itsInit()method. TheCPUclass acts as a facade that abstracts over different underlying CPU implementations.Available CPU types (
cpuname):safe: A safe implementation.dynamic: A dynamic implementation.asm: A high-performance asm.js implementation (singleton).smp: A multi-core SMP implementation (singleton).wasm: A WebAssembly implementation.
Required parameters for the constructor:
cpuname: The name of the CPU implementation to use.ram: A RAM object providing memory access methods (e.g.,Read32Big,Write32Big,Read16Big,Write16Big,Read8Big,Write8Big, and amemoryproperty for WASM).heap: A typed array representing the heap.ncores: The number of cores (required forsmp).
Control the CPU execution and state
masterOnce initialized, the
CPUinstance provides several methods to control the emulator and inspect its state. These methods are forwarded to the underlying implementation:Step(): Executes a single instruction.Reset(): Resets the CPU state.RaiseInterrupt(): Triggers an interrupt.ClearInterrupt(): Clears an interrupt.ProgressTime(ticks): Advances the simulated time.GetTicks(): Returns the current simulated clock ticks.GetTimeToNextInterrupt(): Returns the time remaining until the next interrupt.AnalyzeImage(): Analyzes the current instruction image.GetFlags(): Retrieves CPU flags.SetFlags(flags): Sets CPU flags.GetStat(): Retrieves CPU status.InvalidateTLB(): Invalidates the Translation Lookaside Buffer.
Additionally, calling
.toString()on theCPUinstance returns a human-readable string representing the current machine state, including the Program Counter (PC), register values (r0-r31), and various status register (SR) flags (e.g., Supervisor mode, Interrupt enabled, etc.).Available CPU implementation methods
masterThe
CPUfacade forwards the following methods to the underlying implementation (Safe, Fast, or WASM). These methods allow you to control the emulation lifecycle and inspect the state:Reset(): Resets the CPU state.Step(): Executes a single instruction or step.RaiseInterrupt(): Triggers an interrupt.ClearInterrupt(): Clears pending interrupts.AnalyzeImage(): Analyzes the current execution image.GetTicks(): Returns the current execution ticks.GetTimeToNextInterrupt(): Returns the estimated time until the next interrupt.ProgressTime(ticks): Advances the emulation time by a specific number of ticks.
If using the
wasmimplementation, the following additional methods are available via the WASM exports:GetFlags()GetStat()GetPC()InvalidateTLB()SetFlags()
Available CPU implementation types
masterThe
CPUfacade supports several underlying implementations, each suited for different performance or feature requirements:Type Description safeA safe CPU implementation. dynamicA dynamic CPU implementation. asmA high-performance asm.js implementation. Note: This is a singleton. smpA multi-core Symmetric Multi-Processing implementation. Note: This is a singleton. wasmA WebAssembly-based implementation.