Boot framework rework (#45)
[lunaix-os.git] / lunaix-os / includes / lunaix / trace.h
1 #ifndef __LUNAIX_TRACE_H
2 #define __LUNAIX_TRACE_H
3
4 #include <lunaix/boot_generic.h>
5 #include <lunaix/hart_state.h>
6 #include <lunaix/generic/trace_arch.h>
7
8 struct ksym_entry
9 {
10     ptr_t pc;
11     char* label;
12 } align(8);
13
14 struct trace_record
15 {
16     ptr_t pc;
17     ptr_t sym_pc;
18     char* symbol;
19 };
20
21 struct ksyms
22 {
23     unsigned long ksym_count;
24     struct ksym_entry syms[0];
25 };
26
27 struct trace_context
28 {
29     struct ksyms* ksym_table;
30 };
31
32 /**
33  * @brief Init the trace service using loaded modksyms module
34  *
35  * @param bhctx
36  */
37 void
38 trace_modksyms_init(struct boot_handoff* bhctx);
39
40 /**
41  * @brief Locate the symbol which is the closest to given pc.
42  *
43  * @param pc
44  * @return struct ksym_entry*
45  */
46 struct ksym_entry*
47 trace_sym_lookup(ptr_t pc);
48
49 /**
50  * @brief Walk the stack backwards to generate stack trace
51  *
52  * @param tb_buffer
53  * @param fp
54  * @param limit
55  * @param last_fp
56  * @return int
57  */
58 int
59 trace_walkback(struct trace_record* tb_buffer,
60                ptr_t fp,
61                int limit,
62                ptr_t* last_fp);
63
64 /**
65  * @brief Print the stack trace starting from the given frame pointer
66  *
67  * @param fp
68  */
69 void
70 trace_printstack_of(ptr_t fp);
71
72 /**
73  * @brief Print the stack trace given the current interrupt context. In addition
74  * to the stacktrace, this will also print all context switches happened
75  * beforehand, and all stack trace in each context. Recommended for verbose
76  * debugging.
77  *
78  * @param isrm
79  */
80 void
81 trace_printstack_isr(const struct hart_state* hstate);
82
83 /**
84  * @brief Print the stack trace starting from caller's frame pointer.
85  *
86  */
87 void
88 trace_printstack();
89
90 void
91 trace_log(const char* fmt, ...);
92
93 #endif /* __LUNAIX_TRACE_H */