File tree Expand file tree Collapse file tree 4 files changed +71
-0
lines changed
utils/embedded-test-support Expand file tree Collapse file tree 4 files changed +71
-0
lines changed Original file line number Diff line number Diff line change @@ -547,6 +547,16 @@ if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB_CROSS_COMPILING)
547
547
"${CMAKE_CURRENT_SOURCE_DIR} /lit.site.cfg.in"
548
548
"${CMAKE_CURRENT_BINARY_DIR}${VARIANT_SUFFIX} /lit.site.cfg"
549
549
"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" )
550
560
endif ()
551
561
552
562
# Add shortcuts for the default variant.
Original file line number Diff line number Diff line change @@ -63,6 +63,15 @@ def main():
63
63
semihosting = False
64
64
qemu_mode = "-bios"
65
65
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
66
75
else :
67
76
assert False
68
77
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments