aboutsummaryrefslogtreecommitdiffstats
path: root/meta-oe/recipes-devtools/ltrace/ltrace/0001-Add-support-for-mips64-n32-n64.patch
blob: d0daf1466f4a512bec6212031fc5d8da252c93fe (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
From 5f6dfafb80bdc2566fe91d5fde96769175fabf35 Mon Sep 17 00:00:00 2001
From: Faraz Shahbazker <faraz.shahbazker@imgtec.com>
Date: Sat, 1 Jul 2017 10:56:59 -0700
Subject: [PATCH] Add support for mips64 n32/n64

Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
Upstream-Status: Pending
Source: http://lists.alioth.debian.org/pipermail/ltrace-devel/2015-May/001327.html

 backend.h                            |   8 +
 ltrace-elf.c                         |  12 ++
 proc.h                               |   1 +
 sysdeps/linux-gnu/mips/Makefile.am   |   1 +
 sysdeps/linux-gnu/mips/abi.c         |  64 +++++++
 sysdeps/linux-gnu/mips/arch.h        |  24 ++-
 sysdeps/linux-gnu/mips/plt.c         |  68 ++++++--
 sysdeps/linux-gnu/mips/signalent1.h  |  52 ++++++
 sysdeps/linux-gnu/mips/syscallent1.h | 328 +++++++++++++++++++++++++++++++++++
 sysdeps/linux-gnu/mips/trace.c       | 241 ++++++++++++++++++-------
 sysdeps/linux-gnu/mksyscallent_mips  |   9 +-
 11 files changed, 728 insertions(+), 80 deletions(-)
 create mode 100644 sysdeps/linux-gnu/mips/abi.c
 create mode 100644 sysdeps/linux-gnu/mips/signalent1.h
 create mode 100644 sysdeps/linux-gnu/mips/syscallent1.h

diff --git a/backend.h b/backend.h
index e25daa0..0d6926a 100644
--- a/backend.h
+++ b/backend.h
@@ -314,6 +314,14 @@ int arch_process_exec(struct process *proc);
 int arch_get_sym_info(struct ltelf *lte, const char *filename, size_t sym_index,
 		      GElf_Rela *rela, GElf_Sym *sym);
 
+/* The following callback has to be implemented in backend if arch.h
+ * defines ARCH_HAVE_GET_ABI
+ *
+ * This is called from read_module just once, when reading the main module.
+ * The value returned is an architecture specific ID for the current ABI
+ * to be used later for ABI-specific operations. */
+char arch_get_abi(GElf_Ehdr ehdr);
+
 enum plt_status {
 	PLT_FAIL,
 	PLT_OK,
diff --git a/ltrace-elf.c b/ltrace-elf.c
index f439cb0..a85edca 100644
--- a/ltrace-elf.c
+++ b/ltrace-elf.c
@@ -1131,6 +1131,14 @@ populate_symtab(struct process *proc, const char *filename,
 				    only_exported_names);
 }
 
+#ifndef ARCH_HAVE_GET_ABI
+char
+arch_get_abi(GElf_Ehdr ehdr)
+{
+       return 0;
+}
+#endif
+
 static int
 read_module(struct library *lib, struct process *proc,
 	    const char *filename, GElf_Addr bias, int main)
@@ -1151,6 +1159,10 @@ read_module(struct library *lib, struct process *proc,
 	 * with 32-bit ltrace.  It is desirable to preserve this.  */
 	proc->e_machine = lte.ehdr.e_machine;
 	proc->e_class = lte.ehdr.e_ident[EI_CLASS];
+	/* Another candidate for the ABI module. We probably
+	 * want to do all of the e_* stuff only once, for main */
+	if (main)
+		proc->e_abi = arch_get_abi(lte.ehdr);
 	get_arch_dep(proc);
 
 	/* Find out the base address.  For PIE main binaries we look
diff --git a/proc.h b/proc.h
index a611456..00094e1 100644
--- a/proc.h
+++ b/proc.h
@@ -117,6 +117,7 @@ struct process {
 	 * nauseam.  */
 	short e_machine;
 	char e_class;
+	char e_abi;
 
 #if defined(HAVE_LIBDW)
 	/* Unwind info for leader, NULL for non-leader procs. */
diff --git a/sysdeps/linux-gnu/mips/Makefile.am b/sysdeps/linux-gnu/mips/Makefile.am
index 1fd8c2a..571ee0d 100644
--- a/sysdeps/linux-gnu/mips/Makefile.am
+++ b/sysdeps/linux-gnu/mips/Makefile.am
@@ -20,6 +20,7 @@ noinst_LTLIBRARIES = \
 	../libcpu.la
 
 ___libcpu_la_SOURCES = \
+	abi.c \
 	plt.c \
 	regs.c \
 	trace.c
diff --git a/sysdeps/linux-gnu/mips/abi.c b/sysdeps/linux-gnu/mips/abi.c
new file mode 100644
index 0000000..64e3c10
--- /dev/null
+++ b/sysdeps/linux-gnu/mips/abi.c
@@ -0,0 +1,64 @@
+/*
+ * This file is part of ltrace.
+ * Copyright (C) 2015 Imagination Technologies Limited
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#include <stdio.h>
+#include <gelf.h>
+#include "arch.h"
+
+/*
+ *  There is no bit in the header-flags to mark N64 ABI, it must be
+ *  determined by exclusion of other ABIs. The following values are
+ *  from elfcpp/mips.h in binutils sources
+ */
+enum
+{
+	E_MIPS_ABI_MASK = 0x0000F000,
+	E_MIPS_ABI_N32 	= 0x00000020,
+	E_MIPS_ABI_O32 	= 0x00001000,
+	E_MIPS_ABI_O64 	= 0x00002000,
+	E_MIPS_ABI_EABI32 = 0x00003000,
+	E_MIPS_ABI_EABI64 = 0x00004000,
+};
+
+char
+arch_get_abi(GElf_Ehdr ehdr)
+{
+	enum mips_abi_type abi;
+	switch (ehdr.e_flags & E_MIPS_ABI_MASK) {
+	case E_MIPS_ABI_O32:
+		abi = ABI_O32; break;
+	case E_MIPS_ABI_O64:
+		abi = ABI_O64; break;
+	case E_MIPS_ABI_EABI32:
+	case E_MIPS_ABI_EABI64:
+		fprintf(stderr, "%s: MIPS EABI is not supported\n", __func__);
+		abi = -1;
+		break;
+	default:
+		if (ehdr.e_flags & E_MIPS_ABI_N32)
+			abi = ABI_N32;
+		else
+			abi = ABI_N64;
+	}
+
+	return abi;
+}
+
+/**@}*/
diff --git a/sysdeps/linux-gnu/mips/arch.h b/sysdeps/linux-gnu/mips/arch.h
index 16273d2..8b75df2 100644
--- a/sysdeps/linux-gnu/mips/arch.h
+++ b/sysdeps/linux-gnu/mips/arch.h
@@ -1,5 +1,6 @@
 /*
  * This file is part of ltrace.
+ * Copyright (C) 2015 Imagination Technologies Limited
  * Copyright (C) 2013,2014 Petr Machata, Red Hat Inc.
  * Copyright (C) 2006 Eric Vaitl
  *
@@ -38,8 +39,12 @@
 #define BREAKPOINT_LENGTH 4
 #define DECR_PC_AFTER_BREAK 0
 
-#define LT_ELFCLASS	ELFCLASS32
+#ifdef __LP64__
+#define LT_ELFCLASS	ELFCLASS64
 #define LT_ELF_MACHINE	EM_MIPS
+#endif /* __LP64__ */
+#define LT_ELFCLASS2	ELFCLASS32
+#define LT_ELF_MACHINE2 EM_MIPS
 
 #define ARCH_HAVE_LTELF_DATA
 struct arch_ltelf_data {
@@ -53,8 +58,14 @@ struct arch_ltelf_data {
 #define ARCH_HAVE_ADD_PLT_ENTRY
 #define ARCH_HAVE_SW_SINGLESTEP
 #define ARCH_HAVE_SYMBOL_RET
-
+#define ARCH_HAVE_GET_ABI
 #define ARCH_HAVE_LIBRARY_SYMBOL_DATA
+
+#ifdef __LP64__
+#define ARCH_HAVE_SIZEOF
+#define ARCH_HAVE_ALIGNOF
+#endif /* __LP64__ */
+
 enum mips_plt_type
 {
 	/* A symbol has associated PLT entry.  */
@@ -73,7 +84,14 @@ enum mips_plt_type
 	MIPS_PLT_NEED_UNRESOLVE,
 };
 
-struct mips_unresolve_data;
+enum mips_abi_type
+{
+	ABI_O32,
+	ABI_N32,
+	ABI_N64,
+	ABI_O64,
+};
+
 struct arch_library_symbol_data {
 	enum mips_plt_type type;
 	union {
diff --git a/sysdeps/linux-gnu/mips/plt.c b/sysdeps/linux-gnu/mips/plt.c
index f3c12da..2d85ad9 100644
--- a/sysdeps/linux-gnu/mips/plt.c
+++ b/sysdeps/linux-gnu/mips/plt.c
@@ -1,5 +1,6 @@
 /*
  * This file is part of ltrace.
+ * Copyright (C) 2015 Imagination Technologies Limited
  * Copyright (C) 2012,2013,2014 Petr Machata, Red Hat Inc.
  * Copyright (C) 2012 Edgar E. Iglesias, Axis Communications
  * Copyright (C) 2008,2009 Juan Cespedes
@@ -182,6 +183,11 @@ arch_find_dl_debug(struct process *proc, arch_addr_t dyn_addr,
 {
 	arch_addr_t rld_addr;
 	int r;
+#ifdef __LP64__
+	size_t addrsize = proc->mask_32bit ? 4 : (sizeof *ret);
+#else /* !__LP64__ */
+	size_t addrsize = sizeof *ret;
+#endif /* !__LP64__ */
 
 	/* MIPS puts the address of the r_debug structure into the
 	 * DT_MIPS_RLD_MAP entry instead of into the DT_DEBUG entry.  */
@@ -189,7 +195,7 @@ arch_find_dl_debug(struct process *proc, arch_addr_t dyn_addr,
 					 DT_MIPS_RLD_MAP, &rld_addr);
 	if (r == 0) {
 		if (umovebytes(proc, rld_addr,
-			       ret, sizeof *ret) != sizeof *ret) {
+			       ret, addrsize) != addrsize) {
 			r = -1;
 		}
 	}
@@ -295,14 +301,25 @@ arch_elf_init(struct ltelf *lte, struct library *lib)
 
 	for (j = 0; j < data->d_size / 16; ++j) {
 		uint32_t insn;
+		int got_size = 4;
+		uint32_t load_inst = 0x24180000U; /* addui t8,0,xx  */
+
+#ifdef __LP64__
+		if (arch_get_abi(lte->ehdr) == ABI_N64
+		    || arch_get_abi(lte->ehdr) == ABI_O64) {
+			got_size = 8;
+			load_inst = 0x64180000U; /* daddui t8,0,xx  */
+		}
+#endif /* __LP64__ */
+
 		if (elf_read_u32(data, j * 16 + 12, &insn) < 0)
 			goto fail_stubs;
 
 		if (insn == 0)
 			continue;
 
-		/* 0x2418XXXX encodes lbu 0,t8,XXXX or li t8,XXXX.  */
-		if ((insn & 0xffff0000U) != 0x24180000U)
+		/* 0x[62]418XXXX encodes [d]addiu t8, 0, XXXX.  */
+		if ((insn & 0xffff0000U) != load_inst)
 			goto fail_stubs;
 
 		unsigned idx = insn & 0xffff;
@@ -323,8 +340,8 @@ arch_elf_init(struct ltelf *lte, struct library *lib)
 			+ lte->arch.mips_local_gotno;
 		/* XXX Double cast.  */
 		arch_addr_t got_entry_addr
-			= (arch_addr_t) (uintptr_t) lte->arch.pltgot_addr
-			+ got_idx * 4;
+			= (arch_addr_t) (uintptr_t) (lte->arch.pltgot_addr
+						     + got_idx * got_size);
 
 		GElf_Rela rela = {
 			/* XXX double cast.  */
@@ -336,7 +353,7 @@ arch_elf_init(struct ltelf *lte, struct library *lib)
 		if (VECT_PUSHBACK(&lte->plt_relocs, &rela) < 0)
 			goto fail_stubs;
 
-		fprintf(stderr,
+		debug(2,
 			"added stub entry for symbol %u at %#lx, GOT @%p\n",
 			idx, (unsigned long) rela.r_addend, got_entry_addr);
 	}
@@ -362,8 +379,17 @@ read_got_entry(struct process *proc, GElf_Addr addr, GElf_Addr *valp)
 {
 	/* XXX double cast.  */
 	arch_addr_t a = (arch_addr_t) (uintptr_t) addr;
-	uint32_t l;
-	if (proc_read_32(proc, a, &l) < 0) {
+	uint64_t l = 0;
+	int result;
+
+#ifdef __LP64__
+	if (!proc->mask_32bit)
+		result = proc_read_64(proc, a, &l);
+	else
+#endif /* __LP64__ */
+		result = proc_read_32(proc, a, (uint32_t *) &l);
+
+	if (result < 0) {
 		fprintf(stderr, "ptrace read got entry @%#" PRIx64 ": %s\n",
 			addr, strerror(errno));
 		return -1;
@@ -426,13 +452,13 @@ arch_elf_add_plt_entry(struct process *proc, struct ltelf *lte,
 	GElf_Addr stub_addr = rela->r_addend + lte->bias;
 
 	debug(2, "PLT-less arch_elf_add_plt_entry %s = %#llx\n",
-	      a_name, stub_addr);
+	      a_name, (unsigned long long) stub_addr);
 
 	struct library_symbol *libsym = NULL;
 	if (default_elf_add_plt_entry(proc, lte, a_name, rela, ndx,
 				      &libsym) < 0) {
-		fprintf(stderr, "%s: failed %s(%#llx): %s\n", __func__,
-			a_name, stub_addr, strerror(errno));
+		fprintf(stderr, "%s: failed %s(%#lx): %s\n", __func__,
+			a_name, (unsigned long) stub_addr, strerror(errno));
 		goto fail;
 	}
 
@@ -503,13 +529,27 @@ jump_to_entry_point(struct process *proc, struct breakpoint *bp)
 static int
 unresolve_got_entry(struct process *proc, GElf_Addr addr, GElf_Addr value)
 {
-	uint32_t v32 = (uint32_t) value;
-	uint32_t a32 = (uint32_t) addr;
-	if (ptrace(PTRACE_POKETEXT, proc->pid, a32, v32) < 0) {
+	arch_addr_t a = (arch_addr_t) (uintptr_t) addr;
+#ifdef __LP64__
+	/* To write 32-bit value in 64-bit mode, we must read-modify-write
+	   the 64-bit value with only the lower 32 bits modified.  */
+	if (proc->mask_32bit) {
+		GElf_Addr orig = ptrace(PTRACE_PEEKTEXT, proc->pid, a, 0);
+		char *obytes = (char *) &orig;
+		char *nbytes = (char *) &value;
+		unsigned i;
+
+		for (i = 0; i < 4; i++)
+			obytes[i] = nbytes[i];
+		value = orig;
+	}
+#endif /* __LP64__ */
+	if (ptrace(PTRACE_POKETEXT, proc->pid, a, (unsigned long) value) < 0) {
 		fprintf(stderr, "failed to unresolve GOT entry: %s\n",
 			strerror(errno));
 		return -1;
 	}
+
 	return 0;
 }
 
diff --git a/sysdeps/linux-gnu/mips/signalent1.h b/sysdeps/linux-gnu/mips/signalent1.h
new file mode 100644
index 0000000..9e9d1f7
--- /dev/null
+++ b/sysdeps/linux-gnu/mips/signalent1.h
@@ -0,0 +1,52 @@
+/*
+ * This file is part of ltrace.
+ * Copyright (C) 2015 Imagination Technologies Limited
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+	"SIG_0",           /* 0 */
+	"SIGHUP",          /* 1 */
+	"SIGINT",          /* 2 */
+	"SIGQUIT",         /* 3 */
+	"SIGILL",          /* 4 */
+	"SIGTRAP",         /* 5 */
+	"SIGIOT",          /* 6 */
+	"SIGEMT",          /* 7 */
+	"SIGFPE",          /* 8 */
+	"SIGKILL",         /* 9 */
+	"SIGBUS",          /* 10 */
+	"SIGSEGV",         /* 11 */
+	"SIGSYS",          /* 12 */
+	"SIGPIPE",         /* 13 */
+	"SIGALRM",         /* 14 */
+	"SIGTERM",         /* 15 */
+	"SIGUSR1",         /* 16 */
+	"SIGUSR2",         /* 17 */
+	"SIGCHLD",         /* 18 */
+	"SIGPWR",          /* 19 */
+	"SIGWINCH",        /* 20 */
+	"SIGURG",          /* 21 */
+	"SIGIO",           /* 22 */
+	"SIGSTOP",         /* 23 */
+	"SIGTSTP",         /* 24 */
+	"SIGCONT",         /* 25 */
+	"SIGTTIN",         /* 26 */
+	"SIGTTOU",         /* 27 */
+	"SIGVTALRM",       /* 28 */
+	"SIGPROF",         /* 29 */
+	"SIGXCPU",         /* 30 */
+	"SIGXFSZ",         /* 31 */
diff --git a/sysdeps/linux-gnu/mips/syscallent1.h b/sysdeps/linux-gnu/mips/syscallent1.h
new file mode 100644
index 0000000..dfa4954
--- /dev/null
+++ b/sysdeps/linux-gnu/mips/syscallent1.h
@@ -0,0 +1,328 @@
+/*
+ * This file is part of ltrace.
+ * Copyright (C) 2015 Imagination Technologies Limited
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+/* MIPS64 */
+
+	"read",                            /* 0 */
+	"write",                           /* 1 */
+	"open",                            /* 2 */
+	"close",                           /* 3 */
+	"stat",                            /* 4 */
+	"fstat",                           /* 5 */
+	"lstat",                           /* 6 */
+	"poll",                            /* 7 */
+	"lseek",                           /* 8 */
+	"mmap",                            /* 9 */
+	"mprotect",                        /* 10 */
+	"munmap",                          /* 11 */
+	"brk",                             /* 12 */
+	"rt_sigaction",                    /* 13 */
+	"rt_sigprocmask",                  /* 14 */
+	"ioctl",                           /* 15 */
+	"pread64",                         /* 16 */
+	"pwrite64",                        /* 17 */
+	"readv",                           /* 18 */
+	"writev",                          /* 19 */
+	"access",                          /* 20 */
+	"pipe",                            /* 21 */
+	"_newselect",                      /* 22 */
+	"sched_yield",                     /* 23 */
+	"mremap",                          /* 24 */
+	"msync",                           /* 25 */
+	"mincore",                         /* 26 */
+	"madvise",                         /* 27 */
+	"shmget",                          /* 28 */
+	"shmat",                           /* 29 */
+	"shmctl",                          /* 30 */
+	"dup",                             /* 31 */
+	"dup2",                            /* 32 */
+	"pause",                           /* 33 */
+	"nanosleep",                       /* 34 */
+	"getitimer",                       /* 35 */
+	"setitimer",                       /* 36 */
+	"alarm",                           /* 37 */
+	"getpid",                          /* 38 */
+	"sendfile",                        /* 39 */
+	"socket",                          /* 40 */
+	"connect",                         /* 41 */
+	"accept",                          /* 42 */
+	"sendto",                          /* 43 */
+	"recvfrom",                        /* 44 */
+	"sendmsg",                         /* 45 */
+	"recvmsg",                         /* 46 */
+	"shutdown",                        /* 47 */
+	"bind",                            /* 48 */
+	"listen",                          /* 49 */
+	"getsockname",                     /* 50 */
+	"getpeername",                     /* 51 */
+	"socketpair",                      /* 52 */
+	"setsockopt",                      /* 53 */
+	"getsockopt",                      /* 54 */
+	"clone",                           /* 55 */
+	"fork",                            /* 56 */
+	"execve",                          /* 57 */
+	"exit",                            /* 58 */
+	"wait4",                           /* 59 */
+	"kill",                            /* 60 */
+	"uname",                           /* 61 */
+	"semget",                          /* 62 */
+	"semop",                           /* 63 */
+	"semctl",                          /* 64 */
+	"shmdt",                           /* 65 */
+	"msgget",                          /* 66 */
+	"msgsnd",                          /* 67 */
+	"msgrcv",                          /* 68 */
+	"msgctl",                          /* 69 */
+	"fcntl",                           /* 70 */
+	"flock",                           /* 71 */
+	"fsync",                           /* 72 */
+	"fdatasync",                       /* 73 */
+	"truncate",                        /* 74 */
+	"ftruncate",                       /* 75 */
+	"getdents",                        /* 76 */
+	"getcwd",                          /* 77 */
+	"chdir",                           /* 78 */
+	"fchdir",                          /* 79 */
+	"rename",                          /* 80 */
+	"mkdir",                           /* 81 */
+	"rmdir",                           /* 82 */
+	"creat",                           /* 83 */
+	"link",                            /* 84 */
+	"unlink",                          /* 85 */
+	"symlink",                         /* 86 */
+	"readlink",                        /* 87 */
+	"chmod",                           /* 88 */
+	"fchmod",                          /* 89 */
+	"chown",                           /* 90 */
+	"fchown",                          /* 91 */
+	"lchown",                          /* 92 */
+	"umask",                           /* 93 */
+	"gettimeofday",                    /* 94 */
+	"getrlimit",                       /* 95 */
+	"getrusage",                       /* 96 */
+	"sysinfo",                         /* 97 */
+	"times",                           /* 98 */
+	"ptrace",                          /* 99 */
+	"getuid",                          /* 100 */
+	"syslog",                          /* 101 */
+	"getgid",                          /* 102 */
+	"setuid",                          /* 103 */
+	"setgid",                          /* 104 */
+	"geteuid",                         /* 105 */
+	"getegid",                         /* 106 */
+	"setpgid",                         /* 107 */
+	"getppid",                         /* 108 */
+	"getpgrp",                         /* 109 */
+	"setsid",                          /* 110 */
+	"setreuid",                        /* 111 */
+	"setregid",                        /* 112 */
+	"getgroups",                       /* 113 */
+	"setgroups",                       /* 114 */
+	"setresuid",                       /* 115 */
+	"getresuid",                       /* 116 */
+	"setresgid",                       /* 117 */
+	"getresgid",                       /* 118 */
+	"getpgid",                         /* 119 */
+	"setfsuid",                        /* 120 */
+	"setfsgid",                        /* 121 */
+	"getsid",                          /* 122 */
+	"capget",                          /* 123 */
+	"capset",                          /* 124 */
+	"rt_sigpending",                   /* 125 */
+	"rt_sigtimedwait",                 /* 126 */
+	"rt_sigqueueinfo",                 /* 127 */
+	"rt_sigsuspend",                   /* 128 */
+	"sigaltstack",                     /* 129 */
+	"utime",                           /* 130 */
+	"mknod",                           /* 131 */
+	"personality",                     /* 132 */
+	"ustat",                           /* 133 */
+	"statfs",                          /* 134 */
+	"fstatfs",                         /* 135 */
+	"sysfs",                           /* 136 */
+	"getpriority",                     /* 137 */
+	"setpriority",                     /* 138 */
+	"sched_setparam",                  /* 139 */
+	"sched_getparam",                  /* 140 */
+	"sched_setscheduler",              /* 141 */
+	"sched_getscheduler",              /* 142 */
+	"sched_get_priority_max",          /* 143 */
+	"sched_get_priority_min",          /* 144 */
+	"sched_rr_get_interval",           /* 145 */
+	"mlock",                           /* 146 */
+	"munlock",                         /* 147 */
+	"mlockall",                        /* 148 */
+	"munlockall",                      /* 149 */
+	"vhangup",                         /* 150 */
+	"pivot_root",                      /* 151 */
+	"_sysctl",                         /* 152 */
+	"prctl",                           /* 153 */
+	"adjtimex",                        /* 154 */
+	"setrlimit",                       /* 155 */
+	"chroot",                          /* 156 */
+	"sync",                            /* 157 */
+	"acct",                            /* 158 */
+	"settimeofday",                    /* 159 */
+	"mount",                           /* 160 */
+	"umount2",                         /* 161 */
+	"swapon",                          /* 162 */
+	"swapoff",                         /* 163 */
+	"reboot",                          /* 164 */
+	"sethostname",                     /* 165 */
+	"setdomainname",                   /* 166 */
+	"create_module",                   /* 167 */
+	"init_module",                     /* 168 */
+	"delete_module",                   /* 169 */
+	"get_kernel_syms",                 /* 170 */
+	"query_module",                    /* 171 */
+	"quotactl",                        /* 172 */
+	"nfsservctl",                      /* 173 */
+	"getpmsg",                         /* 174 */
+	"putpmsg",                         /* 175 */
+	"afs_syscall",                     /* 176 */
+	"reserved177",                     /* 177 */
+	"gettid",                          /* 178 */
+	"readahead",                       /* 179 */
+	"setxattr",                        /* 180 */
+	"lsetxattr",                       /* 181 */
+	"fsetxattr",                       /* 182 */
+	"getxattr",                        /* 183 */
+	"lgetxattr",                       /* 184 */
+	"fgetxattr",                       /* 185 */
+	"listxattr",                       /* 186 */
+	"llistxattr",                      /* 187 */
+	"flistxattr",                      /* 188 */
+	"removexattr",                     /* 189 */
+	"lremovexattr",                    /* 190 */
+	"fremovexattr",                    /* 191 */
+	"tkill",                           /* 192 */
+	"reserved193",                     /* 193 */
+	"futex",                           /* 194 */
+	"sched_setaffinity",               /* 195 */
+	"sched_getaffinity",               /* 196 */
+	"cacheflush",                      /* 197 */
+	"cachectl",                        /* 198 */
+	"sysmips",                         /* 199 */
+	"io_setup",                        /* 200 */
+	"io_destroy",                      /* 201 */
+	"io_getevents",                    /* 202 */
+	"io_submit",                       /* 203 */
+	"io_cancel",                       /* 204 */
+	"exit_group",                      /* 205 */
+	"lookup_dcookie",                  /* 206 */
+	"epoll_create",                    /* 207 */
+	"epoll_ctl",                       /* 208 */
+	"epoll_wait",                      /* 209 */
+	"remap_file_pages",                /* 210 */
+	"rt_sigreturn",                    /* 211 */
+	"set_tid_address",                 /* 212 */
+	"restart_syscall",                 /* 213 */
+	"semtimedop",                      /* 214 */
+	"fadvise64",                       /* 215 */
+	"timer_create",                    /* 216 */
+	"timer_settime",                   /* 217 */
+	"timer_gettime",                   /* 218 */
+	"timer_getoverrun",                /* 219 */
+	"timer_delete",                    /* 220 */
+	"clock_settime",                   /* 221 */
+	"clock_gettime",                   /* 222 */
+	"clock_getres",                    /* 223 */
+	"clock_nanosleep",                 /* 224 */
+	"tgkill",                          /* 225 */
+	"utimes",                          /* 226 */
+	"mbind",                           /* 227 */
+	"get_mempolicy",                   /* 228 */
+	"set_mempolicy",                   /* 229 */
+	"mq_open",                         /* 230 */
+	"mq_unlink",                       /* 231 */
+	"mq_timedsend",                    /* 232 */
+	"mq_timedreceive",                 /* 233 */
+	"mq_notify",                       /* 234 */
+	"mq_getsetattr",                   /* 235 */
+	"vserver",                         /* 236 */
+	"waitid",                          /* 237 */
+	"238",                             /* 238 */
+	"add_key",                         /* 239 */
+	"request_key",                     /* 240 */
+	"keyctl",                          /* 241 */
+	"set_thread_area",                 /* 242 */
+	"inotify_init",                    /* 243 */
+	"inotify_add_watch",               /* 244 */
+	"inotify_rm_watch",                /* 245 */
+	"migrate_pages",                   /* 246 */
+	"openat",                          /* 247 */
+	"mkdirat",                         /* 248 */
+	"mknodat",                         /* 249 */
+	"fchownat",                        /* 250 */
+	"futimesat",                       /* 251 */
+	"newfstatat",                      /* 252 */
+	"unlinkat",                        /* 253 */
+	"renameat",                        /* 254 */
+	"linkat",                          /* 255 */
+	"symlinkat",                       /* 256 */
+	"readlinkat",                      /* 257 */
+	"fchmodat",                        /* 258 */
+	"faccessat",                       /* 259 */
+	"pselect6",                        /* 260 */
+	"ppoll",                           /* 261 */
+	"unshare",                         /* 262 */
+	"splice",                          /* 263 */
+	"sync_file_range",                 /* 264 */
+	"tee",                             /* 265 */
+	"vmsplice",                        /* 266 */
+	"move_pages",                      /* 267 */
+	"set_robust_list",                 /* 268 */
+	"get_robust_list",                 /* 269 */
+	"kexec_load",                      /* 270 */
+	"getcpu",                          /* 271 */
+	"epoll_pwait",                     /* 272 */
+	"ioprio_set",                      /* 273 */
+	"ioprio_get",                      /* 274 */
+	"utimensat",                       /* 275 */
+	"signalfd",                        /* 276 */
+	"timerfd",                         /* 277 */
+	"eventfd",                         /* 278 */
+	"fallocate",                       /* 279 */
+	"timerfd_create",                  /* 280 */
+	"timerfd_gettime",                 /* 281 */
+	"timerfd_settime",                 /* 282 */
+	"signalfd4",                       /* 283 */
+	"eventfd2",                        /* 284 */
+	"epoll_create1",                   /* 285 */
+	"dup3",                            /* 286 */
+	"pipe2",                           /* 287 */
+	"inotify_init1",                   /* 288 */
+	"preadv",                          /* 289 */
+	"pwritev",                         /* 290 */
+	"rt_tgsigqueueinfo",               /* 291 */
+	"perf_event_open",                 /* 292 */
+	"accept4",                         /* 293 */
+	"recvmmsg",                        /* 294 */
+	"fanotify_init",                   /* 295 */
+	"fanotify_mark",                   /* 296 */
+	"prlimit64",                       /* 297 */
+	"name_to_handle_at",               /* 298 */
+	"open_by_handle_at",               /* 299 */
+	"clock_adjtime",                   /* 300 */
+	"syncfs",                          /* 301 */
+	"sendmmsg",                        /* 302 */
+	"setns",                           /* 303 */
+	"process_vm_readv",                /* 304 */
+	"process_vm_writev",               /* 305 */
diff --git a/sysdeps/linux-gnu/mips/trace.c b/sysdeps/linux-gnu/mips/trace.c
index e81b374..d54818e 100644
--- a/sysdeps/linux-gnu/mips/trace.c
+++ b/sysdeps/linux-gnu/mips/trace.c
@@ -1,5 +1,6 @@
 /*
  * This file is part of ltrace.
+ * Copyright (C) 2015 Imagination Technologies Limited
  * Copyright (C) 2013 Petr Machata, Red Hat Inc.
  * Copyright (C) 2012 Edgar E. Iglesias, Axis Communications
  * Copyright (C) 2010 Arnaud Patard, Mandriva SA
@@ -29,6 +30,7 @@
 #include <signal.h>
 #include <sys/ptrace.h>
 #include <asm/ptrace.h>
+#include <asm/unistd.h>
 #include <assert.h>
 #include <asm/unistd.h>
 
@@ -68,6 +70,44 @@
 void
 get_arch_dep(struct process *proc)
 {
+#ifdef __LP64__
+	proc->mask_32bit = (proc->e_class == ELFCLASS32);
+#endif /* __LP64__ */
+	/* n32 personality is best approximated by n64,
+	   at least for syscall numbers */
+	proc->personality = (proc->e_class == ELFCLASS64
+			     || proc->e_abi == ABI_N32);
+}
+
+/**
+   \param abi ABI of current process, from mips_abi_type enum
+   \param list An array of 4 elements, each corresponding to an ABI, in
+   the order: o32, n32, n64, o64
+
+   return value from array corresponding to requested ABI
+ */
+static int
+abi_select(const int abi, const int list[])
+{
+	int retval;
+	switch (abi)
+	{
+	case ABI_N32:
+		retval = list[1];
+		break;
+	case ABI_N64:
+		retval = list[2];
+		break;
+	case ABI_O64:
+		retval = list[3];
+		break;
+	case ABI_O32:
+	default:
+		retval = list[0];
+		break;
+	}
+
+	return retval;
 }
 
 /**
@@ -90,53 +130,94 @@ get_arch_dep(struct process *proc)
 int
 syscall_p(struct process *proc, int status, int *sysnum)
 {
-	if (WIFSTOPPED(status)
-			&& WSTOPSIG(status) == (SIGTRAP | proc->tracesysgood)) {
-		/* get the user's pc (plus 8) */
-		long pc = (long)get_instruction_pointer(proc);
-		/* fetch the SWI instruction */
-		int insn = ptrace(PTRACE_PEEKTEXT, proc->pid, pc - 4, 0);
-		int num = ptrace(PTRACE_PEEKTEXT, proc->pid, pc - 8, 0);
-
-		/*
-		   On a mips,  syscall looks like:
-		   24040fa1    li v0, 0x0fa1   # 4001 --> _exit syscall
-		   0000000c    syscall
-		 */
-		if(insn!=0x0000000c){
-			/* sigreturn returns control to the point
-			   where the signal was received; skip check 
-			   for preceeding syscall instruction */
-			int depth = proc->callstack_depth;
-			struct callstack_element *top = NULL;
-			if (depth > 0)
-				top = &proc->callstack[depth - 1];
-
-			if (top != NULL &&  top->is_syscall &&
-			    (top->c_un.syscall == (__NR_rt_sigreturn -
-						   __NR_Linux) ||
-			     top->c_un.syscall == (__NR_sigreturn -
-						   __NR_Linux))) {
-				*sysnum = top->c_un.syscall;
-				return 2;
-			}
-			else
-				return 0;
-		}
-
-		*sysnum = (num & 0xFFFF) - 4000;
-		/* if it is a syscall, return 1 or 2 */
-		if (proc->callstack_depth > 0 &&
-				proc->callstack[proc->callstack_depth - 1].is_syscall &&
-				proc->callstack[proc->callstack_depth - 1].c_un.syscall == *sysnum) {
+	unsigned long pc;
+	int insn, prev;
+	int min_syscall, max_syscall, sigreturn, rt_sigreturn;
+	struct callstack_element *top = NULL;
+	int depth = proc->callstack_depth;
+	const int syscallbase[] = {__NR_O32_Linux, __NR_N32_Linux,
+				   __NR_64_Linux, __NR_O32_Linux};
+	const int syscallnum[] = {__NR_O32_Linux_syscalls,
+				  __NR_N32_Linux_syscalls,
+				  __NR_64_Linux_syscalls,
+				  __NR_O32_Linux_syscalls};
+	const int rt_sigreturn_list[] = {193, 211, 211, 193};
+	const int sigreturn_list[] = {119, -1, -1, 119};
+
+	if (!WIFSTOPPED(status)
+	    || WSTOPSIG(status) != (SIGTRAP | proc->tracesysgood))
+		return 0;
+
+	/* get the user's pc (plus 8) */
+	pc = (unsigned long)get_instruction_pointer(proc);
+	/* fetch the SWI instruction */
+	insn = ptrace(PTRACE_PEEKTEXT, proc->pid, pc - 4, 0);
+	prev = ptrace(PTRACE_PEEKTEXT, proc->pid, pc - 8, 0);
+
+	if (depth > 0)
+		top = &proc->callstack[depth - 1];
+
+	/* Range of syscall numbers varies with ABI; ref:asm/unistd.h */
+	min_syscall = abi_select(proc->e_abi, syscallbase);
+	max_syscall = min_syscall + abi_select(proc->e_abi, syscallnum);
+	sigreturn = min_syscall + abi_select(proc->e_abi, sigreturn_list);
+	rt_sigreturn = min_syscall + abi_select(proc->e_abi, rt_sigreturn_list);
+
+	/* not a syscall instruction */
+	if(insn!=0x0000000c){
+		/* sigreturn returns control to the point where the signal was
+		   received; skip check for preceeding syscall instruction */
+		if (top != NULL &&  top->is_syscall
+		    && (top->c_un.syscall == (rt_sigreturn - min_syscall)
+			|| top->c_un.syscall == (sigreturn - min_syscall))) {
+			*sysnum = top->c_un.syscall;
 			return 2;
 		}
+		else
+			return 0;
+	}
 
-		if (*sysnum >= 0) {
-			return 1;
-		}
+	/*
+	  On a mips,  syscall looks like:
+	  24020fa1    li v0, 0x0fa1   # 4001 --> _exit syscall
+	  0000000c    syscall
+	*/
+	if ((prev & 0xFFFF0000) == 0x24020000) {
+		*sysnum = (prev & 0xFFFF) - min_syscall;
 	}
-	return 0;
+	/*
+	  The above is not necessary in Linux kernel > v2.6.35. Recent
+	  kernels have a fancy-pants method of restarting syscalls.
+	  We must read v0 instead, to get the syscall number.
+
+	  Unfortunately, v0 is not preserved till the point of return.
+	  If already in syscall and v0 is invalid, assume this event
+	  to be a return without attempting to match previous syscall.
+
+	  Caveat: logic fails if v0 incidentally contains a valid
+	  syscall number, distinct from the current syscall number,
+	  at the point of return from a nested syscall.
+	*/
+	else {
+		int v0 = ptrace(PTRACE_PEEKUSER, proc->pid, off_v0, 0);
+
+		if ((v0 >= min_syscall) && (v0 <= max_syscall))
+			*sysnum = v0 - min_syscall;
+		else if (depth > 0 && top->is_syscall)
+			*sysnum = top->c_un.syscall;
+		else /* syscall instruction without valid number - ignored */
+			return 0;
+	}
+
+	/* if it is a syscall, return 1 or 2 */
+	if (depth > 0 && top->is_syscall && top->c_un.syscall == *sysnum) {
+		return 2;
+	}
+
+	if (*sysnum >= 0)
+		return 1;
+	else
+		return 0;
 }
 
 /* Based on GDB code.  */
@@ -162,9 +243,11 @@ mips32_relative_offset (uint32_t inst)
   return ((itype_immediate(inst) ^ 0x8000) - 0x8000) << 2;
 }
 
-int mips_next_pcs(struct process *proc, uint32_t pc, uint32_t *newpc)
+int mips_next_pcs(struct process *proc, unsigned long pc,
+		  unsigned long *newpc)
 {
-	uint32_t inst, rx;
+	uint32_t inst;
+	unsigned long rx;
 	int op;
 	int rn;
 	int nr = 0;
@@ -277,8 +360,8 @@ int mips_next_pcs(struct process *proc, uint32_t pc, uint32_t *newpc)
 	return nr;
 
 fail:
-	printf("nr=%d pc=%x\n", nr, pc);
-	printf("pc=%x %x\n", newpc[0], newpc[1]);
+	printf("nr=%d pc=%lx\n", nr, pc);
+	printf("pc=%lx %lx\n", newpc[0], newpc[1]);
 	return 0;
 }
 
@@ -304,17 +387,27 @@ fail:
  * branches within the LL-SC sequence.
  */
 #define inrange(x,lo,hi) ((x)<=(hi) && (x)>=(lo))
+/* Instruction encodings for atomic operations */
+#ifdef __mips64
+#define op_SC_p(op)	(op == 0x38 || op == 0x3c)
+#define op_LL_p(op)	(op == 0x30 || op == 0x34)
+#else /* !__mips64 */
+#define op_SC_p(op)	(op == 0x38)
+#define op_LL_p(op)	(op == 0x30)
+#endif /* !__mips64 */
+
 static int
-mips_atomic_next_pcs(struct process *proc, uint32_t lladdr, uint32_t *newpcs)
+mips_atomic_next_pcs(struct process *proc, unsigned long lladdr,
+		     unsigned long *newpcs)
 {
 	int nr = 0;
 
-	uint32_t scaddr;
+	unsigned long scaddr;
 	for (scaddr = lladdr + 4; scaddr - lladdr <= 2048; scaddr += 4) {
 		/* Found SC, now stepover trailing branch */
 		uint32_t inst;
 		if (proc_read_32(proc, (arch_addr_t)scaddr, &inst) >= 0 &&
-		    itype_op(inst) == 0x38) {
+		    op_SC_p (itype_op(inst))) {
 			newpcs[nr++] = scaddr + 4;
 			break;
 		}
@@ -327,16 +420,16 @@ mips_atomic_next_pcs(struct process *proc, uint32_t lladdr, uint32_t *newpcs)
 	}
 
 	/* Scan LL<->SC range for branches going outside that range */
-	uint32_t spc;
+	unsigned long spc;
 	for (spc = lladdr + 4; spc < scaddr; spc += 4) {
-		uint32_t scanpcs[2];
+		unsigned long scanpcs[2];
 		int snr = mips_next_pcs(proc, spc, scanpcs);
 
 		int i;
 		for (i = 0; i < snr; ++i) {
 			if (!inrange(scanpcs[i], lladdr, scaddr)) {
-				uint32_t *tmp = realloc(newpcs, (nr + 1) *
-							sizeof *newpcs);
+				unsigned long *tmp = realloc(newpcs, (nr + 1)
+							     * sizeof *newpcs);
 				if (tmp == NULL) {
 					perror("malloc atomic next pcs");
 					return -1;
@@ -357,8 +450,8 @@ arch_sw_singlestep(struct process *proc, struct breakpoint *bp,
 		   int (*add_cb)(arch_addr_t, struct sw_singlestep_data *),
 		   struct sw_singlestep_data *add_cb_data)
 {
-	uint32_t pc = (uint32_t) get_instruction_pointer(proc);
-	uint32_t *newpcs;
+	unsigned long pc = (unsigned long) get_instruction_pointer(proc);
+	unsigned long *newpcs;
 	int nr;
 	uint32_t inst;
 
@@ -369,7 +462,7 @@ arch_sw_singlestep(struct process *proc, struct breakpoint *bp,
 		return SWS_FAIL;
 
 	/* Starting an atomic read-modify-write sequence */
-	if (itype_op(inst) == 0x30)
+	if (op_LL_p(itype_op(inst)))
 		nr = mips_atomic_next_pcs(proc, pc, newpcs);
 	else
 		nr = mips_next_pcs(proc, pc, newpcs);
@@ -462,7 +555,7 @@ gimme_arg(enum tof type, struct process *proc, int arg_num,
 				debug(2,"ret = %#lx",addr);
 				return addr;
 			}
-			ret = addr + 4*arg_num;
+			ret = addr + sizeof(long) * arg_num;
 			ret=ptrace(PTRACE_PEEKTEXT,proc->pid,addr,0);
 			debug(2,"ret = %#lx",ret);
 			return ret;
@@ -474,7 +567,7 @@ gimme_arg(enum tof type, struct process *proc, int arg_num,
 			debug(2,"ret = %#lx",addr);
 			return addr;
 		}
-		ret = addr + 4*arg_num;
+		ret = addr + sizeof(long) * arg_num;
 		ret=ptrace(PTRACE_PEEKTEXT,proc->pid,addr,0);
 		debug(2,"ret = %#lx",ret);
 		return ret;
@@ -483,4 +576,34 @@ gimme_arg(enum tof type, struct process *proc, int arg_num,
 	return 0;
 }
 
+#ifdef __LP64__
+size_t
+arch_type_sizeof(struct process *proc, struct arg_type_info *info)
+{
+	if (proc == NULL)
+		return (size_t)-2;
+
+	switch (info->type) {
+	case ARGTYPE_LONG:
+	case ARGTYPE_ULONG:
+		return proc->mask_32bit ? 4 : sizeof (long);
+
+	case ARGTYPE_POINTER:
+		return proc->mask_32bit ? 4 : sizeof (void *);
+
+	default:
+		/* Use default value.  */
+		return (size_t)-2;
+	}
+}
+
+size_t
+arch_type_alignof(struct process *proc, struct arg_type_info *info)
+{
+	if (proc == NULL)
+		return (size_t)-2;
+
+	return arch_type_sizeof(proc, info);
+}
+#endif /* __LP64__ */
 /**@}*/
diff --git a/sysdeps/linux-gnu/mksyscallent_mips b/sysdeps/linux-gnu/mksyscallent_mips
index f3961b4..f8dcfe1 100755
--- a/sysdeps/linux-gnu/mksyscallent_mips
+++ b/sysdeps/linux-gnu/mksyscallent_mips
@@ -19,9 +19,7 @@
 
 # hack expression to generate arch/syscallent.h from <asm/unistd.h>
 # It reads from stdin and writes to stdout
-# It should work OK on i386,m68k,arm,ia64
-# It does NOT work in mips, s390
-# It is untested in other architectures
+# Default is o32; arch=mips64 generates n64 syscalls
 
 BEGIN {
 	max=0;
@@ -31,7 +29,10 @@ BEGIN {
 {
 	#debug
 	#printf("/%s/%s/%s/%s/\n", $1, $2, $3, $4);
-	if ($2 ~ /__NR_Linux/ && $3 ~ /4000/) {
+        min=4000
+        if (arch ~ "mips64") min=5000
+
+	if ($2 ~ /__NR_Linux/ && $3 ~ min) {
 		syscall=1;
 	}
 	if ($2 ~ /__NR_Linux_syscalls/) {
-- 
2.13.2