Home | History | Annotate | Line # | Download | only in include
dbregs.h revision 1.4.14.3
      1  1.4.14.3  pgoyette /*	$NetBSD: dbregs.h,v 1.4.14.3 2019/01/18 08:50:24 pgoyette Exp $	*/
      2       1.1     kamil 
      3  1.4.14.1  pgoyette /*
      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 #ifndef	_X86_DBREGS_H_
     30       1.1     kamil #define	_X86_DBREGS_H_
     31       1.1     kamil 
     32       1.2     kamil #include <sys/param.h>
     33       1.2     kamil #include <sys/types.h>
     34       1.4     kamil #include <machine/reg.h>
     35       1.1     kamil 
     36       1.2     kamil /*
     37       1.2     kamil  * CPU Debug Status Register (DR6)
     38       1.2     kamil  *
     39       1.2     kamil  * Reserved bits: 4-12 and on x86_64 32-64
     40       1.2     kamil  */
     41       1.4     kamil #define X86_DR6_DR0_BREAKPOINT_CONDITION_DETECTED	__BIT(0)
     42       1.4     kamil #define X86_DR6_DR1_BREAKPOINT_CONDITION_DETECTED	__BIT(1)
     43       1.4     kamil #define X86_DR6_DR2_BREAKPOINT_CONDITION_DETECTED	__BIT(2)
     44       1.4     kamil #define X86_DR6_DR3_BREAKPOINT_CONDITION_DETECTED	__BIT(3)
     45       1.4     kamil #define X86_DR6_DEBUG_REGISTER_ACCESS_DETECTED		__BIT(13)
     46       1.4     kamil #define X86_DR6_SINGLE_STEP				__BIT(14)
     47       1.4     kamil #define X86_DR6_TASK_SWITCH				__BIT(15)
     48  1.4.14.3  pgoyette #define X86_DR6_MBZ					__BITS(32, 63)
     49       1.2     kamil 
     50       1.2     kamil /*
     51       1.2     kamil  * CPU Debug Control Register (DR7)
     52       1.2     kamil  *
     53  1.4.14.1  pgoyette  * LOCAL_EXACT_BREAKPOINT and GLOBAL_EXACT_BREAKPOINT are no longer used
     54  1.4.14.1  pgoyette  * since the P6 processor family - portable code should set these bits
     55  1.4.14.1  pgoyette  * unconditionally in order to get exact breakpoints.
     56       1.2     kamil  *
     57  1.4.14.1  pgoyette  * Reserved bits: 10, 12, 14-15 and on x86_64 32-64.
     58       1.2     kamil  */
     59       1.4     kamil #define X86_DR7_LOCAL_DR0_BREAKPOINT		__BIT(0)
     60       1.4     kamil #define X86_DR7_GLOBAL_DR0_BREAKPOINT		__BIT(1)
     61       1.4     kamil #define X86_DR7_LOCAL_DR1_BREAKPOINT		__BIT(2)
     62       1.4     kamil #define X86_DR7_GLOBAL_DR1_BREAKPOINT		__BIT(3)
     63       1.4     kamil #define X86_DR7_LOCAL_DR2_BREAKPOINT		__BIT(4)
     64       1.4     kamil #define X86_DR7_GLOBAL_DR2_BREAKPOINT		__BIT(5)
     65       1.4     kamil #define X86_DR7_LOCAL_DR3_BREAKPOINT		__BIT(6)
     66       1.4     kamil #define X86_DR7_GLOBAL_DR3_BREAKPOINT		__BIT(7)
     67       1.4     kamil #define X86_DR7_LOCAL_EXACT_BREAKPOINT		__BIT(8)
     68       1.4     kamil #define X86_DR7_GLOBAL_EXACT_BREAKPOINT		__BIT(9)
     69       1.4     kamil #define X86_DR7_RESTRICTED_TRANSACTIONAL_MEMORY	__BIT(11)
     70       1.4     kamil #define X86_DR7_GENERAL_DETECT_ENABLE		__BIT(13)
     71       1.4     kamil #define X86_DR7_DR0_CONDITION_MASK		__BITS(16, 17)
     72       1.4     kamil #define X86_DR7_DR0_LENGTH_MASK			__BITS(18, 19)
     73       1.4     kamil #define X86_DR7_DR1_CONDITION_MASK		__BITS(20, 21)
     74       1.4     kamil #define X86_DR7_DR1_LENGTH_MASK			__BITS(22, 23)
     75       1.4     kamil #define X86_DR7_DR2_CONDITION_MASK		__BITS(24, 25)
     76       1.4     kamil #define X86_DR7_DR2_LENGTH_MASK			__BITS(26, 27)
     77       1.4     kamil #define X86_DR7_DR3_CONDITION_MASK		__BITS(28, 29)
     78       1.4     kamil #define X86_DR7_DR3_LENGTH_MASK			__BITS(30, 31)
     79  1.4.14.3  pgoyette #define X86_DR7_MBZ				__BITS(32, 63)
     80       1.2     kamil 
     81       1.2     kamil /*
     82  1.4.14.1  pgoyette  * X86_DR7_CONDITION_IO_READWRITE is currently unused. It requires DE
     83  1.4.14.1  pgoyette  * (debug extension) flag in control register CR4 set, and not all CPUs
     84  1.4.14.1  pgoyette  * support it.
     85       1.2     kamil  */
     86       1.4     kamil enum x86_dr7_condition {
     87       1.4     kamil 	X86_DR7_CONDITION_EXECUTION		= 0x0,
     88       1.4     kamil 	X86_DR7_CONDITION_DATA_WRITE		= 0x1,
     89       1.4     kamil 	X86_DR7_CONDITION_IO_READWRITE		= 0x2,
     90       1.4     kamil 	X86_DR7_CONDITION_DATA_READWRITE	= 0x3
     91       1.2     kamil };
     92       1.2     kamil 
     93       1.2     kamil /*
     94  1.4.14.1  pgoyette  * 0x2 is currently unimplemented - it reflects 8 bytes on modern CPUs.
     95       1.2     kamil  */
     96       1.4     kamil enum x86_dr7_length {
     97       1.4     kamil 	X86_DR7_LENGTH_BYTE		= 0x0,
     98       1.4     kamil 	X86_DR7_LENGTH_TWOBYTES		= 0x1,
     99       1.2     kamil 	/* 0x2 undefined */
    100       1.4     kamil 	X86_DR7_LENGTH_FOURBYTES	= 0x3
    101       1.2     kamil };
    102       1.2     kamil 
    103       1.3     kamil /*
    104       1.4     kamil  * The number of available watchpoint/breakpoint registers available since
    105       1.4     kamil  * Intel 80386. New CPUs (x86_64) ship with up to 16 Debug Registers but they
    106       1.4     kamil  * still offer the same number of watchpoints/breakpoints.
    107       1.3     kamil  */
    108       1.4     kamil #define X86_DBREGS	4
    109       1.3     kamil 
    110  1.4.14.1  pgoyette void x86_dbregs_init(void);
    111  1.4.14.1  pgoyette void x86_dbregs_clear(struct lwp *);
    112  1.4.14.1  pgoyette void x86_dbregs_abandon(struct lwp *);
    113  1.4.14.1  pgoyette void x86_dbregs_read(struct lwp *, struct dbreg *);
    114  1.4.14.2  pgoyette 
    115  1.4.14.2  pgoyette void x86_dbregs_save(struct lwp *);
    116  1.4.14.2  pgoyette void x86_dbregs_restore(struct lwp *);
    117  1.4.14.2  pgoyette 
    118  1.4.14.1  pgoyette void x86_dbregs_store_dr6(struct lwp *);
    119       1.4     kamil int x86_dbregs_user_trap(void);
    120  1.4.14.1  pgoyette int x86_dbregs_validate(const struct dbreg *);
    121  1.4.14.1  pgoyette void x86_dbregs_write(struct lwp *, const struct dbreg *);
    122  1.4.14.1  pgoyette void x86_dbregs_switch(struct lwp *, struct lwp *);
    123       1.1     kamil 
    124       1.2     kamil #endif /* !_X86_DBREGS_H_ */
    125