MonkOS  v0.1
A simple 64-bit operating system (x86_64)
dump.h
Go to the documentation of this file.
1 //============================================================================
2 /// @file dump.h
3 /// @brief Debugging memory and CPU state dump routines.
4 //
5 // Copyright 2016 Brett Vickers.
6 // Use of this source code is governed by a BSD-style license
7 // that can be found in the MonkOS LICENSE file.
8 //============================================================================
9 
10 #pragma once
11 
12 #include <core.h>
13 #include <kernel/x86/cpu.h>
14 
15 //----------------------------------------------------------------------------
16 // @function dump_registers
17 /// @brief Dump the contents of a CPU registers structure to a string
18 /// buffer.
19 /// @param[in] buf Pointer to the character buffer to hold the resulting
20 /// null-terminated string.
21 /// @param[in] bufsize Size of the buffer used to hold the string.
22 /// @param[in] regs Pointer to a CPU registers structure.
23 /// @returns The number of characters that would have been written to the
24 /// buffer if n had been sufficiently large.
25 //----------------------------------------------------------------------------
26 int
27 dump_registers(char *buf, size_t bufsize, const registers_t *regs);
28 
29 //----------------------------------------------------------------------------
30 // @function dump_cpuflags
31 /// @brief Dump the contents of the CPU flags register.
32 /// @param[in] buf Pointer to the character buffer to hold the resulting
33 /// null-terminated string.
34 /// @param[in] bufsize Size of the buffer used to hold the string.
35 /// @param[in] rflags The 64-bit rflags register value.
36 /// @returns The number of characters that would have been written to the
37 /// buffer if n had been sufficiently large.
38 //----------------------------------------------------------------------------
39 int
40 dump_cpuflags(char *buf, size_t bufsize, uint64_t rflags);
41 
42 //----------------------------------------------------------------------------
43 // @enum dumpstyle
44 /// @brief Memory dump output style.
45 /// @details Used to select how the memory address is displayed in a
46 /// a memory dump.
47 //----------------------------------------------------------------------------
49 {
50  DUMPSTYLE_NOADDR = 0, ///< No address or offset in memory dump.
51  DUMPSTYLE_ADDR = 1, ///< Include full address in memory dump.
52  DUMPSTYLE_OFFSET = 2, ///< Include address offset in memory dump.
53 };
54 
55 //----------------------------------------------------------------------------
56 // @function dump_memory
57 /// @brief Dump the contents of memory.
58 /// @param[in] buf Pointer to the character buffer to hold the resulting
59 /// null-terminated string.
60 /// @param[in] bufsize Size of the buffer used to hold the string.
61 /// @param[in] mem Pointer to the first byte of memory to dump.
62 /// @param[in] memsize Number of memory bytes to dump.
63 /// @param[in] style The output style used for the memory dump.
64 /// @returns The number of characters that would have been written to the
65 /// buffer if n had been sufficiently large.
66 //----------------------------------------------------------------------------
67 int
68 dump_memory(char *buf, size_t bufsize, const void *mem, size_t memsize,
69  enum dumpstyle style);
Core include file.
No address or offset in memory dump.
Definition: dump.h:50
A record describing all 64-bit general-purpose registers.
Definition: cpu.h:38
Include address offset in memory dump.
Definition: dump.h:52
int dump_cpuflags(char *buf, size_t bufsize, uint64_t rflags)
Dump the contents of the CPU flags register.
Definition: dump.c:33
dumpstyle
Memory dump output style.
Definition: dump.h:48
int dump_registers(char *buf, size_t bufsize, const registers_t *regs)
Dump the contents of a CPU registers structure to a string buffer.
Definition: dump.c:16
x86 CPU-specific function implementations.
Include full address in memory dump.
Definition: dump.h:51
int dump_memory(char *buf, size_t bufsize, const void *mem, size_t memsize, enum dumpstyle style)
Dump the contents of memory.
Definition: dump.c:50