From 774e3796b252383aafb8b3f30d51a19400c74516 Mon Sep 17 00:00:00 2001 From: Brett Weiland Date: Sun, 18 Apr 2021 16:00:17 -0500 Subject: modified: src/bootloader/bios_functions/bios_disk.asm modified: src/bootloader/bootloader.asm new file: src/include/kernel.h modified: src/include/libc.h modified: src/include/paging.h new file: src/include/panic.h modified: src/kernel/kernel.c modified: src/kernel/libc.c modified: src/kernel/page.c new file: src/kernel/panic.c modified: src/link.ld modified: src/makefile modified: tools/page/page.py --- src/include/kernel.h | 5 +++++ src/include/libc.h | 9 +++++---- src/include/paging.h | 39 ++++++++++++++++++++++++++++++++------- src/include/panic.h | 27 +++++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 11 deletions(-) create mode 100644 src/include/kernel.h create mode 100644 src/include/panic.h (limited to 'src/include') diff --git a/src/include/kernel.h b/src/include/kernel.h new file mode 100644 index 0000000..2a87f5e --- /dev/null +++ b/src/include/kernel.h @@ -0,0 +1,5 @@ +#define EASTEREGG_BLOATWARE //TODO move to some kind of global config file +void panic(); + +#define KERNEL_PANIC_INVOKED 0 +//more to come diff --git a/src/include/libc.h b/src/include/libc.h index cdf6dbc..c7ccda7 100644 --- a/src/include/libc.h +++ b/src/include/libc.h @@ -2,11 +2,12 @@ #define _STRING_H_ #include +void *strcpy(char *dest, char *src); +void *memcpy(void *dest, void *src, size_t n); //TODO +void *bzero(const void *dest, size_t size); +void *memset(void *s, char c, size_t n); int strcmp(const char *str1, const char *str2); int strncmp(const char *str1, const char *str2, size_t n); -void strcpy(char *dest, char *src); -void memcpy(void *dest, void *src, size_t n); //TODO int memcmp(const void *s1, const void *s2, size_t n); -void bzero(const void *dest, size_t size); -int ceil(float n1); +int ceil(double n1); #endif diff --git a/src/include/paging.h b/src/include/paging.h index 267da43..3d31ef2 100644 --- a/src/include/paging.h +++ b/src/include/paging.h @@ -45,19 +45,38 @@ typedef struct __attribute__((packed)) { #define PAGE_SIZE_2M 21 #define PAGE_SIZE_1G 30 +#define MAX_BUDDY_ORDER 8 + +#define MAX_ZONE_CNT 16 //should cover all cases + struct memory_table { - uint64_t base; + void *base; uint64_t length; uint32_t type; uint32_t ACPI; } __attribute__((packed)); +/** + * the bsizes are there so we don't have to calculate it every time. + * + * Keep in mind that at if the allocator reaches the last buddy, + * it _will_ have to calculate the bitwidth, even if it's a multiple of 64. + * This scenario hopefully won't happen much during time sensitive areas, + * and (I think) linux calculates the buddy size every single time anyway. +**/ struct phys_map { - uint64_t map_size; //this way we won't have to calculate it every time - void *chunk_start; - uint64_t chunk_size; - uint64_t *buddies; -} __attribute__((packed)); + struct phys_map *next; + void *zone_paddr; + uint64_t extra_bits; + uint64_t *buddy[MAX_BUDDY_ORDER]; +}; + +//clean up doing extra work some other time +#define LSIZE_FROM_BITLEN(bitlen) (((bitlen) + 63) / 64) +#define BITLEN_FROM_LSIZE(lsize) ((lsize) * 64) +#define GET_BUDDY_BITLEN(zone_len, order) ((zone_len) / (0x1000 << (order))) +#define GET_ORDER_CHUNKSIZE(order) (0x1000 << ((order))) + extern void* _meminfo_loc; @@ -66,6 +85,12 @@ extern void* _stage2_pagetable; bool map_page(void *virtual_addr, void *physical_addr, uint8_t PAGE_SIZE); void debug_print_memory(); void create_pagetable_stage2(uint64_t free_mem); -void init_memory(); +void init_memory(); //TODO removeme +void init_pmap(); +void *palloc(); +void *pfree(); +void debug_pmap(); + + #endif diff --git a/src/include/panic.h b/src/include/panic.h new file mode 100644 index 0000000..1386348 --- /dev/null +++ b/src/include/panic.h @@ -0,0 +1,27 @@ +#ifndef PANIC_INCLUDED +#define PANIC_INCLUDED + +#define EASTEREGG_BLOATWARE + +#include + +void panic(int reason, int type); +struct stack_frame { + struct stack_frame *next; + uint64_t function_base; +} __attribute__((packed)); + +//kernel panic reasons, likely to grow at an extremely fast rate +#define KERNEL_PANIC_PMAPSIZE 0 +#define KERNEL_PANIC_RSDP_UNFOUND 1 +#define KERNEL_PANIC_KERNEL_RETURNED 2 + + +//kernel panic types, may or may not expand once I get further in development +#define KERNEL_PANIC_INVOKED 0 +#define KERNEL_PANIC_ERROR 1 //i'll change this once I see what happends + +//TODO move this to some kind of global more accesable header +#define DEV_EMAIL "brett_weiland@bpcspace.com" + +#endif -- cgit v1.2.3