[comp.emacs] GNU exists on IBM RT running AIX

karl@haddock.UUCP (Karl Heuer) (06/29/87)

I have succeeded in bringing up Gnu Emacs under AIX, unexec and all.  Details
later this week.

Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint

karl@haddock.ISC.COM (Karl Heuer) (07/11/87)

Nearly two weeks ago I wrote in article <640@haddock.UUCP>:
>I have succeeded in bringing up Gnu Emacs under AIX, unexec and all.  Details
>later this week.

Sorry about the delay; I got sidetracked by other commitments.  Also I was
hoping to snarf a more recent copy of emacs before posting the diffs; 18.40 is
the latest we have here.  (If someone offers to send me 18.47, or makes it
available via UUCP from the 617 area code, I'd be most grateful.)

Anyway, here's the first installment, to get y'all started.  The existing
unexec code seems to know two formats, BSD and COFF.  AIX uses a variant of
COFF known as GPOFF.  Rather than attempt to hack the COFF code to make it
write GPOFF, I took the easy way out and wrote my own unexec() from scratch.
Some ambitious person should fold it (with #ifdef) into the existing unexec.c,
without making it such a special case.

This code writes a stripped a.out; it should be relatively easy to copy the
symbol table too.  I don't know of any way to make the initialized data
segment pure, so no special action is taken in that respect.

Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint
---- cut here ----
#!/bin/sh
tr -d '\12' <<\EOF | tr '@' '\12' >unexec.c
#include "config.h"
@
@#include <a.out.h>
@#define	HSIZE	sizeof(struct exec)
@static struct exec hdr;
@extern etext;
@extern char *sbrk();
@
@#define	TBASE	0x10000000
@#define	DBASE	0x20000000
@#define	text_start	(TBASE+HSIZE)
@#define	text_end	((unsigned int)&etext)
@
@int unexec(name) char *name; {
@    register unsigned int data_start, data_end;
@    register int fd;
@    data_start = DBASE | (text_end & 0x7FF);
@    data_end = (unsigned int)sbrk(0);
@    hdr.a_magic[0] = A_MAGIC0;
@    hdr.a_magic[1] = A_MAGIC1;
@    hdr.a_flags = A_TOFF|A_EXEC|A_PURE;
@    hdr.a_cpu = A_SELF;
@    hdr.a_hdrlen = HSIZE;
@    hdr.a_text = text_end - text_start + HSIZE;
@    hdr.a_data = data_end - data_start;
@    hdr.a_bss = 0;
@    hdr.a_entry = (long)text_start;
@    hdr.a_tbase = TBASE;
@    hdr.a_dbase = (long)data_start;
@    if ((fd = creat(name, 0777)) < 0 || write(fd, (char *)&hdr, H
SIZE) != HSIZE || write(fd, (char *)text_start, text_end - text_st
art) != text_end - text_start || write(fd, (char *)data_start, dat
a_end - data_start) != data_end - data_start) {
@	close(fd);
@	error("Unable to unexec to %s", name);
@    }
@    close(fd);
@    return (0);
@}@
EOF

karl@haddock.ISC.COM (Karl Heuer) (07/14/87)

This is the second installment of the AIX patches, covering lisp/paths.el and
lisp/man.el.  The former has only two changes, to recognize AIX as a USG-like
system (see comments attached to s-aix.h, coming soon).  The latter was hacked
to recognize footers for man pages on my system, which is quite probably not
something I should be exporting.  If you have AIX with on-line man pages,
you'd better verify this one before patching it.

Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint
---- cut here ----
*** paths.el-orig	Mon Jul 13 18:46:34 1987
--- paths.el	Mon Jul 13 18:46:34 1987
***************
*** 50,56 ****
    "Name of user's primary mail file.")
  
  (defconst rmail-spool-directory
!   (if (memq system-type '(hpux usg-unix-v))
        "/usr/mail/"
      "/usr/spool/mail/")
    "Name of directory used by system mailer for delivering new mail.
--- 50,56 ----
    "Name of user's primary mail file.")
  
  (defconst rmail-spool-directory
!   (if (memq system-type '(hpux usg-unix-v aix))
        "/usr/mail/"
      "/usr/spool/mail/")
    "Name of directory used by system mailer for delivering new mail.
***************
*** 57,63 ****
  Its name should end with a slash.")
  
  (defconst rmail-primary-inbox-list 
!   (if (memq system-type '(hpux usg-unix-v))
        '("~/mbox" "/usr/mail/$LOGNAME")
      '("~/mbox" "/usr/spool/mail/$USER"))
   "List of files which are inboxes for user's primary mail file ~/RMAIL.")
--- 57,63 ----
  Its name should end with a slash.")
  
  (defconst rmail-primary-inbox-list 
!   (if (memq system-type '(hpux usg-unix-v aix))
        '("~/mbox" "/usr/mail/$LOGNAME")
      '("~/mbox" "/usr/spool/mail/$USER"))
   "List of files which are inboxes for user's primary mail file ~/RMAIL.")
*** man.el-orig	Mon Jul 13 18:46:34 1987
--- man.el	Mon Jul 13 18:46:34 1987
***************
*** 103,108 ****
--- 103,110 ----
        ;;     "     Hewlett-Packard   -1- (printed 12/31/99)"  FMHWA12ID!!
        ;;    System V (well WICATs anyway):
        ;;     "Page 1			  (printed 7/24/85)"
+       ;;    AIX (based on a single sample)
+       ;;     "Rev. 1.0                     Page 1"
        ;;    Who is administering PCP to these corporate bozos?
        (goto-char (point-min))
        (while (re-search-forward
***************
*** 110,116 ****
  		   "^ *Hewlett-Packard.*(printed [0-9/]*)$"
  		 (if (eq system-type 'usg-unix-v)
  		     "^ *Page [0-9]*.*(printed [0-9/]*)$"
! 		   "^\\(Printed\\|Sun Release\\) [0-9].*[0-9]$"))
  	       nil t)
  	(replace-match ""))
  
--- 112,120 ----
  		   "^ *Hewlett-Packard.*(printed [0-9/]*)$"
  		 (if (eq system-type 'usg-unix-v)
  		     "^ *Page [0-9]*.*(printed [0-9/]*)$"
! 		   (if (eq system-type 'aix)
! 		       "^ *Rev\\. [0-9.]+ *Page [0-9]*$"
! 		     "^\\(Printed\\|Sun Release\\) [0-9].*[0-9]$")))
  	       nil t)
  	(replace-match ""))

karl@haddock.ISC.COM (Karl Heuer) (07/22/87)

This is s-aix.h, the third installment of the AIX patches.  I chose to make a
new s- file rather than using s-usg5-2-2.h and hacking config.h; there seemed
to be enough differences to justify calling it a separate flavor of UNIX.  I
defined the cpp symbol USG because it is a SysV derivative, and also defined
the symbol AIX for more specific testing.  The lisp variable system-type is
set to 'aix, which may or may not be a good idea.

Old versions of AIX don't have a select system call.  (You can check for it by
typing "ar t /lib/libc.a select.o".)  If you don't have it, you should turn
off HAVE_SELECT.  Do this in config.h (see next posting), not s-aix.h.

If you do have select, make sure it isn't being clobbered by the bogus select
in libcurses.  To test this, type "cd /tmp; ar x /usr/lib/libcurses.a select.o
&& size select.o"; if you get a non-zero result you have a problem.  You
should get rid of the bogus routine with "ar d /usr/lib/libcurses.a select.o"
if you have root permission, otherwise just make a local copy of libcurses and
hack the Makefile to load it instead of the one in /usr/lib.

Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint
---- cut here ----
#!/bin/sh
cat <<\EOF >s-aix.h
/* Definitions file for GNU Emacs running on AIX
   Copyright (C) 1985, 1986 Free Software Foundation, Inc.

This file is part of GNU Emacs.

GNU Emacs is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.  No author or distributor
accepts responsibility to anyone for the consequences of using it
or for whether it serves any particular purpose or works at all,
unless he says so in writing.  Refer to the GNU Emacs General Public
License for full details.

Everyone is granted permission to copy, modify and redistribute
GNU Emacs, but only under the conditions described in the
GNU Emacs General Public License.   A copy of this license is
supposed to have been given to you along with GNU Emacs so you
can know your rights and responsibilities.  It should be in a
file named COPYING.  Among other things, the copyright notice
and this notice must be preserved on all copies.  */


/*
 *	Define symbols to identify the version of Unix this is.
 *	Define all the symbols that apply correctly.
 */

#define	AIX
#define USG				/* Close enough */
#define USG5

/* SYSTEM_TYPE should indicate the kind of system you are using.
 It sets the Lisp variable system-type.  */

#define SYSTEM_TYPE "aix"

/* nomultiplejobs should be defined if your system's shell
 does not have "job control" (the ability to stop a program,
 run some other program, then continue the first one).  */

#define NOMULTIPLEJOBS

/* Default is to set interrupt_input to 0: don't do input buffering within Emacs */

/* #define INTERRUPT_INPUT */

/* Letter to use in finding device name of first pty,
  if system supports pty's.  'p' means it is /dev/ptyp0  */

#define FIRST_PTY_LETTER 'p'

/*
 *	Define HAVE_TERMIO if the system provides sysV-style ioctls
 *	for terminal control.
 */

#define HAVE_TERMIO

/*
 *	Define HAVE_TIMEVAL if the system supports the BSD style clock values.
 *	Look in <sys/time.h> for a timeval structure.
 */

/* #define HAVE_TIMEVAL */
 
/*
 *	Define HAVE_SELECT if the system supports the `select' system call.
 */

#define HAVE_SELECT

/*
 *	Define HAVE_PTYS if the system supports pty devices.
 */

/* #define HAVE_PTYS */

/* Define HAVE_SOCKETS if system supports 4.2-compatible sockets.  */

/* #define HAVE_SOCKETS */

/*
 *	Define NONSYSTEM_DIR_LIBRARY to make Emacs emulate
 *      The 4.2 opendir, etc., library functions.
 */

#define NONSYSTEM_DIR_LIBRARY

/* Define this symbol if your system has the functions bcopy, etc. */

#define BSTRING	/* we can emulate them as follows: */
#define	bcopy(src, dst, len)	(void)memcpy(dst, src, len)
#define	bzero(buf, len)		(void)memset(buf, '\0', len)
#define	bcmp			memcmp

/* subprocesses should be defined if you want to
 have code for asynchronous subprocesses
 (as used in M-x compile and M-x shell).
 This is supposed to work now on system V release 2.  */

#define subprocesses

/* If your system uses COFF (Common Object File Format) then define the
   preprocessor symbol "COFF". */

#define	GPOFF	/* This is almost like COFF */

/* define MAIL_USE_FLOCK if the mailer uses flock
   to interlock access to /usr/spool/mail/$USER.
   The alternative is that a lock file named
   /usr/spool/mail/$USER.lock.  */

/* #define MAIL_USE_FLOCK */

/* Define CLASH_DETECTION if you want lock files to be written
   so that Emacs can tell instantly when you try to modify
   a file that someone else has modified in his Emacs.  */

/* #define CLASH_DETECTION */

/* Define SHORTNAMES if the C compiler can distinguish only
   short names.  It means that the stuff in ../shortnames
   must be run to convert the long names to short ones.  */

/* #define SHORTNAMES */

/* We use the Berkeley (and usg5.2.2) interface to nlist.  */

#define NLIST_STRUCT

/* The file containing the kernel's symbol table is called /unix.  */

#define KERNEL_FILE "/unix"

/* The symbol in the kernel where the load average is found
   is named avenrun.  */

#define LDAV_SYMBOL "avenrun"

/* Special hacks needed to make Emacs run on this system.  */

/* setjmp and longjmp can safely replace _setjmp and _longjmp,
   but they will run slower.  */

#define _setjmp setjmp
#define _longjmp longjmp

/* On USG-based systems the system calls are interruptable by signals
 that the user program has elected to catch.  Thus the system call
 must be retried in these cases.  To handle this without massive
 changes in the source code, we remap the standard system call names
 to names for our own functions in sysdep.c that do the system call
 with retries. */

#define read sys_read
#define open sys_open
#define write sys_write

#define INTERRUPTABLE_OPEN
#define INTERRUPTABLE_IO

/* On USG-based systems these have different names */

#define index strchr
#define rindex strrchr

/* AIX handles static bss correctly */
/* #define static */

/* Either this definition or the default should generate the same code */
#define ADDR_CORRECT(x) (x)

/* Use terminfo instead of termcap.  */

#define TERMINFO
EOF
exit 0

karl@haddock.ISC.COM (Karl Heuer) (07/22/87)

This is the fourth and last installment of the AIX patches.  It contains the
diffs for two files, config.h and m-ibmrt.h.

The only change I needed to make to config.h (other than the obvious selection
of s- and m- files) was to increase the value of PURESIZE.  (For some reason,
the distributed value was too small for the system as I received it.)  As I
mentioned in part 3, if you have an old version of AIX you should add the line
"#undef HAVE_SELECT" to config.h.

I tried to make m-ibmrt.h correct for AIX without breaking it for BSD.  Since
rumor has it that emacs has already run on the latter but not the former, I
usually assumed that the existing parameters were correct for BSD.  Someone
correct me if I got these wrong:

NO_ARG_ARRAY		Works on AIX; now set for BSD only.
WORD_MACHINE		No, it isn't.  This must have been a mistake.
START_FILES		AIX only; needed for loader weirdness.
HAVE_ALLOCA		(Really?  Does this use a builtin, or what?)  BSD only.
C_ALLOCA		AIX only.  I couldn't write a "real" alloca.
DATA_SEG_BITS		\ AIX uses segments 1 and 2, not 0 and 1.  (Segment
DATA_START		|   0 is kernel.)
TEXT_START		/
C_SWITCH_MACHINE	BSD only; the AIX compiler doesn't know what this is.
LD_SWITCH_MACHINE	\ AIX only.  Determined by looking at the output
LIB_STANDARD		/   of "cc -#".  Egad.
RTPC_REGISTER_BUG	\ BSD only.  As far as I know, the AIX compiler
SHORT_CAST_BUG		/   doesn't have these bugs.

Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint
---- cut here ----
*** config.h-dist	Tue Jul 21 18:37:14 1987
--- config.h	Tue Jul 21 18:52:42 1987
***************
*** 24,30 ****
     See the file ../etc/MACHINES for a list of systems and
     the names of the s- files to use for them.
     See s-template.h for documentation on writing s- files.  */
! #include "s-bsd4-2.h"
   
  /* Include here a m- file that describes the machine and system you use.
     See the file ../etc/MACHINES for a list of machines and
--- 24,30 ----
     See the file ../etc/MACHINES for a list of systems and
     the names of the s- files to use for them.
     See s-template.h for documentation on writing s- files.  */
! #include "s-aix.h"
   
  /* Include here a m- file that describes the machine and system you use.
     See the file ../etc/MACHINES for a list of machines and
***************
*** 31,37 ****
     the names of the m- files to use for them.
     See m-template.h for info on what m- files should define.
     */
! #include "m-vax.h"
  
  /* Load in the conversion definitions if this system
     needs them and the source file being compiled has not
--- 31,37 ----
     the names of the m- files to use for them.
     See m-template.h for info on what m- files should define.
     */
! #include "m-ibmrt.h"
  
  /* Load in the conversion definitions if this system
     needs them and the source file being compiled has not
***************
*** 91,97 ****
  #ifdef HAVE_X_WINDOWS
  #define PURESIZE 120000
  #else
! #define PURESIZE 115500
  #endif
  #endif
  
--- 91,97 ----
  #ifdef HAVE_X_WINDOWS
  #define PURESIZE 120000
  #else
! #define PURESIZE 116000
  #endif
  #endif
  
*** m-ibmrt.h-dist	Tue Jul 21 18:57:43 1987
--- m-ibmrt.h	Tue Jul 21 18:53:03 1987
***************
*** 36,47 ****
  /* Define NO_ARG_ARRAY if you cannot take the address of the first of a
   * group of arguments and treat it as an array of the arguments.  */
  
  #define NO_ARG_ARRAY
  
  /* Define WORD_MACHINE if addresses and such have
   * to be corrected before they can be used as byte counts.  */
  
! #define WORD_MACHINE
  
  /* Define how to take a char and sign-extend into an int.
     On machines where char is signed, this is a no-op.  */
--- 36,49 ----
  /* Define NO_ARG_ARRAY if you cannot take the address of the first of a
   * group of arguments and treat it as an array of the arguments.  */
  
+ #ifdef BSD
  #define NO_ARG_ARRAY
+ #endif
  
  /* Define WORD_MACHINE if addresses and such have
   * to be corrected before they can be used as byte counts.  */
  
! #undef WORD_MACHINE
  
  /* Define how to take a char and sign-extend into an int.
     On machines where char is signed, this is a no-op.  */
***************
*** 80,85 ****
--- 82,91 ----
     and temacs will do (load "loadup") automatically unless told otherwise.  */
  
  #undef CANNOT_DUMP
+ #ifdef AIX
+ /* AIX loader doesn't like pre-crt0 */
+ #define	START_FILES	/lib/crt0.o
+ #endif
  
  /* Define VIRT_ADDR_VARIES if the virtual addresses of
     pure and impure space as loaded can vary, and even their
***************
*** 97,104 ****
--- 103,117 ----
     Define neither one if an assembler-language alloca
     in the file alloca.s should be used.  */
  
+ #ifdef BSD
  #define HAVE_ALLOCA
+ #else
+ #define C_ALLOCA
+ #define	STACK_DIRECTION	(-1)
+ #define	ALIGN_SIZE	4
+ #endif
  
+ #ifdef BSD
  /* The data segment in this machine always starts at address 0x10000000.
     An address of data cannot be stored correctly in a Lisp object;
     we always lose the high bits.  We must tell XPNTR to add them back.  */
***************
*** 109,114 ****
--- 122,133 ----
  /* The text segment always starts at 0.
     This way we don't need to have a label _start defined.  */
  #define TEXT_START 0
+ #else
+ /* Under AIX, text is in segment 1 and data is in segment 2. */
+ #define DATA_SEG_BITS 0x20000000
+ #define DATA_START    0x20000000
+ #define TEXT_START    0x10000000
+ #endif
  
  /* Taking a pointer to a char casting it as int pointer */
  /* and then taking the int which the int pointer points to */
***************
*** 125,132 ****
--- 144,158 ----
  
  /* Special switches to give the C compiler.  */
  
+ #ifdef BSD
  #define C_SWITCH_MACHINE -ma
+ #endif
  
+ #ifdef AIX
+ #define	LD_SWITCH_MACHINE -n -T0x10000000 -K -e start
+ #define	LIB_STANDARD -lrts -lc
+ #endif
+ 
  /* Don't attempt to relabel some of the data as text when dumping.
     It does not work because their virtual addresses are not consecutive.
     This enables us to use the standard crt0.o.  */
***************
*** 133,138 ****
--- 159,165 ----
  
  #define NO_REMAP
  
+ #ifdef BSD
  /* Turn off some `register' declarations.  */
  
  #define RTPC_REGISTER_BUG
***************
*** 139,141 ****
--- 166,169 ----
  
  /* (short) negative-int doesn't sign-extend correctly */
  #define SHORT_CAST_BUG
+ #endif