Skip to content

Commit

Permalink
Merge pull request #3 from digmouse233/lib
Browse files Browse the repository at this point in the history
Lib
  • Loading branch information
MRNIU authored Nov 22, 2021
2 parents b1258e9 + 61965f7 commit a19f35d
Show file tree
Hide file tree
Showing 82 changed files with 24,667 additions and 119 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# vmm
# intr

虚拟内存管理
中断管理+键盘输入

7 changes: 4 additions & 3 deletions cmake/header_files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ function(target_include_arch_header_files Target)
target_include_directories(${Target} PRIVATE ${SimpleKernel_SOURCE_CODE_DIR}/arch/${SimpleKernelArch}/)
if (SimpleKernelArch STREQUAL "ia32/i386" OR SimpleKernelArch STREQUAL "ia32/x86_64")
target_include_directories(${Target} PRIVATE ${SimpleKernel_SOURCE_CODE_DIR}/arch/ia32)
target_include_directories(${Target} PRIVATE ${SimpleKernel_SOURCE_CODE_DIR}/arch/ia32/multiboot2/include)
target_include_directories(${Target} PRIVATE ${SimpleKernel_SOURCE_CODE_DIR}/arch/ia32/port/include)
target_include_directories(${Target} PRIVATE ${SimpleKernel_SOURCE_CODE_DIR}/arch/${SimpleKernelArch}/gdt/include)
target_include_directories(${Target} PRIVATE ${SimpleKernel_SOURCE_CODE_DIR}/arch/${SimpleKernelArch}/intr/include)
target_include_directories(${Target} PRIVATE ${SimpleKernel_SOURCE_CODE_DIR}/arch/ia32/apic/include)
elseif (SimpleKernelArch STREQUAL riscv64)
target_include_directories(${Target} PRIVATE ${SimpleKernel_SOURCE_CODE_DIR}/arch/${SimpleKernelArch}/opensbi/include)
target_include_directories(${Target} PRIVATE ${SimpleKernel_SOURCE_CODE_DIR}/arch/${SimpleKernelArch}/intr/include)
endif()
endfunction()

Expand All @@ -36,12 +38,11 @@ function(target_include_common_header_files Target)
endfunction()

function(target_include_drv_header_files Target)
target_include_directories(${Target} PRIVATE ${SimpleKernel_SOURCE_CODE_DIR}/drv/dtb/include)
target_include_directories(${Target} PRIVATE ${SimpleKernel_SOURCE_CODE_DIR}/drv/multiboot2/include)
target_include_directories(${Target} PRIVATE ${SimpleKernel_SOURCE_CODE_DIR}/drv/tui/include)
target_include_directories(${Target} PRIVATE ${SimpleKernel_SOURCE_CODE_DIR}/drv/uart/include)
target_include_directories(${Target} PRIVATE ${SimpleKernel_SOURCE_CODE_DIR}/drv/opensbi/include)
target_include_directories(${Target} PRIVATE ${SimpleKernel_SOURCE_CODE_DIR}/drv/sbi_console/include)
target_include_directories(${Target} PRIVATE ${SimpleKernel_SOURCE_CODE_DIR}/drv/dtb/include)
target_include_directories(${Target} PRIVATE ${SimpleKernel_SOURCE_CODE_DIR}/drv/multiboot2/include)
target_include_directories(${Target} PRIVATE ${SimpleKernel_SOURCE_CODE_DIR}/drv/keyboard/include)
endfunction()
Binary file not shown.
Binary file added docs/RISC-V-Reader-Chinese-v2p1.pdf
Binary file not shown.
Binary file added docs/riscv-mmu.pdf
Binary file not shown.
Binary file added docs/riscv-spec-20191213.pdf
Binary file not shown.
Binary file added docs/sifive-interrupt-cookbook.pdf
Binary file not shown.
16 changes: 16 additions & 0 deletions src/arch/arm/boot/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

# This file is a part of Simple-XX/SimpleKernel (https://github.com/Simple-XX/SimpleKernel).
#
# CMakeLists.txt for Simple-XX/SimpleKernel.

PROJECT(boot C ASM)

find_asm_source_files(ASM_SOURCE_FILES ${boot_SOURCE_DIR})

set(boot_src ${ASM_SOURCE_FILES})

add_library(${PROJECT_NAME} OBJECT ${boot_src})

target_include_libc_header_files(${PROJECT_NAME})
target_include_drv_header_files(${PROJECT_NAME})
target_include_arch_header_files(${PROJECT_NAME})
16 changes: 15 additions & 1 deletion src/arch/ia32/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ if (${SimpleKernelArch} STREQUAL "ia32/i386")
find_asm_source_files(gdt_asm_src ${arch_SOURCE_DIR}/i386/gdt)
aux_source_directory(${arch_SOURCE_DIR}/i386/gdt gdt_cpp_src)
set(gdt_src ${gdt_asm_src} ${gdt_cpp_src})

find_asm_source_files(intr_asm_src ${arch_SOURCE_DIR}/i386/intr)
aux_source_directory(${arch_SOURCE_DIR}/i386/intr intr_cpp_src)
set(intr_src ${intr_asm_src} ${intr_cpp_src})


# 64 位
elseif (${SimpleKernelArch} STREQUAL "ia32/x86_64")
# 寻找汇编文件
Expand All @@ -29,15 +35,22 @@ elseif (${SimpleKernelArch} STREQUAL "ia32/x86_64")
find_asm_source_files(gdt_asm_src ${arch_SOURCE_DIR}/x86_64/gdt)
aux_source_directory(${arch_SOURCE_DIR}/x86_64/gdt gdt_cpp_src)
set(gdt_src ${gdt_asm_src} ${gdt_cpp_src})

find_asm_source_files(intr_asm_src ${arch_SOURCE_DIR}/x86_64/intr)
aux_source_directory(${arch_SOURCE_DIR}/x86_64/intr intr_cpp_src)
set(intr_src ${intr_asm_src} ${intr_cpp_src})
endif ()

# 寻找 CXX 文件
aux_source_directory(${arch_SOURCE_DIR}/port port_cpp_src)
# 添加到 port_src
set(port_src ${port_cpp_src})

aux_source_directory(${arch_SOURCE_DIR}/apic apic_cpp_src)
set(apic_src ${apic_cpp_src})

# 设置子模块所有的源码
set(arch_src ${boot_src} ${port_src} ${gdt_src})
set(arch_src ${boot_src} ${port_src} ${gdt_src} ${intr_src} ${apic_src})

# 添加子模块
add_library(${PROJECT_NAME} OBJECT ${arch_src})
Expand All @@ -46,3 +59,4 @@ add_library(${PROJECT_NAME} OBJECT ${arch_src})
target_include_arch_header_files(${PROJECT_NAME})
target_include_libc_header_files(${PROJECT_NAME})
target_include_common_header_files(${PROJECT_NAME})
target_include_drv_header_files(${PROJECT_NAME})
41 changes: 41 additions & 0 deletions src/arch/ia32/apic/apic.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

/**
* @file apic.cpp
* @brief APIC 抽象
* @author Zone.N ([email protected])
* @version 1.0
* @date 2021-09-18
* @copyright MIT LICENSE
* https://github.com/Simple-XX/SimpleKernel
* @par change log:
* <table>
* <tr><th>Date<th>Author<th>Description
* <tr><td>2021-09-18<td>digmouse233<td>迁移到 doxygen
* </table>
*/

#include "stdio.h"
#include "assert.h"
#include "intr.h"
#include "cpu.hpp"
#include "apic.h"

// 64-ia-32-architectures-software-developer-vol-3a-manual#10

/// @todo 完善,加入内核
APIC::APIC(void) {
return;
}

APIC::~APIC(void) {
return;
}

/// @see 64-ia-32-architectures-software-developer-vol-3a-manual#10.4.3

int32_t APIC::init(void) {
LOCAL_APIC::init();
IO_APIC::init();
printf("apic init.\n");
return 0;
}
60 changes: 60 additions & 0 deletions src/arch/ia32/apic/include/apic.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

/**
* @file apic.h
* @brief APIC 抽象头文件
* @author Zone.N ([email protected])
* @version 1.0
* @date 2021-09-18
* @copyright MIT LICENSE
* https://github.com/Simple-XX/SimpleKernel
* @par change log:
* <table>
* <tr><th>Date<th>Author<th>Description
* <tr><td>2021-09-18<td>digmouse233<td>迁移到 doxygen
* </table>
*/

#ifndef _APIC_H_
#define _APIC_H_

#include "stdint.h"

/**
* @brief APIC 抽象
*/
class APIC {
private:
protected:
public:
APIC(void);
~APIC(void);
static int32_t init(void);
};

/**
* @brief 本地 APIC
*/
class LOCAL_APIC {
private:
protected:
public:
LOCAL_APIC(void);
~LOCAL_APIC(void);
static int32_t init(void);
};

/**
* @brief IO APIC
*/
class IO_APIC {
private:
protected:
public:
IO_APIC(void);
~IO_APIC(void);
static int32_t init(void);
};

static APIC apic;

#endif /* _APIC_H_ */
35 changes: 35 additions & 0 deletions src/arch/ia32/apic/io_apic.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

/**
* @file io_apic.cpp
* @brief IOAPIC 抽象
* @author Zone.N ([email protected])
* @version 1.0
* @date 2021-09-18
* @copyright MIT LICENSE
* https://github.com/Simple-XX/SimpleKernel
* @par change log:
* <table>
* <tr><th>Date<th>Author<th>Description
* <tr><td>2021-09-18<td>digmouse233<td>迁移到 doxygen
* </table>
*/

#include "intr.h"
#include "cpu.hpp"
#include "io.h"
#include "apic.h"

/// @todo

IO_APIC::IO_APIC(void) {
return;
}

IO_APIC::~IO_APIC(void) {
return;
}

int32_t IO_APIC::init(void) {
printf("io apic init.\n");
return 0;
}
72 changes: 72 additions & 0 deletions src/arch/ia32/apic/local_apic.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@

/**
* @file loacl_apic.cpp
* @brief loacl APIC 抽象
* @author Zone.N ([email protected])
* @version 1.0
* @date 2021-09-18
* @copyright MIT LICENSE
* https://github.com/Simple-XX/SimpleKernel
* @par change log:
* <table>
* <tr><th>Date<th>Author<th>Description
* <tr><td>2021-09-18<td>digmouse233<td>迁移到 doxygen
* </table>
*/

#include "stdio.h"
#include "assert.h"
#include "intr.h"
#include "cpu.hpp"
#include "apic.h"

/// @see 64-ia-32-architectures-software-developer-vol-3a-manual#10

/// @todo 完善,加入内核
LOCAL_APIC::LOCAL_APIC(void) {
return;
}

LOCAL_APIC::~LOCAL_APIC(void) {
return;
}

/// @see 64-ia-32-architectures-software-developer-vol-3a-manual#10.4.3

int32_t LOCAL_APIC::init(void) {
// 先判断 cpu 是否支持
CPU::CPUID cpuid;
if (cpuid.xapic() == false) {
warn("Not support LOCAL_APIC&xAPIC.\n");
}
if (cpuid.x2apic() == false) {
warn("Not support x2APIC.\n");
}
uint64_t msr = CPU::READ_MSR(CPU::IA32_APIC_BASE);
// 开启 xAPIC 与 x2APIC
msr |= (CPU::IA32_APIC_BASE_GLOBAL_ENABLE_BIT |
CPU::IA32_APIC_BASE_X2APIC_ENABLE_BIT);
CPU::WRITE_MSR(CPU::IA32_APIC_BASE, msr);
// 设置 SIVR
msr = CPU::READ_MSR(CPU::IA32_X2APIC_SIVR);
if (cpuid.eoi() == true) {
msr |= CPU::IA32_X2APIC_SIVR_EOI_ENABLE_BIT;
}
msr |= CPU::IA32_X2APIC_SIVR_APIC_ENABLE_BIT;
CPU::WRITE_MSR(CPU::IA32_X2APIC_SIVR, msr);

// 屏蔽所有 LVT
msr = 0;
msr |= CPU::IA32_X2APIC_LVT_MASK_BIT;
msr = 0x10000;
CPU::WRITE_MSR(CPU::IA32_X2APIC_CMCI, msr);
CPU::WRITE_MSR(CPU::IA32_X2APIC_LVT_TIMER, msr);
CPU::WRITE_MSR(CPU::IA32_X2APIC_LVT_THERMAL, msr);
CPU::WRITE_MSR(CPU::IA32_X2APIC_LVT_PMI, msr);
CPU::WRITE_MSR(CPU::IA32_X2APIC_LVT_LINT0, msr);
CPU::WRITE_MSR(CPU::IA32_X2APIC_LVT_LINT1, msr);
CPU::WRITE_MSR(CPU::IA32_X2APIC_LVT_ERROR, msr);

printf("local apic init.\n");
return 0;
}
Loading

0 comments on commit a19f35d

Please sign in to comment.