Tag Archives: jam
Using the OpenWatcom Assembler with Jam
I’ve previously covered the OS/2 port of Perforce Jam.
Here we’ll go over what it takes to make Jam know about the OpenWatcom assembler, Wasm.
First we can look at the Jambase file, in the source where we find the
actions As
{
$(AS) $(ASFLAGS) $(ASHDRS) -o $(<) $(>)
}
and we see that Jam has a few variables related to assembler files.
The Jamfile
First, we tell Jam that our assembler is Wasm.
AS = wasm ;
Then we redefine the As actions to be
actions As
{
$(AS) -q $(ASFLAGS) $(ASHDRS) -fo=$(<) $(>)
}
where -fo=$(<)
is the output file, and $(>)
the input file. We could also have used the newer syntax, $(1)
and $(2)
. The -q
tells Wasm to operate quetly; it means we won’t see the copyright information every time we run Jam; only the nice As file.asm
output.
Now, we can make use of these changes with
Main hello.exe : hello.c sum.asm ;
The Sources
The source files we mentioned above are hello.c
and sum.asm
.
Here is hello.c
#include <stdio.h> int sum( int a, int b ); int main( int argc, char *argv[] ) { printf( "Hello, %d.\n", sum( 3, 5 ) ); return 0; }
And here is sum.asm
.386 .model flat .code PUBLIC sum_ sum_ PROC add eax, edx ret sum_ ENDP END
These two files demonstrate how we can declare a function in C, and then define it in an assembly file. We are using the register calling convention of OpenWatcom. The first argument is in eax
, the second in edx
and the return value is again in eax
. That means we don’t have to worry about stack manipulation at all, in a simple function like sum()
. OpenWatcom appends _
to function names with the register convention, so we have to append it also in the .asm
file.
With the above Jamfile, we just run
jam
and our demonstration program is built and linked properly for us.
Running the Demo
Now, when we run
hello
on the command line, we see
Hello, 8.
Final Words
This has been written as Jamfile demonstration, but it can also be viewed as a demonstration of the register calling in OpenWatcom.
Do you need professional help with OS/2? Write to johann@myrkraverk.com.
Building Jam 2.6 on OS/2 with OpenWatcom
These instructions pertain to ArcaOS 5.0.1 and OpenWatcom 1.9. Any other OS/2 versions and compilers may behave slightly differently; your mileage may wary.
Here we will go through the process of porting Perforce Jam 2.6, released in 2014. At the time of writing, the source can be downloaded from the Perforce website.
There is also FT Jam, from the FreeType project, which is quite possibly more advanced, even though it’s based on Perforce Jam 2.5. and hasn’t been updated since about 2006, apparently.
Haiku Jam is also worth checking out.
Copyright and disclaimers
Jam has the following copyright:
Copyright 1993-2002 Christopher Seiwald and Perforce Software, Inc.
License is hereby granted to use this software and distribute it freely, as long as this copyright notice is retained and modifications are clearly marked.
ALL WARRANTIES ARE HEREBY DISCLAIMED.
Furthermore, no work has been done to insure the OS/2 port is fit for any particular purpose, except to ensure it successfully builds itself.
The Makefile
The settings at the start should look like this.
CC = wcl386 CFLAGS = EXENAME = jam0.exe TARGET = -fe=$(EXENAME)
That is, the compiler is wcl386
, with no special C flags, and the name is jam0.exe
without the period and slash. The -fe=
tells wcl386
what to name the executable file; possible mnemonic: file executable.
Optionally add wtouch all
as the final command in the “all” rule, or build with -c
; otherwise WMake will complain the “all” target has not been built.
That takes care of the Makefile.
The make1.c file
There are minor changes in the make1.c file, because it unconditionally calls unlink() and we “fix that” with these macros at the start.
# ifdef OS_OS2 # define INCL_DOSFILEMGR # include <os2.h> # define unlink DosDelete # endif
You will need to remove the READ ONLY flag from the file before it
can be saved.
attrib -r make1.c
The execunix.c file
In this file, there are some major changes; so to speak.
At the top we add
# define INCL_DOSPROCESS # define INCL_DOSFILEMGR # include <os2.h> # define unlink DosDelete
inside the OS/2 section, because it also calls unlink()
unconditionally. And we also need to get access to process information, to get the PID.
The complete section shoudl look like this:
# ifdef OS_OS2 # define USE_EXECNT # include <process.h> # define INCL_DOSPROCESS # define INCL_DOSFILEMGR # include <os2.h> # define unlink DosDelete # endif
After this change, on line 188, is a
# ifdef USE_EXECNT
inside which is an NT call GetCurrentProcessId()
which we port to use DosGetInfoBlocks()
instead.
So at the start of the scope, we declare two new pointers, to the thread and process structure respectively.
TIB *thread; PIB *process;
And before sprintf() that refers to the PID, we call
DosGetInfoBlocks( &thread, &process );
while inside the sprint()
call itself, where GetCurrentProcessId() used to
be, we have
process->pib_ulpid
instead. The complete function call now looks like
sprintf( cmdtab[ slot ].tempfile, "%s\\jam%lut%d.bat", tempdir, process->pib_ulpid, slot );
where we have carefully updated the format specification to reflect unsigned long %lu
, instead of integer %d
. Even though integers and longs are the same size on 32bit OS/2, there’s no reason to be sloppy about format specifiers in the printf()
family of functions.
You will also need to remove the read only bit before saving the file.
attrib -r execunix.c
The jamgram.c and parse.c files
These source files will have some warning about undeclared function names. This is ok, and is not worth fixing just to get Jam working on OS/2. Maybe later, and particularly if Perforce is willing to accept contributions, it may turn out to be a worthwhile effort to fix.
This takes care of the source files.
Building It
Now do
wmake -u -c
in a command prompt, and Jam will bootstrap itself. The Jam built object files and executable will be in a subdirectory called bin.os2x86
so don’t be surprised if you only see the jam0.exe
file at first.
On modern hardware, the complete build takes only a few seconds.
The -u
is for unix compatibility mode, and allows WMake to understand the backslash line continuation syntax; lines that end with \
are joined. Without this, there will be an error.
As mentioned previously, the -c
is to stop WMake from complaining that “all” has not been built. Leave it out of you added wtouch all
to the rule.
Installation
To install Jam, just copy the jam.exe
file into c:\usr\local\bin
, which you may have to create first, or wherever your %UNIXROOT%
is.
mkdir c:\usr\local
mkdir c:\usr\local\bin
copy bin.os2x86\jam.exe c:\usr\local\bin\
It is normal that the mkdir
commands fail when the directory exists already.
Alternatively, you can write the commands like this, in case your
UNIXROOT
is not C:
.
mkdir %UNIXROOT%\usr\local
mkdir %UNIXROOT%\usr\local\bin
copy bin.os2x86\jam.exe %UNIXROOT%\usr\local\bin
Final Words
Congratulations, now you have completed the build and installation of Perforce Jam 2.6.
Happy building.
Do you need professional assistance with OS/2? Write to johann@myrkraverk.com.