If you want to run open source solutions on IBM i, you need to know PASE. Follow this guidance to get started
Editor’s note: This article is excerpted from chapter 2 of Open Source Starter Guide for IBM i Developers.
PASE is an acronym for Portable Application Solutions Environment (after being initially called the Private Address Space Environment). In my book, it’s the Pretty Awesome Software Environment, where it seems like just about anything is possible.
PASE is important because it’s like Oz in The Wizard of Oz, where you suddenly leave the black and white world of RPG and then land, sometimes with a thud, into the color-filled world of open source. But what the heck is it? It’s an integrated runtime environment that allows you to run most AIX programs unaltered, right there on IBM i! It isn’t an emulation environment, nor is it interpreted. It is simply an AIX runtime with access to the full range of IBM i resources. It’s designed for accommodation, particularly for C and C++ programs, but also a full range of others.
PASE and ILE
There are really worlds that live in complete harmony on IBM i (for example, the ILE world and the PASE world). And the remarkable thing is that these worlds peacefully coexist, sharing many resources across what would seem to be an impenetrable wall. Here is just some of what is shared in these environments:
- User/group profiles
- Process structures
- Thread structures
- Database (DB2)
- Integrated File System (IFS)
- System Licensed Internal Code (SLIC) kernel, below Machine Interface (MI)
- PowerPC machine instruction set (no emulation)
- Most everything ... even “underwear”—such as hardware resources (disk, memory, CPU, and so on)
The IBM i really does have quite a unique architecture, and you are welcome to grub around on the Internet for more information, but I think the success of the architecture and the reason that PASE and ILE live so comfortably together is that the operating system lives well above the hardware; so much of what goes on with processor changes has little to no effect on the existing running applications. Sure, they run faster, but they also still run.
When was the last time you ran a DOS program from 1985 in Windows 10? OK, who would want to? Sometimes I hear complaints that folks make the latest POWER8 system look like a dinosaur because they are still running apps written in 1990 (or earlier) on IBM i. “Pshaw,” I say! Move some applications that run in PHP, or Ruby/Rails out of the constantly patched environments of Windows and get settled in on PASE or ILE on IBM i. Free up some admin time to have some fun, for goodness sakes. Life is too short to spend it patching security holes …, but let’s not go there right now. Classic buffer overflow exploits that fall over into some privilege-escalation bug just don’t happen in the PASE Garden of Eden. You are safe and secure there.
The beauty of sharing in PASE and ILE makes it the perfect place to leverage rock-solid business apps with nice, cutting-edge Web technologies like Node.js. What are the differences between the two? Let’s look at Table 1 below.
Table 2.1: Differences Between the PASE and ILE Environments
PASE |
ILE |
/QOpenSys/IBM |
LIB/FILE.MBR |
Debuggers “unlimited” |
Debuggers “very limited” |
Allows code generation |
No code generation |
Uses syscalls to kernel |
Uses MI to kernel |
ASCII |
EBCDIC |
Float, double, int, char |
Adds packed, zoned |
Main program (/PATH/mypgm) |
ILE *PGM |
Shared objects (lib.a, lib.so) |
ILE *SRVPGM |
Use env vars (PATH, LIBPATH) |
Uses *LIBL |
Shells (qp2term, ssh, bash …) |
QSH (*PGMs) |
Call ILE (_PGMCALL, _ILECALL) |
Call PASE (Qp2RunPase, Qp2CallPase, QP2SHELL) |
Even with these differences, there is much similarity. What I find in common particularly within each environment is the way you can leverage programs to work together. ILE allows for multiple languages and program objects to play well together. The same applies to PASE. Combined, PASE and ILE take advantage of the power of IBM i and maximize the flexibility in which you can approach building solutions. And, as much as I love to play within that garden of flexibility, the real value is that when it comes to running a business, you have a broad world of programming and solutions at your fingertips.
Installing PASE
No biggie here. You install using the Install Licensed Programs menu or command (you choose). The product is 5770-SS1 Option 33. It is a free licensed program, and actually this thing should come installed with the base OS, in my humble opinion. It seems to be an increasingly essential component of everything I run into. Keep it current with PTFs. Actually, as a runtime, I really never gave it a second thought after I installed it. Like the IBM i OS, it just runs.
PASE Applications
Remember that 5733OPS ships with a bunch of PASE-ready applications. They are already compiled for PASE, most likely for AIX version 5.1, which is the lowest common denominator for all currently supported versions of IBM i.
Theoretically (remember this is technology, not science), you can take binaries compiled for the corresponding AIX release and drop them into PASE, and they might work. Several websites have binaries ready for download and installation. The Young i Professionals website (http://yips.idevcloud.com/wiki/) is one, and the perzl.org website is another.
You can also compile your own binaries if you have an adventurous spirit and a lack of good common sense. I can’t remember exactly what year it was, maybe 2004 or so, that I was compiling PHP in PASE during the Thanksgiving holiday. It was an excruciating learning curve for a “seat of the pants” RPG programmer like me, but the gleeful happy dance that resulted from a clean compile was worth the effort. Nothing like trying something new and finally getting it to work! I just love this stuff. So, if a hack like me could figure it out from scratch over a decade ago, you certainly can do it today. There is plenty of help from many very good minds that know the PASE environment and can steer you through the ins and outs of compiling C code (it’s mostly C with some C++). The GNU compiler is now included as part of the 5733OPS license code offering. It’s practically begging you to try!
PASE apps can be written in C, C++, Fortran, or PowerPC assembler (!). PASE apps use the same binary executable format as AIX PowerPC applications, which is cool and very compatible. Those PASE binaries run in an IBM i job, and as I mentioned, PASE programs use IBM i system functions, such as file systems, security, and sockets. So, again, this is not an operating system within an operating system. The AIX runtime isn’t emulated; it is running on top of SLIC, just like RPG or COBOL, so not only do you have the full range of AIX APIs available, but they run fast. The best of both worlds. There is a broad subset of AIX technology available in PASE, including:
- Standard C and C++ runtime (both threadsafe and non-threadsafe)
- Fortran runtime (both threadsafe and non-threadsafe)
- pthreads threading package
- iconv services for data conversion (handy and available in ILE)
- Berkeley Software Distributions (BSD) equivalent support
- X Window System client support with Motif widget set
- Pseudo terminal (PTY) support
You have your choice of shells, so you can be opinionated about such things (I'm a BASH guy myself). And if you happen to spend a bit of time in Linux distros, like I do, it eventually becomes as comfortable as that overstuffed chair you lounge in. You can enter the PASE world from the IBM i command line by calling QP2TERM, but why would you want to run a terminal emulator from within a terminal emulator? And the shell is terrible (OK, see, now I am opinionated about shells). Typically, you’d have a happier experience using SSH to access the PASE environment, and I highly recommend you do so. The open source Secure Shell (SSH) and Telnet client PuTTY is what I use, but there are several, and any of them will do the job.
Using PASE
You can call PASE programs from the ILE world, and vice versa. Table 2 shows a list of the commands that take you from one world to another (although the jump really isn’t that far).
Table 2: PASE to ILE and Vice Versa
PASE to ILE |
ILE to PASE |
_PGMCALL—Call *PGM |
Qp2RunPase—Run PASE program (main) |
_ILELOADX—Load *SRVPGM |
Qp2dlopen—Load PASE module (*.a, *.so) |
_ILESYMX—Find export symbol (proc) |
Qp2dlsym—Find export symbol (function) |
_ILECALLX—Call export procedure |
Qp2CallPase—Call PASE function |
_CVTSSP—Convert space pointer |
Qp2dlclose—Close load |
_CVTTS64—Convert teraspace addr |
Qp2dlerror—Get last error dl operation |
_GETTS64—Get teraspace addr |
Qp2malloc—Alloc PASE heap memory |
GETTS64SPP—Get teraspace addr |
Qp2free—Free PASE heap memory |
_GETTS64M—Get multiple teraspace |
Qp2SignalPase—Post signal to PASE |
_SETSPP—Set space pointer |
Qp2EndPase—End PASE |
SETSPPTS64—Set space pointer |
Qp2jobCCSID—Get PASE job CCSID (last) |
_SETSPPM—Set multiple space pointers |
Qp2paseCCSID—Get PASE CCSID (last) |
systemCL()—Run CL command |
Qp2ptrsize—Get ptr size running PASE job |
It’s actually pretty simple. Take a look at this CL program that runs the ls program in PASE (ls is the “list files” command similar to dir). It’s the “cheater’s” way to do it because I am just invoking the PASE shell and running the command within it.
PGM
DCL VAR(&CMD) TYPE(*CHAR) LEN(20) VALUE('/QOpenSys/bin/ls')
DCL VAR(&PARM1) TYPE(*CHAR) LEN(10) VALUE('/')
DCL VAR(&NULL) TYPE(*CHAR) LEN(1) VALUE(X'00')
CHGVAR VAR(&CMD) VALUE(&CMD *TCAT &NULL)
CHGVAR VAR(&PARM1) VALUE(&PARM1 *TCAT &NULL)
CALL PGM(QP2SHELL) PARM(&CMD &PARM1)
ENDIT:
ENDPGM
The flip side is to invoke an ILE CL program from PASE. That takes a C language program, compiled in PASE:
/* sampleCL.c
example to demonstrate use of sampleCL to run a CL command
Compile with a command similar to the following.
xlc -o sampleCL -I /whatever/pase -bI:/whatever/pase/as400_libc.exp sampleCL.c
Example program using QP2SHELL() follows.
call qp2shell (’sampleCL’ ’wrkactjob’) */
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <as400_types.h> /* PASE header */
#include <as400_protos.h> /* PASE header */
void main(int argc, char* argv[])
{
int rc;
if (argc!=2)
{
printf("usage: %s \"CL command\"\n", argv[0]);
exit(1);
}
printf("running CL command: \"%s\"\n", argv[1]);
/* process the CL command */
rc = systemCL(argv[1], /* use first parameter for CL command */
SYSTEMCL_MSG_STDOUT
SYSTEMCL_MSG_STDERR ); /* collect messages */
printf("systemCL returned %d. \n", rc);
if (rc != 0)
{
perror("systemCL");
exit(rc);
}
}
You may not be a C programmer, but I bet you can follow the coding here. You have a standard set of C header files—such as stdio.h, stdlib.h, and errno.h—and then some PASE-specific headers that reference the APIs and constants needed to make the CL call. In this case, you aren’t “shelling into” the IBM i command line and back out. The results will be piped directly back to the C program and displayed on the command line.
These examples, and a host of others, can be found in the IBM Knowledge Center PDF, IBM PASE for i (https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_71/rzalf/rzalfmstpdf.htm). My preference is for agonizing detail, explaining stuff that even the author thinks the audience should know, but this document is a little light on details in some places. If you can get the examples to compile, though, that learning curve alone should be a good grounding.
PASE is where all the action is in the IBM i open source software world. It’s a lush garden of goodness! Enjoy!
LATEST COMMENTS
MC Press Online