shithub: drawcpu

ref: 6d3e368f2d0796e366d2df8ed56e3b6fe0c42182
dir: /posix-arm64/run.s/

View raw version
/* SPDX-License-Identifier: Unlicense */
.text
.global _run
_run:
    mov x29, x0         // entry (x0 is the first argument, equivalent to rdi)
    mov x9, x1          // _tos (x1 is the second argument, equivalent to rsi)
    mov x19, x2         // argc (x2 is the third argument, equivalent to rdx)
    mov x20, x3         // argv (x3 is the fourth argument, equivalent to rcx)

    // Push argv onto stack
    mov x10, x19        // x10 = argc
    add x10, x10, #1    // x10 = argc + 1
    lsl x10, x10, #3    // x10 = (argc + 1) * 8 (shifting left by 3 is multiplying by 8)
    sub sp, sp, x10     // Allocate space on stack
    mov x0, sp          // x0 = new stack pointer (destination for memcpy)
    mov x1, x20         // x1 = argv (source for memcpy)
    mov x2, x10         // x2 = number of bytes to copy
    bl _memcpy           // Call memcpy to copy argv to stack

    // Push argc onto stack
    str x19, [sp, #-16]!  // Push argc onto stack and update stack pointer

    // Jump to entry point
    br x29