rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2012-2014 Travis Geiselbrecht |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining |
| 5 | * a copy of this software and associated documentation files |
| 6 | * (the "Software"), to deal in the Software without restriction, |
| 7 | * including without limitation the rights to use, copy, modify, merge, |
| 8 | * publish, distribute, sublicense, and/or sell copies of the Software, |
| 9 | * and to permit persons to whom the Software is furnished to do so, |
| 10 | * subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice shall be |
| 13 | * included in all copies or substantial portions of the Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 22 | */ |
| 23 | #ifndef __KERNEL_DEBUG_H |
| 24 | #define __KERNEL_DEBUG_H |
| 25 | |
| 26 | #include <compiler.h> |
| 27 | |
| 28 | __BEGIN_CDECLS; |
| 29 | |
| 30 | #include <debug.h> |
| 31 | |
| 32 | /* kernel event log */ |
| 33 | #if WITH_KERNEL_EVLOG |
| 34 | |
| 35 | #include <lib/evlog.h> |
| 36 | |
| 37 | #ifndef KERNEL_EVLOG_LEN |
| 38 | #define KERNEL_EVLOG_LEN 1024 |
| 39 | #endif |
| 40 | |
| 41 | void kernel_evlog_init(void); |
| 42 | |
| 43 | void kernel_evlog_add(uintptr_t id, uintptr_t arg0, uintptr_t arg1); |
| 44 | void kernel_evlog_dump(void); |
| 45 | |
| 46 | #else // !WITH_KERNEL_EVLOG |
| 47 | |
| 48 | /* do nothing versions */ |
| 49 | static inline void kernel_evlog_init(void) {} |
| 50 | static inline void kernel_evlog_add(uintptr_t id, uintptr_t arg0, uintptr_t arg1) {} |
| 51 | static inline void kernel_evlog_dump(void) {} |
| 52 | |
| 53 | #endif |
| 54 | |
| 55 | enum { |
| 56 | KERNEL_EVLOG_NULL = 0, |
| 57 | KERNEL_EVLOG_CONTEXT_SWITCH, |
| 58 | KERNEL_EVLOG_PREEMPT, |
| 59 | KERNEL_EVLOG_TIMER_TICK, |
| 60 | KERNEL_EVLOG_TIMER_CALL, |
| 61 | KERNEL_EVLOG_IRQ_ENTER, |
| 62 | KERNEL_EVLOG_IRQ_EXIT, |
| 63 | }; |
| 64 | |
| 65 | #define KEVLOG_THREAD_SWITCH(from, to) kernel_evlog_add(KERNEL_EVLOG_CONTEXT_SWITCH, (uintptr_t)from, (uintptr_t)to) |
| 66 | #define KEVLOG_THREAD_PREEMPT(thread) kernel_evlog_add(KERNEL_EVLOG_PREEMPT, (uintptr_t)thread, 0) |
| 67 | #define KEVLOG_TIMER_TICK() kernel_evlog_add(KERNEL_EVLOG_TIMER_TICK, 0, 0) |
| 68 | #define KEVLOG_TIMER_CALL(ptr, arg) kernel_evlog_add(KERNEL_EVLOG_TIMER_CALL, (uintptr_t)ptr, (uintptr_t)arg) |
| 69 | #define KEVLOG_IRQ_ENTER(irqn) kernel_evlog_add(KERNEL_EVLOG_IRQ_ENTER, (uintptr_t)irqn, 0) |
| 70 | #define KEVLOG_IRQ_EXIT(irqn) kernel_evlog_add(KERNEL_EVLOG_IRQ_EXIT, (uintptr_t)irqn, 0) |
| 71 | |
| 72 | __END_CDECLS; |
| 73 | |
| 74 | #endif |
| 75 | |