source: releases/F-Script Anywhere/1.1.2a1/Source/bytesex.c@ 519

Last change on this file since 519 was 7, checked in by Nicholas Riley, 22 years ago

F-Script Anywhere 1.1.2a1

File size: 56.6 KB
Line 
1/*
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.1 (the "License"). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
12 * this file.
13 *
14 * The Original Code and all software distributed under the License are
15 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
20 * under the License.
21 *
22 * @APPLE_LICENSE_HEADER_END@
23 */
24/* byte_sex.c */
25#include <string.h>
26#include <mach-o/fat.h>
27#include <mach-o/loader.h>
28#import <mach/m68k/thread_status.h>
29#import <mach/ppc/thread_status.h>
30#import <mach/m88k/thread_status.h>
31#import <mach/i860/thread_status.h>
32#import <mach/i386/thread_status.h>
33#import <mach/hppa/thread_status.h>
34#import <mach/sparc/thread_status.h>
35#include <mach-o/nlist.h>
36#include <mach-o/reloc.h>
37#include <mach-o/ranlib.h>
38#include "stuff/bool.h"
39#include "stuff/bytesex.h"
40
41__private_extern__
42double
43SWAP_DOUBLE(
44double d)
45{
46 union {
47 char c[8];
48 double d;
49 } in, out;
50 in.d = d;
51 out.c[0] = in.c[7];
52 out.c[1] = in.c[6];
53 out.c[2] = in.c[5];
54 out.c[3] = in.c[4];
55 out.c[4] = in.c[3];
56 out.c[5] = in.c[2];
57 out.c[6] = in.c[1];
58 out.c[7] = in.c[0];
59 return(out.d);
60}
61
62__private_extern__
63float
64SWAP_FLOAT(
65float f)
66{
67 union {
68 char c[7];
69 float f;
70 } in, out;
71 in.f = f;
72 out.c[0] = in.c[3];
73 out.c[1] = in.c[2];
74 out.c[2] = in.c[1];
75 out.c[3] = in.c[0];
76 return(out.f);
77}
78
79/*
80 * get_host_byte_sex() returns the enum constant for the byte sex of the host
81 * it is running on.
82 */
83__private_extern__
84enum byte_sex
85get_host_byte_sex(
86void)
87{
88 unsigned long s;
89
90 s = (BIG_ENDIAN_BYTE_SEX << 24) | LITTLE_ENDIAN_BYTE_SEX;
91 return((enum byte_sex)*((char *)&s));
92}
93
94__private_extern__
95void
96swap_fat_header(
97struct fat_header *fat_header,
98enum byte_sex target_byte_sex)
99{
100#ifdef __MWERKS__
101 enum byte_sex dummy;
102 dummy = target_byte_sex;
103#endif
104
105 fat_header->magic = SWAP_LONG(fat_header->magic);
106 fat_header->nfat_arch = SWAP_LONG(fat_header->nfat_arch);
107}
108
109__private_extern__
110void
111swap_fat_arch(
112struct fat_arch *fat_archs,
113unsigned long nfat_arch,
114enum byte_sex target_byte_sex)
115{
116 unsigned long i;
117#ifdef __MWERKS__
118 enum byte_sex dummy;
119 dummy = target_byte_sex;
120#endif
121
122 for(i = 0; i < nfat_arch; i++){
123 fat_archs[i].cputype = SWAP_LONG(fat_archs[i].cputype);
124 fat_archs[i].cpusubtype = SWAP_LONG(fat_archs[i].cpusubtype);
125 fat_archs[i].offset = SWAP_LONG(fat_archs[i].offset);
126 fat_archs[i].size = SWAP_LONG(fat_archs[i].size);
127 fat_archs[i].align = SWAP_LONG(fat_archs[i].align);
128 }
129}
130
131__private_extern__
132void
133swap_mach_header(
134struct mach_header *mh,
135enum byte_sex target_byte_sex)
136{
137#ifdef __MWERKS__
138 enum byte_sex dummy;
139 dummy = target_byte_sex;
140#endif
141 mh->magic = SWAP_LONG(mh->magic);
142 mh->cputype = SWAP_LONG(mh->cputype);
143 mh->cpusubtype = SWAP_LONG(mh->cpusubtype);
144 mh->filetype = SWAP_LONG(mh->filetype);
145 mh->ncmds = SWAP_LONG(mh->ncmds);
146 mh->sizeofcmds = SWAP_LONG(mh->sizeofcmds);
147 mh->flags = SWAP_LONG(mh->flags);
148}
149
150__private_extern__
151void
152swap_load_command(
153struct load_command *lc,
154enum byte_sex target_byte_sex)
155{
156#ifdef __MWERKS__
157 enum byte_sex dummy;
158 dummy = target_byte_sex;
159#endif
160 lc->cmd = SWAP_LONG(lc->cmd);
161 lc->cmdsize = SWAP_LONG(lc->cmdsize);
162}
163
164__private_extern__
165void
166swap_segment_command(
167struct segment_command *sg,
168enum byte_sex target_byte_sex)
169{
170#ifdef __MWERKS__
171 enum byte_sex dummy;
172 dummy = target_byte_sex;
173#endif
174 /* segname[16] */
175 sg->cmd = SWAP_LONG(sg->cmd);
176 sg->cmdsize = SWAP_LONG(sg->cmdsize);
177 sg->vmaddr = SWAP_LONG(sg->vmaddr);
178 sg->vmsize = SWAP_LONG(sg->vmsize);
179 sg->fileoff = SWAP_LONG(sg->fileoff);
180 sg->filesize = SWAP_LONG(sg->filesize);
181 sg->maxprot = SWAP_LONG(sg->maxprot);
182 sg->initprot = SWAP_LONG(sg->initprot);
183 sg->nsects = SWAP_LONG(sg->nsects);
184 sg->flags = SWAP_LONG(sg->flags);
185}
186
187__private_extern__
188void
189swap_section(
190struct section *s,
191unsigned long nsects,
192enum byte_sex target_byte_sex)
193{
194 unsigned long i;
195#ifdef __MWERKS__
196 enum byte_sex dummy;
197 dummy = target_byte_sex;
198#endif
199
200 for(i = 0; i < nsects; i++){
201 /* sectname[16] */
202 /* segname[16] */
203 s[i].addr = SWAP_LONG(s[i].addr);
204 s[i].size = SWAP_LONG(s[i].size);
205 s[i].offset = SWAP_LONG(s[i].offset);
206 s[i].align = SWAP_LONG(s[i].align);
207 s[i].reloff = SWAP_LONG(s[i].reloff);
208 s[i].nreloc = SWAP_LONG(s[i].nreloc);
209 s[i].flags = SWAP_LONG(s[i].flags);
210 s[i].reserved1 = SWAP_LONG(s[i].reserved1);
211 s[i].reserved2 = SWAP_LONG(s[i].reserved2);
212 }
213}
214
215__private_extern__
216void
217swap_symtab_command(
218struct symtab_command *st,
219enum byte_sex target_byte_sex)
220{
221#ifdef __MWERKS__
222 enum byte_sex dummy;
223 dummy = target_byte_sex;
224#endif
225 st->cmd = SWAP_LONG(st->cmd);
226 st->cmdsize = SWAP_LONG(st->cmdsize);
227 st->symoff = SWAP_LONG(st->symoff);
228 st->nsyms = SWAP_LONG(st->nsyms);
229 st->stroff = SWAP_LONG(st->stroff);
230 st->strsize = SWAP_LONG(st->strsize);
231}
232
233__private_extern__
234void
235swap_dysymtab_command(
236struct dysymtab_command *dyst,
237enum byte_sex target_byte_sex)
238{
239#ifdef __MWERKS__
240 enum byte_sex dummy;
241 dummy = target_byte_sex;
242#endif
243 dyst->cmd = SWAP_LONG(dyst->cmd);
244 dyst->cmdsize = SWAP_LONG(dyst->cmdsize);
245 dyst->ilocalsym = SWAP_LONG(dyst->ilocalsym);
246 dyst->nlocalsym = SWAP_LONG(dyst->nlocalsym);
247 dyst->iextdefsym = SWAP_LONG(dyst->iextdefsym);
248 dyst->nextdefsym = SWAP_LONG(dyst->nextdefsym);
249 dyst->iundefsym = SWAP_LONG(dyst->iundefsym);
250 dyst->nundefsym = SWAP_LONG(dyst->nundefsym);
251 dyst->tocoff = SWAP_LONG(dyst->tocoff);
252 dyst->ntoc = SWAP_LONG(dyst->ntoc);
253 dyst->modtaboff = SWAP_LONG(dyst->modtaboff);
254 dyst->nmodtab = SWAP_LONG(dyst->nmodtab);
255 dyst->extrefsymoff = SWAP_LONG(dyst->extrefsymoff);
256 dyst->nextrefsyms = SWAP_LONG(dyst->nextrefsyms);
257 dyst->indirectsymoff = SWAP_LONG(dyst->indirectsymoff);
258 dyst->nindirectsyms = SWAP_LONG(dyst->nindirectsyms);
259 dyst->extreloff = SWAP_LONG(dyst->extreloff);
260 dyst->nextrel = SWAP_LONG(dyst->nextrel);
261 dyst->locreloff = SWAP_LONG(dyst->locreloff);
262 dyst->nlocrel = SWAP_LONG(dyst->nlocrel);
263}
264
265__private_extern__
266void
267swap_symseg_command(
268struct symseg_command *ss,
269enum byte_sex target_byte_sex)
270{
271#ifdef __MWERKS__
272 enum byte_sex dummy;
273 dummy = target_byte_sex;
274#endif
275 ss->cmd = SWAP_LONG(ss->cmd);
276 ss->cmdsize = SWAP_LONG(ss->cmdsize);
277 ss->offset = SWAP_LONG(ss->offset);
278 ss->size = SWAP_LONG(ss->size);
279}
280
281__private_extern__
282void
283swap_fvmlib_command(
284struct fvmlib_command *fl,
285enum byte_sex target_byte_sex)
286{
287#ifdef __MWERKS__
288 enum byte_sex dummy;
289 dummy = target_byte_sex;
290#endif
291 fl->cmd = SWAP_LONG(fl->cmd);
292 fl->cmdsize = SWAP_LONG(fl->cmdsize);
293 fl->fvmlib.name.offset = SWAP_LONG(fl->fvmlib.name.offset);
294 fl->fvmlib.minor_version = SWAP_LONG(fl->fvmlib.minor_version);
295 fl->fvmlib.header_addr = SWAP_LONG(fl->fvmlib.header_addr);
296}
297
298__private_extern__
299void
300swap_dylib_command(
301struct dylib_command *dl,
302enum byte_sex target_byte_sex)
303{
304#ifdef __MWERKS__
305 enum byte_sex dummy;
306 dummy = target_byte_sex;
307#endif
308 dl->cmd = SWAP_LONG(dl->cmd);
309 dl->cmdsize = SWAP_LONG(dl->cmdsize);
310 dl->dylib.name.offset = SWAP_LONG(dl->dylib.name.offset);
311 dl->dylib.timestamp = SWAP_LONG(dl->dylib.timestamp);
312 dl->dylib.current_version = SWAP_LONG(dl->dylib.current_version);
313 dl->dylib.compatibility_version =
314 SWAP_LONG(dl->dylib.compatibility_version);
315}
316
317__private_extern__
318void
319swap_sub_framework_command(
320struct sub_framework_command *sub,
321enum byte_sex target_byte_sex)
322{
323#ifdef __MWERKS__
324 enum byte_sex dummy;
325 dummy = target_byte_sex;
326#endif
327 sub->cmd = SWAP_LONG(sub->cmd);
328 sub->cmdsize = SWAP_LONG(sub->cmdsize);
329 sub->umbrella.offset = SWAP_LONG(sub->umbrella.offset);
330}
331
332__private_extern__
333void
334swap_sub_umbrella_command(
335struct sub_umbrella_command *usub,
336enum byte_sex target_byte_sex)
337{
338#ifdef __MWERKS__
339 enum byte_sex dummy;
340 dummy = target_byte_sex;
341#endif
342 usub->cmd = SWAP_LONG(usub->cmd);
343 usub->cmdsize = SWAP_LONG(usub->cmdsize);
344 usub->sub_umbrella.offset = SWAP_LONG(usub->sub_umbrella.offset);
345}
346
347__private_extern__
348void
349swap_sub_library_command(
350struct sub_library_command *lsub,
351enum byte_sex target_byte_sex)
352{
353#ifdef __MWERKS__
354 enum byte_sex dummy;
355 dummy = target_byte_sex;
356#endif
357 lsub->cmd = SWAP_LONG(lsub->cmd);
358 lsub->cmdsize = SWAP_LONG(lsub->cmdsize);
359 lsub->sub_library.offset = SWAP_LONG(lsub->sub_library.offset);
360}
361
362__private_extern__
363void
364swap_sub_client_command(
365struct sub_client_command *csub,
366enum byte_sex target_byte_sex)
367{
368#ifdef __MWERKS__
369 enum byte_sex dummy;
370 dummy = target_byte_sex;
371#endif
372 csub->cmd = SWAP_LONG(csub->cmd);
373 csub->cmdsize = SWAP_LONG(csub->cmdsize);
374 csub->client.offset = SWAP_LONG(csub->client.offset);
375}
376
377__private_extern__
378void
379swap_prebound_dylib_command(
380struct prebound_dylib_command *pbdylib,
381enum byte_sex target_byte_sex)
382{
383#ifdef __MWERKS__
384 enum byte_sex dummy;
385 dummy = target_byte_sex;
386#endif
387 pbdylib->cmd = SWAP_LONG(pbdylib->cmd);
388 pbdylib->cmdsize = SWAP_LONG(pbdylib->cmdsize);
389 pbdylib->name.offset = SWAP_LONG(pbdylib->name.offset);
390 pbdylib->nmodules = SWAP_LONG(pbdylib->nmodules);
391 pbdylib->linked_modules.offset =
392 SWAP_LONG(pbdylib->linked_modules.offset);
393}
394
395__private_extern__
396void
397swap_dylinker_command(
398struct dylinker_command *dyld,
399enum byte_sex target_byte_sex)
400{
401#ifdef __MWERKS__
402 enum byte_sex dummy;
403 dummy = target_byte_sex;
404#endif
405 dyld->cmd = SWAP_LONG(dyld->cmd);
406 dyld->cmdsize = SWAP_LONG(dyld->cmdsize);
407 dyld->name.offset = SWAP_LONG(dyld->name.offset);
408}
409
410__private_extern__
411void
412swap_fvmfile_command(
413struct fvmfile_command *ff,
414enum byte_sex target_byte_sex)
415{
416#ifdef __MWERKS__
417 enum byte_sex dummy;
418 dummy = target_byte_sex;
419#endif
420 ff->cmd = SWAP_LONG(ff->cmd);
421 ff->cmdsize = SWAP_LONG(ff->cmdsize);
422 ff->name.offset = SWAP_LONG(ff->name.offset);
423 ff->header_addr = SWAP_LONG(ff->header_addr);
424}
425
426
427__private_extern__
428void
429swap_thread_command(
430struct thread_command *ut,
431enum byte_sex target_byte_sex)
432{
433#ifdef __MWERKS__
434 enum byte_sex dummy;
435 dummy = target_byte_sex;
436#endif
437 ut->cmd = SWAP_LONG(ut->cmd);
438 ut->cmdsize = SWAP_LONG(ut->cmdsize);
439}
440
441__private_extern__
442void
443swap_m68k_thread_state_regs(
444struct m68k_thread_state_regs *cpu,
445enum byte_sex target_byte_sex)
446{
447 unsigned long i;
448#ifdef __MWERKS__
449 enum byte_sex dummy;
450 dummy = target_byte_sex;
451#endif
452
453 for(i = 0; i < 8; i++)
454 cpu->dreg[i] = SWAP_LONG(cpu->dreg[i]);
455 for(i = 0; i < 8; i++)
456 cpu->areg[i] = SWAP_LONG(cpu->areg[i]);
457 cpu->pad0 = SWAP_SHORT(cpu->pad0);
458 cpu->sr = SWAP_SHORT(cpu->sr);
459 cpu->pc = SWAP_LONG(cpu->pc);
460}
461
462__private_extern__
463void
464swap_m68k_thread_state_68882(
465struct m68k_thread_state_68882 *fpu,
466enum byte_sex target_byte_sex)
467{
468 unsigned long i, tmp;
469#ifdef __MWERKS__
470 enum byte_sex dummy;
471 dummy = target_byte_sex;
472#endif
473
474 for(i = 0; i < 8; i++){
475 tmp = SWAP_LONG(fpu->regs[i].fp[0]);
476 fpu->regs[i].fp[1] = SWAP_LONG(fpu->regs[i].fp[1]);
477 fpu->regs[i].fp[0] = SWAP_LONG(fpu->regs[i].fp[2]);
478 fpu->regs[i].fp[2] = tmp;
479 }
480 fpu->cr = SWAP_LONG(fpu->cr);
481 fpu->sr = SWAP_LONG(fpu->sr);
482 fpu->iar = SWAP_LONG(fpu->iar);
483 fpu->state = SWAP_LONG(fpu->state);
484}
485
486__private_extern__
487void
488swap_m68k_thread_state_user_reg(
489struct m68k_thread_state_user_reg *user_reg,
490enum byte_sex target_byte_sex)
491{
492#ifdef __MWERKS__
493 enum byte_sex dummy;
494 dummy = target_byte_sex;
495#endif
496 user_reg->user_reg = SWAP_LONG(user_reg->user_reg);
497}
498
499__private_extern__
500void
501swap_ppc_thread_state_t(
502ppc_thread_state_t *cpu,
503enum byte_sex target_byte_sex)
504{
505 cpu->srr0 = SWAP_LONG(cpu->srr0);
506 cpu->srr1 = SWAP_LONG(cpu->srr1);
507 cpu->r0 = SWAP_LONG(cpu->r0);
508 cpu->r1 = SWAP_LONG(cpu->r1);
509 cpu->r2 = SWAP_LONG(cpu->r2);
510 cpu->r3 = SWAP_LONG(cpu->r3);
511 cpu->r4 = SWAP_LONG(cpu->r4);
512 cpu->r5 = SWAP_LONG(cpu->r5);
513 cpu->r6 = SWAP_LONG(cpu->r6);
514 cpu->r7 = SWAP_LONG(cpu->r7);
515 cpu->r8 = SWAP_LONG(cpu->r8);
516 cpu->r9 = SWAP_LONG(cpu->r9);
517 cpu->r10 = SWAP_LONG(cpu->r10);
518 cpu->r11 = SWAP_LONG(cpu->r11);
519 cpu->r12 = SWAP_LONG(cpu->r12);
520 cpu->r13 = SWAP_LONG(cpu->r13);
521 cpu->r14 = SWAP_LONG(cpu->r14);
522 cpu->r15 = SWAP_LONG(cpu->r15);
523 cpu->r16 = SWAP_LONG(cpu->r16);
524 cpu->r17 = SWAP_LONG(cpu->r17);
525 cpu->r18 = SWAP_LONG(cpu->r18);
526 cpu->r19 = SWAP_LONG(cpu->r19);
527 cpu->r20 = SWAP_LONG(cpu->r20);
528 cpu->r21 = SWAP_LONG(cpu->r21);
529 cpu->r22 = SWAP_LONG(cpu->r22);
530 cpu->r23 = SWAP_LONG(cpu->r23);
531 cpu->r24 = SWAP_LONG(cpu->r24);
532 cpu->r25 = SWAP_LONG(cpu->r25);
533 cpu->r26 = SWAP_LONG(cpu->r26);
534 cpu->r27 = SWAP_LONG(cpu->r27);
535 cpu->r28 = SWAP_LONG(cpu->r28);
536 cpu->r29 = SWAP_LONG(cpu->r29);
537 cpu->r30 = SWAP_LONG(cpu->r30);
538 cpu->r31 = SWAP_LONG(cpu->r31);
539 cpu->cr = SWAP_LONG(cpu->cr);
540 cpu->xer = SWAP_LONG(cpu->xer);
541 cpu->lr = SWAP_LONG(cpu->lr);
542 cpu->ctr = SWAP_LONG(cpu->ctr);
543 cpu->mq = SWAP_LONG(cpu->mq);
544 cpu->pad = SWAP_LONG(cpu->pad);
545}
546
547__private_extern__
548void
549swap_ppc_float_state_t(
550ppc_float_state_t *fpu,
551enum byte_sex target_byte_sex)
552{
553 unsigned long i;
554#ifdef __MWERKS__
555 enum byte_sex dummy;
556 dummy = target_byte_sex;
557#endif
558
559 for(i = 0; i < 32; i++)
560 fpu->fpregs[i] = SWAP_DOUBLE(fpu->fpregs[i]);
561
562 fpu->fpscr_pad = SWAP_LONG(fpu->fpscr_pad);
563 fpu->fpscr = SWAP_LONG(fpu->fpscr);
564}
565
566__private_extern__
567void
568swap_ppc_exception_state_t(
569ppc_exception_state_t *state,
570enum byte_sex target_byte_sex)
571{
572 unsigned long i;
573#ifdef __MWERKS__
574 enum byte_sex dummy;
575 dummy = target_byte_sex;
576#endif
577
578 state->dar = SWAP_LONG(state->dar);
579 state->dsisr = SWAP_LONG(state->dsisr);
580 state->exception = SWAP_LONG(state->exception);
581 state->pad0 = SWAP_LONG(state->pad0);
582
583 for(i = 0; i < 4; i++)
584 state->pad1[i] = SWAP_LONG(state->pad1[i]);
585}
586
587__private_extern__
588void
589swap_m88k_thread_state_grf_t(
590m88k_thread_state_grf_t *cpu,
591enum byte_sex target_byte_sex)
592{
593#ifdef __MWERKS__
594 enum byte_sex dummy;
595 dummy = target_byte_sex;
596#endif
597 cpu->r1 = SWAP_LONG(cpu->r1);
598 cpu->r2 = SWAP_LONG(cpu->r2);
599 cpu->r3 = SWAP_LONG(cpu->r3);
600 cpu->r4 = SWAP_LONG(cpu->r4);
601 cpu->r5 = SWAP_LONG(cpu->r5);
602 cpu->r6 = SWAP_LONG(cpu->r6);
603 cpu->r7 = SWAP_LONG(cpu->r7);
604 cpu->r8 = SWAP_LONG(cpu->r8);
605 cpu->r9 = SWAP_LONG(cpu->r9);
606 cpu->r10 = SWAP_LONG(cpu->r10);
607 cpu->r11 = SWAP_LONG(cpu->r11);
608 cpu->r12 = SWAP_LONG(cpu->r12);
609 cpu->r13 = SWAP_LONG(cpu->r13);
610 cpu->r14 = SWAP_LONG(cpu->r14);
611 cpu->r15 = SWAP_LONG(cpu->r15);
612 cpu->r16 = SWAP_LONG(cpu->r16);
613 cpu->r17 = SWAP_LONG(cpu->r17);
614 cpu->r18 = SWAP_LONG(cpu->r18);
615 cpu->r19 = SWAP_LONG(cpu->r19);
616 cpu->r20 = SWAP_LONG(cpu->r20);
617 cpu->r21 = SWAP_LONG(cpu->r21);
618 cpu->r22 = SWAP_LONG(cpu->r22);
619 cpu->r23 = SWAP_LONG(cpu->r23);
620 cpu->r24 = SWAP_LONG(cpu->r24);
621 cpu->r25 = SWAP_LONG(cpu->r25);
622 cpu->r26 = SWAP_LONG(cpu->r26);
623 cpu->r27 = SWAP_LONG(cpu->r27);
624 cpu->r28 = SWAP_LONG(cpu->r28);
625 cpu->r29 = SWAP_LONG(cpu->r29);
626 cpu->r30 = SWAP_LONG(cpu->r30);
627 cpu->r31 = SWAP_LONG(cpu->r31);
628 cpu->xip = SWAP_LONG(cpu->xip);
629 cpu->xip_in_bd = SWAP_LONG(cpu->xip_in_bd);
630 cpu->nip = SWAP_LONG(cpu->nip);
631}
632
633__private_extern__
634void
635swap_m88k_thread_state_xrf_t(
636m88k_thread_state_xrf_t *fpu,
637enum byte_sex target_byte_sex)
638{
639 enum byte_sex host_byte_sex;
640
641 struct swapped_m88k_fpsr {
642 union {
643 struct {
644 unsigned afinx:BIT_WIDTH(0);
645 unsigned afovf:BIT_WIDTH(1);
646 unsigned afunf:BIT_WIDTH(2);
647 unsigned afdvz:BIT_WIDTH(3);
648 unsigned afinv:BIT_WIDTH(4);
649 unsigned :BITS_WIDTH(15,5);
650 unsigned xmod:BIT_WIDTH(16);
651 unsigned :BITS_WIDTH(31,17);
652 } fields;
653 unsigned long word;
654 } u;
655 } ssr;
656 struct swapped_m88k_fpcr {
657 union {
658 struct {
659 unsigned efinx:BIT_WIDTH(0);
660 unsigned efovf:BIT_WIDTH(1);
661 unsigned efunf:BIT_WIDTH(2);
662 unsigned efdvz:BIT_WIDTH(3);
663 unsigned efinv:BIT_WIDTH(4);
664 unsigned :BITS_WIDTH(13,5);
665 m88k_fpcr_rm_t rm:BITS_WIDTH(15,14);
666 unsigned :BITS_WIDTH(31,16);
667 } fields;
668 unsigned long word;
669 } u;
670 } scr;
671
672 host_byte_sex = get_host_byte_sex();
673
674 fpu->x1.x[0] = SWAP_LONG(fpu->x1.x[0]);
675 fpu->x1.x[1] = SWAP_LONG(fpu->x1.x[1]);
676 fpu->x1.x[2] = SWAP_LONG(fpu->x1.x[2]);
677 fpu->x1.x[3] = SWAP_LONG(fpu->x1.x[3]);
678 fpu->x2.x[0] = SWAP_LONG(fpu->x2.x[0]);
679 fpu->x2.x[1] = SWAP_LONG(fpu->x2.x[1]);
680 fpu->x2.x[2] = SWAP_LONG(fpu->x2.x[2]);
681 fpu->x2.x[3] = SWAP_LONG(fpu->x2.x[3]);
682 fpu->x3.x[0] = SWAP_LONG(fpu->x3.x[0]);
683 fpu->x3.x[1] = SWAP_LONG(fpu->x3.x[1]);
684 fpu->x3.x[2] = SWAP_LONG(fpu->x3.x[2]);
685 fpu->x3.x[3] = SWAP_LONG(fpu->x3.x[3]);
686 fpu->x4.x[0] = SWAP_LONG(fpu->x4.x[0]);
687 fpu->x4.x[1] = SWAP_LONG(fpu->x4.x[1]);
688 fpu->x4.x[2] = SWAP_LONG(fpu->x4.x[2]);
689 fpu->x4.x[3] = SWAP_LONG(fpu->x4.x[3]);
690 fpu->x5.x[0] = SWAP_LONG(fpu->x5.x[0]);
691 fpu->x5.x[1] = SWAP_LONG(fpu->x5.x[1]);
692 fpu->x5.x[2] = SWAP_LONG(fpu->x5.x[2]);
693 fpu->x5.x[3] = SWAP_LONG(fpu->x5.x[3]);
694 fpu->x6.x[0] = SWAP_LONG(fpu->x6.x[0]);
695 fpu->x6.x[1] = SWAP_LONG(fpu->x6.x[1]);
696 fpu->x6.x[2] = SWAP_LONG(fpu->x6.x[2]);
697 fpu->x6.x[3] = SWAP_LONG(fpu->x6.x[3]);
698 fpu->x7.x[0] = SWAP_LONG(fpu->x7.x[0]);
699 fpu->x7.x[1] = SWAP_LONG(fpu->x7.x[1]);
700 fpu->x7.x[2] = SWAP_LONG(fpu->x7.x[2]);
701 fpu->x7.x[3] = SWAP_LONG(fpu->x7.x[3]);
702 fpu->x8.x[0] = SWAP_LONG(fpu->x8.x[0]);
703 fpu->x8.x[1] = SWAP_LONG(fpu->x8.x[1]);
704 fpu->x8.x[2] = SWAP_LONG(fpu->x8.x[2]);
705 fpu->x8.x[3] = SWAP_LONG(fpu->x8.x[3]);
706 fpu->x9.x[0] = SWAP_LONG(fpu->x9.x[0]);
707 fpu->x9.x[1] = SWAP_LONG(fpu->x9.x[1]);
708 fpu->x9.x[2] = SWAP_LONG(fpu->x9.x[2]);
709 fpu->x9.x[3] = SWAP_LONG(fpu->x9.x[3]);
710 fpu->x10.x[0] = SWAP_LONG(fpu->x10.x[0]);
711 fpu->x10.x[1] = SWAP_LONG(fpu->x10.x[1]);
712 fpu->x10.x[2] = SWAP_LONG(fpu->x10.x[2]);
713 fpu->x10.x[3] = SWAP_LONG(fpu->x10.x[3]);
714 fpu->x11.x[0] = SWAP_LONG(fpu->x11.x[0]);
715 fpu->x11.x[1] = SWAP_LONG(fpu->x11.x[1]);
716 fpu->x11.x[2] = SWAP_LONG(fpu->x11.x[2]);
717 fpu->x11.x[3] = SWAP_LONG(fpu->x11.x[3]);
718 fpu->x12.x[0] = SWAP_LONG(fpu->x12.x[0]);
719 fpu->x12.x[1] = SWAP_LONG(fpu->x12.x[1]);
720 fpu->x12.x[2] = SWAP_LONG(fpu->x12.x[2]);
721 fpu->x12.x[3] = SWAP_LONG(fpu->x12.x[3]);
722 fpu->x13.x[0] = SWAP_LONG(fpu->x13.x[0]);
723 fpu->x13.x[1] = SWAP_LONG(fpu->x13.x[1]);
724 fpu->x13.x[2] = SWAP_LONG(fpu->x13.x[2]);
725 fpu->x13.x[3] = SWAP_LONG(fpu->x13.x[3]);
726 fpu->x14.x[0] = SWAP_LONG(fpu->x14.x[0]);
727 fpu->x14.x[1] = SWAP_LONG(fpu->x14.x[1]);
728 fpu->x14.x[2] = SWAP_LONG(fpu->x14.x[2]);
729 fpu->x14.x[3] = SWAP_LONG(fpu->x14.x[3]);
730 fpu->x15.x[0] = SWAP_LONG(fpu->x15.x[0]);
731 fpu->x15.x[1] = SWAP_LONG(fpu->x15.x[1]);
732 fpu->x15.x[2] = SWAP_LONG(fpu->x15.x[2]);
733 fpu->x15.x[3] = SWAP_LONG(fpu->x15.x[3]);
734 fpu->x16.x[0] = SWAP_LONG(fpu->x16.x[0]);
735 fpu->x16.x[1] = SWAP_LONG(fpu->x16.x[1]);
736 fpu->x16.x[2] = SWAP_LONG(fpu->x16.x[2]);
737 fpu->x16.x[3] = SWAP_LONG(fpu->x16.x[3]);
738 fpu->x17.x[0] = SWAP_LONG(fpu->x17.x[0]);
739 fpu->x17.x[1] = SWAP_LONG(fpu->x17.x[1]);
740 fpu->x17.x[2] = SWAP_LONG(fpu->x17.x[2]);
741 fpu->x17.x[3] = SWAP_LONG(fpu->x17.x[3]);
742 fpu->x18.x[0] = SWAP_LONG(fpu->x18.x[0]);
743 fpu->x18.x[1] = SWAP_LONG(fpu->x18.x[1]);
744 fpu->x18.x[2] = SWAP_LONG(fpu->x18.x[2]);
745 fpu->x18.x[3] = SWAP_LONG(fpu->x18.x[3]);
746 fpu->x19.x[0] = SWAP_LONG(fpu->x19.x[0]);
747 fpu->x19.x[1] = SWAP_LONG(fpu->x19.x[1]);
748 fpu->x19.x[2] = SWAP_LONG(fpu->x19.x[2]);
749 fpu->x19.x[3] = SWAP_LONG(fpu->x19.x[3]);
750 fpu->x20.x[0] = SWAP_LONG(fpu->x20.x[0]);
751 fpu->x20.x[1] = SWAP_LONG(fpu->x20.x[1]);
752 fpu->x20.x[2] = SWAP_LONG(fpu->x20.x[2]);
753 fpu->x20.x[3] = SWAP_LONG(fpu->x20.x[3]);
754 fpu->x21.x[0] = SWAP_LONG(fpu->x21.x[0]);
755 fpu->x21.x[1] = SWAP_LONG(fpu->x21.x[1]);
756 fpu->x21.x[2] = SWAP_LONG(fpu->x21.x[2]);
757 fpu->x21.x[3] = SWAP_LONG(fpu->x21.x[3]);
758 fpu->x22.x[0] = SWAP_LONG(fpu->x22.x[0]);
759 fpu->x22.x[1] = SWAP_LONG(fpu->x22.x[1]);
760 fpu->x22.x[2] = SWAP_LONG(fpu->x22.x[2]);
761 fpu->x22.x[3] = SWAP_LONG(fpu->x22.x[3]);
762 fpu->x23.x[0] = SWAP_LONG(fpu->x23.x[0]);
763 fpu->x23.x[1] = SWAP_LONG(fpu->x23.x[1]);
764 fpu->x23.x[2] = SWAP_LONG(fpu->x23.x[2]);
765 fpu->x23.x[3] = SWAP_LONG(fpu->x23.x[3]);
766 fpu->x24.x[0] = SWAP_LONG(fpu->x24.x[0]);
767 fpu->x24.x[1] = SWAP_LONG(fpu->x24.x[1]);
768 fpu->x24.x[2] = SWAP_LONG(fpu->x24.x[2]);
769 fpu->x24.x[3] = SWAP_LONG(fpu->x24.x[3]);
770 fpu->x25.x[0] = SWAP_LONG(fpu->x25.x[0]);
771 fpu->x25.x[1] = SWAP_LONG(fpu->x25.x[1]);
772 fpu->x25.x[2] = SWAP_LONG(fpu->x25.x[2]);
773 fpu->x25.x[3] = SWAP_LONG(fpu->x25.x[3]);
774 fpu->x26.x[0] = SWAP_LONG(fpu->x26.x[0]);
775 fpu->x26.x[1] = SWAP_LONG(fpu->x26.x[1]);
776 fpu->x26.x[2] = SWAP_LONG(fpu->x26.x[2]);
777 fpu->x26.x[3] = SWAP_LONG(fpu->x26.x[3]);
778 fpu->x27.x[0] = SWAP_LONG(fpu->x27.x[0]);
779 fpu->x27.x[1] = SWAP_LONG(fpu->x27.x[1]);
780 fpu->x27.x[2] = SWAP_LONG(fpu->x27.x[2]);
781 fpu->x27.x[3] = SWAP_LONG(fpu->x27.x[3]);
782 fpu->x28.x[0] = SWAP_LONG(fpu->x28.x[0]);
783 fpu->x28.x[1] = SWAP_LONG(fpu->x28.x[1]);
784 fpu->x28.x[2] = SWAP_LONG(fpu->x28.x[2]);
785 fpu->x28.x[3] = SWAP_LONG(fpu->x28.x[3]);
786 fpu->x29.x[0] = SWAP_LONG(fpu->x29.x[0]);
787 fpu->x29.x[1] = SWAP_LONG(fpu->x29.x[1]);
788 fpu->x29.x[2] = SWAP_LONG(fpu->x29.x[2]);
789 fpu->x29.x[3] = SWAP_LONG(fpu->x29.x[3]);
790 fpu->x30.x[0] = SWAP_LONG(fpu->x30.x[0]);
791 fpu->x30.x[1] = SWAP_LONG(fpu->x30.x[1]);
792 fpu->x30.x[2] = SWAP_LONG(fpu->x30.x[2]);
793 fpu->x30.x[3] = SWAP_LONG(fpu->x30.x[3]);
794 fpu->x31.x[0] = SWAP_LONG(fpu->x31.x[0]);
795 fpu->x31.x[1] = SWAP_LONG(fpu->x31.x[1]);
796 fpu->x31.x[2] = SWAP_LONG(fpu->x31.x[2]);
797 fpu->x31.x[3] = SWAP_LONG(fpu->x31.x[3]);
798
799 if(target_byte_sex == host_byte_sex){
800 memcpy(&ssr, &(fpu->fpsr), sizeof(struct swapped_m88k_fpsr));
801 ssr.u.word = SWAP_LONG(ssr.u.word);
802 fpu->fpsr.afinx = ssr.u.fields.afinx;
803 fpu->fpsr.afovf = ssr.u.fields.afovf;
804 fpu->fpsr.afunf = ssr.u.fields.afunf;
805 fpu->fpsr.afdvz = ssr.u.fields.afdvz;
806 fpu->fpsr.afinv = ssr.u.fields.afinv;
807 fpu->fpsr.xmod = ssr.u.fields.xmod;
808
809 memcpy(&scr, &(fpu->fpcr), sizeof(struct swapped_m88k_fpcr));
810 scr.u.word = SWAP_LONG(scr.u.word);
811 fpu->fpcr.efinx = scr.u.fields.efinx;
812 fpu->fpcr.efovf = scr.u.fields.efovf;
813 fpu->fpcr.efunf = scr.u.fields.efunf;
814 fpu->fpcr.efdvz = scr.u.fields.efdvz;
815 fpu->fpcr.efinv = scr.u.fields.efinv;
816 fpu->fpcr.rm = scr.u.fields.rm;
817 }
818 else{
819 ssr.u.fields.afinx = fpu->fpsr.afinx;
820 ssr.u.fields.afovf = fpu->fpsr.afovf;
821 ssr.u.fields.afunf = fpu->fpsr.afunf;
822 ssr.u.fields.afdvz = fpu->fpsr.afdvz;
823 ssr.u.fields.afinv = fpu->fpsr.afinv;
824 ssr.u.fields.xmod = fpu->fpsr.xmod;
825 ssr.u.word = SWAP_LONG(ssr.u.word);
826 memcpy(&(fpu->fpsr), &ssr, sizeof(struct swapped_m88k_fpsr));
827
828 scr.u.fields.efinx = fpu->fpcr.efinx;
829 scr.u.fields.efovf = fpu->fpcr.efovf;
830 scr.u.fields.efunf = fpu->fpcr.efunf;
831 scr.u.fields.efdvz = fpu->fpcr.efdvz;
832 scr.u.fields.efinv = fpu->fpcr.efinv;
833 scr.u.fields.rm = fpu->fpcr.rm;
834 scr.u.word = SWAP_LONG(scr.u.word);
835 memcpy(&(fpu->fpcr), &scr, sizeof(struct swapped_m88k_fpcr));
836 }
837}
838
839__private_extern__
840void
841swap_m88k_thread_state_user_t(
842m88k_thread_state_user_t *user,
843enum byte_sex target_byte_sex)
844{
845#ifdef __MWERKS__
846 enum byte_sex dummy;
847 dummy = target_byte_sex;
848#endif
849 user->user = SWAP_LONG(user->user);
850}
851
852__private_extern__
853void
854swap_m88110_thread_state_impl_t(
855m88110_thread_state_impl_t *spu,
856enum byte_sex target_byte_sex)
857{
858 unsigned long i;
859 enum byte_sex host_byte_sex;
860
861 struct swapped_m88110_bp_ctrl {
862 union {
863 struct {
864 unsigned v:BIT_WIDTH(0);
865 m88110_match_t addr_match:BITS_WIDTH(12,1);
866 unsigned :BITS_WIDTH(26,13);
867 unsigned rwm:BIT_WIDTH(27);
868 unsigned rw:BIT_WIDTH(28);
869 unsigned :BITS_WIDTH(31,29);
870 } fields;
871 unsigned long word;
872 } u;
873 } sbpc;
874
875 struct swap_m88110_psr {
876 union {
877 struct {
878 unsigned :BITS_WIDTH(1,0);
879 unsigned mxm_dis:BIT_WIDTH(2);
880 unsigned sfu1dis:BIT_WIDTH(3);
881 unsigned :BITS_WIDTH(22,4);
882 unsigned trace:BIT_WIDTH(23);
883 unsigned :BIT_WIDTH(24);
884 unsigned sm:BIT_WIDTH(25);
885 unsigned sgn_imd:BIT_WIDTH(26);
886 unsigned :BIT_WIDTH(27);
887 unsigned c:BIT_WIDTH(28);
888 unsigned se:BIT_WIDTH(29);
889 unsigned le:BIT_WIDTH(30);
890 unsigned supr:BIT_WIDTH(31);
891 } fields;
892 unsigned long word;
893 } u;
894 } spsr;
895
896 struct swapped_m88110_fp_trap_status {
897 union {
898 struct {
899 unsigned efinx:BIT_WIDTH(0);
900 unsigned efovf:BIT_WIDTH(1);
901 unsigned efunf:BIT_WIDTH(2);
902 unsigned efdvz:BIT_WIDTH(3);
903 unsigned efinv:BIT_WIDTH(4);
904 unsigned priv:BIT_WIDTH(5);
905 unsigned unimp:BIT_WIDTH(6);
906 unsigned int:BIT_WIDTH(7);
907 unsigned sfu1_disabled:BIT_WIDTH(8);
908 unsigned :BITS_WIDTH(13,9);
909 m88110_iresult_size_t iresult_size:BITS_WIDTH(15,14);
910 unsigned :BITS_WIDTH(31,16);
911 } fields;
912 unsigned long word;
913 } u;
914 } sfps;
915
916 host_byte_sex = get_host_byte_sex();
917
918 if(target_byte_sex == host_byte_sex){
919 for(i = 0; i < M88110_N_DATA_BP; i++){
920 spu->data_bp[i].addr = SWAP_LONG(spu->data_bp[i].addr);
921 memcpy(&sbpc, &(spu->data_bp[i].ctrl),
922 sizeof(struct swapped_m88110_bp_ctrl));
923 sbpc.u.word = SWAP_LONG(sbpc.u.word);
924 spu->data_bp[i].ctrl.v = sbpc.u.fields.v;
925 spu->data_bp[i].ctrl.addr_match = sbpc.u.fields.addr_match;
926 spu->data_bp[i].ctrl.rwm = sbpc.u.fields.rwm;
927 spu->data_bp[i].ctrl.rw = sbpc.u.fields.rw;
928 }
929
930 memcpy(&spsr, &(spu->psr), sizeof(struct swap_m88110_psr));
931 spsr.u.word = SWAP_LONG(spsr.u.word);
932 spu->psr.mxm_dis = spsr.u.fields.mxm_dis;
933 spu->psr.sfu1dis = spsr.u.fields.sfu1dis;
934 spu->psr.trace = spsr.u.fields.trace;
935 spu->psr.sm = spsr.u.fields.sm;
936 spu->psr.sgn_imd = spsr.u.fields.sgn_imd;
937 spu->psr.c = spsr.u.fields.c;
938 spu->psr.se = spsr.u.fields.se;
939 spu->psr.le = spsr.u.fields.le;
940 spu->psr.supr = spsr.u.fields.supr;
941
942 memcpy(&sfps, &(spu->fp_trap_status),
943 sizeof(struct swapped_m88110_fp_trap_status));
944 sfps.u.word = SWAP_LONG(sfps.u.word);
945 spu->fp_trap_status.efinx = sfps.u.fields.efinx;
946 spu->fp_trap_status.efovf = sfps.u.fields.efovf;
947 spu->fp_trap_status.efunf = sfps.u.fields.efunf;
948 spu->fp_trap_status.efdvz = sfps.u.fields.efdvz;
949 spu->fp_trap_status.efinv = sfps.u.fields.efinv;
950 spu->fp_trap_status.priv = sfps.u.fields.priv;
951 spu->fp_trap_status.unimp = sfps.u.fields.unimp;
952 spu->fp_trap_status.sfu1_disabled = sfps.u.fields.sfu1_disabled;
953 spu->fp_trap_status.iresult_size = sfps.u.fields.iresult_size;
954 }
955 else{
956 for(i = 0; i < M88110_N_DATA_BP; i++){
957 spu->data_bp[i].addr = SWAP_LONG(spu->data_bp[i].addr);
958 sbpc.u.fields.v = spu->data_bp[i].ctrl.v;
959 sbpc.u.fields.addr_match = spu->data_bp[i].ctrl.addr_match;
960 sbpc.u.fields.rwm = spu->data_bp[i].ctrl.rwm;
961 sbpc.u.fields.rw = spu->data_bp[i].ctrl.rw;
962 sbpc.u.word = SWAP_LONG(sbpc.u.word);
963 memcpy(&(spu->data_bp[i].ctrl), &sbpc,
964 sizeof(struct swapped_m88110_bp_ctrl));
965 }
966
967 spsr.u.fields.mxm_dis = spu->psr.mxm_dis;
968 spsr.u.fields.sfu1dis = spu->psr.sfu1dis;
969 spsr.u.fields.trace = spu->psr.trace;
970 spsr.u.fields.sm = spu->psr.sm;
971 spsr.u.fields.sgn_imd = spu->psr.sgn_imd;
972 spsr.u.fields.c = spu->psr.c;
973 spsr.u.fields.se = spu->psr.se;
974 spsr.u.fields.le = spu->psr.le;
975 spsr.u.fields.supr = spu->psr.supr;
976 spsr.u.word = SWAP_LONG(spsr.u.word);
977 memcpy(&(spu->psr), &spsr, sizeof(struct swap_m88110_psr));
978
979 sfps.u.fields.efinx = spu->fp_trap_status.efinx;
980 sfps.u.fields.efovf = spu->fp_trap_status.efovf;
981 sfps.u.fields.efunf = spu->fp_trap_status.efunf;
982 sfps.u.fields.efdvz = spu->fp_trap_status.efdvz;
983 sfps.u.fields.efinv = spu->fp_trap_status.efinv;
984 sfps.u.fields.priv = spu->fp_trap_status.priv;
985 sfps.u.fields.unimp = spu->fp_trap_status.unimp;
986 sfps.u.fields.sfu1_disabled = spu->fp_trap_status.sfu1_disabled;
987 sfps.u.fields.iresult_size = spu->fp_trap_status.iresult_size;
988 sfps.u.word = SWAP_LONG(sfps.u.word);
989 memcpy(&(spu->fp_trap_status), &sfps,
990 sizeof(struct swapped_m88110_fp_trap_status));
991 }
992 spu->intermediate_result.x[0] =
993 SWAP_LONG(spu->intermediate_result.x[0]);
994 spu->intermediate_result.x[1] =
995 SWAP_LONG(spu->intermediate_result.x[1]);
996 spu->intermediate_result.x[2] =
997 SWAP_LONG(spu->intermediate_result.x[2]);
998 spu->intermediate_result.x[3] =
999 SWAP_LONG(spu->intermediate_result.x[3]);
1000}
1001
1002__private_extern__
1003void
1004swap_i860_thread_state_regs(
1005struct i860_thread_state_regs *cpu,
1006enum byte_sex target_byte_sex)
1007{
1008 unsigned long i;
1009#ifdef __MWERKS__
1010 enum byte_sex dummy;
1011 dummy = target_byte_sex;
1012#endif
1013
1014 for(i = 0; i < 31; i++)
1015 cpu->ireg[i] = SWAP_LONG(cpu->ireg[i]);
1016 for(i = 0; i < 30; i++)
1017 cpu->freg[i] = SWAP_LONG(cpu->freg[i]);
1018 cpu->psr = SWAP_LONG(cpu->psr);
1019 cpu->epsr = SWAP_LONG(cpu->epsr);
1020 cpu->db = SWAP_LONG(cpu->db);
1021 cpu->pc = SWAP_LONG(cpu->pc);
1022 cpu->_padding_ = SWAP_LONG(cpu->_padding_);
1023 cpu->Mres3 = SWAP_DOUBLE(cpu->Mres3);
1024 cpu->Ares3 = SWAP_DOUBLE(cpu->Ares3);
1025 cpu->Mres2 = SWAP_DOUBLE(cpu->Mres2);
1026 cpu->Ares2 = SWAP_DOUBLE(cpu->Ares2);
1027 cpu->Mres1 = SWAP_DOUBLE(cpu->Mres1);
1028 cpu->Ares1 = SWAP_DOUBLE(cpu->Ares1);
1029 cpu->Ires1 = SWAP_DOUBLE(cpu->Ires1);
1030 cpu->Lres3m = SWAP_DOUBLE(cpu->Lres3m);
1031 cpu->Lres2m = SWAP_DOUBLE(cpu->Lres2m);
1032 cpu->Lres1m = SWAP_DOUBLE(cpu->Lres1m);
1033 cpu->KR = SWAP_DOUBLE(cpu->KR);
1034 cpu->KI = SWAP_DOUBLE(cpu->KI);
1035 cpu->T = SWAP_DOUBLE(cpu->T);
1036 cpu->Fsr3 = SWAP_LONG(cpu->Fsr3);
1037 cpu->Fsr2 = SWAP_LONG(cpu->Fsr2);
1038 cpu->Fsr1 = SWAP_LONG(cpu->Fsr1);
1039 cpu->Mergelo32 = SWAP_LONG(cpu->Mergelo32);
1040 cpu->Mergehi32 = SWAP_LONG(cpu->Mergehi32);
1041}
1042
1043__private_extern__
1044void
1045swap_i386_thread_state(
1046i386_thread_state_t *cpu,
1047enum byte_sex target_byte_sex)
1048{
1049#ifdef __MWERKS__
1050 enum byte_sex dummy;
1051 dummy = target_byte_sex;
1052#endif
1053 cpu->eax = SWAP_LONG(cpu->eax);
1054 cpu->ebx = SWAP_LONG(cpu->ebx);
1055 cpu->ecx = SWAP_LONG(cpu->ecx);
1056 cpu->edx = SWAP_LONG(cpu->edx);
1057 cpu->edi = SWAP_LONG(cpu->edi);
1058 cpu->esi = SWAP_LONG(cpu->esi);
1059 cpu->ebp = SWAP_LONG(cpu->ebp);
1060 cpu->esp = SWAP_LONG(cpu->esp);
1061 cpu->ss = SWAP_LONG(cpu->ss);
1062 cpu->eflags = SWAP_LONG(cpu->eflags);
1063 cpu->eip = SWAP_LONG(cpu->eip);
1064 cpu->cs = SWAP_LONG(cpu->cs);
1065 cpu->ds = SWAP_LONG(cpu->ds);
1066 cpu->es = SWAP_LONG(cpu->es);
1067 cpu->fs = SWAP_LONG(cpu->fs);
1068 cpu->gs = SWAP_LONG(cpu->gs);
1069}
1070
1071__private_extern__
1072void
1073swap_i386_thread_fpstate(
1074i386_thread_fpstate_t *fpu,
1075enum byte_sex target_byte_sex)
1076{
1077 struct swapped_fp_control {
1078 union {
1079 struct {
1080 unsigned short
1081 :3,
1082 /*inf*/ :1,
1083 rc :2,
1084 pc :2,
1085 :2,
1086 precis :1,
1087 undfl :1,
1088 ovrfl :1,
1089 zdiv :1,
1090 denorm :1,
1091 invalid :1;
1092 } fields;
1093 unsigned short half;
1094 } u;
1095 } sfpc;
1096
1097 struct swapped_fp_status {
1098 union {
1099 struct {
1100 unsigned short
1101 busy :1,
1102 c3 :1,
1103 tos :3,
1104 c2 :1,
1105 c1 :1,
1106 c0 :1,
1107 errsumm :1,
1108 stkflt :1,
1109 precis :1,
1110 undfl :1,
1111 ovrfl :1,
1112 zdiv :1,
1113 denorm :1,
1114 invalid :1;
1115 } fields;
1116 unsigned short half;
1117 } u;
1118 } sfps;
1119
1120 struct swapped_fp_tag {
1121 union {
1122 struct {
1123 unsigned short
1124 tag7 :2,
1125 tag6 :2,
1126 tag5 :2,
1127 tag4 :2,
1128 tag3 :2,
1129 tag2 :2,
1130 tag1 :2,
1131 tag0 :2;
1132 } fields;
1133 unsigned short half;
1134 } u;
1135 } sfpt;
1136
1137 struct swapped_fp_data_reg {
1138 unsigned short mant;
1139 unsigned short mant1 :16,
1140 mant2 :16,
1141 mant3 :16;
1142 union {
1143 struct {
1144 unsigned short sign :1,
1145 exp :15;
1146 } fields;
1147 unsigned short half;
1148 } u;
1149 } sfpd;
1150
1151 struct swapped_sel {
1152 union {
1153 struct {
1154 unsigned short
1155 index :13,
1156 ti :1,
1157 rpl :2;
1158 } fields;
1159 unsigned short half;
1160 } u;
1161 } ss;
1162
1163 enum byte_sex host_byte_sex;
1164 unsigned long i;
1165
1166 host_byte_sex = get_host_byte_sex();
1167
1168 fpu->environ.ip = SWAP_LONG(fpu->environ.ip);
1169 fpu->environ.opcode = SWAP_SHORT(fpu->environ.opcode);
1170 fpu->environ.dp = SWAP_LONG(fpu->environ.dp);
1171
1172 if(target_byte_sex == host_byte_sex){
1173 memcpy(&sfpc, &(fpu->environ.control),
1174 sizeof(struct swapped_fp_control));
1175 sfpc.u.half = SWAP_SHORT(sfpc.u.half);
1176 fpu->environ.control.rc = sfpc.u.fields.rc;
1177 fpu->environ.control.pc = sfpc.u.fields.pc;
1178 fpu->environ.control.precis = sfpc.u.fields.precis;
1179 fpu->environ.control.undfl = sfpc.u.fields.undfl;
1180 fpu->environ.control.ovrfl = sfpc.u.fields.ovrfl;
1181 fpu->environ.control.zdiv = sfpc.u.fields.zdiv;
1182 fpu->environ.control.denorm = sfpc.u.fields.denorm;
1183 fpu->environ.control.invalid = sfpc.u.fields.invalid;
1184
1185 memcpy(&sfps, &(fpu->environ.status),
1186 sizeof(struct swapped_fp_status));
1187 sfps.u.half = SWAP_SHORT(sfps.u.half);
1188 fpu->environ.status.busy = sfps.u.fields.busy;
1189 fpu->environ.status.c3 = sfps.u.fields.c3;
1190 fpu->environ.status.tos = sfps.u.fields.tos;
1191 fpu->environ.status.c2 = sfps.u.fields.c2;
1192 fpu->environ.status.c1 = sfps.u.fields.c1;
1193 fpu->environ.status.c0 = sfps.u.fields.c0;
1194 fpu->environ.status.errsumm = sfps.u.fields.errsumm;
1195 fpu->environ.status.stkflt = sfps.u.fields.stkflt;
1196 fpu->environ.status.precis = sfps.u.fields.precis;
1197 fpu->environ.status.undfl = sfps.u.fields.undfl;
1198 fpu->environ.status.ovrfl = sfps.u.fields.ovrfl;
1199 fpu->environ.status.zdiv = sfps.u.fields.zdiv;
1200 fpu->environ.status.denorm = sfps.u.fields.denorm;
1201 fpu->environ.status.invalid = sfps.u.fields.invalid;
1202
1203 memcpy(&sfpt, &(fpu->environ.tag),
1204 sizeof(struct swapped_fp_tag));
1205 sfpt.u.half = SWAP_SHORT(sfpt.u.half);
1206 fpu->environ.tag.tag7 = sfpt.u.fields.tag7;
1207 fpu->environ.tag.tag6 = sfpt.u.fields.tag6;
1208 fpu->environ.tag.tag5 = sfpt.u.fields.tag5;
1209 fpu->environ.tag.tag4 = sfpt.u.fields.tag4;
1210 fpu->environ.tag.tag3 = sfpt.u.fields.tag3;
1211 fpu->environ.tag.tag2 = sfpt.u.fields.tag2;
1212 fpu->environ.tag.tag1 = sfpt.u.fields.tag1;
1213 fpu->environ.tag.tag0 = sfpt.u.fields.tag0;
1214
1215 memcpy(&ss, &(fpu->environ.cs),
1216 sizeof(struct swapped_sel));
1217 ss.u.half = SWAP_SHORT(ss.u.half);
1218 fpu->environ.cs.index = ss.u.fields.index;
1219 fpu->environ.cs.ti = ss.u.fields.ti;
1220 fpu->environ.cs.rpl = ss.u.fields.rpl;
1221
1222 memcpy(&ss, &(fpu->environ.ds),
1223 sizeof(struct swapped_sel));
1224 ss.u.half = SWAP_SHORT(ss.u.half);
1225 fpu->environ.ds.index = ss.u.fields.index;
1226 fpu->environ.ds.ti = ss.u.fields.ti;
1227 fpu->environ.ds.rpl = ss.u.fields.rpl;
1228
1229 for(i = 0; i < 8; i++){
1230 memcpy(&sfpd, &(fpu->stack.ST[i]),
1231 sizeof(struct swapped_fp_data_reg));
1232 fpu->stack.ST[i].mant = SWAP_SHORT(sfpd.mant);
1233 fpu->stack.ST[i].mant1 = SWAP_SHORT(sfpd.mant1);
1234 fpu->stack.ST[i].mant2 = SWAP_SHORT(sfpd.mant2);
1235 fpu->stack.ST[i].mant3 = SWAP_SHORT(sfpd.mant3);
1236 sfpd.u.half = SWAP_SHORT(sfpd.u.half);
1237 fpu->stack.ST[i].exp = sfpd.u.fields.exp;
1238 fpu->stack.ST[i].sign = sfpd.u.fields.sign;
1239 }
1240 }
1241 else{
1242 sfpc.u.fields.rc = fpu->environ.control.rc;
1243 sfpc.u.fields.pc = fpu->environ.control.pc;
1244 sfpc.u.fields.precis = fpu->environ.control.precis;
1245 sfpc.u.fields.undfl = fpu->environ.control.undfl;
1246 sfpc.u.fields.ovrfl = fpu->environ.control.ovrfl;
1247 sfpc.u.fields.zdiv = fpu->environ.control.zdiv;
1248 sfpc.u.fields.denorm = fpu->environ.control.denorm;
1249 sfpc.u.fields.invalid = fpu->environ.control.invalid;
1250 sfpc.u.half = SWAP_SHORT(sfpc.u.half);
1251 memcpy(&(fpu->environ.control), &sfpc,
1252 sizeof(struct swapped_fp_control));
1253
1254 sfps.u.fields.busy = fpu->environ.status.busy;
1255 sfps.u.fields.c3 = fpu->environ.status.c3;
1256 sfps.u.fields.tos = fpu->environ.status.tos;
1257 sfps.u.fields.c2 = fpu->environ.status.c2;
1258 sfps.u.fields.c1 = fpu->environ.status.c1;
1259 sfps.u.fields.c0 = fpu->environ.status.c0;
1260 sfps.u.fields.errsumm = fpu->environ.status.errsumm;
1261 sfps.u.fields.stkflt = fpu->environ.status.stkflt;
1262 sfps.u.fields.precis = fpu->environ.status.precis;
1263 sfps.u.fields.undfl = fpu->environ.status.undfl;
1264 sfps.u.fields.ovrfl = fpu->environ.status.ovrfl;
1265 sfps.u.fields.zdiv = fpu->environ.status.zdiv;
1266 sfps.u.fields.denorm = fpu->environ.status.denorm;
1267 sfps.u.fields.invalid = fpu->environ.status.invalid;
1268 sfps.u.half = SWAP_SHORT(sfps.u.half);
1269 memcpy(&(fpu->environ.status), &sfps,
1270 sizeof(struct swapped_fp_status));
1271
1272 sfpt.u.fields.tag7 = fpu->environ.tag.tag7;
1273 sfpt.u.fields.tag6 = fpu->environ.tag.tag6;
1274 sfpt.u.fields.tag5 = fpu->environ.tag.tag5;
1275 sfpt.u.fields.tag4 = fpu->environ.tag.tag4;
1276 sfpt.u.fields.tag3 = fpu->environ.tag.tag3;
1277 sfpt.u.fields.tag2 = fpu->environ.tag.tag2;
1278 sfpt.u.fields.tag1 = fpu->environ.tag.tag1;
1279 sfpt.u.fields.tag0 = fpu->environ.tag.tag0;
1280 sfpt.u.half = SWAP_SHORT(sfpt.u.half);
1281 memcpy(&(fpu->environ.tag), &sfpt,
1282 sizeof(struct swapped_fp_tag));
1283
1284 ss.u.fields.index = fpu->environ.cs.index;
1285 ss.u.fields.ti = fpu->environ.cs.ti;
1286 ss.u.fields.rpl = fpu->environ.cs.rpl;
1287 ss.u.half = SWAP_SHORT(ss.u.half);
1288 memcpy(&(fpu->environ.cs), &ss,
1289 sizeof(struct swapped_sel));
1290
1291 ss.u.fields.index = fpu->environ.ds.index;
1292 ss.u.fields.ti = fpu->environ.ds.ti;
1293 ss.u.fields.rpl = fpu->environ.ds.rpl;
1294 ss.u.half = SWAP_SHORT(ss.u.half);
1295 memcpy(&(fpu->environ.cs), &ss,
1296 sizeof(struct swapped_sel));
1297
1298 for(i = 0; i < 8; i++){
1299 sfpd.mant = SWAP_SHORT(fpu->stack.ST[i].mant);
1300 sfpd.mant1 = SWAP_SHORT(fpu->stack.ST[i].mant1);
1301 sfpd.mant2 = SWAP_SHORT(fpu->stack.ST[i].mant2);
1302 sfpd.mant3 = SWAP_SHORT(fpu->stack.ST[i].mant3);
1303 sfpd.u.fields.exp = fpu->stack.ST[i].exp;
1304 sfpd.u.fields.sign = fpu->stack.ST[i].sign;
1305 sfpd.u.half = SWAP_SHORT(sfpd.u.half);
1306 memcpy(&(fpu->stack.ST[i]), &sfpd,
1307 sizeof(struct swapped_fp_data_reg));
1308 }
1309 }
1310}
1311
1312__private_extern__
1313void
1314swap_i386_thread_exceptstate(
1315i386_thread_exceptstate_t *exc,
1316enum byte_sex target_byte_sex)
1317{
1318 struct swapped_err_code {
1319 union {
1320 struct err_code_normal {
1321 unsigned int :16,
1322 index :13,
1323 tbl :2,
1324 ext :1;
1325 } normal;
1326 struct err_code_pgfault {
1327 unsigned int :29,
1328 user :1,
1329 wrtflt :1,
1330 prot :1;
1331 } pgfault;
1332 unsigned long word;
1333 } u;
1334 } sec;
1335 unsigned long word;
1336 enum byte_sex host_byte_sex;
1337
1338 host_byte_sex = get_host_byte_sex();
1339
1340 exc->trapno = SWAP_LONG(exc->trapno);
1341 if(exc->trapno == 14){
1342 if(target_byte_sex == host_byte_sex){
1343 memcpy(&sec, &(exc->err), sizeof(struct swapped_err_code));
1344 sec.u.word = SWAP_LONG(sec.u.word);
1345 exc->err.pgfault.user = sec.u.pgfault.user;
1346 exc->err.pgfault.wrtflt = sec.u.pgfault.wrtflt;
1347 exc->err.pgfault.prot = sec.u.pgfault.prot;
1348 }
1349 else{
1350 sec.u.pgfault.prot = exc->err.pgfault.prot;
1351 sec.u.pgfault.wrtflt = exc->err.pgfault.wrtflt;
1352 sec.u.pgfault.user = exc->err.pgfault.user;
1353 sec.u.word = SWAP_LONG(sec.u.word);
1354 memcpy(&(exc->err), &sec, sizeof(struct swapped_err_code));
1355 }
1356 }
1357 else{
1358 if(target_byte_sex == host_byte_sex){
1359 memcpy(&sec, &(exc->err), sizeof(struct swapped_err_code));
1360 sec.u.word = SWAP_LONG(sec.u.word);
1361 word = sec.u.normal.index;
1362 exc->err.normal.index = SWAP_LONG(word);
1363 exc->err.normal.tbl = sec.u.normal.tbl;
1364 exc->err.normal.ext = sec.u.normal.ext;
1365 }
1366 else{
1367 sec.u.normal.ext = exc->err.normal.ext;
1368 sec.u.normal.tbl = exc->err.normal.tbl;
1369 word = exc->err.normal.index;
1370 sec.u.normal.index = SWAP_LONG(word);
1371 sec.u.word = SWAP_LONG(sec.u.word);
1372 memcpy(&(exc->err), &sec, sizeof(struct swapped_err_code));
1373 }
1374 }
1375}
1376
1377__private_extern__
1378void
1379swap_i386_thread_cthreadstate(
1380i386_thread_cthreadstate_t *user,
1381enum byte_sex target_byte_sex)
1382{
1383#ifdef __MWERKS__
1384 enum byte_sex dummy;
1385 dummy = target_byte_sex;
1386#endif
1387 user->self = SWAP_LONG(user->self);
1388}
1389
1390__private_extern__
1391void
1392swap_hppa_integer_thread_state(
1393struct hp_pa_integer_thread_state *regs,
1394enum byte_sex target_byte_sex)
1395{
1396#ifdef __MWERKS__
1397 enum byte_sex dummy;
1398 dummy = target_byte_sex;
1399#endif
1400 regs->ts_gr1 = SWAP_LONG(regs->ts_gr1);
1401 regs->ts_gr2 = SWAP_LONG(regs->ts_gr2);
1402 regs->ts_gr3 = SWAP_LONG(regs->ts_gr3);
1403 regs->ts_gr4 = SWAP_LONG(regs->ts_gr4);
1404 regs->ts_gr5 = SWAP_LONG(regs->ts_gr5);
1405 regs->ts_gr6 = SWAP_LONG(regs->ts_gr6);
1406 regs->ts_gr7 = SWAP_LONG(regs->ts_gr7);
1407 regs->ts_gr8 = SWAP_LONG(regs->ts_gr8);
1408 regs->ts_gr9 = SWAP_LONG(regs->ts_gr9);
1409 regs->ts_gr10 = SWAP_LONG(regs->ts_gr10);
1410 regs->ts_gr11 = SWAP_LONG(regs->ts_gr11);
1411 regs->ts_gr12 = SWAP_LONG(regs->ts_gr12);
1412 regs->ts_gr13 = SWAP_LONG(regs->ts_gr13);
1413 regs->ts_gr14 = SWAP_LONG(regs->ts_gr14);
1414 regs->ts_gr15 = SWAP_LONG(regs->ts_gr15);
1415 regs->ts_gr16 = SWAP_LONG(regs->ts_gr16);
1416 regs->ts_gr17 = SWAP_LONG(regs->ts_gr17);
1417 regs->ts_gr18 = SWAP_LONG(regs->ts_gr18);
1418 regs->ts_gr19 = SWAP_LONG(regs->ts_gr19);
1419 regs->ts_gr20 = SWAP_LONG(regs->ts_gr20);
1420 regs->ts_gr21 = SWAP_LONG(regs->ts_gr21);
1421 regs->ts_gr22 = SWAP_LONG(regs->ts_gr22);
1422 regs->ts_gr23 = SWAP_LONG(regs->ts_gr23);
1423 regs->ts_gr24 = SWAP_LONG(regs->ts_gr24);
1424 regs->ts_gr25 = SWAP_LONG(regs->ts_gr25);
1425 regs->ts_gr26 = SWAP_LONG(regs->ts_gr26);
1426 regs->ts_gr27 = SWAP_LONG(regs->ts_gr27);
1427 regs->ts_gr28 = SWAP_LONG(regs->ts_gr28);
1428 regs->ts_gr29 = SWAP_LONG(regs->ts_gr29);
1429 regs->ts_gr30 = SWAP_LONG(regs->ts_gr30);
1430 regs->ts_gr31 = SWAP_LONG(regs->ts_gr31);
1431 regs->ts_sr0 = SWAP_LONG(regs->ts_sr0);
1432 regs->ts_sr1 = SWAP_LONG(regs->ts_sr1);
1433 regs->ts_sr2 = SWAP_LONG(regs->ts_sr2);
1434 regs->ts_sr3 = SWAP_LONG(regs->ts_sr3);
1435 regs->ts_sar = SWAP_LONG(regs->ts_sar);
1436}
1437
1438__private_extern__
1439void swap_hppa_frame_thread_state(
1440struct hp_pa_frame_thread_state *frame,
1441enum byte_sex target_byte_sex)
1442{
1443#ifdef __MWERKS__
1444 enum byte_sex dummy;
1445 dummy = target_byte_sex;
1446#endif
1447 frame->ts_pcsq_front = SWAP_LONG(frame->ts_pcsq_front);
1448 frame->ts_pcsq_back = SWAP_LONG(frame->ts_pcsq_back);
1449 frame->ts_pcoq_front = SWAP_LONG(frame->ts_pcoq_front);
1450 frame->ts_pcoq_back = SWAP_LONG(frame->ts_pcoq_back);
1451 frame->ts_psw = SWAP_LONG(frame->ts_psw);
1452 frame->ts_unaligned_faults = SWAP_LONG(frame->ts_unaligned_faults);
1453 frame->ts_fault_address = SWAP_LONG(frame->ts_fault_address);
1454 frame->ts_step_range_start = SWAP_LONG(frame->ts_step_range_start);
1455 frame->ts_step_range_stop = SWAP_LONG(frame->ts_step_range_stop);
1456}
1457
1458__private_extern__
1459void swap_hppa_fp_thread_state(
1460struct hp_pa_fp_thread_state *fp,
1461enum byte_sex target_byte_sex)
1462{
1463#ifdef __MWERKS__
1464 enum byte_sex dummy;
1465 dummy = target_byte_sex;
1466#endif
1467 fp->ts_fp0 = SWAP_DOUBLE(fp->ts_fp0);
1468 fp->ts_fp1 = SWAP_DOUBLE(fp->ts_fp1);
1469 fp->ts_fp2 = SWAP_DOUBLE(fp->ts_fp2);
1470 fp->ts_fp3 = SWAP_DOUBLE(fp->ts_fp3);
1471 fp->ts_fp4 = SWAP_DOUBLE(fp->ts_fp4);
1472 fp->ts_fp5 = SWAP_DOUBLE(fp->ts_fp5);
1473 fp->ts_fp6 = SWAP_DOUBLE(fp->ts_fp6);
1474 fp->ts_fp7 = SWAP_DOUBLE(fp->ts_fp7);
1475 fp->ts_fp8 = SWAP_DOUBLE(fp->ts_fp8);
1476 fp->ts_fp9 = SWAP_DOUBLE(fp->ts_fp9);
1477 fp->ts_fp10 = SWAP_DOUBLE(fp->ts_fp10);
1478 fp->ts_fp11 = SWAP_DOUBLE(fp->ts_fp11);
1479 fp->ts_fp12 = SWAP_DOUBLE(fp->ts_fp12);
1480 fp->ts_fp13 = SWAP_DOUBLE(fp->ts_fp13);
1481 fp->ts_fp14 = SWAP_DOUBLE(fp->ts_fp14);
1482 fp->ts_fp15 = SWAP_DOUBLE(fp->ts_fp15);
1483 fp->ts_fp16 = SWAP_DOUBLE(fp->ts_fp16);
1484 fp->ts_fp17 = SWAP_DOUBLE(fp->ts_fp17);
1485 fp->ts_fp18 = SWAP_DOUBLE(fp->ts_fp18);
1486 fp->ts_fp19 = SWAP_DOUBLE(fp->ts_fp19);
1487 fp->ts_fp20 = SWAP_DOUBLE(fp->ts_fp20);
1488 fp->ts_fp21 = SWAP_DOUBLE(fp->ts_fp21);
1489 fp->ts_fp22 = SWAP_DOUBLE(fp->ts_fp22);
1490 fp->ts_fp23 = SWAP_DOUBLE(fp->ts_fp23);
1491 fp->ts_fp24 = SWAP_DOUBLE(fp->ts_fp24);
1492 fp->ts_fp25 = SWAP_DOUBLE(fp->ts_fp25);
1493 fp->ts_fp26 = SWAP_DOUBLE(fp->ts_fp26);
1494 fp->ts_fp27 = SWAP_DOUBLE(fp->ts_fp27);
1495 fp->ts_fp28 = SWAP_DOUBLE(fp->ts_fp28);
1496 fp->ts_fp29 = SWAP_DOUBLE(fp->ts_fp29);
1497 fp->ts_fp30 = SWAP_DOUBLE(fp->ts_fp30);
1498 fp->ts_fp31 = SWAP_DOUBLE(fp->ts_fp31);
1499}
1500
1501__private_extern__
1502void
1503swap_sparc_thread_state_regs(
1504struct sparc_thread_state_regs *cpu,
1505enum byte_sex target_byte_sex)
1506{
1507 struct swapped_psr {
1508 union {
1509 struct {
1510 unsigned int
1511 cwp:BITS_WIDTH(4,0),
1512 et:BIT_WIDTH(5),
1513 ps:BIT_WIDTH(6),
1514 s:BIT_WIDTH(7),
1515 pil:BITS_WIDTH(11,8),
1516 ef:BIT_WIDTH(12),
1517 ec:BIT_WIDTH(13),
1518 reserved:BITS_WIDTH(19,14),
1519 icc:BITS_WIDTH(23,20),
1520 ver:BITS_WIDTH(27,24),
1521 impl:BITS_WIDTH(31,28);
1522 } fields;
1523 unsigned int word;
1524 } u;
1525 } spsr;
1526 struct p_status *pr_status;
1527 enum byte_sex host_byte_sex;
1528
1529 host_byte_sex = get_host_byte_sex();
1530
1531 cpu->regs.r_pc = SWAP_LONG(cpu->regs.r_pc);
1532 cpu->regs.r_npc = SWAP_LONG(cpu->regs.r_npc);
1533 cpu->regs.r_y = SWAP_LONG(cpu->regs.r_y);
1534 cpu->regs.r_g1 = SWAP_LONG(cpu->regs.r_g1);
1535 cpu->regs.r_g2 = SWAP_LONG(cpu->regs.r_g2);
1536 cpu->regs.r_g3 = SWAP_LONG(cpu->regs.r_g3);
1537 cpu->regs.r_g4 = SWAP_LONG(cpu->regs.r_g4);
1538 cpu->regs.r_g5 = SWAP_LONG(cpu->regs.r_g5);
1539 cpu->regs.r_g6 = SWAP_LONG(cpu->regs.r_g6);
1540 cpu->regs.r_g7 = SWAP_LONG(cpu->regs.r_g7);
1541 cpu->regs.r_o0 = SWAP_LONG(cpu->regs.r_o0);
1542 cpu->regs.r_o1 = SWAP_LONG(cpu->regs.r_o1);
1543 cpu->regs.r_o2 = SWAP_LONG(cpu->regs.r_o2);
1544 cpu->regs.r_o3 = SWAP_LONG(cpu->regs.r_o3);
1545 cpu->regs.r_o4 = SWAP_LONG(cpu->regs.r_o4);
1546 cpu->regs.r_o5 = SWAP_LONG(cpu->regs.r_o5);
1547 cpu->regs.r_o6 = SWAP_LONG(cpu->regs.r_o6);
1548 cpu->regs.r_o7 = SWAP_LONG(cpu->regs.r_o7);
1549
1550 pr_status = (struct p_status *) &(cpu->regs.r_psr);
1551 if(target_byte_sex == host_byte_sex){
1552 memcpy(&spsr, &(cpu->regs.r_psr), sizeof(struct swapped_psr));
1553 spsr.u.word = SWAP_LONG(spsr.u.word);
1554 pr_status->PSRREG.psr_bits.cwp = spsr.u.fields.cwp;
1555 pr_status->PSRREG.psr_bits.ps = spsr.u.fields.ps;
1556 pr_status->PSRREG.psr_bits.s = spsr.u.fields.s;
1557 pr_status->PSRREG.psr_bits.pil = spsr.u.fields.pil;
1558 pr_status->PSRREG.psr_bits.ef = spsr.u.fields.ef;
1559 pr_status->PSRREG.psr_bits.ec = spsr.u.fields.ec;
1560 pr_status->PSRREG.psr_bits.reserved = spsr.u.fields.reserved;
1561 pr_status->PSRREG.psr_bits.icc = spsr.u.fields.icc;
1562 pr_status->PSRREG.psr_bits.et = spsr.u.fields.ver;
1563 pr_status->PSRREG.psr_bits.impl = spsr.u.fields.impl;
1564 }
1565 else{
1566 spsr.u.fields.cwp = pr_status->PSRREG.psr_bits.cwp;
1567 spsr.u.fields.ps = pr_status->PSRREG.psr_bits.ps;
1568 spsr.u.fields.s = pr_status->PSRREG.psr_bits.s;
1569 spsr.u.fields.pil = pr_status->PSRREG.psr_bits.pil;
1570 spsr.u.fields.ef = pr_status->PSRREG.psr_bits.ef;
1571 spsr.u.fields.ec = pr_status->PSRREG.psr_bits.ec;
1572 spsr.u.fields.reserved = pr_status->PSRREG.psr_bits.reserved;
1573 spsr.u.fields.icc = pr_status->PSRREG.psr_bits.icc;
1574 spsr.u.fields.ver = pr_status->PSRREG.psr_bits.et;
1575 spsr.u.fields.impl = pr_status->PSRREG.psr_bits.impl;
1576 spsr.u.word = SWAP_LONG(spsr.u.word);
1577 memcpy(&(cpu->regs.r_psr), &spsr, sizeof(struct swapped_psr));
1578 }
1579}
1580
1581__private_extern__
1582void
1583swap_sparc_thread_state_fpu(
1584struct sparc_thread_state_fpu *fpu,
1585enum byte_sex target_byte_sex)
1586{
1587 struct swapped_fsr {
1588 union {
1589 struct {
1590 unsigned int
1591 cexc:BITS_WIDTH(4,0),
1592 aexc:BITS_WIDTH(9,5),
1593 fcc:BITS_WIDTH(11,10),
1594 pr:BIT_WIDTH(12),
1595 qne:BIT_WIDTH(13),
1596 ftt:BITS_WIDTH(16,14),
1597 res:BITS_WIDTH(22,17),
1598 tem:BITS_WIDTH(27,23),
1599 rp:BITS_WIDTH(29,28),
1600 rd:BITS_WIDTH(31,30);
1601 } fields;
1602 unsigned int word;
1603 } u;
1604 } sfsr;
1605 unsigned long i;
1606 struct f_status *fpu_status;
1607 enum byte_sex host_byte_sex;
1608
1609 host_byte_sex = get_host_byte_sex();
1610
1611
1612 /* floating point registers */
1613 for(i = 0; i < 16; i++) /* 16 doubles */
1614 fpu->fpu.fpu_fr.Fpu_dregs[i] =
1615 SWAP_DOUBLE(fpu->fpu.fpu_fr.Fpu_dregs[i]);
1616
1617 fpu->fpu.Fpu_q[0].FQu.whole = SWAP_DOUBLE(fpu->fpu.Fpu_q[0].FQu.whole);
1618 fpu->fpu.Fpu_q[1].FQu.whole = SWAP_DOUBLE(fpu->fpu.Fpu_q[1].FQu.whole);
1619 fpu->fpu.Fpu_flags = SWAP_LONG(fpu->fpu.Fpu_flags);
1620 fpu->fpu.Fpu_extra = SWAP_LONG(fpu->fpu.Fpu_extra);
1621 fpu->fpu.Fpu_qcnt = SWAP_LONG(fpu->fpu.Fpu_qcnt);
1622
1623 fpu_status = (struct f_status *) &(fpu->fpu.Fpu_fsr);
1624 if(target_byte_sex == host_byte_sex){
1625 memcpy(&sfsr, &(fpu->fpu.Fpu_fsr), sizeof(unsigned int));
1626 sfsr.u.word = SWAP_LONG(sfsr.u.word);
1627 fpu_status->FPUREG.Fpu_fsr_bits.rd = sfsr.u.fields.rd;
1628 fpu_status->FPUREG.Fpu_fsr_bits.rp = sfsr.u.fields.rp;
1629 fpu_status->FPUREG.Fpu_fsr_bits.tem = sfsr.u.fields.tem;
1630 fpu_status->FPUREG.Fpu_fsr_bits.res = sfsr.u.fields.res;
1631 fpu_status->FPUREG.Fpu_fsr_bits.ftt = sfsr.u.fields.ftt;
1632 fpu_status->FPUREG.Fpu_fsr_bits.qne = sfsr.u.fields.qne;
1633 fpu_status->FPUREG.Fpu_fsr_bits.pr = sfsr.u.fields.pr;
1634 fpu_status->FPUREG.Fpu_fsr_bits.fcc = sfsr.u.fields.fcc;
1635 fpu_status->FPUREG.Fpu_fsr_bits.aexc = sfsr.u.fields.aexc;
1636 fpu_status->FPUREG.Fpu_fsr_bits.cexc = sfsr.u.fields.cexc;
1637 }
1638 else{
1639 sfsr.u.fields.rd = fpu_status->FPUREG.Fpu_fsr_bits.rd;
1640 sfsr.u.fields.rp = fpu_status->FPUREG.Fpu_fsr_bits.rp;
1641 sfsr.u.fields.tem = fpu_status->FPUREG.Fpu_fsr_bits.tem;
1642 sfsr.u.fields.res = fpu_status->FPUREG.Fpu_fsr_bits.res;
1643 sfsr.u.fields.ftt = fpu_status->FPUREG.Fpu_fsr_bits.ftt;
1644 sfsr.u.fields.qne = fpu_status->FPUREG.Fpu_fsr_bits.qne;
1645 sfsr.u.fields.pr = fpu_status->FPUREG.Fpu_fsr_bits.pr;
1646 sfsr.u.fields.fcc = fpu_status->FPUREG.Fpu_fsr_bits.fcc;
1647 sfsr.u.fields.aexc = fpu_status->FPUREG.Fpu_fsr_bits.aexc;
1648 sfsr.u.fields.cexc = fpu_status->FPUREG.Fpu_fsr_bits.cexc;
1649 sfsr.u.word = SWAP_LONG(sfsr.u.word);
1650 memcpy(&(fpu->fpu.Fpu_fsr), &sfsr, sizeof(struct swapped_fsr));
1651 }
1652}
1653
1654__private_extern__
1655void
1656swap_ident_command(
1657struct ident_command *id_cmd,
1658enum byte_sex target_byte_sex)
1659{
1660#ifdef __MWERKS__
1661 enum byte_sex dummy;
1662 dummy = target_byte_sex;
1663#endif
1664 id_cmd->cmd = SWAP_LONG(id_cmd->cmd);
1665 id_cmd->cmdsize = SWAP_LONG(id_cmd->cmdsize);
1666}
1667
1668__private_extern__
1669void
1670swap_routines_command(
1671struct routines_command *r_cmd,
1672enum byte_sex target_byte_sex)
1673{
1674#ifdef __MWERKS__
1675 enum byte_sex dummy;
1676 dummy = target_byte_sex;
1677#endif
1678 r_cmd->cmd = SWAP_LONG(r_cmd->cmd);
1679 r_cmd->cmdsize = SWAP_LONG(r_cmd->cmdsize);
1680 r_cmd->init_address = SWAP_LONG(r_cmd->init_address);
1681 r_cmd->init_module = SWAP_LONG(r_cmd->init_module);
1682 r_cmd->reserved1 = SWAP_LONG(r_cmd->reserved1);
1683 r_cmd->reserved2 = SWAP_LONG(r_cmd->reserved2);
1684 r_cmd->reserved3 = SWAP_LONG(r_cmd->reserved3);
1685 r_cmd->reserved4 = SWAP_LONG(r_cmd->reserved4);
1686 r_cmd->reserved5 = SWAP_LONG(r_cmd->reserved5);
1687 r_cmd->reserved6 = SWAP_LONG(r_cmd->reserved6);
1688}
1689
1690__private_extern__
1691void
1692swap_twolevel_hints_command(
1693struct twolevel_hints_command *hints_cmd,
1694enum byte_sex target_byte_sex)
1695{
1696#ifdef __MWERKS__
1697 enum byte_sex dummy;
1698 dummy = target_byte_sex;
1699#endif
1700 hints_cmd->cmd = SWAP_LONG(hints_cmd->cmd);
1701 hints_cmd->cmdsize = SWAP_LONG(hints_cmd->cmdsize);
1702 hints_cmd->offset = SWAP_LONG(hints_cmd->offset);
1703 hints_cmd->nhints = SWAP_LONG(hints_cmd->nhints);
1704}
1705
1706__private_extern__
1707void
1708swap_twolevel_hint(
1709struct twolevel_hint *hints,
1710unsigned long nhints,
1711enum byte_sex target_byte_sex)
1712{
1713 struct swapped_twolevel_hint {
1714 union {
1715 struct {
1716 unsigned long
1717 itoc:24,
1718 isub_image:8;
1719 } fields;
1720 unsigned long word;
1721 } u;
1722 } shint;
1723
1724 unsigned long i;
1725 enum byte_sex host_byte_sex;
1726
1727 host_byte_sex = get_host_byte_sex();
1728
1729 for(i = 0; i < nhints; i++){
1730 if(target_byte_sex == host_byte_sex){
1731 memcpy(&shint, hints + i, sizeof(struct swapped_twolevel_hint));
1732 shint.u.word = SWAP_LONG(shint.u.word);
1733 hints[i].itoc = shint.u.fields.itoc;
1734 hints[i].isub_image = shint.u.fields.isub_image;
1735 }
1736 else{
1737 shint.u.fields.isub_image = hints[i].isub_image;
1738 shint.u.fields.itoc = hints[i].itoc;
1739 shint.u.word = SWAP_LONG(shint.u.word);
1740 memcpy(hints + i, &shint, sizeof(struct swapped_twolevel_hint));
1741 }
1742 }
1743}
1744
1745__private_extern__
1746void
1747swap_prebind_cksum_command(
1748struct prebind_cksum_command *cksum_cmd,
1749enum byte_sex target_byte_sex)
1750{
1751#ifdef __MWERKS__
1752 enum byte_sex dummy;
1753 dummy = target_byte_sex;
1754#endif
1755 cksum_cmd->cmd = SWAP_LONG(cksum_cmd->cmd);
1756 cksum_cmd->cmdsize = SWAP_LONG(cksum_cmd->cmdsize);
1757 cksum_cmd->cksum = SWAP_LONG(cksum_cmd->cksum);
1758}
1759
1760__private_extern__
1761void
1762swap_nlist(
1763struct nlist *symbols,
1764unsigned long nsymbols,
1765enum byte_sex target_byte_sex)
1766{
1767 unsigned long i;
1768#ifdef __MWERKS__
1769 enum byte_sex dummy;
1770 dummy = target_byte_sex;
1771#endif
1772
1773 for(i = 0; i < nsymbols; i++){
1774 symbols[i].n_un.n_strx = SWAP_LONG(symbols[i].n_un.n_strx);
1775 /* n_type */
1776 /* n_sect */
1777 symbols[i].n_desc = SWAP_SHORT(symbols[i].n_desc);
1778 symbols[i].n_value = SWAP_LONG(symbols[i].n_value);
1779 }
1780}
1781
1782__private_extern__
1783void
1784swap_ranlib(
1785struct ranlib *ranlibs,
1786unsigned long nranlibs,
1787enum byte_sex target_byte_sex)
1788{
1789 unsigned long i;
1790#ifdef __MWERKS__
1791 enum byte_sex dummy;
1792 dummy = target_byte_sex;
1793#endif
1794
1795 for(i = 0; i < nranlibs; i++){
1796 ranlibs[i].ran_un.ran_strx = SWAP_LONG(ranlibs[i].ran_un.ran_strx);
1797 ranlibs[i].ran_off = SWAP_LONG(ranlibs[i].ran_off);
1798 }
1799}
1800
1801__private_extern__
1802void
1803swap_relocation_info(
1804struct relocation_info *relocs,
1805unsigned long nrelocs,
1806enum byte_sex target_byte_sex)
1807{
1808 unsigned long i;
1809 enum byte_sex host_byte_sex;
1810 enum bool to_host_byte_sex, scattered;
1811
1812 struct swapped_relocation_info {
1813 long r_address;
1814 union {
1815 struct {
1816 unsigned int
1817 r_type:4,
1818 r_extern:1,
1819 r_length:2,
1820 r_pcrel:1,
1821 r_symbolnum:24;
1822 } fields;
1823 unsigned long word;
1824 } u;
1825 } sr;
1826
1827 struct swapped_scattered_relocation_info {
1828 unsigned long word;
1829 long r_value;
1830 } *ssr;
1831
1832 host_byte_sex = get_host_byte_sex();
1833 to_host_byte_sex = (enum bool)(target_byte_sex == host_byte_sex);
1834
1835 for(i = 0; i < nrelocs; i++){
1836 if(to_host_byte_sex)
1837 scattered = (enum bool)(
1838 (SWAP_LONG(relocs[i].r_address) & R_SCATTERED) != 0);
1839 else
1840 scattered = (enum bool)
1841 (((relocs[i].r_address) & R_SCATTERED) != 0);
1842 if(scattered == FALSE){
1843 if(to_host_byte_sex){
1844 memcpy(&sr, relocs + i, sizeof(struct relocation_info));
1845 sr.r_address = SWAP_LONG(sr.r_address);
1846 sr.u.word = SWAP_LONG(sr.u.word);
1847 relocs[i].r_address = sr.r_address;
1848 relocs[i].r_symbolnum = sr.u.fields.r_symbolnum;
1849 relocs[i].r_pcrel = sr.u.fields.r_pcrel;
1850 relocs[i].r_length = sr.u.fields.r_length;
1851 relocs[i].r_extern = sr.u.fields.r_extern;
1852 relocs[i].r_type = sr.u.fields.r_type;
1853 }
1854 else{
1855 sr.r_address = relocs[i].r_address;
1856 sr.u.fields.r_symbolnum = relocs[i].r_symbolnum;
1857 sr.u.fields.r_length = relocs[i].r_length;
1858 sr.u.fields.r_pcrel = relocs[i].r_pcrel;
1859 sr.u.fields.r_extern = relocs[i].r_extern;
1860 sr.u.fields.r_type = relocs[i].r_type;
1861 sr.r_address = SWAP_LONG(sr.r_address);
1862 sr.u.word = SWAP_LONG(sr.u.word);
1863 memcpy(relocs + i, &sr, sizeof(struct relocation_info));
1864 }
1865 }
1866 else{
1867 ssr = (struct swapped_scattered_relocation_info *)(relocs + i);
1868 ssr->word = SWAP_LONG(ssr->word);
1869 ssr->r_value = SWAP_LONG(ssr->r_value);
1870 }
1871 }
1872}
1873
1874__private_extern__
1875void
1876swap_indirect_symbols(
1877unsigned long *indirect_symbols,
1878unsigned long nindirect_symbols,
1879enum byte_sex target_byte_sex)
1880{
1881 unsigned long i;
1882#ifdef __MWERKS__
1883 enum byte_sex dummy;
1884 dummy = target_byte_sex;
1885#endif
1886
1887 for(i = 0; i < nindirect_symbols; i++)
1888 indirect_symbols[i] = SWAP_LONG(indirect_symbols[i]);
1889}
1890
1891__private_extern__
1892void
1893swap_dylib_reference(
1894struct dylib_reference *refs,
1895unsigned long nrefs,
1896enum byte_sex target_byte_sex)
1897{
1898 struct swapped_dylib_reference {
1899 union {
1900 struct {
1901 unsigned long
1902 flags:8,
1903 isym:24;
1904 } fields;
1905 unsigned long word;
1906 } u;
1907 } sref;
1908
1909 unsigned long i;
1910 enum byte_sex host_byte_sex;
1911
1912 host_byte_sex = get_host_byte_sex();
1913
1914 for(i = 0; i < nrefs; i++){
1915 if(target_byte_sex == host_byte_sex){
1916 memcpy(&sref, refs + i, sizeof(struct swapped_dylib_reference));
1917 sref.u.word = SWAP_LONG(sref.u.word);
1918 refs[i].flags = sref.u.fields.flags;
1919 refs[i].isym = sref.u.fields.isym;
1920 }
1921 else{
1922 sref.u.fields.isym = refs[i].isym;
1923 sref.u.fields.flags = refs[i].flags;
1924 sref.u.word = SWAP_LONG(sref.u.word);
1925 memcpy(refs + i, &sref, sizeof(struct swapped_dylib_reference));
1926 }
1927 }
1928
1929}
1930
1931__private_extern__
1932void
1933swap_dylib_module(
1934struct dylib_module *mods,
1935unsigned long nmods,
1936enum byte_sex target_byte_sex)
1937{
1938 unsigned long i;
1939#ifdef __MWERKS__
1940 enum byte_sex dummy;
1941 dummy = target_byte_sex;
1942#endif
1943
1944 for(i = 0; i < nmods; i++){
1945 mods[i].module_name = SWAP_LONG(mods[i].module_name);
1946 mods[i].iextdefsym = SWAP_LONG(mods[i].iextdefsym);
1947 mods[i].nextdefsym = SWAP_LONG(mods[i].nextdefsym);
1948 mods[i].irefsym = SWAP_LONG(mods[i].irefsym);
1949 mods[i].nrefsym = SWAP_LONG(mods[i].nrefsym);
1950 mods[i].ilocalsym = SWAP_LONG(mods[i].ilocalsym);
1951 mods[i].nlocalsym = SWAP_LONG(mods[i].nlocalsym);
1952 mods[i].iextrel = SWAP_LONG(mods[i].iextrel);
1953 mods[i].nextrel = SWAP_LONG(mods[i].nextrel);
1954 mods[i].iinit_iterm = SWAP_LONG(mods[i].iinit_iterm);
1955 mods[i].ninit_nterm = SWAP_LONG(mods[i].ninit_nterm);
1956 mods[i].objc_module_info_addr =
1957 SWAP_LONG(mods[i].objc_module_info_addr);
1958 mods[i].objc_module_info_size =
1959 SWAP_LONG(mods[i].objc_module_info_size);
1960 }
1961}
1962
1963__private_extern__
1964void
1965swap_dylib_table_of_contents(
1966struct dylib_table_of_contents *tocs,
1967unsigned long ntocs,
1968enum byte_sex target_byte_sex)
1969{
1970 unsigned long i;
1971#ifdef __MWERKS__
1972 enum byte_sex dummy;
1973 dummy = target_byte_sex;
1974#endif
1975
1976 for(i = 0; i < ntocs; i++){
1977 tocs[i].symbol_index = SWAP_LONG(tocs[i].symbol_index);
1978 tocs[i].module_index = SWAP_LONG(tocs[i].module_index);
1979 }
1980}
Note: See TracBrowser for help on using the repository browser.