Skip to content
Browse files

add some code of lab3

  • Loading branch information...
1 parent 7271475 commit c474a755e8108fc178eedfde2671fdbc3bcce993 @kelwin committed Jan 16, 2013
Showing with 159 additions and 19 deletions.
  1. +3 −0 .gitignore
  2. +1 −1 GNUmakefile
  3. +2 −2 grade-functions.sh
  4. 0 grade-lab1.sh
  5. 0 grade-lab2.sh
  6. 0 grade-lab3.sh
  7. +1 −1 kern/init.c
  8. +78 −0 kern/trap.c
  9. +74 −15 kern/trapentry.S
View
3 .gitignore
@@ -13,3 +13,6 @@
/sol?/
/conf/lab.mk
/tags
+/GPATH
+/GRTAGS
+/GTAGS
View
2 GNUmakefile
@@ -195,7 +195,7 @@ tarball: realclean
# For test runs
prep-%:
$(V)rm -f $(OBJDIR)/kern/init.o $(IMAGES)
- $(V)$(MAKE) "DEFS=-DTEST=$$(case $* in *_*) echo $*;; *) echo user_$*;; esac)" $(IMAGES)
+ $(V)$(MAKE) "DEFS=-DTEST=`case $* in *_*) echo $*;; *) echo user_$*;; esac`" $(IMAGES)
$(V)rm -f $(OBJDIR)/kern/init.o
run-%-nox-gdb: .gdbinit
View
4 grade-functions.sh 100644 → 100755
@@ -1,4 +1,4 @@
-verbose=false
+verbose=true
if [ "x$1" = "x-v" ]
then
@@ -64,7 +64,7 @@ run () {
echo "br *0x$brkaddr"
echo c
) > jos.in
- gdb -batch -nx -x jos.in > /dev/null 2>&1
+ i386-jos-elf-gdb -batch -nx -x jos.in
# Make sure QEMU is dead. On OS X, exiting gdb
# doesn't always exit QEMU.
View
0 grade-lab1.sh 100644 → 100755
File mode changed.
View
0 grade-lab2.sh 100644 → 100755
File mode changed.
View
0 grade-lab3.sh 100644 → 100755
File mode changed.
View
2 kern/init.c
@@ -40,7 +40,7 @@ i386_init(void)
ENV_CREATE(TEST, ENV_TYPE_USER);
#else
// Touch all you want.
- ENV_CREATE(user_hello, ENV_TYPE_USER);
+ ENV_CREATE(user_softint, ENV_TYPE_USER);
#endif // TEST*
// We only have one user environment for now, so just run it.
View
78 kern/trap.c
@@ -65,6 +65,84 @@ trap_init(void)
extern struct Segdesc gdt[];
// LAB 3: Your code here.
+ extern void __idt_divide();
+ extern void __idt_debug();
+ extern void __idt_nmi();
+ extern void __idt_breakpoint();
+ extern void __idt_overflow();
+ extern void __idt_bound();
+ extern void __idt_illop();
+ extern void __idt_device();
+ extern void __idt_dblflt();
+ extern void __idt_tss();
+ extern void __idt_segnp();
+ extern void __idt_stack();
+ extern void __idt_gpflt();
+ extern void __idt_pgflt();
+ extern void __idt_fperr();
+ extern void __idt_align();
+ extern void __idt_mchk();
+ extern void __idt_simd();
+ extern void __idt_syscall();
+ extern void __idt_default();
+
+ extern void __idt_irq0();
+ extern void __idt_irq1();
+ extern void __idt_irq2();
+ extern void __idt_irq3();
+ extern void __idt_irq4();
+ extern void __idt_irq5();
+ extern void __idt_irq6();
+ extern void __idt_irq7();
+ extern void __idt_irq8();
+ extern void __idt_irq9();
+ extern void __idt_irq10();
+ extern void __idt_irq11();
+ extern void __idt_irq12();
+ extern void __idt_irq13();
+ extern void __idt_irq14();
+
+ int i = 0;
+ SETGATE(idt[0], 0, GD_KT, __idt_default, 0);
+ for (i = 1; i < 255; ++i) {
+ idt[i] = idt[0];
+ }
+
+ SETGATE(idt[T_DIVIDE], 1, GD_KT, __idt_divide, 0);
+ SETGATE(idt[T_DEBUG], 1, GD_KT, __idt_debug, 0);
+ SETGATE(idt[T_NMI], 0, GD_KT, __idt_nmi, 0);
+ SETGATE(idt[T_BRKPT], 1, GD_KT, __idt_breakpoint, 3);
+ SETGATE(idt[T_OFLOW], 1, GD_KT, __idt_overflow, 0);
+ SETGATE(idt[T_BOUND], 1, GD_KT, __idt_bound, 0);
+ SETGATE(idt[T_ILLOP], 1, GD_KT, __idt_illop, 0);
+ SETGATE(idt[T_DEVICE], 1, GD_KT, __idt_device, 0);
+ SETGATE(idt[T_DBLFLT], 1, GD_KT, __idt_dblflt, 0);
+ SETGATE(idt[T_TSS], 1, GD_KT, __idt_tss, 0);
+ SETGATE(idt[T_SEGNP], 1, GD_KT, __idt_segnp, 0);
+ SETGATE(idt[T_STACK], 1, GD_KT, __idt_stack, 0);
+ SETGATE(idt[T_GPFLT], 1, GD_KT, __idt_gpflt, 0);
+ SETGATE(idt[T_PGFLT], 1, GD_KT, __idt_pgflt, 0);
+ SETGATE(idt[T_FPERR], 1, GD_KT, __idt_fperr, 0);
+ SETGATE(idt[T_ALIGN], 1, GD_KT, __idt_align, 0);
+ SETGATE(idt[T_MCHK], 1, GD_KT, __idt_mchk, 0);
+ SETGATE(idt[T_SIMDERR], 1, GD_KT, __idt_simd, 0);
+ SETGATE(idt[T_SYSCALL], 0, GD_KT, __idt_syscall, 3);
+
+ SETGATE(idt[IRQ_OFFSET], 0, GD_KT, __idt_irq0, 0);
+ SETGATE(idt[IRQ_OFFSET + 1], 0, GD_KT, __idt_irq1, 0);
+ SETGATE(idt[IRQ_OFFSET + 2], 0, GD_KT, __idt_irq2, 0);
+ SETGATE(idt[IRQ_OFFSET + 3], 0, GD_KT, __idt_irq3, 0);
+ SETGATE(idt[IRQ_OFFSET + 4], 0, GD_KT, __idt_irq4, 0);
+ SETGATE(idt[IRQ_OFFSET + 5], 0, GD_KT, __idt_irq5, 0);
+ SETGATE(idt[IRQ_OFFSET + 6], 0, GD_KT, __idt_irq6, 0);
+ SETGATE(idt[IRQ_OFFSET + 7], 0, GD_KT, __idt_irq7, 0);
+ SETGATE(idt[IRQ_OFFSET + 8], 0, GD_KT, __idt_irq8, 0);
+ SETGATE(idt[IRQ_OFFSET + 9], 0, GD_KT, __idt_irq9, 0);
+ SETGATE(idt[IRQ_OFFSET + 10], 0, GD_KT, __idt_irq10, 0);
+ SETGATE(idt[IRQ_OFFSET + 11], 0, GD_KT, __idt_irq11, 0);
+ SETGATE(idt[IRQ_OFFSET + 12], 0, GD_KT, __idt_irq12, 0);
+ SETGATE(idt[IRQ_OFFSET + 13], 0, GD_KT, __idt_irq13, 0);
+ SETGATE(idt[IRQ_OFFSET + 14], 0, GD_KT, __idt_irq14, 0);
// Per-CPU setup
trap_init_percpu();
View
89 kern/trapentry.S
@@ -20,26 +20,26 @@
* void NAME();
* where NAME is the argument passed to TRAPHANDLER.
*/
-#define TRAPHANDLER(name, num) \
- .globl name; /* define global symbol for 'name' */ \
- .type name, @function; /* symbol type is function */ \
- .align 2; /* align function definition */ \
- name: /* function starts here */ \
- pushl $(num); \
- jmp _alltraps
+#define TRAPHANDLER(name, num) \
+ .globl name; /* define global symbol for 'name' */ \
+ .type name, @function; /* symbol type is function */ \
+ .align 2; /* align function definition */ \
+ name: /* function starts here */ \
+ pushl $(num); \
+ jmp _alltraps
/* Use TRAPHANDLER_NOEC for traps where the CPU doesn't push an error code.
* It pushes a 0 in place of the error code, so the trap frame has the same
* format in either case.
*/
-#define TRAPHANDLER_NOEC(name, num) \
- .globl name; \
- .type name, @function; \
- .align 2; \
- name: \
- pushl $0; \
- pushl $(num); \
- jmp _alltraps
+#define TRAPHANDLER_NOEC(name, num) \
+ .globl name; \
+ .type name, @function; \
+ .align 2; \
+ name: \
+ pushl $0; \
+ pushl $(num); \
+ jmp _alltraps
.text
@@ -48,8 +48,67 @@
*/
+// Processor definde exceptions
+TRAPHANDLER_NOEC(__idt_divide, T_DIVIDE) // divide error
+TRAPHANDLER_NOEC(__idt_debug, T_DEBUG) // debug exception
+TRAPHANDLER_NOEC(__idt_nmi, T_NMI) // non-maskable interrupt
+TRAPHANDLER_NOEC(__idt_breakpoint, T_BRKPT) // breakpoint
+TRAPHANDLER_NOEC(__idt_overflow, T_OFLOW) // overflow
+TRAPHANDLER_NOEC(__idt_bound, T_BOUND) // bounds check
+TRAPHANDLER_NOEC(__idt_illop, T_ILLOP) // illegal opcode
+TRAPHANDLER_NOEC(__idt_device, T_DEVICE) // device not available
+TRAPHANDLER(__idt_dblflt, T_DBLFLT) // double fault
+TRAPHANDLER(__idt_tss, T_TSS) // invalid task switch segment
+TRAPHANDLER(__idt_segnp, T_SEGNP) // segment not present
+TRAPHANDLER(__idt_stack, T_STACK) // stack exception
+TRAPHANDLER(__idt_gpflt, T_GPFLT) // general protection fault
+TRAPHANDLER(__idt_pgflt, T_PGFLT) // page fault
+TRAPHANDLER_NOEC(__idt_fperr, T_FPERR) // floating point error
+TRAPHANDLER(__idt_align, T_ALIGN) // aligment check
+TRAPHANDLER_NOEC(__idt_mchk, T_MCHK) // machine check
+TRAPHANDLER_NOEC(__idt_simd, T_SIMDERR) // SIMD floating point error
+
+// Arbitrarily chosen
+TRAPHANDLER_NOEC(__idt_syscall, T_SYSCALL) // system call
+TRAPHANDLER(__idt_default, T_DEFAULT) // catchall
+
+// Hardware IRQs
+TRAPHANDLER_NOEC(__idt_irq0, IRQ_OFFSET + IRQ_TIMER)
+TRAPHANDLER_NOEC(__idt_irq1, IRQ_OFFSET + IRQ_KBD)
+TRAPHANDLER_NOEC(__idt_irq2, IRQ_OFFSET + 2)
+TRAPHANDLER_NOEC(__idt_irq3, IRQ_OFFSET + 3)
+TRAPHANDLER_NOEC(__idt_irq4, IRQ_OFFSET + IRQ_SERIAL)
+TRAPHANDLER_NOEC(__idt_irq5, IRQ_OFFSET + 5)
+TRAPHANDLER_NOEC(__idt_irq6, IRQ_OFFSET + 6)
+TRAPHANDLER_NOEC(__idt_irq7, IRQ_OFFSET + IRQ_SPURIOUS)
+TRAPHANDLER_NOEC(__idt_irq8, IRQ_OFFSET + 8)
+TRAPHANDLER_NOEC(__idt_irq9, IRQ_OFFSET + 9)
+TRAPHANDLER_NOEC(__idt_irq10, IRQ_OFFSET + 10)
+TRAPHANDLER_NOEC(__idt_irq11, IRQ_OFFSET + 11)
+TRAPHANDLER_NOEC(__idt_irq12, IRQ_OFFSET + 12)
+TRAPHANDLER_NOEC(__idt_irq13, IRQ_OFFSET + 13)
+TRAPHANDLER_NOEC(__idt_irq14, IRQ_OFFSET + IRQ_IDE)
+TRAPHANDLER_NOEC(__idt_irq19, IRQ_OFFSET + IRQ_ERROR)
+
+// Hardware IRQ numbers. We receive these as (IRQ_OFFSET+IRQ_WHATEVER)
+#define IRQ_TIMER 0
+#define IRQ_KBD 1
+#define IRQ_SERIAL 4
+#define IRQ_SPURIOUS 7
+#define IRQ_IDE 14
+#define IRQ_ERROR 19
+
/*
* Lab 3: Your code here for _alltraps
*/
+_alltraps:
+ pushl %ds //build trapframe
+ pushl %es
+ pushal
+ movw $GD_KD, %ax //switch to kernel data segment
+ movw %ax, %ds
+ movw %ax, %es
+ pushl %esp //call trap()
+ call trap

0 comments on commit c474a75

Please sign in to comment.
Something went wrong with that request. Please try again.