Fixing bugs...

This commit is contained in:
ice-bit 2019-09-24 12:39:05 +02:00
parent 9b5bf087b5
commit a378ca4061
8 changed files with 43 additions and 29 deletions

View File

@ -1,8 +1,14 @@
OBJS = multiboot.asm.o kernel_loader.asm.o ports.asm.o gdt.asm.o idt.asm.o interrupts.asm.o
OBJS = multiboot.asm.o kernel_loader.asm.o ports.asm.o \
gdt.asm.o idt.asm.o interrupts.asm.o assert.o
ASM = nasm
ASMFLAGS = -f elf
CC = i686-elf-gcc # cross-compiler
CFLAGS = -m32 -fno-stack-protector -ffreestanding -Wall -Wextra -Werror -g -c
all: $(OBJS)
%.asm.o: %.asm
$(ASM) $(ASMFLAGS) $< -o $@
$(ASM) $(ASMFLAGS) $< -o $@
%.o: %.c
$(CC) $(CFLAGS) $< -o $@

View File

@ -4,13 +4,13 @@
extern void panic(const char *message, const char *file, uint32_t line) {
asm volatile("cli"); // Disable interrupts
kprint("PANIC(");
kprint(message);
kprint(") at ");
kprint(file);
kprint(":");
kprint((uint8_t*)"PANIC(");
kprint((uint8_t*)message);
kprint((uint8_t*)") at ");
kprint((uint8_t*)file);
kprint((uint8_t*)":");
kprint_dec(line);
kprint("\n");
kprint((uint8_t*)"\n");
// Now hang on for ever
for(;;);
}
@ -19,13 +19,13 @@ extern void panic(const char *message, const char *file, uint32_t line) {
extern void panic_assert(const char *file, uint32_t line, const char *desc) {
asm volatile("cli"); // Disable interrupts
kprint("ASSERTION-FAILED(");
kprint(desc);
kprint(") at ");
kprint(file);
kprint(":");
kprint((uint8_t*)"ASSERTION-FAILED(");
kprint((uint8_t*)desc);
kprint((uint8_t*)") at ");
kprint((uint8_t*)file);
kprint((uint8_t*)":");
kprint_dec(line);
kprint("\n");
kprint((uint8_t*)"\n");
// Now hang on forever
for(;;);
}

View File

@ -1,4 +1,5 @@
OBJS = tty.o gdt.o idt.o isr.o timer.o keyboard.o fs.o
OBJS = tty.o gdt.o idt.o isr.o timer.o keyboard.o \
fs.o ordered_list.o kheap.o paging.o
CC = i686-elf-gcc # cross-compiler
CFLAGS = -m32 -fno-stack-protector -ffreestanding -Wall -Wextra -Werror -g -c

View File

@ -6,12 +6,12 @@ extern page_directory_t *kernel_directory;
uint32_t placement_addr = (uint32_t)&end;
heap_t *kheap = 0;
uint32_t kmalloc_init(uint32_t sz, int32_t align, uint32_t *phys) {
uint32_t kmalloc_int(uint32_t sz, int32_t align, uint32_t *phys) {
if(kheap != 0) {
void *addr = alloc(sz, (uint8_t)align, &kheap);
void *addr = alloc(sz, (uint8_t)align, kheap);
if(phys != 0) {
page_t *page = get_page((uint32_t)addr, 0, kernel_directory);
*phys = page->frame*0x1000 + (uint32_t)addr&0xFFF;
*phys = (page->frame*0x1000 + (uint32_t)addr)&0xFFF;
}
return (uint32_t)addr;
} else {
@ -58,7 +58,7 @@ static int32_t find_smallest_hole(uint32_t size, uint8_t page_align, heap_t *hea
if(page_align > 0) {
uint32_t loc = (uint32_t)header;
int32_t offset = 0;
if((loc+sizeof(header_t)) & 0xFFFFF000 != 0) // Page aligned memory
if(((loc+sizeof(header_t)) & 0xFFFFF000) != 0) // Page aligned memory
offset = 0x1000 - (loc+sizeof(header_t))%0x1000;
int32_t hole_size = (int32_t)header->size - offset;
if(hole_size >= (int32_t)size)
@ -91,7 +91,7 @@ heap_t *create_heap(uint32_t start, uint32_t end, uint32_t max, uint8_t supervis
start += sizeof(type_t)*HEAP_INDEX_SIZE;
// Check if start address is page-aligned
if(start & 0xFFFFF000 != 0) {
if((start & 0xFFFFF000) != 0) {
start &= 0xFFFFF000;
start += 0x1000;
}
@ -116,7 +116,7 @@ heap_t *create_heap(uint32_t start, uint32_t end, uint32_t max, uint8_t supervis
static void expand(uint32_t new_size, heap_t *heap) {
// Before anything else let's check that new size is greater than older one
ASSERT(new_size > heap->end_address - heap->start_address);
if(new_size&0xFFFFF000 != 0) {
if((new_size&0xFFFFF000) != 0) {
new_size &= 0xFFFFF000;
new_size += 0x1000;
}
@ -166,9 +166,9 @@ void *alloc(uint32_t size, uint8_t page_align, heap_t *heap) {
uint32_t new_len = heap->end_address-heap->start_address;
i = 0; // Endmost header in location
uint32_t idx = -1; // Endmost header's index
int32_t idx = -1; // Endmost header's index
uint32_t value = 0x0; // Endmost header's value
while(i < heap->index.size) {
while((uint32_t)i < heap->index.size) {
uint32_t tmp = (uint32_t)lookup_ordered_list(i, &heap->index);
if(tmp > value) {
value = tmp;
@ -187,7 +187,7 @@ void *alloc(uint32_t size, uint8_t page_align, heap_t *heap) {
foot->header = head;
insert_ordered_list((void*)head, &heap->index);
} else {
header_t *head = lookup_ordered_list(idx, &heap->index);
header_t *head = lookup_ordered_list((uint32_t)idx, &heap->index);
head->size += new_len - old_len;
// Rewrite the footer
footer_t *foot = (footer_t*) ((uint32_t)head + head->size - sizeof(footer_t));

View File

@ -33,6 +33,7 @@
#define HEAP_MIN_SIZE 0x70000
#include <stdint.h>
#include "../cpu/assert.h"
#include "ordered_list.h"
#include "paging.h"
@ -62,7 +63,7 @@ heap_t *create_heap(uint32_t start, uint32_t end, uint32_t max, uint8_t supervis
void *alloc(uint32_t size, uint8_t page_align, heap_t *heap);
void free(void *p, heap_t *heap);
// Public heap functions
uint32_t kmalloc_init(uint32_t sz, int32_t align, uint32_t *phys);
uint32_t kmalloc_int(uint32_t sz, int32_t align, uint32_t *phys);
void kfree(void *p);
uint32_t kmalloc_a(uint32_t sz);
uint32_t kmalloc_p(uint32_t sz, uint32_t *phys);

View File

@ -29,7 +29,7 @@ ordered_list_t place_ordered_list(void *addr, uint32_t max_size, lessthan_predic
// Destroy an ordered list
void destroy_ordered_list(ordered_list_t *array) {
// Not ready yet TODO:
kfree(array->array);
}
// Insert item into the array
@ -66,4 +66,4 @@ void remove_ordered_list(uint32_t i, ordered_list_t *array) {
i++;
}
array->size--;
}
}

View File

@ -5,10 +5,12 @@
* Released under GPLv3 *
* https://github.com/ice-bit/iceOS *
***************************************/
#ifndef ORDERED_LIST
#define ORDERED_LIST
#ifndef ORDERED_LIST_H
#define ORDERED_LIST_H
#include <stdint.h>
#include "kheap.h"
#include "../cpu/assert.h"
#include "../libc/string.h"
/* Our list is always in a 'sorted state',

View File

@ -34,5 +34,9 @@ void switch_page_directory(page_directory_t *new);
page_t *get_page(uint32_t addr, int32_t make, page_directory_t *dir);
// Handle page faults
void page_fault(registers_t regs);
// Allocate a new frame
void alloc_frame(page_t *page, int32_t is_kernel, int32_t is_writeable);
// Deallocate frame
void free_frame(page_t *page);
#endif