// load_pls is a really crazy routine to read a playlist in from a file. // Currently, it is limited to 255 character lines void load_pls( char *plsname ) { FILE *pls; char *bytes, line[255], filename[255], *artist, *title, *tmp; int bcount, i, j, l, valid = 0; struct stat *pls_stat; pls_stat = (struct stat *)malloc(sizeof(struct stat)); if ( stat(plsname, pls_stat) == -1 ) { perror("stat"); return; } pls = fopen(plsname, "r"); bytes = (char *)malloc(pls_stat->st_size); artist = (char *)malloc(80); title = (char *)malloc(79); tmp = (char *)malloc(80); bcount = fread(bytes, 1, pls_stat->st_size, pls); j = 0; pls_clear(); for ( i = 0; i < bcount; i++ ) { if ( bytes[i] == '\n' || bytes[i] == '\r' ) { // Process a line if ( strcmp(line, "[playlist]") == 0 ) { valid = 1; } if ( valid && strncmp(line, "File", 4) == 0 ) { for ( l = 0; line[l] != '='; l++ ); l++; sprintf(filename, "%s", line+l); //artist = strtok(filename, "-"); artist[strlen(artist)-1] = '\0'; //tmp = strtok(NULL, ""); title = tmp+1; title[strlen(title)-4] = '\0'; pls_add("/mp3", filename); } j = 0; line[j] = '\0'; } else { line[j] = bytes[i]; line[j+1] = '\0'; j++; } } }
int32_t test_process_sleep() { /* * We set the following list : * plsready : * Name Pri State time to sleep * Pri42 42 READY 0 * Pri2 2 READY 0 * * plswaiting: * PRI41 41 SLEEP QUANTUM - 1 * PRI32 32 SLEEP 2*QUANTUM * PRI21 21 BLOCK 0 * PRI12 12 SLEEP 3*QUANTUM * * After the test the list will look like this: * plsready : * Name Pri State time to sleep * Pri42 42 READY 0 * PRI41 41 READY 0 * Pri2 2 READY 0 * * plswaiting: * PRI32 32 SLEEP QUANTUM * PRI21 21 BLOCK 0 * PRI12 12 SLEEP 2*QUANTUM */ pcb *p; pcb parray[MAXPCB]; pls_reset(&plsready); pls_reset(&plswaiting); /* * First populate the list */ p = &parray[0]; pcb_reset(p); pcb_set_name(p, "pri42"); pcb_set_pri(p, 42); pcb_set_state(p, READY); pcb_set_empty(p, FALSE); pls_add(&plsready, p); p = &parray[1]; pcb_reset(p); pcb_set_name(p, "pri2"); pcb_set_pri(p, 2); pcb_set_state(p, READY); pcb_set_empty(p, FALSE); pls_add(&plsready, p); p = &parray[2]; pcb_reset(p); pcb_set_name(p, "pri41"); pcb_set_pri(p, 41); pcb_set_state(p, SLEEPING); pcb_set_sleep(p, QUANTUM - 1); pcb_set_empty(p, FALSE); pls_add(&plswaiting, p); p = &parray[3]; pcb_reset(p); pcb_set_name(p, "pri32"); pcb_set_pri(p, 32); pcb_set_state(p, SLEEPING); pcb_set_sleep(p, 2 * QUANTUM); pcb_set_empty(p, FALSE); pls_add(&plswaiting, p); p = &parray[4]; pcb_reset(p); pcb_set_name(p, "pri21"); pcb_set_pri(p, 21); pcb_set_state(p, BLOCKED); pcb_set_empty(p, FALSE); pls_add(&plswaiting, p); p = &parray[5]; pcb_reset(p); pcb_set_name(p, "pri12"); pcb_set_pri(p, 12); pcb_set_state(p, SLEEPING); pcb_set_sleep(p, 3 * QUANTUM); pcb_set_empty(p, FALSE); pls_add(&plswaiting, p); /* * Ok, fire in the hole! */ process_sleep(); /* * Now the long and painfull check */ if (strcmp(pcb_get_name(plsready.start), "pri42") != 0) return -1; p = pcb_get_next(plsready.start); if (strcmp(pcb_get_name(p), "pri41") != 0 || pcb_get_sleep(p) != 0 || pcb_get_state(p) != READY) return -2; p = pcb_get_next(p); if (strcmp(pcb_get_name(p), "pri2") != 0) return -3; if (strcmp(pcb_get_name(plswaiting.start), "pri32") != 0 || pcb_get_sleep(plswaiting.start) != QUANTUM || pcb_get_state(plswaiting.start) != SLEEPING) return -4; p = pcb_get_next(plswaiting.start); if (strcmp(pcb_get_name(p), "pri21") != 0) return -5; p = pcb_get_next(p); if (strcmp(pcb_get_name(p), "pri12") != 0 || pcb_get_sleep(p) != 2 * QUANTUM || pcb_get_state(p) != SLEEPING) return -6; return OMGROXX; }
/** * \private * create a pcb with all the needed value at the specified location */ uint32_t create_proc(char *name, uint32_t prio, uint32_t argc, char **params) { uint32_t *i, j; int32_t pid; pcb *p; prgm *prg; //kdebug_println("Create process in"); if (name == NULL) return NULLPTR; if (prio > MAX_PRI || prio < MIN_PRI) return INVARG; if (pcb_counter <= MAXPCB) { /* * Allocate a pcb */ p = alloc_pcb(); if (p == NULL) return OUTOMEM; /* * Reset the pcb */ pcb_reset(p); /* * Check that the program exist */ prg = search_prgm(name); if (prg == NULL) return INVARG; /* * Set the name */ pcb_set_name(p, name); /* * init the program counter */ pcb_set_epc(p, (uint32_t) prg->address); /* * get a pid */ pid = get_next_pid(); if (pid < 0) return pid; /* contain an error code */ pcb_set_pid(p, pid); /* set the pid */ pcb_set_pri(p, prio); /* set the priority */ /* * Set the supervisor of the process, which is the one we ask for the creation * or -1 if the system ask. * This value is in the global variable current_pcb */ if (current_pcb != NULL) { pcb_set_supervisor(p, pcb_get_pid(current_pcb)); pcb_set_supervised(current_pcb, pid); } else pcb_set_supervisor(p, -1); /* <<<<<<< HEAD:src/kernel/kprocess.c <<<<<<< HEAD:src/kernel/kprocess.c * Set the parameters of the function */ //p->registers.a_reg[0] = (params == NULL) ? 0 : stoi(get_arg(params, 0)) + 1; //p->registers.a_reg[1] = (uint32_t) params; /* the adresse of the first arg */ if (params != NULL) { p->registers.a_reg[0] = argc + 1; p->registers.a_reg[1] = (uint32_t) params; } else { p->registers.a_reg[0] = 0; p->registers.a_reg[1] = 0; } /* ======= >>>>>>> 3e4887fd7d8130975ae6c220ed2077f5f2538be9:src/kernel/kprocess.c * Set the stack pointer ======= * Set the stack pointer >>>>>>> ef0b08729fd10e82db039bea92d2ce232b3a027b:src/kernel/kprocess.c */ i = allocate_stack(pcb_get_pid(p)); if (i == NULL) return OUTOMEM; /* * We add the arg on the stack */ //kprint("sp set\n"); if (params != NULL) { //kprint((char *) params); //kprint("params not null\n"); //kprint(itos((uint32_t) i, c)); //kprint("\n"); i = (uint32_t *) ((uint32_t) i - (ARG_SIZE * (argc + 1) * sizeof(char))); /* set the sp after the arg */ //kprint(itos((uint32_t) i, c)); //kprint("\n"); pcb_set_sp(p, (uint32_t) i); /* set the stack pointer */ for (j = 0; j < (argc + 1) * (ARG_SIZE * sizeof(char) / sizeof(uint32_t)); j++) { //kprint("Copy params\n"); *i = (uint32_t) * params; //kprint("Param copied\n"); //i += ARG_SIZE * sizeof(char); i++; (uint32_t *) params++; } //kprint((char *) pcb_get_sp(p)); } else pcb_set_sp(p, (uint32_t) i); //kprint("copy arg done\n"); /* * Set the parameters of the function * The begin of the parameters are pointed by the stack pointer */ if (params != NULL) { p->registers.a_reg[0] = argc + 1; p->registers.a_reg[1] = (uint32_t) pcb_get_sp(p); } else { p->registers.a_reg[0] = 0; p->registers.a_reg[1] = 0; } /* * Set the state */ pcb_set_state(p, READY); /* * Set the last error */ pcb_set_error(p, OMGROXX); /* * The pcb is no more empty */ pcb_set_empty(p, FALSE); /* * Now we can add the pcb to the ready list */ if (pls_add(&plsready, p) == OUTOMEM) { /* * Adding fail, don't forget to dealloc every allocated stuff */ deallocate_stack(pcb_get_pid(p)); pcb_reset(p); return OUTOMEM; } /* * Everything goes well, we add one to the pcb_counter */ pcb_counter++; } else return OUTOMEM; //kdebug_println("Create process out"); return pid; }