1 ; =============================================================================
2 ; BareMetal -- a 64-bit OS written in Assembly for x86-64 systems
3 ; Copyright (C) 2008-2011 Return Infinity -- see LICENSE.TXT
6 ; =============================================================================
13 ; -----------------------------------------------------------------------------
14 ; os_debug_dump_reg -- Dump the values on the registers to the screen (For debug purposes)
16 ; OUT: Nothing, all registers preserved
18 pushfq
; Push the registers used by this function
23 pushfq
; Push the flags to the stack
24 push r15
; Push all of the registers to the stack
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
46 mov al, [os_debug_dump_reg_stage
]
47 mov bl, 5 ; Each string is 5 bytes
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
71 mov rsi
, os_debug_dump_flag_string1
; Print the Zero flag
83 mov rsi
, os_debug_dump_flag_string2
; Print the Sign flag
95 mov rsi
, os_debug_dump_flag_string3
; Print the Direction flag
107 mov rsi
, os_debug_dump_flag_string4
; Print the Overflow flag
120 os_debug_dump_reg_done:
121 call os_print_newline
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
138 push rdx
; total number of bytes to display
139 push rbx
; color attribute
141 mov bl, 0x07 ; Default of light grey on black
144 je os_debug_dump_mem_done
145 mov rdx
, rcx
; Save the total number of bytes to display
150 os_debug_dump_mem_print_address:
152 call os_debug_dump_rax
157 xor rcx
, rcx
; Clear the counter
159 os_debug_dump_mem_next_byte_hex:
161 call os_print_char_hex_with_color
162 xor bl, 10000000b ; Toggle between light grey on black and light grey on dark grey
165 jne os_debug_dump_mem_next_byte_hex
172 xor rcx
, rcx
; Clear the counter
174 os_debug_dump_mem_next_byte_ascii:
176 call os_print_char_with_color
177 xor bl, 10000000b ; Toggle between light grey on black and light grey on dark grey
180 jne os_debug_dump_mem_next_byte_ascii
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:
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
206 call os_print_char_hex
208 call os_print_char_hex
210 call os_print_char_hex
212 call os_print_char_hex
216 call os_print_char_hex
218 call os_print_char_hex
222 call os_print_char_hex
225 call os_print_char_hex
227 ; -----------------------------------------------------------------------------
230 ; -----------------------------------------------------------------------------
231 ; os_debug_get_ip -- Dump content of RIP into RAX
237 ; -----------------------------------------------------------------------------
240 ; -----------------------------------------------------------------------------
241 ; os_debug_dump_MAC -- Dump MAC address to screen
243 ; OUT: Nothing, all registers preserved
251 os_debug_dump_MAC_display:
253 call os_debug_dump_al
256 jnz os_debug_dump_MAC_display
262 ; -----------------------------------------------------------------------------
265 ; =============================================================================