[PATCH master 1/3] RISC-V: cpu: request stack memory region

Antony Pavlov antonynpavlov at gmail.com
Sat Apr 3 10:00:56 BST 2021


On Sat, 3 Apr 2021 09:09:15 +0200
Ahmad Fatoum <a.fatoum at pengutronix.de> wrote:

> Hello Antony,
> 
> On 02.04.21 10:13, Antony Pavlov wrote:
> >> This is strange. Could you print get_runtime_offset() at this location?
> >> It should be zero, because relocate_to_current_adr() had previously run,
> >> but it seems it's not for you? I don't see how compiler reordering could have
> >> occurred given that we don't do LTO and relocate_to_current_adr is thus
> >> a compiler barrier.
> 
> [ Naïve me thinking there are any guarantees from GCC for self-modifying code ]
> 
> > +    empty_slot_init(0, 0xffffffff);
> 
> That's tremendously useful. Thanks! I don't quite understand how it works
> though. It registers a "fall-back" device for all of the 32-bit address
> space?

Yes, it registers such device.

To my great surprise riscv-qemu (at least v2.12) generates no "bus error"
exception on access to unattended address.

I have just compared qemu-2.12 riscv behaviour with mips behaviour.
I have disabled empty_slot in mips_malta code:

--- a/hw/mips/mips_malta.c
+++ b/hw/mips/mips_malta.c
@@ -1014,7 +1014,7 @@ void mips_malta_init(MachineState *machine)
     /* The whole address space decoded by the GT-64120A doesn't generate
        exception when accessing invalid memory. Create an empty slot to
        emulate this feature. */
-    empty_slot_init(0, 0x20000000);
+    //empty_slot_init(0, 0x20000000);
 
     qdev_init_nofail(dev);
 


I have reconfigured qemu malta barebox to use only 16 MB of RAM. 

diff --git a/arch/mips/boards/qemu-malta/lowlevel.S b/arch/mips/boards/qemu-malta/lowlevel.S
index 98821e0426..6cb77b6c3e 100644
--- a/arch/mips/boards/qemu-malta/lowlevel.S
+++ b/arch/mips/boards/qemu-malta/lowlevel.S
@@ -82,4 +82,4 @@ __start:
 	li	t0, GT_LD(0x1bdfffff)
 	sw	t0, GT_PCI0M1HD_OFS(t1)
 
-ENTRY_FUNCTION_END(BOARD_PBL_START, qemu_malta, SZ_256M)
+ENTRY_FUNCTION_END(BOARD_PBL_START, qemu_malta, SZ_16M)
diff --git a/arch/mips/configs/qemu-malta_defconfig b/arch/mips/configs/qemu-malta_defconfig
index b9994f392c..3d33ae4120 100644
--- a/arch/mips/configs/qemu-malta_defconfig
+++ b/arch/mips/configs/qemu-malta_defconfig
@@ -33,7 +33,6 @@ CONFIG_CMD_SHA256SUM=y
 CONFIG_CMD_UNCOMPRESS=y
 CONFIG_CMD_SLEEP=y
 CONFIG_CMD_DHCP=y
-CONFIG_CMD_MIITOOL=y
 CONFIG_CMD_PING=y
 CONFIG_CMD_TFTP=y
 CONFIG_CMD_ECHO_E=y
@@ -59,7 +58,6 @@ CONFIG_NET_NFS=y
 CONFIG_NET_NETCONSOLE=y
 CONFIG_OFDEVICE=y
 CONFIG_OF_BAREBOX_DRIVERS=y
-CONFIG_DRIVER_NET_RTL8139=y
 # CONFIG_SPI is not set
 CONFIG_I2C=y
 CONFIG_I2C_GPIO=y
@@ -71,10 +69,8 @@ CONFIG_DRIVER_CFI=y
 CONFIG_CFI_BUFFER_WRITE=y
 CONFIG_VIDEO=y
 CONFIG_FRAMEBUFFER_CONSOLE=y
-CONFIG_DRIVER_VIDEO_BOCHS_PCI=y
+CONFIG_DRIVER_VIDEO_EDID=y
 CONFIG_GPIO_MALTA_FPGA_I2C=y
-CONFIG_PCI=y
-CONFIG_PCI_DEBUG=y
 CONFIG_FS_CRAMFS=y
 CONFIG_FS_TFTP=y
 CONFIG_FS_FAT=y
diff --git a/arch/mips/dts/qemu-malta.dts b/arch/mips/dts/qemu-malta.dts
index 32e473cac0..69d78061f6 100644
--- a/arch/mips/dts/qemu-malta.dts
+++ b/arch/mips/dts/qemu-malta.dts
@@ -16,7 +16,7 @@
 
 	memory at 0 {
 		device_type = "memory";
-		reg = <0x00000000 0x10000000>;
+		reg = <0x00000000 0x01000000>;
 	};
 
 	uart0: serial at 180003f8 {


It is easy to see that emulated mips CPU generates bus error exception on access to unattended address
at 0xa2000000 (start RAM + 32M):

 
barebox$ qemu-system-mips-malta-no-empty-slot -nodefaults -M malta -m 16 -serial stdio -monitor null -bios barebox-flash-image


barebox 2021.03.0-00137-g8c6a139124-dirty #2 Sat Apr 3 11:38:55 MSK 2021


Board: qemu malta
malta-fpga-i2c-gpio 1f000b00.gpio at 1f000b00.of: probed gpiochip-1 with base 0
cfi_flash 1e000000.flash at 1e000000.of: found cfi flash at 0xbe000000, size 4 MiB
i2c-gpio i2c0.of: using pins 0 (SDA) and 1 (SCL)
netconsole: registered as netconsole-1
malloc space: 0xa0b50000 -> 0xa0f4ffff (size 4 MiB)
envfs: no envfs (magic mismatch) - envfs never written?

Hit any to stop autoboot:    2
barebox at qemu malta:/ iomem
0x00000000 - 0xffffffff (size 0x00000000) iomem
  0x180003f8 - 0x180003ff (size 0x00000008) 180003f8.serial at 180003f8.of
  0x1e000000 - 0x1e3fffff (size 0x00400000) 1e000000.flash at 1e000000.of
  0x1f000900 - 0x1f00093f (size 0x00000040) 1f000900.serial at 1f000900.of
  0x1f000b00 - 0x1f000b1f (size 0x00000020) 1f000b00.gpio at 1f000b00.of
  0xa0000000 - 0xa0ffffff (size 0x01000000) kseg1_ram0
    0xa0b49000 - 0xa0b4ffff (size 0x00007000) stack
    0xa0b50000 - 0xa0f4ffff (size 0x00400000) malloc space
    0xa0f50000 - 0xa0fa655f (size 0x00056560) barebox
    0xa0fa6560 - 0xa0ff2edf (size 0x0004c980) barebox data
    0xa0ffaee0 - 0xa0ffef33 (size 0x00004054) bss
barebox at qemu malta:/ md 0xa2000000

Ooops, bus error on load or store!

$ 0   : 00000000 00000000 00000000 00000001
$ 4   : 00000100 00000001 00000001 00000030
$ 8   : a0fa2198 00000000 ffffffff 00000010
$12   : 00000000 0000005c 0000002f 2f696e69
$16   : a2000000 00000000 a2000000 00000004
$20   : 00000000 a0b4fc30 a0b4fc80 a0b4fc39
$24   : 00000010 a0f60de4                  
$28   : 00000000 a0b4fc20 a0b4fc80 a0f50930
Hi    : 0000000a
Lo    : 00000000
epc   : a0f50930
ra    : a0f50930
Status: 00000002
Cause : 0000041c
Config: 80008482

### ERROR ### Please RESET the board ###








> > There are empty_slot read warnings on master:
> > 
> >     barebox$ qemu-system-riscv32 -nographic -M erizo -bios ./images/barebox-erizo-generic.img -serial stdio -monitor none -trace file=/dev/null 
> >     >get_runtime_offset()=0x00000000
> >     empty_slot: read from 0000000000022caf
> >     empty_slot: read from 0000000000022cae
> >     empty_slot: read from 0000000000022cb0
> >     empty_slot: read from 0000000000022cb1
> >     riscv-timer riscv-timer: running at 24000000 Hz
> >     Switch to console [cs0]
> > 
> >     barebox 2021.03.0-00134-gc4a1684da9-dirty #1 Fri Apr 2 10:33:45 MSK 2021
> > 
> >     Board: generic Erizo SoC board
> >     riscv-timer riscv-timer: running at 24000000 Hz
> >     malloc space: 0x804ffd80 -> 0x805ffd7f (size 1 MiB)
> > 
> >     Hit any to stop autoboot:    1
> >     boot: error 2
> >     barebox:/ 
> > 
> > 
> > There is no empty_slot warning with fef19e17f651^ barebox:
> > 
> >     barebox$ qemu-system-riscv32 -nographic -M erizo -bios ./images/barebox-erizo-generic.img -serial stdio -monitor none -trace file=/dev/null 
> >     >RISC-V system with no 'timebase-frequency' in DTS
> >     Switch to console [cs0]
> > 
> >     barebox 2021.03.0-00122-g6107208573 #1 Fri Apr 2 11:09:16 MSK 2021
> > 
> >     Board: generic Erizo SoC board
> >     RISC-V system with no 'timebase-frequency' in DTS
> >     malloc space: 0x802ffd80 -> 0x803ffd7f (size 1 MiB)
> > 
> >     Hit any to stop autoboot:    0
> >     boot: error 2
> >     barebox:/ 
> 
> Thanks. I identified two issues and CC'd you on a patch fixing them.
> Breaking erizo has been a blessing to sort out this kind of bugs early :D
> 
> Cheers,
> Ahmad
> 
> -- 
> Pengutronix e.K.                           |                             |
> Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
> 31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


-- 
Best regards,
  Antony Pavlov



More information about the barebox mailing list