Subject: Re: [RFC] Running reverse-endian binaries
To: Emmanuel Dreyfus <manu@netbsd.org>
From: Michael Graff <explorer@flame.org>
List: tech-kern
Date: 12/26/2002 13:17:42
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

This sounds like a Bad Idea.  Sorry.  :)

Wouldn't you have to runtime choose which htonl() and so on to run?
Remember that it's not just for kernel stuff, it's also for on-disk
and in-packet data.

I don't see a straight-forward way of doing that which won't kill
performance, cause major issues with nightmare-like hacks, or both.

- --Michael

manu@netbsd.org (Emmanuel Dreyfus) writes:

> Hi all
> 
> A nice feature for NetBSD/mips would be the ability to run reverse
> endian binaries, it would make possible to run IRIX binaries on
> NetBSD/cobalt, for instance. Moreover, I recently had some questions
> from someone that would want to run big endian binaries on NetBSD/hpcarm
> (which is little endian for now), so I'd like to get a more precise idea
> of what needs to be done.
> 
> Here is a rought idea:
> 
> - add a P_REVENDIAN p_flag in struct proc
> - check for reverse-endianness in
> sys/kern/exec_elf32.c:exec_elf32_makecmds(), and set the P_REVENDIAN
> flag correctly.
> - modify copy{in|out}[_proc] to eventually reverse the data copied from
> and to userland if P_REVENDIAN is set
> - modify the trap handler to 
>   + set endianness to the kernel endianness immediatly on kernel enter
>   + after the trap frame is made, reverse the data in it if P_REVENDIAN
>   + same before restoring the context from trap frame
>   + when leaving the kernel, restore process' endianness
> 
> All the modification would be ifdef REVERSE_ENDIAN
> 
> Opinions about this? Did I missed something important? 
> I have a little concern about memory mappings: would mmap'ed memory from
> files be seen correctly? 
> 
> -- 
> Emmanuel Dreyfus.
> "Of course, it runs NetBSD" -- http://www.netbsd.org
> manu@netbsd.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (NetBSD)
Comment: See http://www.flame.org/~explorer/pgp for my keys

iD8DBQE+C3H2l6Nz7kJWYWYRAq/SAJ44PHj7U1535/ulwifPQSjT5ATGGwCeJJWt
ExPzVPppsYmNvzF1cDawXvE=
=+yew
-----END PGP SIGNATURE-----