Close

Building TUTOR with GCC Toolchain

A project log for Retro 68000 CPU in an FPGA

Making a Retrocomputer with a 68000 CPU in an FPGA

land-boardscomland-boards.com 08/12/2020 at 18:260 Comments

In the last log I got the toolchain working on my Raspberry Pi to cross compile code for the 68K CPU.

In this log, I will try and assemble the TUTOR 1.3 code using the toolchain. I am using FileZilla to transfer the file to the Raspberry Pi. Here is the command line to assemble the code (adapted version of Jeff Tranter's command line):

./m68k-coff-as -m68000 -alms -a=tutor13.lst -o tutor13.o tutor13.s

When I run it I get a lot of errors starting with:

./m68k-coff-as -m68000 -o tutor13.o tutor13.s    tutor13.s: Assembler messages:
tutor13.s:5812: Error: value out of range
tutor13.s:5812: Error: Value of -132 too large for field of 1 bytes at 0xf82bad
tutor13.s:6822: Error: value out of range
tutor13.s:6822: Error: Value of 142 too large for field of 1 bytes at 0xf83421
tutor13.s:6838: Error: value out of range
tutor13.s:6838: Error: Value of 162 too large for field of 1 bytes at 0xf83449

 Line 5812 is a short branch instruction:

         BSR.S   COMMAS20

I thought short branches are 16-bits? If so, then a branch of -132 should not be too far away. Same for the rest of the list. I wonder if there's a missing option on the assemble line to specify the size of the BRA.S instruction?

./m68k-coff-as -help
Usage: ./m68k-coff-as [option...] [asmfile...]
Options:
  -a[sub-option...]       turn on listings
                          Sub-options [default hls]:
                          c      omit false conditionals
                          d      omit debugging directives
                          h      include high-level source
                          l      include assembly
                          m      include macro expansions
                          n      omit forms processing
                          s      include symbols
                          =FILE  list to FILE (must be last sub-option)
  --alternate             initially turn on alternate macro syntax
  -D                      produce assembler debugging messages
  --defsym SYM=VAL        define symbol SYM to given value
  -f                      skip whitespace and comment preprocessing
  -g --gen-debug          generate debugging information
  --gstabs                generate STABS debugging information
  --gstabs+               generate STABS debug info with GNU extensions
  --gdwarf-2              generate DWARF2 debugging information
  --help                  show this message and exit
  --target-help           show target specific options
  -I DIR                  add DIR to search list for .include directives
  -J                      don't warn about signed overflow
  -K                      warn when differences altered for long displacements
  -L,--keep-locals        keep local symbols (e.g. starting with `L')
  -M,--mri                assemble in MRI compatibility mode
  --MD FILE               write dependency information in FILE (default none)
  -nocpp                  ignored
  -o OBJFILE              name the object-file output OBJFILE (default a.out)
  -R                      fold data section into text section
  --statistics            print various measured statistics from execution
  --strip-local-absolute  strip local absolute symbols
  --traditional-format    Use same format as native assembler when possible
  --version               print assembler version number and exit
  -W  --no-warn           suppress warnings
  --warn                  don't suppress warnings
  --fatal-warnings        treat warnings as errors
  --itbl INSTTBL          extend instruction set to include instructions
                          matching the specifications defined in file INSTTBL
  -w                      ignored
  -X                      ignored
  -Z                      generate object file even after errors
  --listing-lhs-width     set the width in words of the output data column of
                          the listing
  --listing-lhs-width2    set the width in words of the continuation lines
                          of the output data column; ignored if smaller than
                          the width of the first line
  --listing-rhs-width     set the max width in characters of the lines from
                          the source file
  --listing-cont-lines    set the maximum number of continuation lines used
                          for the output data column of the listing
680X0 options:
-l                      use 1 word for refs to undefined symbols [default 2]
-m68000 | -m68008 | -m68010 | -m68020 | -m68030 | -m68040 | -m68060 |
-m68302 | -m68331 | -m68332 | -m68333 | -m68340 | -m68360 | -mcpu32 |
-m5200  | -m5202  | -m5204  | -m5206  | -m5206e | -m521x  | -m5249  |
-m528x  | -m5307  | -m5407  | -m547x  | -m548x  | -mcfv4  | -mcfv4e
                        specify variant of 680X0 architecture [default 68020]
-m68881 | -m68882 | -mno-68881 | -mno-68882
                        target has/lacks floating-point coprocessor
                        [default yes for 68020, 68030, and cpu32]
-m68851 | -mno-68851
                        target has/lacks memory-management unit coprocessor
                        [default yes for 68020 and up]
-pic, -k                generate position independent code
-S                      turn jbsr into jsr
--pcrel                 never turn PC-relative branches into absolute jumps
--register-prefix-optional
                        recognize register names without prefix character
--bitwise-or            do not treat `|' as a comment character
--base-size-default-16  base reg without size is 16 bits
--base-size-default-32  base reg without size is 32 bits (default)
--disp-size-default-16  displacement with unknown size is 16 bits
--disp-size-default-32  displacement with unknown size is 32 bits (default)

Report bugs to 

Looking at the difference between BRA and BRA.S shows that the branch is being treated as a byte offset instead of a short offset. 

 5810 ???? 6100 F70A             BSR     EAZ
 5811
 5812 ???? 617C                  BSR.S   COMMAS20
 5813

Toolchain Problem

It looks like the assembler did install but the C compiler is missing and it really would be worthwhile to have a C cross-compiler that lets me generate code under Windows. Trying a different way of making the gcc toolchain (Building the 68000 cross compiler - Automated).

Another Try at the GNU GCC Toolchain

I went onto the 68000 Assembly Language programming group on facebook and got a pointer to Steve Moody's gcc for 68k github page that eventually got me running on the GCC toolchain. 

The toolchain is running in VirtualBox under Linux.

Steve has a Makefile that does most of the work The one thing I did have to change was to set the variable PWD to the path to install. I got my son who's a wiz at all things Linux to help me figure out why it was crashing.

PWD = /home/doug/m68k-elf-toolchain

If you try it there are certainly better ways and your path will not be the same. You can get the path with the pwd command but you have to be in the right folder in terminal. 

I was rewarded with a GCC toolchain that assembled code correctly. 

I then installed srecord with:

sudo apt install srecord

 That installs the srecord program srec_cat. It installed version 1.58.D001 on my install.

Typing the line to assemble:

/opt/m68k-elf/bin/m68k-elf-as monitor.s -o monitor.o

 Created code.

Discussions