diff --git a/emulation/betrusted.repl b/emulation/betrusted.repl index 646373bbe..d864f1235 100644 --- a/emulation/betrusted.repl +++ b/emulation/betrusted.repl @@ -4,41 +4,36 @@ cpu: CPU.VexRiscv @ sysbus privilegeArchitecture: PrivilegeArchitecture.Priv1_10 uart: UART.LiteX_UART @ { - sysbus 0x60008000; - sysbus 0xF0008000 // shadow + sysbus 0x60006000; + sysbus 0xF0006000 // shadow } -> cpu@1002 uartconsole: UART.LiteX_UART @ { - sysbus 0x6000A000; - sysbus 0xF000A000 // shadow + sysbus 0x60007000; + sysbus 0xF0007000 // shadow } -> cpu@1003 uartserver0: UART.LiteX_UART @ { - sysbus 0x6000C000; - sysbus 0xF000C000 // shadow + sysbus 0x60008000; + sysbus 0xF0008000 // shadow } -> cpu@1004 uartserver1: UART.LiteX_UART @ { - sysbus 0x6000E000; - sysbus 0xF000E000 // shadow + sysbus 0x60009000; + sysbus 0xF0009000 // shadow } -> cpu@1005 timer0: Timers.LiteX_Timer_32 @ { - sysbus 0x60003000; - sysbus 0xF0003000 // shadow + sysbus 0x60002000; + sysbus 0xF0002000 // shadow } frequency: 100000000 -> cpu@1001 -//spi: SPI.PicoRV_SPI @ { - // sysbus 0x60004000; - // sysbus 0xe0004000 // shadow -//} - rom: Memory.MappedMemory @ { sysbus 0x00000000; sysbus 0x80000000 // shadow @@ -54,16 +49,20 @@ sram: Memory.MappedMemory @ { fbmem: Memory.MappedMemory @ sysbus 0xB0000000 size: 0x6000 -memlcd: Video.BetrustedLCD @ sysbus 0xF0011000 +memlcd: Video.BetrustedLCD @ sysbus 0xF000C000 -kbd: Input.BetrustedKbd @ sysbus 0xF0006000 +keyboard: Input.BetrustedKbd @ sysbus 0xF0015000 + +trng_server: Miscellaneous.BetrustedRNGServer @ sysbus 0xF001A000 + +trng_kernel: Miscellaneous.BetrustedRNGKernel @ sysbus 0xF0019000 cpu_timer: Timers.LiteX_CPUTimer @ sysbus 0xf0000800 frequency: 100000000 // IRQ #100 is Machine Timer Interrupt -> cpu@100 -ticktimer: Timers.TickTimer @ sysbus 0xF0017000 +ticktimer: Timers.TickTimer @ sysbus 0xF0012000 periodInMs: 1 -> cpu @ 1008 @@ -78,7 +77,5 @@ flash_mem: Memory.MappedMemory @ { sysbus: init: - Tag <0xe0000000 0x800> "CTRL" - Tag <0xE0006000 0x800> "REBOOT" - Tag <0xE0006800 0x800> "RGB" - Tag <0xE0007000 0x800> "VERSION" + Tag <0xF0000000 0x1000> "CTRL" + Tag <0xF001B000 0x1000> "TRNG" diff --git a/emulation/peripherals/trng_kernel.cs b/emulation/peripherals/trng_kernel.cs new file mode 100644 index 000000000..79c46d3c6 --- /dev/null +++ b/emulation/peripherals/trng_kernel.cs @@ -0,0 +1,48 @@ +// +// Copyright (c) 2010-2019 Antmicro +// +// This file is licensed under the MIT License. +// Full license text is available in 'licenses/MIT.txt'. +// +using Antmicro.Renode.Core; +using Antmicro.Renode.Core.Structure.Registers; +using Antmicro.Renode.Logging; + +namespace Antmicro.Renode.Peripherals.Miscellaneous +{ + public class BetrustedRNGKernel : BasicDoubleWordPeripheral, IKnownSize + { + public BetrustedRNGKernel(Machine machine) : base(machine) + { + DefineRegisters(); + } + + public long Size { get { return 0x1000; } } + + private void DefineRegisters() + { + Registers.STATUS.Define(this) // RDY is set on reset + .WithValueField(0, 32, FieldMode.Read, valueProviderCallback: _ => + { + return 3; + }, name: "STATUS"); + + Registers.DATA.Define(this) + .WithValueField(0, 32, FieldMode.Read, valueProviderCallback: _ => + { + return (uint)rng.Next(); + }, name: "DATA"); + } + + private readonly PseudorandomNumberGenerator rng = EmulationManager.Instance.CurrentEmulation.RandomGenerator; + + private enum Registers + { + STATUS = 0x0, + DATA = 0x4, + EV_STATUS = 0x8, + EV_PENDING = 0x0c, + EV_ENABLE = 0x10, + } + } +} diff --git a/emulation/peripherals/trng_server.cs b/emulation/peripherals/trng_server.cs new file mode 100644 index 000000000..43892a27d --- /dev/null +++ b/emulation/peripherals/trng_server.cs @@ -0,0 +1,52 @@ +// +// Copyright (c) 2010-2019 Antmicro +// +// This file is licensed under the MIT License. +// Full license text is available in 'licenses/MIT.txt'. +// +using Antmicro.Renode.Core; +using Antmicro.Renode.Core.Structure.Registers; +using Antmicro.Renode.Logging; + +namespace Antmicro.Renode.Peripherals.Miscellaneous +{ + public class BetrustedRNGServer : BasicDoubleWordPeripheral, IKnownSize + { + public BetrustedRNGServer(Machine machine) : base(machine) + { + DefineRegisters(); + } + + public long Size { get { return 0x1000; } } + + private void DefineRegisters() + { + Registers.STATUS.Define(this) // RDY is set on reset + .WithValueField(0, 32, FieldMode.Read, valueProviderCallback: _ => + { + return (1 << 0) | (1 << 21); + }, name: "STATUS"); + + Registers.DATA.Define(this) + .WithValueField(0, 32, FieldMode.Read, valueProviderCallback: _ => + { + return (uint)rng.Next(); + }, name: "DATA"); + } + + private readonly PseudorandomNumberGenerator rng = EmulationManager.Instance.CurrentEmulation.RandomGenerator; + + private enum Registers + { + CONTROL = 0x0, + STATUS = 0x4, + DATA = 0x8, + AV_CONFIG = 0xc, + RO_CONFIG = 0x10, + ERRORS = 0x14, + EV_STATUS = 0x18, + EV_PENDING = 0x1c, + EV_ENABLE = 0x20, + } + } +} diff --git a/emulation/renode.svd b/emulation/renode.svd index 6548ff5bf..6a9c3179f 100644 --- a/emulation/renode.svd +++ b/emulation/renode.svd @@ -12,68 +12,9 @@ 0xFFFFFFFF - - CTRL - 0xF0000000 - CTRL - - - RESET - - 0x0000 - 0x00 - 32 - - - reset - 0 - [0:0] - 0 - - - - - SCRATCH - - 0x0004 - 0x12345678 - 32 - - - scratch - 31 - [31:0] - 0 - - - - - BUS_ERRORS - - 0x0008 - 0x00 - 32 - - - bus_errors - 31 - [31:0] - 0 - - - - - - 0 - 0xc - registers - - IDENTIFIER_MEM - 0xF0002000 + 0xF0001000 IDENTIFIER_MEM @@ -100,7 +41,7 @@ to the Wishbone/CSR bus are working correctly. The initial reset value of TIMER0 - 0xF0003000 + 0xF0002000 TIMER0 @@ -246,17 +187,19 @@ register to disable individual events.]]> REBOOT - 0xF0004000 + 0xF0003000 REBOOT - CTRL + SOC_RESET + 0x0000 0x00 32 - ctrl + soc_reset 7 [7:0] 0 @@ -265,6 +208,7 @@ register to disable individual events.]]> ADDR + 0x0004 0x00 32 @@ -277,16 +221,32 @@ register to disable individual events.]]> + + CPU_RESET + + 0x0008 + 0x00 + 32 + + + cpu_reset + 0 + [0:0] + 0 + + + 0 - 0x8 + 0xc registers CRG - 0xF0005000 + 0xF0004000 CRG @@ -410,7 +370,7 @@ register to disable individual events.]]> GPIO - 0xF0006000 + 0xF0005000 GPIO @@ -499,8 +459,8 @@ console, others undefined]]> uartsel - 1 - [1:0] + 0 + [0:0] 0 @@ -724,7 +684,7 @@ register to disable individual events.]]> UART_PHY - 0xF0007000 + 0xF0006000 UART_PHY @@ -750,7 +710,7 @@ register to disable individual events.]]> UART - 0xF0008000 + 0xF0007000 UART @@ -908,7 +868,7 @@ register to disable individual events.]]> CONSOLE_PHY - 0xF0009000 + 0xF0008000 CONSOLE_PHY @@ -934,7 +894,7 @@ register to disable individual events.]]> CONSOLE - 0xF000A000 + 0xF0009000 CONSOLE @@ -1090,377 +1050,9 @@ register to disable individual events.]]> 3 - - SERVER0_PHY - 0xF000B000 - SERVER0_PHY - - - TUNING_WORD - 0x0000 - 0x4b7f5a - 32 - - - tuning_word - 31 - [31:0] - 0 - - - - - - 0 - 0x4 - registers - - - - SERVER0 - 0xF000C000 - SERVER0 - - - RXTX - 0x0000 - 0x00 - 32 - - - rxtx - 7 - [7:0] - 0 - - - - - TXFULL - 0x0004 - 0x00 - 32 - - - txfull - 0 - [0:0] - 0 - - - - - RXEMPTY - 0x0008 - 0x00 - 32 - - - rxempty - 0 - [0:0] - 0 - - - - - EV_STATUS - - 0x000c - 0x00 - 32 - - - tx - 0 - [0:0] - 0 - - - - rx - 1 - [1:1] - 1 - - - - - - EV_PENDING - - 0x0010 - 0x00 - 32 - - - tx - 0 - [0:0] - 0 - - - - rx - 1 - [1:1] - 1 - - - - - - EV_ENABLE - - 0x0014 - 0x00 - 32 - - - tx - 0 - [0:0] - 0 - - - - rx - 1 - [1:1] - 1 - - - - - - TXEMPTY - 0x0018 - 0x00 - 32 - - - txempty - 0 - [0:0] - 0 - - - - - RXFULL - 0x001c - 0x00 - 32 - - - rxfull - 0 - [0:0] - 0 - - - - - - 0 - 0x20 - registers - - - server0 - 4 - - - - SERVER1_PHY - 0xF000D000 - SERVER1_PHY - - - TUNING_WORD - 0x0000 - 0x4b7f5a - 32 - - - tuning_word - 31 - [31:0] - 0 - - - - - - 0 - 0x4 - registers - - - - SERVER1 - 0xF000E000 - SERVER1 - - - RXTX - 0x0000 - 0x00 - 32 - - - rxtx - 7 - [7:0] - 0 - - - - - TXFULL - 0x0004 - 0x00 - 32 - - - txfull - 0 - [0:0] - 0 - - - - - RXEMPTY - 0x0008 - 0x00 - 32 - - - rxempty - 0 - [0:0] - 0 - - - - - EV_STATUS - - 0x000c - 0x00 - 32 - - - tx - 0 - [0:0] - 0 - - - - rx - 1 - [1:1] - 1 - - - - - - EV_PENDING - - 0x0010 - 0x00 - 32 - - - tx - 0 - [0:0] - 0 - - - - rx - 1 - [1:1] - 1 - - - - - - EV_ENABLE - - 0x0014 - 0x00 - 32 - - - tx - 0 - [0:0] - 0 - - - - rx - 1 - [1:1] - 1 - - - - - - TXEMPTY - 0x0018 - 0x00 - 32 - - - txempty - 0 - [0:0] - 0 - - - - - RXFULL - 0x001c - 0x00 - 32 - - - rxfull - 0 - [0:0] - 0 - - - - - - 0 - 0x20 - registers - - - server1 - 5 - - INFO - 0xF000F000 + 0xF000A000 INFO @@ -1651,212 +1243,16 @@ modifications.]]> - - XADC_TEMPERATURE - - 0x0030 - 0x00 - 32 - - - xadc_temperature - 11 - [11:0] - 0 - - - - - XADC_VCCINT - - 0x0034 - 0x00 - 32 - - - xadc_vccint - 11 - [11:0] - 0 - - - - - XADC_VCCAUX - - 0x0038 - 0x00 - 32 - - - xadc_vccaux - 11 - [11:0] - 0 - - - - - XADC_VCCBRAM - - 0x003c - 0x00 - 32 - - - xadc_vccbram - 11 - [11:0] - 0 - - - - - XADC_EOC - - 0x0040 - 0x00 - 32 - - - xadc_eoc - 0 - [0:0] - 0 - - - - - XADC_EOS - - 0x0044 - 0x00 - 32 - - - xadc_eos - 0 - [0:0] - 0 - - - - - XADC_DRP_ENABLE - 0x0048 - 0x00 - 32 - - - xadc_drp_enable - 0 - [0:0] - 0 - - - - - XADC_DRP_READ - 0x004c - 0x00 - 32 - - - xadc_drp_read - 0 - [0:0] - 0 - - - - - XADC_DRP_WRITE - 0x0050 - 0x00 - 32 - - - xadc_drp_write - 0 - [0:0] - 0 - - - - - XADC_DRP_DRDY - 0x0054 - 0x00 - 32 - - - xadc_drp_drdy - 0 - [0:0] - 0 - - - - - XADC_DRP_ADR - 0x0058 - 0x00 - 32 - - - xadc_drp_adr - 6 - [6:0] - 0 - - - - - XADC_DRP_DAT_W - 0x005c - 0x00 - 32 - - - xadc_drp_dat_w - 15 - [15:0] - 0 - - - - - XADC_DRP_DAT_R - 0x0060 - 0x00 - 32 - - - xadc_drp_dat_r - 15 - [15:0] - 0 - - - 0 - 0x64 + 0x30 registers SRAM_EXT - 0xF0010000 + 0xF000B000 SRAM_EXT @@ -1898,7 +1294,7 @@ VCCBRAM (V) = ``Value`` x 3 / 4096.]]> MEMLCD - 0xF0011000 + 0xF000C000 MEMLCD @@ -2014,7 +1410,7 @@ register to disable individual events.]]> COM - 0xF0012000 + 0xF000D000 COM @@ -2166,19 +1562,19 @@ register to disable individual events.]]> - - com - 16 - 0 0x1c registers + + com + 4 + I2C - 0xF0013000 + 0xF000E000 I2C @@ -2426,12 +1822,12 @@ register to disable individual events.]]> i2c - 6 + 5 BTEVENTS - 0xF0014000 + 0xF000F000 BTEVENTS @@ -2515,12 +1911,12 @@ register to disable individual events.]]> btevents - 7 + 6 MESSIBLE - 0xF0015000 + 0xF0010000 MESSIBLE @@ -2586,7 +1982,7 @@ register advances the read pointer automatically.]]> MESSIBLE2 - 0xF0016000 + 0xF0011000 MESSIBLE2 @@ -2652,7 +2048,7 @@ register advances the read pointer automatically.]]> TICKTIMER - 0xF0017000 + 0xF0012000 TICKTIMER @@ -2797,12 +2193,12 @@ register to disable individual events.]]> ticktimer - 8 + 7 POWER - 0xF0018000 + 0xF0013000 POWER @@ -2843,47 +2239,32 @@ and not safe to shut down, resets to 01 to allow extSRAM access immediately during init]]> - noisebias + reset_ec 5 [5:5] 5 - - - - noise - 7 - [7:6] - 6 - - - - reset_ec - 8 - [8:8] - 8 up5k_on - 9 - [9:9] - 9 + 6 + [6:6] + 6 boostmode - 10 - [10:10] - 10 + 7 + [7:7] + 7 selfdestruct - 11 - [11:11] - 11 + 8 + [8:8] + 8 @@ -2962,7 +2343,7 @@ reset fashion]]> SPINOR - 0xF0019000 + 0xF0014000 SPINOR @@ -3243,7 +2624,7 @@ checked]]> KEYBOARD - 0xF001A000 + 0xF0015000 KEYBOARD @@ -3453,19 +2834,19 @@ again until the interrupt is serviced.]]> keyboard - 9 + 8 SEED - 0xF001B000 + 0xF0016000 SEED SEED1 0x0000 - 0x20483d3b + 0x2bab99b7 32 @@ -3480,7 +2861,7 @@ again until the interrupt is serviced.]]> SEED0 0x0004 - 0x1febda0d + 0x364d429c 32 @@ -3500,7 +2881,7 @@ again until the interrupt is serviced.]]> ROMTEST - 0xF001C000 + 0xF0017000 ROMTEST @@ -3542,7 +2923,7 @@ again until the interrupt is serviced.]]> AUDIO - 0xF001D000 + 0xF0018000 AUDIO @@ -3909,69 +3290,213 @@ I2S_FORMAT.I2S_STANDARD is I2S standard]]> audio - 10 + 9 - TRNG_OSC - 0xF001E000 - TRNG_OSC + TRNG_KERNEL + 0xF0019000 + TRNG_KERNEL - CTL + STATUS 0x0000 - 0x2000192 + 0x00 32 - ena + ready 0 [0:0] 0 - + - gang + avail 1 [1:1] 1 - + - dwell - 21 - [21:2] + rdcount + 11 + [11:2] 2 - + - delay - 31 - [31:22] - 22 - + wrcount + 21 + [21:12] + 12 + - RAND + DATA 0x0004 - 0xdeadbeef + 0x00 32 - rand + data 31 [31:0] 0 - + + + + + + EV_STATUS + + 0x0008 + 0x00 + 32 + + + avail + 0 + [0:0] + 0 + + + + error + 1 + [1:1] + 1 + + + + + + EV_PENDING + + 0x000c + 0x00 + 32 + + + avail + 0 + [0:0] + 0 + + + + error + 1 + [1:1] + 1 + + + + + + EV_ENABLE + + 0x0010 + 0x00 + 32 + + + avail + 0 + [0:0] + 0 + + + + error + 1 + [1:1] + 1 + + + + + + + 0 + 0x14 + registers + + + trng_kernel + 10 + + + + TRNG_SERVER + 0xF001A000 + TRNG_SERVER + + + CONTROL + 0x0000 + 0x09 + 32 + + + enable + 0 + [0:0] + 0 + + + + ro_dis + 1 + [1:1] + 1 + + + + av_dis + 2 + [2:2] + 2 + + + + powersave + 3 + [3:3] + 3 + + + + no_check + 4 + [4:4] + 4 + + + + clr_err + 5 + [5:5] + 5 + + + + + + DATA + 0x0004 + 0x00 + 32 + + + data + 31 + [31:0] + 0 + @@ -3982,25 +3507,511 @@ coupling of the deterministic sysclk noise into the rings.]]> 32 - fresh + avail 0 [0:0] 0 - + + + + rdcount + 10 + [10:1] + 1 + + + + wrcount + 20 + [20:11] + 11 + + + + full + 21 + [21:21] + 21 + + + + + + AV_CONFIG + 0x000c + 0x30d40 + 32 + + + powerdelay + 19 + [19:0] + 0 + + + + + + RO_CONFIG + 0x0010 + 0x10000c9 + 32 + + + gang + 0 + [0:0] + 0 + + + + dwell + 20 + [20:1] + 1 + + + + delay + 30 + [30:21] + 21 + + + + + + ERRORS + 0x0014 + 0x00 + 32 + + + server_underrun + 9 + [9:0] + 0 + + + + kernel_underrun + 19 + [19:10] + 10 + + + + ro_health + 20 + [20:20] + 20 + + + + av_health + 21 + [21:21] + 21 + + + + + + EV_STATUS + + 0x0018 + 0x00 + 32 + + + avail + 0 + [0:0] + 0 + + + + error + 1 + [1:1] + 1 + + + + health + 2 + [2:2] + 2 + + + + + + EV_PENDING + + 0x001c + 0x00 + 32 + + + avail + 0 + [0:0] + 0 + + + + error + 1 + [1:1] + 1 + + + + health + 2 + [2:2] + 2 + + + + + + EV_ENABLE + + 0x0020 + 0x00 + 32 + + + avail + 0 + [0:0] + 0 + + + + error + 1 + [1:1] + 1 + + + + health + 2 + [2:2] + 2 + 0 - 0xc + 0x24 + registers + + + trng_server + 11 + + + + TRNG + 0xF001B000 + TRNG + + + XADC_TEMPERATURE + + 0x0000 + 0x00 + 32 + + + xadc_temperature + 11 + [11:0] + 0 + + + + + XADC_VCCINT + + 0x0004 + 0x00 + 32 + + + xadc_vccint + 11 + [11:0] + 0 + + + + + XADC_VCCAUX + + 0x0008 + 0x00 + 32 + + + xadc_vccaux + 11 + [11:0] + 0 + + + + + XADC_VCCBRAM + + 0x000c + 0x00 + 32 + + + xadc_vccbram + 11 + [11:0] + 0 + + + + + XADC_VBUS + + 0x0010 + 0x00 + 32 + + + xadc_vbus + 11 + [11:0] + 0 + + + + + XADC_USB_P + + 0x0014 + 0x00 + 32 + + + xadc_usb_p + 11 + [11:0] + 0 + + + + + XADC_USB_N + + 0x0018 + 0x00 + 32 + + + xadc_usb_n + 11 + [11:0] + 0 + + + + + XADC_NOISE0 + + 0x001c + 0x00 + 32 + + + xadc_noise0 + 11 + [11:0] + 0 + + + + + XADC_NOISE1 + + 0x0020 + 0x00 + 32 + + + xadc_noise1 + 11 + [11:0] + 0 + + + + + XADC_EOC + + 0x0024 + 0x00 + 32 + + + xadc_eoc + 0 + [0:0] + 0 + + + + + XADC_EOS + + 0x0028 + 0x00 + 32 + + + xadc_eos + 0 + [0:0] + 0 + + + + + XADC_DRP_ENABLE + 0x002c + 0x00 + 32 + + + xadc_drp_enable + 0 + [0:0] + 0 + + + + + XADC_DRP_READ + 0x0030 + 0x00 + 32 + + + xadc_drp_read + 0 + [0:0] + 0 + + + + + XADC_DRP_WRITE + 0x0034 + 0x00 + 32 + + + xadc_drp_write + 0 + [0:0] + 0 + + + + + XADC_DRP_DRDY + 0x0038 + 0x00 + 32 + + + xadc_drp_drdy + 0 + [0:0] + 0 + + + + + XADC_DRP_ADR + 0x003c + 0x00 + 32 + + + xadc_drp_adr + 6 + [6:0] + 0 + + + + + XADC_DRP_DAT_W + 0x0040 + 0x00 + 32 + + + xadc_drp_dat_w + 15 + [15:0] + 0 + + + + + XADC_DRP_DAT_R + 0x0044 + 0x00 + 32 + + + xadc_drp_dat_r + 15 + [15:0] + 0 + + + + + + 0 + 0x48 registers AES - 0xF001F000 + 0xF001C000 AES @@ -4463,7 +4474,7 @@ automatically on data and IV ready]]> SHA512 - 0xF0020000 + 0xF001D000 SHA512 @@ -4953,12 +4964,12 @@ in bits]]> sha512 - 11 + 12 ENGINE - 0xF0021000 + 0xF001E000 ENGINE @@ -5182,12 +5193,12 @@ exactly reflects the binary layout of an Engine instruction.]]> engine - 12 + 13 JTAG - 0xF0022000 + 0xF001F000 JTAG @@ -5350,4 +5361,4 @@ entered. Defaults to a range of 1.67-5.00 seconds]]> - + \ No newline at end of file diff --git a/emulation/xous-release.resc b/emulation/xous-release.resc index da37e7408..c283b423a 100644 --- a/emulation/xous-release.resc +++ b/emulation/xous-release.resc @@ -13,6 +13,8 @@ i @peripherals/LiteX_Timer_32.cs i @peripherals/memlcd.cs i @peripherals/keyboard.cs i @peripherals/ticktimer.cs +i @peripherals/trng_kernel.cs +i @peripherals/trng_server.cs # Load the Betrusted Renode Platform file machine LoadPlatformDescription @betrusted.repl