OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Dec 06, 2019 6:32 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: m68k bare bone
PostPosted: Mon Nov 18, 2019 4:05 pm 
Offline

Joined: Thu Oct 16, 2014 1:05 am
Posts: 9
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:
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


Top
 Profile  
 
 Post subject: Re: m68k bare bone
PostPosted: Mon Nov 18, 2019 4:51 pm 
Offline
Member
Member
User avatar

Joined: Thu Oct 13, 2016 4:55 pm
Posts: 414
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:
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:
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


Top
 Profile  
 
 Post subject: Re: m68k bare bone
PostPosted: Tue Nov 19, 2019 6:31 am 
Offline

Joined: Thu Oct 16, 2014 1:05 am
Posts: 9
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 ?


Top
 Profile  
 
 Post subject: Re: m68k bare bone
PostPosted: Tue Nov 19, 2019 9:11 am 
Offline
Member
Member
User avatar

Joined: Thu Nov 16, 2006 12:01 pm
Posts: 7429
Location: Germany
You might want to check out...

Code:
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.

_________________
Every good solution is obvious once you've found it.


Top
 Profile  
 
 Post subject: Re: m68k bare bone
PostPosted: Tue Nov 19, 2019 12:13 pm 
Offline
Member
Member
User avatar

Joined: Thu Oct 13, 2016 4:55 pm
Posts: 414
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


Top
 Profile  
 
 Post subject: Re: m68k bare bone
PostPosted: Wed Nov 20, 2019 2:46 am 
Offline
Member
Member
User avatar

Joined: Thu Nov 16, 2006 12:01 pm
Posts: 7429
Location: Germany
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.

_________________
Every good solution is obvious once you've found it.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group