Hi everyone!
I'm just setting up my environment to start developing also on my laptop, but I'm facing some problems compiling asm code that has variables on it in Apple silicon processors.
For example, in this case:
var syscall* : WORD
proc NtAllocateVirtualMemory(ProcessHandle: HANDLE, BaseAddress: PVOID, ZeroBits: ULONG, RegionSize: PSIZE_T, AllocationType: ULONG, Protect: ULONG): NTSTATUS {.asmNoStackFrame.} =
asm """
mov r10, rcx
mov eax, `syscall`
syscall
ret
"""
I get the following error when trying to compile with the following flags nim c -d=mingw --app=console --cpu=amd64 HalosGate.nim:
relocation truncated to fit: R_X86_64_32S against `.bss`
The error only shows when I am using the special character "`" to include a variable inside asm code, basically when getting the syscall value.
Full code for debugging can be found in the following GitHub: https://github.com/zimawhit3/HellsGateNim
If it's a pain, I have written an inline assembler for Nim that supports advanced patterns:
Codegen: https://github.com/mratsim/constantine/blob/50717d8/constantine/primitives/macro_assembler_x86.nim
Example usage: https://github.com/mratsim/constantine/blob/50717d8/constantine/arithmetic/assembly/limbs_asm_x86.nim
More advanced example in: https://github.com/mratsim/constantine/tree/50717d8/constantine/arithmetic/assembly
At one point I'll try to create a proper package for it and also support ARM codegen but I certainly don't look forward to documenting GCC/Clang inline assembly syntax.