console: Make die() and friends variadic
die() currently only accepts a fixed message string, which is rather inconvenient when there is extra information that would be helpful to print in the error message. This currently requires an extra call to printk(), which is somewhat awkward: printk(BIOS_EMERG, "Bad table, opcode %d at %d", id, i); die(""); // what do I say here? die() already has a printk() inside it to print the error message, so let's just make it variadic to combine the two. die("Bad table, opcode %d at %d", id, i); // much better Forwarding variadic arguments from one function to another is rather tricky, so die_with_post_code() is redefined as a variadic macro instead. Change-Id: I28b9eac32899a1aa89e086e0d3889b75459581aa Signed-off-by: Jacob Garber <jgarber1@ualberta.ca> Reviewed-on: https://review.coreboot.org/c/coreboot/+/33153 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Martin Roth <martinroth@google.com> Reviewed-by: Keith Short <keithshort@chromium.org>
This commit is contained in:
parent
b5962a934a
commit
913437e8a2
|
@ -30,17 +30,15 @@ __weak void die_notify(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Report a fatal error */
|
/* Report a fatal error */
|
||||||
void __noreturn die(const char *msg)
|
void __noreturn die(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
printk(BIOS_EMERG, "%s", msg);
|
va_list args;
|
||||||
|
|
||||||
|
va_start(args, fmt);
|
||||||
|
vprintk(BIOS_EMERG, fmt, args);
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
die_notify();
|
die_notify();
|
||||||
halt();
|
halt();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Report a fatal error with a post code */
|
|
||||||
void __noreturn die_with_post_code(uint8_t value, const char *msg)
|
|
||||||
{
|
|
||||||
post_code(value);
|
|
||||||
die(msg);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -42,8 +42,9 @@ void post_log_clear(void);
|
||||||
#endif
|
#endif
|
||||||
/* this function is weak and can be overridden by a mainboard function. */
|
/* this function is weak and can be overridden by a mainboard function. */
|
||||||
void mainboard_post(u8 value);
|
void mainboard_post(u8 value);
|
||||||
void __noreturn die(const char *msg);
|
void __noreturn die(const char *fmt, ...);
|
||||||
void __noreturn die_with_post_code(uint8_t value, const char *msg);
|
#define die_with_post_code(value, fmt, ...) \
|
||||||
|
do { post_code(value); die(fmt, ##__VA_ARGS__); } while (0)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This function is weak and can be overridden to provide additional
|
* This function is weak and can be overridden to provide additional
|
||||||
|
|
Loading…
Reference in New Issue