mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-11-22 20:06:40 +00:00
[stage2] Add "hexdump"
This commit is contained in:
parent
0d5796fa0b
commit
c71e7c8c2e
2 changed files with 38 additions and 0 deletions
|
@ -6,6 +6,8 @@
|
|||
#include "panic_color.h"
|
||||
#include "timers.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
__attribute__ ((noreturn)) void panic(uint32_t code) {
|
||||
/* Set Panic Code for NX_BOOTLOADER. */
|
||||
|
@ -38,3 +40,37 @@ __attribute__((noinline)) bool overlaps(uint64_t as, uint64_t ae, uint64_t bs, u
|
|||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Adapted from https://gist.github.com/ccbrown/9722406 */
|
||||
void hexdump(const void* data, size_t size, uintptr_t addrbase) {
|
||||
const uint8_t *d = (const uint8_t *)data;
|
||||
char ascii[17];
|
||||
ascii[16] = '\0';
|
||||
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
if (i % 16 == 0) {
|
||||
printf("%0*" PRIXPTR ": | ", 2 * sizeof(addrbase), addrbase + i);
|
||||
}
|
||||
printf("%02X ", d[i]);
|
||||
if (d[i] >= ' ' && d[i] <= '~') {
|
||||
ascii[i % 16] = d[i];
|
||||
} else {
|
||||
ascii[i % 16] = '.';
|
||||
}
|
||||
if ((i+1) % 8 == 0 || i+1 == size) {
|
||||
printf(" ");
|
||||
if ((i+1) % 16 == 0) {
|
||||
printf("| %s \n", ascii);
|
||||
} else if (i+1 == size) {
|
||||
ascii[(i+1) % 16] = '\0';
|
||||
if ((i+1) % 16 <= 8) {
|
||||
printf(" ");
|
||||
}
|
||||
for (size_t j = (i+1) % 16; j < 16; j++) {
|
||||
printf(" ");
|
||||
}
|
||||
printf("| %s \n", ascii);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,6 +102,8 @@ static inline bool check_32bit_address_range_in_program(uintptr_t addr, size_t s
|
|||
overlaps_a(start, end, __start__, __end__);
|
||||
}
|
||||
|
||||
void hexdump(const void* data, size_t size, uintptr_t addrbase);
|
||||
|
||||
void panic(uint32_t code);
|
||||
void generic_panic(void);
|
||||
void panic_predefined(uint32_t which);
|
||||
|
|
Loading…
Reference in a new issue