Skip to content

Commit

Permalink
Improve early kernel debugging prints
Browse files Browse the repository at this point in the history
Since the early kernel debugging prints are useful only in a few
debugging scenarios, define a configuration option that disables them by
default (if enabled, it produces duplicate output which might be
confusing).

Implement early kernel debugging prints for the HiKey960.
  • Loading branch information
martin-decky committed Sep 15, 2021
1 parent 8ce56a6 commit ebb3538
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 7 deletions.
3 changes: 3 additions & 0 deletions HelenOS.config
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,9 @@
% Debug build
! CONFIG_DEBUG (y/n)

% Early debugging print
! [CONFIG_DEBUG=y] CONFIG_DEBUG_EARLY_PRINT (n/y)

% Sanitize undefined behavior (userspace)
! CONFIG_UBSAN (n/y)

Expand Down
4 changes: 4 additions & 0 deletions kernel/arch/amd64/src/asm.S
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,8 @@ bad_rip_msg:
*/
FUNCTION_BEGIN(early_putuchar)

#if (defined(CONFIG_DEBUG_EARLY_PRINT))

#if (defined(CONFIG_L4RE_UVMM_EARLY_PRINT))
xorl %eax, %eax /* RAX==0: uvmm's print hypercall */
mov %rdi, %rcx /* RCX: printed character */
Expand Down Expand Up @@ -540,6 +542,8 @@ FUNCTION_BEGIN(early_putuchar)
popq %rbx
leave

#endif

#endif

ret
Expand Down
2 changes: 2 additions & 0 deletions kernel/arch/arm64/include/arch/machine_func.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ struct arm_machine_ops {
inr_t (*machine_enable_vtimer_irq)(void);
size_t (*machine_get_irq_count)(void);
const char *(*machine_get_platform_name)(void);
void (*machine_early_uart_output)(char32_t);
};

extern void machine_ops_init(void);
Expand All @@ -59,6 +60,7 @@ extern void machine_input_init(void);
extern inr_t machine_enable_vtimer_irq(void);
extern size_t machine_get_irq_count(void);
extern const char *machine_get_platform_name(void);
extern void machine_early_uart_output(char32_t);

#endif

Expand Down
11 changes: 11 additions & 0 deletions kernel/arch/arm64/src/arm64.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <arch/asm.h>
#include <arch/exception.h>
#include <arch/machine_func.h>
#include <console/console.h>
#include <interrupt.h>
#include <proc/scheduler.h>
#include <syscall/syscall.h>
Expand Down Expand Up @@ -255,5 +256,15 @@ void irq_initialize_arch(irq_t *irq __attribute__((unused)))
{
}

void early_putuchar(char32_t c)
{
#ifdef CONFIG_DEBUG_EARLY_PRINT
if (c == '\n')
machine_early_uart_output('\r');

machine_early_uart_output(c);
#endif
}

/** @}
*/
4 changes: 0 additions & 4 deletions kernel/arch/arm64/src/asm.S
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ FUNCTION_BEGIN(memcpy_to_uspace_failover_address)
FUNCTION_END(memcpy_from_uspace_failover_address)
FUNCTION_END(memcpy_to_uspace_failover_address)

FUNCTION_BEGIN(early_putuchar)
ret
FUNCTION_END(early_putuchar)

/** Flush instruction caches
*
* @param x0 Starting address of the flushing.
Expand Down
16 changes: 15 additions & 1 deletion kernel/arch/arm64/src/mach/hikey960/hikey960.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,28 @@ static const char *hikey960_get_platform_name(void)
return "hikey960";
}

static void hikey960_early_uart_output(char32_t c)
{
volatile uint32_t *uartdr = (volatile uint32_t *)
PA2KA(HIKEY960_UART_ADDRESS);
volatile uint32_t *uartfr = (volatile uint32_t *)
PA2KA(HIKEY960_UART_ADDRESS + 24);

while (*uartfr & 0x20U) {
}

*uartdr = c;
}

struct arm_machine_ops hikey960_machine_ops = {
hikey960_init,
hikey960_irq_exception,
hikey960_output_init,
hikey960_input_init,
hikey960_enable_vtimer_irq,
hikey960_get_irq_count,
hikey960_get_platform_name
hikey960_get_platform_name,
hikey960_early_uart_output
};

/** @}
Expand Down
7 changes: 7 additions & 0 deletions kernel/arch/arm64/src/machine_func.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,12 @@ const char *machine_get_platform_name(void)
return machine_ops->machine_get_platform_name();
}

/** Early debugging output. */
void machine_early_uart_output(char32_t c)
{
if (machine_ops->machine_early_uart_output != NULL)
machine_ops->machine_early_uart_output(c);
}

/** @}
*/
2 changes: 1 addition & 1 deletion kernel/arch/ia32/src/asm.S
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ interrupt_handlers:
*/
FUNCTION_BEGIN(early_putuchar)

#if ((defined(CONFIG_EGA)) && (!defined(CONFIG_FB)))
#if ((defined(CONFIG_DEBUG_EARLY_PRINT)) && (defined(CONFIG_EGA)) && (!defined(CONFIG_FB)))

/* Prologue, save preserved registers */
pushl %ebp
Expand Down
2 changes: 1 addition & 1 deletion kernel/generic/src/console/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ void putuchar(const char32_t ch)
*
* The early_putuchar() function is used to output
* the character for low-level debugging purposes.
* Note that the early_putc() function might be
* Note that the early_putuchar() function might be
* a no-op on certain hardware configurations.
*/
early_putuchar(ch);
Expand Down

0 comments on commit ebb3538

Please sign in to comment.