void init_pcb_priority(struct pcb_s* pcb, func_t f, void* args ,unsigned int stack_size, unsigned int prio){

    // STEP 1 : initialisation de la pcb lors de la creation d'un processus

    pcb->pid   = pid++;
    pcb->state = ready;

    pcb->priority = prio;

    pcb->co = (int) start_current_process; // l'adresse de start_current_process est stockee dans co (program counter)
    pcb->f     = f;
    pcb->argsPointer = args; //argument de la fonction f
    pcb->startStack = (char*) phyAlloc_alloc(stack_size);

    //On decale le pointeur de pile sp a cause du pop.

    pcb->sp = (unsigned int*) (pcb->startStack + stack_size);
    pcb->sp --;

    *(pcb->sp) = 0x13;
    pcb->sp--;
    *(pcb->sp) = (unsigned int) &start_current_process;

    pcb->sp -= 14;


    // STEP 2 : liste chainee facon FIFO

    if(pcb->pid == 0 ){
        //etape initiale premier process cree
        head = pcb;
        pcb->next = NULL;

    }else{
        // on ajoute le process a la fin
        tail->next = pcb;

    }

    //et on met a jour tail
    tail = pcb;
}
Example #2
0
void init_ctx( ctx_s* ctx, func_t f, unsigned int stack_size)
{
	ctx->sp_end = phyAlloc_alloc(stack_size);
	ctx->sp = ctx->sp_end + stack_size*MEM_UNIT;
	ctx->pc = f;
}