p-code, p-machine, p-System

Version numbers

This is an overview of different p-System versions.
The underlying basis for the p-System is the hypothetical machine called the p-machine (for “pseudo-machine”). In most implementations, the p-machine is emulated by an interpreter written in the native instruction set of the hardware on which the system is running (for example, Macro-11 for the Terak, 8086 for the IBM Personal Computer, 6502 for Apple, 8080, Z80). The rest of the p-system is p-code, running on this interpreter, which it regards as a machine in its own right.
During the development of the p-System, the p-machine has, on occasion, been changed, meaning that the instruction set was modified. Every time this happens, the ROMAN NUMERAL section of the version number is changed. This is the ONLY time that the Roman numeral is changed. Bug fixes or architecture changes, no matter how extensive, do not change the Roman number.
Note, therefore, that the correct way of spelling the most recent version, is “IV.1”, not “4.1”.

Brief p-System history

This is a listing of p-System version numbers, when they appeared, why, and from whom (not always UCSD). Only more major versions are listed, since there have been too many minor changes to list conveniently. Major events in the development, such as the release of Apple and Western Digital MicroEngine versions, are given breaks in the sequence.

1977

– I.2: released in-house at UCSD
– I.3: released at UCSD, also released to a few other UC campuses. All parts of the system still contained in SYSTEM.PASCAL.
– I.4: general release. System divided into separate filer, editor, compiler.
– I.5: UNITs developed, compiler now able to compile them. Editor now able to copy from other files. Filer how has wildcarding.

1979

– II.0: Second p-machine version. Division of single Remote I/O channel into separate input and output.
– II.1: INTRINSIC units appear: linked directly from library at run-time, rather than being copied into the code file. System now has 32 segments rather than 16, UNITS can be declared as resident or non-resident.
– II.1x7b More swapping capabilities added: screen handlers and others can be made to stay on disc, loaded only when needed.

About this time, the p-System was transferred from the jurisdiction of the University of California to that of Softech Microsystems, a division of Softech Inc., specifically established to maintain the p-System. This was a long process, and the point at which the system was no longer maintained by the University is not clear.

– Apple Pascal 1.0 Close to II.0
– Apple Pascal 1.1 Essentially the same as UCSD II.1; minor modification to editor.
– Apple Pascal 1.2 Support for 64K and 128K systems
– Apple Pascal 1.3 1985
– Apple III Pascal version 2.0 1985

WESTERN DIGITAL CORPORATION

When Western Digital undertook the Pascal MicroEngine project, it designed a new version of the p-machine to implement. This new version was labelled III (since I and II already existed). Version III is therefore dedicated to MicroEngine-based machines.
Volition Systems is a company formed by Randy Bush and Roger Sumner. First version of the Advanced System Editor. Among the changes introduced in version III is the first appearance of parallel processes, and the routines and types needed to control them.
– III.E1 Third p-machine version, by Western Digital Inc. Developed for the Western Digital MicroEngine, (thus far) the only hardware p-machine. Some architectural and philosophical changes from previous versions.
– III.F Some debugging, minor improvements in I/O. Single character typeahead only. Subversions are F0 and F1.
– III.G0 More debugging. NO typeahead whatever.
– III.H0 More debugging. Typeahead restored, but not reliable.

Versions from Western Digital, from Volition Systems and for PDQ.
– III.H1 By Volition Systems for the PDQ-3. Much more reliable than other versions of III.
– III.H1 IME, III.h4 More debugging. System reliability improved, at cost of increased system size and reduced available memory.

SOFTECH MICROSYSTEMS

SofTech MicroSystem’s development efforts started with I.5, II.0, andII.1; intervening efforts by Apple, Western Digital, and Volition Systems were not involved.
Major architectural changes were made:
– expansion of the 16-segment system to 256 segments;
– all segments (units, assembly segments, segment routines, etc.) can be dropped from memory;
– all currently loaded segments are kept in memory until demand forces them to be dropped.
– programs can create and start parallel tasks (the program itself is the main task).
The running of the tasks is done differently from the way version III does it.

1980

– IV.0 Most recent p-machine change.
Extensive changes in both p-machine instruction set and Pascal system architecture.
SofTech MicroSystems licensed various companies (such as the IBM PC, DEC Rainbow and Xerox and Texas Instruments TI -99/4) to bring up IV.0 implementations on their machines.

– IV.1 Under license from SofTech MicroSystems, several companies(such as Sage Technology in Nevada, and Network Consulting Incorporated in British Columbia) bring up IV.1 for various machines:
– NCI releases a version for the IBM PC more powerful, faster, and more reliable than that released by IBM.
– Ticom Inc. releases a version for the DEC Rainbow 100.
– Advanced Systems Editor now available under IV.
– Scheduling of parallel processes debugged.

NCI eventually took over from SofTech Microsystems and then later Pecan took over from NCI.
Pecan continued the work under the name Pecan Software Systems Inc. In 1986 they sold the Power System, a host based version of the p-System for MS-DOS, Macintosh Finder, AtariTOS, AmigaDos, Apple II under Prodos, CP/M, RT-11, RSX, RSTS, VMS, Unix. The Pascal compiler then allowed native code generation (8086,68000,9900, PDP-11, Z80 and 8080) besides p-code and 16 MB of addressable memory for code. Besides Pascal also Modula-2, Basic and Fortran-77 compilers were available,

Cabot Software in the UK embedded software was the last known commercial company to use the UCSD p-System technology, mainly in embedded systems. It seems they continued that until around 1999. No more commercial company seems to have a license from UCSD for the p-System now.

p-code versions

The term p-code was introduced by the group of Niklaus Wirth, for example for the intermediate code produced by the Pascal-P compiler. P-code is the Assembly language for a hypothetical stack machine, the P-machine, said to have been an imitation of the instruction set for the Burroughs Large System. The term was used in the classic book Algorithms + Data Structures = Programs, N. Wirth, P-H 1976. Byte articles on writing a Pascal Compiler in Northstar BASIC (ca Aug 1978) also used the term. Later used as the intermediate language in the UCSD P-system. Variants: P2 P-code, P4 P-code, UCSD P-code, LASL P-code. See here for an introduction to p-code.
There are different interpreters for I.3, I.5, II.0, II.1, III, IV.0, and IV.1 at least. In general you can not expect code compiled with the compiler on one release to work with an interpreter from a different release. The differences between the dot releases were minor but could still cause problems.
I.5 and II.0 are actually pretty similar. The biggest differences seem to have occurred between II and III. Version IV added opcodes and changed memory handling to allow more than 64K to be used.

III completely changed the opcodes around. III was only for the Western Digital Pascal Microengine.

IV.0 was derived from II.1 and III. The p-code opcodes are almost the same as III, there are other significant differences such as the memory handling.
Opcodes didn’t change within version numbers. So, the I.x opcodes remained the same (eg the North Star UCSD p-System. The Apple Pascal system used the same op-codes in its different incarnations. But the interpreter code changed to make it faster with some opcodes.
The difference between I.5 and II.0 was the extension of some of the LDC instructions, and a couple of new instructions (). All the rest were the same. The primary reason for the change to II.0 was to speed up the system, and enhanced stability.

Internals

Relevant documents on the p-machine and p-code. In documents like Internals, Operating System, Technical Reference, quite a lot internals are disclosed how the p-machine, p-code and -system are constructed.

p-Source A guide to the Apple Pascal System, Randall Hyde
On performance, optimize, internal operation, p-Code,
modifying the interpreter, BIOS device drivers
Apple III Pascal – Technical Reference Manual
Apple Pascal Operating System Reference manual
Internal_Architecture
SofTech MicroSystems P-System Internal Architecture Reference Manual
pSystem Fortran BASIC System Internals
UCSD P-System UCSD PASCAL Internal Architecture Guide
Softech Microsystems p-Systems Reference
Softech Pascal IV Internal Archecture 1981
2232400-0001 TI UCSD p-System Internal_Architecture Software Library April 1983

MicroEngine p-machine opcodes 1 (III)
MicroEngine p-machine opcodes 2 (III)

Apple Pascal p-machine description
Apple II Pascal 1.1 interpreter disassembly
Apple II Pascal 1.1 interpreter disassembly
Apple ][ Pascal 1.3 P-Machine source isting
Pascal p-code program disassembler I.5 Pascal source
PDP_11 I.5 interpreter source
Z80/8080 Interpreter
p-code interpreter I.5
The p-System Stack and Heap
p-code list with descriptions version IV
Detailed p-machine description Apple 1.3
Pascal II: Operand Formats

p-code list with descriptions version IV




Appendix p-code mnemonics

See here for the p-codes for version IV


I.3 I.5 II.0 II.1
$00 SLDC 0 SLDC 0
$01 SLDC 1 SLDC 1 SLDC 1 SLDC 1
$7F SLDC 7F SLDC 7F SLDC 7F SLDC 7F
$80 ABI ABI ABI ABI
$81 ABR ABR ABR ABR
$82 ADI ADI ADI ADI
$83 ADR ADR ADR ADR
$84 AND LAND LAND LAND
$85 DIF DIF DIF DIF
$86 DVI DVI DVI DVI
$87 DVR DVR DVR DVR
$88 CHK CHK CHK CHK
$89 FLO FLO FLO FLO
$8A FLT FLT FLT FLT
$8B INN INN INN INN
$8C INT INT INT INT
$8D IOR LOR LOR LOR
$8E MOD MODI MODI MODI
$8F MPI MPI MPI MPI
$90 MPR MPR MPR MPR
$91 NGI NGI NGI NGI
$92 NGR NGR NGR NGR
$93 NOT NOT NOT NOT
$94 SRS SRS SRS SRS
$95 SBI SBI SBI SBI
$96 SBR SBR SBR SBR
$97 SGS SGS SGS SGS
$98 SQI SQI SQI SQI
$99 SQR SQR SQR SQR
$9A STO STO STO STO
$9B IXS IXS IXS IXS
$9C UNI UNI UNI UNI
$9D S2P S2P NOTIMP LDE
$9E CSP CSP CSP
$9F LDCN LDCN LDCN LDCN
$A0 ADJ ADJ ADJ ADJ
$A1 FJP FJP FJP FJP
$A2 INC INCR INCR INCR
$A3 IND STIND STIND IND
$A4 IXA IXA IXA IXA
$A5 LAO LAO LAO LAO
$A6 LCA LCA LSA LSA
$A7 LDO LDO NOTIMP LAE
$A8 MOV MOV MOV MOV
$A9 MVB MVB LDO LDO
$AA SAS SAS SAS SAS
$AB SRO SRO SRO SRO
$AC XJP XJP XJP XJP
$AD RNP RNP RNP
$AE CIP CIP CIP
$AF COMPAR EQU CEQU CEQU
$B0 COMPAR CGEQ CGEQ CGEQ
$B1 COMPAR CGTR CGTR CGTR
$B2 LDA LDA LDA LDA
$B3 LDC LDC LDC LDC
$B4 COMPAR CLEQ CLEQ CLEQ
$B5 COMPAR CLSS CLSS CLSS
$B6 LOD LOD LOD LOD
$B7 COMPAR CNEQ CNEQ CNEQ
$B8 STR STR STR STR
$B9 UJP UJP UJP UJP
$BA LDP LDP LDP LDP
$BB STP STP STP STP
$BC LDM LDM LDM LDM
$BD STM STM STM STM
$BE LDB LDB LDB LDB
$BF STB STB STB STB
$C0 IXP IXP IXP IXP
$C1 ?? RBP RBP RBP
$C2 ?? CBP CBP CBP
$C3 EQUI EQUI EQUI EQUI
$C4 GEQUI GEQI GEQI GEQI
$C5 GRTI GTRI GTRI GTRI
$C6 LLA LLA LLA LLA
$C7 LDCI LDCI LDCI LDCI
$C8 LEQI LEQI LEQI LEQI
$C9 LESI LESI LESI LESI
$CA LDL LDL LDL LDL
$CB NEQI NEQI NEQI NEQI
$CC STL STL STL STL
$CD ?? CXP CXP CXP
$CE ?? CLP CLP CLP
$CF ?? CGP CGP CGP
$D0 S1P S1P LPA LPA
$D1 IXB IXB NOTIMP STE
$D2 BYT BYT NOTIMP
$D3 EFJ EFJ EFJ EFJ
$D4 NFJ NFJ NFJ NFP
$D5 BPT BPT BPT BPT
$D6 XIT ABORT ABORT ABORT
$D7 NOP BACK BACK NOP
$D8 SLDLS SLDL SLDL
$D9 SLDLS SLDL SLDL
$DA SLDLS SLDL SLDL
$DB SLDLS SLDL SLDL
$DC SLDLS SLDL SLDL
$DD SLDLS SLDL SLDL
$DE SLDLS SLDL SLDL
$DF SLDLS SLDL SLDL
$E0 SLDLS SLDL SLDL
$E1 SLDLS SLDL SLDL
$E2 SLDLS SLDL SLDL
$E3 SLDLS SLDL SLDL
$E4 SLDLS SLDL SLDL
$E5 SLDLS SLDL SLDL
$E6 SLDLS SLDL SLDL
$E7 SLDLS SLDL SLDL
$E8 SLDOS SLDO SLDO
$E9 SLDOS SLDO SLDO
$EA SLDOS SLDO SLDO
$EB SLDOS SLDO SLDO
$EC SLDOS SLDO SLDO
$ED SLDOS SLDO SLDO
$EE SLDOS SLDO SLDO
$EF SLDOS SLDO SLDO
$F0 SLDOS SLDO SLDO
$F1 SLDOS SLDO SLDO
$F2 SLDOS SLDO SLDO
$F3 SLDOS SLDO SLDO
$F4 SLDOS SLDO SLDO
$F5 SLDOS SLDO SLDO
$F6 SLDOS SLDO SLDO
$F7 SLDOS SLDO SLDO
$F8 SINDS SIND0 SLD0
$F9 SINDS SIND SIND
$FA SINDS SIND SIND
$FB SINDS SIND SIND
$FC SINDS SIND SIND
$FD SINDS SIND SIND
$FE SINDS SIND SIND
$FF SINDS SIND SIND

Table by L.Boshell 1983-1996
History mostly based on a text by Alastair Milne written in 1982, various places on the web and the messages in the UCSD Yahoo group.