Home | History | Annotate | Line # | Download | only in include
dbregs.h revision 1.2.4.1
      1  1.2.4.1  bouyer /*	$NetBSD: dbregs.h,v 1.2.4.1 2017/04/21 16:53:39 bouyer Exp $	*/
      2      1.1   kamil 
      3      1.1   kamil /*-
      4      1.1   kamil  * Copyright (c) 2016 The NetBSD Foundation, Inc.
      5      1.1   kamil  * All rights reserved.
      6      1.1   kamil  *
      7      1.1   kamil  * Redistribution and use in source and binary forms, with or without
      8      1.1   kamil  * modification, are permitted provided that the following conditions
      9      1.1   kamil  * are met:
     10      1.1   kamil  * 1. Redistributions of source code must retain the above copyright
     11      1.1   kamil  *    notice, this list of conditions and the following disclaimer.
     12      1.1   kamil  * 2. Redistributions in binary form must reproduce the above copyright
     13      1.1   kamil  *    notice, this list of conditions and the following disclaimer in the
     14      1.1   kamil  *    documentation and/or other materials provided with the distribution.
     15      1.1   kamil  *
     16      1.1   kamil  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17      1.1   kamil  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18      1.1   kamil  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19      1.1   kamil  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20      1.1   kamil  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21      1.1   kamil  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22      1.1   kamil  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23      1.1   kamil  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24      1.1   kamil  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25      1.1   kamil  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26      1.1   kamil  * POSSIBILITY OF SUCH DAMAGE.
     27      1.1   kamil  */
     28      1.1   kamil 
     29      1.1   kamil 
     30      1.1   kamil #ifndef	_X86_DBREGS_H_
     31      1.1   kamil #define	_X86_DBREGS_H_
     32      1.1   kamil 
     33      1.2   kamil #include <sys/param.h>
     34      1.2   kamil #include <sys/types.h>
     35  1.2.4.1  bouyer #include <machine/reg.h>
     36      1.1   kamil 
     37      1.2   kamil /*
     38      1.2   kamil  * CPU Debug Status Register (DR6)
     39      1.2   kamil  *
     40      1.2   kamil  * Reserved bits: 4-12 and on x86_64 32-64
     41      1.2   kamil  */
     42  1.2.4.1  bouyer #define X86_DR6_DR0_BREAKPOINT_CONDITION_DETECTED	__BIT(0)
     43  1.2.4.1  bouyer #define X86_DR6_DR1_BREAKPOINT_CONDITION_DETECTED	__BIT(1)
     44  1.2.4.1  bouyer #define X86_DR6_DR2_BREAKPOINT_CONDITION_DETECTED	__BIT(2)
     45  1.2.4.1  bouyer #define X86_DR6_DR3_BREAKPOINT_CONDITION_DETECTED	__BIT(3)
     46  1.2.4.1  bouyer #define X86_DR6_DEBUG_REGISTER_ACCESS_DETECTED		__BIT(13)
     47  1.2.4.1  bouyer #define X86_DR6_SINGLE_STEP				__BIT(14)
     48  1.2.4.1  bouyer #define X86_DR6_TASK_SWITCH				__BIT(15)
     49      1.2   kamil 
     50      1.2   kamil /*
     51      1.2   kamil  * CPU Debug Control Register (DR7)
     52      1.2   kamil  *
     53      1.2   kamil  * LOCAL_EXACT_BREAKPOINT and GLOBAL_EXACT_BREAKPOINT are no longer used since
     54      1.2   kamil  * the P6 processor family - portable code should set these bits
     55      1.2   kamil  * unconditionally in oder to get exact breakpoints
     56      1.2   kamil  *
     57      1.2   kamil  * Reserved bits: 10, 12, 14-15 and on x86_64 32-64
     58      1.2   kamil  */
     59  1.2.4.1  bouyer #define X86_DR7_LOCAL_DR0_BREAKPOINT		__BIT(0)
     60  1.2.4.1  bouyer #define X86_DR7_GLOBAL_DR0_BREAKPOINT		__BIT(1)
     61  1.2.4.1  bouyer #define X86_DR7_LOCAL_DR1_BREAKPOINT		__BIT(2)
     62  1.2.4.1  bouyer #define X86_DR7_GLOBAL_DR1_BREAKPOINT		__BIT(3)
     63  1.2.4.1  bouyer #define X86_DR7_LOCAL_DR2_BREAKPOINT		__BIT(4)
     64  1.2.4.1  bouyer #define X86_DR7_GLOBAL_DR2_BREAKPOINT		__BIT(5)
     65  1.2.4.1  bouyer #define X86_DR7_LOCAL_DR3_BREAKPOINT		__BIT(6)
     66  1.2.4.1  bouyer #define X86_DR7_GLOBAL_DR3_BREAKPOINT		__BIT(7)
     67  1.2.4.1  bouyer #define X86_DR7_LOCAL_EXACT_BREAKPOINT		__BIT(8)
     68  1.2.4.1  bouyer #define X86_DR7_GLOBAL_EXACT_BREAKPOINT		__BIT(9)
     69  1.2.4.1  bouyer #define X86_DR7_RESTRICTED_TRANSACTIONAL_MEMORY	__BIT(11)
     70  1.2.4.1  bouyer #define X86_DR7_GENERAL_DETECT_ENABLE		__BIT(13)
     71  1.2.4.1  bouyer 
     72  1.2.4.1  bouyer #define X86_DR7_DR0_CONDITION_MASK		__BITS(16, 17)
     73  1.2.4.1  bouyer #define X86_DR7_DR0_LENGTH_MASK			__BITS(18, 19)
     74  1.2.4.1  bouyer #define X86_DR7_DR1_CONDITION_MASK		__BITS(20, 21)
     75  1.2.4.1  bouyer #define X86_DR7_DR1_LENGTH_MASK			__BITS(22, 23)
     76  1.2.4.1  bouyer #define X86_DR7_DR2_CONDITION_MASK		__BITS(24, 25)
     77  1.2.4.1  bouyer #define X86_DR7_DR2_LENGTH_MASK			__BITS(26, 27)
     78  1.2.4.1  bouyer #define X86_DR7_DR3_CONDITION_MASK		__BITS(28, 29)
     79  1.2.4.1  bouyer #define X86_DR7_DR3_LENGTH_MASK			__BITS(30, 31)
     80      1.2   kamil 
     81      1.2   kamil /*
     82  1.2.4.1  bouyer  * X86_DR7_CONDITION_IO_READWRITE is currently unused
     83      1.2   kamil  * it requires DE (debug extension) flag in control register CR4 set
     84      1.2   kamil  * not all CPUs support it
     85      1.2   kamil  */
     86  1.2.4.1  bouyer enum x86_dr7_condition {
     87  1.2.4.1  bouyer 	X86_DR7_CONDITION_EXECUTION		= 0x0,
     88  1.2.4.1  bouyer 	X86_DR7_CONDITION_DATA_WRITE		= 0x1,
     89  1.2.4.1  bouyer 	X86_DR7_CONDITION_IO_READWRITE		= 0x2,
     90  1.2.4.1  bouyer 	X86_DR7_CONDITION_DATA_READWRITE	= 0x3
     91      1.2   kamil };
     92      1.2   kamil 
     93      1.2   kamil /*
     94      1.2   kamil  * 0x2 is currently unimplemented - it reflects 8 bytes on modern CPUs
     95      1.2   kamil  */
     96  1.2.4.1  bouyer enum x86_dr7_length {
     97  1.2.4.1  bouyer 	X86_DR7_LENGTH_BYTE		= 0x0,
     98  1.2.4.1  bouyer 	X86_DR7_LENGTH_TWOBYTES		= 0x1,
     99      1.2   kamil 	/* 0x2 undefined */
    100  1.2.4.1  bouyer 	X86_DR7_LENGTH_FOURBYTES	= 0x3
    101      1.2   kamil };
    102      1.2   kamil 
    103  1.2.4.1  bouyer /*
    104  1.2.4.1  bouyer  * The number of available watchpoint/breakpoint registers available since
    105  1.2.4.1  bouyer  * Intel 80386. New CPUs (x86_64) ship with up to 16 Debug Registers but they
    106  1.2.4.1  bouyer  * still offer the same number of watchpoints/breakpoints.
    107  1.2.4.1  bouyer  */
    108  1.2.4.1  bouyer #define X86_DBREGS	4
    109  1.2.4.1  bouyer 
    110  1.2.4.1  bouyer /*
    111  1.2.4.1  bouyer  * Store the initial Debug Register state of CPU
    112  1.2.4.1  bouyer  * This copy will be used to initialize new debug register state
    113  1.2.4.1  bouyer  */
    114  1.2.4.1  bouyer void x86_dbregs_setup_initdbstate(void);
    115      1.2   kamil 
    116      1.2   kamil /*
    117  1.2.4.1  bouyer  * Reset CPU Debug Registers - to be used after returning to user context
    118      1.2   kamil  */
    119  1.2.4.1  bouyer void x86_dbregs_clear(struct lwp *l);
    120      1.2   kamil 
    121      1.2   kamil /*
    122  1.2.4.1  bouyer  * Retrieve Debug Registers from LWP's PCB and save in regs
    123  1.2.4.1  bouyer  * In case of empty register set, initialize it
    124      1.2   kamil  */
    125  1.2.4.1  bouyer void x86_dbregs_read(struct lwp *l, struct dbreg *regs);
    126      1.2   kamil 
    127      1.2   kamil /*
    128      1.2   kamil  * Set CPU Debug Registers - to be used before entering user-land context
    129      1.2   kamil  */
    130  1.2.4.1  bouyer void x86_dbregs_set(struct lwp *l);
    131      1.1   kamil 
    132      1.2   kamil /*
    133  1.2.4.1  bouyer  * Store DR6 in LWP - to be used in trap function
    134      1.2   kamil  */
    135  1.2.4.1  bouyer void x86_dbregs_store_dr6(struct lwp *l);
    136      1.2   kamil 
    137      1.2   kamil /*
    138      1.2   kamil  * Check if trap is triggered from user-land if so return nonzero value
    139      1.2   kamil  */
    140  1.2.4.1  bouyer int x86_dbregs_user_trap(void);
    141      1.1   kamil 
    142  1.2.4.1  bouyer /*
    143  1.2.4.1  bouyer  * Check if trap is triggered from user-land if so return nonzero value
    144  1.2.4.1  bouyer  */
    145  1.2.4.1  bouyer int x86_dbregs_validate(const struct dbreg *regs);
    146  1.2.4.1  bouyer 
    147  1.2.4.1  bouyer /*
    148  1.2.4.1  bouyer  * Write new Debug Registers from regs into LWP's PCB
    149  1.2.4.1  bouyer  */
    150  1.2.4.1  bouyer void x86_dbregs_write(struct lwp *l, const struct dbreg *regs);
    151      1.1   kamil 
    152      1.2   kamil #endif /* !_X86_DBREGS_H_ */
    153