|
| 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; |
0 commit comments