xref: /freebsd/sys/arm/include/stack.h (revision 2e3f49888ec8851bafb22011533217487764fdb0)
1 /*-
2  * Copyright (c) 2000, 2001 Ben Harris
3  * Copyright (c) 1996 Scott K. Stevens
4  *
5  * Mach Operating System
6  * Copyright (c) 1991,1990 Carnegie Mellon University
7  * All Rights Reserved.
8  *
9  * Permission to use, copy, modify and distribute this software and its
10  * documentation is hereby granted, provided that both the copyright
11  * notice and this permission notice appear in all copies of the
12  * software, derivative works or modified versions, and any portions
13  * thereof, and that both notices appear in supporting documentation.
14  *
15  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
17  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18  *
19  * Carnegie Mellon requests users of this software to return to
20  *
21  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
22  *  School of Computer Science
23  *  Carnegie Mellon University
24  *  Pittsburgh PA 15213-3890
25  *
26  * any improvements or extensions that they make and grant Carnegie the
27  * rights to redistribute these changes.
28  */
29 
30 #ifndef _MACHINE_STACK_H_
31 #define	_MACHINE_STACK_H_
32 
33 #define INKERNEL(va)	(((vm_offset_t)(va)) >= VM_MIN_KERNEL_ADDRESS)
34 
35 #define FR_SCP	(0)
36 #define FR_RLV	(-1)
37 #define FR_RSP	(-2)
38 #define FR_RFP	(-3)
39 
40 /* The state of the unwind process */
41 struct unwind_state {
42 	uint32_t registers[16];
43 	uint32_t start_pc;
44 	uint32_t *insn;
45 	u_int entries;
46 	u_int byte;
47 	uint16_t update_mask;
48 };
49 
50 /* The register names */
51 #define	FP	11
52 #define	SP	13
53 #define	LR	14
54 #define	PC	15
55 
56 #ifdef _KERNEL
57 
58 int unwind_stack_one(struct unwind_state *, int);
59 
60 struct linker_file;
61 void unwind_module_loaded(struct linker_file *);
62 void unwind_module_unloaded(struct linker_file *);
63 
64 #ifdef _SYS_PROC_H_
65 
66 #include <machine/pcb.h>
67 
68 /* Get the current kernel thread stack usage. */
69 #define	GET_STACK_USAGE(total, used) do {				\
70 	struct thread *td = curthread;					\
71 	(total) = td->td_kstack_pages * PAGE_SIZE - sizeof(struct pcb);	\
72 	(used) = td->td_kstack + (total) - (vm_offset_t)&td;		\
73 } while (0)
74 
75 static __inline bool
76 kstack_contains(struct thread *td, vm_offset_t va, size_t len)
77 {
78 	return (va >= td->td_kstack && va + len >= va &&
79 	    va + len <= td->td_kstack + td->td_kstack_pages * PAGE_SIZE -
80 	    sizeof(struct pcb));
81 }
82 #endif	/* _SYS_PROC_H_ */
83 
84 #endif
85 
86 #endif /* !_MACHINE_STACK_H_ */
87