Skip to content

Commit

Permalink
feat(opensbi_interface): add new 3rd
Browse files Browse the repository at this point in the history
Signed-off-by: Zone.N <[email protected]>
  • Loading branch information
MRNIU committed Mar 7, 2024
1 parent 6c6bd1b commit 1d004b7
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 94 deletions.
4 changes: 0 additions & 4 deletions cmake/add_header.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ endfunction()
function(add_header_driver _target)
target_include_directories(${_target} PRIVATE
${CMAKE_SOURCE_DIR}/src/kernel/driver/include)
target_include_directories(${_target} PRIVATE
${CMAKE_SOURCE_DIR}/src/kernel/driver/opensbi/include)
endfunction()

function(add_header_3rd _target)
Expand All @@ -51,7 +49,5 @@ function(add_header_3rd _target)
target_include_directories(${_target} PRIVATE
${gnu-efi_BINARY_DIR}/inc/protocol)
elseif (${TARGET_ARCH} STREQUAL "riscv64")
target_include_directories(${_target} PRIVATE
${opensbi_BINARY_DIR}/include)
endif ()
endfunction()
1 change: 1 addition & 0 deletions cmake/compile_config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ list(APPEND COMMON_LINK_LIB
>

$<$<STREQUAL:${TARGET_ARCH},riscv64>:
opensbi_interface::opensbi_interface
>

$<$<STREQUAL:${TARGET_ARCH},aarch64>:
Expand Down
5 changes: 5 additions & 0 deletions src/kernel/arch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,8 @@ target_compile_options(${PROJECT_NAME} PRIVATE
target_link_options(${PROJECT_NAME} PRIVATE
${DEFAULT_KERNEL_LINK_OPTIONS}
)

# 添加要链接的库
target_link_libraries(${PROJECT_NAME} PRIVATE
${DEFAULT_KERNEL_LINK_LIB}
)
58 changes: 13 additions & 45 deletions src/kernel/arch/riscv64/arch_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,56 +14,24 @@
* </table>
*/

#include "cstdint"
#include "sbi/sbi_ecall_interface.h"

struct sbiret_t {
/// 错误码
long error;
/// 返回值
long value;
};

sbiret_t ecall(unsigned long _arg0, unsigned long _arg1, unsigned long _arg2,
unsigned long _arg3, unsigned long _arg4, unsigned long _arg5,
int _fid, int _eid) {
sbiret_t ret;
register uintptr_t a0 asm("a0") = (uintptr_t)(_arg0);
register uintptr_t a1 asm("a1") = (uintptr_t)(_arg1);
register uintptr_t a2 asm("a2") = (uintptr_t)(_arg2);
register uintptr_t a3 asm("a3") = (uintptr_t)(_arg3);
register uintptr_t a4 asm("a4") = (uintptr_t)(_arg4);
register uintptr_t a5 asm("a5") = (uintptr_t)(_arg5);
register uintptr_t a6 asm("a6") = (uintptr_t)(_fid);
register uintptr_t a7 asm("a7") = (uintptr_t)(_eid);
asm("ecall"
: "+r"(a0), "+r"(a1)
: "r"(a2), "r"(a3), "r"(a4), "r"(a5), "r"(a6), "r"(a7)
: "memory");
ret.error = a0;
ret.value = a1;
return ret;
}

void put_char(const char _c) {
ecall(_c, 0, 0, 0, 0, 0, 0, SBI_EXT_0_1_CONSOLE_PUTCHAR);
return;
}
#include "opensbi_interface.h"

int32_t arch_init(uint32_t _argc, uint8_t **_argv) {
(void)_argc;
(void)_argv;

put_char('H');
put_char('e');
put_char('l');
put_char('l');
put_char('W');
put_char('o');
put_char('r');
put_char('l');
put_char('d');
put_char('!');
sbi_debug_console_write_byte('H');
sbi_debug_console_write_byte('e');
sbi_debug_console_write_byte('l');
sbi_debug_console_write_byte('l');
sbi_debug_console_write_byte('o');
sbi_debug_console_write_byte('W');
sbi_debug_console_write_byte('o');
sbi_debug_console_write_byte('r');
sbi_debug_console_write_byte('l');
sbi_debug_console_write_byte('d');
sbi_debug_console_write_byte('!');
sbi_debug_console_write_byte('\n');

// 进入死循环
while (1) {
Expand Down
58 changes: 13 additions & 45 deletions test/system_test/opensbi_test/boot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,53 +14,21 @@
* </table>
*/

#include "cstdint"
#include "sbi/sbi_ecall_interface.h"

struct sbiret_t {
/// 错误码
long error;
/// 返回值
long value;
};

sbiret_t ecall(unsigned long _arg0, unsigned long _arg1, unsigned long _arg2,
unsigned long _arg3, unsigned long _arg4, unsigned long _arg5,
int _fid, int _eid) {
sbiret_t ret;
register uintptr_t a0 asm("a0") = (uintptr_t)(_arg0);
register uintptr_t a1 asm("a1") = (uintptr_t)(_arg1);
register uintptr_t a2 asm("a2") = (uintptr_t)(_arg2);
register uintptr_t a3 asm("a3") = (uintptr_t)(_arg3);
register uintptr_t a4 asm("a4") = (uintptr_t)(_arg4);
register uintptr_t a5 asm("a5") = (uintptr_t)(_arg5);
register uintptr_t a6 asm("a6") = (uintptr_t)(_fid);
register uintptr_t a7 asm("a7") = (uintptr_t)(_eid);
asm("ecall"
: "+r"(a0), "+r"(a1)
: "r"(a2), "r"(a3), "r"(a4), "r"(a5), "r"(a6), "r"(a7)
: "memory");
ret.error = a0;
ret.value = a1;
return ret;
}

void put_char(const char _c) {
ecall(_c, 0, 0, 0, 0, 0, 0, SBI_EXT_0_1_CONSOLE_PUTCHAR);
return;
}
#include "opensbi_interface.h"

int main(int, char **) {
put_char('H');
put_char('e');
put_char('l');
put_char('l');
put_char('W');
put_char('o');
put_char('r');
put_char('l');
put_char('d');
put_char('!');
sbi_debug_console_write_byte('H');
sbi_debug_console_write_byte('e');
sbi_debug_console_write_byte('l');
sbi_debug_console_write_byte('l');
sbi_debug_console_write_byte('o');
sbi_debug_console_write_byte('W');
sbi_debug_console_write_byte('o');
sbi_debug_console_write_byte('r');
sbi_debug_console_write_byte('l');
sbi_debug_console_write_byte('d');
sbi_debug_console_write_byte('!');
sbi_debug_console_write_byte('\n');

return 0;
}

0 comments on commit 1d004b7

Please sign in to comment.