Skip to content

Commit b07c0a6

Browse files
[binutils] add binutils support
1 parent acbc64e commit b07c0a6

File tree

519 files changed

+7794
-6335
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

519 files changed

+7794
-6335
lines changed

.github/workflows/branch.yml

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ env:
1111
AUTOTESTER_ROM: ${{github.workspace}}/secrets/83pce_515_530.rom
1212
CEDEV: ${{github.workspace}}/CEdev
1313
CEDEV_BIN: ${{github.workspace}}/CEdev/bin
14+
CEDEV_BINUTILS_BIN: ${{github.workspace}}/CEdev/binutils/bin
1415
CEDEV_EXAMPLES: ${{github.workspace}}/CEdev/examples
1516
CEDEV_TEST: ${{github.workspace}}/toolchain/test
1617
CEMU_PATH: ${{github.workspace}}/CEmu
@@ -32,36 +33,59 @@ jobs:
3233
- runs-on: macos-15-intel
3334
fasmg: /source/macos/x64/fasmg
3435
arch-suffix: "-intel"
35-
ez80-bins-suffix: macOS_intel
36+
llvm-project: ez80-clang-link_macOS_intel_nightly.zip
37+
binutils-gdb: binutils_macos_intel_nightly.tar.gz
3638
- runs-on: macos-14
3739
fasmg: /source/macos/x64/fasmg
3840
arch-suffix: "-arm"
39-
ez80-bins-suffix: macOS_arm
41+
llvm-project: ez80-clang-link_macOS_arm_nightly.zip
42+
binutils-gdb: binutils_macos_arm_nightly.tar.gz
4043
- runs-on: windows-latest
4144
fasmg: /fasmg.exe
42-
ez80-bins-suffix: windows
45+
llvm-project: ez80-clang-link_windows_nightly.zip
46+
binutils-gdb: binutils_windows_nightly.zip
4347
env: "env:"
4448
exe: .exe
4549
nul: nul
4650
ldflags: LDFLAGS="-static-libgcc -static-libstdc++ -static"
4751
- runs-on: ubuntu-22.04
48-
ez80-bins-suffix: ubuntu
52+
llvm-project: ez80-clang-link_ubuntu_nightly.zip
53+
binutils-gdb: binutils_ubuntu_nightly.tar.gz
4954
fasmg: /fasmg.x64
5055
runs-on: ${{matrix.runs-on}}
5156
steps:
5257
- name: Prepare Build Environment
53-
run: cmake -E echo >> $${{matrix.env}}GITHUB_PATH ${{env.CEDEV_BIN}}
58+
run: |
59+
cmake -E echo >> $${{matrix.env}}GITHUB_PATH ${{env.CEDEV_BIN}}
60+
cmake -E echo >> $${{matrix.env}}GITHUB_PATH ${{env.CEDEV_BINUTILS_BIN}}
61+
cmake -E make_directory "${{env.CEDEV}}"
62+
cmake -E make_directory "${{env.CEDEV_BIN}}"
5463
5564
- name: Download ez80-clang and ez80-link
5665
id: ez80-bins
5766
uses: carlosperate/download-file-action@v2.0.2
5867
with:
59-
file-url: https://github.com/CE-Programming/llvm-project/releases/download/nightly/ez80-clang-link_${{matrix.ez80-bins-suffix}}_nightly.zip
60-
- name: Extract ez80-clang
61-
uses: DuckSoft/extract-7z-action@v1.0
68+
file-url: https://github.com/CE-Programming/llvm-project/releases/download/nightly/${{matrix.llvm-project}}
69+
- name: Extract ez80-clang (Unix)
70+
if: runner.os != 'Windows'
71+
run: unzip -q "${{steps.ez80-bins.outputs.file-path}}" -d "${{env.CEDEV_BIN}}"
72+
- name: Extract ez80-clang (Windows)
73+
if: runner.os == 'Windows'
74+
run: Expand-Archive -Path "${{steps.ez80-bins.outputs.file-path}}" -DestinationPath "${{env.CEDEV_BIN}}"
75+
shell: pwsh
76+
77+
- name: Download binutils
78+
id: binutils
79+
uses: carlosperate/download-file-action@v2.0.2
6280
with:
63-
pathSource: ${{steps.ez80-bins.outputs.file-path}}
64-
pathTarget: ${{env.CEDEV_BIN}}
81+
file-url: https://github.com/CE-Programming/binutils-gdb/releases/download/nightly/${{matrix.binutils-gdb}}
82+
- name: Extract binutils (Unix)
83+
if: runner.os != 'Windows'
84+
run: tar -xzf "${{steps.binutils.outputs.file-path}}" -C "${{env.CEDEV}}"
85+
- name: Extract binutils (Windows)
86+
if: runner.os == 'Windows'
87+
run: Expand-Archive -Path "${{steps.binutils.outputs.file-path}}" -DestinationPath "${{env.CEDEV}}"
88+
shell: pwsh
6589

6690
- name: Add fasmg website to /etc/hosts since DNS seems to be broken
6791
if: runner.os == 'macOS'
@@ -109,7 +133,9 @@ jobs:
109133

110134
- name: Make Binaries Executable
111135
if: runner.os != 'Windows'
112-
run: chmod +x ${{env.CEDEV_BIN}}/*
136+
run: |
137+
chmod +x ${{env.CEDEV_BIN}}/*
138+
chmod +x ${{env.CEDEV_BINUTILS_BIN}}/*
113139
- name: Test Build Dependencies
114140
run: |
115141
ez80-clang --version
@@ -135,9 +161,14 @@ jobs:
135161
PREFIX: ${{github.workspace}}
136162
run: make -j4 -C ${{env.TOOLCHAIN_PATH}} install V=1 DESTDIR=${{github.workspace}}
137163

164+
- name: Remove Fasmg
165+
run: cmake -E rm -f ${{env.CEDEV_BIN}}/fasmg${{matrix.exe}}
166+
138167
- name: Make Binaries Executable
139168
if: runner.os != 'Windows'
140-
run: chmod +x ${{env.CEDEV_BIN}}/*
169+
run: |
170+
chmod +x ${{env.CEDEV_BIN}}/*
171+
chmod +x ${{env.CEDEV_BINUTILS_BIN}}/*
141172
142173
- name: Build Test Graphics
143174
run: make -j4 -C ${{env.CEDEV_TEST}} COMPRESSED=${{matrix.compressed}} V=1 gfx

.github/workflows/make.yml

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ env:
1313
AUTOTESTER_ROM: ${{github.workspace}}/secrets/83pce_515_530.rom
1414
CEDEV: ${{github.workspace}}/CEdev
1515
CEDEV_BIN: ${{github.workspace}}/CEdev/bin
16+
CEDEV_BINUTILS_BIN: ${{github.workspace}}/CEdev/binutils/bin
1617
CEDEV_EXAMPLES: ${{github.workspace}}/CEdev/examples
1718
CEDEV_TEST: ${{github.workspace}}/toolchain/test
1819
CEMU_PATH: ${{github.workspace}}/CEmu
@@ -32,40 +33,64 @@ jobs:
3233
- runs-on: macos-15-intel
3334
fasmg: /source/macos/x64/fasmg
3435
arch-suffix: "-intel"
35-
ez80-bins-suffix: macOS_intel
36+
llvm-project: ez80-clang-link_macOS_intel_nightly.zip
37+
binutils-gdb: binutils_macos_intel_nightly.tar.gz
3638
install-output-ext: "dmg"
3739
- runs-on: macos-14
3840
fasmg: /source/macos/x64/fasmg
3941
arch-suffix: "-arm"
40-
ez80-bins-suffix: macOS_arm
42+
llvm-project: ez80-clang-link_macOS_arm_nightly.zip
43+
binutils-gdb: binutils_macos_arm_nightly.tar.gz
4144
install-output-ext: "dmg"
4245
- runs-on: windows-latest
4346
fasmg: /fasmg.exe
44-
ez80-bins-suffix: windows
47+
llvm-project: ez80-clang-link_windows_nightly.zip
48+
binutils-gdb: binutils_windows_nightly.zip
4549
env: "env:"
4650
exe: .exe
4751
nul: nul
4852
ldflags: LDFLAGS="-static-libgcc -static-libstdc++ -static"
4953
install-output-ext: "zip"
5054
- runs-on: ubuntu-22.04
51-
ez80-bins-suffix: ubuntu
55+
llvm-project: ez80-clang-link_ubuntu_nightly.zip
56+
binutils-gdb: binutils_ubuntu_nightly.tar.gz
5257
fasmg: /fasmg.x64
5358
install-output-ext: "tar.gz"
59+
5460
runs-on: ${{matrix.runs-on}}
5561
steps:
5662
- name: Prepare Build Environment
57-
run: cmake -E echo >> $${{matrix.env}}GITHUB_PATH ${{env.CEDEV_BIN}}
63+
run: |
64+
cmake -E echo >> $${{matrix.env}}GITHUB_PATH ${{env.CEDEV_BIN}}
65+
cmake -E echo >> $${{matrix.env}}GITHUB_PATH ${{env.CEDEV_BINUTILS_BIN}}
66+
cmake -E make_directory "${{env.CEDEV}}"
67+
cmake -E make_directory "${{env.CEDEV_BIN}}"
5868
5969
- name: Download ez80-clang and ez80-link
6070
id: ez80-bins
6171
uses: carlosperate/download-file-action@v2.0.2
6272
with:
63-
file-url: https://github.com/CE-Programming/llvm-project/releases/download/nightly/ez80-clang-link_${{matrix.ez80-bins-suffix}}_nightly.zip
64-
- name: Extract ez80-clang
65-
uses: DuckSoft/extract-7z-action@v1.0
73+
file-url: https://github.com/CE-Programming/llvm-project/releases/download/nightly/${{matrix.llvm-project}}
74+
- name: Extract ez80-clang (Unix)
75+
if: runner.os != 'Windows'
76+
run: unzip -q "${{steps.ez80-bins.outputs.file-path}}" -d "${{env.CEDEV_BIN}}"
77+
- name: Extract ez80-clang (Windows)
78+
if: runner.os == 'Windows'
79+
run: Expand-Archive -Path "${{steps.ez80-bins.outputs.file-path}}" -DestinationPath "${{env.CEDEV_BIN}}"
80+
shell: pwsh
81+
82+
- name: Download binutils
83+
id: binutils
84+
uses: carlosperate/download-file-action@v2.0.2
6685
with:
67-
pathSource: ${{steps.ez80-bins.outputs.file-path}}
68-
pathTarget: ${{env.CEDEV_BIN}}
86+
file-url: https://github.com/CE-Programming/binutils-gdb/releases/download/nightly/${{matrix.binutils-gdb}}
87+
- name: Extract binutils (Unix)
88+
if: runner.os != 'Windows'
89+
run: tar -xzf "${{steps.binutils.outputs.file-path}}" -C "${{env.CEDEV}}"
90+
- name: Extract binutils (Windows)
91+
if: runner.os == 'Windows'
92+
run: Expand-Archive -Path "${{steps.binutils.outputs.file-path}}" -DestinationPath "${{env.CEDEV}}"
93+
shell: pwsh
6994

7095
- name: Add fasmg website to /etc/hosts since DNS seems to be broken
7196
if: runner.os == 'macOS'
@@ -139,9 +164,14 @@ jobs:
139164
PREFIX: ${{github.workspace}}
140165
run: make -j4 -C ${{env.TOOLCHAIN_PATH}} install V=1 DESTDIR=${{github.workspace}}
141166

167+
- name: Remove Fasmg
168+
run: cmake -E rm -f ${{env.CEDEV_BIN}}/fasmg${{matrix.exe}}
169+
142170
- name: Make Binaries Executable
143171
if: runner.os != 'Windows'
144-
run: chmod +x ${{env.CEDEV_BIN}}/*
172+
run: |
173+
chmod +x ${{env.CEDEV_BIN}}/*
174+
chmod +x ${{env.CEDEV_BINUTILS_BIN}}/*
145175
146176
- name: "[macOS] CodeSign Toolchain binaries"
147177
if: runner.os == 'macOS' && github.repository == 'CE-Programming/toolchain' # don't run on forks, since they don't have secrets
@@ -461,4 +491,3 @@ jobs:
461491
token: ${{ secrets.CI_PAT_CLIBS_NIGHTLTY }}
462492
repository: CE-Programming/libraries
463493
event-type: ci-clibs-nightly
464-

docs/headers/ti/sprintf.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ The truncating behavior of C99 `snprintf` can be replicated with `boot_asprintf`
7272
7373
printf and fprintf
7474
------------------
75-
`printf` and `fprintf` can be replicated by using `fputs`
75+
76+
`printf` and `fprintf` can be replicated by using `fputs`.
7677

7778
.. code-block:: c
7879

docs/static/asm.rst

Lines changed: 43 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,50 @@
11
.. _asm:
22

3-
Assembly Routines
4-
=================
3+
Assembly Files
4+
==============
55

6-
Assembly routines can be linked into a C/C++ program by putting them into the same **src** directory that your C/C++ sources are in, but with an **.asm** extension.
7-
These can be placed in any subdirectory of **src** just like C/C++ sources.
6+
Assembly files can be linked into a C/C++ program by putting them into the same **src** directory that your C/C++ sources are in.
7+
Use a **.S** extension if you want the compiler's preprocessor to run on the file first, or use a **.s** extension if the assembly file does not need to be preprocessed.
88

9-
Assembly Files
10-
--------------
9+
The use of inline assembly is supported, but highly discouraged as future changes to the compiler may render the inline assembly incompatible, and it reduces the readablity of the code.
10+
11+
Assembler
12+
---------
1113

12-
.. _asm-consts:
14+
The CE Toolchain uses the GNU Assembler (GAS) to assemble source files.
15+
Historically the fasmg assembler was used, but is no longer supported to allow for better cross-platform support and linking performance.
1316

14-
Constants
15-
^^^^^^^^^
17+
Documentation for the GNU Assembler: https://www.sourceware.org/binutils/docs/as/index.html
1618

17-
The top of the file is a good place defining constants or including other files that define constants.
18-
These will be availabe throughout the rest of the file, but not in other files.
19-
You can define a constant by saying :code:`my_constant := 42`.
20-
You can include common constants in multiple files by defining them in a file named, say, **file.inc** and putting :code:`include 'file.inc'` in every file that needs them.
21-
You should not generally put any labels, code, or data here.
22-
If you try to reference a label defined here, you will get an :code:`Error: variable term used where not expected.` linker error which means you are trying to resolve an address that doesn't belong to any section.
23-
See :ref:`asm-section` to fix this problem.
19+
Specific Z80/ez80 directives: https://www.sourceware.org/binutils/docs/as/Z80-Directives.html
2420

2521
.. _asm-assume:
2622

2723
Assume
2824
^^^^^^
2925

30-
You should add a :code:`assume adl=1` before trying to emit any code, which ensures that you get 24-bit eZ80 instructions.
31-
If you end an assembly file with :code:`assume adl=0` (which is the eZ80's 16-bit Z80 compatibility mode), it will propogate to another random assembly file.
32-
All toolchain and compiler-generated sources make sure to reset the mode at the top of the file and end the file in the same mode, but if one of your sources end in Z80 mode, then any other one of your sources might begin in Z80 mode, so it is safer to put the :code:`assume` line in every file.
26+
You should add a :code:`.assume ADL=1` before trying to emit any code, which ensures that you get 24-bit eZ80 instructions.
3327

3428
.. _asm-section:
3529

36-
Section
37-
^^^^^^^
30+
Sections
31+
^^^^^^^^
3832

39-
Now that we are in the correct mode, we need to tell the linker where to put things.
40-
We use :code:`section .text` for code, :code:`section .data` for variables, and :code:`section .rodata` for constant data.
41-
Currently these are all placed in RAM, so which section you choose to switch to is much less important than how often you switch sections, even if you are switching to the same section you are already in.
42-
This is because every time you start a new, or restart the same, section, the linker gets a new opportunity to delete a block of dead code/data.
33+
The CE Toolchain uses :code:`.section .text` for code, :code:`.section .data` for variables, and :code:`.section .rodata` for constant data.
34+
Every time you start a new section (such as :code:`.section .text.function`), the linker has an opportunity to delete a block of dead code/data.
4335
Because of this, the correct time to switch sections is usually every time you start a new function or variable.
44-
You should not let execution fall off the end of a block because you won't know if that block will be included or deleted from the output, however you can if you say :code:`require _symbol` of some public or private symbol defined in the next section to ensure that if the current block is included, then that will force the next block to also be included.
45-
To define a symbol in a block that can be referenced from other blocks, you should do :code:`private _symbol` or :code:`public _symbol` right before its definition.
46-
If it is private then it is only able to be referenced from the same file and no :ref:`extern <asm-extern>` should be used.
47-
If it is public then it can be referenced within the same file without :ref:`extern <asm-extern>` just like private symbols, but public symbols can also be referenced from other files and even C/C++!
48-
The public assembly symbol named :code:`_symbol` is accessible in C by the global name :code:`symbol`, assuming it is properly declared, with your asm symbol acting as the definition.
36+
To define a symbol in a block that can be referenced from other blocks, you should do :code:`.local _symbol` or :code:`.global _symbol` right before its definition.
37+
If it is local then it is only able to be referenced from the same file and no :ref:`.extern <asm-extern>` should be used.
38+
If it is global then it can be referenced within the same file without :ref:`.extern <asm-extern>` just like local symbols, but global symbols can also be referenced from other files and even C/C++!
39+
The gllobal assembly symbol named :code:`_symbol` is accessible in C by the global name :code:`symbol` (note the leading underscore), assuming it is properly declared, with your asm symbol acting as the definition.
4940

5041
.. _asm-extern:
5142

5243
Extern
5344
^^^^^^
5445

55-
At the end of the file is a good place to list every external symbol that you might depend on like :code:`extern _symbol`.
56-
This includes both public symbols defined in another assembly file and global symbols from C, prefixed with an underscore like usual.
57-
Lastly, you should not let execution fall off the end of a file because the next file that gets assembled is unpredictable and you could end up anywhere!
46+
At the end of the file is a good place to list every external symbol that you might depend on like :code:`.extern _symbol`.
47+
This includes both global symbols defined in another assembly file and global symbols from C, prefixed with an underscore.
5848
Block ordering can only be relied on within a single file, and only for blocks belonging to the same section.
5949

6050
Linking ASM routines to C/C++
@@ -69,17 +59,18 @@ Below is an example C prototype followed by the assembly implementation:
6959

7060
.. code-block:: c
7161
72-
void asm_func(int arg);
62+
void asm_func(int argument);
7363
7464
:code:`asm_func.asm`
7565

7666
.. code-block::
7767
78-
assume adl=1
79-
80-
section .text
81-
82-
public _asm_func
68+
.assume adl=1
69+
70+
.section .text._asm_func
71+
.global _asm_func
72+
.type _asm_func, @function
73+
8374
_asm_func:
8475
pop hl
8576
pop de
@@ -91,33 +82,29 @@ Below is an example C prototype followed by the assembly implementation:
9182
pop de
9283
9384
ret
94-
95-
extern _external_func
85+
86+
.extern _external_func
9687
9788
:code:`asm_func.c`
9889

9990
.. code-block::
10091
101-
int external_func(int arg) {
92+
int external_func(int arg)
93+
{
10294
printf("external_func called with %d\n", arg);
10395
return 4321;
10496
}
10597
106-
void test() {
98+
void test(void)
99+
{
107100
int arg = 1234;
108101
printf("calling asm_func with %d\n", arg);
109102
int ret = asm_func(arg);
110103
printf("asm_func returned %d\n", ret);
111104
}
112105
113-
Preserve
114-
^^^^^^^^
115-
116-
Assembly routines must preserve the :code:`IX` and :code:`SP` registers.
117-
All other registers are free for use.
118-
119-
Arguments
120-
^^^^^^^^^
106+
ABI Arguments
107+
^^^^^^^^^^^^^
121108

122109
Arguments are pushed from last to first corresponding to the C prototype.
123110
In eZ80, 3 bytes are always pushed to the stack regardless of the actual size.
@@ -126,6 +113,9 @@ For example, if a *short* type is used, the upper byte of the value pushed on th
126113
This table lists the locations relative to *sp* from within the called funciton.
127114
Note that :code:`sp + [0,2]` contains the return address.
128115

116+
Assembly routines must preserve the :code:`IX` and :code:`SP` registers.
117+
All other registers are free for use.
118+
129119
+-------------+------------+----------------------+
130120
| C/C++ Type | Size | Stack Location |
131121
+=============+============+======================+
@@ -150,8 +140,8 @@ Note that :code:`sp + [0,2]` contains the return address.
150140
| pointer | 3 bytes | sp + [3,5] |
151141
+-------------+------------+----------------------+
152142

153-
Returns
154-
^^^^^^^
143+
ABI Returns
144+
^^^^^^^^^^^
155145

156146
This table lists which registers are used for return values from a function.
157147
The type's sign does not affect the registers used, but may affect the value returned.

0 commit comments

Comments
 (0)