Permalink
Browse files

lab2

  • Loading branch information...
aclements committed Sep 16, 2009
1 parent ebd5a0a commit b9a9356306bf497641271c1d97a894b22a39cd95
Showing with 1,557 additions and 20 deletions.
  1. +7 −4 .gdbinit.tmpl
  2. +2 −2 conf/lab.mk
  3. +34 −0 grade-lab2.sh
  4. +52 −0 inc/env.h
  5. +1 −1 inc/mmu.h
  6. +81 −0 inc/trap.h
  7. +389 −0 kern/env.c
  8. +43 −0 kern/env.h
  9. +5 −13 kern/init.c
  10. +28 −0 kern/kclock.c
  11. +33 −0 kern/kclock.h
  12. +770 −0 kern/pmap.c
  13. +91 −0 kern/pmap.h
  14. +21 −0 kern/trap.h
View
@@ -1,9 +1,5 @@
set $lastcs = -1
-# This fails on Darwin because the default gdb has no ELF support
-# echo + symbol-file obj/kern/kernel\n
-# symbol-file obj/kern/kernel
-
define hook-stop
# There doesn't seem to be a good way to detect if we're in 16- or
# 32-bit mode, but we always run with CS == 8 in 32-bit mode.
@@ -25,3 +21,10 @@ end
echo + target remote localhost:1234\n
target remote localhost:1234
+
+# If this fails, it's probably because your GDB doesn't support ELF.
+# Look at the tools page at
+# http://pdos.csail.mit.edu/6.828/2009/tools.html
+# for instructions on building GDB with ELF support.
+echo + symbol-file obj/kern/kernel\n
+symbol-file obj/kern/kernel
View
@@ -1,2 +1,2 @@
-LAB=1
-PACKAGEDATE=Wed Sep 9 16:24:04 EDT 2009
+LAB=2
+PACKAGEDATE=Wed Sep 16 15:18:45 EDT 2009
View
@@ -0,0 +1,34 @@
+#!/bin/sh
+
+qemuopts="-hda obj/kern/kernel.img"
+. ./grade-functions.sh
+
+
+$make
+run
+
+score=0
+
+echo_n "Page directory: "
+ if grep "check_boot_pgdir() succeeded!" jos.out >/dev/null
+ then
+ score=`expr 20 + $score`
+ echo OK $time
+ else
+ echo WRONG $time
+ fi
+
+echo_n "Page management: "
+ if grep "page_check() succeeded!" jos.out >/dev/null
+ then
+ score=`expr 30 + $score`
+ echo OK $time
+ else
+ echo WRONG $time
+ fi
+
+echo "Score: $score/50"
+
+if [ $score -lt 50 ]; then
+ exit 1
+fi
View
@@ -0,0 +1,52 @@
+/* See COPYRIGHT for copyright information. */
+
+#ifndef JOS_INC_ENV_H
+#define JOS_INC_ENV_H
+
+#include <inc/types.h>
+#include <inc/queue.h>
+#include <inc/trap.h>
+#include <inc/memlayout.h>
+
+typedef int32_t envid_t;
+
+// An environment ID 'envid_t' has three parts:
+//
+// +1+---------------21-----------------+--------10--------+
+// |0| Uniqueifier | Environment |
+// | | | Index |
+// +------------------------------------+------------------+
+// \--- ENVX(eid) --/
+//
+// The environment index ENVX(eid) equals the environment's offset in the
+// 'envs[]' array. The uniqueifier distinguishes environments that were
+// created at different times, but share the same environment index.
+//
+// All real environments are greater than 0 (so the sign bit is zero).
+// envid_ts less than 0 signify errors. The envid_t == 0 is special, and
+// stands for the current environment.
+
+#define LOG2NENV 10
+#define NENV (1 << LOG2NENV)
+#define ENVX(envid) ((envid) & (NENV - 1))
+
+// Values of env_status in struct Env
+#define ENV_FREE 0
+#define ENV_RUNNABLE 1
+#define ENV_NOT_RUNNABLE 2
+
+struct Env {
+ struct Trapframe env_tf; // Saved registers
+ LIST_ENTRY(Env) env_link; // Free list link pointers
+ envid_t env_id; // Unique environment identifier
+ envid_t env_parent_id; // env_id of this env's parent
+ unsigned env_status; // Status of the environment
+ uint32_t env_runs; // Number of times environment has run
+
+ // Address space
+ pde_t *env_pgdir; // Kernel virtual address of page dir
+ physaddr_t env_cr3; // Physical address of page dir
+
+};
+
+#endif // !JOS_INC_ENV_H
View
@@ -74,7 +74,7 @@
// Only flags in PTE_USER may be used in system calls.
#define PTE_USER (PTE_AVAIL | PTE_P | PTE_W | PTE_U)
-// address in page table entry
+// Address in page table or page directory entry
#define PTE_ADDR(pte) ((physaddr_t) (pte) & ~0xFFF)
// Control Register flags
View
@@ -0,0 +1,81 @@
+#ifndef JOS_INC_TRAP_H
+#define JOS_INC_TRAP_H
+
+// Trap numbers
+// These are processor defined:
+#define T_DIVIDE 0 // divide error
+#define T_DEBUG 1 // debug exception
+#define T_NMI 2 // non-maskable interrupt
+#define T_BRKPT 3 // breakpoint
+#define T_OFLOW 4 // overflow
+#define T_BOUND 5 // bounds check
+#define T_ILLOP 6 // illegal opcode
+#define T_DEVICE 7 // device not available
+#define T_DBLFLT 8 // double fault
+/* #define T_COPROC 9 */ // reserved (not generated by recent processors)
+#define T_TSS 10 // invalid task switch segment
+#define T_SEGNP 11 // segment not present
+#define T_STACK 12 // stack exception
+#define T_GPFLT 13 // general protection fault
+#define T_PGFLT 14 // page fault
+/* #define T_RES 15 */ // reserved
+#define T_FPERR 16 // floating point error
+#define T_ALIGN 17 // aligment check
+#define T_MCHK 18 // machine check
+#define T_SIMDERR 19 // SIMD floating point error
+
+// These are arbitrarily chosen, but with care not to overlap
+// processor defined exceptions or interrupt vectors.
+#define T_SYSCALL 48 // system call
+#define T_DEFAULT 500 // catchall
+
+// Hardware IRQ numbers. We receive these as (IRQ_OFFSET+IRQ_WHATEVER)
+#define IRQ_TIMER 0
+#define IRQ_KBD 1
+#define IRQ_SPURIOUS 7
+#define IRQ_IDE 14
+#define IRQ_ERROR 19
+
+#ifndef __ASSEMBLER__
+
+#include <inc/types.h>
+
+struct PushRegs {
+ /* registers as pushed by pusha */
+ uint32_t reg_edi;
+ uint32_t reg_esi;
+ uint32_t reg_ebp;
+ uint32_t reg_oesp; /* Useless */
+ uint32_t reg_ebx;
+ uint32_t reg_edx;
+ uint32_t reg_ecx;
+ uint32_t reg_eax;
+};
+
+struct Trapframe {
+ struct PushRegs tf_regs;
+ uint16_t tf_es;
+ uint16_t tf_padding1;
+ uint16_t tf_ds;
+ uint16_t tf_padding2;
+ uint32_t tf_trapno;
+ /* below here defined by x86 hardware */
+ uint32_t tf_err;
+ uintptr_t tf_eip;
+ uint16_t tf_cs;
+ uint16_t tf_padding3;
+ uint32_t tf_eflags;
+ /* below here only when crossing rings, such as from user to kernel */
+ uintptr_t tf_esp;
+ uint16_t tf_ss;
+ uint16_t tf_padding4;
+};
+
+
+#endif /* !__ASSEMBLER__ */
+
+// Must equal 'sizeof(struct Trapframe)'.
+// A static_assert in kern/trap.c checks this.
+#define SIZEOF_STRUCT_TRAPFRAME 0x44
+
+#endif /* !JOS_INC_TRAP_H */
Oops, something went wrong.

0 comments on commit b9a9356

Please sign in to comment.