All Projects → seaswalker → Tiny Os

seaswalker / Tiny Os

《操作系统真象还原》一书实现的系统代码

Programming Languages

c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to Tiny Os

Workshops
Stars: ✭ 47 (-58.04%)
Mutual labels:  learning-by-doing, operating-system
ArvernOS
💾 A minimal, experimental and "toy" monolithic kernel to learn about OS development // Work In Progress
Stars: ✭ 313 (+179.46%)
Mutual labels:  operating-system, learning-by-doing
Computer Science Resources
A list of resources in different fields of Computer Science (multiple languages)
Stars: ✭ 1,316 (+1075%)
Mutual labels:  operating-system
Papers Notebook
📄 🇨🇳 📃 论文阅读笔记(分布式系统、虚拟化、机器学习)Papers Notebook (Distributed System, Virtualization, Machine Learning), created by @gaocegege
Stars: ✭ 1,678 (+1398.21%)
Mutual labels:  operating-system
Rcore Tutorial Book V3
v3.5 https://rcore-os.github.io/rCore-Tutorial-Book-v3/
Stars: ✭ 102 (-8.93%)
Mutual labels:  operating-system
Tutorials
All of the code for my Medium articles
Stars: ✭ 92 (-17.86%)
Mutual labels:  learning-by-doing
Puredarwin
Darwin is the Open Source core of macOS, and PureDarwin is a community project to extend Darwin into a complete, usable operating system.
Stars: ✭ 1,592 (+1321.43%)
Mutual labels:  operating-system
Reactos
A free Windows-compatible Operating System
Stars: ✭ 10,216 (+9021.43%)
Mutual labels:  operating-system
Snakeware
A free Linux distro with a Python-based userspace
Stars: ✭ 1,514 (+1251.79%)
Mutual labels:  operating-system
Java8 Guides Tutorials
Java 8 Guides and Tutorials - A lot of awesome examples using Java 8 features like Stream, Lambda, Functional Interface, Date and Time API and much more
Stars: ✭ 100 (-10.71%)
Mutual labels:  learning-by-doing
Jingos
JingOS - The World’s First Linux-based OS design for Tablets
Stars: ✭ 101 (-9.82%)
Mutual labels:  operating-system
Axel
Operating System
Stars: ✭ 96 (-14.29%)
Mutual labels:  operating-system
It Starts With Clojure
a Practical guide to Clojure
Stars: ✭ 93 (-16.96%)
Mutual labels:  learning-by-doing
Minios
Simple DIY OS
Stars: ✭ 106 (-5.36%)
Mutual labels:  operating-system
Ultra Club
《Taro 多端小程序开发大型实战》源代码
Stars: ✭ 93 (-16.96%)
Mutual labels:  learning-by-doing
Learn Heroku
🏁 Learn how to deploy your web application to Heroku from scratch step-by-step in 7 minutes!
Stars: ✭ 110 (-1.79%)
Mutual labels:  learning-by-doing
Selectstarsql
An interactive SQL book
Stars: ✭ 92 (-17.86%)
Mutual labels:  learning-by-doing
Boneos
💥 BoneOS Kernel and Operating System Source Tree
Stars: ✭ 96 (-14.29%)
Mutual labels:  operating-system
Balena Os
The central place for all things BalenaOS related.
Stars: ✭ 104 (-7.14%)
Mutual labels:  operating-system
Aura Operating System
AuraOS, the Franco-English Operating System developed in C# using Cosmos!
Stars: ✭ 111 (-0.89%)
Mutual labels:  operating-system

tiny-os

环境准备

Bochs

在Mac上使用以下命令安装:

brew install bochs

配置

每个章节下的bios配置部分应视bochs的具体版本而定,可自行修改:

# 对应真实机器的bios
romimage: file=/usr/local/Cellar/bochs/2.6.9_2/share/bochs/BIOS-bochs-latest
# 对应真实机器的VGA bios
vgaromimage: file=/usr/local/Cellar/bochs/2.6.9_2/share/bochs/VGABIOS-lgpl-latest

说明

每个章节下的代码均可以独立运行,在对应的目录下执行以下命令即可启动:

./build.sh

即可启动执行。完毕之后可执行以下命令清理环境:

./clean.sh

运行

第三章

结果

第四章

结果

有以下几点需要注意:

  1. 书中的源码boot.inc的DESC_LIMIT_VIDEO2定义可能有误,应修改为:

    DESC_LIMIT_VIDEO2 equ 00000000000000000000000000001011b
    

    原因是保护模式的基地址是0xb8000,所以最后8位应该是b,而不是0,这样才能正确显示字母'P'。

    第164页的图4-11同样有问题,第4个GDT表项(显存)的base应该等于0xb8000,因为如果是图中的0xc00b8000,那么对应的物理内存地址是3072MB处,明显不合理。

  2. Mac上的nasm并不支持数字中间以下划线分割的写法,会出现编译错误。

  3. 第161页代码4-3的21行为:

    times 60 dq 0
    

    Apple版本的nasm这样写会报错,原因是不能把int型的0赋给dq。稍加变通即可:

    times 120 dd 0
    

第五章

内存检测

这里对书中源码进行了改造,只使用e820一种方式,检测失败时会在第一行显示字符串: 'failed',成功将在第二行显示: 'done',如下图:

内存检测结果

内存检测的结果通过命令: x /4wx 0xb00查看,如下图:

检测结果

结果正是我们设置的内存大小: 32MB,无误。

内存分页

内存分页结果

这一节注意要和前面的保护模式、内存检测部分结合起来。

加载内核

由于此时没有可以用于打印的手段,所以正确性需要到下一章节验证。此部分需要使用Linux交叉编译器中的ld命令才可以正常链接,Mac自带的无法使用,Mac上的安装参考:

11-kernel-crosscompiler

第六章

打印字符串

打印字符

这里是打印字符和打印字符串两者结合的效果,这里遇到了一个奇怪的问题,如果在main.c中存在除main之外的其它函数,那么实验结果将不正确,原因未知。

打印数字

打印数字

第七章

ASM

汇编中断实现

改进

改进

Timer

timer

实验中的中断号与书中不同。

第八章

Assert

Assert

注意, 在64位Linux系统上编译时有几点需要注意:

  • GCC加上参数:

    -m32 -fno-stack-protector
    
  • LD增加参数:

    -m elf_i386
    
  • 在Ubuntu上使用apt安装的bximage版本较老, 创建镜像的命令为:

    bximage -hd -mode=flat -size=10 -q disk.img
    

内存池

内存池

内存分配

内存分配

注:上一节中内存池初始化代码有一个bug:用户内存池其实地址应该是0xc009a1e0,已在此节修正。

第九章

线程启动

线程启动

线程调度

线程调度

这部分两次上下文切换的过程较难理解,整理成如下的时序图:

时序图

注意:

  • 如果被调度线程是第一次执行,那么转到线程对应的函数
  • 如果不是第一次被调度,那么走时序图的下半部分,原因是switch_to中保存的起始地址其实是此函数的返回地址
  • 虚线流程由第二次调度触发

第十章

锁

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].