Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic SDK setup #5

Merged
merged 11 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
*~
.ninja*
**/build/*
43 changes: 43 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright 2024 ETH Zurich and University of Bologna.
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0
#
# Moritz Scherer <[email protected]>

cmake_minimum_required(VERSION 3.13)

include(${CMAKE_CURRENT_LIST_DIR}/cmake/Utils.cmake)

set(CMAKE_C_STANDARD 99)

set(CMAKE_C_COMPILER_WORKS 1)
set(CMAKE_TOOLCHAIN_FILE cmake/toolchain_gcc.cmake)

project(chimera-sdk LANGUAGES C ASM)

set(AVAILABLE_TARGETS
"Cheshire"
CACHE STRING "Available Targets"
)

get_property(OPT_STRINGS CACHE OPT PROPERTY STRINGS)

if(NOT TARGET_PLATFORM IN_LIST AVAILABLE_TARGETS)
message(FATAL_ERROR "Wrong value for TARGET_PLATFORM: Got ${TARGET_PLATFORM}")
endif()


if (TARGET_PLATFORM STREQUAL "Cheshire")
add_subdirectory(targets/cheshire)
endif()

add_subdirectory(hal)

add_library(chimera-sdk INTERFACE)
target_link_libraries(chimera-sdk INTERFACE hal)
target_link_libraries(chimera-sdk INTERFACE runtime)
target_sources(chimera-sdk INTERFACE $<TARGET_OBJECTS:runtime>)

enable_testing()

add_subdirectory(tests)
19 changes: 19 additions & 0 deletions cmake/Utils.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2024 ETH Zurich and University of Bologna.
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0
#
# Moritz Scherer <[email protected]>

macro(add_chimera_executable name)
add_executable(${ARGV})
add_custom_command(
TARGET ${name}
POST_BUILD
COMMAND ${CMAKE_OBJDUMP} -dhS $<TARGET_FILE:${name}> > $<TARGET_FILE:${name}>.s)
endmacro()

## TODO: Add vsim target or some such
macro(add_chimera_test name)
add_chimera_executable(${ARGV})
add_test(NAME ${name} COMMAND ${name})
endmacro()
16 changes: 16 additions & 0 deletions cmake/toolchain_gcc.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2024 ETH Zurich and University of Bologna.
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0
#
# Moritz Scherer <[email protected]>

set(CMAKE_EXECUTABLE_SUFFIX ".elf")

set(CMAKE_SYSTEM_NAME Generic)

set(CMAKE_C_COMPILER riscv32-unknown-elf-gcc)
set(CMAKE_CXX_COMPILER riscv32-unknown-elf-g++)
set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER})
set(CMAKE_OBJCOPY riscv32-unknown-elf-objcopy)
set(CMAKE_OBJDUMP riscv32-unknown-elf-objdump)
set(CMAKE_AR riscv32-unknown-elf-ar)
16 changes: 16 additions & 0 deletions hal/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2024 ETH Zurich and University of Bologna.
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0
#
# Moritz Scherer <[email protected]>

file(GLOB_RECURSE SOURCES
"src/*"
)

add_library(hal STATIC ${SOURCES})

target_include_directories(hal
PUBLIC
"inc/"
)
26 changes: 26 additions & 0 deletions hal/inc/device_api.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2024 ETH Zurich and University of Bologna.
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0
//
// Moritz Scherer <[email protected]>

#include <stdio.h>
#include <stdint.h>

typedef bool (*chi_device_callback)(struct chi_device *device);

typedef struct chi_device_api
{
int (*open)(struct chi_device *device);
int (*close)(struct chi_device *device);
ssize_t (*read_async)(struct chi_device *device,
void *buffer, uint32_t size, chi_device_callback cb);
ssize_t (*write_async)(struct chi_device *device,
const void *buffer, uint32_t size, chi_device_callback cb);
} chi_device_api_t;

typedef struct chi_device {
struct chi_device_api *api; // function pointers
uint32_t* device_addr;
void *cfg;
} chi_device_t;
8 changes: 8 additions & 0 deletions hal/src/device_api.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright 2024 ETH Zurich and University of Bologna.
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0
//
// Moritz Scherer <[email protected]>

#include <stdio.h>
#include <stdint.h>
5 changes: 5 additions & 0 deletions targets/CMakeLists.txt
viv-eth marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright 2024 ETH Zurich and University of Bologna.
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0
#
# Moritz Scherer <[email protected]>
30 changes: 30 additions & 0 deletions targets/cheshire/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2024 ETH Zurich and University of Bologna.
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0
#
# Moritz Scherer <[email protected]>

file(GLOB_RECURSE ASM_SOURCES
"src/crt0.S"
)
set_property(SOURCE ${ASM_SOURCES} PROPERTY LANGUAGE ASM)
add_library(runtime OBJECT ${ASM_SOURCES})

set(ISA rv32imc)
set(ABI ilp32)

target_compile_options(runtime
PUBLIC
-march=${ISA}
-mabi=${ABI}
)

target_link_options(runtime
PUBLIC
-march=${ISA}
-mabi=${ABI}
-nostartfiles
-nostdlib
-L${CMAKE_CURRENT_LIST_DIR}
-Tlink.ld
)
51 changes: 51 additions & 0 deletions targets/cheshire/common.ldh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* Copyright 2022 ETH Zurich and University of Bologna. */
/* Licensed under the Apache License, Version 2.0, see LICENSE for details. */
/* SPDX-License-Identifier: Apache-2.0 */

/* Nicole Narr <[email protected]> */
/* Christopher Reinwardt <[email protected]> */
/* Paul Scheffler <[email protected]> */

/* This header defines symbols and rules universal to bare-metal execution */

ENTRY(_start)

MEMORY {
bootrom (rx) : ORIGIN = 0x02000000, LENGTH = 16K
/* We assume at least 64 KiB SPM, same minus stack for ROMs. */
/* If more SPM is available, CRT0 repoints the stack. */
extrom (rx) : ORIGIN = 0x00000000, LENGTH = 48K
spm (rwx) : ORIGIN = 0x10000000, LENGTH = 64K
memisl (rwx) : ORIGIN = 0x18000000, LENGTH = 64K
/* We assume at least 8 MiB of DRAM (minimum for Linux). */
dram (rwx) : ORIGIN = 0x80000000, LENGTH = 8M
}

SECTIONS {
/* Keep binaries lean */
/DISCARD/ : { *(.riscv.attributes) *(.comment) }

/* Global and stack pointer */
/* By default, keep the calling context (boot ROM) stack pointer */
__global_pointer$ = ADDR(.misc) + SIZEOF(.misc) / 2;
__stack_pointer$ = 0;

/* Further addresses */
__base_dma = 0x01000000;
__base_bootrom = 0x02000000;
__base_clint = 0x02040000;
__base_axirt = 0x020C0000;
__base_axirtgrd = 0x020C1ffc;
__base_regs = 0x03000000;
__base_llc = 0x03001000;
__base_uart = 0x03002000;
__base_i2c = 0x03003000;
__base_spih = 0x03004000;
__base_gpio = 0x03005000;
__base_slink = 0x03006000;
__base_vga = 0x03007000;
__base_plic = 0x04000000;
__base_memisl = ORIGIN(memisl);
__base_spm = ORIGIN(spm);
__base_dram = ORIGIN(dram);
}
44 changes: 44 additions & 0 deletions targets/cheshire/link.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* Copyright 2022 ETH Zurich and University of Bologna. */
/* Licensed under the Apache License, Version 2.0, see LICENSE for details. */
/* SPDX-License-Identifier: Apache-2.0 */

/* Nicole Narr <[email protected]> */
/* Christopher Reinwardt <[email protected]> */
/* Paul Scheffler <[email protected]> */

INCLUDE common.ldh

SECTIONS {
.text : {
*(.text._start)
*(.text)
*(.text.*)
} > memisl

.misc : ALIGN(16) {
*(.rodata)
*(.rodata.*)
*(.data)
*(.data.*)
*(.srodata)
*(.srodata.*)
*(.sdata)
*(.sdata.*)
} > memisl

. = ALIGN(32);
__bss_start = .;
.bss : {
*(.bss)
*(.bss.*)
*(.sbss)
*(.sbss.*)
} > memisl
. = ALIGN(32);
__bss_end = .;

.bulk : ALIGN(16) {
*(.bulk)
*(.bulk.*)
} > memisl
}
Loading