diff --git a/macros/README.md b/macros/README.md index 9b690d3..3126143 100644 --- a/macros/README.md +++ b/macros/README.md @@ -185,10 +185,21 @@ library, use this macro in this way: `CRT strlen` -An underscore is prepended. +An underscore is prepended on the Mac. ## Declaring `main()` Put `MAIN` on a line by itself. Notice there is no colon. -An underscore is prepended. +An underscore is prepended on the Mac. + +## `errno` + +The externally defined `errno` is accessed via a CRT function which +isn't seen when coding in C and C++. The function is named differently +on Mac versus Linux. To get the address of `errno` use: + +`ERRNO_ADDR` + +This macro makes the correct CRT call and leaves the address of `errno` +in `x0`. diff --git a/macros/README.pdf b/macros/README.pdf index 261ba4b..8ee66da 100644 Binary files a/macros/README.pdf and b/macros/README.pdf differ diff --git a/macros/apple-linux-convergence.S b/macros/apple-linux-convergence.S index aae5135..8d283a7 100644 --- a/macros/apple-linux-convergence.S +++ b/macros/apple-linux-convergence.S @@ -75,6 +75,18 @@ main: #endif .endm +/* Fetching the address of the externally defined errno is quite + different on Apple and Linux. This macro leaves the address of + errno in x0. +*/ +.macro ERRNO_ADDR +#if defined(__APPLE__) + bl ___error +#else + bl __errno_location +#endif +.endm + .macro CRT label #if defined(__APPLE__) bl _\label diff --git a/more/apple_silicon/apple-linux-convergence.S b/more/apple_silicon/apple-linux-convergence.S index aae5135..8d283a7 100644 --- a/more/apple_silicon/apple-linux-convergence.S +++ b/more/apple_silicon/apple-linux-convergence.S @@ -75,6 +75,18 @@ main: #endif .endm +/* Fetching the address of the externally defined errno is quite + different on Apple and Linux. This macro leaves the address of + errno in x0. +*/ +.macro ERRNO_ADDR +#if defined(__APPLE__) + bl ___error +#else + bl __errno_location +#endif +.endm + .macro CRT label #if defined(__APPLE__) bl _\label diff --git a/python/apple-linux-convergence.S b/python/apple-linux-convergence.S index aae5135..8d283a7 100644 --- a/python/apple-linux-convergence.S +++ b/python/apple-linux-convergence.S @@ -75,6 +75,18 @@ main: #endif .endm +/* Fetching the address of the externally defined errno is quite + different on Apple and Linux. This macro leaves the address of + errno in x0. +*/ +.macro ERRNO_ADDR +#if defined(__APPLE__) + bl ___error +#else + bl __errno_location +#endif +.endm + .macro CRT label #if defined(__APPLE__) bl _\label diff --git a/section_1/hello_world/apple-linux-convergence.S b/section_1/hello_world/apple-linux-convergence.S index aae5135..8d283a7 100644 --- a/section_1/hello_world/apple-linux-convergence.S +++ b/section_1/hello_world/apple-linux-convergence.S @@ -75,6 +75,18 @@ main: #endif .endm +/* Fetching the address of the externally defined errno is quite + different on Apple and Linux. This macro leaves the address of + errno in x0. +*/ +.macro ERRNO_ADDR +#if defined(__APPLE__) + bl ___error +#else + bl __errno_location +#endif +.endm + .macro CRT label #if defined(__APPLE__) bl _\label diff --git a/section_2/float/apple-linux-convergence.S b/section_2/float/apple-linux-convergence.S index aae5135..8d283a7 100644 --- a/section_2/float/apple-linux-convergence.S +++ b/section_2/float/apple-linux-convergence.S @@ -75,6 +75,18 @@ main: #endif .endm +/* Fetching the address of the externally defined errno is quite + different on Apple and Linux. This macro leaves the address of + errno in x0. +*/ +.macro ERRNO_ADDR +#if defined(__APPLE__) + bl ___error +#else + bl __errno_location +#endif +.endm + .macro CRT label #if defined(__APPLE__) bl _\label