SD Core for Linux LC2.0-0

sdconv, the Byte Order Convertor

A tool for turning compiled program files between big-endian and little-endian form: what it converts in this build, what it refuses, and why you will rarely need it.

This document is separate so that it can be withheld. It links to nothing outside the administrator set. Where a page in another set is worth naming, it is named in words.

sdconv was written to move SD files between computers that store numbers in opposite byte orders. SD Core for Linux runs on little-endian machines (x86-64), and so does SD Core for Windows, so a conversion between the two is never needed. Whether a converted file would run on a big-endian machine is not something this page can say.

Read this first: sdconv does not convert hashed files. Given one it says so, changes nothing and exits 1. It converts compiled program files only, and only the header of each. This SD cannot open a big-endian hashed file, so a converted file would be of no use here.

The short version#

Where it is and who can run it#

/usr/local/sdsys/bin/sdconv. Only sd is linked into /usr/local/bin, so type the full path. It opens each file for read and write, so you need write access to it. A file it cannot open for writing is skipped without a word. It takes no configuration file. Run it with SD stopped, or on files SD is not using: it makes no check for that.

The command line#

sdconv {options} pathname ...
Option What it does
-B Convert to big-endian.
-L Convert to little-endian.
-D Debug. It is accepted, is not listed in the usage text, and does nothing for a program file: the progress it would print belongs to the hashed-file routine that is not called. It prints no extra output.
(neither -B nor -L) Convert to the byte order of the machine it is run on, which here is little-endian, so the same as -L.

Options may be joined in one word (-BD) and are not case sensitive. If both -B and -L appear, the last one wins. Several pathnames may follow, and the shell may expand a wildcard (bp.out/*). The program does not descend into a directory: a directory that is not a hashed file is skipped. With no pathname, or an option it does not know, it prints the usage text and exits 1.

$ sdconv

Usage: SDCONV {options} pathname(s)

Options:
   -B      Force conversion to big-endian
   -L      Force conversion to little-endian

Only compiled programs are converted; a hashed file is refused (exit status 1).

(preceded, as always, by the banner.) A run that did something looks like a run that did nothing:

$ sdconv -B objfile
[ SDCONV LC2.0-0   Copyright, Ladybridge Systems, 2007.  All rights reserved. ]

$ echo $?
0

The only failures it reports are Cannot read name, Error converting name, a seek or write error naming the file, and Cannot allocate memory for name, and only for a file it had already recognized as a program object.

What it converts: compiled program files#

A compiled program is a plain operating system file that begins with a one-byte marker, 0x64 for little-endian and 0x65 for big-endian. SD keeps them in:

A file whose first byte is neither value, or that is shorter than the 165-byte header, is not touched.

before   64 00 00 00 00 00 bf 01 00 00 00 00 08 00 68 00
after -B 65 00 00 00 00 00 00 00 01 bf 00 00 00 08 00 68

(the first 16 bytes of a global catalog entry, before and after). Then sdconv -L on the same file restored it byte for byte, and a second -B on a file already big-endian changed nothing.

Only the object header is converted: the program id, the start offset, the argument, variable and stack counts, the offsets of the symbol and line tables, the object size, the flags and the compile time. The compiled code, the symbol tables and the constants are not touched. SD's own source says that floating point constants are the one thing in the code that needs swapping, and that SD does it when it loads them.

What it does not convert: hashed files#

$ ls zzcust; sdconv -B zzcust; echo rc=$?
%0  %1
zzcust is a hashed file: sdconv converts compiled programs only, nothing was changed
rc=1

%0 and %1 are left byte for byte, with -B, with -L and with no option: the tool converts neither the header, the data groups nor the index nodes of a hashed file.

A hashed file taken to a machine of the other byte order cannot be converted by this tool, and this SD could not open it if it were.

What it will not do#