* fix hyprutils to find pixman includes
[t2sde.git] / architecture / ia64 / package / ruby / ia64.patch
blob865f2f2d047cd20d034beeb6fa4f0305bb45822f
1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # T2 SDE: architecture/ia64/package/*/ia64.patch
3 # Copyright (C) 2024 The T2 SDE Project
4 #
5 # This Copyright note is generated by scripts/Create-CopyPatch,
6 # more information can be found in the files COPYING and README.
7 #
8 # This patch file is dual-licensed. It is available under the license the
9 # patched project is licensed under, as long as it is an OpenSource license
10 # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
11 # of the GNU General Public License version 2 as used by the T2 SDE.
12 # --- T2-COPYRIGHT-NOTE-END ---
14 Revert ia64 removal d17344cfc56edc4599252041b3ec0d46af0851fd
16 miniruby crashes though, except when run in gdb, yay, likely
17 native fiber related: 6c6bf9ffcbfeb8be9d9c342e7604b74ec819e88a
19 diff -urN --exclude '*orig' ruby-3.1.5/common.mk ruby-3.1.5-ia64/common.mk
20 --- ruby-3.1.5/common.mk 2024-04-23 12:20:59.000000000 +0200
21 +++ ruby-3.1.5-ia64/common.mk 2024-05-30 11:24:24.908189690 +0200
22 @@ -997,6 +997,8 @@
23 strlcpy.$(OBJEXT): {$(VPATH)}strlcpy.c
24 strstr.$(OBJEXT): {$(VPATH)}strstr.c
25 tgamma.$(OBJEXT): {$(VPATH)}tgamma.c
26 +ia64.$(OBJEXT): {$(VPATH)}ia64.s
27 + $(CC) $(CFLAGS) -c $<
29 .coroutine_obj $(COROUTINE_OBJ): \
30 {$(VPATH)}$(COROUTINE_SRC) \
31 diff -urN --exclude '*orig' ruby-3.1.5/configure.ac ruby-3.1.5-ia64/configure.ac
32 --- ruby-3.1.5/configure.ac 2024-04-23 12:20:59.000000000 +0200
33 +++ ruby-3.1.5-ia64/configure.ac 2024-05-30 11:18:37.540127727 +0200
34 @@ -1935,6 +1935,24 @@
36 AC_FUNC_MEMCMP
38 +# http://sources.redhat.com/ml/libc-hacker/2005-08/msg00008.html
39 +# Debian GNU/Linux Etch's libc6.1 2.3.6.ds1-13etch5 has this problem.
40 +# Debian GNU/Linux Lenny's libc6.1 2.7-10 has no problem.
41 +AC_CACHE_CHECK(for broken erfc of glibc-2.3.6 on IA64, rb_cv_broken_glibc_ia64_erfc,
42 + [AC_TRY_RUN([
43 +#include <math.h>
44 +int
45 +main()
47 + erfc(10000.0);
48 + return 0;
50 +],
51 + rb_cv_broken_glibc_ia64_erfc=no,
52 + rb_cv_broken_glibc_ia64_erfc=yes,
53 + rb_cv_broken_glibc_ia64_erfc=no)])
54 +AS_CASE([$rb_cv_broken_glibc_ia64_erfc],[yes],[ac_cv_func_erf=no])
56 AS_CASE(["$target_os"],[freebsd*],[
57 AC_DEFINE(BROKEN_CLOSE)
58 AC_REPLACE_FUNCS(close)
59 @@ -2452,6 +2470,21 @@
60 ])])
63 +AS_IF([test x"$target_cpu" = xia64], [
64 + AC_LIBOBJ([ia64])
65 + AC_CACHE_CHECK(for __libc_ia64_register_backing_store_base,
66 + rb_cv___libc_ia64_register_backing_store_base,
67 + [rb_cv___libc_ia64_register_backing_store_base=no
68 + AC_TRY_LINK(
69 + [extern unsigned long __libc_ia64_register_backing_store_base;],
70 + [unsigned long p = __libc_ia64_register_backing_store_base;
71 + printf("%ld\n", p);],
72 + [rb_cv___libc_ia64_register_backing_store_base=yes])])
73 + AS_IF([test $rb_cv___libc_ia64_register_backing_store_base = yes], [
74 + AC_DEFINE(HAVE___LIBC_IA64_REGISTER_BACKING_STORE_BASE)
75 + ])
76 +])
78 AC_CACHE_CHECK(whether right shift preserve sign bit, rb_cv_rshift_sign,
79 [AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([], [(-1==(-1>>1))])],
80 rb_cv_rshift_sign=yes,
81 diff -urN --exclude '*orig' ruby-3.1.5/cont.c ruby-3.1.5-ia64/cont.c
82 --- ruby-3.1.5/cont.c 2024-04-23 12:20:59.000000000 +0200
83 +++ ruby-3.1.5-ia64/cont.c 2024-05-30 11:28:52.676237454 +0200
84 @@ -204,6 +204,11 @@
85 VALUE *stack;
86 VALUE *stack_src;
87 size_t stack_size;
88 +#ifdef __ia64
89 + VALUE *register_stack;
90 + VALUE *register_stack_src;
91 + int register_stack_size;
92 +#endif
93 } machine;
94 rb_execution_context_t saved_ec;
95 rb_jmpbuf_t jmpbuf;
96 @@ -373,6 +378,12 @@
97 if (vacancy) {
98 fiber_pool_vacancy_remove(vacancy);
100 +#ifdef __ia64
101 + if (cont->machine.register_stack) {
102 + rb_gc_mark_locations(cont->machine.register_stack,
103 + cont->machine.register_stack + cont->machine.register_stack_size);
105 +#endif
107 return vacancy;
109 @@ -798,6 +809,10 @@
110 sec->machine.stack_start = fiber->stack.current;
111 sec->machine.stack_maxsize = fiber->stack.available;
113 +#ifdef __ia64
114 + sec->machine.register_stack_maxsize = sec->machine.stack_maxsize;
115 +#endif
117 fiber->context.argument = (void*)fiber;
119 return vm_stack;
120 @@ -988,6 +1003,9 @@
121 fiber_stack_release(fiber);
124 +#ifdef __ia64
125 + RUBY_FREE_UNLESS_NULL(cont->machine.register_stack);
126 +#endif
127 RUBY_FREE_UNLESS_NULL(cont->saved_vm_stack.ptr);
129 if (mjit_enabled) {
130 @@ -1018,7 +1036,11 @@
131 if (cont->machine.stack) {
132 size += cont->machine.stack_size * sizeof(*cont->machine.stack);
135 +#ifdef __ia64
136 + if (cont->machine.register_stack) {
137 + size += cont->machine.register_stack_size * sizeof(*cont->machine.register_stack);
139 +#endif
140 return size;
143 @@ -1114,6 +1136,9 @@
144 size_t size;
146 SET_MACHINE_STACK_END(&th->ec->machine.stack_end);
147 +#ifdef __ia64
148 + th->ec->machine.register_stack_end = rb_ia64_bsp();
149 +#endif
151 if (th->ec->machine.stack_start > th->ec->machine.stack_end) {
152 size = cont->machine.stack_size = th->ec->machine.stack_start - th->ec->machine.stack_end;
153 @@ -1133,6 +1158,20 @@
155 FLUSH_REGISTER_WINDOWS;
156 MEMCPY(cont->machine.stack, cont->machine.stack_src, VALUE, size);
158 +#ifdef __ia64
159 + rb_ia64_flushrs();
160 + size = cont->machine.register_stack_size = th->ec->machine.register_stack_end - th->ec->machine.register_stack_start;
161 + cont->machine.register_stack_src = th->ec->machine.register_stack_start;
162 + if (cont->machine.register_stack) {
163 + REALLOC_N(cont->machine.register_stack, VALUE, size);
165 + else {
166 + cont->machine.register_stack = ALLOC_N(VALUE, size);
169 + MEMCPY(cont->machine.register_stack, cont->machine.register_stack_src, VALUE, size);
170 +#endif
173 static const rb_data_type_t cont_data_type = {
174 @@ -1154,6 +1193,10 @@
175 /* saved_ec->machine.stack_end should be NULL */
176 /* because it may happen GC afterward */
177 sec->machine.stack_end = NULL;
179 +#ifdef __ia64
180 + sec->machine.register_stack_end = NULL;
181 +#endif
184 static void
185 @@ -1428,11 +1471,53 @@
186 VALUE, cont->machine.stack_size);
189 +#ifdef __ia64
190 + if (cont->machine.register_stack_src) {
191 + MEMCPY(cont->machine.register_stack_src, cont->machine.register_stack,
192 + VALUE, cont->machine.register_stack_size);
194 +#endif
196 ruby_longjmp(cont->jmpbuf, 1);
199 NORETURN(NOINLINE(static void cont_restore_0(rb_context_t *, VALUE *)));
201 +#ifdef __ia64
202 +#define C(a) rse_##a##0, rse_##a##1, rse_##a##2, rse_##a##3, rse_##a##4
203 +#define E(a) rse_##a##0= rse_##a##1= rse_##a##2= rse_##a##3= rse_##a##4
204 +static volatile int C(a), C(b), C(c), C(d), C(e);
205 +static volatile int C(f), C(g), C(h), C(i), C(j);
206 +static volatile int C(k), C(l), C(m), C(n), C(o);
207 +static volatile int C(p), C(q), C(r), C(s), C(t);
208 +#if 0
209 +{/* the above lines make cc-mode.el confused so much */}
210 +#endif
211 +int rb_dummy_false = 0;
212 +NORETURN(NOINLINE(static void register_stack_extend(rb_context_t *, VALUE *, VALUE *)));
213 +static void
214 +register_stack_extend(rb_context_t *cont, VALUE *vp, VALUE *curr_bsp)
216 + if (rb_dummy_false) {
217 + /* use registers as much as possible */
218 + E(a) = E(b) = E(c) = E(d) = E(e) =
219 + E(f) = E(g) = E(h) = E(i) = E(j) =
220 + E(k) = E(l) = E(m) = E(n) = E(o) =
221 + E(p) = E(q) = E(r) = E(s) = E(t) = 0;
222 + E(a) = E(b) = E(c) = E(d) = E(e) =
223 + E(f) = E(g) = E(h) = E(i) = E(j) =
224 + E(k) = E(l) = E(m) = E(n) = E(o) =
225 + E(p) = E(q) = E(r) = E(s) = E(t) = 0;
227 + if (curr_bsp < cont->machine.register_stack_src+cont->machine.register_stack_size) {
228 + register_stack_extend(cont, vp, (VALUE*)rb_ia64_bsp());
230 + cont_restore_0(cont, vp);
232 +#undef C
233 +#undef E
234 +#endif
236 static void
237 cont_restore_0(rb_context_t *cont, VALUE *addr_in_prev_frame)
239 @@ -1481,6 +1566,9 @@
241 cont_restore_1(cont);
243 +#ifdef __ia64
244 +#define cont_restore_0(cont, vp) register_stack_extend((cont), (vp), (VALUE*)rb_ia64_bsp())
245 +#endif
248 * Document-class: Continuation
249 diff -urN --exclude '*orig' ruby-3.1.5/dln.c ruby-3.1.5-ia64/dln.c
250 --- ruby-3.1.5/dln.c 2024-04-23 12:20:59.000000000 +0200
251 +++ ruby-3.1.5-ia64/dln.c 2024-05-30 11:18:37.568127732 +0200
252 @@ -208,7 +208,7 @@
254 #endif
256 -#if defined(_AIX)
257 +#if defined(_AIX) && ! defined(_IA64)
258 static void
259 aix_loaderror(const char *pathname)
261 @@ -432,7 +432,7 @@
263 #endif /* hpux */
265 -#if defined(_AIX)
266 +#if defined(_AIX) && ! defined(_IA64)
267 #define DLN_DEFINED
269 void (*init_fct)(void);
270 diff -urN --exclude '*orig' ruby-3.1.5/ext/etc/etc.c ruby-3.1.5-ia64/ext/etc/etc.c
271 --- ruby-3.1.5/ext/etc/etc.c 2024-04-23 12:20:59.000000000 +0200
272 +++ ruby-3.1.5-ia64/ext/etc/etc.c 2024-05-30 11:18:37.576127733 +0200
273 @@ -788,6 +788,9 @@
274 # ifndef PROCESSOR_ARCHITECTURE_AMD64
275 # define PROCESSOR_ARCHITECTURE_AMD64 9
276 # endif
277 +# ifndef PROCESSOR_ARCHITECTURE_IA64
278 +# define PROCESSOR_ARCHITECTURE_IA64 6
279 +# endif
280 # ifndef PROCESSOR_ARCHITECTURE_INTEL
281 # define PROCESSOR_ARCHITECTURE_INTEL 0
282 # endif
283 @@ -799,6 +802,9 @@
284 case PROCESSOR_ARCHITECTURE_ARM:
285 mach = "ARM";
286 break;
287 + case PROCESSOR_ARCHITECTURE_IA64:
288 + mach = "IA64";
289 + break;
290 case PROCESSOR_ARCHITECTURE_INTEL:
291 mach = "x86";
292 break;
293 diff -urN --exclude '*orig' ruby-3.1.5/gc.c ruby-3.1.5-ia64/gc.c
294 --- ruby-3.1.5/gc.c 2024-04-23 12:20:59.000000000 +0200
295 +++ ruby-3.1.5-ia64/gc.c 2024-05-30 11:36:51.936322945 +0200
296 @@ -6110,7 +6110,11 @@
298 /* Marking */
300 +#ifdef __ia64
301 +#define SET_STACK_END (SET_MACHINE_STACK_END(&ec->machine.stack_end), ec->machine.register_stack_end = rb_ia64_bsp())
302 +#else
303 #define SET_STACK_END SET_MACHINE_STACK_END(&ec->machine.stack_end)
304 +#endif
306 #define STACK_START (ec->machine.stack_start)
307 #define STACK_END (ec->machine.stack_end)
308 @@ -6158,12 +6162,20 @@
309 static int
310 stack_check(rb_execution_context_t *ec, int water_mark)
312 + int ret;
313 SET_STACK_END;
315 size_t length = STACK_LENGTH;
316 size_t maximum_length = STACK_LEVEL_MAX - water_mark;
318 - return length > maximum_length;
319 + ret = length > maximum_length;
320 +#ifdef __ia64
321 + if (!ret) {
322 + ret = (VALUE*)rb_ia64_bsp() - ec->machine.register_stack_start >
323 + ec->machine.register_stack_maxsize/sizeof(VALUE) - water_mark;
325 +#endif
326 + return ret;
328 #else
329 #define stack_check(ec, water_mark) FALSE
330 @@ -6545,6 +6557,11 @@
332 gc_mark_locations(objspace, stack_start, stack_end, cb);
334 +#ifdef __ia64
335 + gc_mark_locations(objspace,
336 + ec->machine.register_stack_start,
337 + ec->machine.register_stack_end, cb);
338 +#endif
339 #if defined(__mc68000__)
340 gc_mark_locations(objspace,
341 (VALUE*)((char*)stack_start + 2),
342 @@ -7697,6 +7714,14 @@
343 return remembered_old_objects;
346 +#undef Init_stack
348 +void
349 +Init_stack(volatile VALUE *addr)
351 + ruby_init_stack(addr);
355 * call-seq:
356 * GC.verify_internal_consistency -> nil
357 diff -urN --exclude '*orig' ruby-3.1.5/gc.h ruby-3.1.5-ia64/gc.h
358 --- ruby-3.1.5/gc.h 2024-04-23 12:20:59.000000000 +0200
359 +++ ruby-3.1.5-ia64/gc.h 2024-05-30 11:40:09.200358132 +0200
360 @@ -18,9 +18,16 @@
361 #define USE_CONSERVATIVE_STACK_END
362 #endif
364 +#ifdef __ia64
365 +#define RB_GC_SAVE_MACHINE_REGISTER_STACK(th) \
366 + do{(th)->ec->machine.register_stack_end = rb_ia64_bsp();}while(0)
367 +#else
368 +#define RB_GC_SAVE_MACHINE_REGISTER_STACK(th)
369 +#endif
370 #define RB_GC_SAVE_MACHINE_CONTEXT(th) \
371 do { \
372 FLUSH_REGISTER_WINDOWS; \
373 + RB_GC_SAVE_MACHINE_REGISTER_STACK(th); \
374 setjmp((th)->ec->machine.regs); \
375 SET_MACHINE_STACK_END(&(th)->ec->machine.stack_end); \
376 } while (0)
377 diff -urN --exclude '*orig' ruby-3.1.5/ia64.S ruby-3.1.5-ia64/ia64.S
378 --- ruby-3.1.5/ia64.S 1970-01-01 01:00:00.000000000 +0100
379 +++ ruby-3.1.5-ia64/ia64.S 2024-05-30 11:18:37.592127736 +0200
380 @@ -0,0 +1,42 @@
381 +// rb_ia64_flushrs and rb_ia64_bsp is written in IA64 assembly language
382 +// because Intel Compiler for IA64 doesn't support inline assembly.
384 +// This file is based on following C program compiled by gcc.
386 +// void rb_ia64_flushrs(void) { __builtin_ia64_flushrs(); }
387 +// void *rb_ia64_bsp(void) { return __builtin_ia64_bsp(); }
389 +// Note that rb_ia64_flushrs and rb_ia64_bsp works in its own stack frame.
390 +// It's because BSP is updated by br.call/brl.call (not alloc instruction).
391 +// So rb_ia64_flushrs flushes stack frames including caller's one.
392 +// rb_ia64_bsp returns the address next to caller's register stack frame.
394 +// See also
395 +// Intel Itanium Architecture Software Developer's Manual
396 +// Volume 2: System Architecture.
398 + .file "ia64.c"
399 + .text
400 + .align 16
401 + .global rb_ia64_flushrs#
402 + .proc rb_ia64_flushrs#
403 +rb_ia64_flushrs:
404 + .prologue
405 + .body
406 + flushrs
407 + ;;
408 + nop.i 0
409 + br.ret.sptk.many b0
410 + .endp rb_ia64_flushrs#
411 + .align 16
412 + .global rb_ia64_bsp#
413 + .proc rb_ia64_bsp#
414 +rb_ia64_bsp:
415 + .prologue
416 + .body
417 + nop.m 0
418 + ;;
419 + mov r8 = ar.bsp
420 + br.ret.sptk.many b0
421 + .endp rb_ia64_bsp#
422 + .ident "GCC: (GNU) 3.3.5 (Debian 1:3.3.5-13)"
423 diff -urN --exclude '*orig' ruby-3.1.5/include/ruby/defines.h ruby-3.1.5-ia64/include/ruby/defines.h
424 --- ruby-3.1.5/include/ruby/defines.h 2024-04-23 12:20:59.000000000 +0200
425 +++ ruby-3.1.5-ia64/include/ruby/defines.h 2024-05-30 11:19:49.568140575 +0200
426 @@ -109,6 +109,10 @@
427 void rb_sparc_flush_register_windows(void);
428 RBIMPL_SYMBOL_EXPORT_END()
429 # define FLUSH_REGISTER_WINDOWS rb_sparc_flush_register_windows()
430 +#elif defined(__ia64)
431 +void *rb_ia64_bsp(void);
432 +void rb_ia64_flushrs(void);
433 +# define FLUSH_REGISTER_WINDOWS rb_ia64_flushrs()
434 #else
435 # define FLUSH_REGISTER_WINDOWS ((void)0)
436 #endif
437 diff -urN --exclude '*orig' ruby-3.1.5/include/ruby/internal/interpreter.h ruby-3.1.5-ia64/include/ruby/internal/interpreter.h
438 --- ruby-3.1.5/include/ruby/internal/interpreter.h 2024-04-23 12:20:59.000000000 +0200
439 +++ ruby-3.1.5-ia64/include/ruby/internal/interpreter.h 2024-05-30 11:22:22.408167838 +0200
440 @@ -67,6 +67,8 @@
442 void ruby_sysinit(int *argc, char ***argv);
447 * Calls ruby_setup() and check error.
449 @@ -141,7 +143,13 @@
451 * @param[in] addr A pointer somewhere on the stack, near its bottom.
453 -void ruby_init_stack(volatile VALUE *addr);
454 +#ifdef __ia64
455 +void ruby_init_stack(volatile VALUE* addr, void* bsp);
456 +#define ruby_init_stack(addr) ruby_init_stack((addr), rb_ia64_bsp())
457 +#else
458 +void ruby_init_stack(volatile VALUE* addr);
459 +#endif
460 +#define Init_stack(addr) ruby_init_stack(addr)
463 * Initializes the VM and builtin libraries.
464 diff -urN --exclude '*orig' ruby-3.1.5/thread.c ruby-3.1.5-ia64/thread.c
465 --- ruby-3.1.5/thread.c 2024-04-23 12:20:59.000000000 +0200
466 +++ ruby-3.1.5-ia64/thread.c 2024-05-30 11:43:47.988397160 +0200
467 @@ -340,7 +340,12 @@
468 # define PRI_THREAD_ID "p"
469 #endif
471 -NOINLINE(static int thread_start_func_2(rb_thread_t *th, VALUE *stack_start));
472 +#ifndef __ia64
473 +#define thread_start_func_2(th, st, rst) thread_start_func_2(th, st)
474 +#endif
475 +NOINLINE(static int thread_start_func_2(rb_thread_t *th, VALUE *stack_start,
476 + VALUE *register_stack_start));
478 void ruby_sigchld_handler(rb_vm_t *); /* signal.c */
480 static void
481 @@ -633,6 +638,9 @@
483 // The thread stack doesn't exist in the forked process:
484 th->ec->machine.stack_start = th->ec->machine.stack_end = NULL;
485 +#ifdef __ia64
486 + th->ec->machine.register_stack_start = th->ec->machine.register_stack_end = NULL;
487 +#endif
489 rb_threadptr_root_fiber_terminate(th);
491 @@ -777,7 +785,7 @@
492 void rb_ec_clear_current_thread_trace_func(const rb_execution_context_t *ec);
494 static int
495 -thread_start_func_2(rb_thread_t *th, VALUE *stack_start)
496 +thread_start_func_2(rb_thread_t *th, VALUE *stack_start, VALUE *register_stack_start)
498 STACK_GROW_DIR_DETECTION;
499 enum ruby_tag_type state;
500 @@ -816,6 +824,9 @@
501 rb_ec_initialize_vm_stack(th->ec, vm_stack, size);
502 th->ec->machine.stack_start = STACK_DIR_UPPER(vm_stack + size, vm_stack);
503 th->ec->machine.stack_maxsize -= size * sizeof(VALUE);
504 +#ifdef __ia64
505 + th->ec->machine.register_stack_start = register_stack_start;
506 +#endif
508 thread_debug("thread start (get lock): %p\n", (void *)th);
510 diff -urN --exclude '*orig' ruby-3.1.5/thread_pthread.c ruby-3.1.5-ia64/thread_pthread.c
511 --- ruby-3.1.5/thread_pthread.c 2024-04-23 12:20:59.000000000 +0200
512 +++ ruby-3.1.5-ia64/thread_pthread.c 2024-05-30 12:03:15.048605340 +0200
513 @@ -729,6 +729,51 @@
514 #define STACKADDR_AVAILABLE 1
515 #elif defined __HAIKU__
516 #define STACKADDR_AVAILABLE 1
517 +#elif defined __ia64 && defined _HPUX_SOURCE
518 +#include <sys/dyntune.h>
520 +#define STACKADDR_AVAILABLE 1
523 + * Do not lower the thread's stack to PTHREAD_STACK_MIN,
524 + * otherwise one would receive a 'sendsig: useracc failed.'
525 + * and a coredump.
526 + */
527 +#undef PTHREAD_STACK_MIN
529 +#define HAVE_PTHREAD_ATTR_GET_NP 1
530 +#undef HAVE_PTHREAD_ATTR_GETSTACK
533 + * As the PTHREAD_STACK_MIN is undefined and
534 + * no one touches the default stacksize,
535 + * it is just fine to use the default.
536 + */
537 +#define pthread_attr_get_np(thid, attr) 0
540 + * Using value of sp is very rough... To make it more real,
541 + * addr would need to be aligned to vps_pagesize.
542 + * The vps_pagesize is 'Default user page size (kBytes)'
543 + * and could be retrieved by gettune().
544 + */
545 +static int
546 +hpux_attr_getstackaddr(const pthread_attr_t *attr, void **addr)
548 + static uint64_t pagesize;
549 + size_t size;
551 + if (!pagesize) {
552 + if (gettune("vps_pagesize", &pagesize)) {
553 + pagesize = 16;
555 + pagesize *= 1024;
557 + pthread_attr_getstacksize(attr, &size);
558 + *addr = (void *)((size_t)((char *)_Asm_get_sp() - size) & ~(pagesize - 1));
559 + return 0;
561 +#define pthread_attr_getstackaddr(attr, addr) hpux_attr_getstackaddr(attr, addr)
562 #endif
564 #ifndef MAINSTACKADDR_AVAILABLE
565 @@ -828,6 +873,9 @@
566 rb_nativethread_id_t id;
567 size_t stack_maxsize;
568 VALUE *stack_start;
569 +#ifdef __ia64
570 + VALUE *register_stack_start;
571 +#endif
572 } native_main_thread;
574 #ifdef STACK_END_ADDRESS
575 @@ -909,10 +957,19 @@
577 #undef ruby_init_stack
578 void
579 -ruby_init_stack(volatile VALUE *addr)
580 +ruby_init_stack(volatile VALUE *addr
581 +#ifdef __ia64
582 + , void *bsp
583 +#endif
586 native_main_thread.id = pthread_self();
588 +#ifdef __ia64
589 + if (!native_main_thread.register_stack_start ||
590 + (VALUE*)bsp < native_main_thread.register_stack_start) {
591 + native_main_thread.register_stack_start = (VALUE*)bsp;
593 +#endif
594 #if MAINSTACKADDR_AVAILABLE
595 if (native_main_thread.stack_maxsize) return;
597 @@ -1016,7 +1073,11 @@
598 rb_raise(rb_eNotImpError, "ruby engine can initialize only in the main thread");
599 #endif
602 +#ifdef __ia64
603 + th->ec->machine.register_stack_start = native_main_thread.register_stack_start;
604 + th->ec->machine.stack_maxsize /= 2;
605 + th->ec->machine.register_stack_maxsize = th->ec->machine.stack_maxsize;
606 +#endif
607 return 0;
610 @@ -1044,9 +1105,9 @@
611 native_thread_init(th);
612 /* run */
613 #if defined USE_NATIVE_THREAD_INIT
614 - thread_start_func_2(th, th->ec->machine.stack_start);
615 + thread_start_func_2(th, th->ec->machine.stack_start, rb_ia64_bsp());
616 #else
617 - thread_start_func_2(th, &stack_start);
618 + thread_start_func_2(th, &stack_start, rb_ia64_bsp());
619 #endif
621 #if USE_THREA_CACHE
622 @@ -1181,6 +1242,10 @@
623 th->altstack = rb_allocate_sigaltstack();
624 #endif
625 th->ec->machine.stack_maxsize = stack_size - space;
626 +#ifdef __ia64
627 + th->ec->machine.stack_maxsize /= 2;
628 + th->ec->machine.register_stack_maxsize = th->ec->machine.stack_maxsize;
629 +#endif
631 CHECK_ERR(pthread_attr_init(&attr));
633 diff -urN --exclude '*orig' ruby-3.1.5/thread_win32.c ruby-3.1.5-ia64/thread_win32.c
634 --- ruby-3.1.5/thread_win32.c 2024-04-23 12:20:59.000000000 +0200
635 +++ ruby-3.1.5-ia64/thread_win32.c 2024-05-30 11:18:37.632127743 +0200
636 @@ -602,7 +602,7 @@
637 thread_debug("thread created (th: %p, thid: %p, event: %p)\n", th,
638 th->thread_id, th->native_thread_data.interrupt_event);
640 - thread_start_func_2(th, th->ec->machine.stack_start);
641 + thread_start_func_2(th, th->ec->machine.stack_start, rb_ia64_bsp());
643 w32_close_handle(thread_id);
644 thread_debug("thread deleted (th: %p)\n", th);
645 diff -urN --exclude '*orig' ruby-3.1.5/tool/m4/ruby_stack_grow_direction.m4 ruby-3.1.5-ia64/tool/m4/ruby_stack_grow_direction.m4
646 --- ruby-3.1.5/tool/m4/ruby_stack_grow_direction.m4 2024-04-23 12:20:59.000000000 +0200
647 +++ ruby-3.1.5-ia64/tool/m4/ruby_stack_grow_direction.m4 2024-05-30 11:18:37.636127744 +0200
648 @@ -3,7 +3,7 @@
649 AS_VAR_PUSHDEF([stack_grow_dir], [rb_cv_stack_grow_dir_$1])
650 AC_CACHE_CHECK(stack growing direction on $1, stack_grow_dir, [
651 AS_CASE(["$1"],
652 -[m68*|x86*|x64|i?86|ppc*|sparc*|alpha*], [ $2=-1],
653 +[m68*|x86*|x64|i?86|ia64|ppc*|sparc*|alpha*], [ $2=-1],
654 [hppa*], [ $2=+1],
656 AC_RUN_IFELSE([AC_LANG_SOURCE([[
657 diff -urN --exclude '*orig' ruby-3.1.5/vm.c ruby-3.1.5-ia64/vm.c
658 --- ruby-3.1.5/vm.c 2024-04-23 12:20:59.000000000 +0200
659 +++ ruby-3.1.5-ia64/vm.c 2024-05-30 11:18:37.644127745 +0200
660 @@ -3305,6 +3305,9 @@
662 extern VALUE *rb_gc_stack_start;
663 extern size_t rb_gc_stack_maxsize;
664 +#ifdef __ia64
665 +extern VALUE *rb_gc_register_stack_start;
666 +#endif
668 /* debug functions */
670 diff -urN --exclude '*orig' ruby-3.1.5/vm_core.h ruby-3.1.5-ia64/vm_core.h
671 --- ruby-3.1.5/vm_core.h 2024-04-23 12:20:59.000000000 +0200
672 +++ ruby-3.1.5-ia64/vm_core.h 2024-05-30 11:18:37.652127746 +0200
673 @@ -966,6 +966,11 @@
674 VALUE *stack_start;
675 VALUE *stack_end;
676 size_t stack_maxsize;
677 +#ifdef __ia64
678 + VALUE *register_stack_start;
679 + VALUE *register_stack_end;
680 + size_t register_stack_maxsize;
681 +#endif
682 RUBY_ALIGNAS(SIZEOF_VALUE) jmp_buf regs;
683 } machine;
685 diff -urN --exclude '*orig' ruby-3.1.5/vm_dump.c ruby-3.1.5-ia64/vm_dump.c
686 --- ruby-3.1.5/vm_dump.c 2024-04-23 12:20:59.000000000 +0200
687 +++ ruby-3.1.5-ia64/vm_dump.c 2024-05-30 11:18:37.656127747 +0200
688 @@ -701,6 +701,14 @@
689 frame.AddrFrame.Offset = context.Rbp;
690 frame.AddrStack.Mode = AddrModeFlat;
691 frame.AddrStack.Offset = context.Rsp;
692 +#elif defined(_M_IA64) || defined(__ia64__)
693 + mac = IMAGE_FILE_MACHINE_IA64;
694 + frame.AddrPC.Mode = AddrModeFlat;
695 + frame.AddrPC.Offset = context.StIIP;
696 + frame.AddrBStore.Mode = AddrModeFlat;
697 + frame.AddrBStore.Offset = context.RsBSP;
698 + frame.AddrStack.Mode = AddrModeFlat;
699 + frame.AddrStack.Offset = context.IntSp;
700 #else /* i386 */
701 mac = IMAGE_FILE_MACHINE_I386;
702 frame.AddrPC.Mode = AddrModeFlat;
703 diff -urN --exclude '*orig' ruby-3.1.5/win32/Makefile.sub ruby-3.1.5-ia64/win32/Makefile.sub
704 --- ruby-3.1.5/win32/Makefile.sub 2024-04-23 12:20:59.000000000 +0200
705 +++ ruby-3.1.5-ia64/win32/Makefile.sub 2024-05-30 11:37:57.340334611 +0200
706 @@ -397,7 +397,7 @@
707 DTRACE_EXT = dmyh
709 !if !defined(STACK)
710 -!if "$(ARCH)" == "x64"
711 +!if "$(ARCH)" == "x64" || "$(ARCH)" == "ia64"
712 STACK = 0x400000
713 !else
714 STACK = 0x200000
715 @@ -676,7 +676,7 @@
716 #define NUM2CLOCKID(v) NUM2INT(v)
717 #define SIZEOF_CLOCK_T 4
718 #define SIZEOF_RLIM_T 0
719 -!if "$(ARCH)" == "x64"
720 +!if "$(ARCH)" == "x64" || "$(ARCH)" == "ia64" || "$(ARCH)" == "ia64"
721 #define SIZEOF_SIZE_T 8
722 #define SIZEOF_PTRDIFF_T 8
723 #define SIZEOF_INTPTR_T 8
724 @@ -717,7 +717,7 @@
725 !else
726 #define PACKED_STRUCT(x) x
727 !endif
728 -!if "$(MACHINE)" == "x86" || "$(ARCH)" == "x64"
729 +!if "$(MACHINE)" == "x86" || "$(ARCH)" == "x64" || "$(ARCH)" == "ia64"
730 #define PACKED_STRUCT_UNALIGNED(x) PACKED_STRUCT(x)
731 !else
732 #define PACKED_STRUCT_UNALIGNED(x) x
733 @@ -782,7 +782,7 @@
734 #define HAVE_INTPTR_T 1
735 #define HAVE_UINTPTR_T 1
736 #define HAVE_SSIZE_T 1
737 -!if "$(ARCH)" == "x64"
738 +!if "$(ARCH)" == "x64" || "$(ARCH)" == "ia64"
739 #define ssize_t __int64
740 #define PRI_PTR_PREFIX "I64"
741 !else
742 @@ -876,7 +876,7 @@
743 !endif
744 #endif
745 #define NEED_IO_SEEK_BETWEEN_RW 1
746 -!if "$(MACHINE)" == "x86" || "$(ARCH)" == "x64"
747 +!if "$(MACHINE)" == "x86" || "$(ARCH)" == "x64" || "$(ARCH)" == "ia64"
748 #define STACK_GROW_DIRECTION -1
749 !endif
750 #define COROUTINE_H "$(COROUTINE_H)"
751 diff -urN --exclude '*orig' ruby-3.1.5/win32/README.win32 ruby-3.1.5-ia64/win32/README.win32
752 --- ruby-3.1.5/win32/README.win32 2024-04-23 12:20:59.000000000 +0200
753 +++ ruby-3.1.5-ia64/win32/README.win32 2024-05-30 11:18:37.668127749 +0200
754 @@ -8,8 +8,8 @@
756 2. Visual C++ 12.0 (2013) or later.
758 - [Note] if you want to build x64 version, use native compiler for
759 - x64.
760 + [Note] if you want to build x64 or ia64 version, use native compiler for
761 + x64/ia64.
763 3. Please set environment variable +INCLUDE+, +LIB+, +PATH+
764 to run required commands properly from the command line.
765 diff -urN --exclude '*orig' ruby-3.1.5/win32/configure.bat ruby-3.1.5-ia64/win32/configure.bat
766 --- ruby-3.1.5/win32/configure.bat 2024-04-23 12:20:59.000000000 +0200
767 +++ ruby-3.1.5-ia64/win32/configure.bat 2024-05-30 11:18:37.668127749 +0200
768 @@ -101,7 +101,8 @@
769 :target
770 echo>> ~tmp~.mak "%~2" \
771 echo>>confargs.tmp --target=%2 \
772 - if NOT "%~2" == "x64-mswin64" goto target3
773 + if "%~2" == "x64-mswin64" goto target2
774 + if NOT "%~2" == "ia64-mswin64" goto target3
775 :target2
776 echo>> ~tmp~.mak "TARGET_OS=mswin64" \
777 :target3
778 diff -urN --exclude '*orig' ruby-3.1.5/win32/setup.mak ruby-3.1.5-ia64/win32/setup.mak
779 --- ruby-3.1.5/win32/setup.mak 2024-04-23 12:20:59.000000000 +0200
780 +++ ruby-3.1.5-ia64/win32/setup.mak 2024-05-30 11:18:37.668127749 +0200
781 @@ -30,6 +30,7 @@
782 i686-mswin32: -prologue- -i686- -epilogue-
783 alpha-mswin32: -prologue- -alpha- -epilogue-
784 x64-mswin64: -prologue- -x64- -epilogue-
785 +ia64-mswin64: -prologue- -ia64- -epilogue-
787 -prologue-: -basic-vars-
788 -generic-: -osname-
789 @@ -187,6 +188,8 @@
790 @$(CPP) <<conftest.c 2>nul | findstr = >>$(MAKEFILE)
791 #if defined _M_X64
792 MACHINE = x64
793 +#elif defined _M_IA64
794 +MACHINE = ia64
795 #else
796 MACHINE = x86
797 #endif
798 @@ -199,6 +202,8 @@
799 @echo MACHINE = alpha>>$(MAKEFILE)
800 -x64-: -osname64-
801 @echo MACHINE = x64>>$(MAKEFILE)
802 +-ia64-: -osname64-
803 + @echo MACHINE = ia64>>$(MAKEFILE)
804 -ix86-: -osname32-
805 @echo MACHINE = x86>>$(MAKEFILE)