Subject: [RFC] Running reverse-endian binaries
To: None <tech-kern@netbsd.org>
From: Emmanuel Dreyfus <manu@netbsd.org>
List: tech-kern
Date: 12/26/2002 21:37:08
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