Permalink
Browse files

6.10: Steal the receiver code.

  • Loading branch information...
1 parent dec0874 commit f24fa354c41b1fd2ab5ce91c2b0aa448ca2ed7d7 @wh5a committed Jun 12, 2010
Showing with 70 additions and 7 deletions.
  1. +8 −3 kern/trap.c
  2. +62 −4 net/input.c
View
@@ -155,18 +155,23 @@ trap_dispatch(struct Trapframe *tf)
//// Lab 6: Add time tick increment to clock interrupts.
time_tick();
sched_yield();
- break;
+ return;
// Handle spurious interupts
// The hardware sometimes raises these because of noise on the
// IRQ line or other reasons. We don't care.
- case IRQ_OFFSET + IRQ_SPURIOUS: {
+ case IRQ_OFFSET + IRQ_SPURIOUS:
cprintf("Spurious interrupt on irq 7\n");
print_trapframe(tf);
return;
- }
default:
+ if (tf->tf_trapno == IRQ_OFFSET + e100_irq) {
+ e100_intr();
+ irq_eoi();
+ return;
+ }
+
// Unexpected trap: The user process or the kernel has a bug.
print_trapframe(tf);
if (tf->tf_cs == GD_KT)
View
@@ -1,11 +1,69 @@
#include "ns.h"
+/* Poll the device driver, using your receive system call, for
+ received packets. You will also need to pass each packet to the
+ core network server environment using the NSREQ_INPUT IPC message.
+*/
+
+#define RX_SLOTS 64
+#define PKTMAP 0x10000000
+
+static void *rx_slot[RX_SLOTS];
+static int head;
+static int tail;
+
+static void
+fill_rxbuf(void)
+{
+ int i, r;
+ void *p;
+
+ while (head - tail < RX_SLOTS) {
+ i = head % RX_SLOTS;
+ p = (void *) PKTMAP + PGSIZE * i;
+ if ((r = sys_page_alloc(0, p, PTE_P|PTE_W|PTE_U))) {
+ cprintf("Input couldn't page_alloc: %e\n", r);
+ break;
+ }
+
+ if ((r = sys_net_rxbuf(p, PGSIZE)))
+ panic("Input couldn't rxbuf: %e", r);
+
+ rx_slot[i] = p;
+ head++;
+ }
+}
+
+static void
+forward_rxbuf(envid_t ns_envid)
+{
+ struct jif_pkt *pkt;
+ int i;
+
+ i = tail % RX_SLOTS;
+ pkt = rx_slot[i];
+
+ while (*((volatile int *)&pkt->jp_len) == 0)
+ sys_yield();
+
+ if (pkt->jp_len > 0)
+ ipc_send(ns_envid, NSREQ_INPUT, pkt, PTE_P|PTE_W|PTE_U);
+ else
+ cprintf("Input rx'ed a bad packet\n");
+ rx_slot[i] = 0;
+ sys_page_unmap(0, pkt);
+
+ tail++;
+}
+
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
+// - read a packet from the device driver
+// - send it to the network server
+ for (;;) {
+ fill_rxbuf();
+ forward_rxbuf(ns_envid);
+ }
}

0 comments on commit f24fa35

Please sign in to comment.