logo

overlay

My own overlay for experimentations, use with caution, no support is provided git clone https://hacktivis.me/git/overlay.git

jamvm-1.6.0-aarch64-support.patch (23347B)


  1. From a44154f7a18496cc3e5fc0b1b2ea69523ebc623a Mon Sep 17 00:00:00 2001
  2. From: Simon South <simon@simonsouth.net>
  3. Date: Mon, 1 Jun 2020 07:09:34 -0400
  4. Subject: [PATCH] Add support for aarch64 on GNU/Linux
  5. ---
  6. AUTHORS | 1 +
  7. README | 2 +-
  8. configure.ac | 7 +-
  9. src/arch/Makefile.am | 2 +-
  10. src/arch/aarch64.h | 147 +++++++++++++++++++++
  11. src/jam.c | 3 +-
  12. src/os/linux/Makefile.am | 2 +-
  13. src/os/linux/aarch64/Makefile.am | 28 ++++
  14. src/os/linux/aarch64/callNative.S | 212 ++++++++++++++++++++++++++++++
  15. src/os/linux/aarch64/dll_md.c | 59 +++++++++
  16. src/os/linux/aarch64/init.c | 51 +++++++
  17. 11 files changed, 508 insertions(+), 6 deletions(-)
  18. create mode 100644 src/arch/aarch64.h
  19. create mode 100644 src/os/linux/aarch64/Makefile.am
  20. create mode 100644 src/os/linux/aarch64/callNative.S
  21. create mode 100644 src/os/linux/aarch64/dll_md.c
  22. create mode 100644 src/os/linux/aarch64/init.c
  23. diff --git a/AUTHORS b/AUTHORS
  24. index e1334fe..6fd0eeb 100644
  25. --- jamvm/jamvm/AUTHORS
  26. +++ jamvm/jamvm/AUTHORS
  27. @@ -1,1 +1,2 @@
  28. Robert Lougher <rob@jamvm.org.uk>
  29. +Simon South <simon@simonsouth.net>
  30. diff --git a/configure.ac b/configure.ac
  31. index 138b7e6..e7051d7 100644
  32. --- jamvm/jamvm/configure.ac
  33. +++ jamvm/jamvm/configure.ac
  34. @@ -46,6 +46,7 @@ x86_64-*-freebsd*) host_os=bsd libdl_needed=no ;;
  35. arm*-*-linux*) host_cpu=arm host_os=linux interp_cflags=-marm ;;
  36. arm*-*-openbsd*) host_cpu=arm host_os=bsd libdl_needed=no ;;
  37. arm*-*-freebsd*) host_cpu=arm host_os=bsd libdl_needed=no ;;
  38. +aarch64*-*-linux*) host_cpu=aarch64 host_os=linux ;;
  39. powerpc*-*-linux*) host_cpu=powerpc host_os=linux ;;
  40. powerpc*-*-openbsd*) host_cpu=powerpc host_os=bsd libdl_needed=no ;;
  41. powerpc*-*-freebsd*) host_cpu=powerpc host_os=bsd libdl_needed=no ;;
  42. @@ -155,10 +156,11 @@ AC_ARG_ENABLE(runtime-reloc-checks,
  43. AC_ARG_ENABLE(int-inlining,
  44. [AS_HELP_STRING(--enable-int-inlining,enable inline threaded version of the interpreter
  45. - (by default enabled on x86_64, i386, powerpc, mips and arm,
  46. + (by default enabled on x86_64, i386, powerpc, mips, arm and aarch64,
  47. disabled otherwise))],,
  48. [if test "$host_cpu" = x86_64 -o "$host_cpu" = i386 -o "$host_cpu" = x86 -o \
  49. - "$host_cpu" = powerpc -o "$host_cpu" = arm -o "$host_cpu" = mips; then
  50. + "$host_cpu" = powerpc -o "$host_cpu" = arm -o "$host_cpu" = mips -o \
  51. + "$host_cpu" = aarch64; then
  52. enable_int_inlining=yes
  53. else
  54. enable_int_inlining=no
  55. @@ -407,6 +409,7 @@ AC_CONFIG_FILES(
  56. src/os/linux/x86_64/Makefile \
  57. src/os/linux/parisc/Makefile \
  58. src/os/linux/mips/Makefile \
  59. + src/os/linux/aarch64/Makefile \
  60. src/os/darwin/i386/Makefile \
  61. src/os/darwin/arm/Makefile \
  62. src/os/darwin/powerpc/Makefile \
  63. diff --git a/src/arch/Makefile.am b/src/arch/Makefile.am
  64. index 7580a1b..4e2a4f9 100644
  65. --- jamvm/jamvm/src/arch/Makefile.am
  66. +++ jamvm/jamvm/src/arch/Makefile.am
  67. @@ -19,4 +19,4 @@
  68. ## Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  69. ##
  70. -EXTRA_DIST = powerpc.h arm.h i386.h x86_64.h parisc.h mips.h sparc.h
  71. +EXTRA_DIST = powerpc.h arm.h i386.h x86_64.h parisc.h mips.h sparc.h aarch64.h
  72. diff --git a/src/arch/aarch64.h b/src/arch/aarch64.h
  73. new file mode 100644
  74. index 0000000..1912e79
  75. --- /dev/null
  76. +++ jamvm/jamvm/src/arch/aarch64.h
  77. @@ -0,0 +1,147 @@
  78. +/*
  79. + * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008
  80. + * Robert Lougher <rob@jamvm.org.uk>.
  81. + * Copyright (C) 2020 Simon South <simon@simonsouth.net>.
  82. + *
  83. + * This file is part of JamVM.
  84. + *
  85. + * This program is free software; you can redistribute it and/or
  86. + * modify it under the terms of the GNU General Public License
  87. + * as published by the Free Software Foundation; either version 2,
  88. + * or (at your option) any later version.
  89. + *
  90. + * This program is distributed in the hope that it will be useful,
  91. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  92. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  93. + * GNU General Public License for more details.
  94. + *
  95. + * You should have received a copy of the GNU General Public License
  96. + * along with this program; if not, write to the Free Software
  97. + * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  98. + */
  99. +
  100. +#include <stdint.h>
  101. +
  102. +#define OS_ARCH "aarch64"
  103. +
  104. +#define HANDLER_TABLE_T static const void
  105. +#define DOUBLE_1_BITS 0x3ff0000000000000LL
  106. +
  107. +#define READ_DBL(v,p,l) v = ((u8)p[0]<<56)|((u8)p[1]<<48)|((u8)p[2]<<40) \
  108. + |((u8)p[3]<<32)|((u8)p[4]<<24)|((u8)p[5]<<16) \
  109. + |((u8)p[6]<<8)|(u8)p[7]; p+=8
  110. +
  111. +/* Needed for i386 -- empty here */
  112. +#define FPU_HACK
  113. +
  114. +#define COMPARE_AND_SWAP_64(addr, old_val, new_val) \
  115. +({ \
  116. + int result, read_val; \
  117. + __asm__ __volatile__ (" \
  118. + 1: ldaxr %2, %1; \
  119. + cmp %2, %3; \
  120. + b.ne 2f; \
  121. + stlxr %w0, %4, %1; \
  122. + cmp %w0, wzr; \
  123. + b.ne 1b; \
  124. + 2: cset %w0, eq;" \
  125. + : "=&r" (result), "+Q" (*addr), "=&r" (read_val) \
  126. + : "r" (old_val), "r" (new_val) \
  127. + : "cc"); \
  128. + result; \
  129. +})
  130. +
  131. +#define COMPARE_AND_SWAP_32(addr, old_val, new_val) \
  132. +({ \
  133. + int result, read_val; \
  134. + __asm__ __volatile__ (" \
  135. + 1: ldaxr %w2, %1; \
  136. + cmp %w2, %w3; \
  137. + b.ne 2f; \
  138. + stlxr %w0, %w4, %1; \
  139. + cmp %w0, wzr; \
  140. + b.ne 1b; \
  141. + 2: cset %w0, eq;" \
  142. + : "=&r" (result), "+Q" (*addr), "=&r" (read_val) \
  143. + : "r" (old_val), "r" (new_val) \
  144. + : "cc"); \
  145. + result; \
  146. +})
  147. +
  148. +#define COMPARE_AND_SWAP(addr, old_val, new_val) \
  149. + COMPARE_AND_SWAP_64(addr, old_val, new_val)
  150. +
  151. +#define LOCKWORD_READ(addr) \
  152. +({ \
  153. + uintptr_t result; \
  154. + __asm__ __volatile__ (" \
  155. + ldar %0, %1;" \
  156. + : "=r" (result) \
  157. + : "Q" (*addr) \
  158. + : "cc"); \
  159. + result; \
  160. +})
  161. +
  162. +#define LOCKWORD_WRITE(addr, value) \
  163. +({ \
  164. + __asm__ __volatile__ (" \
  165. + stlr %1, %0;" \
  166. + : "=Q" (*addr) \
  167. + : "r" (value) \
  168. + : "cc"); \
  169. +})
  170. +
  171. +#define LOCKWORD_COMPARE_AND_SWAP(addr, old_val, new_val) \
  172. + COMPARE_AND_SWAP_64(addr, old_val, new_val)
  173. +
  174. +#define FLUSH_CACHE(addr, length) \
  175. +{ \
  176. + uintptr_t start = (uintptr_t) (addr); \
  177. + uintptr_t end = start + length; \
  178. + uintptr_t i; \
  179. + \
  180. + for(i = start & aarch64_data_cache_line_mask; \
  181. + i < end; \
  182. + i += aarch64_data_cache_line_len) \
  183. + __asm__ ("dc cvau, %0" :: "r" (i)); \
  184. + \
  185. + __asm__ ("dsb ish"); \
  186. + \
  187. + for(i = start & aarch64_instruction_cache_line_mask; \
  188. + i < end; \
  189. + i += aarch64_instruction_cache_line_len) \
  190. + __asm__ ("ic ivau, %0" :: "r" (i)); \
  191. + \
  192. + __asm__ ("dsb ish; isb"); \
  193. +}
  194. +
  195. +#define GEN_REL_JMP(target_addr, patch_addr, patch_size) \
  196. +({ \
  197. + int patched = FALSE; \
  198. + \
  199. + if(patch_size >= 4) { \
  200. + /* Guard against the pointer difference being \
  201. + larger than the signed range */ \
  202. + long long offset = (uintptr_t)(target_addr) - \
  203. + (uintptr_t)(patch_addr); \
  204. + \
  205. + if(offset >= -1<<28 && offset < 1<<28) { \
  206. + *(uint32_t*)(patch_addr) = offset>>2 & 0x03ffffff \
  207. + | 0x14000000; \
  208. + patched = TRUE; \
  209. + } \
  210. + } \
  211. + patched; \
  212. +})
  213. +
  214. +#define MBARRIER() __asm__ ("dmb ish" ::: "memory")
  215. +#define RMBARRIER() __asm__ ("dmb ishld" ::: "memory")
  216. +#define WMBARRIER() __asm__ ("dmb ishst" ::: "memory")
  217. +#define JMM_LOCK_MBARRIER() __asm__ ("dmb ish" ::: "memory")
  218. +#define JMM_UNLOCK_MBARRIER() JMM_LOCK_MBARRIER()
  219. +
  220. +/* Defined in src/os/linux/aarch64/init.c */
  221. +extern unsigned char aarch64_data_cache_line_len;
  222. +extern uintptr_t aarch64_data_cache_line_mask;
  223. +extern unsigned char aarch64_instruction_cache_line_len;
  224. +extern uintptr_t aarch64_instruction_cache_line_mask;
  225. diff --git a/src/jam.c b/src/jam.c
  226. index 052f84a..c97524a 100644
  227. --- jamvm/jamvm/src/jam.c
  228. +++ jamvm/jamvm/src/jam.c
  229. @@ -98,7 +98,8 @@ void showUsage(char *name) {
  230. void showVersionAndCopyright() {
  231. printf("java version \"%s\"\n", JAVA_COMPAT_VERSION);
  232. printf("JamVM version %s\n", VERSION);
  233. - printf("Copyright (C) 2003-2013 Robert Lougher <rob@jamvm.org.uk>\n\n");
  234. + printf("Copyright (C) 2003-2013 Robert Lougher <rob@jamvm.org.uk>\n");
  235. + printf("Portions Copyright (C) 2020 Simon South <simon@simonsouth.net>\n\n");
  236. printf("This program is free software; you can redistribute it and/or\n");
  237. printf("modify it under the terms of the GNU General Public License\n");
  238. printf("as published by the Free Software Foundation; either version 2,\n");
  239. diff --git a/src/os/linux/Makefile.am b/src/os/linux/Makefile.am
  240. index 542094e..83e7dfe 100644
  241. --- jamvm/jamvm/src/os/linux/Makefile.am
  242. +++ jamvm/jamvm/src/os/linux/Makefile.am
  243. @@ -20,7 +20,7 @@
  244. ##
  245. SUBDIRS = @arch@
  246. -DIST_SUBDIRS = powerpc arm i386 x86_64 parisc mips
  247. +DIST_SUBDIRS = powerpc arm i386 x86_64 parisc mips aarch64
  248. noinst_LTLIBRARIES = libos.la
  249. libos_la_SOURCES = os.c
  250. diff --git a/src/os/linux/aarch64/Makefile.am b/src/os/linux/aarch64/Makefile.am
  251. new file mode 100644
  252. index 0000000..0e5134f
  253. --- /dev/null
  254. +++ jamvm/jamvm/src/os/linux/aarch64/Makefile.am
  255. @@ -0,0 +1,28 @@
  256. +##
  257. +## Copyright (C) 2003, 2004, 2005, 2006, 2007, 2010, 2011, 2012
  258. +## Robert Lougher <rob@jamvm.org.uk>.
  259. +##
  260. +## File added by Simon South <simon@simonsouth.net>.
  261. +##
  262. +## This file is part of JamVM.
  263. +##
  264. +## This program is free software; you can redistribute it and/or
  265. +## modify it under the terms of the GNU General Public License
  266. +## as published by the Free Software Foundation; either version 2,
  267. +## or (at your option) any later version.
  268. +##
  269. +## This program is distributed in the hope that it will be useful,
  270. +## but WITHOUT ANY WARRANTY; without even the implied warranty of
  271. +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  272. +## GNU General Public License for more details.
  273. +##
  274. +## You should have received a copy of the GNU General Public License
  275. +## along with this program; if not, write to the Free Software
  276. +## Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  277. +##
  278. +
  279. +noinst_LTLIBRARIES = libnative.la
  280. +libnative_la_SOURCES = init.c dll_md.c callNative.S
  281. +
  282. +AM_CPPFLAGS = -I$(top_builddir)/src -I$(top_srcdir)/src
  283. +AM_CCASFLAGS = -I$(top_builddir)/src
  284. diff --git a/src/os/linux/aarch64/callNative.S b/src/os/linux/aarch64/callNative.S
  285. new file mode 100644
  286. index 0000000..e067c4f
  287. --- /dev/null
  288. +++ jamvm/jamvm/src/os/linux/aarch64/callNative.S
  289. @@ -0,0 +1,212 @@
  290. +/*
  291. + * Copyright (C) 2008, 2009, 2011, 2012 Robert Lougher <rob@jamvm.org.uk>.
  292. + * Copyright (C) 2020 Simon South <simon@simonsouth.net>.
  293. + *
  294. + * This file is part of JamVM.
  295. + *
  296. + * This program is free software; you can redistribute it and/or
  297. + * modify it under the terms of the GNU General Public License
  298. + * as published by the Free Software Foundation; either version 2,
  299. + * or (at your option) any later version.
  300. + *
  301. + * This program is distributed in the hope that it will be useful,
  302. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  303. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  304. + * GNU General Public License for more details.
  305. + *
  306. + * You should have received a copy of the GNU General Public License
  307. + * along with this program; if not, write to the Free Software
  308. + * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  309. + */
  310. +
  311. +#include "config.h"
  312. +
  313. +#ifndef USE_FFI
  314. + .text
  315. + .arch armv8-a
  316. + .align 2
  317. + .global callJNIMethod
  318. + .type callJNIMethod,function
  319. +
  320. +/*
  321. + * Arguments passed in:
  322. + *
  323. + * x0 JNIEnv
  324. + * x1 class or NULL
  325. + * x2 sig
  326. + * w3 extra arg
  327. + * x4 ostack
  328. + * x5 function pntr
  329. + * w6 args count
  330. + */
  331. +
  332. +/* Register usage:
  333. + *
  334. + * x20 ostack
  335. + * x19 sig pntr
  336. + * x16 function pntr
  337. + * x15 ostack pntr
  338. + * x14 args pntr
  339. + * x13 float/double handler
  340. + * x12 int/long handler
  341. + * w11 fp regs remaining
  342. + * w10 int regs remaining
  343. + * x9 scratch
  344. + * x2-x7 outgoing int args
  345. + * x1 outgoing class or this pntr
  346. + * x0 outgoing JNIEnv (as passed in)
  347. + *
  348. + * d0 - d7 outgoing float args
  349. + */
  350. +
  351. +callJNIMethod:
  352. + stp x29, x30, [sp, #-32]!
  353. + mov x29, sp
  354. + stp x19, x20, [x29, #16]
  355. +
  356. + sub sp, sp, w3 /* allocate room for stacked args */
  357. + mov x14, sp
  358. +
  359. + mov x20, x4 /* preserve ostack */
  360. + add x19, x2, #1 /* init sig pntr -- skipping '(' */
  361. +
  362. + mov x16, x5 /* save function pntr */
  363. + mov x15, x20 /* init ostack pntr */
  364. +
  365. + adr x13, fp_reg_handlers-8
  366. + adr x12, int_reg_handlers-8
  367. +
  368. + mov w11, #8 /* fp regs remaining */
  369. + mov w10, #6 /* int regs remaining */
  370. +
  371. + cbnz x1, scan_sig /* is method non-static? */
  372. + ldr x1, [x15], #8 /* yes, load x1 with "this" */
  373. +
  374. +scan_sig:
  375. + ldrb w9, [x19], #1 /* get next sig char */
  376. +
  377. + cmp w9, #41 /* ')' */
  378. + b.eq done
  379. +
  380. + cmp w9, #74 /* 'J' */
  381. + b.eq long
  382. +
  383. + cmp w9, #70 /* 'F' */
  384. + b.eq float
  385. +
  386. + cmp w9, #68 /* 'D' */
  387. + b.eq double
  388. +
  389. +skip_brackets:
  390. + cmp w9, #91 /* '[' */
  391. + b.ne 1f
  392. + ldrb w9, [x19], #1
  393. + b skip_brackets
  394. +1:
  395. + cmp w9, #76 /* 'L' */
  396. + b.ne int
  397. +
  398. +skip_ref:
  399. + ldrb w9, [x19], #1
  400. + cmp w9, #59 /* ';' */
  401. + b.ne skip_ref
  402. +
  403. +int:
  404. + ldr x9, [x15], #8
  405. + cbz w10, stack_push
  406. +
  407. +load_int_reg:
  408. + sub w10, w10, #1
  409. + add x12, x12, #8
  410. + br x12
  411. +
  412. +int_reg_handlers:
  413. + mov x2, x9
  414. + b scan_sig
  415. + mov x3, x9
  416. + b scan_sig
  417. + mov x4, x9
  418. + b scan_sig
  419. + mov x5, x9
  420. + b scan_sig
  421. + mov x6, x9
  422. + b scan_sig
  423. + mov x7, x9
  424. + b scan_sig
  425. +
  426. +long:
  427. + ldr x9, [x15], #16
  428. + cbz w10, stack_push
  429. + b load_int_reg
  430. +
  431. +float:
  432. + ldr w9, [x15], #8
  433. + cbz w11, stack_push
  434. + b load_fp_reg
  435. +
  436. +double:
  437. + ldr x9, [x15], #16
  438. + cbz w11, stack_push
  439. +
  440. +load_fp_reg:
  441. + sub w11, w11, #1
  442. + add x13, x13, #8
  443. + br x13
  444. +
  445. +fp_reg_handlers:
  446. + fmov d0, x9
  447. + b scan_sig
  448. + fmov d1, x9
  449. + b scan_sig
  450. + fmov d2, x9
  451. + b scan_sig
  452. + fmov d3, x9
  453. + b scan_sig
  454. + fmov d4, x9
  455. + b scan_sig
  456. + fmov d5, x9
  457. + b scan_sig
  458. + fmov d6, x9
  459. + b scan_sig
  460. + fmov d7, x9
  461. + b scan_sig
  462. +
  463. +stack_push:
  464. + str x9, [x14], #8
  465. + b scan_sig
  466. +
  467. +done:
  468. + /* Call the function */
  469. + blr x16
  470. +
  471. + mov sp, x29 /* Pop argument area */
  472. +
  473. + ldrb w9, [x19] /* Return type */
  474. +
  475. + cmp w9, #86 /* 'V' */
  476. + b.eq return
  477. +
  478. + cmp w9, #68 /* 'D' */
  479. + b.ne 2f
  480. + str d0, [x20], #16
  481. + b return
  482. +2:
  483. + cmp w9, #70 /* 'F' */
  484. + b.ne 3f
  485. + str s0, [x20], #8
  486. + b return
  487. +3:
  488. + cmp w9, #74 /* 'J' */
  489. + b.ne 4f
  490. + str x0, [x20], #16
  491. + b return
  492. +4:
  493. + str x0, [x20], #8
  494. +
  495. +return:
  496. + mov x0, x20 /* return ostack */
  497. +
  498. + ldp x19, x20, [x29, #16]
  499. + ldp x29, x30, [sp], #32
  500. + ret
  501. +#endif
  502. diff --git a/src/os/linux/aarch64/dll_md.c b/src/os/linux/aarch64/dll_md.c
  503. new file mode 100644
  504. index 0000000..189f8a8
  505. --- /dev/null
  506. +++ jamvm/jamvm/src/os/linux/aarch64/dll_md.c
  507. @@ -0,0 +1,59 @@
  508. +/*
  509. + * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2010, 2011
  510. + * Robert Lougher <rob@jamvm.org.uk>.
  511. + * Copyright (C) 2020 Simon South <simon@simonsouth.net>.
  512. + *
  513. + * This file is part of JamVM.
  514. + *
  515. + * This program is free software; you can redistribute it and/or
  516. + * modify it under the terms of the GNU General Public License
  517. + * as published by the Free Software Foundation; either version 2,
  518. + * or (at your option) any later version.
  519. + *
  520. + * This program is distributed in the hope that it will be useful,
  521. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  522. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  523. + * GNU General Public License for more details.
  524. + *
  525. + * You should have received a copy of the GNU General Public License
  526. + * along with this program; if not, write to the Free Software
  527. + * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  528. + */
  529. +
  530. +#include "jam.h"
  531. +
  532. +#ifndef USE_FFI
  533. +
  534. +int nativeExtraArg(MethodBlock *mb) {
  535. + char *sig = mb->type;
  536. + int stack_args = 0;
  537. + int int_args = 6;
  538. + int fp_args = 8;
  539. +
  540. + while(*++sig != ')')
  541. + switch(*sig) {
  542. + case 'F':
  543. + case 'D':
  544. + if(fp_args == 0)
  545. + stack_args += 8;
  546. + else
  547. + fp_args--;
  548. +
  549. + default:
  550. + if(int_args == 0)
  551. + stack_args += 8;
  552. + else
  553. + int_args--;
  554. +
  555. + if(*sig == '[')
  556. + while(*++sig == '[');
  557. + if(*sig == 'L')
  558. + while(*++sig != ';');
  559. + break;
  560. + }
  561. +
  562. + /* Ensure the stack remains 16 byte aligned. */
  563. + return (stack_args + 15) & ~15;
  564. +}
  565. +
  566. +#endif
  567. diff --git a/src/os/linux/aarch64/init.c b/src/os/linux/aarch64/init.c
  568. new file mode 100644
  569. index 0000000..b21dc55
  570. --- /dev/null
  571. +++ jamvm/jamvm/src/os/linux/aarch64/init.c
  572. @@ -0,0 +1,51 @@
  573. +/*
  574. + * Copyright (C) 2003, 2004, 2005, 2006, 2007
  575. + * Robert Lougher <rob@jamvm.org.uk>.
  576. + * Copyright (C) 2020 Simon South <simon@simonsouth.net>.
  577. + *
  578. + * This file is part of JamVM.
  579. + *
  580. + * This program is free software; you can redistribute it and/or
  581. + * modify it under the terms of the GNU General Public License
  582. + * as published by the Free Software Foundation; either version 2,
  583. + * or (at your option) any later version.
  584. + *
  585. + * This program is distributed in the hope that it will be useful,
  586. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  587. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  588. + * GNU General Public License for more details.
  589. + *
  590. + * You should have received a copy of the GNU General Public License
  591. + * along with this program; if not, write to the Free Software
  592. + * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  593. + */
  594. +
  595. +#include "arch/aarch64.h"
  596. +
  597. +/* Length in bytes of the smallest line in the host system's data cache */
  598. +unsigned char aarch64_data_cache_line_len;
  599. +
  600. +/* Mask used to align a virtual address to a line in the data cache */
  601. +uintptr_t aarch64_data_cache_line_mask;
  602. +
  603. +/* Length in bytes of the smallest line in the host system's instruction
  604. + cache */
  605. +unsigned char aarch64_instruction_cache_line_len;
  606. +
  607. +/* Mask used to align a virtual address to a line in the instruction cache */
  608. +uintptr_t aarch64_instruction_cache_line_mask;
  609. +
  610. +void initialisePlatform() {
  611. + unsigned int cache_type;
  612. +
  613. + /* Extract information from the cache-type register, which describes aspects
  614. + of the host's cache configuration */
  615. + __asm__ ("mrs %0, ctr_el0" : "=r" (cache_type));
  616. +
  617. + aarch64_data_cache_line_len = 4 << ((cache_type >> 16) & 0x0f);
  618. + aarch64_data_cache_line_mask = ~(aarch64_data_cache_line_len - 1);
  619. +
  620. + aarch64_instruction_cache_line_len = 4 << (cache_type & 0x0f);
  621. + aarch64_instruction_cache_line_mask =
  622. + ~(aarch64_instruction_cache_line_len - 1);
  623. +}
  624. --
  625. 2.26.2