summaryrefslogtreecommitdiff
path: root/src/boot/efi/log.c
blob: 9cbbb3a9337a7aa3db19ec7e77959cd39c67a36a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* SPDX-License-Identifier: LGPL-2.1-or-later */

#include "log.h"
#include "proto/simple-text-io.h"

static unsigned log_count = 0;

_noreturn_ static void freeze(void) {
        for (;;)
                BS->Stall(60 * 1000 * 1000);
}

void efi_assert(const char *expr, const char *file, unsigned line, const char *function) {
        log_error("systemd-boot assertion '%s' failed at %s:%u@%s. Halting.", expr, file, line, function);
        freeze();
}

EFI_STATUS log_internal(EFI_STATUS status, const char *format, ...) {
        assert(format);

        int32_t attr = ST->ConOut->Mode->Attribute;

        if (ST->ConOut->Mode->CursorColumn > 0)
                ST->ConOut->OutputString(ST->ConOut, (char16_t *) u"\r\n");
        ST->ConOut->SetAttribute(ST->ConOut, EFI_TEXT_ATTR(EFI_LIGHTRED, EFI_BLACK));

        va_list ap;
        va_start(ap, format);
        vprintf_status(status, format, ap);
        va_end(ap);

        ST->ConOut->OutputString(ST->ConOut, (char16_t *) u"\r\n");
        ST->ConOut->SetAttribute(ST->ConOut, attr);

        log_count++;
        return status;
}

void log_wait(void) {
        if (log_count == 0)
                return;

        BS->Stall(MIN(4u, log_count) * 2500 * 1000);
        log_count = 0;
}

#if defined(__ARM_EABI__)
/* These override the (weak) div0 handlers from libgcc as they would otherwise call raise() instead. */

_used_ _noreturn_ int __aeabi_idiv0(int return_value) {
        log_error("Division by zero.");
        freeze();
}

_used_ _noreturn_ long long __aeabi_ldiv0(long long return_value) {
        log_error("Division by zero.");
        freeze();
}
#endif