Example #1
0
static L4_ThreadId_t launch(L4_BootRec_t *br)
{
    AddrSpace_t *as = task_new(mman_tid);
    if (!as) {
        debug("launch: can't create address space for %s\n", L4_Module_Cmdline(br));
        return L4_nilthread;
    }

    /* we have to explicitly grab these from sigma0 */
    L4_Word_t mi;
    for (mi = 0; mi < L4_Module_Size(br); mi += 4096) {
        L4_Sigma0_GetPage(L4_nilthread, L4_Fpage(L4_Module_Start(br) + mi, 4096));
    }

    L4_Word_t start = elf_load32(as, L4_Module_Start(br), L4_Module_Size(br));
    thread_start(as->tid, start, L4_Module_Cmdline(br), n_paths, dir_paths, dir_caps);

    printf("    %s\n", L4_Module_Cmdline(br));
    return as->tid;
}
Example #2
0
FILE *
fopen(const char *fname, const char *prot)
{
	L4_BootRec_t *rec;
	struct bootinfo *handle;
	FILE *newfile;


	rec = find_bootrec(fname);
	
	if (rec == NULL) {
		return NULL;
	}

	/* Note: We may want to allocate froma different pool
	   of memory to minimise this being tramped on a by a
	   user */

	newfile = malloc(sizeof(FILE));

	if (newfile == NULL) {
		return NULL;
	}

	handle = malloc(sizeof(struct bootinfo));

	if (handle == NULL) {
		free(newfile);
		return NULL;
	}

	handle->total_size = L4_Module_Size(rec);
	handle->buffer = (char*) L4_Module_Start(rec);

	newfile->handle = handle;
	newfile->write_fn = bootinfo_write;
	newfile->read_fn = bootinfo_read;
	newfile->close_fn = bootinfo_close;
	newfile->eof_fn = bootinfo_eof;
	newfile->current_pos = 0;
	newfile->buffering_mode = _IONBF;
	newfile->buffer = NULL;
	newfile->unget_pos = 0;
	newfile->eof = 0;

#ifdef THREAD_SAFE
	newfile->mutex.holder = 0;
	newfile->mutex.needed = 0;
	newfile->mutex.count = 0;
#endif

	return newfile;
}
Example #3
0
int main (void)
{
    L4_Word_t total;

    printf("\n\nHasenpfeffer operating system\n");
    printf("Copyright (C) 2005,2006. Senko Rasic <*****@*****.**>\n\n");


    printf("Initializing root task...\n");
    L4_KernelInterfacePage_t *kip = (L4_KernelInterfacePage_t *) L4_GetKernelInterface();
    void *bi = (void *) L4_BootInfo(kip);
    
    // we need to preload these I/O pages
    // ATA
    L4_Sigma0_GetPage(L4_nilthread, L4_Fpage(0x0000, 4096));

    // KIP
    L4_Sigma0_GetPage(L4_nilthread, L4_Fpage(L4_BootInfo(kip), 4096));
    L4_BootRec_t *br = NULL;

    if (L4_BootInfo_Valid((void *) bi)) {
        int n = L4_BootInfo_Entries(bi);
        br = L4_BootInfo_FirstEntry(bi);
        while (--n) {
            /* touch roottask data from here, because sigma0 only gives pages to initial *thread* */
            if (L4_BootRec_Type(br) == L4_BootInfo_SimpleExec) {
                L4_Word_t mi;
                for (mi = 0; mi < L4_Module_Size(br); mi += 4096) {
                    L4_Sigma0_GetPage(L4_nilthread, L4_Fpage(L4_Module_Start(br) + mi, 4096));
                }
            }
            br = L4_BootRec_Next(br);
        }
    } else {
        printf("panic: invalid bootinfo data\n");
        return 0;
    }

    memory_init();
    total = memory_get_free();

    printf("Creating root memory manager...\n");
    mman_tid = create_local_thread("root memory manager", kip, 1, memman, 4096);
    thread_init(mman_tid);

    printf("Initializing root task manager...\n");
    HpfCapability full, newthread, newtask;
    task_manager_init(&full, &newtask, &newthread);

    dir_paths[0] = "/process/TaskManager";
    dir_caps[0] = full;
    n_paths = 1;

    printf("Loading initial programs...\n");
    int n = L4_BootInfo_Entries(bi);
    br = L4_BootInfo_FirstEntry(bi);
    int first_program = 1;
    while (--n) {
        if (L4_BootRec_Type(br) == L4_BootInfo_Module) {
            L4_ThreadId_t tid = launch(br);
            if (first_program) {
                first_program = 0;

                // this is the root directory server
                if (hermes_capability(tid, &(dir_caps[1]))) {
                    // dir_paths[1] = "/process/DirectoryService";
                    dir_paths[1] = ""; // <- catch-all
                    n_paths = 2;
                }
            }
        }
        br = L4_BootRec_Next(br);
    }

    printf("Init done, running...\n\n");
    task_manager_main();

    return 0;
}
Example #4
0
static unsigned int
sys$bootinfo_find_initial_objects(L4_KernelInterfacePage_t *kip,
        unsigned int max, struct initial_obj *initial_objs)
{
    char                        data_name[INITIAL_NAME_MAX];

    L4_BootRec_t                *record;

    L4_Word_t                   dsize;
    L4_Word_t                   dstart;
    L4_Word_t                   tsize;
    L4_Word_t                   tstart;
    L4_Word_t                   type;

    unsigned int                count;
    unsigned int                flags;
    unsigned int                num_recs;
    unsigned int                objects;

    void                        *bootinfo;

#   define DIT_INITIAL          32L // Root task

    bootinfo = (void*) L4_BootInfo(kip);
    count = 0;

    // Check bootinfo validity

    if (L4_BootInfo_Valid(bootinfo) == 0)
    {
        return(0);
    }

    num_recs = L4_BootInfo_Entries(bootinfo);
    record = L4_BootInfo_FirstEntry(bootinfo);

    while(num_recs > 0)
    {
        PANIC(record == NULL);
        type = L4_BootRec_Type(record);
        objects = 0;

        switch(type)
        {
            case L4_BootInfo_Module:
                sys$add_initial_object(initial_objs++,
                        L4_Module_Cmdline(record),
                        L4_Module_Start(record),
                        (L4_Module_Start(record) + L4_Module_Size(record)) - 1,
                        0, VMS$IOF_APP | VMS$IOF_PHYS);
                objects = 1;
                break;

            case L4_BootInfo_SimpleExec:
                if (L4_SimpleExec_Flags(record) & DIT_INITIAL)
                {
                    flags = VMS$IOF_ROOT | VMS$IOF_VIRT;
                }
                else
                {
                    flags = VMS$IOF_APP;
                }

                tstart = L4_SimpleExec_TextVstart(record);
                tsize = L4_SimpleExec_TextSize(record);
                dstart = L4_SimpleExec_DataVstart(record);
                dsize = L4_SimpleExec_DataSize(record);

                sys$add_initial_object(initial_objs++,
                        L4_SimpleExec_Cmdline(record),
                        tstart, (tstart + tsize) - 1,
                        L4_SimpleExec_InitialIP(record),
                        flags | VMS$IOF_PHYS);
                objects = 1;

                if ((!((dstart < (tstart + tsize) && dstart >= tstart)))
                        && (dsize != 0))
                {
                    sys$strncpy(data_name, L4_SimpleExec_Cmdline(record),
                            INITIAL_NAME_MAX - 5);
                    sys$strncat(data_name, ".data", INITIAL_NAME_MAX);

                    sys$add_initial_object(initial_objs++, data_name,
                            dstart, dstart + dsize - 1, 0,
                            VMS$IOF_ROOT | VMS$IOF_VIRT | VMS$IOF_PHYS);
                    objects++;
                }

                break;

            case L4_BootInfo_Multiboot:
                sys$add_initial_object(initial_objs++, "MultiBoot information",
                        L4_MBI_Address(record), L4_MBI_Address(record) + 0xFFF,
                        0, VMS$IOF_PHYS | VMS$IOF_BOOT | VMS$IOF_VIRT);
                objects = 1;
                break;

            default:
                PANIC(1);
                break;
        }

        if (objects > 0)
        {
            count += objects;

            if (count == max) goto overflow;
        }

        record = L4_BootRec_Next(record);
        num_recs--;
    }

    sys$add_initial_object(initial_objs++, "Boot",
            (vms$pointer) bootinfo,
            (vms$pointer) bootinfo + (L4_BootInfo_Size(bootinfo) - 1),
            0, VMS$IOF_BOOT | VMS$IOF_PHYS | VMS$IOF_VIRT);
    count++;

overflow:
    return count;
}