Skip to content

Commit

Permalink
Fix stack addresses + minor correction
Browse files Browse the repository at this point in the history
- Fix stack top/bottom addresses in print_stack function.
- Make use of the BUFSIZE define as the read limit.
- Take a void* as hexdump base parameter.

Signed-off-by: mrxx0 <[email protected]>
  • Loading branch information
mrxx0 authored and xlmod committed Nov 21, 2022
1 parent 48eafee commit 31b992d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion include/kernel/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#include <stdint.h>

void hexdump(uint32_t *base, uint32_t limit);
void hexdump(void *base, uint32_t limit);
void print_stack();

#endif
12 changes: 7 additions & 5 deletions kernel/memory/hexdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,22 @@ static int hexdump_diaplay_char(int c) {
* @limit is number of bytes we want to print
*
*/
void hexdump(uint8_t *base, uint32_t limit) {
void hexdump(void *base, uint32_t limit) {
struct kbd_event evt;
uint32_t l = 0, i = 0;
uint8_t oldcolor = vga.color;
uint8_t *p = (uint8_t *)base;

VGA_setforegroundcolor(VGA_COLOR_WHITE);
while (i < limit) {
kprintf("%8p: ", base + i);
kprintf("%8p: ", p + i);
for (uint32_t j = i; j < limit && j < i + 16; j++) {
VGA_setforegroundcolor(base[j] ? VGA_COLOR_LIGHT_GREEN : VGA_COLOR_WHITE);
kprintf("%2x ", base[j]);
VGA_setforegroundcolor(p[j] ? VGA_COLOR_LIGHT_GREEN : VGA_COLOR_WHITE);
kprintf("%2x ", p[j]);
}
kprintf(" ");
for (uint32_t j = i; j < limit && j < i + 16; j++) {
kprintf("%c", hexdump_diaplay_char(base[j]));
kprintf("%c", hexdump_diaplay_char(p[j]));
}
l += 1;
if (l == VGA_HEIGHT) {
Expand All @@ -76,3 +77,4 @@ void hexdump(uint8_t *base, uint32_t limit) {
}
vga.color = oldcolor;
}

8 changes: 4 additions & 4 deletions kernel/memory/print_stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
* Helper function to print the kernel stack
*
* created: 2022/11/19 - lfalkau <[email protected]>
* updated: 2022/11/19 - lfalkau <lfalkau@student.42.fr>
* updated: 2022/11/21 - mrxx0 <chcoutur@student.42.fr>
*/

#include <kernel/memory.h>

extern uint32_t *stack_bottom;
extern void *stack_bottom;
extern void *stack_top;

void print_stack() {
uint32_t stack_size = 16384;
hexdump(stack_bottom, stack_size);
hexdump(&stack_bottom, (void *)&stack_top - (void *)&stack_bottom);
}
2 changes: 1 addition & 1 deletion kernel/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ static void handle_command()
*/
static void fill_buffer(char c, uint8_t i)
{
if (i < 20)
if (i < BUFSIZE - 1)
buffer[i] = c;
}

Expand Down

0 comments on commit 31b992d

Please sign in to comment.