手贱更新了全部东西,然后用最新gcc编译后发现项目运行不了了
错误表现为mov byte ptr es:[edi],al这一行无法继续运行
尝试从原版文件运行,发现是可行的。
然后尝试怀疑boot或loader问题,但是拖了能运行的kernel到img中是可运行的,排除
用bochs断点单步,发现elf拷贝内存时出错,尝试用readelf给出的信息和调试信息做对比
单步调试时发现前三个程序头无错,但是第四个就不行了,分析VirtAddr
0x80480f4=134512884(10)byte=128.2815mb
但是默认的bochsrc中配置的内存大小为32mb,显然越界了
重新配置内存大小就可以解决
但是这样做会和原先设计的内存分布有冲突,需要解决为什么elf会分配到128的位置
因为于老师的教程出得很早了,所以有些配置还是需要修改的,除了上面说的内存
最新的bochs也不能运行,因为相关联的文件存储地址变化了,不再是
romimage: file=/usr/share/bochs/BIOS-bochs-latest
vgaromimage: file=/usr/share/vgabios/vgabios.bin
keyboard_mapping: enabled=1, map=/usr/share/bochs/keymaps/x11-pc-us.map
可以直接#屏蔽或者使用标准写法
romimage: file=$BXSHARE/BIOS-bochs-latest
vgaromimage: file=$BXSHARE/VGABIOS-lgpl-latest
keyboard_mapping: enabled=1, map=gui/keymaps/x11-pc-de.map
另外Makefile中的CFLAGS和LDFLAGS分别添加
-m32 -fno-stack-protector
-m elf_i386
看了下elf文件越界位置的内容,发现只是一些版本说明的东西,没什么用?
对比原先正常的elf文件
现在唯一知道的是最新的ld在elf里添加了新的段.not.gnu.property,而根据ld手册上说的
确实-Ttext无法管到.not.gnu.property它们的位置,所以导致了越界
看了下于老师的内存分布,决定把这个多出来的段放在kernel.bin加载位置的最后这个地方
最后编译运行,问题解决