-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstage2.asm
More file actions
226 lines (206 loc) · 3.54 KB
/
Copy pathstage2.asm
File metadata and controls
226 lines (206 loc) · 3.54 KB
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
[BITS 16]
[ORG 0x7E00]
stage2_start:
mov si, msg_stage2
call print_string
call show_system_info
call shell
jmp halt
show_system_info:
pusha
mov si, msg_separator
call print_string
mov si, msg_memory
call print_string
int 0x12
call print_decimal
mov si, msg_kb
call print_string
; CPUID tespiti
mov si, msg_cpu
call print_string
call detect_cpu
mov si, msg_separator
call print_string
popa
ret
detect_cpu:
pusha
; CPUID destegi var mi kontrol et
pushf
pop ax
mov cx, ax
xor ax, 0x200000
push ax
popf
pushf
pop ax
push cx
popf
xor ax, cx
jz .no_cpuid
mov eax, 0
cpuid
mov [cpu_vendor], ebx
mov [cpu_vendor+4], edx
mov [cpu_vendor+8], ecx
mov byte [cpu_vendor+12], 0
mov si, cpu_vendor
call print_string
jmp .done
.no_cpuid:
mov si, msg_no_cpuid
call print_string
.done:
mov si, msg_newline
call print_string
popa
ret
shell:
mov si, msg_shell_help
call print_string
.prompt:
mov si, msg_prompt
call print_string
mov di, input_buffer
call read_line
cmp byte [input_buffer], 0
je .prompt.
mov si, input_buffer
mov di, cmd_help
call strcmp
cmp ax, 1
je .do_help
mov si, input_buffer
mov di, cmd_info
call strcmp
cmp ax, 1
je .do_info
mov si, msg_unknown
call print_string
jmp .prompt
.do_help:
mov si, msg_shell_help
call print_string
jmp .prompt
.do_info:
call show_system_info
jmp .prompt
strcmp:
; String karsilastirma mantigi (case insensitive)
push si
push di
.loop:
mov al, [si]
mov bl, [di]
cmp al, 'a'
jb .next
cmp al, 'z'
ja .next
sub al, 32
.next:
cmp al, bl
jne .not_equal
test al, al
jz .equal
inc si
inc di
jmp .loop
.equal:
pop di
pop si
mov ax, 1
ret
.not_equal:
pop di
pop si
xor ax, ax
ret
; Helpers
read_line:
pusha
xor cx, cx
.loop:
mov ah, 0x00
int 0x16
cmp al, 13 ; Enter?
je .done
cmp al, 8 ; Backspace?
je .backspace
cmp cx, 62
jge .loop
stosb
inc cx
mov ah, 0x0E
int 0x10
jmp .loop
.backspace:
test cx, cx
jz .loop
dec di
dec cx
mov ah, 0x0E
mov al, 8
int 0x10
mov al, ' '
int 0x10
mov al, 8
int 0x10
jmp .loop
.done:
mov byte [di], 0
mov si, msg_newline
call print_string
popa
ret
print_string:
pusha
mov ah, 0x0E
.loop:
lodsb
test al, al
jz .done
int 0x10
jmp .loop
.done:
popa
ret
print_decimal:
pusha
xor cx, cx
mov bx, 10
.divide:
xor dx, dx
div bx
push dx
inc cx
test ax, ax
jnz .divide
.print:
pop ax
add al, '0'
mov ah, 0x0E
int 0x10
loop .print
popa
ret
halt:
cli
hlt
jmp halt
; Global Mesajlar
msg_stage2: db "STAGE2 Successfully loaded!", 13, 10, 0
msg_separator: db "----------------------------------------", 13, 10, 0
msg_memory: db " Memory : ", 0
msg_kb: db " KB (conventional)", 13, 10, 0
msg_cpu: db " CPU : ", 0
msg_no_cpuid: db "CPUID not supported", 0
msg_newline: db 13, 10, 0
msg_shell_help: db "Commands: HELP, INFO, CLEAR, REBOOT", 13, 10, 0
msg_prompt: db "boot> ", 0
msg_unknown: db "Unknown command.", 13, 10, 0
cmd_help: db "HELP", 0
cmd_info: db "INFO", 0
cpu_vendor: times 13 db 0
input_buffer: times 64 db 0
times 2048 - ($ - $$) db 0.