-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
390 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
# XYZ OS | ||
|
||
本仓库负责存储郑州轻工业大学计算机学院操作系统课程设计代码 | ||
|
||
| day1 | 已完成 2023-5-28 | | | ||
| 日期 | 进度 | 备注 | | ||
| ---- | ---------------- | ---- | | ||
| day1 | 已完成 2023-5-28 | | | ||
| day2 | 已完成 2023-5-28 | | | ||
| day3 | 未完成 | | | ||
| day3 | 已完成 2023-5-28 | | | ||
| day4 | 未完成 | | | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
TOOLPATH = ../z_tools/ | ||
INCPATH = ../z_tools/haribote/ | ||
|
||
MAKE = $(TOOLPATH)make.exe -r | ||
NASK = $(TOOLPATH)nask.exe | ||
CC1 = $(TOOLPATH)cc1.exe -I$(INCPATH) -Os -Wall -quiet | ||
GAS2NASK = $(TOOLPATH)gas2nask.exe -a | ||
OBJ2BIM = $(TOOLPATH)obj2bim.exe | ||
BIM2HRB = $(TOOLPATH)bim2hrb.exe | ||
RULEFILE = $(TOOLPATH)haribote/haribote.rul | ||
EDIMG = $(TOOLPATH)edimg.exe | ||
IMGTOL = $(TOOLPATH)imgtol.com | ||
COPY = copy | ||
DEL = del | ||
|
||
# 默认动作 | ||
|
||
default : | ||
$(MAKE) run | ||
|
||
# 镜像文件生成 | ||
|
||
ipl10.bin : ipl10.nas Makefile | ||
$(NASK) ipl10.nas ipl10.bin ipl10.lst | ||
|
||
asmhead.bin : asmhead.nas Makefile | ||
$(NASK) asmhead.nas asmhead.bin asmhead.lst | ||
|
||
bootpack.gas : bootpack.c Makefile | ||
$(CC1) -o bootpack.gas bootpack.c | ||
|
||
bootpack.nas : bootpack.gas Makefile | ||
$(GAS2NASK) bootpack.gas bootpack.nas | ||
|
||
bootpack.obj : bootpack.nas Makefile | ||
$(NASK) bootpack.nas bootpack.obj bootpack.lst | ||
|
||
naskfunc.obj : naskfunc.nas Makefile | ||
$(NASK) naskfunc.nas naskfunc.obj naskfunc.lst | ||
|
||
bootpack.bim : bootpack.obj naskfunc.obj Makefile | ||
$(OBJ2BIM) @$(RULEFILE) out:bootpack.bim stack:3136k map:bootpack.map \ | ||
bootpack.obj naskfunc.obj | ||
# 3MB+64KB=3136KB | ||
|
||
bootpack.hrb : bootpack.bim Makefile | ||
$(BIM2HRB) bootpack.bim bootpack.hrb 0 | ||
|
||
haribote.sys : asmhead.bin bootpack.hrb Makefile | ||
copy /B asmhead.bin+bootpack.hrb haribote.sys | ||
|
||
haribote.img : ipl10.bin haribote.sys Makefile | ||
$(EDIMG) imgin:../z_tools/fdimg0at.tek \ | ||
wbinimg src:ipl10.bin len:512 from:0 to:0 \ | ||
copy from:haribote.sys to:@: \ | ||
imgout:haribote.img | ||
|
||
# 其他指令 | ||
|
||
img : | ||
$(MAKE) haribote.img | ||
|
||
run : | ||
$(MAKE) img | ||
$(COPY) haribote.img ..\z_tools\qemu\fdimage0.bin | ||
$(MAKE) -C ../z_tools/qemu | ||
|
||
install : | ||
$(MAKE) img | ||
$(IMGTOL) w a: haribote.img | ||
|
||
clean : | ||
-$(DEL) *.bin | ||
-$(DEL) *.lst | ||
-$(DEL) *.gas | ||
-$(DEL) *.obj | ||
-$(DEL) bootpack.nas | ||
-$(DEL) bootpack.map | ||
-$(DEL) bootpack.bim | ||
-$(DEL) bootpack.hrb | ||
-$(DEL) haribote.sys | ||
|
||
src_only : | ||
$(MAKE) clean | ||
-$(DEL) haribote.img |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
## 运行方式: | ||
|
||
直接执行 make.bat | ||
|
||
## 代码说明: | ||
|
||
这一天修改的内容很多 | ||
|
||
包括读入 10 个柱面的数据 | ||
|
||
引入 C 语言 | ||
|
||
makefile 使用了变量进行书写 | ||
|
||
在 naskfunc 里又实现了一个函数用于运行 HLT 指令 因为 C 语言无法直接执行汇编指令 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
; haribote-os boot asm | ||
; TAB=4 | ||
|
||
BOTPAK EQU 0x00280000 ; 加载bootpack | ||
DSKCAC EQU 0x00100000 ; 磁盘缓存的位置 | ||
DSKCAC0 EQU 0x00008000 ; 磁盘缓存的位置(实模式) | ||
|
||
; BOOT_INFO相关 | ||
CYLS EQU 0x0ff0 ; 引导扇区设置 | ||
LEDS EQU 0x0ff1 | ||
VMODE EQU 0x0ff2 ; 关于颜色的信息 | ||
SCRNX EQU 0x0ff4 ; 分辨率X | ||
SCRNY EQU 0x0ff6 ; 分辨率Y | ||
VRAM EQU 0x0ff8 ; 图像缓冲区的起始地址 | ||
|
||
ORG 0xc200 ; 这个的程序要被装载的内存地址 | ||
|
||
; 信息保存到内存 | ||
|
||
MOV AL,0x13 ; VGA显卡,320x200x8bit | ||
MOV AH,0x00 | ||
INT 0x10 | ||
MOV BYTE [VMODE],8 ; 屏幕的模式(参考C语言的引用) | ||
MOV WORD [SCRNX],320 | ||
MOV WORD [SCRNY],200 | ||
MOV DWORD [VRAM],0x000a0000 | ||
|
||
; 通过BIOS获取指示灯状态 | ||
|
||
MOV AH,0x02 | ||
INT 0x16 ; keyboard BIOS | ||
MOV [LEDS],AL | ||
|
||
; 防止PIC接受所有中断 | ||
; AT兼容机的规范、PIC初始化 | ||
; 然后之前在CLI不做任何事就挂起 | ||
; PIC在同意后初始化 | ||
|
||
MOV AL,0xff | ||
OUT 0x21,AL | ||
NOP ; 不断执行OUT指令 | ||
OUT 0xa1,AL | ||
|
||
CLI ; 进一步中断CPU | ||
|
||
; 让CPU支持1M以上内存、设置A20GATE | ||
|
||
CALL waitkbdout | ||
MOV AL,0xd1 | ||
OUT 0x64,AL | ||
CALL waitkbdout | ||
MOV AL,0xdf ; enable A20 | ||
OUT 0x60,AL | ||
CALL waitkbdout | ||
|
||
; 保护模式转换 | ||
|
||
[INSTRSET "i486p"] ; 说明使用486指令 | ||
|
||
LGDT [GDTR0] ; 设置临时GDT | ||
MOV EAX,CR0 | ||
AND EAX,0x7fffffff ; 使用bit31(禁用分页) | ||
OR EAX,0x00000001 ; bit0到1转换(保护模式过渡) | ||
MOV CR0,EAX | ||
JMP pipelineflush | ||
pipelineflush: | ||
MOV AX,1*8 ; 写32bit的段 | ||
MOV DS,AX | ||
MOV ES,AX | ||
MOV FS,AX | ||
MOV GS,AX | ||
MOV SS,AX | ||
|
||
; bootpack传递 | ||
|
||
MOV ESI,bootpack ; 源 | ||
MOV EDI,BOTPAK ; 目标 | ||
MOV ECX,512*1024/4 | ||
CALL memcpy | ||
|
||
; 传输磁盘数据 | ||
|
||
; 从引导区开始 | ||
|
||
MOV ESI,0x7c00 ; 源 | ||
MOV EDI,DSKCAC ; 目标 | ||
MOV ECX,512/4 | ||
CALL memcpy | ||
|
||
; 剩余的全部 | ||
|
||
MOV ESI,DSKCAC0+512 ; 源 | ||
MOV EDI,DSKCAC+512 ; 目标 | ||
MOV ECX,0 | ||
MOV CL,BYTE [CYLS] | ||
IMUL ECX,512*18*2/4 ; 除以4得到字节数 | ||
SUB ECX,512/4 ; IPL偏移量 | ||
CALL memcpy | ||
|
||
; 由于还需要asmhead才能完成 | ||
; 完成其余的bootpack任务 | ||
|
||
; bootpack启动 | ||
|
||
MOV EBX,BOTPAK | ||
MOV ECX,[EBX+16] | ||
ADD ECX,3 ; ECX += 3; | ||
SHR ECX,2 ; ECX /= 4; | ||
JZ skip ; 传输完成 | ||
MOV ESI,[EBX+20] ; 源 | ||
ADD ESI,EBX | ||
MOV EDI,[EBX+12] ; 目标 | ||
CALL memcpy | ||
skip: | ||
MOV ESP,[EBX+12] ; 堆栈的初始化 | ||
JMP DWORD 2*8:0x0000001b | ||
|
||
waitkbdout: | ||
IN AL,0x64 | ||
AND AL,0x02 | ||
JNZ waitkbdout ; AND结果不为0跳转到waitkbdout | ||
RET | ||
|
||
memcpy: | ||
MOV EAX,[ESI] | ||
ADD ESI,4 | ||
MOV [EDI],EAX | ||
ADD EDI,4 | ||
SUB ECX,1 | ||
JNZ memcpy ; 运算结果不为0跳转到memcpy | ||
RET | ||
; memcpy地址前缀大小 | ||
|
||
ALIGNB 16 | ||
GDT0: | ||
RESB 8 ; 初始值 | ||
DW 0xffff,0x0000,0x9200,0x00cf ; 写32bit位段寄存器 | ||
DW 0xffff,0x0000,0x9a28,0x0047 ; 可执行的文件的32bit寄存器(bootpack用) | ||
|
||
DW 0 | ||
GDTR0: | ||
DW 8*3-1 | ||
DD GDT0 | ||
|
||
ALIGNB 16 | ||
bootpack: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// 声明一个函数,这个函数的实现在naskfunc.nas中 链接阶段会被链接到一起 | ||
void io_hlt(void); | ||
|
||
void HariMain(void) | ||
{ | ||
|
||
fin: | ||
io_hlt(); /* 执行naskfunc.nas中的_io_hlt函数 */ | ||
goto fin; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
; haribote-ipl | ||
; TAB=4 | ||
|
||
CYLS EQU 10 ; 声明CYLS=10 | ||
|
||
ORG 0x7c00 ; 指明程序装载地址 | ||
|
||
; 标准FAT12格式软盘专用的代码 Stand FAT12 format floppy code | ||
|
||
JMP entry | ||
DB 0x90 | ||
DB "HARIBOTE" ; 启动扇区名称(8字节) | ||
DW 512 ; 每个扇区(sector)大小(必须512字节) | ||
DB 1 ; 簇(cluster)大小(必须为1个扇区) | ||
DW 1 ; FAT起始位置(一般为第一个扇区) | ||
DB 2 ; FAT个数(必须为2) | ||
DW 224 ; 根目录大小(一般为224项) | ||
DW 2880 ; 该磁盘大小(必须为2880扇区1440*1024/512) | ||
DB 0xf0 ; 磁盘类型(必须为0xf0) | ||
DW 9 ; FAT的长度(必??9扇区) | ||
DW 18 ; 一个磁道(track)有几个扇区(必须为18) | ||
DW 2 ; 磁头数(必??2) | ||
DD 0 ; 不使用分区,必须是0 | ||
DD 2880 ; 重写一次磁盘大小 | ||
DB 0,0,0x29 ; 意义不明(固定) | ||
DD 0xffffffff ; (可能是)卷标号码 | ||
DB "HARIBOTEOS " ; 磁盘的名称(必须为11字?,不足填空格) | ||
DB "FAT12 " ; 磁盘格式名称(必??8字?,不足填空格) | ||
RESB 18 ; 先空出18字节 | ||
|
||
; 程序主体 | ||
|
||
entry: | ||
MOV AX,0 ; 初始化寄存器 | ||
MOV SS,AX | ||
MOV SP,0x7c00 | ||
MOV DS,AX | ||
|
||
; 读取磁盘 | ||
|
||
MOV AX,0x0820 | ||
MOV ES,AX | ||
MOV CH,0 ; 柱面0 | ||
MOV DH,0 ; 磁头0 | ||
MOV CL,2 ; 扇区2 | ||
|
||
readloop: | ||
MOV SI,0 ; 记录失败次数寄存器 | ||
|
||
retry: | ||
MOV AH,0x02 ; AH=0x02 : 读入磁盘 | ||
MOV AL,1 ; 1个扇区 | ||
MOV BX,0 | ||
MOV DL,0x00 ; A驱动器 | ||
INT 0x13 ; 调用磁盘BIOS | ||
JNC next ; 没出错则跳转到next | ||
ADD SI,1 ; 往SI加1 | ||
CMP SI,5 ; 比较SI与5 | ||
JAE error ; SI >= 5 跳转到error | ||
MOV AH,0x00 | ||
MOV DL,0x00 ; A驱动器 | ||
INT 0x13 ; 重置驱动器 | ||
JMP retry | ||
next: | ||
MOV AX,ES ; 把内存地址后移0x200(512/16十六进制转换) | ||
ADD AX,0x0020 | ||
MOV ES,AX ; ADD ES,0x020因为没有ADD ES,只能通过AX进行 | ||
ADD CL,1 ; 往CL里面加1 | ||
CMP CL,18 ; 比较CL与18 | ||
JBE readloop ; CL <= 18 跳转到readloop | ||
MOV CL,1 | ||
ADD DH,1 | ||
CMP DH,2 | ||
JB readloop ; DH < 2 跳转到readloop | ||
MOV DH,0 | ||
ADD CH,1 | ||
CMP CH,CYLS | ||
JB readloop ; CH < CYLS 跳转到readloop | ||
|
||
; 读取完毕,跳转到haribote.sys执行! | ||
MOV [0x0ff0],CH ; IPLがどこまで読んだのかをメモ | ||
JMP 0xc200 | ||
|
||
error: | ||
MOV SI,msg | ||
|
||
putloop: | ||
MOV AL,[SI] | ||
ADD SI,1 ; 给SI加1 | ||
CMP AL,0 | ||
JE fin | ||
MOV AH,0x0e ; 显示一个文字 | ||
MOV BX,15 ; 指定字符颜色 | ||
INT 0x10 ; 调用显卡BIOS | ||
JMP putloop | ||
|
||
fin: | ||
HLT ; 让CPU停止,等待指令 | ||
JMP fin ; 无限循环 | ||
|
||
msg: | ||
DB 0x0a, 0x0a ; 换行两次 | ||
DB "load error" | ||
DB 0x0a ; 换行 | ||
DB 0 | ||
|
||
RESB 0x7dfe-$ ; 填写0x00直到0x001fe | ||
|
||
DB 0x55, 0xaa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9 |
Oops, something went wrong.