Skip to content

Commit e977146

Browse files
committed
Apply patches, mostly from Yimin Gu <[email protected]>
1 parent 0c7ba30 commit e977146

File tree

9 files changed

+272
-3
lines changed

9 files changed

+272
-3
lines changed

arch/Config.in.riscv

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ choice
7171

7272
config BR2_RISCV_32
7373
bool "32-bit"
74-
select BR2_USE_MMU
7574

7675
config BR2_RISCV_64
7776
bool "64-bit"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
linux/
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
2+
index fcbb81feb..fc48b458a 100644
3+
--- a/arch/riscv/Kconfig
4+
+++ b/arch/riscv/Kconfig
5+
@@ -162,8 +162,8 @@ config MMU
6+
7+
config PAGE_OFFSET
8+
hex
9+
- default 0xC0000000 if 32BIT
10+
- default 0x80000000 if 64BIT && !MMU
11+
+ default 0xC0000000 if 32BIT && MMU
12+
+ default 0x80000000 if !MMU
13+
default 0xff60000000000000 if 64BIT
14+
15+
config KASAN_SHADOW_OFFSET
16+
@@ -237,7 +237,6 @@ config ARCH_RV32I
17+
select GENERIC_LIB_ASHRDI3
18+
select GENERIC_LIB_LSHRDI3
19+
select GENERIC_LIB_UCMPDI2
20+
- select MMU
21+
22+
config ARCH_RV64I
23+
bool "RV64I"
24+
25+
diff --git a/arch/riscv/include/uapi/asm/unistd.h b/arch/riscv/include/uapi/asm/unistd.h
26+
index 73d7cdd2e..53f5410c1 100644
27+
--- a/arch/riscv/include/uapi/asm/unistd.h
28+
+++ b/arch/riscv/include/uapi/asm/unistd.h
29+
@@ -15,9 +15,14 @@
30+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
31+
*/
32+
33+
-#if defined(__LP64__) && !defined(__SYSCALL_COMPAT)
34+
+#ifndef __SYSCALL_COMPAT
35+
#define __ARCH_WANT_NEW_STAT
36+
#define __ARCH_WANT_SET_GET_RLIMIT
37+
+#endif
38+
+
39+
+#ifndef __LP64__
40+
+#define __ARCH_WANT_STAT64
41+
+#define __ARCH_WANT_TIME32_SYSCALLS
42+
#endif /* __LP64__ */
43+
44+
#define __ARCH_WANT_SYS_CLONE3
45+
--
46+
2.38.1
47+
48+

board/qemu/riscv32-virt/readme.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@ Run Linux in emulation with:
22

33
qemu-system-riscv32 -M virt -bios output/images/fw_jump.elf -kernel output/images/Image -append "rootwait root=/dev/vda ro" -drive file=output/images/rootfs.ext2,format=raw,id=hd0 -device virtio-blk-device,drive=hd0 -netdev user,id=net0 -device virtio-net-device,netdev=net0 -nographic # qemu_riscv32_virt_defconfig
44

5+
alternatively:
6+
7+
qemu-system-riscv32 -M virt -bios none -kernel output/images/Image -append "rootwait root=/dev/vda ro" -drive file=output/images/rootfs.ext2,format=raw,id=hd0 -device virtio-blk-device,drive=hd0 -nographic -cpu rv32,mmu=off # qemu_riscv32_nommu_virt_defconfig
8+
59
The login prompt will appear in the terminal that started Qemu.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
BR2_riscv=y
2+
BR2_riscv_custom=y
3+
BR2_RISCV_ISA_CUSTOM_RVM=y
4+
BR2_RISCV_32=y
5+
# BR2_RISCV_USE_MMU is not set
6+
BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_5_19=y
7+
BR2_PTHREADS_NONE=y
8+
BR2_GLOBAL_PATCH_DIR="board/qemu/riscv32-virt/nommu/patches"
9+
BR2_ROOTFS_POST_IMAGE_SCRIPT="board/qemu/post-image.sh"
10+
BR2_ROOTFS_POST_SCRIPT_ARGS="$(BR2_DEFCONFIG)"
11+
BR2_LINUX_KERNEL=y
12+
BR2_LINUX_KERNEL_CUSTOM_VERSION=y
13+
BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="5.19"
14+
BR2_LINUX_KERNEL_DEFCONFIG="nommu_rv32_virt"
15+
BR2_PACKAGE_BUSYBOX_CONFIG="package/busybox/busybox-minimal.config"
16+
# BR2_PACKAGE_IFUPDOWN_SCRIPTS is not set
17+
BR2_TARGET_ROOTFS_EXT2=y
18+
BR2_PACKAGE_HOST_QEMU=y
19+
BR2_PACKAGE_HOST_QEMU_SYSTEM_MODE=y

package/Makefile.in

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,16 @@ endif
3939
# Compute GNU_TARGET_NAME
4040
GNU_TARGET_NAME = $(ARCH)-$(TARGET_VENDOR)-$(TARGET_OS)-$(LIBC)$(ABI)
4141

42-
# FLAT binary format needs uclinux, except RISC-V 64-bits which needs
42+
# FLAT binary format needs uclinux, except RISC-V nommu which needs
4343
# the regular linux name.
44-
ifeq ($(BR2_BINFMT_FLAT):$(BR2_RISCV_64),y:)
44+
ifeq ($(BR2_BINFMT_FLAT),y)
45+
ifeq ($(BR2_RISCV_64),y)
46+
TARGET_OS = linux
47+
else ifeq ($(BR2_RISCV_32),y)
48+
TARGET_OS = linux
49+
else
4550
TARGET_OS = uclinux
51+
endif
4652
else
4753
TARGET_OS = linux
4854
endif
@@ -179,6 +185,9 @@ ifeq ($(BR2_BINFMT_FLAT),y)
179185
ifeq ($(BR2_RISCV_64),y)
180186
TARGET_CFLAGS += -fPIC
181187
endif
188+
ifeq ($(BR2_RISCV_32),y)
189+
TARGET_CFLAGS += -fPIC
190+
endif
182191
ifeq ($(BR2_BINFMT_FLAT_ONE),y)
183192
ELF2FLT_FLAGS = $(if $($(PKG)_FLAT_STACKSIZE),\
184193
-Wl$(comma)-elf2flt="-r -s$($(PKG)_FLAT_STACKSIZE)",\
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
elf2flt.c | 9 ++++++---
3+
ld-elf2flt.c | 2 +-
4+
2 files changed, 7 insertions(+), 4 deletions(-)
5+
6+
diff --git a/elf2flt.c b/elf2flt.c
7+
index 949edd1..28f3808 100644
8+
--- a/elf2flt.c
9+
+++ b/elf2flt.c
10+
@@ -81,7 +81,7 @@ const char *elf2flt_progname;
11+
#include <elf/v850.h>
12+
#elif defined(TARGET_xtensa)
13+
#include <elf/xtensa.h>
14+
-#elif defined(TARGET_riscv64)
15+
+#elif defined(TARGET_riscv64) || defined(TARGET_riscv32)
16+
#include <elf/riscv.h>
17+
#endif
18+
19+
@@ -127,6 +127,8 @@ const char *elf2flt_progname;
20+
#define ARCH "xtensa"
21+
#elif defined(TARGET_riscv64)
22+
#define ARCH "riscv64"
23+
+#elif defined(TARGET_riscv32)
24+
+#define ARCH "riscv32"
25+
#else
26+
#error "Don't know how to support your CPU architecture??"
27+
#endif
28+
@@ -838,7 +841,7 @@ output_relocs (
29+
goto good_32bit_resolved_reloc;
30+
default:
31+
goto bad_resolved_reloc;
32+
-#elif defined(TARGET_riscv64)
33+
+#elif defined(TARGET_riscv64) || defined(TARGET_riscv32)
34+
case R_RISCV_32_PCREL:
35+
case R_RISCV_ADD32:
36+
case R_RISCV_ADD64:
37+
diff --git a/ld-elf2flt.c b/ld-elf2flt.c
38+
index 75ee1bb..68b2a4a 100644
39+
--- a/ld-elf2flt.c
40+
+++ b/ld-elf2flt.c
41+
@@ -327,7 +327,7 @@ static int do_final_link(void)
42+
/* riscv adds a global pointer symbol to the linker file with the
43+
"RISCV_GP:" prefix. Remove the prefix for riscv64 architecture and
44+
the entire line for other architectures. */
45+
- if (streq(TARGET_CPU, "riscv64"))
46+
+ if (streq(TARGET_CPU, "riscv64") || streq(TARGET_CPU, "riscv32"))
47+
append_sed(&sed, "^RISCV_GP:", "");
48+
else
49+
append_sed(&sed, "^RISCV_GP:", NULL);
50+
--
51+
2.38.1
52+
53+
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
Patch originally From: Yimin Gu <[email protected]>
2+
---
3+
Rules.mak | 2 ++
4+
extra/Configs/Config.in | 9 +++++++++
5+
extra/Configs/Config.riscv32 | 14 ++++++++++++++
6+
libc/sysdeps/linux/riscv32 | 1 +
7+
libc/sysdeps/linux/riscv64/bits/wordsize.h | 3 ++-
8+
libc/sysdeps/linux/riscv64/sys/asm.h | 6 +++++-
9+
6 files changed, 33 insertions(+), 2 deletions(-)
10+
create mode 100644 extra/Configs/Config.riscv32
11+
create mode 120000 libc/sysdeps/linux/riscv32
12+
13+
diff --git a/Rules.mak b/Rules.mak
14+
index 3fb64c728..71a14fc38 100644
15+
--- a/Rules.mak
16+
+++ b/Rules.mak
17+
@@ -305,6 +305,7 @@ ifneq ($(TARGET_ARCH),c6x)
18+
ifneq ($(TARGET_ARCH),h8300)
19+
ifneq ($(TARGET_ARCH),arc)
20+
ifneq ($(TARGET_ARCH),aarch64)
21+
+ifneq ($(TARGET_ARCH),riscv32)
22+
CPU_CFLAGS-y += -msoft-float
23+
endif
24+
endif
25+
@@ -316,6 +317,7 @@ endif
26+
endif
27+
endif
28+
endif
29+
+endif
30+
31+
ifeq ($(TARGET_ARCH),aarch64)
32+
CPU_CFLAGS-y += -ftls-model=initial-exec
33+
diff --git a/extra/Configs/Config.in b/extra/Configs/Config.in
34+
index a58ceb265..5e6af800d 100644
35+
--- a/extra/Configs/Config.in
36+
+++ b/extra/Configs/Config.in
37+
@@ -39,6 +39,7 @@ choice
38+
default TARGET_or1k if DESIRED_TARGET_ARCH = "or1k"
39+
default TARGET_powerpc if DESIRED_TARGET_ARCH = "powerpc"
40+
default TARGET_riscv64 if DESIRED_TARGET_ARCH = "riscv64"
41+
+ default TARGET_riscv32 if DESIRED_TARGET_ARCH = "riscv32"
42+
default TARGET_sh if DESIRED_TARGET_ARCH = "sh"
43+
default TARGET_sparc if DESIRED_TARGET_ARCH = "sparc"
44+
default TARGET_sparc64 if DESIRED_TARGET_ARCH = "sparc64"
45+
@@ -125,6 +126,9 @@ config TARGET_powerpc
46+
config TARGET_riscv64
47+
bool "riscv64"
48+
49+
+config TARGET_riscv32
50+
+ bool "riscv32"
51+
+
52+
config TARGET_sh
53+
bool "superh"
54+
55+
@@ -240,6 +244,10 @@ if TARGET_riscv64
56+
source "extra/Configs/Config.riscv64"
57+
endif
58+
59+
+if TARGET_riscv32
60+
+source "extra/Configs/Config.riscv32"
61+
+endif
62+
+
63+
if TARGET_sh
64+
source "extra/Configs/Config.sh"
65+
endif
66+
@@ -538,6 +546,7 @@ config UCLIBC_HAS_LINUXTHREADS
67+
select UCLIBC_HAS_REALTIME
68+
depends on !TARGET_aarch64 && \
69+
!TARGET_riscv64 && \
70+
+ !TARGET_riscv32 && \
71+
!TARGET_metag
72+
help
73+
If you want to compile uClibc with Linuxthreads support, then answer Y.
74+
diff --git a/extra/Configs/Config.riscv32 b/extra/Configs/Config.riscv32
75+
new file mode 100644
76+
index 000000000..304d30f70
77+
--- /dev/null
78+
+++ b/extra/Configs/Config.riscv32
79+
@@ -0,0 +1,14 @@
80+
+#
81+
+# For a description of the syntax of this configuration file,
82+
+# see extra/config/Kconfig-language.txt
83+
+#
84+
+
85+
+config TARGET_ARCH
86+
+ string
87+
+ default "riscv32"
88+
+
89+
+config FORCE_OPTIONS_FOR_ARCH
90+
+ bool
91+
+ default y
92+
+ select ARCH_LITTLE_ENDIAN
93+
+ select ARCH_HAS_MMU
94+
diff --git a/libc/sysdeps/linux/riscv32 b/libc/sysdeps/linux/riscv32
95+
new file mode 120000
96+
index 000000000..11677ef05
97+
--- /dev/null
98+
+++ b/libc/sysdeps/linux/riscv32
99+
@@ -0,0 +1 @@
100+
+riscv64
101+
\ No newline at end of file
102+
diff --git a/libc/sysdeps/linux/riscv64/bits/wordsize.h b/libc/sysdeps/linux/riscv64/bits/wordsize.h
103+
index 67a16ba62..1fc649aad 100644
104+
--- a/libc/sysdeps/linux/riscv64/bits/wordsize.h
105+
+++ b/libc/sysdeps/linux/riscv64/bits/wordsize.h
106+
@@ -25,5 +25,6 @@
107+
#if __riscv_xlen == 64
108+
# define __WORDSIZE_TIME64_COMPAT32 1
109+
#else
110+
-# error "rv32i-based targets are not supported"
111+
+# define __WORDSIZE_TIME64_COMPAT32 1
112+
+// # warning "rv32i-based targets are experimental"
113+
#endif
114+
diff --git a/libc/sysdeps/linux/riscv64/sys/asm.h b/libc/sysdeps/linux/riscv64/sys/asm.h
115+
index ddb84b683..3c94c9a70 100644
116+
--- a/libc/sysdeps/linux/riscv64/sys/asm.h
117+
+++ b/libc/sysdeps/linux/riscv64/sys/asm.h
118+
@@ -26,7 +26,11 @@
119+
# define REG_S sd
120+
# define REG_L ld
121+
#elif __riscv_xlen == 32
122+
-# error "rv32i-based targets are not supported"
123+
+# define PTRLOG 2
124+
+# define SZREG 4
125+
+# define REG_S sw
126+
+# define REG_L lw
127+
+// # warning "rv32i-based targets are experimental"
128+
#else
129+
# error __riscv_xlen must equal 32 or 64
130+
#endif
131+
--
132+
2.37.1
133+
134+

package/uclibc/Config.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ config BR2_PACKAGE_UCLIBC_ARCH_SUPPORTS
1717
default y if BR2_powerpc
1818
# see libc/sysdeps/linux/riscv64/sys/asm.h
1919
default y if BR2_RISCV_64 && (BR2_RISCV_ABI_LP64 || BR2_RISCV_ABI_LP64D)
20+
default y if BR2_RISCV_32
2021
default y if BR2_sh4
2122
default y if BR2_sh4eb
2223
default y if BR2_sparc
@@ -138,6 +139,7 @@ config BR2_UCLIBC_TARGET_ARCH
138139
default "i386" if BR2_i386
139140
default "x86_64" if BR2_x86_64
140141
default "riscv64" if BR2_RISCV_64
142+
default "riscv32" if BR2_RISCV_32
141143

142144
config BR2_UCLIBC_MIPS_ABI
143145
string

0 commit comments

Comments
 (0)