• Leave everything intact before _start

    From Frederick Virchanza Gotham@cauldwell.thomas@nospicedham.gmail.com to comp.lang.asm.x86 on Wed Mar 15 08:14:44 2023
    From Newsgroup: comp.lang.asm.x86


    I've been programming since the 90's in Visual Basic, C, C++, but just this month I've really gotten into x86_64 assembler.

    Using the GNU compiler suite, I've built my program and given it a new entry point called 'pre_start' which does a few things before jumping into '_start'.

    When 'pre_start' is finished processing and it's just about to jump into '_start', I want to be certain that pre_start hasn't left any remnants at all -- I need every register to be the way it was, and for the stack to be unaltered.

    Using the NASM assembler, I've written two macroes. I subsitute the former in at the beginning of "pre_start", and I substitute the latter in just before the instruction 'jmp _start'.

    Here's what I currently have. What else would you put in there? I want to make a generic way of saving and restoring everything that might change so that the function has no lasting observable effect.

    %macro backup_all_registers 0
    push rax
    push rbx
    push rcx
    push rdx
    push rsi
    push rdi
    push r8
    push r9
    push r10
    push r11
    push r12
    push r13
    push r14
    push r15
    %endmacro

    %macro restore_all_registers 0
    pop r15
    pop r14
    pop r13
    pop r12
    pop r11
    pop r10
    pop r9
    pop r8
    pop rdi
    pop rsi
    pop rdx
    pop rcx
    pop rbx
    pop rax
    %endmacro

    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From Frederick Virchanza Gotham@cauldwell.thomas@nospicedham.gmail.com to comp.lang.asm.x86 on Wed Mar 15 09:42:19 2023
    From Newsgroup: comp.lang.asm.x86

    On Wednesday, March 15, 2023 at 3:21:00rC>PM UTC, Frederick Virchanza Gotham wrote:

    Here's what I currently have. What else would you put in there?
    By the way I don't save the frame pointer (rbp) because I follow "save_registers" with "enter 0,0".
    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From Terje Mathisen@terje.mathisen@nospicedham.tmsw.no to comp.lang.asm.x86 on Wed Mar 15 22:42:24 2023
    From Newsgroup: comp.lang.asm.x86

    Frederick Virchanza Gotham wrote:
    On Wednesday, March 15, 2023 at 3:21:00rC>PM UTC, Frederick Virchanza Gotham wrote:

    Here's what I currently have. What else would you put in there?


    By the way I don't save the frame pointer (rbp) because I follow "save_registers" with "enter 0,0".

    What's wrong with PUSHA?

    Alternatively, why do you need so many registers for a little
    pre-amble/setup module?

    Terje
    --
    - <Terje.Mathisen at tmsw.no>
    "almost all programming can be viewed as an exercise in caching"

    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From Frederick Virchanza Gotham@cauldwell.thomas@nospicedham.gmail.com to comp.lang.asm.x86 on Thu Mar 16 01:26:35 2023
    From Newsgroup: comp.lang.asm.x86

    On Wednesday, March 15, 2023 at 9:51:29rC>PM UTC, Terje Mathisen wrote:

    What's wrong with PUSHA?
    There's no equivalent of PUSHA or PUSHAD on x86_64.
    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From Terje Mathisen@terje.mathisen@nospicedham.tmsw.no to comp.lang.asm.x86 on Thu Mar 16 09:45:14 2023
    From Newsgroup: comp.lang.asm.x86

    Frederick Virchanza Gotham wrote:
    On Wednesday, March 15, 2023 at 9:51:29rC>PM UTC, Terje Mathisen wrote:

    What's wrong with PUSHA?


    There's no equivalent of PUSHA or PUSHAD on x86_64.

    So that was a pair of opcodes AMD grabbed then! Thanks for enlightening me!

    I still want to know about why you need so many regs?

    Terje
    --
    - <Terje.Mathisen at tmsw.no>
    "almost all programming can be viewed as an exercise in caching"

    --- Synchronet 3.21d-Linux NewsLink 1.2