Skip to contentSkip to conversation

big endian code of NUE gcc

Linux-ia64 Fujio Ikegami 2 participants 2 messages Sep 19, 2000

lore
Share & tools
lore
#0 lore raw

Hi,

I tried to get big endian code by using NUE gcc under IA-32 Linux as follows:
gcc -mbig-endian -o endian endian.c
But the code I got was not big endian.
Question:
Is the compiler option of -mbig-endian effective?
Does Red Hat support big endian code?

Best Regards,
Fujio Ikegami

<attachement>
1. Operation
[ikegami@alfard hit]$ nue
bash$ gcc -mbig-endian -o endian endian.c
bash$ endian
u1634 u32345678 u6434567890ABCDEF
u16
FFFFF98E 3412 |4 |
u32
FFFFF988 78563412 |xV4 |
u64
FFFFF980 EFCDAB90 78563412 | xV4 |
bash$

2. endian.c
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
void dump(char *title,void *vp,int len);
int main() {
unsigned short int u16;
unsigned int u32;
unsigned long long int u64;
u16=0x1234;
u32=0x12345678;
u64=0x1234567890abcdef;
printf("u16=%x u32=%x u64=%lX\n",u16,u32,u64);
dump("u16",&u16,2);
dump("u32",&u32,4);
dump("u64",&u64,8);
return 0;
}
void dump(char *title,void *vp,int len) {
// hex dump */

     unsigned char *p;
     int i,j,c;
     char buf[32];

     p=(unsigned char *)vp;
     printf("%s\n",title);
     for(i=j=0;i<len;i++) {
       c=p[i];
       if (i%16=0) {
         if (i>0) printf(" |%s|\n",buf);
         printf("%08X  ",p+i);
         j=0;
       }
       if (i%4=0) printf(" ");
       printf("%02X",c);
       sprintf(&buf[j++],"%c",to_char(c));
     }
     for(i=j;i<16;i++) {
       if (i%4=0) printf(" ");
       printf("  ");
     }
     printf(" |%s|\n",buf);
     return;
}

int to_char(int c) {
if (c<' ' || c>0x7f) return ' ';
return c;
}

#1 lore raw

ia64-linux is little-endian. The -mbig-endian option won't do anything useful on an ia64-linux system. You probably should have gotten a linker error message though. I think gcc needs to pass an option to the assembler so that it can set the big-endian bit in the elf header. Or else emit an assembler directive to do this.

If you are emitting code for a different OS, and that OS has big-endian support, and gcc has support for that OS, then -mbig-endian should do something useful. I do not know of any big-endian IA-64 targets at this time though, so the big-endian support has never been tested.

Jim