Example #1
0
int kernel_start()
{
	int i;

	// point to low address (0GB ~ ...)
	pgd_tmp[PGD_INDEX(0)] =
		(uint32_t)pte_low | PAGE_PRESENT | PAGE_WRITE;

	// point to high address (3GB ~ 4GB)
	pgd_tmp[PGD_INDEX(PAGE_OFFSET)] =
		(uint32_t)pte_hig | PAGE_PRESENT | PAGE_WRITE;

	for (i = 0; i < 1024; i++) {
		pte_low[i] = (i << 12) | PAGE_PRESENT | PAGE_WRITE;
	}

	for (i = 0; i < 1024; i++) {
		pte_hig[i] = (i << 12) | PAGE_PRESENT | PAGE_WRITE;
	}

	// set page directory
	set_cr3(pgd_tmp);
	page_on();

	kernel_stack_top = ((uint32_t)kernel_stack + STACK_SIZE) & 0xFFFFFFF0;

	set_esp(kernel_stack_top);

	global_mboot_ptr = 
		(multiboot_t *)((uint32_t)global_mboot_tmp + PAGE_OFFSET);

	kernel_init();

	return 0;
}
Example #2
0
void phantom_thread_in_interrupt_fork()
{
    SHOW_INFO0( 10, "ifork in...");
    assert( forkLock.lock != 0 );
    hal_spin_lock(&schedlock);

    child = get_thread(GET_CURRENT_THREAD()->child_tid);
    parent = GET_CURRENT_THREAD();


//#warning cli
    // Save to me, switch to me
    SHOW_INFO0( 10, "ifork save...");
    phantom_switch_context(parent, parent, &schedlock );
    SHOW_INFO0( 10, "ifork saved...");
    // (OLD) phantom_switch_context() below returns here in old thread!!

    if(!(parent->thread_flags & THREAD_FLAG_PREFORK))
    {
        set_esp(old_sp);
        SHOW_INFO0( 10, "ifork in old...");
        // Second return. We're in old tread and done with fork;
        //GET_CURRENT_THREAD() = parent;
        SET_CURRENT_THREAD(parent);

        // Let child be elegible to run
        child->sleep_flags &= ~THREAD_SLEEP_LOCKED;
        t_enqueue_runq(child);

        return;
    }
    SHOW_INFO0( 10, "ifork cont...");

    parent->thread_flags &= ~THREAD_FLAG_PREFORK;
    //GET_CURRENT_THREAD() = child;
    SET_CURRENT_THREAD(child);

    // Now switch stack and copy some 512 bytes there to make sure
    // new one will have some place to return to

    int cp_size = 512;
    void *from = (void*) (old_sp = get_esp());
    void *to = (child->stack) - cp_size - 1;

    SHOW_INFO0( 10, "ifork memmove...");
    memmove(to, from, cp_size);

    //printf("set ESP...\n");
    SHOW_INFO0( 10, "set ESP...");
    set_esp((int)to);

//#warning sti
    // Save to new, switch to me -- WILL RETURN TO (X)
//printf("ifork GO...\n");
    phantom_switch_context(child, parent, &schedlock );
    // (NEW) phantom_switch_context() below returns here in new thread!!

//printf("ifork in NEW...\n");


}