help needed - m68k embedded based on 3.2.2 lazarus / 68-Other OS ---------------------------------------------------------------------- parc_de · 2022-02-17 16:08 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 · 2022-02-19 18:00 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 · 2022-02-19 18:27 Did you try FPCupdeluxe? On its "Cross" tab you can check: CPU: m68k OS: embedded ---------------------------------------------------------------------- FPK · 2022-02-19 20:33 Quote from: parc_de on February 19, 2022, 07:00:27 pm  So, my question is now: m68k platform, embedded ... how can I get a hex output file ? Run objcopy with -O ihex ... ---------------------------------------------------------------------- parc_de · 2022-02-19 21:29 Quote from: FPK on February 19, 2022, 09:33:07 pmQuote from: parc_de on February 19, 2022, 07:00:27 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 · 2022-02-20 09:03 Wrong/no linker script? Check the .elf with objdump -x ---------------------------------------------------------------------- PascalDragon · 2022-02-20 13:03 Quote from: parc_de on February 19, 2022, 07:00:27 pm- you have to create an own system.pas (which I have done now) The embedded target already provides a System unit. ---------------------------------------------------------------------- parc_de · 2022-02-20 20:17 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program test; var  a: Int32; begin  a := 2;  a := a + 2 + 2;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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 00000000
:   0:   4e56 0000       linkw %fp,#0   4:   4eb9 0000 0000  jsr 0
   a:   7002            moveq #2,%d0   c:   7006            moveq #6,%d0   e:   4eb9 0000 0000  jsr 0
  14:   4e5e          unlk %fp  16:   4e75            rts and this is the test.s: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i         .file "test.pas"# Begin asmlist al_procedures .section .text.n_main      .balignw 4,0x4e71.globl  PASCALMAINPASCALMAIN:.globl  mainmain:      link.w  %a6,#0        jbsr    fpc_initializeunits        moveq.l #2,%d0        moveq.l #6,%d0        jbsr    fpc_do_exit        unlk  %a6        rts.Le0:.... ---------------------------------------------------------------------- FPK · 2022-02-20 20:41 Quote from: parc_de on February 20, 2022, 09:17:20 pmWell, 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? QuoteThe 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 · 2022-02-21 06:34 Quote from: FPK on February 20, 2022, 09:41:06 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 ? Marten ---------------------------------------------------------------------- PascalDragon · 2022-02-21 12:51 Quote from: parc_de on February 21, 2022, 07:34:23 amQuote from: FPK on February 20, 2022, 09:41:06 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 · 2022-02-21 20:16 Quote from: PascalDragon on February 21, 2022, 01:51:43 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 · 2022-02-22 08:41 Quote from: parc_de on February 21, 2022, 09:16:25 pmI 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 · 2022-02-22 12:48 Quote from: PascalDragon on February 22, 2022, 09:41:15 am 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 · 2022-02-23 08:09 Quote from: parc_de on February 22, 2022, 01:48:37 pmThe 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)).