一个简单的操作系统内核,实现了简单的功能,如启动,线程/进程管理,内存管理,文件管理,输入输出,用户进程,系统调用等,总代码7k行左右。
sudo docker run --net=host -e DISPLAY=127.0.0.1:10.0 -v $HOME/.Xauthority:/root/.Xauthority:rw -v /tmp/.X11-unix:/tmp/.X11-unix linxin8/os /run_gui.sh
#include "disk/file_system.h"
#include "kernel/asm_interface.h"
#include "kernel/init.h"
#include "kernel/interrupt.h"
#include "kernel/keyboard.h"
#include "kernel/memory.h"
#include "kernel/timer.h"
#include "lib/debug.h"
#include "lib/macro.h"
#include "lib/new.h"
#include "lib/stdint.h"
#include "lib/stdio.h"
#include "lib/stdlib.h"
#include "process/process.h"
#include "thread/sync.h"
#include "thread/thread.h"
int main()
{
init_all();
printf("main pid %d\n", getpid());
Process::execute((void*)user_main, "u1");
Interrupt::enable();
while (true)
{
Thread::yield();
}
return 0;
}
void user_main(void* arg)
{
UNUSED(arg);
printf("\nuser process pid %d\n\n", getpid());
int32_t test = 0;
while (true)
{
char buffer[2];
int32_t fd[2];
if (pipe(fd) == -1)
{
printf("pip failed");
while (true) {}
}
auto pid = fork();
if (pid == 0)
{
test--;
printf("i am child %d, test addr: %x, value %d\n\n", getpid(), &test, test);
write(fd[1], "123456", 6);
printf("write ok\n");
while (true) {}
}
test++;
printf("i am parent %d, child %d, test addr: %x, value %d\n\n", getpid(), pid, &test, test);
while (true)
{
read(fd[0], buffer, 1);
printf("%c", buffer[0]);
}
while (true) {}
}
}
bochs
g++-10
nasm
ubuntu
sudo apt install nasm
sudo apt install -y g++ libx11-dev libxrandr-dev build-essential libgtk2.0-dev libreadline-dev libcanberra-gtk-module
wget https://sourceforge.net/projects/bochs/files/bochs/2.6.9/bochs-2.6.9.tar.gz/download
mv download bochs.tar
tar -xvf bochs.tar bochs-2.6.9/
cd bochs-2.6.9/
./configure --enable-debugger --with-x11 --enable-all-optimizations
make
sudo make install
sudo apt install g++-10
- 下载项目
- 进入项目目录
- 执行命令 make run
make 编译
make run 编译并运行
make rebuild 清理项目并重新编译