AMD64 Architecture

本文详细介绍了AMD64架构的特点及Yasm对其的支持情况。AMD64是在x86基础上发展起来的64位架构,增加了寄存器数量并扩展了算术运算和地址空间。此外,还介绍了在64位模式下指令集的变化,包括新的寄存器使用方式、指令编码规则以及内存寻址等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

AMD64 Architecture

The AMD64 architecture is a new 64-bit architecture developed by AMD, based on the 32-bit x86 architecture. It extends the original x86 architecture by doubling the number of general purpose and SIMD registers, extending the arithmetic operations and address space to 64 bits, as well as other features.

Recently, Intel has introduced an essentially identical version of AMD64 called EM64T.

Yasm AMD64 Support

Yasm extends the base NASM syntax to support AMD64 as follows. To enable assembly of instructions for the 64-bit mode of AMD64 processors, use the directive BITS 64. As with NASM's BITS directive, this does not change the format of the output object file to 64 bits; it only changes the assembler mode to assume that the instructions being assembled will be run in 64-bit mode. To specify an AMD64 object file, use "-m amd64" on the YasmCommandLine, or explicitly target a 64-bit object format such as "-f win64" or "-f elf64".

Note: the following is a copy of the documentation in the yasm_arch(7) man page.

Register Changes

The additional 64-bit general purpose registers are named r8-r15. There are also 8-bit (rXb), 16-bit (rXw), and 32-bit (rXd) subregisters that map to the least significant 8, 16, or 32 bits of the 64-bit register. The original 8 general purpose registers have also been extended to 64-bits: eax, edx, ecx, ebx, esi, edi, esp, and ebp have new 64-bit versions called rax, rdx, rcx, rbx, rsi, rdi, rsp, and rbp respectively. The old 32-bit registers map to the least significant bits of the new 64-bit registers.

New 8-bit registers are also available that map to the 8 least significant bits of rsi, rdi, rsp, and rbp. These are called sil, dil, spl, and bpl respectively. Unfortunately, due to the way instructions are encoded, these new 8-bit registers are encoded the same as the old 8-bit registers ah, dh, ch, and bh. The processor tells which is being used by the presence of the new REX prefix that is used to specify the other extended registers. This means it is illegal to mix the use of ah, dh, ch, and bh with an instruction that requires the REX prefix for other reasons. For instance:

    add ah, [r10]

(NASM syntax) is not a legal instruction because the use of r10 requires a REX prefix, making it impossible to use ah.

In 64-bit mode, an additional 8 SSE2 registers are also available. These are named xmm8-xmm15.

64 Bit Instructions

By default, most operations in 64-bit mode remain 32-bit; operations that are 64-bit usually require a REX prefix (one bit in the REX prefix determines whether an operation is 64-bit or 32-bit). Thus, essentially all 32-bit instructions have a 64-bit version, and the 64-bit versions of instructions can use extended registers "for free" (as the REX prefix is already present). Examples in NASM syntax:

    mov eax, 1  ; 32-bit instruction
    mov rcx, 1  ; 64-bit instruction

Instructions that modify the stack (push, pop, call, ret, enter, and leave) are implicitly 64-bit. Their 32-bit counterparts are not available, but their 16-bit counterparts are. Examples in NASM syntax:

    push eax  ; illegal instruction
    push rbx  ; 1-byte instruction
    push r11  ; 2-byte instruction with REX prefix

Implicit Zero Extension

Results of 32-bit operations are implicitly zero-extended to the upper 32 bits of the corresponding 64-bit register. 16 and 8 bit operations, on the other hand, do not affect upper bits of the register (just as in 32-bit and 16-bit modes). This can be used to generate smaller code in some instances. Examples in NASM syntax:

    mov ecx, 1  ; 1 byte shorter than mov rcx, 1
    and edx, 3  ; equivalent to and rdx, 3

Immediates

For most instructions in 64-bit mode, immediate values remain 32 bits; their value is sign-extended into the upper 32 bits of the target register prior to being used. The exception is the mov instruction, which can take a 64-bit immediate when the destination is a 64-bit register. Examples in NASM syntax:

    add rax, 1                  ; optimized down to signed 8-bit immediate
    add rax, dword 1            ; force immediate size to 32-bit
    add rax, 0xffffffff         ; sign-extended 32-bit immediate
    add rax, -1                 ; same as above
    add rax, 0xffffffffffffffff ; warning (>32 bit), truncated to same as above
    mov eax, 1                  ; 5 byte instruction
    mov rax, 1                  ; 5 byte instruction (optimized to signed 32-bit immediate)
    mov rax, qword 1            ; 10 byte instruction (force 64-bit immediate)
    mov rbx, 0x1234567890abcdef ; 10 byte instruction
    mov rcx, 0xffffffff         ; 10 byte instruction (does not fit in signed 32-bit size)
    mov ecx, -1                 ; 5 byte instruction equivalent to above
    mov rcx, sym                ; 5 byte - yasm defaults to 32-bit size for symbols
    mov rcx, qword sym          ; 10 byte - override default size

Displacements

Just like immediates, displacements, for the most part, remain 32 bits and are sign extended prior to use. Again, the exception is one restricted form of the mov instruction: between the al/ax/eax/rax register and a 64-bit absolute address (no registers allowed in the effective address). In NASM syntax, use of the 64-bit absolute form requires [qword]. Examples in NASM syntax:

    mov eax, [1]    ; 32 bit, with sign extension
    mov al, [rax-1] ; 32 bit, with sign extension
    mov al, [qword 0x1122334455667788] ; 64-bit absolute
    mov al, [0x1122334455667788] ; truncated to 32-bit (warning)

RIP Relative Addressing

In 64-bit mode, a new form of effective addressing is available to make it easier to write position-independent code. Any memory reference may be made RIP relative (RIP is the instruction pointer register, which contains the address of the location immediately following the current instruction).

In NASM syntax, there are two ways to specify RIP-relative addressing:

    mov dword [rip+10], 1

stores the value 1 ten bytes after the end of the instruction. "10" can also be a symbolic constant, and will be treated the same way. On the other hand,

    mov dword [symb wrt rip], 1

stores the value 1 into the address of symbol "symb". This is distinctly different than the behavior of:

    mov dword [symb+rip], 1

which takes the address of the end of the instruction, adds the address of "symb" to it, then stores the value 1 there. If symb is a variable, this will not store the value 1 into the symb variable!

Memory references

Usually the size of a memory reference can be deduced by which registers you're moving--for example, "mov [rax],ecx" is a 32-bit move, because ecx is 32 bits. YASM currently gives the non-obvious "invalid combination of opcode and operands" error if it can't figure out how much memory you're moving. The fix in this case is to add a memory size specifier: qword, dword, word, or byte.

Here's a 64-bit memory move, which sets 8 bytes starting at rax:

    mov qword [rax], 1

Here's a 32-bit memory move, which sets 4 bytes:

    mov dword [rax], 1

Here's a 16-bit memory move, which sets 2 bytes:

    mov word [rax], 1

Here's an 8-bit memory move, which sets 1 byte:

    mov byte [rax], 1
 
<think>好的,我现在需要帮助用户在配备Apple M2芯片的MacBook上安装VirtualBox时遇到的问题。用户遇到的错误信息是:“The installer has detected an unsupported architecture. VirtualBox only runs on the amd64 architecture.” 我需要分析这个问题并提供解决方案。 首先,我要确认用户的问题根源。M2芯片属于ARM架构,而VirtualBox官方目前可能不支持ARM架构,特别是对于macOS。错误信息明确指出VirtualBox只能在AMD64(即x86_64)架构上运行。所以,问题可能在于VirtualBox尚未原生支持Apple Silicon(M1/M2)芯片。 接下来,我需要考虑可能的解决方案。首先,检查VirtualBox官网是否有支持ARM的版本。但根据我的知识,Oracle VirtualBox目前还没有官方支持Apple Silicon的版本。因此,可能需要寻找替代方案或变通方法。 替代方案可能包括使用UTM或Parallels Desktop等支持ARM架构的虚拟机软件。另外,用户可能尝试通过Rosetta 2转译来运行x86版本的VirtualBox,但需要确认是否可行。不过,VirtualBox需要内核扩展,而Rosetta可能无法处理这一点,导致安装失败。 另一个思路是使用Homebrew安装VirtualBox。但Homebrew的版本可能同样依赖于架构支持,因此需要检查是否有适用于ARM的版本。或者,用户可能需要安装x86版本的Homebrew,然后通过Rosetta运行。不过,这种方法可能比较复杂,并且不一定能成功安装VirtualBox。 还有可能用户下载的是错误的安装包,比如x86的版本,而应该寻找为ARM架构编译的版本。但如前所述,官方可能没有提供。因此,可能需要等待官方支持,或者寻找社区开发的版本。 此外,用户可能需要使用UTM来虚拟化x86系统,然后在其中运行VirtualBox,但这样会导致性能下降,并且步骤繁琐。 总结可能的解决方案: 1. 使用UTM或Parallels替代VirtualBox。 2. 通过Rosetta 2安装VirtualBox,可能需要调整安装方式。 3. 检查是否下载了正确的安装包,或尝试其他版本。 4. 使用Docker或其他容器化解决方案代替虚拟机。 接下来,需要详细说明每个步骤,确保用户能够理解并执行。同时,需要提醒用户注意兼容性和性能问题,尤其是通过Rosetta运行可能带来的问题。 另外,需要验证是否有其他用户成功在M2上安装VirtualBox的方法,例如使用开发版或测试版。例如,是否有社区提供的补丁或编译版本支持ARM架构。 最后,建议用户考虑长期解决方案,如等待VirtualBox官方支持,或者转向其他原生支持ARM的虚拟化软件。</think>在配备Apple M2芯片(ARM架构)的MacBook上安装VirtualBox时出现**"Unsupported architecture"**错误,是因为**Oracle VirtualBox目前尚未原生支持Apple Silicon芯片**(截至2024年7月)。以下是可用的解决方案: --- ### 方案一:使用UTM替代(推荐原生ARM方案) UTM是基于QEMU的免费开源虚拟机软件,原生支持M1/M2芯片: ```bash # 通过Homebrew安装 brew install --cask utm # 或手动下载: # 官网 https://mac.getutm.app ``` * 支持安装Windows 11 ARM版、Linux ARM版系统 * 图形化界面友好,无需转译 * 性能优于Rosetta转译方案 --- ### 方案二:通过Rosetta 2转译安装(x86兼容模式) 1. 强制终端使用Rosetta: ```bash # 新建Rosetta终端 sudo softwareupdate --install-rosetta mkdir -p /Applications/Utilities/Rosetta echo '#!/bin/bash\narch -x86_64 $SHELL' > /Applications/Utilities/Rosetta/Terminal chmod +x /Applications/Utilities/Rosetta/Terminal ``` 2. 通过Rosetta终端安装: ```bash # 安装x86版Homebrew arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" # 安装VirtualBox arch -x86_64 /usr/local/bin/brew install --cask virtualbox ``` * ⚠️ 注意:需关闭SIP(`csrutil disable`),且存在内核扩展兼容性问题 --- ### 方案三:Parallels Desktop(商业软件最佳体验) ```bash # 官网下载(18.1.0+版本原生支持M2): https://www.parallels.com/products/desktop/ ``` * 完美支持M1/M2芯片 * 直接运行Windows 11 ARM版(可通过微软官网下载) * 提供3D加速和USB设备直通 --- ### 方案四:Docker Desktop替代方案 如果仅需Linux环境: ```bash brew install --cask docker ``` * 使用ARM64容器镜像(如`--platform linux/arm64`) * 无需完整虚拟机,资源占用更低 --- ### 常见问题说明 1. **VirtualBox何时支持M2?** - Oracle尚未公布官方支持计划,建议关注[VirtualBox论坛](https://forums.virtualbox.org/) 2. **通过UTM安装x86系统:** ```bash # 在UTM中创建虚拟机时选择"Emulate"模式 # 可安装x86版Ubuntu等系统,但性能较低 ``` 3. **性能对比:** | 方案 | 原生支持ARM | x86系统支持 | 3D加速 | 启动速度 | |--------------|-------------|-------------|--------|----------| | UTM | ✅ | ⚠️需模拟 | ❌ | 中等 | | Parallels | ✅ | ✅ | ✅ | 快 | | VirtualBox | ❌ | ❌ | ❌ | 不可用 | 建议优先选择**UTM**或**Parallels Desktop**获得最佳体验,如需进一步帮助可提供具体使用场景。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值