* remove "\r" nonsense
[mascara-docs.git] / amd64 / bareMetalOS-0.5.2 / baremetal0.5.2 / os / syscalls / debug.asm
blob7f5baab8e15fc04f10304154f4143aea01f70bc7
1 ; =============================================================================
2 ; BareMetal -- a 64-bit OS written in Assembly for x86-64 systems
3 ; Copyright (C) 2008-2011 Return Infinity -- see LICENSE.TXT
5 ; Debug functions
6 ; =============================================================================
8 align 16
9 db 'DEBUG: DEBUG '
10 align 16
13 ; -----------------------------------------------------------------------------
14 ; os_debug_dump_reg -- Dump the values on the registers to the screen (For debug purposes)
15 ; IN: Nothing
16 ; OUT: Nothing, all registers preserved
17 os_debug_dump_reg:
18 pushfq ; Push the registers used by this function
19 push rsi
20 push rbx
21 push rax
23 pushfq ; Push the flags to the stack
24 push r15 ; Push all of the registers to the stack
25 push r14
26 push r13
27 push r12
28 push r11
29 push r10
30 push r9
31 push r8
32 push rsp
33 push rbp
34 push rdi
35 push rsi
36 push rdx
37 push rcx
38 push rbx
39 push rax
41 mov byte [os_debug_dump_reg_stage], 0x00 ; Reset the stage to 0 since we are starting
42 os_debug_dump_reg_next:
43 mov rsi, os_debug_dump_reg_string00
44 xor rax, rax
45 xor rbx, rbx
46 mov al, [os_debug_dump_reg_stage]
47 mov bl, 5 ; Each string is 5 bytes
48 mul bl ; AX = BL x AL
49 add rsi, rax ; Add the offset to get to the correct string
50 call os_print_string ; Print the register name
51 pop rax ; Pop the register from the stack
52 call os_debug_dump_rax ; Print the hex string value of RAX
53 inc byte [os_debug_dump_reg_stage]
54 cmp byte [os_debug_dump_reg_stage], 0x11 ; Check to see if all 16 registers as well as the flags are displayed
55 jne os_debug_dump_reg_next
57 mov rbx, rax ; Store the flags in RBX
59 mov rsi, os_debug_dump_flag_string0 ; Print the Carry flag
60 call os_print_string
61 bt rbx, 0
62 jc carry_1
63 carry_0:
64 mov al, '0'
65 jmp print_carry
66 carry_1:
67 mov al, '1'
68 print_carry:
69 call os_print_char
71 mov rsi, os_debug_dump_flag_string1 ; Print the Zero flag
72 call os_print_string
73 bt rbx, 6
74 jc zero_1
75 zero_0:
76 mov al, '0'
77 jmp print_zero
78 zero_1:
79 mov al, '1'
80 print_zero:
81 call os_print_char
83 mov rsi, os_debug_dump_flag_string2 ; Print the Sign flag
84 call os_print_string
85 bt rbx, 7
86 jc sign_1
87 sign_0:
88 mov al, '0'
89 jmp print_sign
90 sign_1:
91 mov al, '1'
92 print_sign:
93 call os_print_char
95 mov rsi, os_debug_dump_flag_string3 ; Print the Direction flag
96 call os_print_string
97 bt rbx, 10
98 jc dir_1
99 dir_0:
100 mov al, '0'
101 jmp print_dir
102 dir_1:
103 mov al, '1'
104 print_dir:
105 call os_print_char
107 mov rsi, os_debug_dump_flag_string4 ; Print the Overflow flag
108 call os_print_string
109 bt rbx, 11
110 jc over_1
111 over_0:
112 mov al, '0'
113 jmp print_over
114 over_1:
115 mov al, '1'
116 print_over:
117 call os_print_char
120 os_debug_dump_reg_done:
121 call os_print_newline
122 pop rax
123 pop rbx
124 pop rsi
125 popfq
127 ; -----------------------------------------------------------------------------
130 ; -----------------------------------------------------------------------------
131 ; os_debug_dump_mem -- Dump some memory content to the screen
132 ; IN: RSI = Start of memory address to dump
133 ; RCX = number of bytes to dump
134 ; OUT: Nothing, all registers preserved
135 os_debug_dump_mem:
136 push rsi
137 push rcx ; counter
138 push rdx ; total number of bytes to display
139 push rbx ; color attribute
140 push rax
141 mov bl, 0x07 ; Default of light grey on black
143 cmp rcx, 0
144 je os_debug_dump_mem_done
145 mov rdx, rcx ; Save the total number of bytes to display
146 add rdx, 15
147 and rdx, 0xFFFFFFF0
148 and rsi, 0xFFFFFFF0
150 os_debug_dump_mem_print_address:
151 mov rax, rsi
152 call os_debug_dump_rax
153 push rsi
154 mov rsi, divider
155 call os_print_string
156 pop rsi
157 xor rcx, rcx ; Clear the counter
159 os_debug_dump_mem_next_byte_hex:
160 lodsb
161 call os_print_char_hex_with_color
162 xor bl, 10000000b ; Toggle between light grey on black and light grey on dark grey
163 add rcx, 1
164 cmp rcx, 16
165 jne os_debug_dump_mem_next_byte_hex
167 push rsi
168 mov rsi, divider
169 call os_print_string
170 pop rsi
171 sub rsi, 0x10
172 xor rcx, rcx ; Clear the counter
174 os_debug_dump_mem_next_byte_ascii:
175 lodsb
176 call os_print_char_with_color
177 xor bl, 10000000b ; Toggle between light grey on black and light grey on dark grey
178 add rcx, 1
179 cmp rcx, 16
180 jne os_debug_dump_mem_next_byte_ascii
182 sub rdx, 16
183 cmp rdx, 0
184 je os_debug_dump_mem_done
185 call os_print_newline
186 jmp os_debug_dump_mem_print_address
188 os_debug_dump_mem_done:
189 pop rax
190 pop rbx
191 pop rcx
192 pop rdx
193 pop rsi
196 divider: db ' | ', 0
197 ; -----------------------------------------------------------------------------
200 ; -----------------------------------------------------------------------------
201 ; os_debug_dump_(rax|eax|ax|al) -- Dump content of RAX, EAX, AX, or AL to the screen in hex format
202 ; IN: RAX = content to dump
203 ; OUT: Nothing, all registers preserved
204 os_debug_dump_rax:
205 ror rax, 56
206 call os_print_char_hex
207 rol rax, 8
208 call os_print_char_hex
209 rol rax, 8
210 call os_print_char_hex
211 rol rax, 8
212 call os_print_char_hex
213 rol rax, 32
214 os_debug_dump_eax:
215 ror rax, 24
216 call os_print_char_hex
217 rol rax, 8
218 call os_print_char_hex
219 rol rax, 16
220 os_debug_dump_ax:
221 ror rax, 8
222 call os_print_char_hex
223 rol rax, 8
224 os_debug_dump_al:
225 call os_print_char_hex
227 ; -----------------------------------------------------------------------------
230 ; -----------------------------------------------------------------------------
231 ; os_debug_get_ip -- Dump content of RIP into RAX
232 ; IN: Nothing
233 ; OUT: RAX = RIP
234 os_debug_get_ip:
235 mov rax, qword [rsp]
237 ; -----------------------------------------------------------------------------
240 ; -----------------------------------------------------------------------------
241 ; os_debug_dump_MAC -- Dump MAC address to screen
242 ; IN: Nothing
243 ; OUT: Nothing, all registers preserved
244 os_debug_dump_MAC:
245 push rsi
246 push rcx
247 push rax
249 mov ecx, 6
250 mov rsi, os_NetMAC
251 os_debug_dump_MAC_display:
252 lodsb
253 call os_debug_dump_al
254 sub ecx, 1
255 test ecx, ecx
256 jnz os_debug_dump_MAC_display
258 pop rax
259 pop rcx
260 pop rsi
262 ; -----------------------------------------------------------------------------
265 ; =============================================================================
266 ; EOF