HelloSilicon icon indicating copy to clipboard operation
HelloSilicon copied to clipboard

Brief explanation of changes

Open francopan opened this issue 7 months ago • 1 comments

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.

francopan avatar Nov 25 '23 07:11 francopan

Created a pull request for this issue: https://github.com/below/HelloSilicon/pull/47

francopan avatar Nov 25 '23 08:11 francopan

It seems this issue could be closed already as the PR for this improvement has already been merged.

maxcnunes avatar Mar 23 '24 12:03 maxcnunes