OS/2 for the PowerPC: Development Tools Coming Online Fast!

From EDM2
Revision as of 18:56, 8 January 2018 by Ak120 (Talk | contribs)

Jump to: navigation, search

by Robert Warren

Development tools for OS/2 for the PowerPC are rapidly becoming available for software developers porting applications to the new PowerPC-based systems. The good news is that porting current OS/2 applications to the new OS/2 for the PowerPC platform is easy. In fact, in the IBM porting lab, over a million lines of code were ported within a week. Volume 6 of The Developer Connection for OS/2 includes the complete MetaWare OS/2 for the OS/2 and PowerPC C/C++ development toolset.

Native and Cross Compilers

The MetaWare High C/C++ compiler is leading the emergence of development tools by providing a native OS/2 compiler, as well as an OS/2 cross compiler to OS/2 for the PowerPC. This means that you will be able to develop applications on your Intel-based OS/2 system and generate executables that run on the new OS/2 for the PowerPC platform. MetaWare provides a variety of development tools that are available in a "native" and "cross" platform capacity. This technology works because the MetaWare toolset provides the same C/C++ language parser and command-line switches on all supported platforms. Most applications will be easily retargeted for use with another platform simply by editing a makefile. Developers do not have to change compiler switches or muck with other compiler-specific issues.

The cross compiler is especially useful for developers who currently have OS/2 applications running and would like to retarget their applications for the PowerPC. While obtaining PowerPC hardware might be difficult initially, generating applications will be an easy port because applications can be built on your existing OS/2 system today.

Start Development NOW!

Since your accompanying Developer Connection for OS/2 CD-ROM contains the MetaWare OS/2 for the PowerPC cross toolset, you can start porting your OS/2 applications to the new operating system immediately using your Intel-based system. I ported several demonstration programs to OS/2 for the PowerPC, without changing a single line of source code. I simply changed my makefiles to include the MetaWare PowerPC toolset and linker; my code compiled and linked without a hitch. Presentation Manager code that uses buttons and dialogs and bitmaps were easily retargeted to the PowerPC. Resource files were quickly recompiled without modification and linked to the executable. I was also able to use code that required the System Object Model (SOM) kernel because, like OS/2 for Intel platforms, the new operating system employs the SOM standard.

A Simple Example

Just to show how easy compiling for OS/2 for the PowerPC is, I'll take you through a simple example. I have a minimal PM application that simply places a WinMessageBox on the screen and then exits when the you press the OK button.

First, you create a definition file (.DEF) for the main module. My Presentation Manager application is named SIMPLE.CPP, so I created a .DEF file named SIMPLE.DEF. Sample Code 1 shows its contents:

NAME           SIMPLE  WINDOWAPI          ; This is a PM app named simple!
DESCRIPTION    'MetaWare Simple Example'  ; Any string you please
PROTMODE                                  ; Protected Mode
HEAPSIZE       1024
STACKSIZE      8192

Sample Code 1. SIMPLE.DEF

If you do not provide a definition file, the linker issues a warning and provides you with a default for a console (text-based) application. This definition file asserts that it is a WINDOWAPI application, which means that it will target Presentation Manager.

Now, let's look at the source for my simple application:

#define INCL_WINWINDOWMGR
#define INCL_WINDIALOGS

#include <os2.h>

void main()
{
 HAB  hab = WinInitialize (0);          // initialize for PM application
 HMQ  hmq = WinCreateMsgQueue (hab, 0); // Create a message queue

 // Call the Message Box routine
 WinMessageBox (HWND_DESKTOP, HWND_DESKTOP, (PCH) "Hello PM World",
   (PCH) "WorkplaceOS", 100, MB_OK | MB_ICONASTERISK | MB_MOVEABLE);

 WinDestroyMsgQueue (hmq);              // Kill the queue
 WinTerminate (hab);                    // Chain to the OS
}

Sample Code 2. SIMPLE.CPP

Finally, I need to compile this using MetaWare's OS/2 cross to PowerPC compiler. This is invoked by the following command line:

hcae6k -Hdef=simple.def simple.cpp

The MetaWare compiler will compile your code and automatically call the assembler and linker with the proper options to create the Presentation Manager compatible executable for the PowerPC.

Now that we have a simple example out of the way, let's talk about some of the differences in the toolset between OS/2 for Intel and OS/2 for the PowerPC development.

ELF Object Files

The object file format used on the PowerPC is the Executable Load Format (ELF). This means that you must use the MLIB.EXE utility to create archive (library) files, rather than the librarian used for Intel/OMF files. MLIB also can be used to link binary resources into executables. A Dump utility also is provided for analysis of ELF object files.

Resources

MRES.EXE is the resource compiler that turns .RC files into binary resource files. MRES is invoked a bit differently from the OS/2 for Intel resource compiler; however, there is a RC compatibility mode that makes it easier to use. Resource files are completely compatible across platforms because they are in the form of simple text files and contain no platform-specific code or data.

Benefits of OS/2 and the PowerPC

The PowerPC running OS/2 is destined for success. The PowerPC provides a flexible and inexpensive way for the mainstream market to take advantage of the high-performance RISC architecture. Until now, systems with RISC chips have been very expensive, running software with no need in the mass market. OS/2 and the PowerPC change the complexion of the RISC market, so that popular software can be quickly retargeted to OS/2 running on the RISC-based PowerPC at a reduced cost. What this boils down to is that more people will be able to realize the performance potential that the RISC-based PowerPC has to offer.

Soon, MetaWare will provide a native PowerPC OS/2 toolset, to go with the native Intel OS/2 toolset and the cross toolset from Intel to PowerPC--all in one package. For licensed developers, all these components will be available free as upgrades. MetaWare is committed to the IBM OS/2 for the PowerPC strategy and providing essential tools and enabling technology for software developers.

Porting Tips

While there are very few coding "gotchas" with the new OS/2 for the PowerPC, they are worth noting before starting on a port. Here are some tips to watch out for when porting to the new processor and operating system:

  • Linked-in assembly routines will have to be converted to PowerPC-based assembly and assembled with the PowerPC assembler. PowerPC architecture reference books are already in available in technical bookstores.
  • The size of structures might change due to the difference in the way that word alignment works on the PowerPC. Any code that compares the size of a structure with a constant might become suspect. However, allocating memory by using the sizeof function to obtain the structure size is completely safe.
  • Specific functions to control Intel-specific hardware devices are not compatible. For example, library functions that control the floating point processor do not apply because there is no X87 chip on a PowerPC. Any port I/O routines must be recoded if the hardware device is not available.

Simply compiling with the MetaWare compiler can help produce more portable code. The compiler can be set to enforce full ANSI C++ syntax checking, which will point out many places that code might not be portable. You can tune up your MetaWare compiler's ANSI enforcement by using the following compiler switch:

hcae6k -Hcpplvl=3 anyfile.cpp

Reprint Courtesy of International Business Machines Corporation, © International Business Machines Corporation