Skip to content

Commit

Permalink
Merge branch 'boot' into new_intr
Browse files Browse the repository at this point in the history
  • Loading branch information
MRNIU committed Jul 8, 2024
2 parents 6c8cd5a + 6aa17eb commit d6c0323
Show file tree
Hide file tree
Showing 15 changed files with 196 additions and 417 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ include(compile_config)

# qemu 参数设置
list(APPEND QEMU_FLAGS
# 不启用图形界面
-nographic
# 使用标准输出显示
-serial stdio
# 启动 telnet 服务,使用 2333 端口,不等待连接
Expand All @@ -57,7 +59,6 @@ if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64")
list(APPEND QEMU_FLAGS
-machine virt
-nographic
# 可选项,qemu7.0 自带了 opensbi1.0
-bios ${opensbi_BINARY_DIR}/platform/generic/firmware/fw_jump.elf
-kernel $<TARGET_FILE:kernel>
Expand Down
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,21 @@ intr branch
- TODO

riscv64 PLIC

x86_64 APIC

- 全局对象

| 对象名 | 位置 | 用途 |
| :--------------------------------------: | :----------------------------------: | :---------------------: |
| `static ostream cout` | src/kernel/libcxx/include/iostream | 内核中的 std::cout 实现 |
| `static Singleton<KernelElf> kKernelElf` | src/kernel/include/kernel_elf.hpp | 解析内核自身的 elf 信息 |
| `static Singleton<KernelFdt> kKernelFdt` | src/kernel/include/kernel_fdt.hpp | 解析 dtb 信息 |
| `static Singleton<BasicInfo> kBasicInfo` | src/kernel/include/basic_info.hpp | 内核基本信息 |
| `static cpu::Serial kSerial(cpu::kCom1)` | src/kernel/arch/x86_64/arch_main.cpp | X86_64 下的串口 |



## 已支持特性

- [x] [BUILD] 使用 CMake 的构建系统
Expand Down
1 change: 0 additions & 1 deletion src/boot/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ add_executable(${PROJECT_NAME}
boot.cpp
load_elf.cpp
out_stream.cpp
graphics.cpp
memory.cpp
)

Expand Down
41 changes: 17 additions & 24 deletions src/boot/boot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* </table>
*/

#include "kernel/include/kernel.h"
#include "load_elf.h"
#include "out_stream.hpp"
#include "project_config.h"
Expand Down Expand Up @@ -65,12 +64,6 @@ efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *system_table) {
debug << L"Unload: " << OutStream::hex_X << loaded_image->Unload
<< OutStream::endl;

// 初始化 Graphics
auto graphics = Graphics();
// 打印图形信息
graphics.PrintInfo();
// 设置为 kDefaultWidth*kDefaultHeight
graphics.SetMode();
// 初始化 Memory
auto memory = Memory();
memory.PrintInfo();
Expand Down Expand Up @@ -107,23 +100,23 @@ efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *system_table) {
return status;
}

// 向内核传递参数
BasicInfo basic_info = {};

// 获取内存信息
basic_info.memory_map_count = memory.GetMemoryMap(basic_info.memory_map);

// 获取 framebuffer 信息
auto [framebuffer_base, framebuffer_size, framebuffer_width,
framebuffer_height, framebuffer_pixel_per_line] =
graphics.GetFrameBuffer();
basic_info.framebuffer.base = framebuffer_base;
basic_info.framebuffer.size = framebuffer_size;
basic_info.framebuffer.width = framebuffer_width;
basic_info.framebuffer.height = framebuffer_height;
basic_info.framebuffer.pitch = framebuffer_pixel_per_line * sizeof(uint32_t);

// 获取 elf 地址
/// 基础信息
/// @note 结构与 basic_info.hpp 同步
struct {
uint64_t physical_memory_addr;
size_t physical_memory_size;
uint64_t kernel_addr;
size_t kernel_size;
uint64_t elf_addr;
size_t elf_size;
} basic_info;

// 获取物理内存信息
auto [physical_memory_addr, physical_memory_size] = memory.GetMemory();

// 填充信息
basic_info.physical_memory_addr = physical_memory_addr;
basic_info.physical_memory_size = physical_memory_size;
basic_info.elf_addr = elf_info.first;
basic_info.elf_size = elf_info.second;

Expand Down
127 changes: 0 additions & 127 deletions src/boot/graphics.cpp

This file was deleted.

65 changes: 3 additions & 62 deletions src/boot/include/load_elf.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
#include <tuple>
#include <utility>

#include "kernel/include/kernel.h"

#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -37,61 +35,6 @@ extern "C" {
}
#endif

/**
* 图形相关
*/
class Graphics {
public:
/**
* 构造函数
*/
Graphics();

/**
* 析构函数
*/
~Graphics() = default;

/// @name 不使用的构造函数
/// @{
Graphics(const Graphics &) = delete;
Graphics(Graphics &&) = delete;
auto operator=(const Graphics &) -> Graphics & = delete;
auto operator=(Graphics &&) -> Graphics & = delete;
/// @}

/**
* 设置图形模式
* @param format 图形像素格式,默认为 PixelBlueGreenRedReserved8BitPerColor
* @param width 宽度,默认为 1920
* @param height 高度,默认为 1080
*/
void SetMode(
EFI_GRAPHICS_PIXEL_FORMAT format = PixelRedGreenBlueReserved8BitPerColor,
uint32_t width = kDefaultWidth, uint32_t height = kDefaultHeight) const;

/**
* 获取图形缓冲区信息
* @return 缓冲区地址,缓冲区长度,垂直像素个数,水平像素个数,每行像素个数
*/
[[nodiscard]] auto GetFrameBuffer() const
-> std::tuple<uint64_t, uint32_t, uint32_t, uint32_t, uint32_t>;

/**
* 输出图形信息
*/
void PrintInfo() const;

private:
/// @name 默认分辨率
/// @{
static constexpr const uint32_t kDefaultWidth = 800;
static constexpr const uint32_t kDefaultHeight = 600;
/// @}
/// 图形输出协议
EFI_GRAPHICS_OUTPUT_PROTOCOL *gop_ = nullptr;
};

/**
* 内存相关
*/
Expand All @@ -116,12 +59,10 @@ class Memory {
/// @}

/**
* 获取内存信息,MemoryMap 指 arch.h 中定义的内存信息类型
* @param mmap 要传递给内核的 MemoryMap 结构数组
* @return mmap 数量
* 获取内存信息,只保留地址与长度
* @return std::pair<uint64_t, size_t> 内存地址与长度
*/
size_t GetMemoryMap(
BasicInfo::MemoryMap mmap[BasicInfo::kMemoryMapMaxCount]) const;
std::pair<uint64_t, size_t> GetMemory() const;

/**
* 输出内存映射信息
Expand Down
Loading

0 comments on commit d6c0323

Please sign in to comment.