Skip to content

Commit c696b93

Browse files
Dave P Martinwildea01
Dave P Martin
authored andcommitted
arm64/debug: Simplify BRK insn opcode declarations
The way the KGDB_DYN_BRK_INS_BYTEx macros are declared is more complex than it needs to be. Also, the macros are only used in one place, which is arch-specific anyway. This patch refactors the macros to simplify them, and exposes an argument so that we can have a single macro instead of 4. As a side effect, this patch also fixes some anomalous spellings of "KGDB". These changes alter the compile types of some integer constants that are harmless but trigger truncation warnings in gcc when assigning to 32-bit variables. This patch adds an explicit cast for the affected cases. Signed-off-by: Dave Martin <[email protected]> Signed-off-by: Will Deacon <[email protected]>
1 parent 72d033e commit c696b93

File tree

2 files changed

+10
-25
lines changed

2 files changed

+10
-25
lines changed

arch/arm64/include/asm/debug-monitors.h

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -66,25 +66,10 @@
6666
*/
6767
#define AARCH64_BREAK_FAULT (AARCH64_BREAK_MON | (FAULT_BRK_IMM << 5))
6868

69-
/*
70-
* Extract byte from BRK instruction
71-
*/
72-
#define KGDB_DYN_DBG_BRK_INS_BYTE(x) \
73-
((((AARCH64_BREAK_MON) & 0xffe0001f) >> (x * 8)) & 0xff)
74-
75-
/*
76-
* Extract byte from BRK #imm16
77-
*/
78-
#define KGBD_DYN_DBG_BRK_IMM_BYTE(x) \
79-
(((((KGDB_DYN_DBG_BRK_IMM) & 0xffff) << 5) >> (x * 8)) & 0xff)
80-
81-
#define KGDB_DYN_DBG_BRK_BYTE(x) \
82-
(KGDB_DYN_DBG_BRK_INS_BYTE(x) | KGBD_DYN_DBG_BRK_IMM_BYTE(x))
83-
84-
#define KGDB_DYN_BRK_INS_BYTE0 KGDB_DYN_DBG_BRK_BYTE(0)
85-
#define KGDB_DYN_BRK_INS_BYTE1 KGDB_DYN_DBG_BRK_BYTE(1)
86-
#define KGDB_DYN_BRK_INS_BYTE2 KGDB_DYN_DBG_BRK_BYTE(2)
87-
#define KGDB_DYN_BRK_INS_BYTE3 KGDB_DYN_DBG_BRK_BYTE(3)
69+
#define AARCH64_BREAK_KGDB_DYN_DBG \
70+
(AARCH64_BREAK_MON | (KGDB_DYN_DBG_BRK_IMM << 5))
71+
#define KGDB_DYN_BRK_INS_BYTE(x) \
72+
((AARCH64_BREAK_KGDB_DYN_DBG >> (8 * (x))) & 0xff)
8873

8974
#define CACHE_FLUSH_IS_SAFE 1
9075

arch/arm64/kernel/kgdb.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,13 @@ static int kgdb_step_brk_fn(struct pt_regs *regs, unsigned int esr)
235235

236236
static struct break_hook kgdb_brkpt_hook = {
237237
.esr_mask = 0xffffffff,
238-
.esr_val = ESR_ELx_VAL_BRK64(KGDB_DYN_DBG_BRK_IMM),
238+
.esr_val = (u32)ESR_ELx_VAL_BRK64(KGDB_DYN_DBG_BRK_IMM),
239239
.fn = kgdb_brk_fn
240240
};
241241

242242
static struct break_hook kgdb_compiled_brkpt_hook = {
243243
.esr_mask = 0xffffffff,
244-
.esr_val = ESR_ELx_VAL_BRK64(KGDB_COMPILED_DBG_BRK_IMM),
244+
.esr_val = (u32)ESR_ELx_VAL_BRK64(KGDB_COMPILED_DBG_BRK_IMM),
245245
.fn = kgdb_compiled_brk_fn
246246
};
247247

@@ -328,9 +328,9 @@ void kgdb_arch_exit(void)
328328
*/
329329
struct kgdb_arch arch_kgdb_ops = {
330330
.gdb_bpt_instr = {
331-
KGDB_DYN_BRK_INS_BYTE0,
332-
KGDB_DYN_BRK_INS_BYTE1,
333-
KGDB_DYN_BRK_INS_BYTE2,
334-
KGDB_DYN_BRK_INS_BYTE3,
331+
KGDB_DYN_BRK_INS_BYTE(0),
332+
KGDB_DYN_BRK_INS_BYTE(1),
333+
KGDB_DYN_BRK_INS_BYTE(2),
334+
KGDB_DYN_BRK_INS_BYTE(3),
335335
}
336336
};

0 commit comments

Comments
 (0)