harib09c的编译和调试

今天是《30天自制操作系统》学习的第12天,今天的工程目录是harib09c,我起的目录名称是day12_boyC,我们一起来调试一下。
day12_boyC目录下直接运行make命令就开始编译了,如下图所示:
harib09c的编译和调试_第1张图片
编译的结果如下(部分截取):

E:\techdoc\30dayOS\code\tolset\day12_boyC>make

E:\techdoc\30dayOS\code\tolset\day12_boyC>..\z_tools\make.exe
../z_tools/make.exe -r img
make.exe[1]: Entering directory `E:/techdoc/30dayOS/code/tolset/day12_boyC'
......
//部分正常结果省略
......
../z_tools/gas2nask.exe -a sheet.gas sheet.nas
../z_tools/nask.exe sheet.nas sheet.obj sheet.lst
../z_tools/cc1.exe -I../z_tools/haribote/ -Os -Wall -quiet -o timer.gas timer.c
timer.c: In function `inthandler20':
timer.c:22: structure has no member named `out'
timer.c:24: warning: passing arg 1 of `fifo8_put' from incompatible pointer type
timer.c: At top level:
timer.c:30: warning: `struct FIFO08' declared inside parameter list
timer.c:30: warning: its scope is only this definition or declaration, which is probably not what you want
timer.c: In function `settimer':
timer.c:35: warning: assignment from incompatible pointer type
make.exe[2]: *** [timer.gas] Error 1
rm graphic.gas graphic.nas dsctbl.gas dsctbl.nas memory.gas memory.nas sheet.gas sheet.nas mouse.gas mouse.nas timer.gas bootpack.gas int.gas fifo.gas int.nas fifo.nas keyboard.gas keyboard.nas
make.exe[2]: Leaving directory `E:/techdoc/30dayOS/code/tolset/day12_boyC'
make.exe[1]: *** [img] Error 2
make.exe[1]: Leaving directory `E:/techdoc/30dayOS/code/tolset/day12_boyC'
..\z_tools\make.exe: *** [default] Error 2

E:\techdoc\30dayOS\code\tolset\day12_boyC>

有一些错误发生,我们仔细查看一下:

timer.c:22: structure has no member named `out'

上面的提示是说:timer.c文件的第22行,结构体没有名称是out的成员。
打开timer.c文件,查看第22行的代码:

	if(timerctl.timeout > 0){
		timerctl.out--;
		if(timerctl.timeout <= 0 ){
			fifo8_put(timerctl.fifo, timerctl.data);
		}
	}

原来是结构体成员写错了,把out修改成timeout就好了。
harib09c的编译和调试_第2张图片
再把后面提示的错误逐一修改过来,重新编译,报错都消失了,如下图所示:
harib09c的编译和调试_第3张图片

【友情提醒】有的时候报错比较多,其实好些都是前面某个错误的连带错误,把前面的错误改掉了,后面的一些错误提示就自动消失了。所以,从前到后,逐一改错,随时编译,是个不错的调试方法。

使用make run命令,运行day12_boyC正常,10秒过后,qemu模拟器的屏幕上出现了"10[sec]"提示信息。运行结果如下图所示:
harib09c的编译和调试_第4张图片
【最后说一下】day12_boyC初次运行时,并没有出现"10[sec]"提示信息,经过仔细比对光盘代码,发现是我的代码出了问题。敲(抄)代码的过程中多注意细节,川合秀实老师在《30天自制操作系统》一书中把代码差异列举的还是比较详尽,运行结果和书中不一样的话,记得及时去比对代码,光盘中每一天学习目录中的代码是最完善的。
错误代码:

E:\techdoc\30dayOS\code\tolset\day12_boyC\bootpack.c
		//没有做timerfifo的状态判断,所以运行不正确。
		if(fifo8_status(&keyfifo) + fifo8_status(&mousefifo) == 0){
			io_sti();//不做hlt
		}

正确代码:

		if(fifo8_status(&keyfifo) + fifo8_status(&mousefifo) + fifo8_status(&timerfifo) == 0){ 
			io_sti();//不做hlt
		}else{

(全文完)

你可能感兴趣的:(C,vim,C语言调试,《30天自制操作系统》)