Merge branch 'cmakeflow' into develop
This commit is contained in:
1
hello-world/.gitignore
vendored
1
hello-world/.gitignore
vendored
@@ -1,2 +1,3 @@
|
||||
/hello
|
||||
/hello.dis
|
||||
build/
|
23
hello-world/CMakeLists.txt
Normal file
23
hello-world/CMakeLists.txt
Normal file
@@ -0,0 +1,23 @@
|
||||
cmake_minimum_required(VERSION 3.21)
|
||||
project(hello-world C)
|
||||
set(TARGET hello)
|
||||
option(HAVE_NO_INIT_FINI "Enable NO_INIT_FINI" OFF)
|
||||
|
||||
if(HAVE_NO_INIT_FINI)
|
||||
#if HAVE_NO_INIT_FINI is ON
|
||||
add_definitions(-DHAVE_NO_INIT_FINI)
|
||||
endif()
|
||||
|
||||
add_executable(${TARGET} hello.c)
|
||||
|
||||
|
||||
|
||||
set(BOARD "iss" CACHE STRING "Target board")
|
||||
message(" BOARD = ${BOARD}")
|
||||
add_subdirectory(../bare-metal-bsp bsp)
|
||||
target_link_libraries(${TARGET} PRIVATE bsp)
|
||||
target_link_options(${TARGET} PRIVATE -Wl,-Map=${TARGET}.map)
|
||||
|
||||
add_custom_command(TARGET ${TARGET} POST_BUILD
|
||||
COMMAND ${CMAKE_OBJDUMP} -S ${TARGET}.elf > ${TARGET}.dis
|
||||
COMMENT "Creating disassembly for ${TARGET}")
|
70
hello-world/CMakePresets.json
Normal file
70
hello-world/CMakePresets.json
Normal file
@@ -0,0 +1,70 @@
|
||||
{
|
||||
"version": 3,
|
||||
"vendor": {
|
||||
"conan": {}
|
||||
},
|
||||
"cmakeMinimumRequired": {
|
||||
"major": 3,
|
||||
"minor": 24,
|
||||
"patch": 0
|
||||
},
|
||||
"configurePresets": [
|
||||
{
|
||||
"name": "debug",
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "Debug",
|
||||
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv32imc.cmake"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "debug_moon",
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "Debug",
|
||||
"BOARD": "moonlight",
|
||||
"HAVE_NO_INIT_FINI": "ON",
|
||||
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv32imc.cmake"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "debug_tgc",
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "Debug",
|
||||
"BOARD": "tgc_vp",
|
||||
"HAVE_NO_INIT_FINI": "ON",
|
||||
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv32imc.cmake"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "debug_64",
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "Debug",
|
||||
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv64gc.cmake"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "debug_64_moon",
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "Debug",
|
||||
"BOARD": "moonlight",
|
||||
"HAVE_NO_INIT_FINI": "ON",
|
||||
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv64gc.cmake"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "debug_64_tgc",
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "Debug",
|
||||
"BOARD": "tgc_vp",
|
||||
"HAVE_NO_INIT_FINI": "ON",
|
||||
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv64gc.cmake"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "release",
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "Release",
|
||||
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv32imc.cmake"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
@@ -1,24 +1,37 @@
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "platform.h"
|
||||
#include "encoding.h"
|
||||
#include "platform.h"
|
||||
#include <string.h>
|
||||
|
||||
int factorial(int i){
|
||||
int factorial(int i) {
|
||||
|
||||
volatile int result = 1;
|
||||
for (int ii = 1; ii <= i; ii++) {
|
||||
result = result * ii;
|
||||
}
|
||||
return result;
|
||||
volatile int result = 1;
|
||||
for (int ii = 1; ii <= i; ii++) {
|
||||
result = result * ii;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
extern volatile uintptr_t tohost;
|
||||
|
||||
void write_tohost(char *string) {
|
||||
volatile uint64_t payload[4] = {64, 0, (uintptr_t)string,
|
||||
(strlen(string) + 1)};
|
||||
tohost = (uintptr_t)payload;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
volatile int result = factorial (10);
|
||||
printf("Factorial is %d\n", result);
|
||||
printf("End of execution");
|
||||
return 0;
|
||||
int main() {
|
||||
char string[] = "hello world with write in hello";
|
||||
|
||||
write_tohost(string);
|
||||
|
||||
write(STDOUT_FILENO, string, sizeof(string));
|
||||
|
||||
int result = factorial(10);
|
||||
printf("Factorial is %d", result);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user