-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsix.asm
185 lines (134 loc) · 2.85 KB
/
six.asm
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
; Write X86/64 ALP to detect protected mode and display the values of GDTR, LDTR, IDTR, TR, and MSW Registers.
%macro IO 4
mov rax, %1
mov rdi, %2
mov rsi, %3
mov rdx, %4
syscall
%endmacro
section .data
m1 db 10, 10, "GDTR Contents : ", 10
l1 equ $ - m1
m2 db "We are in protected mode :) ", 10
l2 equ $ - m2
m3 db "We aren't in protected mode :( ", 10
l3 equ $ - m3
m4 db 10, 10, "LDTR contents are : ", 10
l4 equ $ - m4
m5 db 10, 10, "IDTR contents are : ", 10
l5 equ $ - m5
m6 db 10, 10, "MSW contents are : ", 10
l6 equ $ - m6
m7 db 10, 10, "TR contents are : ", 10
l7 equ $ - m7
colon db " : "
col equ $ - colon
newLine db " ",10
nl equ $ - newLine
section .bss
gdt: resd 01
resw 01
ldt: resw 01
idt: resd 01
resw 01
msw: resw 01
tr: resw 01
result resw 01
section .text
global _start
_start:
call protectedModeCheck
call getGDT
call getLDT
call getIDT
call getMSW
call getTR
IO 1, 1, newLine, nl
mov rax, 60
mov rdi, 0
syscall
getGDT:
sgdt[gdt]
IO 1, 1, m1, l1
mov bx, word[gdt + 4]
call print
mov bx, word[gdt + 2]
call print
IO 1, 1, colon, col
mov bx, word[gdt]
call print
ret
getLDT:
sldt[ldt]
IO 1, 1, m4, l4
mov bx, word[ldt + 2]
call print
IO 1, 1, colon, col
mov bx, word[ldt]
call print
ret
getIDT:
sidt[idt]
IO 1, 1, m5, l5
mov bx, word[idt + 4]
call print
mov bx, word[idt + 2]
call print
IO 1, 1, colon, col
mov bx, word[idt]
call print
ret
getMSW:
smsw[msw]
IO 1, 1, m6, l6
mov bx, word[msw]
call print
ret
getTR:
str[tr]
IO 1, 1, m7, l7
mov bx, word[tr]
call print
ret
protectedModeCheck:
bt ax, 0
jc next
jnc next2
next:
IO 1, 1, m2, l2
next2:
IO 1, 1, m3, l3
ret
print:
mov rcx, 4
mov rdi, result
repeat:
rol bx, 4
mov al, bl
and al, 0fh
cmp al, 09h
jg add37
add al, 30h
jmp skip
add37:
add al, 37h
skip:
mov [rdi], al
inc rdi
loop repeat
IO 1, 1, result, 4
ret
ret
; Output
; -----------------------------
; We aren't in protected mode :(
; GDTR Contents :
; 00077000 : 007F
; LDTR contents are :
; FFFF : 0000
; IDTR contents are :
; 00000000 : 0FFF
; MSW contents are :
; 0033
; TR contents are :
; 0040