jdict

command line tool for looking up terms in yomidict dictionaries
git clone anongit@rnpnr.xyz:jdict.git
Log | Files | Refs | Feed | README | LICENSE

platform_linux_aarch64.c (2597B)


      1 /* See LICENSE for license details. */
      2 typedef unsigned char  u8;
      3 typedef signed   long  i64;
      4 typedef unsigned long  u64;
      5 typedef signed   int   i32;
      6 typedef unsigned int   u32;
      7 typedef unsigned int   b32;
      8 typedef unsigned short u16;
      9 typedef signed   long  size;
     10 typedef unsigned long  usize;
     11 typedef signed   long  iptr;
     12 
     13 #define SYS_openat             56
     14 #define SYS_close              57
     15 #define SYS_getdents64         61
     16 #define SYS_read               63
     17 #define SYS_write              64
     18 #define SYS_fstat              80
     19 #define SYS_exit               93
     20 #define SYS_mmap              222
     21 
     22 /* NOTE(rnp): technically arm64 can have 4K, 16K or 64K pages but we will just assume 64K */
     23 #define PAGESIZE 65536
     24 
     25 #define O_DIRECTORY   0x4000
     26 
     27 #include "platform_linux.c"
     28 
     29 static FORCE_INLINE i64
     30 syscall1(i64 n, i64 a1)
     31 {
     32 	register i64 x8 asm("x8") = n;
     33 	register i64 x0 asm("x0") = a1;
     34 	asm volatile ("svc 0"
     35 		: "=r"(x0)
     36 		: "0"(x0), "r"(x8)
     37 		: "memory", "cc"
     38 	);
     39 	return x0;
     40 }
     41 
     42 static FORCE_INLINE i64
     43 syscall2(i64 n, i64 a1, i64 a2)
     44 {
     45 	register i64 x8 asm("x8") = n;
     46 	register i64 x0 asm("x0") = a1;
     47 	register i64 x1 asm("x1") = a2;
     48 	asm volatile ("svc 0"
     49 		: "=r"(x0)
     50 		: "0"(x0), "r"(x8), "r"(x1)
     51 		: "memory", "cc"
     52 	);
     53 	return x0;
     54 }
     55 
     56 static FORCE_INLINE i64
     57 syscall3(i64 n, i64 a1, i64 a2, i64 a3)
     58 {
     59 	register i64 x8 asm("x8") = n;
     60 	register i64 x0 asm("x0") = a1;
     61 	register i64 x1 asm("x1") = a2;
     62 	register i64 x2 asm("x2") = a3;
     63 	asm volatile ("svc 0"
     64 		: "=r"(x0)
     65 		: "0"(x0), "r"(x8), "r"(x1), "r"(x2)
     66 		: "memory", "cc"
     67 	);
     68 	return x0;
     69 }
     70 
     71 static FORCE_INLINE i64
     72 syscall4(i64 n, i64 a1, i64 a2, i64 a3, i64 a4)
     73 {
     74 	register i64 x8 asm("x8") = n;
     75 	register i64 x0 asm("x0") = a1;
     76 	register i64 x1 asm("x1") = a2;
     77 	register i64 x2 asm("x2") = a3;
     78 	register i64 x3 asm("x3") = a4;
     79 	asm volatile ("svc 0"
     80 		: "=r"(x0)
     81 		: "0"(x0), "r"(x8), "r"(x1), "r"(x2), "r"(x3)
     82 		: "memory", "cc"
     83 	);
     84 	return x0;
     85 }
     86 
     87 static FORCE_INLINE i64
     88 syscall6(i64 n, i64 a1, i64 a2, i64 a3, i64 a4, i64 a5, i64 a6)
     89 {
     90 	register i64 x8 asm("x8") = n;
     91 	register i64 x0 asm("x0") = a1;
     92 	register i64 x1 asm("x1") = a2;
     93 	register i64 x2 asm("x2") = a3;
     94 	register i64 x3 asm("x3") = a4;
     95 	register i64 x4 asm("x4") = a5;
     96 	register i64 x5 asm("x5") = a6;
     97 	asm volatile ("svc 0"
     98 		: "=r"(x0)
     99 		: "0"(x0), "r"(x8), "r"(x1), "r"(x2), "r"(x3), "r"(x4), "r"(x5)
    100 		: "memory", "cc"
    101 	);
    102 	return x0;
    103 }
    104 
    105 asm (
    106 	".global _start\n"
    107 	"_start:\n"
    108 	"	ldr	x0, [sp], #8\n"
    109 	"	mov	x1, sp\n"
    110 	"       add     x2, sp, x0, lsl #3\n"
    111 	"       add     x2, x2, #8\n"
    112 	"       sub     sp, sp, #8\n"
    113 	"	bl      linux_main\n"
    114 	"	brk     #0\n"
    115 );