-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlibgc-7.6.8-e2k.patch
819 lines (785 loc) · 31 KB
/
libgc-7.6.8-e2k.patch
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
From 8ed786cd8c2ad65c0782bb972c22abd0e83302e8 Mon Sep 17 00:00:00 2001
From: Ilya Kurdyukov <[email protected]>
Date: Fri, 2 Jul 2021 12:00:00 +0700
Subject: [PATCH] libgc-7.6.8 e2k support
Made from the published MCST patch for an older version:
https://storage.mcst.ru/pub/pdk/cur/patches/gc-7.2d/0001-e2k_port.patch
---
Makefile.am | 3 +-
Makefile.direct | 6 +++
Makefile.in | 3 +-
config.guess | 3 ++
config.sub | 2 +
configure | 6 ++-
configure.ac | 6 ++-
e2k_save_regs_in_stack.c | 88 +++++++++++++++++++++++++++++++
include/gc.h | 7 ++-
include/private/gc_priv.h | 26 +++++++--
include/private/gcconfig.h | 26 +++++++++
include/private/pthread_support.h | 2 +-
mach_dep.c | 4 +-
mark.c | 28 +++++++++-
mark_rts.c | 17 +++++-
misc.c | 10 ++--
os_dep.c | 22 ++++++++
pthread_stop_world.c | 46 +++++++++++++++-
pthread_support.c | 3 ++
tests/test.c | 2 +-
20 files changed, 286 insertions(+), 24 deletions(-)
create mode 100644 e2k_save_regs_in_stack.c
diff --git a/Makefile.am b/Makefile.am
index c487b0a..6279fad 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -119,7 +119,8 @@ libgc_la_LDFLAGS = $(extra_ldflags_libgc) -version-info $(LIBGC_VER_INFO) \
-no-undefined
EXTRA_libgc_la_SOURCES = ia64_save_regs_in_stack.s sparc_mach_dep.S \
- sparc_netbsd_mach_dep.s sparc_sunos4_mach_dep.s
+ sparc_netbsd_mach_dep.s sparc_sunos4_mach_dep.s \
+ e2k_save_regs_in_stack.c
if CPLUSPLUS
# C++ Interface
diff --git a/Makefile.direct b/Makefile.direct
index f661cf0..4ef7877 100644
--- a/Makefile.direct
+++ b/Makefile.direct
@@ -120,6 +120,7 @@ SRCS= $(CSRCS) \
include/private/pthread_stop_world.h include/private/darwin_semaphore.h \
include/private/darwin_stop_world.h include/private/thread_local_alloc.h \
ia64_save_regs_in_stack.s sparc_mach_dep.S \
+ e2k_save_regs_in_stack.c \
sparc_netbsd_mach_dep.s sparc_sunos4_mach_dep.s $(CORD_SRCS)
DOC_FILES= doc/README.Mac doc/README.OS2 \
@@ -328,6 +329,7 @@ dyn_test:
mach_dep.o: $(srcdir)/mach_dep.c $(srcdir)/sparc_mach_dep.S \
$(srcdir)/sparc_sunos4_mach_dep.s \
$(srcdir)/ia64_save_regs_in_stack.s \
+ $(srcdir)/e2k_save_regs_in_stack.c \
$(srcdir)/sparc_netbsd_mach_dep.s $(UTILS)
rm -f mach_dep.o
./if_mach SPARC SOLARIS $(CC) -c -o mach_dep2.o $(srcdir)/sparc_mach_dep.S
@@ -338,6 +340,9 @@ mach_dep.o: $(srcdir)/mach_dep.c $(srcdir)/sparc_mach_dep.S \
./if_mach IA64 "" $(AS) -o ia64_save_regs_in_stack.o $(srcdir)/ia64_save_regs_in_stack.s
./if_mach IA64 "" $(CC) -c -o mach_dep1.o $(SPECIALCFLAGS) $(srcdir)/mach_dep.c
./if_mach IA64 "" $(LD) -r -o mach_dep.o mach_dep1.o ia64_save_regs_in_stack.o
+ ./if_mach E2K "" $(CC) -c -o e2k_save_regs_in_stack.o $(srcdir)/e2k_save_regs_in_stack.c
+ ./if_mach E2K "" $(CC) -c -o mach_dep1.o $(SPECIALCFLAGS) $(srcdir)/mach_dep.c
+ ./if_mach E2K "" $(LD) -r -o mach_dep.o mach_dep1.o e2k_save_regs_in_stack.o
-./if_not_there mach_dep.o $(CC) -c $(SPECIALCFLAGS) $(srcdir)/mach_dep.c
-./if_not_there mach_dep.o `cygpath -w /bin/sh` $(CC) -c $(SPECIALCFLAGS) $(srcdir)/mach_dep.c
-./if_not_there mach_dep.o /bin/sh $(CC) -c $(SPECIALCFLAGS) $(srcdir)/mach_dep.c
@@ -410,6 +415,7 @@ gctest: tests/test.o base_lib $(UTILS)
./if_mach SPARC DRSNX $(CC) $(CFLAGS) -o gctest tests/test.o gc.a -lucb
./if_mach HP_PA HPUX $(CC) $(CFLAGS) -o gctest tests/test.o gc.a -ldld `./threadlibs`
./if_mach M68K AMIGA $(CC) $(CFLAGS) -UGC_AMIGA_MAKINGLIB -o gctest tests/test.o gc.a `./threadlibs`
+ ./if_mach E2K LINUX $(CC) $(CFLAGS) -o gctest tests/test.o gc.a -lm `./threadlibs`
./if_not_there gctest $(CC) $(CFLAGS) -o gctest tests/test.o gc.a `./threadlibs`
# If an optimized setjmp_test generates a segmentation fault,
diff --git a/Makefile.in b/Makefile.in
index 64fffdc..3bbcc79 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -1046,7 +1046,8 @@ libgc_la_LDFLAGS = $(extra_ldflags_libgc) -version-info $(LIBGC_VER_INFO) \
-no-undefined
EXTRA_libgc_la_SOURCES = ia64_save_regs_in_stack.s sparc_mach_dep.S \
- sparc_netbsd_mach_dep.s sparc_sunos4_mach_dep.s
+ sparc_netbsd_mach_dep.s sparc_sunos4_mach_dep.s \
+ e2k_save_regs_in_stack.c
@CPLUSPLUS_TRUE@libgccpp_la_SOURCES = gc_cpp.cc
@CPLUSPLUS_TRUE@libgccpp_la_LIBADD = ./libgc.la
diff --git a/config.guess b/config.guess
index 6c32c86..feec8ed 100755
--- a/config.guess
+++ b/config.guess
@@ -891,6 +891,9 @@ EOF
UNAME_MACHINE=aarch64_be
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
exit ;;
+ e2k:Linux:*:*)
+ echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+ exit ;;
alpha:Linux:*:*)
case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in
EV5) UNAME_MACHINE=alphaev5 ;;
diff --git a/config.sub b/config.sub
index 7ffe373..182e1ff 100755
--- a/config.sub
+++ b/config.sub
@@ -249,6 +249,7 @@ case $basic_machine in
1750a | 580 \
| a29k \
| aarch64 | aarch64_be \
+ | e2k \
| alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \
| alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \
| am33_2.0 \
@@ -371,6 +372,7 @@ case $basic_machine in
580-* \
| a29k-* \
| aarch64-* | aarch64_be-* \
+ | e2k-* \
| alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \
| alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \
| alphapca5[67]-* | alpha64pca5[67]-* | arc-* | arceb-* \
diff --git a/configure b/configure
index bc06264..ac2f220 100755
--- a/configure
+++ b/configure
@@ -16372,7 +16372,8 @@ fi
case "$host" in
x86-*-linux* | ia64-*-linux* | i586-*-linux* | i686-*-linux* \
- | x86_64-*-linux* | alpha-*-linux* | powerpc*-*-linux* | sparc*-*-linux*)
+ | x86_64-*-linux* | alpha-*-linux* | powerpc*-*-linux* | sparc*-*-linux* \
+ | e2k-*-linux*)
$as_echo "#define GC_LINUX_THREADS 1" >>confdefs.h
$as_echo "#define _REENTRANT 1" >>confdefs.h
@@ -17179,6 +17180,9 @@ $as_echo "#define SUNOS53_SHARED_LIB 1" >>confdefs.h
ia64-*-*)
machdep="ia64_save_regs_in_stack.lo"
;;
+ e2k-*-*)
+ machdep="e2k_save_regs_in_stack.lo"
+ ;;
*-*-nacl*)
$as_echo "#define NO_EXECUTE_PERMISSION 1" >>confdefs.h
diff --git a/configure.ac b/configure.ac
index 9a2951e..2d705b2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -188,7 +188,8 @@ case "$THREADS" in
AC_CHECK_LIB(pthread, pthread_self, THREADDLLIBS="-lpthread",,)
case "$host" in
x86-*-linux* | ia64-*-linux* | i586-*-linux* | i686-*-linux* \
- | x86_64-*-linux* | alpha-*-linux* | powerpc*-*-linux* | sparc*-*-linux*)
+ | x86_64-*-linux* | alpha-*-linux* | powerpc*-*-linux* | sparc*-*-linux* \
+ | e2k-*-linux*)
AC_DEFINE(GC_LINUX_THREADS)
AC_DEFINE(_REENTRANT)
if test "${enable_parallel_mark}" != no; then
@@ -661,6 +662,9 @@ case "$host" in
ia64-*-*)
machdep="ia64_save_regs_in_stack.lo"
;;
+ e2k-*-*)
+ machdep="e2k_save_regs_in_stack.lo"
+ ;;
*-*-nacl*)
AC_DEFINE(NO_EXECUTE_PERMISSION)
;;
diff --git a/e2k_save_regs_in_stack.c b/e2k_save_regs_in_stack.c
new file mode 100644
index 0000000..e32e5fb
--- /dev/null
+++ b/e2k_save_regs_in_stack.c
@@ -0,0 +1,88 @@
+#include <errno.h>
+#include <error.h>
+#include <stdint.h>
+#include <sys/syscall.h>
+#include <asm/e2k_syswork.h>
+#include "private/gc_priv.h"
+
+#define VA_SIZE 48
+#define VA_MSB (VA_SIZE - 1)
+#define E2K_PSHTP_SIZE 12
+
+typedef struct e2k_rwap_lo_fields {
+ uint64_t base : VA_SIZE; /* [VA_MSB:0] */
+ uint64_t other : 16; /* [64:VA_SIZE] */
+} e2k_rwap_lo_fields_t;
+
+typedef union e2k_rwap_lo_struct {
+ e2k_rwap_lo_fields_t fields;
+ uint64_t word;
+} e2k_rwap_lo_struct_t;
+
+typedef struct e2k_rwap_hi_fields {
+ uint64_t curptr : 32; /* [31:0] */
+ uint64_t size : 32; /* [63:32] */
+} e2k_rwap_hi_fields_t;
+
+typedef union e2k_rwap_hi_struct {
+ e2k_rwap_hi_fields_t fields;
+ uint64_t word;
+} e2k_rwap_hi_struct_t;
+
+#define get_stack_index(ps) \
+{ \
+ e2k_rwap_lo_struct_t psp_lo; \
+ e2k_rwap_hi_struct_t psp_hi; \
+ uint64_t pshtp; \
+ char tmp = 0, val = 0; \
+ asm volatile ( \
+ "1:\n\t" \
+ "ldb [ %[tmp] + 0x0 ] 0x7, %[val]\n\t" \
+ "rrd %%pshtp, %[pshtp]\n\t" \
+ "rrd %%psp.lo, %[psp_lo]\n\t" \
+ "rrd %%psp.hi, %[psp_hi]\n" \
+ "{\n\t" \
+ "stb [ %[tmp] + 0x0 ] 0x2, %[val]\n\t" \
+ "ibranch 1b ? %%MLOCK\n" \
+ "}\n" \
+ : [val] "=&r" (val), \
+ [psp_lo] "=&r" (psp_lo.word), \
+ [psp_hi] "=&r" (psp_hi.word), \
+ [pshtp] "=&r" (pshtp) \
+ : [tmp] "r" (&tmp)); \
+ *ps = psp_lo.fields.base + \
+ psp_hi.fields.curptr + \
+ 2 * ((uint64_t)(((int64_t)(pshtp) << \
+ (64 - E2K_PSHTP_SIZE)) >> \
+ (64 - E2K_PSHTP_SIZE))); \
+}
+
+size_t GC_get_procedure_stack(ptr_t *ps_buf) {
+ uint64_t ps;
+ uint64_t current_size, ps_size;
+ int ret;
+ get_stack_index(&ps);
+ while (-1 == syscall(__NR_access_hw_stacks,
+ E2K_READ_PROCEDURE_STACK,
+ &ps, NULL, 0, &ps_size) &&
+ errno == EAGAIN)
+ get_stack_index(&ps);
+ *ps_buf = realloc(*ps_buf, ps_size);
+ if (!*ps_buf)
+ error(ENOMEM, ENOMEM, "Could not allocate memory for procedure stack.");
+ while (-1 == (ret = syscall(__NR_access_hw_stacks,
+ E2K_READ_PROCEDURE_STACK, &ps,
+ *ps_buf, ps_size, ¤t_size)) &&
+ errno == EAGAIN)
+ get_stack_index(&ps);
+ if (ret || current_size != ps_size)
+ error(1, 0, "Could not read procedure stack.");
+ return ps_size;
+}
+
+ptr_t GC_save_regs_in_stack(void) {
+ uint64_t ps;
+ asm volatile("\tflushr\n");
+ get_stack_index(&ps);
+ return (ptr_t)ps;
+}
diff --git a/include/gc.h b/include/gc.h
index 690b4a0..9383aba 100644
--- a/include/gc.h
+++ b/include/gc.h
@@ -1265,8 +1265,13 @@ GC_API int GC_CALL GC_invoke_finalizers(void);
/* The function is sometimes called keep_alive in other */
/* settings. */
#if defined(__GNUC__) && !defined(__INTEL_COMPILER)
+#if defined(__e2k__)
+# define GC_reachable_here(ptr) \
+ __asm__ __volatile__(" " : : "r"(ptr) : "memory")
+#else
# define GC_reachable_here(ptr) \
__asm__ __volatile__(" " : : "X"(ptr) : "memory")
+#endif
#else
GC_API void GC_CALL GC_noop1(GC_word);
# define GC_reachable_here(ptr) GC_noop1((GC_word)(ptr))
@@ -1344,7 +1349,7 @@ GC_API void * GC_CALL GC_call_with_alloc_lock(GC_fn_type /* fn */,
/* platforms this contains just a single address. */
struct GC_stack_base {
void * mem_base; /* Base of memory stack. */
-# if defined(__ia64) || defined(__ia64__) || defined(_M_IA64)
+# if defined(__ia64) || defined(__ia64__) || defined(_M_IA64) || defined(__e2k__)
void * reg_base; /* Base of separate register stack. */
# endif
};
diff --git a/include/private/gc_priv.h b/include/private/gc_priv.h
index 9080f05..49d5f16 100644
--- a/include/private/gc_priv.h
+++ b/include/private/gc_priv.h
@@ -1566,7 +1566,7 @@ struct GC_traced_stack_sect_s {
/* NULL if no such "frame" active. */
#endif /* !THREADS */
-#ifdef IA64
+#if defined(IA64) || defined(E2K)
/* Similar to GC_push_all_stack_sections() but for IA-64 registers store. */
GC_INNER void GC_push_all_register_sections(ptr_t bs_lo, ptr_t bs_hi,
int eager, struct GC_traced_stack_sect_s *traced_stack_sect);
@@ -1699,10 +1699,26 @@ GC_EXTERN void (*GC_push_typed_structures)(void);
GC_INNER void GC_with_callee_saves_pushed(void (*fn)(ptr_t, void *),
volatile ptr_t arg);
-#if defined(SPARC) || defined(IA64)
+#if defined(SPARC) || defined(IA64) || defined(E2K)
/* Cause all stacked registers to be saved in memory. Return a */
/* pointer to the top of the corresponding memory stack. */
ptr_t GC_save_regs_in_stack(void);
+ #ifdef E2K
+ /* Copy full procedure stack to buffer. Get tag of target memory. */
+ size_t GC_get_procedure_stack(ptr_t *);
+ #ifdef __ptr64__
+ #define LOAD_TAGGED_VALUE(ptr, tag) ({ \
+ ptr_t val; \
+ asm volatile ( "\n\t" \
+ "ldd,sm %[adr], 0x0, %[val]\n\t" \
+ "gettagd %[val], %[tag]\n" \
+ : [val] "=r" (val), [tag] "=r" (tag) \
+ : [adr] "r" (ptr)); \
+ val; })
+ #else
+ #error "Unsupported march for e2k target"
+ #endif
+ #endif
#endif
/* Push register contents onto mark stack. */
@@ -1754,7 +1770,7 @@ GC_INNER void GC_cond_register_dynamic_libraries(void);
/* Machine dependent startup routines */
ptr_t GC_get_main_stack_base(void); /* Cold end of stack. */
-#ifdef IA64
+#if defined(IA64) || defined(E2K)
GC_INNER ptr_t GC_get_register_stack_base(void);
/* Cold end of register stack. */
#endif
@@ -2304,7 +2320,7 @@ GC_EXTERN signed_word GC_bytes_found;
GC_EXTERN GC_bool GC_dont_query_stack_min;
/* Defined and set in os_dep.c. */
# endif
-#elif defined(IA64)
+#elif defined(IA64) || defined(E2K)
GC_EXTERN ptr_t GC_save_regs_ret_val; /* defined in mach_dep.c. */
/* Previously set to backing store pointer. */
#endif /* !THREADS */
@@ -2584,7 +2600,7 @@ GC_INNER void *GC_store_debug_info_inner(void *p, word sz, const char *str,
# define NEED_FIND_LIMIT
#endif
-#if (defined(SVR4) || defined(AIX) || defined(DGUX) \
+#if (defined(SVR4) || defined(AIX) || defined(DGUX) || defined(E2K) \
|| (defined(LINUX) && defined(SPARC))) && !defined(PCR)
# define NEED_FIND_LIMIT
#endif
diff --git a/include/private/gcconfig.h b/include/private/gcconfig.h
index 693a329..a9e8785 100644
--- a/include/private/gcconfig.h
+++ b/include/private/gcconfig.h
@@ -323,6 +323,10 @@
# define AARCH64
# define mach_type_known
# endif
+# if defined(LINUX) && defined(__e2k__)
+# define E2K
+# define mach_type_known
+# endif
# if defined(LINUX) && (defined(__arm) || defined(__arm__))
# define ARM32
# define mach_type_known
@@ -655,6 +659,7 @@
/* S390 ==> 390-like machine */
/* running LINUX */
/* AARCH64 ==> ARM AArch64 */
+ /* E2K ==> Elbrus 2000 */
/* ARM32 ==> Intel StrongARM */
/* IA64 ==> Intel IPF */
/* (e.g. Itanium) */
@@ -803,6 +808,7 @@
&& !defined(__INTEL_COMPILER) && !defined(__PATHCC__) \
&& !defined(__FUJITSU) /* for FX10 system */ \
&& !(defined(POWERPC) && defined(DARWIN)) /* for MacOS X 10.3.9 */ \
+ && !defined(__e2k__) \
&& !defined(RTEMS) \
&& !defined(__ARMCC_VERSION) /* does not exist in armcc gnu emu */ \
&& !defined(__clang__) /* since no-op in clang (3.0) */
@@ -2225,6 +2231,26 @@
# endif
# endif
+# ifdef E2K
+# define MACH_TYPE "E2K"
+# define CPP_WORDSZ 64
+# define ALIGNMENT 8
+# ifndef HBLKSIZE
+# define HBLKSIZE 4096
+# endif
+# ifdef LINUX
+# define OS_TYPE "LINUX"
+# define LINUX_STACKBOTTOM
+# define DYNAMIC_LOADING
+ extern int __dso_handle[];
+ extern int _end[];
+# define DATASTART ((ptr_t)__dso_handle)
+# define DATAEND ((ptr_t)_end)
+ extern ptr_t GC_register_stackbottom;
+# define BACKING_STORE_BASE GC_register_stackbottom
+# endif
+# endif
+
# ifdef ARM32
# if defined(NACL)
# define MACH_TYPE "NACL"
diff --git a/include/private/pthread_support.h b/include/private/pthread_support.h
index 1bdb326..8a7f0eb 100644
--- a/include/private/pthread_support.h
+++ b/include/private/pthread_support.h
@@ -99,7 +99,7 @@ typedef struct GC_Thread_Rep {
/* valid only if the thread is blocked; */
/* non-NULL value means already set. */
# endif
-# ifdef IA64
+# if defined(IA64) || defined(E2K)
ptr_t backing_store_end;
ptr_t backing_store_ptr;
# endif
diff --git a/mach_dep.c b/mach_dep.c
index 14b4c9d..d61ed69 100644
--- a/mach_dep.c
+++ b/mach_dep.c
@@ -90,7 +90,7 @@
#endif /* MACOS && __MWERKS__ */
-# if defined(SPARC) || defined(IA64)
+# if defined(SPARC) || defined(IA64) || defined(E2K)
/* Value returned from register flushing routine; either sp (SPARC) */
/* or ar.bsp (IA64). */
GC_INNER ptr_t GC_save_regs_ret_val = NULL;
@@ -282,7 +282,7 @@ GC_INNER void GC_with_callee_saves_pushed(void (*fn)(ptr_t, void *),
ABORT("feenableexcept failed");
# endif
# endif /* GETCONTEXT_FPU_EXCMASK_BUG */
-# if defined(SPARC) || defined(IA64)
+# if defined(SPARC) || defined(IA64) || defined(E2K)
/* On a register window machine, we need to save register */
/* contents on the stack for this to work. This may already be */
/* subsumed by the getcontext() call. */
diff --git a/mark.c b/mark.c
index bf28a8a..e8559f6 100644
--- a/mark.c
+++ b/mark.c
@@ -738,7 +738,13 @@ GC_INNER mse * GC_mark_from(mse *mark_stack_top, mse *mark_stack,
credit -= WORDS_TO_BYTES(WORDSZ/2); /* guess */
while (descr != 0) {
if ((descr & SIGNB) != 0) {
+ #ifdef E2K
+ int tag;
+ current = (word)LOAD_TAGGED_VALUE(current_p, tag);
+ if (tag == 0) {
+ #else
current = *(word *)current_p;
+ #endif
FIXUP_POINTER(current);
if (current >= (word)least_ha && current < (word)greatest_ha) {
PREFETCH((ptr_t)current);
@@ -752,6 +758,9 @@ GC_INNER mse * GC_mark_from(mse *mark_stack_top, mse *mark_stack,
PUSH_CONTENTS((ptr_t)current, mark_stack_top,
mark_stack_limit, current_p);
}
+ #ifdef E2K
+ }
+ #endif
}
descr <<= 1;
current_p += sizeof(word);
@@ -827,7 +836,7 @@ GC_INNER mse * GC_mark_from(mse *mark_stack_top, mse *mark_stack,
{
# define PREF_DIST 4
-# ifndef SMALL_CONFIG
+# if !defined(SMALL_CONFIG) && !defined(E2K)
word deferred;
/* Try to prefetch the next pointer to be examined ASAP. */
@@ -864,7 +873,13 @@ GC_INNER mse * GC_mark_from(mse *mark_stack_top, mse *mark_stack,
/* Empirically, unrolling this loop doesn't help a lot. */
/* Since PUSH_CONTENTS expands to a lot of code, */
/* we don't. */
+ #ifdef E2K
+ int tag;
+ current = (word)LOAD_TAGGED_VALUE(current_p, tag);
+ if (tag == 0) {
+ #else
current = *(word *)current_p;
+ #endif
FIXUP_POINTER(current);
PREFETCH(current_p + PREF_DIST*CACHE_LINE_SIZE);
if (current >= (word)least_ha && current < (word)greatest_ha) {
@@ -881,10 +896,13 @@ GC_INNER mse * GC_mark_from(mse *mark_stack_top, mse *mark_stack,
PUSH_CONTENTS((ptr_t)current, mark_stack_top,
mark_stack_limit, current_p);
}
+ #ifdef E2K
+ }
+ #endif
current_p += ALIGNMENT;
}
-# ifndef SMALL_CONFIG
+# if !defined(SMALL_CONFIG) && !defined(E2K)
/* We still need to mark the entry we previously prefetched. */
/* We already know that it passes the preliminary pointer */
/* validity test. */
@@ -1576,7 +1594,13 @@ GC_API void GC_CALL GC_push_all_eager(char *bottom, char *top)
lim = t - 1 /* longword */;
for (p = b; (word)p <= (word)lim;
p = (word *)(((ptr_t)p) + ALIGNMENT)) {
+ #ifdef E2K
+ int tag;
+ register word q = (word)LOAD_TAGGED_VALUE(p, tag);
+ if (tag == 0)
+ #else
register word q = *p;
+ #endif
GC_PUSH_ONE_STACK(q, p);
}
# undef GC_greatest_plausible_heap_addr
diff --git a/mark_rts.c b/mark_rts.c
index a85a43c..d654095 100644
--- a/mark_rts.c
+++ b/mark_rts.c
@@ -632,11 +632,12 @@ STATIC void GC_push_conditional_with_exclusions(ptr_t bottom, ptr_t top,
}
}
-#ifdef IA64
+#if defined(IA64) || defined(E2K)
/* Similar to GC_push_all_stack_sections() but for IA-64 registers store. */
GC_INNER void GC_push_all_register_sections(ptr_t bs_lo, ptr_t bs_hi,
int eager, struct GC_traced_stack_sect_s *traced_stack_sect)
{
+ #ifndef E2K
while (traced_stack_sect != NULL) {
ptr_t frame_bs_lo = traced_stack_sect -> backing_store_end;
GC_ASSERT((word)frame_bs_lo <= (word)bs_hi);
@@ -648,6 +649,7 @@ STATIC void GC_push_conditional_with_exclusions(ptr_t bottom, ptr_t top,
bs_hi = traced_stack_sect -> saved_backing_store_ptr;
traced_stack_sect = traced_stack_sect -> prev;
}
+ #endif
GC_ASSERT((word)bs_lo <= (word)bs_hi);
if (eager) {
GC_push_all_eager(bs_lo, bs_hi);
@@ -828,6 +830,19 @@ STATIC void GC_push_current_stack(ptr_t cold_gc_frame,
/* don't have to worry about the boundary. */
}
# endif
+# ifdef E2K
+ /* We also need to push procedure stack store. */
+ /* Procedure stack grows up, so we can't use */
+ /* GC_push_all_stack_partially_eager. */
+ {
+ ptr_t bs_lo = NULL, bs_hi;
+ size_t stack_size = GC_get_procedure_stack(&bs_lo);
+ bs_hi = bs_lo + stack_size;
+ GC_push_all_register_sections(bs_lo, bs_hi, TRUE,
+ GC_traced_stack_sect);
+ free(bs_lo);
+ }
+# endif
# endif /* !THREADS */
}
diff --git a/misc.c b/misc.c
index a0b0bad..efe5ef4 100644
--- a/misc.c
+++ b/misc.c
@@ -81,7 +81,7 @@ GC_INNER GC_bool GC_debugging_started = FALSE;
ptr_t GC_stackbottom = 0;
-#ifdef IA64
+#if defined(IA64) || defined(E2K)
ptr_t GC_register_stackbottom = 0;
#endif
@@ -1186,11 +1186,11 @@ GC_API void GC_CALL GC_init(void)
|| defined(GC_WIN32_THREADS) || defined(GC_SOLARIS_THREADS)
if (GC_stackbottom == 0) {
GC_stackbottom = GC_get_main_stack_base();
-# if (defined(LINUX) || defined(HPUX)) && defined(IA64)
+# if (defined(LINUX) || defined(HPUX)) && defined(IA64) || defined(E2K)
GC_register_stackbottom = GC_get_register_stack_base();
# endif
} else {
-# if (defined(LINUX) || defined(HPUX)) && defined(IA64)
+# if (defined(LINUX) || defined(HPUX)) && defined(IA64) || defined(E2K)
if (GC_register_stackbottom == 0) {
WARN("GC_register_stackbottom should be set with GC_stackbottom\n", 0);
/* The following may fail, since we may rely on */
@@ -2036,7 +2036,7 @@ STATIC void GC_do_blocking_inner(ptr_t data, void * context GC_ATTR_UNUSED)
struct blocking_data * d = (struct blocking_data *) data;
GC_ASSERT(GC_is_initialized);
GC_ASSERT(GC_blocked_sp == NULL);
-# ifdef SPARC
+# ifdef SPARC || defined(E2K)
GC_blocked_sp = GC_save_regs_in_stack();
# else
GC_blocked_sp = (ptr_t) &d; /* save approx. sp */
@@ -2047,7 +2047,7 @@ STATIC void GC_do_blocking_inner(ptr_t data, void * context GC_ATTR_UNUSED)
d -> client_data = (d -> fn)(d -> client_data);
-# ifdef SPARC
+# ifdef SPARC || defined(E2K)
GC_ASSERT(GC_blocked_sp != NULL);
# else
GC_ASSERT(GC_blocked_sp == (ptr_t)(&d));
diff --git a/os_dep.c b/os_dep.c
index 1be3009..cf298a5 100644
--- a/os_dep.c
+++ b/os_dep.c
@@ -1002,7 +1002,14 @@ GC_INNER size_t GC_page_size = 0;
}
result -= MIN_PAGE_SIZE; /* no underflow expected */
}
+#ifdef E2K
+ {
+ char tmp;
+ asm volatile("ldb %1,0,%0":"=r"(tmp):"r"(result): "memory");
+ }
+#else
GC_noop1((word)(*result));
+#endif
}
}
GC_reset_fault_handler();
@@ -1084,6 +1091,13 @@ GC_INNER size_t GC_page_size = 0;
return result;
}
# endif /* IA64 */
+# ifdef E2K
+ GC_INNER ptr_t GC_get_register_stack_base(void)
+ {
+ ptr_t result = GC_find_limit(GC_save_regs_in_stack(), FALSE);
+ return result;
+ }
+# endif
STATIC ptr_t GC_linux_main_stack_base(void)
{
@@ -1354,6 +1368,14 @@ GC_INNER size_t GC_page_size = 0;
RESTORE_CANCEL(cancel_state);
}
UNLOCK();
+# endif
+# ifdef E2K
+ LOCK();
+ {
+ ptr_t bsp = GC_save_regs_in_stack();
+ b->reg_base = GC_find_limit(bsp, FALSE);
+ }
+ UNLOCK();
# endif
return GC_SUCCESS;
}
diff --git a/pthread_stop_world.c b/pthread_stop_world.c
index bea5b65..fa1611c 100644
--- a/pthread_stop_world.c
+++ b/pthread_stop_world.c
@@ -225,7 +225,7 @@ STATIC void GC_suspend_handler_inner(ptr_t dummy, void *context);
ABORT("Bad signal in suspend_handler");
}
-# if defined(IA64) || defined(HP_PA) || defined(M68K)
+# if defined(IA64) || defined(HP_PA) || defined(M68K) || defined(E2K)
GC_with_callee_saves_pushed(GC_suspend_handler_inner, NULL);
# else
/* We believe that in all other cases the full context is already */
@@ -305,6 +305,14 @@ STATIC void GC_suspend_handler_inner(ptr_t dummy GC_ATTR_UNUSED,
# ifdef IA64
me -> backing_store_ptr = GC_save_regs_in_stack();
# endif
+# ifdef E2K
+ ptr_t stack = NULL;
+ size_t stack_size;
+ GC_save_regs_in_stack();
+ stack_size = GC_get_procedure_stack(&stack);
+ me->backing_store_ptr = stack;
+ me->backing_store_end = stack + stack_size;
+# endif
/* Tell the thread that wants to stop the world that this */
/* thread has been stopped. Note that sem_post() is */
@@ -333,6 +341,12 @@ STATIC void GC_suspend_handler_inner(ptr_t dummy GC_ATTR_UNUSED,
/* Simply dropping the sigsuspend call should be safe, but is */
/* unlikely to be efficient. */
+# ifdef E2K
+ stack = me->backing_store_ptr;
+ me->backing_store_ptr = NULL;
+ me->backing_store_end = NULL;
+ free(stack);
+# endif
# ifdef DEBUG_THREADS
GC_log_printf("Continuing %p\n", (void *)self);
# endif
@@ -521,6 +535,10 @@ GC_INNER void GC_push_all_stacks(void)
ptr_t lo, hi;
/* On IA64, we also need to scan the register backing store. */
IF_IA64(ptr_t bs_lo; ptr_t bs_hi;)
+#ifdef E2K
+ size_t stack_size;
+ ptr_t bs_lo, bs_hi;
+#endif
struct GC_traced_stack_sect_s *traced_stack_sect;
pthread_t self = pthread_self();
word total_size = 0;
@@ -537,6 +555,13 @@ GC_INNER void GC_push_all_stacks(void)
traced_stack_sect = p -> traced_stack_sect;
if (THREAD_EQUAL(p -> id, self)) {
GC_ASSERT(!p->thread_blocked);
+# ifdef E2K
+ GC_save_regs_in_stack();
+ bs_lo = NULL;
+ stack_size = GC_get_procedure_stack(&bs_lo);
+ p->backing_store_ptr = bs_lo;
+ p->backing_store_end = bs_hi = bs_lo + stack_size;
+# endif
# ifdef SPARC
lo = (ptr_t)GC_save_regs_in_stack();
# else
@@ -563,9 +588,17 @@ GC_INNER void GC_push_all_stacks(void)
hi = GC_stackbottom;
IF_IA64(bs_lo = BACKING_STORE_BASE;)
}
+# ifdef E2K
+ bs_lo = p->backing_store_ptr;
+ bs_hi = p->backing_store_end;
+# endif
# ifdef DEBUG_THREADS
GC_log_printf("Stack for thread %p = [%p,%p)\n",
(void *)p->id, (void *)lo, (void *)hi);
+# ifdef E2K
+ GC_log_printf("Procedure stack for thread %p = [%p,%p)\n",
+ (void *)p->id, (void *)bs_lo, (void *)bs_hi);
+# endif
# endif
if (0 == lo) ABORT("GC_push_all_stacks: sp not set!");
if (p->altstack != NULL && (word)p->altstack <= (word)lo
@@ -586,7 +619,7 @@ GC_INNER void GC_push_all_stacks(void)
(ptr_t)(p -> stop_info.reg_storage + NACL_GC_REG_STORAGE_SIZE));
total_size += NACL_GC_REG_STORAGE_SIZE * sizeof(ptr_t);
# endif
-# ifdef IA64
+# if defined(IA64) || defined(E2K)
# ifdef DEBUG_THREADS
GC_log_printf("Reg stack for thread %p = [%p,%p)\n",
(void *)p->id, (void *)bs_lo, (void *)bs_hi);
@@ -597,6 +630,15 @@ GC_INNER void GC_push_all_stacks(void)
THREAD_EQUAL(p -> id, self),
traced_stack_sect);
total_size += bs_hi - bs_lo; /* bs_lo <= bs_hi */
+# ifdef E2K
+ if (THREAD_EQUAL(p->id, self)) {
+ bs_lo = p->backing_store_ptr;
+ p->backing_store_ptr = NULL;
+ p->backing_store_end = NULL;
+ free(bs_lo);
+ bs_lo = bs_hi = NULL;
+ }
+# endif
# endif
}
}
diff --git a/pthread_support.c b/pthread_support.c
index 3dc7b59..0aa7e91 100644
--- a/pthread_support.c
+++ b/pthread_support.c
@@ -1328,6 +1328,9 @@ GC_INNER void GC_do_blocking_inner(ptr_t data, void * context GC_ATTR_UNUSED)
# if defined(SPARC) || defined(IA64)
ptr_t stack_ptr = GC_save_regs_in_stack();
# endif
+# ifdef E2K
+ GC_save_regs_in_stack();
+# endif
# if defined(GC_DARWIN_THREADS) && !defined(DARWIN_DONT_PARSE_STACK)
GC_bool topOfStackUnset = FALSE;
# endif
diff --git a/tests/test.c b/tests/test.c
index 067ead4..15c837c 100644
--- a/tests/test.c
+++ b/tests/test.c
@@ -1422,7 +1422,7 @@ void run_one_test(void)
FAIL;
}
if (!TEST_FAIL_COUNT(1)) {
-# if!(defined(POWERPC) || defined(IA64)) || defined(M68K)
+# if!(defined(POWERPC) || defined(IA64)) || defined(M68K) || defined(E2K)
/* On POWERPCs function pointers point to a descriptor in the */
/* data segment, so there should have been no failures. */
/* The same applies to IA64. Something similar seems to */
--
2.17.1