Exemplo n.º 1
0
void init_multitasking()
{
  asm volatile("cli");

  kernel_proc = create_process("microkernel", 0, 1, 0);
  kernel_proc->pgdir = (uint32_t)system_dir;

  new_process = (uint32_t)kernel_proc;

  current_task = (uint32_t)create_task("initiating_task",tasking_initiator, 0, 0x202, kernel_proc);  //Scheduler initalization task
  old_task = current_task;

  Spurious_task = create_task("Spurious_task", Spurious_task_func, 0, 0x202, kernel_proc);
  Spurious_task->special = 1;

  Idle_task = create_task("System_idle_task",idle, 0, 0x202, kernel_proc);  //default task, this dosent run
  Idle_task->special = 1;

  Shell_proc = create_process("Shell", 0, 1, kernel_proc);
  Shell_Ostream_task = create_task("Shell_Ostream", Shell_Double_buffer, 10, 0x202, Shell_proc);
  Activate_task_direct(Shell_Ostream_task); //This is the task which would make printing to console possible!
  Shell_Istream_task = create_task("Shell_Istream", Shell_Input, 1, 0x202, Shell_proc);
  Activate_task_direct(Shell_Istream_task); //This would manage keyboard input and delivery to the required process.
  //Shell_Istream_task->special = 1;
  Shell_task = create_task("Shell_task", Shell, 5, 0x202, Shell_proc);  //Main shell task.
  //Shell_task->special = 1;
  Activate_task_direct(Shell_task);

  SAS_proc = create_process("SAS", 0, 1, kernel_proc); //Scheduler Assistance System process.
  Activate_task_direct(create_task("SAS_init", SAS_init, 1, 0x202, SAS_proc)); //Initialization of SAS system.

  reached_bottom = 0;
  Scheduler_init(); // Let the FUN Begin :D Lets Switch from the old monotasking world to Multitasking World :D defined in tasking.asm
  while(1); //Never comeback :D
}
Exemplo n.º 2
0
int kmain (void){
	init_hw();
  	uart_init();
  	
	/*-- INPUT --*/
	//char buffer[32];
  	//uart_receive_str(buffer, 32);  //read

	/*-- PROCESS --*/
	create_process(funcA, NULL, STACK_SIZE,0);
	create_process(funcB, NULL, STACK_SIZE,0);
	create_process(functC,NULL,STACK_SIZE,1);
	
	/*-- virtual memory --*/
	//init_kern_translation_table();

	//configure_mmu_C();
	//start_mmu_C();

	//uint32_t* pt = (uint32_t*)vMem_Alloc(1);
	//*pt = sizeof(uint32_t);
	//uint32_t* pt = 0x500000;
	
	/*-- start --*/
	start_sched();

	while(1){}
	/* Pas atteignable vues nos 2 fonctions */
	return 0;
  
}
Exemplo n.º 3
0
void init_multitasking()
{
  asm volatile("cli");
  //memset((void*)(200*1024*1024),0,(40*1024*1024));
  kernel_proc = create_process("microkernel", 0, 1, 0);

  new_process = (uint32_t)kernel_proc;

  current_task = (uint32_t)create_task("initiating_task",tasking_initiator, 20, 0x202, kernel_proc);  //Scheduler initalization task
  old_task = current_task;

  Idle_task = create_task("System_idle_task",idle, 20, 0x202, kernel_proc);  //default task
  Activate_task_direct(Idle_task);

  Activate_task_direct(create_task("idle2",idle2, 10, 0x202, kernel_proc));
  Activate_task_direct(create_task("idle3",idle3, 10, 0x202, kernel_proc));
  Activate_task_direct(create_task("idle4",idle4, 10, 0x202, kernel_proc));
  Activate_task_direct(create_task("idle5",idle5, 10, 0x202, kernel_proc));
  Activate_task_direct(create_task("idle6",idle6, 10, 0x202, kernel_proc));
  //Activate_task_direct(create_task("Main_Kernel",kernel_main, 10, 0x202, kernel_proc));

  Shell_proc = create_process("Shell", 0, 1, kernel_proc);
  Activate_task_direct(create_task("Shell_Ostream", Console_Writer, 10, 0x202, Shell_proc));
  reached_bottom = 0;
  Scheduler_init(); // Let the FUN Begin :D Lets Switch from the old monotasking world to Multitasking World :D defined in tasking.asm
}
Exemplo n.º 4
0
void multi_processes_test()
{
	int rc, status;
	int pid1, pid2, pid3;
	char *process_test1[] = {
		"/process_test",
		"alice",
		NULL
	};
	char *process_test2[] = {
		"/process_test",
		"bob",
		NULL
	};
	char *process_test3[] = {
		"/process_test",
		"cathy",
		NULL
	};

	pid1 = create_process(process_test1[0], process_test1, 0, 16);
	if (pid1 == -1) {
		printf("create_process failed, err(%d).\n", pid1);
		goto out;
	}

	pid2 = create_process(process_test2[0], process_test2, 0, 16);
	if (pid2 == -1) {
		printf("create_process failed, err(%d).\n", pid2);
		goto out;
	}

	pid3 = create_process(process_test3[0], process_test3, 0, 16);
	if (pid3 == -1) {
		printf("create_process failed, err(%d).\n", pid3);
		goto out;
	}

	rc = waitpid(pid1, &status, 0);
	if (rc != 0) {
		printf("wait alice failed, err(%d).\n", rc);
	}

	rc = waitpid(pid2, &status, 0);
	if (rc != 0) {
		printf("wait bob failed, err(%d).\n", rc);
	}

	rc = waitpid(pid3, &status, 0);
	if (rc != 0) {
		printf("wait cathy failed, err(%d).\n", rc);
	}

 out:
	return;
}
Exemplo n.º 5
0
//------------------------------------------------------------------------
int kmain ( void )
{
	init_hw();
	create_process(funcB, NULL, STACK_SIZE);
	create_process(funcA, NULL, STACK_SIZE);
	start_sched();
	ctx_switch();
	/* Pas atteignable vu nos 2 fonctions */
	return 0;
}
Exemplo n.º 6
0
Arquivo: main.c Projeto: chywoo/vos
void main(void)
{
	kernel_init();

	create_process(ex_ps1);
	create_process(ex_ps2);
	create_process(ex_ps3);

	scheduler();
}
Exemplo n.º 7
0
//-----------------------------------------------------------------------------
int
notmain ( void )
{

	create_process( turn_led_off );
	create_process( play_music );

	start_scheduler();

 	return 0;
}
Exemplo n.º 8
0
void kmain()
{
	init_kernel();

	create_process(&process1);
	create_process(&process2);
	
	start_kernel();
	
	__asm("cps 0x10"); // CPU to USER mode
	
	while (1) ;
}
Exemplo n.º 9
0
/*
 * This test creates a sender and a receiver process. The receiver process
 * has the higher priority and is scheduled first. 
 * The execution sequence is as follow:
 * 1. The receiver executes a receive() and becomes RECEIVE_BLOCKED. 
 * 2. The sender gets executed and does a send(). The message is immediately
 *    delivered, unblocking the receiver and making the sender REPLY_BLOCKED.
 * 3. The receiver is executed. It does a receive and becomes RECEIVE_BLOCKED
 *    again.  
 * 4. The sender gets executed and does a message(). The message is immediately
 *    delivered, unblocking the receiver. The sender is still STATE_READY.
 * 5. The receiver gets the execution again. 
 * This test send() and message() in the case that the receiver is  
 * ready to receive. It also test receive() in the case that there is no 
 * messages pending. 
 */
void test_ipc_3()
{
    PORT new_port;

    test_reset();
    new_port = create_process (test_ipc_3_receiver_process, 6, 0, "Receiver");
    create_process(test_ipc_3_sender_process, 5, (PARAM) new_port, "Sender");
    resign();

    kprintf("Back to boot.\n");  
    if (check_sum == 1 || check_sum == 7)
	test_failed(52);
}
Exemplo n.º 10
0
//------------------------------------------------------------------------
int start_kernel ( void ) {
    malloc_init((void *) HEAP_START);

    create_process(&funcOne, (void*) 0);
    create_process(&funcTwo, (void*) 0);

    sem_init(&sem_test, 1);
    
    start_sched();

    /* Pas atteignable vues nos 2 fonctions */
    return(0);
}
Exemplo n.º 11
0
void ls_test()
{
	int rc, status;
	char *ls_root[] = {
		"/ls",
		"-l",
		"/",
		NULL
	};
	char *ls_proc[] = {
		"/ls",
		"/proc",
		NULL
	};
	char *ls_dev[] = {
		"/ls",
		"/dev",
		NULL
	};

	printf("unit_test list directory:\n");

	printf("listing /\n");
	rc = create_process(ls_root[0], ls_root, 0, 16);
	if (rc == -1) {
		printf("create_process(%s) failed, err(%d).\n", ls_root[0], rc);
		goto out;
	}

	rc = waitpid(rc, &status, 0);

	printf("listing /proc\n");
	rc = create_process(ls_proc[0], ls_proc, 0, 16);
	if (rc == -1) {
		printf("create_process(%s) failed, err(%d).\n", ls_proc[0], rc);
		goto out;
	}

	rc = waitpid(rc, &status, 0);

	printf("listing /dev\n");
	rc = create_process(ls_dev[0], ls_dev, 0, 16);

	rc = waitpid(rc, &status, 0);
	if (rc == -1) {
		printf("waiting %s failed, err(%d).\n", ls_proc[0], rc);
	}

 out:
	return;
}
Exemplo n.º 12
0
void kmain( void )
{    
    sched_init();
    
    p1=create_process((func_t*)&user_process_1);
    p2=create_process((func_t*)&user_process_2);
    
    __asm("cps 0x10"); // switch CPU to USER mode
    // **********************************************************************
    
    sys_yieldto(p1);

    // this is now unreachable
    PANIC();
}
Exemplo n.º 13
0
int main(int argc, char *argv[])
{
	unsigned short volume;
	pid_t pid = create_process();

	switch(pid) {
		case -1:
			return EXIT_FAILURE;
			break;
		case 0:
			if(argc > 1)
			{
				if(sscanf(argv[1], "%d", &volume) != EOF)
				{
					if(volume >= 0 && volume <= 100)
					{
						change_volume(volume);
					}
				}
			}
		break;
		default:
			if(wait(NULL) == -1) {
				perror("wait :");
				exit(EXIT_FAILURE);
			}
	}

	return 0;
}
int main() {

  pptr head=NULL;
  pptr tail=NULL;
  int i=0;
  int tprio,tarr_time,tburst_time,tpid;
  pptr tprocess;
  FILE *read;
  read=fopen("inputp","r");
  write=fopen("write","w");
  //trace=fopen("trace","w");
  for(i=1;i<=3;i++) {
    tpid=++g_pid;
    fscanf(read,"%d",&tarr_time);
    fscanf(read,"%d",&tburst_time);
    fscanf(read,"%d",&tprio);//toscan the priority
    tprocess=create_process(tpid,tarr_time,tburst_time);
    tprocess->over=tprio;//assigning prio
    add_to_queue(&head,&tail,tprocess);
  } fclose(read);

  tprocess=head;
  i=0;
  while(tprocess!=NULL) {
    ++i;
    tprocess=tprocess->next;
  }
  priopre(&head,&tail,i);
  return 0;
}
Exemplo n.º 15
0
/* handle a socket event */
static void master_socket_poll_event( struct fd *fd, int event )
{
    struct master_socket *sock = get_fd_user( fd );
    assert( master_socket->obj.ops == &master_socket_ops );

    assert( sock == master_socket );  /* there is only one master socket */

    if (event & (POLLERR | POLLHUP))
    {
        /* this is not supposed to happen */
        fprintf( stderr, "wineserver: Error on master socket\n" );
        release_object( sock );
    }
    else if (event & POLLIN)
    {
        struct sockaddr_un dummy;
        unsigned int len = sizeof(dummy);
        int client = accept( get_unix_fd( master_socket->fd ), (struct sockaddr *) &dummy, &len );
        if (client == -1) return;
        if (sock->timeout)
        {
            remove_timeout_user( sock->timeout );
            sock->timeout = NULL;
        }
        fcntl( client, F_SETFL, O_NONBLOCK );
        create_process( client, NULL, 0 );
    }
}
Exemplo n.º 16
0
void sc_syscall(ProcessState ** processtable, ProcessState * myprocess, SyscallReq * req) {
  //http://docs.cs.up.ac.za/programming/asm/derick_tut/syscalls.html
  switch(req->trapcode) { // read
    case 0b00000000000: do { // exit
      myprocess->state = 0;
    }while(0);break;

    case 0b00000000001: do { // fork
      ProcessState * newprocess = create_process(processtable, NULL, myprocess);
      if(newprocess == NULL){
        printf("process table is full\n");
      }
      newprocess->registers.ax.reg = 0;
      myprocess->registers.ax.reg = newprocess->pid;
    }while(0);break;

    case 0b00000000010: do {
      myprocess->registers.ax.reg = read(req->ax, &(myprocess->mem[req->ex]), req->fx);
    }while(0);break;

    case 0b00000000011: do { //write
      myprocess->registers.ax.reg = write(req->ax, &(myprocess->mem[req->ex]), req->fx);
    }while(0);break;

    default: do {

    }while(0);break;
  }
}
Exemplo n.º 17
0
/*
 * This test creates a sender and a receiver process. The sender process
 * has the higher priority and will be scheduled first.
 * The execution sequence is as follow:
 * 1. The sender executes a send(). Since the receiver is not RECEIVE_BLOCKED,
 *    the sender will be SEND_BLOCKED.
 * 2. Execution resumes with the receiver. The receiver executes a receive(),
 *    which will return immediately, and change the sender to state
 *    REPLY_BLOCKED.
 * 3. The receivers does a reply(), and put the sender back on the ready queue.
 *    The resign() in the reply() will therefore transfer the control back to
 *    the sender.
 * 4. The sender executes a message(). Since the receiver is not
 *    RECEIVE_BLOCKED, the sender will be MESSAGE_BLOCKED.
 * 5. Execution resumes with the receiver. The receiver executes a receive(),
 *    which will return immediately, and change the sender to STATE_READY.
 * 6. The receiver does a resign() and pass the execution back to the sender.
 * This test send() and message() in the case that the receiver is not
 * ready to receive. It also test receive() in the case that there are messages
 * pending.
 */
void test_ipc_2 ()
{
    PORT new_port;

    test_reset();
    new_port = create_process (test_ipc_2_receiver_process, 5, 0, "Receiver");
    create_process (test_ipc_2_sender_process, 6, (PARAM) new_port, "Sender");

    check_num_proc_on_ready_queue(3);
    check_process("Sender", STATE_READY, TRUE);
    check_process("Receiver", STATE_READY, TRUE);
    if (test_result != 0)
       test_failed(test_result);

    resign();
}
Exemplo n.º 18
0
/*
 * Creates two new processes with different priorities. When the main
 * thread calls resign(), execution should continue with test_process_c()
 * This process then removes itself from the ready queue and calls resign()
 * again. Execution should then continue in test_process_a()
 */
void test_dispatcher_4()
{
    test_reset();
    create_process(test_dispatcher_4_process_a, 5, 42, "Test process A");
    kprintf("Created process A\n");
    create_process(test_dispatcher_4_process_c, 7, 0, "Test process C");
    kprintf("Created process C\n");

    check_sum = 0;
    resign();
    if (check_sum == 0)
       test_failed(21); 

    if (check_sum != 3)
       test_failed(22); 
}
Exemplo n.º 19
0
void timer_process(PROCESS self, PARAM param) {
    PROCESS sender;
    int proc_index;
    int i;

    create_process(timer_notifier, 7, 0, "Timer notifier");
    while (42) {
        Timer_Message *msg = receive(&sender);
        if (msg != NULL) {
            // Message from client
            proc_index = sender - pcb;
            assert(sender == &pcb[proc_index]);
            ticks_remaining[proc_index] = msg->num_of_ticks;
        } else {
            // Message from timer notifier
            for (i = 0; i < MAX_PROCS; i++) {
                if (ticks_remaining[i] != 0) {
                    ticks_remaining[i]--;
                    if (ticks_remaining[i] == 0) {
                        assert(pcb[i].state == STATE_REPLY_BLOCKED);
                        reply(&pcb[i]);
                    }
                }
            }
        }
    }
}
Exemplo n.º 20
0
void create_process(int depth, char** argv)
{
	int pid, status;

	// Jeśli dziecko
	if((pid = fork()) == 0)
	{
		if(depth > 0)
			create_process(depth - 1, argv);	
		printf("Rozpoczęcie procesu potomnego %d, pid %d\n", depth, getpid());
		struct timespec t = {0, MS_TO_NS(500)};
		int i;
		int steps = atoi(argv[depth + 2]);
		for(i = 0; i <= steps; ++i)
		{
			printf("Potomny %d, krok %d/%d\n", depth, i, steps);
			nanosleep(&t, NULL);
		}
		printf("Koniec procesu potomnego %d, pid %d\n", depth, getpid());

		if(depth > 0)
		{
			pid = wait(&status);
			printf("Proces %d, zakończony: kod %d\n", pid, WEXITSTATUS(status));
		}
		
		exit(depth);
	}
}
Exemplo n.º 21
0
//------------------------------------------------------------------------
int start_kernel ( void ) {
    malloc_init((void*) HEAP_START);
    init_priorities();
    
    // Initializing the elements
    int unsorted[MAX_SIZE];
    unsorted[0] = 3;
    unsorted[1] = 8;
    unsorted[2] = 6;
    unsorted[3] = 2;
    unsorted[4] = 4;
    unsorted[5] = 1;
    unsorted[6] = 12;
    unsorted[7] = 10;

    int i;
    for (i = 0; i < MAX_SIZE; i++) {
        create_process(sort, (void*) unsorted[i], 2);
    }

    sem_init(&insert_sem, 1);

    start_sched();

    return(0);
}
Exemplo n.º 22
0
int	parse_champ_number(t_state *state, char **argv, int i, int count)
{
    int         tmp;
    int         n;

    tmp = 0;
    n = 0;
    while (i <= count)
    {
        if (!ft_strcmp(argv[i], "-n"))
        {
            n++;
            tmp = ft_atoi(argv[i + 1]);
            if (tmp <= 0)
                error_exit(state, "Error: position to be assigned cannot be less 0 or less\n");
            else if (tmp <= MAX_PLAYERS && tmp <= state->champ_count)
            {
                if (state->champ[tmp - 1] == NULL)
                    create_process(state, tmp, argv[i + 2]);
                else
                    error_exit(state, "Error: position already assigned\n");
            }
            else if (tmp > MAX_PLAYERS || tmp > state->champ_count)
                error_exit(state, "Error: Attempting to assign postion greater than max players / current players\n");
            i++;
        }
        else if (ft_strcmp(argv[i], "-n"))
            i++;
    }
    state->occupied = n;
    return (0);
}
Exemplo n.º 23
0
int wmain(int argc, wchar_t* argv[])
{
    void* proc2;

    start_redirection_server();

    if (argc==1)
    {
        do_mainA();

        proc2 = create_process(do_mainB, "B", "rw", fids);
        if (proc2)
            start_process(proc2);
        else
            perror("Failed to start processB: ");

        if (proc2)
        {
            int exit;
            do_piping();
            exit=wait_for_process(proc2);
            printf("wait_for_process returned %d\r\n", exit);
        }
    }
    else
    {
        do_mainB();
    }

    return 0;
}
Exemplo n.º 24
0
    bool
    Module_scanner<Impl>::insert_process(ast::Process const& node) {
      auto proc = create_process(node);
      m_mod.processes.push_back(proc);

      return false;
    }
Exemplo n.º 25
0
void add_endpoint(UsbDevice * udev, EndpointDesc * endpoint_desc)
{
	List * endpointListHook;
	EndpointHandle * endpointHandle;

	endpointHandle = ALLOC(sizeof(EndpointHandle));
	endpointHandle->process = create_process(udev->workqueue);
	endpointHandle->endpoint = ALLOC(sizeof(Endpoint));

	endpointHandle->endpoint->p_endpoint_desc = endpoint_desc;
	endpointHandle->endpoint->timeout = STD_TIMEOUT;

	INIT_SPINLOCK(&endpointHandle->endpoint->lock);

	endpointHandle->endpoint->complete_transfers = NULL;
	endpointHandle->endpoint->pending_transfers = NULL;

	endpointHandle->callback = NULL;

	endpointHandle->context = NULL;

	endpointListHook = ALLOC(sizeof(List));
	endpointListHook->data = endpointHandle;

	pushBack(&udev->endpoints_handles, endpointListHook);
}
Exemplo n.º 26
0
		int do_execute(const std::vector<std::basic_string<CharType>>& args, boost::system::error_code& ec)
		{
			if (args.empty())
			{
				ec = make_error_code(executeplus_error::external_process_failed);

				return EXIT_FAILURE;
			}

			const std::basic_string<CharType> application = args.front();
			std::basic_ostringstream<CharType> command_line_buffer;

			for (auto it = args.begin(); it != args.end(); ++it)
			{
				if (it != args.begin())
				{
					command_line_buffer << " ";
				}

				command_line_buffer << escape_argument_if_needed(*it);
			}

			std::basic_string<CharType> command_line = command_line_buffer.str();

			return create_process(application.c_str(), &command_line[0]);
		}
Exemplo n.º 27
0
int main() {

  pptr head=NULL;
  pptr tail=NULL;
  int i=0;
  int tpid,tarr_time,tburst_time;
  pptr tprocess;
  FILE *read;
  read=fopen("input","r");
  write=fopen("write","w");
  trace=fopen("trace","w");
  for(i=1;i<=3;i++) {
    //fscanf(read,"%d",&tpid);
    tpid=++g_pid;
    fscanf(read,"%d",&tarr_time);
    fscanf(read,"%d",&tburst_time);
    tprocess=create_process(tpid,tarr_time,tburst_time);
    add_to_queue(&head,&tail,tprocess);
  } fclose(read);

  fcfs(head,tail);



  return 0;


}
Exemplo n.º 28
0
void cat_test()
{
	int rc, status;
	char *cat[] = {
		"/cat",
		"/crontab",
		NULL
	};

	printf("unit_test cat file:\n");

	rc = create_process(cat[0], cat, 0, 16);
	if (rc == -1) {
		printf("create_process(%s) failed, err(%d).\n", cat[0], rc);
		goto out;
	}

	rc = waitpid(rc, &status, 0);
	if (rc == -1) {
		printf("waiting %s failed, err(%d).\n", cat[0], rc);
	}

 out:
	return;
}
Exemplo n.º 29
0
int
RSIM_Simulator::exec(int argc, char **argv)
{
    assert(argc>0);

    create_process();

    SgAsmGenericHeader *fhdr = process->load(argv[0]);
    entry_va = fhdr->get_base_va() + fhdr->get_entry_rva();

    RSIM_Thread *main_thread = process->get_thread(getpid());
    assert(main_thread!=NULL);
    process->initialize_stack(fhdr, argc, argv);

    process->binary_trace_start();

    if ((process->get_tracing_flags() & tracingFacilityBit(TRACE_MMAP))) {
        fprintf(process->get_tracing_file(), "memory map after program load:\n");
        process->get_memory()->dump(process->get_tracing_file(), "  ");
    }

    main_thread->tracing(TRACE_STATE)->mesg("Initial state:\n");
    main_thread->policy.dump_registers(main_thread->tracing(TRACE_STATE));

    return 0;
}
Exemplo n.º 30
0
void mkdir_test()
{
	int rc, status;
	char *mkdir[] = {
		"/mkdir",
		"/test",
		NULL
	};

	printf("unit_test make directory.\n");

	rc = create_process(mkdir[0], mkdir, 0, 16);
	if (rc == -1) {
		printf("create_process(%s) failed, err(%d).\n", mkdir[0], rc);
		goto out;
	}

	rc = waitpid(rc, &status, 0);
	if (rc == -1) {
		printf("waiting %s failed, err(%d).\n", mkdir[0], rc);
	}

 out:
	return;
}