Skip to content

Commit dd1e3a9

Browse files
committed
[embedded] Add a riscv32-qemu-virt QEMU test configuration
1 parent 9ee1ddc commit dd1e3a9

File tree

4 files changed

+71
-0
lines changed

4 files changed

+71
-0
lines changed

test/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,16 @@ if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB_CROSS_COMPILING)
547547
"${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in"
548548
"${CMAKE_CURRENT_BINARY_DIR}${VARIANT_SUFFIX}/lit.site.cfg"
549549
"test${VARIANT_SUFFIX}.lit.site.cfg")
550+
551+
set(VARIANT_SUFFIX "-embedded-riscv32")
552+
set(VARIANT_TRIPLE "riscv32-none-none-eabi")
553+
set(VARIANT_EXTERNAL_EMBEDDED_PLATFORM TRUE)
554+
set(VARIANT_EXTERNAL_EMBEDDED_DEVICE "riscv32-qemu-virt")
555+
set(SWIFT_TEST_RESULTS_DIR "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/swift-test-results/${VARIANT_TRIPLE}")
556+
swift_configure_lit_site_cfg(
557+
"${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in"
558+
"${CMAKE_CURRENT_BINARY_DIR}${VARIANT_SUFFIX}/lit.site.cfg"
559+
"test${VARIANT_SUFFIX}.lit.site.cfg")
550560
endif()
551561

552562
# Add shortcuts for the default variant.

utils/embedded-test-support/embedded-test-support.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@ def main():
6363
semihosting = False
6464
qemu_mode = "-bios"
6565
always_optimize_for_size = True
66+
elif args.device == "riscv32-qemu-virt":
67+
target = "riscv32-none-none-eabi"
68+
qemu_binary = "qemu-system-riscv32"
69+
qemu_machine = "virt"
70+
mmcu = ""
71+
entry_point = "start"
72+
semihosting = False
73+
qemu_mode = "-bios none -kernel"
74+
always_optimize_for_size = True
6675
else:
6776
assert False
6877

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
MEMORY
2+
{
3+
ram : ORIGIN = 0x80000000, LENGTH = 128K
4+
}
5+
6+
SECTIONS
7+
{
8+
.text : { *(.start*) ; *(.text*) } > ram
9+
.bss : { *(.bss*) } > ram
10+
.data : { *(.data*) ; *(.rodata*) } > ram
11+
/DISCARD/ : { *(.swift_modhash*) }
12+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift open source project
4+
//
5+
// Copyright (c) 2024 Apple Inc. and the Swift project authors.
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#include <stddef.h>
14+
#include <stdint.h>
15+
16+
int puts(const char *p);
17+
18+
__attribute__((naked))
19+
__attribute__((section(".start")))
20+
void start() {
21+
asm volatile("la sp, stack + 8192 - 4");
22+
asm volatile("call main");
23+
asm volatile("call halt");
24+
}
25+
26+
void halt(void) {
27+
puts("HALT\n");
28+
asm("unimp");
29+
}
30+
31+
__attribute__((aligned(4))) char stack[8192];
32+
33+
int putchar(int c) {
34+
// This is only valid in an emulator (QEMU), and it's skipping a proper configuration of the UART device
35+
// and waiting for a "ready to transit" state.
36+
37+
// QEMU riscv32-virt's specific location of the 16550A UART and its THR register
38+
*(volatile uint8_t *)(0x10000000 + 0) = c;
39+
return c;
40+
}

0 commit comments

Comments
 (0)