├── LICENSE ├── README.md ├── 项目1_接管裸机的控制权 ├── README.md ├── assets │ ├── 1552226408291.png │ ├── 1552227242908.png │ ├── 1552271147394.png │ ├── 1552272581692.png │ ├── 1552467657158.png │ ├── 1552467788784.png │ ├── 1552468513604.png │ ├── 1552468550884.png │ ├── 1552468565052.png │ ├── 1552468583545.png │ ├── 1552703419649.png │ ├── 1552703642857.png │ ├── 1552703678270.png │ ├── 1552703748635.png │ ├── 1552703937800.png │ ├── 1552704456384.png │ └── 1552704577646.png ├── jed_stone.img └── src │ └── jed_stone.asm ├── 项目2_加载用户程序的监控程序 ├── JedOS_v1.0.img ├── README.md ├── assets │ ├── 1552468988623.png │ ├── 1552469596237.png │ ├── 1552469611675.png │ ├── 1552478989633.png │ ├── 1552478996468.png │ ├── 1552625507750.png │ ├── 1552625533434.png │ ├── 1552625555420.png │ ├── 1552626559519.png │ ├── 1552626677030.png │ ├── 1552626741275.png │ ├── 1552626893982.png │ ├── 1552626947654.png │ ├── 1552626975346.png │ ├── 1552626977256.png │ ├── 1552627004777.png │ ├── 1552627055247.png │ ├── 1552627079259.png │ ├── 1552627081929.png │ ├── 1552703748635.png │ └── flowchart.png └── src │ ├── bootloader.asm │ ├── header.asm │ ├── merge.sh │ ├── oskernel.asm │ ├── stone_bottomleft.asm │ ├── stone_bottomright.asm │ ├── stone_topleft.asm │ └── stone_topright.asm ├── 项目3_开发独立内核的操作系统 ├── JedOS_v1.1.img ├── README.md ├── assets │ ├── 1553611177143.png │ ├── 1553780851523.png │ ├── 1553780865303.png │ ├── 1553780904935.png │ ├── 1553780922256.png │ ├── 1553780938859.png │ ├── 1553780961276.png │ ├── 1553780981119.png │ ├── 1553781070065.png │ ├── 1553781095424.png │ ├── 1553781332383.png │ └── 1553781404384.png └── src │ ├── bootloader.asm │ ├── liba.asm │ ├── libc.c │ ├── merge.sh │ ├── oskernel.asm │ ├── stringio.h │ ├── usrprog │ ├── header.asm │ ├── stone_bottomleft.asm │ ├── stone_bottomright.asm │ ├── stone_topleft.asm │ └── stone_topright.asm │ └── usrproginfo.asm ├── 项目4_异步事件编程技术 ├── JedOS_v1.2.img ├── README.md ├── assets │ ├── 1554294052391.png │ ├── 1554294135211.png │ ├── 1554294369607.png │ ├── 1554294409851.png │ ├── 1554294500818.png │ ├── 1554294601065.png │ ├── 1554294731399.png │ ├── 1554294799321.png │ ├── 1554294819285.png │ ├── 1554294929011.png │ ├── 1554294940443.png │ ├── 1554294985104.png │ ├── 1554344609435.png │ ├── 1554344612831.png │ ├── 1554344812737.png │ └── 1554344923054.png └── src │ ├── bootloader.asm │ ├── hotwheel.asm │ ├── kernel.c │ ├── liba.asm │ ├── macro.asm │ ├── merge.sh │ ├── osstarter.asm │ ├── stringio.h │ ├── usrprog │ ├── intcaller.asm │ ├── interrupt │ │ ├── int33~36.asm │ │ └── intouch.asm │ ├── stone_bottomleft.asm │ ├── stone_bottomright.asm │ ├── stone_topleft.asm │ └── stone_topright.asm │ └── usrproginfo.asm ├── 项目5_实现系统调用 ├── JedOS_v1.3.img ├── README.md ├── assets │ ├── 1555727545043.png │ ├── 1555727712376.png │ ├── 1555727791792.png │ ├── 1555727843599.png │ ├── 1555727947447.png │ ├── 1555727993888.png │ ├── 1555728178849.png │ ├── 1555728215973.png │ ├── 1555728244608.png │ └── 1555728336372.png └── src │ ├── bootloader.asm │ ├── hotwheel.asm │ ├── kernel.c │ ├── lib │ ├── systema.asm │ └── systemc.c │ ├── liba.asm │ ├── macro.asm │ ├── merge.sh │ ├── osstarter.asm │ ├── stringio.h │ ├── usrprog │ ├── interrupt │ │ ├── int33h~36h.asm │ │ └── intouch.asm │ ├── interrupt_caller.asm │ ├── stone_bottomleft.asm │ ├── stone_bottomright.asm │ ├── stone_topleft.asm │ ├── stone_topright.asm │ └── syscall_test.asm │ └── usrproginfo.asm ├── 项目6_二状态进程模型 ├── .DS_Store ├── JedOS_v1.4.img ├── README.md ├── assets │ ├── 1557309403947.png │ ├── 1557309533854.png │ ├── 1557309553962.png │ ├── 1557309658467.png │ ├── 1557309727124.png │ ├── 1557309820907.png │ ├── 1557309879043.png │ ├── 1557408924509.png │ ├── 1557409096988.png │ ├── 1557409127112.png │ ├── 1557409179309.png │ ├── 1557409199900.png │ ├── 1557409228348.png │ ├── 1557409248148.png │ ├── 1557409259884.png │ ├── 1557409284078.png │ └── 1557409695499.png └── src │ ├── bootloader.asm │ ├── kernel.c │ ├── lib │ ├── systema.asm │ └── systemc.c │ ├── liba.asm │ ├── macro.asm │ ├── merge.sh │ ├── multiprocess.asm │ ├── osstarter.asm │ ├── stringio.h │ ├── usrprog │ ├── interrupt │ │ ├── int33h~36h.asm │ │ ├── intouch.asm │ │ ├── stone_bottomleft.asm │ │ ├── stone_bottomright.asm │ │ ├── stone_topleft.asm │ │ └── stone_topright.asm │ ├── interrupt_caller.asm │ ├── stone_bottomleft.asm │ ├── stone_bottomright.asm │ ├── stone_topleft.asm │ ├── stone_topright.asm │ └── syscall_test.asm │ └── usrproginfo.asm └── 项目7_进程控制与通信 ├── JedOS_v1.5.img ├── README.md ├── assets ├── 1559751636452.png ├── 1559751697219.png ├── 1559751965179.png ├── 1559752034244.png ├── 1559752143451.png ├── 1559752320162.png └── 1559752388595.png └── src ├── bootloader.asm ├── kernel.c ├── lib ├── systema.asm └── systemc.c ├── liba.asm ├── macro.asm ├── merge.sh ├── multiprocess.asm ├── osstarter.asm ├── process.h ├── stringio.h ├── usrprog ├── fork_test.asm ├── fork_test_c_version.c ├── fork_test_helper.asm ├── interrupt │ ├── int33h~36h.asm │ ├── intouch.asm │ ├── stone_bottomleft.asm │ ├── stone_bottomright.asm │ ├── stone_topleft.asm │ └── stone_topright.asm ├── interrupt_caller.asm ├── stone_bottomleft.asm ├── stone_bottomright.asm ├── stone_topleft.asm ├── stone_topright.asm └── syscall_test.asm └── usrproginfo.asm /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Jed Zhang 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 操作系统原理实验(课程项目) 2 | 3 | * 中山大学计算机学院 4 | * 操作系统原理实验(Operating Systems Laboratory, DCS218) 5 | * 教师:凌应标 6 | * 2018-2019 学年第二学期(大二下) 7 | 8 | 9 | ## 实验目录 10 | 11 | | 序号 | 名称 | 简介 | 镜像文件 | 成绩 | 12 | | ---- | ------------------------------------------------------ | ------------------------------------------------------ | ------------------------------------------------------------ | ---- | 13 | | 1 | [接管裸机的控制权](项目1_接管裸机的控制权) | 在裸机(虚拟机)上运行自己的程序 | [jed_stone.img](项目1_接管裸机的控制权/jed_stone.img?raw=true) | A++ | 14 | | 2 | [加载用户程序的监控程序](项目2_加载用户程序的监控程序) | 实现监控程序(原始操作系统)执行用户程序这一项基本功能 | [JedOS_v1.0.img](项目2_加载用户程序的监控程序/JedOS_v1.0.img?raw=true) | A++ | 15 | | 3 | [开发独立内核的操作系统](项目3_开发独立内核的操作系统) | 用C和汇编实现操作系统内核,并增加批处理能力 | [JedOS_v1.1.img](项目3_开发独立内核的操作系统/JedOS_v1.1.img?raw=true) | A+++ | 16 | | 4 | [异步事件编程技术](项目4_异步事件编程技术) | 用时钟中断、键盘中断等处理异步事件 | [JedOS_v1.2.img](项目4_异步事件编程技术/JedOS_v1.2.img?raw=true) | A+++ | 17 | | 5 | [实现系统调用](项目5_实现系统调用) | 实现原型操作系统中一些基本的系统调用 | [JedOS_v1.3.img](项目5_实现系统调用/JedOS_v1.3.img?raw=true) | A++ | 18 | | 6 | [二状态进程模型](项目6_二状态进程模型) | 多进程分时系统,采用时间片轮转调度进程运行 | [JedOS_v1.4.img](项目6_二状态进程模型/JedOS_v1.4.img?raw=true) | A+++ | 19 | | 7 | [进程控制与通信](项目7_进程控制与通信) | 五状态进程模型,支持 fork、wait 和 exit | [JedOS_v1.5.img](项目7_进程控制与通信/JedOS_v1.5.img?raw=true) | A+++ | 20 | 21 | 22 | 23 | ## 特色 24 | 25 | * GCC + NASM 实模式(16 位兼容的 32 位代码); 26 | * 使用 Shell 脚本自动编译、链接、整合; 27 | * 未经美化的界面 28 | * 软盘镜像仅在 VMware Workstation Pro 15 中测试过; 29 | * 详细的实验报告文档。 30 | 31 | 32 | ## License 33 | 34 | MIT 35 | -------------------------------------------------------------------------------- /项目1_接管裸机的控制权/assets/1552226408291.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目1_接管裸机的控制权/assets/1552226408291.png -------------------------------------------------------------------------------- /项目1_接管裸机的控制权/assets/1552227242908.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目1_接管裸机的控制权/assets/1552227242908.png -------------------------------------------------------------------------------- /项目1_接管裸机的控制权/assets/1552271147394.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目1_接管裸机的控制权/assets/1552271147394.png -------------------------------------------------------------------------------- /项目1_接管裸机的控制权/assets/1552272581692.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目1_接管裸机的控制权/assets/1552272581692.png -------------------------------------------------------------------------------- /项目1_接管裸机的控制权/assets/1552467657158.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目1_接管裸机的控制权/assets/1552467657158.png -------------------------------------------------------------------------------- /项目1_接管裸机的控制权/assets/1552467788784.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目1_接管裸机的控制权/assets/1552467788784.png -------------------------------------------------------------------------------- /项目1_接管裸机的控制权/assets/1552468513604.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目1_接管裸机的控制权/assets/1552468513604.png -------------------------------------------------------------------------------- /项目1_接管裸机的控制权/assets/1552468550884.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目1_接管裸机的控制权/assets/1552468550884.png -------------------------------------------------------------------------------- /项目1_接管裸机的控制权/assets/1552468565052.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目1_接管裸机的控制权/assets/1552468565052.png -------------------------------------------------------------------------------- /项目1_接管裸机的控制权/assets/1552468583545.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目1_接管裸机的控制权/assets/1552468583545.png -------------------------------------------------------------------------------- /项目1_接管裸机的控制权/assets/1552703419649.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目1_接管裸机的控制权/assets/1552703419649.png -------------------------------------------------------------------------------- /项目1_接管裸机的控制权/assets/1552703642857.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目1_接管裸机的控制权/assets/1552703642857.png -------------------------------------------------------------------------------- /项目1_接管裸机的控制权/assets/1552703678270.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目1_接管裸机的控制权/assets/1552703678270.png -------------------------------------------------------------------------------- /项目1_接管裸机的控制权/assets/1552703748635.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目1_接管裸机的控制权/assets/1552703748635.png -------------------------------------------------------------------------------- /项目1_接管裸机的控制权/assets/1552703937800.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目1_接管裸机的控制权/assets/1552703937800.png -------------------------------------------------------------------------------- /项目1_接管裸机的控制权/assets/1552704456384.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目1_接管裸机的控制权/assets/1552704456384.png -------------------------------------------------------------------------------- /项目1_接管裸机的控制权/assets/1552704577646.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目1_接管裸机的控制权/assets/1552704577646.png -------------------------------------------------------------------------------- /项目1_接管裸机的控制权/jed_stone.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目1_接管裸机的控制权/jed_stone.img -------------------------------------------------------------------------------- /项目1_接管裸机的控制权/src/jed_stone.asm: -------------------------------------------------------------------------------- 1 | ; jed_stone.asm 2 | ; 原作:凌应标 2014-03 3 | ; 改写:张怡昕(17341203) 2019-03 4 | ; 说明:本程序在文本方式显示器上从左边射出一个字符,以45度向右下运动,撞到边框后反射。 5 | 6 | Dn_Rt equ 1 ; D-Down,U-Up,R-right,L-Left 7 | Up_Rt equ 2 8 | Up_Lt equ 3 9 | Dn_Lt equ 4 10 | delay equ 50000 ; 计时器延迟计数,用于控制画框的速度 11 | ddelay equ 580 ; 计时器延迟计数,用于控制画框的速度 12 | 13 | org 7C00h ; 程序装载到7C00h,这里存放的是主引导记录 14 | 15 | start: 16 | mov ax,cs 17 | mov es,ax ; ES = CS 18 | mov ds,ax ; DS = CS 19 | mov es,ax ; ES = CS 20 | mov ax,0B800h 21 | mov gs,ax ; GS = B800h,指向文本模式的显示缓冲区 22 | mov byte[char],'X' 23 | 24 | loop1: 25 | dec word[count] ; 递减计数变量 26 | jnz loop1 ; >0:跳转; 27 | mov word[count],delay 28 | dec word[dcount] ; 递减计数变量 29 | jnz loop1 30 | mov word[count],delay 31 | mov word[dcount],ddelay 32 | 33 | mov al,1 34 | cmp al,byte[rdul] 35 | jz DnRt 36 | mov al,2 37 | cmp al,byte[rdul] 38 | jz UpRt 39 | mov al,3 40 | cmp al,byte[rdul] 41 | jz UpLt 42 | mov al,4 43 | cmp al,byte[rdul] 44 | jz DnLt 45 | ; jmp $ 46 | 47 | DnRt: 48 | inc word[x] 49 | inc word[y] 50 | mov bx,word[x] 51 | mov ax,screenh 52 | sub ax,bx 53 | jz dr2ur 54 | mov bx,word[y] 55 | mov ax,screenw 56 | sub ax,bx 57 | jz dr2dl 58 | jmp show 59 | 60 | dr2ur: 61 | mov word[x],paddingh 62 | mov byte[rdul],Up_Rt 63 | jmp show 64 | 65 | dr2dl: 66 | mov word[y],paddingw 67 | mov byte[rdul],Dn_Lt 68 | jmp show 69 | 70 | 71 | UpRt: 72 | dec word[x] 73 | inc word[y] 74 | mov bx,word[y] 75 | mov ax,screenw 76 | sub ax,bx 77 | jz ur2ul 78 | mov bx,word[x] 79 | mov ax,-1 80 | sub ax,bx 81 | jz ur2dr 82 | jmp show 83 | 84 | ur2ul: 85 | mov word[y],paddingw 86 | mov byte[rdul],Up_Lt 87 | jmp show 88 | 89 | ur2dr: 90 | mov word[x],1 91 | mov byte[rdul],Dn_Rt 92 | jmp show 93 | 94 | 95 | UpLt: 96 | dec word[x] 97 | dec word[y] 98 | mov bx,word[x] 99 | mov ax,-1 100 | sub ax,bx 101 | jz ul2dl 102 | mov bx,word[y] 103 | mov ax,-1 104 | sub ax,bx 105 | jz ul2ur 106 | jmp show 107 | 108 | ul2dl: 109 | mov word[x],1 110 | mov byte[rdul],Dn_Lt 111 | jmp show 112 | ul2ur: 113 | mov word[y],1 114 | mov byte[rdul],Up_Rt 115 | jmp show 116 | 117 | DnLt: 118 | inc word[x] 119 | dec word[y] 120 | mov bx,word[y] 121 | mov ax,-1 122 | sub ax,bx 123 | jz dl2dr 124 | mov bx,word[x] 125 | mov ax,screenh 126 | sub ax,bx 127 | jz dl2ul 128 | jmp show 129 | 130 | dl2dr: 131 | mov word[y],1 132 | mov byte[rdul],Dn_Rt 133 | jmp show 134 | 135 | dl2ul: 136 | mov word[x],paddingh 137 | mov byte[rdul],Up_Lt 138 | jmp show 139 | 140 | show: 141 | xor ax,ax ; 计算显存地址 142 | mov ax,word[x] 143 | mov bx,80 144 | mul bx 145 | add ax,word[y] 146 | mov bx,2 147 | mul bx 148 | mov bp,ax 149 | mov ah,[curcolor2] ; 弹字符的背景色和前景色(默认值为07h,详见文档) 150 | inc byte[curcolor2] 151 | cmp byte[curcolor2], 0fh 152 | jnz skip 153 | mov byte[curcolor2], 1 ; 为了不改变背景色 154 | skip: 155 | mov al,byte[char] ; AL = 显示字符值(默认值为20h=空格符) 156 | mov word[gs:bp],ax ; 显示字符的ASCII码值 157 | 158 | mov si, myinfo ; 显示姓名和学号 159 | mov di, 2 160 | mov cx, word[infolen] 161 | loop2: ; 显示myinfo中的每个字符 162 | mov al, byte[ds:si] 163 | inc si 164 | mov ah, [curcolor] ; 背景色和前景色 165 | add byte[curcolor], 12h ; 变色,该数字可随意调节以达到不错的效果 166 | mov word [gs:di],ax 167 | add di,2 168 | loop loop2 169 | 170 | jmp loop1 171 | 172 | end: 173 | jmp $ ; 停止画框,无限循环 174 | 175 | DataArea: 176 | count dw delay 177 | dcount dw ddelay 178 | rdul db Dn_Rt ; 向右下运动 179 | char db 0 180 | 181 | screenw equ 80 ; 屏幕宽度字符数 182 | screenh equ 25 ; 屏幕高度字符数 183 | x dw 7 ; 起始行数 184 | y dw 0 ; 起始列数 185 | paddingw equ screenw-2 186 | paddingh equ screenh-2 187 | 188 | myinfo db ' Zhang Yixin, 17341203 ' 189 | infolen dw $-myinfo ; myinfo字符串的长度 190 | curcolor db 80h ; 保存当前字符颜色属性,用于myinfo 191 | curcolor2 db 09h ; 保存当前字符颜色属性,用于移动的字符 192 | 193 | times 510-($-$$) db 0 ; 填充0,一直到第510字节 194 | db 55h, 0AAh ; 扇区末尾两个字节为0x55和0xAA -------------------------------------------------------------------------------- /项目2_加载用户程序的监控程序/JedOS_v1.0.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目2_加载用户程序的监控程序/JedOS_v1.0.img -------------------------------------------------------------------------------- /项目2_加载用户程序的监控程序/assets/1552468988623.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目2_加载用户程序的监控程序/assets/1552468988623.png -------------------------------------------------------------------------------- /项目2_加载用户程序的监控程序/assets/1552469596237.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目2_加载用户程序的监控程序/assets/1552469596237.png -------------------------------------------------------------------------------- /项目2_加载用户程序的监控程序/assets/1552469611675.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目2_加载用户程序的监控程序/assets/1552469611675.png -------------------------------------------------------------------------------- /项目2_加载用户程序的监控程序/assets/1552478989633.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目2_加载用户程序的监控程序/assets/1552478989633.png -------------------------------------------------------------------------------- /项目2_加载用户程序的监控程序/assets/1552478996468.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目2_加载用户程序的监控程序/assets/1552478996468.png -------------------------------------------------------------------------------- /项目2_加载用户程序的监控程序/assets/1552625507750.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目2_加载用户程序的监控程序/assets/1552625507750.png -------------------------------------------------------------------------------- /项目2_加载用户程序的监控程序/assets/1552625533434.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目2_加载用户程序的监控程序/assets/1552625533434.png -------------------------------------------------------------------------------- /项目2_加载用户程序的监控程序/assets/1552625555420.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目2_加载用户程序的监控程序/assets/1552625555420.png -------------------------------------------------------------------------------- /项目2_加载用户程序的监控程序/assets/1552626559519.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目2_加载用户程序的监控程序/assets/1552626559519.png -------------------------------------------------------------------------------- /项目2_加载用户程序的监控程序/assets/1552626677030.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目2_加载用户程序的监控程序/assets/1552626677030.png -------------------------------------------------------------------------------- /项目2_加载用户程序的监控程序/assets/1552626741275.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目2_加载用户程序的监控程序/assets/1552626741275.png -------------------------------------------------------------------------------- /项目2_加载用户程序的监控程序/assets/1552626893982.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目2_加载用户程序的监控程序/assets/1552626893982.png -------------------------------------------------------------------------------- /项目2_加载用户程序的监控程序/assets/1552626947654.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目2_加载用户程序的监控程序/assets/1552626947654.png -------------------------------------------------------------------------------- /项目2_加载用户程序的监控程序/assets/1552626975346.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目2_加载用户程序的监控程序/assets/1552626975346.png -------------------------------------------------------------------------------- /项目2_加载用户程序的监控程序/assets/1552626977256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目2_加载用户程序的监控程序/assets/1552626977256.png -------------------------------------------------------------------------------- /项目2_加载用户程序的监控程序/assets/1552627004777.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目2_加载用户程序的监控程序/assets/1552627004777.png -------------------------------------------------------------------------------- /项目2_加载用户程序的监控程序/assets/1552627055247.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目2_加载用户程序的监控程序/assets/1552627055247.png -------------------------------------------------------------------------------- /项目2_加载用户程序的监控程序/assets/1552627079259.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目2_加载用户程序的监控程序/assets/1552627079259.png -------------------------------------------------------------------------------- /项目2_加载用户程序的监控程序/assets/1552627081929.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目2_加载用户程序的监控程序/assets/1552627081929.png -------------------------------------------------------------------------------- /项目2_加载用户程序的监控程序/assets/1552703748635.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目2_加载用户程序的监控程序/assets/1552703748635.png -------------------------------------------------------------------------------- /项目2_加载用户程序的监控程序/assets/flowchart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目2_加载用户程序的监控程序/assets/flowchart.png -------------------------------------------------------------------------------- /项目2_加载用户程序的监控程序/src/bootloader.asm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目2_加载用户程序的监控程序/src/bootloader.asm -------------------------------------------------------------------------------- /项目2_加载用户程序的监控程序/src/header.asm: -------------------------------------------------------------------------------- 1 | offset_oskernel equ 0A100h 2 | 3 | offset_usrprog1 equ 0A300h 4 | offset_usrprog2 equ 0A700h 5 | offset_usrprog3 equ 0AB00h 6 | offset_usrprog4 equ 0AF00h 7 | 8 | ; 用于在指定位置显示字符串,参数:(字符串首地址, 字符串字节数, 行数, 列数) 9 | %macro PRINT_IN_POS 4 10 | pusha ; 保护现场 11 | mov ax, cs ; 置其他段寄存器值与CS相同 12 | mov ds, ax ; 数据段 13 | mov bp, %1 ; BP=当前串的偏移地址 14 | mov ax, ds ; ES:BP = 串地址 15 | mov es, ax ; 置ES=DS 16 | mov cx, %2 ; CX = 串长(=9) 17 | mov ax, 1301h ; AH = 13h(功能号)、AL = 01h(光标置于串尾) 18 | mov bx, 0007h ; 页号为0(BH = 0) 黑底白字(BL = 07h) 19 | mov dh, %3 ; 行号=0 20 | mov dl, %4 ; 列号=0 21 | int 10h ; BIOS的10h功能:显示一行字符 22 | popa ; 恢复现场 23 | %endmacro -------------------------------------------------------------------------------- /项目2_加载用户程序的监控程序/src/merge.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | output_file="JedOS_v1.0.img" 4 | asm_files=("bootloader" "oskernel" "stone_topleft" "stone_topright" "stone_bottomleft" "stone_bottomright") 5 | 6 | 7 | rm -f ${output_file} 8 | 9 | for asm_file in ${asm_files[@]} 10 | do 11 | nasm ${asm_file}.asm -o ${asm_file}.img 12 | cat ${asm_file}.img >> "${output_file}" 13 | rm -f ${asm_file}.img 14 | echo "[+] ${asm_file} done" 15 | done 16 | 17 | echo "[+] ${output_file} generated successfully." -------------------------------------------------------------------------------- /项目2_加载用户程序的监控程序/src/oskernel.asm: -------------------------------------------------------------------------------- 1 | %include "header.asm" 2 | org 0A100h 3 | 4 | start: 5 | call ClearScreen ; 清屏 6 | PRINT_IN_POS str_title, titlelen, 5, 35 7 | PRINT_IN_POS str_subtitle, subtitlelen, 6, 29 8 | PRINT_IN_POS str_date, datelen, 8, 35 9 | PRINT_IN_POS str_hint1, hint1len, 15, 10 10 | 11 | Keyboard: 12 | mov ah, 0; Bochs: 0000:a173 13 | int 16h 14 | cmp al, '1'; 按下1 15 | je offset_usrprog1 ; 执行用户程序1 16 | cmp al, '2'; 按下2 17 | je offset_usrprog2 ; 执行用户程序2 18 | cmp al, '3'; 按下3 19 | je offset_usrprog3 ; 执行用户程序3 20 | cmp al, '4'; 按下4 21 | je offset_usrprog4 ; 执行用户程序14 22 | jmp Keyboard; 无效按键,重新等待用户按键 23 | 24 | ClearScreen: ; 函数:清屏 25 | pusha 26 | mov ax, 0003h 27 | int 10h ; 中断调用,清屏 28 | popa 29 | ret 30 | 31 | DataArea: 32 | str_title db 'JedOS V1.0' 33 | titlelen equ ($-str_title) 34 | 35 | str_subtitle db 'Zhang Yixin, 17341203' 36 | subtitlelen equ ($-str_subtitle) 37 | 38 | str_date db '2019-03-12' 39 | datelen equ ($-str_date) 40 | 41 | str_hint1 db 'Press a key (1/2/3/4) to run the corresponding user program!' 42 | hint1len equ ($-str_hint1) 43 | 44 | SectorEnding: 45 | times 510-($-$$) db 0 46 | db 0x55,0xaa -------------------------------------------------------------------------------- /项目2_加载用户程序的监控程序/src/stone_bottomleft.asm: -------------------------------------------------------------------------------- 1 | ; 原作:凌应标 2014-03 2 | ; 改写:张怡昕(17341203) 2019-03 3 | ; 说明:本程序是jed_stone.asm的改版。本程序在显示器左上角进行字符反弹。 4 | ; 参数:(-1, -1, 40, 13, 0, 7) 5 | %include "header.asm" 6 | org offset_usrprog3 7 | 8 | Dn_Rt equ 1 ; D-Down,U-Up,R-right,L-Left 9 | Up_Rt equ 2 10 | Up_Lt equ 3 11 | Dn_Lt equ 4 12 | delay equ 50000 ; 计时器延迟计数,用于控制画框的速度 13 | ddelay equ 580 ; 计时器延迟计数,用于控制画框的速度 14 | 15 | screen_left equ -1 ; 字符运动左边界 16 | screen_top equ 11 ; 字符运动上边界 17 | screen_right equ 40 ; 字符运动右边界 18 | screen_bottom equ 25 ; 字符运动下边界 19 | originpos_y equ 0 ; 起点列数 20 | originpos_x equ 19 ; 起点行数 21 | 22 | start: 23 | call ClearScreen ; 清屏 24 | mov ax,cs 25 | mov es,ax ; ES = CS 26 | mov ds,ax ; DS = CS 27 | mov es,ax ; ES = CS 28 | mov ax,0B800h 29 | mov gs,ax ; GS = B800h,指向文本模式的显示缓冲区 30 | mov byte[char],'X' 31 | 32 | PRINT_IN_POS hint1, hint1len, 3, 30 33 | 34 | initialize: ; 多次调用用户程序时,可保证初始值是相同的 35 | mov word[x], originpos_x 36 | mov word[y], originpos_y 37 | mov byte[curcolor], 80h 38 | mov byte[curcolor2], 01h 39 | mov word[count], delay 40 | mov word[dcount], ddelay 41 | mov byte[rdul], Dn_Rt ; 向右下运动 42 | 43 | loop1: 44 | dec word[count] ; 递减计数变量 45 | jnz loop1 ; >0:跳转; 46 | mov word[count],delay 47 | dec word[dcount] ; 递减计数变量 48 | jnz loop1 49 | mov word[count],delay 50 | mov word[dcount],ddelay 51 | 52 | mov al,1 53 | cmp al,byte[rdul] 54 | jz DnRt 55 | mov al,2 56 | cmp al,byte[rdul] 57 | jz UpRt 58 | mov al,3 59 | cmp al,byte[rdul] 60 | jz UpLt 61 | mov al,4 62 | cmp al,byte[rdul] 63 | jz DnLt 64 | ; jmp $ 65 | 66 | DnRt: 67 | inc word[x] 68 | inc word[y] 69 | mov bx,word[x] 70 | mov ax,screen_bottom 71 | sub ax,bx 72 | jz dr2ur 73 | mov bx,word[y] 74 | mov ax,screen_right 75 | sub ax,bx 76 | jz dr2dl 77 | jmp show 78 | 79 | dr2ur: 80 | mov word[x],screen_bottom-2 81 | mov byte[rdul],Up_Rt 82 | jmp show 83 | 84 | dr2dl: 85 | mov word[y],screen_right-2 86 | mov byte[rdul],Dn_Lt 87 | jmp show 88 | 89 | 90 | UpRt: 91 | dec word[x] 92 | inc word[y] 93 | mov bx,word[y] 94 | mov ax,screen_right 95 | sub ax,bx 96 | jz ur2ul 97 | mov bx,word[x] 98 | mov ax,screen_top 99 | sub ax,bx 100 | jz ur2dr 101 | jmp show 102 | 103 | ur2ul: 104 | mov word[y],screen_right-2 105 | mov byte[rdul],Up_Lt 106 | jmp show 107 | 108 | ur2dr: 109 | mov word[x],screen_top+2 110 | mov byte[rdul],Dn_Rt 111 | jmp show 112 | 113 | 114 | UpLt: 115 | dec word[x] 116 | dec word[y] 117 | mov bx,word[x] 118 | mov ax,screen_top 119 | sub ax,bx 120 | jz ul2dl 121 | mov bx,word[y] 122 | mov ax,screen_left 123 | sub ax,bx 124 | jz ul2ur 125 | jmp show 126 | 127 | ul2dl: 128 | mov word[x],screen_top+2 129 | mov byte[rdul],Dn_Lt 130 | jmp show 131 | ul2ur: 132 | mov word[y],screen_left+2 133 | mov byte[rdul],Up_Rt 134 | jmp show 135 | 136 | DnLt: 137 | inc word[x] 138 | dec word[y] 139 | mov bx,word[y] 140 | mov ax,screen_left 141 | sub ax,bx 142 | jz dl2dr 143 | mov bx,word[x] 144 | mov ax,screen_bottom 145 | sub ax,bx 146 | jz dl2ul 147 | jmp show 148 | 149 | dl2dr: 150 | mov word[y],screen_left+2 151 | mov byte[rdul],Dn_Rt 152 | jmp show 153 | 154 | dl2ul: 155 | mov word[x],screen_bottom-2 156 | mov byte[rdul],Up_Lt 157 | jmp show 158 | 159 | show: 160 | xor ax,ax ; 计算显存地址 161 | mov ax,word[x] 162 | mov bx,80 163 | mul bx 164 | add ax,word[y] 165 | mov bx,2 166 | mul bx 167 | mov bp,ax 168 | mov ah,[curcolor2] ; 弹字符的背景色和前景色(默认值为07h,详见文档) 169 | inc byte[curcolor2] 170 | cmp byte[curcolor2], 0fh 171 | jnz skip 172 | mov byte[curcolor2], 1 ; 为了不改变背景色 173 | skip: 174 | mov al,byte[char] ; AL = 显示字符值(默认值为20h=空格符) 175 | mov word[gs:bp],ax ; 显示字符的ASCII码值 176 | 177 | mov ah, 01h ; 功能号:查询键盘缓冲区但不等待 178 | int 16h 179 | jz continue ; 无键盘按下,继续 180 | cmp al, 27 ; 是否按下ESC 181 | je QuitUsrProg ; 若按下ESC,退出用户程序 182 | 183 | continue: 184 | jmp loop1 185 | 186 | end: 187 | jmp $ ; 停止画框,无限循环 188 | 189 | QuitUsrProg: 190 | jmp 0A100h ; 退出用户程序 191 | 192 | ClearScreen: ; 函数:清屏 193 | pusha 194 | mov ax, 0003h 195 | int 10h ; 中断调用,清屏 196 | popa 197 | ret 198 | 199 | DataArea: 200 | count dw delay 201 | dcount dw ddelay 202 | rdul db Dn_Rt ; 向右下运动 203 | char db 0 204 | 205 | x dw originpos_x 206 | y dw originpos_y 207 | 208 | myinfo db ' Zhang Yixin, 17341203 ' 209 | infolen dw $-myinfo ; myinfo字符串的长度 210 | curcolor db 80h ; 保存当前字符颜色属性,用于myinfo 211 | curcolor2 db 01h ; 保存当前字符颜色属性,用于移动的字符 212 | 213 | hint1 db 'User program 3 is running. Press ESC to exit.' 214 | hint1len equ ($-hint1) 215 | 216 | times 1022-($-$$) db 0 ; 填充0,一直到第1022字节 217 | db 55h, 0AAh ; 扇区末尾两个字节为0x55和0xAA -------------------------------------------------------------------------------- /项目3_开发独立内核的操作系统/JedOS_v1.1.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目3_开发独立内核的操作系统/JedOS_v1.1.img -------------------------------------------------------------------------------- /项目3_开发独立内核的操作系统/assets/1553611177143.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目3_开发独立内核的操作系统/assets/1553611177143.png -------------------------------------------------------------------------------- /项目3_开发独立内核的操作系统/assets/1553780851523.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目3_开发独立内核的操作系统/assets/1553780851523.png -------------------------------------------------------------------------------- /项目3_开发独立内核的操作系统/assets/1553780865303.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目3_开发独立内核的操作系统/assets/1553780865303.png -------------------------------------------------------------------------------- /项目3_开发独立内核的操作系统/assets/1553780904935.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目3_开发独立内核的操作系统/assets/1553780904935.png -------------------------------------------------------------------------------- /项目3_开发独立内核的操作系统/assets/1553780922256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目3_开发独立内核的操作系统/assets/1553780922256.png -------------------------------------------------------------------------------- /项目3_开发独立内核的操作系统/assets/1553780938859.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目3_开发独立内核的操作系统/assets/1553780938859.png -------------------------------------------------------------------------------- /项目3_开发独立内核的操作系统/assets/1553780961276.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目3_开发独立内核的操作系统/assets/1553780961276.png -------------------------------------------------------------------------------- /项目3_开发独立内核的操作系统/assets/1553780981119.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目3_开发独立内核的操作系统/assets/1553780981119.png -------------------------------------------------------------------------------- /项目3_开发独立内核的操作系统/assets/1553781070065.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目3_开发独立内核的操作系统/assets/1553781070065.png -------------------------------------------------------------------------------- /项目3_开发独立内核的操作系统/assets/1553781095424.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目3_开发独立内核的操作系统/assets/1553781095424.png -------------------------------------------------------------------------------- /项目3_开发独立内核的操作系统/assets/1553781332383.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目3_开发独立内核的操作系统/assets/1553781332383.png -------------------------------------------------------------------------------- /项目3_开发独立内核的操作系统/assets/1553781404384.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目3_开发独立内核的操作系统/assets/1553781404384.png -------------------------------------------------------------------------------- /项目3_开发独立内核的操作系统/src/bootloader.asm: -------------------------------------------------------------------------------- 1 | ; @Author: Jed 2 | ; @Description: 引导程序;本文件独立编译为二进制程序,与其他asm或C程序无关 3 | ; @Date: 2019-03-21 4 | ; @LastEditTime: 2019-03-23 5 | 6 | BITS 16 7 | org 7c00h 8 | 9 | offset_upinfo equ 7E00h ; 用户程序信息表被装入的位置 10 | offset_oskernel equ 8000h ; 操作系统内核被装入的位置 11 | 12 | global _start 13 | _start: 14 | mov ax, cs ; 置其他段寄存器值与CS相同 15 | mov ds, ax ; 数据段 16 | mov bp, load_msg ; BP=当前串的偏移地址 17 | mov ax, ds ; ES:BP = 串地址 18 | mov es, ax ; 置ES=DS 19 | mov cx, load_msg_len ; CX = 串长 20 | mov ax, 1301h ; AH = 13h(功能号)、AL = 01h(光标置于串尾) 21 | mov bx, 0007h ; 页号为0(BH = 0) 黑底白字(BL = 07h) 22 | mov dh, 0 ; 行号=0 23 | mov dl, 0 ; 列号=0 24 | int 10h ; BIOS的10h功能:显示一行字符 25 | 26 | LoadUsrProgInfo: ; 加载用户程序信息表 27 | mov ax,cs ; 段地址; 存放数据的内存基地址 28 | mov es,ax ; 设置段地址(不能直接mov es,段地址) 29 | mov bx, offset_upinfo ; 偏移地址; 存放数据的内存偏移地址 30 | mov ah,2 ; 功能号 31 | mov al,1 ; 扇区数 32 | mov dl,0 ; 驱动器号; 软盘为0,硬盘和U盘为80H 33 | mov dh,0 ; 磁头号; 起始编号为0 34 | mov ch,0 ; 柱面号; 起始编号为0 35 | mov cl,2 ; 起始扇区号 ; 起始编号为1 36 | int 13H ; 调用读磁盘BIOS的13h功能 37 | 38 | LoadOsKernel: ; 加载操作系统内核 39 | mov ax,cs ; 段地址; 存放数据的内存基地址 40 | mov es,ax ; 设置段地址(不能直接mov es,段地址) 41 | mov bx, offset_oskernel ; 偏移地址; 存放数据的内存偏移地址 42 | mov ah,2 ; 功能号 43 | mov al,16 ; 扇区数 44 | mov dl,0 ; 驱动器号; 软盘为0,硬盘和U盘为80H 45 | mov dh,0 ; 磁头号; 起始编号为0 46 | mov ch,0 ; 柱面号; 起始编号为0 47 | mov cl,3 ; 起始扇区号 ; 起始编号为1 48 | int 13H ; 调用读磁盘BIOS的13h功能 49 | 50 | EnterOs: 51 | jmp offset_oskernel ; 跳转到操作系统内核执行 52 | 53 | AfterRun: 54 | jmp $ ; 无限循环 55 | 56 | DataArea: 57 | load_msg db 'Bootloader is loading operating system...' 58 | load_msg_len equ ($-load_msg) 59 | 60 | SectorEnding: 61 | times 510-($-$$) db 0 62 | db 0x55,0xaa ; 主引导记录标志 -------------------------------------------------------------------------------- /项目3_开发独立内核的操作系统/src/merge.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | rm -rf temp 3 | mkdir temp 4 | rm *.img 5 | 6 | nasm bootloader.asm -o ./temp/bootloader.bin 7 | nasm usrproginfo.asm -o ./temp/usrproginfo.bin 8 | 9 | cd usrprog 10 | nasm stone_topleft.asm -o ../temp/stone_topleft.bin 11 | nasm stone_topright.asm -o ../temp/stone_topright.bin 12 | nasm stone_bottomleft.asm -o ../temp/stone_bottomleft.bin 13 | nasm stone_bottomright.asm -o ../temp/stone_bottomright.bin 14 | cd .. 15 | 16 | nasm -f elf32 oskernel.asm -o ./temp/oskernel.o 17 | nasm -f elf32 liba.asm -o ./temp/liba.o 18 | gcc -c -m16 -march=i386 -masm=intel -nostdlib -ffreestanding -mpreferred-stack-boundary=2 -lgcc -shared libc.c -o ./temp/libc.o 19 | ld -m elf_i386 -N -Ttext 0x8000 --oformat binary ./temp/oskernel.o ./temp/liba.o ./temp/libc.o -o ./temp/kernel.bin 20 | rm ./temp/*.o 21 | 22 | dd if=./temp/bootloader.bin of=JedOS_v1.1.img bs=512 count=1 2>/dev/null 23 | dd if=./temp/usrproginfo.bin of=JedOS_v1.1.img bs=512 seek=1 count=1 2>/dev/null 24 | dd if=./temp/kernel.bin of=JedOS_v1.1.img bs=512 seek=2 count=16 2>/dev/null 25 | dd if=./temp/stone_topleft.bin of=JedOS_v1.1.img bs=512 seek=18 count=2 2>/dev/null 26 | dd if=./temp/stone_topright.bin of=JedOS_v1.1.img bs=512 seek=20 count=2 2>/dev/null 27 | dd if=./temp/stone_bottomleft.bin of=JedOS_v1.1.img bs=512 seek=22 count=2 2>/dev/null 28 | dd if=./temp/stone_bottomright.bin of=JedOS_v1.1.img bs=512 seek=24 count=2 2>/dev/null 29 | 30 | echo "[+] Done." -------------------------------------------------------------------------------- /项目3_开发独立内核的操作系统/src/oskernel.asm: -------------------------------------------------------------------------------- 1 | ; @Author: Jed 2 | ; @Description: 操作系统内核文件;程序入口_start也在这里 3 | ; @Date: 2019-03-22 4 | ; @LastEditTime: 2019-03-23 5 | BITS 16 6 | 7 | [extern startUp] 8 | [extern shell] 9 | 10 | global _start 11 | _start: 12 | call dword startUp 13 | 14 | Keyboard: 15 | mov ah, 0 16 | int 16h 17 | cmp al, 0dh ; 按下回车 18 | jne Keyboard ; 无效按键,重新等待用户按键 19 | call dword shell ; 进入命令行界面 20 | jmp Keyboard ; 无限循环 -------------------------------------------------------------------------------- /项目3_开发独立内核的操作系统/src/stringio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: Jed 3 | * @Description: 涉及字符串输入输出的C函数库 4 | * @Date: 2019-03-23 5 | * @LastEditTime: 2019-03-28 6 | */ 7 | #include 8 | 9 | extern void printInPos(char *msg, uint16_t len, uint8_t row, uint8_t col); 10 | extern void putchar(char c); 11 | extern char getch(); 12 | 13 | // char tempc; // 临时存放一个字符的地方 14 | 15 | /* 字符串长度 */ 16 | uint16_t strlen(char *str) { 17 | int count = 0; 18 | while (str[count++] != '\0'); 19 | return count - 1; // 循环中使用后递增,因此这里需要减1 20 | } 21 | 22 | /* 比较字符串 */ 23 | uint8_t strcmp(char* str1, char* str2) { 24 | int i = 0; 25 | while (1) { 26 | if(str1[i]=='\0' || str2[i]=='\0') { break; } 27 | if(str1[i] != str2[i]) { break; } 28 | ++i; 29 | } 30 | return str1[i] - str2[i]; 31 | } 32 | 33 | /* 在光标处显示字符串 */ 34 | void print(char* str) { 35 | for(int i = 0, len = strlen(str); i < len; i++) { 36 | putchar(str[i]); 37 | } 38 | } 39 | 40 | /* 读取字符串到缓冲区 */ 41 | void readToBuf(char* buffer, uint16_t maxlen) { 42 | int i = 0; 43 | while(1) { 44 | char tempc = getch(); 45 | if(!(tempc==0xD || tempc=='\b' || tempc>=32 && tempc<=127)) { continue; } // 非有效字符不予理会 46 | if(i > 0 && i < maxlen-1) { // buffer中有字符且未满 47 | if(tempc == 0x0D) { 48 | break; // 按下回车,停止读取 49 | } 50 | else if(tempc == '\b') { // 按下退格,则删除一个字符 51 | putchar('\b'); 52 | putchar(' '); 53 | putchar('\b'); 54 | --i; 55 | } 56 | else{ 57 | putchar(tempc); // 回显 58 | buffer[i] = tempc; 59 | ++i; 60 | } 61 | } 62 | else if(i >= maxlen-1) { // 达到最大值,只能按退格或回车 63 | if(tempc == '\b') { // 按下退格,则删除一个字符 64 | putchar('\b'); 65 | putchar(' '); 66 | putchar('\b'); 67 | --i; 68 | } 69 | else if(tempc == 0x0D) { 70 | break; // 按下回车,停止读取 71 | } 72 | } 73 | else if(i <= 0) { // buffer中没有字符,只能输入或回车,不能删除 74 | if(tempc == 0x0D) { 75 | break; // 按下回车,停止读取 76 | } 77 | else if(tempc != '\b') { 78 | putchar(tempc); // 回显 79 | buffer[i] = tempc; 80 | ++i; 81 | } 82 | } 83 | } 84 | putchar('\r'); putchar('\n'); 85 | buffer[i] = '\0'; // 字符串必须以空字符结尾 86 | } 87 | 88 | /* 将整数转为指定进制的字符串 */ 89 | char* itoa(int val, int base) { 90 | if(val==0) return "0"; 91 | static char buf[32] = {0}; 92 | int i = 30; 93 | for(; val && i ; --i, val /= base) { 94 | buf[i] = "0123456789ABCDEF"[val % base]; 95 | } 96 | return &buf[i+1]; 97 | } 98 | 99 | /* 判断字符是否是十进制数字 */ 100 | uint8_t isnum(char c) { 101 | return c>='0' && c<='9'; 102 | } 103 | 104 | /* 获取字符串的第一个空格前的词 */ 105 | void getFirstWord(char* str, char* buf) { 106 | int i = 0; 107 | while(str[i] && str[i] != ' ') { 108 | buf[i] = str[i]; 109 | i++; 110 | } 111 | buf[i] = '\0'; // 字符串必须以空字符结尾 112 | } 113 | 114 | /* 获取字符串的第一个空格后的词 */ 115 | void getAfterFirstWord(char* str, char* buf) { 116 | buf[0] = '\0'; // 为了应对用户故意搞破坏 117 | int i = 0; 118 | while(str[i] && str[i] != ' ') { 119 | i++; 120 | } 121 | while(str[i] && str[i] == ' ') { 122 | i++; 123 | } 124 | int j = 0; 125 | while(str[i]) { 126 | buf[j++] = str[i++]; 127 | } 128 | buf[j] = '\0'; // 字符串必须以空字符结尾 129 | } -------------------------------------------------------------------------------- /项目3_开发独立内核的操作系统/src/usrprog/header.asm: -------------------------------------------------------------------------------- 1 | offset_usrprog1 equ 0A300h 2 | offset_usrprog2 equ 0A700h 3 | offset_usrprog3 equ 0AB00h 4 | offset_usrprog4 equ 0AF00h 5 | 6 | ; 用于在指定位置显示字符串,参数:(字符串首地址, 字符串字节数, 行数, 列数) 7 | %macro PRINT_IN_POS 4 8 | pusha ; 保护现场 9 | mov ax, cs ; 置其他段寄存器值与CS相同 10 | mov ds, ax ; 数据段 11 | mov bp, %1 ; BP=当前串的偏移地址 12 | mov ax, ds ; ES:BP = 串地址 13 | mov es, ax ; 置ES=DS 14 | mov cx, %2 ; CX = 串长(=9) 15 | mov ax, 1301h ; AH = 13h(功能号)、AL = 01h(光标置于串尾) 16 | mov bx, 0007h ; 页号为0(BH = 0) 黑底白字(BL = 07h) 17 | mov dh, %3 ; 行号=0 18 | mov dl, %4 ; 列号=0 19 | int 10h ; BIOS的10h功能:显示一行字符 20 | popa ; 恢复现场 21 | %endmacro -------------------------------------------------------------------------------- /项目3_开发独立内核的操作系统/src/usrprog/stone_bottomleft.asm: -------------------------------------------------------------------------------- 1 | ; 原作:凌应标 2014-03 2 | ; 改写:张怡昕(17341203) 2019-03 3 | ; 说明:本程序是jed_stone.asm的改版。本程序在显示器左上角进行字符反弹。 4 | ; 参数:(-1, -1, 40, 13, 0, 7) 5 | %include "header.asm" 6 | org offset_usrprog3 7 | 8 | Dn_Rt equ 1 ; D-Down,U-Up,R-right,L-Left 9 | Up_Rt equ 2 10 | Up_Lt equ 3 11 | Dn_Lt equ 4 12 | delay equ 50000 ; 计时器延迟计数,用于控制画框的速度 13 | ddelay equ 580 ; 计时器延迟计数,用于控制画框的速度 14 | 15 | screen_left equ -1 ; 字符运动左边界 16 | screen_top equ 11 ; 字符运动上边界 17 | screen_right equ 40 ; 字符运动右边界 18 | screen_bottom equ 25 ; 字符运动下边界 19 | originpos_y equ 0 ; 起点列数 20 | originpos_x equ 19 ; 起点行数 21 | 22 | start: 23 | pusha 24 | call ClearScreen ; 清屏 25 | mov ax,cs 26 | mov es,ax ; ES = CS 27 | mov ds,ax ; DS = CS 28 | mov es,ax ; ES = CS 29 | mov ax,0B800h 30 | mov gs,ax ; GS = B800h,指向文本模式的显示缓冲区 31 | mov byte[char],'X' 32 | 33 | PRINT_IN_POS hint1, hint1len, 16, 30 34 | 35 | initialize: ; 多次调用用户程序时,可保证初始值是相同的 36 | mov word[x], originpos_x 37 | mov word[y], originpos_y 38 | mov byte[curcolor], 80h 39 | mov byte[curcolor2], 01h 40 | mov word[count], delay 41 | mov word[dcount], ddelay 42 | mov byte[rdul], Dn_Rt ; 向右下运动 43 | 44 | loop1: 45 | dec word[count] ; 递减计数变量 46 | jnz loop1 ; >0:跳转; 47 | mov word[count],delay 48 | dec word[dcount] ; 递减计数变量 49 | jnz loop1 50 | mov word[count],delay 51 | mov word[dcount],ddelay 52 | 53 | mov al,1 54 | cmp al,byte[rdul] 55 | jz DnRt 56 | mov al,2 57 | cmp al,byte[rdul] 58 | jz UpRt 59 | mov al,3 60 | cmp al,byte[rdul] 61 | jz UpLt 62 | mov al,4 63 | cmp al,byte[rdul] 64 | jz DnLt 65 | ; jmp $ 66 | 67 | DnRt: 68 | inc word[x] 69 | inc word[y] 70 | mov bx,word[x] 71 | mov ax,screen_bottom 72 | sub ax,bx 73 | jz dr2ur 74 | mov bx,word[y] 75 | mov ax,screen_right 76 | sub ax,bx 77 | jz dr2dl 78 | jmp show 79 | 80 | dr2ur: 81 | mov word[x],screen_bottom-2 82 | mov byte[rdul],Up_Rt 83 | jmp show 84 | 85 | dr2dl: 86 | mov word[y],screen_right-2 87 | mov byte[rdul],Dn_Lt 88 | jmp show 89 | 90 | 91 | UpRt: 92 | dec word[x] 93 | inc word[y] 94 | mov bx,word[y] 95 | mov ax,screen_right 96 | sub ax,bx 97 | jz ur2ul 98 | mov bx,word[x] 99 | mov ax,screen_top 100 | sub ax,bx 101 | jz ur2dr 102 | jmp show 103 | 104 | ur2ul: 105 | mov word[y],screen_right-2 106 | mov byte[rdul],Up_Lt 107 | jmp show 108 | 109 | ur2dr: 110 | mov word[x],screen_top+2 111 | mov byte[rdul],Dn_Rt 112 | jmp show 113 | 114 | 115 | UpLt: 116 | dec word[x] 117 | dec word[y] 118 | mov bx,word[x] 119 | mov ax,screen_top 120 | sub ax,bx 121 | jz ul2dl 122 | mov bx,word[y] 123 | mov ax,screen_left 124 | sub ax,bx 125 | jz ul2ur 126 | jmp show 127 | 128 | ul2dl: 129 | mov word[x],screen_top+2 130 | mov byte[rdul],Dn_Lt 131 | jmp show 132 | ul2ur: 133 | mov word[y],screen_left+2 134 | mov byte[rdul],Up_Rt 135 | jmp show 136 | 137 | DnLt: 138 | inc word[x] 139 | dec word[y] 140 | mov bx,word[y] 141 | mov ax,screen_left 142 | sub ax,bx 143 | jz dl2dr 144 | mov bx,word[x] 145 | mov ax,screen_bottom 146 | sub ax,bx 147 | jz dl2ul 148 | jmp show 149 | 150 | dl2dr: 151 | mov word[y],screen_left+2 152 | mov byte[rdul],Dn_Rt 153 | jmp show 154 | 155 | dl2ul: 156 | mov word[x],screen_bottom-2 157 | mov byte[rdul],Up_Lt 158 | jmp show 159 | 160 | show: 161 | xor ax,ax ; 计算显存地址 162 | mov ax,word[x] 163 | mov bx,80 164 | mul bx 165 | add ax,word[y] 166 | mov bx,2 167 | mul bx 168 | mov bp,ax 169 | mov ah,[curcolor2] ; 弹字符的背景色和前景色(默认值为07h,详见文档) 170 | inc byte[curcolor2] 171 | cmp byte[curcolor2], 0fh 172 | jnz skip 173 | mov byte[curcolor2], 1 ; 为了不改变背景色 174 | skip: 175 | mov al,byte[char] ; AL = 显示字符值(默认值为20h=空格符) 176 | mov word[gs:bp],ax ; 显示字符的ASCII码值 177 | 178 | mov ah, 01h ; 功能号:查询键盘缓冲区但不等待 179 | int 16h 180 | jz continue ; 无键盘按下,继续 181 | mov ah, 0 ; 功能号:查询键盘输入 182 | int 16h 183 | cmp al, 27 ; 是否按下ESC 184 | je QuitUsrProg ; 若按下ESC,退出用户程序 185 | 186 | continue: 187 | jmp loop1 188 | 189 | end: 190 | jmp $ ; 停止画框,无限循环 191 | 192 | QuitUsrProg: 193 | popa 194 | retf 195 | 196 | ClearScreen: ; 函数:清屏 197 | pusha 198 | mov ax, 0003h 199 | int 10h ; 中断调用,清屏 200 | popa 201 | ret 202 | 203 | DataArea: 204 | count dw delay 205 | dcount dw ddelay 206 | rdul db Dn_Rt ; 向右下运动 207 | char db 0 208 | 209 | x dw originpos_x 210 | y dw originpos_y 211 | 212 | curcolor db 80h ; 保存当前字符颜色属性,用于myinfo 213 | curcolor2 db 01h ; 保存当前字符颜色属性,用于移动的字符 214 | 215 | hint1 db 'This is user program 3. Press ESC to exit.' 216 | hint1len equ ($-hint1) 217 | 218 | times 1024-($-$$) db 0 219 | -------------------------------------------------------------------------------- /项目3_开发独立内核的操作系统/src/usrprog/stone_bottomright.asm: -------------------------------------------------------------------------------- 1 | ; 原作:凌应标 2014-03 2 | ; 改写:张怡昕(17341203) 2019-03 3 | ; 说明:本程序是jed_stone.asm的改版。本程序在显示器左上角进行字符反弹。 4 | ; 参数:(39, 11, 80, 25, 40, 19) 5 | %include "header.asm" 6 | org offset_usrprog4 7 | 8 | Dn_Rt equ 1 ; D-Down,U-Up,R-right,L-Left 9 | Up_Rt equ 2 10 | Up_Lt equ 3 11 | Dn_Lt equ 4 12 | delay equ 50000 ; 计时器延迟计数,用于控制画框的速度 13 | ddelay equ 580 ; 计时器延迟计数,用于控制画框的速度 14 | 15 | screen_left equ 39 ; 字符运动左边界 16 | screen_top equ 11 ; 字符运动上边界 17 | screen_right equ 80 ; 字符运动右边界 18 | screen_bottom equ 25 ; 字符运动下边界 19 | originpos_y equ 40 ; 起点列数 20 | originpos_x equ 19 ; 起点行数 21 | 22 | start: 23 | pusha 24 | call ClearScreen ; 清屏 25 | mov ax,cs 26 | mov es,ax ; ES = CS 27 | mov ds,ax ; DS = CS 28 | mov es,ax ; ES = CS 29 | mov ax,0B800h 30 | mov gs,ax ; GS = B800h,指向文本模式的显示缓冲区 31 | mov byte[char],'X' 32 | 33 | PRINT_IN_POS hint1, hint1len, 16, 30 34 | 35 | initialize: ; 多次调用用户程序时,可保证初始值是相同的 36 | mov word[x], originpos_x 37 | mov word[y], originpos_y 38 | mov byte[curcolor], 80h 39 | mov byte[curcolor2], 01h 40 | mov word[count], delay 41 | mov word[dcount], ddelay 42 | mov byte[rdul], Dn_Rt ; 向右下运动 43 | 44 | loop1: 45 | dec word[count] ; 递减计数变量 46 | jnz loop1 ; >0:跳转; 47 | mov word[count],delay 48 | dec word[dcount] ; 递减计数变量 49 | jnz loop1 50 | mov word[count],delay 51 | mov word[dcount],ddelay 52 | 53 | mov al,1 54 | cmp al,byte[rdul] 55 | jz DnRt 56 | mov al,2 57 | cmp al,byte[rdul] 58 | jz UpRt 59 | mov al,3 60 | cmp al,byte[rdul] 61 | jz UpLt 62 | mov al,4 63 | cmp al,byte[rdul] 64 | jz DnLt 65 | ; jmp $ 66 | 67 | DnRt: 68 | inc word[x] 69 | inc word[y] 70 | mov bx,word[x] 71 | mov ax,screen_bottom 72 | sub ax,bx 73 | jz dr2ur 74 | mov bx,word[y] 75 | mov ax,screen_right 76 | sub ax,bx 77 | jz dr2dl 78 | jmp show 79 | 80 | dr2ur: 81 | mov word[x],screen_bottom-2 82 | mov byte[rdul],Up_Rt 83 | jmp show 84 | 85 | dr2dl: 86 | mov word[y],screen_right-2 87 | mov byte[rdul],Dn_Lt 88 | jmp show 89 | 90 | 91 | UpRt: 92 | dec word[x] 93 | inc word[y] 94 | mov bx,word[y] 95 | mov ax,screen_right 96 | sub ax,bx 97 | jz ur2ul 98 | mov bx,word[x] 99 | mov ax,screen_top 100 | sub ax,bx 101 | jz ur2dr 102 | jmp show 103 | 104 | ur2ul: 105 | mov word[y],screen_right-2 106 | mov byte[rdul],Up_Lt 107 | jmp show 108 | 109 | ur2dr: 110 | mov word[x],screen_top+2 111 | mov byte[rdul],Dn_Rt 112 | jmp show 113 | 114 | 115 | UpLt: 116 | dec word[x] 117 | dec word[y] 118 | mov bx,word[x] 119 | mov ax,screen_top 120 | sub ax,bx 121 | jz ul2dl 122 | mov bx,word[y] 123 | mov ax,screen_left 124 | sub ax,bx 125 | jz ul2ur 126 | jmp show 127 | 128 | ul2dl: 129 | mov word[x],screen_top+2 130 | mov byte[rdul],Dn_Lt 131 | jmp show 132 | ul2ur: 133 | mov word[y],screen_left+2 134 | mov byte[rdul],Up_Rt 135 | jmp show 136 | 137 | DnLt: 138 | inc word[x] 139 | dec word[y] 140 | mov bx,word[y] 141 | mov ax,screen_left 142 | sub ax,bx 143 | jz dl2dr 144 | mov bx,word[x] 145 | mov ax,screen_bottom 146 | sub ax,bx 147 | jz dl2ul 148 | jmp show 149 | 150 | dl2dr: 151 | mov word[y],screen_left+2 152 | mov byte[rdul],Dn_Rt 153 | jmp show 154 | 155 | dl2ul: 156 | mov word[x],screen_bottom-2 157 | mov byte[rdul],Up_Lt 158 | jmp show 159 | 160 | show: 161 | xor ax,ax ; 计算显存地址 162 | mov ax,word[x] 163 | mov bx,80 164 | mul bx 165 | add ax,word[y] 166 | mov bx,2 167 | mul bx 168 | mov bp,ax 169 | mov ah,[curcolor2] ; 弹字符的背景色和前景色(默认值为07h,详见文档) 170 | inc byte[curcolor2] 171 | cmp byte[curcolor2], 0fh 172 | jnz skip 173 | mov byte[curcolor2], 1 ; 为了不改变背景色 174 | skip: 175 | mov al,byte[char] ; AL = 显示字符值(默认值为20h=空格符) 176 | mov word[gs:bp],ax ; 显示字符的ASCII码值 177 | 178 | mov ah, 01h ; 功能号:查询键盘缓冲区但不等待 179 | int 16h 180 | jz continue ; 无键盘按下,继续 181 | mov ah, 0 ; 功能号:查询键盘输入 182 | int 16h 183 | cmp al, 27 ; 是否按下ESC 184 | je QuitUsrProg ; 若按下ESC,退出用户程序 185 | 186 | continue: 187 | jmp loop1 188 | 189 | end: 190 | jmp $ ; 停止画框,无限循环 191 | 192 | QuitUsrProg: 193 | popa 194 | retf 195 | 196 | ClearScreen: ; 函数:清屏 197 | pusha 198 | mov ax, 0003h 199 | int 10h ; 中断调用,清屏 200 | popa 201 | ret 202 | 203 | DataArea: 204 | count dw delay 205 | dcount dw ddelay 206 | rdul db Dn_Rt ; 向右下运动 207 | char db 0 208 | 209 | x dw originpos_x 210 | y dw originpos_y 211 | 212 | curcolor db 80h ; 保存当前字符颜色属性,用于myinfo 213 | curcolor2 db 01h ; 保存当前字符颜色属性,用于移动的字符 214 | 215 | hint1 db 'This is user program 4. Press ESC to exit.' 216 | hint1len equ ($-hint1) 217 | 218 | times 1024-($-$$) db 0 219 | -------------------------------------------------------------------------------- /项目3_开发独立内核的操作系统/src/usrprog/stone_topleft.asm: -------------------------------------------------------------------------------- 1 | ; 原作:凌应标 2014-03 2 | ; 改写:张怡昕(17341203) 2019-03 3 | ; 说明:本程序是jed_stone.asm的改版。本程序在显示器左上角进行字符反弹。 4 | ; 参数:(-1, -1, 40, 13, 0, 7) 5 | %include "header.asm" 6 | org offset_usrprog1 7 | 8 | Dn_Rt equ 1 ; D-Down,U-Up,R-right,L-Left 9 | Up_Rt equ 2 10 | Up_Lt equ 3 11 | Dn_Lt equ 4 12 | delay equ 50000 ; 计时器延迟计数,用于控制画框的速度 13 | ddelay equ 580 ; 计时器延迟计数,用于控制画框的速度 14 | 15 | screen_left equ -1 ; 字符运动左边界 16 | screen_top equ -1 ; 字符运动上边界 17 | screen_right equ 40 ; 字符运动右边界 18 | screen_bottom equ 13 ; 字符运动下边界 19 | originpos_y equ 0 ; 起点列数 20 | originpos_x equ 7 ; 起点行数 21 | 22 | start: 23 | pusha 24 | call ClearScreen ; 清屏 25 | mov ax,cs 26 | mov es,ax ; ES = CS 27 | mov ds,ax ; DS = CS 28 | mov es,ax ; ES = CS 29 | mov ax,0B800h 30 | mov gs,ax ; GS = B800h,指向文本模式的显示缓冲区 31 | mov byte[char],'X' 32 | 33 | PRINT_IN_POS hint1, hint1len, 16, 30 34 | 35 | initialize: ; 多次调用用户程序时,可保证初始值是相同的 36 | mov word[x], originpos_x 37 | mov word[y], originpos_y 38 | mov byte[curcolor], 80h 39 | mov byte[curcolor2], 01h 40 | mov word[count], delay 41 | mov word[dcount], ddelay 42 | mov byte[rdul], Dn_Rt ; 向右下运动 43 | 44 | loop1: 45 | dec word[count] ; 递减计数变量 46 | jnz loop1 ; >0:跳转; 47 | mov word[count],delay 48 | dec word[dcount] ; 递减计数变量 49 | jnz loop1 50 | mov word[count],delay 51 | mov word[dcount],ddelay 52 | 53 | mov al,1 54 | cmp al,byte[rdul] 55 | jz DnRt 56 | mov al,2 57 | cmp al,byte[rdul] 58 | jz UpRt 59 | mov al,3 60 | cmp al,byte[rdul] 61 | jz UpLt 62 | mov al,4 63 | cmp al,byte[rdul] 64 | jz DnLt 65 | ; jmp $ 66 | 67 | DnRt: 68 | inc word[x] 69 | inc word[y] 70 | mov bx,word[x] 71 | mov ax,screen_bottom 72 | sub ax,bx 73 | jz dr2ur 74 | mov bx,word[y] 75 | mov ax,screen_right 76 | sub ax,bx 77 | jz dr2dl 78 | jmp show 79 | 80 | dr2ur: 81 | mov word[x],screen_bottom-2 82 | mov byte[rdul],Up_Rt 83 | jmp show 84 | 85 | dr2dl: 86 | mov word[y],screen_right-2 87 | mov byte[rdul],Dn_Lt 88 | jmp show 89 | 90 | 91 | UpRt: 92 | dec word[x] 93 | inc word[y] 94 | mov bx,word[y] 95 | mov ax,screen_right 96 | sub ax,bx 97 | jz ur2ul 98 | mov bx,word[x] 99 | mov ax,screen_top 100 | sub ax,bx 101 | jz ur2dr 102 | jmp show 103 | 104 | ur2ul: 105 | mov word[y],screen_right-2 106 | mov byte[rdul],Up_Lt 107 | jmp show 108 | 109 | ur2dr: 110 | mov word[x],screen_top+2 111 | mov byte[rdul],Dn_Rt 112 | jmp show 113 | 114 | 115 | UpLt: 116 | dec word[x] 117 | dec word[y] 118 | mov bx,word[x] 119 | mov ax,screen_top 120 | sub ax,bx 121 | jz ul2dl 122 | mov bx,word[y] 123 | mov ax,screen_left 124 | sub ax,bx 125 | jz ul2ur 126 | jmp show 127 | 128 | ul2dl: 129 | mov word[x],screen_top+2 130 | mov byte[rdul],Dn_Lt 131 | jmp show 132 | ul2ur: 133 | mov word[y],screen_left+2 134 | mov byte[rdul],Up_Rt 135 | jmp show 136 | 137 | DnLt: 138 | inc word[x] 139 | dec word[y] 140 | mov bx,word[y] 141 | mov ax,screen_left 142 | sub ax,bx 143 | jz dl2dr 144 | mov bx,word[x] 145 | mov ax,screen_bottom 146 | sub ax,bx 147 | jz dl2ul 148 | jmp show 149 | 150 | dl2dr: 151 | mov word[y],screen_left+2 152 | mov byte[rdul],Dn_Rt 153 | jmp show 154 | 155 | dl2ul: 156 | mov word[x],screen_bottom-2 157 | mov byte[rdul],Up_Lt 158 | jmp show 159 | 160 | show: 161 | xor ax,ax ; 计算显存地址 162 | mov ax,word[x] 163 | mov bx,80 164 | mul bx 165 | add ax,word[y] 166 | mov bx,2 167 | mul bx 168 | mov bp,ax 169 | mov ah,[curcolor2] ; 弹字符的背景色和前景色(默认值为07h,详见文档) 170 | inc byte[curcolor2] 171 | cmp byte[curcolor2], 0fh 172 | jnz skip 173 | mov byte[curcolor2], 1 ; 为了不改变背景色 174 | skip: 175 | mov al,byte[char] ; AL = 显示字符值(默认值为20h=空格符) 176 | mov word[gs:bp],ax ; 显示字符的ASCII码值 177 | 178 | mov ah, 01h ; 功能号:查询键盘缓冲区但不等待 179 | int 16h 180 | jz continue ; 无键盘按下,继续 181 | mov ah, 0 ; 功能号:查询键盘输入 182 | int 16h 183 | cmp al, 27 ; 是否按下ESC 184 | je QuitUsrProg ; 若按下ESC,退出用户程序 185 | 186 | continue: 187 | jmp loop1 188 | 189 | end: 190 | jmp $ ; 停止画框,无限循环 191 | 192 | QuitUsrProg: 193 | popa 194 | retf 195 | 196 | ClearScreen: ; 函数:清屏 197 | pusha 198 | mov ax, 0003h 199 | int 10h ; 中断调用,清屏 200 | popa 201 | ret 202 | 203 | DataArea: 204 | count dw delay 205 | dcount dw ddelay 206 | rdul db Dn_Rt ; 向右下运动 207 | char db 0 208 | 209 | x dw originpos_x 210 | y dw originpos_y 211 | 212 | curcolor db 80h ; 保存当前字符颜色属性,用于myinfo 213 | curcolor2 db 01h ; 保存当前字符颜色属性,用于移动的字符 214 | 215 | hint1 db 'This is user program 1. Press ESC to exit.' 216 | hint1len equ ($-hint1) 217 | 218 | times 1024-($-$$) db 0 219 | -------------------------------------------------------------------------------- /项目3_开发独立内核的操作系统/src/usrprog/stone_topright.asm: -------------------------------------------------------------------------------- 1 | ; 原作:凌应标 2014-03 2 | ; 改写:张怡昕(17341203) 2019-03 3 | ; 说明:本程序是jed_stone.asm的改版。本程序在显示器左上角进行字符反弹。 4 | ; 参数:(39, -1, 80, 13, 40, 7) 5 | %include "header.asm" 6 | org offset_usrprog2 7 | 8 | Dn_Rt equ 1 ; D-Down,U-Up,R-right,L-Left 9 | Up_Rt equ 2 10 | Up_Lt equ 3 11 | Dn_Lt equ 4 12 | delay equ 50000 ; 计时器延迟计数,用于控制画框的速度 13 | ddelay equ 580 ; 计时器延迟计数,用于控制画框的速度 14 | 15 | screen_left equ 39 ; 字符运动左边界 16 | screen_top equ -1 ; 字符运动上边界 17 | screen_right equ 80 ; 字符运动右边界 18 | screen_bottom equ 13 ; 字符运动下边界 19 | originpos_y equ 40 ; 起点列数 20 | originpos_x equ 7 ; 起点行数 21 | 22 | start: 23 | pusha 24 | call ClearScreen ; 清屏 25 | mov ax,cs 26 | mov es,ax ; ES = CS 27 | mov ds,ax ; DS = CS 28 | mov es,ax ; ES = CS 29 | mov ax,0B800h 30 | mov gs,ax ; GS = B800h,指向文本模式的显示缓冲区 31 | mov byte[char],'X' 32 | 33 | PRINT_IN_POS hint1, hint1len, 16, 30 34 | 35 | initialize: ; 多次调用用户程序时,可保证初始值是相同的 36 | mov word[x], originpos_x 37 | mov word[y], originpos_y 38 | mov byte[curcolor], 80h 39 | mov byte[curcolor2], 01h 40 | mov word[count], delay 41 | mov word[dcount], ddelay 42 | mov byte[rdul], Dn_Rt ; 向右下运动 43 | 44 | loop1: 45 | dec word[count] ; 递减计数变量 46 | jnz loop1 ; >0:跳转; 47 | mov word[count],delay 48 | dec word[dcount] ; 递减计数变量 49 | jnz loop1 50 | mov word[count],delay 51 | mov word[dcount],ddelay 52 | 53 | mov al,1 54 | cmp al,byte[rdul] 55 | jz DnRt 56 | mov al,2 57 | cmp al,byte[rdul] 58 | jz UpRt 59 | mov al,3 60 | cmp al,byte[rdul] 61 | jz UpLt 62 | mov al,4 63 | cmp al,byte[rdul] 64 | jz DnLt 65 | ; jmp $ 66 | 67 | DnRt: 68 | inc word[x] 69 | inc word[y] 70 | mov bx,word[x] 71 | mov ax,screen_bottom 72 | sub ax,bx 73 | jz dr2ur 74 | mov bx,word[y] 75 | mov ax,screen_right 76 | sub ax,bx 77 | jz dr2dl 78 | jmp show 79 | 80 | dr2ur: 81 | mov word[x],screen_bottom-2 82 | mov byte[rdul],Up_Rt 83 | jmp show 84 | 85 | dr2dl: 86 | mov word[y],screen_right-2 87 | mov byte[rdul],Dn_Lt 88 | jmp show 89 | 90 | 91 | UpRt: 92 | dec word[x] 93 | inc word[y] 94 | mov bx,word[y] 95 | mov ax,screen_right 96 | sub ax,bx 97 | jz ur2ul 98 | mov bx,word[x] 99 | mov ax,screen_top 100 | sub ax,bx 101 | jz ur2dr 102 | jmp show 103 | 104 | ur2ul: 105 | mov word[y],screen_right-2 106 | mov byte[rdul],Up_Lt 107 | jmp show 108 | 109 | ur2dr: 110 | mov word[x],screen_top+2 111 | mov byte[rdul],Dn_Rt 112 | jmp show 113 | 114 | 115 | UpLt: 116 | dec word[x] 117 | dec word[y] 118 | mov bx,word[x] 119 | mov ax,screen_top 120 | sub ax,bx 121 | jz ul2dl 122 | mov bx,word[y] 123 | mov ax,screen_left 124 | sub ax,bx 125 | jz ul2ur 126 | jmp show 127 | 128 | ul2dl: 129 | mov word[x],screen_top+2 130 | mov byte[rdul],Dn_Lt 131 | jmp show 132 | ul2ur: 133 | mov word[y],screen_left+2 134 | mov byte[rdul],Up_Rt 135 | jmp show 136 | 137 | DnLt: 138 | inc word[x] 139 | dec word[y] 140 | mov bx,word[y] 141 | mov ax,screen_left 142 | sub ax,bx 143 | jz dl2dr 144 | mov bx,word[x] 145 | mov ax,screen_bottom 146 | sub ax,bx 147 | jz dl2ul 148 | jmp show 149 | 150 | dl2dr: 151 | mov word[y],screen_left+2 152 | mov byte[rdul],Dn_Rt 153 | jmp show 154 | 155 | dl2ul: 156 | mov word[x],screen_bottom-2 157 | mov byte[rdul],Up_Lt 158 | jmp show 159 | 160 | show: 161 | xor ax,ax ; 计算显存地址 162 | mov ax,word[x] 163 | mov bx,80 164 | mul bx 165 | add ax,word[y] 166 | mov bx,2 167 | mul bx 168 | mov bp,ax 169 | mov ah,[curcolor2] ; 弹字符的背景色和前景色(默认值为07h,详见文档) 170 | inc byte[curcolor2] 171 | cmp byte[curcolor2], 0fh 172 | jnz skip 173 | mov byte[curcolor2], 1 ; 为了不改变背景色 174 | skip: 175 | mov al,byte[char] ; AL = 显示字符值(默认值为20h=空格符) 176 | mov word[gs:bp],ax ; 显示字符的ASCII码值 177 | 178 | mov ah, 01h ; 功能号:查询键盘缓冲区但不等待 179 | int 16h 180 | jz continue ; 无键盘按下,继续 181 | mov ah, 0 ; 功能号:查询键盘输入 182 | int 16h 183 | cmp al, 27 ; 是否按下ESC 184 | je QuitUsrProg ; 若按下ESC,退出用户程序 185 | 186 | continue: 187 | jmp loop1 188 | 189 | end: 190 | jmp $ ; 停止画框,无限循环 191 | 192 | QuitUsrProg: 193 | popa 194 | retf 195 | 196 | ClearScreen: ; 函数:清屏 197 | pusha 198 | mov ax, 0003h 199 | int 10h ; 中断调用,清屏 200 | popa 201 | ret 202 | 203 | DataArea: 204 | count dw delay 205 | dcount dw ddelay 206 | rdul db Dn_Rt ; 向右下运动 207 | char db 0 208 | 209 | x dw originpos_x 210 | y dw originpos_y 211 | 212 | curcolor db 80h ; 保存当前字符颜色属性,用于myinfo 213 | curcolor2 db 01h ; 保存当前字符颜色属性,用于移动的字符 214 | 215 | hint1 db 'This is user program 2. Press ESC to exit.' 216 | hint1len equ ($-hint1) 217 | 218 | times 1024-($-$$) db 0 219 | -------------------------------------------------------------------------------- /项目3_开发独立内核的操作系统/src/usrproginfo.asm: -------------------------------------------------------------------------------- 1 | %include "usrprog/header.asm" 2 | %macro UsrProgInfoBlock 7 ; 参数:(PID,程序名,字节数,柱面,磁头,扇区,内存地址) 3 | pid%1 db %1 ; 程序编号PID;相对偏移0 4 | name%1 db %2 ; 程序名(至多32字节);相对偏移1 5 | times 16-($-name%1) db 0 ; 程序名占6字节 6 | size%1 dw %3 ; 程序大小;相对偏移17 7 | cylinder%1 db %4 ; 柱面;相对偏移19 8 | head%1 db %5 ; 磁头;相对偏移20 9 | sector%1 db %6 ; 扇区;相对偏移21 10 | addr%1 dw %7 ; 内存中的地址;相对偏移22 11 | %endmacro ; 共24个字节 12 | 13 | UsrProgNumber: 14 | db 4 ; 用户程序数量 15 | 16 | UserProgInfo: 17 | UsrProgInfoBlock 1, 'stone_topleft', 1024, 0, 1, 1, offset_usrprog1 18 | UsrProgInfoBlock 2, 'stone_topright', 1024, 0, 1, 3, offset_usrprog2 19 | UsrProgInfoBlock 3, 'stone_botleft', 1024, 0, 1, 5, offset_usrprog3 20 | UsrProgInfoBlock 4, 'stone_botright', 1024, 0, 1, 7, offset_usrprog4 21 | 22 | 23 | SectorEnding: 24 | times 512-($-$$) db 0 -------------------------------------------------------------------------------- /项目4_异步事件编程技术/JedOS_v1.2.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目4_异步事件编程技术/JedOS_v1.2.img -------------------------------------------------------------------------------- /项目4_异步事件编程技术/assets/1554294052391.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目4_异步事件编程技术/assets/1554294052391.png -------------------------------------------------------------------------------- /项目4_异步事件编程技术/assets/1554294135211.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目4_异步事件编程技术/assets/1554294135211.png -------------------------------------------------------------------------------- /项目4_异步事件编程技术/assets/1554294369607.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目4_异步事件编程技术/assets/1554294369607.png -------------------------------------------------------------------------------- /项目4_异步事件编程技术/assets/1554294409851.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目4_异步事件编程技术/assets/1554294409851.png -------------------------------------------------------------------------------- /项目4_异步事件编程技术/assets/1554294500818.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目4_异步事件编程技术/assets/1554294500818.png -------------------------------------------------------------------------------- /项目4_异步事件编程技术/assets/1554294601065.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目4_异步事件编程技术/assets/1554294601065.png -------------------------------------------------------------------------------- /项目4_异步事件编程技术/assets/1554294731399.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目4_异步事件编程技术/assets/1554294731399.png -------------------------------------------------------------------------------- /项目4_异步事件编程技术/assets/1554294799321.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目4_异步事件编程技术/assets/1554294799321.png -------------------------------------------------------------------------------- /项目4_异步事件编程技术/assets/1554294819285.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目4_异步事件编程技术/assets/1554294819285.png -------------------------------------------------------------------------------- /项目4_异步事件编程技术/assets/1554294929011.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目4_异步事件编程技术/assets/1554294929011.png -------------------------------------------------------------------------------- /项目4_异步事件编程技术/assets/1554294940443.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目4_异步事件编程技术/assets/1554294940443.png -------------------------------------------------------------------------------- /项目4_异步事件编程技术/assets/1554294985104.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目4_异步事件编程技术/assets/1554294985104.png -------------------------------------------------------------------------------- /项目4_异步事件编程技术/assets/1554344609435.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目4_异步事件编程技术/assets/1554344609435.png -------------------------------------------------------------------------------- /项目4_异步事件编程技术/assets/1554344612831.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目4_异步事件编程技术/assets/1554344612831.png -------------------------------------------------------------------------------- /项目4_异步事件编程技术/assets/1554344812737.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目4_异步事件编程技术/assets/1554344812737.png -------------------------------------------------------------------------------- /项目4_异步事件编程技术/assets/1554344923054.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目4_异步事件编程技术/assets/1554344923054.png -------------------------------------------------------------------------------- /项目4_异步事件编程技术/src/bootloader.asm: -------------------------------------------------------------------------------- 1 | ; @Author: Jed 2 | ; @Description: 引导程序;本文件独立编译为二进制程序,与其他asm或C程序无关 3 | ; @Date: 2019-03-21 4 | ; @LastEditTime: 2019-03-23 5 | 6 | BITS 16 7 | org 7c00h 8 | 9 | offset_upinfo equ 7E00h ; 用户程序信息表被装入的位置 10 | offset_oskernel equ 8000h ; 操作系统内核被装入的位置 11 | 12 | global _start 13 | _start: 14 | mov ax, cs ; 置其他段寄存器值与CS相同 15 | mov ds, ax ; 数据段 16 | mov bp, load_msg ; BP=当前串的偏移地址 17 | mov ax, ds ; ES:BP = 串地址 18 | mov es, ax ; 置ES=DS 19 | mov cx, load_msg_len ; CX = 串长 20 | mov ax, 1301h ; AH = 13h(功能号)、AL = 01h(光标置于串尾) 21 | mov bx, 0007h ; 页号为0(BH = 0) 黑底白字(BL = 07h) 22 | mov dh, 0 ; 行号=0 23 | mov dl, 0 ; 列号=0 24 | int 10h ; BIOS的10h功能:显示一行字符 25 | 26 | LoadUsrProgInfo: ; 加载用户程序信息表 27 | mov ax,cs ; 段地址; 存放数据的内存基地址 28 | mov es,ax ; 设置段地址(不能直接mov es,段地址) 29 | mov bx, offset_upinfo ; 偏移地址; 存放数据的内存偏移地址 30 | mov ah,2 ; 功能号 31 | mov al,1 ; 扇区数 32 | mov dl,0 ; 驱动器号; 软盘为0,硬盘和U盘为80H 33 | mov dh,0 ; 磁头号; 起始编号为0 34 | mov ch,0 ; 柱面号; 起始编号为0 35 | mov cl,2 ; 起始扇区号 ; 起始编号为1 36 | int 13H ; 调用读磁盘BIOS的13h功能 37 | 38 | LoadOsKernel: ; 加载操作系统内核 39 | mov ax,cs ; 段地址; 存放数据的内存基地址 40 | mov es,ax ; 设置段地址(不能直接mov es,段地址) 41 | mov bx, offset_oskernel ; 偏移地址; 存放数据的内存偏移地址 42 | mov ah,2 ; 功能号 43 | mov al,16 ; 扇区数 44 | mov dl,0 ; 驱动器号; 软盘为0,硬盘和U盘为80H 45 | mov dh,0 ; 磁头号; 起始编号为0 46 | mov ch,0 ; 柱面号; 起始编号为0 47 | mov cl,3 ; 起始扇区号 ; 起始编号为1 48 | int 13H ; 调用读磁盘BIOS的13h功能 49 | 50 | EnterOs: 51 | jmp offset_oskernel ; 跳转到操作系统内核执行 52 | 53 | AfterRun: 54 | jmp $ ; 无限循环 55 | 56 | DataArea: 57 | load_msg db 'Bootloader is loading operating system...' 58 | load_msg_len equ ($-load_msg) 59 | 60 | SectorEnding: 61 | times 510-($-$$) db 0 62 | db 0x55,0xaa ; 主引导记录标志 -------------------------------------------------------------------------------- /项目4_异步事件编程技术/src/hotwheel.asm: -------------------------------------------------------------------------------- 1 | BITS 16 2 | [global Timer] 3 | Timer: 4 | push ax 5 | push ds 6 | push gs 7 | push si 8 | 9 | mov ax,cs 10 | mov ds,ax ; DS = CS 11 | mov ax,0B800h ; 文本窗口显存起始地址 12 | mov gs,ax ; GS = B800h 13 | 14 | dec byte [count] ; 递减计数变量 15 | jnz EndInt ; >0:跳转 16 | mov byte[count],delay ; 重置计数变量=初值delay 17 | mov si, hotwheel ; 风火轮首字符地址 18 | add si, [wheel_offset] ; 风火轮字符偏移量 19 | mov al, [si] ; al=要显示的字符 20 | mov ah, 0Ch ; ah=黑底,淡红色 21 | mov [gs:((80*24+79)*2)], ax ; 更新显存 22 | inc byte[wheel_offset] ; 递增偏移量 23 | cmp byte[wheel_offset], 4 ; 检查偏移量是否超过3 24 | jne EndInt ; 没有超过,中断返回 25 | mov byte[wheel_offset], 0 ; 超过3了,重置为0 26 | EndInt: 27 | mov al,20h ; AL = EOI 28 | out 20h,al ; 发送EOI到主8529A 29 | out 0A0h,al ; 发送EOI到从8529A 30 | 31 | pop si 32 | pop gs 33 | pop ds 34 | pop ax 35 | iret ; 从中断返回 36 | 37 | 38 | DataArea: 39 | delay equ 3 ; 计时器延迟计数 40 | count db delay ; 计时器计数变量,初值=delay 41 | hotwheel db '-\|/' ; 风火轮字符 42 | wheel_offset dw 0 ; 风火轮字符偏移量,初值=0 -------------------------------------------------------------------------------- /项目4_异步事件编程技术/src/macro.asm: -------------------------------------------------------------------------------- 1 | offset_usrprog1 equ 0A300h 2 | offset_usrprog2 equ 0A700h 3 | offset_usrprog3 equ 0AB00h 4 | offset_usrprog4 equ 0AF00h 5 | offset_intcaller equ 0xB300 6 | 7 | offset_upinfo equ 7E00h ; 用户程序信息表被装入的位置 8 | 9 | 10 | %macro WRITE_INT_VECTOR 2 ; 写中断向量表;参数:(中断号,中断处理程序地址) 11 | push ax 12 | push es 13 | mov ax, 0 14 | mov es, ax ; ES = 0 15 | mov word[es:%1*4], %2 ; 设置中断向量的偏移地址 16 | mov ax,cs 17 | mov word[es:%1*4+2], ax ; 设置中断向量的段地址=CS 18 | pop es 19 | pop ax 20 | %endmacro 21 | 22 | %macro MOVE_INT_VECTOR 2 ; 将参数1的中断向量转移至参数2处 23 | push ax 24 | push es 25 | push si 26 | mov ax, 0 27 | mov es, ax 28 | mov si, [es:%1*4] 29 | mov [es:%2*4], si 30 | mov si, [es:%1*4+2] 31 | mov [es:%2*4+2], si 32 | pop si 33 | pop es 34 | pop ax 35 | %endmacro 36 | 37 | %macro PRINT_IN_POS 4 38 | pusha ; 保护现场 39 | push ds 40 | push es 41 | mov ax, cs ; 置其他段寄存器值与CS相同 42 | mov ds, ax ; 数据段 43 | mov bp, %1 ; BP=当前串的偏移地址 44 | mov ax, ds ; ES:BP = 串地址 45 | mov es, ax ; 置ES=DS 46 | mov cx, %2 ; CX = 串长(=9) 47 | mov ax, 1301h ; AH = 13h(功能号)、AL = 01h(光标置于串尾) 48 | mov bx, 0007h ; 页号为0(BH = 0) 黑底白字(BL = 07h) 49 | mov dh, %3 ; 行号=0 50 | mov dl, %4 ; 列号=0 51 | int 10h ; BIOS的10h功能:显示一行字符 52 | pop es 53 | pop ds 54 | popa ; 恢复现场 55 | %endmacro -------------------------------------------------------------------------------- /项目4_异步事件编程技术/src/merge.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | rm -rf temp 3 | mkdir temp 4 | rm *.img 5 | 6 | nasm bootloader.asm -o ./temp/bootloader.bin 7 | nasm usrproginfo.asm -o ./temp/usrproginfo.bin 8 | 9 | cd usrprog 10 | nasm stone_topleft.asm -o ../temp/stone_topleft.bin 11 | nasm stone_topright.asm -o ../temp/stone_topright.bin 12 | nasm stone_bottomleft.asm -o ../temp/stone_bottomleft.bin 13 | nasm stone_bottomright.asm -o ../temp/stone_bottomright.bin 14 | nasm intcaller.asm -o ../temp/intcaller.bin 15 | cd .. 16 | 17 | nasm -f elf32 hotwheel.asm -o ./temp/hotwheel.o 18 | 19 | nasm -f elf32 osstarter.asm -o ./temp/osstarter.o 20 | nasm -f elf32 liba.asm -o ./temp/liba.o 21 | gcc -c -m16 -march=i386 -masm=intel -nostdlib -ffreestanding -mpreferred-stack-boundary=2 -lgcc -shared kernel.c -o ./temp/kernel.o 22 | ld -m elf_i386 -N -Ttext 0x8000 --oformat binary ./temp/osstarter.o ./temp/liba.o ./temp/kernel.o ./temp/hotwheel.o -o ./temp/kernel.bin 23 | rm ./temp/*.o 24 | 25 | dd if=./temp/bootloader.bin of=JedOS_v1.2.img bs=512 count=1 2> /dev/null 26 | dd if=./temp/usrproginfo.bin of=JedOS_v1.2.img bs=512 seek=1 count=1 2> /dev/null 27 | dd if=./temp/kernel.bin of=JedOS_v1.2.img bs=512 seek=2 count=16 2> /dev/null 28 | dd if=./temp/stone_topleft.bin of=JedOS_v1.2.img bs=512 seek=18 count=2 2> /dev/null 29 | dd if=./temp/stone_topright.bin of=JedOS_v1.2.img bs=512 seek=20 count=2 2> /dev/null 30 | dd if=./temp/stone_bottomleft.bin of=JedOS_v1.2.img bs=512 seek=22 count=2 2> /dev/null 31 | dd if=./temp/stone_bottomright.bin of=JedOS_v1.2.img bs=512 seek=24 count=2 2> /dev/null 32 | dd if=./temp/intcaller.bin of=JedOS_v1.2.img bs=512 seek=26 count=2 2> /dev/null 33 | 34 | 35 | echo "[+] Done." -------------------------------------------------------------------------------- /项目4_异步事件编程技术/src/osstarter.asm: -------------------------------------------------------------------------------- 1 | ; @Author: Jed 2 | ; @Description: 操作系统内核入口 3 | ; @Date: 2019-03-22 4 | ; @LastEditTime: 2019-03-23 5 | 6 | BITS 16 7 | %include "macro.asm" 8 | [extern startUp] 9 | [extern shell] 10 | [extern Timer] 11 | 12 | global _start 13 | _start: 14 | MOVE_INT_VECTOR 08h, 38h 15 | WRITE_INT_VECTOR 08h, Timer ; 装填时钟中断向量表 16 | call dword startUp 17 | 18 | Keyboard: 19 | mov ah, 0 20 | int 16h 21 | cmp al, 0dh ; 按下回车 22 | jne Keyboard ; 无效按键,重新等待用户按键 23 | call dword shell ; 进入命令行界面 24 | jmp Keyboard ; 无限循环 -------------------------------------------------------------------------------- /项目4_异步事件编程技术/src/stringio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: Jed 3 | * @Description: 涉及字符串输入输出的C函数库 4 | * @Date: 2019-03-23 5 | * @LastEditTime: 2019-04-01 6 | */ 7 | #include 8 | #define funi(a) fun( a, 10) 9 | extern void printInPos(const char *msg, uint16_t len, uint8_t row, uint8_t col); 10 | // extern void putchar(char c); 11 | extern void putchar_c(char c, uint8_t color); 12 | extern char getch(); 13 | enum bios_color {white_c=0x07}; 14 | // char tempc; // 临时存放一个字符的地方 15 | 16 | /* 字符串长度 */ 17 | uint16_t strlen(const char *str) { 18 | int count = 0; 19 | while (str[count++] != '\0'); 20 | return count - 1; // 循环中使用后递增,因此这里需要减1 21 | } 22 | 23 | /* 比较字符串 */ 24 | uint8_t strcmp(const char* str1, const char* str2) { 25 | int i = 0; 26 | while (1) { 27 | if(str1[i]=='\0' || str2[i]=='\0') { break; } 28 | if(str1[i] != str2[i]) { break; } 29 | ++i; 30 | } 31 | return str1[i] - str2[i]; 32 | } 33 | 34 | /* 显示一个白色字符 */ 35 | void putchar(char c) { 36 | putchar_c(c, 0x07); 37 | } 38 | 39 | /* 在光标处显示字符串 */ 40 | void print(const char* str) { 41 | for(int i = 0, len = strlen(str); i < len; i++) { 42 | putchar(str[i]); 43 | } 44 | } 45 | 46 | /* 在光标处显示彩色字符串 */ 47 | void print_c(const char* str, uint8_t color) { 48 | for(int i = 0, len = strlen(str); i < len; i++) { 49 | putchar_c(str[i], color); 50 | } 51 | } 52 | 53 | /* 读取字符串到缓冲区 */ 54 | void readToBuf(char* buffer, uint16_t maxlen) { 55 | int i = 0; 56 | while(1) { 57 | char tempc = getch(); 58 | if(!(tempc==0xD || tempc=='\b' || tempc>=32 && tempc<=127)) { continue; } // 非有效字符不予理会 59 | if(i > 0 && i < maxlen-1) { // buffer中有字符且未满 60 | if(tempc == 0x0D) { 61 | break; // 按下回车,停止读取 62 | } 63 | else if(tempc == '\b') { // 按下退格,则删除一个字符 64 | putchar('\b'); 65 | putchar(' '); 66 | putchar('\b'); 67 | --i; 68 | } 69 | else{ 70 | putchar(tempc); // 回显 71 | buffer[i] = tempc; 72 | ++i; 73 | } 74 | } 75 | else if(i >= maxlen-1) { // 达到最大值,只能按退格或回车 76 | if(tempc == '\b') { // 按下退格,则删除一个字符 77 | putchar('\b'); 78 | putchar(' '); 79 | putchar('\b'); 80 | --i; 81 | } 82 | else if(tempc == 0x0D) { 83 | break; // 按下回车,停止读取 84 | } 85 | } 86 | else if(i <= 0) { // buffer中没有字符,只能输入或回车,不能删除 87 | if(tempc == 0x0D) { 88 | break; // 按下回车,停止读取 89 | } 90 | else if(tempc != '\b') { 91 | putchar(tempc); // 回显 92 | buffer[i] = tempc; 93 | ++i; 94 | } 95 | } 96 | } 97 | putchar('\r'); putchar('\n'); 98 | buffer[i] = '\0'; // 字符串必须以空字符结尾 99 | } 100 | 101 | /* 将整数转为指定进制的字符串 */ 102 | const char* itoa(int val, int base) { 103 | if(val==0) return "0"; 104 | static char buf[32] = {0}; 105 | int i = 30; 106 | for(; val && i ; --i, val /= base) { 107 | buf[i] = "0123456789ABCDEF"[val % base]; 108 | } 109 | return &buf[i+1]; 110 | } 111 | 112 | /* 判断字符是否是十进制数字 */ 113 | uint8_t isnum(char c) { 114 | return c>='0' && c<='9'; 115 | } 116 | 117 | /* 获取字符串的第一个空格前的词 */ 118 | void getFirstWord(const char* str, char* buf) { 119 | int i = 0; 120 | while(str[i] && str[i] != ' ') { 121 | buf[i] = str[i]; 122 | i++; 123 | } 124 | buf[i] = '\0'; // 字符串必须以空字符结尾 125 | } 126 | 127 | /* 获取字符串的第一个空格后的词 */ 128 | void getAfterFirstWord(const char* str, char* buf) { 129 | buf[0] = '\0'; // 为了应对用户故意搞破坏 130 | int i = 0; 131 | while(str[i] && str[i] != ' ') { 132 | i++; 133 | } 134 | while(str[i] && str[i] == ' ') { 135 | i++; 136 | } 137 | int j = 0; 138 | while(str[i]) { 139 | buf[j++] = str[i++]; 140 | } 141 | buf[j] = '\0'; // 字符串必须以空字符结尾 142 | } -------------------------------------------------------------------------------- /项目4_异步事件编程技术/src/usrprog/intcaller.asm: -------------------------------------------------------------------------------- 1 | %include "../macro.asm" 2 | org offset_intcaller 3 | 4 | Start: 5 | pusha 6 | push ds 7 | mov ax, cs 8 | mov ds, ax 9 | call ClearScreen 10 | PRINT_IN_POS hint_msg1, hint_msg1_len, 7, 10 11 | PRINT_IN_POS hint_msg2, hint_msg2_len, 10, 10 12 | 13 | ; 这四个中断处理程序是相同的,参数是不同的 14 | WRITE_INT_VECTOR 33, Int33~36 15 | WRITE_INT_VECTOR 34, Int33~36 16 | WRITE_INT_VECTOR 35, Int33~36 17 | WRITE_INT_VECTOR 36, Int33~36 18 | 19 | Keyboard: 20 | mov ah, 0 21 | int 16h 22 | cmp al, '3' ; 按下3 23 | je callInt33 ; 执行int 33 24 | cmp al, '4' ; 按下4 25 | je callInt34 ; 执行int 34 26 | cmp al, '5' ; 按下5 27 | je callInt35 ; 执行int 35 28 | cmp al, '6' ; 按下6 29 | je callInt36 ; 执行int 36 30 | cmp al, 27 ; 按下ESC 31 | je QuitUsrProg ; 直接退出 32 | jmp Keyboard ; 无效按键,重新等待用户按键 33 | 34 | callInt33: 35 | mov word[start_row], 0 36 | mov word[end_row], 5 37 | int 33 38 | jmp QuitUsrProg 39 | callInt34: 40 | mov word[start_row], 6 41 | mov word[end_row], 11 42 | int 34 43 | jmp QuitUsrProg 44 | callInt35: 45 | mov word[start_row], 12 46 | mov word[end_row], 17 47 | int 35 48 | jmp QuitUsrProg 49 | callInt36: 50 | mov word[start_row], 18 51 | mov word[end_row], 24 52 | int 36 53 | jmp QuitUsrProg 54 | 55 | QuitUsrProg: 56 | pop ds 57 | popa 58 | retf 59 | 60 | ClearScreen: ; 函数:清屏 61 | pusha 62 | mov ax, 0003h 63 | int 10h ; 中断调用,清屏 64 | popa 65 | ret 66 | 67 | Footer: 68 | hint_msg1 db 'This is the Interrupt Caller Programme.' 69 | hint_msg1_len equ $-hint_msg1 70 | hint_msg2 db 'Press `3/4/5/6` to call int 33/34/35/36. Press `ESC` to quit.' 71 | hint_msg2_len equ $-hint_msg2 72 | 73 | %include "interrupt/int33~36.asm" -------------------------------------------------------------------------------- /项目4_异步事件编程技术/src/usrprog/interrupt/int33~36.asm: -------------------------------------------------------------------------------- 1 | ; @Author: Jed 2 | ; @Description: int 33h/34h/35h/36h的中断处理程序 3 | ; @Date: 2019-03-28 4 | ; @LastEditTime: 2019-04-03 5 | 6 | Int33~36: 7 | push ax 8 | push si 9 | push ds 10 | push gs 11 | 12 | mov ax,cs 13 | mov ds,ax ; DS = CS 14 | mov ax,0B800h ; 文本窗口显存起始地址 15 | mov gs,ax ; GS = B800h 16 | mov ax, [start_row] ; ax=start_row 17 | mov ah, 2*80 ; ah=2*80 18 | mul ah ; ax=start_row * 2 * 80 19 | mov si, ax ; si初始化为起始位置指针 20 | disploop: 21 | mov al, [temp_char] ; 要显示的字符 22 | mov [gs:si], al ; 显示字符 23 | inc si ; 递增指针 24 | mov ah, [temp_color] ; 字符颜色属性 25 | mov [gs:si], ah ; 显示颜色属性 26 | inc si ; 递增指针 27 | add byte[temp_color], 11h ; 改变颜色 28 | call Delay ; 延时 29 | 30 | mov ah, 01h ; 功能号:查询键盘缓冲区但不等待 31 | int 16h 32 | jz NoEsc ; 无键盘按下,继续 33 | mov ah, 0 ; 功能号:查询键盘输入 34 | int 16h 35 | cmp al, 27 ; 是否按下ESC 36 | je QuitInt ; 若按下ESC,退出用户程序 37 | NoEsc: 38 | mov ax, [end_row] ; al=end_row,ah实际上无用 39 | mov ah, 2*80 40 | mul ah ; ax=end_row * 2 * 80 41 | add ax, [start_row] ; ax=start_row + end_row*2*80 42 | cmp si, ax 43 | jne disploop ; 范围全部显示完,中断返回 44 | 45 | QuitInt: 46 | pop gs 47 | pop ds 48 | pop si 49 | pop ax 50 | iret ; 中断返回 51 | 52 | Delay: ; 延迟一段时间 53 | push ax 54 | push cx 55 | mov ax, 100 56 | delay_outer: 57 | mov cx, 50000 58 | delay_inner: 59 | loop delay_inner 60 | dec ax 61 | cmp ax, 0 62 | jne delay_outer 63 | pop cx 64 | pop ax 65 | ret 66 | 67 | DataArea: 68 | start_row dw 0 69 | end_row dw 0 70 | temp_color db 0 71 | temp_char db ' ' -------------------------------------------------------------------------------- /项目4_异步事件编程技术/src/usrprog/interrupt/intouch.asm: -------------------------------------------------------------------------------- 1 | IntOuch: 2 | pusha 3 | push ds 4 | push es 5 | 6 | mov ax, cs ; 置其他段寄存器值与CS相同 7 | mov ds, ax ; 数据段 8 | mov bp, ouch_msg ; BP=当前串的偏移地址 9 | mov ax, ds ; ES:BP = 串地址 10 | mov es, ax ; 置ES=DS 11 | mov cx, ouch_msg_len ; CX = 串长 12 | mov ax, 1300h ; AH = 13h(功能号)、AL = 01h(光标不动) 13 | mov bx, 0007h ; 页号为0(BH = 0) 黑底白字(BL = 07h) 14 | mov dh, 20 ; 行号=0 15 | mov dl, 40 ; 列号=0 16 | int 10h ; BIOS的10h功能:显示一行字符 17 | 18 | call Delay 19 | 20 | mov ax, cs ; 置其他段寄存器值与CS相同 21 | mov ds, ax ; 数据段 22 | mov bp, ouch_clear ; BP=当前串的偏移地址 23 | mov ax, ds ; ES:BP = 串地址 24 | mov es, ax ; 置ES=DS 25 | mov cx, ouch_msg_len ; CX = 串长 26 | mov ax, 1300h ; AH = 13h(功能号)、AL = 01h(光标不动) 27 | mov bx, 0007h ; 页号为0(BH = 0) 黑底白字(BL = 07h) 28 | mov dh, 20 ; 行号=0 29 | mov dl, 40 ; 列号=0 30 | int 10h ; BIOS的10h功能:显示一行字符 31 | 32 | int 39h ; 原来的BIOS int 09h 33 | 34 | mov al,20h ; AL = EOI 35 | out 20h,al ; 发送EOI到主8529A 36 | out 0A0h,al ; 发送EOI到从8529A 37 | 38 | pop es 39 | pop ds 40 | popa 41 | iret ; 从中断返回 42 | 43 | Delay: ; 延迟一段时间 44 | push ax 45 | push cx 46 | mov ax, 580 47 | delay_outer: 48 | mov cx, 50000 49 | delay_inner: 50 | loop delay_inner 51 | dec ax 52 | cmp ax, 0 53 | jne delay_outer 54 | pop cx 55 | pop ax 56 | ret 57 | 58 | 59 | ouch_msg db 'OUCH! OUCH!' 60 | ouch_msg_len equ $-ouch_msg 61 | ouch_clear db ' ' -------------------------------------------------------------------------------- /项目4_异步事件编程技术/src/usrprog/stone_bottomleft.asm: -------------------------------------------------------------------------------- 1 | ; 原作:凌应标 2014-03 2 | ; 改写:张怡昕(17341203) 2019-03 3 | ; 说明:本程序是jed_stone.asm的改版。本程序在显示器左上角进行字符反弹。 4 | ; 参数:(-1, -1, 40, 13, 0, 7) 5 | %include "../macro.asm" 6 | org offset_usrprog3 7 | 8 | Dn_Rt equ 1 ; D-Down,U-Up,R-right,L-Left 9 | Up_Rt equ 2 10 | Up_Lt equ 3 11 | Dn_Lt equ 4 12 | delay equ 50000 ; 计时器延迟计数,用于控制画框的速度 13 | ddelay equ 580 ; 计时器延迟计数,用于控制画框的速度 14 | 15 | screen_left equ -1 ; 字符运动左边界 16 | screen_top equ 11 ; 字符运动上边界 17 | screen_right equ 40 ; 字符运动右边界 18 | screen_bottom equ 25 ; 字符运动下边界 19 | originpos_y equ 0 ; 起点列数 20 | originpos_x equ 19 ; 起点行数 21 | 22 | start: 23 | pusha 24 | mov ax, 0 25 | mov es, ax 26 | MOVE_INT_VECTOR 09h, 39h 27 | WRITE_INT_VECTOR 09h, IntOuch 28 | call ClearScreen ; 清屏 29 | mov ax,cs 30 | mov es,ax ; ES = CS 31 | mov ds,ax ; DS = CS 32 | mov es,ax ; ES = CS 33 | mov ax,0B800h 34 | mov gs,ax ; GS = B800h,指向文本模式的显示缓冲区 35 | mov byte[char],'X' 36 | 37 | PRINT_IN_POS hint1, hint1len, 16, 30 38 | 39 | initialize: ; 多次调用用户程序时,可保证初始值是相同的 40 | mov word[x], originpos_x 41 | mov word[y], originpos_y 42 | mov byte[curcolor], 80h 43 | mov byte[curcolor2], 01h 44 | mov word[count], delay 45 | mov word[dcount], ddelay 46 | mov byte[rdul], Dn_Rt ; 向右下运动 47 | 48 | loop1: 49 | dec word[count] ; 递减计数变量 50 | jnz loop1 ; >0:跳转; 51 | mov word[count],delay 52 | dec word[dcount] ; 递减计数变量 53 | jnz loop1 54 | mov word[count],delay 55 | mov word[dcount],ddelay 56 | 57 | mov al,1 58 | cmp al,byte[rdul] 59 | jz DnRt 60 | mov al,2 61 | cmp al,byte[rdul] 62 | jz UpRt 63 | mov al,3 64 | cmp al,byte[rdul] 65 | jz UpLt 66 | mov al,4 67 | cmp al,byte[rdul] 68 | jz DnLt 69 | ; jmp $ 70 | 71 | DnRt: 72 | inc word[x] 73 | inc word[y] 74 | mov bx,word[x] 75 | mov ax,screen_bottom 76 | sub ax,bx 77 | jz dr2ur 78 | mov bx,word[y] 79 | mov ax,screen_right 80 | sub ax,bx 81 | jz dr2dl 82 | jmp show 83 | 84 | dr2ur: 85 | mov word[x],screen_bottom-2 86 | mov byte[rdul],Up_Rt 87 | jmp show 88 | 89 | dr2dl: 90 | mov word[y],screen_right-2 91 | mov byte[rdul],Dn_Lt 92 | jmp show 93 | 94 | 95 | UpRt: 96 | dec word[x] 97 | inc word[y] 98 | mov bx,word[y] 99 | mov ax,screen_right 100 | sub ax,bx 101 | jz ur2ul 102 | mov bx,word[x] 103 | mov ax,screen_top 104 | sub ax,bx 105 | jz ur2dr 106 | jmp show 107 | 108 | ur2ul: 109 | mov word[y],screen_right-2 110 | mov byte[rdul],Up_Lt 111 | jmp show 112 | 113 | ur2dr: 114 | mov word[x],screen_top+2 115 | mov byte[rdul],Dn_Rt 116 | jmp show 117 | 118 | 119 | UpLt: 120 | dec word[x] 121 | dec word[y] 122 | mov bx,word[x] 123 | mov ax,screen_top 124 | sub ax,bx 125 | jz ul2dl 126 | mov bx,word[y] 127 | mov ax,screen_left 128 | sub ax,bx 129 | jz ul2ur 130 | jmp show 131 | 132 | ul2dl: 133 | mov word[x],screen_top+2 134 | mov byte[rdul],Dn_Lt 135 | jmp show 136 | ul2ur: 137 | mov word[y],screen_left+2 138 | mov byte[rdul],Up_Rt 139 | jmp show 140 | 141 | DnLt: 142 | inc word[x] 143 | dec word[y] 144 | mov bx,word[y] 145 | mov ax,screen_left 146 | sub ax,bx 147 | jz dl2dr 148 | mov bx,word[x] 149 | mov ax,screen_bottom 150 | sub ax,bx 151 | jz dl2ul 152 | jmp show 153 | 154 | dl2dr: 155 | mov word[y],screen_left+2 156 | mov byte[rdul],Dn_Rt 157 | jmp show 158 | 159 | dl2ul: 160 | mov word[x],screen_bottom-2 161 | mov byte[rdul],Up_Lt 162 | jmp show 163 | 164 | show: 165 | xor ax,ax ; 计算显存地址 166 | mov ax,word[x] 167 | mov bx,80 168 | mul bx 169 | add ax,word[y] 170 | mov bx,2 171 | mul bx 172 | mov bp,ax 173 | mov ah,[curcolor2] ; 弹字符的背景色和前景色(默认值为07h,详见文档) 174 | inc byte[curcolor2] 175 | cmp byte[curcolor2], 0fh 176 | jnz skip 177 | mov byte[curcolor2], 1 ; 为了不改变背景色 178 | skip: 179 | mov al,byte[char] ; AL = 显示字符值(默认值为20h=空格符) 180 | mov word[gs:bp],ax ; 显示字符的ASCII码值 181 | 182 | mov ah, 01h ; 功能号:查询键盘缓冲区但不等待 183 | int 16h 184 | jz continue ; 无键盘按下,继续 185 | mov ah, 0 ; 功能号:查询键盘输入 186 | int 16h 187 | cmp al, 27 ; 是否按下ESC 188 | je QuitUsrProg ; 若按下ESC,退出用户程序 189 | 190 | continue: 191 | jmp loop1 192 | 193 | end: 194 | jmp $ ; 停止画框,无限循环 195 | 196 | QuitUsrProg: 197 | MOVE_INT_VECTOR 39h, 09h 198 | popa 199 | retf 200 | 201 | ClearScreen: ; 函数:清屏 202 | pusha 203 | mov ax, 0003h 204 | int 10h ; 中断调用,清屏 205 | popa 206 | ret 207 | 208 | DataArea: 209 | count dw delay 210 | dcount dw ddelay 211 | rdul db Dn_Rt ; 向右下运动 212 | char db 0 213 | 214 | x dw originpos_x 215 | y dw originpos_y 216 | 217 | curcolor db 80h ; 保存当前字符颜色属性,用于myinfo 218 | curcolor2 db 01h ; 保存当前字符颜色属性,用于移动的字符 219 | 220 | hint1 db 'This is user program 3. Press ESC to exit.' 221 | hint1len equ ($-hint1) 222 | 223 | %include "interrupt/intouch.asm" -------------------------------------------------------------------------------- /项目4_异步事件编程技术/src/usrproginfo.asm: -------------------------------------------------------------------------------- 1 | ; @Author: Jed 2 | ; @Description: 用户车呢光绪信息表。放在软盘第2个扇区。 3 | ; @Date: 2019-03-29 4 | ; @LastEditTime: 2019-04-01 5 | 6 | %include "macro.asm" 7 | %macro UsrProgInfoBlock 7 ; 参数:(PID,程序名,字节数,柱面,磁头,扇区,内存地址) 8 | pid%1 db %1 ; 程序编号PID;相对偏移0 9 | name%1 db %2 ; 程序名(至多32字节);相对偏移1 10 | times 16-($-name%1) db 0 ; 程序名占6字节 11 | size%1 dw %3 ; 程序大小;相对偏移17 12 | cylinder%1 db %4 ; 柱面;相对偏移19 13 | head%1 db %5 ; 磁头;相对偏移20 14 | sector%1 db %6 ; 扇区;相对偏移21 15 | addr%1 dw %7 ; 内存中的地址;相对偏移22 16 | %endmacro ; 共24个字节 17 | 18 | UsrProgNumber: 19 | db 5 ; 用户程序数量 20 | 21 | UserProgInfo: 22 | UsrProgInfoBlock 1, 'stone_topleft', 1024, 0, 1, 1, offset_usrprog1 23 | UsrProgInfoBlock 2, 'stone_topright', 1024, 0, 1, 3, offset_usrprog2 24 | UsrProgInfoBlock 3, 'stone_botleft', 1024, 0, 1, 5, offset_usrprog3 25 | UsrProgInfoBlock 4, 'stone_botright', 1024, 0, 1, 7, offset_usrprog4 26 | UsrProgInfoBlock 5, 'interrupt_caller', 512, 0, 1, 9, offset_intcaller 27 | 28 | SectorEnding: 29 | times 512-($-$$) db 0 -------------------------------------------------------------------------------- /项目5_实现系统调用/JedOS_v1.3.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目5_实现系统调用/JedOS_v1.3.img -------------------------------------------------------------------------------- /项目5_实现系统调用/assets/1555727545043.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目5_实现系统调用/assets/1555727545043.png -------------------------------------------------------------------------------- /项目5_实现系统调用/assets/1555727712376.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目5_实现系统调用/assets/1555727712376.png -------------------------------------------------------------------------------- /项目5_实现系统调用/assets/1555727791792.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目5_实现系统调用/assets/1555727791792.png -------------------------------------------------------------------------------- /项目5_实现系统调用/assets/1555727843599.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目5_实现系统调用/assets/1555727843599.png -------------------------------------------------------------------------------- /项目5_实现系统调用/assets/1555727947447.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目5_实现系统调用/assets/1555727947447.png -------------------------------------------------------------------------------- /项目5_实现系统调用/assets/1555727993888.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目5_实现系统调用/assets/1555727993888.png -------------------------------------------------------------------------------- /项目5_实现系统调用/assets/1555728178849.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目5_实现系统调用/assets/1555728178849.png -------------------------------------------------------------------------------- /项目5_实现系统调用/assets/1555728215973.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目5_实现系统调用/assets/1555728215973.png -------------------------------------------------------------------------------- /项目5_实现系统调用/assets/1555728244608.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目5_实现系统调用/assets/1555728244608.png -------------------------------------------------------------------------------- /项目5_实现系统调用/assets/1555728336372.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目5_实现系统调用/assets/1555728336372.png -------------------------------------------------------------------------------- /项目5_实现系统调用/src/bootloader.asm: -------------------------------------------------------------------------------- 1 | ; @Author: Jed 2 | ; @Description: 引导程序;独立编译 3 | ; @Date: 2019-03-21 4 | ; @LastEditTime: 2019-04-12 5 | 6 | BITS 16 7 | %include "macro.asm" 8 | org 7c00h 9 | 10 | global _start 11 | _start: 12 | mov ax, cs 13 | mov ds, ax ; ds=cs 14 | PRINT_IN_POS msg, msg_len, 0, 0 ; 调用宏,显示字符串 15 | 16 | LoadOsKernel: 17 | LOAD_TO_MEM 16, 0, 0, 3, offset_oskernel ; 调用宏,加载操作系统内核 18 | 19 | LoadUsrProgInfo: 20 | LOAD_TO_MEM 1, 0, 0, 2, offset_upinfo ; 调用宏,加载用户程序信息表 21 | 22 | EnterOs: 23 | jmp offset_oskernel ; 跳转到操作系统内核 24 | 25 | DataArea: 26 | msg db 'Bootloader is loading operating system...' 27 | msg_len equ ($-msg) 28 | 29 | times 510-($-$$) db 0 30 | db 0x55, 0xaa ; 主引导记录标志 -------------------------------------------------------------------------------- /项目5_实现系统调用/src/hotwheel.asm: -------------------------------------------------------------------------------- 1 | BITS 16 2 | [global Timer] 3 | Timer: 4 | push ax 5 | push ds 6 | push gs 7 | push si 8 | 9 | mov ax,cs 10 | mov ds,ax ; DS = CS 11 | mov ax,0B800h ; 文本窗口显存起始地址 12 | mov gs,ax ; GS = B800h 13 | 14 | dec byte [count] ; 递减计数变量 15 | jnz EndInt ; >0:跳转 16 | mov byte[count],delay ; 重置计数变量=初值delay 17 | mov si, hotwheel ; 风火轮首字符地址 18 | add si, [wheel_offset] ; 风火轮字符偏移量 19 | mov al, [si] ; al=要显示的字符 20 | mov ah, 0Ch ; ah=黑底,淡红色 21 | mov [gs:((80*24+79)*2)], ax ; 更新显存 22 | inc byte[wheel_offset] ; 递增偏移量 23 | cmp byte[wheel_offset], 4 ; 检查偏移量是否超过3 24 | jne EndInt ; 没有超过,中断返回 25 | mov byte[wheel_offset], 0 ; 超过3了,重置为0 26 | EndInt: 27 | mov al,20h ; AL = EOI 28 | out 20h,al ; 发送EOI到主8529A 29 | out 0A0h,al ; 发送EOI到从8529A 30 | 31 | pop si 32 | pop gs 33 | pop ds 34 | pop ax 35 | iret ; 从中断返回 36 | 37 | 38 | DataArea: 39 | delay equ 3 ; 计时器延迟计数 40 | count db delay ; 计时器计数变量,初值=delay 41 | hotwheel db '-\|/' ; 风火轮字符 42 | wheel_offset dw 0 ; 风火轮字符偏移量,初值=0 -------------------------------------------------------------------------------- /项目5_实现系统调用/src/lib/systema.asm: -------------------------------------------------------------------------------- 1 | BITS 16 2 | [global sys_showOuch] 3 | [global sys_toUpper] 4 | [global sys_toLower] 5 | [global sys_atoi] 6 | [global sys_itoa] 7 | [global sys_printInPos] 8 | 9 | sys_showOuch: 10 | pusha ; 保护现场 11 | push ds 12 | push es 13 | mov ax, cs ; 置其他段寄存器值与CS相同 14 | mov ds, ax ; 数据段 15 | mov bp, ouch_str ; BP=当前串的偏移地址 16 | mov ax, ds ; ES:BP = 串地址 17 | mov es, ax ; 置ES=DS 18 | mov cx, 4 ; CX = 串长 19 | mov ax, 1301h ; AH = 13h(功能号)、AL = 01h(光标置于串尾) 20 | mov bx, 0038h ; 页号为0(BH = 0) 黑底白字(BL = 07h) 21 | mov dh, 12 ; 行号 22 | mov dl, 38 ; 列号 23 | int 10h ; BIOS的10h功能:显示一行字符 24 | pop es 25 | pop ds 26 | popa ; 恢复现场 27 | ret 28 | ouch_str db 'OUCH' 29 | 30 | [extern toupper] 31 | sys_toUpper: 32 | push es ; 传递参数 33 | push dx ; 传递参数 34 | call dword toupper 35 | pop dx ; 丢弃参数 36 | pop es ; 丢弃参数 37 | ret 38 | 39 | [extern tolower] 40 | sys_toLower: 41 | push es ; 传递参数 42 | push dx ; 传递参数 43 | call dword tolower 44 | pop dx ; 丢弃参数 45 | pop es ; 丢弃参数 46 | ret 47 | 48 | [extern atoi] 49 | sys_atoi: 50 | push es ; 传递参数 51 | push dx ; 传递参数 52 | call dword atoi 53 | pop dx ; 丢弃参数 54 | pop es ; 丢弃参数 55 | ret 56 | 57 | [extern itoa_buf] 58 | sys_itoa: 59 | push es ; 传递参数buf 60 | push dx ; 传递参数buf 61 | mov ax, 0 62 | push ax ; 传递参数base 63 | mov ax, 10 ; 10进制 64 | push ax ; 传递参数base 65 | mov ax, 0 66 | push ax ; 传递参数val 67 | push bx ; 传递参数val 68 | call dword itoa_buf 69 | pop bx ; 丢弃参数 70 | pop ax ; 丢弃参数 71 | pop ax ; 丢弃参数 72 | pop ax ; 丢弃参数 73 | pop dx ; 丢弃参数 74 | pop es ; 丢弃参数 75 | ret 76 | 77 | [extern strlen] 78 | sys_printInPos: 79 | pusha 80 | mov bp, dx ; es:bp=串地址 81 | push es ; 传递参数 82 | push bp ; 传递参数 83 | call dword strlen ; 返回值ax=串长 84 | pop bp ; 丢弃参数 85 | pop es ; 丢弃参数 86 | mov bl, 07h ; 颜色 87 | mov dh, ch ; 行号 88 | mov dl, cl ; 列号 89 | mov cx, ax ; 串长 90 | mov bh, 0 ; 页码 91 | mov al, 0 ; 光标不动 92 | mov ah, 13h ; BIOS功能号 93 | int 10h 94 | popa 95 | ret -------------------------------------------------------------------------------- /项目5_实现系统调用/src/lib/systemc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define bool unsigned short 3 | #define true 1 4 | #define false 0 5 | 6 | /* 将字符串中的小写字母转换为大写 */ 7 | void toupper(char* str) { 8 | int i=0; 9 | while(str[i]) { 10 | if (str[i] >= 'a' && str[i] <= 'z') 11 | str[i] = str[i]-'a'+'A'; 12 | i++; 13 | } 14 | } 15 | 16 | /* 将字符串中的大写字母转换为小写 */ 17 | void tolower(char* str) { 18 | int i=0; 19 | while(str[i]) { 20 | if (str[i] >= 'A' && str[i] <= 'Z') 21 | str[i] = str[i]-'A'+'a'; 22 | i++; 23 | } 24 | } 25 | 26 | /* 翻转字符串 */ 27 | void my_reverse(char str[], int len) 28 | { 29 | int start, end; 30 | char temp; 31 | for (start = 0, end = len - 1; start < end; start++, end--) { 32 | temp = *(str + start); 33 | *(str + start) = *(str + end); 34 | *(str + end) = temp; 35 | } 36 | } 37 | 38 | /* 将数字转换为字符串并放在str中 */ 39 | char* itoa_buf(int num, int base, char* str) 40 | { 41 | int i = 0; 42 | bool isNegative = false; 43 | 44 | /* A zero is same "0" string in all base */ 45 | if (num == 0) { 46 | str[i] = '0'; 47 | str[i + 1] = '\0'; 48 | return str; 49 | } 50 | 51 | /* negative numbers are only handled if base is 10 52 | otherwise considered unsigned number */ 53 | if (num < 0 && base == 10) { 54 | isNegative = true; 55 | num = -num; 56 | } 57 | 58 | while (num != 0) { 59 | int rem = num % base; 60 | str[i++] = (rem > 9) ? (rem - 10) + 'A' : rem + '0'; 61 | num = num / base; 62 | } 63 | 64 | /* Append negative sign for negative numbers */ 65 | if (isNegative) { 66 | str[i++] = '-'; 67 | } 68 | 69 | str[i] = '\0'; 70 | 71 | my_reverse(str, i); 72 | 73 | return str; 74 | } 75 | 76 | /* 将十进制数字字符串转换为整数 */ 77 | int atoi(char *str) { 78 | int res = 0; // Initialize result 79 | 80 | // Iterate through all characters of input string and 81 | // update result 82 | for (int i = 0; str[i] != '\0'; ++i) { 83 | res = res*10 + str[i] - '0'; 84 | } 85 | // return result. 86 | return res; 87 | } -------------------------------------------------------------------------------- /项目5_实现系统调用/src/macro.asm: -------------------------------------------------------------------------------- 1 | offset_upinfo equ 7E00h ; 用户程序信息表被装入的位置 2 | offset_oskernel equ 8000h ; 操作系统内核被装入的位置 3 | 4 | offset_usrprog1 equ 0A300h 5 | offset_usrprog2 equ 0A700h 6 | offset_usrprog3 equ 0AB00h 7 | offset_usrprog4 equ 0AF00h 8 | offset_intcaller equ 0xB300 9 | offset_syscalltest equ 0xB500 10 | 11 | %macro WRITE_INT_VECTOR 2 ; 写中断向量表;参数:(中断号,中断处理程序地址) 12 | push ax 13 | push es 14 | mov ax, 0 15 | mov es, ax ; ES = 0 16 | mov word[es:%1*4], %2 ; 设置中断向量的偏移地址 17 | mov ax,cs 18 | mov word[es:%1*4+2], ax ; 设置中断向量的段地址=CS 19 | pop es 20 | pop ax 21 | %endmacro 22 | 23 | %macro MOVE_INT_VECTOR 2 ; 转移中断向量;参数:(源中断号,目的中断号) 24 | push ax 25 | push es 26 | push si 27 | mov ax, 0 28 | mov es, ax 29 | mov si, [es:%1*4] 30 | mov [es:%2*4], si 31 | mov si, [es:%1*4+2] 32 | mov [es:%2*4+2], si 33 | pop si 34 | pop es 35 | pop ax 36 | %endmacro 37 | 38 | %macro PRINT_IN_POS 4 ; 在指定位置打印字符串;参数:(串地址,串长,行号,列号) 39 | pusha ; 保护现场 40 | push ds 41 | push es 42 | mov ax, cs ; 置其他段寄存器值与CS相同 43 | mov ds, ax ; 数据段 44 | mov bp, %1 ; BP=当前串的偏移地址 45 | mov ax, ds ; ES:BP = 串地址 46 | mov es, ax ; 置ES=DS 47 | mov cx, %2 ; CX = 串长(=9) 48 | mov ax, 1301h ; AH = 13h(功能号)、AL = 01h(光标置于串尾) 49 | mov bx, 0007h ; 页号为0(BH = 0) 黑底白字(BL = 07h) 50 | mov dh, %3 ; 行号=0 51 | mov dl, %4 ; 列号=0 52 | int 10h ; BIOS的10h功能:显示一行字符 53 | pop es 54 | pop ds 55 | popa ; 恢复现场 56 | %endmacro 57 | 58 | %macro LOAD_TO_MEM 5 ; 读软盘到内存;参数:(扇区数,柱面号,磁头号,扇区号,内存地址) 59 | pusha 60 | push es 61 | mov ax,cs ; 段地址; 存放数据的内存基地址 62 | mov es,ax ; 设置段地址(不能直接mov es,段地址) 63 | mov bx, %5 ; 偏移地址; 存放数据的内存偏移地址 64 | mov ah,2 ; 功能号 65 | mov al, %1 ; 扇区数 66 | mov dl,0 ; 驱动器号; 软盘为0,硬盘和U盘为80H 67 | mov dh,%3 ; 磁头号; 起始编号为0 68 | mov ch, %2 ; 柱面号; 起始编号为0 69 | mov cl,%4 ; 起始扇区号 ; 起始编号为1 70 | int 13H ; 调用读磁盘BIOS的13h功能 71 | pop es 72 | popa 73 | %endmacro -------------------------------------------------------------------------------- /项目5_实现系统调用/src/merge.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | rm -rf temp 3 | mkdir temp 4 | rm *.img 5 | 6 | nasm bootloader.asm -o ./temp/bootloader.bin 7 | nasm usrproginfo.asm -o ./temp/usrproginfo.bin 8 | 9 | cd usrprog 10 | nasm stone_topleft.asm -o ../temp/stone_topleft.bin 11 | nasm stone_topright.asm -o ../temp/stone_topright.bin 12 | nasm stone_bottomleft.asm -o ../temp/stone_bottomleft.bin 13 | nasm stone_bottomright.asm -o ../temp/stone_bottomright.bin 14 | nasm interrupt_caller.asm -o ../temp/interrupt_caller.bin 15 | nasm syscall_test.asm -o ../temp/syscall_test.bin 16 | cd .. 17 | 18 | cd lib 19 | nasm -f elf32 systema.asm -o ../temp/systema.o 20 | gcc -c -m16 -march=i386 -masm=intel -nostdlib -ffreestanding -mpreferred-stack-boundary=2 -lgcc -shared systemc.c -o ../temp/systemc.o 21 | cd .. 22 | 23 | nasm -f elf32 hotwheel.asm -o ./temp/hotwheel.o 24 | 25 | nasm -f elf32 osstarter.asm -o ./temp/osstarter.o 26 | nasm -f elf32 liba.asm -o ./temp/liba.o 27 | gcc -c -m16 -march=i386 -masm=intel -nostdlib -ffreestanding -mpreferred-stack-boundary=2 -lgcc -shared kernel.c -o ./temp/kernel.o 28 | ld -m elf_i386 -N -Ttext 0x8000 --oformat binary ./temp/osstarter.o ./temp/liba.o ./temp/kernel.o ./temp/systema.o ./temp/systemc.o ./temp/hotwheel.o -o ./temp/kernel.bin 29 | rm ./temp/*.o 30 | 31 | dd if=./temp/bootloader.bin of=JedOS_v1.3.img bs=512 count=1 2> /dev/null 32 | dd if=./temp/usrproginfo.bin of=JedOS_v1.3.img bs=512 seek=1 count=1 2> /dev/null 33 | dd if=./temp/kernel.bin of=JedOS_v1.3.img bs=512 seek=2 count=16 2> /dev/null 34 | dd if=./temp/stone_topleft.bin of=JedOS_v1.3.img bs=512 seek=18 count=2 2> /dev/null 35 | dd if=./temp/stone_topright.bin of=JedOS_v1.3.img bs=512 seek=20 count=2 2> /dev/null 36 | dd if=./temp/stone_bottomleft.bin of=JedOS_v1.3.img bs=512 seek=22 count=2 2> /dev/null 37 | dd if=./temp/stone_bottomright.bin of=JedOS_v1.3.img bs=512 seek=24 count=2 2> /dev/null 38 | dd if=./temp/interrupt_caller.bin of=JedOS_v1.3.img bs=512 seek=26 count=1 2> /dev/null 39 | dd if=./temp/syscall_test.bin of=JedOS_v1.3.img bs=512 seek=27 count=3 2> /dev/null 40 | 41 | 42 | echo "[+] Done." -------------------------------------------------------------------------------- /项目5_实现系统调用/src/osstarter.asm: -------------------------------------------------------------------------------- 1 | ; @Author: Jed 2 | ; @Description: 操作系统内核入口 3 | ; @Date: 2019-03-22 4 | ; @LastEditTime: 2019-03-23 5 | 6 | BITS 16 7 | %include "macro.asm" 8 | [extern startUp] 9 | [extern shell] 10 | [extern syscaller] 11 | [extern Timer] 12 | 13 | global _start 14 | _start: 15 | WRITE_INT_VECTOR 21h, syscaller 16 | 17 | MOVE_INT_VECTOR 08h, 38h 18 | WRITE_INT_VECTOR 08h, Timer ; 装填时钟中断向量表 19 | call dword startUp 20 | 21 | Keyboard: 22 | mov ah, 0 23 | int 16h 24 | cmp al, 0Dh ; 按下回车 25 | jne Keyboard ; 无效按键,重新等待用户按键 26 | call dword shell ; 进入命令行界面 27 | jmp Keyboard ; 无限循环 -------------------------------------------------------------------------------- /项目5_实现系统调用/src/stringio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: Jed 3 | * @Description: 涉及字符串输入输出的C函数库 4 | * @Date: 2019-03-23 5 | * @LastEditTime: 2019-04-19 6 | */ 7 | #include 8 | extern void printInPos(const char *msg, uint16_t len, uint8_t row, uint8_t col); 9 | // extern void putchar(char c); 10 | extern void putchar_c(char c, uint8_t color); 11 | extern char getch(); 12 | enum bios_color {white_c=0x07}; 13 | // char tempc; // 临时存放一个字符的地方 14 | 15 | /* 字符串长度 */ 16 | uint16_t strlen(const char *str) { 17 | int count = 0; 18 | while (str[count++] != '\0'); 19 | return count - 1; // 循环中使用后递增,因此这里需要减1 20 | } 21 | 22 | /* 比较字符串 */ 23 | uint8_t strcmp(const char* str1, const char* str2) { 24 | int i = 0; 25 | while (1) { 26 | if(str1[i]=='\0' || str2[i]=='\0') { break; } 27 | if(str1[i] != str2[i]) { break; } 28 | ++i; 29 | } 30 | return str1[i] - str2[i]; 31 | } 32 | 33 | /* 显示一个白色字符 */ 34 | void putchar(char c) { 35 | putchar_c(c, 0x07); 36 | } 37 | 38 | /* 在光标处显示字符串 */ 39 | void print(const char* str) { 40 | for(int i = 0, len = strlen(str); i < len; i++) { 41 | putchar(str[i]); 42 | } 43 | } 44 | 45 | /* 在光标处显示彩色字符串 */ 46 | void print_c(const char* str, uint8_t color) { 47 | for(int i = 0, len = strlen(str); i < len; i++) { 48 | putchar_c(str[i], color); 49 | } 50 | } 51 | 52 | /* 读取字符串到缓冲区 */ 53 | void readToBuf(char* buffer, uint16_t maxlen) { 54 | int i = 0; 55 | while(1) { 56 | char tempc = getch(); 57 | if(!(tempc==0xD || tempc=='\b' || tempc>=32 && tempc<=127)) { continue; } // 非有效字符不予理会 58 | if(i > 0 && i < maxlen-1) { // buffer中有字符且未满 59 | if(tempc == 0x0D) { 60 | break; // 按下回车,停止读取 61 | } 62 | else if(tempc == '\b') { // 按下退格,则删除一个字符 63 | putchar('\b'); 64 | putchar(' '); 65 | putchar('\b'); 66 | --i; 67 | } 68 | else{ 69 | putchar(tempc); // 回显 70 | buffer[i] = tempc; 71 | ++i; 72 | } 73 | } 74 | else if(i >= maxlen-1) { // 达到最大值,只能按退格或回车 75 | if(tempc == '\b') { // 按下退格,则删除一个字符 76 | putchar('\b'); 77 | putchar(' '); 78 | putchar('\b'); 79 | --i; 80 | } 81 | else if(tempc == 0x0D) { 82 | break; // 按下回车,停止读取 83 | } 84 | } 85 | else if(i <= 0) { // buffer中没有字符,只能输入或回车,不能删除 86 | if(tempc == 0x0D) { 87 | break; // 按下回车,停止读取 88 | } 89 | else if(tempc != '\b') { 90 | putchar(tempc); // 回显 91 | buffer[i] = tempc; 92 | ++i; 93 | } 94 | } 95 | } 96 | putchar('\r'); putchar('\n'); 97 | buffer[i] = '\0'; // 字符串必须以空字符结尾 98 | } 99 | 100 | /* 将整数转为指定进制的字符串 */ 101 | char* itoa(int val, int base) { 102 | if(val==0) return "0"; 103 | static char buf[32] = {0}; 104 | int i = 30; 105 | for(; val && i ; --i, val /= base) { 106 | buf[i] = "0123456789ABCDEF"[val % base]; 107 | } 108 | return &buf[i+1]; 109 | } 110 | 111 | /* 判断字符是否是十进制数字 */ 112 | uint8_t isnum(char c) { 113 | return c>='0' && c<='9'; 114 | } 115 | 116 | /* 获取字符串的第一个空格前的词 */ 117 | void getFirstWord(const char* str, char* buf) { 118 | int i = 0; 119 | while(str[i] && str[i] != ' ') { 120 | buf[i] = str[i]; 121 | i++; 122 | } 123 | buf[i] = '\0'; // 字符串必须以空字符结尾 124 | } 125 | 126 | /* 获取字符串的第一个空格后的词 */ 127 | void getAfterFirstWord(const char* str, char* buf) { 128 | buf[0] = '\0'; // 为了应对用户故意搞破坏 129 | int i = 0; 130 | while(str[i] && str[i] != ' ') { 131 | i++; 132 | } 133 | while(str[i] && str[i] == ' ') { 134 | i++; 135 | } 136 | int j = 0; 137 | while(str[i]) { 138 | buf[j++] = str[i++]; 139 | } 140 | buf[j] = '\0'; // 字符串必须以空字符结尾 141 | } -------------------------------------------------------------------------------- /项目5_实现系统调用/src/usrprog/interrupt/int33h~36h.asm: -------------------------------------------------------------------------------- 1 | ; @Author: Jed 2 | ; @Description: int 33h/34h/35h/36h的中断处理程序 3 | ; @Date: 2019-03-28 4 | ; @LastEditTime: 2019-04-17 5 | 6 | Int33h~36h: 7 | push ax 8 | push si 9 | push ds 10 | push gs 11 | 12 | mov ax,cs 13 | mov ds,ax ; DS = CS 14 | mov ax,0B800h ; 文本窗口显存起始地址 15 | mov gs,ax ; GS = B800h 16 | mov ax, [start_row] ; ax=start_row 17 | mov ah, 2*80 ; ah=2*80 18 | mul ah ; ax=start_row * 2 * 80 19 | mov si, ax ; si初始化为起始位置指针 20 | disploop: 21 | mov al, [temp_char] ; 要显示的字符 22 | mov [gs:si], al ; 显示字符 23 | inc si ; 递增指针 24 | mov ah, [temp_color] ; 字符颜色属性 25 | mov [gs:si], ah ; 显示颜色属性 26 | inc si ; 递增指针 27 | add byte[temp_color], 11h ; 改变颜色 28 | call Delay ; 延时 29 | 30 | mov ah, 01h ; 功能号:查询键盘缓冲区但不等待 31 | int 16h 32 | jz NoEsc ; 无键盘按下,继续 33 | mov ah, 0 ; 功能号:查询键盘输入 34 | int 16h 35 | cmp al, 27 ; 是否按下ESC 36 | je QuitInt ; 若按下ESC,退出用户程序 37 | NoEsc: 38 | mov ax, [end_row] ; al=end_row,ah实际上无用 39 | mov ah, 2*80 40 | mul ah ; ax=end_row * 2 * 80 41 | add ax, [start_row] ; ax=start_row + end_row*2*80 42 | cmp si, ax 43 | jne disploop ; 范围全部显示完,中断返回 44 | 45 | QuitInt: 46 | pop gs 47 | pop ds 48 | pop si 49 | pop ax 50 | iret ; 中断返回 51 | 52 | Delay: ; 延迟一段时间 53 | push ax 54 | push cx 55 | mov ax, 100 56 | delay_outer: 57 | mov cx, 50000 58 | delay_inner: 59 | loop delay_inner 60 | dec ax 61 | cmp ax, 0 62 | jne delay_outer 63 | pop cx 64 | pop ax 65 | ret 66 | 67 | DataArea: 68 | start_row dw 0 69 | end_row dw 0 70 | temp_color db 0 71 | temp_char db ' ' -------------------------------------------------------------------------------- /项目5_实现系统调用/src/usrprog/interrupt/intouch.asm: -------------------------------------------------------------------------------- 1 | IntOuch: 2 | pusha 3 | push ds 4 | push es 5 | 6 | mov ax, cs ; 置其他段寄存器值与CS相同 7 | mov ds, ax ; 数据段 8 | mov bp, ouch_msg ; BP=当前串的偏移地址 9 | mov ax, ds ; ES:BP = 串地址 10 | mov es, ax ; 置ES=DS 11 | mov cx, ouch_msg_len ; CX = 串长 12 | mov ax, 1300h ; AH = 13h(功能号)、AL = 01h(光标不动) 13 | mov bx, 0007h ; 页号为0(BH = 0) 黑底白字(BL = 07h) 14 | mov dh, 20 ; 行号=0 15 | mov dl, 40 ; 列号=0 16 | int 10h ; BIOS的10h功能:显示一行字符 17 | 18 | call Delay 19 | 20 | mov ax, cs ; 置其他段寄存器值与CS相同 21 | mov ds, ax ; 数据段 22 | mov bp, ouch_clear ; BP=当前串的偏移地址 23 | mov ax, ds ; ES:BP = 串地址 24 | mov es, ax ; 置ES=DS 25 | mov cx, ouch_msg_len ; CX = 串长 26 | mov ax, 1300h ; AH = 13h(功能号)、AL = 01h(光标不动) 27 | mov bx, 0007h ; 页号为0(BH = 0) 黑底白字(BL = 07h) 28 | mov dh, 20 ; 行号=0 29 | mov dl, 40 ; 列号=0 30 | int 10h ; BIOS的10h功能:显示一行字符 31 | 32 | int 39h ; 原来的BIOS int 09h 33 | 34 | mov al,20h ; AL = EOI 35 | out 20h,al ; 发送EOI到主8529A 36 | out 0A0h,al ; 发送EOI到从8529A 37 | 38 | pop es 39 | pop ds 40 | popa 41 | iret ; 从中断返回 42 | 43 | Delay: ; 延迟一段时间 44 | push ax 45 | push cx 46 | mov ax, 580 47 | delay_outer: 48 | mov cx, 50000 49 | delay_inner: 50 | loop delay_inner 51 | dec ax 52 | cmp ax, 0 53 | jne delay_outer 54 | pop cx 55 | pop ax 56 | ret 57 | 58 | 59 | ouch_msg db 'OUCH! OUCH!' 60 | ouch_msg_len equ $-ouch_msg 61 | ouch_clear db ' ' -------------------------------------------------------------------------------- /项目5_实现系统调用/src/usrprog/interrupt_caller.asm: -------------------------------------------------------------------------------- 1 | %include "../macro.asm" 2 | org offset_intcaller 3 | 4 | Start: 5 | pusha 6 | push ds 7 | mov ax, cs 8 | mov ds, ax 9 | call ClearScreen 10 | PRINT_IN_POS hint_msg1, hint_msg1_len, 7, 10 11 | PRINT_IN_POS hint_msg2, hint_msg2_len, 10, 10 12 | 13 | ; 这四个中断处理程序是相同的,参数是不同的 14 | WRITE_INT_VECTOR 33h, Int33h~36h 15 | WRITE_INT_VECTOR 34h, Int33h~36h 16 | WRITE_INT_VECTOR 35h, Int33h~36h 17 | WRITE_INT_VECTOR 36h, Int33h~36h 18 | 19 | Keyboard: 20 | mov ah, 0 21 | int 16h 22 | cmp al, '3' ; 按下3 23 | je callInt33h ; 执行int 33h 24 | cmp al, '4' ; 按下4 25 | je callInt34h ; 执行int 34h 26 | cmp al, '5' ; 按下5 27 | je callInt35h ; 执行int 35h 28 | cmp al, '6' ; 按下6 29 | je callInt36h ; 执行int 36h 30 | cmp al, 27 ; 按下ESC 31 | je QuitUsrProg ; 直接退出 32 | jmp Keyboard ; 无效按键,重新等待用户按键 33 | 34 | callInt33h: 35 | mov word[start_row], 0 36 | mov word[end_row], 5 37 | int 33h 38 | jmp QuitUsrProg 39 | callInt34h: 40 | mov word[start_row], 6 41 | mov word[end_row], 11 42 | int 34h 43 | jmp QuitUsrProg 44 | callInt35h: 45 | mov word[start_row], 12 46 | mov word[end_row], 17 47 | int 35h 48 | jmp QuitUsrProg 49 | callInt36h: 50 | mov word[start_row], 18 51 | mov word[end_row], 24 52 | int 36h 53 | jmp QuitUsrProg 54 | 55 | QuitUsrProg: 56 | pop ds 57 | popa 58 | retf 59 | 60 | ClearScreen: ; 函数:清屏 61 | pusha 62 | mov ax, 0003h 63 | int 10h ; 中断调用,清屏 64 | popa 65 | ret 66 | 67 | Footer: 68 | hint_msg1 db 'This is the Interrupt Caller Programme.' 69 | hint_msg1_len equ $-hint_msg1 70 | hint_msg2 db 'Press `3/4/5/6` to call int 33/34/35/36. Press `ESC` to quit.' 71 | hint_msg2_len equ $-hint_msg2 72 | 73 | %include "interrupt/int33h~36h.asm" -------------------------------------------------------------------------------- /项目5_实现系统调用/src/usrprog/stone_bottomleft.asm: -------------------------------------------------------------------------------- 1 | ; 原作:凌应标 2014-03 2 | ; 改写:张怡昕(17341203) 2019-03 3 | ; 说明:本程序是jed_stone.asm的改版。本程序在显示器左上角进行字符反弹。 4 | ; 参数:(-1, -1, 40, 13, 0, 7) 5 | %include "../macro.asm" 6 | org offset_usrprog3 7 | 8 | Dn_Rt equ 1 ; D-Down,U-Up,R-right,L-Left 9 | Up_Rt equ 2 10 | Up_Lt equ 3 11 | Dn_Lt equ 4 12 | delay equ 50000 ; 计时器延迟计数,用于控制画框的速度 13 | ddelay equ 580 ; 计时器延迟计数,用于控制画框的速度 14 | 15 | screen_left equ -1 ; 字符运动左边界 16 | screen_top equ 11 ; 字符运动上边界 17 | screen_right equ 40 ; 字符运动右边界 18 | screen_bottom equ 25 ; 字符运动下边界 19 | originpos_y equ 0 ; 起点列数 20 | originpos_x equ 19 ; 起点行数 21 | 22 | start: 23 | pusha 24 | mov ax, 0 25 | mov es, ax 26 | MOVE_INT_VECTOR 09h, 39h 27 | WRITE_INT_VECTOR 09h, IntOuch 28 | call ClearScreen ; 清屏 29 | mov ax,cs 30 | mov es,ax ; ES = CS 31 | mov ds,ax ; DS = CS 32 | mov es,ax ; ES = CS 33 | mov ax,0B800h 34 | mov gs,ax ; GS = B800h,指向文本模式的显示缓冲区 35 | mov byte[char],'X' 36 | 37 | PRINT_IN_POS hint1, hint1len, 16, 30 38 | 39 | initialize: ; 多次调用用户程序时,可保证初始值是相同的 40 | mov word[x], originpos_x 41 | mov word[y], originpos_y 42 | mov byte[curcolor], 80h 43 | mov byte[curcolor2], 01h 44 | mov word[count], delay 45 | mov word[dcount], ddelay 46 | mov byte[rdul], Dn_Rt ; 向右下运动 47 | 48 | loop1: 49 | dec word[count] ; 递减计数变量 50 | jnz loop1 ; >0:跳转; 51 | mov word[count],delay 52 | dec word[dcount] ; 递减计数变量 53 | jnz loop1 54 | mov word[count],delay 55 | mov word[dcount],ddelay 56 | 57 | mov al,1 58 | cmp al,byte[rdul] 59 | jz DnRt 60 | mov al,2 61 | cmp al,byte[rdul] 62 | jz UpRt 63 | mov al,3 64 | cmp al,byte[rdul] 65 | jz UpLt 66 | mov al,4 67 | cmp al,byte[rdul] 68 | jz DnLt 69 | ; jmp $ 70 | 71 | DnRt: 72 | inc word[x] 73 | inc word[y] 74 | mov bx,word[x] 75 | mov ax,screen_bottom 76 | sub ax,bx 77 | jz dr2ur 78 | mov bx,word[y] 79 | mov ax,screen_right 80 | sub ax,bx 81 | jz dr2dl 82 | jmp show 83 | 84 | dr2ur: 85 | mov word[x],screen_bottom-2 86 | mov byte[rdul],Up_Rt 87 | jmp show 88 | 89 | dr2dl: 90 | mov word[y],screen_right-2 91 | mov byte[rdul],Dn_Lt 92 | jmp show 93 | 94 | 95 | UpRt: 96 | dec word[x] 97 | inc word[y] 98 | mov bx,word[y] 99 | mov ax,screen_right 100 | sub ax,bx 101 | jz ur2ul 102 | mov bx,word[x] 103 | mov ax,screen_top 104 | sub ax,bx 105 | jz ur2dr 106 | jmp show 107 | 108 | ur2ul: 109 | mov word[y],screen_right-2 110 | mov byte[rdul],Up_Lt 111 | jmp show 112 | 113 | ur2dr: 114 | mov word[x],screen_top+2 115 | mov byte[rdul],Dn_Rt 116 | jmp show 117 | 118 | 119 | UpLt: 120 | dec word[x] 121 | dec word[y] 122 | mov bx,word[x] 123 | mov ax,screen_top 124 | sub ax,bx 125 | jz ul2dl 126 | mov bx,word[y] 127 | mov ax,screen_left 128 | sub ax,bx 129 | jz ul2ur 130 | jmp show 131 | 132 | ul2dl: 133 | mov word[x],screen_top+2 134 | mov byte[rdul],Dn_Lt 135 | jmp show 136 | ul2ur: 137 | mov word[y],screen_left+2 138 | mov byte[rdul],Up_Rt 139 | jmp show 140 | 141 | DnLt: 142 | inc word[x] 143 | dec word[y] 144 | mov bx,word[y] 145 | mov ax,screen_left 146 | sub ax,bx 147 | jz dl2dr 148 | mov bx,word[x] 149 | mov ax,screen_bottom 150 | sub ax,bx 151 | jz dl2ul 152 | jmp show 153 | 154 | dl2dr: 155 | mov word[y],screen_left+2 156 | mov byte[rdul],Dn_Rt 157 | jmp show 158 | 159 | dl2ul: 160 | mov word[x],screen_bottom-2 161 | mov byte[rdul],Up_Lt 162 | jmp show 163 | 164 | show: 165 | xor ax,ax ; 计算显存地址 166 | mov ax,word[x] 167 | mov bx,80 168 | mul bx 169 | add ax,word[y] 170 | mov bx,2 171 | mul bx 172 | mov bp,ax 173 | mov ah,[curcolor2] ; 弹字符的背景色和前景色(默认值为07h,详见文档) 174 | inc byte[curcolor2] 175 | cmp byte[curcolor2], 0fh 176 | jnz skip 177 | mov byte[curcolor2], 1 ; 为了不改变背景色 178 | skip: 179 | mov al,byte[char] ; AL = 显示字符值(默认值为20h=空格符) 180 | mov word[gs:bp],ax ; 显示字符的ASCII码值 181 | 182 | mov ah, 01h ; 功能号:查询键盘缓冲区但不等待 183 | int 16h 184 | jz continue ; 无键盘按下,继续 185 | mov ah, 0 ; 功能号:查询键盘输入 186 | int 16h 187 | cmp al, 27 ; 是否按下ESC 188 | je QuitUsrProg ; 若按下ESC,退出用户程序 189 | 190 | continue: 191 | jmp loop1 192 | 193 | end: 194 | jmp $ ; 停止画框,无限循环 195 | 196 | QuitUsrProg: 197 | MOVE_INT_VECTOR 39h, 09h 198 | popa 199 | retf 200 | 201 | ClearScreen: ; 函数:清屏 202 | pusha 203 | mov ax, 0003h 204 | int 10h ; 中断调用,清屏 205 | popa 206 | ret 207 | 208 | DataArea: 209 | count dw delay 210 | dcount dw ddelay 211 | rdul db Dn_Rt ; 向右下运动 212 | char db 0 213 | 214 | x dw originpos_x 215 | y dw originpos_y 216 | 217 | curcolor db 80h ; 保存当前字符颜色属性,用于myinfo 218 | curcolor2 db 01h ; 保存当前字符颜色属性,用于移动的字符 219 | 220 | hint1 db 'This is user program 3. Press ESC to exit.' 221 | hint1len equ ($-hint1) 222 | 223 | %include "interrupt/intouch.asm" -------------------------------------------------------------------------------- /项目5_实现系统调用/src/usrprog/syscall_test.asm: -------------------------------------------------------------------------------- 1 | ; @Author: Jed 2 | ; @Description: 测试系统调用的用户程序 3 | ; @Date: 2019-04-17 4 | ; @LastEditTime: 2019-04-19 5 | 6 | %include "../macro.asm" 7 | org offset_syscalltest 8 | 9 | Start: 10 | pusha 11 | push es 12 | 13 | mov ax, 0003h 14 | int 10h ; 清屏 15 | 16 | PRINT_IN_POS hint_all, hint_all_len, 0, 0 17 | mov ah, 0 18 | int 16h 19 | cmp al, 27 ; 按下ESC 20 | je QuitUsrProg ; 直接退出 21 | 22 | PRINT_IN_POS hint0, hint_len, 2, 0 23 | mov ah, 00h ; 系统调用功能号ah=00h,显示OUCH 24 | int 21h 25 | mov ah, 0 26 | int 16h 27 | cmp al, 27 ; 按下ESC 28 | je QuitUsrProg ; 直接退出 29 | 30 | PRINT_IN_POS hint1, hint_len, 2, 0 31 | mov ax, cs 32 | mov es, ax ; es=cs 33 | mov dx, upper_lower ; es:dx=串地址 34 | PRINT_IN_POS upper_lower, 14, 3, 0 35 | mov ah, 01h ; 系统调用功能号ah=01h,大写转小写 36 | int 21h 37 | PRINT_IN_POS upper_lower, 14, 4, 0 38 | mov ah, 0 39 | int 16h 40 | cmp al, 27 ; 按下ESC 41 | je QuitUsrProg ; 直接退出 42 | 43 | PRINT_IN_POS hint2, hint_len, 2, 0 44 | mov ax, cs 45 | mov es, ax ; es=cs 46 | mov dx, upper_lower ; es:dx=串地址 47 | mov ah, 02h ; 系统调用功能号ah=02h,小写转大写 48 | int 21h 49 | PRINT_IN_POS upper_lower, 14, 5, 0 50 | mov ah, 0 51 | int 16h 52 | cmp al, 27 ; 按下ESC 53 | je QuitUsrProg ; 直接退出 54 | 55 | PRINT_IN_POS hint3, hint_len, 2, 0 56 | mov ax, cs 57 | mov es, ax ; es=cs 58 | mov dx, number_buf 59 | mov ah, 03h ; 系统调用功能号ah=03h,atoi 60 | int 21h ; ax=数值 61 | mov bx, 1 62 | add bx, ax ; bx=ax+1,然后使用下一个系统调用来检查其结果 63 | mov ah, 0 64 | int 16h 65 | cmp al, 27 ; 按下ESC 66 | je QuitUsrProg ; 直接退出 67 | 68 | PRINT_IN_POS hint4, hint_len, 2, 0 69 | mov ax, cs 70 | mov es, ax ; es=cs 71 | mov dx, number_buf 72 | mov ah, 04h ; 系统调用功能号ah=04h,itoa 73 | int 21h ; es:dx=转换后的数字字符串 74 | mov ch, 6 75 | mov cl, 0 76 | mov ah, 05h 77 | int 21h 78 | 79 | mov ah, 0 80 | int 16h 81 | cmp al, 27 ; 按下ESC 82 | je QuitUsrProg ; 直接退出 83 | 84 | PRINT_IN_POS hint5, hint_len, 2, 0 85 | mov ax, cs 86 | mov es, ax ; es=cs 87 | mov dx, test_message1 ; es:dx=串地址 88 | mov ch, 19 ; 行号 89 | mov cl, 0 ; 列号 90 | mov ah, 05h ; 系统调用功能号ah=05h 91 | int 21h ; 显示第一条字符串 92 | mov dx, test_message2 93 | mov ch, 20 94 | mov cl, 0 95 | int 21h ; 显示第二条字符串 96 | mov ah, 0 97 | int 16h 98 | cmp al, 27 ; 按下ESC 99 | je QuitUsrProg ; 直接退出 100 | QuitUsrProg: 101 | pop es 102 | popa 103 | retf 104 | 105 | DataArea: 106 | hint_all db 'Welcome to syscall_test program, where there are several tests of system call. See the document for more details.' 107 | hint_all_len equ $-hint_all 108 | 109 | hint0 db 'Test of ah=00h is running. press ENTER to continue, or ESC to quit.' 110 | hint1 db 'Test of ah=01h is running. press ENTER to continue, or ESC to quit.' 111 | hint2 db 'Test of ah=02h is running. press ENTER to continue, or ESC to quit.' 112 | hint3 db 'Test of ah=03h is running. press ENTER to continue, or ESC to quit.' 113 | hint4 db 'Test of ah=04h is running. press ENTER to continue, or ESC to quit.' 114 | hint5 db 'Test of ah=05h is running. press ENTER to continue, or ESC to quit.' 115 | hint_len equ ($-hint5) 116 | 117 | upper_lower db 'AbCdEfGhIjKlMn', 0 ; 字符串以'\0'结尾 118 | 119 | number_buf db '12345', 0 ; 字符串以'\0'结尾 120 | test_message1 db 'This is a test message,' 121 | test_message2 db 'printed using `ah=05h` and `int 21h`.' -------------------------------------------------------------------------------- /项目5_实现系统调用/src/usrproginfo.asm: -------------------------------------------------------------------------------- 1 | ; @Author: Jed 2 | ; @Description: 用户车呢光绪信息表。放在软盘第2个扇区。 3 | ; @Date: 2019-03-29 4 | ; @LastEditTime: 2019-04-01 5 | 6 | %include "macro.asm" 7 | %macro UsrProgInfoBlock 7 ; 参数:(PID,程序名,字节数,柱面,磁头,扇区,内存地址) 8 | pid%1 db %1 ; 程序编号PID;相对偏移0 9 | name%1 db %2 ; 程序名(至多32字节);相对偏移1 10 | times 16-($-name%1) db 0 ; 程序名占6字节 11 | size%1 dw %3 ; 程序大小;相对偏移17 12 | cylinder%1 db %4 ; 柱面;相对偏移19 13 | head%1 db %5 ; 磁头;相对偏移20 14 | sector%1 db %6 ; 扇区;相对偏移21 15 | addr%1 dw %7 ; 内存中的地址;相对偏移22 16 | %endmacro ; 共24个字节 17 | 18 | UsrProgNumber: 19 | db 6 ; 用户程序数量 20 | 21 | UserProgInfo: 22 | UsrProgInfoBlock 1, 'stone_topleft', 1024, 0, 1, 1, offset_usrprog1 23 | UsrProgInfoBlock 2, 'stone_topright', 1024, 0, 1, 3, offset_usrprog2 24 | UsrProgInfoBlock 3, 'stone_botleft', 1024, 0, 1, 5, offset_usrprog3 25 | UsrProgInfoBlock 4, 'stone_botright', 1024, 0, 1, 7, offset_usrprog4 26 | UsrProgInfoBlock 5, 'interrupt_caller', 512, 0, 1, 9, offset_intcaller 27 | UsrProgInfoBlock 6, 'syscall_test', 1536, 0, 1, 10, offset_syscalltest 28 | 29 | SectorEnding: 30 | times 512-($-$$) db 0 -------------------------------------------------------------------------------- /项目6_二状态进程模型/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目6_二状态进程模型/.DS_Store -------------------------------------------------------------------------------- /项目6_二状态进程模型/JedOS_v1.4.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目6_二状态进程模型/JedOS_v1.4.img -------------------------------------------------------------------------------- /项目6_二状态进程模型/assets/1557309403947.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目6_二状态进程模型/assets/1557309403947.png -------------------------------------------------------------------------------- /项目6_二状态进程模型/assets/1557309533854.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目6_二状态进程模型/assets/1557309533854.png -------------------------------------------------------------------------------- /项目6_二状态进程模型/assets/1557309553962.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目6_二状态进程模型/assets/1557309553962.png -------------------------------------------------------------------------------- /项目6_二状态进程模型/assets/1557309658467.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目6_二状态进程模型/assets/1557309658467.png -------------------------------------------------------------------------------- /项目6_二状态进程模型/assets/1557309727124.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目6_二状态进程模型/assets/1557309727124.png -------------------------------------------------------------------------------- /项目6_二状态进程模型/assets/1557309820907.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目6_二状态进程模型/assets/1557309820907.png -------------------------------------------------------------------------------- /项目6_二状态进程模型/assets/1557309879043.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目6_二状态进程模型/assets/1557309879043.png -------------------------------------------------------------------------------- /项目6_二状态进程模型/assets/1557408924509.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目6_二状态进程模型/assets/1557408924509.png -------------------------------------------------------------------------------- /项目6_二状态进程模型/assets/1557409096988.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目6_二状态进程模型/assets/1557409096988.png -------------------------------------------------------------------------------- /项目6_二状态进程模型/assets/1557409127112.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目6_二状态进程模型/assets/1557409127112.png -------------------------------------------------------------------------------- /项目6_二状态进程模型/assets/1557409179309.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目6_二状态进程模型/assets/1557409179309.png -------------------------------------------------------------------------------- /项目6_二状态进程模型/assets/1557409199900.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目6_二状态进程模型/assets/1557409199900.png -------------------------------------------------------------------------------- /项目6_二状态进程模型/assets/1557409228348.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目6_二状态进程模型/assets/1557409228348.png -------------------------------------------------------------------------------- /项目6_二状态进程模型/assets/1557409248148.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目6_二状态进程模型/assets/1557409248148.png -------------------------------------------------------------------------------- /项目6_二状态进程模型/assets/1557409259884.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目6_二状态进程模型/assets/1557409259884.png -------------------------------------------------------------------------------- /项目6_二状态进程模型/assets/1557409284078.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目6_二状态进程模型/assets/1557409284078.png -------------------------------------------------------------------------------- /项目6_二状态进程模型/assets/1557409695499.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目6_二状态进程模型/assets/1557409695499.png -------------------------------------------------------------------------------- /项目6_二状态进程模型/src/bootloader.asm: -------------------------------------------------------------------------------- 1 | ; @Author: Jed 2 | ; @Description: 引导程序;独立编译 3 | ; @Date: 2019-03-21 4 | ; @LastEditTime: 2019-04-12 5 | 6 | BITS 16 7 | %include "macro.asm" 8 | org 7c00h 9 | 10 | global _start 11 | _start: 12 | mov ax, cs 13 | mov ds, ax ; ds=cs 14 | PRINT_IN_POS msg, msg_len, 0, 0 ; 调用宏,显示字符串 15 | 16 | LoadOsKernel: 17 | LOAD_TO_MEM 34, 0, 0, 3, 0h, addr_oskernel & 0FFFFh ; 调用宏,加载操作系统内核 18 | 19 | LoadUsrProgInfo: 20 | LOAD_TO_MEM 1, 0, 0, 2, 0h, addr_upinfo & 0FFFFh ; 调用宏,加载用户程序信息表 21 | 22 | EnterOs: 23 | jmp addr_oskernel ; 跳转到操作系统内核 24 | 25 | DataArea: 26 | msg db 'Bootloader is loading operating system...' 27 | msg_len equ ($-msg) 28 | 29 | times 510-($-$$) db 0 30 | db 0x55, 0xaa ; 主引导记录标志 -------------------------------------------------------------------------------- /项目6_二状态进程模型/src/lib/systema.asm: -------------------------------------------------------------------------------- 1 | BITS 16 2 | [global sys_showOuch] 3 | [global sys_toUpper] 4 | [global sys_toLower] 5 | [global sys_atoi] 6 | [global sys_itoa] 7 | [global sys_printInPos] 8 | [global sys_timer_flag] 9 | 10 | sys_showOuch: 11 | pusha ; 保护现场 12 | push ds 13 | push es 14 | mov ax, cs ; 置其他段寄存器值与CS相同 15 | mov ds, ax ; 数据段 16 | mov bp, ouch_str ; BP=当前串的偏移地址 17 | mov ax, ds ; ES:BP = 串地址 18 | mov es, ax ; 置ES=DS 19 | mov cx, 4 ; CX = 串长 20 | mov ax, 1301h ; AH = 13h(功能号)、AL = 01h(光标置于串尾) 21 | mov bx, 0038h ; 页号为0(BH = 0) 黑底白字(BL = 07h) 22 | mov dh, 12 ; 行号 23 | mov dl, 38 ; 列号 24 | int 10h ; BIOS的10h功能:显示一行字符 25 | pop es 26 | pop ds 27 | popa ; 恢复现场 28 | ret 29 | ouch_str db 'OUCH' 30 | 31 | [extern toupper] 32 | sys_toUpper: 33 | push es ; 传递参数 34 | push dx ; 传递参数 35 | call dword toupper 36 | pop dx ; 丢弃参数 37 | pop es ; 丢弃参数 38 | ret 39 | 40 | [extern tolower] 41 | sys_toLower: 42 | push es ; 传递参数 43 | push dx ; 传递参数 44 | call dword tolower 45 | pop dx ; 丢弃参数 46 | pop es ; 丢弃参数 47 | ret 48 | 49 | [extern atoi] 50 | sys_atoi: 51 | push es ; 传递参数 52 | push dx ; 传递参数 53 | call dword atoi 54 | pop dx ; 丢弃参数 55 | pop es ; 丢弃参数 56 | ret 57 | 58 | [extern itoa_buf] 59 | sys_itoa: 60 | push es ; 传递参数buf 61 | push dx ; 传递参数buf 62 | mov ax, 0 63 | push ax ; 传递参数base 64 | mov ax, 10 ; 10进制 65 | push ax ; 传递参数base 66 | mov ax, 0 67 | push ax ; 传递参数val 68 | push bx ; 传递参数val 69 | call dword itoa_buf 70 | pop bx ; 丢弃参数 71 | pop ax ; 丢弃参数 72 | pop ax ; 丢弃参数 73 | pop ax ; 丢弃参数 74 | pop dx ; 丢弃参数 75 | pop es ; 丢弃参数 76 | ret 77 | 78 | [extern strlen] 79 | sys_printInPos: 80 | pusha 81 | mov bp, dx ; es:bp=串地址 82 | push es ; 传递参数 83 | push bp ; 传递参数 84 | call dword strlen ; 返回值ax=串长 85 | pop bp ; 丢弃参数 86 | pop es ; 丢弃参数 87 | mov bl, 07h ; 颜色 88 | mov dh, ch ; 行号 89 | mov dl, cl ; 列号 90 | mov cx, ax ; 串长 91 | mov bh, 0 ; 页码 92 | mov al, 0 ; 光标不动 93 | mov ah, 13h ; BIOS功能号 94 | int 10h 95 | popa 96 | ret 97 | 98 | [extern timer_flag] 99 | sys_timer_flag: 100 | mov ax, [cs:timer_flag] 101 | ret -------------------------------------------------------------------------------- /项目6_二状态进程模型/src/lib/systemc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define bool unsigned short 3 | #define true 1 4 | #define false 0 5 | 6 | /* 将字符串中的小写字母转换为大写 */ 7 | void toupper(char* str) { 8 | int i=0; 9 | while(str[i]) { 10 | if (str[i] >= 'a' && str[i] <= 'z') 11 | str[i] = str[i]-'a'+'A'; 12 | i++; 13 | } 14 | } 15 | 16 | /* 将字符串中的大写字母转换为小写 */ 17 | void tolower(char* str) { 18 | int i=0; 19 | while(str[i]) { 20 | if (str[i] >= 'A' && str[i] <= 'Z') 21 | str[i] = str[i]-'A'+'a'; 22 | i++; 23 | } 24 | } 25 | 26 | /* 翻转字符串 */ 27 | void my_reverse(char str[], int len) 28 | { 29 | int start, end; 30 | char temp; 31 | for (start = 0, end = len - 1; start < end; start++, end--) { 32 | temp = *(str + start); 33 | *(str + start) = *(str + end); 34 | *(str + end) = temp; 35 | } 36 | } 37 | 38 | /* 将数字转换为字符串并放在str中 */ 39 | char* itoa_buf(int num, int base, char* str) 40 | { 41 | int i = 0; 42 | bool isNegative = false; 43 | 44 | /* A zero is same "0" string in all base */ 45 | if (num == 0) { 46 | str[i] = '0'; 47 | str[i + 1] = '\0'; 48 | return str; 49 | } 50 | 51 | /* negative numbers are only handled if base is 10 52 | otherwise considered unsigned number */ 53 | if (num < 0 && base == 10) { 54 | isNegative = true; 55 | num = -num; 56 | } 57 | 58 | while (num != 0) { 59 | int rem = num % base; 60 | str[i++] = (rem > 9) ? (rem - 10) + 'A' : rem + '0'; 61 | num = num / base; 62 | } 63 | 64 | /* Append negative sign for negative numbers */ 65 | if (isNegative) { 66 | str[i++] = '-'; 67 | } 68 | 69 | str[i] = '\0'; 70 | 71 | my_reverse(str, i); 72 | 73 | return str; 74 | } 75 | 76 | /* 将十进制数字字符串转换为整数 */ 77 | int atoi(char *str) { 78 | int res = 0; // Initialize result 79 | 80 | // Iterate through all characters of input string and 81 | // update result 82 | for (int i = 0; str[i] != '\0'; ++i) { 83 | res = res*10 + str[i] - '0'; 84 | } 85 | // return result. 86 | return res; 87 | } 88 | 89 | /* 将BCD码转为数字 */ 90 | uint8_t bcd2decimal(uint8_t bcd) 91 | { 92 | return ((bcd & 0xF0) >> 4) * 10 + (bcd & 0x0F); 93 | } -------------------------------------------------------------------------------- /项目6_二状态进程模型/src/macro.asm: -------------------------------------------------------------------------------- 1 | addr_upinfo equ 07E00h ; 用户程序信息表被装入的位置 2 | addr_oskernel equ 08000h ; 操作系统内核被装入的位置 3 | 4 | addr_usrprog1 equ 10000h ; 四个普通用户程序的物理地址 5 | addr_usrprog2 equ 20000h ; 四个普通用户程序的物理地址 6 | addr_usrprog3 equ 30000h ; 四个普通用户程序的物理地址 7 | addr_usrprog4 equ 40000h ; 四个普通用户程序的物理地址 8 | addr_intcaller equ 50000h 9 | addr_syscalltest equ 0xB500 10 | 11 | %macro WRITE_INT_VECTOR 2 ; 写中断向量表;参数:(中断号,中断处理程序地址) 12 | push ax 13 | push es 14 | mov ax, 0 15 | mov es, ax ; ES = 0 16 | mov word[es:%1*4], %2 ; 设置中断向量的偏移地址 17 | mov ax,cs 18 | mov word[es:%1*4+2], ax ; 设置中断向量的段地址=CS 19 | pop es 20 | pop ax 21 | %endmacro 22 | 23 | %macro MOVE_INT_VECTOR 2 ; 转移中断向量;参数:(源中断号,目的中断号) 24 | push ax 25 | push es 26 | push si 27 | mov ax, 0 28 | mov es, ax ; es=0 29 | mov si, [es:%1*4] 30 | mov [es:%2*4], si 31 | mov si, [es:%1*4+2] 32 | mov [es:%2*4+2], si 33 | pop si 34 | pop es 35 | pop ax 36 | %endmacro 37 | 38 | %macro PRINT_IN_POS 4 ; 在指定位置打印字符串;参数:(串地址,串长,行号,列号) 39 | pusha ; 保护现场 40 | push ds 41 | push es 42 | mov ax, cs ; 置其他段寄存器值与CS相同 43 | mov ds, ax ; 数据段 44 | mov bp, %1 ; BP=当前串的偏移地址 45 | mov ax, ds ; ES:BP = 串地址 46 | mov es, ax ; 置ES=DS 47 | mov cx, %2 ; CX = 串长(=9) 48 | mov ax, 1301h ; AH = 13h(功能号)、AL = 01h(光标置于串尾) 49 | mov bx, 0007h ; 页号为0(BH = 0) 黑底白字(BL = 07h) 50 | mov dh, %3 ; 行号=0 51 | mov dl, %4 ; 列号=0 52 | int 10h ; BIOS的10h功能:显示一行字符 53 | pop es 54 | pop ds 55 | popa ; 恢复现场 56 | %endmacro 57 | 58 | %macro LOAD_TO_MEM 6 ; 读软盘到内存;参数:(扇区数,柱面号,磁头号,扇区号,内存段值,内存偏移量) 59 | pusha 60 | push es 61 | mov ax, %5 ; 段地址; 存放数据的内存基地址 62 | mov es, ax ; 设置段地址(不能直接mov es,段地址) 63 | mov bx, %6 ; 偏移地址; 存放数据的内存偏移地址 64 | mov ah, 2 ; 功能号 65 | mov al, %1 ; 扇区数 66 | mov dl, 0 ; 驱动器号; 软盘为0,硬盘和U盘为80H 67 | mov dh, %3 ; 磁头号; 起始编号为0 68 | mov ch, %2 ; 柱面号; 起始编号为0 69 | mov cl, %4 ; 起始扇区号 ; 起始编号为1 70 | int 13H ; 调用读磁盘BIOS的13h功能 71 | pop es 72 | popa 73 | %endmacro -------------------------------------------------------------------------------- /项目6_二状态进程模型/src/merge.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | rm -rf temp 3 | mkdir temp 4 | rm *.img 5 | 6 | nasm bootloader.asm -o ./temp/bootloader.bin 7 | nasm usrproginfo.asm -o ./temp/usrproginfo.bin 8 | 9 | cd usrprog 10 | nasm stone_topleft.asm -o ../temp/stone_topleft.bin 11 | nasm stone_topright.asm -o ../temp/stone_topright.bin 12 | nasm stone_bottomleft.asm -o ../temp/stone_bottomleft.bin 13 | nasm stone_bottomright.asm -o ../temp/stone_bottomright.bin 14 | nasm interrupt_caller.asm -o ../temp/interrupt_caller.bin 15 | nasm syscall_test.asm -o ../temp/syscall_test.bin 16 | cd .. 17 | 18 | cd lib 19 | nasm -f elf32 systema.asm -o ../temp/systema.o 20 | gcc -c -m16 -march=i386 -masm=intel -nostdlib -ffreestanding -mpreferred-stack-boundary=2 -lgcc -shared systemc.c -o ../temp/systemc.o 21 | cd .. 22 | 23 | nasm -f elf32 osstarter.asm -o ./temp/osstarter.o 24 | nasm -f elf32 liba.asm -o ./temp/liba.o 25 | nasm -f elf32 multiprocess.asm -o ./temp/multiprocess.o 26 | gcc -c -m16 -march=i386 -masm=intel -nostdlib -ffreestanding -mpreferred-stack-boundary=2 -lgcc -shared kernel.c -o ./temp/kernel.o 27 | ld -m elf_i386 -N -Ttext 0x8000 --oformat binary ./temp/osstarter.o ./temp/liba.o ./temp/kernel.o ./temp/systema.o ./temp/systemc.o ./temp/multiprocess.o -o ./temp/kernel.bin 28 | # rm ./temp/*.o 29 | 30 | dd if=./temp/bootloader.bin of=JedOS_v1.4.img bs=512 count=1 2> /dev/null 31 | dd if=./temp/usrproginfo.bin of=JedOS_v1.4.img bs=512 seek=1 count=1 2> /dev/null 32 | dd if=./temp/kernel.bin of=JedOS_v1.4.img bs=512 seek=2 count=34 2> /dev/null 33 | dd if=./temp/stone_topleft.bin of=JedOS_v1.4.img bs=512 seek=36 count=2 2> /dev/null 34 | dd if=./temp/stone_topright.bin of=JedOS_v1.4.img bs=512 seek=38 count=2 2> /dev/null 35 | dd if=./temp/stone_bottomleft.bin of=JedOS_v1.4.img bs=512 seek=40 count=2 2> /dev/null 36 | dd if=./temp/stone_bottomright.bin of=JedOS_v1.4.img bs=512 seek=42 count=2 2> /dev/null 37 | dd if=./temp/interrupt_caller.bin of=JedOS_v1.4.img bs=512 seek=44 count=1 2> /dev/null 38 | dd if=./temp/syscall_test.bin of=JedOS_v1.4.img bs=512 seek=45 count=3 2> /dev/null 39 | 40 | 41 | echo "[+] Done." -------------------------------------------------------------------------------- /项目6_二状态进程模型/src/osstarter.asm: -------------------------------------------------------------------------------- 1 | ; @Author: Jed 2 | ; @Description: 操作系统内核入口 3 | ; @Date: 2019-03-22 4 | ; @LastEditTime: 2019-03-23 5 | 6 | BITS 16 7 | %include "macro.asm" 8 | [extern startUp] 9 | [extern shell] 10 | [extern syscaller] 11 | [extern Timer] 12 | 13 | extern set_clock 14 | 15 | global _start 16 | _start: 17 | WRITE_INT_VECTOR 21h, syscaller ; 装填系统调用中断向量表 18 | 19 | SetTimer: 20 | mov al,34h ; 设控制字值 21 | out 43h,al ; 写控制字到控制字寄存器 22 | mov ax,29830 ; 每秒 20 次中断(50ms 一次) 23 | out 40h,al ; 写计数器 0 的低字节 24 | mov al,ah ; AL=AH 25 | out 40h,al ; 写计数器 0 的高字节 26 | WRITE_INT_VECTOR 08h, Timer 27 | call dword startUp ; 进入欢迎界面 28 | 29 | Keyboard: 30 | mov ah, 0 31 | int 16h 32 | cmp al, 0Dh ; 按下回车 33 | jne Keyboard ; 无效按键,重新等待用户按键 34 | call dword shell ; 进入命令行界面 35 | jmp Keyboard ; 无限循环 -------------------------------------------------------------------------------- /项目6_二状态进程模型/src/stringio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: Jed 3 | * @Description: 涉及字符串输入输出的C函数库 4 | * @Date: 2019-03-23 5 | * @LastEditTime: 2019-05-02 6 | */ 7 | #ifndef _STRINGIO_H_ 8 | #define _STRINGIO_H_ 9 | 10 | #include 11 | #define NEWLINE putchar('\r');putchar('\n') 12 | extern void printInPos(const char *msg, uint16_t len, uint8_t row, uint8_t col); 13 | extern void putchar_c(char c, uint8_t color); 14 | extern char getch(); 15 | enum bios_color {white_c=0x07}; 16 | 17 | /* 字符串长度 */ 18 | uint16_t strlen(const char *str) { 19 | int count = 0; 20 | while (str[count++] != '\0'); 21 | return count - 1; // 循环中使用后递增,因此这里需要减1 22 | } 23 | 24 | /* 比较字符串 */ 25 | uint8_t strcmp(const char* str1, const char* str2) { 26 | int i = 0; 27 | while (1) { 28 | if(str1[i]=='\0' || str2[i]=='\0') { break; } 29 | if(str1[i] != str2[i]) { break; } 30 | ++i; 31 | } 32 | return str1[i] - str2[i]; 33 | } 34 | 35 | /* 显示一个白色字符 */ 36 | void putchar(char c) { 37 | putchar_c(c, 0x07); 38 | } 39 | 40 | /* 在光标处显示字符串 */ 41 | void print(const char* str) { 42 | for(int i = 0, len = strlen(str); i < len; i++) { 43 | putchar(str[i]); 44 | } 45 | } 46 | 47 | /* 在光标处显示彩色字符串 */ 48 | void print_c(const char* str, uint8_t color) { 49 | for(int i = 0, len = strlen(str); i < len; i++) { 50 | putchar_c(str[i], color); 51 | } 52 | } 53 | 54 | /* 读取字符串到缓冲区 */ 55 | void readToBuf(char* buffer, uint16_t maxlen) { 56 | int i = 0; 57 | while(1) { 58 | char tempc = getch(); 59 | if(!(tempc==0xD || tempc=='\b' || tempc>=32 && tempc<=127)) { continue; } // 非有效字符不予理会 60 | if(i > 0 && i < maxlen-1) { // buffer中有字符且未满 61 | if(tempc == 0x0D) { 62 | break; // 按下回车,停止读取 63 | } 64 | else if(tempc == '\b') { // 按下退格,则删除一个字符 65 | putchar('\b'); 66 | putchar(' '); 67 | putchar('\b'); 68 | --i; 69 | } 70 | else{ 71 | putchar(tempc); // 回显 72 | buffer[i] = tempc; 73 | ++i; 74 | } 75 | } 76 | else if(i >= maxlen-1) { // 达到最大值,只能按退格或回车 77 | if(tempc == '\b') { // 按下退格,则删除一个字符 78 | putchar('\b'); 79 | putchar(' '); 80 | putchar('\b'); 81 | --i; 82 | } 83 | else if(tempc == 0x0D) { 84 | break; // 按下回车,停止读取 85 | } 86 | } 87 | else if(i <= 0) { // buffer中没有字符,只能输入或回车,不能删除 88 | if(tempc == 0x0D) { 89 | break; // 按下回车,停止读取 90 | } 91 | else if(tempc != '\b') { 92 | putchar(tempc); // 回显 93 | buffer[i] = tempc; 94 | ++i; 95 | } 96 | } 97 | } 98 | putchar('\r'); putchar('\n'); 99 | buffer[i] = '\0'; // 字符串必须以空字符结尾 100 | } 101 | 102 | /* 将整数转为指定进制的字符串 */ 103 | char* itoa(int val, int base) { 104 | if(val==0) return "0"; 105 | static char buf[32] = {0}; 106 | int i = 30; 107 | for(; val && i ; --i, val /= base) { 108 | buf[i] = "0123456789ABCDEF"[val % base]; 109 | } 110 | return &buf[i+1]; 111 | } 112 | 113 | /* 判断字符是否是十进制数字 */ 114 | uint8_t isnum(char c) { 115 | return c>='0' && c<='9'; 116 | } 117 | 118 | /* 获取字符串的第一个空格前的词 */ 119 | void getFirstWord(const char* str, char* buf) { 120 | int i = 0; 121 | while(str[i] && str[i] != ' ') { 122 | buf[i] = str[i]; 123 | i++; 124 | } 125 | buf[i] = '\0'; // 字符串必须以空字符结尾 126 | } 127 | 128 | /* 获取字符串的第一个空格后的词 */ 129 | void getAfterFirstWord(const char* str, char* buf) { 130 | buf[0] = '\0'; // 为了应对用户故意搞破坏 131 | int i = 0; 132 | while(str[i] && str[i] != ' ') { 133 | i++; 134 | } 135 | while(str[i] && str[i] == ' ') { 136 | i++; 137 | } 138 | int j = 0; 139 | while(str[i]) { 140 | buf[j++] = str[i++]; 141 | } 142 | buf[j] = '\0'; // 字符串必须以空字符结尾 143 | } 144 | 145 | #endif -------------------------------------------------------------------------------- /项目6_二状态进程模型/src/usrprog/interrupt/int33h~36h.asm: -------------------------------------------------------------------------------- 1 | ; @Author: Jed 2 | ; @Description: int 33h/34h/35h/36h的中断处理程序 3 | ; @Date: 2019-03-28 4 | ; @LastEditTime: 2019-04-17 5 | 6 | Int33h~36h: 7 | push ax 8 | push si 9 | push ds 10 | push gs 11 | 12 | mov ax,cs 13 | mov ds,ax ; DS = CS 14 | mov ax,0B800h ; 文本窗口显存起始地址 15 | mov gs,ax ; GS = B800h 16 | mov ax, [start_row] ; ax=start_row 17 | mov ah, 2*80 ; ah=2*80 18 | mul ah ; ax=start_row * 2 * 80 19 | mov si, ax ; si初始化为起始位置指针 20 | disploop: 21 | mov al, [temp_char] ; 要显示的字符 22 | mov [gs:si], al ; 显示字符 23 | inc si ; 递增指针 24 | mov ah, [temp_color] ; 字符颜色属性 25 | mov [gs:si], ah ; 显示颜色属性 26 | inc si ; 递增指针 27 | add byte[temp_color], 11h ; 改变颜色 28 | call Delay ; 延时 29 | 30 | mov ah, 01h ; 功能号:查询键盘缓冲区但不等待 31 | int 16h 32 | jz NoEsc ; 无键盘按下,继续 33 | mov ah, 0 ; 功能号:查询键盘输入 34 | int 16h 35 | cmp al, 27 ; 是否按下ESC 36 | je QuitInt ; 若按下ESC,退出用户程序 37 | NoEsc: 38 | mov ax, [end_row] ; al=end_row,ah实际上无用 39 | mov ah, 2*80 40 | mul ah ; ax=end_row * 2 * 80 41 | add ax, [start_row] ; ax=start_row + end_row*2*80 42 | cmp si, ax 43 | jne disploop ; 范围全部显示完,中断返回 44 | 45 | QuitInt: 46 | pop gs 47 | pop ds 48 | pop si 49 | pop ax 50 | iret ; 中断返回 51 | 52 | Delay: ; 延迟一段时间 53 | push ax 54 | push cx 55 | mov ax, 100 56 | delay_outer: 57 | mov cx, 50000 58 | delay_inner: 59 | loop delay_inner 60 | dec ax 61 | cmp ax, 0 62 | jne delay_outer 63 | pop cx 64 | pop ax 65 | ret 66 | 67 | DataArea: 68 | start_row dw 0 69 | end_row dw 0 70 | temp_color db 0 71 | temp_char db ' ' -------------------------------------------------------------------------------- /项目6_二状态进程模型/src/usrprog/interrupt/intouch.asm: -------------------------------------------------------------------------------- 1 | IntOuch: 2 | pusha 3 | push ds 4 | push es 5 | 6 | mov ax, cs ; 置其他段寄存器值与CS相同 7 | mov ds, ax ; 数据段 8 | mov bp, ouch_msg ; BP=当前串的偏移地址 9 | mov ax, ds ; ES:BP = 串地址 10 | mov es, ax ; 置ES=DS 11 | mov cx, ouch_msg_len ; CX = 串长 12 | mov ax, 1300h ; AH = 13h(功能号)、AL = 01h(光标不动) 13 | mov bx, 0007h ; 页号为0(BH = 0) 黑底白字(BL = 07h) 14 | mov dh, 20 ; 行号=0 15 | mov dl, 40 ; 列号=0 16 | int 10h ; BIOS的10h功能:显示一行字符 17 | 18 | call Delay 19 | 20 | mov ax, cs ; 置其他段寄存器值与CS相同 21 | mov ds, ax ; 数据段 22 | mov bp, ouch_clear ; BP=当前串的偏移地址 23 | mov ax, ds ; ES:BP = 串地址 24 | mov es, ax ; 置ES=DS 25 | mov cx, ouch_msg_len ; CX = 串长 26 | mov ax, 1300h ; AH = 13h(功能号)、AL = 01h(光标不动) 27 | mov bx, 0007h ; 页号为0(BH = 0) 黑底白字(BL = 07h) 28 | mov dh, 20 ; 行号=0 29 | mov dl, 40 ; 列号=0 30 | int 10h ; BIOS的10h功能:显示一行字符 31 | 32 | int 39h ; 原来的BIOS int 09h 33 | 34 | mov al,20h ; AL = EOI 35 | out 20h,al ; 发送EOI到主8529A 36 | out 0A0h,al ; 发送EOI到从8529A 37 | 38 | pop es 39 | pop ds 40 | popa 41 | iret ; 从中断返回 42 | 43 | Delay: ; 延迟一段时间 44 | push ax 45 | push cx 46 | mov ax, 580 47 | delay_outer: 48 | mov cx, 50000 49 | delay_inner: 50 | loop delay_inner 51 | dec ax 52 | cmp ax, 0 53 | jne delay_outer 54 | pop cx 55 | pop ax 56 | ret 57 | 58 | 59 | ouch_msg db 'OUCH! OUCH!' 60 | ouch_msg_len equ $-ouch_msg 61 | ouch_clear db ' ' -------------------------------------------------------------------------------- /项目6_二状态进程模型/src/usrprog/interrupt_caller.asm: -------------------------------------------------------------------------------- 1 | %include "../macro.asm" 2 | org addr_intcaller 3 | 4 | Start: 5 | pusha 6 | push ds 7 | mov ax, cs 8 | mov ds, ax 9 | call ClearScreen 10 | PRINT_IN_POS hint_msg1, hint_msg1_len, 7, 10 11 | PRINT_IN_POS hint_msg2, hint_msg2_len, 10, 10 12 | 13 | ; 这四个中断处理程序是相同的,参数是不同的 14 | WRITE_INT_VECTOR 33h, Int33h~36h 15 | WRITE_INT_VECTOR 34h, Int33h~36h 16 | WRITE_INT_VECTOR 35h, Int33h~36h 17 | WRITE_INT_VECTOR 36h, Int33h~36h 18 | 19 | Keyboard: 20 | mov ah, 0 21 | int 16h 22 | cmp al, '3' ; 按下3 23 | je callInt33h ; 执行int 33h 24 | cmp al, '4' ; 按下4 25 | je callInt34h ; 执行int 34h 26 | cmp al, '5' ; 按下5 27 | je callInt35h ; 执行int 35h 28 | cmp al, '6' ; 按下6 29 | je callInt36h ; 执行int 36h 30 | cmp al, 27 ; 按下ESC 31 | je QuitUsrProg ; 直接退出 32 | jmp Keyboard ; 无效按键,重新等待用户按键 33 | 34 | callInt33h: 35 | mov word[start_row], 0 36 | mov word[end_row], 5 37 | int 33h 38 | jmp QuitUsrProg 39 | callInt34h: 40 | mov word[start_row], 6 41 | mov word[end_row], 11 42 | int 34h 43 | jmp QuitUsrProg 44 | callInt35h: 45 | mov word[start_row], 12 46 | mov word[end_row], 17 47 | int 35h 48 | jmp QuitUsrProg 49 | callInt36h: 50 | mov word[start_row], 18 51 | mov word[end_row], 24 52 | int 36h 53 | jmp QuitUsrProg 54 | 55 | QuitUsrProg: 56 | pop ds 57 | popa 58 | retf 59 | 60 | ClearScreen: ; 函数:清屏 61 | pusha 62 | mov ax, 0003h 63 | int 10h ; 中断调用,清屏 64 | popa 65 | ret 66 | 67 | Footer: 68 | hint_msg1 db 'This is the Interrupt Caller Programme.' 69 | hint_msg1_len equ $-hint_msg1 70 | hint_msg2 db 'Press `3/4/5/6` to call int 33/34/35/36. Press `ESC` to quit.' 71 | hint_msg2_len equ $-hint_msg2 72 | 73 | %include "interrupt/int33h~36h.asm" -------------------------------------------------------------------------------- /项目6_二状态进程模型/src/usrprog/syscall_test.asm: -------------------------------------------------------------------------------- 1 | ; @Author: Jed 2 | ; @Description: 测试系统调用的用户程序 3 | ; @Date: 2019-04-17 4 | ; @LastEditTime: 2019-04-19 5 | 6 | %include "../macro.asm" 7 | org addr_syscalltest 8 | 9 | Start: 10 | pusha 11 | push es 12 | 13 | mov ax, 0003h 14 | int 10h ; 清屏 15 | 16 | PRINT_IN_POS hint_all, hint_all_len, 0, 0 17 | mov ah, 0 18 | int 16h 19 | cmp al, 27 ; 按下ESC 20 | je QuitUsrProg ; 直接退出 21 | 22 | PRINT_IN_POS hint0, hint_len, 2, 0 23 | mov ah, 00h ; 系统调用功能号ah=00h,显示OUCH 24 | int 21h 25 | mov ah, 0 26 | int 16h 27 | cmp al, 27 ; 按下ESC 28 | je QuitUsrProg ; 直接退出 29 | 30 | PRINT_IN_POS hint1, hint_len, 2, 0 31 | mov ax, cs 32 | mov es, ax ; es=cs 33 | mov dx, upper_lower ; es:dx=串地址 34 | PRINT_IN_POS upper_lower, 14, 3, 0 35 | mov ah, 01h ; 系统调用功能号ah=01h,大写转小写 36 | int 21h 37 | PRINT_IN_POS upper_lower, 14, 4, 0 38 | mov ah, 0 39 | int 16h 40 | cmp al, 27 ; 按下ESC 41 | je QuitUsrProg ; 直接退出 42 | 43 | PRINT_IN_POS hint2, hint_len, 2, 0 44 | mov ax, cs 45 | mov es, ax ; es=cs 46 | mov dx, upper_lower ; es:dx=串地址 47 | mov ah, 02h ; 系统调用功能号ah=02h,小写转大写 48 | int 21h 49 | PRINT_IN_POS upper_lower, 14, 5, 0 50 | mov ah, 0 51 | int 16h 52 | cmp al, 27 ; 按下ESC 53 | je QuitUsrProg ; 直接退出 54 | 55 | PRINT_IN_POS hint3, hint_len, 2, 0 56 | mov ax, cs 57 | mov es, ax ; es=cs 58 | mov dx, number_buf 59 | mov ah, 03h ; 系统调用功能号ah=03h,atoi 60 | int 21h ; ax=数值 61 | mov bx, 1 62 | add bx, ax ; bx=ax+1,然后使用下一个系统调用来检查其结果 63 | mov ah, 0 64 | int 16h 65 | cmp al, 27 ; 按下ESC 66 | je QuitUsrProg ; 直接退出 67 | 68 | PRINT_IN_POS hint4, hint_len, 2, 0 69 | mov ax, cs 70 | mov es, ax ; es=cs 71 | mov dx, number_buf 72 | mov ah, 04h ; 系统调用功能号ah=04h,itoa 73 | int 21h ; es:dx=转换后的数字字符串 74 | mov ch, 6 75 | mov cl, 0 76 | mov ah, 05h 77 | int 21h 78 | 79 | mov ah, 0 80 | int 16h 81 | cmp al, 27 ; 按下ESC 82 | je QuitUsrProg ; 直接退出 83 | 84 | PRINT_IN_POS hint5, hint_len, 2, 0 85 | mov ax, cs 86 | mov es, ax ; es=cs 87 | mov dx, test_message1 ; es:dx=串地址 88 | mov ch, 19 ; 行号 89 | mov cl, 0 ; 列号 90 | mov ah, 05h ; 系统调用功能号ah=05h 91 | int 21h ; 显示第一条字符串 92 | mov dx, test_message2 93 | mov ch, 20 94 | mov cl, 0 95 | int 21h ; 显示第二条字符串 96 | mov ah, 0 97 | int 16h 98 | cmp al, 27 ; 按下ESC 99 | je QuitUsrProg ; 直接退出 100 | QuitUsrProg: 101 | pop es 102 | popa 103 | retf 104 | 105 | DataArea: 106 | hint_all db 'Welcome to syscall_test program, where there are several tests of system call. See the document for more details.' 107 | hint_all_len equ $-hint_all 108 | 109 | hint0 db 'Test of ah=00h is running. press ENTER to continue, or ESC to quit.' 110 | hint1 db 'Test of ah=01h is running. press ENTER to continue, or ESC to quit.' 111 | hint2 db 'Test of ah=02h is running. press ENTER to continue, or ESC to quit.' 112 | hint3 db 'Test of ah=03h is running. press ENTER to continue, or ESC to quit.' 113 | hint4 db 'Test of ah=04h is running. press ENTER to continue, or ESC to quit.' 114 | hint5 db 'Test of ah=05h is running. press ENTER to continue, or ESC to quit.' 115 | hint_len equ ($-hint5) 116 | 117 | upper_lower db 'AbCdEfGhIjKlMn', 0 ; 字符串以'\0'结尾 118 | 119 | number_buf db '12345', 0 ; 字符串以'\0'结尾 120 | test_message1 db 'This is a test message,' 121 | test_message2 db 'printed using `ah=05h` and `int 21h`.' -------------------------------------------------------------------------------- /项目6_二状态进程模型/src/usrproginfo.asm: -------------------------------------------------------------------------------- 1 | ; @Author: Jed 2 | ; @Description: 用户车呢光绪信息表。放在软盘第2个扇区。 3 | ; @Date: 2019-03-29 4 | ; @LastEditTime: 2019-04-01 5 | 6 | %include "macro.asm" 7 | %macro UsrProgInfoBlock 8 ; 参数:(ProgID,程序名,字节数,柱面,磁头,扇区,内存地址) 8 | progid%1 db %1 ; 程序编号ProgID;相对偏移0 9 | name%1 db %2 ; 程序名(至多32字节);相对偏移1 10 | times 16-($-name%1) db 0 ; 程序名占6字节 11 | size%1 dw %3 ; 程序大小;相对偏移17 12 | cylinder%1 db %4 ; 柱面;相对偏移19 13 | head%1 db %5 ; 磁头;相对偏移20 14 | sector%1 db %6 ; 扇区;相对偏移21 15 | addr_seg%1 dw %7 ; 内存地址段值;相对偏移22 16 | addr_off%1 dw %8 ; 内存地址偏移量;相对偏移24 17 | %endmacro ; 共26个字节 18 | 19 | UsrProgNumber: 20 | db 6 ; 用户程序数量 21 | 22 | UserProgInfo: 23 | UsrProgInfoBlock 1, 'stone_topleft', 1024, 1, 0, 1, addr_usrprog1 >> 4 & 0F000h, addr_usrprog1 & 0FFFFh 24 | UsrProgInfoBlock 2, 'stone_topright', 1024, 1, 0, 3, addr_usrprog2 >> 4 & 0F000h, addr_usrprog2 & 0FFFFh 25 | UsrProgInfoBlock 3, 'stone_botleft', 1024, 1, 0, 5, addr_usrprog3 >> 4 & 0F000h, addr_usrprog3 & 0FFFFh 26 | UsrProgInfoBlock 4, 'stone_botright', 1024, 1, 0, 7, addr_usrprog4 >> 4 & 0F000h, addr_usrprog4 & 0FFFFh 27 | UsrProgInfoBlock 5, 'interrupt_caller', 512, 1, 0, 9, addr_intcaller >> 4 & 0F000h, addr_intcaller & 0FFFFh 28 | UsrProgInfoBlock 6, 'syscall_test', 1536, 1, 0, 10, addr_syscalltest >> 4 & 0F000h, addr_syscalltest & 0FFFFh 29 | 30 | SectorEnding: 31 | times 512-($-$$) db 0 -------------------------------------------------------------------------------- /项目7_进程控制与通信/JedOS_v1.5.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目7_进程控制与通信/JedOS_v1.5.img -------------------------------------------------------------------------------- /项目7_进程控制与通信/assets/1559751636452.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目7_进程控制与通信/assets/1559751636452.png -------------------------------------------------------------------------------- /项目7_进程控制与通信/assets/1559751697219.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目7_进程控制与通信/assets/1559751697219.png -------------------------------------------------------------------------------- /项目7_进程控制与通信/assets/1559751965179.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目7_进程控制与通信/assets/1559751965179.png -------------------------------------------------------------------------------- /项目7_进程控制与通信/assets/1559752034244.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目7_进程控制与通信/assets/1559752034244.png -------------------------------------------------------------------------------- /项目7_进程控制与通信/assets/1559752143451.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目7_进程控制与通信/assets/1559752143451.png -------------------------------------------------------------------------------- /项目7_进程控制与通信/assets/1559752320162.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目7_进程控制与通信/assets/1559752320162.png -------------------------------------------------------------------------------- /项目7_进程控制与通信/assets/1559752388595.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jed-Z/operating-systems-lab/e4c3581390e8b919553018e82596e292d9ec18ed/项目7_进程控制与通信/assets/1559752388595.png -------------------------------------------------------------------------------- /项目7_进程控制与通信/src/bootloader.asm: -------------------------------------------------------------------------------- 1 | ; @Author: Jed 2 | ; @Description: 引导程序;独立编译 3 | ; @Date: 2019-03-21 4 | ; @LastEditTime: 2019-04-12 5 | 6 | BITS 16 7 | %include "macro.asm" 8 | org 7c00h 9 | 10 | global _start 11 | _start: 12 | mov ax, cs 13 | mov ds, ax ; ds=cs 14 | PRINT_IN_POS msg, msg_len, 0, 0 ; 调用宏,显示字符串 15 | 16 | LoadOsKernel: 17 | LOAD_TO_MEM 34, 0, 0, 3, 0h, addr_oskernel & 0FFFFh ; 调用宏,加载操作系统内核 18 | 19 | LoadUsrProgInfo: 20 | LOAD_TO_MEM 1, 0, 0, 2, 0h, addr_upinfo & 0FFFFh ; 调用宏,加载用户程序信息表 21 | 22 | EnterOs: 23 | jmp addr_oskernel ; 跳转到操作系统内核 24 | 25 | DataArea: 26 | msg db 'Bootloader is loading operating system...' 27 | msg_len equ ($-msg) 28 | 29 | times 510-($-$$) db 0 30 | db 0x55, 0xaa ; 主引导记录标志 -------------------------------------------------------------------------------- /项目7_进程控制与通信/src/lib/systema.asm: -------------------------------------------------------------------------------- 1 | BITS 16 2 | [global sys_showOuch] 3 | [global sys_toUpper] 4 | [global sys_toLower] 5 | [global sys_atoi] 6 | [global sys_itoa] 7 | [global sys_printInPos] 8 | [global sys_timer_flag] 9 | 10 | sys_showOuch: 11 | pusha ; 保护现场 12 | push ds 13 | push es 14 | mov ax, cs ; 置其他段寄存器值与CS相同 15 | mov ds, ax ; 数据段 16 | mov bp, ouch_str ; BP=当前串的偏移地址 17 | mov ax, ds ; ES:BP = 串地址 18 | mov es, ax ; 置ES=DS 19 | mov cx, 4 ; CX = 串长 20 | mov ax, 1301h ; AH = 13h(功能号)、AL = 01h(光标置于串尾) 21 | mov bx, 0038h ; 页号为0(BH = 0) 黑底白字(BL = 07h) 22 | mov dh, 12 ; 行号 23 | mov dl, 38 ; 列号 24 | int 10h ; BIOS的10h功能:显示一行字符 25 | pop es 26 | pop ds 27 | popa ; 恢复现场 28 | ret 29 | ouch_str db 'OUCH' 30 | 31 | [extern toupper] 32 | sys_toUpper: 33 | push es ; 传递参数 34 | push dx ; 传递参数 35 | call dword toupper 36 | pop dx ; 丢弃参数 37 | pop es ; 丢弃参数 38 | ret 39 | 40 | [extern tolower] 41 | sys_toLower: 42 | push es ; 传递参数 43 | push dx ; 传递参数 44 | call dword tolower 45 | pop dx ; 丢弃参数 46 | pop es ; 丢弃参数 47 | ret 48 | 49 | [extern atoi] 50 | sys_atoi: 51 | push es ; 传递参数 52 | push dx ; 传递参数 53 | call dword atoi 54 | pop dx ; 丢弃参数 55 | pop es ; 丢弃参数 56 | ret 57 | 58 | [extern itoa_buf] 59 | sys_itoa: 60 | push es ; 传递参数buf 61 | push dx ; 传递参数buf 62 | mov ax, 0 63 | push ax ; 传递参数base 64 | mov ax, 10 ; 10进制 65 | push ax ; 传递参数base 66 | mov ax, 0 67 | push ax ; 传递参数val 68 | push bx ; 传递参数val 69 | call dword itoa_buf 70 | pop bx ; 丢弃参数 71 | pop ax ; 丢弃参数 72 | pop ax ; 丢弃参数 73 | pop ax ; 丢弃参数 74 | pop dx ; 丢弃参数 75 | pop es ; 丢弃参数 76 | ret 77 | 78 | [extern strlen] 79 | sys_printInPos: 80 | pusha 81 | mov bp, dx ; es:bp=串地址 82 | push es ; 传递参数 83 | push bp ; 传递参数 84 | call dword strlen ; 返回值ax=串长 85 | pop bp ; 丢弃参数 86 | pop es ; 丢弃参数 87 | mov bl, 07h ; 颜色 88 | mov dh, ch ; 行号 89 | mov dl, cl ; 列号 90 | mov cx, ax ; 串长 91 | mov bh, 0 ; 页码 92 | mov al, 0 ; 光标不动 93 | mov ah, 13h ; BIOS功能号 94 | int 10h 95 | popa 96 | ret 97 | 98 | [extern timer_flag] 99 | sys_timer_flag: 100 | mov ax, [cs:timer_flag] 101 | ret -------------------------------------------------------------------------------- /项目7_进程控制与通信/src/lib/systemc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define bool unsigned short 3 | #define true 1 4 | #define false 0 5 | 6 | /* 将字符串中的小写字母转换为大写 */ 7 | void toupper(char* str) { 8 | int i=0; 9 | while(str[i]) { 10 | if (str[i] >= 'a' && str[i] <= 'z') 11 | str[i] = str[i]-'a'+'A'; 12 | i++; 13 | } 14 | } 15 | 16 | /* 将字符串中的大写字母转换为小写 */ 17 | void tolower(char* str) { 18 | int i=0; 19 | while(str[i]) { 20 | if (str[i] >= 'A' && str[i] <= 'Z') 21 | str[i] = str[i]-'A'+'a'; 22 | i++; 23 | } 24 | } 25 | 26 | /* 翻转字符串 */ 27 | void my_reverse(char str[], int len) 28 | { 29 | int start, end; 30 | char temp; 31 | for (start = 0, end = len - 1; start < end; start++, end--) { 32 | temp = *(str + start); 33 | *(str + start) = *(str + end); 34 | *(str + end) = temp; 35 | } 36 | } 37 | 38 | /* 将数字转换为字符串并放在str中 */ 39 | char* itoa_buf(int num, int base, char* str) 40 | { 41 | int i = 0; 42 | bool isNegative = false; 43 | 44 | /* A zero is same "0" string in all base */ 45 | if (num == 0) { 46 | str[i] = '0'; 47 | str[i + 1] = '\0'; 48 | return str; 49 | } 50 | 51 | /* negative numbers are only handled if base is 10 52 | otherwise considered unsigned number */ 53 | if (num < 0 && base == 10) { 54 | isNegative = true; 55 | num = -num; 56 | } 57 | 58 | while (num != 0) { 59 | int rem = num % base; 60 | str[i++] = (rem > 9) ? (rem - 10) + 'A' : rem + '0'; 61 | num = num / base; 62 | } 63 | 64 | /* Append negative sign for negative numbers */ 65 | if (isNegative) { 66 | str[i++] = '-'; 67 | } 68 | 69 | str[i] = '\0'; 70 | 71 | my_reverse(str, i); 72 | 73 | return str; 74 | } 75 | 76 | /* 将十进制数字字符串转换为整数 */ 77 | int atoi(char *str) { 78 | int res = 0; // Initialize result 79 | 80 | // Iterate through all characters of input string and 81 | // update result 82 | for (int i = 0; str[i] != '\0'; ++i) { 83 | res = res*10 + str[i] - '0'; 84 | } 85 | // return result. 86 | return res; 87 | } 88 | 89 | /* 将BCD码转为数字 */ 90 | uint8_t bcd2decimal(uint8_t bcd) 91 | { 92 | return ((bcd & 0xF0) >> 4) * 10 + (bcd & 0x0F); 93 | } -------------------------------------------------------------------------------- /项目7_进程控制与通信/src/macro.asm: -------------------------------------------------------------------------------- 1 | addr_upinfo equ 07E00h ; 用户程序信息表被装入的位置 2 | addr_oskernel equ 08000h ; 操作系统内核被装入的位置 3 | 4 | addr_usrprog1 equ 10000h ; 四个普通用户程序的物理地址 5 | addr_usrprog2 equ 20000h ; 四个普通用户程序的物理地址 6 | addr_usrprog3 equ 30000h ; 四个普通用户程序的物理地址 7 | addr_usrprog4 equ 40000h ; 四个普通用户程序的物理地址 8 | addr_intcaller equ 50000h 9 | ; addr_syscalltest equ 0B500h 10 | addr_forktest equ 60000h 11 | 12 | %macro WRITE_INT_VECTOR 2 ; 写中断向量表;参数:(中断号,中断处理程序地址) 13 | push ax 14 | push es 15 | mov ax, 0 16 | mov es, ax ; ES = 0 17 | mov word[es:%1*4], %2 ; 设置中断向量的偏移地址 18 | mov ax,cs 19 | mov word[es:%1*4+2], ax ; 设置中断向量的段地址=CS 20 | pop es 21 | pop ax 22 | %endmacro 23 | 24 | %macro MOVE_INT_VECTOR 2 ; 转移中断向量;参数:(源中断号,目的中断号) 25 | push ax 26 | push es 27 | push si 28 | mov ax, 0 29 | mov es, ax ; es=0 30 | mov si, [es:%1*4] 31 | mov [es:%2*4], si 32 | mov si, [es:%1*4+2] 33 | mov [es:%2*4+2], si 34 | pop si 35 | pop es 36 | pop ax 37 | %endmacro 38 | 39 | %macro PRINT_IN_POS 4 ; 在指定位置打印字符串;参数:(串地址,串长,行号,列号) 40 | pusha ; 保护现场 41 | push ds 42 | push es 43 | mov ax, cs ; 置其他段寄存器值与CS相同 44 | mov ds, ax ; 数据段 45 | mov bp, %1 ; BP=当前串的偏移地址 46 | mov ax, ds ; ES:BP = 串地址 47 | mov es, ax ; 置ES=DS 48 | mov cx, %2 ; CX = 串长(=9) 49 | mov ax, 1301h ; AH = 13h(功能号)、AL = 01h(光标置于串尾) 50 | mov bx, 0007h ; 页号为0(BH = 0) 黑底白字(BL = 07h) 51 | mov dh, %3 ; 行号=0 52 | mov dl, %4 ; 列号=0 53 | int 10h ; BIOS的10h功能:显示一行字符 54 | pop es 55 | pop ds 56 | popa ; 恢复现场 57 | %endmacro 58 | 59 | %macro LOAD_TO_MEM 6 ; 读软盘到内存;参数:(扇区数,柱面号,磁头号,扇区号,内存段值,内存偏移量) 60 | pusha 61 | push es 62 | mov ax, %5 ; 段地址; 存放数据的内存基地址 63 | mov es, ax ; 设置段地址(不能直接mov es,段地址) 64 | mov bx, %6 ; 偏移地址; 存放数据的内存偏移地址 65 | mov ah, 2 ; 功能号 66 | mov al, %1 ; 扇区数 67 | mov dl, 0 ; 驱动器号; 软盘为0,硬盘和U盘为80H 68 | mov dh, %3 ; 磁头号; 起始编号为0 69 | mov ch, %2 ; 柱面号; 起始编号为0 70 | mov cl, %4 ; 起始扇区号 ; 起始编号为1 71 | int 13H ; 调用读磁盘BIOS的13h功能 72 | pop es 73 | popa 74 | %endmacro 75 | 76 | %macro PUTCHAR 1 77 | pusha 78 | mov al, %1 ; al=要打印的字符 79 | mov bh, 0 ; bh=页码 80 | mov ah, 0Eh ; 功能号:打印一个字符 81 | int 10h ; 打印字符 82 | popa 83 | %endmacro 84 | 85 | %macro PRINTLN 1 86 | pusha 87 | mov si, %1 88 | Loop1_%1: 89 | cmp byte[cs:si], 0 90 | je Quit1_%1 91 | PUTCHAR [cs:si] 92 | inc si 93 | jmp Loop1_%1 94 | Quit1_%1: 95 | popa 96 | %endmacro -------------------------------------------------------------------------------- /项目7_进程控制与通信/src/merge.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | rm -rf temp 3 | mkdir temp 4 | rm *.img 5 | 6 | nasm bootloader.asm -o ./temp/bootloader.bin 7 | nasm usrproginfo.asm -o ./temp/usrproginfo.bin 8 | 9 | cd usrprog 10 | nasm stone_topleft.asm -o ../temp/stone_topleft.bin 11 | nasm stone_topright.asm -o ../temp/stone_topright.bin 12 | nasm stone_bottomleft.asm -o ../temp/stone_bottomleft.bin 13 | nasm stone_bottomright.asm -o ../temp/stone_bottomright.bin 14 | nasm interrupt_caller.asm -o ../temp/interrupt_caller.bin 15 | nasm fork_test.asm -o ../temp/fork_test.bin 16 | cd .. 17 | 18 | cd lib 19 | nasm -f elf32 systema.asm -o ../temp/systema.o 20 | gcc -fno-pie -c -m16 -march=i386 -masm=intel -ffreestanding -mpreferred-stack-boundary=2 -shared systemc.c -o ../temp/systemc.o 21 | cd .. 22 | 23 | nasm -f elf32 osstarter.asm -o ./temp/osstarter.o 24 | nasm -f elf32 liba.asm -o ./temp/liba.o 25 | nasm -f elf32 multiprocess.asm -o ./temp/multiprocess.o 26 | gcc -fno-pie -c -m16 -march=i386 -masm=intel -ffreestanding -mpreferred-stack-boundary=2 -shared kernel.c -o ./temp/kernel.o 27 | ld -m elf_i386 -N -Ttext 0x8000 --oformat binary ./temp/osstarter.o ./temp/liba.o ./temp/kernel.o ./temp/systema.o ./temp/systemc.o ./temp/multiprocess.o -o ./temp/kernel.bin 28 | rm ./temp/*.o 29 | 30 | dd if=./temp/bootloader.bin of=JedOS_v1.5.img bs=512 count=1 2> /dev/null 31 | dd if=./temp/usrproginfo.bin of=JedOS_v1.5.img bs=512 seek=1 count=1 2> /dev/null 32 | dd if=./temp/kernel.bin of=JedOS_v1.5.img bs=512 seek=2 count=34 2> /dev/null 33 | dd if=./temp/stone_topleft.bin of=JedOS_v1.5.img bs=512 seek=36 count=2 2> /dev/null 34 | dd if=./temp/stone_topright.bin of=JedOS_v1.5.img bs=512 seek=38 count=2 2> /dev/null 35 | dd if=./temp/stone_bottomleft.bin of=JedOS_v1.5.img bs=512 seek=40 count=2 2> /dev/null 36 | dd if=./temp/stone_bottomright.bin of=JedOS_v1.5.img bs=512 seek=42 count=2 2> /dev/null 37 | dd if=./temp/interrupt_caller.bin of=JedOS_v1.5.img bs=512 seek=44 count=1 2> /dev/null 38 | dd if=./temp/fork_test.bin of=JedOS_v1.5.img bs=512 seek=48 count=2 2> /dev/null 39 | 40 | 41 | echo "[+] Done." -------------------------------------------------------------------------------- /项目7_进程控制与通信/src/osstarter.asm: -------------------------------------------------------------------------------- 1 | ; @Author: Jed 2 | ; @Description: 操作系统内核入口 3 | ; @Date: 2019-03-22 4 | ; @LastEditTime: 2019-03-23 5 | 6 | BITS 16 7 | %include "macro.asm" 8 | [extern startUp] 9 | [extern shell] 10 | [extern syscaller] 11 | [extern Timer] 12 | [extern sys_fork] 13 | [extern sys_wait] 14 | [extern sys_exit] 15 | 16 | global _start 17 | _start: 18 | WRITE_INT_VECTOR 21h, syscaller ; 装填系统调用中断向量表 19 | WRITE_INT_VECTOR 22h, sys_fork 20 | WRITE_INT_VECTOR 23h, sys_wait 21 | WRITE_INT_VECTOR 24h, sys_exit 22 | 23 | SetTimer: 24 | mov al,34h ; 设控制字值 25 | out 43h,al ; 写控制字到控制字寄存器 26 | mov ax,29830 ; 每秒 20 次中断(50ms 一次) 27 | out 40h,al ; 写计数器 0 的低字节 28 | mov al,ah ; AL=AH 29 | out 40h,al ; 写计数器 0 的高字节 30 | WRITE_INT_VECTOR 08h, Timer 31 | MOVE_INT_VECTOR 08h, 48h 32 | call dword startUp ; 进入欢迎界面 33 | 34 | Keyboard: 35 | mov ah, 0 36 | int 16h 37 | cmp al, 0Dh ; 按下回车 38 | jne Keyboard ; 无效按键,重新等待用户按键 39 | call dword shell ; 进入命令行界面 40 | jmp Keyboard ; 无限循环 -------------------------------------------------------------------------------- /项目7_进程控制与通信/src/process.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: Jed 3 | * @Description: PCB、进程调度、do_fork、do_wait、do_exit 4 | * @Date: 2019-06-04 5 | * @LastEditTime: 2019-06-06 6 | */ 7 | #include 8 | #define PROCESS_NUM 8 9 | 10 | extern void goBackToKernel(); 11 | extern void copyStack(); 12 | extern uint16_t current_process_id; // 当前进程ID,定义在multiprocess.asm中 13 | extern uint16_t stack_length; 14 | extern uint16_t from_seg, to_seg; 15 | 16 | typedef struct RegisterImage{ 17 | uint16_t ax; // 0 18 | uint16_t cx; // 2 19 | uint16_t dx; // 4 20 | uint16_t bx; // 6 21 | uint16_t sp; // 8 22 | uint16_t bp; // 10 23 | uint16_t si; // 12 24 | uint16_t di; // 14 25 | uint16_t ds; // 16 26 | uint16_t es; // 18 27 | uint16_t fs; // 20 28 | uint16_t gs; // 22 29 | uint16_t ss; // 24 30 | uint16_t ip; // 26 31 | uint16_t cs; // 28 32 | uint16_t flags; // 30 33 | } RegisterImage; 34 | 35 | typedef struct PCB{ 36 | RegisterImage regimg; 37 | uint8_t id; // 32 38 | uint8_t state; // 33 39 | }PCB; 40 | 41 | enum PCB_STATE {P_NEW, P_READY, P_RUNNING, P_BLOCKED, P_EXIT}; 42 | extern PCB pcb_table[PROCESS_NUM]; // PCB表,定义在内核kernel.c中 43 | 44 | void pcb_init() { 45 | for(int i = 0; i < PROCESS_NUM; i++) { 46 | pcb_table[i].id = i; 47 | pcb_table[i].state = 0; 48 | pcb_table[i].regimg.ax = 0; 49 | pcb_table[i].regimg.cx = 0; 50 | pcb_table[i].regimg.dx = 0; 51 | pcb_table[i].regimg.bx = 0; 52 | pcb_table[i].regimg.sp = 0xFE00; 53 | pcb_table[i].regimg.bp = 0; 54 | pcb_table[i].regimg.si = 0; 55 | pcb_table[i].regimg.di = 0; 56 | pcb_table[i].regimg.ds = 0; 57 | pcb_table[i].regimg.es = 0; 58 | pcb_table[i].regimg.fs = 0; 59 | pcb_table[i].regimg.gs = 0xB800; 60 | pcb_table[i].regimg.ss = 0; 61 | pcb_table[i].regimg.ip = 0; 62 | pcb_table[i].regimg.cs = 0; 63 | pcb_table[i].regimg.flags = 512; 64 | } 65 | } 66 | 67 | /* 获取当前进程的PCB指针 */ 68 | PCB* getCurrentPcb() { 69 | return &pcb_table[current_process_id]; 70 | } 71 | 72 | /* 获取PCB表的首地址 */ 73 | PCB* getPcbTable() { 74 | return &pcb_table[0]; 75 | } 76 | 77 | /* 进程调度 */ 78 | void pcbSchedule() { 79 | uint16_t privious_id = current_process_id; 80 | getCurrentPcb()->state = P_READY; 81 | do { 82 | current_process_id++; 83 | if(current_process_id >= PROCESS_NUM) current_process_id = 1; 84 | } while(getCurrentPcb()->state != P_READY); 85 | getCurrentPcb()->state = P_RUNNING; 86 | 87 | // 没有发现其它处于就绪态的进程,返回内核 88 | // if(current_process_id == privious_id) { 89 | // goBackToKernel(); 90 | // } 91 | } 92 | 93 | void initSubPcb(uint16_t sid) { 94 | pcb_table[sid].id = sid; 95 | pcb_table[sid].state = P_READY; // 设置子进程为就绪态 96 | pcb_table[sid].regimg.ax = 0; // 子进程的fork返回值=0 97 | pcb_table[sid].regimg.cx = getCurrentPcb()->regimg.cx; 98 | pcb_table[sid].regimg.dx = getCurrentPcb()->regimg.dx; 99 | pcb_table[sid].regimg.bx = getCurrentPcb()->regimg.bx; 100 | pcb_table[sid].regimg.sp = getCurrentPcb()->regimg.sp; 101 | pcb_table[sid].regimg.bp = getCurrentPcb()->regimg.bp; 102 | pcb_table[sid].regimg.si = getCurrentPcb()->regimg.si; 103 | pcb_table[sid].regimg.di = getCurrentPcb()->regimg.di; 104 | pcb_table[sid].regimg.ds = getCurrentPcb()->regimg.ds; 105 | pcb_table[sid].regimg.es = getCurrentPcb()->regimg.es; 106 | pcb_table[sid].regimg.fs = getCurrentPcb()->regimg.fs; 107 | pcb_table[sid].regimg.gs = getCurrentPcb()->regimg.gs; 108 | pcb_table[sid].regimg.ss = sid * 0x1000; // 子进程的堆栈段 109 | pcb_table[sid].regimg.ip = getCurrentPcb()->regimg.ip; 110 | pcb_table[sid].regimg.cs = getCurrentPcb()->regimg.cs; 111 | pcb_table[sid].regimg.flags = getCurrentPcb()->regimg.flags; 112 | 113 | stack_length = 0xFE00 - pcb_table[sid].regimg.sp; 114 | from_seg = getCurrentPcb()->regimg.ss; 115 | to_seg = pcb_table[sid].regimg.ss; 116 | } 117 | 118 | 119 | void do_fork() { 120 | uint16_t sid = 1; // 子进程ID 121 | for(sid = 1; sid < PROCESS_NUM; sid++) { 122 | if(pcb_table[sid].state == P_NEW) break; 123 | } 124 | if(sid >= PROCESS_NUM || sid <= 0) { 125 | getCurrentPcb()->regimg.ax = -1; // fork失败,给父进程返回-1 126 | } 127 | else { 128 | getCurrentPcb()->regimg.ax = sid; // fork成功,给父进程返回子进程ID 129 | initSubPcb(sid); // 为子进程初始化PCB 130 | copyStack(); // 拷贝父进程的栈到子进程的栈 131 | pcb_table[sid].regimg.ax = 0; 132 | pcb_table[sid].id = current_process_id; // 父进程的ID 133 | } 134 | } 135 | 136 | void do_wait() { 137 | PCB* to_be_blocked = getCurrentPcb(); 138 | pcbSchedule(); 139 | to_be_blocked->state = P_BLOCKED; 140 | } 141 | 142 | void do_exit() { 143 | PCB* to_exit = getCurrentPcb(); 144 | getCurrentPcb()->state = P_EXIT; 145 | pcb_table[getCurrentPcb()->id].state = P_READY; 146 | pcbSchedule(); 147 | to_exit->state = P_EXIT; 148 | } -------------------------------------------------------------------------------- /项目7_进程控制与通信/src/stringio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: Jed 3 | * @Description: 涉及字符串输入输出的C函数库 4 | * @Date: 2019-03-23 5 | * @LastEditTime: 2019-05-02 6 | */ 7 | #ifndef _STRINGIO_H_ 8 | #define _STRINGIO_H_ 9 | 10 | #include 11 | #define NEWLINE putchar('\r');putchar('\n') 12 | extern void printInPos(const char *msg, uint16_t len, uint8_t row, uint8_t col); 13 | extern void putchar_c(char c, uint8_t color); 14 | extern char getch(); 15 | enum bios_color {white_c=0x07}; 16 | 17 | /* 字符串长度 */ 18 | uint16_t strlen(const char *str) { 19 | int count = 0; 20 | while (str[count++] != '\0'); 21 | return count - 1; // 循环中使用后递增,因此这里需要减1 22 | } 23 | 24 | /* 比较字符串 */ 25 | uint8_t strcmp(const char* str1, const char* str2) { 26 | int i = 0; 27 | while (1) { 28 | if(str1[i]=='\0' || str2[i]=='\0') { break; } 29 | if(str1[i] != str2[i]) { break; } 30 | ++i; 31 | } 32 | return str1[i] - str2[i]; 33 | } 34 | 35 | /* 显示一个白色字符 */ 36 | void putchar(char c) { 37 | putchar_c(c, 0x07); 38 | } 39 | 40 | /* 在光标处显示字符串 */ 41 | void print(const char* str) { 42 | for(int i = 0, len = strlen(str); i < len; i++) { 43 | putchar(str[i]); 44 | } 45 | } 46 | 47 | /* 在光标处显示彩色字符串 */ 48 | void print_c(const char* str, uint8_t color) { 49 | for(int i = 0, len = strlen(str); i < len; i++) { 50 | putchar_c(str[i], color); 51 | } 52 | } 53 | 54 | /* 读取字符串到缓冲区 */ 55 | void readToBuf(char* buffer, uint16_t maxlen) { 56 | int i = 0; 57 | while(1) { 58 | char tempc = getch(); 59 | if(!(tempc==0xD || tempc=='\b' || tempc>=32 && tempc<=127)) { continue; } // 非有效字符不予理会 60 | if(i > 0 && i < maxlen-1) { // buffer中有字符且未满 61 | if(tempc == 0x0D) { 62 | break; // 按下回车,停止读取 63 | } 64 | else if(tempc == '\b') { // 按下退格,则删除一个字符 65 | putchar('\b'); 66 | putchar(' '); 67 | putchar('\b'); 68 | --i; 69 | } 70 | else{ 71 | putchar(tempc); // 回显 72 | buffer[i] = tempc; 73 | ++i; 74 | } 75 | } 76 | else if(i >= maxlen-1) { // 达到最大值,只能按退格或回车 77 | if(tempc == '\b') { // 按下退格,则删除一个字符 78 | putchar('\b'); 79 | putchar(' '); 80 | putchar('\b'); 81 | --i; 82 | } 83 | else if(tempc == 0x0D) { 84 | break; // 按下回车,停止读取 85 | } 86 | } 87 | else if(i <= 0) { // buffer中没有字符,只能输入或回车,不能删除 88 | if(tempc == 0x0D) { 89 | break; // 按下回车,停止读取 90 | } 91 | else if(tempc != '\b') { 92 | putchar(tempc); // 回显 93 | buffer[i] = tempc; 94 | ++i; 95 | } 96 | } 97 | } 98 | putchar('\r'); putchar('\n'); 99 | buffer[i] = '\0'; // 字符串必须以空字符结尾 100 | } 101 | 102 | /* 将整数转为指定进制的字符串 */ 103 | char* itoa(int val, int base) { 104 | if(val==0) return "0"; 105 | static char buf[32] = {0}; 106 | int i = 30; 107 | for(; val && i ; --i, val /= base) { 108 | buf[i] = "0123456789ABCDEF"[val % base]; 109 | } 110 | return &buf[i+1]; 111 | } 112 | 113 | /* 判断字符是否是十进制数字 */ 114 | uint8_t isnum(char c) { 115 | return c>='0' && c<='9'; 116 | } 117 | 118 | /* 获取字符串的第一个空格前的词 */ 119 | void getFirstWord(const char* str, char* buf) { 120 | int i = 0; 121 | while(str[i] && str[i] != ' ') { 122 | buf[i] = str[i]; 123 | i++; 124 | } 125 | buf[i] = '\0'; // 字符串必须以空字符结尾 126 | } 127 | 128 | /* 获取字符串的第一个空格后的词 */ 129 | void getAfterFirstWord(const char* str, char* buf) { 130 | buf[0] = '\0'; // 为了应对用户故意搞破坏 131 | int i = 0; 132 | while(str[i] && str[i] != ' ') { 133 | i++; 134 | } 135 | while(str[i] && str[i] == ' ') { 136 | i++; 137 | } 138 | int j = 0; 139 | while(str[i]) { 140 | buf[j++] = str[i++]; 141 | } 142 | buf[j] = '\0'; // 字符串必须以空字符结尾 143 | } 144 | 145 | #endif -------------------------------------------------------------------------------- /项目7_进程控制与通信/src/usrprog/fork_test.asm: -------------------------------------------------------------------------------- 1 | BITS 16 2 | %include "../macro.asm" 3 | [global _start] 4 | 5 | _start: 6 | mov ax, 0003h 7 | int 10h ; 清屏 8 | PRINTLN welcome ; 打印欢迎信息 9 | 10 | int 22h ; 调用fork(),ax=fork的结果 11 | cmp ax, 0 12 | jl ForkFailure 13 | cmp ax, 0 14 | jg ForkParent 15 | cmp ax, 0 16 | je ForkSon 17 | 18 | jmp QuitUsrProg 19 | 20 | 21 | ForkFailure: ; ------ fork失败 ------ 22 | PRINTLN error_fork 23 | jmp QuitUsrProg 24 | 25 | 26 | ForkParent: ; ------ 父进程 ------ 27 | PRINTLN parent_say 28 | int 23h ; 调用wait() 29 | 30 | PRINTLN result_1 31 | PRINTLN the_str 32 | PRINTLN result_2 33 | call printLetterCount 34 | PRINTLN finishbye 35 | int 24h ; 调用exit(),退出父进程 36 | 37 | jmp QuitUsrProg 38 | 39 | ForkSon: ; ------ 子进程 ------ 40 | PRINTLN son_say 41 | call countLetter ; 统计字母个数 42 | int 24h ; 调用exit(),退出子进程 43 | jmp QuitUsrProg 44 | 45 | 46 | 47 | QuitUsrProg: 48 | jmp $ 49 | 50 | countLetter: ; 函数:统计the_str中的字母个数并保存在letter_count中 51 | pusha 52 | mov si, the_str 53 | loopCheck: 54 | cmp byte[si], 0 55 | je quitCountLetter 56 | cmp byte[si], 'a' 57 | jl loopContinue 58 | cmp byte[si], 'z' 59 | jg loopContinue 60 | inc word[letter_count] ; 如果是小写字母则递增 61 | loopContinue: 62 | inc si 63 | jmp loopCheck 64 | quitCountLetter: 65 | popa 66 | ret 67 | 68 | printLetterCount: ; 函数:打印letter_count(默认为两位数) 69 | pusha 70 | mov ax, [letter_count] 71 | mov bl, 10 72 | div bl ; al = ax/ah, ah = ax%ah 73 | add al, '0' ; 十位数的ASCII 74 | add ah, '0' ; 个位数的ASCII 75 | PUTCHAR al ; 打印十位数 76 | PUTCHAR ah ; 打印个位数 77 | popa 78 | ret 79 | 80 | DataArea: 81 | the_str db '129djwqhdsajd128dw9i39ie93i8494urjoiew98kdkd', 0 82 | letter_count dw 0 ; 用于存放字母个数的全局变量 83 | 84 | welcome db 'This is the `fork_test` user programme.', 0Dh, 0Ah, 0Ah, 0Ah, 0 85 | error_fork db '[-] Error in fork! Press ESC to quit.', 0Dh, 0Ah, 0 86 | parent_say db '[+] Parent process entered.', 0Dh, 0Ah, 0 87 | son_say db '[+] Son process entered.', 0Dh, 0Ah, 0 88 | result_1 db 0Dh, 0Ah, 'The string is: ', 0 89 | result_2 db 0Dh, 0Ah, 'Letter number is: ', 0 90 | finishbye db 0Dh, 0Ah, 0Dh, 0Ah, 91 | db '[+] The fork test is finished! Press ESC to quit.', 0Dh, 0Ah, 0 -------------------------------------------------------------------------------- /项目7_进程控制与通信/src/usrprog/fork_test_c_version.c: -------------------------------------------------------------------------------- 1 | #include "../process.h" 2 | extern void print(char*); 3 | extern void clearScreen(); 4 | extern char* itoa(); 5 | extern int fork(); 6 | extern void wait(); 7 | extern void exit(); 8 | 9 | int letter_count = 0; 10 | char the_str[] = "129djwqhdsajd128dw9i39ie93i8494urjoiew98kdkd"; 11 | 12 | void countLetter() { 13 | char* ptr = the_str; 14 | while(ptr) { 15 | if(*ptr >= 'a' && *ptr <= 'z') { 16 | letter_count += 1; 17 | } 18 | } 19 | } 20 | 21 | void cmain() 22 | { 23 | clearScreen(); 24 | print("This is the `fork_test` user programme.\r\n"); 25 | 26 | int pid = fork(); 27 | 28 | if(pid < 0) { // fork失败 29 | print("[-] Error in fork! Press ESC to quit.\r\n"); 30 | } 31 | else if(pid > 0) { // 父进程 32 | print("[+] Parent process entered.\r\n"); 33 | wait(); 34 | 35 | print("The string is: "); 36 | print(the_str); 37 | print("\r\nLetter number is: "); 38 | print(itoa(letter_count, 10)); 39 | print("\r\n\r\n[+] The fork test is finished! Press ESC to quit.\r\n"); 40 | exit(); 41 | } 42 | else { // 子进程 43 | print("[+] Son process entered.\r\n"); 44 | countLetter(); // 统计字母个数 45 | exit(); 46 | } 47 | } -------------------------------------------------------------------------------- /项目7_进程控制与通信/src/usrprog/fork_test_helper.asm: -------------------------------------------------------------------------------- 1 | BITS 16 2 | %include "../macro.asm" 3 | [global _start] 4 | 5 | _start: 6 | mov ax, 0003h 7 | int 10h ; 清屏 8 | PRINTLN welcome ; 打印欢迎信息 9 | 10 | int 22h ; 调用fork(),ax=fork的结果 11 | cmp ax, 0 12 | jl ForkFailure 13 | cmp ax, 0 14 | jg ForkParent 15 | cmp ax, 0 16 | je ForkSon 17 | 18 | jmp QuitUsrProg 19 | 20 | 21 | ForkFailure: 22 | PRINTLN error_fork 23 | jmp QuitUsrProg 24 | 25 | ForkParent: ; 父进程 26 | PRINTLN parent_say 27 | int 23h ; 调用wait() 28 | 29 | PRINTLN finishbye 30 | int 24h ; 调用exit() 31 | 32 | jmp QuitUsrProg 33 | 34 | ForkSon: ; 子进程 35 | PRINTLN son_say 36 | call countLetter 37 | int 24h ; 调用exit() 38 | jmp QuitUsrProg 39 | 40 | 41 | QuitUsrProg: 42 | jmp $ 43 | 44 | countLetter: 45 | mov word[letter_count], 8 46 | ret 47 | 48 | DataArea: 49 | the_str db '129djwqhdsajd128dw9i39ie93i8494urjoiew98kdkd', 0 50 | letter_count dw 0 51 | 52 | welcome db 'This is the `fork_test` user programme.', 0Dh, 0Ah, 0Ah, 0Ah, 0 53 | finishbye db 0Ah, 'The fork test is finished. Press ESC to quit.', 0Dh, 0Ah, 0 54 | parent_say db 'This is PARENT', 0Dh, 0Ah, 0 55 | son_say db 'This is SON', 0Dh, 0Ah, 0 56 | error_fork db '[-] Error in fork!', 0Dh, 0Ah, 0 57 | result_1 db 'Letter number = ', 0 58 | -------------------------------------------------------------------------------- /项目7_进程控制与通信/src/usrprog/interrupt/int33h~36h.asm: -------------------------------------------------------------------------------- 1 | ; @Author: Jed 2 | ; @Description: int 33h/34h/35h/36h的中断处理程序 3 | ; @Date: 2019-03-28 4 | ; @LastEditTime: 2019-04-17 5 | 6 | Int33h~36h: 7 | push ax 8 | push si 9 | push ds 10 | push gs 11 | 12 | mov ax,cs 13 | mov ds,ax ; DS = CS 14 | mov ax,0B800h ; 文本窗口显存起始地址 15 | mov gs,ax ; GS = B800h 16 | mov ax, [start_row] ; ax=start_row 17 | mov ah, 2*80 ; ah=2*80 18 | mul ah ; ax=start_row * 2 * 80 19 | mov si, ax ; si初始化为起始位置指针 20 | disploop: 21 | mov al, [temp_char] ; 要显示的字符 22 | mov [gs:si], al ; 显示字符 23 | inc si ; 递增指针 24 | mov ah, [temp_color] ; 字符颜色属性 25 | mov [gs:si], ah ; 显示颜色属性 26 | inc si ; 递增指针 27 | add byte[temp_color], 11h ; 改变颜色 28 | call Delay ; 延时 29 | 30 | mov ah, 01h ; 功能号:查询键盘缓冲区但不等待 31 | int 16h 32 | jz NoEsc ; 无键盘按下,继续 33 | mov ah, 0 ; 功能号:查询键盘输入 34 | int 16h 35 | cmp al, 27 ; 是否按下ESC 36 | je QuitInt ; 若按下ESC,退出用户程序 37 | NoEsc: 38 | mov ax, [end_row] ; al=end_row,ah实际上无用 39 | mov ah, 2*80 40 | mul ah ; ax=end_row * 2 * 80 41 | add ax, [start_row] ; ax=start_row + end_row*2*80 42 | cmp si, ax 43 | jne disploop ; 范围全部显示完,中断返回 44 | 45 | QuitInt: 46 | pop gs 47 | pop ds 48 | pop si 49 | pop ax 50 | iret ; 中断返回 51 | 52 | Delay: ; 延迟一段时间 53 | push ax 54 | push cx 55 | mov ax, 100 56 | delay_outer: 57 | mov cx, 50000 58 | delay_inner: 59 | loop delay_inner 60 | dec ax 61 | cmp ax, 0 62 | jne delay_outer 63 | pop cx 64 | pop ax 65 | ret 66 | 67 | DataArea: 68 | start_row dw 0 69 | end_row dw 0 70 | temp_color db 0 71 | temp_char db ' ' -------------------------------------------------------------------------------- /项目7_进程控制与通信/src/usrprog/interrupt/intouch.asm: -------------------------------------------------------------------------------- 1 | IntOuch: 2 | pusha 3 | push ds 4 | push es 5 | 6 | mov ax, cs ; 置其他段寄存器值与CS相同 7 | mov ds, ax ; 数据段 8 | mov bp, ouch_msg ; BP=当前串的偏移地址 9 | mov ax, ds ; ES:BP = 串地址 10 | mov es, ax ; 置ES=DS 11 | mov cx, ouch_msg_len ; CX = 串长 12 | mov ax, 1300h ; AH = 13h(功能号)、AL = 01h(光标不动) 13 | mov bx, 0007h ; 页号为0(BH = 0) 黑底白字(BL = 07h) 14 | mov dh, 20 ; 行号=0 15 | mov dl, 40 ; 列号=0 16 | int 10h ; BIOS的10h功能:显示一行字符 17 | 18 | call Delay 19 | 20 | mov ax, cs ; 置其他段寄存器值与CS相同 21 | mov ds, ax ; 数据段 22 | mov bp, ouch_clear ; BP=当前串的偏移地址 23 | mov ax, ds ; ES:BP = 串地址 24 | mov es, ax ; 置ES=DS 25 | mov cx, ouch_msg_len ; CX = 串长 26 | mov ax, 1300h ; AH = 13h(功能号)、AL = 01h(光标不动) 27 | mov bx, 0007h ; 页号为0(BH = 0) 黑底白字(BL = 07h) 28 | mov dh, 20 ; 行号=0 29 | mov dl, 40 ; 列号=0 30 | int 10h ; BIOS的10h功能:显示一行字符 31 | 32 | int 39h ; 原来的BIOS int 09h 33 | 34 | mov al,20h ; AL = EOI 35 | out 20h,al ; 发送EOI到主8529A 36 | out 0A0h,al ; 发送EOI到从8529A 37 | 38 | pop es 39 | pop ds 40 | popa 41 | iret ; 从中断返回 42 | 43 | Delay: ; 延迟一段时间 44 | push ax 45 | push cx 46 | mov ax, 580 47 | delay_outer: 48 | mov cx, 50000 49 | delay_inner: 50 | loop delay_inner 51 | dec ax 52 | cmp ax, 0 53 | jne delay_outer 54 | pop cx 55 | pop ax 56 | ret 57 | 58 | 59 | ouch_msg db 'OUCH! OUCH!' 60 | ouch_msg_len equ $-ouch_msg 61 | ouch_clear db ' ' -------------------------------------------------------------------------------- /项目7_进程控制与通信/src/usrprog/interrupt_caller.asm: -------------------------------------------------------------------------------- 1 | jmp $ -------------------------------------------------------------------------------- /项目7_进程控制与通信/src/usrprog/stone_bottomleft.asm: -------------------------------------------------------------------------------- 1 | ; @Author: Jed 2 | ; @Description: 本程序在显示器左下角进行字符反弹。标准起始点参数为(-1, 11, 40, 25, 0, 19) 3 | ; @Date: 2019-05-06 4 | ; @LastEditTime: 2019-05-06 5 | %include "../macro.asm" 6 | org addr_usrprog3 & 0FFFFh 7 | 8 | Dn_Rt equ 1 ; D-Down,U-Up,R-right,L-Left 9 | Up_Rt equ 2 10 | Up_Lt equ 3 11 | Dn_Lt equ 4 12 | delay equ 50000 ; 计时器延迟计数,用于控制画框的速度 13 | ddelay equ 580 ; 计时器延迟计数,用于控制画框的速度 14 | 15 | screen_left equ -1 ; 字符运动左边界 16 | screen_top equ 11 ; 字符运动上边界 17 | screen_right equ 40 ; 字符运动右边界 18 | screen_bottom equ 25 ; 字符运动下边界 19 | originpos_y equ 35 ; 起点列数 20 | originpos_x equ 19 ; 起点行数 21 | 22 | start: 23 | pusha 24 | push ds 25 | mov ax, 0 26 | mov es, ax 27 | call ClearScreen ; 清屏 28 | mov ax,cs 29 | mov es,ax ; ES = CS 30 | mov ds,ax ; DS = CS 31 | mov es,ax ; ES = CS 32 | mov ax,0B800h 33 | mov gs,ax ; GS = B800h,指向文本模式的显示缓冲区 34 | mov byte[char],'X' 35 | 36 | initialize: ; 多次调用用户程序时,可保证初始值是相同的 37 | mov word[x], originpos_x 38 | mov word[y], originpos_y 39 | mov byte[curcolor], 80h 40 | mov byte[curcolor2], 01h 41 | mov word[count], delay 42 | mov word[dcount], ddelay 43 | mov byte[rdul], Dn_Rt ; 向右下运动 44 | 45 | loop1: 46 | dec word[count] ; 递减计数变量 47 | jnz loop1 ; >0:跳转; 48 | mov word[count],delay 49 | dec word[dcount] ; 递减计数变量 50 | jnz loop1 51 | mov word[count],delay 52 | mov word[dcount],ddelay 53 | 54 | mov al,1 55 | cmp al,byte[rdul] 56 | jz DnRt 57 | mov al,2 58 | cmp al,byte[rdul] 59 | jz UpRt 60 | mov al,3 61 | cmp al,byte[rdul] 62 | jz UpLt 63 | mov al,4 64 | cmp al,byte[rdul] 65 | jz DnLt 66 | 67 | DnRt: 68 | inc word[x] 69 | inc word[y] 70 | mov bx,word[x] 71 | mov ax,screen_bottom 72 | sub ax,bx 73 | jz dr2ur 74 | mov bx,word[y] 75 | mov ax,screen_right 76 | sub ax,bx 77 | jz dr2dl 78 | jmp show 79 | 80 | dr2ur: 81 | mov word[x],screen_bottom-2 82 | mov byte[rdul],Up_Rt 83 | jmp show 84 | 85 | dr2dl: 86 | mov word[y],screen_right-2 87 | mov byte[rdul],Dn_Lt 88 | jmp show 89 | 90 | 91 | UpRt: 92 | dec word[x] 93 | inc word[y] 94 | mov bx,word[y] 95 | mov ax,screen_right 96 | sub ax,bx 97 | jz ur2ul 98 | mov bx,word[x] 99 | mov ax,screen_top 100 | sub ax,bx 101 | jz ur2dr 102 | jmp show 103 | 104 | ur2ul: 105 | mov word[y],screen_right-2 106 | mov byte[rdul],Up_Lt 107 | jmp show 108 | 109 | ur2dr: 110 | mov word[x],screen_top+2 111 | mov byte[rdul],Dn_Rt 112 | jmp show 113 | 114 | 115 | UpLt: 116 | dec word[x] 117 | dec word[y] 118 | mov bx,word[x] 119 | mov ax,screen_top 120 | sub ax,bx 121 | jz ul2dl 122 | mov bx,word[y] 123 | mov ax,screen_left 124 | sub ax,bx 125 | jz ul2ur 126 | jmp show 127 | 128 | ul2dl: 129 | mov word[x],screen_top+2 130 | mov byte[rdul],Dn_Lt 131 | jmp show 132 | ul2ur: 133 | mov word[y],screen_left+2 134 | mov byte[rdul],Up_Rt 135 | jmp show 136 | 137 | DnLt: 138 | inc word[x] 139 | dec word[y] 140 | mov bx,word[y] 141 | mov ax,screen_left 142 | sub ax,bx 143 | jz dl2dr 144 | mov bx,word[x] 145 | mov ax,screen_bottom 146 | sub ax,bx 147 | jz dl2ul 148 | jmp show 149 | 150 | dl2dr: 151 | mov word[y],screen_left+2 152 | mov byte[rdul],Dn_Rt 153 | jmp show 154 | 155 | dl2ul: 156 | mov word[x],screen_bottom-2 157 | mov byte[rdul],Up_Lt 158 | jmp show 159 | 160 | show: 161 | xor ax,ax ; 计算显存地址 162 | mov ax,word[x] 163 | mov bx,80 164 | mul bx 165 | add ax,word[y] 166 | mov bx,2 167 | mul bx 168 | mov bp,ax 169 | mov ah,[curcolor2] ; 弹字符的背景色和前景色(默认值为07h,详见文档) 170 | inc byte[curcolor2] 171 | cmp byte[curcolor2], 0fh 172 | jnz skip 173 | mov byte[curcolor2], 1 ; 为了不改变背景色 174 | skip: 175 | mov al,byte[char] ; AL = 显示字符值(默认值为20h=空格符) 176 | mov word[gs:bp],ax ; 显示字符的ASCII码值 177 | 178 | mov ah, 06h ; 功能号:获取timer_flag 179 | int 21h ;ax=timer_flag 180 | cmp ax, 0 181 | jne continue ; 如果已设置timer_flag,则不进行键盘判断 182 | mov ah, 01h ; 功能号:查询键盘缓冲区但不等待 183 | int 16h 184 | jz continue ; 无键盘按下,继续 185 | mov ah, 0 ; 功能号:查询键盘输入 186 | int 16h 187 | cmp al, 27 ; 是否按下ESC 188 | je QuitUsrProg ; 若按下ESC,退出用户程序 189 | 190 | continue: 191 | jmp loop1 192 | 193 | end: 194 | jmp $ ; 停止画框,无限循环 195 | 196 | QuitUsrProg: 197 | ; MOVE_INT_VECTOR 39h, 09h 198 | pop ds 199 | popa 200 | retf 201 | 202 | ClearScreen: ; 函数:清屏 203 | pusha 204 | mov ax, 0003h 205 | int 10h ; 中断调用,清屏 206 | popa 207 | ret 208 | 209 | DataArea: 210 | count dw delay 211 | dcount dw ddelay 212 | rdul db Dn_Rt ; 向右下运动 213 | char db 0 214 | 215 | x dw originpos_x 216 | y dw originpos_y 217 | 218 | curcolor db 80h ; 保存当前字符颜色属性,用于myinfo 219 | curcolor2 db 01h ; 保存当前字符颜色属性,用于移动的字符 -------------------------------------------------------------------------------- /项目7_进程控制与通信/src/usrprog/stone_bottomright.asm: -------------------------------------------------------------------------------- 1 | ; @Author: Jed 2 | ; @Description: 本程序在显示器右下角进行字符反弹。标准起始点参数为(39, 11, 80, 25, 40, 19) 3 | ; @Date: 2019-05-06 4 | ; @LastEditTime: 2019-05-06 5 | %include "../macro.asm" 6 | org addr_usrprog4 & 0FFFFh 7 | 8 | Dn_Rt equ 1 ; D-Down,U-Up,R-right,L-Left 9 | Up_Rt equ 2 10 | Up_Lt equ 3 11 | Dn_Lt equ 4 12 | delay equ 50000 ; 计时器延迟计数,用于控制画框的速度 13 | ddelay equ 580 ; 计时器延迟计数,用于控制画框的速度 14 | 15 | screen_left equ 39 ; 字符运动左边界 16 | screen_top equ 11 ; 字符运动上边界 17 | screen_right equ 80 ; 字符运动右边界 18 | screen_bottom equ 25 ; 字符运动下边界 19 | originpos_y equ 40 ; 起点列数 20 | originpos_x equ 19 ; 起点行数 21 | 22 | start: 23 | pusha 24 | push ds 25 | mov ax, 0 26 | mov es, ax 27 | call ClearScreen ; 清屏 28 | mov ax,cs 29 | mov es,ax ; ES = CS 30 | mov ds,ax ; DS = CS 31 | mov es,ax ; ES = CS 32 | mov ax,0B800h 33 | mov gs,ax ; GS = B800h,指向文本模式的显示缓冲区 34 | mov byte[char],'X' 35 | 36 | initialize: ; 多次调用用户程序时,可保证初始值是相同的 37 | mov word[x], originpos_x 38 | mov word[y], originpos_y 39 | mov byte[curcolor], 80h 40 | mov byte[curcolor2], 01h 41 | mov word[count], delay 42 | mov word[dcount], ddelay 43 | mov byte[rdul], Dn_Rt ; 向右下运动 44 | 45 | loop1: 46 | dec word[count] ; 递减计数变量 47 | jnz loop1 ; >0:跳转; 48 | mov word[count],delay 49 | dec word[dcount] ; 递减计数变量 50 | jnz loop1 51 | mov word[count],delay 52 | mov word[dcount],ddelay 53 | 54 | mov al,1 55 | cmp al,byte[rdul] 56 | jz DnRt 57 | mov al,2 58 | cmp al,byte[rdul] 59 | jz UpRt 60 | mov al,3 61 | cmp al,byte[rdul] 62 | jz UpLt 63 | mov al,4 64 | cmp al,byte[rdul] 65 | jz DnLt 66 | 67 | DnRt: 68 | inc word[x] 69 | inc word[y] 70 | mov bx,word[x] 71 | mov ax,screen_bottom 72 | sub ax,bx 73 | jz dr2ur 74 | mov bx,word[y] 75 | mov ax,screen_right 76 | sub ax,bx 77 | jz dr2dl 78 | jmp show 79 | 80 | dr2ur: 81 | mov word[x],screen_bottom-2 82 | mov byte[rdul],Up_Rt 83 | jmp show 84 | 85 | dr2dl: 86 | mov word[y],screen_right-2 87 | mov byte[rdul],Dn_Lt 88 | jmp show 89 | 90 | 91 | UpRt: 92 | dec word[x] 93 | inc word[y] 94 | mov bx,word[y] 95 | mov ax,screen_right 96 | sub ax,bx 97 | jz ur2ul 98 | mov bx,word[x] 99 | mov ax,screen_top 100 | sub ax,bx 101 | jz ur2dr 102 | jmp show 103 | 104 | ur2ul: 105 | mov word[y],screen_right-2 106 | mov byte[rdul],Up_Lt 107 | jmp show 108 | 109 | ur2dr: 110 | mov word[x],screen_top+2 111 | mov byte[rdul],Dn_Rt 112 | jmp show 113 | 114 | 115 | UpLt: 116 | dec word[x] 117 | dec word[y] 118 | mov bx,word[x] 119 | mov ax,screen_top 120 | sub ax,bx 121 | jz ul2dl 122 | mov bx,word[y] 123 | mov ax,screen_left 124 | sub ax,bx 125 | jz ul2ur 126 | jmp show 127 | 128 | ul2dl: 129 | mov word[x],screen_top+2 130 | mov byte[rdul],Dn_Lt 131 | jmp show 132 | ul2ur: 133 | mov word[y],screen_left+2 134 | mov byte[rdul],Up_Rt 135 | jmp show 136 | 137 | DnLt: 138 | inc word[x] 139 | dec word[y] 140 | mov bx,word[y] 141 | mov ax,screen_left 142 | sub ax,bx 143 | jz dl2dr 144 | mov bx,word[x] 145 | mov ax,screen_bottom 146 | sub ax,bx 147 | jz dl2ul 148 | jmp show 149 | 150 | dl2dr: 151 | mov word[y],screen_left+2 152 | mov byte[rdul],Dn_Rt 153 | jmp show 154 | 155 | dl2ul: 156 | mov word[x],screen_bottom-2 157 | mov byte[rdul],Up_Lt 158 | jmp show 159 | 160 | show: 161 | xor ax,ax ; 计算显存地址 162 | mov ax,word[x] 163 | mov bx,80 164 | mul bx 165 | add ax,word[y] 166 | mov bx,2 167 | mul bx 168 | mov bp,ax 169 | mov ah,[curcolor2] ; 弹字符的背景色和前景色(默认值为07h,详见文档) 170 | inc byte[curcolor2] 171 | cmp byte[curcolor2], 0fh 172 | jnz skip 173 | mov byte[curcolor2], 1 ; 为了不改变背景色 174 | skip: 175 | mov al,byte[char] ; AL = 显示字符值(默认值为20h=空格符) 176 | mov word[gs:bp],ax ; 显示字符的ASCII码值 177 | 178 | mov ah, 06h ; 功能号:获取timer_flag 179 | int 21h ;ax=timer_flag 180 | cmp ax, 0 181 | jne continue ; 如果已设置timer_flag,则不进行键盘判断 182 | mov ah, 01h ; 功能号:查询键盘缓冲区但不等待 183 | int 16h 184 | jz continue ; 无键盘按下,继续 185 | mov ah, 0 ; 功能号:查询键盘输入 186 | int 16h 187 | cmp al, 27 ; 是否按下ESC 188 | je QuitUsrProg ; 若按下ESC,退出用户程序 189 | 190 | continue: 191 | jmp loop1 192 | 193 | end: 194 | jmp $ ; 停止画框,无限循环 195 | 196 | QuitUsrProg: 197 | ; MOVE_INT_VECTOR 39h, 09h 198 | pop ds 199 | popa 200 | retf 201 | 202 | ClearScreen: ; 函数:清屏 203 | pusha 204 | mov ax, 0003h 205 | int 10h ; 中断调用,清屏 206 | popa 207 | ret 208 | 209 | DataArea: 210 | count dw delay 211 | dcount dw ddelay 212 | rdul db Dn_Rt ; 向右下运动 213 | char db 0 214 | 215 | x dw originpos_x 216 | y dw originpos_y 217 | 218 | curcolor db 80h ; 保存当前字符颜色属性,用于myinfo 219 | curcolor2 db 01h ; 保存当前字符颜色属性,用于移动的字符 -------------------------------------------------------------------------------- /项目7_进程控制与通信/src/usrprog/stone_topleft.asm: -------------------------------------------------------------------------------- 1 | ; @Author: Jed 2 | ; @Description: 本程序在显示器左上角进行字符反弹。标准起始点参数为(-1, -1, 40, 13, 0, 7) 3 | ; @Date: 2019-05-06 4 | ; @LastEditTime: 2019-05-06 5 | %include "../macro.asm" 6 | org addr_usrprog2 & 0FFFFh 7 | 8 | Dn_Rt equ 1 ; D-Down,U-Up,R-right,L-Left 9 | Up_Rt equ 2 10 | Up_Lt equ 3 11 | Dn_Lt equ 4 12 | delay equ 50000 ; 计时器延迟计数,用于控制画框的速度 13 | ddelay equ 580 ; 计时器延迟计数,用于控制画框的速度 14 | 15 | screen_left equ -1 ; 字符运动左边界 16 | screen_top equ -1 ; 字符运动上边界 17 | screen_right equ 40 ; 字符运动右边界 18 | screen_bottom equ 13 ; 字符运动下边界 19 | originpos_y equ 4 ; 起点列数 20 | originpos_x equ 11 ; 起点行数 21 | 22 | start: 23 | pusha 24 | push ds 25 | mov ax, 0 26 | mov es, ax 27 | call ClearScreen ; 清屏 28 | mov ax,cs 29 | mov es,ax ; ES = CS 30 | mov ds,ax ; DS = CS 31 | mov es,ax ; ES = CS 32 | mov ax,0B800h 33 | mov gs,ax ; GS = B800h,指向文本模式的显示缓冲区 34 | mov byte[char],'X' 35 | 36 | initialize: ; 多次调用用户程序时,可保证初始值是相同的 37 | mov word[x], originpos_x 38 | mov word[y], originpos_y 39 | mov byte[curcolor], 80h 40 | mov byte[curcolor2], 01h 41 | mov word[count], delay 42 | mov word[dcount], ddelay 43 | mov byte[rdul], Dn_Rt ; 向右下运动 44 | 45 | loop1: 46 | dec word[count] ; 递减计数变量 47 | jnz loop1 ; >0:跳转; 48 | mov word[count],delay 49 | dec word[dcount] ; 递减计数变量 50 | jnz loop1 51 | mov word[count],delay 52 | mov word[dcount],ddelay 53 | 54 | mov al,1 55 | cmp al,byte[rdul] 56 | jz DnRt 57 | mov al,2 58 | cmp al,byte[rdul] 59 | jz UpRt 60 | mov al,3 61 | cmp al,byte[rdul] 62 | jz UpLt 63 | mov al,4 64 | cmp al,byte[rdul] 65 | jz DnLt 66 | 67 | DnRt: 68 | inc word[x] 69 | inc word[y] 70 | mov bx,word[x] 71 | mov ax,screen_bottom 72 | sub ax,bx 73 | jz dr2ur 74 | mov bx,word[y] 75 | mov ax,screen_right 76 | sub ax,bx 77 | jz dr2dl 78 | jmp show 79 | 80 | dr2ur: 81 | mov word[x],screen_bottom-2 82 | mov byte[rdul],Up_Rt 83 | jmp show 84 | 85 | dr2dl: 86 | mov word[y],screen_right-2 87 | mov byte[rdul],Dn_Lt 88 | jmp show 89 | 90 | 91 | UpRt: 92 | dec word[x] 93 | inc word[y] 94 | mov bx,word[y] 95 | mov ax,screen_right 96 | sub ax,bx 97 | jz ur2ul 98 | mov bx,word[x] 99 | mov ax,screen_top 100 | sub ax,bx 101 | jz ur2dr 102 | jmp show 103 | 104 | ur2ul: 105 | mov word[y],screen_right-2 106 | mov byte[rdul],Up_Lt 107 | jmp show 108 | 109 | ur2dr: 110 | mov word[x],screen_top+2 111 | mov byte[rdul],Dn_Rt 112 | jmp show 113 | 114 | 115 | UpLt: 116 | dec word[x] 117 | dec word[y] 118 | mov bx,word[x] 119 | mov ax,screen_top 120 | sub ax,bx 121 | jz ul2dl 122 | mov bx,word[y] 123 | mov ax,screen_left 124 | sub ax,bx 125 | jz ul2ur 126 | jmp show 127 | 128 | ul2dl: 129 | mov word[x],screen_top+2 130 | mov byte[rdul],Dn_Lt 131 | jmp show 132 | ul2ur: 133 | mov word[y],screen_left+2 134 | mov byte[rdul],Up_Rt 135 | jmp show 136 | 137 | DnLt: 138 | inc word[x] 139 | dec word[y] 140 | mov bx,word[y] 141 | mov ax,screen_left 142 | sub ax,bx 143 | jz dl2dr 144 | mov bx,word[x] 145 | mov ax,screen_bottom 146 | sub ax,bx 147 | jz dl2ul 148 | jmp show 149 | 150 | dl2dr: 151 | mov word[y],screen_left+2 152 | mov byte[rdul],Dn_Rt 153 | jmp show 154 | 155 | dl2ul: 156 | mov word[x],screen_bottom-2 157 | mov byte[rdul],Up_Lt 158 | jmp show 159 | 160 | show: 161 | xor ax,ax ; 计算显存地址 162 | mov ax,word[x] 163 | mov bx,80 164 | mul bx 165 | add ax,word[y] 166 | mov bx,2 167 | mul bx 168 | mov bp,ax 169 | mov ah,[curcolor2] ; 弹字符的背景色和前景色(默认值为07h,详见文档) 170 | inc byte[curcolor2] 171 | cmp byte[curcolor2], 0fh 172 | jnz skip 173 | mov byte[curcolor2], 1 ; 为了不改变背景色 174 | skip: 175 | mov al,byte[char] ; AL = 显示字符值(默认值为20h=空格符) 176 | mov word[gs:bp],ax ; 显示字符的ASCII码值 177 | 178 | mov ah, 06h ; 功能号:获取timer_flag 179 | int 21h ; ax=timer_flag 180 | cmp ax, 0 181 | jne continue ; 如果已设置timer_flag,则不进行键盘判断 182 | mov ah, 01h ; 功能号:查询键盘缓冲区但不等待 183 | int 16h 184 | jz continue ; 无键盘按下,继续 185 | mov ah, 0 ; 功能号:查询键盘输入 186 | int 16h 187 | cmp al, 27 ; 是否按下ESC 188 | je QuitUsrProg ; 若按下ESC,退出用户程序 189 | 190 | continue: 191 | jmp loop1 192 | 193 | QuitUsrProg: 194 | pop ds 195 | popa 196 | retf 197 | 198 | ClearScreen: ; 函数:清屏 199 | pusha 200 | mov ax, 0003h 201 | int 10h ; 中断调用,清屏 202 | popa 203 | ret 204 | 205 | DataArea: 206 | count dw delay 207 | dcount dw ddelay 208 | rdul db Dn_Rt ; 向右下运动 209 | char db 0 210 | 211 | x dw originpos_x 212 | y dw originpos_y 213 | 214 | curcolor db 80h ; 保存当前字符颜色属性,用于myinfo 215 | curcolor2 db 01h ; 保存当前字符颜色属性,用于移动的字符 -------------------------------------------------------------------------------- /项目7_进程控制与通信/src/usrprog/stone_topright.asm: -------------------------------------------------------------------------------- 1 | ; @Author: Jed 2 | ; @Description: 本程序在显示器右上角进行字符反弹。标准起始点参数为(39, -1, 80, 13, 40, 7) 3 | ; @Date: 2019-05-06 4 | ; @LastEditTime: 2019-05-06 5 | %include "../macro.asm" 6 | org addr_usrprog2 & 0FFFFh 7 | 8 | Dn_Rt equ 1 ; D-Down,U-Up,R-right,L-Left 9 | Up_Rt equ 2 10 | Up_Lt equ 3 11 | Dn_Lt equ 4 12 | delay equ 50000 ; 计时器延迟计数,用于控制画框的速度 13 | ddelay equ 580 ; 计时器延迟计数,用于控制画框的速度 14 | 15 | screen_left equ 39 ; 字符运动左边界 16 | screen_top equ -1 ; 字符运动上边界 17 | screen_right equ 80 ; 字符运动右边界 18 | screen_bottom equ 13 ; 字符运动下边界 19 | originpos_y equ 45 ; 起点列数 20 | originpos_x equ 0 ; 起点行数 21 | 22 | start: 23 | pusha 24 | push ds 25 | mov ax, 0 26 | mov es, ax 27 | call ClearScreen ; 清屏 28 | mov ax,cs 29 | mov es,ax ; ES = CS 30 | mov ds,ax ; DS = CS 31 | mov es,ax ; ES = CS 32 | mov ax,0B800h 33 | mov gs,ax ; GS = B800h,指向文本模式的显示缓冲区 34 | mov byte[char],'X' 35 | 36 | initialize: ; 多次调用用户程序时,可保证初始值是相同的 37 | mov word[x], originpos_x 38 | mov word[y], originpos_y 39 | mov byte[curcolor], 80h 40 | mov byte[curcolor2], 01h 41 | mov word[count], delay 42 | mov word[dcount], ddelay 43 | mov byte[rdul], Dn_Rt ; 向右下运动 44 | 45 | loop1: 46 | dec word[count] ; 递减计数变量 47 | jnz loop1 ; >0:跳转; 48 | mov word[count],delay 49 | dec word[dcount] ; 递减计数变量 50 | jnz loop1 51 | mov word[count],delay 52 | mov word[dcount],ddelay 53 | 54 | mov al,1 55 | cmp al,byte[rdul] 56 | jz DnRt 57 | mov al,2 58 | cmp al,byte[rdul] 59 | jz UpRt 60 | mov al,3 61 | cmp al,byte[rdul] 62 | jz UpLt 63 | mov al,4 64 | cmp al,byte[rdul] 65 | jz DnLt 66 | 67 | DnRt: 68 | inc word[x] 69 | inc word[y] 70 | mov bx,word[x] 71 | mov ax,screen_bottom 72 | sub ax,bx 73 | jz dr2ur 74 | mov bx,word[y] 75 | mov ax,screen_right 76 | sub ax,bx 77 | jz dr2dl 78 | jmp show 79 | 80 | dr2ur: 81 | mov word[x],screen_bottom-2 82 | mov byte[rdul],Up_Rt 83 | jmp show 84 | 85 | dr2dl: 86 | mov word[y],screen_right-2 87 | mov byte[rdul],Dn_Lt 88 | jmp show 89 | 90 | 91 | UpRt: 92 | dec word[x] 93 | inc word[y] 94 | mov bx,word[y] 95 | mov ax,screen_right 96 | sub ax,bx 97 | jz ur2ul 98 | mov bx,word[x] 99 | mov ax,screen_top 100 | sub ax,bx 101 | jz ur2dr 102 | jmp show 103 | 104 | ur2ul: 105 | mov word[y],screen_right-2 106 | mov byte[rdul],Up_Lt 107 | jmp show 108 | 109 | ur2dr: 110 | mov word[x],screen_top+2 111 | mov byte[rdul],Dn_Rt 112 | jmp show 113 | 114 | 115 | UpLt: 116 | dec word[x] 117 | dec word[y] 118 | mov bx,word[x] 119 | mov ax,screen_top 120 | sub ax,bx 121 | jz ul2dl 122 | mov bx,word[y] 123 | mov ax,screen_left 124 | sub ax,bx 125 | jz ul2ur 126 | jmp show 127 | 128 | ul2dl: 129 | mov word[x],screen_top+2 130 | mov byte[rdul],Dn_Lt 131 | jmp show 132 | ul2ur: 133 | mov word[y],screen_left+2 134 | mov byte[rdul],Up_Rt 135 | jmp show 136 | 137 | DnLt: 138 | inc word[x] 139 | dec word[y] 140 | mov bx,word[y] 141 | mov ax,screen_left 142 | sub ax,bx 143 | jz dl2dr 144 | mov bx,word[x] 145 | mov ax,screen_bottom 146 | sub ax,bx 147 | jz dl2ul 148 | jmp show 149 | 150 | dl2dr: 151 | mov word[y],screen_left+2 152 | mov byte[rdul],Dn_Rt 153 | jmp show 154 | 155 | dl2ul: 156 | mov word[x],screen_bottom-2 157 | mov byte[rdul],Up_Lt 158 | jmp show 159 | 160 | show: 161 | xor ax,ax ; 计算显存地址 162 | mov ax,word[x] 163 | mov bx,80 164 | mul bx 165 | add ax,word[y] 166 | mov bx,2 167 | mul bx 168 | mov bp,ax 169 | mov ah,[curcolor2] ; 弹字符的背景色和前景色(默认值为07h,详见文档) 170 | inc byte[curcolor2] 171 | cmp byte[curcolor2], 0fh 172 | jnz skip 173 | mov byte[curcolor2], 1 ; 为了不改变背景色 174 | skip: 175 | mov al,byte[char] ; AL = 显示字符值(默认值为20h=空格符) 176 | mov word[gs:bp],ax ; 显示字符的ASCII码值 177 | 178 | mov ah, 06h ; 功能号:获取timer_flag 179 | int 21h ;ax=timer_flag 180 | cmp ax, 0 181 | jne continue ; 如果已设置timer_flag,则不进行键盘判断 182 | mov ah, 01h ; 功能号:查询键盘缓冲区但不等待 183 | int 16h 184 | jz continue ; 无键盘按下,继续 185 | mov ah, 0 ; 功能号:查询键盘输入 186 | int 16h 187 | cmp al, 27 ; 是否按下ESC 188 | je QuitUsrProg ; 若按下ESC,退出用户程序 189 | 190 | continue: 191 | jmp loop1 192 | 193 | QuitUsrProg: 194 | pop ds 195 | popa 196 | retf 197 | 198 | ClearScreen: ; 函数:清屏 199 | pusha 200 | mov ax, 0003h 201 | int 10h ; 中断调用,清屏 202 | popa 203 | ret 204 | 205 | DataArea: 206 | count dw delay 207 | dcount dw ddelay 208 | rdul db Dn_Rt ; 向右下运动 209 | char db 0 210 | 211 | x dw originpos_x 212 | y dw originpos_y 213 | 214 | curcolor db 80h ; 保存当前字符颜色属性,用于myinfo 215 | curcolor2 db 01h ; 保存当前字符颜色属性,用于移动的字符 -------------------------------------------------------------------------------- /项目7_进程控制与通信/src/usrprog/syscall_test.asm: -------------------------------------------------------------------------------- 1 | ; @Author: Jed 2 | ; @Description: 测试系统调用的用户程序 3 | ; @Date: 2019-04-17 4 | ; @LastEditTime: 2019-04-19 5 | 6 | %include "../macro.asm" 7 | org addr_syscalltest 8 | 9 | Start: 10 | pusha 11 | push es 12 | 13 | mov ax, 0003h 14 | int 10h ; 清屏 15 | 16 | PRINT_IN_POS hint_all, hint_all_len, 0, 0 17 | mov ah, 0 18 | int 16h 19 | cmp al, 27 ; 按下ESC 20 | je QuitUsrProg ; 直接退出 21 | 22 | PRINT_IN_POS hint0, hint_len, 2, 0 23 | mov ah, 00h ; 系统调用功能号ah=00h,显示OUCH 24 | int 21h 25 | mov ah, 0 26 | int 16h 27 | cmp al, 27 ; 按下ESC 28 | je QuitUsrProg ; 直接退出 29 | 30 | PRINT_IN_POS hint1, hint_len, 2, 0 31 | mov ax, cs 32 | mov es, ax ; es=cs 33 | mov dx, upper_lower ; es:dx=串地址 34 | PRINT_IN_POS upper_lower, 14, 3, 0 35 | mov ah, 01h ; 系统调用功能号ah=01h,大写转小写 36 | int 21h 37 | PRINT_IN_POS upper_lower, 14, 4, 0 38 | mov ah, 0 39 | int 16h 40 | cmp al, 27 ; 按下ESC 41 | je QuitUsrProg ; 直接退出 42 | 43 | PRINT_IN_POS hint2, hint_len, 2, 0 44 | mov ax, cs 45 | mov es, ax ; es=cs 46 | mov dx, upper_lower ; es:dx=串地址 47 | mov ah, 02h ; 系统调用功能号ah=02h,小写转大写 48 | int 21h 49 | PRINT_IN_POS upper_lower, 14, 5, 0 50 | mov ah, 0 51 | int 16h 52 | cmp al, 27 ; 按下ESC 53 | je QuitUsrProg ; 直接退出 54 | 55 | PRINT_IN_POS hint3, hint_len, 2, 0 56 | mov ax, cs 57 | mov es, ax ; es=cs 58 | mov dx, number_buf 59 | mov ah, 03h ; 系统调用功能号ah=03h,atoi 60 | int 21h ; ax=数值 61 | mov bx, 1 62 | add bx, ax ; bx=ax+1,然后使用下一个系统调用来检查其结果 63 | mov ah, 0 64 | int 16h 65 | cmp al, 27 ; 按下ESC 66 | je QuitUsrProg ; 直接退出 67 | 68 | PRINT_IN_POS hint4, hint_len, 2, 0 69 | mov ax, cs 70 | mov es, ax ; es=cs 71 | mov dx, number_buf 72 | mov ah, 04h ; 系统调用功能号ah=04h,itoa 73 | int 21h ; es:dx=转换后的数字字符串 74 | mov ch, 6 75 | mov cl, 0 76 | mov ah, 05h 77 | int 21h 78 | 79 | mov ah, 0 80 | int 16h 81 | cmp al, 27 ; 按下ESC 82 | je QuitUsrProg ; 直接退出 83 | 84 | PRINT_IN_POS hint5, hint_len, 2, 0 85 | mov ax, cs 86 | mov es, ax ; es=cs 87 | mov dx, test_message1 ; es:dx=串地址 88 | mov ch, 19 ; 行号 89 | mov cl, 0 ; 列号 90 | mov ah, 05h ; 系统调用功能号ah=05h 91 | int 21h ; 显示第一条字符串 92 | mov dx, test_message2 93 | mov ch, 20 94 | mov cl, 0 95 | int 21h ; 显示第二条字符串 96 | mov ah, 0 97 | int 16h 98 | cmp al, 27 ; 按下ESC 99 | je QuitUsrProg ; 直接退出 100 | QuitUsrProg: 101 | pop es 102 | popa 103 | retf 104 | 105 | DataArea: 106 | hint_all db 'Welcome to syscall_test program, where there are several tests of system call. See the document for more details.' 107 | hint_all_len equ $-hint_all 108 | 109 | hint0 db 'Test of ah=00h is running. press ENTER to continue, or ESC to quit.' 110 | hint1 db 'Test of ah=01h is running. press ENTER to continue, or ESC to quit.' 111 | hint2 db 'Test of ah=02h is running. press ENTER to continue, or ESC to quit.' 112 | hint3 db 'Test of ah=03h is running. press ENTER to continue, or ESC to quit.' 113 | hint4 db 'Test of ah=04h is running. press ENTER to continue, or ESC to quit.' 114 | hint5 db 'Test of ah=05h is running. press ENTER to continue, or ESC to quit.' 115 | hint_len equ ($-hint5) 116 | 117 | upper_lower db 'AbCdEfGhIjKlMn', 0 ; 字符串以'\0'结尾 118 | 119 | number_buf db '12345', 0 ; 字符串以'\0'结尾 120 | test_message1 db 'This is a test message,' 121 | test_message2 db 'printed using `ah=05h` and `int 21h`.' -------------------------------------------------------------------------------- /项目7_进程控制与通信/src/usrproginfo.asm: -------------------------------------------------------------------------------- 1 | ; @Author: Jed 2 | ; @Description: 用户车呢光绪信息表。放在软盘第2个扇区。 3 | ; @Date: 2019-03-29 4 | ; @LastEditTime: 2019-06-06 5 | 6 | %include "macro.asm" 7 | %macro UsrProgInfoBlock 8 ; 参数:(ProgID,程序名,字节数,柱面,磁头,扇区,内存地址) 8 | progid%1 db %1 ; 程序编号ProgID;相对偏移0 9 | name%1 db %2 ; 程序名(至多32字节);相对偏移1 10 | times 16-($-name%1) db 0 ; 程序名占6字节 11 | size%1 dw %3 ; 程序大小;相对偏移17 12 | cylinder%1 db %4 ; 柱面;相对偏移19 13 | head%1 db %5 ; 磁头;相对偏移20 14 | sector%1 db %6 ; 扇区;相对偏移21 15 | addr_seg%1 dw %7 ; 内存地址段值;相对偏移22 16 | addr_off%1 dw %8 ; 内存地址偏移量;相对偏移24 17 | %endmacro ; 共26个字节 18 | 19 | UsrProgNumber: ; 用户程序数量 20 | db (SectorEnding-UserProgInfo) / 24 21 | 22 | UserProgInfo: 23 | UsrProgInfoBlock 1, 'stone_topleft', 1024, 1, 0, 1, addr_usrprog1 >> 4 & 0F000h, addr_usrprog1 & 0FFFFh 24 | UsrProgInfoBlock 2, 'stone_topright', 1024, 1, 0, 3, addr_usrprog2 >> 4 & 0F000h, addr_usrprog2 & 0FFFFh 25 | UsrProgInfoBlock 3, 'stone_botleft', 1024, 1, 0, 5, addr_usrprog3 >> 4 & 0F000h, addr_usrprog3 & 0FFFFh 26 | UsrProgInfoBlock 4, 'stone_botright', 1024, 1, 0, 7, addr_usrprog4 >> 4 & 0F000h, addr_usrprog4 & 0FFFFh 27 | UsrProgInfoBlock 5, 'interrupt_caller', 512, 1, 0, 9, addr_intcaller >> 4 & 0F000h, addr_intcaller & 0FFFFh 28 | ; UsrProgInfoBlock 6, 'syscall_test', 1536, 1, 0, 10, addr_syscalltest >> 4 & 0F000h, addr_syscalltest & 0FFFFh 29 | UsrProgInfoBlock 6, 'fork_test', 1024, 1, 0, 13, addr_forktest >> 4 & 0F000h, addr_forktest & 0FFFFh 30 | 31 | SectorEnding: 32 | times 512-($-$$) db 0 --------------------------------------------------------------------------------