feature: print_stack working (dont use opti flags, else the stack is broken)
This commit is contained in:
parent
963bf46b62
commit
a02931a165
4
Makefile
4
Makefile
@ -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
8
headers/debug.h
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
struct stackframe {
|
||||||
|
struct stackframe *ebp;
|
||||||
|
uint32_t eip;
|
||||||
|
};
|
@ -3,30 +3,30 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#define GDT_ADDRESS 0x00000800
|
#define GDT_ADDRESS 0x00000800
|
||||||
#define GDT_SIZE 7
|
#define GDT_SIZE 7
|
||||||
|
|
||||||
// https://wiki.osdev.org/Global_Descriptor_Table#GDTR
|
// https://wiki.osdev.org/Global_Descriptor_Table#GDTR
|
||||||
struct gdt_descriptor {
|
struct gdt_descriptor {
|
||||||
uint16_t size;
|
uint16_t size;
|
||||||
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
|
||||||
#define GDT_FLAG_PAGE_MODE 0b1000
|
#define GDT_FLAG_PAGE_MODE 0b1000
|
||||||
#define GDT_FLAG_BYTE_MODE 0b1000
|
#define GDT_FLAG_BYTE_MODE 0b1000
|
||||||
|
|
||||||
#define GDT_ACCESS_P_VALID 0b10000000
|
#define GDT_ACCESS_P_VALID 0b10000000
|
||||||
#define GDT_ACCESS_DPL_KERNEL_MODE 0b00000000
|
#define GDT_ACCESS_DPL_KERNEL_MODE 0b00000000
|
||||||
#define GDT_ACCESS_DPL_USER_MODE 0b01100000
|
#define GDT_ACCESS_DPL_USER_MODE 0b01100000
|
||||||
#define GDT_ACCESS_S_CODE_OR_DATA 0b00010000
|
#define GDT_ACCESS_S_CODE_OR_DATA 0b00010000
|
||||||
#define GDT_ACCESS_S_SYSTEM_SEGMENT 0b00010000
|
#define GDT_ACCESS_S_SYSTEM_SEGMENT 0b00010000
|
||||||
#define GDT_ACCESS_E_EXECUTABLE 0b00001000
|
#define GDT_ACCESS_E_EXECUTABLE 0b00001000
|
||||||
#define GDT_ACCESS_E_NOT_EXECUTABLE 0b00000000
|
#define GDT_ACCESS_E_NOT_EXECUTABLE 0b00000000
|
||||||
#define GDT_ACCESS_DC_CONFORM 0b00000100 // TODO UNDERSTAND THIS BIT
|
#define GDT_ACCESS_DC_CONFORM 0b00000100 // TODO UNDERSTAND THIS BIT
|
||||||
#define GDT_ACCESS_DC_NOT_CONFORM 0b00000000
|
#define GDT_ACCESS_DC_NOT_CONFORM 0b00000000
|
||||||
#define GDT_ACCESS_RW_READABLE_FOR_CODE_WRITABLE_FOR_DATA 0b00000010
|
#define GDT_ACCESS_RW_READABLE_FOR_CODE_WRITABLE_FOR_DATA 0b00000010
|
||||||
#define GDT_ACCESS_A_ACCESSED 0b00000001
|
#define GDT_ACCESS_A_ACCESSED 0b00000001
|
||||||
#define GDT_ACCESS_A_NOT_ACCESSED 0b00000000
|
#define GDT_ACCESS_A_NOT_ACCESSED 0b00000000
|
||||||
|
@ -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
13
src/debug/print_stack.c
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
@ -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 |
|
||||||
|
@ -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();
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user