| Both sides previous revisionPrevious revisionNext revision | Previous revision |
| ns32ktoolchain [2023/04/12 07:55] – [Standalone binaries] admin | ns32ktoolchain [2026/06/02 08:02] (current) – admin |
|---|
| ==== Overview ==== | ==== Overview ==== |
| |
| The **[[wp>GNU_toolchain|GNU Toolchain]]** is a collection of opensource software used for developing other software and OS-es. GNU Toolchain "by design" supports high portability and cross-compilation. It includes (among other tools) the **[[wp>GNU_Binutils|GNU Binutils]]** (assembler, linker e.t.c) and **GCC** (**[[wp>GNU Compiler Collection]]**: c, c++, fortran, ada e.t.c.). | The **[[wp>GNU_toolchain|GNU Toolchain]]** is a collection of opensource software used for developing other software and OS-es. GNU Toolchain supports high portability and cross-compilation by design. It includes (among other tools) the **[[wp>GNU_Binutils|GNU Binutils]]** (assembler, linker etc.) and **GCC** (**[[wp>GNU Compiler Collection]]**: c, c++, fortran, ada etc.). |
| |
| To run GNU Toolchain you have to use [[wp>Unix-like]] environment on real *NIX (Free/Net/Open-BSD Linux e.t.c.) with GNU tools pre-installed or UNIX-like environment like **[[wp>Cygwin]]** or **[[https://www.msys2.org/|MSYS2]]** for Windows. Virtual machine to run *NIX would be good too. | To run GNU Toolchain you have to use a [[wp>Unix-like]] environment on real *NIX systems (Free/Net/Open-BSD Linux etc.) with GNU tools pre-installed or UNIX-like environment like **[[wp>Cygwin]]** or **[[https://www.msys2.org/|MSYS2]]** for Windows. Virtual machine to run *NIX would be good too. |
| |
| To support cross-compilation there are three system names that the building scripts knows about: the machine you are building on (''BUILD''), the machine that you are building for (''HOST''), and the machine that toolchain will produce code for (''TARGET''). When you configure toolchains, you specify these with ''--build='', ''--host='', and ''--target=''. | To support cross-compilation there are three system names that the build scripts know about: the machine you are building on (''BUILD''), the machine that you are building for (''HOST''), and the machine that toolchain will produce code for (''TARGET''). When you configure toolchains, you specify these with ''--build='', ''--host='', and ''--target=''. |
| |
| ==== ns32k architecture support ==== | ==== ns32k architecture support ==== |
| |
| **GNU Toolchain** supports a lot of ''TARGET'' architectures (50+). The **ns32k** architecture support was actively developed around 1990-2000 due to **[[http://cpu-ns32k.net/PC532.html|PC532]]** platform popularity but faded-out now. **GNU binutils** still supports **ns32k** architecture (upto ''binutils-2.27'' was tested) but latest GCC supporting **ns32k** was a **GCC 3.4.x** (''gcc-3.4.6''), **GCC 4.0.x** (''gcc-4.0.4'') and was removed starting from the **GCC 4.1** and above. However it's still possible to build and use previous versions. | **GNU Toolchain** supports a lot of ''TARGET'' architectures (50+). The **ns32k** architecture support was actively developed around 1990-2000 due to **[[http://cpu-ns32k.net/PC532.html|PC532]]** platform popularity but faded away now. **GNU binutils** still supports **ns32k** architecture (up to ''binutils-2.27'' was tested) but latest GCC version supporting **ns32k** was a **GCC 3.4.x** (''gcc-3.4.6''), **GCC 4.0.x** (''gcc-4.0.4'') and was removed starting from the **GCC 4.1** and above. However it's still possible to build and use previous versions. |
| |
| The latest "large" OS which supported **ns32k** was **NetBSD 1.5.3** on the **PC532** platform ([[http://www.netbsd.org/ports/pc532/faq.html|FAQ]]). It used **GNU Toolchain** (slightly patched) to build itself (surprise?), ''binutils-2.9.1'' and ''egcs-1.1.2'' (also known as ''GCC 2.91'', see a Wikipedia for details about GCC history) | The last major OS which supported **ns32k** was **NetBSD 1.5.3** on the **PC532** platform ([[http://www.netbsd.org/ports/pc532/faq.html|FAQ]]). It used **GNU Toolchain** (slightly patched) to build itself (surprise?), ''binutils-2.9.1'' and ''egcs-1.1.2'' (also known as ''GCC 2.91'', see a Wikipedia for details about GCC history) |
| |
| NetBSD's **ns32k** ''TARGET'' for PC532 is ''ns32k-pc532-netbsd''.\\ | NetBSD's **ns32k** ''TARGET'' for PC532 is ''ns32k-pc532-netbsd''.\\ |
| NOTE! There are many flavors of the **a.out** formats for **ns32k**. For example, early GENIX (extracted from the 4.1BSD) had a different [[http://wiki.sensi.org/download/ns32k/a_out_5.pdf|a.out]] format than NetBSD. | NOTE! There are many flavors of the **a.out** formats for **ns32k**. For example, early GENIX (extracted from the 4.1BSD) had a different [[http://wiki.sensi.org/download/ns32k/a_out_5.pdf|a.out]] format than NetBSD. |
| |
| National Semiconductor's [[ns32ksoft#GENIX|GENIX 2]] was a System V Release 2 (SYSVR2) and Release 3 (SYSVR3) ports and used **COFF** **ns32k** executables. [[ns32ksoft#snx_gnx_crosstools|GNX 4]] cross tools also uses enhanced COFF format (with debug info, modules support e.t.c.). GNX4 cross-tools has a SYS5_2 and SYS5_3 targets. "GNX Language tools 4" book has "COFF Programmers Guide" chapter. | National Semiconductor's [[ns32ksoft#GENIX|GENIX 2]] was a System V Release 2 (SYSVR2) and Release 3 (SYSVR3) ports and used **COFF** **ns32k** executables. [[ns32ksoft#snx_gnx_crosstools|GNX 4]] cross tools also uses enhanced COFF format (with debug info, modules support etc.). GNX4 cross-tools has a SYS5_2 and SYS5_3 targets. "GNX Language tools 4" book has "COFF Programmers Guide" chapter. |
| |
| **ELF** was introduced in the System V Release 4 (SVR4) about 1990. There is no known any **ns32k** UNIX systems ported from the System V Release 4 codebase with ELF support (correct me). | **ELF** was introduced in the System V Release 4 (SVR4) about 1990. There are no known **ns32k** UNIX systems ported from the System V Release 4 codebase with ELF support (correct me). |
| |
| UNIX System V ELF specifications defines an "e_machine" identifier for ns32k: | UNIX System V ELF specifications defines an "e_machine" identifier for **ns32k**, but GNU Toolcains support for this target was never fully implemented: |
| ^Name^Value^Meaning^ | ^Name^Value^Meaning^ |
| |EM_NS32K|97|National Semiconductor 32000 series| | |EM_NS32K|97|National Semiconductor 32000 series| |
| http://www.sco.com/developers/gabi/latest/ch4.eheader.html | http://www.sco.com/developers/gabi/latest/ch4.eheader.html |
| |
| System V Release 3 introduced an early //static shared libraries// implementation with ''mkshlib'' and COFF files. SYSVR4 replaced it with more advanced //shared oblect// concept that required compiler and linker support (''ld.so'' module, GOT (Global Ofset Table), PLT, PIC (Position Independent Code) e.t.c. available with ELF only). | System V Release 3 introduced an early //static shared libraries// implementation with ''mkshlib'' and COFF files. SYSVR4 replaced it with more advanced //shared object// concept that required compiler and linker support (''ld.so'' module, GOT (Global Offset Table), PLT, PIC (Position Independent Code) etc. available with ELF only). |
| |
| **Sidenote:** An earlier GCC had support for many another ns32k targets: i.e. GCC 1.42 had a ''ns32k-ns-genix'' target (with output compatible with native GENIX ''as'' syntax, see [[ns32ksoft#GENIX]] ). Unfortunately ''ns32k-ns-genix'' was buggy in the GCC 2.0 and GCC 2.1 and was removed in the GCC 2.2 . | **Sidenote:** An earlier GCC had support for many another **ns32k** targets: i.e. GCC 1.42 had a ''ns32k-ns-genix'' target (with output compatible with native GENIX ''as'' syntax, see [[ns32ksoft#GENIX]] ). Unfortunately ''ns32k-ns-genix'' was buggy in the GCC 2.0 and GCC 2.1 and was removed in the GCC 2.2 . |
| |
| Early [[wp>Mach-O]] object file format also had a definition for NS32000 architecture. | Early [[wp>Mach-O]] object file format also had a definition for NS32000 architecture. |
| </code> | </code> |
| |
| This will install a new shining ''ns32k-pc532-netbsd-as'', ''ns32k-pc532-netbsd-ld'' e.t.c. into ''/opt/cross/'' . | This will install a newly generated binaries ''ns32k-pc532-netbsd-as'', ''ns32k-pc532-netbsd-ld'' etc. into ''/opt/cross/'' . |
| |
| Add this directory to the PATH (it's mandatory for GCC build): | Add this directory to the PATH (it's mandatory for GCC build): |
| https://sourceware.org/binutils/docs/as/index.html | https://sourceware.org/binutils/docs/as/index.html |
| |
| On the other hand, GNU ''as'' is just a "backend" for the GCC compiler and rarely used standalone. An examples of the GNU ''as'' usage may be found in the NetBSD ns32k for the pc532 port: in the bootloader, kernel ans some libraries call optimized for speed. | On the other hand, GNU ''as'' is just a "backend" for the GCC compiler and rarely used standalone. An examples of the GNU ''as'' usage may be found in the NetBSD ns32k for the pc532 port: in the bootloader, kernel and some libraries call optimized for speed. |
| |
| GCC compiler has an interesting option ''-S'' to produce an assembly ''.s'' file from the ''.c''. Resulting files are fully compatible with ''gas''. Also GCC may pass an options to ''as'' with ''-Wa'' option. To produce an assembler listing with source code lines: | GCC compiler has an interesting option ''-S'' to produce an assembly ''.s'' file from the ''.c''. Resulting files are fully compatible with ''gas''. Also GCC may pass an options to ''as'' with ''-Wa'' option. To produce an assembler listing with source code lines: |
| Precompiled binaries: http://wiki.sensi.org/download/ns32k/ns32k-netbsd-cross-i686-linux.tgz \\ | Precompiled binaries: http://wiki.sensi.org/download/ns32k/ns32k-netbsd-cross-i686-linux.tgz \\ |
| Includes binutils-2.27, gcc-3.4.6, NetBSD-1.5.3 headers. Prefix: ''/opt/cross'' \\ | Includes binutils-2.27, gcc-3.4.6, NetBSD-1.5.3 headers. Prefix: ''/opt/cross'' \\ |
| Binaris are compiled with GCC-3 for the i686 arhitecture and tested on the modern 64-bit Centos 7 (RHEL 7) \\ | Binaries are compiled with GCC-3 for the i686 architecture and tested on the modern 64-bit Centos 7 (RHEL 7) \\ |
| Since these are 32-bit -i686 binaries, install a ''glibc.i686'' package \\ | Since these are 32-bit -i686 binaries, install a ''glibc.i686'' package \\ |
| Just copy this TAR file to the root ''/'' and extract it with ''tar zxf'' \\ | Just copy this TAR file to the root ''/'' and extract it with ''tar zxf'' \\ |
| ns32k-pc532-netbsd-gcc -c -ffreestanding -o emutest.o emutest.c | ns32k-pc532-netbsd-gcc -c -ffreestanding -o emutest.o emutest.c |
| </code> | </code> |
| The option ''-ffreestanding'' disables "hosted" environment where ''main()'' is the first "user" function in the programm called by **crt0.o**. | The option ''-ffreestanding'' disables "hosted" environment where ''main()'' is the first "user" function in the program called by **crt0.o**. |
| |
| NOTE! GCC sometimes emits "built-in" functions like ''__udivdi3'' and requres "compiler runtime" library [[https://gcc.gnu.org/onlinedocs/gccint/Libgcc.html|libgcc]] for target processor. Just smplify your arithmetic expressions to avoid this. | NOTE! GCC sometimes emits "built-in" functions like ''__udivdi3'' and requires "compiler runtime" library [[https://gcc.gnu.org/onlinedocs/gccint/Libgcc.html|libgcc]] for target processor. Just smplify your arithmetic expressions to avoid this. |
| |
| Another useful GCC option is: ''-fomit-frame-pointer'' - it disables usage of the ''fp'' register (frame pointer) and use ''sp''-related (stack pointer) addressing for local variables like "old" compilers. GCC also supports ''-fpic'' option to compile PIC (Position-Independent Code) with ''sb''-related addressing ''0(_glblvar(sb))''. | Another useful GCC option is: ''-fomit-frame-pointer'' - it disables usage of the ''fp'' register (frame pointer) and use ''sp''-related (stack pointer) addressing for local variables like "old" compilers. GCC also supports ''-fpic'' option to compile PIC (Position-Independent Code) with ''sb''-related addressing ''0(_glblvar(sb))''. |
| -Ttext 0x0 -M -Map emutest.map -o emutest.bin emutest.o | -Ttext 0x0 -M -Map emutest.map -o emutest.bin emutest.o |
| </code> | </code> |
| | GNU ld [[https://sourceware.org/binutils/docs/ld.pdf|documentation]] . |
| | |
| To check binary file: | To check binary file: |
| <code> | <code> |
| ns32k-pc532-netbsd-objdump.exe -D -x --target=binary -m ns32k emutest.bin | ns32k-pc532-netbsd-objdump.exe -D -x --target=binary -m ns32k emutest.bin |
| </code> | </code> |
| GNU ld [[https://sourceware.org/binutils/docs/ld.pdf|documentation]] . | |
| |
| Run ''emul32k'' emulator and binary file: | Run ''emul32k'' emulator and binary file: |
| <code> | <code> |
| GDB 2.8.1: initial ns32k support: m-merlin.h m-umax.h m-npl.h ns32k-opcode.h ns32k-pinsn.c coffread.c \\ | GDB 2.8.1: initial ns32k support: m-merlin.h m-umax.h m-npl.h ns32k-opcode.h ns32k-pinsn.c coffread.c \\ |
| GDB 3.1: ns32k support: m-merlin.h m-umax.h m-npl.h ns32k-opcode.h ns32k-pinsn.c coffread.c \\ | GDB 3.1: ns32k support: m-merlin.h m-umax.h m-npl.h ns32k-opcode.h ns32k-pinsn.c coffread.c \\ |
| GDB 3.3: the same, more instructions, bugs correction e.t.c. \\ | GDB 3.3: the same, more instructions, bugs correction etc. \\ |
| ... \\ | ... \\ |
| GDB 4.0.1: uses [[wp>Binary_File_Descriptor_library|BFD]] \\ | GDB 4.0.1: uses [[wp>Binary_File_Descriptor_library|BFD]] \\ |