hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

+riscv64.ha (2031B)


      1 // SPDX-License-Identifier: MPL-2.0
      2 // (c) Hare authors <https://harelang.org>
      3 
      4 // #define __ADDR_BND_PKEY_PAD (_Alignof(void *) < sizeof(short) ? sizeof(short) : _Alignof(void *))
      5 def __ADDR_BND_PKEY_PAD: size = 8;
      6 
      7 // Returns the new PID to the parent, void to the child, or errno if something
      8 // goes wrong.
      9 export fn clone(
     10 	stack: nullable *opaque,
     11 	flags: int,
     12 	parent_tid: nullable *int,
     13 	child_tid: nullable *int,
     14 	tls: u64,
     15 ) (int | void | errno) = {
     16 	match (wrap_return(syscall5(SYS_clone,
     17 		flags: u64, stack: uintptr: u64,
     18 		parent_tid: uintptr: u64,
     19 		tls, child_tid: uintptr: u64))) {
     20 	case let u: u64 =>
     21 		switch (u) {
     22 		case 0 =>
     23 			return;
     24 		case =>
     25 			return u: int;
     26 		};
     27 	case let err: errno =>
     28 		return err;
     29 	};
     30 };
     31 
     32 export def O_DIRECTORY: int = 0o200000;
     33 export def O_DIRECT: int = 0o40000;
     34 
     35 export type cmsghdr = struct {
     36 	cmsg_len: socklen_t,
     37 	_padding: int,
     38 	cmsg_level: int,
     39 	cmsg_type: int,
     40 };
     41 
     42 export def EDEADLOCK: int = EDEADLK;
     43 
     44 export type epoll_event = struct {
     45 	events: u32,
     46 	data: epoll_data,
     47 };
     48 
     49 export type cpu_set = struct {
     50 	__bits: [16]u64,
     51 };
     52 
     53 export type ucontext = struct {
     54 	uc_flags: u64,
     55 	uc_link: *ucontext,
     56 	uc_stack: stack_t,
     57 	uc_sigmask: sigset,
     58 	_u8: [1024 / 8 - size(sigset)]u8,
     59 	uc_mcontext: sigcontext,
     60 };
     61 
     62 export type sigcontext = struct {
     63 	sc_regs: user_regs,
     64 	sc_fpregs: fp_state,
     65 };
     66 
     67 export type user_regs = struct {
     68 	x0: u64, // XXX: Why is this here?
     69 	pc: u64,
     70 	ra: u64,
     71 	sp: u64,
     72 	gp: u64,
     73 	tp: u64,
     74 	t0: u64,
     75 	t1: u64,
     76 	t2: u64,
     77 	s0: u64,
     78 	s1: u64,
     79 	a0: u64,
     80 	a1: u64,
     81 	a2: u64,
     82 	a3: u64,
     83 	a4: u64,
     84 	a5: u64,
     85 	a6: u64,
     86 	a7: u64,
     87 	s2: u64,
     88 	s3: u64,
     89 	s4: u64,
     90 	s5: u64,
     91 	s6: u64,
     92 	s7: u64,
     93 	s8: u64,
     94 	s9: u64,
     95 	s10: u64,
     96 	s11: u64,
     97 	t3: u64,
     98 	t4: u64,
     99 	t5: u64,
    100 	t6: u64,
    101 };
    102 
    103 export type fp_state = union {
    104 	f: f_ext_state,
    105 	d: d_ext_state,
    106 	q: q_ext_state,
    107 };
    108 
    109 export type f_ext_state = struct {
    110 	f: [32]u32,
    111 	fcsr: u32,
    112 };
    113 
    114 export type d_ext_state = struct {
    115 	f: [32]u64,
    116 	fcsr: u32,
    117 };
    118 
    119 export type q_ext_state = struct {
    120 	f: [64]u64,
    121 	fcsr: u32,
    122 	reserved: [3]u32,
    123 };