Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
verilator
srecord
d2
dtc
];
in {
formatter = pkgs.alejandra;
Expand Down
4 changes: 4 additions & 0 deletions sw/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ enable_testing()

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

include(ExternalProject)

include(cmake/opensbi.cmake)

add_subdirectory(device)
6 changes: 5 additions & 1 deletion sw/cheri_toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ string(CONCAT CMAKE_C_FLAGS_INIT
" -Wall -Wextra"
)

set(CMAKE_ASM_FLAGS_INIT "")
set(CMAKE_ASM_FLAGS_INIT
# Workaround: Our current build of the LLVM toolchain crashes
# when trying to erroneously relax the devicetree assembly file.
"-mno-relax"
)

set(CMAKE_EXE_LINKER_FLAGS_INIT
"-nodefaultlibs"
Expand Down
57 changes: 57 additions & 0 deletions sw/cmake/opensbi.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Copyright lowRISC contributors.
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0

set(OPENSBI_REPOSITORY https://github.com/lowrisc/opensbi)
set(OPENSBI_TAG mocha-devel)

# build command - run make with build options.
set(BUILD_COMMAND
make
# Use CHERI LLVM.
LLVM=1
# ISA options.
PLATFORM_RISCV_XLEN=64
PLATFORM_RISCV_ISA=rv64imac_zcherihybrid
PLATFORM_RISCV_ABI=l64pc128
# Build for the 'generic' platform, which uses devicetree data.
PLATFORM=generic
# Use the Mocha defconfig file.
PLATFORM_DEFCONFIG=mocha_defconfig
# Build a 'payload' and 'jump' firmware.
FW_PAYLOAD=y
FW_JUMP=y
# Disable position-independent code and link to DRAM base,
# as loading position-independent executables is not supported by
# our Verilator ELF loader.
FW_PIC=n
FW_TEXT_START=0x80000000
# 0x2 bit = build with runtime debug printing.
FW_OPTIONS=0x2
)

# Built firmware binaries to copy into the root of the external project directory.
set(FIRMWARES
build/platform/generic/firmware/fw_payload.elf
build/platform/generic/firmware/fw_payload.bin
build/platform/generic/firmware/fw_jump.elf
build/platform/generic/firmware/fw_jump.bin
)

# install command - copy the firmware binaries to the root of the external project directory.
set(INSTALL_COMMAND
cp ${FIRMWARES} <INSTALL_DIR>
)

ExternalProject_Add(
opensbi PREFIX opensbi
GIT_REPOSITORY ${OPENSBI_REPOSITORY}
GIT_TAG ${OPENSBI_TAG}
# OpenSBI builds in its own 'build' sub-directory.
BUILD_IN_SOURCE true
# make is job server aware.
BUILD_JOB_SERVER_AWARE true
CONFIGURE_COMMAND "" # no configure step needed, do nothing here.
BUILD_COMMAND ${BUILD_COMMAND}
INSTALL_COMMAND ${INSTALL_COMMAND}
)
15 changes: 14 additions & 1 deletion sw/device/bootrom/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,20 @@ set(NAME bootrom)
add_executable(${NAME} bootrom.c)
target_link_libraries(${NAME} hal_vanilla runtime_vanilla startup_vanilla)
target_compile_options(${NAME} PUBLIC ${VANILLA_FLAGS})
target_link_options(${NAME} PUBLIC
target_link_options(${NAME} PUBLIC
"-nodefaultlibs"
"-Wl,--defsym,BOOT_ROM_OFFSET=0x00"
"-T${LDS}"
"-L${LDS_DIR}"
)
install(TARGETS ${NAME})
mocha_add_executable_artefacts(${NAME})

set(NAME dt_dram_bootrom)
add_executable(${NAME} dt_dram_bootrom.c ../devicetree/mocha.S)
target_link_libraries(${NAME} startup_vanilla)
target_compile_options(${NAME} PUBLIC ${VANILLA_FLAGS})
target_link_options(${NAME} PUBLIC
"-nodefaultlibs"
"-Wl,--defsym,BOOT_ROM_OFFSET=0x00"
"-T${LDS}"
Expand Down
34 changes: 34 additions & 0 deletions sw/device/bootrom/dt_dram_bootrom.c
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bootrom can now jump to dram

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright lowRISC contributors (COSMIC project).
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

#include "boot/trap.h"
#include "builtin.h"
#include "hal/mocha.h"
#if defined(__riscv_zcherihybrid)
#include <cheriintrin.h>
#endif /* defined(__riscv_zcherihybrid) */

// An example boot ROM fragment that jumps into DRAM with
// the current hart ID and a pointer to devicetree blob in
// the a0 and a1 registers respectively.

/* Pointer to devicetree blob, defined in devicetree/mocha.S */
extern char dt_blob_start[];

int main(void)
{
asm volatile("mv a0, zero\n" /* a0 = hart id */
"mv a1, %[dtb]\n" /* a1 = pointer to devicetree blob */
"jr %[dram]\n"
:
: [dtb] "r"(dt_blob_start), [dram] "r"(dram_base)
: "a0", "a1", "memory");
return 0;
}

void _trap_handler(struct trap_registers *registers, struct trap_context *context)
{
(void)registers;
(void)context;
}
6 changes: 6 additions & 0 deletions sw/device/devicetree/REUSE.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version = 1

[[annotations]]
path = ["mocha.S"]
SPDX-FileCopyrightText = "lowRISC Contributors (COSMIC project)."
SPDX-License-Identifier = "Apache-2.0"
Loading