Compiling KLH10

From Computer History Wiki
Revision as of 07:16, 26 February 2012 by Lexthehex (talk | contribs) (Compiling KLH10 on Gentoo x86_64)
Jump to: navigation, search

Introduction

This is a brief guide to compiling Ken Harrenstein's KLH10 PDP-10 emulator. It was written on an AMD64 Gentoo machine with 2GB RAM and gcc 4.5.3-r1. The author currently has a bad cold, so please excuse any mistakes/foolishness caused by light-headedness.

I was satisfied with using SIMH to run MIT's ITS operating system, but there was an annoying bug: the reported time of the system looped endlessly over three hours, and did not seem to keep proper time. Was the clock running too fast? It seemed to be okay, but something was amiss with the way that ITS reads the clock. In an effort to narrow down the cause, I decided to get KLH10 running and see if it exhibited the same problem. I have not found an answer yet.

Useful links: Viktor Björn's tutorial 'Some notes on setting up an ITS system'

This tutorial assumes that you are running a Linux system with a modern version of gcc. Some of these instructions will not apply to your system, or may differ. I am using a current Gentoo system, as of February 2012. The system has been configured as a 'multilib' configuration, with a mixture of 32- and 64-bit. By default, gcc compiles for 64-bit. (verify this)

Step 1: obtaining the KLH-10 source. There are two places that you can get the source, but I recommend using the Panda source, which you can download at [1]. As mentioned in Mr. Björn's tutorial, if you are using gcc 4.x or later (I am!) you need to apply this patch. I needed to apply some additional patches of my own - see later.

Step 2: unpack the source - easy: 'tar -xzf panda-dist.tar.gz'

Step 3: compile the source. Here's where I got lost. The instructions (panda-dist/klh10-2.0h/doc/install.txt) tell you to:

  1. Unpack the main distribution, and the auxiliary distribution (I didn't, as I don't need it yet).
  2. Configure for the native platform. Again, I didn't do anything here. Perhaps I should have.
  3. 'Build a KN10 from sources'. Here, I was stumped. Which sources? Where? How? (Remember, I have a cold and my brain is a bit woolly.)

The example shows:

       $ cd <distrib>/bld/<platform>
       $ make base-kl          ;;; or base-ks or base-ks-its

On my system, '<distrib>' is 'klh10-2.0h' and '<platform>' is 'lnx86' (Linux, x86) - so, I did:

       $ cd klh10-2.0h/bld/lnx86

.. but was dismayed to find a solitary file in this directory:

       -rwxr-xr-x 1 lex root 70 Feb 21  2005 00build

This contains a 'make' command:

       #!/bin/sh
       make base-kl CONFFLAGS_AUX=-DKLH10_I_CIRC=1 LDFLAGS=-static

Predictably, executing it causes make to output an error, because there is no Makefile.

       make: *** No rule to make target `base-kl'.  Stop.

Eventually, I decided to copy the command from the '00build' file, but source the Makefile.mk in the 'src' directory, two levels up (../../src/). This gave me this command:

       make -f ../../src/Makefile.mk base-kl CONFFLAGS_AUX=-DKLH10_I_CIRC=1 LDFLAGS=-static

I was happy that at this point, gcc compiled some code before aborting with a syntax error in ../../cenv.h. This was easily-fixed: edit cenv.h and find line 270.

       #   define _FILE_OFFSET_BITS=64 /* Use 64-bit file ops */

Change that to:

       #   define _FILE_OFFSET_BITS 64 /* Use 64-bit file ops */

I.e. change the '=' to a space.

Repeating the 'make base-kl ...' command should cause compilation to progress a bit further, before it aborts with an undefined reference to 'lites_init'. That function is in src/dvlites.c, and is an addition that the Panda team added: it sends the processor status over the parallel port, where it is displayed by a custom bit of hardware (a microcontroller, as designed by Spare Time Gizmos. I have almost all of the parts for this device, but alas! My computer doesn't have a parallel port, and no serial port either. I'll have to think of another way to display the CPU status, and I have thought of a few:

  1. Display the CPU status as a window on the screen.
  2. Send it to a file, or a pipe (to be interpreted by another application).
  3. Send it over the network, to be displayed by other hardware.
  4. Display it on standard PC hardware - e.g. the keyboard LEDs. Problem: there aren't many LEDs, and XKB might not take too kindly to my app stealing its control.

I've decided on '2' at present, but might do the window thing first, as I am trying to learn to program with SDL.

Back to the patching of the KLH10 code. My next edit was to add an 'extern int' declaration to src/klh10.c, edit src/dvlites.c and change '#include <asm/io.h>' to '#include <sys/io.h>', having determined that it's using the functions ioperm() and outb() to write to the parallel port.

The addition to klh10.c is at the top: find the section marked '/* Imported functions */' and add this line after the final 'extern int' of the block:

       extern int lites_init(unsigned int prt);

After one more command, the klh10 executable should compile.

       make -f ../../src/Makefile.mk base-kl CONFFLAGS_AUX="-DKLH10_I_CIRC=1 -DKLH10_DEV_LITES=1" LDFLAGS="-static"

You may not need the '-DKLH10_DEV_LITES=1' definition, as I added this while testing [note to self: tidy this document!].

Diffs

The Wiki may process these in some way, so I may upload them as a separate file.

cenv.h patch

diff -u src/cenv.h /home/lex/Projects/KLH10/TOPS-20/panda-dist/klh10-2.0h/src/cenv.h --- src/cenv.h 2002-03-28 08:48:50.000000000 +0000 +++ /home/lex/Projects/KLH10/TOPS-20/panda-dist/klh10-2.0h/src/cenv.h 2012-02-26 03:04:08.000000000 +0000 @@ -267,7 +267,7 @@

#  define CENV_SYSF_LFS 64		/* off_t exists and has 64 bits */
#  define CENV_SYSF_FSEEKO 1		/* And have some flavor of fseeko */
#  ifndef _FILE_OFFSET_BITS

-# define _FILE_OFFSET_BITS=64 /* Use 64-bit file ops */ +# define _FILE_OFFSET_BITS 64 /* Use 64-bit file ops */

#  endif
#  ifndef _LARGEFILE_SOURCE
#   define _LARGEFILE_SOURCE		/* Include fseeko, ftello, etc */

dvlites.c patch

diff -u src/dvlites.c /home/lex/Projects/KLH10/TOPS-20/panda-dist/klh10-2.0h/src/dvlites.c --- src/dvlites.c 2005-02-21 23:19:13.000000000 +0000 +++ /home/lex/Projects/KLH10/TOPS-20/panda-dist/klh10-2.0h/src/dvlites.c 2012-02-26 03:46:04.000000000 +0000 @@ -31,7 +31,8 @@

#if KLH10_DEV_LITES		/* Moby conditional for entire file */

-#include <asm/io.h> +/* #include <asm/io.h> */ +#include <sys/io.h>

#include "dvlites.h"

klh10.c patch

diff -u src/klh10.c /home/lex/Projects/KLH10/TOPS-20/panda-dist/klh10-2.0h/src/klh10.c --- src/klh10.c 2005-02-21 23:20:34.000000000 +0000 +++ /home/lex/Projects/KLH10/TOPS-20/panda-dist/klh10-2.0h/src/klh10.c 2012-02-26 03:42:42.000000000 +0000 @@ -82,6 +82,7 @@

extern void apr_init(void);
extern void apr_init_aprid(void);
extern int apr_run(void);

+extern int lites_init(unsigned int prt);

/* Local function kept external for easier debug access  */
void errpt(void);

kn10def.h patch

diff -u src/kn10def.h /home/lex/Projects/KLH10/TOPS-20/panda-dist/klh10-2.0h/src/kn10def.h --- src/kn10def.h 2006-06-15 17:30:59.000000000 +0000 +++ /home/lex/Projects/KLH10/TOPS-20/panda-dist/klh10-2.0h/src/kn10def.h 2012-02-26 02:25:55.000000000 +0000 @@ -235,7 +235,7 @@

#if KLH10_EXTADR
# define PC_ADDXCT(x) { register pcinc_t i__ = (x); if (i__) PC_ADD(i__); }
#else

-# define PC_ADDXCT(x) (cpu.mr_PC += (x)) /* For now; fix up later? */ +# define PC_ADDXCT(x) { register pcinc_t i__ = (x); cpu.mr_PC += i__; } /* gcc4 fix by Roch Kusiak */

#endif

/* Macros for putting PC into a word.

Lexthehex 22:16, 25 February 2012 (PST)