Git Product home page Git Product logo

hariboteos's Introduction

HariboteOS

《30天自制操作系统》(川合秀实 著)配套代码改编版。因为作者使用了其自己编写的一套非标准的工具,且无法在非Windows平台下运行,所以本项目在原代码的基础上使用NASM、GCC、Qemu等工具进行编译、运行。

本项目已完成第0~28天内容(除去第28天日文显示部分),项目主要实现已经完成。因为该书后两章内容更偏向于应用层面,所以便不在本项目中实现,有兴趣的朋友可以根据前面的基础上继续完成。

项目特色

  • 采用GCC、NASM作为工具链,可跨平台使用
  • 基于LinkerScript构建内核
  • 不依赖于作者自定义HRB文件格式,支持ELF文件格式
  • 支持部分C标准库函数的简单实现(libc文件)
  • 头文件拆分,结构更为清晰
  • 中文键盘支持

环境依赖

  • nasm
  • gcc
  • binutils
  • qemu-system-i386
  • mtools

可选依赖

  • gdb(调试使用)

Mac下安装

MacOS下默认Xcode Command Line Tools使用的gcc为clang的别名,在本项目实现中未对clang进行测试,可能会存在问题。

在Mac下推荐使用x86_64-elf-gcc工具链进行编译,可使用brew install x86_64-elf-gcc x86_64-elf-binutils x86_64-elf-gdb安装。

运行

进入对应的文件夹,使用下面的命令运行:

$ make qemu
# 若使用工具链包含前缀,如x86_64-elf-,可以使用GCCPREFIX
$ make qemu GCCPREFIX=x86_64-elf-

若要使用GDB进行调试,请设置DEBUG

$ make qemu DEBUG=1

最终目录结构

  • app:应用程序源码
  • include:系统内核头文件
  • kernel:系统内核代码
  • libc:简单的C标准库部分实现

C标准库实现

  • strcmp
  • strncmp

参考自xv6实现:

  • vsprintf
  • sprintf

来自《C程序设计语言》:

  • rand

项目进度

  • 第1天:Hello world
  • 第2天:汇编与Makefile
  • 第3天:进入32位模式
  • 第4天:画面显示
  • 第5天:GDT/IDT
  • 第6天:中断处理
  • 第7天:FIFO
  • 第8天:鼠标与32位模式
  • 第9天:内存管理
  • 第10天:窗口叠加
  • 第11天:窗口处理
  • 第12天:定时器1
  • 第13天:定时器2
  • 第14天:键盘输入
  • 第15天:多任务1
  • 第16天:多任务2
  • 第17天:命令行窗口
  • 第18天:命令行命令
  • 第19天:应用程序
  • 第20天:API
  • 第21天:保护操作系统
  • 第22天:C语言应用程序(修改为ELF格式)
  • 第23天:应用程序图形处理
  • 第24天:窗口操作
  • 第25天:更多窗口
  • 第26天:窗口操作提速
  • 第27天:LDT与库(未按书上处理)
  • 第28天:文件操作与文字显示(不包含日文显示部分)

本项目不继续添加第29天以及第30天的内容,有兴趣的朋友可继续阅读后续章节。

待解决问题

  • 定时器执行若使用io_sti而非io_stihlt时会卡死
  • 启动时偶尔黑屏,无法正常绘制界面
  • 多个命令行同时执行命令时会卡死
  • 第28天中__alloca无效,sosu2无法运行

博客文章

版权信息

项目中代码版权主要归原书作者所有,本人仅针对无法直接运行的部分对该代码作出部分修改。

hariboteos's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

hariboteos's Issues

大佬有点问题想问

大佬您好!我的机器是mac的m系列芯片,在运行您的day7的代码的时候make qemu出现闪退问题,前几天都没有出现过这种问题,但是从day7往后一部分的day的项目都出现了闪退问题,还麻烦您可以不吝赐教,非常感谢🙏!!!

a.c:(.text+0x16): undefined reference to `_GLOBAL_OFFSET_TABLE_'

推进到21天时,有这个错误
gcc 版本 gcc version 11.4.0 (Ubuntu 11.4.0-1ubuntu1~22.04)

gcc -Wall -Wno-format -Wno-unused -std=gnu99 -static -m32 -I ./include -I ../libc/include -ffunction-sections -nostdlib -nostdinc -fno-builtin -ffreestanding -fno-pie -c fs.c -o fs.bin
gcc -Wall -Wno-format -Wno-unused -std=gnu99 -static -m32 -I ./include -I ../libc/include -ffunction-sections -nostdlib -nostdinc -fno-builtin -ffreestanding -fno-pie -c command.c -o command.bin
gcc -Wall -Wno-format -Wno-unused -std=gnu99 -static -m32 -I ./include -I ../libc/include -ffunction-sections -nostdlib -nostdinc -fno-builtin -ffreestanding -fno-pie -c api.c -o api.bin
nasm -f elf api_asm.asm -o api_asm.bin -l api_asm.lst
nasm -f elf app.asm -o app.bin -l app.lst
nasm -f bin app/hello.asm -o app/hello.hrb -l app/hello.lst
nasm -f bin app/hello2.asm -o app/hello2.hrb -l app/hello2.lst
nasm -f elf app/a_asm.asm -o app/a_asm.o
gcc -Wall -Wno-format -Wno-unused -std=gnu99 -m32 -c app/a.c -o app/a.o
ld -m elf_i386 --oformat binary -e main app/a.o app/a_asm.o -o app/a.hrb
ld: app/a.o: in function main': a.c:(.text+0x16): undefined reference to GLOBAL_OFFSET_TABLE'
make: *** [Makefile:63: app/a.hrb] Error 1

#include <stdio.h> 编译报错

在day 5的时候,我看您加了lib。但是我在编译stdio.c的时候会报这样的错误

x86_64-elf-gcc -Wall -m32 -fno-pie stdio.c stdio.bin
stdio.c:2:10: fatal error: stdio.h: No such file or directory
2 | #include <stdio.h>
| ^~~~~~~~~
compilation terminated.

查了一下因为x86_64-elf-gcc 并不支持 stdio.h 请问您是如何解决的

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.