haribote系统调用 工程管理及应用程序阅读注释
Posted 资质平庸的程序员
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了haribote系统调用 工程管理及应用程序阅读注释相关的知识,希望对你有一定的参考价值。
[ 1] haribote ipl09.nas 引导程序阅读注释。
[ 2] haribote asmhead.nas 从实模式进入保护模式程序阅读注释。
[ 3] haribote dsctbl.c 设置GDT和IDT程序阅读注释。
[ 4] haribote memory.c 内存管理程序阅读注释。
[ 5] haribote int.c 可编程中断控制器(PIC)初始配置程序阅读注释。
[ 6] haribote timer.c 定时器管理程序阅读注释。
[ 7] haribote fifo.c 循环队列管理程序阅读注释。
[ 8] haribote keyboard.c 键盘管理程序阅读注释。
[ 9] haribote mouse.c 鼠标管理程序阅读注释。
[10] haribote graphic.c 由像素点阵转换显卡画面信息程序阅读注释。
[11] haribote sheet.c 窗口画面及显示管理程序阅读注释。
[12] haribote window.c 自制窗口画面信息程序阅读注释。
[13] haribote file.c 文件读取程序阅读注释。
[14] haribote mtask.c 多任务管理程序阅读注释。
[15] haribote console.c 命令行窗口交互管理程序阅读注释。
[16] haribote naskfunc.nas 汇编函数接口程序阅读注释。
[17] haribote bootpack.c 主任务程序代码阅读注释。
篇幅较长,可通过浏览器的搜索功能(Ctrl + f)搜索函数名了解相应函数的实现机制,如 open_console。
[18] baribote系统调用 工程管理及其应用程序阅读注释
此文更博就算是完成了对linux0.11和haribote的粗略阅读啦,从4月算起,约经历了半年时光。想到此刻正是更早岁月中积累的铺垫和推动,曾经努力光阴中的激动仿佛也已赶来。
系统调用apilib
api001.nas
; api001.nas,系统调用号为1的系统调用-打印字符
; 告知编译器
; 目标文件格式,本文件中包含 i486 指令;
; 编译成 32位机器码; 本程序原文件名。
[FORMAT "WCOFF"]
[INSTRSET "i486p"]
[BITS 32]
[FILE "api001.nas"]
; 告知编译器_api_putchar标号为全局标识符
GLOBAL _api_putchar
; 告知编译器代码段开始
[SECTION .text]
; _api_putchar,
; 打印字符c,见内核程序 hrb_api()
_api_putchar: ; void api_putchar(int c);
MOV EDX,1 ; EDX = 系统调用号,见 hrb_api()
MOV AL,[ESP+4] ; AL = 参数
INT 0x40 ; 进入内核执行 _asm_hrb_api,见 init_gdtidt(),
; _asm_hrb_api 执行完系统调用号为1的子程序后将执行IRETD返回
RET ; 返回到调用本函数的下一语句处
; 涉及特权级变化的 INT 指令相当于
; push ss
; push esp
; pushf
; push cs
; push eip
;
; IRETD 指令为 INT 指令逆操作
api002.nas
; api002.nas,系统调用号为2的系统调用-打印字符串
; 同 api001.nas
[FORMAT "WCOFF"]
[INSTRSET "i486p"]
[BITS 32]
[FILE "api002.nas"]
GLOBAL _api_putstr0
[SECTION .text]
; 同 api001.nas
; _api_putstr0,
; 打印字符串s,见内核程序 hrb_api()
_api_putstr0: ; void api_putstr0(char *s);
PUSH EBX ; 备份 EBX
MOV EDX,2 ; EDX=2,系统调用号,见 hrb_api()
MOV EBX,[ESP+8] ; EBX=参数s的值
INT 0x40 ; 进入内核执行 _asm_hrb_api,见 init_gdtidt(),
; _asm_hrb_api 执行完系统调用号为2的子程序后将执行IRETD返回
POP EBX ; 恢复 EBX
RET ; 返回到调用本函数的下一语句处
api003.nas
; api003.nas,系统调用号为3的系统调用-打印指定数字符
; 同 api001.nas
[FORMAT "WCOFF"]
[INSTRSET "i486p"]
[BITS 32]
[FILE "api003.nas"]
GLOBAL _api_putstr1
[SECTION .text]
; 同 api001.nas
; api_putstr1,
; 打印s所指字符序列前l个字符
_api_putstr1: ; void api_putstr1(char *s, int l);
PUSH EBX ; 备份 EBX
MOV EDX,3 ; EDX=3,系统调用号,见 hrb_api()
MOV EBX,[ESP+ 8] ; s
MOV ECX,[ESP+12] ; l
INT 0x40 ; 进入内核执行 _asm_hrb_api,见 init_gdtidt(),
; _asm_hrb_api 执行完系统调用号为3的子程序后将执行IRETD返回
POP EBX ; 恢复 EBX
RET ; 返回到调用本函数的下一语句处
api004.nas
; api004.nas,系统调用号为4的系统调用-结束应用程序
; 同 api001.nas
[FORMAT "WCOFF"]
[INSTRSET "i486p"]
[BITS 32]
[FILE "api004.nas"]
GLOBAL _api_end
[SECTION .text]
; 同 api001.nas
; _api_end,
; 退出应用程序
_api_end: ; void api_end(void);
MOV EDX,4 ; EDX=系统调用号,见 hrb_api()
INT 0x40 ; 进入内核执行 _asm_hrb_api,见 init_gdtidt()
; _asm_hrb_api 执行EDX=4的子程序后将调用 _asm_end_app 结束引用程序
api005.nas
; api005.nas,系统调用号为5的系统调用-打开运行在用户态的命令行窗口
; 同 api001.nas
[FORMAT "WCOFF"]
[INSTRSET "i486p"]
[BITS 32]
[FILE "api005.nas"]
GLOBAL _api_openwin
[SECTION .text]
; 同 api001.nas
; _api_openwin,
; 打开一个应用程序命令行窗口。
; 窗口画面信息存于buf所指内存段中,窗口宽高分别为xsiz,ysiz,
; col_inv标识窗口是否包含透明色,title所指字符为窗口标题。
_api_openwin: ; int api_openwin(char *buf, int xsiz, int ysiz, int col_inv, char *title);
PUSH EDI ; 依次备份 EDI ESI EBX
PUSH ESI
PUSH EBX
MOV EDX,5 ; EDX=5,系统调用号,见 hrb_api()
MOV EBX,[ESP+16] ; buf
MOV ESI,[ESP+20] ; xsiz
MOV EDI,[ESP+24] ; ysiz
MOV EAX,[ESP+28] ; col_inv
MOV ECX,[ESP+32] ; title
INT 0x40 ; 进入内核执行 _asm_hrb_api,见 init_gdtidt(),
; _asm_hrb_api 执行完系统调用号为3的子程序后将执行IRETD返回
POP EBX ; 依次恢复 EBX ESI EDI
POP ESI
POP EDI
RET ; 返回到调用本函数的下一语句处
api006.nas
; api006.nas,系统调用号为6的系统调用-在应用程序窗口中打印字符串
; 同 api001.nas
[FORMAT "WCOFF"]
[INSTRSET "i486p"]
[BITS 32]
[FILE "api006.nas"]
GLOBAL _api_putstrwin
[SECTION .text]
; 同 api001.nas
; _api_putstrwin,
; 在win所管理的应用程序窗口中(x,y)位置处以色号col打印字符串,字符串长len
_api_putstrwin: ; void api_putstrwin(int win, int x, int y, int col, int len, char *str);
PUSH EDI ; 依次备份 EDI ESI EBP EBX
PUSH ESI
PUSH EBP
PUSH EBX
MOV EDX,6 ; EDX=6,系统调用号,见 hrb_api()
MOV EBX,[ESP+20] ; win
MOV ESI,[ESP+24] ; x
MOV EDI,[ESP+28] ; y
MOV EAX,[ESP+32] ; col
MOV ECX,[ESP+36] ; len
MOV EBP,[ESP+40] ; str
INT 0x40 ; 进入内核执行 _asm_hrb_api,见 init_gdtidt(),
; _asm_hrb_api 执行完系统调用号为3的子程序后将执行IRETD返回
POP EBX ; 依次恢复 EBX EBP ESI EDI
POP EBP
POP ESI
POP EDI
RET ; 返回到调用本函数的下一语句处
api007.nas
; api007.nas,系统调用号为7的系统调用-在应用程序窗口中绘制矩形
; 同 api001.nas
[FORMAT "WCOFF"]
[INSTRSET "i486p"]
[BITS 32]
[FILE "api007.nas"]
GLOBAL _api_boxfilwin
[SECTION .text]
; 同 api001.nas
; _api_boxfilwin,
; 在win所管理窗口[(x0,y0),(x1,y1)]区域绘制色号为col的矩形。
_api_boxfilwin: ; void api_boxfilwin(int win, int x0, int y0, int x1, int y1, int col);
PUSH EDI ; 依次备份 EDI ESI EBP EBX
PUSH ESI
PUSH EBP
PUSH EBX
MOV EDX,7 ; EDX=7,系统调用号,见 hrb_api()
MOV EBX,[ESP+20] ; win
MOV EAX,[ESP+24] ; x0
MOV ECX,[ESP+28] ; y0
MOV ESI,[ESP+32] ; x1
MOV EDI,[ESP+36] ; y1
MOV EBP,[ESP+40] ; col
INT 0x40 ; 进入内核执行 _asm_hrb_api,见 init_gdtidt(),
; _asm_hrb_api 执行完系统调用号为3的子程序后将执行IRETD返回
POP EBX ; 依次恢复 EBX EBP ESI EDI
POP EBP
POP ESI
POP EDI
RET ; 返回到调用本函数的下一语句处
api008.nas
; api008.nas,系统调用号为8的系统调用-初始化应用程序内存管理
; 同 api001.nas
[FORMAT "WCOFF"]
[INSTRSET "i486p"]
[BITS 32]
[FILE "api008.nas"]
GLOBAL _api_initmalloc
[SECTION .text]
; 同 api001.nas
; _api_initmalloc,
; 初始化应用程序内存管理
_api_initmalloc: ; void api_initmalloc(void);
PUSH EBX
MOV EDX,8 ; EDX=8,系统调用号,见 hrb_api()
MOV EBX,[CS:0x0020] ; 应用程序头部偏移20h处存储了堆内存在应用程序数据内存段中的偏移地址
MOV EAX,EBX
ADD EAX,32*1024 ; 预留32KB
MOV ECX,[CS:0x0000] ; 应用程序头部0x0处存储了应用程序数据段大小
SUB ECX,EAX ; ECX -= EAX,还剩下的数据段大小;该段内存用作堆内存
INT 0x40 ; 进入内核执行 _asm_hrb_api,见 init_gdtidt(),
; _asm_hrb_api 执行完系统调用号为3的子程序后将执行IRETD返回
POP EBX
RET ; 返回到调用本函数的下一语句处
api009.nas
; api009.nas,系统调用号为9的系统调用-内存分配
; 同 api001.nas
[FORMAT "WCOFF"]
[INSTRSET "i486p"]
[BITS 32]
[FILE "api009.nas"]
GLOBAL _api_malloc
[SECTION .text]
; 同 api001.nas
; _api_malloc,
; 从应用程序堆内存空间分配size大小内存
_api_malloc: ; char *api_malloc(int size);
PUSH EBX
MOV EDX,9 ; EDX=9,系统调用号,见 hrb_api()
MOV EBX,[CS:0x0020] ; 堆内存在数据段中的偏移,即管理
; 应用程序堆内存分配的结构体偏移地址,见 _api_initmalloc
MOV ECX,[ESP+8] ; size
INT 0x40 ; 进入内核执行 _asm_hrb_api,见 init_gdtidt(),
; _asm_hrb_api 执行完系统调用号为3的子程序后将执行IRETD返回
POP EBX
RET ; 返回到调用本函数的下一语句处
api010.nas
; api0010.nas,系统调用号为10的系统调用-内存释放
; 同 api001.nas
[FORMAT "WCOFF"]
[INSTRSET "i486p"]
[BITS 32]
[FILE "api010.nas"]
GLOBAL _api_free
[SECTION .text]
; 同 api001.nas
; _api_free,
; 释放内存段[addr, addr+size)
_api_free: ; void api_free(char *addr, int size);
PUSH EBX
MOV EDX,10 ; EDX=10,系统调用号,见 hrb_api()
MOV EBX,[CS:0x0020] ; 堆内存在数据段中的偏移,即管理
; 应用程序堆内存分配的结构体偏移地址,见 _api_initmalloc
MOV EAX,[ESP+ 8] ; addr
MOV ECX,[ESP+12] ; size
INT 0x40 ; 进入内核执行 _asm_hrb_api,见 init_gdtidt(),
; _asm_hrb_api 执行完系统调用号为3的子程序后将执行IRETD返回
POP EBX
RET ; 返回到调用本函数的下一语句处
api011.nas
; api0011.nas,系统调用号为11的系统调用-绘制一个点
; 同 api001.nas
[FORMAT "WCOFF"]
[INSTRSET "i486p"]
[BITS 32]
[FILE "api011.nas"]
GLOBAL _api_point
[SECTION .text]
; 同 api001.nas
; _api_point,
; 在win所管理窗口的(x,y)处以色号col绘制一个点
_api_point: ; void api_point(int win, int x, int y, int col);
PUSH EDI
PUSH ESI
PUSH EBX
MOV EDX,11 ; EDX=11,系统调用号,见 hrb_api()
MOV EBX,[ESP+16] ; win
MOV ESI,[ESP+20] ; x
MOV EDI,[ESP+24] ; y
MOV EAX,[ESP+28] ; col
INT 0x40 ; 进入内核执行 _asm_hrb_api,见 init_gdtidt(),
; _asm_hrb_api 执行完系统调用号为3的子程序后将执行IRETD返回
POP EBX
POP ESI
POP EDI
RET ; 返回到调用本函数的下一语句处
api012.nas
; api0012.nas,系统调用号为12的系统调用-刷新窗口指定区域画面
; 同 api001.nas
[FORMAT "WCOFF"]
[INSTRSET "i486p"]
[BITS 32]
[FILE "api012.nas"]
GLOBAL _api_refreshwin
[SECTION .text]
; 同 api001.nas
; _api_refreshwin,
; 刷新win所管理窗口[(x0,y0),(x1,y1)]区域画面
_api_refreshwin: ; void api_refreshwin(int win, int x0, int y0, int x1, int y1);
PUSH EDI
PUSH ESI
PUSH EBX
MOV EDX,12 ; EDX=12,系统调用号,见 hrb_api()
MOV EBX,[ESP+16] ; win
MOV EAX,[ESP+20] ; x0
MOV ECX,[ESP+24] ; y0
MOV ESI,[ESP+28] ; x1
MOV EDI,[ESP+32] ; y1
INT 0x40 ; 进入内核执行 _asm_hrb_api,见 init_gdtidt(),
; _asm_hrb_api 执行完系统调用号为3的子程序后将执行IRETD返回
POP EBX
POP ESI
POP EDI
RET ; 返回到调用本函数的下一语句处
api013.nas
; api0013.nas,系统调用号为13的系统调用-绘制线条
; 同 api001.nas
[FORMAT "WCOFF"]
[INSTRSET "i486p"]
[BITS 32]
[FILE "api013.nas"]
GLOBAL _api_linewin
[SECTION .text]
; 同 api001.nas
; _api_linewin,
; 在win所管理窗口中以色号col绘制起于(x0,y0)终于(x1,y1)的线条
_api_linewin: ; void api_linewin(int win, int x0, int y0, int x1, int y1, int col);
PUSH EDI
PUSH ESI
PUSH EBP
PUSH EBX
MOV EDX,13 ; EDX=13,系统调用号,见 hrb_api()
MOV EBX,[ESP+20] ; win
MOV EAX,[ESP+24] ; x0
MOV ECX,[ESP+28] ; y0
MOV ESI,[ESP+32] ; x1
MOV EDI,[ESP+36] ; y1
MOV EBP,[ESP+40] ; col
INT 0x40 ; 进入内核执行 _asm_hrb_api,见 init_gdtidt(),
; _asm_hrb_api 执行完系统调用号为3的子程序后将执行IRETD返回
POP EBX
POP EBP
POP ESI
POP EDI
RET ; 返回到调用本函数的下一语句处
api014.nas
; api0014.nas,系统调用号为14的系统调用-释放管理窗口结构体内存资源
; 同 api001.nas
[FORMAT "WCOFF"]
[INSTRSET "i486p"]
[BITS 32]
[FILE "api014.nas"]
GLOBAL _api_closewin
[SECTION .text]
; 同 api001.nas
; _api_closewin,
; 关闭由win所管理的窗口
_api_closewin: ; void api_closewin(int win);
PUSH EBX
MOV EDX,14 ; EDX=14,系统调用号,见 hrb_api()
MOV EBX,[ESP+8] ; win
INT 0x40 ; 进入内核执行 _asm_hrb_api,见 init_gdtidt(),
; _asm_hrb_api 执行完系统调用号为3的子程序后将执行IRETD返回
POP EBX
RET ; 返回到调用本函数的下一语句处
api015.nas
; api0015.nas,系统调用号为15的系统调用-读取当前(任务循环队列)数据
; 同 api001.nas
[FORMAT "WCOFF"]
[INSTRSET "i486p"]
[BITS 32]
[FILE "api015.nas"]
GLOBAL _api_getkey
[SECTION .text]
; 同 api001.nas
; _api_getkey,
; 从当前任务内核循环队列中获取数据;
; mode=0,无数据直接返回;mode=1,等待直到有数据。
_api_getkey: ; int api_getkey(int mode);
MOV EDX,15 ; EDX=15,系统调用号,见 hrb_api()
MOV EAX,[ESP+4] ; mode
INT 0x40 ; 进入内核执行 _asm_hrb_api,见 init_gdtidt(),
; _asm_hrb_api 执行完系统调用号为3的子程序后将执行IRETD返回
RET ; 返回到调用本函数的下一语句处
api016.nas
; api0016.nas,系统调用号为16的系统调用-分配定时器
; 同 api001.nas
[FORMAT "WCOFF"]
[INSTRSET "i486p"]
[BITS 32]
[FILE "api016.nas"]
GLOBAL _api_alloctimer
[SECTION .text]
; 同 api001.nas
; _api_alloctimer,
; 分配(管理)定时器(结构体)。
_api_alloctimer: ; int api_alloctimer(void);
MOV EDX,16 ; EDX=16,系统调用号,见 hrb_api()
INT 0x40 ; 进入内核执行 _asm_hrb_api,见 init_gdtidt(),
; _asm_hrb_api 执行完系统调用号为3的子程序后将执行IRETD返回
RET ; 返回到调用本函数的下一语句处
api017.nas
; api0017.nas,系统调用号为17的系统调用-初始化定时器
; 同 api001.nas
[FORMAT "WCOFF"]
[INSTRSET "i486p"]
[BITS 32]
[FILE "api017.nas"]
GLOBAL _api_inittimer
[SECTION .text]
; 同 api001.nas
;_api_inittimer,
; 初始化timer所管理定时器,定时器基数为data.
_api_inittimer: ; void api_inittimer(int timer, int data);
PUSH EBX
MOV EDX,17 ; EDX=17,系统调用号,见 hrb_api()
MOV EBX,[ESP+ 8] ; timer
MOV EAX,[ESP+12] ; data
INT 0x40 ; 进入内核执行 _asm_hrb_api,见 init_gdtidt(),
; _asm_hrb_api 执行完系统调用号为3的子程序后将执行IRETD返回
POP EBX
RET ; 返回到调用本函数的下一语句处
api018.nas
; api0018.nas,系统调用号为18的系统调用-设置定时器
; 同 api001.nas
[FORMAT "WCOFF"]
[INSTRSET "i486p"]
[BITS 32]
[FILE "api018.nas"]
GLOBAL _api_settimer
[SECTION .text]
; 同 api001.nas
; _api_settimer,
; 设置timer所管理定时器超时时间为time(单位10ms)
_api_settimer: ; void api_settimer(int timer, int time);
PUSH EBX
MOV EDX,18 ; EDX=18,系统调用号,见 hrb_api()
MOV EBX,[ESP+ 8] ; timer
MOV EAX,[ESP+12] ; time
INT 0x40 ; 进入内核执行 _asm_hrb_api,见 init_gdtidt(),
; _asm_hrb_api 执行完系统调用号为3的子程序后将执行IRETD返回
POP EBX
RET ; 返回到调用本函数的下一语句处
api019.nas
; api0019.nas,系统调用号为19的系统调用-释放定时器
; 同 api001.nas
[FORMAT "WCOFF"]
[INSTRSET "i486p"]
[BITS 32]
[FILE "api019.nas"]
GLOBAL _api_freetimer
[SECTION .text]
; 同 api001.nas
;_api_freetimer,
; 释放timer所管理定时器。
_api_freetimer: ; void api_freetimer(int timer);
PUSH EBX
MOV EDX,19 ; EDX=19,系统调用号,见 hrb_api()
MOV EBX,[ESP+ 8] ; timer
INT 0x40 ; 进入内核执行 _asm_hrb_api,见 init_gdtidt(),
; _asm_hrb_api 执行完系统调用号为3的子程序后将执行IRETD返回
POP EBX
RET ; 返回到调用本函数的下一语句处
api020.nas
; api0020.nas,系统调用号为20的系统调用-蜂鸣发生器。
; 同 api001.nas
[FORMAT "WCOFF"]
[INSTRSET "i486p"]
[BITS 32]
[FILE "api020.nas"]
GLOBAL _api_beep
[SECTION .text]
; 同 api001.nas
; _api_beep,
; 蜂鸣发生器,tone为声音频率,0时关闭。
_api_beep: ; void api_beep(int tone);
MOV EDX,20 ; EDX=20,系统调用号,见 hrb_api()
MOV EAX,[ESP+4] ; tone,声音频率
INT 0x40 ; 进入内核执行 _asm_hrb_api,见 init_gdtidt(),
; _asm_hrb_api 执行完系统调用号为3的子程序后将执行IRETD返回
RET ; 返回到调用本函数的下一语句处
api021.nas
; api0021.nas,系统调用号为21的系统调用-打开文件。
; 同 api001.nas
[FORMAT "WCOFF"]
[INSTRSET "i486p"]
[BITS 32]
[FILE "api021.nas"]
GLOBAL _api_fopen
[SECTION .text]
; 同 api001.nas
; _api_fopen,
; 打开fname所指文件。
_api_fopen: ; int api_fopen(char *fname);
PUSH EBX
MOV EDX,21 ; EDX=21,系统调用号,见 hrb_api()
MOV EBX,[ESP+8] ; fname
INT 0x40 ; 进入内核执行 _asm_hrb_api,见 init_gdtidt(),
; _asm_hrb_api 执行完系统调用号为3的子程序后将执行IRETD返回
POP EBX
RET ; 返回到调用本函数的下一语句处
api022.nas
; api0022.nas,系统调用号为22的系统调用-关闭文件。
; 同 api001.nas
[FORMAT "WCOFF"]
[INSTRSET "i486p"]
[BITS 32]
[FILE "api022.nas"]
GLOBAL _api_fclose
[SECTION .text]
; 同 api001.nas
; _api_fclose,
; 关闭fhandle对应的文件。
_api_fclose: ; void api_fclose(int fhandle);
MOV EDX,22 ; EDX=22,系统调用号,见 hrb_api()
MOV EAX,[ESP+4] ; fhandle
INT 0x40 ; 进入内核执行 _asm_hrb_api,见 init_gdtidt(),
; _asm_hrb_api 执行完系统调用号为3的子程序后将执行IRETD返回
RET ; 返回到调用本函数的下一语句处
api023.nas
; api0023.nas,系统调用号为23的系统调用-设置文件内容位置。
; 同 api001.nas
[FORMAT "WCOFF"]
[INSTRSET "i486p"]
[BITS 32]
[FILE "api023.nas"]
GLOBAL _api_fseek
[SECTION .text]
; 同 api001.nas
; _api_fseek,
; 从fhandle所管理文件的mode标识的位置移动offset。
_api_fseek: ; void api_fseek(int fhandle, int offset, int mode);
PUSH EBX
MOV EDX,23 ; EDX=23,系统调用号,见 hrb_api()
MOV EAX,[ESP+8] ; fhandle
MOV ECX,[ESP+16] ; mode
MOV EBX,[ESP+12] ; offset
INT 0x40 ; 进入内核执行 _asm_hrb_api,见 init_gdtidt(),
; _asm_hrb_api 执行完系统调用号为3的子程序后将执行IRETD返回
POP EBX
RET ; 返回到调用本函数的下一语句处
api024.nas
; api0024.nas,系统调用号为24的系统调用-获取文件大小和位置信息。
; 同 api001.nas
[FORMAT "WCOFF"]
[INSTRSET "i486p"]
[BITS 32]
[FILE "api024.nas"]
GLOBAL _api_fsize
[SECTION .text]
; 同 api001.nas
; _api_fsize,
; mode=0,获取文件大小;
; mode=1,文件当前位置;
; mode=2,返回文件当前位置与文件末尾的偏移。
_api_fsize: ; int api_fsize(int fhandle, int mode);
MOV EDX,24 ; EDX=24,系统调用号,见 hrb_api()
MOV EAX,[ESP+4] ; fhandle
MOV ECX,[ESP+8] ; mode
INT 0x40 ; 进入内核执行 _asm_hrb_api,见 init_gdtidt(),
; _asm_hrb_api 执行完系统调用号为3的子程序后将执行IRETD返回
RET ; 返回到调用本函数的下一语句处
api025.nas
; api0025.nas,系统调用号为25的系统调用-读取文件内容。
; 同 api001.nas
[FORMAT "WCOFF"]
[INSTRSET "i486p"]
[BITS 32]
[FILE "api025.nas"]
GLOBAL _api_fread
[SECTION .text]
; 同 api001.nas
; _api_fread,
; 从fhandle所管理文件最多读取maxsize字节内容到buf所指内存段中。
_api_fread: ; int api_fread(char *buf, int maxsize, int fhandle);
PUSH EBX
MOV EDX,25 ; EDX=25,系统调用号,见 hrb_api()
MOV EAX,[ESP+16] ; fhandle
MOV ECX,[ESP+12] ; maxsize
MOV EBX,[ESP+8] ; buf
INT 0x40 ; 进入内核执行 _asm_hrb_api,见 init_gdtidt(),
; _asm_hrb_api 执行完系统调用号为3的子程序后将执行IRETD返回
POP EBX
RET ; 返回到调用本函数的下一语句处
api026.nas
; api0026.nas,系统调用号为26的系统调用-获取窗口命令行数据。
; 同 api001.nas
[FORMAT "WCOFF"]
[INSTRSET "i486p"]
[BITS 32]
[FILE "api026.nas"]
GLOBAL _api_cmdline
[SECTION .text]
; 同 api001.nas
; _api_cmdline,
; 获取命令行数据到buf所指内存段,最多获取maxsize字节。
_api_cmdline: ; int api_cmdline(char *buf, int maxsize);
PUSH EBX
MOV EDX,26 ; EDX=26,系统调用号,见 hrb_api()
MOV ECX,[ESP+12] ; maxsize
MOV EBX,[ESP+8] ; buf
INT 0x40 ; 进入内核执行 _asm_hrb_api,见 init_gdtidt(),
; _asm_hrb_api 执行完系统调用号为3的子程序后将执行IRETD返回
POP EBX
RET ; 返回到调用本函数的下一语句处
api027.nas
; api0027.nas,系统调用号为27的系统调用-获取语言模式。
; 同 api001.nas
[FORMAT "WCOFF"]
[INSTRSET "i486p"]
[BITS 32]
[FILE "api027.nas"]
GLOBAL _api_getlang
[SECTION .text]
; 同 api001.nas
; _api_getlang,
; 获取语言模式。
_api_getlang: ; int api_getlang(void);
MOV EDX,27 ; EDX=26,系统调用号,见 hrb_api()
INT 0x40 ; 进入内核执行 _asm_hrb_api,见 init_gdtidt(),
; _asm_hrb_api 执行完系统调用号为3的子程序后将执行IRETD返回
RET ; 返回到调用本函数的下一语句处
apilib.h
/* apilib.h,声明 haribote 系统调用 */
void api_putchar(int c);
void api_putstr0(char *s);
void api_putstr1(char *s, int l);
void api_end(void);
int api_openwin(char *buf, int xsiz, int ysiz, int col_inv, char *title);
void api_putstrwin(int win, int x, int y, int col, int len, char *str);
void api_boxfilwin(int win, int x0, int y0, int x1, int y1, int col);
void api_initmalloc(void);
char *api_malloc(int size);
void api_free(char *addr, int size);
void api_point(int win, int x, int y, int col);
void api_refreshwin(int win, int x0, int y0, int x1, int y1);
void api_linewin(int win, int x0, int y0, int x1, int y1, int col);
void api_closewin(int win);
int api_getkey(int mode);
int api_alloctimer(void);
void api_inittimer(int timer, int data);
void api_settimer(int timer, int time);
void api_freetimer(int timer);
void api_beep(int tone);
int api_fopen(char *fname);
void api_fclose(int fhandle);
void api_fseek(int fhandle, int offset, int mode);
int api_fsize(int fhandle, int mode);
int api_fread(char *buf, int maxsize, int fhandle);
int api_cmdline(char *buf, int maxsize);
int api_getlang(void);
Makefile
根目录Makefile
# haribote 工程根目录 Makefile
# 此文阅读工程管理文件欲粗略了解工程管理相关,
# 此文对其内所包含的一些工具的具体用法也不知祥。
# haribote 工具路径,依赖头文件路径,可根据实际目录更改
TOOLPATH = ../z_tools/
INCPATH = ../z_tools/haribote/
# make 是解析 Makefile 的工具;
# eding.exe 是制作映像文件的工具;
# imgtol.com 是将映像文件写入软盘的工具;
# copy,del 是拷贝和删除命令。
MAKE = $(TOOLPATH)make.exe -r
EDIMG = $(TOOLPATH)edimg.exe
IMGTOL = $(TOOLPATH)imgtol.com
COPY = copy
DEL = del
# make 默认解析规则;
# 由于目标 default 不存在,所以该规则下的命令会被无条件执行。
default :
$(MAKE) haribote.img
# 由目标 default 所在规则触发被解析,
# 当目标 haribote.img 不存在或其先决依赖文件改变时重新生成 haribote.img
haribote.img : haribote/ipl09.bin haribote/haribote.sys Makefile \\
a/a.hrb hello3/hello3.hrb hello4/hello4.hrb hello5/hello5.hrb \\
winhelo/winhelo.hrb winhelo2/winhelo2.hrb winhelo3/winhelo3.hrb \\
star1/star1.hrb stars/stars.hrb stars2/stars2.hrb \\
lines/lines.hrb walk/walk.hrb noodle/noodle.hrb \\
beepdown/beepdown.hrb color/color.hrb color2/color2.hrb \\
sosu/sosu.hrb sosu2/sosu2.hrb sosu3/sosu3.hrb \\
type/type.hrb iroha/iroha.hrb chklang/chklang.hrb \\
notrec/notrec.hrb bball/bball.hrb invader/invader.hrb \\
calc/calc.hrb tview/tview.hrb mmlplay/mmlplay.hrb gview/gview.hrb
$(EDIMG) imgin:../z_tools/fdimg0at.tek \\
wbinimg src:haribote/ipl09.bin len:512 from:0 to:0 \\
copy from:haribote/haribote.sys to:@: \\
copy from:ipl09.nas to:@: \\
copy from:make.bat to:@: \\
copy from:a/a.hrb to:@: \\
copy from:hello3/hello3.hrb to:@: \\
copy from:hello4/hello4.hrb to:@: \\
copy from:hello5/hello5.hrb to:@: \\
copy from:winhelo/winhelo.hrb to:@: \\
copy from:winhelo2/winhelo2.hrb to:@: \\
copy from:winhelo3/winhelo3.hrb to:@: \\
copy from:star1/star1.hrb to:@: \\
copy from:stars/stars.hrb to:@: \\
copy from:stars2/stars2.hrb to:@: \\
copy from:lines/lines.hrb to:@: \\
copy from:walk/walk.hrb to:@: \\
copy from:noodle/noodle.hrb to:@: \\
copy from:beepdown/beepdown.hrb to:@: \\
copy from:color/color.hrb to:@: \\
copy from:color2/color2.hrb to:@: \\
copy from:sosu/sosu.hrb to:@: \\
copy from:sosu2/sosu2.hrb to:@: \\
copy from:sosu3/sosu3.hrb to:@: \\
copy from:type/type.hrb to:@: \\
copy from:iroha/iroha.hrb to:@: \\
copy from:chklang/chklang.hrb to:@: \\
copy from:euc.txt to:@: \\
copy from:notrec/notrec.hrb to:@: \\
copy from:bball/bball.hrb to:@: \\
copy from:invader/invader.hrb to:@: \\
copy from:calc/calc.hrb to:@: \\
copy from:tview/tview.hrb to:@: \\
copy from:mmlplay/mmlplay.hrb to:@: \\
copy from:mmldata/kirakira.mml to:@: \\
copy from:mmldata/fujisan.mml to:@: \\
copy from:mmldata/daigo.mml to:@: \\
copy from:mmldata/daiku.mml to:@: \\
copy from:gview/gview.hrb to:@: \\
copy from:pictdata/fujisan.jpg to:@: \\
copy from:pictdata/night.bmp to:@: \\
copy from:nihongo/nihongo.fnt to:@: \\
imgout:haribote.img
# make run
# 由于目标 run 不存在,所以该规则下的规则会被无条件执行。
# [1] 更新映像文件 haribote.img;
# [2] 将更新的映像文件拷贝到虚拟机 qemu.exe 同目录下的 fdimage0.bin中;
# [3] 启动虚拟机 qemu.exe 加载 fdimage0.bin运行。
run :
$(MAKE) haribote.img
$(COPY) haribote.img ..\\z_tools\\qemu\\fdimage0.bin
$(MAKE) -C ../z_tools/qemu
# make install
# 由于目标 install 不存在,所以该规则下的命令会被无条件还行。
# [1] 更新映像文件 haribote.img;
# [2] 将更新的影响文件写入软盘中。
install :
$(MAKE) haribote.img
$(IMGTOL) w a: haribote.img
# make full
# 由于目标 full 不存在,所以该规则下的命令将会被无条件执行。
# 根据最新工程源文件更新硬盘映像文件 haribote.img。
full :
$(MAKE) -C haribote
$(MAKE) -C apilib
$(MAKE) -C a
$(MAKE) -C hello3
$(MAKE) -C hello4
$(MAKE) -C hello5
$(MAKE) -C winhelo
$(MAKE) -C winhelo2
$(MAKE) -C winhelo3
$(MAKE) -C star1
$(MAKE) -C stars
$(MAKE) -C stars2
$(MAKE) -C lines
$(MAKE) -C walk
$(MAKE) -C noodle
$(MAKE) -C beepdown
$(MAKE) -C color
$(MAKE) -C color2
$(MAKE) -C sosu
$(MAKE) -C sosu2
$(MAKE) -C sosu3
$(MAKE) -C type
$(MAKE) -C iroha
$(MAKE) -C chklang
$(MAKE) -C notrec
$(MAKE) -C bball
$(MAKE) -C invader
$(MAKE) -C calc
$(MAKE) -C tview
$(MAKE) -C mmlplay
$(MAKE) -C gview
$(MAKE) haribote.img
# make run_full
# 由于目标 run_full 不存在,所以规则下的命令将会无条件执行。
# [1] 根据工程最新源文件更新映像文件 haribote.img;
# [2] 将更新映像文件拷贝到虚拟机 qemu.ext 同目录下的 fdimage0.bin中;
# [3] 启动虚拟机 qemu.exe 加载 fdimage0.bin 运行。
run_full :
$(MAKE) full
$(COPY) haribote.img ..\\z_tools\\qemu\\fdimage0.bin
$(MAKE) -C ../z_tools/qemu
# make install_full
# 由于目标 install_full 不存在,所以该规则下的命令将会被无条件执行。
# [1] 根据工程最新源文件更新映像文件 haribote.img;
# [2] 将更新的影响文件写入软盘中。
install_full :
$(MAKE) full
$(IMGTOL) w a: haribote.img
# make run_os
# 由于目标 run_os 不存在,所以该规则下的命令将会被无条件执行。
# [1] 根据 haribote OS 最新源码更新映像文件 haribote.img;
# [2] 启动虚拟机 qemu.exe 加载映像文件运行。
run_os :
$(MAKE) -C haribote
$(MAKE) run
clean :
# make src_only
# 由于目标 src_only 不存在,所以该规则下的命令会被无条件执行。
# 删除映像文件 haribote.img。
src_only :
$(MAKE) clean
-$(DEL) haribote.img
# make clean_full
# 由于目标 clean_full 不存在,所以该规则下的命令会被无条件执行。
# 在工程各子目录下执行 make clean 命令。
clean_full :
$(MAKE) -C haribote clean
$(MAKE) -C apilib clean
$(MAKE) -C a clean
$(MAKE) -C hello3 clean
$(MAKE) -C hello4 clean
$(MAKE) -C hello5 clean
$(MAKE) -C winhelo clean
$(MAKE) -C winhelo2 clean
$(MAKE) -C winhelo3 clean
$(MAKE) -C star1 clean
$(MAKE) -C stars clean
$(MAKE) -C stars2 clean
$(MAKE) -C lines clean
$(MAKE) -C walk clean
$(MAKE) -C noodle clean
$(MAKE) -C beepdown clean
$(MAKE) -C color clean
$(MAKE) -C color2 clean
$(MAKE) -C sosu clean
$(MAKE) -C sosu2 clean
$(MAKE) -C sosu3 clean
$(MAKE) -C type clean
$(MAKE) -C iroha clean
$(MAKE) -C chklang clean
$(MAKE) -C notrec clean
$(MAKE) -C bball clean
$(MAKE) -C invader clean
$(MAKE) -C calc clean
$(MAKE) -C tview clean
$(MAKE) -C mmlplay clean
$(MAKE) -C gview clean
# make src_only_full
# 由于目标 src_only_full 不存在,所以该规则下的命令将会被执行。
# [1] 在工程各子目录下执行 make src_only;
# [2] 删除映像文件 haribote.img。
# 即只保留源文件。
src_only_full :
$(MAKE) -C haribote src_only
$(MAKE) -C apilib src_only
$(MAKE) -C a src_only
$(MAKE) -C hello3 src_only
$(MAKE) -C hello4 src_only
$(MAKE) -C hello5 src_only
$(MAKE) -C winhelo src_only
$(MAKE) -C winhelo2 src_only
$(MAKE) -C winhelo3 src_only
$(MAKE) -C star1 src_only
$(MAKE) -C stars src_only
$(MAKE) -C stars2 src_only
$(MAKE) -C lines src_only
$(MAKE) -C walk src_only
$(MAKE) -C noodle src_only
$(MAKE) -C beepdown src_only
$(MAKE) -C color src_only
$(MAKE) -C color2 src_only
$(MAKE) -C sosu src_only
$(MAKE) -C sosu2 src_only
$(MAKE) -C sosu3 src_only
$(MAKE) -C type src_only
$(MAKE) -C iroha src_only
$(MAKE) -C chklang src_only
$(MAKE) -C notrec src_only
$(MAKE) -C bball src_only
$(MAKE) -C invader src_only
$(MAKE) -C calc src_only
$(MAKE) -C tview src_only
$(MAKE) -C mmlplay src_only
$(MAKE) -C gview src_only
-$(DEL) haribote.img
# make refresh
# 由于目标 refresh 不存在,所以该规则下的命令会被无条件执行。
# [1] 根据工程最新源文件生成映像文件;
# [2-3] 删除各工程目录下的输出和映像文件。
refresh :
$(MAKE) full
$(MAKE) clean_full
-$(DEL) haribote.img
haribote/Makefile
# 将目标文件集赋给变量 OBJS_BOOTPACK
OBJS_BOOTPACK = bootpack.obj naskfunc.obj hankaku.obj graphic.obj dsctbl.obj \\
int.obj fifo.obj keyboard.obj mouse.obj memory.obj sheet.obj timer.obj \\
mtask.obj window.obj console.obj file.obj tek.obj
# haribote 工具路径,依赖头文件路径,可根据实际目录更改
TOOLPATH = ../../z_tools/
INCPATH = ../../z_tools/haribote/
# make 是解析 Makefile 的工具;
# nask.exe 是汇编编译器;
# ccl.exe 是C程序编译器;
# gas2nask.exe,obj2bim.exe,bin2obj.exe,bim2hrb.exe 是目标文件格式转换工具;
# makefont.exe 是将 hankaku.txt 文件转换为字库文件的工具;
# haribote.rul 相当于链接脚本;
# eding.exe 是制作映像文件的工具;
# imgtol.com 是将映像文件写入软盘的工具;
# golib00.exe 库文件制作工具;
# copy,del 是拷贝和删除命令。
MAKE = $(TOOLPATH)make.exe -r
NASK = $(TOOLPATH)nask.exe
CC1 = $(TOOLPATH)cc1.exe -I$(INCPATH) -Os -Wall -quiet
GAS2NASK = $(TOOLPATH)gas2nask.exe -a
OBJ2BIM = $(TOOLPATH)obj2bim.exe
MAKEFONT = $(TOOLPATH)makefont.exe
BIN2OBJ = $(TOOLPATH)bin2obj.exe
BIM2HRB = $(TOOLPATH)bim2hrb.exe
RULEFILE = ../haribote.rul
EDIMG = $(TOOLPATH)edimg.exe
IMGTOL = $(TOOLPATH)imgtol.com
GOLIB = $(TOOLPATH)golib00.exe
COPY = copy
DEL = del
# make 默认解析规则,
# 由于目标 default 不存在,所以该规则下的命令将会被无条件执行。
# [1] 解析目标 ipl09.bin 所在规则;
# [2] 解析目标 haribote.sys 所在规则。
default :
$(MAKE) ipl09.bin
$(MAKE) haribote.sys
# 由目标 default 所在规则触发解析。
# 当目标 ipl09.bin 不存在或其先决依赖文件 ipl09.nas Makefile 改变时,
# 该规则下的命令将会被执行: 将汇编引导程序 ipl09.nas 编译成目标文件
# ipl09.bin。
ipl09.bin : ipl09.nas Makefile
$(NASK) ipl09.nas ipl09.bin ipl09.lst
# 由目标 haribote.sys 所在规则触发解析
# 当目标 asmhead.bin 不存在 或其先决依赖文件 asmhead.nas Makefile 改变时
# 该规则下的命令将被执行, 将汇编程序 asmhead.nas 编译为 asmhead.bin 。
asmhead.bin : asmhead.nas Makefile
$(NASK) asmhead.nas asmhead.bin asmhead.lst
# 由目标 hankaku.obj 所在规则触发解析
# 当目标 hankaku.bin 不存在或其先决依赖条件 hankaku.txt Makefile 改变时,
# 该规则下的命令会被执行: 将文件 hankaku.txt 转换为 hankaku.bin 。
hankaku.bin : hankaku.txt Makefile
$(MAKEFONT) hankaku.txt hankaku.bin
# 由目标 bootpack.bim 所在规则触发解析
# 当目标 hankaku.obj 不存在或其先决依赖条件 hankaku.bin Makefile 改变时,
# 该规则下的命令会被执行: 将目标文件 hankaku.bin 转换为 hankaku.obj,
# 起始地址为 _hankaku 。
hankaku.obj : hankaku.bin Makefile
$(BIN2OBJ) hankaku.bin hankaku.obj _hankaku
# 由目标 bootpack.hrb 所在规则触发解析
# 当目标 bootpack.bim 不存在或其先决依赖条件 $(OBJS_BOOTPACK) Makefile 改变时,
#该改规则下的命令会被执行: 将目标文件 $(OBJS_BOOTPACK) 链接到 bootpack.bim 中。
#
# 该规则会引发目标 $(OBJS_BOOTPACK) 所在规则的解析(匹配第3个隐式规则)。
bootpack.bim : $(OBJS_BOOTPACK) Makefile
$(OBJ2BIM) @$(RULEFILE) out:bootpack.bim stack:3136k map:bootpack.map \\
$(OBJS_BOOTPACK)
# 3MB+64KB=3136KB
# 由目标 haribote.hrb 所在规则触发解析
# 当目标 bootpack.hrb 不存在或其先决依赖条件 bootpack.bim Makefile 改变时,
# 该规则下的命令会被执行: 将目标文件 bootpack.bin 转换为 bootpack.hrb。
#
# 该规则会引发目标 bootpack.bim 所在规则的解析。
bootpack.hrb : bootpack.bim Makefile
$(BIM2HRB) bootpack.bim bootpack.hrb 0
# 由目标 default 所在规则触发解析。
# 当目标 haribote.sys 不存在或其先决依赖文件 asmhead.bin bootpack.hrb Makefile
# 改变时,该规则下的命令将会被执行: 将 asmhead.bin 和 bootpack.hrb 拷贝到 haribote.sys
# 文件中。
#
# 该规则会检查目标 asmhead.bin 和 bootpack.hrb 所在规则的检查。
haribote.sys : asmhead.bin bootpack.hrb Makefile
copy /B asmhead.bin+bootpack.hrb haribote.sys
# 以下是3个隐式规则,自动变量 $* 代表目标命名中 % 之前部分命名;
# 第3个隐式隐式规则由 bootpack.bim 目标所在规则匹配并被解析,遂
# 匹配第2个隐式规则并被解析,再匹配第1个隐式规则并被解析。
#
# 根据与 .gas 文件同名的 .c文件生成 .gas文件,
# 若相应的 .gas 文件不存在或 .c文件有变时。
#
# 如
# 由第2条隐式规则匹配并形成实际规则
# bootpack.gas : bootpack.c Makefile
# $(CC1) -o $*.gas $*.c
# 该规则生成 bootpack.gas, 第2条规则再生成 bootpack.nas,
# 第3条规则再生成 bootpack.obj,这样就得到了 $(OBJS_BOOTPACK) 中的目标文件,
# 从而生成目标 bootpack.bim
%.gas : %.c bootpack.h Makefile
$(CC1) -o $*.gas $*.c
#
# 根据与 .nas 文件同名的 .gas文件生成 .nas文件,
# 若相应的 .nas 文件不存在或 .gas文件有变时。
#
# 如
# 由第3条隐式规则匹配并形成实际规则
# bootpack.nas : bootpack.gas Makefile
# $(GAS2NASK) $*.gas $*.nas
# 该规则会匹配第1条隐式规则并形成实际的规则而被解析。
%.nas : %.gas Makefile
$(GAS2NASK) $*.gas $*.nas
#
# 根据与 $(OBJS_BOOTPACK) 中 .obj 文件同名的 .nas 文件生成 .obj 文件,
# 当相应 .obj 文件不存在或 %.nas 有变时。
#
# 如
# bootpack.obj : bootpack.nas Makefile
# $(NASK) $*.nas $*.obj $*.lst
#
# 该规则会匹配第2条隐式规则并形成实际的规则而被解析。
%.obj : %.nas Makefile
$(NASK) $*.nas $*.obj $*.lst
# 举个简单例子感受下吧。
# 文件 main.c Makefile
#
# Makefile 内容如下
# all: main.out
#
# main.out : main.o
# gcc main.o -o main.out
#
# main.o : main.c
#
# %.o: %.c
# gcc -c -o $*.o $*.c
#
# 在 Makefile 同目录下执行 Make
# gcc -c -o main.o main.c
# gcc main.o -o main.out
# make clean
# 由于目标 clean 不存在,所以该规则下的命令会被无条件执行。
# 删除由 make 解析本 Makefile 时所生成的文件。
clean :
-$(DEL) asmhead.bin
-$(DEL) hankaku.bin
-$(DEL) *.lst
-$(DEL) *.obj
-$(DEL) *.map
-$(DEL) *.bim
-$(DEL) *.hrb
# make src_only
# 由于目标 src_only 不存在,所以该规则下的命令会被无条件执行。
# [1] 清理由 make 解析本 Makefile 时所生成的文件;
# [2] 删除引导程序目标文件;
# [3] 删除内核目标文件 haribote.sys。
# 即只保留源文件。
src_only :
$(MAKE) clean
-$(DEL) ipl09.bin
-$(DEL) haribote.sys
apilib/Makefile
# haribote 系统调用库 Makefile
# 将目标文件集赋给变量 OBJS_API
OBJS_API = api001.obj api002.obj api003.obj api004.obj api005.obj api006.obj \\
api007.obj api008.obj api009.obj api010.obj api011.obj api012.obj \\
api013.obj api014.obj api015.obj api016.obj api017.obj api018.obj \\
api019.obj api020.obj api021.obj api022.obj api023.obj api024.obj \\
api025.obj api026.obj api027.obj alloca.obj
# haribote 工具路径,依赖头文件路径,可根据实际目录更改
TOOLPATH = ../../z_tools/
INCPATH = ../../z_tools/haribote/
# make 是解析 Makefile 的工具;
# nask.exe 是汇编编译器;
# ccl.exe 是C程序编译器;
# gas2nask.exe,obj2bim.exe,bin2obj.exe,bim2hrb.exe 是目标文件格式转换工具;
# makefont.exe 是将 hankaku.txt 文件转换为字库文件的工具;
# haribote.rul 相当于链接脚本;
# eding.exe 是制作映像文件的工具;
# imgtol.com 是将映像文件写入软盘的工具;
# golib00.exe 库文件制作工具;
# copy,del 是拷贝和删除命令。
MAKE = $(TOOLPATH)make.exe -r
NASK = $(TOOLPATH)nask.exe
CC1 = $(TOOLPATH)cc1.exe -I$(INCPATH) -Os -Wall -quiet
GAS2NASK = $(TOOLPATH)gas2nask.exe -a
OBJ2BIM = $(TOOLPATH)obj2bim.exe
MAKEFONT = $(TOOLPATH)makefont.exe
BIN2OBJ = $(TOOLPATH)bin2obj.exe
BIM2HRB = $(TOOLPATH)bim2hrb.exe
RULEFILE = ../haribote.rul
EDIMG = $(TOOLPATH)edimg.exe
IMGTOL = $(TOOLPATH)imgtol.com
GOLIB = $(TOOLPATH)golib00.exe
COPY = copy
DEL = del
# make 默认解析规则,
# 由于目标 default 不存在,所以该规则下的命令将会被无条件执行。
# 即解析目标 apilib.lib 所在规则。
default :
$(MAKE) apilib.lib
# make apilib.lib
# apilib.lib 不存在或先决依赖文件 Makefile $(OBJS_API) 有改变时,
# 该规则下的命令将会被执行, 即将 $(OBJS_API) 目标文件打包到库文
# 件 apilib.lib 中。该命令将会匹配后续隐式规则。
apilib.lib : Makefile $(OBJS_API)
$(GOLIB) $(OBJS_API) out:apilib.lib
# 以下是隐式规则,自动变量 $* 代表目标命名中 % 之前部分命名;
# 该隐式规则由 apilib.lib 目标所在规则匹配并被解析, 即根据
# 与 $(OBJS_API) 中 .obj 文件同名的 .nas 文件生成 .obj 文件。
%.obj : %.nas Makefile
$(NASK) $*.nas $*.obj $*.lst
# make clean
# 由于目标 clean 不存在,所以改规则下的命令会被无条件执行,
# 即删除由 make 解析本 Makefile 时生成的中间文件。
clean :
-$(DEL) *.lst
-$(DEL) *.obj
# make src_only
# 由于目标 src_only 不存在,所以该规则下的命令会被无条件执行,
# 即删除由 make 解析本 Makefile 时生成的所有文件,,只保留源文件。
src_only :
$(MAKE) clean
-$(DEL) apilib.lib
app_make.txt
# app_make.txt,haribote 应用程序 Makefile 公用 Makefile 部分,
# 会被各应用程序包含到其 Makefile 中。
# haribote app 工具路径,依赖头文件路径,库路径,操作系统路径,
# 可根据实际目录更改
TOOLPATH = ../../z_tools/
INCPATH = ../../z_tools/haribote/
APILIBPATH = ../apilib/
HARIBOTEPATH = ../haribote/
# make 是解析 Makefile 的工具;
# nask.exe 是汇编编译器;
# ccl.exe 是C程序编译器;
# gas2nask.exe,obj2bim.exe,bin2obj.exe,bim2hrb.exe 是目标文件格式转换工具;
# makefont.exe 是将 hankaku.txt 文件转换为字库文件的工具;
# haribote.rul 相当于链接脚本;
# eding.exe 是制作映像文件的工具;
# imgtol.com 是将映像文件写入软盘的工具;
# golib00.exe 库文件制作工具;
# copy,del 是拷贝和删除命令。
MAKE = $(TOOLPATH)make.exe -r
NASK = $(TOOLPATH)nask.exe
CC1 = $(TOOLPATH)cc1.exe -I$(INCPATH) -I../ -Os -Wall -quiet
GAS2NASK = $(TOOLPATH)gas2nask.exe -a
OBJ2BIM = $(TOOLPATH)obj2bim.exe
MAKEFONT = $(TOOLPATH)makefont.exe
BIN2OBJ = $(TOOLPATH)bin2obj.exe
BIM2HRB = $(TOOLPATH)bim2hrb.exe
BIM2BIN = $(TOOLPATH)bim2bin.exe
RULEFILE = ../haribote.rul
EDIMG = $(TOOLPATH)edimg.exe
IMGTOL = $(TOOLPATH)imgtol.com
GOLIB = $(TOOLPATH)golib00.exe
COPY = copy
DEL = del
# make 默认解析规则,
# 由于目标 default 不存在,所以该规则下的命令将会被无条件执行。
# 即解析目标 $(APP).hrb 所在规则。变量 APP 在应用程序 Makefile
# 中被定义,标识应用程序名。结合应用程序 harib27f/a 看下吧。
default :
$(MAKE) $(APP).hrb
# 该规则由目标 default 所在规则间接触发解析,
# 若 $(APP).bim 不存在或其先决依赖文件有变时,该规则下的命令被执行,即生成
# 目标文件 $(APP).bim, 从这里可以看出为应用程序栈设置了1Kb。
$(APP).bim : $(APP).obj $(APILIBPATH)apilib.lib Makefile ../app_make.txt
$(OBJ2BIM) @$(RULEFILE) out:$(APP).bim map:$(APP).map stack:$(STACK) \\
$(APP).obj $(APILIBPATH)apilib.lib
# make haribote.img 或被 make run 触发解析,
# 即将可执行应用程序 haribote 内核,$(APP).hrb 以及字库文件 nihong.fnt 加入映像文件中。
haribote.img : ../haribote/ipl09.bin ../haribote/haribote.sys $(APP).hrb \\
Makefile ../app_make.txt
$(EDIMG) imgin:../../z_tools/fdimg0at.tek \\
wbinimg src:../haribote/ipl09.bin len:512 from:0 to:0 \\
copy from:../haribote/haribote.sys to:@: \\
copy from:$(APP).hrb to:@: \\
copy from:../nihongo/nihongo.fnt to:@: \\
imgout:haribote.img
# 以下是5条隐式规则,根据应用程序 Makefile,第5条隐式规则
# 将会被 default 目标所在规则匹配并被解析,随之匹配第4条
# 隐式规则,然后触发目标 $(APP).bim 所在规则被解析, 该规
# 则的 .obj 先决依赖文件将会匹配第3条隐式规则,第3条隐式
# 规则将会匹配第2条隐式规则, 第2条隐式规则将会匹配第1条
# 隐式规则。即由完成由源文件 $(APP).C 生成可执行文件 $(APP).hrb。
%.gas : %.c ../apilib.h Makefile ../app_make.txt
$(CC1) -o $*.gas $*.c
%.nas : %.gas Makefile ../app_make.txt
$(GAS2NASK) $*.gas $*.nas
%.obj : %.nas Makefile ../app_make.txt
$(NASK) $*.nas $*.obj $*.lst
%.org : %.bim Makefile ../app_make.txt
$(BIM2HRB) $*.bim $*.org $(MALLOC)
%.hrb : %.org Makefile ../app_make.txt
$(BIM2BIN) -osacmp in:$*.org out:$*.hrb
# make run
# 由于目标 run 不存在,所以该规则下的命令将会被无条件执行,
# [1] 即制作额外包含可执行应用程序 $(APP).hrb,字库的映像文件;
# [2] 将映像文件拷贝到虚拟机 qemu.exe 同目录的 fdimage0.bin 中;
# [3] 启动虚拟机 qemu.exe 加载 fdimage0.bin 运行。
run :
$(MAKE) haribote.img
$(COPY) haribote.img ..\\..\\z_tools\\qemu\\fdimage0.bin
$(MAKE) -C ../../z_tools/qemu
# make full
# 由于目标 full 不存在,所以该规则下的命令将会被无条件执行,
# [1] 到库文件所在目录执行 make 生成系统调用库文件;
# [2] 生成可执行应用程序 $(APP).hrb
full :
$(MAKE) -C $(APILIBPATH)
$(MAKE) $(APP).hrb
# make run_full
# 由于目标 run_full 不存在,所以该规则下的命令将会被无条件执行,
# [1] 到库文件所在目录执行 make 生成系统调用库文件;
# [2] 到操作系统目录下执行 make 命令生成操作系统内核文件;
# [3] 在虚拟机 qemu.exe 中运行操作系统。
run_full :
$(MAKE) -C $(APILIBPATH)
$(MAKE) -C ../haribote
$(MAKE) run
# make clean
# 由于目标 clean 不存在,所以该规则下的命令将会被无条件执行,
# 即删除由 make 解析本 Makefile 时生成的中间文件。
clean :
-$(DEL) *.lst
-$(DEL) *.obj
-$(DEL) *.map
-$(DEL) *.bim
-$(DEL) *.org
-$(DEL) haribote.img
# make src_only
# 由于目标 src_only 不存在,所以该规则下的命令将会被无条件执行,
# 即删除由 make 解析本 Makefile 时生成所有文件,只保留源文件。
src_only :
$(MAKE) clean
-$(DEL) $(APP).hrb
a/Makefile
# 应用程序 a.c Makefile
# 可执行应用程序名,应用程序栈内存大小,应用程序堆内存大小 变量
APP = a
STACK = 1k
MALLOC = 0k
# 将上层目录的 app_make.txt 内容拷贝到此处,
# 看看上层目录 app_make.txt 的内容吧。
include ../app_make.txt
# ../app_make.txt 也会生成 $(APP).hrb,会不会冲突呢
$(APP).hrb : $(APP).org Makefile
$(COPY) $(APP).org $(APP).hrb
bball/Makefile
# 应用程序 bball.c Makefile
# 可执行应用程序名,应用程序栈内存大小,应用程序堆内存大小 变量
APP = bball
STACK = 52k
MALLOC = 0k
# 将上层目录的 app_make.txt 内容拷贝到此处
include ../app_make.txt
beepdown/Makefile
# 应用程序 beepdown.c Makefile
# 可执行应用程序名,应用程序栈内存大小,应用程序堆内存大小 变量
APP = beepdown
STACK = 1k
MALLOC = 40k
# 将上层目录的 app_make.txt 内容拷贝到此处
include ../app_make.txt
calc/Makefile
# 应用程序 calc.c Makefile
# 可执行应用程序名,应用程序栈内存大小,应用程序堆内存大小 变量
APP = calc
STACK = 4k
MALLOC = 0k
# 将上层目录的 app_make.txt 内容拷贝到此处
include ../app_make.txt
chklang/Makefile
# 应用程序 chklang.c Makefile
# 可执行应用程序名,应用程序栈内存大小,应用程序堆内存大小 变量
APP = chklang
STACK = 1k
MALLOC = 0k
# 将上层目录的 app_make.txt 内容拷贝到此处
include ../app_make.txt
color/Makefile
# 应用程序 color.c Makefile
# 可执行应用程序名,应用程序栈内存大小,应用程序堆内存大小 变量
APP = color
STACK = 1k
MALLOC = 56k
# 将上层目录的 app_make.txt 内容拷贝到此处
include ../app_make.txt
color2/Makefile
# 应用程序 color2.c Makefile
# 可执行应用程序名,应用程序栈内存大小,应用程序堆内存大小 变量
APP = color2
STACK = 1k
MALLOC = 56k
# 将上层目录的 app_make.txt 内容拷贝到此处
include ../app_make.txt
gview/Makefile
# 应用程序 gview Makefile, 因为有多个源文件,所以没有使用../app_make.txt
# 可执行应用程序名,应用程序栈内存大小,应用程序堆内存大小 变量
APP = gview
STACK = 4480k
MALLOC = 0k
# haribote 工具路径,依赖头文件路径,内核程序路径,可根据实际目录更改
TOOLPATH = ../../z_tools/
INCPATH = ../../z_tools/haribote/
APILIBPATH = ../apilib/
HARIBOTEPATH = ../haribote/
# make 是解析 Makefile 的工具;
# nask.exe 是汇编编译器;
# ccl.exe 是C程序编译器;
# gas2nask.exe,obj2bim.exe,bin2obj.exe,bim2hrb.exe 是目标文件格式转换工具;
# makefont.exe 是将 hankaku.txt 文件转换为字库文件的工具;
# haribote.rul 相当于链接脚本;
# eding.exe 是制作映像文件的工具;
# imgtol.com 是将映像文件写入软盘的工具;
# golib00.exe 库文件制作工具;
# copy,del 是拷贝和删除命令。
MAKE = $(TOOLPATH)make.exe -r
NASK = $(TOOLPATH)nask.exe
CC1 = $(TOOLPATH)cc1.exe -I$(INCPATH) -I../ -Os -Wall -quiet
GAS2NASK = $(TOOLPATH)gas2nask.exe -a
OBJ2BIM = $(TOOLPATH)obj2bim.exe
MAKEFONT = $(TOOLPATH)makefont.exe
BIN2OBJ = $(TOOLPATH)bin2obj.exe
BIM2HRB = $(TOOLPATH)bim2hrb.exe
BIM2BIN = $(TOOLPATH)bim2bin.exe
RULEFILE = ../haribote.rul
EDIMG = $(TOOLPATH)edimg.exe
IMGTOL = $(TOOLPATH)imgtol.com
GOLIB = $(TOOLPATH)golib00.exe
COPY = copy
DEL = del
# make 默认解析规则,
# 即解析 $(APP).hrb 目标所在规则
default :
$(MAKE) $(APP).hrb
# 由第4条隐式规则触发被解析,即依赖 $(APP).obj 生成 $(APP).bim,
# 且触发目标为 $(APP).obj 规则的解析,即匹配第3条隐式规则被解析,即触发生成
# $(APP).obj bmp.obj jpeg.obj。
$(APP).bim : $(APP).obj bmp.obj jpeg.obj $(APILIBPATH)apilib.lib Makefile
$(OBJ2BIM) @$(RULEFILE) out:$(APP).bim map:$(APP).map stack:$(STACK) \\
$(APP).obj jpeg.obj bmp.obj $(APILIBPATH)apilib.lib
# 由 make run 触发解析,将应用程序加入映像文件中
haribote.img : ../haribote/ipl20.bin ../haribote/haribote.sys $(APP).hrb \\
Makefile
$(EDIMG) imgin:../../z_tools/fdimg0at.tek \\
wbinimg src:../haribote/ipl20.bin len:512 from:0 to:0 \\
copy from:../haribote/haribote.sys to:@: \\
copy from:$(APP).hrb to:@: \\
copy from:../nihongo/nihongo.fnt to:@: \\
imgout:haribote.img
# 以下是5条隐式规则,自动变量 $* 代表目标命名中 % 之前部分命名;
# 第5条隐式规则由目标 default 下的命令 make $(APP).hrb 触发解析
# 即触发解析规则
# $(APP).hrb : $(APP).org Makefile
# $(BIM2BIN) -osacmp in:$*.org out:$*.hrb
# 第5条规则触发解析第4条规则,第4条规则触发解析 $(APP).bim 目标所
# 在规则的解析,该规则将触发第3条隐式规则的解析,遂触发第2,1条规则
# 被解析,从而完成由源文件 $(APP).C 生成可执行程序 $(APP).hrb。
#
# 先决依赖文件后缀为 .gas 的规则将触发该规则被解析,即根据C源文件
# 生成同名的 .gas 文件。
%.gas : %.c ../apilib.h Makefile
$(CC1) -o $*.gas $*.c
# 先决依赖文件后缀为 .nas 的规则将触发该规则被解析,即根据 .gas 文
# 件生成同名的 .nas 文件。
%.nas : %.gas Makefile
$(GAS2NASK) $*.gas $*.nas
# 先决依赖文件后缀为 .obj 的规则将触发该规则被解析,即根据 .nas 文
# 件生成同名的 .obj 文件。
%.obj : %.nas Makefile
$(NASK) $*.nas $*.obj $*.lst
# 先决依赖文件后缀为 .org 的规则将触发该规则被解析,即根据 .bim 文
# 件生成同名的 .org 文件。
%.org : %.bim Makefile
$(BIM2HRB) $*.bim $*.org $(MALLOC)
# 先决依赖文件后缀为 .hrb 的规则将触发该规则被解析,即根据 .org 文
# 件生成同名的 .hrb 文件。
%.hrb : %.org Makefile
$(BIM2BIN) -osacmp in:$*.org out:$*.hrb
# make run
# 由于目标 run 不存在,所以该规则下的命令会被无条件执行
# [1] 生成包含内核和本可执行应用程序映像文件;
# [2] 将映像文件拷贝到虚拟机同目录的 fdimage0.bin 中;
# [3] 启动虚拟机 qemu.exe 加载 fdimage0.bin 运行。
run :
$(MAKE) haribote.img
$(COPY) haribote.img ..\\..\\z_tools\\qemu\\fdimage0.bin
$(MAKE) -C ../../z_tools/qemu
# make full
# 由于目标 full 不存在,所以该规则下的命令会被无条件执行
# [1] 重新生成系统调用库;
# [2] 重新生成本可执行应用程序。
full :
$(MAKE) -C $(APILIBPATH)
$(MAKE) $(APP).hrb
# make run_full
# 由于目标 run_full 不存在,所以该规则下的命令会被无条件执行
# [1] 重新生成系统调用库;
# [2] 重新生成内核文件;
# [3] 启动虚拟机 qemu.exe 运行程序。
run_full :
$(MAKE) -C $(APILIBPATH)
$(MAKE) -C ../haribote
$(MAKE) run
# make clean
# 由于目标 clean 不存在,所以该规则下的命令会被无条件执行
# 删除由 make 解析本 Makefile 生成的中间文件。
clean :
-$(DEL) *.lst
-$(DEL) gview.obj
-$(DEL) jpeg.obj
-$(DEL) *.map
-$(DEL) *.bim
-$(DEL) *.org
-$(DEL) haribote.img
# make src_only
# 由于目标 src_only 不存在,所以该规则下的命令会被无条件执行
# 删除由 make 解析本 Makefile 生成的所有文件,即只保留源文件。
src_only :
$(MAKE) clean
-$(DEL) $(APP).hrb
hello3/Makefile
# 应用程序 hello3.c Makefile
# 可执行应用程序名,应用程序栈内存大小,应用程序堆内存大小 变量
APP = hello3
STACK = 1k
MALLOC = 0k
# 将上层目录的 app_make.txt 内容拷贝到此处
include ../app_make.txt
hello4/Makefile
# 应用程序 hello4.c Makefile
# 可执行应用程序名,应用程序栈内存大小,应用程序堆内存大小 变量
APP = hello4
STACK = 1k
MALLOC = 0k
# 将上层目录的 app_make.txt 内容拷贝到此处
include ../app_make.txt
# ../app_make.txt 也会生成 $(APP).hrb,会不会冲突呢
$(APP).hrb : $(APP).org Makefile
$(COPY) $(APP).org $(APP).hrb
hello5/Makefile
# 应用程序 hello5.c Makefile
# 可执行应用程序名,应用程序栈内存大小,应用程序堆内存大小 变量
APP = hello5
STACK = 1k
MALLOC = 0k
# 将上层目录的 app_make.txt 内容拷贝到此处
include ../app_make.txt
# ../app_make.txt 也会生成 $(APP).hrb,会不会冲突呢
$(APP).hrb : $(APP).org Makefile
$(COPY) $(APP).org $(APP).hrb
invader/Makefile
# 应用程序 invader.c Makefile
# 可执行应用程序名,应用程序栈内存大小,应用程序堆内存大小 变量
APP = invader
STACK = 90k
MALLOC = 0k
# 将上层目录的 app_make.txt 内容拷贝到此处
include ../app_make.txt
iroha/Makefile
# 应用程序 iroha.c Makefile
# 可执行应用程序名,应用程序栈内存大小,应用程序堆内存大小 变量
APP = iroha
STACK = 1k
MALLOC = 0k
# 将上层目录的 app_make.txt 内容拷贝到此处
include ../app_make.txt
# ../app_make.txt 也会生成 $(APP).hrb,会不会冲突呢
$(APP).hrb : $(APP).org Makefile
$(COPY) $(APP).org $(APP).hrb
lines/Makefile
# 应用程序 lines.c Makefile
# 可执行应用程序名,应用程序栈内存大小,应用程序堆内存大小 变量
APP = lines
STACK = 1k
MALLOC = 48k
# 将上层目录的 app_make.txt 内容拷贝到此处
include ../app_make.txt
mmlplay/Makefile
# 应用程序 mmlplay.c Makefile
# 可执行应用程序名,应用程序栈内存大小,应用程序堆内存大小 变量
APP = mmlplay
STACK = 132k
MALLOC = 0k
# 将上层目录的 app_make.txt 内容拷贝到此处
include ../app_make.txt
noodle/Makefile
# 应用程序 noodle.c Makefile
# 可执行应用程序名,应用程序栈内存大小,应用程序堆内存大小 变量
APP = noodle
STACK = 1k
MALLOC 以上是关于haribote系统调用 工程管理及应用程序阅读注释的主要内容,如果未能解决你的问题,请参考以下文章
haribote bootpack.c 主任务程序代码阅读注释
haribote naskfunc.nas 汇编函数接口程序阅读注释