Skip to content

Commit 55f8b93

Browse files
committed
day03-1
1 parent de3e420 commit 55f8b93

File tree

12 files changed

+425
-0
lines changed

12 files changed

+425
-0
lines changed

day02/01/helloos.img

1.41 MB
Binary file not shown.

day02/01/helloos.nas

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
; hello-os
2+
; TAB=4
3+
4+
ORG 0x7c00 ;指明程序的装载地址
5+
6+
; 以下的记述用于标准FAT12格式的软盘
7+
8+
JMP entry
9+
db 0x90
10+
db "HARIBOTE"
11+
dw 512
12+
db 1
13+
dw 1
14+
db 2
15+
dw 224
16+
dw 2880
17+
db 0xf0
18+
dw 9
19+
dw 18
20+
dw 2
21+
dd 0
22+
dd 2880
23+
db 0,0,0x29
24+
dd 0xffffffff
25+
db "HARIBOTEOS "
26+
db "FAT32 "
27+
resb 18
28+
29+
;程序核心
30+
entry: ;0x7c50
31+
mov AX,0 ; 初始化寄存器
32+
mov SS,AX
33+
mov SP,0x7c00
34+
mov DS,AX
35+
mov ES,AX
36+
37+
mov SI,msg
38+
39+
putloop:
40+
mov AL,[SI]
41+
add SI,1
42+
cmp AL,0
43+
44+
je fin
45+
mov AH,0x0e ;显示一个文字
46+
mov BL,0 ;指定字符颜色
47+
INT 0x10 ;调用显卡BIOS
48+
jmp putloop
49+
50+
fin:
51+
HLT ;让CPU停止,等待指令
52+
jmp fin
53+
54+
msg: ;0x7c74
55+
DB 0x0a, 0x0a ;换行两次
56+
db "HELLO, world"
57+
db 0x0a ;换行
58+
db 0
59+
60+
times 510-($-$$) db 0
61+
db 0x55,0xaa
62+
63+
;一下是启动区以外部分的输出
64+
db 0xf0,0xff,0xff,0x00,0x00,0x00,0x00,0x00
65+
resb 4600
66+
db 0xf0,0xff,0xff,0x00,0x00,0x00,0x00,0x00
67+
resb 1469432

day02/02/Makefile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# 添加默认命令
2+
default :
3+
make img
4+
bootloader : ipl.nas Makefile
5+
nasm -o bootloader -l ipl.lst ipl.nas
6+
helloos.img : bootloader
7+
dd if=/dev/zero of=helloos.img bs=512 count=2880
8+
dd if=bootloader of=helloos.img bs=1
9+
img :
10+
make -r helloos.img
11+
run : helloos.img
12+
qemu-system-i386 helloos.img
13+
clean :
14+
rm ipl.lst
15+
rm bootloader

day02/02/helloos.img

512 Bytes
Binary file not shown.

day02/02/ipl.nas

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
; hello-os
2+
; TAB=4
3+
4+
ORG 0x7c00 ;指明程序的装载地址
5+
6+
; 以下的记述用于标准FAT12格式的软盘
7+
8+
JMP entry
9+
db 0x90
10+
db "HARIBOTE"
11+
dw 512
12+
db 1
13+
dw 1
14+
db 2
15+
dw 224
16+
dw 2880
17+
db 0xf0
18+
dw 9
19+
dw 18
20+
dw 2
21+
dd 0
22+
dd 2880
23+
db 0,0,0x29
24+
dd 0xffffffff
25+
db "HARIBOTEOS "
26+
db "FAT32 "
27+
resb 18
28+
29+
;程序核心
30+
entry: ;0x7c50
31+
mov AX,0 ; 初始化寄存器
32+
mov SS,AX
33+
mov SP,0x7c00
34+
mov DS,AX
35+
mov ES,AX
36+
37+
mov SI,msg
38+
39+
putloop:
40+
mov AL,[SI]
41+
add SI,1
42+
cmp AL,0
43+
44+
je fin
45+
mov AH,0x0e ;显示一个文字
46+
mov BL,0 ;指定字符颜色
47+
INT 0x10 ;调用显卡BIOS
48+
jmp putloop
49+
50+
fin:
51+
HLT ;让CPU停止,等待指令
52+
jmp fin
53+
54+
msg: ;0x7c74
55+
DB 0x0a, 0x0a ;换行两次
56+
db "HELLO, world"
57+
db 0x0a ;换行
58+
db 0
59+
60+
times 510-($-$$) db 0
61+
db 0x55,0xaa

day02/note.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
## Day02
2+
3+
> 首先BIOS从硬盘中的第一个扇区加载数据,加载的数据从内存的0x7c00处开始保存,程序都是保存在磁盘镜像文
4+
> 件中的
5+
6+
#### 汇编指令
7+
- ORG : origin 的意思,告诉告诉编译器,程序的起始地址
8+
- JMP : go to 的意思, jump
9+
- entry: 标号,类似这样的都是标号,其实就是计算机根据ORG计算出来的地址。
10+
- mov : 赋值指令,MOV SS,AX 等于 SS = AX
11+
- [] : 表示内存的地址,表示存储至该地址或者取该地址处的值
12+
- cmp : 比较两个操作数
13+
- je : 比较后跳转,**相等才跳转,不等不跳转**
14+
- INT : interrupt 中断
15+
- HLT : 使计算机进入休眠,直到检测到外部变化,计算机才会醒过来。
16+
17+
#### 寄存器
18+
- 8 个代表性的寄存器
19+
- AX : 累加寄存器
20+
- BX : 基址寄存器
21+
- CX : 计数寄存器
22+
- DX : 数据寄存器
23+
- SP : 栈指针寄存器
24+
- BP : 基址指针寄存器
25+
- SI : 源变址寄存器
26+
- DI : 目的变址寄存器
27+
- AX,BX,CX,DX 分为H和L两种,以AX为例即是 AL和AH,即低8位和高8位
28+
- 段寄存器
29+
- ES : 附件段寄存器
30+
- CS : 代码段寄存器
31+
- SS : 栈段寄存器
32+
- DS : 数据段寄存器
33+
- FS :
34+
- GS :
35+
36+
#### 0x7c00
37+
- 这是一个内存中的地址,启动系统的初始地址都在该处
38+
39+
#### nasm 命令
40+
- \-l :编译时生成list文件,里面包含代码和对应的机器码等内容
41+
- \-o :用来指定编译后的文件的名称
42+
43+
#### dd 命令
44+
45+
dd if=/dev/zero of=os.img bs=512 count=2880 //新建一个空的2880\* 512 字节的软盘文件(当时软盘的大小)
46+
dd if=bootloader of=os.img bs=512 count=1
47+
48+
- if : 输入文件
49+
- of : 输出文件
50+
- bs : 输入/输出块的大小
51+
- count : 拷贝块的个数
52+
53+
##### makefile
54+
55+
> makefile规则规定了编译的依赖关系,也就是目标文件依赖于条件,生成规则用命令来描述。编译时,如果需
56+
> 要的条件的文件比目标更新的话,就会执行生成命令来更新目标
57+
58+
- 文件名可为Makefile,也可为makefile
59+
- 规则
60+
目标 : 需要的条件(冒号两边有空格)
61+
命令 (命令前面是tab不是空格,vim编辑时最好将tab替换成空格的命令去掉)
62+
- 目标可以是一个或者多个,可以是Object file,也可以是一个执行文件,甚至可以是一个标签。
63+
- 需要的条件就是生成目标所需要的文件或者目录,可以一个或者多个
64+
- 命令就是生成目标所需要执行的脚本,可添加多个命令
65+
66+
67+
- 使用 直接利用 make 目标 命令便可生成目标文件
68+
- make 会在Makefile中自动的寻找,生成目标文件的规则并加以利用,
69+
70+

day03/01/Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# 添加默认命令
2+
default :
3+
make img
4+
bootloader : ipl.nas Makefile
5+
nasm -o bootloader -l ipl.lst ipl.nas
6+
helloos.img : bootloader
7+
dd if=bootloader of=helloos.img bs=1
8+
dd if=/dev/zero of=helloos.img bs=512 seek=1 count=2879
9+
img :
10+
make -r helloos.img
11+
run : helloos.img
12+
qemu-system-i386 helloos.img
13+
clean :
14+
rm ipl.lst
15+
rm bootloader
16+
src :
17+
make clean
18+
rm *.img

day03/01/bootloader

512 Bytes
Binary file not shown.

day03/01/helloos.img

1.41 MB
Binary file not shown.

day03/01/ipl.lst

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
1 ; hello-os
2+
2 ; TAB=4
3+
3
4+
4 ORG 0x7c00 ;指明程序的装载地址
5+
5
6+
6 ; 以下的记述用于标准FAT12格式的软盘
7+
7
8+
8 00000000 EB4E JMP entry
9+
9 00000002 90 db 0x90
10+
10 00000003 48415249424F5445 db "HARIBOTE"
11+
11 0000000B 0002 dw 512
12+
12 0000000D 01 db 1
13+
13 0000000E 0100 dw 1
14+
14 00000010 02 db 2
15+
15 00000011 E000 dw 224
16+
16 00000013 400B dw 2880
17+
17 00000015 F0 db 0xf0
18+
18 00000016 0900 dw 9
19+
19 00000018 1200 dw 18
20+
20 0000001A 0200 dw 2
21+
21 0000001C 00000000 dd 0
22+
22 00000020 400B0000 dd 2880
23+
23 00000024 000029 db 0,0,0x29
24+
24 00000027 FFFFFFFF dd 0xffffffff
25+
25 0000002B 48415249424F54454F- db "HARIBOTEOS "
26+
25 00000034 5320
27+
26 00000036 4641543332202020 db "FAT32 "
28+
27 0000003E <res 00000012> resb 18
29+
27 ****************** warning: uninitialized space declared in .text section: zeroing
30+
28
31+
29 ;程序核心
32+
30 entry: ;0x7c50
33+
31 00000050 B80000 mov AX,0 ; 初始化寄存器
34+
32 00000053 8ED0 mov SS,AX
35+
33 00000055 BC007C mov SP,0x7c00
36+
34 00000058 8ED8 mov DS,AX
37+
35 0000005A 8EC0 mov ES,AX
38+
36
39+
37 ; 读盘时的参数
40+
38 0000005C B82008 mov AX,0x0820
41+
39 0000005F 8EC0 mov ES,AX
42+
40 00000061 B500 mov CH,0 ; 柱面 0
43+
41 00000063 B600 mov DH,0 ; 磁头 0
44+
42 00000065 B102 mov CL,2 ; 扇区 2
45+
43
46+
44 ; 读盘指令
47+
45 00000067 B402 mov AH,0x02 ; 读盘指令
48+
46 00000069 B001 mov AL,1 ; 1个扇区
49+
47 0000006B BB0000 mov BX,0
50+
48 0000006E B200 mov DL,0x00 ; A驱动器
51+
49 00000070 CD13 INT 0x13 ; 调用磁盘BIOS
52+
50 00000072 7200 JC error
53+
51
54+
52 error:
55+
53 00000074 BE[8B00] mov SI,msg
56+
54
57+
55 putloop:
58+
56 00000077 8A04 mov AL,[SI]
59+
57 00000079 83C601 add SI,1
60+
58 0000007C 3C00 cmp AL,0
61+
59
62+
60 0000007E 7408 je fin
63+
61 00000080 B40E mov AH,0x0e ;显示一个文字
64+
62 00000082 B300 mov BL,0 ;指定字符颜色
65+
63 00000084 CD10 INT 0x10 ;调用显卡BIOS
66+
64 00000086 EBEF jmp putloop
67+
65
68+
66 fin:
69+
67 00000088 F4 HLT ;让CPU停止,等待指令
70+
68 00000089 EBFD jmp fin
71+
69
72+
70 msg: ;0x7c74
73+
71 0000008B 0A0A DB 0x0a, 0x0a ;换行两次
74+
72 0000008D 48454C4C4F2C20776F- db "HELLO, world"
75+
72 00000096 726C64
76+
73 00000099 0A db 0x0a ;换行
77+
74 0000009A 00 db 0
78+
75
79+
76 0000009B 00<rept> times 510-($-$$) db 0
80+
77 000001FE 55AA db 0x55,0xaa

0 commit comments

Comments
 (0)