Permalink
Browse files

lab4

  • Loading branch information...
1 parent 2ceda43 commit b825df1cefa71a3b9f2c0bf58e559d80c14b9a4e @aclements aclements committed Oct 7, 2009
View
@@ -1,2 +1,2 @@
-LAB=3
-PACKAGEDATE=Fri Oct 2 14:17:20 EDT 2009
+LAB=4
+PACKAGEDATE=Wed Oct 7 18:43:11 EDT 2009
View
@@ -0,0 +1,147 @@
+#!/bin/sh
+
+qemuopts="-hda obj/kern/kernel.img"
+. ./grade-functions.sh
+
+
+$make
+run
+
+score=0
+total=0
+timeout=10
+
+runtest1 dumbfork \
+ '.00000000. new env 00001000' \
+ '.00000000. new env 00001001' \
+ '0: I am the parent!' \
+ '9: I am the parent!' \
+ '0: I am the child!' \
+ '9: I am the child!' \
+ '19: I am the child!' \
+ '.00001001. exiting gracefully' \
+ '.00001001. free env 00001001' \
+ '.00001002. exiting gracefully' \
+ '.00001002. free env 00001002'
+
+echo "Part A score: $score/5"
+echo
+total=`expr $total + $score`
+
+score=0
+
+runtest1 faultread \
+ ! 'I read ........ from location 0!' \
+ '.00001001. user fault va 00000000 ip 008.....' \
+ 'TRAP frame at 0xf.......' \
+ ' trap 0x0000000e Page Fault' \
+ ' err 0x00000004' \
+ '.00001001. free env 00001001'
+
+runtest1 faultwrite \
+ '.00001001. user fault va 00000000 ip 008.....' \
+ 'TRAP frame at 0xf.......' \
+ ' trap 0x0000000e Page Fault' \
+ ' err 0x00000006' \
+ '.00001001. free env 00001001'
+
+runtest1 faultdie \
+ 'i faulted at va deadbeef, err 6' \
+ '.00001001. exiting gracefully' \
+ '.00001001. free env 00001001'
+
+runtest1 faultalloc \
+ 'fault deadbeef' \
+ 'this string was faulted in at deadbeef' \
+ 'fault cafebffe' \
+ 'fault cafec000' \
+ 'this string was faulted in at cafebffe' \
+ '.00001001. exiting gracefully' \
+ '.00001001. free env 00001001'
+
+runtest1 faultallocbad \
+ '.00001001. user_mem_check assertion failure for va deadbeef' \
+ '.00001001. free env 00001001'
+
+runtest1 faultnostack \
+ '.00001001. user_mem_check assertion failure for va eebfff..' \
+ '.00001001. free env 00001001'
+
+runtest1 faultbadhandler \
+ '.00001001. user_mem_check assertion failure for va (deadb|eebfe)...' \
+ '.00001001. free env 00001001'
+
+runtest1 faultevilhandler \
+ '.00001001. user_mem_check assertion failure for va (f0100|eebfe)...' \
+ '.00001001. free env 00001001'
+
+runtest1 forktree \
+ '....: I am .0.' \
+ '....: I am .1.' \
+ '....: I am .000.' \
+ '....: I am .100.' \
+ '....: I am .110.' \
+ '....: I am .111.' \
+ '....: I am .011.' \
+ '....: I am .001.' \
+ '.00001001. exiting gracefully' \
+ '.00001002. exiting gracefully' \
+ '.0000200.. exiting gracefully' \
+ '.0000200.. free env 0000200.'
+
+echo "Part B score: $score/45"
+echo
+total=`expr $total + $score`
+
+score=0
+
+runtest1 spin \
+ '.00000000. new env 00001000' \
+ '.00000000. new env 00001001' \
+ 'I am the parent. Forking the child...' \
+ '.00001001. new env 00001002' \
+ 'I am the parent. Running the child...' \
+ 'I am the child. Spinning...' \
+ 'I am the parent. Killing the child...' \
+ '.00001001. destroying 00001002' \
+ '.00001001. free env 00001002' \
+ '.00001001. exiting gracefully' \
+ '.00001001. free env 00001001'
+
+runtest1 pingpong \
+ '.00000000. new env 00001000' \
+ '.00000000. new env 00001001' \
+ '.00001001. new env 00001002' \
+ 'send 0 from 1001 to 1002' \
+ '1002 got 0 from 1001' \
+ '1001 got 1 from 1002' \
+ '1002 got 8 from 1001' \
+ '1001 got 9 from 1002' \
+ '1002 got 10 from 1001' \
+ '.00001001. exiting gracefully' \
+ '.00001001. free env 00001001' \
+ '.00001002. exiting gracefully' \
+ '.00001002. free env 00001002' \
+
+timeout=20
+runtest1 primes \
+ '.00000000. new env 00001000' \
+ '.00000000. new env 00001001' \
+ '.00001001. new env 00001002' \
+ '2 .00001002. new env 00001003' \
+ '3 .00001003. new env 00001004' \
+ '5 .00001004. new env 00001005' \
+ '7 .00001005. new env 00001006' \
+ '11 .00001006. new env 00001007'
+
+echo "Part C score: $score/15"
+echo
+total=`expr $total + $score`
+
+
+
+echo "Score: $total/65"
+
+if [ $total -lt 65 ]; then
+ exit 1
+fi
View
@@ -47,6 +47,15 @@ struct Env {
pde_t *env_pgdir; // Kernel virtual address of page dir
physaddr_t env_cr3; // Physical address of page dir
+ // Exception handling
+ void *env_pgfault_upcall; // page fault upcall entry point
+
+ // Lab 4 IPC
+ bool env_ipc_recving; // env is blocked receiving
+ void *env_ipc_dstva; // va at which to map received page
+ uint32_t env_ipc_value; // data value sent to us
+ envid_t env_ipc_from; // envid of the sender
+ int env_ipc_perm; // perm of page mapping received
};
#endif // !JOS_INC_ENV_H
View
@@ -13,6 +13,9 @@
// the maximum allowed
#define E_FAULT 6 // Memory fault
-#define MAXERROR 6
+#define E_IPC_NOT_RECV 7 // Attempt to send to env that is not recving
+#define E_EOF 8 // Unexpected end of file
+
+#define MAXERROR 8
#endif // !JOS_INC_ERROR_H */
View
@@ -0,0 +1,129 @@
+/* See COPYRIGHT for copyright information. */
+
+/* $OpenBSD: isareg.h,v 1.2 1997/11/07 08:07:03 niklas Exp $ */
+/* $NetBSD: isareg.h,v 1.5 1995/04/17 12:09:13 cgd Exp $ */
+
+/*
+ * ISA Bus conventions
+ */
+
+/*
+ * Input / Output Port Assignments
+ */
+
+#ifndef IO_ISABEGIN
+#define IO_ISABEGIN 0x000 /* 0x000 - Beginning of I/O Registers */
+
+ /* CPU Board */
+#define IO_DMA1 0x000 /* 8237A DMA Controller #1 */
+#define IO_ICU1 0x020 /* 8259A Interrupt Controller #1 */
+#define IO_PMP1 0x026 /* 82347 Power Management Peripheral */
+#define IO_TIMER1 0x040 /* 8253 Timer #1 */
+#define IO_TIMER2 0x048 /* 8253 Timer #2 (EISA only) */
+#define IO_KBD 0x060 /* 8042 Keyboard */
+#define IO_PPI 0x061 /* Programmable Peripheral Interface */
+#define IO_RTC 0x070 /* RTC */
+#define IO_NMI IO_RTC /* NMI Control */
+#define IO_DMAPG 0x080 /* DMA Page Registers */
+#define IO_ICU2 0x0A0 /* 8259A Interrupt Controller #2 */
+#define IO_DMA2 0x0C0 /* 8237A DMA Controller #2 */
+#define IO_NPX 0x0F0 /* Numeric Coprocessor */
+
+ /* Cards */
+ /* 0x100 - 0x16F Open */
+
+#define IO_WD2 0x170 /* Secondary Fixed Disk Controller */
+#define IO_PMP2 0x178 /* 82347 Power Management Peripheral */
+
+ /* 0x17A - 0x1EF Open */
+
+#define IO_WD1 0x1f0 /* Primary Fixed Disk Controller */
+#define IO_GAME 0x200 /* Game Controller */
+
+ /* 0x208 - 0x237 Open */
+
+#define IO_BMS2 0x238 /* secondary InPort Bus Mouse */
+#define IO_BMS1 0x23c /* primary InPort Bus Mouse */
+
+ /* 0x240 - 0x277 Open */
+
+#define IO_LPT2 0x278 /* Parallel Port #2 */
+
+ /* 0x280 - 0x2E7 Open */
+
+#define IO_COM4 0x2e8 /* COM4 i/o address */
+
+ /* 0x2F0 - 0x2F7 Open */
+
+#define IO_COM2 0x2f8 /* COM2 i/o address */
+
+ /* 0x300 - 0x32F Open */
+
+#define IO_BT0 0x330 /* bustek 742a default addr. */
+#define IO_AHA0 0x330 /* adaptec 1542 default addr. */
+#define IO_UHA0 0x330 /* ultrastore 14f default addr. */
+#define IO_BT1 0x334 /* bustek 742a default addr. */
+#define IO_AHA1 0x334 /* adaptec 1542 default addr. */
+
+ /* 0x338 - 0x34F Open */
+
+#define IO_WDS 0x350 /* WD7000 scsi */
+
+ /* 0x354 - 0x36F Open */
+
+#define IO_FD2 0x370 /* secondary base i/o address */
+#define IO_LPT1 0x378 /* Parallel Port #1 */
+
+ /* 0x380 - 0x3AF Open */
+
+#define IO_MDA 0x3B0 /* Monochome Adapter */
+#define IO_LPT3 0x3BC /* Monochome Adapter Printer Port */
+#define IO_VGA 0x3C0 /* E/VGA Ports */
+#define IO_CGA 0x3D0 /* CGA Ports */
+
+ /* 0x3E0 - 0x3E7 Open */
+
+#define IO_COM3 0x3e8 /* COM3 i/o address */
+#define IO_FD1 0x3f0 /* primary base i/o address */
+#define IO_COM1 0x3f8 /* COM1 i/o address */
+
+#define IO_ISAEND 0x3FF /* - 0x3FF End of I/O Registers */
+#endif /* !IO_ISABEGIN */
+
+/*
+ * Input / Output Port Sizes - these are from several sources, and tend
+ * to be the larger of what was found, ie COM ports can be 4, but some
+ * boards do not fully decode the address, thus 8 ports are used.
+ */
+
+#ifndef IO_ISASIZES
+#define IO_ISASIZES
+
+#define IO_COMSIZE 8 /* 8250, 16X50 com controllers */
+#define IO_CGASIZE 16 /* CGA controllers */
+#define IO_DMASIZE 16 /* 8237 DMA controllers */
+#define IO_DPGSIZE 32 /* 74LS612 DMA page reisters */
+#define IO_FDCSIZE 8 /* Nec765 floppy controllers */
+#define IO_WDCSIZE 8 /* WD compatible disk controller */
+#define IO_GAMSIZE 16 /* AT compatible game controller */
+#define IO_ICUSIZE 16 /* 8259A interrupt controllers */
+#define IO_KBDSIZE 16 /* 8042 Keyboard controllers */
+#define IO_LPTSIZE 8 /* LPT controllers, some use onl */
+#define IO_MDASIZE 16 /* Monochrome display controller */
+#define IO_RTCSIZE 16 /* CMOS real time clock, NMI con */
+#define IO_TMRSIZE 16 /* 8253 programmable timers */
+#define IO_NPXSIZE 16 /* 80387/80487 NPX registers */
+#define IO_VGASIZE 16 /* VGA controllers */
+#define IO_PMPSIZE 2 /* 82347 Power Management Peripheral */
+#endif /* !IO_ISASIZES */
+
+/*
+ * Input / Output Memory Physical Addresses
+ */
+
+#ifndef IOM_BEGIN
+#define IOM_BEGIN 0x0a0000 /* Start of I/O Memory "hole" */
+#define IOM_END 0x100000 /* End of I/O Memory "hole" */
+#define IOM_SIZE (IOM_END - IOM_BEGIN)
+
+#endif // !IOM_BEGIN
View
@@ -16,6 +16,7 @@
#include <inc/env.h>
#include <inc/memlayout.h>
#include <inc/syscall.h>
+#include <inc/trap.h>
#define USED(x) (void)(x)
@@ -26,6 +27,9 @@ extern volatile struct Env envs[NENV];
extern volatile struct Page pages[];
void exit(void);
+// pgfault.c
+void set_pgfault_handler(void (*handler)(struct UTrapframe *utf));
+
// readline.c
char* readline(const char *buf);
@@ -34,6 +38,40 @@ void sys_cputs(const char *string, size_t len);
int sys_cgetc(void);
envid_t sys_getenvid(void);
int sys_env_destroy(envid_t);
+void sys_yield(void);
+static envid_t sys_exofork(void);
+int sys_env_set_status(envid_t env, int status);
+int sys_env_set_trapframe(envid_t env, struct Trapframe *tf);
+int sys_env_set_pgfault_upcall(envid_t env, void *upcall);
+int sys_page_alloc(envid_t env, void *pg, int perm);
+int sys_page_map(envid_t src_env, void *src_pg,
+ envid_t dst_env, void *dst_pg, int perm);
+int sys_page_unmap(envid_t env, void *pg);
+int sys_ipc_try_send(envid_t to_env, uint32_t value, void *pg, int perm);
+int sys_ipc_recv(void *rcv_pg);
+
+// This must be inlined. Exercise for reader: why?
+static __inline envid_t sys_exofork(void) __attribute__((always_inline));
+static __inline envid_t
+sys_exofork(void)
+{
+ envid_t ret;
+ __asm __volatile("int %2"
+ : "=a" (ret)
+ : "a" (SYS_exofork),
+ "i" (T_SYSCALL)
+ );
+ return ret;
+}
+
+// ipc.c
+void ipc_send(envid_t to_env, uint32_t value, void *pg, int perm);
+int32_t ipc_recv(envid_t *from_env_store, void *pg, int *perm_store);
+
+// fork.c
+#define PTE_SHARE 0x400
+envid_t fork(void);
+envid_t sfork(void); // Challenge!
View
@@ -8,6 +8,16 @@ enum
SYS_cgetc,
SYS_getenvid,
SYS_env_destroy,
+ SYS_page_alloc,
+ SYS_page_map,
+ SYS_page_unmap,
+ SYS_exofork,
+ SYS_env_set_status,
+ SYS_env_set_trapframe,
+ SYS_env_set_pgfault_upcall,
+ SYS_yield,
+ SYS_ipc_try_send,
+ SYS_ipc_recv,
NSYSCALLS
};
Oops, something went wrong.

0 comments on commit b825df1

Please sign in to comment.