Exemple #1
0
void syscall_proc()
{
  syscall_init_done = 1;
  
  while(1) {
    MESSAGE * msg_p = recv(NORMAL_MSG);
    //    msg_p = va2la(msg_p->sender_pid, msg_p); //地址已经转换好了
    //    printf("syscall");
    struct MSG_BODY_S * body_p = &(msg_p->body);
    switch (msg_p->type) {
    case MSG_get_ticks:
      body_p->arg1 = _get_ticks();
      break;
    case MSG_write:
      _write(body_p->arg1, body_p->arg2, get_process(msg_p->sender_pid));
      break;
    case MSG_writek:
      _writek(body_p->arg1, body_p->arg2, get_process(msg_p->sender_pid));
      break;
    default:
      break;
    }
    unblock_process(msg_p->sender_pid);
  }
}
Exemple #2
0
//int argc;
//char *argv[];
main(int argc,char * argv[])
{
    int command;
    int prio;
    float ratio;
    int status;

    if (argc < (MAXPRIO+1))
    {
        fprintf(stdout, "incorrect usage\n");
        return;
    }

    initialize();
    for (prio=MAXPRIO; prio >= 1; prio--)
    {
        init_prio_queue(prio, atoi(argv[prio]));
    }
    for (status = fscanf(stdin, "%d", &command);((status!=EOF) && status);status = fscanf(stdin, "%d", &command))
    {
        switch (command)
        {
        case FINISH:
            finish_process();
            break;
        case BLOCK:
            block_process();
            break;
        case QUANTUM_EXPIRE:
            quantum_expire();
            break;
        case UNBLOCK:
            fscanf(stdin, "%f", &ratio);
            unblock_process(ratio);
            break;
        case UPGRADE_PRIO:
            fscanf(stdin, "%d", &prio);
            fscanf(stdin, "%f", &ratio);
            if (prio > MAXPRIO || prio <= 0)
            {
                fprintf(stdout, "** invalid priority\n");
                return;
            }
            else
            {
                upgrade_process_prio(prio, ratio);
            }
            break;
        case NEW_JOB:
            fscanf(stdin, "%d", &prio);
            if (prio > MAXPRIO || prio <= 0)
            {
                fprintf(stdout, "** invalid priority\n");
                return;
            }
            else
            {
                add_process(prio);
            }
            break;
        case FLUSH:
            finish_all_processes();
            break;
        }
    }
}
Exemple #3
0
int comms_reply(unsigned int port, void *buf, unsigned int size)
{
  
  //return no such port when port doesn't exist
  if (bt(comms_bitmap,port))
  {
    update_port_error(cr3(),-ERR_IPC_NO_SUCH_PORT);
    return -ERR_IPC_NO_SUCH_PORT;
  }
  //return invalid port when port exceeds max ports
  if (port >= COMMS_MAX_PORTS)
  {
    update_error(port,-ERR_IPC_INVALID_PORT);
    return -ERR_IPC_INVALID_PORT;
  }
  //return invalid msg size if buf is less than 1 or exceeds max msg size
  if ((size < 1) | (size > COMMS_MAX_MSG))
  {
    update_error(port,-ERR_IPC_INVALID_MSG_SIZE);
    return -ERR_IPC_INVALID_MSG_SIZE;
  }
  //return invalid buffer when a buffer equals NULL
  if (buf == NULL)
  {
    update_error(port,-ERR_IPC_INVALID_BUFFER);
    return -ERR_IPC_INVALID_BUFFER;
  }
  
  
  //double check if the message is still there
  if (msg_port[port]->queue != NULL)
  {
    //save message into temp
    msg* temp = msg_port[port]->queue;
    
    //check if the sizes are correct
    if (temp->rep_size != size)
    {
      return -ERR_IPC_REPLY_MISMATCH;
    }
        
    //move to next message
    msg_port[port]->queue = msg_port[port]->queue->next;
    //if there is no messages make sure last knows this
    if (msg_port[port] == NULL)
    {
      msg_port[port]->last = NULL;
    }
    
    //switch to client pd
    i386_set_page_directory(temp->pd);
    
    //copy buf into reply address
    copy_4((unsigned int)buf+temp->mult,temp->rep_buf,size/4);
    
    //switch back to server pd
    i386_set_page_directory(msg_port[port]->pcb->pd);
    
    //remove the server page table from the message
    ((page_directory*)(temp->pd))->table[temp->offset] = 0;
    
    //free the memory the message used    
    mem_free(temp);
    
    //unblock the client
    unblock_process(port);
  }else
  {
    //will this happen?    
  } 
  //return OK  
  return OK;
}
Exemple #4
0
void tty_process()
{
  MESSAGE m;
  TTY * tty_p;
  int i=0;
  PROCESS * self = get_process(TASK_TTY);


  tty_init_done = 1;
  
  while(1){
    xmemcpy(&m, recv(NORMAL_MSG|INT_MSG), sizeof(MESSAGE)); /* 这里memcpy是因为, 收到的msg可能来自fs_task
							       ,fs_task作为发送者不能被block,
							       会马上被唤醒,那么栈上的变量会没有,
							       所以要复制一份
							    */

    switch(m.type) {
    case MSG_tty_read:
      queue_read_msg(&m);
      break;
    case MSG_tty_write:
      queue_write_msg(&m);
      break;
    default:			/* 这个是来自键盘中断的消息,因为中断函数不能block,所以消息内容不能确定
				   所以,不能用type来判断
				 */
      for (i=0, tty_p=&tty_table[i];i<TTY_NUM;i++, tty_p=&(tty_table[i])) {
	if (! keyboard_read(tty_p)) break;
      }
      
      break;
    }
    
    if (m.type == MSG_tty_read || m.type == MSG_tty_write) { /* unblock fs_task */
      unblock_process(m.sender_pid);
    }
    for (i=0;i<TTY_NUM;i++) {
      if (wait_read_msgs[i].ext_flag) {
	if (do_read(&(wait_read_msgs[i].m))) {
	  wait_read_msgs[i].ext_flag = 0;
	  unblock_process(((MESSAGE*)(wait_read_msgs[i].m.tty_read_REQUEST_M))->sender_pid);
	}
      }
    }
    for (i=0;i<TTY_NUM;i++) {
      if (wait_write_msgs[i].ext_flag) {
	if (do_write(&(wait_write_msgs[i].m))) {
	  wait_write_msgs[i].ext_flag = 0;
	  unblock_process(((MESSAGE*)(wait_write_msgs[i].m.tty_write_REQUEST_M))->sender_pid);
	}
      }
    }
    
    for (i=0, tty_p=&tty_table[i];i<TTY_NUM;i++, tty_p=&(tty_table[i])) {
      keyboard_write(tty_p);
      flush_tty_out_cache(tty_p);
    }

    /* 清理来自keyboard中断的信息 */
    /* while(self->int_msg_count > 0) { */
    /*   recv(INT_MSG); */
    /* } */
  
    
  }
}