Code Monkey home page Code Monkey logo

tiny-os's Introduction

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

tiny-os's People

Contributors

seaswalker avatar

Watchers

 avatar

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.