Day1:获取并运行 Linux0.11
参考资料:https://zhuanlan.zhihu.com/p/438577225
这是我参考的一个别人写的 Linux0.11 解读:https://github.com/dibingfa/flash-linux0.11-talk
我获取 Linux-0.11 源码的链接:https://github.com/Wangzhike/HIT-Linux-0.11.git
先运行
sudo dpkg --add-architecture i386
加入i386架构兼容
这个在后面./run的时候可能有些包要32位的。
在 ubuntu 20.04 下,从参考资料 “安装 Linux 0.11” 那里开始往下看,即可成功运行 Linux 0.11
我在新电脑上编译 Linux0.11时,发现会报错,如下
原因是主机上缺少 i386 的 libc,使用如下命令安装
sudo apt install linux-libc-dev:i386
接着继续编译 Linux0.11 即可
如果之前已经运行过,那么再次运行的方式是
cd ~/oslab
./run
运行 ./rungdb 会报错,如下:
./gdb: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
使用 sudo apt install libncurses5 会发现该包已经安装
实际上,我们需要安装的是 i386 架构的 libncurses5,使用如下命令安装
sudo apt install libncurses5:i386
再次运行,报错信息变了:
/gdb: error while loading shared libraries: libexpat.so.1: cannot open shared object file: No such file or directory
接着使用 sudo apt-file find libname 和 sudo apt install libname:i386 组合拳,把所有共享库安装好即可
可以启动 ./rungdb 程序了,但是感觉并不能进行源码级调试
=================== 上面的内容放弃掉,我们不折腾 bochs =================
谷歌搜索 “如何调试 linux0.11”,发现如下网页
https://www.cnblogs.com/chaoguo1234/p/16883932.html
使用如下命令,可知 ubuntu20.04 上已有了 qemu-system-i386,版本 7.2.91
在这里 clone linux0.11 的源码:https://github.com/yuan-xy/Linux-0.11
clone 后,运行 make start,出现如下错误:
修改 Makefile,把 qemu-system-x86_64 改成 i386,运行如下命令
make
make start
成功启动 Linux 0.11
接着运行 make debug,qemu 会在启动后停住
此时在另外一个窗口运行 gdb,使用 target remote localhost:1234 即可连接 qemu 进行调试
但是,此时由于没有读入符号表,我们只能看到汇编指令
使用 gdb tools/system 启动
随后键入
target remote localhost:1234
b main
c
即可进行源码级调试