# 书籍-从零开始写Linux内核 -- 练习代码 **Repository Path**: theflyfish/Linux0.11-from-scratch-code ## Basic Information - **Project Name**: 书籍-从零开始写Linux内核 -- 练习代码 - **Description**: 《从零开始写Linux内核》第一版书籍的配套和练习代码,仅供学习使用 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-06-02 - **Last Updated**: 2025-06-16 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 书籍-从零开始写Linux内核 -- 练习代码 #### 介绍 《从零开始写Linux内核》第一版书籍的配套和练习代码,仅供学习使用 #### 《从零开始写Linux内核》 作者:海纳 机械工业出版社 2025年2月第1版第2次印刷 ISBN 978-7-111-76644-5 #### 编码环境和软件 1. 编译和链接环境:Linux操作系统
Ubuntu 24.04.1 LTS (GNU/Linux 6.8.0-51-generic x86_64)
gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
as: GNU assembler (GNU Binutils for Ubuntu) 2.42
ld: GNU ld (GNU Binutils for Ubuntu) 2.42
make: GNU Make 4.3
2. bochs运行环境:Windows 11 家庭版 3. bochs版本 Bochs-win64-3.0.exe 4. IDE: GVIM 9.1 #### 踩坑记录 ##### 硬盘驱动器号 ``` load_setup: movw $0x0000, %dx movw $0x0002, %cx movw $0x0200, %bx movb $SETUPLEN, %al movb $0x02, %ah int $0x13 ```
硬盘驱动器号正确是"80h",不是书中说的“07h”(参见Page 25:dl代表驱动器号,0代表软盘,7代表硬盘)。
如果从硬盘启动,正确的代码如下
``` load_setup: movw $0x0080, %dx movw $0x0002, %cx movw $0x0200, %bx movb $SETUPLEN, %al movb $0x02, %ah ``` ##### ldsw错误
Page 28中有如下代码
``` movw $0x0000, %ax movw %ax, %ds ldsw (4 * 0x41), %si movw $INITSEG, %ax movw %ax, %es movw $0x0080, %di movw $0x10, %cx rep movsb /* get hd1 data */ movw $0x0000, %ax movw %ax, %ds ldsw (4 * 0x46), %si movw $INITSEG, %ax movw %ax, %es movw $0x0090, %di movw $0x10, %cx rep movsb ``` 其中两处ldsw代码是错误的,ldsw会同时修改ds和si两个寄存器,把地址为(4 * 0x41)连续4个字节里面包含的内容赋值给ds和si。 正确写法如下,这个问题让我卡壳两天。 ``` movw $(4 * 0x41), %si movw $(4 * 0x46), %si ```