[mem] That should fix a bunch of stuff.
This commit is contained in:
parent
3db19d1605
commit
679bd270f4
@ -149,7 +149,9 @@ void * __attribute__ ((malloc)) valloc(size_t size) {
|
||||
}
|
||||
|
||||
void free(void * ptr) {
|
||||
klfree(ptr);
|
||||
if ((uintptr_t)ptr > placement_pointer) {
|
||||
klfree(ptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -911,3 +913,10 @@ static void * __attribute__ ((malloc)) klcalloc(size_t nmemb, size_t size) {
|
||||
return ptr;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
/*
|
||||
* vim:noexpandtab
|
||||
* vim:tabstop=4
|
||||
* vim:shiftwidth=4
|
||||
*/
|
||||
|
@ -6,18 +6,6 @@
|
||||
#include <fs.h>
|
||||
#include <elf.h>
|
||||
|
||||
static void
|
||||
a_task(int argc, char ** argv) {
|
||||
syscall_print("Hello world!\n");
|
||||
syscall_print("I am: (");
|
||||
char blarg[2] = { '0' + argc, 0};
|
||||
syscall_print(blarg);
|
||||
syscall_print(") ");
|
||||
syscall_print(argv[0]);
|
||||
syscall_print("\n");
|
||||
syscall_exit(2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load and execute.
|
||||
* @param path Path to the executable to attempt to execute.
|
||||
@ -76,9 +64,6 @@ exec(
|
||||
|
||||
enter_user_jmp((uintptr_t)header->e_entry, argc, argv);
|
||||
|
||||
|
||||
|
||||
|
||||
/* We should never reach this mode */
|
||||
kexit(0x5ADFACE);
|
||||
} else {
|
||||
@ -93,8 +78,6 @@ exec(
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* vim:noexpandtab
|
||||
* vim:tabstop=4
|
||||
|
@ -164,8 +164,6 @@ alloc_frame(
|
||||
page->present = 1;
|
||||
page->rw = (is_writeable == 1) ? 1 : 0;
|
||||
page->user = (is_kernel == 1) ? 0 : 1;
|
||||
page->rw = 1;
|
||||
page->user = 1;
|
||||
page->frame = index;
|
||||
}
|
||||
}
|
||||
@ -208,13 +206,20 @@ paging_install(uint32_t memsize) {
|
||||
memset(kernel_directory, 0, sizeof(page_directory_t));
|
||||
|
||||
uint32_t i = 0;
|
||||
while (i < 0x400000 ) { //placement_pointer + 0x1000) {
|
||||
alloc_frame(get_page(i, 1, kernel_directory), 0, 0);
|
||||
while (i < placement_pointer + 0x3000) {
|
||||
alloc_frame(get_page(i, 1, kernel_directory), 1, 0);
|
||||
i += 0x1000;
|
||||
}
|
||||
isrs_install_handler(14, page_fault);
|
||||
kernel_directory->physical_address = (uintptr_t)kernel_directory->physical_tables;
|
||||
|
||||
/* Kernel Heap Space */
|
||||
for (i = placement_pointer; i < 0x2000000; i += 0x1000) {
|
||||
get_page(i, 1, kernel_directory);
|
||||
alloc_frame(get_page(i, 1, kernel_directory), 1, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
current_directory = clone_directory(kernel_directory);
|
||||
switch_page_directory(kernel_directory);
|
||||
@ -285,7 +290,6 @@ page_fault(
|
||||
void
|
||||
heap_install() {
|
||||
heap_end = (placement_pointer + 0x1000) & ~0xFFF;
|
||||
placement_pointer = 0;
|
||||
}
|
||||
|
||||
void *
|
||||
@ -296,11 +300,6 @@ sbrk(
|
||||
ASSERT(heap_end % 0x1000 == 0);
|
||||
uintptr_t address = heap_end;
|
||||
heap_end += increment;
|
||||
uintptr_t i;
|
||||
for (i = address; i < heap_end; i += 0x1000) {
|
||||
get_page(i, 1, kernel_directory);
|
||||
alloc_frame(get_page(i, 1, kernel_directory), 0, 1);
|
||||
}
|
||||
memset((void *)address, 0x0, increment);
|
||||
return (void *)address;
|
||||
}
|
||||
|
@ -59,42 +59,6 @@ clone_table(
|
||||
return table;
|
||||
}
|
||||
|
||||
uintptr_t
|
||||
copy_stack(
|
||||
void *new_stack_start,
|
||||
size_t size,
|
||||
uintptr_t initial
|
||||
) {
|
||||
uintptr_t i;
|
||||
for ( i = (uintptr_t)new_stack_start;
|
||||
i >= ((uintptr_t)new_stack_start - size);
|
||||
i -= 0x1000) {
|
||||
alloc_frame(get_page(i, 1, current_directory), 0 /* user */, 1 /* writable */);
|
||||
}
|
||||
uintptr_t pd_addr;
|
||||
__asm__ __volatile__ ("mov %%cr3, %0" : "=r" (pd_addr));
|
||||
__asm__ __volatile__ ("mov %0, %%cr3" : : "r" (pd_addr));
|
||||
uintptr_t old_stack_pointer;
|
||||
__asm__ __volatile__ ("mov %%esp, %0" : "=r" (old_stack_pointer));
|
||||
uintptr_t old_base_pointer;
|
||||
__asm__ __volatile__ ("mov %%ebp, %0" : "=r" (old_base_pointer));
|
||||
uintptr_t offset = (uintptr_t)new_stack_start - initial;
|
||||
uintptr_t new_stack_pointer = old_stack_pointer + offset;
|
||||
uintptr_t new_base_pointer = old_base_pointer + offset;
|
||||
memcpy((void *)new_stack_pointer, (void *)old_stack_pointer, initial - old_stack_pointer);
|
||||
for (i = (uintptr_t)new_stack_start; i > (uintptr_t)new_stack_start - size; i -= 4) {
|
||||
uintptr_t temp = *(uintptr_t*)i;
|
||||
if ((old_stack_pointer < temp) && (temp < initial_esp)) {
|
||||
temp = temp + offset;
|
||||
uintptr_t *temp2 = (uintptr_t *)i;
|
||||
*temp2 = temp;
|
||||
}
|
||||
}
|
||||
__asm__ __volatile__ ("mov %0, %%esp" : : "r" (new_stack_pointer));
|
||||
__asm__ __volatile__ ("mov %0, %%ebp" : : "r" (new_base_pointer));
|
||||
return (uintptr_t)new_stack_start - size;
|
||||
}
|
||||
|
||||
void
|
||||
tasking_install() {
|
||||
__asm__ __volatile__ ("cli");
|
||||
@ -105,10 +69,12 @@ tasking_install() {
|
||||
current_task->esp = 0;
|
||||
current_task->ebp = 0;
|
||||
current_task->eip = 0;
|
||||
current_task->stack = initial_esp; //copy_stack((void *)0xE000000, KERNEL_STACK_SIZE, initial_esp);
|
||||
current_task->page_directory = current_directory;
|
||||
current_task->stack = initial_esp;
|
||||
current_task->page_directory = current_directory; //clone_directory(current_directory);
|
||||
current_task->next = 0;
|
||||
|
||||
//switch_page_directory(current_task->page_directory);
|
||||
|
||||
__asm__ __volatile__ ("sti");
|
||||
}
|
||||
|
||||
@ -184,6 +150,7 @@ switch_task() {
|
||||
__asm__ __volatile__ ("mov %%ebp, %0" : "=r" (ebp));
|
||||
eip = read_eip();
|
||||
if (eip == 0x10000) {
|
||||
|
||||
return;
|
||||
}
|
||||
current_task->eip = eip;
|
||||
@ -241,7 +208,6 @@ enter_user_jmp(uintptr_t location, int argc, char ** argv) {
|
||||
set_kernel_stack(current_task->stack + KERNEL_STACK_SIZE);
|
||||
__asm__ __volatile__(
|
||||
"cli\n"
|
||||
//"mov $0x23, %ax\n"
|
||||
"mov $0x23, %%ax\n"
|
||||
"mov %%ax, %%ds\n"
|
||||
"mov %%ax, %%es\n"
|
||||
|
@ -26,6 +26,9 @@ void open_fs(fs_node_t *node, uint8_t read, uint8_t write) {
|
||||
}
|
||||
|
||||
void close_fs(fs_node_t *node) {
|
||||
if (node == fs_root) {
|
||||
HALT_AND_CATCH_FIRE("Attemped to close the filesystem root. kablooey", NULL);
|
||||
}
|
||||
if (node->close != 0) {
|
||||
node->close(node);
|
||||
}
|
||||
|
@ -106,17 +106,20 @@ int main(struct multiboot *mboot, uint32_t mboot_mag, uintptr_t esp)
|
||||
irq_install(); /* Hardware interrupt requests */
|
||||
|
||||
|
||||
/* Memory management */
|
||||
paging_install(mboot_ptr->mem_upper); /* Paging */
|
||||
heap_install(); /* Kernel heap */
|
||||
|
||||
/* Hardware drivers */
|
||||
timer_install(); /* PIC driver */
|
||||
keyboard_install(); /* Keyboard interrupt handler */
|
||||
serial_install(); /* Serial console */
|
||||
|
||||
/* Memory management */
|
||||
paging_install(mboot_ptr->mem_upper); /* Paging */
|
||||
heap_install(); /* Kernel heap */
|
||||
tasking_install(); /* Multi-tasking */
|
||||
enable_fpu();
|
||||
syscalls_install();
|
||||
tasking_install(); /* Multi-tasking */
|
||||
enable_fpu(); /* Enable the floating point unit */
|
||||
syscalls_install(); /* Install the system calls */
|
||||
|
||||
/* Initialize the standard VGA display */
|
||||
ansi_init(&writech, 80, 25);
|
||||
|
||||
/* Kernel Version */
|
||||
@ -151,15 +154,5 @@ int main(struct multiboot *mboot, uint32_t mboot_mag, uintptr_t esp)
|
||||
|
||||
start_shell();
|
||||
|
||||
uint32_t i = 0;
|
||||
while (1) {
|
||||
if (!fork()) {
|
||||
kprintf("%d\n",getpid());
|
||||
kexit(getpid());
|
||||
while (1) { }
|
||||
}
|
||||
++i;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user