2018-09-25 09:22:51 -07:00
|
|
|
/* See COPYRIGHT for copyright information. */
|
|
|
|
|
|
|
|
#include <inc/mmu.h>
|
|
|
|
#include <inc/memlayout.h>
|
|
|
|
#include <inc/trap.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
###################################################################
|
|
|
|
# exceptions/interrupts
|
|
|
|
###################################################################
|
|
|
|
|
|
|
|
/* TRAPHANDLER defines a globally-visible function for handling a trap.
|
|
|
|
* It pushes a trap number onto the stack, then jumps to _alltraps.
|
|
|
|
* Use TRAPHANDLER for traps where the CPU automatically pushes an error code.
|
|
|
|
*
|
|
|
|
* You shouldn't call a TRAPHANDLER function from C, but you may
|
|
|
|
* need to _declare_ one in C (for instance, to get a function pointer
|
|
|
|
* during IDT setup). You can declare the function with
|
|
|
|
* 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
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
|
|
|
|
.text
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Lab 3: Your code here for generating entry points for the different traps.
|
|
|
|
*/
|
2019-04-23 01:44:23 -07:00
|
|
|
TRAPHANDLER_NOEC(t_divide, T_DIVIDE);
|
|
|
|
TRAPHANDLER_NOEC(t_debug, T_DEBUG);
|
|
|
|
TRAPHANDLER_NOEC(t_nmi, T_NMI);
|
|
|
|
TRAPHANDLER_NOEC(t_brkpt, T_BRKPT);
|
|
|
|
TRAPHANDLER_NOEC(t_oflow, T_OFLOW);
|
|
|
|
TRAPHANDLER_NOEC(t_bound, T_OFLOW);
|
|
|
|
TRAPHANDLER_NOEC(t_illop, T_OFLOW);
|
|
|
|
TRAPHANDLER_NOEC(t_device, T_OFLOW);
|
|
|
|
TRAPHANDLER(t_dblflt, T_OFLOW);
|
|
|
|
TRAPHANDLER(t_tss, T_TSS);
|
|
|
|
TRAPHANDLER(t_segnp, T_SEGNP);
|
|
|
|
TRAPHANDLER(t_stack, T_STACK);
|
|
|
|
TRAPHANDLER(t_gpflt, T_GPFLT);
|
|
|
|
TRAPHANDLER(t_pgflt, T_PGFLT);
|
|
|
|
TRAPHANDLER_NOEC(t_fperr, T_FPERR);
|
|
|
|
TRAPHANDLER(t_align, T_ALIGN);
|
|
|
|
TRAPHANDLER_NOEC(t_mchk, T_MCHK);
|
|
|
|
TRAPHANDLER_NOEC(t_simderr, T_SIMDERR);
|
|
|
|
TRAPHANDLER_NOEC(t_syscall, T_SYSCALL);
|
|
|
|
TRAPHANDLER(t_default, T_DEFAULT);
|
2018-09-25 09:22:51 -07:00
|
|
|
|
2019-04-01 21:22:40 -07:00
|
|
|
// HINT 1 : TRAPHANDLER_NOEC(t_divide, T_DIVIDE);
|
|
|
|
// Do something like this if there is no error code for the trap
|
|
|
|
// HINT 2 : TRAPHANDLER(t_dblflt, T_DBLFLT);
|
|
|
|
// Do something like this if the trap includes an error code..
|
|
|
|
// HINT 3 : READ Intel's manual to check if the trap includes an error code
|
|
|
|
// or not...
|
2018-09-25 09:22:51 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Lab 3: Your code here for _alltraps
|
|
|
|
*/
|
|
|
|
|
2019-04-23 01:44:23 -07:00
|
|
|
.globl _alltraps
|
|
|
|
_alltraps:
|
|
|
|
sub $0x2, %esp
|
2019-04-23 02:06:11 -07:00
|
|
|
mov %ds, %eax
|
|
|
|
push %ax
|
2019-04-23 01:44:23 -07:00
|
|
|
sub $0x2, %esp
|
2019-04-23 02:06:11 -07:00
|
|
|
mov %es, %eax
|
|
|
|
push %ax
|
2019-04-23 01:44:23 -07:00
|
|
|
pushal
|
|
|
|
mov $(GD_KD), %eax
|
|
|
|
movl %eax, %ds
|
|
|
|
movl %eax, %es
|
|
|
|
pushl %esp
|
|
|
|
call trap
|