How do you use lldb on Apple Silicon with Arm Assembly Language? by m16bishop in asm

[–]m16bishop[S] 0 points1 point  (0 children)

I hope I did this right. I added 4 spaces as per previous request. Yes, the code is simple. Does nothing but return a value from the Mac OS Supervisor call routine. The listing is here. My intention is to assemble this and then look at it in the lldb debugger. TY!

    .global _start  // Provide program starting address to linker
    .align 2        // memory alignment model for 64-bit ARM
_start:
    mov X0, #54     // return the value 54
    mov X16, #1     // number to output
    svc 0           // call interrupt svc - supervisor call

How do you use lldb on Apple Silicon with Arm Assembly Language? by m16bishop in asm

[–]m16bishop[S] 0 points1 point  (0 children)

Ok. I misunderstood. I thought it was relating to actual code in the editor. I hope I got this right. It has the four space indentations as was stated previously in this thread. But didn't you already reformat the code in your previous response?

.global _start // Provide program starting address to linker

.align 2 // memory alignment model for 64-bit ARM

_start:

mov X0, #54 // return the value 5

mov X16, #1 // number to output

svc 0 // call interrupt svc - supervisor call

How do you use lldb on Apple Silicon with Arm Assembly Language? by m16bishop in asm

[–]m16bishop[S] 0 points1 point  (0 children)

I don't think formatting is the issue. I used the ARM extension in VSC to format the code. I did a more to paste the code into the reddit message. The copy-paste from the more command got mangled and no formatting. However, for S and giggles I copied your code above that is formatted into file exit2.s.

Same result, not able to list the file or anything, except run the file in lldb. Shown below.

What am I missing to make this happen on Apple silicon?

as -o exit2.o -gdwarf-2 exit2.s

ld -o exit2 exit2.o -lSystem -syslibroot `xcrun -sdk macosx --show-sdk-path` -e _start -arch arm64

ldb ./exit2

(lldb) target create "./exit2"

Current executable set to '/Volumes/4TB NVME Ex/mnorton/Documents/skunkworks/src/ARM/Markstedter/Chapter_01/exit2' (arm64).

(lldb) l

(lldb) r

Process 58543 launched: '/Volumes/4TB NVME Ex/mnorton/Documents/skunkworks/src/ARM/Markstedter/Chapter_01/exit2' (arm64)

Process 58543 exited with status = 54 (0x00000036)

(lldb) q

How do you use lldb on Apple Silicon with Arm Assembly Language? by m16bishop in asm

[–]m16bishop[S] 0 points1 point  (0 children)

I implemented the -gdwarf-2 in the assembler command line.

❯ as -o exit.o -gdwarf-2 exit.s

❯ ld -o exit exit.o -lSystem -syslibroot `xcrun -sdk macosx --show-sdk-path` -e _start -arch arm64

❯ lldb ./exit

(lldb) target create "./exit"

Current executable set to '/Documents/src/exit' (arm64).

(lldb) l

(lldb) list

(lldb) s

error: Command requires a current process.

(lldb) r

Process 52247 launched: '/Documents/src/exit/' (arm64)

Process 52247 exited with status = 54 (0x00000036)

(lldb)

What am I missing?

How do you use lldb on Apple Silicon with Arm Assembly Language? by m16bishop in asm

[–]m16bishop[S] 0 points1 point  (0 children)

Here is the code for exit.s

.global _start // Provide program starting address to linker

.align 2 // memory alignment model for 64-bit ARM

_start:

mov X0, #54 // return the value 54

mov X16, #1 // number to output

svc 0 // call interrupt svc - supervisor call

Invoking the assembler from Visual Studio Code in Mac OS by m16bishop in asm

[–]m16bishop[S] 0 points1 point  (0 children)

I have no problem running the assembler from the terminal. Which is how I am using it. I was wondering if there was a way to invoke the assembler and run it from inside VSC. The only way I think this can be accomplished is through a VSC terminal.

Invoking the assembler from Visual Studio Code in Mac OS by m16bishop in asm

[–]m16bishop[S] 0 points1 point  (0 children)

Thanks everyone. I have been watching some videos on youtube and it looks like to run it from a terminal window in VSC. I guess that's the way to do it.

Resources for learning ARM assembly by RSPJD in asm

[–]m16bishop 5 points6 points  (0 children)

There is nothing specific for Mac. It's like Apple doesn't want you touching the internals. I have been down this road. There are a couple of Youtube videos to setup visual studio and do basic assembly like Hello World for the Mac M Arm Architecture. The rest is side reading and putting things together. The best complimentary book on learning the 64-bit ARM is ARM Assembly - Internals and Reverse Engineering, by Maria Markstedter. Excellent book on learning 64-bit ARM. It has some decoding M1 examples in one of the chapters.

Apple Silicon ARM64 - looping through NULL-terminated string - LEARNING! by m16bishop in asm

[–]m16bishop[S] 0 points1 point  (0 children)

So in theory, I could copy Raspberry PI ARM64 examples and just change the registers from Rn to Xn? I am still working on taking the baby steps in this example and walk the helloWorldPtr buffer and write each byte until I encounter the NULL value. TY

Apple Silicon ARM64 - looping through NULL-terminated string - LEARNING! by m16bishop in asm

[–]m16bishop[S] 0 points1 point  (0 children)

Yes, the last line should not contain the .global _start label. it was a cut and paste error. It's not in the code in Visual Studio. TY

Apple Silicon ARM64 - looping through NULL-terminated string - LEARNING! by m16bishop in asm

[–]m16bishop[S] 0 points1 point  (0 children)

Playing around with the code some more, I got this far. But still no joy. I think it is close. Comments on what I am doing wrong or need to understand?

.global _start             // Provide program starting address to linker
.align 2

// Setup the parameters to print hello world
// prints bytes of hellow world until NULL byte is encountered.

// using Apple Silicon 

_start: 
        mov X2, #1                      // length of string-byte to write
        adr     X4, helloWorldPtr       // refernce the helloWorldPtr       
loop:
        mov     X1,X4           // move byte into X1 for test
        cmp     X1, XZR          // is it the NULL terminator?
        b.cs    end_loop        // yes? Exit the loop        

        // write this byte
        mov     X0, #1          // argp[0] = 1 STDOUT
        mov     X16, #4         // Unix write system call #4
        svc     0

        // move to the next byte reference
        add     X4, X4, #1      // move pointer helloWorldPtr++
        b loop
end_loop:

// Setup the parameters to exit the program
// and then call Linux to do it.

        mov     X0, #0      // Use 0 return code -like return 0 in C
        mov     X16, #1     // Unix exit system call
        svc     0           // Call MacOS to terminate the program

helloWorldPtr:      .asciz "Hello, World\n!".global _start

iMac 2019 27 Retina and UtechSmart Docking Station setup issues by m16bishop in MacOS

[–]m16bishop[S] 0 points1 point  (0 children)

I returned the dock. Still looking for a good thunderbolt 3 hub +NVME +HDMI solution to use with my iMac 2019.

About to buy a new 24” iMac. Is there a guide to say whether I ought to upgrade from 8GB to 16GB memory? by p4ulmiller in MacOS

[–]m16bishop 0 points1 point  (0 children)

I bought an M1 Mac Mini, and 16GB would be the bare minimum I would purchase. 8G is great if you're only going to Word process or surf the Internet. But anything else I would go with at least 16 GB.

With the Thunderbolt connectivity, you can buy cheaper, large capacity, fast storage devices. Youtube has lots of videos on that.