Add a default common print method
This commit is contained in:
parent
1f25cc23da
commit
8ccf823c67
@ -2,10 +2,17 @@
|
|||||||
#define COMMON_H
|
#define COMMON_H
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a kernel panic message through the UART and hang the core.
|
* Sends a panic message through the default output of the kernel.
|
||||||
* @param format The format of the message
|
* @param format The format of the message
|
||||||
* @param ... The parameters of the message
|
* @param ... The parameters of the message
|
||||||
*/
|
*/
|
||||||
void panic(const char *format, ...);
|
void panic(const char *format, ...);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prints a string to the default output of the kernel.
|
||||||
|
* @param format The format of the string
|
||||||
|
* @param ... The parameters of the string
|
||||||
|
*/
|
||||||
|
void print(const char *format, ...);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@ -1,3 +1,4 @@
|
|||||||
|
#include "common.h"
|
||||||
#include "syscon.h"
|
#include "syscon.h"
|
||||||
#include "uart.h"
|
#include "uart.h"
|
||||||
|
|
||||||
@ -5,7 +6,8 @@
|
|||||||
|
|
||||||
void kmain(void) {
|
void kmain(void) {
|
||||||
uart_init();
|
uart_init();
|
||||||
uart_printf("Hello world, %s!\n", ARCH);
|
|
||||||
|
print("Hello world, %s!\n", ARCH);
|
||||||
|
|
||||||
power_off();
|
power_off();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,21 +1,39 @@
|
|||||||
#include "../common.h"
|
#include "../common.h"
|
||||||
|
#include "../uart.h"
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
#include "../uart.h"
|
#define VPRINT(method, format, args) \
|
||||||
|
VPRINT_(method, format, args)
|
||||||
|
#define VPRINT_(method, format, args) \
|
||||||
|
method ## _ ## vprintf(format, args)
|
||||||
|
|
||||||
|
#define PRINT(method, str)\
|
||||||
|
PRINT_(method, str)
|
||||||
|
#define PRINT_(method, str)\
|
||||||
|
method ## _ ## puts(str)
|
||||||
|
|
||||||
|
#define DEFAULT_OUTPUT_METHOD uart
|
||||||
|
#define DEFAULT_PRINT_ARGS(format) \
|
||||||
|
va_list args = nullptr; \
|
||||||
|
va_start(args, format); \
|
||||||
|
DEFAULT_VPRINT(format, args); \
|
||||||
|
va_end(args)
|
||||||
|
#define DEFAULT_VPRINT(format, args) \
|
||||||
|
VPRINT(DEFAULT_OUTPUT_METHOD, format, args)
|
||||||
|
#define DEFAULT_PRINT(str)\
|
||||||
|
PRINT(DEFAULT_OUTPUT_METHOD, str)
|
||||||
|
|
||||||
void panic(const char *format, ...) {
|
void panic(const char *format, ...) {
|
||||||
uart_puts("Kernel panic!");
|
DEFAULT_PRINT("Kernel panic!");
|
||||||
uart_puts("Reason:");
|
DEFAULT_PRINT("Reason:");
|
||||||
|
|
||||||
va_list args = nullptr;
|
|
||||||
va_start(args, format);
|
|
||||||
|
|
||||||
// Print the reason
|
// Print the reason
|
||||||
uart_vprintf(format, args);
|
DEFAULT_PRINT_ARGS(format);
|
||||||
|
|
||||||
va_end(args);
|
|
||||||
|
|
||||||
// Hang
|
// Hang
|
||||||
asm volatile("wfi");
|
asm volatile("wfi");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void print(const char *format, ...) {
|
||||||
|
DEFAULT_PRINT_ARGS(format);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user