Ejemplo n.º 1
0
// Send 'val' (and 'pg' with 'perm', if 'pg' is nonnull) to 'toenv'.
// This function keeps trying until it succeeds.
// It should panic() on any error other than -E_IPC_NOT_RECV.
//
// Hint:
//   Use sys_yield() to be CPU-friendly.
//   If 'pg' is null, pass sys_ipc_recv a value that it will understand
//   as meaning "no page".  (Zero is not the right value.)
void
ipc_send(envid_t to_env, uint32_t val, void *pg, int perm)
{
	// LAB 4: Your code here.
	//panic("ipc_send not implemented");
	int result;

	if(pg == NULL)
	{
		result=sys_ipc_try_send(to_env, val, (void *)UTOP, perm);
	}
	else
	{
		result=sys_ipc_try_send(to_env, val, pg, perm);
	}
	
	while(result < 0)
	{
		if(result != -E_IPC_NOT_RECV)
		{
			panic ("ipc send error!");
		}
		
		sys_yield ();

		if(pg == NULL)
		{
			result=sys_ipc_try_send(to_env, val, (void *)UTOP, perm);
		}
		else
		{
			result=sys_ipc_try_send(to_env, val, pg, perm);
		}
	}
}
Ejemplo n.º 2
0
// Send 'val' (and 'pg' with 'perm', if 'pg' is nonnull) to 'toenv'.
// This function keeps trying until it succeeds.
// It should panic() on any error other than -E_IPC_NOT_RECV.
//
// Hint:
//   Use sys_yield() to be CPU-friendly.
//   If 'pg' is null, pass sys_ipc_recv a value that it will understand
//   as meaning "no page".  (Zero is not the right value.)
void
ipc_send(envid_t to_env, uint32_t val, void *pg, int perm)
{
	int r;

	if (pg == NULL)
		pg = (void *)UTOP;

	do {
		int r = sys_ipc_try_send(to_env, val, pg, perm);

		switch (r) {
		case 0:
		case 1:
			return;

		case -E_IPC_NOT_RECV:
			sys_yield();
			continue;

		default:
			panic("sys_ipc_try_send(%08x, %u, %08x, %d) failed: %e\n",
				to_env, val, pg, perm, r);
		}
	} while (1);
}
Ejemplo n.º 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 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);
	
	}
}
Ejemplo n.º 4
0
Archivo: ipc.c Proyecto: gzs715/JOS
// Send 'val' (and 'pg' with 'perm', assuming 'pg' is nonnull) to 'toenv'.
// This function keeps trying until it succeeds.
// It should panic() on any error other than -E_IPC_NOT_RECV.
//
// Hint:
//   Use sys_yield() to be CPU-friendly.
//   If 'pg' is null, pass sys_ipc_recv a value that it will understand
//   as meaning "no page".  (Zero is not the right value.)
void
ipc_send(envid_t to_env, uint32_t val, void *pg, int perm)
{
	// LAB 4: Your code here.
	int ret;
	void * srcva;
	if(pg == 0)
		srcva = (void*)UTOP;
	else
		srcva = pg;
	while(1)
	{
		ret = sys_ipc_try_send(to_env,val,srcva,perm);
		if(ret == 0 || ret == 1)		
		{
			//cprintf("return 0\n");
			sys_yield();
			break;
		}
		else if(ret == -E_IPC_NOT_RECV)
		{
			//cprintf("ipc not recv\n");
			sys_yield();
			continue;
		}
		else
			panic("error occur in ipc send:%e",ret);
	}
	//cprintf("return from ipc send\n");
	//panic("ipc_send not implemented");
}
Ejemplo n.º 5
0
// Dispatches to the correct kernel function, passing the arguments.
int64_t
syscall(uint64_t syscallno, uint64_t a1, uint64_t a2, uint64_t a3, uint64_t a4, uint64_t a5)
{
	// Call the function corresponding to the 'syscallno' parameter.
	// Return any appropriate return value.
	// LAB 3: Your code here.
//	panic("syscall not implemented");

	switch (syscallno) {

	case SYS_cputs:
			sys_cputs((const char *)a1, (size_t)a2);
			return 0;
	case SYS_cgetc:
			return sys_cgetc();
        case SYS_getenvid:
			return sys_getenvid();
        case SYS_env_destroy:
			return sys_env_destroy(a1);
	case SYS_yield:
			sys_yield();
			return 0;			
	case SYS_page_alloc:
        		return sys_page_alloc((envid_t)a1, (void *)a2,(int)a3);
	case SYS_page_map:
			return sys_page_map((envid_t)a1, (void *)a2, (envid_t)a3, (void *)a4, (int)a5);        
	case SYS_page_unmap:
			return sys_page_unmap((envid_t)a1, (void *)a2);        
	case SYS_exofork:
			return sys_exofork();        
	case SYS_env_set_status:
			return sys_env_set_status((envid_t)a1, a2);	
	case SYS_env_set_pgfault_upcall:
			return sys_env_set_pgfault_upcall((envid_t)a1,(void *)a2);		
	case SYS_ipc_try_send:
			return sys_ipc_try_send((envid_t)a1, (uint32_t)a2, (void *)a3, a4);
	case SYS_ipc_recv:
			return sys_ipc_recv((void *)a1);	
	case SYS_env_set_trapframe:
			return sys_env_set_trapframe((envid_t)a1, (struct Trapframe *)a2);
	case SYS_time_msec:
			return sys_time_msec();
	case SYS_packet_transmit:
			return sys_packet_transmit((char*)a1,(size_t)a2);
	case SYS_packet_receive:
                        return sys_packet_receive((char *)a1);
	//lab 7 code from here
	case SYS_insmod:
			return sys_insmod((char *)a1, (char *)a2,(char *)a3);
	case SYS_rmmod:
			return sys_rmmod((char *)a1);
	case SYS_lsmod:
			return sys_lsmod();
	case SYS_depmod:
			return sys_depmod((char *)a1);
	//lab7 code ends here
	default:
		return -E_NO_SYS;
	}
}
Ejemplo n.º 6
0
// Send 'val' (and 'pg' with 'perm', if 'pg' is nonnull) to 'toenv'.
// This function keeps trying until it succeeds.
// It should panic() on any error other than -E_IPC_NOT_RECV.
//
// Hint:
//   Use sys_yield() to be CPU-friendly.
//   If 'pg' is null, pass sys_ipc_try_send a value that it will understand
//   as meaning "no page".  (Zero is not the right value.)
void
ipc_send(envid_t to_env, uint32_t val, void *pg, int perm)
{
	// LAB 4: Your code here.
	struct Env *env;
	int r;
	void *srcva;

	if (pg == NULL) {
		srcva = (void *)~0;
	} else {
		srcva = pg;
	}

	IPC_DEBUG("ipc_send: perm = %d\n", perm);
	
	while ((r = sys_ipc_try_send(to_env, val, srcva, perm)) != 0) {
		if (r != -E_IPC_NOT_RECV) {
			panic("ipc_send: sys_ipc_try_send erro %e\n", r);
		}
	}

	// I tested and found out a sys_yield() here actually made things slower!
	// sys_yield();

	return;

}
Ejemplo n.º 7
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.
    uint8_t data[2048];
    int length, r;

    for (;;) {
        while ((length = sys_pkt_receive(data)) < 0)
            sys_yield();

        while (sys_page_alloc(0, &nsipcbuf, PTE_P | PTE_W | PTE_U) < 0)
            sys_yield();

        nsipcbuf.pkt.jp_len = length;
        memmove(nsipcbuf.pkt.jp_data, data, length);

        while (sys_ipc_try_send(ns_envid, NSREQ_INPUT, &nsipcbuf, PTE_P | PTE_W | PTE_U) < 0)
            sys_yield();
    }
}
Ejemplo n.º 8
0
Archivo: ipc.c Proyecto: dannoy/JOS
// Send 'val' (and 'pg' with 'perm', if 'pg' is nonnull) to 'toenv'.
// This function keeps trying until it succeeds.
// It should panic() on any error other than -E_IPC_NOT_RECV.
//
// Hint:
//   Use sys_yield() to be CPU-friendly.
//   If 'pg' is null, pass sys_ipc_recv a value that it will understand
//   as meaning "no page".  (Zero is not the right value.)
void
ipc_send(envid_t to_env, uint32_t val, void *pg, int perm)
{
	// LAB 4: Your code here.
    //panic("ipc_send not implemented");
    /* lj */
    int ret = 0;
    void *addr = NULL;
    addr = pg ? pg : (void *)-1;
    //cprintf("%x->%x [%d]\n", thisenv->env_id, to_env, val);
    
    while (1) {
        if(-E_IPC_NOT_RECV == ret) {
            sys_yield();
        }

        ret = sys_ipc_try_send(to_env, val, addr, perm);

        if(0 == ret) {
            break;
        }
        else if(-E_IPC_NOT_RECV == ret) {
            //cprintf("%x continue\n", thisenv->env_id);
            continue;
        }
        else if(ret < 0) {
            panic("ipc_send error:%e", ret);
        }
    }
}
Ejemplo n.º 9
0
Archivo: syscall.c Proyecto: ichaos/jos
// 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.
        curenv->env_syscalls++;
        switch(syscallno){
        case SYS_cputs:
                sys_cputs((char *)a1, (size_t)a2);break;
        case SYS_cgetc:
                sys_cgetc();break;
        case SYS_getenvid:
                return sys_getenvid();
        case SYS_env_destroy:
                return sys_env_destroy((envid_t)a1);
        case SYS_dump_env:
                sys_dump_env();break;
        case SYS_page_alloc:
                return sys_page_alloc((envid_t)a1, (void *)a2, (int)a3);
        case SYS_page_map: {
                return sys_page_map((envid_t)a1, (void *)a2,
                                    (envid_t)a3, (void *)a4, (int)a5);
        }
        case SYS_page_unmap:
                return sys_page_unmap((envid_t)a1, (void *)a2);
        case SYS_exofork:
                return sys_exofork();
        case SYS_env_set_status:
                return sys_env_set_status((envid_t)a1,(int)a2);
        case SYS_env_set_trapframe:
                return sys_env_set_trapframe((envid_t)a1,
                                             (struct Trapframe *)a2);
        case SYS_env_set_pgfault_upcall:
                return sys_env_set_pgfault_upcall((envid_t)a1, (void *)a2);
        case SYS_yield:
                sys_yield();break;//new add syscall for lab4;
        case SYS_ipc_try_send:
                return sys_ipc_try_send((envid_t)a1, (uint32_t)a2,
                                        (void *)a3, (unsigned)a4);
        case SYS_ipc_recv:
                return sys_ipc_recv((void *)a1);
        case SYS_ide_read:
                sys_ide_read((uint32_t)a1, (void *)a2, (size_t)a3);
                break;
        case SYS_ide_write:
                sys_ide_write((uint32_t)a1, (void *)a2, (size_t)a3);
                break;
        case SYS_time_msec:
                return sys_time_msec();
        case NSYSCALLS:
                break;
        default:
                return -E_INVAL;
        }
        return 0;

	//panic("syscall not implemented");
}
Ejemplo n.º 10
0
// 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.
	int32_t ret = -E_INVAL;
	switch(syscallno) {
		case SYS_cputs:
			sys_cputs((char *)a1, a2);
			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_yield:
			sys_yield();
			ret = 0;
			break;
		case SYS_map_kernel_page:
			ret = sys_map_kernel_page((void *)a1, (void *)a2);
			break;
		case SYS_sbrk:
			ret = sys_sbrk(a1);
			break;
		case SYS_exofork:
			ret = sys_exofork();
			break;
		case SYS_env_set_status:
			ret = sys_env_set_status(a1,a2);
			break;
		case SYS_page_alloc:
			ret = sys_page_alloc(a1,(void*)a2,a3);
			break;
		case SYS_page_map:
			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_env_set_pgfault_upcall:
			ret = sys_env_set_pgfault_upcall(a1,(void*)a2);
			break;
		case SYS_ipc_try_send:
			ret = sys_ipc_try_send(a1,a2,(void*)a3,a4);
			break;
		case SYS_ipc_recv:
			ret = sys_ipc_recv((void*)a1);
	}
	return ret;
//	panic("syscall not implemented");
}
Ejemplo n.º 11
0
Archivo: syscall.c Proyecto: dannoy/JOS
// 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.
    /* lj */
    int ret = 0;
    switch(syscallno) {
        case SYS_cputs:
            sys_cputs((const char *)a1, a2);
        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_yield:
            sys_yield();
        break;
        case SYS_exofork:
            ret = sys_exofork();
        break;
        case SYS_env_set_status:
            ret = sys_env_set_status((envid_t)a1, a2);
        break;
        case SYS_page_alloc:
            ret = sys_page_alloc((envid_t)a1, (void *)a2, a3);
        break;
        case SYS_page_map:
            ret = sys_page_map((envid_t)a1, (void *)a2, (envid_t)a3, (void *)a4, a5);
        break;
        case SYS_page_unmap:
            ret = sys_page_unmap((envid_t)a1, (void *)a2);
        break;
        case SYS_env_set_pgfault_upcall:
            ret = sys_env_set_pgfault_upcall((envid_t)a1, (void *)a2);
        break;
        case SYS_ipc_try_send:
            ret = sys_ipc_try_send((envid_t)a1, a2, (void *)a3, a4);
        break;
        case SYS_ipc_recv:
            ret = sys_ipc_recv((void *)a1);
        break;
        default:
            ret = -E_INVAL;
        break;
    }

    //panic("syscall not implemented");
    //cprintf("%d return to user %d\n", syscallno, ret);
    return ret;
}
Ejemplo n.º 12
0
// Send 'val' (and 'pg' with 'perm', assuming 'pg' is nonnull) to 'toenv'.
// This function keeps trying until it succeeds.
// It should panic() on any error other than -E_IPC_NOT_RECV.
void
ipc_send(envid_t to_env, uint32_t val, void *pg, int perm)
{
	int r;
	while (( r = sys_ipc_try_send(to_env, val, pg, perm)) == -E_IPC_NOT_RECV) {
		sys_yield();
	}
	if (r < 0)
		panic("icp_send %e", r);
}
Ejemplo n.º 13
0
// 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.
	int32_t r =0;
	switch(syscallno){
		case SYS_cputs:
			sys_cputs((const char*)a1,(size_t)a2);
			break;
		case SYS_cgetc:
			r = sys_cgetc();
			break;
		case SYS_getenvid:
			r = sys_getenvid();
			break;
		case SYS_env_destroy:
			r = sys_env_destroy((envid_t)a1);
			break;
		case SYS_yield:
			sys_yield();
			r =0;
			break;
		case SYS_exofork:
			r = sys_exofork();
			break;
		case SYS_env_set_status:
			r = sys_env_set_status((envid_t)a1,(int)a2);
			break;
		case SYS_page_alloc:
			r = sys_page_alloc((envid_t)a1 ,(void *)a2, (int)a3);
			break;
		case SYS_page_map:
			r = sys_page_map((envid_t)a1, (void *)a2, (envid_t)a3, (void *)a4, (int)a5);
			break;
		case SYS_page_unmap:
			r = sys_page_unmap((envid_t)a1,(void *)a2);
			break;
		case SYS_env_set_pgfault_upcall:
			r = sys_env_set_pgfault_upcall((envid_t)a1, (void *)a2);
			break;
		case SYS_ipc_try_send:
			r = sys_ipc_try_send((envid_t)a1, (uint32_t)a2, (void *)a3, (unsigned int)a4);
			break;
		case SYS_ipc_recv:
			r = sys_ipc_recv((void *)a1);
			break;
		default:
			r = -E_INVAL;
	}
	return r;
	panic("syscall not implemented");
}
Ejemplo n.º 14
0
// Send 'val' (and 'pg' with 'perm', if 'pg' is nonnull) to 'toenv'.
// This function keeps trying until it succeeds.
// It should panic() on any error other than -E_IPC_NOT_RECV.
//
// Hint:
//   Use sys_yield() to be CPU-friendly.
//   If 'pg' is null, pass sys_ipc_try_send a value that it will understand
//   as meaning "no page".  (Zero is not the right value.)
void
ipc_send(envid_t to_env, uint32_t val, void *pg, int perm)
{
	// LAB 4: Your code here.
	// panic("ipc_send not implemented");
	int r;
	void *srcva = pg?pg:(void*)UTOP;
	while ((r = sys_ipc_try_send(to_env, val, srcva, perm))) {
		if (r != -E_IPC_NOT_RECV) panic("sys_ipc_try_send fail:%e, pg:%#0x, perm:%d\n", r, (int)pg, perm);
		sys_yield();
	}
}
Ejemplo n.º 15
0
Archivo: ipc.c Proyecto: zellux/nexus
// Send 'val' (and 'pg' with 'perm', assuming 'pg' is nonnull) to 'toenv'.
// This function keeps trying until it succeeds.
// It should panic() on any error other than -E_IPC_NOT_RECV.
//
// Hint:
//   Use sys_yield() to be CPU-friendly.
//   If 'pg' is null, pass sys_ipc_recv a value that it will understand
//   as meaning "no page".  (Zero is not the right value.)
void
ipc_send(envid_t to_env, uint32_t val, void *pg, int perm)
{
	// LAB 4: Your code here.
    int ret;

    dprintk("[IPC] send from %08x to %08x, value=%d, pg=%p, perm=%x\n",
            sys_getenvid(), to_env, val, pg, perm);
    while (1) {
        if (pg == NULL) {
            /* TODO: allow pg=0 */
            ret = sys_ipc_try_send(to_env, val, (void *) -1, 0);
        } else {
            ret = sys_ipc_try_send(to_env, val, pg, perm);
        }
        if (ret == 0 || ret == 1)
            break;
        if (ret != -E_IPC_NOT_RECV)
            panic("ipc_send error %e", ret);
    }
}
Ejemplo n.º 16
0
// 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.

//	panic("syscall not implemented");

	switch (syscallno) {
	case SYS_cputs:
		sys_cputs((char *)a1, a2);
		break;
	case SYS_cgetc:
		return sys_cgetc();
	case SYS_env_destroy:
		return sys_env_destroy(a1);
	case SYS_getenvid:
		return sys_getenvid();
	case SYS_yield:
		sys_yield();
		break;
	case SYS_page_alloc:
		return sys_page_alloc(a1, (void *)a2, a3);
	case SYS_page_map:
		return sys_page_map(a1, (void *)a2, a3, (void *)a4, a5);
	case SYS_page_unmap:
		return sys_page_unmap(a1, (void *)a2);
	case SYS_env_set_status:
		return sys_env_set_status(a1, a2);
	case SYS_exofork:
		return sys_exofork();
	case SYS_env_set_pgfault_upcall:
		return sys_env_set_pgfault_upcall(a1, (void *)a2);
	case SYS_ipc_try_send:
		return sys_ipc_try_send(a1, a2, (void*)a3, a4);
	case SYS_ipc_recv:
		return sys_ipc_recv((void*)a1);
	case SYS_env_set_trapframe:
		return sys_env_set_trapframe(a1, (struct Trapframe *)a2);
	case SYS_time_msec:
		return sys_time_msec();
	case SYS_trans_pkt:
		return sys_trans_pkt((void*)a1, a2);
	case SYS_recv_pkt:
		return sys_recv_pkt((void *)a1, (size_t *)a2);
	default:
		return -E_INVAL;
	}

	return 0;
}
Ejemplo n.º 17
0
// 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.
	switch (syscallno){
		case SYS_getenvid:
			return sys_getenvid();
		case SYS_cputs:
			sys_cputs((const char*)a1, a2);
			return 0;
		case SYS_cgetc:
			return sys_cgetc();
		case SYS_env_destroy:
			return sys_env_destroy(a1);
		case SYS_map_kernel_page:
			return sys_map_kernel_page((void*)a1, (void*)a2);
		case SYS_sbrk:
			return sys_sbrk(a1);
		case SYS_yield:
			sys_yield();
			return 0;
		case SYS_exofork:
			return sys_exofork();
		case SYS_env_set_status:
			return sys_env_set_status((envid_t)a1, (int)a2);
		case SYS_page_alloc:
			return sys_page_alloc((envid_t)a1, (void *)a2, 
						(int)a3);
		case SYS_page_map:
			return sys_page_map((envid_t)*((uint32_t*)a1),
					(void*)*((uint32_t*)a1+1), 
					(envid_t)*((uint32_t*)a1+2), 
					(void*)*((uint32_t*)a1+3), 
					(int)*((uint32_t*)a1+4));
		case SYS_page_unmap:
			return sys_page_unmap((envid_t)a1, (void*)a2);
		case SYS_env_set_priority:
			return sys_env_set_priority((envid_t)a1, (int) a2);
		case SYS_env_set_pgfault_upcall:
			return sys_env_set_pgfault_upcall((envid_t)a1,
						 (void*)a2);
		case SYS_ipc_recv:
			return sys_ipc_recv((void*)a1);
		case SYS_ipc_try_send:
			return sys_ipc_try_send((envid_t)a1, a2, 
						(void*)a3, (int)a4);
		default:
			return -E_INVAL;
	}
}
Ejemplo n.º 18
0
// Send 'val' (and 'pg' with 'perm', if 'pg' is nonnull) to 'toenv'.
// This function keeps trying until it succeeds.
// It should panic() on any error other than -E_IPC_NOT_RECV.
//
// Hint:
//   Use sys_yield() to be CPU-friendly.
//   If 'pg' is null, pass sys_ipc_try_send a value that it will understand
//   as meaning "no page".  (Zero is not the right value.)
void
ipc_send(envid_t to_env, uint32_t val, void *pg, int perm)
{
	// LAB 4: Your code here.
	
	
	int result = -E_IPC_NOT_RECV ; 
	if ( pg ) 
		result = sys_ipc_try_send( to_env , val , pg , perm ) ; 
	else
		result = sys_ipc_try_send( to_env , val , (void*)UTOP , perm ) ; 
	
	if ( result == 0 ) return ; 
	if ( result == -E_IPC_NOT_RECV ) {
		if ( pg ) 
			result = sys_ipc_try_send( to_env , val , pg , perm ) ; 
		else
			result = sys_ipc_try_send( to_env , val , (void*)UTOP , perm ) ; 
		if ( result == 0 ) return ; 
	}
	panic("ipc_send error %e.",result);
}
Ejemplo n.º 19
0
// Dispatches to the correct kernel function, passing the arguments.
	int64_t
syscall(uint64_t syscallno, uint64_t a1, uint64_t a2, uint64_t a3, uint64_t a4, uint64_t a5)
{
	// Call the function corresponding to the 'syscallno' parameter.
	// Return any appropriate return value.
	// LAB 3: Your code here.
	uint64_t retval = 0;

	switch (syscallno) {
		case SYS_cputs:
			sys_cputs((char *) a1, (size_t) a2);
			return retval;
		case SYS_cgetc:
			return (int64_t) sys_cgetc();
		case SYS_getenvid:
			return (int64_t) sys_getenvid();
		case SYS_env_destroy:
			return (int64_t) sys_env_destroy((envid_t) a1);
		case SYS_yield:
			sys_yield();
			return retval;
		case SYS_exofork:
			return (int64_t)sys_exofork();
		case SYS_page_alloc:
			return (int64_t)sys_page_alloc((envid_t)a1, (void *)a2, (int)a3);
		case SYS_page_map:
			return (int64_t)sys_page_map((envid_t)a1, (void *)a2, (envid_t)a3, (void *)a4, (int)a5);
		case SYS_page_unmap:
			return (int64_t)sys_page_unmap((envid_t)a1, (void *)a2);
		case SYS_env_set_status:
			return (int64_t)sys_env_set_status((envid_t)a1, (int)a2);
		case SYS_env_set_pgfault_upcall:
			return (int64_t)sys_env_set_pgfault_upcall((envid_t)a1, (void *)a2);
		case SYS_ipc_try_send:
			return (int64_t) sys_ipc_try_send((envid_t) a1, (uint32_t) a2, (void *) a3, (unsigned) a4);
		case SYS_ipc_recv:
			return (int64_t)sys_ipc_recv((void*)a1);
		case SYS_env_set_trapframe:
			return sys_env_set_trapframe((envid_t)a1, (struct Trapframe*)a2);
		case SYS_time_msec:
			return sys_time_msec();
		case SYS_net_try_send:
			return sys_net_try_send((char *) a1, (int) a2);
		case SYS_net_try_receive:
			return sys_net_try_receive((char *) a1, (int *) a2);
		default:
			return -E_INVAL;
	}

	panic("syscall not implemented");
}
Ejemplo n.º 20
0
Archivo: ipc.c Proyecto: RudoIf/J-O-S
// Send 'val' (and 'pg' with 'perm', if 'pg' is nonnull) to 'toenv'.
// This function keeps trying until it succeeds.
// It should panic() on any error other than -E_IPC_NOT_RECV.
//
// Hint:
//   Use sys_yield() to be CPU-friendly.
//   If 'pg' is null, pass sys_ipc_recv a value that it will understand
//   as meaning "no page".  (Zero is not the right value.)
void
ipc_send(envid_t to_env, uint32_t val, void *pg, int perm)
{
	// LAB 4: Your code here.
	int r;
	if(!pg)
		pg = (void*)UTOP; 
	while((r = sys_ipc_try_send(to_env,val,pg,perm)) != 0)
	{
		if(/* r < 0 && */r != -E_IPC_NOT_RECV )
			panic ("ipc: sys try send failed : %e", r);
	}
	sys_yield();
}
Ejemplo n.º 21
0
Archivo: ipc.c Proyecto: Hisham-A/JOS
// Send 'val' (and 'pg' with 'perm', if 'pg' is nonnull) to 'toenv'.
// This function keeps trying until it succeeds.
// It should panic() on any error other than -E_IPC_NOT_RECV.
//
// Hint:
//   Use sys_yield() to be CPU-friendly.
//   If 'pg' is null, pass sys_ipc_recv a value that it will understand
//   as meaning "no page".  (Zero is not the right value.)
void
ipc_send(envid_t to_env, uint32_t val, void *pg, int perm)
{
	// LAB 4: Your code here.
	//panic("ipc_send not implemented");
	int ret;
	pg = (pg == NULL ? (void*)UTOP : pg);
	while((ret = sys_ipc_try_send(to_env,val,pg,perm))<0) {
		if(ret != -E_IPC_NOT_RECV)
			panic("sys_ipc_try_send in ipc_send: %e",ret);
		//cprintf("Sending fialeddddddddddddddd\n\n\n\n\n");
		sys_yield();
	}	
}
Ejemplo n.º 22
0
// Send 'val' (and 'pg' with 'perm', if 'pg' is nonnull) to 'toenv'.
// This function keeps trying until it succeeds.
// It should panic() on any error other than -E_IPC_NOT_RECV.
//
// Hint:
//   Use sys_yield() to be CPU-friendly.
//   If 'pg' is null, pass sys_ipc_recv a value that it will understand
//   as meaning "no page".  (Zero is not the right value.)
void
ipc_send(envid_t to_env, uint32_t val, void *pg, int perm)
{
	//cprintf("to_env: %08x from_env: %08x\n", to_env, thisenv->env_id);
	int ret = -E_IPC_NOT_RECV;
	if (!pg) pg = (void *)UTOP;
	while (true) {
		ret = sys_ipc_try_send(to_env,val,pg,perm);
		if (ret == 0) return;
		if (ret != -E_IPC_NOT_RECV) break;
		sys_yield();
	}
	panic("Send failed: %e", ret);
}
Ejemplo n.º 23
0
// Send 'val' (and 'pg' with 'perm', if 'pg' is nonnull) to 'toenv'.
// This function keeps trying until it succeeds.
// It should panic() on any error other than -E_IPC_NOT_RECV.
//
// Hint:
//   Use sys_yield() to be CPU-friendly.
//   If 'pg' is null, pass sys_ipc_recv a value that it will understand
//   as meaning "no page".  (Zero is not the right value.)
void
ipc_send(envid_t to_env, uint32_t val, void *pg, int perm)
{
	// LAB 4: Your code here.
	int r;

	if(pg == NULL)
		pg = (void *)~0x0;
	while((r = sys_ipc_try_send(to_env, val, pg, perm)) < 0){
		if(r != -E_IPC_NOT_RECV)
            panic("Send message error %e\n",r);
		sys_yield();
	}
	// panic("ipc_send not implemented");
}
Ejemplo n.º 24
0
// Send 'val' (and 'pg' with 'perm', if 'pg' is nonnull) to 'toenv'.
// This function keeps trying until it succeeds.
// It should panic() on any error other than -E_IPC_NOT_RECV.
//
// Hint:
//   Use sys_yield() to be CPU-friendly.
//   If 'pg' is null, pass sys_ipc_recv a value that it will understand
//   as meaning "no page".  (Zero is not the right value.)
void
ipc_send(envid_t to_env, uint32_t val, void *pg, int perm)
{
	// LAB 4: Your code here.
	int r;
	if (pg == NULL)
		pg = (void*)UTOP;
	while ((r = sys_ipc_try_send(to_env, val, pg, perm)) < 0)
	{
		if(r != -E_IPC_NOT_RECV)
			panic("Panic in lib ipc.c : ipc_send() \n");
		sys_yield();
	}
	//panic("ipc_send not implemented");
}
Ejemplo n.º 25
0
// Send 'val' (and 'pg' with 'perm', assuming 'pg' is nonnull) to 'toenv'.
// This function keeps trying until it succeeds.
// It should panic() on any error other than -E_IPC_NOT_RECV.
//
// Hint:
//   Use sys_yield() to be CPU-friendly.
//   If 'pg' is null, pass sys_ipc_recv a value that it will understand
//   as meaning "no page".  (Zero is not the right value.)
void
ipc_send(envid_t to_env, uint32_t val, void *pg, int perm)
{
	// LAB 4: Your code here.
	int r;

	while ((r = sys_ipc_try_send(to_env, val, pg != NULL ? pg : (void *)UTOP, perm)) < 0){
		if (r != -E_IPC_NOT_RECV){
			panic("lib ipc_send failed. returned %d\n", r);
		}

		sys_yield();
	}

	// panic("ipc_send not implemented");
}
Ejemplo n.º 26
0
// 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.

	switch (syscallno) {
		case (SYS_cputs):
			sys_cputs((const char *) a1, a2);
			return 0;
		case (SYS_cgetc):
			return sys_cgetc();
		case (SYS_getenvid):
			return sys_getenvid();
		case (SYS_env_destroy):
			return sys_env_destroy(a1, a2);
		case (SYS_yield):
			sys_yield();
			return 0;
		case (SYS_exofork):
			return sys_exofork();
		case (SYS_env_set_status):
			return sys_env_set_status(a1, a2);
		case (SYS_page_alloc):
			return sys_page_alloc(a1, (void *) a2, a3);
		case (SYS_page_map):
			return sys_page_map(a1, (void *) a2, a3, (void *) a4, a5);
		case (SYS_page_unmap):
			return sys_page_unmap(a1, (void *) a2);
		case (SYS_env_set_pgfault_upcall):
			return sys_env_set_pgfault_upcall(a1, (void *) a2);
		case (SYS_ipc_try_send):
			return sys_ipc_try_send(a1, a2, (void *) a3, a4);
		case (SYS_ipc_recv):
			return sys_ipc_recv((void *) a1);
		case (SYS_env_set_trapframe):
			return sys_env_set_trapframe(a1, (struct Trapframe *) a2);
		case (SYS_time_msec):
			return sys_time_msec();
		case (SYS_e1000_transmit):
			return sys_e1000_transmit(a1, (char *) a2, a3);
	default:
		return -E_INVAL;
	}
}
Ejemplo n.º 27
0
// Send 'val' (and 'pg' with 'perm', if 'pg' is nonnull) to 'toenv'.
// This function keeps trying until it succeeds.
// It should panic() on any error other than -E_IPC_NOT_RECV.
//
// Hint:
//   Use sys_yield() to be CPU-friendly.
//   If 'pg' is null, pass sys_ipc_recv a value that it will understand
//   as meaning "no page".  (Zero is not the right value.)
void
ipc_send(envid_t to_env, uint32_t val, void *pg, int perm)
{
	// LAB 4: Your code here.
	
	if(!pg)
		pg = (void*)0xFFFFFFFF;
	
	// No need to loop due to LAB 4 CHALLENGE
	int ret;

	ret = sys_ipc_try_send(to_env, val, pg, perm);
	
	if(ret != 0)
		panic("ipc_send got unknown error %d: %e\n", ret, ret);
	
}
Ejemplo n.º 28
0
// Send 'val' (and 'pg' with 'perm', if 'pg' is nonnull) to 'toenv'.
// This function keeps trying until it succeeds.
// It should panic() on any error other than -E_IPC_NOT_RECV.
void
ipc_send(envid_t to_env, uint32_t val, void *pg, int perm)
{
//   If 'pg' is null, pass sys_ipc_recv a value that it will understand
//   as meaning "no page".  (Zero is not the right value.)
  void *srcva = pg ? pg : (void *)UTOP;
  int r;
  while (1) {
    r = sys_ipc_try_send(to_env, val, srcva, perm);
    if (r == -E_IPC_NOT_RECV)
//   Use sys_yield() to be CPU-friendly.
      sys_yield();
    else if (r < 0)
      panic("sys_ipc_try_send: %e\n", r);
    else
      return;
  }
}
Ejemplo n.º 29
0
// Dispatches to the correct kernel function, passing the arguments.
uint32_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.

	switch (syscallno){
	
		case SYS_cputs:
			sys_cputs( (const char *)a1, a2);
			return 0;
		case SYS_cgetc:
			return sys_cgetc();
		case SYS_getenvid:
			return sys_getenvid();
		case SYS_env_destroy:
			return sys_env_destroy(a1);		
		case SYS_yield:
			sys_yield();
			return 0;
		case SYS_exofork:
			return sys_exofork();
		case SYS_env_set_status:
			return sys_env_set_status(a1, a2);
		case SYS_page_alloc:	
			return sys_page_alloc(a1, (void *)a2, a3);
		case SYS_page_map:
			return sys_page_map(a1, (void *)a2, a3, (void *)a4, a5);
		case SYS_env_set_trapframe:
			return sys_env_set_trapframe(a1, (struct Trapframe *)a2);		
		case SYS_page_unmap:
			return sys_page_unmap(a1, (void *)a2);
		case SYS_env_set_pgfault_upcall:
			return sys_env_set_pgfault_upcall(a1, (void *)a2);
		case SYS_ipc_try_send:
			return sys_ipc_try_send(a1, a2, (void *)a3, a4);
		case SYS_ipc_recv:
			return sys_ipc_recv((void *)a1);

		default: panic("this syscall ( %d )is not yet implemented", syscallno); 
	}
}
Ejemplo n.º 30
0
Archivo: ipc.c Proyecto: HVNT/6.828
// Send 'val' (and 'pg' with 'perm', if 'pg' is nonnull) to 'toenv'.
// This function keeps trying until it succeeds.
// It should panic() on any error other than -E_IPC_NOT_RECV.
//
// Hint:
//   Use sys_yield() to be CPU-friendly.
//   If 'pg' is null, pass sys_ipc_recv a value that it will understand
//   as meaning "no page".  (Zero is not the right value.)
void
ipc_send(envid_t to_env, uint32_t val, void *pg, int perm)
{
  // LAB 4: Your code here.
  // seanyliu
  //panic("ipc_send not implemented");
  int r;
  if (pg == NULL) {
    pg = (void *) UTOP;
    perm = 0;
  }
  while (1) {
    r = sys_ipc_try_send(to_env, val, pg, perm);
    if (r == -E_IPC_NOT_RECV) {
      sys_yield();
    }
    else if (r < 0) panic ("ipc_send: failed to send: %d", r);
    else break;
  }
}