Skip to contentSkip to conversation

PPC byte ordering

DISCUSSION David Riley 6 participants 7 messages Jul 19, 2000 – Oct 31, 2000

lore
Share & tools
lore
#3 lore raw
In reply to Timothy A. Seufert
Quoted 10 lines
Quoted 6 lines · Neil Russell

It would in theory be possible to have the kernel run big-endian as it is and have certain user programs run little endian by setting the LE bit in the MSR register for the process in question. The real problem here is that you have to add a *lot* of code to system calls to make this work. There are a few system calls that this would be real difficult, such as ioctl(). I once looked into doing this for the MIPS with SVR4 UNIX.

Quoted 6 lines

The other real problem is that Linus Torvalds has already said that he will never ever in a million years accept a patch which attempts to do such a thing, so you'd have to fork the kernel to do it. According to Linus, architectures are either big or little-endian, not both. A sane position considering the syscall ugliness you mention

How do the linux-mips people handle with big- and little-endian code ? Maybe they know a good solution, which allows both big- and little-endian code to execute.
The PPC is big-endian by nature, and what for we do need little-endian code to be executed on a PPC ?

MfG

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#0 lore raw

Before I get dirty looks, I know the PowerPC's default byte ordering is big-endian (the way things *should* be :-). What I'm asking is slightly irrelevant to most development discussion here, but...

I know that the PowerPC does allow both endian modes. My big question is how well it works in little endian mode. I know we'll never switch Linux to this, since that would be too much unnecessary work, but just for reference: Is it broken? I have heard reports to this effect.

Thanks,
David

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#1 lore raw

Some PPC CPUs don't implement all load/store instructions for little endian; for instance, the 603 CPUs don't do lmw, stmw, lswi, lswx, stswi, stswx for little endian. I seem to remember that there are other problems aside from the ones that I mentioned. Later CPUs don't seem to have a problem.

It would in theory be possible to have the kernel run big-endian as it is and have certain user programs run little endian by setting the LE bit in the MSR register for the process in question. The real problem here is that you have to add a *lot* of code to system calls to make this work. There are a few system calls that this would be real difficult, such as ioctl(). I once looked into doing this for the MIPS with SVR4 UNIX.

Neil.

Quoted 4 lines · David Riley

Before I get dirty looks, I know the PowerPC's default byte ordering is big-endian (the way things *should* be :-). What I'm asking is slightly irrelevant to most development discussion here, but...

Quoted 8 lines

I know that the PowerPC does allow both endian modes. My big question is how well it works in little endian mode. I know we'll never switch Linux to this, since that would be too much unnecessary work, but just for reference: Is it broken? I have heard reports to this effect.

Thanks,
David

--
Neil Russell <[email protected]>

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#2 lore raw
Quoted 6 lines · Neil Russell

It would in theory be possible to have the kernel run big-endian as it is and have certain user programs run little endian by setting the LE bit in the MSR register for the process in question. The real problem here is that you have to add a *lot* of code to system calls to make this work. There are a few system calls that this would be real difficult, such as ioctl(). I once looked into doing this for the MIPS with SVR4 UNIX.

The other real problem is that Linus Torvalds has already said that he will never ever in a million years accept a patch which attempts to do such a thing, so you'd have to fork the kernel to do it. According to Linus, architectures are either big or little-endian, not both. A sane position considering the syscall ugliness you mention...

Tim Seufert

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#5 lore raw
Quoted 8 lines · Timothy A. Seufert
Quoted 6 lines · Neil Russell

It would in theory be possible to have the kernel run big-endian as it is and have certain user programs run little endian by setting the LE bit in the MSR register for the process in question. The real problem here is that you have to add a *lot* of code to system calls to make this work. There are a few system calls that this would be real difficult, such as ioctl(). I once looked into doing this for the MIPS with SVR4 UNIX.

Quoted 4 lines

The other real problem is that Linus Torvalds has already said that he will never ever in a million years accept a patch which attempts to do such a thing, so you'd have to fork the kernel to do it. According to Linus, architectures are either big or little-endian,

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Quoted 1 line

not both. A sane position considering the syscall ugliness you

^^^^^^^^^

Quoted 1 line

mention...

Really? Or did he mean: big-endian kernels must not run little-endian binaries and vice versa.

Note that there exist 3 flavors of MIPS: 32-bit big-endian, 32-bit little-endian and 64-bit. Linux supports them all. Expect to upgrade the hard drives on your local Debian mirror soon :-)

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#4 lore raw
In reply to Heiko Jakob
Quoted 3 lines · Heiko Jakob

How do the linux-mips people handle with big- and little-endian code ? Maybe they know a good solution, which allows both big- and little-endian code to execute.

They compiler the kernel and the apps for different endianness AFAICT.

Quoted 2 lines

The PPC is big-endian by nature, and what for we do need little-endian code to be executed on a PPC ?

We don't need, especially since PPC endian switching is painful enough that you don't want to switch endianness on the fly:

- the 601 uses a completely different, and much more complex method

- switching the processor is not sufficient if you want to access I/O due to the "address munging" system used to give the impression of little-endianness. The bridge also has to be reprogrammed, which is slow and causes some problems with SMP when the two processors are runninng with different byte orderings. Even a simple memory copy between two areas use by different endianness process would have to mung/unmung the data, even for simple text (or processes communicating through pipes...).

I have written an x86 emulator for ROM BIOSes, it is much easier to run it in big endian and do byte swaps on every memory access (even the registers are byte swapped in a memory image actually). Older processors will trap on a 16 bit access at an odd address in LE mode, but lhbrx/sthbrx on an odd address will work perfectly in BE mode. The BIOS does a lot of 16 bit unaligned accesses due to its 8-bit 8088 origins, the emulator just does not care, to the point that there is not a single alignment check in the code (download it from ftp://vlab1.iram.es/pub/ if you are curious).

In short, the mixed endian capability of PPC is not good enough to be effectively used. It would be a nightmare to try to use it. Make your life
simpler: forget about it.

If you absolutely want to do it, add minimal support to the kernel (wont't be easy to support 601 though) and handle the rest as a userspace problem.

Gabriel.

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#6 lore raw
In reply to Geert Uytterhoeven
Quoted 16 lines · Geert Uytterhoeven
Quoted 8 lines · Timothy A. Seufert
Quoted 6 lines · Neil Russell

It would in theory be possible to have the kernel run big-endian as it is and have certain user programs run little endian by setting the LE bit in the MSR register for the process in question. The real problem here is that you have to add a *lot* of code to system calls to make this work. There are a few system calls that this would be real difficult, such as ioctl(). I once looked into doing this for the MIPS with SVR4 UNIX.

Quoted 4 lines

The other real problem is that Linus Torvalds has already said that he will never ever in a million years accept a patch which attempts to do such a thing, so you'd have to fork the kernel to do it. According to Linus, architectures are either big or little-endian,

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Quoted 1 line

not both. A sane position considering the syscall ugliness you

^^^^^^^^^

Quoted 8 lines
Quoted 1 line

mention...

Really? Or did he mean: big-endian kernels must not run little-endian binaries and vice versa.

Note that there exist 3 flavors of MIPS: 32-bit big-endian, 32-bit little-endian and 64-bit. Linux supports them all. Expect to upgrade the hard drives on your local Debian mirror soon :-)

You're absolutely correct -- what he doesn't want (at least as I interpreted the email I'm remembering from a linux-kernel discussion) is mixing modes. In other words, the official Linus kernel will never support mixed LE and BE processes at runtime; you must choose one or the other at kernel compile time.

Tim Seufert

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/