tools/testing/selftests/powerpc/include/instructions.h

Source file repositories/reference/linux-study-clean/tools/testing/selftests/powerpc/include/instructions.h

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/powerpc/include/instructions.h
Extension
.h
Size
4759 bytes
Lines
147
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

#ifndef _SELFTESTS_POWERPC_INSTRUCTIONS_H
#define _SELFTESTS_POWERPC_INSTRUCTIONS_H

#include <stdio.h>
#include <stdlib.h>

/* This defines the "copy" instruction from Power ISA 3.0 Book II, section 4.4. */
#define __COPY(RA, RB, L) \
	(0x7c00060c | (RA) << (31-15) | (RB) << (31-20) | (L) << (31-10))
#define COPY(RA, RB, L) \
	.long __COPY((RA), (RB), (L))

static inline void copy(void *i)
{
	asm volatile(str(COPY(0, %0, 0))";"
			:
			: "b" (i)
			: "memory"
		    );
}

static inline void copy_first(void *i)
{
	asm volatile(str(COPY(0, %0, 1))";"
			:
			: "b" (i)
			: "memory"
		    );
}

/* This defines the "paste" instruction from Power ISA 3.0 Book II, section 4.4. */
#define __PASTE(RA, RB, L, RC) \
	(0x7c00070c | (RA) << (31-15) | (RB) << (31-20) | (L) << (31-10) | (RC) << (31-31))
#define PASTE(RA, RB, L, RC) \
	.long __PASTE((RA), (RB), (L), (RC))

static inline int paste(void *i)
{
	int cr;

	asm volatile(str(PASTE(0, %1, 0, 0))";"
			"mfcr %0;"
			: "=r" (cr)
			: "b" (i)
			: "memory"
		    );
	return cr;
}

static inline int paste_last(void *i)
{
	int cr;

	asm volatile(str(PASTE(0, %1, 1, 1))";"
			"mfcr %0;"
			: "=r" (cr)
			: "b" (i)
			: "memory"
		    );
	return cr;
}

#define PPC_INST_COPY                  __COPY(0, 0, 0)
#define PPC_INST_COPY_FIRST            __COPY(0, 0, 1)
#define PPC_INST_PASTE                 __PASTE(0, 0, 0, 0)
#define PPC_INST_PASTE_LAST            __PASTE(0, 0, 1, 1)

/* This defines the prefixed load/store instructions */
#ifdef __ASSEMBLER__
#  define stringify_in_c(...)	__VA_ARGS__
#else
#  define __stringify_in_c(...)	#__VA_ARGS__
#  define stringify_in_c(...)	__stringify_in_c(__VA_ARGS__) " "
#endif

#define __PPC_RA(a)	(((a) & 0x1f) << 16)
#define __PPC_RS(s)	(((s) & 0x1f) << 21)
#define __PPC_RT(t)	__PPC_RS(t)
#define __PPC_PREFIX_R(r)	(((r) & 0x1) << 20)

#define PPC_PREFIX_MLS			0x06000000
#define PPC_PREFIX_8LS			0x04000000

#define PPC_INST_LBZ			0x88000000
#define PPC_INST_LHZ			0xa0000000
#define PPC_INST_LHA			0xa8000000
#define PPC_INST_LWZ			0x80000000
#define PPC_INST_STB			0x98000000
#define PPC_INST_STH			0xb0000000
#define PPC_INST_STW			0x90000000

Annotation

Implementation Notes