-
Notifications
You must be signed in to change notification settings - Fork 1
/
asmhead.nas
145 lines (117 loc) · 4.22 KB
/
asmhead.nas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
; haribote-os
; TAB=4
BOTPAK EQU 0x00280000 ; bootpack‚̃[ƒhæ
DSKCAC EQU 0x00100000 ; ƒfƒBƒXƒNƒLƒƒƒbƒVƒ…‚ÌêŠ
DSKCAC0 EQU 0x00008000 ; ƒfƒBƒXƒNƒLƒƒƒbƒVƒ…‚ÌêŠiƒŠƒAƒ‹ƒ‚[ƒhj
; 关于启动信息 BOOT_INFO
CYLS EQU 0x0ff0 ; 设定启动区
LEDS EQU 0x0ff1 ; 保存键盘状态
VMODE EQU 0x0ff2 ; 保存颜色信息
SCRNX EQU 0x0ff4 ; x轴分辨率
SCRNY EQU 0x0ff6 ; y轴分辨率
VRAM EQU 0x0ff8 ; 保存图像缓冲区地址
ORG 0xc200
; VGA显卡, 320x200x8bit 彩色
MOV AL,0x13
MOV AH,0x00
INT 0x10
MOV BYTE [VMODE], 8 ; 8bit彩色
MOV WORD [SCRNX], 320
MOV WORD [SCRNY], 200
MOV DWORD[VRAM], 0x000a0000
; 通过BIOS调用获取键盘状态
MOV AH, 0x02
INT 0x16
MOV [LEDS], AL
; we well explain the following code later!!!
; PIC‚ªˆêØ‚ÌŠ„‚èž‚Ý‚ðŽó‚¯•t‚¯‚È‚¢‚悤‚É‚·‚é
; ATŒÝŠ·‹@‚ÌŽd—l‚Å‚ÍAPIC‚̉Šú‰»‚ð‚·‚é‚È‚çA
; ‚±‚¢‚‚ðCLI‘O‚É‚â‚Á‚Ä‚¨‚©‚È‚¢‚ÆA‚½‚܂Ƀnƒ“ƒOƒAƒbƒv‚·‚é
; PIC‚̉Šú‰»‚Í‚ ‚Æ‚Å‚â‚é
MOV AL,0xff
OUT 0x21,AL
NOP ; OUT–½—ß‚ð˜A‘±‚³‚¹‚é‚Æ‚¤‚Ü‚‚¢‚©‚È‚¢‹@Ží‚ª‚ ‚é‚炵‚¢‚Ì‚Å
OUT 0xa1,AL
CLI ; ‚³‚ç‚ÉCPUƒŒƒxƒ‹‚Å‚àŠ„‚èž‚Ý‹ÖŽ~
; CPU‚©‚ç1MBˆÈã‚̃ƒ‚ƒŠ‚ɃAƒNƒZƒX‚Å‚«‚é‚悤‚ÉAA20GATE‚ðÝ’è
CALL waitkbdout
MOV AL,0xd1
OUT 0x64,AL
CALL waitkbdout
MOV AL,0xdf ; enable A20
OUT 0x60,AL
CALL waitkbdout
; ƒvƒƒeƒNƒgƒ‚[ƒhˆÚs
[INSTRSET "i486p"] ; 486‚Ì–½—ß‚Ü‚ÅŽg‚¢‚½‚¢‚Æ‚¢‚¤‹Lq
LGDT [GDTR0] ; Žb’èGDT‚ðÝ’è
MOV EAX,CR0
AND EAX,0x7fffffff ; bit31‚ð0‚É‚·‚éiƒy[ƒWƒ“ƒO‹ÖŽ~‚Ì‚½‚ßj
OR EAX,0x00000001 ; bit0‚ð1‚É‚·‚éiƒvƒƒeƒNƒgƒ‚[ƒhˆÚs‚Ì‚½‚ßj
MOV CR0,EAX
JMP pipelineflush
pipelineflush:
MOV AX,1*8 ; “Ç‚Ý‘‚«‰Â”\ƒZƒOƒƒ“ƒg32bit
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
; ‚‚¢‚łɃfƒBƒXƒNƒf[ƒ^‚à–{—ˆ‚̈ʒu‚Ö“]‘—
; ‚Ü‚¸‚̓u[ƒgƒZƒNƒ^‚©‚ç
MOV ESI,0x7c00 ; “]‘—Œ³
MOV EDI,DSKCAC ; “]‘—æ
MOV ECX,512/4
CALL memcpy
; Žc‚è‘S•”
MOV ESI,DSKCAC0+512 ; “]‘—Œ³
MOV EDI,DSKCAC+512 ; “]‘—æ
MOV ECX,0
MOV CL,BYTE [CYLS]
IMUL ECX,512*18*2/4 ; ƒVƒŠƒ“ƒ_”‚©‚çƒoƒCƒg”/4‚É•ÏŠ·
SUB ECX,512/4 ; IPL‚Ì•ª‚¾‚¯·‚µˆø‚
CALL memcpy
; asmhead‚Å‚µ‚È‚¯‚ê‚΂¢‚¯‚È‚¢‚±‚Æ‚Í‘S•”‚µI‚í‚Á‚½‚Ì‚ÅA
; ‚ ‚Æ‚Íbootpack‚É”C‚¹‚é
; bootpack‚Ì‹N“®
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] ; ƒXƒ^ƒbƒN‰Šú’l
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 ; ˆø‚«ŽZ‚µ‚½Œ‹‰Ê‚ª0‚Å‚È‚¯‚ê‚Îmemcpy‚Ö
RET
; memcpy‚̓AƒhƒŒƒXƒTƒCƒYƒvƒŠƒtƒBƒNƒX‚ð“ü‚ê–Y‚ê‚È‚¯‚ê‚ÎAƒXƒgƒŠƒ“ƒO–½—ß‚Å‚à‘‚¯‚é
ALIGNB 16
GDT0:
RESB 8 ; ƒkƒ‹ƒZƒŒƒNƒ^
DW 0xffff,0x0000,0x9200,0x00cf ; “Ç‚Ý‘‚«‰Â”\ƒZƒOƒƒ“ƒg32bit
DW 0xffff,0x0000,0x9a28,0x0047 ; ŽÀs‰Â”\ƒZƒOƒƒ“ƒg32bitibootpack—pj
DW 0
GDTR0:
DW 8*3-1
DD GDT0
ALIGNB 16
bootpack: