Skip to content

Commit 23c60d0

Browse files
committed
Separate init routines and load DTB
1 parent e1e9326 commit 23c60d0

File tree

5 files changed

+263
-316
lines changed

5 files changed

+263
-316
lines changed

demos/riscv.html

+1
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ <h1 style="font-family:'Raleway';">RISC-V Simple Demo</h1>
226226
statsid: "stats",
227227
system: {
228228
kernelURL: tests[1],
229+
dtbURL: "riscv.dtb",
229230
arch: "riscv",
230231
cpu: "safe",
231232
memorysize: 64,

js/master/system.js

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ function jor1kGUI(parameters)
4141

4242
// add path to every URL
4343
this.params.system.kernelURL = this.params.path + this.params.system.kernelURL;
44+
this.params.system.dtbURL = this.params.path + this.params.system.dtbURL;
4445
this.params.fs.basefsURL = this.params.path + this.params.fs.basefsURL;
4546
if (this.params.fs.extendedfsURL) {
4647
this.params.fs.extendedfsURL = this.params.path + this.params.fs.extendedfsURL;

js/worker/init_openrisc.js

+134
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
// -------------------------------------------------
2+
// --------------- INIT OPENRISC -------------------
3+
// -------------------------------------------------
4+
5+
"use strict";
6+
// common
7+
var message = require('./messagehandler'); // global variable
8+
var utils = require('./utils');
9+
10+
// CPU
11+
var OR1KCPU = require('./or1k');
12+
13+
var UARTDev = require('./dev/uart');
14+
var IRQDev = require('./dev/irq');
15+
var TimerDev = require('./dev/timer');
16+
var FBDev = require('./dev/framebuffer');
17+
var EthDev = require('./dev/ethmac');
18+
var ATADev = require('./dev/ata');
19+
var RTCDev = require('./dev/rtc');
20+
var TouchscreenDev = require('./dev/touchscreen');
21+
var KeyboardDev = require('./dev/keyboard');
22+
var SoundDev = require('./dev/sound');
23+
var VirtIODev = require('./dev/virtio');
24+
var Virtio9p = require('./dev/virtio/9p');
25+
var VirtioDummy = require('./dev/virtio/dummy');
26+
var VirtioInput = require('./dev/virtio/input');
27+
var VirtioNET = require('./dev/virtio/net');
28+
var VirtioBlock = require('./dev/virtio/block');
29+
var VirtioGPU = require('./dev/virtio/gpu');
30+
var VirtioConsole = require('./dev/virtio/console');
31+
32+
/*
33+
Heap Layout for OpenRISC emulation
34+
==================================
35+
The heap is needed by the asm.js CPU.
36+
For compatibility all CPUs use the same layout
37+
by using the different views of typed arrays
38+
39+
------ Core 1 ------
40+
0x0 - 0x7F 32 CPU registers
41+
0x80 - 0x1FFF CPU specific, usually unused or temporary data
42+
0x2000 - 0x3FFF group 0 (system control and status)
43+
0x4000 - 0x5FFF group 1 (data MMU)
44+
0x6000 - 0x7FFF group 2 (instruction MMU)
45+
------ Core 2 ------
46+
0x8000 - 0x807F 32 CPU registers
47+
0x8080 - 0x9FFF CPU specific, usually unused or temporary data
48+
0xA000 - 0xBFFF group 0 (system control and status)
49+
0xC000 - 0xDFFF group 1 (data MMU)
50+
0xE000 - 0xFFFF group 2 (instruction MMU)
51+
------ Core 3 ------
52+
...
53+
------- RAM --------
54+
0x100000 - ... RAM
55+
*/
56+
57+
function InitOpenRISC(system, initdata) {
58+
message.Debug("Init OpenRISC SoC");
59+
var irqhandler = system;
60+
61+
try {
62+
system.cpu = new OR1KCPU(initdata.cpu, system.ram, system.heap, system.ncores);
63+
} catch (e) {
64+
message.Debug("Error: failed to create CPU:" + e);
65+
}
66+
system.devices.push(system.cpu);
67+
68+
system.irqdev = new IRQDev(irqhandler);
69+
system.timerdev = new TimerDev();
70+
system.uartdev0 = new UARTDev(0, irqhandler, 0x2);
71+
system.uartdev1 = new UARTDev(1, irqhandler, 0x3);
72+
system.ethdev = new EthDev(system.ram, irqhandler);
73+
system.ethdev.TransmitCallback = function(data) {
74+
message.Send("ethmac", data);
75+
};
76+
77+
system.fbdev = new FBDev(system.ram);
78+
system.atadev = new ATADev(irqhandler);
79+
system.tsdev = new TouchscreenDev(irqhandler);
80+
system.kbddev = new KeyboardDev(irqhandler);
81+
system.snddev = new SoundDev(irqhandler, system.ram);
82+
system.rtcdev = new RTCDev(irqhandler);
83+
84+
system.virtioinputdev = new VirtioInput(system.ram);
85+
system.virtionetdev = new VirtioNET(system.ram);
86+
system.virtioblockdev = new VirtioBlock(system.ram);
87+
system.virtiodummydev = new VirtioDummy(system.ram);
88+
system.virtiogpudev = new VirtioGPU(system.ram);
89+
system.virtioconsoledev = new VirtioConsole(system.ram);
90+
system.virtiodev1 = new VirtIODev(irqhandler, 0x6, system.ram, system.virtio9pdev);
91+
system.virtiodev2 = new VirtIODev(irqhandler, 0xB, system.ram, system.virtiodummydev);
92+
system.virtiodev3 = new VirtIODev(irqhandler, 0xC, system.ram, system.virtiodummydev);
93+
94+
system.devices.push(system.irqdev);
95+
system.devices.push(system.timerdev);
96+
system.devices.push(system.uartdev0);
97+
system.devices.push(system.uartdev1);
98+
system.devices.push(system.ethdev);
99+
system.devices.push(system.fbdev);
100+
system.devices.push(system.atadev);
101+
system.devices.push(system.tsdev);
102+
system.devices.push(system.kbddev);
103+
system.devices.push(system.snddev);
104+
system.devices.push(system.rtcdev);
105+
system.devices.push(system.virtio9pdev);
106+
system.devices.push(system.virtiodev1);
107+
system.devices.push(system.virtiodev2);
108+
system.devices.push(system.virtiodev3);
109+
110+
system.devices.push(system.virtioinputdev);
111+
system.devices.push(system.virtionetdev);
112+
system.devices.push(system.virtioblockdev);
113+
system.devices.push(system.virtiodummydev);
114+
system.devices.push(system.virtiogpudev);
115+
system.devices.push(system.virtioconsoledev);
116+
117+
system.ram.AddDevice(system.uartdev0, 0x90000000, 0x7);
118+
system.ram.AddDevice(system.fbdev, 0x91000000, 0x1000);
119+
system.ram.AddDevice(system.ethdev, 0x92000000, 0x1000);
120+
system.ram.AddDevice(system.tsdev, 0x93000000, 0x1000);
121+
system.ram.AddDevice(system.kbddev, 0x94000000, 0x100);
122+
system.ram.AddDevice(system.uartdev1, 0x96000000, 0x7);
123+
system.ram.AddDevice(system.virtiodev1, 0x97000000, 0x1000);
124+
system.ram.AddDevice(system.snddev, 0x98000000, 0x400);
125+
system.ram.AddDevice(system.rtcdev, 0x99000000, 0x1000);
126+
system.ram.AddDevice(system.irqdev, 0x9A000000, 0x1000);
127+
system.ram.AddDevice(system.timerdev, 0x9B000000, 0x1000);
128+
system.ram.AddDevice(system.virtiodev2, 0x9C000000, 0x1000);
129+
system.ram.AddDevice(system.virtiodev3, 0x9D000000, 0x1000);
130+
system.ram.AddDevice(system.atadev, 0x9E000000, 0x1000);
131+
132+
}
133+
134+
module.exports = InitOpenRISC;

js/worker/init_riscv.js

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// -------------------------------------------------
2+
// ---------------- INIT RISCV ---------------------
3+
// -------------------------------------------------
4+
5+
/*
6+
compile dts file via
7+
dtc -O dtb riscv.dts > riscv.dtb
8+
od -A n -t x1 -v riscv.dtb | sed 's/ /,0x/g'
9+
*/
10+
11+
"use strict";
12+
// common
13+
var message = require('./messagehandler'); // global variable
14+
var utils = require('./utils');
15+
16+
// CPU
17+
var RISCVCPU = require('./riscv');;
18+
19+
// Devices
20+
var HTIF = require('./riscv/htif');
21+
var CLINTDev = require('./dev/clint');
22+
var PLICDev = require('./dev/plic');
23+
var ROMDev = require('./dev/rom');
24+
var UARTDev = require('./dev/uart');
25+
26+
//var IRQDev = require('./dev/irq');
27+
//var TimerDev = require('./dev/timer');
28+
//var FBDev = require('./dev/framebuffer');
29+
//var EthDev = require('./dev/ethmac');
30+
//var ATADev = require('./dev/ata');
31+
//var RTCDev = require('./dev/rtc');
32+
//var TouchscreenDev = require('./dev/touchscreen');
33+
//var KeyboardDev = require('./dev/keyboard');
34+
//var SoundDev = require('./dev/sound');
35+
var VirtIODev = require('./dev/virtio');
36+
var Virtio9p = require('./dev/virtio/9p');
37+
//var VirtioDummy = require('./dev/virtio/dummy');
38+
//var VirtioInput = require('./dev/virtio/input');
39+
//var VirtioNET = require('./dev/virtio/net');
40+
//var VirtioBlock = require('./dev/virtio/block');
41+
//var VirtioGPU = require('./dev/virtio/gpu');
42+
//var VirtioConsole = require('./dev/virtio/console');
43+
44+
45+
function InitRISCV(system, initdata) {
46+
message.Debug("Init RISCV SoC");
47+
var irqhandler = system;
48+
49+
// at the moment the htif interface is part of the CPU initialization.
50+
// However, it uses uartdev0
51+
system.htif = new HTIF(system.ram, system);
52+
53+
system.cpu = new RISCVCPU(initdata.cpu, system.ram, system.htif, system.heap, system.ncores);
54+
55+
system.devices.push(system.cpu);
56+
57+
system.rom = new ArrayBuffer(0x2000);
58+
var buffer32view = new Int32Array(system.rom);
59+
var buffer8view = new Uint8Array(system.rom);
60+
// boot process starts at 0x1000
61+
buffer32view[0x400] = 0x297 + 0x80000000 - 0x1000; // auipc t0, DRAM_BASE=0x80000000
62+
buffer32view[0x401] = 0x597; // auipc a1, 0 // a1 = 0x1004
63+
buffer32view[0x402] = 0x58593 + ((8*4-4)<<20); // addi a1, a1, 0 (pointer to dtb)
64+
buffer32view[0x403] = 0xf1402573; // csrr a0,mhartid
65+
buffer32view[0x404] = 0x00028067 // jalr zero, t0, 0 (jump straight to DRAM_BASE)
66+
buffer32view[0x405] = 0x00000000; // trap vector
67+
buffer32view[0x406] = 0x00000000; // trap vector
68+
buffer32view[0x407] = 0x00000000; // trap vector
69+
70+
message.Debug("Load DTB");
71+
utils.LoadBinaryResourceII(initdata.dtbURL,
72+
function(buffer) {
73+
var configstring = new Uint8Array(buffer);
74+
for(var i=0; i<configstring.length; i++) buffer8view[0x1020+i] = configstring[i];
75+
}.bind(this)
76+
, false, function(error){throw error;});
77+
78+
system.virtiodev1 = new VirtIODev(irqhandler, 0x1, system.ram, system.virtio9pdev);
79+
system.romdev = new ROMDev(system.rom);
80+
system.uartdev0 = new UARTDev(0, irqhandler, 2);
81+
system.clintdev = new CLINTDev(irqhandler);
82+
system.plicdev = new PLICDev(irqhandler);
83+
84+
system.devices.push(system.romdev);
85+
system.devices.push(system.uartdev0);
86+
system.devices.push(system.clintdev);
87+
system.devices.push(system.plicdev);
88+
system.devices.push(system.virtiodev1);
89+
system.devices.push(system.virtio9pdev);
90+
91+
system.ram.AddDevice(system.romdev, 0x00000000, 0x7);
92+
system.ram.AddDevice(system.uartdev0, 0x03000000, 0x2000);
93+
system.ram.AddDevice(system.clintdev, 0x02000000, 0x2000);
94+
system.ram.AddDevice(system.plicdev, 0x04000000, 0xF00000);
95+
system.ram.AddDevice(system.virtiodev1, 0x20000000, 0x2000);
96+
97+
}
98+
99+
module.exports = InitRISCV;

0 commit comments

Comments
 (0)