Skip to content

Commit

Permalink
finish exercise1~6 of lab1
Browse files Browse the repository at this point in the history
  • Loading branch information
euxcet committed Mar 16, 2019
1 parent 2669aa1 commit 20601e4
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ a.out
chytesting
disk0
*.orig
.DS_Store
8 changes: 7 additions & 1 deletion labcodes/lab1/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ TARGETS: $(TARGETS)

.DEFAULT_GOAL := TARGETS

.PHONY: qemu qemu-nox debug debug-nox
.PHONY: qemu qemu-nox debug debug-nox debug-lab1
qemu-mon: $(UCOREIMG)
$(V)$(QEMU) -no-reboot -monitor stdio -hda $< -serial null
qemu: $(UCOREIMG)
Expand All @@ -226,6 +226,12 @@ debug-nox: $(UCOREIMG)
$(V)sleep 2
$(V)$(TERMINAL) -e "gdb -q -x tools/gdbinit"

debug-lab1: $(UCOREIMG)
$(V)$(TERMINAL) -e "$(QEMU) -S -s -d in_asm -D $(BINDIR)/bios.log -monitor stdio -hda $< -serial null"
$(V)sleep 2
$(V)$(TERMINAL) -e "gdb -tui -q -x tools/gdbinit_lab1"


.PHONY: grade touch

GRADE_GDB_IN := .gdb.in
Expand Down
18 changes: 16 additions & 2 deletions labcodes/lab1/kern/debug/kdebug.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,6 @@ read_eip(void) {
* Note that, the length of ebp-chain is limited. In boot/bootasm.S, before jumping
* to the kernel entry, the value of ebp has been set to zero, that's the boundary.
* */
void
print_stackframe(void) {
/* LAB1 YOUR CODE : STEP 1 */
/* (1) call read_ebp() to get the value of ebp. the type is (uint32_t);
* (2) call read_eip() to get the value of eip. the type is (uint32_t);
Expand All @@ -302,5 +300,21 @@ print_stackframe(void) {
* NOTICE: the calling funciton's return addr eip = ss:[ebp+4]
* the calling funciton's ebp = ss:[ebp]
*/
void
print_stackframe(void) {
uint32_t ebp = read_ebp();
uint32_t eip = read_eip();
int depth;
for(depth = 0; depth < STACKFRAME_DEPTH; depth++) {
if (ebp == 0) break;
cprintf("ebp:0x%08x eip:0x%08x args:", ebp, eip);
int i;
for(i = 0; i < 4; i++) {
cprintf("0x%08x%c", *((uint32_t*)ebp + 2 + i), i < 3 ? ' ' : '\n');
}
print_debuginfo(eip - 1);
eip = *((uint32_t*)ebp + 1);
ebp = *(uint32_t*)ebp;
}
}

3 changes: 1 addition & 2 deletions labcodes/lab1/kern/init/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ kern_init(void) {

//LAB1: CAHLLENGE 1 If you try to do it, uncomment lab1_switch_test()
// user/kernel mode switch test
//lab1_switch_test();
lab1_switch_test();

/* do nothing */
while (1);
Expand Down Expand Up @@ -101,4 +101,3 @@ lab1_switch_test(void) {
lab1_switch_to_kernel();
lab1_print_cur_status();
}

15 changes: 13 additions & 2 deletions labcodes/lab1/kern/trap/trap.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ static struct pseudodesc idt_pd = {
};

/* idt_init - initialize IDT to each of the entry points in kern/trap/vectors.S */
void
idt_init(void) {
/* LAB1 YOUR CODE : STEP 2 */
/* (1) Where are the entry addrs of each Interrupt Service Routine (ISR)?
* All ISR's entry addrs are stored in __vectors. where is uintptr_t __vectors[] ?
Expand All @@ -46,6 +44,15 @@ idt_init(void) {
* You don't know the meaning of this instruction? just google it! and check the libs/x86.h to know more.
* Notice: the argument of lidt is idt_pd. try to find it!
*/
void
idt_init(void) {
extern uintptr_t __vectors[];
int i;
for(i = 0; i < 256; i++) {
SETGATE(idt[i], 0, GD_KTEXT, __vectors[i], DPL_KERNEL);
}
SETGATE(idt[T_SWITCH_TOK], 0, GD_KTEXT, __vectors[T_SWITCH_TOK], DPL_USER);
lidt(&idt_pd);
}

static const char *
Expand Down Expand Up @@ -147,6 +154,10 @@ trap_dispatch(struct trapframe *tf) {
* (2) Every TICK_NUM cycle, you can print some info using a funciton, such as print_ticks().
* (3) Too Simple? Yes, I think so!
*/
ticks++;
if (ticks % TICK_NUM == 0) {
print_ticks();
}
break;
case IRQ_OFFSET + IRQ_COM1:
c = cons_getc();
Expand Down
5 changes: 4 additions & 1 deletion labcodes/lab1/tools/gdbinit
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
define hook-stop
x/i $pc
end
file bin/kernel
target remote :1234
break kern_init
continue
continue
3 changes: 3 additions & 0 deletions labcodes/lab1/tools/gdbinit_lab1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
file bin/kernel
target remote :1234
set architecture i8086

0 comments on commit 20601e4

Please sign in to comment.