2 * linux-user semihosting checks
5 * Written by Alex Bennée <alex.bennee@linaro.org>
7 * SPDX-License-Identifier: GPL-3.0-or-later
10 #define SYS_WRITE0 0x04
11 #define SYS_HEAPINFO 0x16
12 #define SYS_REPORTEXC 0x18
20 int main(int argc
, char *argv
[argc
])
22 #if UINTPTR_MAX == UINT32_MAX
23 uintptr_t exit_code
= 0x20026;
25 uintptr_t exit_block
[2] = {0x20026, 0};
26 uintptr_t exit_code
= (uintptr_t) &exit_block
;
34 void *ptr_to_info
= (void *) &info
;
36 __semi_call(SYS_WRITE0
, (uintptr_t) "Checking HeapInfo\n");
38 memset(&info
, 0, sizeof(info
));
39 __semi_call(SYS_HEAPINFO
, (uintptr_t) &ptr_to_info
);
41 if (info
.heap_base
== NULL
|| info
.heap_limit
== NULL
) {
42 printf("null heap: %p -> %p\n", info
.heap_base
, info
.heap_limit
);
46 /* Error if heap base is above limit */
47 if ((uintptr_t) info
.heap_base
>= (uintptr_t) info
.heap_limit
) {
48 printf("heap base %p >= heap_limit %p\n",
49 info
.heap_base
, info
.heap_limit
);
53 if (info
.stack_base
== NULL
|| info
.stack_limit
) {
54 printf("null stack: %p -> %p\n", info
.stack_base
, info
.stack_limit
);
58 /* check our local variables are indeed inside the reported stack */
59 if (ptr_to_info
> info
.stack_base
) {
60 printf("info appears to be above stack: %p > %p\n", ptr_to_info
,
63 } else if (ptr_to_info
< info
.stack_limit
) {
64 printf("info appears to be outside stack: %p < %p\n", ptr_to_info
,
69 if (ptr_to_info
> info
.heap_base
&& ptr_to_info
< info
.heap_limit
) {
70 printf("info appears to be inside the heap: %p in %p:%p\n",
71 ptr_to_info
, info
.heap_base
, info
.heap_limit
);
75 printf("heap: %p -> %p\n", info
.heap_base
, info
.heap_limit
);
76 printf("stack: %p -> %p\n", info
.stack_base
, info
.stack_limit
);
78 __semi_call(SYS_WRITE0
, (uintptr_t) "Passed HeapInfo checks");
79 __semi_call(SYS_REPORTEXC
, exit_code
);
80 /* if we get here we failed */