SD Core for Windows WC2.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 Windows runs on little-endian machines (x86-64), and so does SD Core for Linux, 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#

C:\Program Files\SD\usr\bin\sdconv.exe. Type that, or just sdconv if SD's program folder is on the system PATH (append.sd.path, in the remote access page of this set). 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 (a read-only copy is left as it was, exit 0). 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. The program does not descend into a folder, and a wildcard is not expanded by anything: sdconv -B bp.out\* converts nothing and exits 0, from PowerShell and from cmd alike. Name the files, in PowerShell with sdconv -B (Get-ChildItem bp.out).FullName. 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 W1.1-3   Copyright, Ladybridge Systems, 2007.  All rights reserved. ]

> $LASTEXITCODE
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#

> sdconv -B C:\sdi_demo\zzcust
C:\sdi_demo\zzcust is a hashed file: sdconv converts compiled programs only, nothing was changed
> $LASTEXITCODE
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#