-
Notifications
You must be signed in to change notification settings - Fork 1
/
naskfunc.nas
147 lines (128 loc) · 2.22 KB
/
naskfunc.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
146
147
; naskfunc
; TAB=4
[FORMAT "WCOFF"] ; 制作目标文件的模式
[INSTRSET "i486p"] ;
[BITS 32] ; 32bit
; the object file info
[FILE "naskfunc.nas"] ; source file's name
GLOBAL _io_hlt, _write_mem8 ; function name
GLOBAL _io_cli, _io_sti, _io_stihlt
GLOBAL _io_in8, _io_in16, _io_in32
GLOBAL _io_out8, _io_out16, _io_out32
GLOBAL _io_load_eflags, _io_store_eflags
GLOBAL _load_gdtr, _load_idtr
GLOBAL _asm_inthandler21, _asm_inthandler27, _asm_inthandler2c
EXTERN _inthandler21, _inthandler27, _inthandler2c
[SECTION .text]
_io_hlt: ; void io_hlt(void);
HLT
RET
_write_mem8: ; void write_mem8(int addr, int data);
MOV ECX, [ESP + 4]
MOV AL, [ESP + 8]
MOV [ECX], AL
RET
_io_cli: ;void io_cli(void);
CLI
RET
_io_sti: ;void io_sti(void);
STI
RET
_io_stihlt: ;void io_stihlt(void)
STI
HLT
RET
_io_in8: ;int io_in8(int port);
MOV EDX, [ESP + 4]
MOV EAX, 0
IN AL, DX
RET
_io_in16:
MOV EDX, [ESP + 4]
MOV EAX, 0
IN AX, DX
RET
_io_in32:
MOV EDX, [ESP + 4]
MOV EAX, 0
IN EAX, DX
RET
_io_out8:
MOV EDX, [ESP + 4]
MOV EAX, [ESP + 8]
OUT DX, AL
RET
_io_out16:
MOV EDX, [ESP + 4]
MOV EAX, [ESP + 8]
OUT DX, AX
RET
_io_out32:
MOV EDX, [ESP + 4]
MOV EAX, [ESP + 8]
OUT DX, EAX
RET
_io_load_eflags: ;int io_load_eflags(void)
PUSHFD
POP EAX
RET
_io_store_eflags: ;void io_store_eflags(int eflags)
MOV EAX, [ESP + 4]
PUSH EAX
POPFD
RET
_load_gdtr: ; void load_gdtr(int limit, int addr);
MOV AX,[ESP+4] ; limit
MOV [ESP+6],AX
LGDT [ESP+6]
RET
_load_idtr: ; void load_idtr(int limit, int addr);
MOV AX,[ESP+4] ; limit
MOV [ESP+6],AX
LIDT [ESP+6]
RET
_asm_inthandler21:
PUSH ES
PUSH DS
PUSHAD
MOV EAX,ESP
PUSH EAX
MOV AX,SS
MOV DS,AX
MOV ES,AX
CALL _inthandler21
POP EAX
POPAD
POP DS
POP ES
IRETD
_asm_inthandler27:
PUSH ES
PUSH DS
PUSHAD
MOV EAX,ESP
PUSH EAX
MOV AX,SS
MOV DS,AX
MOV ES,AX
CALL _inthandler27
POP EAX
POPAD
POP DS
POP ES
IRETD
_asm_inthandler2c:
PUSH ES
PUSH DS
PUSHAD
MOV EAX,ESP
PUSH EAX
MOV AX,SS
MOV DS,AX
MOV ES,AX
CALL _inthandler2c
POP EAX
POPAD
POP DS
POP ES
IRETD