arch/csky/kernel/probes/simulate-insn.c

Source file repositories/reference/linux-study-clean/arch/csky/kernel/probes/simulate-insn.c

File Facts

System
Linux kernel
Corpus path
arch/csky/kernel/probes/simulate-insn.c
Extension
.c
Size
8148 bytes
Lines
391
Domain
Architecture Layer
Bucket
arch/csky
Inferred role
Architecture Layer: implementation source
Status
source implementation candidate

Why This File Exists

CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: GPL-2.0+

#include <linux/bitops.h>
#include <linux/kernel.h>
#include <linux/kprobes.h>

#include "decode-insn.h"
#include "simulate-insn.h"

static inline bool csky_insn_reg_get_val(struct pt_regs *regs,
					 unsigned long index,
					 unsigned long *ptr)
{
	if (index < 14)
		*ptr = *(&regs->a0 + index);

	if (index > 15 && index < 31)
		*ptr = *(&regs->exregs[0] + index - 16);

	switch (index) {
	case 14:
		*ptr = regs->usp;
		break;
	case 15:
		*ptr = regs->lr;
		break;
	case 31:
		*ptr = regs->tls;
		break;
	default:
		goto fail;
	}

	return true;
fail:
	return false;
}

static inline bool csky_insn_reg_set_val(struct pt_regs *regs,
					 unsigned long index,
					 unsigned long val)
{
	if (index < 14)
		*(&regs->a0 + index) = val;

	if (index > 15 && index < 31)
		*(&regs->exregs[0] + index - 16) = val;

	switch (index) {
	case 14:
		regs->usp = val;
		break;
	case 15:
		regs->lr = val;
		break;
	case 31:
		regs->tls = val;
		break;
	default:
		goto fail;
	}

	return true;
fail:
	return false;
}

void __kprobes
simulate_br16(u32 opcode, long addr, struct pt_regs *regs)
{
	instruction_pointer_set(regs,
		addr + sign_extend32((opcode & 0x3ff) << 1, 9));
}

void __kprobes
simulate_br32(u32 opcode, long addr, struct pt_regs *regs)
{
	instruction_pointer_set(regs,
		addr + sign_extend32((opcode & 0xffff0000) >> 15, 15));
}

void __kprobes
simulate_bt16(u32 opcode, long addr, struct pt_regs *regs)
{
	if (regs->sr & 1)
		instruction_pointer_set(regs,
			addr + sign_extend32((opcode & 0x3ff) << 1, 9));
	else
		instruction_pointer_set(regs, addr + 2);
}

Annotation

Implementation Notes