no more PF in kmain, but still PF in process OR corruption of fb
This commit is contained in:
@@ -1,3 +1,7 @@
|
|||||||
target remote localhost:1234
|
target remote localhost:1234
|
||||||
set disassembly-flavor intel
|
set disassembly-flavor intel
|
||||||
display/4i $rip
|
display/4i $rip
|
||||||
|
|
||||||
|
# Trying to debug that flanterm page fault
|
||||||
|
|
||||||
|
# b plot_char_unscaled_uncanvas if $rdi == 0 || $rsi == 0 || $rdx == 0 || $r10 == 0
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
#define PEPPEROS_VERSION_MAJOR "0"
|
#define PEPPEROS_VERSION_MAJOR "0"
|
||||||
#define PEPPEROS_VERSION_MINOR "0"
|
#define PEPPEROS_VERSION_MINOR "0"
|
||||||
#define PEPPEROS_VERSION_PATCH "58"
|
#define PEPPEROS_VERSION_PATCH "58"
|
||||||
#define PEPPEROS_SPLASH "pepperOS version "PEPPEROS_VERSION_MAJOR"."PEPPEROS_VERSION_MINOR"."PEPPEROS_VERSION_PATCH"\n"
|
#define PEPPEROS_SPLASH "\x1b[38;5;196mPepperOS\x1b[0m version "PEPPEROS_VERSION_MAJOR"."PEPPEROS_VERSION_MINOR"."PEPPEROS_VERSION_PATCH"\n"
|
||||||
|
|
||||||
/* process */
|
/* process */
|
||||||
#define PROCESS_NAME_MAX 64
|
#define PROCESS_NAME_MAX 64
|
||||||
|
|||||||
@@ -9,7 +9,9 @@ void panic(struct cpu_status_t* ctx, const char* str)
|
|||||||
if (ctx == NULL)
|
if (ctx == NULL)
|
||||||
{
|
{
|
||||||
DEBUG("\x1b[38;5;231m\x1b[48;5;196mKernel panic!!!\x1b[0m Something went horribly wrong! (no cpu ctx)");
|
DEBUG("\x1b[38;5;231m\x1b[48;5;196mKernel panic!!!\x1b[0m Something went horribly wrong! (no cpu ctx)");
|
||||||
|
fctprintf((void*)&skputc, 0, "\x1b[38;5;231m\x1b[48;5;27m");
|
||||||
DIE_DEBUG(str);
|
DIE_DEBUG(str);
|
||||||
|
fctprintf((void*)&skputc, 0, "\x1b[0m");
|
||||||
skputc('\r');
|
skputc('\r');
|
||||||
skputc('\n');
|
skputc('\n');
|
||||||
DEBUG("\x1b[38;5;231m\x1b[48;5;196mend Kernel panic - halting...\x1b[0m");
|
DEBUG("\x1b[38;5;231m\x1b[48;5;196mend Kernel panic - halting...\x1b[0m");
|
||||||
|
|||||||
@@ -25,6 +25,8 @@
|
|||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <kernel.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#error "Please do not compile Flanterm as C++ code! Flanterm should be compiled as C99 or newer."
|
#error "Please do not compile Flanterm as C++ code! Flanterm should be compiled as C99 or newer."
|
||||||
#endif
|
#endif
|
||||||
@@ -662,6 +664,17 @@ static void plot_char_unscaled_canvas(struct flanterm_context *_ctx, struct flan
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void plot_char_unscaled_uncanvas(struct flanterm_context *_ctx, struct flanterm_fb_char *c, size_t x, size_t y) {
|
static void plot_char_unscaled_uncanvas(struct flanterm_context *_ctx, struct flanterm_fb_char *c, size_t x, size_t y) {
|
||||||
|
|
||||||
|
if (_ctx == NULL)
|
||||||
|
{
|
||||||
|
panic(NULL, "plot_char_unscaled_uncanvas: _ctx is NULL");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c == NULL)
|
||||||
|
{
|
||||||
|
panic(NULL, "plot_char_unscaled_uncanvas: c is NULL");
|
||||||
|
}
|
||||||
|
|
||||||
struct flanterm_fb_context *ctx = (void *)_ctx;
|
struct flanterm_fb_context *ctx = (void *)_ctx;
|
||||||
|
|
||||||
if (x >= _ctx->cols || y >= _ctx->rows) {
|
if (x >= _ctx->cols || y >= _ctx->rows) {
|
||||||
@@ -953,6 +966,12 @@ static void draw_cursor(struct flanterm_context *_ctx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void flanterm_fb_double_buffer_flush(struct flanterm_context *_ctx) {
|
static void flanterm_fb_double_buffer_flush(struct flanterm_context *_ctx) {
|
||||||
|
|
||||||
|
if (_ctx == NULL)
|
||||||
|
{
|
||||||
|
panic(NULL, "flanterm_fb_double_buffer_flush: _ctx is NULL");
|
||||||
|
}
|
||||||
|
|
||||||
struct flanterm_fb_context *ctx = (void *)_ctx;
|
struct flanterm_fb_context *ctx = (void *)_ctx;
|
||||||
|
|
||||||
if (_ctx->cursor_enabled) {
|
if (_ctx->cursor_enabled) {
|
||||||
|
|||||||
31
src/kmain.c
31
src/kmain.c
File diff suppressed because one or more lines are too long
@@ -23,40 +23,36 @@ static uintptr_t end;
|
|||||||
// Kernel root table (level 4)
|
// Kernel root table (level 4)
|
||||||
extern uint64_t *kernel_pml4;
|
extern uint64_t *kernel_pml4;
|
||||||
|
|
||||||
static void kheap_grow(size_t size)
|
|
||||||
{
|
|
||||||
size_t pages = ALIGN_UP(size + sizeof(struct heap_block_t), PAGE_SIZE) / PAGE_SIZE;
|
|
||||||
|
|
||||||
if (pages == 0) pages = 1;
|
|
||||||
|
|
||||||
for (size_t i = 0; i < pages; i++)
|
|
||||||
{
|
|
||||||
kheap_map_page();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void kheap_map_page()
|
|
||||||
{
|
|
||||||
uintptr_t phys = pmm_alloc();
|
|
||||||
paging_map_page(kernel_pml4, end, phys, PTE_PRESENT | PTE_WRITABLE | PTE_NOEXEC);
|
|
||||||
end += PAGE_SIZE;
|
|
||||||
//DEBUG("Mapped first kheap page");
|
|
||||||
}
|
|
||||||
|
|
||||||
void kheap_init()
|
void kheap_init()
|
||||||
{
|
{
|
||||||
kheap_start = ALIGN_UP(kernel_virt_base + KERNEL_SIZE, PAGE_SIZE);
|
kheap_start = ALIGN_UP(kernel_virt_base + KERNEL_SIZE, PAGE_SIZE);
|
||||||
end = kheap_start;
|
|
||||||
|
|
||||||
// At least 1 page must be mapped for it to work
|
size_t heap_pages = ALIGN_UP(KHEAP_SIZE, PAGE_SIZE) / PAGE_SIZE;
|
||||||
kheap_map_page();
|
DEBUG("Mapping %d kernel heap pages at 0x%p", heap_pages, kheap_start);
|
||||||
|
|
||||||
|
uintptr_t current_addr = kheap_start;
|
||||||
|
|
||||||
|
// Map/alloc enough pages for heap (KHEAP_SIZE)
|
||||||
|
for (size_t i=0; i<heap_pages; i++)
|
||||||
|
{
|
||||||
|
uintptr_t phys = pmm_alloc();
|
||||||
|
if (phys == 0)
|
||||||
|
{
|
||||||
|
panic(NULL, "Not enough memory available to initialize kernel heap.");
|
||||||
|
}
|
||||||
|
|
||||||
|
paging_map_page(kernel_pml4, current_addr, phys, PTE_PRESENT | PTE_WRITABLE);
|
||||||
|
current_addr += PAGE_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
end = current_addr;
|
||||||
|
|
||||||
// Give linked list head its properties
|
// Give linked list head its properties
|
||||||
head = (struct heap_block_t*)kheap_start;
|
head = (struct heap_block_t*)kheap_start;
|
||||||
head->size = PAGE_SIZE - sizeof(struct heap_block_t);
|
head->size = (end-kheap_start) - sizeof(struct heap_block_t);
|
||||||
head->free = true;
|
head->free = true;
|
||||||
head->next = NULL;
|
head->next = NULL;
|
||||||
DEBUG("kernel heap initialized, head=0x%p, max_size=%u bytes", head, KHEAP_SIZE);
|
DEBUG("Kernel heap initialized, head=0x%p, size=%u bytes", head, head->size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void* kmalloc(size_t size)
|
void* kmalloc(size_t size)
|
||||||
@@ -73,12 +69,12 @@ void* kmalloc(size_t size)
|
|||||||
if (curr->free && curr->size >= size)
|
if (curr->free && curr->size >= size)
|
||||||
{
|
{
|
||||||
// We split the block if it is big enough
|
// We split the block if it is big enough
|
||||||
if (curr->size >= size + BLOCK_MIN_SIZE)
|
if (curr->size >= size + sizeof(struct heap_block_t) + 16)
|
||||||
{
|
{
|
||||||
//struct heap_block_t* new_block = (struct heap_block_t*)((uintptr_t)curr + sizeof(struct heap_block_t) + size);
|
//struct heap_block_t* new_block = (struct heap_block_t*)((uintptr_t)curr + sizeof(struct heap_block_t) + size);
|
||||||
struct heap_block_t* split = (struct heap_block_t*)((uintptr_t)curr + sizeof(*curr) + size);
|
struct heap_block_t* split = (struct heap_block_t*)((uintptr_t)curr + sizeof(struct heap_block_t) + size);
|
||||||
|
|
||||||
split->size = curr->size - size - sizeof(*curr);
|
split->size = curr->size - size - sizeof(struct heap_block_t);
|
||||||
split->free = true;
|
split->free = true;
|
||||||
split->next = curr->next;
|
split->next = curr->next;
|
||||||
|
|
||||||
@@ -94,25 +90,12 @@ void* kmalloc(size_t size)
|
|||||||
curr = curr->next;
|
curr = curr->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we're here it means we didn't have enough memory
|
// No growing. If we're here it means the initial pool
|
||||||
// for the block allocation. So we will allocate more..
|
// wasn't sufficient. Too bad.
|
||||||
uintptr_t old_end = end;
|
DEBUG("Kernel heap is OUT OF MEMORY!");
|
||||||
kheap_grow(size + sizeof(struct heap_block_t));
|
// if we were terrorists maybe we should panic
|
||||||
|
// or just wait for others to free stuff?
|
||||||
struct heap_block_t* block = (struct heap_block_t*)old_end;
|
return NULL;
|
||||||
block->size = ALIGN_UP(end - old_end - sizeof(struct heap_block_t), 16);
|
|
||||||
block->free = true;
|
|
||||||
block->next = NULL;
|
|
||||||
|
|
||||||
// Put the block at the end of the list
|
|
||||||
curr = head;
|
|
||||||
while (curr->next)
|
|
||||||
{
|
|
||||||
curr = curr->next;
|
|
||||||
}
|
|
||||||
curr->next = block;
|
|
||||||
|
|
||||||
return kmalloc(size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void kfree(void* ptr)
|
void kfree(void* ptr)
|
||||||
|
|||||||
@@ -14,13 +14,15 @@
|
|||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
struct heap_block_t
|
struct heap_block_t
|
||||||
{
|
{
|
||||||
size_t size;
|
size_t size;
|
||||||
bool free;
|
bool free; // 1byte
|
||||||
|
uint8_t reserved[7]; // (7+1 = 8 bytes)
|
||||||
struct heap_block_t* next;
|
struct heap_block_t* next;
|
||||||
};
|
} __attribute__((aligned(16)));
|
||||||
|
|
||||||
void kheap_init();
|
void kheap_init();
|
||||||
void* kmalloc(size_t size);
|
void* kmalloc(size_t size);
|
||||||
|
|||||||
@@ -21,6 +21,18 @@ void scheduler_init()
|
|||||||
|
|
||||||
struct cpu_status_t* scheduler_schedule(struct cpu_status_t* context)
|
struct cpu_status_t* scheduler_schedule(struct cpu_status_t* context)
|
||||||
{
|
{
|
||||||
|
if (context == NULL)
|
||||||
|
{
|
||||||
|
panic(NULL, "Scheduler called with NULL context");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (current_process == NULL)
|
||||||
|
{
|
||||||
|
// Wtf happened
|
||||||
|
current_process = processes_list;
|
||||||
|
//panic(NULL, "Scheduler called without current process");
|
||||||
|
}
|
||||||
|
|
||||||
current_process->context = context;
|
current_process->context = context;
|
||||||
//current_process->status = READY;
|
//current_process->status = READY;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
; Task (process) switching
|
|
||||||
|
|
||||||
bits 64
|
|
||||||
|
|
||||||
global switch_to_task
|
|
||||||
switch_to_task:
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user