Browse Source

renamed stuff

master
Mathieu Serandour 1 year ago
parent
commit
3fde65b447
  1. 8
      kernel/acpi/acpi.c
  2. 2
      kernel/drivers/hpet.c
  3. 14
      kernel/drivers/pcie.c
  4. 6
      kernel/drivers/terminal/terminal.c
  5. 8
      kernel/drivers/terminal/video.c
  6. 22
      kernel/entry.c
  7. 2
      kernel/int/apic.c
  8. 4
      kernel/int/isr.c
  9. 2
      kernel/lib/common.h
  10. 4
      kernel/lib/dump.c
  11. 2
      kernel/lib/dump.h
  12. 18
      kernel/lib/logging.c
  13. 18
      kernel/lib/logging.h
  14. 12
      kernel/lib/panic.c
  15. 8
      kernel/lib/sprintf.c
  16. 6
      kernel/lib/sprintf.h
  17. 2
      kernel/memory/gdt.c
  18. 38
      kernel/memory/heap.c
  19. 13
      kernel/memory/heap.h
  20. 13
      kernel/memory/kalloc.h
  21. 6
      kernel/memory/paging.c
  22. 2
      kernel/memory/physical_allocator.c

8
kernel/acpi/acpi.c

@ -54,7 +54,7 @@ void read_acpi_tables(const void* rsdp_location) {
size_t n_entries = (xsdt->header.length - sizeof(xsdt->header)) / sizeof(void*);
klog_debug("%u ACPI entries found", n_entries);
log_debug("%u ACPI entries found", n_entries);
bool madt_parsed = false,
hpet_parsed = false,
@ -120,7 +120,7 @@ static void parse_madt(const struct MADT* table) {
(void)override_ioapic_passed;
//kprintf("table size: %u\n", end-ptr);
//printf("table size: %u\n", end-ptr);
while(ptr < end) {
//for(int i = 10; i>0; i--) {
const struct MADTEntryHeader* entry_header = ptr;
@ -165,12 +165,12 @@ static void parse_madt(const struct MADT* table) {
}
break;
default:
kprintf("WARNING: invalid APIC MADT entry %u\n", entry_header->type);
printf("WARNING: invalid APIC MADT entry %u\n", entry_header->type);
}
//kprintf("entry: type %u ; size %u\n", entry_header->type,entry_header->length);
//printf("entry: type %u ; size %u\n", entry_header->type,entry_header->length);
ptr += entry_header->length;
}

2
kernel/drivers/hpet.c

@ -52,7 +52,7 @@ struct HPET_MMIO* const base = (void *)HPET_VIRTUAL_ADDRESS;
static uint32_t hpet_period = 0;
void hpet_init(void) {
klog_debug("init hpet...");
log_debug("init hpet...");
hpet_period = base->capabilities >> 32;
}

14
kernel/drivers/pcie.c

@ -2,7 +2,7 @@
#include "../lib/logging.h"
#include "../lib/dump.h"
#include "../lib/assert.h"
#include "../memory/kalloc.h"
#include "../memory/heap.h"
#include "../memory/paging.h"
#include "../lib/string.h"
@ -112,11 +112,11 @@ static void scan_devices(void) {
struct PCIE_configuration_space* config_space
) {
current->next = kmalloc(
current->next = malloc(
sizeof(struct device_desc_node)
);
klog_debug("device %u:%u - %u", bus, device, func);
log_debug("device %u:%u - %u", bus, device, func);
current = current->next;
current->next = NULL;
@ -150,7 +150,7 @@ static void scan_devices(void) {
// now create the final array
installed_devices = kmalloc(
installed_devices = malloc(
n_installed_devices
* sizeof(struct pcie_device_descriptor));
@ -166,7 +166,7 @@ static void scan_devices(void) {
struct device_desc_node* next = device->next;
kfree(device);
free(device);
device = next;
}
}
@ -199,7 +199,7 @@ static void identity_unmap_possible_config_spaces(void) {
*/
void pcie_init(void) {
klog_debug("init pcie...");
log_debug("init pcie...");
// calculate the highest bus number
@ -217,5 +217,5 @@ void pcie_init(void) {
identity_unmap_possible_config_spaces();
klog_info("found %u PCI Express devices", n_installed_devices);
log_info("found %u PCI Express devices", n_installed_devices);
}

6
kernel/drivers/terminal/terminal.c

@ -7,7 +7,7 @@
#include "../../lib/string.h"
#include "../../lib/assert.h"
#include "../../lib/logging.h"
#include "../../memory/kalloc.h"
#include "../../memory/heap.h"
#define TAB_SPACE 6
@ -63,7 +63,7 @@ extern int _binary_charmap_bmp;
void setup_terminal(void) {
klog_debug("setup the terminal...");
log_debug("setup the terminal...");
assert(charmap == NULL);
assert(char_buffer == NULL);
@ -94,7 +94,7 @@ void setup_terminal(void) {
nlines = TERMINAL_N_PAGES * term_nlines;
// allocate the terminal buffer
char_buffer = kmalloc(ncols * nlines * sizeof(struct Char));
char_buffer = malloc(ncols * nlines * sizeof(struct Char));
// calculate the margins
#ifdef BIGGER_FONT

8
kernel/drivers/terminal/video.c

@ -5,7 +5,7 @@
#include "../../lib/string.h"
#include "../../lib/logging.h"
//#include "../memory/kalloc.h"
//#include "../memory/heap.h"
#include "../../lib/common.h"
#include "../../lib/assert.h"
#include "video.h"
@ -246,7 +246,7 @@ void imageBlit(const Image* restrict src, Image* restrict dst,
/*
Image* alloc_image(uint32_t width, uint32_t height, uint32_t bpp) {
Image* ret = kmalloc(sizeof(Image));
Image* ret = malloc(sizeof(Image));
ret->w = width;
ret->h = height;
@ -261,7 +261,7 @@ Image* alloc_image(uint32_t width, uint32_t height, uint32_t bpp) {
else
ret->pitch = (uint32_t)allign16(width * (bpp/8));
ret->pix = kmalloc(ret->pitch * height);
ret->pix = malloc(ret->pitch * height);
return ret;
}
@ -271,7 +271,7 @@ Image* alloc_image(uint32_t width, uint32_t height, uint32_t bpp) {
void free_image(Image* im) {
assert(im != NULL);
kfree(im->pix);
free(im->pix);
}
*/

22
kernel/entry.c

@ -15,7 +15,7 @@
#include "memory/physical_allocator.h"
#include "memory/paging.h"
#include "memory/vmap.h"
#include "memory/kalloc.h"
#include "memory/heap.h"
#include "lib/sprintf.h"
#include "lib/string.h"
@ -81,8 +81,8 @@ static const void *stivale2_get_tag(const struct stivale2_struct *stivale2_struc
}
#define PRINT_VAL(v) kprintf(#v "=%ld\n", (uint64_t)v);
#define PRINT_HEX(v) kprintf(#v "=%lx\n", (uint64_t)v);
#define PRINT_VAL(v) printf(#v "=%ld\n", (uint64_t)v);
#define PRINT_HEX(v) printf(#v "=%lx\n", (uint64_t)v);
// const char but represents a big string
extern const char _binary_bootmessage_txt;
@ -96,7 +96,7 @@ static void debug_terminal() {
char buff[256];
for(int i = 0; i < 256; i++)
buff[i] = i+1;
kputs(buff);
puts(buff);
}
static void print_fb_infos(struct stivale2_struct_tag_framebuffer* fbtag) {
@ -112,7 +112,7 @@ static void print_fb_infos(struct stivale2_struct_tag_framebuffer* fbtag) {
static void init_memory(const struct stivale2_struct_tag_memmap* memmap_tag,
const struct stivale2_struct_tag_framebuffer* fbtag) {
klog_debug("init memory...");
log_debug("init memory...");
init_physical_allocator(memmap_tag);
@ -130,7 +130,7 @@ static void init_memory(const struct stivale2_struct_tag_memmap* memmap_tag,
map_acpi_mmios();
// init kernel heap
kheap_init();
heap_init();
}
@ -185,11 +185,11 @@ void _start(struct stivale2_struct *stivale2_struct) {
terminal_clear();
kputs(&_binary_bootmessage_txt);
puts(&_binary_bootmessage_txt);
kprintf("boot logs:\n");
kputs(klog_get());
klog_flush();
printf("boot logs:\n");
puts(log_get());
log_flush();
pcie_init();
@ -200,7 +200,7 @@ void _start(struct stivale2_struct *stivale2_struct) {
for(;;) {
asm volatile("hlt");
kprintf("%lu\r", clock());
printf("%lu\r", clock());
}
__builtin_unreachable();

2
kernel/int/apic.c

@ -42,7 +42,7 @@ inline uint64_t read(uint32_t m_address) {
}
void apic_setup_clock(void) {
klog_info("setup local apic clock...");
log_info("setup local apic clock...");
// enable apic msr
uint64_t IA32_APIC_BASE = read_msr(0x1b);

4
kernel/int/isr.c

@ -38,7 +38,7 @@ __attribute__((interrupt)) void ISR_general_handler(struct IFrame* interrupt_fra
}
__attribute__((interrupt)) void ISR_error_handler(struct IFrame* interrupt_frame, uint64_t error_code) {
(void) error_code;
kprintf("ERROR CODE: %lu\n", error_code);
printf("ERROR CODE: %lu\n", error_code);
panic_handler("ISR_error_handler", interrupt_frame);
}
__attribute__((interrupt)) void ISR_div_by_zero_handler(struct IFrame* interrupt_frame) {
@ -89,7 +89,7 @@ __attribute__((interrupt)) void ISR_stack_segment_fault_handler(struct IFrame* i
}
__attribute__((interrupt)) void ISR_general_protection_fault_handler(struct IFrame* interrupt_frame, uint64_t error_code) {
(void) error_code;
kprintf("ERROR CODE: %lu\n", error_code);
printf("ERROR CODE: %lu\n", error_code);
panic_handler("ISR_general_protection_fault_handler", interrupt_frame);
}
__attribute__((interrupt)) void ISR_page_fault_handler(struct IFrame* interrupt_frame, uint64_t error_code) {

2
kernel/lib/common.h

@ -20,7 +20,7 @@ typedef int8_t i8;
#define __noreturn __attribute__((noreturn))
#ifndef NDEBUG
#define PDEBUG kprintf("'%s':%d - %s()\n", __FILE__, __LINE__,__func__);
#define PDEBUG printf("'%s':%d - %s()\n", __FILE__, __LINE__,__func__);
#endif
inline uint64_t allign16(uint64_t p) {

4
kernel/lib/dump.c

@ -90,11 +90,11 @@ void dump(const void* addr, size_t size, size_t line_size, uint8_t mode) {
if(size-- <= 1)
break;
else {
kprintf(row_fmt, *(uint64_t *)ptr & mask);
printf(row_fmt, *(uint64_t *)ptr & mask);
ptr+=pitch;
}
}
kprintf(last_row_fmt, *(uint64_t *)ptr & mask);
printf(last_row_fmt, *(uint64_t *)ptr & mask);
ptr+=pitch;
}
}

2
kernel/lib/dump.h

@ -21,7 +21,7 @@
/**
* dump a memory chunk in kprintf
* dump a memory chunk in printf
* addr: address of the beginning of the chunk
* size: number of bytes to dump
* line_size: number of words per line

18
kernel/lib/logging.c

@ -23,7 +23,7 @@ static inline void append_string(const char* str) {
unsigned len = strlen(str);
if(i+len >= BUFFER_SIZE)
klog_flush();
log_flush();
memcpy(logs_buffer+i, str, len);
i += len;
}
@ -44,7 +44,7 @@ static const char* get_level_names_and_set_terminal_color(unsigned level) {
}
}
void klog(unsigned level, const char* string) {
void log(unsigned level, const char* string) {
if(level < current_level)
return; // avoid overflows
@ -53,11 +53,11 @@ void klog(unsigned level, const char* string) {
// print on the screen
// with fancy colors
kputs(level_name);
puts(level_name);
set_terminal_fgcolor(TEXT_COLOR);
kputs(string);
kputs("\n");
puts(string);
puts("\n");
// append to the buffer
append_string(level_name);
@ -67,7 +67,7 @@ void klog(unsigned level, const char* string) {
void klogf(unsigned level, const char* fmt, ...) {
void logf(unsigned level, const char* fmt, ...) {
if(level < current_level)
return;
@ -79,7 +79,7 @@ void klogf(unsigned level, const char* fmt, ...) {
vsprintf(string, fmt, ap);
va_end(ap);
klog(level, string);
log(level, string);
}
@ -88,12 +88,12 @@ void set_logging_level(unsigned level) {
}
const char* klog_get(void) {
const char* log_get(void) {
logs_buffer[i] = 0;
return logs_buffer;
}
void klog_flush(void) {
void log_flush(void) {
i = 0;
}

18
kernel/lib/logging.h

@ -15,21 +15,21 @@
#ifndef NDEBUG
#define klog_debug(...) klogf(LOG_LEVEL_DEBUG, __VA_ARGS__)
#define log_debug(...) logf(LOG_LEVEL_DEBUG, __VA_ARGS__)
#else
#define klog_debug(...)
#define log_debug(...)
#endif
#define klog_info(...) klogf(LOG_LEVEL_INFO, __VA_ARGS__)
#define klog_warn(...) klogf(LOG_LEVEL_WARN, __VA_ARGS__)
#define log_info(...) logf(LOG_LEVEL_INFO, __VA_ARGS__)
#define log_warn(...) logf(LOG_LEVEL_WARN, __VA_ARGS__)
void klog(unsigned level, const char* string);
void log(unsigned level, const char* string);
// behaves like kprintf
void klogf(unsigned level, const char* fmt, ...);
// behaves like printf
void logf(unsigned level, const char* fmt, ...);
void set_logging_level(unsigned level);
const char* klog_get(void);
const char* log_get(void);
void klog_flush(void);
void log_flush(void);

12
kernel/lib/panic.c

@ -12,13 +12,13 @@ extern uint64_t _rbp(void);
// always inline: make sure
static inline __attribute__((always_inline)) void stack_trace(void) {
void** ptr = (void**)_rbp();
kputs("backtrace:\n");
puts("backtrace:\n");
for(unsigned i = 0; i < MAX_STACK_TRACE; i++) {
if(*ptr == 0) // reached the top
break;
kprintf("\t%llx \n", *(ptr+1));
printf("\t%llx \n", *(ptr+1));
ptr = *ptr;
}
@ -32,17 +32,17 @@ __attribute__((noreturn)) void panic(const char* panic_string) {
if(panic_string == NULL)
panic_string = "(null)";
kputs(
puts(
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
"!!!!!!!!!!!!! KERNL PANIC !!!!!!!!!!!!!\n"
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
kputs(panic_string);
kputs("\n\n");
puts(panic_string);
puts("\n\n");
stack_trace();
kputs(
puts(
"\n\n"
"you may manually shutdown the machine.\n"
);

8
kernel/lib/sprintf.c

@ -193,20 +193,20 @@ int sprintf(char* str, const char* format, ...) {
//
//}
void kputs(const char* s) {
void puts(const char* s) {
terminal_handler_t print_fun = get_terminal_handler();
if(print_fun)
print_fun(s, strlen(s));
}
int kprintf(const char* format, ...) {
int printf(const char* format, ...) {
va_list ap;
int ret;
va_start(ap, format);
ret = vkprintf(format, ap);
ret = vprintf(format, ap);
va_end(ap);
@ -214,7 +214,7 @@ int kprintf(const char* format, ...) {
return ret;
}
int vkprintf(const char* format, va_list ap) {
int vprintf(const char* format, va_list ap) {
terminal_handler_t print_fun = get_terminal_handler();
char buf[1024];

6
kernel/lib/sprintf.h

@ -12,9 +12,9 @@ int snprintf(char *str, size_t size, const char *format, ...);
int vsprintf(char *str, const char *format, va_list ap);
int vsnprintf(char *str, size_t size, const char *format, va_list ap);
int vkprintf(const char* format, va_list ap);
int kprintf(const char* format, ...);
int vprintf(const char* format, va_list ap);
int printf(const char* format, ...);
void kputs(const char* s);
void puts(const char* s);
#endif

2
kernel/memory/gdt.c

@ -91,7 +91,7 @@ struct GDTDescriptor gdt_descriptor = {
};
#define PRINT_STRUCT(TARGET) \
kprintf("&" #TARGET "=0x%8lx\tsizeof(" #TARGET ")=%ld (0x%lx)\n", \
printf("&" #TARGET "=0x%8lx\tsizeof(" #TARGET ")=%ld (0x%lx)\n", \
&TARGET, sizeof(TARGET),sizeof(TARGET))
volatile int y = 5421;

38
kernel/memory/kalloc.c → kernel/memory/heap.c

@ -1,7 +1,7 @@
#include <stdint.h>
#include <stddef.h>
#include "kalloc.h"
#include "heap.h"
#include "../lib/sprintf.h"
#include "../memory/vmap.h"
#include "../memory/paging.h"
@ -59,8 +59,8 @@ static_assert(sizeof(seg_header) % 8 == 0);
*
*/
static void *kheap_begin = (void *)KERNEL_HEAP_BEGIN;
static size_t kheap_size = 0;
static void *heap_begin = (void *)KERNEL_HEAP_BEGIN;
static size_t heap_size = 0;
// sum of the available heap ranges,
// without the last free segment:
@ -77,21 +77,21 @@ static seg_header* current_segment = NULL;
* expand the heap by size bytes
*/
static void expand_heap(size_t size) {
size_t new_kheap_pages_size = (kheap_size + size + 0xfff) >> 12;
size_t old_kheap_pages_size = (kheap_size + 0xfff) >> 12;
size_t new_heap_pages_size = (heap_size + size + 0xfff) >> 12;
size_t old_heap_pages_size = (heap_size + 0xfff) >> 12;
// alloc extra pages if needed
if(new_kheap_pages_size != old_kheap_pages_size) {
if(new_heap_pages_size != old_heap_pages_size) {
alloc_pages(
kheap_begin + (old_kheap_pages_size << 12),
new_kheap_pages_size - old_kheap_pages_size,
heap_begin + (old_heap_pages_size << 12),
new_heap_pages_size - old_heap_pages_size,
PRESENT_ENTRY | PL_XD // execute disable pages
);
}
// create a new segment in the extra space
seg_header* new_segment = kheap_begin + kheap_size;
seg_header* new_segment = heap_begin + heap_size;
new_segment->next = current_segment;
@ -101,9 +101,9 @@ static void expand_heap(size_t size) {
current_segment = new_segment;
kheap_size += size;
heap_size += size;
klog_debug("kernel heap extended to %lu KB", kheap_size / 1024);
log_debug("kernel heap extended to %lu KB", heap_size / 1024);
}
/**
@ -245,15 +245,15 @@ static seg_header* split_segment(seg_header* pred, seg_header* tosplit, size_t s
}
void kheap_init(void) {
void heap_init(void) {
klog_debug("init kernel heap...");
log_debug("init kernel heap...");
expand_heap(MIN_EXPAND_SIZE);
}
void* __attribute__((noinline)) kmalloc(size_t size) {
void* __attribute__((noinline)) malloc(size_t size) {
// align the size to assure that
// the whole structure is alligned
size = ((size + 7 ) / 8) * 8;
@ -321,12 +321,12 @@ void* __attribute__((noinline)) kmalloc(size_t size) {
expand_heap(MAX(size+sizeof(seg_header), MIN_EXPAND_SIZE));
// retrty now that we are sure that the memory is avaiable
return kmalloc(size);
return malloc(size);
}
// O(1) free
void kfree(void *ptr) {
void free(void *ptr) {
seg_header* header = ptr - sizeof(seg_header);
assert(header->free == 0);
@ -342,19 +342,19 @@ void kfree(void *ptr) {
#ifndef NDEBUG
void kmalloc_test(void) {
void malloc_test(void) {
void* arr[128];
uint64_t size = 5;
for(int j = 0; j < 100; j++) {
for(int i = 0; i < 128; i++) {
arr[i] = kmalloc(size % 1024);
arr[i] = malloc(size % 1024);
size = (16807 * size) % ((1lu << 31) - 1);
}
for(int i = 0; i < 128; i++)
kfree(arr[i]);
free(arr[i]);
}
}
#endif

13
kernel/memory/heap.h

@ -0,0 +1,13 @@
#pragma once
#include <stddef.h>
// provides 8byte-aligned
// free memory
void* malloc(size_t size);
void free(void* p);
void heap_init(void);
#ifndef NDEBUG
void malloc_test(void);
#endif

13
kernel/memory/kalloc.h

@ -1,13 +0,0 @@
#pragma once
#include <stddef.h>
// provides 8byte-aligned
// free memory
void* kmalloc(size_t size);
void kfree(void* p);
void kheap_init(void);
#ifndef NDEBUG
void kmalloc_test(void);
#endif

6
kernel/memory/paging.c

@ -276,13 +276,13 @@ static inline void print_struct(int level, void** table, uint64_t virt) {
uint64_t v = (virt << 9) | i;
for(int i = 0; i < level; i++)
kputs("-");
puts("-");
if(level == 2) {
kprintf(" %lx -> %lx\n", v << 12, extract_pointer(addr[i]));
printf(" %lx -> %lx\n", v << 12, extract_pointer(addr[i]));
}
else {
kputs("\n");
puts("\n");
print_struct(level+1, extract_pointer(addr[i]), v);
}
}

2
kernel/memory/physical_allocator.c

@ -182,7 +182,7 @@ void init_physical_allocator(const struct stivale2_struct_tag_memmap* memmap) {
n_ranges = j;
total_available_pages = total_pages - n_ranges;
klog_info(
log_info(
"found %u MB of usable memory in the system (%u pages, %u physical ranges)",
total_available_pages * 4 / 1024,
total_available_pages,

Loading…
Cancel
Save