feature: print_stack working (dont use opti flags, else the stack is broken)

This commit is contained in:
0x35c 2024-09-17 11:10:41 +02:00
parent 963bf46b62
commit a02931a165
10 changed files with 53 additions and 25 deletions

View File

@ -3,9 +3,9 @@ NAME := bozOS
AS := i386-elf-as AS := i386-elf-as
ASFLAGS := ASFLAGS :=
CC := i386-elf-gcc CC := i386-elf-gcc
CFLAGS := -std=gnu99 -ffreestanding -O2 -Wall -Wextra -iquotelibbozo/headers -iquoteheaders -MMD -g CFLAGS := -std=gnu99 -ffreestanding -Wall -Wextra -iquotelibbozo/headers -iquoteheaders -MMD -fno-omit-frame-pointer -g
LD := $(CC) LD := $(CC)
LDFLAGS := -T boot/linker.ld -ffreestanding -O2 -nostdlib LDFLAGS := -T boot/linker.ld -ffreestanding -nostdlib
LIBS := -L libbozo/build/ -lbozo -lgcc LIBS := -L libbozo/build/ -lbozo -lgcc
SSRC := $(shell find src -name '*.s') SSRC := $(shell find src -name '*.s')

8
headers/debug.h Normal file
View File

@ -0,0 +1,8 @@
#pragma once
#include <stdint.h>
struct stackframe {
struct stackframe *ebp;
uint32_t eip;
};

View File

@ -11,7 +11,7 @@ struct gdt_descriptor {
uint32_t base; uint32_t base;
} __attribute__((packed)); } __attribute__((packed));
void initGdt(); void init_gdt();
#define GDT_FLAG_64BIT_MODE 0b0010 #define GDT_FLAG_64BIT_MODE 0b0010
#define GDT_FLAG_32BIT_MODE 0b0100 #define GDT_FLAG_32BIT_MODE 0b0100

View File

@ -48,6 +48,7 @@ typedef enum {
REBOOT, REBOOT,
POWEROFF, POWEROFF,
HALT, HALT,
STACK,
ECHO, ECHO,
COLOR, COLOR,
MERDELLA, MERDELLA,
@ -57,3 +58,4 @@ typedef enum {
void reboot(void); void reboot(void);
void halt(void); void halt(void);
void shell_init(void); void shell_init(void);
void print_stack(void);

13
src/debug/print_stack.c Normal file
View File

@ -0,0 +1,13 @@
#include "debug.h"
#include "kprintf.h"
void print_stack(void)
{
struct stackframe *stack =
(struct stackframe *)__builtin_frame_address(0);
while (stack) {
kprintf(0, "stack->ebp: %d\n", stack->ebp);
stack = stack->ebp;
}
}

View File

@ -34,10 +34,10 @@ static void set_gdt_entry_value(uint8_t *target, uint32_t base, uint32_t limit,
target[6] |= (granularity << 4); target[6] |= (granularity << 4);
} }
void initGdt(void) void init_gdt(void)
{ {
gdtr->size = 8 * GDT_SIZE - 1; gdtr->size = 8 * GDT_SIZE - 1;
gdtr->base = (uint32_t)&gdt_entries; gdtr->base = (uint32_t)&gdt_entries[0];
set_gdt_entry_value(gdt_entries + 0x00, 0, 0, 0, 0); // Null segment set_gdt_entry_value(gdt_entries + 0x00, 0, 0, 0, 0); // Null segment
@ -58,7 +58,7 @@ void initGdt(void)
GDT_ACCESS_A_ACCESSED, GDT_ACCESS_A_ACCESSED,
GDT_FLAG_32BIT_MODE | GDT_FLAG_PAGE_MODE); // Kernel data GDT_FLAG_32BIT_MODE | GDT_FLAG_PAGE_MODE); // Kernel data
set_gdt_entry_value( set_gdt_entry_value(
gdt_entries + 0x18, 0, 0x0, gdt_entries + 0x18, 0, 0xFFFFF,
GDT_ACCESS_P_VALID | GDT_ACCESS_DPL_KERNEL_MODE | GDT_ACCESS_P_VALID | GDT_ACCESS_DPL_KERNEL_MODE |
GDT_ACCESS_S_CODE_OR_DATA | GDT_ACCESS_E_NOT_EXECUTABLE | GDT_ACCESS_S_CODE_OR_DATA | GDT_ACCESS_E_NOT_EXECUTABLE |
GDT_ACCESS_DC_CONFORM | GDT_ACCESS_DC_CONFORM |

View File

@ -24,6 +24,6 @@ void kernel_main(void)
/* Initialize terminal interface */ /* Initialize terminal interface */
terminal_initialize(); terminal_initialize();
initGdt(); init_gdt();
shell_init(); shell_init();
} }

View File

@ -29,6 +29,8 @@ static CMD_TOK find_command(char *line)
command = POWEROFF; command = POWEROFF;
else if (!strcmp(line, "halt")) else if (!strcmp(line, "halt"))
command = HALT; command = HALT;
else if (!strcmp(line, "stack"))
command = STACK;
else if (!strcmp(line, "echo")) else if (!strcmp(line, "echo"))
command = ECHO; command = ECHO;
else if (!strcmp(line, "color")) else if (!strcmp(line, "color"))
@ -95,6 +97,9 @@ void shell_init(void)
case HALT: case HALT:
halt(); halt();
break; break;
case STACK:
print_stack();
break;
case ECHO: case ECHO:
kprintf(0, "echoing\n"); kprintf(0, "echoing\n");
break; break;

View File

@ -27,8 +27,8 @@ void reboot(void)
} while (check_flag(tmp, KBD_BIT_UDATA)); } while (check_flag(tmp, KBD_BIT_UDATA));
outb(KBD_INTERFACE, KBD_RESET); /* pulse CPU reset line */ outb(KBD_INTERFACE, KBD_RESET); /* pulse CPU reset line */
loop: loop:
asm volatile("hlt"); /* if that didn't work, halt the CPU */ asm volatile("hlt");
goto loop; /* if a NMI is received, halt again */ goto loop;
} }
void halt(void) void halt(void)

View File