Helping ordinary people create extraordinary websites!
HOME TUTORIALS SCRIPTS WEB HOSTING BLOG FORUM
Get Our Newsletter
Email:

Porting Enterprise Apps from UNIX to Linux

By Martyn Honeyford
2005-04-17


Architecture-Specific Changes

Architecture-specific code in an application is typically limited to a few areas. I'll look at some examples in this section.

Determining endian-ness
The programmer does not have to worry about which architecture the code being written for. Linux provides a way to determine the endian-ness in /usr/include/endian.h. Following is a typical code snippet you can use to determine if the operating environment is big- or little-endian; you can set a specific flag for your convenience.

/• Are we big-endian? •/

#include <endian.h>
#if __BYTE_ORDER == __LITTLE_ENDIAN
#define MY_BIG_ENDIAN
#elif __BYTE_ORDER == __BIG_ENDIAN
#undef MY_BIG_ENDIAN
#endif
Determining the stack pointer
Inline assembly can be written to determine the stack pointer.

int get_stack(void ••StackPtr)

{
•StackPtr = 0;
#ifdef CMP_x86
__asm__ __volatile__ ("movl %%esp, %0": "=m" (StackPtr) );
#else
#error No code for this architecture in __FILE__
#endif
return(0);
}

Implementing compare and swap
Here's an example of implementing compare and swap for the Intel architecture.

bool_t My_CompareAndSwap(IN int •ptr, IN int old, IN int new)

{

#ifdef CMP_x86
unsigned char ret;

/• Note that sete sets a 'byte' not the word •/

__asm__ __volatile__ (
" lock\n"
" cmpxchgl %2,%1\n"
" sete %0\n"
: "=q" (ret), "=m" (•ptr)
: "r" (new), "m" (•ptr), "a" (old)
: "memory");

return ret;
#else
#error No code for this architecture in __FILE__
#endif

}


Tutorial Pages:
» A Practical Checklist, Tips, and Insight Drawn from Experience
» Get the Build System Working
» Decide on a Viable Operating Environment
» Architecture-Specific Changes
» Choose an IPC Mechanism
» Select the Threading Model
» File System, Usage Parameters, Stacks
» Memory Maps and Using Shared Memory Segments
» Signaling
» Configure Kernel Karameters
» Parser Tools like lex/yacc
» Globalization Issues
» Security Concerns
» Locating Installed Packages and Variable Data
» Testing
» There's a Port in Every Storm
» Resources


First published by IBM DeveloperWorks


 | Bookmark
Related Tutorials:
» How to Install PHP 5 on Linux
» How to Install Apache 2 on Linux
» How to Install MySQL 5.0 on Linux
» SMB Caching
» Mound --Bind
» Tar Wild Card Interpretation