© iPerimeter Ltd 2014 1 Unix and IBM i  AIX and Linux run natively on Power Systems  IBM i can do Unix type things in two ways:  Posix/QShell  Ordinary.

Slides:



Advertisements
Similar presentations
Java File I/O. File I/O is important! Being able to write and read from files is necessary and is also one common practice of a programmer. Examples include.
Advertisements

C Tutorial Ross Shaull cs146a Why C Standard systems language – Historical reasons (OS have historically been written in C, so libraries written.
Programmer-defined classes Part 2. Topics Returning objects from methods The this keyword Overloading methods Class methods Packaging classes Javadoc.
CSI 3120, Implementing subprograms, page 1 Implementing subprograms The environment in block-structured languages The structure of the activation stack.
ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson slides3.ppt Modification date: March 16, Addressing Modes The methods used in machine instructions.
Chapter 7 Process Environment Chien-Chung Shen CIS, UD
en-us/sharepoint/fp
Inline Assembly Section 1: Recitation 7. In the early days of computing, most programs were written in assembly code. –Unmanageable because No type checking,
Program Design and Development
CSCE 121, Sec 200, 507, 508 Fall 2010 Prof. Jennifer L. Welch.
Pointers Pointer - A pointer is a derived data type; that is it is a data type built from one of the standard types. Its value is any of the addresses.
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
Guide To UNIX Using Linux Third Edition
Guide To UNIX Using Linux Third Edition
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 2: Operating-System Structures Modified from the text book.
Zach Miller Condor Project Computer Sciences Department University of Wisconsin-Madison Flexible Data Placement Mechanisms in Condor.
POSIX: Files Introduction to Operating Systems: Discussion 1 Read Solaris System Interface Guide: Ch. 5.1 Basic File I/O.
University of Washington CSE 351 : The Hardware/Software Interface Section 5 Structs as parameters, buffer overflows, and lab 3.
1 Chapter One A First Program Using C#. 2 Objectives Learn about programming tasks Learn object-oriented programming concepts Learn about the C# programming.
Homework Reading Programming Assignments
PHP TUTORIAL. HISTORY OF PHP  PHP as it's known today is actually the successor to a product named PHP/FI.  Created in 1994 by Rasmus Lerdorf, the very.
MIPS coding. SPIM Some links can be found such as:
Files and Streams. Java I/O File I/O I/O streams provide data input/output solutions to the programs. A stream can represent many different kinds of sources.
OS provide a user-friendly environment and manage resources of the computer system. Operating systems manage: –Processes –Memory –Storage –I/O subsystem.
Chapter 2: Operating-System Structures. 2.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 2: Operating-System Structures Operating.
By Noorez Kassam Welcome to JNI. Why use JNI ? 1. You already have significantly large and tricky code written in another language and you would rather.
Programming With C.
IT253: Computer Organization Lecture 3: Memory and Bit Operations Tonga Institute of Higher Education.
1 C - Memory Simple Types Arrays Pointers Pointer to Pointer Multi-dimensional Arrays Dynamic Memory Allocation.
Pointers OVERVIEW.
1 Programming in C Hello World! Soon I will control the world! Soon I will control the world!
1 Week 12 l Overview of Streams and File I/O l Text File I/O Streams and File I/O.
Project 2: Initial Implementation Notes Tao Yang.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
CNIT 127: Exploit Development Ch 3: Shellcode. Topics Protection rings Syscalls Shellcode nasm Assembler ld GNU Linker objdump to see contents of object.
JAVA COURSE 1 Computer Engineering Association. Compile your first program Public class Hello{ public class Hello(){ System.out.println(“Hello”); } puclic.
Fall 2002CS 150: Intro. to Computing1 Streams and File I/O (That is, Input/Output) OR How you read data from files and write data to files.
Pointers *, &, array similarities, functions, sizeof.
Computer Organization and Design Pointers, Arrays and Strings in C Montek Singh Sep 18, 2015 Lab 5 supplement.
Files Tutor: You will need ….
Object Oriented Software Development 4. C# data types, objects and references.
Page 1 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Strings Chapter 5.
1 CSC103: Introduction to Computer and Programming Lecture No 28.
Characters and Strings
Embedding Assembly Code in C Programs תרגול 7 שילוב קוד אסמבלי בקוד C.
Announcements Assignment 1 due Wednesday at 11:59PM Quiz 1 on Thursday 1.
Announcements Assignment 1 will be regraded for all who’s score (not percentage) is less than 6 (out of 65). If your score is 6 or higher, but you feel.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 11: Pointers.
CS 31 Discussion, Week 7 Faisal Alquaddoomi, Office Hours: BH 2432, W 4:30-6:30pm, F 12:30-1:30pm.
C is a high level language (HLL)
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
C Programming Day 2. 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/LA07/003 Version No. 1.0 Union –mechanism to create user defined data types.
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
Linux Administration Working with the BASH Shell.
7-Nov Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Oct lecture23-24-hll-interrupts 1 High Level Language vs. Assembly.
Chapter 7 Process Environment Chien-Chung Shen CIS/UD
Hank Childs, University of Oregon April 6 th, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __ / / / /
Lecture 3 Translation.
Last week: We talked about: History of C Compiler for C programming
User-Written Functions
Chapter 22 – part a Stream refer to any source of input or any destination for output. Many small programs, obtain all their input from one stream usually.
System Programming and administration
C Basics.
Operation System Program 4
Computer Science I CSC 135.
Format String.
File Input and Output.
CSC 253 Lecture 2.
SPL – PS2 C++ Memory Handling.
Presentation transcript:

© iPerimeter Ltd Unix and IBM i  AIX and Linux run natively on Power Systems  IBM i can do Unix type things in two ways:  Posix/QShell  Ordinary *PGM code, but called via symbolic link from IFS  Unix (Posix) artefacts in /bin, etc.  QSH command from IBM i environment  Portable Application Solutions Environment, or PASE  AIX code running exactly as it would on AIX, though with limitations to maintain the integrity of IBM i and of its stored objects  Unix (AIX) artefacts in /QOpenSys/bin, etc.  CALL QP2TERM or CALL QP2SHELL  Can also be called direct from an ILE program, although interfacing is complex; PASE memory is not accessible from ILE except via specific IBM APIs, and relevant documentation is sparse  Used extensively by IBM i and its licensed programs  From V6R1 onwards, Java uses PASE  Used by third party products, e.g. Essbase, QAS  Free-of-charge IBM i Developer Tools, 5799-PTL, deliver several important PASE-based tools, specifically PERL, plus some Posix-based tools  IBM i database via CLI or JDBC – no special treatment  Creation of PASE programs on IBM i requires AIX C compiler installed  Open source gcc, or IBM supplied (chargeable) PTL requires the latter  N.B. All PASE and QShell processing, as always in Unix, is case sensitive

© iPerimeter Ltd IBM i job ILE Program Code EBCDIC PASE in this Job (32-bit or 64-bit) ASCII Interfacing ILE and PASE IBM i variables PASE variables IBM-supplied ILE/PASE API (‘QP2’) PASE Library Exported function Custom, Standardised Interface Mechanism written in ILE C 1. Start PASE in job 2. Load required PASE library ILE-PASE data exchange (parameter passing, ASCII EBCDIC) 3. Find and 4. Call req’d library function Output parameters, via special QP2 PASE memory allocation that can also be accessed via ILE pointer Argument list array and signature Data exchange buffer: input strings and output function result Input integer values 5. Unload library, close PASE

© iPerimeter Ltd Simple (?) example – AIX C code, compiled on AIX & run in PASE  Example C source code: test.c  inp1 integer  inp2 string  inp3 integer  inp4 string  outp5 string  outp6 integer  function result is -99  Compile and bind to create C library: test.a  Now FTP test.a to IBM i IFS (use binary mode)  test.a is our PASE library, TestFunction is our exported function

© iPerimeter Ltd ILE C code to call TestFunction: Steps 1 and 2  1. Start PASE in job  2. Load required PASE library  example assumes test.a is in the current IFS directory ( CHGCURDIR )  note (basic) exception handling: ‘QP2’ exceptions, PASE exceptions

© iPerimeter Ltd ILE C code to call TestFunction: Step 3, and notes on Step 4  3. Find required PASE function  Note exception handling as step 2  Now the fun starts: Step 4. We need to:  A. Set up our QP2 argument list and signature, and our QP2 data buffer  B. Translate input strings (inp2, inp4) to ASCII  C. Get all our input parameters into the QP2 argument list and QP2 data buffer  D. Allocate PASE memory for output parameters  E. Get all our output parameter pointers into the QP2 argument list  F. Call TestFunction (at last!)  G. Get function result  H. Get output parameters (outp5, outp6)  I. Translate output strings (outp5) to EBCDIC

© iPerimeter Ltd ILE C code to call TestFunction: Step 4: Call function: A  4.A. Set up our QP2 argument list and signature, and our QP2 data buffer  inp1 integer (QP2 ‘word’, 32 bits = 4 bytes long)  inp2 string (pointer will be set to location of string in data buffer)  inp3 integer (QP2 word)  inp4 string (pointer will be set to location of string in data buffer)  outp5 string (pointer, see later)  outp6 integer (pointer, see later)  Note the null terminator (QP2_ARG_END) on the signature

© iPerimeter Ltd ILE C code to call TestFunction: Step 4: Call function: B  4.B. Translate input strings (inp2, inp4) to ASCII  Only inp2 shown, to save space; inp4 handled identically  Note that we are assuming iconv is successful – could reasonably add relevant exception handling here  Puts ASCII version straight into QP2 data buffer, adding the necessary C string null terminator

© iPerimeter Ltd ILE C code to call TestFunction: Step 4: Call function: C, D, E  C. Get all our input parameters into the QP2 argument list and QP2 data buffer  Put inp1 and inp3 into QP2 argument list. We’ve already put inp2 & inp4 in the data buffer, just need to set their correct pointer values in the QP2 argument list  D. Allocate PASE memory for output parameters  TestFunction needs to see PASE 32 bit pointers for the two output parameters;  ILE C needs to see the same memory locations via ordinary IBM i pointers;  Qp2malloc does this magic  E. Get all our output parameter pointers into the QP2 argument list  Note that Qp2malloc returns a 64-bit PASE pointer; the ones in the QP2 argument list are 32-bit  Have not tried 64-bit PASE  This lot is what made me decide I wanted to do this in ILE C (where there was a decent, if 64-bit PASE, example in the IBM documentation) not in ILE RPG

© iPerimeter Ltd ILE C code to call TestFunction: Step 4: Call function: F, G, H, I  F. Call TestFunction (at last!)  QP2/PASE exception handling as step 2  The QP2_RESULT_WORD indicates that there will be a 32-bit integer function result from TestFunction  G. Get function result  Returned in the QP2 data buffer as mentioned previously  H. Get output parameters (outp5, outp6)  Note the use of the ILE versions of the Qp2malloc-generated pointers  I. Translate output strings (actually only one, outp5) to EBCDIC

© iPerimeter Ltd ILE C code to call TestFunction: Step 5, Output, Notes  5. Unload library, close PASE  Output (to job standard output, stdout):  First 7 lines come from PASE  Last 3 lines come from ILE  Notes:  Code embedded: test.c (PASE) and QCLESRC. CALLPASE (ILE). Note that the ILE code differs slightly from the examples above, which have been tidied up for clarity.  Compilation option needed for ILE C code: CRTBNDC TERASPACE(*YES *TSIFC)