Ejemplo n.º 1
0
void finish_SRTN(int id)
{
	if (queue_peek(q) == NULL || q->head->task.id != id) {
		printf("Queue either empty, or the process with the given id is not the current head of the Queue!\n");
		return;
	}
	Element *el = queue_poll(q);
	free(el);
	if (queue_size(q)){
		switch_task(q->head->task.id);
	}else{
		switch_task(IDLE);
		free_SRTN();
	}
}
Ejemplo n.º 2
0
/* Called by svc_handler */
void sched_svc_end_task(void) {
    struct task_ctrl *task = get_task_ctrl(curr_task);

    if (task->stack_limit > task->stack_top) {
        panic_print("Task (0x%x, fptr: 0x%x) has overflowed its stack. stack_top: 0x%x stack_limit: 0x%x", task, task->fptr, task->stack_top, task->stack_limit);
    }

    list_remove(&task->runnable_task_list);

    /* Periodic (but only if aborted) */
    if (task->period && task->abort) {
        list_remove(&task->periodic_task_list);
    }

    /* Periodic (but only if not aborted) */
    if (!task->abort && task->period) {
        task->running = 0;

        /* Reset stack */
        task->stack_top = task->stack_base;
    }
    else {
        /* Add to queue for freeing */
        list_add(&task->free_task_list, &free_task_list);

        total_tasks -= 1;
    }

    switch_task(NULL);
}
Ejemplo n.º 3
0
void kexit(int status) {
  current_task->exit_status = status;
  current_task->STATUS = TASK_ZOMBIE;
  current_task->end_time = timer_tick;
  //current_task->parent = 0; //A zombie has no parent
  if (DEBUG) printf("Exiting with status %d\n", status);
  switch_task();  
  printf("Warning: Should never come here at the end of kexit.c");
  return;
}
Ejemplo n.º 4
0
Archivo: pit.c Proyecto: ablakely/xnix
void timer_handler(struct regs *r)
{
	timer_ticks++;
	switch_task();

	if (timer_ticks % 18 == 0)
	{
		uptime++;
	}
}
Ejemplo n.º 5
0
static void xtest_a(void * data, char * name) {
	fs_node_t * tty = data;

	fprintf(tty, "[%s] Hello world.\n", name);

	while (1) {
		fprintf(tty, "[%s] Ping.\n", name);
		unsigned long s, ss;
		relative_time(1, 0, &s, &ss);
		sleep_until((process_t *)current_process, s, ss);
		switch_task(0);
	}
}
Ejemplo n.º 6
0
uint32_t read_serial(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buffer) {
	if (size < 1) {
		return 0;
	}
	memset(buffer, 0x00, 1);
	uint32_t collected = 0;
	while (collected < size) {
		while (!serial_rcvd((int)node->device)) {
			switch_task(1);
		}
		debug_print(NOTICE, "Data received from TTY");
		buffer[collected] = serial_recv((int)node->device);
		collected++;
	}
	return collected;
}
Ejemplo n.º 7
0
void consumer() {
    while (1) {
        uint32_t times = rand()%7;
        while (times--) {
            sem_wait(n);
            sem_wait(s);

            buffer--;
            printf("%d", buffer);
        //    printf("Buffer length = %d\n", buffer);

            sem_signal(s);
            sem_signal(e);
        //    printf("Consume a product !\n");
        }
        switch_task();
    }
}
Ejemplo n.º 8
0
void producer() {
    while (1) {
        uint32_t times = rand()%7;
        while (times--) {
        //    printf("Produced a product !\n");
            sem_wait(e);
            sem_wait(s);

            buffer++;
            printf("%d", buffer);
        //    printf("Buffer length = %d\n", buffer);

            sem_signal(s);
            sem_signal(n);
        }
        switch_task();
    }
}
Ejemplo n.º 9
0
Archivo: task.c Proyecto: Roenke/os
void next_task()
{
    uint8_t is_enabled = readeflags() & 0x200;
    cli();
    
    if (task_count <= 1)
    {
        return;
    }

    task_t *previous_task = current_task;
    current_task = current_task->next;
    switch_task(&(previous_task->regs), current_task->regs);

    if(is_enabled)
    {
        sti();
    }
}
Ejemplo n.º 10
0
Archivo: main.c Proyecto: etel/ponyos
/*
 * multiboot i386 (pc) kernel entry point
 */
int kmain(struct multiboot *mboot, uint32_t mboot_mag, uintptr_t esp) {
	initial_esp = esp;
	extern char * cmdline;

	uint32_t mboot_mods_count = 0;
	mboot_mod_t * mboot_mods = NULL;
	mboot_ptr = mboot;

	ENABLE_EARLY_BOOT_LOG(0);

	assert(mboot_mag == MULTIBOOT_EAX_MAGIC && "Didn't boot with multiboot, not sure how we got here.");
	debug_print(NOTICE, "Processing Multiboot information.");

	/* Initialize core modules */
	gdt_install();      /* Global descriptor table */
	idt_install();      /* IDT */
	isrs_install();     /* Interrupt service requests */
	irq_install();      /* Hardware interrupt requests */

	if (mboot_ptr->flags & (1 << 3)) {
		debug_print(NOTICE, "There %s %d module%s starting at 0x%x.", mboot_ptr->mods_count == 1 ? "is" : "are", mboot_ptr->mods_count, mboot_ptr->mods_count == 1 ? "" : "s", mboot_ptr->mods_addr);
		debug_print(NOTICE, "Current kernel heap start point would be 0x%x.", &end);
		if (mboot_ptr->mods_count > 0) {
			uintptr_t last_mod = (uintptr_t)&end;
			uint32_t i;
			mboot_mods = (mboot_mod_t *)mboot_ptr->mods_addr;
			mboot_mods_count = mboot_ptr->mods_count;
			for (i = 0; i < mboot_ptr->mods_count; ++i ) {
				mboot_mod_t * mod = &mboot_mods[i];
				uint32_t module_start = mod->mod_start;
				uint32_t module_end   = mod->mod_end;
				if ((uintptr_t)mod + sizeof(mboot_mod_t) > last_mod) {
					/* Just in case some silly person put this *behind* the modules... */
					last_mod = (uintptr_t)mod + sizeof(mboot_mod_t);
				}
				debug_print(NOTICE, "Module %d is at 0x%x:0x%x", i, module_start, module_end);
				if (last_mod < module_end) {
					last_mod = module_end;
				}
			}
			debug_print(NOTICE, "Moving kernel heap start to 0x%x", last_mod);
			kmalloc_startat(last_mod);
		}
	}

	paging_install(mboot_ptr->mem_upper + mboot_ptr->mem_lower);
	if (mboot_ptr->flags & (1 << 6)) {
		debug_print(NOTICE, "Parsing memory map.");
		mboot_memmap_t * mmap = (void *)mboot_ptr->mmap_addr;
		while ((uintptr_t)mmap < mboot_ptr->mmap_addr + mboot_ptr->mmap_length) {
			if (mmap->type == 2) {
				for (unsigned long long int i = 0; i < mmap->length; i += 0x1000) {
					if (mmap->base_addr + i > 0xFFFFFFFF) break; /* xxx */
					debug_print(INFO, "Marking 0x%x", (uint32_t)(mmap->base_addr + i));
					paging_mark_system((mmap->base_addr + i) & 0xFFFFF000);
				}
			}
			mmap = (mboot_memmap_t *) ((uintptr_t)mmap + mmap->size + sizeof(uintptr_t));
		}
	}
	paging_finalize();

	{
		char cmdline_[1024];

		size_t len = strlen((char *)mboot_ptr->cmdline);
		memmove(cmdline_, (char *)mboot_ptr->cmdline, len + 1);

		/* Relocate the command line */
		cmdline = (char *)kmalloc(len + 1);
		memcpy(cmdline, cmdline_, len + 1);
	}

	/* Memory management */
	heap_install();     /* Kernel heap */

	if (cmdline) {
		args_parse(cmdline);
	}

	vfs_install();
	tasking_install();  /* Multi-tasking */
	timer_install();    /* PIC driver */
	fpu_install();      /* FPU/SSE magic */
	syscalls_install(); /* Install the system calls */
	shm_install();      /* Install shared memory */
	modules_install();  /* Modules! */

	DISABLE_EARLY_BOOT_LOG();

	/* Load modules from bootloader */
	debug_print(NOTICE, "%d modules to load", mboot_mods_count);
	for (unsigned int i = 0; i < mboot_ptr->mods_count; ++i ) {
		mboot_mod_t * mod = &mboot_mods[i];
		uint32_t module_start = mod->mod_start;
		uint32_t module_end = mod->mod_end;
		size_t   module_size = module_end - module_start;

		if (!module_quickcheck((void *)module_start)) {
			debug_print(NOTICE, "Loading ramdisk: 0x%x:0x%x", module_start, module_end);
			ramdisk_mount(module_start, module_size);
		} else {

			debug_print(NOTICE, "Loading a module: 0x%x:0x%x", module_start, module_end);
			module_data_t * mod_info = (module_data_t *)module_load_direct((void *)(module_start), module_size);
			if (mod_info) {
				debug_print(NOTICE, "Loaded: %s", mod_info->mod_info->name);
			}
		}
	}

	/* Map /dev to a device mapper */
	map_vfs_directory("/dev");

	if (args_present("root")) {
		vfs_mount_type("ext2", args_value("root"), "/");
	}

	if (args_present("start")) {
		char * c = args_value("start");
		if (!c) {
			debug_print(WARNING, "Expected an argument to kernel option `start`. Ignoring.");
		} else {
			debug_print(NOTICE, "Got start argument: %s", c);
			boot_arg = strdup(c);
		}
	}

	if (!fs_root) {
		debug_print(CRITICAL, "No root filesystem is mounted. Skipping init.");
		map_vfs_directory("/");
		switch_task(0);
	}

	/* Prepare to run /bin/init */
	char * argv[] = {
		"/bin/init",
		boot_arg,
		NULL
	};
	int argc = 0;
	while (argv[argc]) {
		argc++;
	}
	system(argv[0], argc, argv); /* Run init */

	return 0;
}
Ejemplo n.º 11
0
static void timer_callback(registers_t regs)
{
    tick++;
    switch_task();
}
Ejemplo n.º 12
0
void spin_lock(uint8_t volatile * lock) {
	while(__sync_lock_test_and_set(lock, 0x01)) {
		switch_task(1);
	}
}
Ejemplo n.º 13
0
static void timer_callback(struct s_regs *regs)
{
    tick++;
    switch_task(regs);
}