Example #1
0
void
input(envid_t ns_envid)
{
	binaryname = "ns_input";

	// LAB 6: Your code here:
	// 	- read a packet from the device driver
	//	- send it to the network server
	// Hint: When you IPC a page to the network server, it will be
	// reading from it for a while, so don't immediately receive
	// another packet in to the same physical page.
	int RPKT_SIZE = 2048;
	
	int lengthOfPacket = RPKT_SIZE - 1;
	int r = 0;
	char buffer[RPKT_SIZE];
	
	while(1){
		while((r = sys_receive(buffer,&lengthOfPacket))<0){
		sys_yield();
	     }	
	
	while((r = sys_page_alloc(0, &nsipcbuf, PTE_P|PTE_U|PTE_W))<0);

	nsipcbuf.pkt.jp_len = lengthOfPacket;
	memmove(nsipcbuf.pkt.jp_data, buffer, lengthOfPacket);

	while((r = sys_ipc_try_send(ns_envid, NSREQ_INPUT, &nsipcbuf, PTE_P|PTE_U|PTE_W)) < 0);
	
	}
}
Example #2
0
int receiveMsg( tid_t sender, struct Message *msg, int timeout )
{
  int status;

  if( timeout == 0 )
    print("receive: timeout is zero\n");

  do
  {
    status = sys_receive( sender, msg, timeout );
  } while( status == -2 );

  return status;
}
Example #3
0
void
input(envid_t ns_envid)
{
	binaryname = "ns_input";

	// LAB 6: Your code here:
	// 	- read a packet from the device driver
	//	- send it to the network server
	// Hint: When you IPC a page to the network server, it will be
	// reading from it for a while, so don't immediately receive
	// another packet in to the same physical page.
	int len;
	while (1) {
	sys_page_alloc(0, &nsipcbuf, PTE_P|PTE_U|PTE_W);
	len = sys_receive(&nsipcbuf.pkt.jp_data);
	if (len >= 0) {
		nsipcbuf.pkt.jp_len = len;
		ipc_send(ns_envid, NSREQ_INPUT, &nsipcbuf, PTE_P|PTE_U);
		}
	}	
}
Example #4
0
//=======
//>>>>>>> new_lab5
// Dispatches to the correct kernel function, passing the arguments.
int32_t
syscall(uint32_t syscallno, uint32_t a1, uint32_t a2, uint32_t a3, uint32_t a4, uint32_t a5)
{
	// Call the function corresponding to the 'syscallno' parameter.
	// Return any appropriate return value.
	// LAB 3: Your code here.
	/*stone's solution for lab3-B*/
	int32_t ret = -E_INVAL;
	switch (syscallno){
		case SYS_cputs:
			sys_cputs((char*)a1, a2);
			ret = 0;
			break;
		case SYS_cgetc:
			ret = sys_cgetc();
			break;
		case SYS_getenvid:
			ret = sys_getenvid();
			break;
		case SYS_env_destroy:
			ret = sys_env_destroy(a1);
			break;
		case SYS_map_kernel_page:
			ret = sys_map_kernel_page((void*)a1, (void*)a2);
			break;
		case SYS_sbrk:
			ret = sys_sbrk(a1);
			break;
		/*stone's solution for lab4-A*/
		case SYS_yield:
			sys_yield();
			ret = 0;
			break;
		case SYS_exofork:
			ret = sys_exofork();
			break;
		case SYS_env_set_status:
			ret = sys_env_set_status(a1, a2);
			break;
		case SYS_env_set_pgfault_upcall:
			ret = sys_env_set_pgfault_upcall((envid_t)a1, (void*)a2);
			break;
		case SYS_page_alloc:
			ret = sys_page_alloc((envid_t)a1, (void*)a2, (int)a3);
			break;
		case SYS_page_map:
			/*stone: see lib/syscall.c for modification details*/
			ret = sys_page_map(*((uint32_t*)a1), (void*)*((uint32_t*)a1 + 1), *((uint32_t*)a1 + 2), (void*)*((uint32_t*)a1 + 3), *((uint32_t*)a1 + 4));
			//ret = sys_page_map(a1, (void*)a2, a3, (void*)a4, a5);
			break;
		case SYS_page_unmap:
			ret = sys_page_unmap(a1, (void*)a2);
			break;
		case SYS_ipc_recv:
			ret = sys_ipc_recv((void*)a1);
			break;
		case SYS_ipc_try_send:
			ret = sys_ipc_try_send((envid_t)a1, a2, (void*)a3, (int)a4);
			break;
		/*stone's solution for lab5*/
		case SYS_env_set_trapframe:
			ret = sys_env_set_trapframe((envid_t)a1, (struct Trapframe*)a2);
			break;
		/*stone's solution for lab6-A*/
		case SYS_time_msec:
			ret = sys_time_msec();
			break;
		case SYS_transmit:
			ret = sys_transmit((uint8_t*)a1, (uint32_t)a2);
			break;
		case SYS_receive:
			ret = sys_receive((uint8_t*)a1, (uint32_t*)a2);
			break;
		default:
			break;
	}
	return ret;
	//panic("syscall not implemented");
}