simple-xx / simplekernel Goto Github PK
View Code? Open in Web Editor NEWSimple kernel for learning operating systems. 用于学习操作系统的简单内核
License: MIT License
Simple kernel for learning operating systems. 用于学习操作系统的简单内核
License: MIT License
为内核提供 stl 支持
长期维护
生成 boot、内核 elf 文件
需要考虑不同平台的区分,使用最小编译参数
Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
Describe the solution you'd like
[Optional] A clear and concise description of what you want to happen.
Describe alternatives you've considered
[Optional] A clear and concise description of any alternative solutions or features you've considered.
Additional context
Add any other context or screenshots about the feature request here.
在 cmake 中定义相关信息,生成头文件以供在内核中使用
使用 cpu_hlt();
打印出来的 tick 数量有时候不够,很难复现
将第三方依赖、内核等编译生成的文件放到指定位置
正在生成内核... drv/mouse/mouse.o
x86_64-elf-ld: drv/console/console.o:/Users/zivyou/workspace/SimpleKernel/src/include/mem/pmm.h:126: multiple definition of mem_page'; drv/clock/clock.o:/Users/zivyou/workspace/SimpleKernel/src/include/mem/pmm.h:126: first defined here x86_64-elf-ld: drv/console/console.o:/Users/zivyou/workspace/SimpleKernel/src/include/mem/pmm.h:124: multiple definition of
mem_zone'; drv/clock/clock.o:/Users/zivyou/workspace/SimpleKernel/src/include/mem/pmm.h:124: first defined here
x86_64-elf-ld: drv/console/console.o:/Users/zivyou/workspace/SimpleKernel/src/include/multiboot2.h:352: multiple definition of `mmap_tag'; drv/clock/clock.o:/Users/zivyou/workspace/SimpleKernel/src/include/multiboot2.h:352: first defined here
......
OS: MacOS (Darwin 192.168.124.8 18.2.0 Darwin Kernel Version 18.2.0: Mon Nov 12 20:24:46 PST 2018; root:xnu-4903.231.4~2/RELEASE_X86_64 x86_64)
x86_64-elf-ld version:
x86_64-elf-ld --version
GNU ld (GNU Binutils) 2.35
Copyright (C) 2020 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later version.
This program has absolutely no warranty.
It seems like a GNU ld bug reported in some version. More details: https://stackoverflow.com/questions/15822700/ld-resolve-multiple-definition-manually
This ld error can be fixed by simply adding "-z muldefs" command line parameter in config file Makefile.env. At least it works for me.
长期问题,保证代码风格的一致性
CMake Error at cmake/toolchain_mac_x86_64.cmake:27 (message):
grub-file not found.
Use grub4mac.sh to install grub.
Call Stack (most recent call first):
/usr/local/Cellar/cmake/3.21.3_1/share/cmake/Modules/CMakeDetermineSystem.cmake:124 (include)
CMakeLists.txt:13 (project)
eflags寄存器信息与 bochs 显示的不同
自动下载并编译第三方依赖,自动生成相关 licence
预计要使用的第三方内容
第三方内容 | 描述 | 类型 |
---|---|---|
CPM | cmake 包管理 | cmake module |
CPMLicences.cmake | 为第三方包生成 licence | cmake module |
google/googletest | 测试 | 库 |
easylogingpp | 日志 | 库 |
rttr | c++ 反射库,在设备驱动部分用 | 库 |
Format.cmake | 代码格式化,支持 clang-format 与 cmake-format | cmake module |
FreeImage | 图片渲染 | 库 |
Freetype | 字体渲染 | 库 |
opensbi | riscv 引导 | 库 |
gnu-efi | gnu uefi 引导 | 库 |
posix-uefi | posix uefi 引导 | 库 |
ovmf | qemu 使用的 uefi 固件 | bin |
edk2 | 构建 qemu 使用的 uefi 固件 ovmf | 库 |
相比 gcc,clang 可以简单构造出交叉编译工具链,可以省去配置环境的麻烦。
在不同的 host 上编译不同的 target,支持以下组合
host | target | gcc | clang |
---|---|---|---|
x86_64-osx | x86_64 | x86_64_elf-gcc | TEST |
x86_64-osx | aarch64 | aarch64-unknown-linux-gnu-gcc | TEST |
x86_64-osx | riscv64 | riscv64-unknown-elf-gcc | TEST |
aarch64-osx | x86_64 | TODO | TODO |
aarch64-osx | aarch64 | TODO | TODO |
aarch64-osx | riscv64 | TODO | TODO |
x86_64-ubuntu | x86_64 | gcc | TEST |
x86_64-ubuntu | aarch64 | aarch64-linux-gnu-gcc | TEST |
x86_64-ubuntu | riscv64 | riscv64-linux-gnu-gcc | TEST |
aarch64-ubuntu | x86_64 | TODO | TEST |
aarch64-ubuntu | aarch64 | TODO | TEST |
aarch64-ubuntu | riscv64 | TODO | TEST |
riscv64-ubuntu | x86_64 | TODO | TODO |
riscv64-ubuntu | aarch64 | TODO | TODO |
riscv64-ubuntu | riscv64 | TODO | TODO |
host: 编译平台
target: 内核要运行的平台
gcc: 使用的 gcc 名称
clang: 使用的 clang 参数
TODO: 暂无测试条件
TEST: 需要进一步验证。
x86_64 平台下的 uefi 支持。
启动、ui、硬件信息处理。
我的系统是MacOS 12.6.5,我尝试用x86_64-elf-as -o boot.o boot.S
手动编译i386架构下的boot.S,给出的错误信息是:
但是使用提供的run.sh
脚本是可以正常编译运行的,我不太熟悉CMakeLists,查找了一下也没有找到可以编译成功的方法。如果将代码的#define ...
修改为.SET ...
倒是可以编译成功,但这样手动编译出来并不符合i386架构。
如果我想用这个boot.S
和一个kernel.c
写一个bare bone,请问要如何编译链接?
或者有什么方法可以让CMake输出所有编译和链接的指令吗?
Describe the bug
Can not find a grub-file. I am using Fedora Core 29, could you please tell where I can get the file or which package am I missing?
To Reproduce
Steps to reproduce the behavior:
./run.sh
which: no grub-file in (/home/shawn/.local/bin:/home/shawn/bin:/home/shawn/.nvm/versions/node/v13.14.0/bin:/home/shawn/.local/bin:/home/shawn/bin:/usr/share/Modules/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/var/lib/snapd/snap/bin)
dirname: missing operand
Try 'dirname --help' for more information.
Expected behavior
Should find the grub-file.
Describe the bug
退格键会影响到上一行;且会留下多余字符
To Reproduce
Steps to reproduce the behavior:
Expected behavior
应该没有多余的字符,且不应该影响上一行
Desktop (please complete the following information):
Env (please complete the following information):
Describe your question
运行 bash ./run.sh
之后
截图为:
输出内容为:
~/workspace/SimpleKernel
☺ bash ./run.sh main 4c86b9db
-- Found brew /opt/homebrew/bin/brew
-- Found riscv64-unknown-elf-gcc /opt/homebrew/bin/riscv64-unknown-elf-gcc.
-- Found qemu /opt/homebrew/bin/qemu-system-riscv64
-- Found brew /opt/homebrew/bin/brew
-- Found riscv64-unknown-elf-gcc /opt/homebrew/bin/riscv64-unknown-elf-gcc.
-- Found qemu /opt/homebrew/bin/qemu-system-riscv64
-- The CXX compiler identification is GNU 13.2.0
-- The ASM compiler identification is GNU
-- Found assembler: /opt/homebrew/bin/riscv64-unknown-elf-gcc
-- Checking whether CXX compiler has -isysroot
-- Checking whether CXX compiler has -isysroot - yes
-- Checking whether CXX compiler supports OSX deployment target flag
-- Checking whether CXX compiler supports OSX deployment target flag - no
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /opt/homebrew/bin/riscv64-unknown-elf-g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- SimpleKernelArch is riscv64
-- CMAKE_BUILD_TYPE is DEBUG
-- CMAKE_C_FLAGS is -march=rv64imafdc -Driscv64 -g -ggdb -O0 -ffreestanding -nostdlib -nostdinc -fexceptions -nostartfiles -fPIC -no-pie -Wall -Wextra -MMD
-- CMAKE_CXX_FLAGS is -march=rv64imafdc -Driscv64 -g -ggdb -O0 -ffreestanding -nostdlib -nostdinc -fexceptions -nostartfiles -fPIC -no-pie -Wall -Wextra -MMD
-- CMAKE_ASM_FLAGS is -march=rv64imafdc -Driscv64 -g -ggdb -O0 -ffreestanding -nostdlib -nostdinc -fexceptions -nostartfiles -fPIC -no-pie -Wall -Wextra -MMD
-- TOOLCHAIN_PREFIX is riscv64-unknown-elf-
-- CMAKE_OBJCOPY is /opt/homebrew/bin/riscv64-unknown-elf-objcopy
-- found asm files: /Users/cmz/workspace/SimpleKernel/src/arch/riscv64/boot/boot.S
-- found asm files: /Users/cmz/workspace/SimpleKernel/src/arch/riscv64/intr/intr_s.S
-- The C compiler identification is GNU 13.2.0
-- Checking whether C compiler has -isysroot
-- Checking whether C compiler has -isysroot - yes
-- Checking whether C compiler supports OSX deployment target flag
-- Checking whether C compiler supports OSX deployment target flag - no
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /opt/homebrew/bin/riscv64-unknown-elf-gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- found asm files: /Users/cmz/workspace/SimpleKernel/src/libcxx/src/__dso_handle.S
-- Configuring done (0.5s)
-- Generating done (0.0s)
-- Build files have been written to: /Users/cmz/workspace/SimpleKernel/build_riscv64
[ 3%] Building ASM object src/libcxx/CMakeFiles/libcxx.dir/src/__dso_handle.S.o
[ 6%] Building CXX object src/libcxx/CMakeFiles/libcxx.dir/src/cxxabi.cpp.o
[ 9%] Building CXX object src/libcxx/CMakeFiles/libcxx.dir/src/iostream.cpp.o
[ 12%] Building CXX object src/libcxx/CMakeFiles/libcxx.dir/src/new.cpp.o
[ 16%] Building CXX object src/libcxx/CMakeFiles/libcxx.dir/src/stack_chk.cpp.o
[ 16%] Built target libcxx
[ 19%] Building ASM object src/arch/riscv64/CMakeFiles/arch.dir/boot/boot.S.o
[ 22%] Building ASM object src/arch/riscv64/CMakeFiles/arch.dir/intr/intr_s.S.o
[ 25%] Building CXX object src/arch/riscv64/CMakeFiles/arch.dir/intr/clint.cpp.o
[ 29%] Building CXX object src/arch/riscv64/CMakeFiles/arch.dir/intr/intr.cpp.o
[ 32%] Building CXX object src/arch/riscv64/CMakeFiles/arch.dir/intr/page_fault.cpp.o
[ 35%] Building CXX object src/arch/riscv64/CMakeFiles/arch.dir/intr/plic.cpp.o
[ 38%] Building CXX object src/arch/riscv64/CMakeFiles/arch.dir/intr/timer.cpp.o
[ 38%] Built target arch
[ 41%] Building CXX object src/kernel/CMakeFiles/kernel.dir/allocator.cpp.o
[ 45%] Building CXX object src/kernel/CMakeFiles/kernel.dir/firstfit.cpp.o
[ 48%] Building CXX object src/kernel/CMakeFiles/kernel.dir/heap.cpp.o
[ 51%] Building CXX object src/kernel/CMakeFiles/kernel.dir/io.cpp.o
[ 54%] Building CXX object src/kernel/CMakeFiles/kernel.dir/kernel_main.cpp.o
[ 58%] Building CXX object src/kernel/CMakeFiles/kernel.dir/pmm.cpp.o
[ 61%] Building CXX object src/kernel/CMakeFiles/kernel.dir/slab.cpp.o
[ 64%] Building CXX object src/kernel/CMakeFiles/kernel.dir/test.cpp.o
[ 67%] Building CXX object src/kernel/CMakeFiles/kernel.dir/vmm.cpp.o
[ 67%] Built target kernel
[ 70%] Building CXX object src/drv/CMakeFiles/drv.dir/opensbi/opensbi.cpp.o
[ 74%] Building CXX object src/drv/CMakeFiles/drv.dir/sbi_console/sbi_console.cpp.o
[ 77%] Building CXX object src/drv/CMakeFiles/drv.dir/dtb/dtb.cpp.o
[ 77%] Built target drv
[ 80%] Building C object src/libc/CMakeFiles/libc.dir/src/stdio/vsprintf.c.o
[ 83%] Building C object src/libc/CMakeFiles/libc.dir/src/stdlib/atoi.c.o
[ 87%] Building C object src/libc/CMakeFiles/libc.dir/src/stdlib/itoa.c.o
[ 90%] Building C object src/libc/CMakeFiles/libc.dir/src/stdlib/strtol.c.o
[ 93%] Building C object src/libc/CMakeFiles/libc.dir/src/string/string.c.o
[ 96%] Building C object src/libc/CMakeFiles/libc.dir/src/math/math.c.o
[ 96%] Built target libc
[100%] Linking CXX executable ../bin/kernel.elf
/opt/homebrew/Cellar/riscv-gnu-toolchain/main/lib/gcc/riscv64-unknown-elf/13.2.0/../../../../riscv64-unknown-elf/bin/ld: warning: ../bin/kernel.elf has a LOAD segment with RWX permissions
Generating kernel debug...
Generating raw kernel...
nm...
readelf...
Disassembling...
[100%] Built target kernel.elf
OpenSBI v1.2
____ _____ ____ _____
/ __ \ / ____| _ \_ _|
| | | |_ __ ___ _ __ | (___ | |_) || |
| | | | '_ \ / _ \ '_ \ \___ \| _ < | |
| |__| | |_) | __/ | | |____) | |_) || |_
\____/| .__/ \___|_| |_|_____/|____/_____|
| |
|_|
Platform Name : riscv-virtio,qemu
Platform Features : medeleg
Platform HART Count : 1
Platform IPI Device : aclint-mswi
Platform Timer Device : aclint-mtimer @ 10000000Hz
Platform Console Device : uart8250
Platform HSM Device : ---
Platform PMU Device : ---
Platform Reboot Device : sifive_test
Platform Shutdown Device : sifive_test
Firmware Base : 0x80000000
Firmware Size : 200 KB
Runtime SBI Version : 1.0
Domain0 Name : root
Domain0 Boot HART : 0
Domain0 HARTs : 0*
Domain0 Region00 : 0x0000000002000000-0x000000000200ffff (I)
Domain0 Region01 : 0x0000000080000000-0x000000008003ffff ()
Domain0 Region02 : 0x0000000000000000-0xffffffffffffffff (R,W,X)
Domain0 Next Address : 0x0000000080200000
Domain0 Next Arg1 : 0x0000000082200000
Domain0 Next Mode : S-mode
Domain0 SysReset : yes
Boot HART ID : 0
Boot HART Domain : root
Boot HART Priv Version : v1.12
Boot HART Base ISA : rv64imafdch
Boot HART ISA Extensions : time,sstc
Boot HART PMP Count : 16
Boot HART PMP Granularity : 4
Boot HART PMP Address Bits: 54
Boot HART MHPM Count : 16
Boot HART MIDELEG : 0x0000000000001666
Boot HART MEDELEG : 0x0000000000f0b509
sbi console init.
BOOT_INFO init.
First Fit Allocator(kernel space): 0x0000000080200000(0x800 pages) init.
First Fit Allocator: 0x0000000080A00000(0x7800 pages) init.
BOOT_INFO reinit.
pmm init.
pmm test done.
paging enabled.
vmm init.
vmm test done.
SLAB Allocator Kernel: 0x0000000080200000(0x0000000800000000 bytes) init.
SLAB Allocator: 0x0000000080A00000(0x0000007800000000 bytes) init.
heap init.
heap test done.
clint init.
plic init.
intr init.
sepc: 0x000000008021D4BC, stval: 0x00000000C0000000, scause: 0x000000000000000D, all_regs(sp): 0x000000008020FD98, sie: 0x0000000000000202
sstatus: val: 0x8000000200006100, sie: disable, spie: disable, spp: S mode,
satp: val: 0x800000000008023E, ppn: 0x000000000008023E, asid: 0x0000000000000000, mode: SV39,
sscratch: 0x0000000000000000
pg_load_excp done: 0x00000000C0000000.
sepc: 0x000000008021D4F2, stval: 0x00000000C0000000, scause: 0x000000000000000F, all_regs(sp): 0x000000008020FD98, sie: 0x0000000000000202
sstatus: val: 0x8000000200006100, sie: disable, spie: disable, spp: S mode,
satp: val: 0x800000000008023E, ppn: 0x000000000008023E, asid: 0x0000000000000000, mode: SV39,
sscratch: 0x0000000000000000
pg_store_excp done: 0x00000000C0000000.
intr test done.
timer init.
sepc: 0x000000008021B138, stval: 0x0000000000000000, scause: 0x8000000000000005, all_regs(sp): 0x000000008020FD78, sie: 0x0000000000000222
sstatus: val: 0x8000000200006120, sie: disable, spie: enable, spp: S mode,
satp: val: 0x800000000008023E, ppn: 0x000000000008023E, asid: 0x0000000000000000, mode: SV39,
sscratch: 0x0000000000000000
Kernel start: 0x0000000080200000, end 0x000000008023BA00, size: 0x3BA00 bytes, 0x3C pages.
Kernel start4k: 0x0000000080200000, end4k: 0x000000008023C000.
Simple Kernel.
sepc: 0x000000008021B1D6, stval: 0x0000000000000000, scause: 0x8000000000000005, all_regs(sp): 0x000000008020FDB8, sie: 0x0000000000000222
sstatus: val: 0x8000000200006120, sie: disable, spie: enable, spp: S mode,
satp: val: 0x800000000008023E, ppn: 0x000000000008023E, asid: 0x0000000000000000, mode: SV39,
sscratch: 0x0000000000000000
sepc: 0x000000008021B1D6, stval: 0x0000000000000000, scause: 0x8000000000000005, all_regs(sp): 0x000000008020FDB8, sie: 0x0000000000000222
sstatus: val: 0x8000000200006120, sie: disable, spie: enable, spp: S mode,
satp: val: 0x800000000008023E, ppn: 0x000000000008023E, asid: 0x0000000000000000, mode: SV39,
sscratch: 0x0000000000000000
sepc: 0x000000008021B1D6, stval: 0x0000000000000000, scause: 0x8000000000000005, all_regs(sp): 0x000000008020FDB8, sie: 0x0000000000000222
sstatus: val: 0x8000000200006120, sie: disable, spie: enable, spp: S mode,
satp: val: 0x800000000008023E, ppn: 0x000000000008023E, asid: 0x0000000000000000, mode: SV39,
sscratch: 0x0000000000000000
sepc: 0x000000008021B1D6, stval: 0x0000000000000000, scause: 0x8000000000000005, all_regs(sp): 0x000000008020FDB8, sie: 0x0000000000000222
sstatus: val: 0x8000000200006120, sie: disable, spie: enable, spp: S mode,
satp: val: 0x800000000008023E, ppn: 0x000000000008023E, asid: 0x0000000000000000, mode: SV39,
sscratch: 0x0000000000000000
sepc: 0x000000008021B1D6, stval: 0x0000000000000000, scause: 0x8000000000000005, all_regs(sp): 0x000000008020FDB8, sie: 0x0000000000000222
sstatus: val: 0x8000000200006120, sie: disable, spie: enable, spp: S mode,
satp: val: 0x800000000008023E, ppn: 0x000000000008023E, asid: 0x0000000000000000, mode: SV39,
sscratch: 0x0000000000000000
sepc: 0x000000008021B1D6, stval: 0x0000000000000000, scause: 0x8000000000000005, all_regs(sp): 0x000000008020FDB8, sie: 0x0000000000000222
sstatus: val: 0x8000000200006120, sie: disable, spie: enable, spp: S mode,
satp: val: 0x800000000008023E, ppn: 0x000000000008023E, asid: 0x0000000000000000, mode: SV39,
sscratch: 0x0000000000000000
sepc: 0x000000008021B1D6, stval: 0x0000000000000000, scause: 0x8000000000000005, all_regs(sp): 0x000000008020FDB8, sie: 0x0000000000000222
sstatus: val: 0x8000000200006120, sie: disable, spie: enable, spp: S mode,
satp: val: 0x800000000008023E, ppn: 0x000000000008023E, asid: 0x0000000000000000, mode: SV39,
sscratch: 0x0000000000000000
sepc: 0x000000008021B1D6, stval: 0x0000000000000000, scause: 0x8000000000000005, all_regs(sp): 0x000000008020FDB8, sie: 0x0000000000000222
sstatus: val: 0x8000000200006120, sie: disable, spie: enable, spp: S mode,
satp: val: 0x800000000008023E, ppn: 0x000000000008023E, asid: 0x0000000000000000, mode: SV39,
sscratch: 0x0000000000000000
sepc: 0x000000008021B1D6, stval: 0x0000000000000000, scause: 0x8000000000000005, all_regs(sp): 0x000000008020FDB8, sie: 0x0000000000000222
sstatus: val: 0x8000000200006120, sie: disable, spie: enable, spp: S mode,
satp: val: 0x800000000008023E, ppn: 0x000000000008023E, asid: 0x0000000000000000, mode: SV39,
sscratch: 0x0000000000000000
sepc: 0x000000008021B1D6, stval: 0x0000000000000000, scause: 0x8000000000000005, all_regs(sp): 0x000000008020FDB8, sie: 0x0000000000000222
sstatus: val: 0x8000000200006120, sie: disable, spie: enable, spp: S mode,
satp: val: 0x800000000008023E, ppn: 0x000000000008023E, asid: 0x0000000000000000, mode: SV39,
sscratch: 0x0000000000000000
sepc: 0x000000008021B1D6, stval: 0x0000000000000000, scause: 0x8000000000000005, all_regs(sp): 0x00
这看起来和 README 里面的图片不太一样:
dockerfile
Describe the bug
一行写满时不能自动换行
To Reproduce
Steps to reproduce the behavior:
Expected behavior
一行写满时应自动从下一行开始继续
Desktop (please complete the following information):
支持 github action,codecov 等
Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
Describe the solution you'd like
[Optional] A clear and concise description of what you want to happen.
Describe alternatives you've considered
[Optional] A clear and concise description of any alternative solutions or features you've considered.
Additional context
Add any other context or screenshots about the feature request here.
内核测试比较麻烦,需要先设计出测试框架
Describe the bug
使用回车、tab时会显示多余的白点
To Reproduce
Steps to reproduce the behavior:
Expected behavior
因该没有多余的东西出现
Desktop (please complete the following information):
setup.sh倒数第五行报错
cp: 无法创建普通文件'./boot_folder/boot/': 不是目录
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.