1 /*
2  * Copyright (c) 2006-2021, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  */
9 
10 #ifndef  LWP_ARCH_H__
11 #define  LWP_ARCH_H__
12 
13 #include <rthw.h>
14 #include <lwp.h>
15 #include <lwp_arch_comm.h>
16 
17 #ifdef ARCH_MM_MMU
18 
19 #ifdef ARCH_MM_MMU_32BIT_LIMIT
20 #define USER_HEAP_VADDR     0xF0000000UL
21 #define USER_HEAP_VEND      0xFE000000UL
22 #define USER_STACK_VSTART   0xE0000000UL
23 #define USER_STACK_VEND     USER_HEAP_VADDR
24 #define USER_VADDR_START    0xC0000000UL
25 #define USER_VADDR_TOP      0xFF000000UL
26 #define USER_LOAD_VADDR     0xD0000000UL
27 #define LDSO_LOAD_VADDR     USER_LOAD_VADDR
28 #elif defined(ARCH_REMAP_KERNEL)
29 #define USER_VADDR_START    0x00001000UL
30 #define USER_VADDR_TOP      0x003ffffff000UL
31 #define USER_STACK_VSTART   0x000270000000UL
32 #define USER_STACK_VEND     (USER_HEAP_VADDR - (ARCH_PAGE_SIZE * 8)) /* start of ARGC ARGV ENVP. FIXME: space is ARG_MAX */
33 #define USER_HEAP_VADDR     0x000300000000UL
34 #define USER_HEAP_VEND      USER_VADDR_TOP
35 #define USER_LOAD_VADDR     0x200000000
36 #define LDSO_LOAD_VADDR     0x200000000
37 #else
38 #define USER_HEAP_VADDR     0x300000000UL
39 #define USER_HEAP_VEND      USER_STACK_VSTART
40 #define USER_STACK_VSTART   0x370000000UL
41 #define USER_STACK_VEND     0x400000000UL
42 #define USER_VADDR_START    0x200000000UL
43 #define USER_VADDR_TOP      0xfffffffffffff000UL
44 #define USER_LOAD_VADDR     0x200000000UL
45 #define LDSO_LOAD_VADDR     0x200000000UL
46 #endif
47 
48 /* this attribution is cpu specified, and it should be defined in riscv_mmu.h */
49 #ifndef MMU_MAP_U_RWCB
50 #define MMU_MAP_U_RWCB 0
51 #endif
52 
53 #ifndef MMU_MAP_U_RW
54 #define MMU_MAP_U_RW 0
55 #endif
56 
57 #ifdef __cplusplus
58 extern "C" {
59 #endif
60 
rt_hw_ffz(unsigned long x)61 rt_inline unsigned long rt_hw_ffz(unsigned long x)
62 {
63     return __builtin_ffsl(~x) - 1;
64 }
65 
icache_invalid_all(void)66 rt_inline void icache_invalid_all(void)
67 {
68     rt_hw_cpu_icache_invalidate_all();
69 }
70 
71 struct rt_hw_stack_frame;
72 void *arch_signal_ucontext_restore(rt_base_t user_sp);
73 void *arch_signal_ucontext_save(int signo, siginfo_t *psiginfo,
74                                 struct rt_hw_stack_frame *exp_frame, rt_base_t user_sp,
75                                 lwp_sigset_t *save_sig_mask);
76 #ifdef __cplusplus
77 }
78 #endif
79 
80 #endif
81 
82 #endif  /*LWP_ARCH_H__*/
83