2
.intel_syntax noprefix
smp_trampoline:
    # clear the direction flag (e.g. go forward in memory when using
    # instructions like lodsb)
    cld
    # disable interrupts
    cli

    # zero data segment
    xor ax, ax
    mov ds, ax

    # Set the A20 line
    in    al, 0x92
    or    al, 2
    out 0x92, al

    # Load 32-bit GDT
    lgdt gdt32_pointer

    # Enable protected mode
    mov eax, cr0
    or  eax, (1 << 0)
    mov cr0, eax
    # normally this should be jmp 0x8:mylabel
    jmp 0x08:protected_mode_setup

I'm trying to write a bootloader in Rust with the assembly being included through global_asm!("start.s"). This means I'm limited to using GNU Asm. Now I want to make a far jump from 16bit mode to protected mode after loading the GDT. In nasm this would be a jmp 0x08:mylabel in GNU Asm this does not seem to exist?

error: unexpected token in argument list
   |
note: instantiated into assembly here
  --> <inline asm>:48:12
   |
48 |     jmp 0x8:protected_mode_setup
   |            ^

error: aborting due to previous error

I also tried jmp far 0x08:protected_mode_setup and jmp 0x08, protected_mode_setup like described here without success.

Minimal source to reproduce the issue: https://github.com/Luis-Hebendanz/rust_asm_error

I opened an issue: https://github.com/rust-lang/rust/issues/84676

Qubasa
  • 183
  • 8
  • Try using a comma, e.g. `jmp 0x8, protected_mode_setup`. – Jester Apr 28 '21 at 21:52
  • Sadly doesn't work – Qubasa Apr 28 '21 at 21:53
  • 2
    The instruction might be called `ljmp`. `ljmp 0x8, protected_mode_setup` works for me. – fuz Apr 28 '21 at 21:56
  • hmm I still get a compiler error, isn't `ljmp` only usable in AT&T syntax? – Qubasa Apr 28 '21 at 21:59
  • `jmp 0x8:label` works in straight `gas` (make sure you have `.code16`). Is the error from the assembler, or the Rust compiler? Can you show the exact source file you start with, and the command you run? AFAIK Rust uses an llvm assembler, not gas itself, so corner cases like 16-bit code may be incompatible. – Nate Eldredge Apr 28 '21 at 22:01
  • sure! Here https://github.com/Luis-Hebendanz/rust_asm_error @NateEldredge – Qubasa Apr 28 '21 at 22:10
  • 1
    Your `start.s` assembles fine with gas, so the problem must be with the Rust compiler. – Nate Eldredge Apr 28 '21 at 22:13
  • @NateEldredge: IIRC, Rust is normally compiled with an LLVM-based compiler. So probably the thing to try is `clang`'s built-in assembler. It's much pickier about `ljmp` in `.intel_syntax noprefix` mode; in [Intel Assembly ljmp syntax from AT&T syntax](https://stackoverflow.com/a/65352001) I didn't find a way to get clang to assemble an Intel-syntax ljmp with a symbol target, only 2 numeric literals. (It was fine in AT&T mode.) I think this might be a duplicate since my answer there covers clang. (Albeit as a side-note, not the main focus.) – Peter Cordes Apr 29 '21 at 04:27

0 Answers0