• harib09c的编译和调试


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

    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>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27

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

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

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

    	if(timerctl.timeout > 0){
    		timerctl.out--;
    		if(timerctl.timeout <= 0 ){
    			fifo8_put(timerctl.fifo, timerctl.data);
    		}
    	}
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    原来是结构体成员写错了,把out修改成timeout就好了。
    修改错误代码
    再把后面提示的错误逐一修改过来,重新编译,报错都消失了,如下图所示:
    make编译harib09c项目OK

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

    使用make run命令,运行day12_boyC正常,10秒过后,qemu模拟器的屏幕上出现了"10[sec]"提示信息。运行结果如下图所示:
    运行harib09c项目,OK
    【最后说一下】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
    		}
    
    • 1
    • 2
    • 3
    • 4
    • 5

    正确代码:

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

    (全文完)

  • 相关阅读:
    数据库管理-第152期 Oracle Vector DB & AI-04(20240220)
    入门力扣自学笔记122 C++ (题目编号768)
    vue项目实际开发的问题及实用技巧分享(三)
    “赋能”企业,数加服装ERP智助企业乘风破浪
    面试题:数据库日期类型字段,需要兼容不同数据库,应该如何选择?
    软考高级:DNS欺骗相关知识和例题
    大恒相机SDK开发
    850. 矩形面积 II
    解密zkLogin:探索前沿的Sui身份验证解决方案
    【Day26】枚举
  • 原文地址:https://blog.csdn.net/ycjnx/article/details/132849187