-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbytesex.c
3026 lines (2833 loc) · 83.3 KB
/
bytesex.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2004, Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/* byte_sex.c */
#define __cr cr
#define __ctr ctr
#define __dar dar
#define __dsisr dsisr
#define __exception exception
#define __fpregs fpregs
#define __fpscr fpscr
#define __fpscr_pad fpscr_pad
#define __lr lr
#define __mq mq
#define __pad0 pad0
#define __pad1 pad1
#define __r0 r0
#define __r1 r1
#define __r10 r10
#define __r11 r11
#define __r12 r12
#define __r13 r13
#define __r14 r14
#define __r15 r15
#define __r16 r16
#define __r17 r17
#define __r18 r18
#define __r19 r19
#define __r2 r2
#define __r20 r20
#define __r21 r21
#define __r22 r22
#define __r23 r23
#define __r24 r24
#define __r25 r25
#define __r26 r26
#define __r27 r27
#define __r28 r28
#define __r29 r29
#define __r3 r3
#define __r30 r30
#define __r31 r31
#define __r4 r4
#define __r5 r5
#define __r6 r6
#define __r7 r7
#define __r8 r8
#define __r9 r9
#define __srr0 srr0
#define __srr1 srr1
#define __vrsave vrsave
#define __xer xer
#define __darwin_i386_exception_state i386_exception_state
#define __darwin_i386_float_state i386_float_state
#define __darwin_i386_thread_state i386_thread_state
#define __busy busy
#define __c0 c0
#define __c1 c1
#define __c2 c2
#define __c3 c3
#define __cs cs
#define __darwin_fp_control fp_control
#define __darwin_fp_status fp_status
#define __darwin_mmst_reg mmst_reg
#define __darwin_xmm_reg xmm_reg
#define __denorm denorm
#define __ds ds
#define __eax eax
#define __ebp ebp
#define __ebx ebx
#define __ecx ecx
#define __edi edi
#define __edx edx
#define __eflags eflags
#define __eip eip
#define __err err
#define __errsumm errsumm
#define __es es
#define __esi esi
#define __esp esp
#define __faultvaddr faultvaddr
#define __fpu_cs fpu_cs
#define __fpu_dp fpu_dp
#define __fpu_ds fpu_ds
#define __fpu_fcw fpu_fcw
#define __fpu_fop fpu_fop
#define __fpu_fsw fpu_fsw
#define __fpu_ftw fpu_ftw
#define __fpu_ip fpu_ip
#define __fpu_mxcsr fpu_mxcsr
#define __fpu_mxcsrmask fpu_mxcsrmask
#define __fpu_reserved fpu_reserved
#define __fpu_reserved1 fpu_reserved1
#define __fpu_rsrv1 fpu_rsrv1
#define __fpu_rsrv2 fpu_rsrv2
#define __fpu_rsrv3 fpu_rsrv3
#define __fpu_rsrv4 fpu_rsrv4
#define __fpu_stmm0 fpu_stmm0
#define __fpu_stmm1 fpu_stmm1
#define __fpu_stmm2 fpu_stmm2
#define __fpu_stmm3 fpu_stmm3
#define __fpu_stmm4 fpu_stmm4
#define __fpu_stmm5 fpu_stmm5
#define __fpu_stmm6 fpu_stmm6
#define __fpu_stmm7 fpu_stmm7
#define __fpu_xmm0 fpu_xmm0
#define __fpu_xmm1 fpu_xmm1
#define __fpu_xmm2 fpu_xmm2
#define __fpu_xmm3 fpu_xmm3
#define __fpu_xmm4 fpu_xmm4
#define __fpu_xmm5 fpu_xmm5
#define __fpu_xmm6 fpu_xmm6
#define __fpu_xmm7 fpu_xmm7
#define __fs fs
#define __gs gs
#define __invalid invalid
#define __mmst_reg mmst_reg
#define __mmst_rsrv mmst_rsrv
#define __ovrfl ovrfl
#define __pc pc
#define __precis precis
#define __rc rc
#define __ss ss
#define __stkflt stkflt
#define __tos tos
#define __trapno trapno
#define __undfl undfl
#define __xmm_reg xmm_reg
#define __zdiv zdiv
#define __rax rax
#define __rbx rbx
#define __rcx rcx
#define __rdx rdx
#define __rdi rdi
#define __rsi rsi
#define __rbp rbp
#define __rsp rsp
#define __r8 r8
#define __r9 r9
#define __r10 r10
#define __r11 r11
#define __r12 r12
#define __r13 r13
#define __r14 r14
#define __r15 r15
#define __rip rip
#define __rflags rflags
#define __dr0 dr0
#define __dr1 dr1
#define __dr2 dr2
#define __dr3 dr3
#define __dr4 dr4
#define __dr5 dr5
#define __dr6 dr6
#define __dr7 dr7
#include <string.h>
#include <mach-o/fat.h>
#include <mach-o/loader.h>
#include <mach/m68k/thread_status.h>
#undef MACHINE_THREAD_STATE /* need to undef these to avoid warnings */
#undef MACHINE_THREAD_STATE_COUNT
#undef THREAD_STATE_NONE
#undef VALID_THREAD_STATE_FLAVOR
#include <mach/ppc/thread_status.h>
#undef MACHINE_THREAD_STATE /* need to undef these to avoid warnings */
#undef MACHINE_THREAD_STATE_COUNT
#undef THREAD_STATE_NONE
#undef VALID_THREAD_STATE_FLAVOR
#include <mach/m88k/thread_status.h>
#include <mach/i860/thread_status.h>
#include <mach/i386/thread_status.h>
#include <mach/hppa/thread_status.h>
#include <mach/sparc/thread_status.h>
#include <mach/arm/thread_status.h>
#include <mach-o/nlist.h>
#include <mach-o/reloc.h>
#include <mach-o/ranlib.h>
#include <xar/xar.h>
#include "stuff/bool.h"
#include "stuff/bytesex.h"
__private_extern__
long long
SWAP_LONG_LONG(
long long ll)
{
union {
char c[8];
long long ll;
} in, out;
in.ll = ll;
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.ll);
}
__private_extern__
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);
}
__private_extern__
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.
*/
__private_extern__
enum byte_sex
get_host_byte_sex(
void)
{
uint32_t s;
s = (BIG_ENDIAN_BYTE_SEX << 24) | LITTLE_ENDIAN_BYTE_SEX;
return((enum byte_sex)*((char *)&s));
}
__private_extern__
void
swap_fat_header(
struct fat_header *fat_header,
enum byte_sex target_byte_sex)
{
#ifdef __MWERKS__
enum byte_sex dummy;
dummy = target_byte_sex;
#endif
fat_header->magic = SWAP_INT(fat_header->magic);
fat_header->nfat_arch = SWAP_INT(fat_header->nfat_arch);
}
__private_extern__
void
swap_fat_arch(
struct fat_arch *fat_archs,
uint32_t nfat_arch,
enum byte_sex target_byte_sex)
{
uint32_t i;
#ifdef __MWERKS__
enum byte_sex dummy;
dummy = target_byte_sex;
#endif
for(i = 0; i < nfat_arch; i++){
fat_archs[i].cputype = SWAP_INT(fat_archs[i].cputype);
fat_archs[i].cpusubtype = SWAP_INT(fat_archs[i].cpusubtype);
fat_archs[i].offset = SWAP_INT(fat_archs[i].offset);
fat_archs[i].size = SWAP_INT(fat_archs[i].size);
fat_archs[i].align = SWAP_INT(fat_archs[i].align);
}
}
__private_extern__
void
swap_fat_arch_64(
struct fat_arch_64 *fat_archs64,
uint32_t nfat_arch,
enum byte_sex target_byte_sex)
{
uint32_t i;
#ifdef __MWERKS__
enum byte_sex dummy;
dummy = target_byte_sex;
#endif
for(i = 0; i < nfat_arch; i++){
fat_archs64[i].cputype = SWAP_INT(fat_archs64[i].cputype);
fat_archs64[i].cpusubtype = SWAP_INT(fat_archs64[i].cpusubtype);
fat_archs64[i].offset = SWAP_LONG_LONG(fat_archs64[i].offset);
fat_archs64[i].size = SWAP_LONG_LONG(fat_archs64[i].size);
fat_archs64[i].align = SWAP_INT(fat_archs64[i].align);
fat_archs64[i].reserved = SWAP_INT(fat_archs64[i].reserved);
}
}
__private_extern__
void
swap_mach_header(
struct mach_header *mh,
enum byte_sex target_byte_sex)
{
#ifdef __MWERKS__
enum byte_sex dummy;
dummy = target_byte_sex;
#endif
mh->magic = SWAP_INT(mh->magic);
mh->cputype = SWAP_INT(mh->cputype);
mh->cpusubtype = SWAP_INT(mh->cpusubtype);
mh->filetype = SWAP_INT(mh->filetype);
mh->ncmds = SWAP_INT(mh->ncmds);
mh->sizeofcmds = SWAP_INT(mh->sizeofcmds);
mh->flags = SWAP_INT(mh->flags);
}
__private_extern__
void
swap_mach_header_64(
struct mach_header_64 *mh,
enum byte_sex target_byte_sex)
{
#ifdef __MWERKS__
enum byte_sex dummy;
dummy = target_byte_sex;
#endif
mh->magic = SWAP_INT(mh->magic);
mh->cputype = SWAP_INT(mh->cputype);
mh->cpusubtype = SWAP_INT(mh->cpusubtype);
mh->filetype = SWAP_INT(mh->filetype);
mh->ncmds = SWAP_INT(mh->ncmds);
mh->sizeofcmds = SWAP_INT(mh->sizeofcmds);
mh->flags = SWAP_INT(mh->flags);
mh->reserved = SWAP_INT(mh->reserved);
}
__private_extern__
void
swap_load_command(
struct load_command *lc,
enum byte_sex target_byte_sex)
{
#ifdef __MWERKS__
enum byte_sex dummy;
dummy = target_byte_sex;
#endif
lc->cmd = SWAP_INT(lc->cmd);
lc->cmdsize = SWAP_INT(lc->cmdsize);
}
__private_extern__
void
swap_segment_command(
struct segment_command *sg,
enum byte_sex target_byte_sex)
{
#ifdef __MWERKS__
enum byte_sex dummy;
dummy = target_byte_sex;
#endif
/* segname[16] */
sg->cmd = SWAP_INT(sg->cmd);
sg->cmdsize = SWAP_INT(sg->cmdsize);
sg->vmaddr = SWAP_INT(sg->vmaddr);
sg->vmsize = SWAP_INT(sg->vmsize);
sg->fileoff = SWAP_INT(sg->fileoff);
sg->filesize = SWAP_INT(sg->filesize);
sg->maxprot = SWAP_INT(sg->maxprot);
sg->initprot = SWAP_INT(sg->initprot);
sg->nsects = SWAP_INT(sg->nsects);
sg->flags = SWAP_INT(sg->flags);
}
__private_extern__
void
swap_segment_command_64(
struct segment_command_64 *sg,
enum byte_sex target_byte_sex)
{
#ifdef __MWERKS__
enum byte_sex dummy;
dummy = target_byte_sex;
#endif
/* segname[16] */
sg->cmd = SWAP_INT(sg->cmd);
sg->cmdsize = SWAP_INT(sg->cmdsize);
sg->vmaddr = SWAP_LONG_LONG(sg->vmaddr);
sg->vmsize = SWAP_LONG_LONG(sg->vmsize);
sg->fileoff = SWAP_LONG_LONG(sg->fileoff);
sg->filesize = SWAP_LONG_LONG(sg->filesize);
sg->maxprot = SWAP_INT(sg->maxprot);
sg->initprot = SWAP_INT(sg->initprot);
sg->nsects = SWAP_INT(sg->nsects);
sg->flags = SWAP_INT(sg->flags);
}
__private_extern__
void
swap_section(
struct section *s,
uint32_t nsects,
enum byte_sex target_byte_sex)
{
uint32_t i;
#ifdef __MWERKS__
enum byte_sex dummy;
dummy = target_byte_sex;
#endif
for(i = 0; i < nsects; i++){
/* sectname[16] */
/* segname[16] */
s[i].addr = SWAP_INT(s[i].addr);
s[i].size = SWAP_INT(s[i].size);
s[i].offset = SWAP_INT(s[i].offset);
s[i].align = SWAP_INT(s[i].align);
s[i].reloff = SWAP_INT(s[i].reloff);
s[i].nreloc = SWAP_INT(s[i].nreloc);
s[i].flags = SWAP_INT(s[i].flags);
s[i].reserved1 = SWAP_INT(s[i].reserved1);
s[i].reserved2 = SWAP_INT(s[i].reserved2);
}
}
__private_extern__
void
swap_section_64(
struct section_64 *s,
uint32_t nsects,
enum byte_sex target_byte_sex)
{
uint32_t i;
#ifdef __MWERKS__
enum byte_sex dummy;
dummy = target_byte_sex;
#endif
for(i = 0; i < nsects; i++){
/* sectname[16] */
/* segname[16] */
s[i].addr = SWAP_LONG_LONG(s[i].addr);
s[i].size = SWAP_LONG_LONG(s[i].size);
s[i].offset = SWAP_INT(s[i].offset);
s[i].align = SWAP_INT(s[i].align);
s[i].reloff = SWAP_INT(s[i].reloff);
s[i].nreloc = SWAP_INT(s[i].nreloc);
s[i].flags = SWAP_INT(s[i].flags);
s[i].reserved1 = SWAP_INT(s[i].reserved1);
s[i].reserved2 = SWAP_INT(s[i].reserved2);
}
}
__private_extern__
void
swap_symtab_command(
struct symtab_command *st,
enum byte_sex target_byte_sex)
{
#ifdef __MWERKS__
enum byte_sex dummy;
dummy = target_byte_sex;
#endif
st->cmd = SWAP_INT(st->cmd);
st->cmdsize = SWAP_INT(st->cmdsize);
st->symoff = SWAP_INT(st->symoff);
st->nsyms = SWAP_INT(st->nsyms);
st->stroff = SWAP_INT(st->stroff);
st->strsize = SWAP_INT(st->strsize);
}
__private_extern__
void
swap_dysymtab_command(
struct dysymtab_command *dyst,
enum byte_sex target_byte_sex)
{
#ifdef __MWERKS__
enum byte_sex dummy;
dummy = target_byte_sex;
#endif
dyst->cmd = SWAP_INT(dyst->cmd);
dyst->cmdsize = SWAP_INT(dyst->cmdsize);
dyst->ilocalsym = SWAP_INT(dyst->ilocalsym);
dyst->nlocalsym = SWAP_INT(dyst->nlocalsym);
dyst->iextdefsym = SWAP_INT(dyst->iextdefsym);
dyst->nextdefsym = SWAP_INT(dyst->nextdefsym);
dyst->iundefsym = SWAP_INT(dyst->iundefsym);
dyst->nundefsym = SWAP_INT(dyst->nundefsym);
dyst->tocoff = SWAP_INT(dyst->tocoff);
dyst->ntoc = SWAP_INT(dyst->ntoc);
dyst->modtaboff = SWAP_INT(dyst->modtaboff);
dyst->nmodtab = SWAP_INT(dyst->nmodtab);
dyst->extrefsymoff = SWAP_INT(dyst->extrefsymoff);
dyst->nextrefsyms = SWAP_INT(dyst->nextrefsyms);
dyst->indirectsymoff = SWAP_INT(dyst->indirectsymoff);
dyst->nindirectsyms = SWAP_INT(dyst->nindirectsyms);
dyst->extreloff = SWAP_INT(dyst->extreloff);
dyst->nextrel = SWAP_INT(dyst->nextrel);
dyst->locreloff = SWAP_INT(dyst->locreloff);
dyst->nlocrel = SWAP_INT(dyst->nlocrel);
}
__private_extern__
void
swap_symseg_command(
struct symseg_command *ss,
enum byte_sex target_byte_sex)
{
#ifdef __MWERKS__
enum byte_sex dummy;
dummy = target_byte_sex;
#endif
ss->cmd = SWAP_INT(ss->cmd);
ss->cmdsize = SWAP_INT(ss->cmdsize);
ss->offset = SWAP_INT(ss->offset);
ss->size = SWAP_INT(ss->size);
}
__private_extern__
void
swap_fvmlib_command(
struct fvmlib_command *fl,
enum byte_sex target_byte_sex)
{
#ifdef __MWERKS__
enum byte_sex dummy;
dummy = target_byte_sex;
#endif
fl->cmd = SWAP_INT(fl->cmd);
fl->cmdsize = SWAP_INT(fl->cmdsize);
fl->fvmlib.name.offset = SWAP_INT(fl->fvmlib.name.offset);
fl->fvmlib.minor_version = SWAP_INT(fl->fvmlib.minor_version);
fl->fvmlib.header_addr = SWAP_INT(fl->fvmlib.header_addr);
}
__private_extern__
void
swap_dylib_command(
struct dylib_command *dl,
enum byte_sex target_byte_sex)
{
#ifdef __MWERKS__
enum byte_sex dummy;
dummy = target_byte_sex;
#endif
dl->cmd = SWAP_INT(dl->cmd);
dl->cmdsize = SWAP_INT(dl->cmdsize);
dl->dylib.name.offset = SWAP_INT(dl->dylib.name.offset);
dl->dylib.timestamp = SWAP_INT(dl->dylib.timestamp);
dl->dylib.current_version = SWAP_INT(dl->dylib.current_version);
dl->dylib.compatibility_version =
SWAP_INT(dl->dylib.compatibility_version);
}
__private_extern__
void
swap_sub_framework_command(
struct sub_framework_command *sub,
enum byte_sex target_byte_sex)
{
#ifdef __MWERKS__
enum byte_sex dummy;
dummy = target_byte_sex;
#endif
sub->cmd = SWAP_INT(sub->cmd);
sub->cmdsize = SWAP_INT(sub->cmdsize);
sub->umbrella.offset = SWAP_INT(sub->umbrella.offset);
}
__private_extern__
void
swap_sub_umbrella_command(
struct sub_umbrella_command *usub,
enum byte_sex target_byte_sex)
{
#ifdef __MWERKS__
enum byte_sex dummy;
dummy = target_byte_sex;
#endif
usub->cmd = SWAP_INT(usub->cmd);
usub->cmdsize = SWAP_INT(usub->cmdsize);
usub->sub_umbrella.offset = SWAP_INT(usub->sub_umbrella.offset);
}
__private_extern__
void
swap_sub_library_command(
struct sub_library_command *lsub,
enum byte_sex target_byte_sex)
{
#ifdef __MWERKS__
enum byte_sex dummy;
dummy = target_byte_sex;
#endif
lsub->cmd = SWAP_INT(lsub->cmd);
lsub->cmdsize = SWAP_INT(lsub->cmdsize);
lsub->sub_library.offset = SWAP_INT(lsub->sub_library.offset);
}
__private_extern__
void
swap_sub_client_command(
struct sub_client_command *csub,
enum byte_sex target_byte_sex)
{
#ifdef __MWERKS__
enum byte_sex dummy;
dummy = target_byte_sex;
#endif
csub->cmd = SWAP_INT(csub->cmd);
csub->cmdsize = SWAP_INT(csub->cmdsize);
csub->client.offset = SWAP_INT(csub->client.offset);
}
__private_extern__
void
swap_prebound_dylib_command(
struct prebound_dylib_command *pbdylib,
enum byte_sex target_byte_sex)
{
#ifdef __MWERKS__
enum byte_sex dummy;
dummy = target_byte_sex;
#endif
pbdylib->cmd = SWAP_INT(pbdylib->cmd);
pbdylib->cmdsize = SWAP_INT(pbdylib->cmdsize);
pbdylib->name.offset = SWAP_INT(pbdylib->name.offset);
pbdylib->nmodules = SWAP_INT(pbdylib->nmodules);
pbdylib->linked_modules.offset =
SWAP_INT(pbdylib->linked_modules.offset);
}
__private_extern__
void
swap_dylinker_command(
struct dylinker_command *dyld,
enum byte_sex target_byte_sex)
{
#ifdef __MWERKS__
enum byte_sex dummy;
dummy = target_byte_sex;
#endif
dyld->cmd = SWAP_INT(dyld->cmd);
dyld->cmdsize = SWAP_INT(dyld->cmdsize);
dyld->name.offset = SWAP_INT(dyld->name.offset);
}
__private_extern__
void
swap_fvmfile_command(
struct fvmfile_command *ff,
enum byte_sex target_byte_sex)
{
#ifdef __MWERKS__
enum byte_sex dummy;
dummy = target_byte_sex;
#endif
ff->cmd = SWAP_INT(ff->cmd);
ff->cmdsize = SWAP_INT(ff->cmdsize);
ff->name.offset = SWAP_INT(ff->name.offset);
ff->header_addr = SWAP_INT(ff->header_addr);
}
__private_extern__
void
swap_thread_command(
struct thread_command *ut,
enum byte_sex target_byte_sex)
{
#ifdef __MWERKS__
enum byte_sex dummy;
dummy = target_byte_sex;
#endif
ut->cmd = SWAP_INT(ut->cmd);
ut->cmdsize = SWAP_INT(ut->cmdsize);
}
__private_extern__
void
swap_m68k_thread_state_regs(
struct m68k_thread_state_regs *cpu,
enum byte_sex target_byte_sex)
{
uint32_t i;
#ifdef __MWERKS__
enum byte_sex dummy;
dummy = target_byte_sex;
#endif
for(i = 0; i < 8; i++)
cpu->dreg[i] = SWAP_INT(cpu->dreg[i]);
for(i = 0; i < 8; i++)
cpu->areg[i] = SWAP_INT(cpu->areg[i]);
cpu->pad0 = SWAP_SHORT(cpu->pad0);
cpu->sr = SWAP_SHORT(cpu->sr);
cpu->pc = SWAP_INT(cpu->pc);
}
__private_extern__
void
swap_m68k_thread_state_68882(
struct m68k_thread_state_68882 *fpu,
enum byte_sex target_byte_sex)
{
uint32_t i, tmp;
#ifdef __MWERKS__
enum byte_sex dummy;
dummy = target_byte_sex;
#endif
for(i = 0; i < 8; i++){
tmp = SWAP_INT(fpu->regs[i].fp[0]);
fpu->regs[i].fp[1] = SWAP_INT(fpu->regs[i].fp[1]);
fpu->regs[i].fp[0] = SWAP_INT(fpu->regs[i].fp[2]);
fpu->regs[i].fp[2] = tmp;
}
fpu->cr = SWAP_INT(fpu->cr);
fpu->sr = SWAP_INT(fpu->sr);
fpu->iar = SWAP_INT(fpu->iar);
fpu->state = SWAP_INT(fpu->state);
}
__private_extern__
void
swap_m68k_thread_state_user_reg(
struct m68k_thread_state_user_reg *user_reg,
enum byte_sex target_byte_sex)
{
#ifdef __MWERKS__
enum byte_sex dummy;
dummy = target_byte_sex;
#endif
user_reg->user_reg = SWAP_INT(user_reg->user_reg);
}
__private_extern__
void
swap_ppc_thread_state_t(
ppc_thread_state_t *cpu,
enum byte_sex target_byte_sex)
{
cpu->srr0 = SWAP_INT(cpu->srr0);
cpu->srr1 = SWAP_INT(cpu->srr1);
cpu->r0 = SWAP_INT(cpu->r0);
cpu->r1 = SWAP_INT(cpu->r1);
cpu->r2 = SWAP_INT(cpu->r2);
cpu->r3 = SWAP_INT(cpu->r3);
cpu->r4 = SWAP_INT(cpu->r4);
cpu->r5 = SWAP_INT(cpu->r5);
cpu->r6 = SWAP_INT(cpu->r6);
cpu->r7 = SWAP_INT(cpu->r7);
cpu->r8 = SWAP_INT(cpu->r8);
cpu->r9 = SWAP_INT(cpu->r9);
cpu->r10 = SWAP_INT(cpu->r10);
cpu->r11 = SWAP_INT(cpu->r11);
cpu->r12 = SWAP_INT(cpu->r12);
cpu->r13 = SWAP_INT(cpu->r13);
cpu->r14 = SWAP_INT(cpu->r14);
cpu->r15 = SWAP_INT(cpu->r15);
cpu->r16 = SWAP_INT(cpu->r16);
cpu->r17 = SWAP_INT(cpu->r17);
cpu->r18 = SWAP_INT(cpu->r18);
cpu->r19 = SWAP_INT(cpu->r19);
cpu->r20 = SWAP_INT(cpu->r20);
cpu->r21 = SWAP_INT(cpu->r21);
cpu->r22 = SWAP_INT(cpu->r22);
cpu->r23 = SWAP_INT(cpu->r23);
cpu->r24 = SWAP_INT(cpu->r24);
cpu->r25 = SWAP_INT(cpu->r25);
cpu->r26 = SWAP_INT(cpu->r26);
cpu->r27 = SWAP_INT(cpu->r27);
cpu->r28 = SWAP_INT(cpu->r28);
cpu->r29 = SWAP_INT(cpu->r29);
cpu->r30 = SWAP_INT(cpu->r30);
cpu->r31 = SWAP_INT(cpu->r31);
cpu->cr = SWAP_INT(cpu->cr);
cpu->xer = SWAP_INT(cpu->xer);
cpu->lr = SWAP_INT(cpu->lr);
cpu->ctr = SWAP_INT(cpu->ctr);
cpu->mq = SWAP_INT(cpu->mq);
cpu->vrsave = SWAP_INT(cpu->vrsave);
}
__private_extern__
void
swap_ppc_thread_state64_t(
ppc_thread_state64_t *cpu,
enum byte_sex target_byte_sex)
{
cpu->srr0 = SWAP_LONG_LONG(cpu->srr0);
cpu->srr1 = SWAP_LONG_LONG(cpu->srr1);
cpu->r0 = SWAP_LONG_LONG(cpu->r0);
cpu->r1 = SWAP_LONG_LONG(cpu->r1);
cpu->r2 = SWAP_LONG_LONG(cpu->r2);
cpu->r3 = SWAP_LONG_LONG(cpu->r3);
cpu->r4 = SWAP_LONG_LONG(cpu->r4);
cpu->r5 = SWAP_LONG_LONG(cpu->r5);
cpu->r6 = SWAP_LONG_LONG(cpu->r6);
cpu->r7 = SWAP_LONG_LONG(cpu->r7);
cpu->r8 = SWAP_LONG_LONG(cpu->r8);
cpu->r9 = SWAP_LONG_LONG(cpu->r9);
cpu->r10 = SWAP_LONG_LONG(cpu->r10);
cpu->r11 = SWAP_LONG_LONG(cpu->r11);
cpu->r12 = SWAP_LONG_LONG(cpu->r12);
cpu->r13 = SWAP_LONG_LONG(cpu->r13);
cpu->r14 = SWAP_LONG_LONG(cpu->r14);
cpu->r15 = SWAP_LONG_LONG(cpu->r15);
cpu->r16 = SWAP_LONG_LONG(cpu->r16);
cpu->r17 = SWAP_LONG_LONG(cpu->r17);
cpu->r18 = SWAP_LONG_LONG(cpu->r18);
cpu->r19 = SWAP_LONG_LONG(cpu->r19);
cpu->r20 = SWAP_LONG_LONG(cpu->r20);
cpu->r21 = SWAP_LONG_LONG(cpu->r21);
cpu->r22 = SWAP_LONG_LONG(cpu->r22);
cpu->r23 = SWAP_LONG_LONG(cpu->r23);
cpu->r24 = SWAP_LONG_LONG(cpu->r24);
cpu->r25 = SWAP_LONG_LONG(cpu->r25);
cpu->r26 = SWAP_LONG_LONG(cpu->r26);
cpu->r27 = SWAP_LONG_LONG(cpu->r27);
cpu->r28 = SWAP_LONG_LONG(cpu->r28);
cpu->r29 = SWAP_LONG_LONG(cpu->r29);
cpu->r30 = SWAP_LONG_LONG(cpu->r30);
cpu->r31 = SWAP_LONG_LONG(cpu->r31);
cpu->cr = SWAP_INT(cpu->cr);
cpu->xer = SWAP_LONG_LONG(cpu->xer);
cpu->lr = SWAP_LONG_LONG(cpu->lr);
cpu->ctr = SWAP_LONG_LONG(cpu->ctr);
cpu->vrsave = SWAP_INT(cpu->vrsave);
}
__private_extern__
void
swap_ppc_float_state_t(
ppc_float_state_t *fpu,
enum byte_sex target_byte_sex)
{
uint32_t i;
#ifdef __MWERKS__
enum byte_sex dummy;
dummy = target_byte_sex;
#endif
for(i = 0; i < 32; i++)
fpu->fpregs[i] = SWAP_DOUBLE(fpu->fpregs[i]);
fpu->fpscr_pad = SWAP_INT(fpu->fpscr_pad);
fpu->fpscr = SWAP_INT(fpu->fpscr);
}
__private_extern__
void
swap_ppc_exception_state_t(
ppc_exception_state_t *state,
enum byte_sex target_byte_sex)
{
uint32_t i;
#ifdef __MWERKS__
enum byte_sex dummy;
dummy = target_byte_sex;
#endif
state->dar = SWAP_INT(state->dar);
state->dsisr = SWAP_INT(state->dsisr);
state->exception = SWAP_INT(state->exception);
state->pad0 = SWAP_INT(state->pad0);
for(i = 0; i < 4; i++)
state->pad1[i] = SWAP_INT(state->pad1[i]);
}
__private_extern__
void
swap_m88k_thread_state_grf_t(
m88k_thread_state_grf_t *cpu,
enum byte_sex target_byte_sex)
{
#ifdef __MWERKS__
enum byte_sex dummy;
dummy = target_byte_sex;
#endif
cpu->r1 = SWAP_INT(cpu->r1);
cpu->r2 = SWAP_INT(cpu->r2);
cpu->r3 = SWAP_INT(cpu->r3);
cpu->r4 = SWAP_INT(cpu->r4);
cpu->r5 = SWAP_INT(cpu->r5);
cpu->r6 = SWAP_INT(cpu->r6);
cpu->r7 = SWAP_INT(cpu->r7);
cpu->r8 = SWAP_INT(cpu->r8);
cpu->r9 = SWAP_INT(cpu->r9);
cpu->r10 = SWAP_INT(cpu->r10);
cpu->r11 = SWAP_INT(cpu->r11);
cpu->r12 = SWAP_INT(cpu->r12);
cpu->r13 = SWAP_INT(cpu->r13);
cpu->r14 = SWAP_INT(cpu->r14);
cpu->r15 = SWAP_INT(cpu->r15);
cpu->r16 = SWAP_INT(cpu->r16);
cpu->r17 = SWAP_INT(cpu->r17);
cpu->r18 = SWAP_INT(cpu->r18);
cpu->r19 = SWAP_INT(cpu->r19);
cpu->r20 = SWAP_INT(cpu->r20);
cpu->r21 = SWAP_INT(cpu->r21);
cpu->r22 = SWAP_INT(cpu->r22);
cpu->r23 = SWAP_INT(cpu->r23);
cpu->r24 = SWAP_INT(cpu->r24);
cpu->r25 = SWAP_INT(cpu->r25);
cpu->r26 = SWAP_INT(cpu->r26);
cpu->r27 = SWAP_INT(cpu->r27);
cpu->r28 = SWAP_INT(cpu->r28);
cpu->r29 = SWAP_INT(cpu->r29);
cpu->r30 = SWAP_INT(cpu->r30);
cpu->r31 = SWAP_INT(cpu->r31);
cpu->xip = SWAP_INT(cpu->xip);
cpu->xip_in_bd = SWAP_INT(cpu->xip_in_bd);
cpu->nip = SWAP_INT(cpu->nip);
}
__private_extern__
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;
uint32_t 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;
uint32_t word;