]>
git.saurik.com Git - apple/xnu.git/blob - pexpert/arm/pe_kprintf.c
2 * Copyright (c) 2000-2019 Apple Inc. All rights reserved.
6 * arm platform expert debugging output initialization.
9 #include <machine/machine_routines.h>
10 #include <pexpert/pexpert.h>
11 #include <kern/debug.h>
12 #include <kern/simple_lock.h>
13 #include <os/log_private.h>
14 #include <libkern/section_keywords.h>
17 typedef void (*PE_kputc_t
)(char);
18 SECURITY_READ_ONLY_LATE(PE_kputc_t
) PE_kputc
;
20 // disable_serial_output disables kprintf() *and* unbuffered panic output.
21 // disable_kprintf_output only disables kprintf().
22 SECURITY_READ_ONLY_LATE(unsigned int) disable_serial_output
= TRUE
;
23 static SECURITY_READ_ONLY_LATE(unsigned int) disable_kprintf_output
= TRUE
;
25 static SIMPLE_LOCK_DECLARE(kprintf_lock
, 0);
27 static void serial_putc_crlf(char c
);
33 if (PE_state
.initialized
== FALSE
) {
34 panic("Platform Expert not initialized");
37 if (debug_boot_arg
& DB_KPRT
) {
38 disable_serial_output
= FALSE
;
42 disable_kprintf_output
= FALSE
;
44 bool enable_kprintf_spam
= false;
45 if (PE_parse_boot_argn("-enable_kprintf_spam", &enable_kprintf_spam
, sizeof(enable_kprintf_spam
))) {
46 disable_kprintf_output
= FALSE
;
51 PE_kputc
= serial_putc_crlf
;
53 PE_kputc
= cnputc_unbuffered
;
56 STARTUP(KPRINTF
, STARTUP_RANK_FIRST
, PE_init_kprintf
);
60 _kprintf(const char *format
, ...)
64 va_start(listp
, format
);
65 _doprnt_log(format
, &listp
, PE_kputc
, 16);
68 #define MP_DEBUG_KPRINTF(x...) _kprintf(x)
70 #define MP_DEBUG_KPRINTF(x...)
73 #if CONFIG_NO_KPRINTF_STRINGS
74 /* Prevent CPP from breaking the definition below */
78 static int cpu_last_locked
= 0;
80 __attribute__((noinline
, not_tail_called
))
82 kprintf(const char *fmt
, ...)
87 void *caller
= __builtin_return_address(0);
89 if (!disable_serial_output
&& !disable_kprintf_output
) {
91 va_copy(listp2
, listp
);
93 * Spin to get kprintf lock but re-enable interrupts while failing.
94 * This allows interrupts to be handled while waiting but
95 * interrupts are disabled once we have the lock.
97 state
= ml_set_interrupts_enabled(FALSE
);
98 while (!simple_lock_try(&kprintf_lock
, LCK_GRP_NULL
)) {
99 ml_set_interrupts_enabled(state
);
100 ml_set_interrupts_enabled(FALSE
);
103 if (cpu_number() != cpu_last_locked
) {
104 MP_DEBUG_KPRINTF("[cpu%d...]\n", cpu_number());
105 cpu_last_locked
= cpu_number();
108 _doprnt_log(fmt
, &listp
, PE_kputc
, 16);
110 simple_unlock(&kprintf_lock
);
112 #if INTERRUPT_MASKED_DEBUG
114 * kprintf holds interrupts disabled for far too long
115 * and would trip the spin-debugger. If we are about to reenable
116 * interrupts then clear the timer and avoid panicking on the delay.
117 * Otherwise, let the code that printed with interrupt disabled
118 * take the panic when it reenables interrupts.
119 * Hopefully one day this is fixed so that this workaround is unnecessary.
122 ml_spin_debug_clear_self();
125 ml_set_interrupts_enabled(state
);
128 os_log_with_args(OS_LOG_DEFAULT
, OS_LOG_TYPE_DEFAULT
, fmt
, listp2
, caller
);
131 va_start(listp
, fmt
);
132 os_log_with_args(OS_LOG_DEFAULT
, OS_LOG_TYPE_DEFAULT
, fmt
, listp
, caller
);
138 serial_putc_crlf(char c
)