standardized comment format and code cleanup

This commit is contained in:
Steffen Vogel 2013-11-20 12:03:24 +01:00
parent 421e7ec66e
commit aa1730919e
12 changed files with 45 additions and 59 deletions

View file

@ -150,6 +150,7 @@ int create_page_map(task_t* task, int copy)
}
memset(pgt, 0x00, sizeof(page_map_t));
// copy kernel tables
spinlock_lock(&kslock);
for(i=0; i<MAP_ENTRIES; i++) {
@ -611,7 +612,7 @@ int print_paging_tree(size_t viraddr)
} else
kputs("invalid page directory\n");
/* convert physical address to virtual */
// convert physical address to virtual
if (paging_enabled && pgt)
pgt = (page_map_t*) (KERNEL_SPACE - 1024*PAGE_SIZE + index1*PAGE_SIZE);
@ -688,11 +689,11 @@ int arch_paging_init(void)
page_map_t* pgt;
size_t viraddr;
// uninstall default handler and install our own
// replace default pagefault handler
irq_uninstall_handler(14);
irq_install_handler(14, pagefault_handler);
// Create a page table to reference to the other page tables
// create a page table to reference to the other page tables
pgt = &pgt_container;
// map this table at the end of the kernel space
@ -714,8 +715,8 @@ int arch_paging_init(void)
}
/*
* Set the page table and page directory entries for the kernel. We map the kernel's physical address
* to the same virtual address.
* Set the page table and page directory entries for the kernel.
* We map the kernel's physical address to the same virtual address.
*/
npages = ((size_t) &kernel_end - (size_t) &kernel_start) >> PAGE_SHIFT;
if ((size_t)&kernel_end & (PAGE_SIZE-1))
@ -723,7 +724,7 @@ int arch_paging_init(void)
map_region((size_t)&kernel_start, (size_t)&kernel_start, npages, MAP_KERNEL_SPACE);
#if MAX_CORES > 1
// Reserve page for smp boot code
// reserve page for smp boot code
if (!map_region(SMP_SETUP_ADDR, SMP_SETUP_ADDR, 1, MAP_KERNEL_SPACE|MAP_NO_CACHE)) {
kputs("could not reserve page for smp boot code\n");
return -ENOMEM;
@ -741,9 +742,7 @@ int arch_paging_init(void)
map_region((size_t) mb_info & PAGE_MASK, (size_t) mb_info & PAGE_MASK, 1, MAP_KERNEL_SPACE);
#if 0
/*
* Map reserved memory regions into the kernel space
*/
// map reserved memory regions into the kernel space
if (mb_info && (mb_info->flags & MULTIBOOT_INFO_MEM_MAP)) {
multiboot_memory_map_t* mmap = (multiboot_memory_map_t*) mb_info->mmap_addr;
multiboot_memory_map_t* mmap_end = (void*) ((size_t) mb_info->mmap_addr + mb_info->mmap_length);
@ -818,10 +817,7 @@ int arch_paging_init(void)
bootinfo->addr = viraddr;
#endif
/*
* we turned on paging
* => now, we are able to register our task
*/
// we turned on paging => now, we are able to register our task
register_task();
// APIC registers into the kernel address space

View file

@ -515,7 +515,7 @@ int unmap_region(size_t viraddr, uint32_t npages)
index_pgd = (viraddr >> 21) & 0x1FF;
index_pgt = (viraddr >> 12) & 0x1FF;
// Currently, we allocate pages only in kernel space.
// currently, we allocate pages only in kernel space.
// => physical address of the page table is identical of the virtual address
pdpt = (page_map_t*) (task->page_map->entries[index_pml4] & PAGE_MASK);
if (!pdpt) {
@ -644,8 +644,10 @@ static void pagefault_handler(struct state *s)
kprintf("Could not map 0x%x at 0x%x\n", phyaddr, viraddr);
put_page(phyaddr);
}
// handle missing paging structures for userspace
// all kernel space paging structures have been initialized in entry64.asm
/*
* handle missing paging structures for userspace
* all kernel space paging structures have been initialized in entry64.asm
*/
else if (viraddr >= PAGE_PGT) {
kprintf("map_region: missing paging structure at: 0x%lx (%s)\n", viraddr, map_to_lvlname(viraddr));
@ -683,7 +685,7 @@ int arch_paging_init(void)
{
uint32_t i, npages;
// uninstall default handler and install our own
// replace default pagefault handler
irq_uninstall_handler(14);
irq_install_handler(14, pagefault_handler);
@ -693,7 +695,7 @@ int arch_paging_init(void)
*/
#if MAX_CORES > 1
// Reserve page for smp boot code
// reserve page for smp boot code
if (!map_region(SMP_SETUP_ADDR, SMP_SETUP_ADDR, 1, MAP_KERNEL_SPACE|MAP_NO_CACHE)) {
kputs("could not reserve page for smp boot code\n");
return -ENOMEM;
@ -702,9 +704,7 @@ int arch_paging_init(void)
#ifdef CONFIG_MULTIBOOT
#if 0
/*
* Map reserved memory regions into the kernel space
*/
// map reserved memory regions into the kernel space
if (mb_info && (mb_info->flags & MULTIBOOT_INFO_MEM_MAP)) {
multiboot_memory_map_t* mmap = (multiboot_memory_map_t*) mb_info->mmap_addr;
multiboot_memory_map_t* mmap_end = (void*) ((size_t) mb_info->mmap_addr + mb_info->mmap_length);
@ -744,10 +744,7 @@ int arch_paging_init(void)
}
#endif
/*
* we turned on paging
* => now, we are able to register our task
*/
// we turned on paging => now, we are able to register our task
register_task();
// APIC registers into the kernel address space

View file

@ -253,7 +253,7 @@ static int initrd_open(fildes_t* file, const char* name)
/* opendir was called: */
if (name[0] == '\0')
return 0;
/* open file was called: */
if (!(file->flags & O_CREAT))
return -ENOENT;
@ -264,11 +264,11 @@ static int initrd_open(fildes_t* file, const char* name)
vfs_node_t* new_node = kmalloc(sizeof(vfs_node_t));
if (BUILTIN_EXPECT(!new_node, 0))
return -EINVAL;
blist = &file->node->block_list;
dir_block_t* dir_block;
dirent_t* dirent;
memset(new_node, 0x00, sizeof(vfs_node_t));
new_node->type = FS_FILE;
new_node->read = &initrd_read;
@ -286,7 +286,7 @@ static int initrd_open(fildes_t* file, const char* name)
if (!dirent->vfs_node) {
dirent->vfs_node = new_node;
strncpy(dirent->name, (char*) name, MAX_FNAME);
goto exit_create_file; // there might be a better Solution ***************
goto exit_create_file; // TODO: there might be a better Solution
}
}
}

View file

@ -29,10 +29,7 @@
#include <metalsvm/stddef.h>
#include <asm/page.h>
/**
* Sets up the environment, page directories etc and
* enables paging.
*/
/** @brief Sets up the environment, page directories etc and enables paging. */
static inline int paging_init(void) { return arch_paging_init(); }
#endif

View file

@ -28,7 +28,7 @@
extern "C" {
#endif
#define NULL ((void*) 0)
#define NULL ((void*) 0)
typedef unsigned int tid_t;
@ -62,10 +62,10 @@ typedef unsigned int tid_t;
irq_nested_enable(flags);\
return ret; \
}
#define CORE_ID smp_id()
#define CORE_ID smp_id()
#endif
/* needed to find the task, which is currently running on this core */
// needed to find the task, which is currently running on this core
struct task;
DECLARE_PER_CORE(struct task*, current_task);

View file

@ -113,7 +113,7 @@ unsigned long strtoul(const char* nptr, char** endptr, int base);
*/
static inline int atoi(const char *str)
{
return (int)strtol(str, (char **)NULL, 10);
return (int)strtol(str, (char **) NULL, 10);
}
#ifdef __cplusplus

View file

@ -147,9 +147,7 @@ tid_t wait(int32_t* result);
*/
void update_load(void);
/** @brief Print the current cpu load
*
*/
/** @brief Print the current cpu load */
void dump_load(void);
#if MAX_CORES > 1
@ -201,9 +199,7 @@ int block_current_task(void);
*/
int set_timer(uint64_t deadline);
/** @brief check is a timer is expired
*
*/
/** @brief check is a timer is expired */
void check_timers(void);
/** @brief Abort current task */

View file

@ -63,7 +63,7 @@ extern const void bss_end;
int lowlevel_init(void)
{
// initialize .bss section
memset((void*)&bss_start, 0x00, ((size_t) &bss_end - (size_t) &bss_start));
memset(&bss_start, 0x00, (char*) &bss_end - (char*) &bss_start);
koutput_init();

View file

@ -74,6 +74,7 @@ int main(void)
kprintf("This is MetalSVM %s Build %u, %u\n",
METALSVM_VERSION, &__BUILD_DATE, &__BUILD_TIME);
popbg();
system_init();
irq_init();
timer_init();
@ -86,7 +87,7 @@ int main(void)
icc_init();
svm_init();
#endif
initrd_init();
initrd_init();
irq_enable();

View file

@ -109,7 +109,7 @@ static int sys_open(const char* name, int flags, int mode)
curr_task->fildes_table[fd] = NULL;
return check;
}
return fd;
}

View file

@ -78,6 +78,7 @@ DEFINE_PER_CORE(task_t*, current_task, task_table+0);
extern const void boot_stack;
/** @brief helper function for the assembly code to determine the current task
*
* @return Pointer to the task_t structure of current task
*/
task_t* get_current_task(void) {
@ -193,8 +194,7 @@ static void wakeup_blocked_tasks(int result)
spinlock_irqsave_unlock(&table_lock);
}
/** @brief A procedure to be called by
* procedures which are called by exiting tasks. */
/** @brief A procedure to be called by procedures which are called by exiting tasks. */
static void NORETURN do_exit(int arg) {
vma_t* tmp;
task_t* curr_task = per_core(current_task);
@ -204,14 +204,14 @@ static void NORETURN do_exit(int arg) {
for (fd = 0; fd < NR_OPEN; fd++) {
if(curr_task->fildes_table[fd] != NULL) {
/*
* delete a descriptor from the per-process object
* reference table. If this is not the last reference to the underlying
* object, the object will be ignored.
*/
* Delete a descriptor from the per-process object
* reference table. If this is not the last reference to the underlying
* object, the object will be ignored.
*/
if (curr_task->fildes_table[fd]->count == 1) {
/* try to close the file */
// try to close the file
status = close_fs(curr_task->fildes_table[fd]);
/* close command failed -> return check = errno */
// close command failed -> return check = errno
if (BUILTIN_EXPECT(status < 0, 0))
kprintf("Task %u was not able to close file descriptor %i. close_fs returned %d", curr_task->id, fd, -status);
kfree(curr_task->fildes_table[fd], sizeof(fildes_t));
@ -247,7 +247,7 @@ static void NORETURN do_exit(int arg) {
#if 0
if (atomic_int32_read(&curr_task->user_usage))
kprintf("Memory leak! Task %d did not release %d pages\n",
curr_task->id, atomic_int32_read(&curr_task->user_usage));
curr_task->id, atomic_int32_read(&curr_task->user_usage));
#endif
curr_task->status = TASK_FINISHED;
@ -412,6 +412,7 @@ int sys_fork(void)
spinlock_init(&task_table[i].vma_lock);
// init fildes_table
// copy VMA list
child = &task_table[i].vma_list;
parent = parent_task->vma_list;
@ -434,7 +435,6 @@ int sys_fork(void)
}
/* init fildes_table */
task_table[i].fildes_table = kmalloc(sizeof(filp_t)*NR_OPEN);
memcpy(task_table[i].fildes_table, parent_task->fildes_table, sizeof(filp_t)*NR_OPEN);
for (fd_i = 0; fd_i < NR_OPEN; fd_i++)

View file

@ -248,7 +248,6 @@ int mmu_init(void)
page_set_mark((size_t)bootinfo >> PAGE_SHIFT);
atomic_int32_inc(&total_allocated_pages);
atomic_int32_dec(&total_available_pages);
#else
#error Currently, MetalSVM supports only the Multiboot specification or the RockCreek processor!
#endif
@ -318,8 +317,8 @@ int mmu_init(void)
* The init ram disk are already loaded.
* Therefore, we set these pages as used.
*/
for(addr=bootinfo->addr; addr < bootinfo->addr+bootinfo->size; addr+=PAGE_SIZE) {
// This area is already mapped, so we need to virt_to_phys() these addresses.
for(addr=bootinfo->addr; addr<bootinfo->addr+bootinfo->size; addr+=PAGE_SIZE) {
// this area is already mapped, so we need to virt_to_phys() these addresses.
page_set_mark(virt_to_phys(addr) >> PAGE_SHIFT);
atomic_int32_inc(&total_allocated_pages);
atomic_int32_dec(&total_available_pages);