HelloSilicon
HelloSilicon copied to clipboard
Brief explanation of changes
I've just started reading the book and when I got to the HelloWorld I noticed that the approach for doing system calls is different.
Since the repo went to trouble of stating where the terminal is (😅), I think a brief explanation of the differences would be important.
On the book (Linux):
...
_start: mov X0, #1 // 1 = StdOut
ldr X1, =helloworld // string to print
mov X2, #13 // length of our string
mov X8, #64 // Linux write system call
svc 0 // Call Linux to output the string
...
On the HelloSillicon repo (Mac):
...
_start: mov X0, #1 // 1 = StdOut
adr X1, helloworld // string to print
mov X2, #13 // length of our string
mov X16, #4 // Unix write system call
svc #0x80 // Call kernel to output the string
...
For starters, why the system call is different: The function number is different (64 and 4) due to each system having different conventions. The table for the Darwin (Apple) system calls can be found at the following link:Darwin System Calls.
This is however one specific version (the most recent at time of writing). Newer versions can be found at here.
Also due to system conventions, the address for storing the function numbers is different. While on Linux is on X8, in Apple Sillicon is X16.
And for calling the interruption as well, while on Linux is 0, on Apple Sillicon is 0x80.
Created a pull request for this issue: https://github.com/below/HelloSilicon/pull/47
It seems this issue could be closed already as the PR for this improvement has already been merged.