27
27
28
28
from .compiler_rt import BuildCompilerRtBuiltins
29
29
from .crosscompileproject import CompilationTargets , CrossCompileMakefileProject , GitRepository
30
+ from ..build_qemu import BuildQEMU
30
31
from ..project import DefaultInstallDir
31
32
from ..run_qemu import LaunchQEMUBase
32
33
from ..simple_project import BoolConfigOption
@@ -39,8 +40,11 @@ class BuildLittleKernel(CrossCompileMakefileProject):
39
40
target = "littlekernel"
40
41
default_directory_basename = "lk"
41
42
supported_architectures = (
43
+ CompilationTargets .FREESTANDING_ARM32 ,
44
+ CompilationTargets .FREESTANDING_AARCH64 ,
42
45
CompilationTargets .FREESTANDING_MORELLO_NO_CHERI ,
43
46
CompilationTargets .FREESTANDING_MORELLO_PURECAP ,
47
+ CompilationTargets .FREESTANDING_RISCV32 ,
44
48
CompilationTargets .FREESTANDING_RISCV64 ,
45
49
CompilationTargets .FREESTANDING_RISCV64_PURECAP ,
46
50
)
@@ -97,22 +101,28 @@ def setup(self):
97
101
self .make_args .set (BUILDROOT = self .build_dir )
98
102
if self .config .verbose :
99
103
self .make_args .set (NOECHO = "" )
100
- for var in ["CFLAGS" , "CPPFLAGS" , "CXXFLAGS" , "LDFLAGS" ]:
104
+ for var in ["CFLAGS" , "CPPFLAGS" , "CXXFLAGS" , "LDFLAGS" , "AR" ]:
101
105
del self .make_args .env_vars [var ]
102
- toolchain_prefix = str (self .sdk_bindir ) + "/"
103
- if self .compiling_for_riscv (include_purecap = True ):
104
- # Use hardfloat to avoid libgcc deps
105
- self .make_args .set (RISCV_FPU = True )
106
106
if self .compiling_for_cheri ():
107
107
self .make_args .set (ARCH_COMPILEFLAGS = "" ) # dont' override the default -mabi=
108
108
109
+ if self .compiling_for_arm32 ():
110
+ # Work around "error: unknown argument: '-mthumb-interwork'"
111
+ self .make_args .set (ENABLE_THUMB = 0 )
112
+
109
113
self .set_make_cmd_with_args ("LD" , self .target_info .linker , ["--unresolved-symbols=report-all" ])
110
- if self .crosscompile_target .is_riscv (include_purecap = True ) and self .use_mmu :
114
+ if self .crosscompile_target .is_riscv64 (include_purecap = True ) and self .use_mmu :
111
115
self .make_args .set (RISCV_MMU = "sv39" , RISCV_MODE = "supervisor" )
116
+ # Use hardfloat to avoid libgcc deps
117
+ self .make_args .set (RISCV_FPU = 1 )
118
+ elif self .crosscompile_target .is_riscv32 (include_purecap = True ):
119
+ if self .use_mmu :
120
+ self .make_args .set (RISCV_MMU = "sv32" , RISCV_MODE = "supervisor" )
121
+ # Use softfloat to match compiler-rt ABI
122
+ self .make_args .set (RISCV_FPU = 0 )
112
123
self .make_args .set (
113
- TOOLCHAIN_PREFIX = toolchain_prefix ,
114
- ARCH_arm64_TOOLCHAIN_PREFIX = toolchain_prefix ,
115
- ARCH_riscv64_TOOLCHAIN_PREFIX = toolchain_prefix ,
124
+ TOOLCHAIN_PREFIX = str (self .sdk_bindir ) + "/llvm-" ,
125
+ CPPFILT = self .sdk_bindir / "llvm-cxxfilt" , # does not match the normal llvm-<binutil> pattern
116
126
)
117
127
118
128
def setup_late (self ) -> None :
@@ -123,15 +133,20 @@ def setup_late(self) -> None:
123
133
def kernel_path (self ) -> Path :
124
134
if self .compiling_for_aarch64 (include_purecap = True ):
125
135
return self .build_dir / "build-qemu-virt-arm64-test/lk.elf"
126
- elif self .compiling_for_riscv (include_purecap = True ):
136
+ elif self .crosscompile_target .is_riscv32 (include_purecap = True ):
137
+ return self .build_dir / "build-qemu-virt-riscv32-test/lk.elf"
138
+ elif self .crosscompile_target .is_riscv64 (include_purecap = True ):
127
139
return self .build_dir / "build-qemu-virt-riscv64-test/lk.elf"
140
+ elif self .compiling_for_arm32 ():
141
+ return self .build_dir / "build-qemu-virt-arm32-test/lk.elf"
128
142
else :
129
143
raise ValueError ("Unsupported arch" )
130
144
131
145
def run_tests (self ):
146
+ qemu = BuildQEMU .qemu_binary (self , xtarget = self .crosscompile_target )
132
147
if self .compiling_for_aarch64 (include_purecap = True ):
133
148
cmd = [
134
- self . config . qemu_bindir / " qemu-system-aarch64" ,
149
+ qemu ,
135
150
"-cpu" ,
136
151
"cortex-a53" ,
137
152
"-m" ,
@@ -151,9 +166,9 @@ def run_tests(self):
151
166
if self .use_mmu :
152
167
bios_args = riscv_bios_arguments (self .crosscompile_target , self )
153
168
cmd = [
154
- self . config . qemu_bindir / " qemu-system-riscv64cheri" ,
169
+ qemu ,
155
170
"-cpu" ,
156
- "rv64" ,
171
+ "rv64" if self . crosscompile_target . is_riscv64 ( include_purecap = True ) else "rv32" ,
157
172
"-m" ,
158
173
"512" ,
159
174
"-smp" ,
@@ -167,6 +182,23 @@ def run_tests(self):
167
182
self .kernel_path ,
168
183
* bios_args ,
169
184
]
185
+ elif self .compiling_for_arm32 ():
186
+ cmd = [
187
+ qemu ,
188
+ "-cpu" ,
189
+ "cortex-a15" ,
190
+ "-m" ,
191
+ "512" ,
192
+ "-smp" ,
193
+ "1" ,
194
+ "-machine" ,
195
+ "virt,highmem=off" ,
196
+ "-net" ,
197
+ "none" ,
198
+ "-nographic" ,
199
+ "-kernel" ,
200
+ self .kernel_path ,
201
+ ]
170
202
else :
171
203
return self .fatal ("Unsupported arch" )
172
204
self .run_cmd (cmd , cwd = self .build_dir , give_tty_control = True )
@@ -175,7 +207,10 @@ def compile(self, **kwargs):
175
207
if self .compiling_for_aarch64 (include_purecap = True ):
176
208
self .run_make ("qemu-virt-arm64-test" , cwd = self .source_dir , parallel = True )
177
209
elif self .compiling_for_riscv (include_purecap = True ):
178
- self .run_make ("qemu-virt-riscv64-test" , cwd = self .source_dir , parallel = True )
210
+ xlen = 64 if self .crosscompile_target .is_riscv64 (include_purecap = True ) else 32
211
+ self .run_make (f"qemu-virt-riscv{ xlen } -test" , cwd = self .source_dir , parallel = True )
212
+ elif self .compiling_for_arm32 ():
213
+ self .run_make ("qemu-virt-arm32-test" , cwd = self .source_dir , parallel = True )
179
214
else :
180
215
return self .fatal ("Unsupported arch" )
181
216
0 commit comments