How to use m68k GCC with the Atari Jaguar and WinXP/7/8

Let's get coding!

Moderator: a31chris

Post Reply
User avatar
a31chris
Jaguar MOD
Posts: 894
Joined: Mon Apr 01, 2013 7:09 am

How to use m68k GCC with the Atari Jaguar and WinXP/7/8

Post by a31chris » Mon Feb 24, 2014 8:24 pm

If you want to use the m68k GCC with the Jaguar and Windows NT/XP and newer, and get up and running fast, first install the Belboz SDKs for XP (Jagdev102) and make sure SMAC(SubQMods Macro Assembler) is updated.

This setup will use the vlink linker included with the XP SDK package since it makes possible the ability to convert different object formats to a single format at the end of the link along with supporting ELF and the Jaguar's GPU. If you're an entrenched SLN user you're on your own.

After that install the m68k ELF GCC cross-compiler for Windows from here:
http://gnutoolchains.com/m68k-elf/

To start you off I've included a zip of the entire directory I used. It includes everything needed to work with this for either ELF or standard Jaguar bjl/emulator a.out output with the change of practically only a single Makefile line. Later you can of course take these files and cannibalize them to your hearts delight. Linker scripts are available in the Hello2 download for converting back and forth if that's all you need. (JagELFLS for converting everything to ELF and JagbinLS for converting everything to standard a.out bin)

Once you get this setup wherever you wish( for instance mine was in my gcc m68k elf folder) you can choose which type of build you want. In the makefile are two lines, one of which will be remarked out( # ).

Code: Select all

jag : $(OFILES)
									  vlink -brawbin1 -EB -TJagbinls $(OFILES) $(LINKEROPT) -o jag.bin
						  # vlink -t -n -EB -belf32m68k -TJagElfls $(OFILES) $(LINKEROPT) -o jagElf.bin
Here it comes by default ready to convert the ELF output to standard Jaguar a.out that can be run on an emulator like Jagulator.

Debugging using gdb and Skunkboard
If you have a skunkboard and wish to debug with GCC you can enable debugging '-g' in the compiler line and swap out the remarked out line with the unremarked line.

Code: Select all

jag : $(OFILES)
									  vlink -t -n -EB -belf32m68k -TJagElfls $(OFILES) $(LINKEROPT) -o jagElf.bin
								 #vlink -brawbin1 -EB -TJagbinls $(OFILES) $(LINKEROPT) -o jag.bin
Its also recommended to remove any optimization from the compile process while debugging:

Code: Select all

m68k-elf-gcc-4.8.0 -c -m68000 -s -DJAGUAR -O2 -o jag.o jag.c
Change the O2 to O0. 'Optimization level Zero.'( Oh-zero. NOT two zeroes.) Rather than 'optimization level 2'(O2).

Make sure to prepare the proper makefile spacing for the first vlink line and its ready to make a debug capable ELF file for the Skunkboard to upload and step through.

Beyond that if you dont have a skunkboard you can still use the GCC for C++ theoretically on the Jag or Java?? or whatever else GCC may support. In theory. Nothing beyond standard C has been tested.

After downloading the 'Hello2' directory then typing 'make clean' and then 'make' you should see something like this:

Code: Select all

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

c:\stuff\m68k-elf\hello2>make clean

Microsoft (R) Program Maintenance Utility Version 1.50
Copyright (c) Microsoft Corp 1988-94. All rights reserved.

del *.o
del *.bin

c:\stuff\m68k-elf\hello2>make

Microsoft (R) Program Maintenance Utility Version 1.50
Copyright (c) Microsoft Corp 1988-94. All rights reserved.

smac -fb startup.s
startup.s[82]: Warning: GPU/DSP code outside of absolute section
m68k-elf-gcc-4.8.0 -c -m68000 -s -DJAGUAR -O2 -o jag.o jag.c
vlink -brawbin1 -EB -TJagbinls startup.o jag.o -L/jaguar/lib -lvbcc -o
jag.bin

c:\stuff\m68k-elf\hello2>
Here is a video of debugging with the Skunkboard. You can ignore all the Cygwin Coldfire stuff and just skip to the actual debugging and step through procedures. Use LOAD instead of RUN etc.

http://www.youtube.com/watch?v=BFKp00xROcU

This is showing a quick way to get up and running fast with GCC using the Belboz SDKs since all the setpaths will be done for vlink, smac, the Jaguar libs and GCC etc by the respective install programs so your system will just know where to find everything right away. Of course this setup is kinda cluttery and will drive some people nuts. This is just a quick proof of concept and in no way the most elegant solution. Beyond this you're on your own setting up your own dev enviroment with its own unique setpaths and arrangements more to your individual tastes.

For using standard C without ELF it is strongly recommended you use the basic vbcc compiler setup. Since the proceeding post after this one outlines the object file NAMES differences between a.out and ELF compilers I do not know if there would be some kind of issue with converting ELF to a.out on a regular basis. Proceed at your own risk. (I think it will probably be fine as I would suspect that vlink will take care of the object names differences issue but just a word of caution and something to be aware of.)

NOTE: As of the time of this posting the GCC was at 4.8.0 and the makefile calls that version. If by the time you read this and install it there is a new version then you will need to update the makefile line to reflect the change.

Please let me know if anything in these instructions is unclear or any problems are run into.


Thanks once again to..

Tursi for his patience...

Frank Wille for his awesome linker and his patience... lots of patience. Poor bastard.

Belboz for the original SDKs and getting Mr. Wille to make his linker compatible with the Jaguar in the first place.

And for the rest of you for bearing with me through my learning experiences.


That lion dude is awesome.
Attachments
hello2.zip
working Jaguar ELF hello world directory. Type 'make clean' at the command prompt then type 'make'.
(22.6 KiB) Downloaded 532 times
What came after the Jaguar was the PS1 which for all it's greatness, ushered in corporate development and with it the bleached, repetitive, bland titles which for the most part we're still playing today. - David Wightman

User avatar
a31chris
Jaguar MOD
Posts: 894
Joined: Mon Apr 01, 2013 7:09 am

Re: M68k GCC/GDB and Skunkboard

Post by a31chris » Tue Feb 25, 2014 6:57 am

While getting Belboz's original 'Hello Jag Users!' C source to work with the m68k ELF GCCs there were names differences I had to fix for it to work with the ELF compiler. This modified version of the "Hello Jag Users!" is in the hello2 directory zip I've included in the preceding post. And here is what we learned was needed to get it to work along with the differences between ELF compiler output and standard a.out output thanks to Frank Wille:

There are unresolved symbols here with ___main and __main etc.(What appears to be two and three underscores etc.) So I've gotta resolve those and if there is no quick formula for it I can just do it trial and error.
There are no underscores added to a symbol when creating ELF objects. The compiler usually knows that it is working in an ELF environment.

The reason for those underscores was to avoid name conflicts, e.g. with CPU registers in the assembler. When switching to ELF the assembler expects CPU registers to have a '%' prefix (e.g. %d0, %d1). So the underscore in front of symbols is no longer needed. Vbccm68k switches into ELF mode (generates symbols without a leading underscore) with the -elf option.

vasmm68k expects ELF registers, with '%' suffix, by specifying -elfregs.

The gcc from the m68k-elf toolchain is expected to generate symbols without leading underscore, as it had been configured for ELF.
You have two options:

1. Rework the startup code and library. Modify the assembler sources to
export symbols without a leading underscore, and recompile C sources for ELF.
This is the cleaner option, but it requires a lot of work.

2. Let vlink fix the symbol names of some objects. For example, when just
jag.o exports symbols without a leading underscore, you can tell vlink
to add them:

Code: Select all

 vlink -belf32m68k -n -TJagElf -EB startup.o -set-adduscore jag.o
  -clr-adduscore -L/jaguar/lib -lvbcc -o jag.bin
Underscores will be added to the symbols from all objects between
-set-adduscore and -clr-adduscore. Similar options exist for removing
underscores: -set-deluscore, -clr-deluscore.

Code: Select all

Joining selected sections:
Warning 22: Attributes of section .data were changed from r--- in Linker  
Script <JagElf> to rw-- in jag.o.
I don't know what's within JagElf, but I would guess that the first
section vlink linked into .data was a read-only section. Then it links
a data section from jag.o, which is read-write (normal for .data).

Running vlink with -M option will give you a map-file with some more
information about section mapping.

Code: Select all

 Warning 64: Section jag.o(.comment) was not recognized by target linker  
> script.
Add .comment to your linker script (JagElf). For example at the end:

Code: Select all

.comment      0 : { *(.comment) }

Regards,

--
Frank Wille
What came after the Jaguar was the PS1 which for all it's greatness, ushered in corporate development and with it the bleached, repetitive, bland titles which for the most part we're still playing today. - David Wightman

User avatar
a31chris
Jaguar MOD
Posts: 894
Joined: Mon Apr 01, 2013 7:09 am

Updated version of VLINK available

Post by a31chris » Tue Aug 19, 2014 5:21 am

I have compiled the latest vlink. I will put it in the first post here and I recommend everyone update theirs. Its version 14c and will be named that. You can rename it to vlink and overwrite the one in the bin directory. However I recommend keeping it as 14c and rename the call in the makefile to vlink14c. When you're confident everything works well then update/overwrite the old one.
What came after the Jaguar was the PS1 which for all it's greatness, ushered in corporate development and with it the bleached, repetitive, bland titles which for the most part we're still playing today. - David Wightman

User avatar
a31chris
Jaguar MOD
Posts: 894
Joined: Mon Apr 01, 2013 7:09 am

VLINK: To rename or not to rename

Post by a31chris » Wed Aug 20, 2014 5:41 pm

I think I'm actually just going to keep the names of the versions in my makefile. I kinda like knowing what version I'm using of things so I don't have to guess if it comes up.
What came after the Jaguar was the PS1 which for all it's greatness, ushered in corporate development and with it the bleached, repetitive, bland titles which for the most part we're still playing today. - David Wightman

User avatar
a31chris
Jaguar MOD
Posts: 894
Joined: Mon Apr 01, 2013 7:09 am

Re: How to use m68k GCC with the Atari Jaguar and WinXP/7/8

Post by a31chris » Mon Dec 01, 2014 2:02 am

vlink 14D is now available. It's in the original download spot in place of the older version. This one has Jaguar specific updates. Recommend everyone updates to this new version. Same suggestions apply. Do not delete old one until new one is proven to be cool.
What came after the Jaguar was the PS1 which for all it's greatness, ushered in corporate development and with it the bleached, repetitive, bland titles which for the most part we're still playing today. - David Wightman

User avatar
a31chris
Jaguar MOD
Posts: 894
Joined: Mon Apr 01, 2013 7:09 am

Re: How to use m68k GCC with the Atari Jaguar and WinXP/7/8

Post by a31chris » Mon Jan 05, 2015 4:27 am

An add-on. All the modifications I did to the hello world file may be unnecessary. Chilly Willy advises that the elf compiler can be told to add the leading underscores so there won't be any unresolved symbol error.
The primary things needed to get it to build and link were to use "-fleading-underscore" in the cflags (otherwise you get a SHITLOAD of undefined symbol errors), and set the linker flags like this "VLN_FLAGS = -nostdlib -Ttext 0x4000 -EB -Bstatic -brawbin1 -minalign 4". That "-minalign 4" is particularly important or your data winds up not aligned to phrases.
Also notice the '-malign 4' recommendation. That should be implemented as well.

This is obviously a much better, more permanent way to do what is discussed above and what I shall recommend going forward.

On the new vlink versions -minalign 4 MUST be used apparently or for instance even the HELLO JAG USERS sample program will result in a black blank screen.
What came after the Jaguar was the PS1 which for all it's greatness, ushered in corporate development and with it the bleached, repetitive, bland titles which for the most part we're still playing today. - David Wightman

User avatar
a31chris
Jaguar MOD
Posts: 894
Joined: Mon Apr 01, 2013 7:09 am

Re: How to use m68k GCC with the Atari Jaguar and WinXP/7/8

Post by a31chris » Tue Jan 06, 2015 7:37 am

It also appears that in the latest vlink to convert ELF objects to a.out for linking with the gpu a.out objects the linker script for that is no longer needed.

Whether the other linker script is still needed to convert all objects to ELF is unknown right now.
What came after the Jaguar was the PS1 which for all it's greatness, ushered in corporate development and with it the bleached, repetitive, bland titles which for the most part we're still playing today. - David Wightman

User avatar
a31chris
Jaguar MOD
Posts: 894
Joined: Mon Apr 01, 2013 7:09 am

Jaguar GPU risc ELF format created and support. VLINK15a

Post by a31chris » Tue Jan 27, 2015 6:20 am

New version of Vlink15a 32bit Windows build is up. Improvements Jaguar gpu risc ELF format created and supported.
Links for those who wish to build their own 64bit builds:

http://sun.hasenbraten.de/vlink/index.php?view=source
What came after the Jaguar was the PS1 which for all it's greatness, ushered in corporate development and with it the bleached, repetitive, bland titles which for the most part we're still playing today. - David Wightman

User avatar
a31chris
Jaguar MOD
Posts: 894
Joined: Mon Apr 01, 2013 7:09 am

Re: How to use m68k GCC with the Atari Jaguar and WinXP/7/8

Post by a31chris » Tue Apr 19, 2016 2:59 am

All the reworking of the original sources for leading underscores is now obsolete. The command line option -fleading-underscore solves this problem with GCC completely.
What came after the Jaguar was the PS1 which for all it's greatness, ushered in corporate development and with it the bleached, repetitive, bland titles which for the most part we're still playing today. - David Wightman

Post Reply