/*
 * Copyright (c) 2026, Chloe M.
 * Provided under the BSD-3 clause.
 *
 * Description: Trap handlers
 * Author:      Chloe M.
 */

#ifndef _MACHINE_TRAP_H_
#define _MACHINE_TRAP_H_ 1

#include <ptdef.h>
#include <machine/frame.h>

/* Trap vectors */
#define TRAP_DIVERR             0x00
#define TRAP_DEBUG_EXCEPTION    0x01
#define TRAP_NMI                0x02
#define TRAP_BREAKPOINT         0x03
#define TRAP_OVERFLOW           0x04
#define TRAP_BOUND_RANGE        0x05
#define TRAP_INVALID_OPCODE     0x06
#define TRAP_NO_COPROCESSOR     0x07
#define TRAP_DOUBLE_FAULT       0x08
#define TRAP_RESERVED           0x09
#define TRAP_INVALID_TSS        0x0A
#define TRAP_SEG_NOT_PRESENT    0x0B
#define TRAP_STACK_SEG_FAULT    0x0C
#define TRAP_GENERAL_PROTECTION 0x0D
#define TRAP_PAGE_FAULT         0x0E
#define TRAP_SYSCALL            0x2E

/* Prototypes of trap functions */
VOID TrapDivError(VOID);
VOID TrapDebugException(VOID);
VOID TrapNmi(VOID);
VOID TrapBreakPoint(VOID);
VOID TrapOverflow(VOID);
VOID TrapBoundRange(VOID);
VOID TrapInvalidOpcode(VOID);
VOID TrapNoCoprocessor(VOID);
VOID TrapDoubleFault(VOID);
VOID TrapReserved(VOID);
VOID TrapInvalidTss(VOID);
VOID TrapSegNotPresent(VOID);
VOID TrapStackSegmentFault(VOID);
VOID TrapGeneralProtection(VOID);
VOID TrapPageFault(VOID);
VOID TrapLegacySyscall(VOID);

/*
 * Used to dispatch traps that happen on the processor
 *
 * @TrapFrame: Trap frame associated with event
 */
VOID MdTrapDispatch(TRAP_FRAME *TrapFrame);

#endif  /* !_MACHINE_TRAP_H_ */
