home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
NeXTSTEP 3.2 (Developer)
/
NS_dev_3.2.iso
/
NextDeveloper
/
Source
/
GNU
/
cctools
/
libstuff
/
bytesex.c
< prev
next >
Wrap
Text File
|
1993-01-04
|
39KB
|
1,320 lines
/* byte_sex.c */
#include <mach-o/fat.h>
#include <mach-o/loader.h>
#import <mach/m68k/thread_status.h>
#import <mach/m98k/thread_status.h>
#import <mach/m88k/thread_status.h>
#import <mach/i860/thread_status.h>
#import <mach/i386/thread_status.h>
#include <mach-o/nlist.h>
#include <mach-o/reloc.h>
#include <bsd/ranlib.h>
#include "stuff/bool.h"
#include "stuff/bytesex.h"
double
SWAP_DOUBLE(
double d)
{
union {
char c[8];
double d;
} in, out;
in.d = d;
out.c[0] = in.c[7];
out.c[1] = in.c[6];
out.c[2] = in.c[5];
out.c[3] = in.c[4];
out.c[4] = in.c[3];
out.c[5] = in.c[2];
out.c[6] = in.c[1];
out.c[7] = in.c[0];
return(out.d);
}
float
SWAP_FLOAT(
float f)
{
union {
char c[7];
float f;
} in, out;
in.f = f;
out.c[0] = in.c[3];
out.c[1] = in.c[2];
out.c[2] = in.c[1];
out.c[3] = in.c[0];
return(out.f);
}
/*
* get_host_byte_sex() returns the enum constant for the byte sex of the host
* it is running on.
*/
enum byte_sex
get_host_byte_sex(
void)
{
unsigned long s;
s = (BIG_ENDIAN_BYTE_SEX << 24) | LITTLE_ENDIAN_BYTE_SEX;
return((enum byte_sex)*((char *)&s));
}
void
swap_fat_header(
struct fat_header *fat_header,
enum byte_sex target_byte_sex)
{
fat_header->magic = SWAP_LONG(fat_header->magic);
fat_header->nfat_arch = SWAP_LONG(fat_header->nfat_arch);
}
void
swap_fat_arch(
struct fat_arch *fat_archs,
unsigned long nfat_arch,
enum byte_sex target_byte_sex)
{
unsigned long i;
for(i = 0; i < nfat_arch; i++){
fat_archs[i].cputype = SWAP_LONG(fat_archs[i].cputype);
fat_archs[i].cpusubtype = SWAP_LONG(fat_archs[i].cpusubtype);
fat_archs[i].offset = SWAP_LONG(fat_archs[i].offset);
fat_archs[i].size = SWAP_LONG(fat_archs[i].size);
fat_archs[i].align = SWAP_LONG(fat_archs[i].align);
}
}
void
swap_mach_header(
struct mach_header *mh,
enum byte_sex target_byte_sex)
{
mh->magic = SWAP_LONG(mh->magic);
mh->cputype = SWAP_LONG(mh->cputype);
mh->cpusubtype = SWAP_LONG(mh->cpusubtype);
mh->filetype = SWAP_LONG(mh->filetype);
mh->ncmds = SWAP_LONG(mh->ncmds);
mh->sizeofcmds = SWAP_LONG(mh->sizeofcmds);
mh->flags = SWAP_LONG(mh->flags);
}
void
swap_load_command(
struct load_command *lc,
enum byte_sex target_byte_sex)
{
lc->cmd = SWAP_LONG(lc->cmd);
lc->cmdsize = SWAP_LONG(lc->cmdsize);
}
void
swap_segment_command(
struct segment_command *sg,
enum byte_sex target_byte_sex)
{
/* segname[16] */
sg->cmd = SWAP_LONG(sg->cmd);
sg->cmdsize = SWAP_LONG(sg->cmdsize);
sg->vmaddr = SWAP_LONG(sg->vmaddr);
sg->vmsize = SWAP_LONG(sg->vmsize);
sg->fileoff = SWAP_LONG(sg->fileoff);
sg->filesize = SWAP_LONG(sg->filesize);
sg->maxprot = SWAP_LONG(sg->maxprot);
sg->initprot = SWAP_LONG(sg->initprot);
sg->nsects = SWAP_LONG(sg->nsects);
sg->flags = SWAP_LONG(sg->flags);
}
void
swap_section(
struct section *s,
unsigned long nsects,
enum byte_sex target_byte_sex)
{
unsigned long i;
for(i = 0; i < nsects; i++){
/* sectname[16] */
/* segname[16] */
s[i].addr = SWAP_LONG(s[i].addr);
s[i].size = SWAP_LONG(s[i].size);
s[i].offset = SWAP_LONG(s[i].offset);
s[i].align = SWAP_LONG(s[i].align);
s[i].reloff = SWAP_LONG(s[i].reloff);
s[i].nreloc = SWAP_LONG(s[i].nreloc);
s[i].flags = SWAP_LONG(s[i].flags);
s[i].reserved1 = SWAP_LONG(s[i].reserved1);
s[i].reserved2 = SWAP_LONG(s[i].reserved2);
}
}
void
swap_symtab_command(
struct symtab_command *st,
enum byte_sex target_byte_sex)
{
st->cmd = SWAP_LONG(st->cmd);
st->cmdsize = SWAP_LONG(st->cmdsize);
st->symoff = SWAP_LONG(st->symoff);
st->nsyms = SWAP_LONG(st->nsyms);
st->stroff = SWAP_LONG(st->stroff);
st->strsize = SWAP_LONG(st->strsize);
}
void
swap_symseg_command(
struct symseg_command *ss,
enum byte_sex target_byte_sex)
{
ss->cmd = SWAP_LONG(ss->cmd);
ss->cmdsize = SWAP_LONG(ss->cmdsize);
ss->offset = SWAP_LONG(ss->offset);
ss->size = SWAP_LONG(ss->size);
}
void
swap_fvmlib_command(
struct fvmlib_command *fl,
enum byte_sex target_byte_sex)
{
fl->cmd = SWAP_LONG(fl->cmd);
fl->cmdsize = SWAP_LONG(fl->cmdsize);
fl->fvmlib.name.offset = SWAP_LONG(fl->fvmlib.name.offset);
fl->fvmlib.minor_version = SWAP_LONG(fl->fvmlib.minor_version);
fl->fvmlib.header_addr = SWAP_LONG(fl->fvmlib.header_addr);
}
void
swap_fvmfile_command(
struct fvmfile_command *ff,
enum byte_sex target_byte_sex)
{
ff->cmd = SWAP_LONG(ff->cmd);
ff->cmdsize = SWAP_LONG(ff->cmdsize);
ff->name.offset = SWAP_LONG(ff->name.offset);
ff->header_addr = SWAP_LONG(ff->header_addr);
}
void
swap_thread_command(
struct thread_command *ut,
enum byte_sex target_byte_sex)
{
ut->cmd = SWAP_LONG(ut->cmd);
ut->cmdsize = SWAP_LONG(ut->cmdsize);
}
void
swap_m68k_thread_state_regs(
struct m68k_thread_state_regs *cpu,
enum byte_sex target_byte_sex)
{
unsigned long i;
for(i = 0; i < 8; i++)
cpu->dreg[i] = SWAP_LONG(cpu->dreg[i]);
for(i = 0; i < 8; i++)
cpu->areg[i] = SWAP_LONG(cpu->areg[i]);
cpu->pad0 = SWAP_SHORT(cpu->pad0);
cpu->sr = SWAP_SHORT(cpu->sr);
cpu->pc = SWAP_LONG(cpu->pc);
}
void
swap_m68k_thread_state_68882(
struct m68k_thread_state_68882 *fpu,
enum byte_sex target_byte_sex)
{
unsigned long i, tmp;
for(i = 0; i < 8; i++){
tmp = SWAP_LONG(fpu->regs[i].fp[0]);
fpu->regs[i].fp[1] = SWAP_LONG(fpu->regs[i].fp[1]);
fpu->regs[i].fp[0] = SWAP_LONG(fpu->regs[i].fp[2]);
fpu->regs[i].fp[2] = tmp;
}
fpu->cr = SWAP_LONG(fpu->cr);
fpu->sr = SWAP_LONG(fpu->sr);
fpu->iar = SWAP_LONG(fpu->iar);
fpu->state = SWAP_LONG(fpu->state);
}
void
swap_m68k_thread_state_user_reg(
struct m68k_thread_state_user_reg *user_reg,
enum byte_sex target_byte_sex)
{
user_reg->user_reg = SWAP_LONG(user_reg->user_reg);
}
void
swap_m98k_thread_state_grf_t(
m98k_thread_state_grf_t *cpu,
enum byte_sex target_byte_sex)
{
enum byte_sex host_byte_sex;
struct swapped_m98k_cr {
union {
struct {
unsigned rsvd:BITS_WIDTH(23,0);
unsigned ox:BIT_WIDTH(24);
unsigned vx:BIT_WIDTH(25);
unsigned fex:BIT_WIDTH(26);
unsigned fx:BIT_WIDTH(27);
unsigned so:BIT_WIDTH(28);
unsigned eq:BIT_WIDTH(29);
unsigned gt:BIT_WIDTH(30);
unsigned lt:BIT_WIDTH(31);
} fields;
unsigned long word;
} u;
} scr;
struct swapped_m98k_xer {
union {
struct {
unsigned byte_count:BITS_WIDTH(6,0);
unsigned rsvd2:BIT_WIDTH(7);
unsigned byte:BITS_WIDTH(15,8);
unsigned rsvd1:BITS_WIDTH(28,16);
unsigned ca:BIT_WIDTH(29);
unsigned ov:BIT_WIDTH(30);
unsigned so:BIT_WIDTH(31);
} fields;
unsigned long word;
} u;
} sxer;
struct swapped_m98k_msr {
union {
struct {
unsigned psfr:BIT_WIDTH(0);
unsigned rsvd2:BITS_WIDTH(3,1);
unsigned dr:BIT_WIDTH(4);
unsigned ir:BIT_WIDTH(5);
unsigned ip:BIT_WIDTH(6);
unsigned rsvd1:BIT_WIDTH(7);
unsigned fe1:BIT_WIDTH(8);
unsigned be:BIT_WIDTH(9);
unsigned se:BIT_WIDTH(10);
unsigned fe0:BIT_WIDTH(11);
unsigned me:BIT_WIDTH(12);
unsigned fp:BIT_WIDTH(13);
unsigned pr:BIT_WIDTH(14);
unsigned ee:BIT_WIDTH(15);
unsigned rsvd3:BITS_WIDTH(31,16);
} fields;
unsigned long word;
} u;
} smsr;
host_byte_sex = get_host_byte_sex();
cpu->r0 = SWAP_LONG(cpu->r0);
cpu->r1 = SWAP_LONG(cpu->r1);
cpu->r2 = SWAP_LONG(cpu->r2);
cpu->r3 = SWAP_LONG(cpu->r3);
cpu->r4 = SWAP_LONG(cpu->r4);
cpu->r5 = SWAP_LONG(cpu->r5);
cpu->r6 = SWAP_LONG(cpu->r6);
cpu->r7 = SWAP_LONG(cpu->r7);
cpu->r8 = SWAP_LONG(cpu->r8);
cpu->r9 = SWAP_LONG(cpu->r9);
cpu->r10 = SWAP_LONG(cpu->r10);
cpu->r11 = SWAP_LONG(cpu->r11);
cpu->r12 = SWAP_LONG(cpu->r12);
cpu->r13 = SWAP_LONG(cpu->r13);
cpu->r14 = SWAP_LONG(cpu->r14);
cpu->r15 = SWAP_LONG(cpu->r15);
cpu->r16 = SWAP_LONG(cpu->r16);
cpu->r17 = SWAP_LONG(cpu->r17);
cpu->r18 = SWAP_LONG(cpu->r18);
cpu->r19 = SWAP_LONG(cpu->r19);
cpu->r20 = SWAP_LONG(cpu->r20);
cpu->r21 = SWAP_LONG(cpu->r21);
cpu->r22 = SWAP_LONG(cpu->r22);
cpu->r23 = SWAP_LONG(cpu->r23);
cpu->r24 = SWAP_LONG(cpu->r24);
cpu->r25 = SWAP_LONG(cpu->r25);
cpu->r26 = SWAP_LONG(cpu->r26);
cpu->r27 = SWAP_LONG(cpu->r27);
cpu->r28 = SWAP_LONG(cpu->r28);
cpu->r29 = SWAP_LONG(cpu->r29);
cpu->r30 = SWAP_LONG(cpu->r30);
cpu->r31 = SWAP_LONG(cpu->r31);
cpu->lr = SWAP_LONG(cpu->lr);
cpu->ctr = SWAP_LONG(cpu->ctr);
cpu->cia = SWAP_LONG(cpu->cia);
if(target_byte_sex == host_byte_sex){
memcpy(&scr, &(cpu->cr), sizeof(struct swapped_m98k_cr));
scr.u.word = SWAP_LONG(scr.u.word);
cpu->cr.lt = scr.u.fields.lt;
cpu->cr.gt = scr.u.fields.gt;
cpu->cr.eq = scr.u.fields.eq;
cpu->cr.so = scr.u.fields.so;
cpu->cr.fx = scr.u.fields.fx;
cpu->cr.fex = scr.u.fields.fex;
cpu->cr.vx = scr.u.fields.vx;
cpu->cr.ox = scr.u.fields.ox;
cpu->cr.rsvd = scr.u.fields.rsvd;
memcpy(&sxer, &(cpu->xer), sizeof(struct swapped_m98k_xer));
sxer.u.word = SWAP_LONG(sxer.u.word);
cpu->xer.byte_count = sxer.u.fields.byte_count;
cpu->xer.rsvd2 = sxer.u.fields.rsvd2;
cpu->xer.byte = sxer.u.fields.byte;
cpu->xer.rsvd1 = sxer.u.fields.rsvd1;
cpu->xer.ca = sxer.u.fields.ca;
cpu->xer.ov = sxer.u.fields.ov;
cpu->xer.so = sxer.u.fields.so;
memcpy(&smsr, &(cpu->msr), sizeof(struct swapped_m98k_msr));
smsr.u.word = SWAP_LONG(smsr.u.word);
cpu->msr.psfr = smsr.u.fields.psfr;
cpu->msr.rsvd2 = smsr.u.fields.rsvd2;
cpu->msr.dr = smsr.u.fields.dr;
cpu->msr.ir = smsr.u.fields.ir;
cpu->msr.ip = smsr.u.fields.ip;
cpu->msr.rsvd1 = smsr.u.fields.rsvd1;
cpu->msr.fe1 = smsr.u.fields.fe1;
cpu->msr.be = smsr.u.fields.be;
cpu->msr.se = smsr.u.fields.se;
cpu->msr.fe0 = smsr.u.fields.fe0;
cpu->msr.me = smsr.u.fields.me;
cpu->msr.fp = smsr.u.fields.fp;
cpu->msr.pr = smsr.u.fields.pr;
cpu->msr.ee = smsr.u.fields.ee;
cpu->msr.rsvd3 = smsr.u.fields.rsvd3;
}
else{
scr.u.fields.lt = cpu->cr.lt;
scr.u.fields.gt = cpu->cr.gt;
scr.u.fields.eq = cpu->cr.eq;
scr.u.fields.so = cpu->cr.so;
scr.u.fields.fx = cpu->cr.fx;
scr.u.fields.fex = cpu->cr.fex;
scr.u.fields.vx = cpu->cr.vx;
scr.u.fields.ox = cpu->cr.ox;
scr.u.fields.rsvd = cpu->cr.rsvd;
scr.u.word = SWAP_LONG(scr.u.word);
memcpy(&(cpu->cr), &scr, sizeof(struct swapped_m98k_cr));
sxer.u.fields.byte_count = cpu->xer.byte_count;
sxer.u.fields.rsvd2 = cpu->xer.rsvd2;
sxer.u.fields.byte = cpu->xer.byte;
sxer.u.fields.rsvd1 = cpu->xer.rsvd1;
sxer.u.fields.ca = cpu->xer.ca;
sxer.u.fields.ov = cpu->xer.ov;
sxer.u.fields.so = cpu->xer.so;
sxer.u.word = SWAP_LONG(sxer.u.word);
memcpy(&(cpu->xer), &sxer, sizeof(struct swapped_m98k_xer));
smsr.u.fields.psfr = cpu->msr.psfr;
smsr.u.fields.rsvd2 = cpu->msr.rsvd2;
smsr.u.fields.dr = cpu->msr.dr;
smsr.u.fields.ir = cpu->msr.ir;
smsr.u.fields.ip = cpu->msr.ip;
smsr.u.fields.rsvd1 = cpu->msr.rsvd1;
smsr.u.fields.fe1 = cpu->msr.fe1;
smsr.u.fields.be = cpu->msr.be;
smsr.u.fields.se = cpu->msr.se;
smsr.u.fields.fe0 = cpu->msr.fe0;
smsr.u.fields.me = cpu->msr.me;
smsr.u.fields.fp = cpu->msr.fp;
smsr.u.fields.pr = cpu->msr.pr;
smsr.u.fields.ee = cpu->msr.ee;
smsr.u.fields.rsvd3 = cpu->msr.rsvd3;
smsr.u.word = SWAP_LONG(smsr.u.word);
memcpy(&(cpu->msr), &smsr, sizeof(struct swapped_m98k_msr));
}
}
void
swap_m88k_thread_state_grf_t(
m88k_thread_state_grf_t *cpu,
enum byte_sex target_byte_sex)
{
cpu->r1 = SWAP_LONG(cpu->r1);
cpu->r2 = SWAP_LONG(cpu->r2);
cpu->r3 = SWAP_LONG(cpu->r3);
cpu->r4 = SWAP_LONG(cpu->r4);
cpu->r5 = SWAP_LONG(cpu->r5);
cpu->r6 = SWAP_LONG(cpu->r6);
cpu->r7 = SWAP_LONG(cpu->r7);
cpu->r8 = SWAP_LONG(cpu->r8);
cpu->r9 = SWAP_LONG(cpu->r9);
cpu->r10 = SWAP_LONG(cpu->r10);
cpu->r11 = SWAP_LONG(cpu->r11);
cpu->r12 = SWAP_LONG(cpu->r12);
cpu->r13 = SWAP_LONG(cpu->r13);
cpu->r14 = SWAP_LONG(cpu->r14);
cpu->r15 = SWAP_LONG(cpu->r15);
cpu->r16 = SWAP_LONG(cpu->r16);
cpu->r17 = SWAP_LONG(cpu->r17);
cpu->r18 = SWAP_LONG(cpu->r18);
cpu->r19 = SWAP_LONG(cpu->r19);
cpu->r20 = SWAP_LONG(cpu->r20);
cpu->r21 = SWAP_LONG(cpu->r21);
cpu->r22 = SWAP_LONG(cpu->r22);
cpu->r23 = SWAP_LONG(cpu->r23);
cpu->r24 = SWAP_LONG(cpu->r24);
cpu->r25 = SWAP_LONG(cpu->r25);
cpu->r26 = SWAP_LONG(cpu->r26);
cpu->r27 = SWAP_LONG(cpu->r27);
cpu->r28 = SWAP_LONG(cpu->r28);
cpu->r29 = SWAP_LONG(cpu->r29);
cpu->r30 = SWAP_LONG(cpu->r30);
cpu->r31 = SWAP_LONG(cpu->r31);
cpu->xip = SWAP_LONG(cpu->xip);
cpu->xip_in_bd = SWAP_LONG(cpu->xip_in_bd);
cpu->nip = SWAP_LONG(cpu->nip);
}
void
swap_m88k_thread_state_xrf_t(
m88k_thread_state_xrf_t *fpu,
enum byte_sex target_byte_sex)
{
enum byte_sex host_byte_sex;
struct swapped_m88k_fpsr {
union {
struct {
unsigned afinx:BIT_WIDTH(0);
unsigned afovf:BIT_WIDTH(1);
unsigned afunf:BIT_WIDTH(2);
unsigned afdvz:BIT_WIDTH(3);
unsigned afinv:BIT_WIDTH(4);
unsigned :BITS_WIDTH(15,5);
unsigned xmod:BIT_WIDTH(16);
unsigned :BITS_WIDTH(31,17);
} fields;
unsigned long word;
} u;
} ssr;
struct swapped_m88k_fpcr {
union {
struct {
unsigned efinx:BIT_WIDTH(0);
unsigned efovf:BIT_WIDTH(1);
unsigned efunf:BIT_WIDTH(2);
unsigned efdvz:BIT_WIDTH(3);
unsigned efinv:BIT_WIDTH(4);
unsigned :BITS_WIDTH(13,5);
m88k_fpcr_rm_t rm:BITS_WIDTH(15,14);
unsigned :BITS_WIDTH(31,16);
} fields;
unsigned long word;
} u;
} scr;
host_byte_sex = get_host_byte_sex();
fpu->x1.x[0] = SWAP_LONG(fpu->x1.x[0]);
fpu->x1.x[1] = SWAP_LONG(fpu->x1.x[1]);
fpu->x1.x[2] = SWAP_LONG(fpu->x1.x[2]);
fpu->x1.x[3] = SWAP_LONG(fpu->x1.x[3]);
fpu->x2.x[0] = SWAP_LONG(fpu->x2.x[0]);
fpu->x2.x[1] = SWAP_LONG(fpu->x2.x[1]);
fpu->x2.x[2] = SWAP_LONG(fpu->x2.x[2]);
fpu->x2.x[3] = SWAP_LONG(fpu->x2.x[3]);
fpu->x3.x[0] = SWAP_LONG(fpu->x3.x[0]);
fpu->x3.x[1] = SWAP_LONG(fpu->x3.x[1]);
fpu->x3.x[2] = SWAP_LONG(fpu->x3.x[2]);
fpu->x3.x[3] = SWAP_LONG(fpu->x3.x[3]);
fpu->x4.x[0] = SWAP_LONG(fpu->x4.x[0]);
fpu->x4.x[1] = SWAP_LONG(fpu->x4.x[1]);
fpu->x4.x[2] = SWAP_LONG(fpu->x4.x[2]);
fpu->x4.x[3] = SWAP_LONG(fpu->x4.x[3]);
fpu->x5.x[0] = SWAP_LONG(fpu->x5.x[0]);
fpu->x5.x[1] = SWAP_LONG(fpu->x5.x[1]);
fpu->x5.x[2] = SWAP_LONG(fpu->x5.x[2]);
fpu->x5.x[3] = SWAP_LONG(fpu->x5.x[3]);
fpu->x6.x[0] = SWAP_LONG(fpu->x6.x[0]);
fpu->x6.x[1] = SWAP_LONG(fpu->x6.x[1]);
fpu->x6.x[2] = SWAP_LONG(fpu->x6.x[2]);
fpu->x6.x[3] = SWAP_LONG(fpu->x6.x[3]);
fpu->x7.x[0] = SWAP_LONG(fpu->x7.x[0]);
fpu->x7.x[1] = SWAP_LONG(fpu->x7.x[1]);
fpu->x7.x[2] = SWAP_LONG(fpu->x7.x[2]);
fpu->x7.x[3] = SWAP_LONG(fpu->x7.x[3]);
fpu->x8.x[0] = SWAP_LONG(fpu->x8.x[0]);
fpu->x8.x[1] = SWAP_LONG(fpu->x8.x[1]);
fpu->x8.x[2] = SWAP_LONG(fpu->x8.x[2]);
fpu->x8.x[3] = SWAP_LONG(fpu->x8.x[3]);
fpu->x9.x[0] = SWAP_LONG(fpu->x9.x[0]);
fpu->x9.x[1] = SWAP_LONG(fpu->x9.x[1]);
fpu->x9.x[2] = SWAP_LONG(fpu->x9.x[2]);
fpu->x9.x[3] = SWAP_LONG(fpu->x9.x[3]);
fpu->x10.x[0] = SWAP_LONG(fpu->x10.x[0]);
fpu->x10.x[1] = SWAP_LONG(fpu->x10.x[1]);
fpu->x10.x[2] = SWAP_LONG(fpu->x10.x[2]);
fpu->x10.x[3] = SWAP_LONG(fpu->x10.x[3]);
fpu->x11.x[0] = SWAP_LONG(fpu->x11.x[0]);
fpu->x11.x[1] = SWAP_LONG(fpu->x11.x[1]);
fpu->x11.x[2] = SWAP_LONG(fpu->x11.x[2]);
fpu->x11.x[3] = SWAP_LONG(fpu->x11.x[3]);
fpu->x12.x[0] = SWAP_LONG(fpu->x12.x[0]);
fpu->x12.x[1] = SWAP_LONG(fpu->x12.x[1]);
fpu->x12.x[2] = SWAP_LONG(fpu->x12.x[2]);
fpu->x12.x[3] = SWAP_LONG(fpu->x12.x[3]);
fpu->x13.x[0] = SWAP_LONG(fpu->x13.x[0]);
fpu->x13.x[1] = SWAP_LONG(fpu->x13.x[1]);
fpu->x13.x[2] = SWAP_LONG(fpu->x13.x[2]);
fpu->x13.x[3] = SWAP_LONG(fpu->x13.x[3]);
fpu->x14.x[0] = SWAP_LONG(fpu->x14.x[0]);
fpu->x14.x[1] = SWAP_LONG(fpu->x14.x[1]);
fpu->x14.x[2] = SWAP_LONG(fpu->x14.x[2]);
fpu->x14.x[3] = SWAP_LONG(fpu->x14.x[3]);
fpu->x15.x[0] = SWAP_LONG(fpu->x15.x[0]);
fpu->x15.x[1] = SWAP_LONG(fpu->x15.x[1]);
fpu->x15.x[2] = SWAP_LONG(fpu->x15.x[2]);
fpu->x15.x[3] = SWAP_LONG(fpu->x15.x[3]);
fpu->x16.x[0] = SWAP_LONG(fpu->x16.x[0]);
fpu->x16.x[1] = SWAP_LONG(fpu->x16.x[1]);
fpu->x16.x[2] = SWAP_LONG(fpu->x16.x[2]);
fpu->x16.x[3] = SWAP_LONG(fpu->x16.x[3]);
fpu->x17.x[0] = SWAP_LONG(fpu->x17.x[0]);
fpu->x17.x[1] = SWAP_LONG(fpu->x17.x[1]);
fpu->x17.x[2] = SWAP_LONG(fpu->x17.x[2]);
fpu->x17.x[3] = SWAP_LONG(fpu->x17.x[3]);
fpu->x18.x[0] = SWAP_LONG(fpu->x18.x[0]);
fpu->x18.x[1] = SWAP_LONG(fpu->x18.x[1]);
fpu->x18.x[2] = SWAP_LONG(fpu->x18.x[2]);
fpu->x18.x[3] = SWAP_LONG(fpu->x18.x[3]);
fpu->x19.x[0] = SWAP_LONG(fpu->x19.x[0]);
fpu->x19.x[1] = SWAP_LONG(fpu->x19.x[1]);
fpu->x19.x[2] = SWAP_LONG(fpu->x19.x[2]);
fpu->x19.x[3] = SWAP_LONG(fpu->x19.x[3]);
fpu->x20.x[0] = SWAP_LONG(fpu->x20.x[0]);
fpu->x20.x[1] = SWAP_LONG(fpu->x20.x[1]);
fpu->x20.x[2] = SWAP_LONG(fpu->x20.x[2]);
fpu->x20.x[3] = SWAP_LONG(fpu->x20.x[3]);
fpu->x21.x[0] = SWAP_LONG(fpu->x21.x[0]);
fpu->x21.x[1] = SWAP_LONG(fpu->x21.x[1]);
fpu->x21.x[2] = SWAP_LONG(fpu->x21.x[2]);
fpu->x21.x[3] = SWAP_LONG(fpu->x21.x[3]);
fpu->x22.x[0] = SWAP_LONG(fpu->x22.x[0]);
fpu->x22.x[1] = SWAP_LONG(fpu->x22.x[1]);
fpu->x22.x[2] = SWAP_LONG(fpu->x22.x[2]);
fpu->x22.x[3] = SWAP_LONG(fpu->x22.x[3]);
fpu->x23.x[0] = SWAP_LONG(fpu->x23.x[0]);
fpu->x23.x[1] = SWAP_LONG(fpu->x23.x[1]);
fpu->x23.x[2] = SWAP_LONG(fpu->x23.x[2]);
fpu->x23.x[3] = SWAP_LONG(fpu->x23.x[3]);
fpu->x24.x[0] = SWAP_LONG(fpu->x24.x[0]);
fpu->x24.x[1] = SWAP_LONG(fpu->x24.x[1]);
fpu->x24.x[2] = SWAP_LONG(fpu->x24.x[2]);
fpu->x24.x[3] = SWAP_LONG(fpu->x24.x[3]);
fpu->x25.x[0] = SWAP_LONG(fpu->x25.x[0]);
fpu->x25.x[1] = SWAP_LONG(fpu->x25.x[1]);
fpu->x25.x[2] = SWAP_LONG(fpu->x25.x[2]);
fpu->x25.x[3] = SWAP_LONG(fpu->x25.x[3]);
fpu->x26.x[0] = SWAP_LONG(fpu->x26.x[0]);
fpu->x26.x[1] = SWAP_LONG(fpu->x26.x[1]);
fpu->x26.x[2] = SWAP_LONG(fpu->x26.x[2]);
fpu->x26.x[3] = SWAP_LONG(fpu->x26.x[3]);
fpu->x27.x[0] = SWAP_LONG(fpu->x27.x[0]);
fpu->x27.x[1] = SWAP_LONG(fpu->x27.x[1]);
fpu->x27.x[2] = SWAP_LONG(fpu->x27.x[2]);
fpu->x27.x[3] = SWAP_LONG(fpu->x27.x[3]);
fpu->x28.x[0] = SWAP_LONG(fpu->x28.x[0]);
fpu->x28.x[1] = SWAP_LONG(fpu->x28.x[1]);
fpu->x28.x[2] = SWAP_LONG(fpu->x28.x[2]);
fpu->x28.x[3] = SWAP_LONG(fpu->x28.x[3]);
fpu->x29.x[0] = SWAP_LONG(fpu->x29.x[0]);
fpu->x29.x[1] = SWAP_LONG(fpu->x29.x[1]);
fpu->x29.x[2] = SWAP_LONG(fpu->x29.x[2]);
fpu->x29.x[3] = SWAP_LONG(fpu->x29.x[3]);
fpu->x30.x[0] = SWAP_LONG(fpu->x30.x[0]);
fpu->x30.x[1] = SWAP_LONG(fpu->x30.x[1]);
fpu->x30.x[2] = SWAP_LONG(fpu->x30.x[2]);
fpu->x30.x[3] = SWAP_LONG(fpu->x30.x[3]);
fpu->x31.x[0] = SWAP_LONG(fpu->x31.x[0]);
fpu->x31.x[1] = SWAP_LONG(fpu->x31.x[1]);
fpu->x31.x[2] = SWAP_LONG(fpu->x31.x[2]);
fpu->x31.x[3] = SWAP_LONG(fpu->x31.x[3]);
if(target_byte_sex == host_byte_sex){
memcpy(&ssr, &(fpu->fpsr), sizeof(struct swapped_m88k_fpsr));
ssr.u.word = SWAP_LONG(ssr.u.word);
fpu->fpsr.afinx = ssr.u.fields.afinx;
fpu->fpsr.afovf = ssr.u.fields.afovf;
fpu->fpsr.afunf = ssr.u.fields.afunf;
fpu->fpsr.afdvz = ssr.u.fields.afdvz;
fpu->fpsr.afinv = ssr.u.fields.afinv;
fpu->fpsr.xmod = ssr.u.fields.xmod;
memcpy(&scr, &(fpu->fpcr), sizeof(struct swapped_m88k_fpcr));
scr.u.word = SWAP_LONG(scr.u.word);
fpu->fpcr.efinx = scr.u.fields.efinx;
fpu->fpcr.efovf = scr.u.fields.efovf;
fpu->fpcr.efunf = scr.u.fields.efunf;
fpu->fpcr.efdvz = scr.u.fields.efdvz;
fpu->fpcr.efinv = scr.u.fields.efinv;
fpu->fpcr.rm = scr.u.fields.rm;
}
else{
ssr.u.fields.afinx = fpu->fpsr.afinx;
ssr.u.fields.afovf = fpu->fpsr.afovf;
ssr.u.fields.afunf = fpu->fpsr.afunf;
ssr.u.fields.afdvz = fpu->fpsr.afdvz;
ssr.u.fields.afinv = fpu->fpsr.afinv;
ssr.u.fields.xmod = fpu->fpsr.xmod;
ssr.u.word = SWAP_LONG(ssr.u.word);
memcpy(&(fpu->fpsr), &ssr, sizeof(struct swapped_m88k_fpsr));
scr.u.fields.efinx = fpu->fpcr.efinx;
scr.u.fields.efovf = fpu->fpcr.efovf;
scr.u.fields.efunf = fpu->fpcr.efunf;
scr.u.fields.efdvz = fpu->fpcr.efdvz;
scr.u.fields.efinv = fpu->fpcr.efinv;
scr.u.fields.rm = fpu->fpcr.rm;
scr.u.word = SWAP_LONG(scr.u.word);
memcpy(&(fpu->fpcr), &scr, sizeof(struct swapped_m88k_fpcr));
}
}
void
swap_m88k_thread_state_user_t(
m88k_thread_state_user_t *user,
enum byte_sex target_byte_sex)
{
user->user = SWAP_LONG(user->user);
}
void
swap_m88110_thread_state_impl_t(
m88110_thread_state_impl_t *spu,
enum byte_sex target_byte_sex)
{
unsigned long i;
enum byte_sex host_byte_sex;
struct swapped_m88110_bp_ctrl {
union {
struct {
unsigned v:BIT_WIDTH(0);
m88110_match_t addr_match:BITS_WIDTH(12,1);
unsigned :BITS_WIDTH(26,13);
unsigned rwm:BIT_WIDTH(27);
unsigned rw:BIT_WIDTH(28);
unsigned :BITS_WIDTH(31,29);
} fields;
unsigned long word;
} u;
} sbpc;
struct swap_m88110_psr {
union {
struct {
unsigned :BITS_WIDTH(1,0);
unsigned mxm_dis:BIT_WIDTH(2);
unsigned sfu1dis:BIT_WIDTH(3);
unsigned :BITS_WIDTH(22,4);
unsigned trace:BIT_WIDTH(23);
unsigned :BIT_WIDTH(24);
unsigned sm:BIT_WIDTH(25);
unsigned sgn_imd:BIT_WIDTH(26);
unsigned :BIT_WIDTH(27);
unsigned c:BIT_WIDTH(28);
unsigned se:BIT_WIDTH(29);
unsigned le:BIT_WIDTH(30);
unsigned supr:BIT_WIDTH(31);
} fields;
unsigned long word;
} u;
} spsr;
struct swapped_m88110_fp_trap_status {
union {
struct {
unsigned efinx:BIT_WIDTH(0);
unsigned efovf:BIT_WIDTH(1);
unsigned efunf:BIT_WIDTH(2);
unsigned efdvz:BIT_WIDTH(3);
unsigned efinv:BIT_WIDTH(4);
unsigned priv:BIT_WIDTH(5);
unsigned unimp:BIT_WIDTH(6);
unsigned int:BIT_WIDTH(7);
unsigned sfu1_disabled:BIT_WIDTH(8);
unsigned :BITS_WIDTH(13,9);
m88110_iresult_size_t iresult_size:BITS_WIDTH(15,14);
unsigned :BITS_WIDTH(31,16);
} fields;
unsigned long word;
} u;
} sfps;
host_byte_sex = get_host_byte_sex();
if(target_byte_sex == host_byte_sex){
for(i = 0; i < M88110_N_DATA_BP; i++){
spu->data_bp[i].addr = SWAP_LONG(spu->data_bp[i].addr);
memcpy(&sbpc, &(spu->data_bp[i].ctrl),
sizeof(struct swapped_m88110_bp_ctrl));
sbpc.u.word = SWAP_LONG(sbpc.u.word);
spu->data_bp[i].ctrl.v = sbpc.u.fields.v;
spu->data_bp[i].ctrl.addr_match = sbpc.u.fields.addr_match;
spu->data_bp[i].ctrl.rwm = sbpc.u.fields.rwm;
spu->data_bp[i].ctrl.rw = sbpc.u.fields.rw;
}
memcpy(&spsr, &(spu->psr), sizeof(struct swap_m88110_psr));
spsr.u.word = SWAP_LONG(spsr.u.word);
spu->psr.mxm_dis = spsr.u.fields.mxm_dis;
spu->psr.sfu1dis = spsr.u.fields.sfu1dis;
spu->psr.trace = spsr.u.fields.trace;
spu->psr.sm = spsr.u.fields.sm;
spu->psr.sgn_imd = spsr.u.fields.sgn_imd;
spu->psr.c = spsr.u.fields.c;
spu->psr.se = spsr.u.fields.se;
spu->psr.le = spsr.u.fields.le;
spu->psr.supr = spsr.u.fields.supr;
memcpy(&sfps, &(spu->fp_trap_status),
sizeof(struct swapped_m88110_fp_trap_status));
sfps.u.word = SWAP_LONG(sfps.u.word);
spu->fp_trap_status.efinx = sfps.u.fields.efinx;
spu->fp_trap_status.efovf = sfps.u.fields.efovf;
spu->fp_trap_status.efunf = sfps.u.fields.efunf;
spu->fp_trap_status.efdvz = sfps.u.fields.efdvz;
spu->fp_trap_status.efinv = sfps.u.fields.efinv;
spu->fp_trap_status.priv = sfps.u.fields.priv;
spu->fp_trap_status.unimp = sfps.u.fields.unimp;
spu->fp_trap_status.sfu1_disabled = sfps.u.fields.sfu1_disabled;
spu->fp_trap_status.iresult_size = sfps.u.fields.iresult_size;
}
else{
for(i = 0; i < M88110_N_DATA_BP; i++){
spu->data_bp[i].addr = SWAP_LONG(spu->data_bp[i].addr);
sbpc.u.fields.v = spu->data_bp[i].ctrl.v;
sbpc.u.fields.addr_match = spu->data_bp[i].ctrl.addr_match;
sbpc.u.fields.rwm = spu->data_bp[i].ctrl.rwm;
sbpc.u.fields.rw = spu->data_bp[i].ctrl.rw;
sbpc.u.word = SWAP_LONG(sbpc.u.word);
memcpy(&(spu->data_bp[i].ctrl), &sbpc,
sizeof(struct swapped_m88110_bp_ctrl));
}
spsr.u.fields.mxm_dis = spu->psr.mxm_dis;
spsr.u.fields.sfu1dis = spu->psr.sfu1dis;
spsr.u.fields.trace = spu->psr.trace;
spsr.u.fields.sm = spu->psr.sm;
spsr.u.fields.sgn_imd = spu->psr.sgn_imd;
spsr.u.fields.c = spu->psr.c;
spsr.u.fields.se = spu->psr.se;
spsr.u.fields.le = spu->psr.le;
spsr.u.fields.supr = spu->psr.supr;
spsr.u.word = SWAP_LONG(spsr.u.word);
memcpy(&(spu->psr), &spsr, sizeof(struct swap_m88110_psr));
sfps.u.fields.efinx = spu->fp_trap_status.efinx;
sfps.u.fields.efovf = spu->fp_trap_status.efovf;
sfps.u.fields.efunf = spu->fp_trap_status.efunf;
sfps.u.fields.efdvz = spu->fp_trap_status.efdvz;
sfps.u.fields.efinv = spu->fp_trap_status.efinv;
sfps.u.fields.priv = spu->fp_trap_status.priv;
sfps.u.fields.unimp = spu->fp_trap_status.unimp;
sfps.u.fields.sfu1_disabled = spu->fp_trap_status.sfu1_disabled;
sfps.u.fields.iresult_size = spu->fp_trap_status.iresult_size;
sfps.u.word = SWAP_LONG(sfps.u.word);
memcpy(&(spu->fp_trap_status), &sfps,
sizeof(struct swapped_m88110_fp_trap_status));
}
spu->intermediate_result.x[0] =
SWAP_LONG(spu->intermediate_result.x[0]);
spu->intermediate_result.x[1] =
SWAP_LONG(spu->intermediate_result.x[1]);
spu->intermediate_result.x[2] =
SWAP_LONG(spu->intermediate_result.x[2]);
spu->intermediate_result.x[3] =
SWAP_LONG(spu->intermediate_result.x[3]);
}
void
swap_i860_thread_state_regs(
struct i860_thread_state_regs *cpu,
enum byte_sex target_byte_sex)
{
unsigned long i;
for(i = 0; i < 31; i++)
cpu->ireg[i] = SWAP_LONG(cpu->ireg[i]);
for(i = 0; i < 30; i++)
cpu->freg[i] = SWAP_LONG(cpu->freg[i]);
cpu->psr = SWAP_LONG(cpu->psr);
cpu->epsr = SWAP_LONG(cpu->epsr);
cpu->db = SWAP_LONG(cpu->db);
cpu->pc = SWAP_LONG(cpu->pc);
cpu->_padding_ = SWAP_LONG(cpu->_padding_);
cpu->Mres3 = SWAP_DOUBLE(cpu->Mres3);
cpu->Ares3 = SWAP_DOUBLE(cpu->Ares3);
cpu->Mres2 = SWAP_DOUBLE(cpu->Mres2);
cpu->Ares2 = SWAP_DOUBLE(cpu->Ares2);
cpu->Mres1 = SWAP_DOUBLE(cpu->Mres1);
cpu->Ares1 = SWAP_DOUBLE(cpu->Ares1);
cpu->Ires1 = SWAP_DOUBLE(cpu->Ires1);
cpu->Lres3m = SWAP_DOUBLE(cpu->Lres3m);
cpu->Lres2m = SWAP_DOUBLE(cpu->Lres2m);
cpu->Lres1m = SWAP_DOUBLE(cpu->Lres1m);
cpu->KR = SWAP_DOUBLE(cpu->KR);
cpu->KI = SWAP_DOUBLE(cpu->KI);
cpu->T = SWAP_DOUBLE(cpu->T);
cpu->Fsr3 = SWAP_LONG(cpu->Fsr3);
cpu->Fsr2 = SWAP_LONG(cpu->Fsr2);
cpu->Fsr1 = SWAP_LONG(cpu->Fsr1);
cpu->Mergelo32 = SWAP_LONG(cpu->Mergelo32);
cpu->Mergehi32 = SWAP_LONG(cpu->Mergehi32);
}
void
swap_i386_thread_state(
i386_thread_state_t *cpu,
enum byte_sex target_byte_sex)
{
cpu->eax = SWAP_LONG(cpu->eax);
cpu->ebx = SWAP_LONG(cpu->ebx);
cpu->ecx = SWAP_LONG(cpu->ecx);
cpu->edx = SWAP_LONG(cpu->edx);
cpu->edi = SWAP_LONG(cpu->edi);
cpu->esi = SWAP_LONG(cpu->esi);
cpu->ebp = SWAP_LONG(cpu->ebp);
cpu->esp = SWAP_LONG(cpu->esp);
cpu->ss = SWAP_LONG(cpu->ss);
cpu->eflags = SWAP_LONG(cpu->eflags);
cpu->eip = SWAP_LONG(cpu->eip);
cpu->cs = SWAP_LONG(cpu->cs);
cpu->ds = SWAP_LONG(cpu->ds);
cpu->es = SWAP_LONG(cpu->es);
cpu->fs = SWAP_LONG(cpu->fs);
cpu->gs = SWAP_LONG(cpu->gs);
}
void
swap_i386_thread_fpstate(
i386_thread_fpstate_t *fpu,
enum byte_sex target_byte_sex)
{
struct swapped_fp_control {
union {
struct {
unsigned short
:3,
/*inf*/ :1,
rc :2,
pc :2,
:2,
precis :1,
undfl :1,
ovrfl :1,
zdiv :1,
denorm :1,
invalid :1;
} fields;
unsigned short half;
} u;
} sfpc;
struct swapped_fp_status {
union {
struct {
unsigned short
busy :1,
c3 :1,
tos :3,
c2 :1,
c1 :1,
c0 :1,
errsumm :1,
stkflt :1,
precis :1,
undfl :1,
ovrfl :1,
zdiv :1,
denorm :1,
invalid :1;
} fields;
unsigned short half;
} u;
} sfps;
struct swapped_fp_tag {
union {
struct {
unsigned short
tag7 :2,
tag6 :2,
tag5 :2,
tag4 :2,
tag3 :2,
tag2 :2,
tag1 :2,
tag0 :2;
} fields;
unsigned short half;
} u;
} sfpt;
struct swapped_fp_data_reg {
unsigned short mant;
unsigned short mant1 :16,
mant2 :16,
mant3 :16;
union {
struct {
unsigned short sign :1,
exp :15;
} fields;
unsigned short half;
} u;
} sfpd;
struct swapped_sel {
union {
struct {
unsigned short
index :13,
ti :1,
rpl :2;
} fields;
unsigned short half;
} u;
} ss;
enum byte_sex host_byte_sex;
unsigned long i;
host_byte_sex = get_host_byte_sex();
fpu->environ.ip = SWAP_LONG(fpu->environ.ip);
fpu->environ.opcode = SWAP_SHORT(fpu->environ.opcode);
fpu->environ.dp = SWAP_LONG(fpu->environ.dp);
if(target_byte_sex == host_byte_sex){
memcpy(&sfpc, &(fpu->environ.control),
sizeof(struct swapped_fp_control));
sfpc.u.half = SWAP_SHORT(sfpc.u.half);
fpu->environ.control.rc = sfpc.u.fields.rc;
fpu->environ.control.pc = sfpc.u.fields.pc;
fpu->environ.control.precis = sfpc.u.fields.precis;
fpu->environ.control.undfl = sfpc.u.fields.undfl;
fpu->environ.control.ovrfl = sfpc.u.fields.ovrfl;
fpu->environ.control.zdiv = sfpc.u.fields.zdiv;
fpu->environ.control.denorm = sfpc.u.fields.denorm;
fpu->environ.control.invalid = sfpc.u.fields.invalid;
memcpy(&sfps, &(fpu->environ.status),
sizeof(struct swapped_fp_status));
sfps.u.half = SWAP_SHORT(sfps.u.half);
fpu->environ.status.busy = sfps.u.fields.busy;
fpu->environ.status.c3 = sfps.u.fields.c3;
fpu->environ.status.tos = sfps.u.fields.tos;
fpu->environ.status.c2 = sfps.u.fields.c2;
fpu->environ.status.c1 = sfps.u.fields.c1;
fpu->environ.status.c0 = sfps.u.fields.c0;
fpu->environ.status.errsumm = sfps.u.fields.errsumm;
fpu->environ.status.stkflt = sfps.u.fields.stkflt;
fpu->environ.status.precis = sfps.u.fields.precis;
fpu->environ.status.undfl = sfps.u.fields.undfl;
fpu->environ.status.ovrfl = sfps.u.fields.ovrfl;
fpu->environ.status.zdiv = sfps.u.fields.zdiv;
fpu->environ.status.denorm = sfps.u.fields.denorm;
fpu->environ.status.invalid = sfps.u.fields.invalid;
memcpy(&sfpt, &(fpu->environ.tag),
sizeof(struct swapped_fp_tag));
sfpt.u.half = SWAP_SHORT(sfpt.u.half);
fpu->environ.tag.tag7 = sfpt.u.fields.tag7;
fpu->environ.tag.tag6 = sfpt.u.fields.tag6;
fpu->environ.tag.tag5 = sfpt.u.fields.tag5;
fpu->environ.tag.tag4 = sfpt.u.fields.tag4;
fpu->environ.tag.tag3 = sfpt.u.fields.tag3;
fpu->environ.tag.tag2 = sfpt.u.fields.tag2;
fpu->environ.tag.tag1 = sfpt.u.fields.tag1;
fpu->environ.tag.tag0 = sfpt.u.fields.tag0;
memcpy(&ss, &(fpu->environ.cs),
sizeof(struct swapped_sel));
ss.u.half = SWAP_SHORT(ss.u.half);
fpu->environ.cs.index = ss.u.fields.index;
fpu->environ.cs.ti = ss.u.fields.ti;
fpu->environ.cs.rpl = ss.u.fields.rpl;
memcpy(&ss, &(fpu->environ.ds),
sizeof(struct swapped_sel));
ss.u.half = SWAP_SHORT(ss.u.half);
fpu->environ.ds.index = ss.u.fields.index;
fpu->environ.ds.ti = ss.u.fields.ti;
fpu->environ.ds.rpl = ss.u.fields.rpl;
for(i = 0; i < 8; i++){
memcpy(&sfpd, &(fpu->stack.ST[i]),
sizeof(struct swapped_fp_data_reg));
fpu->stack.ST[i].mant = SWAP_SHORT(sfpd.mant);
fpu->stack.ST[i].mant1 = SWAP_SHORT(sfpd.mant1);
fpu->stack.ST[i].mant2 = SWAP_SHORT(sfpd.mant2);
fpu->stack.ST[i].mant3 = SWAP_SHORT(sfpd.mant3);
sfpd.u.half = SWAP_SHORT(sfpd.u.half);
fpu->stack.ST[i].exp = sfpd.u.fields.exp;
fpu->stack.ST[i].sign = sfpd.u.fields.sign;
}
}
else{
sfpc.u.fields.rc = fpu->environ.control.rc;
sfpc.u.fields.pc = fpu->environ.control.pc;
sfpc.u.fields.precis = fpu->environ.control.precis;
sfpc.u.fields.undfl = fpu->environ.control.undfl;
sfpc.u.fields.ovrfl = fpu->environ.control.ovrfl;
sfpc.u.fields.zdiv = fpu->environ.control.zdiv;
sfpc.u.fields.denorm = fpu->environ.control.denorm;
sfpc.u.fields.invalid = fpu->environ.control.invalid;
sfpc.u.half = SWAP_SHORT(sfpc.u.half);
memcpy(&(fpu->environ.control), &sfpc,
sizeof(struct swapped_fp_control));
sfps.u.fields.busy = fpu->environ.status.busy;
sfps.u.fields.c3 = fpu->environ.status.c3;
sfps.u.fields.tos = fpu->environ.status.tos;
sfps.u.fields.c2 = fpu->environ.status.c2;
sfps.u.fields.c1 = fpu->environ.status.c1;
sfps.u.fields.c0 = fpu->environ.status.c0;
sfps.u.fields.errsumm = fpu->environ.status.errsumm;
sfps.u.fields.stkflt = fpu->environ.status.stkflt;
sfps.u.fields.precis = fpu->environ.status.precis;
sfps.u.fields.undfl = fpu->environ.status.undfl;
sfps.u.fields.ovrfl = fpu->environ.status.ovrfl;
sfps.u.fields.zdiv = fpu->environ.status.zdiv;
sfps.u.fields.denorm = fpu->environ.status.denorm;
sfps.u.fields.invalid = fpu->environ.status.invalid;
sfps.u.half = SWAP_SHORT(sfps.u.half);
memcpy(&(fpu->environ.status), &sfps,
sizeof(struct swapped_fp_status));
sfpt.u.fields.tag7 = fpu->environ.tag.tag7;
sfpt.u.fields.tag6 = fpu->environ.tag.tag6;
sfpt.u.fields.tag5 = fpu->environ.tag.tag5;
sfpt.u.fields.tag4 = fpu->environ.tag.tag4;
sfpt.u.fields.tag3 = fpu->environ.tag.tag3;
sfpt.u.fields.tag2 = fpu->environ.tag.tag2;
sfpt.u.fields.tag1 = fpu->environ.tag.tag1;
sfpt.u.fields.tag0 = fpu->environ.tag.tag0;
sfpt.u.half = SWAP_SHORT(sfpt.u.half);
memcpy(&(fpu->environ.tag), &sfpt,
sizeof(struct swapped_fp_tag));
ss.u.fields.index = fpu->environ.cs.index;
ss.u.fields.ti = fpu->environ.cs.ti;
ss.u.fields.rpl = fpu->environ.cs.rpl;
ss.u.half = SWAP_SHORT(ss.u.half);
memcpy(&(fpu->environ.cs), &ss,
sizeof(struct swapped_sel));
ss.u.fields.index = fpu->environ.ds.index;
ss.u.fields.ti = fpu->environ.ds.ti;
ss.u.fields.rpl = fpu->environ.ds.rpl;
ss.u.half = SWAP_SHORT(ss.u.half);
memcpy(&(fpu->environ.cs), &ss,
sizeof(struct swapped_sel));
for(i = 0; i < 8; i++){
sfpd.mant = SWAP_SHORT(fpu->stack.ST[i].mant);
sfpd.mant1 = SWAP_SHORT(fpu->stack.ST[i].mant1);
sfpd.mant2 = SWAP_SHORT(fpu->stack.ST[i].mant2);
sfpd.mant3 = SWAP_SHORT(fpu->stack.ST[i].mant3);
sfpd.u.fields.exp = fpu->stack.ST[i].exp;
sfpd.u.fields.sign = fpu->stack.ST[i].sign;
sfpd.u.half = SWAP_SHORT(sfpd.u.half);
memcpy(&(fpu->stack.ST[i]), &sfpd,
sizeof(struct swapped_fp_data_reg));
}
}
}
void
swap_i386_thread_exceptstate(
i386_thread_exceptstate_t *exc,
enum byte_sex target_byte_sex)
{
struct swapped_err_code {
union {
struct err_code_normal {
unsigned int :16,
index :13,
tbl :2,
ext :1;
} normal;
struct err_code_pgfault {
unsigned int :29,
user :1,
wrtflt :1,
prot :1;
} pgfault;
unsigned long word;
} u;
} sec;
unsigned long word;
enum byte_sex host_byte_sex;
host_byte_sex = get_host_byte_sex();
exc->trapno = SWAP_LONG(exc->trapno);
if(exc->trapno == 14){
if(target_byte_sex == host_byte_sex){
memcpy(&sec, &(exc->err), sizeof(struct swapped_err_code));
sec.u.word = SWAP_LONG(sec.u.word);
exc->err.pgfault.user = sec.u.pgfault.user;
exc->err.pgfault.wrtflt = sec.u.pgfault.wrtflt;
exc->err.pgfault.prot = sec.u.pgfault.prot;
}
else{
sec.u.pgfault.prot = exc->err.pgfault.prot;
sec.u.pgfault.wrtflt = exc->err.pgfault.wrtflt;
sec.u.pgfault.user = exc->err.pgfault.user;
sec.u.word = SWAP_LONG(sec.u.word);
memcpy(&(exc->err), &sec, sizeof(struct swapped_err_code));
}
}
else{
if(target_byte_sex == host_byte_sex){
memcpy(&sec, &(exc->err), sizeof(struct swapped_err_code));
sec.u.word = SWAP_LONG(sec.u.word);
word = sec.u.normal.index;
exc->err.normal.index = SWAP_LONG(word);
exc->err.normal.tbl = sec.u.normal.tbl;
exc->err.normal.ext = sec.u.normal.ext;
}
else{
sec.u.normal.ext = exc->err.normal.ext;
sec.u.normal.tbl = exc->err.normal.tbl;
word = exc->err.normal.index;
sec.u.normal.index = SWAP_LONG(word);
sec.u.word = SWAP_LONG(sec.u.word);
memcpy(&(exc->err), &sec, sizeof(struct swapped_err_code));
}
}
}
void
swap_i386_thread_cthreadstate(
i386_thread_cthreadstate_t *user,
enum byte_sex target_byte_sex)
{
user->self = SWAP_LONG(user->self);
}
void
swap_ident_command(
struct ident_command *id,
enum byte_sex target_byte_sex)
{
id->cmd = SWAP_LONG(id->cmd);
id->cmdsize = SWAP_LONG(id->cmdsize);
}
void
swap_nlist(
struct nlist *symbols,
unsigned long nsymbols,
enum byte_sex target_byte_sex)
{
unsigned long i;
for(i = 0; i < nsymbols; i++){
symbols[i].n_un.n_strx = SWAP_LONG(symbols[i].n_un.n_strx);
/* n_type */
/* n_sect */
symbols[i].n_desc = SWAP_SHORT(symbols[i].n_desc);
symbols[i].n_value = SWAP_LONG(symbols[i].n_value);
}
}
void
swap_ranlib(
struct ranlib *ranlibs,
unsigned long nranlibs,
enum byte_sex target_byte_sex)
{
unsigned long i;
for(i = 0; i < nranlibs; i++){
ranlibs[i].ran_un.ran_strx = SWAP_LONG(ranlibs[i].ran_un.ran_strx);
ranlibs[i].ran_off = SWAP_LONG(ranlibs[i].ran_off);
}
}
void
swap_relocation_info(
struct relocation_info *relocs,
unsigned long nrelocs,
enum byte_sex target_byte_sex)
{
unsigned long i;
enum byte_sex host_byte_sex;
enum bool to_host_byte_sex, scattered;
struct swapped_relocation_info {
long r_address;
union {
struct {
unsigned int
r_type:4,
r_extern:1,
r_length:2,
r_pcrel:1,
r_symbolnum:24;
} fields;
unsigned long word;
} u;
} sr;
struct swapped_scattered_relocation_info {
unsigned long word;
long r_value;
} *ssr;
host_byte_sex = get_host_byte_sex();
to_host_byte_sex = target_byte_sex == host_byte_sex;
for(i = 0; i < nrelocs; i++){
if(to_host_byte_sex)
scattered = (SWAP_LONG(relocs[i].r_address) & R_SCATTERED) != 0;
else
scattered = ((relocs[i].r_address) & R_SCATTERED) != 0;
if(scattered == FALSE){
if(to_host_byte_sex){
memcpy(&sr, relocs + i, sizeof(struct relocation_info));
sr.r_address = SWAP_LONG(sr.r_address);
sr.u.word = SWAP_LONG(sr.u.word);
relocs[i].r_address = sr.r_address;
relocs[i].r_symbolnum = sr.u.fields.r_symbolnum;
relocs[i].r_pcrel = sr.u.fields.r_pcrel;
relocs[i].r_length = sr.u.fields.r_length;
relocs[i].r_extern = sr.u.fields.r_extern;
relocs[i].r_type = sr.u.fields.r_type;
}
else{
sr.r_address = relocs[i].r_address;
sr.u.fields.r_symbolnum = relocs[i].r_symbolnum;
sr.u.fields.r_length = relocs[i].r_length;
sr.u.fields.r_pcrel = relocs[i].r_pcrel;
sr.u.fields.r_extern = relocs[i].r_extern;
sr.u.fields.r_type = relocs[i].r_type;
sr.r_address = SWAP_LONG(sr.r_address);
sr.u.word = SWAP_LONG(sr.u.word);
memcpy(relocs + i, &sr, sizeof(struct relocation_info));
}
}
else{
ssr = (struct swapped_scattered_relocation_info *)(relocs + i);
ssr->word = SWAP_LONG(ssr->word);
ssr->r_value = SWAP_LONG(ssr->r_value);
}
}
}