div.c
on xv6Makefile
: change -O2
to -O0
; add _div
to UPROGS
pid 4 div: trap 0 err 0 on cpu 0 eip 0x62 addr 0x0--kill proc
trap()
?struct trapframe
from?
alltraps
in trapasm.S
vector0
, …, vector255
in vectors.S
trap.c
for setting up the idt
#include "types.h"
#include "user.h"
int
main(int argc, char **argv)
{
int x, y, z;
if (argc < 3){
printf(2, "usage: div x y\n");
exit();
}
x = atoi(argv[1]);
y = atoi(argv[2]);
z = x / y;
printf(1, "%d / %d = %d\n", x, y, z);
exit();
}
traps.h
%idtr
register: base address of IDTcs:offset
: entry pointtype
%eflags
%eflags
trap.c
: tvinit()
- SETGATE
, idtinit()
- lidt
vectors.S
b idtinit
p/x idt[0]
source gdbutil
& printdesc idt[0]
vm.c
: switchuvm()
- ss0
and esp0
div.asm
and find the idivl
instruction (e.g., at 0x62
)idivl
(e.g., b *0x62
)info registers
: esp. cs
& esp
si
x/6x $esp
trap()
: who set tf->trapno
case T_DIVIDE: return;
and single-step until iret
idivl