Page 1 of 1

m68k bare bone

Posted: Mon Nov 18, 2019 4:05 pm
by iliak
Hi

I want to make a binary file (aka a rom) to use as a ROM in a 68000 chipset. I built my compiler toolchain (m68k-amigaos-*) and it produces nice elf files, so it should be Ok on this side (I hope...).

The gitlab project can be reached here : https://gitlab.mimicprod.net/os/miga.
The project contains the asm bootstrap code (src/bootstrap/bootstrap.s) which calls some C code. The goal is to mimic the Amiga ROM logic. So I made some shared libraries (exec.library, dos.library, graphics.library...) in C (src/libraries & src/devices). And now, I want them to be included in the ROM.

The linker file is has follow (src/bootstrap/linker.ld):

Code: Select all

MEMORY {
    ram (rwx): ORIGIN = 0x0, LENGTH = 15M
    rom (rx): ORIGIN = 0xF00000, LENGTH = 1M
};

PROVIDE (_stack = ORIGIN(ram) + LENGTH(ram));

ENTRY (_reset_handler);

SECTIONS
{
    .text : {
        *(.text*)
        *(.data*)
        *(.bss*)
        . = ALIGN(4);
    } >rom
};

The final output is an AmigaOS "loadseg()ble executable/binary" that I convert to a binary file with the following command:

m68k-amigaos-objcopy -O binary -j .text bootstrap rom.bin

The disassembly output is correct, but only the bootstrap glue is present, no other piece of code of the libraries.


My question is how to configure CMake to make a binary file which contains every sections of the code this way :

- bootstrap.s
- exec.library code
- dos.library code
- graphics.library code
- ....

AND relocate all the above code at memory location 0xF00000 ?

Made shorter, how to build a m68k bare bone in CMake ;)

Iliak

Re: m68k bare bone

Posted: Mon Nov 18, 2019 4:51 pm
by bzt
Hi,

First of all, good job! It's good to see there are still such projects like yours!
iliak wrote:My question is how to configure CMake to make a binary file which contains every sections of the code this way :
Short answer, you don't. CMake is not capable of doing that. CMake will create Makefiles (or whatever), which will call a linker (for Clang that would most likely be LLVM-lld). It is the linker's job to do what you want, using the linker script you provide to it.
iliak wrote:AND relocate all the above code at memory location 0xF00000 ?
Your linker script looks OK to me (you have added "> rom", and you've included all sections), but it's been decades since I last linked a ROM. But I'm certain it's the linker and the linker script that needs your attention, not CMake. First, I suggest to check the exact command. Is the linker called with all the .o files, or only just one? Is the linker script passed to the linker? Second, check if the ELFs really have those sections (try readelf in your toolchain). Once you can run ld from the command line correctly, it is only then when I suggest to move to CMake to generate the exact same command.

Moreover,

Code: Select all

m68k-amigaos-objcopy -O binary -j .text bootstrap rom.bin
and that you have "bootstrap.s" suggests that you're not linking properly, and you only convert the bootstrap ELF into rom.bin. There should be something like:

Code: Select all

m68k-amigaos-ld -L linker.lds bootstrap.o exec.o graphic.o... -o rom.elf
m68k-amigaos-objcopy -O binary -j .text rom.elf rom.bin
Ah, another thing. This command removes everything except the text segment. Did you redirect all your sections into the text segment in the linker script? Otherwise this command will wipe out everything that's not strictly code.

Cheers,
bzt

Re: m68k bare bone

Posted: Tue Nov 19, 2019 6:31 am
by iliak
So all the libraries and the bootstrap codes should be built as shared library and use the linker with the good linker script and the "-objcopy command line" to build the ROM ?

Just to be sure, the linker script produces a code that can be loaded at 0xF00000 ?

Re: m68k bare bone

Posted: Tue Nov 19, 2019 9:11 am
by Solar
You might want to check out...

Code: Select all

SET_TARGET_PROPERTIES( <target name>  PROPERTIES  LINK_FLAGS "..." )
...to set custom linker options (like using a specific linker script) for a specific target (like your ROM image).

And a special slap on the shoulder for working on Amiga things. I still miss that thing, it was the all-around best computing experience I ever had.

Re: m68k bare bone

Posted: Tue Nov 19, 2019 12:13 pm
by bzt
iliak wrote:So all the libraries and the bootstrap codes should be built as shared library and use the linker with the good linker script and the "-objcopy command line" to build the ROM ?
ELF doesn't necessarily mean shared library. I think you should simply link the objects together, or at least I'm certain your rom image won't contain any library code if you only convert bootstrap into rom.

If memory serves me, AmigaOS used no standard shared libraries, but versioned memory images (a library could be loaded in different versions) and jump tables in caller processes to the appropriate functions inside those memory images. If I remember correctly, you could have process A having the address of a function in library 1.0 in its jump table, and process B having the address of the same function in library 2.0. But that was a long time ago, I might be wrong about this. On a sidenote, you can implement your own dynamic linker based on ELF structures, you don't need to recreate AmigaOS ABI if you don't want to (imho it's easier to implement what you already have in ELF structures, GOT, PLT etc.).
iliak wrote:Just to be sure, the linker script produces a code that can be loaded at 0xF00000 ?
You can tell that if you use readelf on the final ELF file before you convert it into rom with objconv.
Solar wrote:And a special slap on the shoulder for working on Amiga things. I still miss that thing, it was the all-around best computing experience I ever had.
Yeah, so true! The hardware as well as the software were way before their time.

Cheers,
bzt

Re: m68k bare bone

Posted: Wed Nov 20, 2019 2:46 am
by Solar
I wrote a little piece on AmigaOS' LibraryBase scheme. Disclaimer, I never actually used Amiga libraries (I just wasn't that good with C/C++ by the time, and stuck to ARexx scripts), but I've read (most of) the ROM Kernel Manuals, and thought the scheme interesting enough to put up that description.