Permalink
Browse files

update lab2

  • Loading branch information...
1 parent f61c7b2 commit 82f50cb270ef5cc0e46d17527a2bc61cf092f825 Haogang Chen committed Sep 15, 2011
Showing with 1,069 additions and 60 deletions.
  1. +10 −0 .dir-locals.el
  2. +14 −0 .gitignore
  3. +9 −3 GNUmakefile
  4. +2 −2 conf/lab.mk
  5. +50 −0 grade-lab2.sh
  6. +0 −7 inc/malloc.h
  7. +12 −18 inc/memlayout.h
  8. +5 −7 inc/mmu.h
  9. +1 −10 kern/entry.S
  10. +4 −13 kern/init.c
  11. +25 −0 kern/kclock.c
  12. +33 −0 kern/kclock.h
  13. +817 −0 kern/pmap.c
  14. +87 −0 kern/pmap.h
View
@@ -0,0 +1,10 @@
+((nil
+ (indent-tabs-mode . t)
+ (tab-width . 8))
+ (c-mode
+ (c-file-style . "bsd")
+ (c-basic-offset . 8))
+ (shell-mode
+ (sh-basic-offset . 8)
+ (sh-indentation . 8))
+ )
View
@@ -0,0 +1,14 @@
+/obj
+/jos.in
+/jos.log
+/jos.out
+/jos.out.*
+/jos.cmd
+/.gdbinit
+/wget.log
+/slirp.cap
+/qemu.out
+/lab?-handin.tar.gz
+/lab?/
+/sol?/
+/conf/lab.mk
View
@@ -7,13 +7,19 @@
#
OBJDIR := obj
+# Run 'make V=1' to turn on verbose commands, or 'make V=0' to turn them off.
+ifeq ($(V),1)
+override V =
+endif
+ifeq ($(V),0)
+override V = @
+endif
+
-include conf/lab.mk
-include conf/env.mk
-ifndef LABSETUP
-LABSETUP := ./
-endif
+LABSETUP ?= ./
TOP = .
View
@@ -1,2 +1,2 @@
-LAB=1
-PACKAGEDATE=Wed Sep 7 19:17:10 EDT 2011
+LAB=2
+PACKAGEDATE=Wed Sep 14 23:28:01 EDT 2011
View
@@ -0,0 +1,50 @@
+#!/bin/sh
+
+qemuopts="-hda obj/kern/kernel.img"
+. ./grade-functions.sh
+
+
+$make
+
+check () {
+ pts=20
+ echo_n "Physical page allocator: "
+ if grep "check_page_alloc() succeeded!" jos.out >/dev/null
+ then
+ pass
+ else
+ fail
+ fi
+
+ pts=20
+ echo_n "Page management: "
+ if grep "check_page() succeeded!" jos.out >/dev/null
+ then
+ pass
+ else
+ fail
+ fi
+
+ pts=20
+ echo_n "Kernel page directory: "
+ if grep "check_kern_pgdir() succeeded!" jos.out >/dev/null
+ then
+ pass
+ else
+ fail
+ fi
+
+ pts=10
+ echo_n "Page management 2: "
+ if grep "check_page_installed_pgdir() succeeded!" jos.out >/dev/null
+ then
+ pass
+ else
+ fail
+ fi
+}
+
+run
+check
+
+showfinal
View
@@ -1,7 +0,0 @@
-#ifndef JOS_INC_MALLOC_H
-#define JOS_INC_MALLOC_H 1
-
-void *malloc(size_t size);
-void free(void *addr);
-
-#endif
View
@@ -3,7 +3,6 @@
#ifndef __ASSEMBLER__
#include <inc/types.h>
-#include <inc/queue.h>
#include <inc/mmu.h>
#endif /* not __ASSEMBLER__ */
@@ -34,8 +33,8 @@
* | Remapped Physical Memory | RW/--
* | | RW/--
* KERNBASE -----> +------------------------------+ 0xf0000000
- * | Cur. Page Table (Kern. RW) | RW/-- PTSIZE
- * VPT,KSTACKTOP--> +------------------------------+ 0xefc00000 --+
+ * | Empty Memory (*) | --/-- PTSIZE
+ * KSTACKTOP ----> +------------------------------+ 0xefc00000 --+
* | Kernel Stack | RW/-- KSTKSIZE |
* | - - - - - - - - - - - - - - -| PTSIZE
* | Invalid Memory (*) | --/-- |
@@ -87,12 +86,8 @@
#define IOPHYSMEM 0x0A0000
#define EXTPHYSMEM 0x100000
-// Virtual page table. Entry PDX[VPT] in the PD contains a pointer to
-// the page directory itself, thereby turning the PD into a page table,
-// which maps all the PTEs containing the page mappings for the entire
-// virtual address space into that 4 Meg region starting at VPT.
-#define VPT (KERNBASE - PTSIZE)
-#define KSTACKTOP VPT
+// Kernel stack.
+#define KSTACKTOP (KERNBASE - PTSIZE)
#define KSTKSIZE (8*PGSIZE) // size of a kernel stack
#define ULIM (KSTACKTOP - PTSIZE)
@@ -101,7 +96,7 @@
* They are global pages mapped in at env allocation time.
*/
-// Same as VPT but read-only for users
+// User read-only virtual page table (see 'vpt' below)
#define UVPT (ULIM - PTSIZE)
// Read-only copies of the Page structures
#define UPAGES (UVPT - PTSIZE)
@@ -134,6 +129,10 @@
#ifndef __ASSEMBLER__
+typedef uint32_t pte_t;
+typedef uint32_t pde_t;
+
+#if JOS_USER
/*
* The page directory entry corresponding to the virtual address range
* [VPT, VPT + PTSIZE) points to the page directory itself. Thus, the page
@@ -148,12 +147,9 @@
* will always be available at virtual address (VPT + (VPT >> PGSHIFT)), to
* which vpd is set in entry.S.
*/
-typedef uint32_t pte_t;
-typedef uint32_t pde_t;
-
extern volatile pte_t vpt[]; // VA of "virtual page table"
extern volatile pde_t vpd[]; // VA of current page directory
-
+#endif
/*
* Page descriptor structures, mapped at UPAGES.
@@ -165,11 +161,9 @@ extern volatile pde_t vpd[]; // VA of current page directory
* You can map a Page * to the corresponding physical address
* with page2pa() in kern/pmap.h.
*/
-LIST_HEAD(Page_list, Page);
-typedef LIST_ENTRY(Page) Page_LIST_entry_t;
-
struct Page {
- Page_LIST_entry_t pp_link; /* free list link */
+ // Next page on the free list.
+ struct Page *pp_link;
// pp_ref is the count of pointers (usually in page table entries)
// to this page, for pages allocated using page_alloc.
View
@@ -20,19 +20,17 @@
// | Index | Index | |
// +----------------+----------------+---------------------+
// \--- PDX(la) --/ \--- PTX(la) --/ \---- PGOFF(la) ----/
-// \----------- VPN(la) -----------/
+// \---------- PGNUM(la) ----------/
//
-// The PDX, PTX, PGOFF, and VPN macros decompose linear addresses as shown.
+// The PDX, PTX, PGOFF, and PGNUM macros decompose linear addresses as shown.
// To construct a linear address la from PDX(la), PTX(la), and PGOFF(la),
// use PGADDR(PDX(la), PTX(la), PGOFF(la)).
// page number field of address
-#define PPN(pa) (((uintptr_t) (pa)) >> PTXSHIFT)
-#define VPN(la) PPN(la) // used to index into vpt[]
+#define PGNUM(la) (((uintptr_t) (la)) >> PTXSHIFT)
// page directory index
#define PDX(la) ((((uintptr_t) (la)) >> PDXSHIFT) & 0x3FF)
-#define VPD(la) PDX(la) // used to index into vpd[]
// page table index
#define PTX(la) ((((uintptr_t) (la)) >> PTXSHIFT) & 0x3FF)
@@ -71,8 +69,8 @@
// hardware, so user processes are allowed to set them arbitrarily.
#define PTE_AVAIL 0xE00 // Available for software use
-// Only flags in PTE_ALLOWED may be used in system calls.
-#define PTE_ALLOWED (PTE_AVAIL | PTE_P | PTE_W | PTE_U)
+// Flags in PTE_SYSCALL may be used in system calls. (Others may not.)
+#define PTE_SYSCALL (PTE_AVAIL | PTE_P | PTE_W | PTE_U)
// Address in page table or page directory entry
#define PTE_ADDR(pte) ((physaddr_t) (pte) & ~0xFFF)
View
@@ -49,7 +49,7 @@ entry:
# KERNBASE+1MB. Hence, we set up a trivial page directory that
# translates virtual addresses [KERNBASE, KERNBASE+4MB) to
# physical addresses [0, 4MB). This 4MB region will be suffice
- # until we set up our real page table in i386_vm_init in lab 2.
+ # until we set up our real page table in mem_init in lab 2.
# Load the physical address of entry_pgdir into cr3. entry_pgdir
# is defined in entrypgdir.c.
@@ -82,16 +82,7 @@ relocated:
spin: jmp spin
-###################################################################
-# See <inc/memlayout.h> for a complete description of these two symbols.
-###################################################################
.data
- .globl vpt
- .set vpt, VPT
- .globl vpd
- .set vpd, (VPT + SRL(VPT, 10))
-
-
###################################################################
# boot stack
###################################################################
View
@@ -6,18 +6,9 @@
#include <kern/monitor.h>
#include <kern/console.h>
+#include <kern/pmap.h>
+#include <kern/kclock.h>
-// Test the stack backtrace function (lab 1 only)
-void
-test_backtrace(int x)
-{
- cprintf("entering test_backtrace %d\n", x);
- if (x > 0)
- test_backtrace(x-1);
- else
- mon_backtrace(0, 0, 0);
- cprintf("leaving test_backtrace %d\n", x);
-}
void
i386_init(void)
@@ -35,8 +26,8 @@ i386_init(void)
cprintf("6828 decimal is %o octal!\n", 6828);
- // Test the stack backtrace function (lab 1 only)
- test_backtrace(5);
+ // Lab 2 memory management initialization functions
+ mem_init();
// Drop into the kernel monitor.
while (1)
View
@@ -0,0 +1,25 @@
+/* See COPYRIGHT for copyright information. */
+
+/* Support for two time-related hardware gadgets: 1) the run time
+ * clock with its NVRAM access functions; 2) the 8253 timer, which
+ * generates interrupts on IRQ 0.
+ */
+
+#include <inc/x86.h>
+
+#include <kern/kclock.h>
+
+
+unsigned
+mc146818_read(unsigned reg)
+{
+ outb(IO_RTC, reg);
+ return inb(IO_RTC+1);
+}
+
+void
+mc146818_write(unsigned reg, unsigned datum)
+{
+ outb(IO_RTC, reg);
+ outb(IO_RTC+1, datum);
+}
View
@@ -0,0 +1,33 @@
+/* See COPYRIGHT for copyright information. */
+
+#ifndef JOS_KERN_KCLOCK_H
+#define JOS_KERN_KCLOCK_H
+#ifndef JOS_KERNEL
+# error "This is a JOS kernel header; user programs should not #include it"
+#endif
+
+#define IO_RTC 0x070 /* RTC port */
+
+#define MC_NVRAM_START 0xe /* start of NVRAM: offset 14 */
+#define MC_NVRAM_SIZE 50 /* 50 bytes of NVRAM */
+
+/* NVRAM bytes 7 & 8: base memory size */
+#define NVRAM_BASELO (MC_NVRAM_START + 7) /* low byte; RTC off. 0x15 */
+#define NVRAM_BASEHI (MC_NVRAM_START + 8) /* high byte; RTC off. 0x16 */
+
+/* NVRAM bytes 9 & 10: extended memory size */
+#define NVRAM_EXTLO (MC_NVRAM_START + 9) /* low byte; RTC off. 0x17 */
+#define NVRAM_EXTHI (MC_NVRAM_START + 10) /* high byte; RTC off. 0x18 */
+
+/* NVRAM bytes 34 and 35: extended memory POSTed size */
+#define NVRAM_PEXTLO (MC_NVRAM_START + 34) /* low byte; RTC off. 0x30 */
+#define NVRAM_PEXTHI (MC_NVRAM_START + 35) /* high byte; RTC off. 0x31 */
+
+/* NVRAM byte 36: current century. (please increment in Dec99!) */
+#define NVRAM_CENTURY (MC_NVRAM_START + 36) /* RTC offset 0x32 */
+
+unsigned mc146818_read(unsigned reg);
+void mc146818_write(unsigned reg, unsigned datum);
+void kclock_init(void);
+
+#endif // !JOS_KERN_KCLOCK_H
Oops, something went wrong.

0 comments on commit 82f50cb

Please sign in to comment.