OpenRISC fixes and setjmp/longjmp work
Stafford Horne
maintainercover OpenRISC fixes and setjmp/longjmp work
Hello,
These are the patches I came up with to get the setjmp/longjmp routines to work on OpenRISC. It seems to be working well.
The patches are on github here:
https://github.com/stffrdhrn/barebox/tree/openrisc-bthread
I had to revert a commit to remove openrisc to do this work, I hope that can be reverted.
Test output:
barebox at or1ksim:/ bthread -v
bthread_printer yield #1
bthread_printer yield #2
bthread_printer yield #3
bthread_printer yield #4
36441 bthread yield calls in 1s
barebox at or1ksim:/ bthread -v
bthread_printer yield #1
bthread_printer yield #2
bthread_printer yield #3
bthread_printer yield #4
36504 bthread yield calls in 1s
barebox at or1ksim:/ bthread
bthread - print info about registered bthreads
print info about registered barebox threads
Options:
-i Print information about registered bthreads
-t measure how many bthreads we currently run in 1s
-c count maximum context switches in 1s
-v verify correct bthread operation
barebox at or1ksim:/ bthread -c bthread -c
269536 bthread context switches possible in 1s
Stafford Horne (4):
openrisc: Use movhi to zero registers
openrisc: Add gitignore for dtb files
openrisc: Add linkage.h
openrisc: Implement setjmp/longjmp/initjmp
arch/openrisc/Kconfig | 1 + arch/openrisc/cpu/start.S | 6 ++-- arch/openrisc/dts/.gitignore | 1 + arch/openrisc/include/asm/linkage.h | 7 ++++ arch/openrisc/include/asm/setjmp.h | 17 +++++++++ arch/openrisc/lib/Makefile | 1 + arch/openrisc/lib/setjmp.S | 56 +++++++++++++++++++++++++++++ 7 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 arch/openrisc/dts/.gitignore create mode 100644 arch/openrisc/include/asm/linkage.h create mode 100644 arch/openrisc/include/asm/setjmp.h create mode 100644 arch/openrisc/lib/setjmp.S
Signature · 1 line
2.26.2
Stafford Horne
maintainerPATCH 1/4 openrisc: Use movhi to zero registers
This is needed when running on FPGA as registers are not guaranteed to be initialized to 0. Using movhi allows to explicitly set 0.
--- arch/openrisc/cpu/start.S | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/openrisc/cpu/start.S +3 -3
@@ -37,10 +37,10 @@ .org 0x100 __reset: /* there is no guarantee r0 is hardwired to zero, clear it here */ - l.andi r0, r0, 0 + l.movhi r0, 0x0 /* reset stack and frame pointers */ - l.andi r1, r0, 0 - l.andi r2, r0, 0 + l.movhi r1, 0x0 + l.movhi r2, 0x0 /* set supervisor mode */ l.ori r3,r0,SPR_SR_SM
Signature · 1 line
2.26.2
Stafford Horne
maintainerPATCH 2/4 openrisc: Add gitignore for dtb files
In reply to Stafford Horne--- arch/openrisc/dts/.gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 arch/openrisc/dts/.gitignore
arch/openrisc/dts/.gitignore new file +1 -0
@@ -0,0 +1 @@ +*dtb*
Signature · 1 line
2.26.2
Stafford Horne
maintainerPATCH 3/4 openrisc: Add linkage.h
In reply to Stafford HorneCopied from glibc minus bits we don't need.
--- arch/openrisc/include/asm/linkage.h | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 arch/openrisc/include/asm/linkage.h
arch/openrisc/include/asm/linkage.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef __ASM_LINKAGE_H +#define __ASM_LINKAGE_H + +#define __ALIGN .align 0 +#define __ALIGN_STR ".align 0" + +#endif
Signature · 1 line
2.26.2
Stafford Horne
maintainerPATCH 4/4 openrisc: Implement setjmp/longjmp/initjmp
In reply to Stafford HorneTested on or1ksim and this seems to work. This is mostly the same as the glibc port implementation, but adjusted as per requirements per barebox.
--- arch/openrisc/Kconfig | 1 + arch/openrisc/include/asm/setjmp.h | 17 +++++++++ arch/openrisc/lib/Makefile | 1 + arch/openrisc/lib/setjmp.S | 56 ++++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+) create mode 100644 arch/openrisc/include/asm/setjmp.h create mode 100644 arch/openrisc/lib/setjmp.S
arch/openrisc/Kconfig +1 -0
@@ -4,6 +4,7 @@ config OPENRISC select HAS_CACHE select HAVE_CONFIGURABLE_MEMORY_LAYOUT select GENERIC_FIND_NEXT_BIT + select HAS_ARCH_SJLJ default y # not used
arch/openrisc/include/asm/setjmp.h new file +17 -0
@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* +* Define the machine-dependent type `jmp_buf'. OpenRISC version. +* Copyright (C) 2021 Free Software Foundation, Inc. +* This file is part of the GNU C Library. +*/ + +#ifndef _OR1K_BITS_SETJMP_H +#define _OR1K_BITS_SETJMP_H 1 + +typedef long int jmp_buf [13 ]; + +int setjmp (jmp_buf jmp) __attribute__((returns_twice)); +void longjmp (jmp_buf jmp,int ret) __attribute__((noreturn)); +int initjmp (jmp_buf jmp,void __noreturn (*func)(void ),void *stack_top); + +#endif /* _OR1K_BITS_SETJMP_H */
arch/openrisc/lib/Makefile +1 -0
@@ -5,4 +5,5 @@ obj-y += muldi3.o obj-y += lshrdi3.o obj-y += ashldi3.o obj-y += ashrdi3.o +obj-y += setjmp.o obj-$(CONFIG_BUILTIN_DTB) += dtb.o
arch/openrisc/lib/setjmp.S new file +56 -0
56 lines not on this page · raw message
Signature · 1 line
2.26.2
Hello Stafford,
Quoted 10 lines · Stafford Horne
Hello,
These are the patches I came up with to get the setjmp/longjmp routines to work on OpenRISC. It seems to be working well.
The patches are on github here:
https://github.com/stffrdhrn/barebox/tree/openrisc-bthreadI had to revert a commit to remove openrisc to do this work, I hope that can be reverted.
Great. Thanks for taking the time!
Could this be tested on qemu-system-or1k? If so, it would be great to have this documented in-tree, so future changes could be tested.
Cheers,
Ahmad
Quoted 50 lines
Test output:
barebox at or1ksim:/ bthread -v
bthread_printeryield #1
bthread_printeryield #2
bthread_printeryield #3
bthread_printeryield #4
36441 bthread yield calls in 1s
barebox at or1ksim:/ bthread -v
bthread_printeryield #1
bthread_printeryield #2
bthread_printeryield #3
bthread_printeryield #4
36504 bthread yield calls in 1s
barebox at or1ksim:/ bthreadbthread - print info about registered bthreads
print info about registered barebox threads
Options:
-i Print information about registered bthreads
-t measure how many bthreads we currently run in 1s
-c count maximum context switches in 1s
-v verify correct bthread operationbarebox at or1ksim:/ bthread -c bthread -c
269536 bthread context switches possible in 1sStafford Horne (4):
openrisc: Use movhi to zero registers
openrisc: Add gitignore for dtb files
openrisc: Addlinkage.h
openrisc: Implement setjmp/longjmp/initjmparch/openrisc/Kconfig | 1 + arch/openrisc/cpu/start.S | 6 ++-- arch/openrisc/dts/.gitignore | 1 + arch/openrisc/include/asm/linkage.h | 7 ++++ arch/openrisc/include/asm/setjmp.h | 17 +++++++++ arch/openrisc/lib/Makefile | 1 + arch/openrisc/lib/setjmp.S | 56 +++++++++++++++++++++++++++++ 7 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 arch/openrisc/dts/.gitignore create mode 100644 arch/openrisc/include/asm/linkage.h create mode 100644 arch/openrisc/include/asm/setjmp.h create mode 100644 arch/openrisc/lib/setjmp.S
Signature · 4 lines
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 |
Stafford Horne
maintainerQuoted 11 lines · Ahmad Fatoum
Hello Stafford,
Quoted 8 lines · Stafford Horne
Hello,
These are the patches I came up with to get the setjmp/longjmp routines to work on OpenRISC. It seems to be working well.
The patches are on github here:
https://github.com/stffrdhrn/barebox/tree/openrisc-bthread
Quoted 6 lines
Quoted 2 lines
I had to revert a commit to remove openrisc to do this work, I hope that can be reverted.
Great. Thanks for taking the time!
Could this be tested on qemu-system-or1k? If so, it would be great to have this documented in-tree, so future changes could be tested.
Sure, I will try to get it working. For some reason qemu was getting hung.
Give me a few days.
-Stafford
Stafford Horne
maintainerQuoted 15 lines · Stafford Horne
Quoted 14 lines · Ahmad Fatoum
Hello Stafford,
Quoted 10 lines · Stafford Horne
Hello,
These are the patches I came up with to get the setjmp/longjmp routines to work on OpenRISC. It seems to be working well.
The patches are on github here:
https://github.com/stffrdhrn/barebox/tree/openrisc-bthreadI had to revert a commit to remove openrisc to do this work, I hope that can be reverted.
Quoted 7 lines
Quoted 3 lines
Great. Thanks for taking the time!
Could this be tested on qemu-system-or1k? If so, it would be great to have this documented in-tree, so future changes could be tested.Sure, I will try to get it working. For some reason qemu was getting hung.
Give me a few days.
Got it working and posted a sepaate patch. I will add documentation as well, but here is what I ran. It should be similar to what I documented on the qemu wiki:
https://wiki.qemu.org/Documentation/Platforms/OpenRISC
$ /home/shorne/work/openrisc/qemu/build/or1k-softmmu/qemu-system-or1k -cpu or1200 \
-M or1k-sim \
-kernel /home/shorne/work/openrisc/barebox/barebox \
-net nic -net tap,ifname=tap0,script=no,downscript=no \
-serial mon:stdio -nographic \
-gdb tcp::10001 \
-m 32barebox 2021.02.0-00120-g763c6fee7-dirty #14 Thu Mar 4 05:13:51 JST 2021
Board: or1ksim
mdio_bus: miibus0: probed
malloc space: 0x01b80000 -> 0x01f7ffff (size 4 MiB)
Hit any to stop autoboot: 3
barebox at or1ksim:/
barebox at or1ksim:/
barebox at or1ksim:/ bthread -v
bthread_printer yield #1
bthread_printer yield #2
bthread_printer yield #3
bthread_printer yield #4
9963 bthread yield calls in 1s
-Stafford