create a special init task (initd), which spawns all other tasks

This commit is contained in:
Stefan Lankes 2011-08-06 15:52:47 +02:00
parent 87cd484bb9
commit e4a170938e
2 changed files with 45 additions and 40 deletions

View file

@ -25,6 +25,7 @@
#include <metalsvm/tasks.h>
#include <metalsvm/errno.h>
#include <metalsvm/init.h>
#include <metalsvm/fs.h>
#ifdef CONFIG_LWIP
#include <lwip/init.h>
#include <lwip/sys.h>
@ -47,6 +48,7 @@
void echo_init(void);
void ping_init(void);
int test_init(void);
/*
* Note that linker symbols are not variables, they have no memory allocated for
@ -178,4 +180,45 @@ int network_shutdown(void)
return 0;
}
static void list_fs(vfs_node_t* node, uint32_t depth)
{
int j, i = 0;
dirent_t* dirent = NULL;
while ((dirent = readdir_fs(node, i)) != 0) {
for(j=0; j<depth; j++)
kputs(" ");
kprintf("%s\n", dirent->name);
if (strcmp(dirent->name, ".") && strcmp(dirent->name, "..")) {
vfs_node_t *new_node = finddir_fs(node, dirent->name);
if (new_node) {
if (new_node->type == FS_FILE) {
char buff[16] = {[0 ... 15] = 0x00};
read_fs(new_node, (uint8_t*)buff, 8, 0);
for(j=0; j<depth+1; j++)
kputs(" ");
kprintf("content: %s\n", buff);
} else list_fs(new_node, depth+1);
}
}
i++;
}
}
static void list_root(void) {
kprintf("List of the file system:\n/\n");
list_fs(fs_root, 1);
}
int initd(void* arg)
{
network_init();
list_root();
test_init();
return 0;
}

View file

@ -24,9 +24,9 @@
#include <metalsvm/mmu.h>
#include <metalsvm/tasks.h>
#include <metalsvm/processor.h>
#include <metalsvm/fs.h>
#include <metalsvm/errno.h>
#include <metalsvm/init.h>
#include <metalsvm/fs.h>
#include <asm/irq.h>
#include <asm/irqflags.h>
#include <asm/kb.h>
@ -34,8 +34,6 @@
#include <asm/icc.h>
#endif
extern int test_init(void);
/*
* Note that linker symbols are not variables, they have no memory allocated for
* maintaining a value, rather their address is their value.
@ -45,39 +43,6 @@ extern const void kernel_end;
extern char __BUILD_DATE;
extern char __BUILD_TIME;
static void list_fs(vfs_node_t* node, uint32_t depth)
{
int j, i = 0;
dirent_t* dirent = NULL;
while ((dirent = readdir_fs(node, i)) != 0) {
for(j=0; j<depth; j++)
kputs(" ");
kprintf("%s\n", dirent->name);
if (strcmp(dirent->name, ".") && strcmp(dirent->name, "..")) {
vfs_node_t *new_node = finddir_fs(node, dirent->name);
if (new_node) {
if (new_node->type == FS_FILE) {
char buff[16] = {[0 ... 15] = 0x00};
read_fs(new_node, (uint8_t*)buff, 8, 0);
for(j=0; j<depth+1; j++)
kputs(" ");
kprintf("content: %s\n", buff);
} else list_fs(new_node, depth+1);
}
}
i++;
}
}
static void list_root(void) {
kprintf("List of the file system:\n/\n");
list_fs(fs_root, 1);
}
#if MAX_CORES > 1
// idle loop of the application processors
int smp_main(void)
@ -117,7 +82,6 @@ int main(void)
kprintf("Kernel starts at %p and ends at %p\n", &kernel_start, &kernel_end);
system_calibration();
network_init();
kprintf("Processor frequency: %u MHz\n", get_cpu_frequency());
kprintf("Total memory: %u MBytes\n", atomic_int32_read(&total_pages)/((1024*1024)/PAGE_SIZE));
@ -125,9 +89,7 @@ int main(void)
kprintf("Current available memory: %u MBytes\n", atomic_int32_read(&total_available_pages)/((1024*1024)/PAGE_SIZE));
sleep(5);
list_root();
test_init();
per_core(current_task)->status = TASK_IDLE;
create_kernel_task(NULL, initd, NULL);
per_core(current_task)->time_slices = 0; // reset the number of time slices
reschedule();