mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-05-27 15:04:33 +00:00
Added dumper library
This commit is contained in:
parent
06c217fdcc
commit
b809cab953
61
Library/dumper.cpp
Normal file
61
Library/dumper.cpp
Normal file
@ -0,0 +1,61 @@
|
||||
#include "dumper.hpp"
|
||||
|
||||
#include <printf.h>
|
||||
#include <uart.hpp>
|
||||
|
||||
using namespace UniversalAsynchronousReceiverTransmitter;
|
||||
|
||||
static inline void print_wrapper(char c, void *unused)
|
||||
{
|
||||
UART(COM1).Write(c);
|
||||
UNUSED(unused);
|
||||
}
|
||||
|
||||
int vprintf(const char *format, va_list list) { return vfctprintf(print_wrapper, NULL, format, list); }
|
||||
|
||||
void WriteRaw(const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
vprintf(format, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void DumpData(const char *Description, void *Address, unsigned long Length)
|
||||
{
|
||||
WriteRaw("-------------------------------------------------------------------------\n");
|
||||
unsigned char *AddressChar = (unsigned char *)Address;
|
||||
unsigned char Buffer[17];
|
||||
unsigned long Iterate;
|
||||
|
||||
if (Description != nullptr)
|
||||
WriteRaw("%s:\n", Description);
|
||||
|
||||
for (Iterate = 0; Iterate < Length; Iterate++)
|
||||
{
|
||||
if ((Iterate % 16) == 0)
|
||||
{
|
||||
if (Iterate != 0)
|
||||
WriteRaw(" %s\n", Buffer);
|
||||
WriteRaw(" %04x ", Iterate);
|
||||
}
|
||||
|
||||
WriteRaw(" %02x", AddressChar[Iterate]);
|
||||
|
||||
if ((AddressChar[Iterate] < 0x20) || (AddressChar[Iterate] > 0x7e))
|
||||
Buffer[Iterate % 16] = '.';
|
||||
else
|
||||
Buffer[Iterate % 16] = AddressChar[Iterate];
|
||||
|
||||
Buffer[(Iterate % 16) + 1] = '\0';
|
||||
}
|
||||
|
||||
while ((Iterate % 16) != 0)
|
||||
{
|
||||
WriteRaw(" ");
|
||||
Iterate++;
|
||||
}
|
||||
|
||||
WriteRaw(" %s\n", Buffer);
|
||||
WriteRaw("-------------------------------------------------------------------------\n");
|
||||
}
|
8
include/dumper.hpp
Normal file
8
include/dumper.hpp
Normal file
@ -0,0 +1,8 @@
|
||||
#ifndef __FENNIX_LIB_DUMPER_H__
|
||||
#define __FENNIX_LIB_DUMPER_H__
|
||||
|
||||
#include <types.h>
|
||||
|
||||
void DumpData(const char *Description, void *Address, unsigned long Length);
|
||||
|
||||
#endif // !__FENNIX_LIB_DUMPER_H__
|
Loading…
x
Reference in New Issue
Block a user