AARCH64 常用的指令和寄存器描述

2024-05-27 15:08

本文主要是介绍AARCH64 常用的指令和寄存器描述,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

  • 当我们在写汇编时要参考什么
1. ABI// 当考虑了ABI之后,这样子写的汇编代码就可以和C代码兼容,可以相互调用
3. 语法 (指令解释中的各种概念是什么)// C1.2 Structure of the A64 assembler language// C2.1 Understanding the A64 instruction descriptions// C6.2 Alphabetical list of A64 base instructions
4. 该指令是否会影响其他的东西// C6.1 About the A64 base instructions1. PSTATE2. PC3. SP
5. 指令中的地址 寻址方式是什么// C1.3 Address generation
6. 想要用的指令在哪个类// C3 A64 Instruction Set Overview
7. 指令如何编码// C4 A64 Instruction Set Encoding
8. 是否为特权指令// C5 The A64 System Instruction Class
9. 是否为SIMD&FP指令// C7 A64 Advanced SIMD and Floating-point Instruction Descriptions
  • 基础知识

有效VA范围由以下因素决定:• 实现的虚拟地址空间的大小。 由 内存管理单元MMU 相关寄存器配置设置。TCR.T1SZTCR.T0SZARMv8-A架构下,它的低位有效位数(也就是虚拟地址空间大小),是可以配置的,最大48,最小12. 不过,为了方便页表的对齐,我们通常会设置一些特定的位数.比如48,39,30.在代码中,你可以看到有关T0SZ,T1SZ的设置,就是用来配置这个项目的. 有效位数为64-TxSZ (或者,也可以说TxSZ是用来设置高位无效位数的)
The only instructions that can read the PC are those that generate a PC relative address:• ADR and ADRP.• The Load register (literal) instruction class.• Direct branches that use an immediate offset.• The unconditional branch with link instructions, BL and BLR, that use the PC to create the return link address.Only explicit control flow instructions can modify the PC:• Conditional and unconditional branch and return instructions.• Exception generation and exception return instructions.
以 SP 作为输入A64 instructions can use the stack pointer only in a limited number of cases:• Load/Store instructions use the current stack pointer as the base address: — When stack alignment checking is enabled by system software and the base register is SP, the current stack pointer must be initially quadword aligned, That is, it must be aligned to 16 bytes. Misalignment generates an SP alignment fault. See SP alignment checking on page D1-2287 for more information. 
• Add and subtract data processing instructions in their immediate and extended register forms, use the current stack pointer as a source register or the destination register or both.• Logical data processing instructions in their immediate form use the current stack pointer as the destination register.
以 PSTATE 作为输出The A64 base instructions that use the Condition flags as an input are:• Conditional branch. The conditional branch instruction is B.cond .• Add or subtract with carry. These instruction types include instructions to perform multi-precision arithmetic and calculate checksums. The add or subtract with carry instructions are ADC , ADCS , SBC , and SBCS , or an architectural alias for these instructions.• Conditional select with increment, negate, or invert.This instruction type conditionally selects between one source register and a second, incremented, negated, inverted, or unmodified source register. The conditional select with increment, negate, or invert instructions are CSINC , CSINV , and CSNEG .These instructions also implement:— Conditional select or move. The Condition flags select one of two source registers as the destination register. Short conditional sequences can be replaced by unconditional instructions followed by a conditional select, CSEL .— Conditional set. Conditionally selects between 0 and 1, or 0 and -1. This can be used to convert the Condition flags to a Boolean value or mask in a general-purpose register, for example. These instructions include CSET and CSETM .• Conditional compare. This instruction type sets the Condition flags to the result of a comparison if the original condition is true, otherwise it sets the Condition flags to an immediate value. It permits the flattening of nested conditional expressions without using conditional branches or performing Boolean arithmetic within the general-purpose registers.The conditional compare instructions are CCMP and CCMN .以 PSTATE 作为输出The A64 base instructions that update the Condition flags as an output are:• Flag-setting data processing instructions, such as ADCS , ADDS , ANDS , BICS , RMIF , SBCS , SETF8 , SETF16 , and SUBS , and the aliases CMN , CMP , and TST .• Conditional compare instructions such as CCMN , CCMP .• The random number generation instructions MRS RNDR and MRS RNDRRS , see Effect of random number generation instructions on Condition flags on page C6-752.直接改变 PSTATEThe A64 base instructions that manipulate the Condition flags are: • The flag manipulation instruction CFINV , which inverts the value of the Carry flag.A64 Base Instruction Descriptions • If ARMv8.5-CondM is implemented, the base instructions AXFLAG and XAFLAG . These instructions convert between the Arm floating point comparison PSTATE condition flag format and an alternative format shown in Table C6-1.The flags can be directly accessed for a read/write using the NZCV, Condition Flags on page C5-400.The A64 base instructions also include conditional branch instructions that do not use the Condition flags as an input: • Compare and branch if a register is zero or nonzero, CBZ and CBNZ .• Test a single bit in a register and branch if the bit is zero or nonzero, TBZ and TBNZ .Effect of random number generation instructions on Condition flags If ARMv8.5-RNG is implemented, then: • When a valid random number is returned, the PSTATE.NZCV flags are set to 0b0000 .• If the random number hardware is not capable of returning a random number in a reasonable period of time, the PSTATE.NZCV flags are set to 0b0100 , and the random number generation instructions return the value 0.Note The definition of “reasonable period of time” is IMPLEMENTATION DEFINED . The expectation is that software might use this as an opportunity to reschedule or run a different routine, perhaps after a small number of retries have failed to return a valid value.value.
  • EL0/1常用的 A64 指令
.inst	// 伪指令 , 表示这条指令不对应任何指令,为未定义指令
.word	// 伪指令 , 在当前位置放一个word型的值add		// 三种变体1.extended register 2. immediate 3.shifted register
adrp	// base = PC[11:0]=ZERO(12); Xd = base + label;
and		// 两种变体1.immediate 2.shifted register
asr		// 两种变体1.register 2.immediate // Arithmetic Shift Right 
b
b.cc	// 属于 B.cond , cond 取自 P173
b.cs
b.eq
b.ge
b.gt
b.hi
b.le
b.ls
b.lt
b.ne
bl		// Branch with Link branches to a PC-relative offset
blr		// Branch with Link to Register calls a subroutine at an address in a register, setting register X30 to PC+4
brk		// 进入debug异常
cmn		// 加,更新PSTATE
cmp 	// 减,更新PSTATE
cneg	// Conditional Negate returns ,根据条件返回两个值中的一个或另一个的负数
csel	// Conditional Select returns
cset	// Conditional Set
eret	// 用于异常返回
ldp		// Load Pair of Registers
ldr		// Load Register
ldrb	// Load Register Byte
ldrh	// Load Register Halfword
ldrsw	// Load Register Signed Word 
lsl		// Logical Shift Left
lsr		// Logical Shift Right
mov		// Move between register and stack pointer
movk	// Move wide with keep moves an optionally-shifted 16-bit immediate value into a register, keeping other bits unchanged.
mrs		// move sytem register value to general-purpose register
msr		// move general-purpose register value to sytem register
mul		// Multiply : Rd = Rn * Rm
neg		// Negate (shifted register) negates an optionally-shifted register value, and writes the result to the destination register.
nop		// No Operation does nothing, other than advance the value of the program counter by 4. 
orr		// Bitwise OR (immediate) performs a bitwise (inclusive) OR of a register value and an immediate register value, and writes the result to the destination register.
ret		// Return from subroutine branches unconditionally to an address in a register, with a hint that this is a subroutine return.
smull	// Signed Multiply Long multiplies two 32-bit register values, and writes the result to the 64-bit destination register.
stp		// Store Pair of Registers calculates an address from a base register value and an immediate offset, and stores two 32-bit words or two 64-bit doublewords to the calculated address, from two registers. For information about memory accesses
str		// Store Register 
strb
strh
stur 	// Store Register (unscaled) calculates an address from a base register value and an immediate offset
sub		// Subtract (extended register) subtracts a sign or zero-extended register value
svc		// 进入svc异常
sxtb	// Signed Extend Byte extracts an 8-bit value from a register,
sxth
sxtw
udiv	// Unsigned Divide divides an unsigned integer register value by another unsigned integer register value
umull	// Unsigned Multiply Long multiplies two 32-bit register values, and writes the result to the 64-bit destination register.
wfi		// Wait For Interrupt is a hint instruction that indicates that the PE can enter a low-power state and remain there until a wakeup event occurs. For more information
  • EL0/1常用的寄存器
// K14 Registers Index P7809// 这里面比较特殊的寄存器 有 SP/PC/PSTATE(及其相关的域寄存器)
// 这些寄存器会被执行的指令隐式改变,而其他寄存器不会被隐式改变,只会被显式改变通用寄存器(31个)// D1.6.1 The general purpose registers, R0-R30 P2277X0 - X30 // P99 B1.2.1 Registers in AArch64 state
SIMD&FP registers(32+2)V0 - V31
PC寄存器PC
状态寄存器(1) // D1.7 Process state, PSTATE P2284PSTATE // 不能被直接访问
特殊寄存器(27个)// C5.2 Special-purpose registers P347 // 默认不能被EL0访问,除非有特殊声明• CurrentEL, that holds PSTATE.EL, and that software can read to determine the current Exception level.• DAIF, that holds the current PSTATE.{D, A, I, F} interrupt mask bits.// 能不能被 EL0 访问, 取决于 SCTLR_EL1.UMA 的设置• DIT, that holds the PSTATE.DIT bit.• NZCV, that holds the PSTATE.{N, Z, C, V} condition flags.// 一直能被 EL0 访问• PAN, that holds the PSTATE.PAN state bit.• SPSel, that holds PSTATE.SP, that at EL1 or higher selects the current SP.• SSBS, that holds the PSTATE.SSBS bit.• TCO, that holds the PSTATE.TCO bit.• UAO, that holds the PSTATE.UAO bit.• ELR_EL1, that holds the address to return to for an exception return from EL1.• SPSR_EL1, that holds process state on taking an exception to AArch64 EL1.• FPCR, that provides control of floating-point operation.• FPSR, that provides floating-point status information.• SP_EL0, that holds the stack pointer for EL0.• SP_EL1, that holds the stack pointer for EL1.• DLR_EL0, that holds the address to return to for a return from Debug state.• DSPSR_EL0, that holds process state on entry to Debug state

这篇关于AARCH64 常用的指令和寄存器描述的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1007826

相关文章

HarmonyOS学习(七)——UI(五)常用布局总结

自适应布局 1.1、线性布局(LinearLayout) 通过线性容器Row和Column实现线性布局。Column容器内的子组件按照垂直方向排列,Row组件中的子组件按照水平方向排列。 属性说明space通过space参数设置主轴上子组件的间距,达到各子组件在排列上的等间距效果alignItems设置子组件在交叉轴上的对齐方式,且在各类尺寸屏幕上表现一致,其中交叉轴为垂直时,取值为Vert

JS常用组件收集

收集了一些平时遇到的前端比较优秀的组件,方便以后开发的时候查找!!! 函数工具: Lodash 页面固定: stickUp、jQuery.Pin 轮播: unslider、swiper 开关: switch 复选框: icheck 气泡: grumble 隐藏元素: Headroom

这15个Vue指令,让你的项目开发爽到爆

1. V-Hotkey 仓库地址: github.com/Dafrok/v-ho… Demo: 戳这里 https://dafrok.github.io/v-hotkey 安装: npm install --save v-hotkey 这个指令可以给组件绑定一个或多个快捷键。你想要通过按下 Escape 键后隐藏某个组件,按住 Control 和回车键再显示它吗?小菜一碟: <template

【C++】_list常用方法解析及模拟实现

相信自己的力量,只要对自己始终保持信心,尽自己最大努力去完成任何事,就算事情最终结果是失败了,努力了也不留遗憾。💓💓💓 目录   ✨说在前面 🍋知识点一:什么是list? •🌰1.list的定义 •🌰2.list的基本特性 •🌰3.常用接口介绍 🍋知识点二:list常用接口 •🌰1.默认成员函数 🔥构造函数(⭐) 🔥析构函数 •🌰2.list对象

常用的jdk下载地址

jdk下载地址 安装方式可以看之前的博客: mac安装jdk oracle 版本:https://www.oracle.com/java/technologies/downloads/ Eclipse Temurin版本:https://adoptium.net/zh-CN/temurin/releases/ 阿里版本: github:https://github.com/

30常用 Maven 命令

Maven 是一个强大的项目管理和构建工具,它广泛用于 Java 项目的依赖管理、构建流程和插件集成。Maven 的命令行工具提供了大量的命令来帮助开发人员管理项目的生命周期、依赖和插件。以下是 常用 Maven 命令的使用场景及其详细解释。 1. mvn clean 使用场景:清理项目的生成目录,通常用于删除项目中自动生成的文件(如 target/ 目录)。共性规律:清理操作

019、JOptionPane类的常用静态方法详解

目录 JOptionPane类的常用静态方法详解 1. showInputDialog()方法 1.1基本用法 1.2带有默认值的输入框 1.3带有选项的输入对话框 1.4自定义图标的输入对话框 2. showConfirmDialog()方法 2.1基本用法 2.2自定义按钮和图标 2.3带有自定义组件的确认对话框 3. showMessageDialog()方法 3.1

工作常用指令与快捷键

Git提交代码 git fetch  git add .  git commit -m “desc”  git pull  git push Git查看当前分支 git symbolic-ref --short -q HEAD Git创建新的分支并切换 git checkout -b XXXXXXXXXXXXXX git push origin XXXXXXXXXXXXXX

java常用面试题-基础知识分享

什么是Java? Java是一种高级编程语言,旨在提供跨平台的解决方案。它是一种面向对象的语言,具有简单、结构化、可移植、可靠、安全等特点。 Java的主要特点是什么? Java的主要特点包括: 简单性:Java的语法相对简单,易于学习和使用。面向对象:Java是一种完全面向对象的语言,支持封装、继承和多态。跨平台性:Java的程序可以在不同的操作系统上运行,称为"Write once,

nginx介绍及常用功能

什么是nginx nginx跟Apache一样,是一个web服务器(网站服务器),通过HTTP协议提供各种网络服务。 Apache:重量级的,不支持高并发的服务器。在Apache上运行数以万计的并发访问,会导致服务器消耗大量内存。操作系统对其进行进程或线程间的切换也消耗了大量的CPU资源,导致HTTP请求的平均响应速度降低。这些都决定了Apache不可能成为高性能WEB服务器  nginx: