Help with compilation on Linux

Ask anything your want about Megadrive/Genesis programming.

Moderator: BigEvilCorporation

Post Reply
edenist
Newbie
Posts: 8
Joined: Mon Jun 23, 2014 12:15 pm
Location: Melbourne, Australia
Contact:

Help with compilation on Linux

Post by edenist » Thu Mar 12, 2015 12:15 am

Hi everyone,

I've been keen on MD development for some time and have now taken the plunge and am shoulder deep in documentation and information. [And loving it, btw :) ].
As a bit of background, I'm fairly competent in an array of languages, I'd done some z80 programming about 10 years back, so am not entirely new to ASM. That being said, I am wanting to get a complete understanding of the MD system from the ground up.

I run a linux system, and I've been setting up my toolchain for building the ROM images. I've built the gendev/sgdk project, and that is working fine. I've compiled some code which has booted successfully on my MD system.

While the SGDK is fantastic for streamlining building projects, I would like to get a more raw taste of the intialisation and startup protocols of the MD and how the code all goes together. I'd like to have my own init code containing the ROM header and startup, and compile it manually.

I have been following the linux-specific instructions at http://darkdust.net/writings/megadrive. I didn't rebuild a whole new m68k toolchain, as I can just use the one built for gendev/SGDK. So I've just been following his code.

Now, to my possible problem. When I compile his code using his sample code , I obtain a .bin file, however it does not run on the MD [hardware and emulator]. Taking a look in a hex editor, my compiled binary is exactly the same to the included one, except it has an extra 18 bytes of zeroes at the end. To confirm, even the included 'firststeps.bin' does not boot on my MD.

The sample code is split up into init.S [the ROM header and initialisations] and firststeps.S [VDP test code]. I put the firststeps.S file into a blank SGDK project and hit make. The binary produced boots up no problem with the SGDK boot code.

Am I correct in assuming the init code on darkdust is not correct to produce a bootable ROM? Or is there something wrong with how I am building the ROM?

Here is my output when manually compiling...

Code: Select all

m68k-elf-as -m68000 init.S -o init.o
m68k-elf-as -m68000 firststeps.S -o firststeps.o
m68k-elf-ld init.o firststeps.o --oformat binary -o firststeps_2.bin
m68k-elf-ld: warning: cannot find entry symbol _start; defaulting to 0000000080000000
Is the 0x80000000 correct for m68k?

I have noticed that when SGDK builds, there are some scripts which run with m68k-elf-as, are these required?

Basically, what I am looking for is a way to compile small amounts of code like that seen on darkdust, to give me the opportunity to poke and prod at the MD while I'm learning. Finding example code which works on linux with the GNU toolchain is proving difficult.

Would appreciate and assistance and advice.

Thanks! :-)

Charles MacDonald
Very interested
Posts: 292
Joined: Sat Apr 21, 2007 1:14 am

Re: Help with compilation on Linux

Post by Charles MacDonald » Thu Mar 12, 2015 2:03 am

You need to specify a linker script (e.g. -T mylinkerscript.ld). You can use the one included with SGDK called "md.ld". This will resolve the missing symbol "_start".

https://code.google.com/p/sgdk/

edenist
Newbie
Posts: 8
Joined: Mon Jun 23, 2014 12:15 pm
Location: Melbourne, Australia
Contact:

Post by edenist » Thu Mar 12, 2015 2:35 am

Thanks, adding the linker script resolved the missing symbol error.

I have a feeling the init.S code included in this sample is incorrect, hence why it is failing to boot [the included .bin from the tutorial site also doesn't work].

I'll try using the init header from sgdk and see if that works instead.

greatkreator
Very interested
Posts: 158
Joined: Sat May 12, 2012 7:37 pm
Location: Ukraine

Post by greatkreator » Thu Mar 12, 2015 4:02 am

For Linux I prefer this one:

viewtopic.php?t=889

And the sources of the library you can add from sgdk.
Linux is more suitable for Sega development.
I do it only on Linux but currently I am tied to some Windows software that works very bad in emulation on Linux and I have to suffer of win mingw buggy compiler which fail each 7-8 compilations.

Linux's "native" gcc compiles in milliseconds (comparing to few seconds or even more for large projects for mingw gcc). As well as those annoying permanent memory failures of mingw gcc on windows.

Post Reply