Recent

Author Topic: help needed - m68k embedded based on 3.2.2  (Read 6885 times)

parc_de

  • New member
  • *
  • Posts: 7
help needed - m68k embedded based on 3.2.2
« on: February 17, 2022, 05:08:13 pm »
Is there any help text available how to start on this platform ? I installed the newest 3.2.2 compiler (precompiled), I installed the m68k cross compler (precompiled) - all stuff under ubuntu 18.04.

I would need a step-by-step guide how to build a simple binary for an embedded m68k target ... so I could at least find out the next steps.

The target would be  - later - an own developed mc68k system.

Thanks

parc_de

  • New member
  • *
  • Posts: 7
Re: help needed - m68k embedded based on 3.2.2
« Reply #1 on: February 19, 2022, 07:00:27 pm »
Ok - I might be totally wrong - but as long as I understand:

- you have to create an own system.pas (which I have done now)
- you have to create a prt0.s file (your startup code - whch I have done now)
- you must use the default linker from gnu (no vasm or vlink)
- you have to define the target as embedded

so, I get the output. I can link all stuff ... but now the big question. I get an elf output, but I need a hex output to program a ROM ...

 So, my question is now: m68k platform, embedded ... how can I get a hex output file ?

Marten

AlexTP

  • Hero Member
  • *****
  • Posts: 2384
    • UVviewsoft
Re: help needed - m68k embedded based on 3.2.2
« Reply #2 on: February 19, 2022, 07:27:21 pm »
Did you try FPCupdeluxe?
On its "Cross" tab you can check:

CPU: m68k
OS: embedded

FPK

  • Moderator
  • Full Member
  • *****
  • Posts: 118
Re: help needed - m68k embedded based on 3.2.2
« Reply #3 on: February 19, 2022, 09:33:07 pm »

 So, my question is now: m68k platform, embedded ... how can I get a hex output file ?


Run objcopy with -O ihex ...

parc_de

  • New member
  • *
  • Posts: 7
Re: help needed - m68k embedded based on 3.2.2
« Reply #4 on: February 19, 2022, 10:29:41 pm »

 So, my question is now: m68k platform, embedded ... how can I get a hex output file ?


Run objcopy with -O ihex ...

Yes, actually I found this some minutes ago, but it it says for this command:

m68k-none-elf/bin/objcopy -O ihex test.elf test.hex

the following:

/home/mf/fpc-3.2.2/m68k-none-elf/bin/objcopy: error: the input file 'test.elf' has no sections

Hmm ?

FPK

  • Moderator
  • Full Member
  • *****
  • Posts: 118
Re: help needed - m68k embedded based on 3.2.2
« Reply #5 on: February 20, 2022, 10:03:18 am »
Wrong/no linker script? Check the .elf with objdump -x

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: help needed - m68k embedded based on 3.2.2
« Reply #6 on: February 20, 2022, 02:03:56 pm »
- you have to create an own system.pas (which I have done now)

The embedded target already provides a System unit.

parc_de

  • New member
  • *
  • Posts: 7
Re: help needed - m68k embedded based on 3.2.2
« Reply #7 on: February 20, 2022, 09:17:20 pm »
Well, its more than difficult to get through this topic - too many documentation pages with old content and not valid any more.

I just wanted to check, if I could get the following program to build an executable:

Code: Pascal  [Select][+][-]
  1. program test;
  2.  
  3. var
  4.   a: Int32;
  5.  
  6. begin
  7.   a := 2;
  8.   a := a + 2 + 2;
  9. end.

with the following command:

ppcross68k test.pas -O1 -a -Cp68000 -Tembedded -e/home/mf/fpc-3.2.2/m68k-none-elf/bin

The hardware has nothing to do with linux or other operating system. Its bare metal programing ... embedded.

I get a test.elf, but with no content. For all the other files (system.pas) the compiler produces *.o files. The test.o file seems to have a good content:

Disassembly of section .text.n_main:

Code: Pascal  [Select][+][-]
  1. 00000000 <main>:
  2.    0:   4e56 0000       linkw %fp,#0
  3.    4:   4eb9 0000 0000  jsr 0 <main>
  4.    a:   7002            moveq #2,%d0
  5.    c:   7006            moveq #6,%d0
  6.    e:   4eb9 0000 0000  jsr 0 <main>
  7.   14:   4e5e            unlk %fp
  8.   16:   4e75            rts

and this is the test.s:

Code: Pascal  [Select][+][-]
  1.         .file "test.pas"
  2. # Begin asmlist al_procedures
  3.  
  4. .section .text.n_main
  5.         .balignw 4,0x4e71
  6. .globl  PASCALMAIN
  7. PASCALMAIN:
  8. .globl  main
  9. main:
  10.         link.w  %a6,#0
  11.         jbsr    fpc_initializeunits
  12.         moveq.l #2,%d0
  13.         moveq.l #6,%d0
  14.         jbsr    fpc_do_exit
  15.         unlk    %a6
  16.         rts
  17. .Le0:
  18. ....


FPK

  • Moderator
  • Full Member
  • *****
  • Posts: 118
Re: help needed - m68k embedded based on 3.2.2
« Reply #8 on: February 20, 2022, 09:41:06 pm »
Well, its more than difficult to get through this topic - too many documentation pages with old content and not valid any more.

Which ones? As m68k-embedded was never officially supported so far, I doubt there are official docs about?

Quote
The hardware has nothing to do with linux or other operating system. Its bare metal programing ... embedded.

I get a test.elf, but with no content. For all the other files (system.pas) the compiler produces *.o files. The test.o file seems to have a good content:


Yes, compiler/systems/t_embed.pas creates no linker script for m68k, see line 259+.


parc_de

  • New member
  • *
  • Posts: 7
Re: help needed - m68k embedded based on 3.2.2
« Reply #9 on: February 21, 2022, 07:34:23 am »

Yes, compiler/systems/t_embed.pas creates no linker script for m68k, see line 259+.

So, this answer seems to indicate, that it is possible to get it working ? Do you have an example how such a linker script may look like for this simple example - so I could build it by hand or at least get a starting point ?

Marten

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: help needed - m68k embedded based on 3.2.2
« Reply #10 on: February 21, 2022, 01:51:43 pm »

Yes, compiler/systems/t_embed.pas creates no linker script for m68k, see line 259+.

So, this answer seems to indicate, that it is possible to get it working ? Do you have an example how such a linker script may look like for this simple example - so I could build it by hand or at least get a starting point ?

As a first step you could copy the part inside the {$ifdef i386} … {$endif i386} as a {$ifdef m68k} … {$endif m68k} and work from there. To speed things up you can simply compile the compiler from within Lazarus by opening compiler/ppc68k.lpi and then using compiler/m68k/pp instead of compiler/ppcross68k to compile your main program (as long as you only work inside t_embed you shouldn't need to recompile the RTL).

parc_de

  • New member
  • *
  • Posts: 7
Re: help needed - m68k embedded based on 3.2.2
« Reply #11 on: February 21, 2022, 09:16:25 pm »

As a first step you could copy the part inside the {$ifdef i386} … {$endif i386} as a {$ifdef m68k} … {$endif m68k} and work from there. To speed things up you can simply compile the compiler from within Lazarus by opening compiler/ppc68k.lpi and then using compiler/m68k/pp instead of compiler/ppcross68k to compile your main program (as long as you only work inside t_embed you shouldn't need to recompile the RTL).

Ok, I deinstalled all old versions (Linux Mint  19) and downloaded the newest Lazarus packages. I downloaded the 3.3.1 trunc source code and yes indeed, I could create a pp binary and this seems to be a more interactive environment to work with.

I created the {$ifdef m68k} … {$endif m68k} sections in the source code and the test.elf looks now very different - but the application is still not included. So a small step is done - the application is still not in the test.elf ...

Any further tips for the next steps / documentation to read ?

Thanks,

Marten

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: help needed - m68k embedded based on 3.2.2
« Reply #12 on: February 22, 2022, 09:41:15 am »
I created the {$ifdef m68k} … {$endif m68k} sections in the source code and the test.elf looks now very different - but the application is still not included. So a small step is done - the application is still not in the test.elf ...

Any further tips for the next steps / documentation to read ?

Because nothing is calling the main function (aka PASCALMAIN) yet. You need to find out how the system you want to start on transfers control to your code (e.g. on i386 one can use the Multiboot specification which is covered by rtl/embedded/i386/multiboot.pp, on the Pi the firmware loads the code at either $8000 (ARM) or $80000 (Aarch64) and then starts executing from there) and then you need to add a function with public name _START (cause that is used as entry at the first line of the link script) which in turn jumps to PASCALMAIN. You can look at the above mentioned multiboot.pp or rtl/embedded/aarch64/raspi3.pp for an inspiration how to do this.

parc_de

  • New member
  • *
  • Posts: 7
Re: help needed - m68k embedded based on 3.2.2
« Reply #13 on: February 22, 2022, 01:48:37 pm »

Because nothing is calling the main function (aka PASCALMAIN) yet. You need to find out how the system you want to start on transfers control to your code (e.g. on i386 one can use the Multiboot specification which is covered by rtl/embedded/i386/multiboot.pp, on the Pi the firmware loads the code at either $8000 (ARM) or $80000 (Aarch64) and then starts executing from there) and then you need to add a function with public name _START (cause that is used as entry at the first line of the link script) which in turn jumps to PASCALMAIN. You can look at the above mentioned multiboot.pp or rtl/embedded/aarch64/raspi3.pp for an inspiration how to do this.

THAT was the information: _START. Adding _START at the beginning of my new runtime library code (prtl0.s) solved most of the problems. The generated code was there in the test.elf output - though relocated for a wrong address, but thats a progress.

Thank you !


PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: help needed - m68k embedded based on 3.2.2
« Reply #14 on: February 23, 2022, 09:09:38 am »
The generated code was there in the test.elf output - though relocated for a wrong address, but thats a progress.

I think you can control that with the . = 0x100000 at the start of the SECTIONS block of the linker script. If that works you could in theory use the imagebase global instead of a hard coded value. This variable is set by -WBxxx (though you'll need to allow that option for system_m68k_embedded (in compiler/options.pas at around line 2756)).

 

TinyPortal © 2005-2018