Skip to content

Commit

Permalink
Minor lab3 updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Austin Clements committed Oct 13, 2011
1 parent 9bf29a3 commit 71f35fe
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 104 deletions.
28 changes: 13 additions & 15 deletions GNUmakefile
Expand Up @@ -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
Expand Down Expand Up @@ -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 "***"
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion conf/lab.mk
@@ -1,2 +1,2 @@
LAB=3
PACKAGEDATE=Wed Sep 28 23:57:24 EDT 2011
PACKAGEDATE=Wed Oct 12 22:56:15 EDT 2011
75 changes: 0 additions & 75 deletions inc/COPYRIGHT
Expand Up @@ -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:

/*
Expand Down Expand Up @@ -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:

/*-
Expand Down
16 changes: 13 additions & 3 deletions inc/memlayout.h
Expand Up @@ -23,6 +23,8 @@
* kernel/user
*
* 4 Gig --------> +------------------------------+
* | Memory-mapped I/O | RW/--
* IOMEMBASE ----> +------------------------------+ 0xfe000000
* | | RW/--
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* : . :
Expand All @@ -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
Expand Down Expand Up @@ -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)

/*
Expand Down
1 change: 1 addition & 0 deletions inc/string.h
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions inc/trap.h
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions inc/x86.h
Expand Up @@ -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 */
2 changes: 2 additions & 0 deletions kern/Makefrag
Expand Up @@ -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 \
Expand Down
2 changes: 1 addition & 1 deletion kern/init.c
Expand Up @@ -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.
Expand Down
5 changes: 1 addition & 4 deletions kern/kclock.c
@@ -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>

Expand Down
1 change: 0 additions & 1 deletion kern/kclock.h
Expand Up @@ -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
11 changes: 7 additions & 4 deletions kern/trap.c
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions lib/string.c
Expand Up @@ -39,6 +39,14 @@ strcpy(char *dst, const char *src)
return ret;
}

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;
Expand Down

0 comments on commit 71f35fe

Please sign in to comment.