Permalink
Browse files

Minor lab3 updates

  • Loading branch information...
1 parent 9bf29a3 commit 71f35fea2e2cc04d927bce9244eaa8b5cb00eaf5 @aclements aclements committed Oct 13, 2011
Showing with 62 additions and 104 deletions.
  1. +13 −15 GNUmakefile
  2. +1 −1 conf/lab.mk
  3. +0 −75 inc/COPYRIGHT
  4. +13 −3 inc/memlayout.h
  5. +1 −0 inc/string.h
  6. +2 −0 inc/trap.h
  7. +13 −0 inc/x86.h
  8. +2 −0 kern/Makefrag
  9. +1 −1 kern/init.c
  10. +1 −4 kern/kclock.c
  11. +0 −1 kern/kclock.h
  12. +7 −4 kern/trap.c
  13. +8 −0 lib/string.c
View
@@ -63,10 +63,6 @@ endif
# try to generate a unique GDB port
GDBPORT := $(shell expr `id -u` % 5000 + 25000)
-# QEMU's gdb stub command line changed in 0.11
-QEMUGDB = $(shell if $(QEMU) -nographic -help | grep -q '^-gdb'; \
- then echo "-gdb tcp::$(GDBPORT)"; \
- else echo "-s -p $(GDBPORT)"; fi)
CC := $(GCCPREFIX)gcc -pipe
AS := $(GCCPREFIX)as
@@ -130,16 +126,18 @@ include lib/Makefrag
include user/Makefrag
+QEMUOPTS = -hda $(OBJDIR)/kern/kernel.img -serial mon:stdio -gdb tcp::$(GDBPORT) -D qemu.log
IMAGES = $(OBJDIR)/kern/kernel.img
-QEMUOPTS = -hda $(OBJDIR)/kern/kernel.img -serial mon:stdio $(QEMUEXTRA)
+QEMUOPTS += $(QEMUEXTRA)
+
.gdbinit: .gdbinit.tmpl
sed "s/localhost:1234/localhost:$(GDBPORT)/" < $^ > $@
-qemu: $(IMAGES)
+qemu: $(IMAGES) .gdbinit
$(QEMU) $(QEMUOPTS)
-qemu-nox: $(IMAGES)
+qemu-nox: $(IMAGES) .gdbinit
@echo "***"
@echo "*** Use Ctrl-a x to exit qemu"
@echo "***"
@@ -149,13 +147,13 @@ qemu-gdb: $(IMAGES) .gdbinit
@echo "***"
@echo "*** Now run 'gdb'." 1>&2
@echo "***"
- $(QEMU) $(QEMUOPTS) -S $(QEMUGDB)
+ $(QEMU) $(QEMUOPTS) -S
qemu-nox-gdb: $(IMAGES) .gdbinit
@echo "***"
@echo "*** Now run 'gdb'." 1>&2
@echo "***"
- $(QEMU) -nographic $(QEMUOPTS) -S $(QEMUGDB)
+ $(QEMU) -nographic $(QEMUOPTS) -S
print-qemu:
@echo $(QEMU)
@@ -168,7 +166,7 @@ print-qemugdb:
# For deleting the build
clean:
- rm -rf $(OBJDIR) .gdbinit jos.in
+ rm -rf $(OBJDIR) .gdbinit jos.in qemu.log
realclean: clean
rm -rf lab$(LAB).tar.gz jos.out
@@ -197,22 +195,22 @@ tarball: realclean
# For test runs
prep-%:
$(V)rm -f $(OBJDIR)/kern/init.o $(IMAGES)
- $(V)$(MAKE) "DEFS=-DTEST=user_$*" $(IMAGES)
+ $(V)$(MAKE) "DEFS=-DTEST=$$(case $* in *_*) echo $*;; *) echo user_$*;; esac)" $(IMAGES)
$(V)rm -f $(OBJDIR)/kern/init.o
run-%-nox-gdb: .gdbinit
$(V)$(MAKE) --no-print-directory prep-$*
- $(QEMU) -nographic $(QEMUOPTS) -S $(QEMUGDB)
+ $(QEMU) -nographic $(QEMUOPTS) -S
run-%-gdb: .gdbinit
$(V)$(MAKE) --no-print-directory prep-$*
- $(QEMU) $(QEMUOPTS) -S $(QEMUGDB)
+ $(QEMU) $(QEMUOPTS) -S
-run-%-nox:
+run-%-nox: .gdbinit
$(V)$(MAKE) --no-print-directory prep-$*
$(QEMU) -nographic $(QEMUOPTS)
-run-%:
+run-%: .gdbinit
$(V)$(MAKE) --no-print-directory prep-$*
$(QEMU) $(QEMUOPTS)
View
@@ -1,2 +1,2 @@
LAB=3
-PACKAGEDATE=Wed Sep 28 23:57:24 EDT 2011
+PACKAGEDATE=Wed Oct 12 22:56:15 EDT 2011
View
@@ -36,46 +36,6 @@ The files in this directory are:
* the copyright notices, if any, listed below.
*/
-isareg.h is copyright:
-
-/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * William Jolitz.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)isa.h 5.7 (Berkeley) 5/9/91
- */
-
queue.h is:
/*
@@ -150,41 +110,6 @@ stdarg.h is:
* @(#)stdarg.h 8.1 (Berkeley) 6/10/93
*/
-timerreg.h is:
-
-/*-
- * Copyright (c) 1993 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
types.h is:
/*-
View
@@ -23,6 +23,8 @@
* kernel/user
*
* 4 Gig --------> +------------------------------+
+ * | Memory-mapped I/O | RW/--
+ * IOMEMBASE ----> +------------------------------+ 0xfe000000
* | | RW/--
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* : . :
@@ -33,11 +35,18 @@
* | Remapped Physical Memory | RW/--
* | | RW/--
* KERNBASE -----> +------------------------------+ 0xf0000000
- * | Empty Memory (*) | --/-- PTSIZE
+ * | Invalid Memory (*) | --/-- PTSIZE
* KSTACKTOP ----> +------------------------------+ 0xefc00000 --+
- * | Kernel Stack | RW/-- KSTKSIZE |
+ * | CPU0's Kernel Stack | RW/-- KSTKSIZE |
+ * | - - - - - - - - - - - - - - -| |
+ * | Invalid Memory (*) | --/-- KSTKGAP |
+ * +------------------------------+ |
+ * | CPU1's Kernel Stack | RW/-- KSTKSIZE |
* | - - - - - - - - - - - - - - -| PTSIZE
- * | Invalid Memory (*) | --/-- |
+ * | Invalid Memory (*) | --/-- KSTKGAP |
+ * +------------------------------+ |
+ * : . : |
+ * : . : |
* ULIM ------> +------------------------------+ 0xef800000 --+
* | Cur. Page Table (User R-) | R-/R- PTSIZE
* UVPT ----> +------------------------------+ 0xef400000
@@ -89,6 +98,7 @@
// Kernel stack.
#define KSTACKTOP (KERNBASE - PTSIZE)
#define KSTKSIZE (8*PGSIZE) // size of a kernel stack
+#define KSTKGAP (8*PGSIZE) // size of a kernel stack guard
#define ULIM (KSTACKTOP - PTSIZE)
/*
View
@@ -7,6 +7,7 @@ int strlen(const char *s);
int strnlen(const char *s, size_t size);
char * strcpy(char *dst, const char *src);
char * strncpy(char *dst, const char *src, size_t size);
+char * strcat(char *dst, const char *src);
size_t strlcpy(char *dst, const char *src, size_t size);
int strcmp(const char *s1, const char *s2);
int strncmp(const char *s1, const char *s2, size_t size);
View
@@ -29,6 +29,8 @@
#define T_SYSCALL 48 // system call
#define T_DEFAULT 500 // catchall
+#define IRQ_OFFSET 32 // IRQ 0 corresponds to int IRQ_OFFSET
+
// Hardware IRQ numbers. We receive these as (IRQ_OFFSET+IRQ_WHATEVER)
#define IRQ_TIMER 0
#define IRQ_KBD 1
View
@@ -280,4 +280,17 @@ read_tsc(void)
return tsc;
}
+static inline uint32_t
+xchg(volatile uint32_t *addr, uint32_t newval)
+{
+ uint32_t result;
+
+ // The + in "+m" denotes a read-modify-write operand.
+ asm volatile("lock; xchgl %0, %1" :
+ "+m" (*addr), "=a" (result) :
+ "1" (newval) :
+ "cc");
+ return result;
+}
+
#endif /* !JOS_INC_X86_H */
View
@@ -35,6 +35,8 @@ KERN_SRCFILES := kern/entry.S \
# Only build files if they exist.
KERN_SRCFILES := $(wildcard $(KERN_SRCFILES))
+# Binary program images to embed within the kernel.
+# Binary files for LAB3
KERN_BINFILES := user/hello \
user/buggyhello \
user/buggyhello2 \
View
@@ -52,7 +52,7 @@ i386_init(void)
* Variable panicstr contains argument to first call to panic; used as flag
* to indicate that the kernel has already called panic.
*/
-static const char *panicstr;
+const char *panicstr;
/*
* Panic is called on unresolvable fatal errors.
View
@@ -1,9 +1,6 @@
/* 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.
- */
+/* Support for reading the NVRAM from the real-time clock. */
#include <inc/x86.h>
View
@@ -28,6 +28,5 @@
unsigned mc146818_read(unsigned reg);
void mc146818_write(unsigned reg, unsigned datum);
-void kclock_init(void);
#endif // !JOS_KERN_KCLOCK_H
View
@@ -79,12 +79,13 @@ trap_init_percpu(void)
ts.ts_esp0 = KSTACKTOP;
ts.ts_ss0 = GD_KD;
- // Initialize the TSS field of the gdt.
+ // Initialize the TSS slot of the gdt.
gdt[GD_TSS0 >> 3] = SEG16(STS_T32A, (uint32_t) (&ts),
sizeof(struct Taskstate), 0);
gdt[GD_TSS0 >> 3].sd_s = 0;
- // Load the TSS
+ // Load the TSS selector (like other segment selectors, the
+ // bottom three bits are special; we leave them 0)
ltr(GD_TSS0);
// Load the IDT
@@ -118,8 +119,10 @@ print_trapframe(struct Trapframe *tf)
cprintf(" eip 0x%08x\n", tf->tf_eip);
cprintf(" cs 0x----%04x\n", tf->tf_cs);
cprintf(" flag 0x%08x\n", tf->tf_eflags);
- cprintf(" esp 0x%08x\n", tf->tf_esp);
- cprintf(" ss 0x----%04x\n", tf->tf_ss);
+ if ((tf->tf_cs & 3) != 0) {
+ cprintf(" esp 0x%08x\n", tf->tf_esp);
+ cprintf(" ss 0x----%04x\n", tf->tf_ss);
+ }
}
void
View
@@ -40,6 +40,14 @@ strcpy(char *dst, const char *src)
}
char *
+strcat(char *dst, const char *src)
+{
+ int len = strlen(dst);
+ strcpy(dst + len, src);
+ return dst;
+}
+
+char *
strncpy(char *dst, const char *src, size_t size) {
size_t i;
char *ret;

0 comments on commit 71f35fe

Please sign in to comment.