Skip to content

Commit

Permalink
refactor: arch
Browse files Browse the repository at this point in the history
Signed-off-by: Zone.N <[email protected]>
  • Loading branch information
MRNIU committed Jan 5, 2024
1 parent cd71f7d commit aa07c11
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 52 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@

本分支是 SImpleKernel 的首个分支。在本分支中,完成了构建系统的基础搭建、基本的文档部署与自动化测试,当然还有最重要的,有基于 uefi 的 x86_64 内核与由 opensbi 启动的 riscv64 内核,可以在 qemu 上运行,并实现了简单的屏幕输出。

调用顺序

- x86_64/aarch64
uefi->main.cpp:main->arch.cpp:arch_init

- riscv64
opensbi->boot.S:_start->main.cpp:main->arch.cpp:arch_init

- 构建系统

参考 [MRNIU/cmake-kernel](https://github.com/MRNIU/cmake-kernel) 的构建系统,详细解释见 [doc/build_system.md](./doc/build_system.md)
Expand Down
4 changes: 1 addition & 3 deletions cmake/add_header.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ endfunction ()

function (add_header_arch _target)
target_include_directories(${_target} PRIVATE
${CMAKE_SOURCE_DIR}/src/kernel/arch/include)
target_include_directories(${_target} PRIVATE
${CMAKE_SOURCE_DIR}/src/kernel/arch/${TARGET_ARCH}/include)
${CMAKE_SOURCE_DIR}/src/kernel/arch)
endfunction ()

function (add_header_kernel _target)
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/arch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ add_library(${PROJECT_NAME} OBJECT
$<$<STREQUAL:${TARGET_ARCH},riscv64>:
${PROJECT_SOURCE_DIR}/${TARGET_ARCH}/boot.S
>
${PROJECT_SOURCE_DIR}/${TARGET_ARCH}/arch.cpp
${PROJECT_SOURCE_DIR}/${TARGET_ARCH}/arch_main.cpp
)

# 添加头文件
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

/**
* @file arch.cpp
* @brief arch cpp
* @file arch_main.cpp
* @brief arch_main cpp
* @author Zone.N ([email protected])
* @version 1.0
* @date 2023-07-15
Expand All @@ -16,7 +16,7 @@

#include "arch.h"

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

Expand Down
8 changes: 4 additions & 4 deletions src/kernel/arch/include/arch.h → src/kernel/arch/arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
* </table>
*/

#ifndef CMAKE_ARCH_H
#define CMAKE_ARCH_H
#ifndef SIMPLEKERNEL_SRC_KERNEL_ARCH_ARCH_H
#define SIMPLEKERNEL_SRC_KERNEL_ARCH_ARCH_H

#include "cstdint"

int32_t arch(uint32_t _argc, uint8_t **_argv);
int32_t arch_init(uint32_t _argc, uint8_t **_argv);

#endif /* CMAKE_ARCH_H */
#endif /* SIMPLEKERNEL_SRC_KERNEL_ARCH_ARCH_H */
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

/**
* @file arch.cpp
* @brief arch cpp
* @file arch_main.cpp
* @brief arch_main cpp
* @author Zone.N ([email protected])
* @version 1.0
* @date 2023-07-15
Expand All @@ -14,12 +14,7 @@
* </table>
*/

#ifdef __cplusplus
extern "C" {
#endif

#include "cstdint"

#include "sbi/sbi_ecall_interface.h"

struct sbiret_t {
Expand Down Expand Up @@ -70,6 +65,14 @@ int arch(int, char **) {
return 0;
}

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

// 进入死循环
while (1) {
;
}

return 0;
}
#endif
29 changes: 0 additions & 29 deletions src/kernel/arch/x86_64/arch.cpp

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

/**
* @file arch.cpp
* @brief arch cpp
* @file arch_main.cpp
* @brief arch_main cpp
* @author Zone.N ([email protected])
* @version 1.0
* @date 2023-07-15
Expand All @@ -16,7 +16,7 @@

#include "arch.h"

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

Expand Down
3 changes: 3 additions & 0 deletions src/kernel/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@
* </table>
*/

#include "arch.h"
#include "kernel.h"

int main(int _argc, char **_argv) {
(void)_argc;
(void)_argv;

auto arch_init_ret = arch_init(_argc, (uint8_t **)_argv);

// 进入死循环
while (1) {
;
Expand Down

0 comments on commit aa07c11

Please sign in to comment.