Skip to content

Commit 883609a

Browse files
committed
sw: tests: add Verilator DRAM loading test
Signed-off-by: Alice Ziuziakowska <a.ziuziakowska@lowrisc.org>
1 parent 1962f9a commit 883609a

4 files changed

Lines changed: 166 additions & 0 deletions

File tree

sw/device/lib/boot/dram_test.ld

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/* Copyright lowRISC contributors (COSMIC project). */
2+
/* Licensed under the Apache License, Version 2.0, see LICENSE for details. */
3+
/* SPDX-License-Identifier: Apache-2.0 */
4+
5+
OUTPUT_ARCH(riscv)
6+
7+
INCLUDE memory.ld
8+
9+
MEMORY {
10+
ram (RWX) : ORIGIN = ORIGIN(DRAM), LENGTH = LENGTH(DRAM)
11+
}
12+
13+
/* Provided in init_vectors.S, immediately jumps into _start. */
14+
ENTRY(_init_vector)
15+
16+
SECTIONS {
17+
_program_start = ORIGIN(ram);
18+
19+
.init_vectors ORIGIN(ram) : {
20+
*(.init_vectors)
21+
} > ram
22+
23+
.text : {
24+
. = ALIGN(8);
25+
*(.text)
26+
*(.text.*)
27+
. = ALIGN(8);
28+
} > ram
29+
30+
.rodata : {
31+
. = ALIGN(8);
32+
/* Small rodata before large rodata */
33+
*(.srodata)
34+
*(.srodata.*)
35+
*(.rodata)
36+
*(.rodata.*)
37+
. = ALIGN(8);
38+
} > ram
39+
40+
/* capability relocation entries */
41+
/* __start___cap_relocs and __stop___cap_relocs are provided by the toolchain */
42+
__cap_relocs : {
43+
*(__cap_relocs)
44+
. = ALIGN(8);
45+
} > ram
46+
47+
.data : {
48+
. = ALIGN(8);
49+
/* Small data before large data */
50+
*(.sdata)
51+
*(.sdata.*)
52+
*(.data)
53+
*(.data.*)
54+
. = ALIGN(8);
55+
} > ram
56+
57+
.bss : {
58+
. = ALIGN(8);
59+
_bss_start = .;
60+
_sbss = .; /* Rust */
61+
/* Small bss before large bss */
62+
*(.sbss)
63+
*(.sbss.*)
64+
*(.bss)
65+
*(.bss.*)
66+
*(COMMON)
67+
. = ALIGN(8);
68+
_ebss = .; /* Rust */
69+
_bss_end = .;
70+
} > ram
71+
72+
.got : {
73+
. = ALIGN(8);
74+
*(.got)
75+
*(.got.*)
76+
. = ALIGN(8);
77+
} > ram
78+
79+
. = ALIGN(1024);
80+
.stack : {
81+
. = ALIGN(1024);
82+
_stack_bottom = .;
83+
. = . + 1024;
84+
_stack_top = .;
85+
_stack_len = _stack_top - _stack_bottom;
86+
} > ram
87+
88+
. = ALIGN(8);
89+
_program_end = .;
90+
}

sw/device/tests/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@ mocha_add_test(NAME tag_controller_tag_test SOURCES tag_controller/tag_test.c LI
1818
mocha_add_test(NAME timer_smoketest SOURCES timer/smoketest.c LIBRARIES ${LIBS} FPGA)
1919
mocha_add_test(NAME timer_interrupt_test SOURCES timer/interrupt.c LIBRARIES ${LIBS})
2020
mocha_add_test(NAME uart_smoketest SOURCES uart/smoketest.c LIBRARIES ${LIBS})
21+
22+
add_subdirectory(dram)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Copyright lowRISC contributors (COSMIC project).
2+
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
# This DRAM test is to test loading a binary into DRAM in Verilator,
6+
# before we have general support for running tests from DRAM.
7+
# For this test, we build a version of the test framework test linked at DRAM
8+
# which we load alongside the test binary. The test binary just jumps into DRAM.
9+
10+
# TODO: This should be generalised to all tests once we have the ability to load
11+
# DRAM in all environments (FPGA, DV).
12+
13+
set(LIBS hal runtime startup test_framework)
14+
15+
add_executable(test_framework_test_vanilla_dram ../test_framework/smoketest.c)
16+
target_compile_options(test_framework_test_vanilla_dram PUBLIC ${VANILLA_FLAGS})
17+
foreach(LIB ${LIBS})
18+
target_link_libraries(test_framework_test_vanilla_dram PUBLIC ${LIB}_vanilla)
19+
target_include_directories(test_framework_test_vanilla_dram PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../../lib")
20+
endforeach()
21+
target_link_options(
22+
test_framework_test_vanilla_dram PUBLIC
23+
# Workaround: This address doesn't matter as we don't use system reset here,
24+
# but it needs to be addressible by the medany code model.
25+
"-Wl,--defsym,BOOT_ROM_OFFSET=0x80000000"
26+
"-T" "dram_test.ld"
27+
"-L" ${LDS_DIR}
28+
)
29+
30+
add_executable(dram_test_rom ../dram/dram_test_rom.c)
31+
target_compile_options(dram_test_rom PUBLIC ${VANILLA_FLAGS})
32+
foreach(LIB ${LIBS})
33+
target_link_libraries(dram_test_rom PUBLIC ${LIB}_vanilla)
34+
target_include_directories(dram_test_rom PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../../lib")
35+
endforeach()
36+
target_link_options(
37+
dram_test_rom PUBLIC
38+
"-Wl,--defsym,BOOT_ROM_OFFSET=0x00"
39+
"-T" "${LDS}"
40+
"-L" ${LDS_DIR}
41+
)
42+
43+
add_test(
44+
NAME dram_load_test_sim_verilator
45+
COMMAND ${PROJECT_SOURCE_DIR}/../util/verilator_runner.sh -E dram_test_rom -E test_framework_test_vanilla_dram
46+
)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright lowRISC contributors (COSMIC project).
2+
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
#include "hal/mocha.h"
6+
#include "hal/uart.h"
7+
#include "runtime/print.h"
8+
#if defined(__riscv_zcherihybrid)
9+
#include <cheriintrin.h>
10+
#endif /* defined(__riscv_zcherihybrid) */
11+
12+
// This test expects a test binary to be loaded into DRAM.
13+
// This will just jump to the start of that test.
14+
15+
bool test_main(void)
16+
{
17+
uart_t console = mocha_system_uart();
18+
uart_init(console);
19+
20+
enum : uint64_t { boot_vector = dram_base + 0x80 };
21+
uprintf(console, "jumping to DRAM boot vector: %lx\n", boot_vector);
22+
23+
void (*boot)(void) = (void (*)(void))boot_vector;
24+
boot();
25+
26+
/* Test in DRAM should have succeeded and terminated the test */
27+
return false;
28+
}

0 commit comments

Comments
 (0)