m68k-coff C cross-compiler


Steps to Create S-records

Commands to Create S-records under Linux

  • compile start.c into an object file start.o with the command:
    /usr/local/m68k-coff/bin/m68k-coff-gcc -m68000 -mshort -c start.c
  • compile func.c into an object file func.o with the command:
    /usr/local/m68k-coff/bin/m68k-coff-gcc -m68000 -mshort -c func.c
  • assemble utils.s into an object file utils.o with the command:
    /usr/local/m68k-coff/m68k-coff-gcc -m68000 -mshort -c utils.s
  • link start.o, func.o, utils.o and libgcc.a together into one object file project.o with the commands:
    /usr/local/m68k-coff/bin/m68k-coff-ld -r -dp -e start -T ldscript start.o func.o utils.o (path to libgcc directory)/libgcc.a -o project.o
    where (path to libgcc directory) is:
    /usr/local/m68k-coff/lib/gcc-lib/m68k-coff/2.95.2/m68000
    where the file "ldscript" contains:
    SECTIONS {.text 0x0900 : {*(.text)}}
    Notice that the number 0x0900 is the one that determines the base address of the loaded code on the SBC68K.

  • convert project.o into S-records in the file project.srec with the command:
    /usr/local/m68k-coff/bin/m68k-coff-objcopy -O srec project.o project.srec
  • convert project.srec into a form with macintosh line terminators with the command:
    tr -d '\012' < project.srec > aproject.srec
  • copy aproject.srec to the folder that corresponds to the virtual macintosh file server:
    cp aproject.srec ~/mac
  • Conventions for passing parameters

  • Parameters are passed on the stack.
  • Parameters are passed in reverse order. When the parameter is a struct the entire struct is pushed onto the stack piece by piece.
  • When the returned value is 4 bytes or smaller it is returned in d0. When it is a struct of size 8 bytes it is returned in d0 and d1. When it is a struct of size 6 bytes or larger than 8 bytes the calling code must provide space for the returned value and pass the address of that space in register a1. The function can then fill the space directly.
  • When the function returns, all registers (except d0 when used to return the function value) are restored to the values they had when it was called.
  • Limitations of m68k-coff-cc C

    These are some limitations of the C provided by the m68k-coff-cc cross-compiler.

  • It does not generate position independent code (PIC) in spite of the existence of a -PIC switch. If you want to write position independent code you should write it in assembly language.
  • Some code generates calls to library functions rather than inline code (e.g. integer division i/j). These functions should be in the c library. If a function is not in libc.a and is not in any other library then you must examine the generated code to determine the parameters and return value expected for that function, and then write the function yourself in assembly language.
  • Inline assembly is possible, but cannot refer to automatic variables, only to global variables. To write inline assembly use the asm {} instruction. E.g.
          asm {movea.l #0x10000,%sp}
    
  • When multiple source files are linked together, their object code appears in the final S-record file in the same sequence that the object files appear in the link statement. Therefore the code that contains the entry point of the program must be listed first in the link statement.
  • When several functions and global variables are present in a source file, their object code appears in the final S-record file in the same sequence that they appear in the source. Therefore the function that serves as the entry point for the final program must appear in the source file before any global variables.

  • [SSU Home Page] [SSU CS Department] [ CS Dept webmaster ] 02/28/01.