-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Because printk() relies on a serial driver (like the ns16550 driver) and drivers require working virtual memory (ioremap()) there is not print functionality early in Xen boot. This commit adds early printk implementation built on the putc SBI call. Signed-off-by: Bobby Eshleman <bobby.eshleman@gmail.com>
- Loading branch information
1 parent
6cd6752
commit a3c9916
Showing
3 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* RISC-V early printk using SBI | ||
* | ||
* Copyright (C) 2021 Bobby Eshleman <bobbyeshleman@gmail.com> | ||
*/ | ||
#include <asm/sbi.h> | ||
#include <asm/early_printk.h> | ||
#include <xen/stdarg.h> | ||
#include <xen/lib.h> | ||
|
||
void _early_puts(const char *s, size_t nr) | ||
{ | ||
while ( nr-- > 0 ) | ||
{ | ||
if (*s == '\n') | ||
sbi_console_putchar('\r'); | ||
sbi_console_putchar(*s); | ||
s++; | ||
} | ||
} | ||
|
||
static void vprintk_early(const char *prefix, const char *fmt, va_list args) | ||
{ | ||
char buf[128]; | ||
int sz; | ||
|
||
early_puts(prefix); | ||
|
||
sz = vscnprintf(buf, sizeof(buf), fmt, args); | ||
|
||
if ( sz < 0 ) { | ||
early_puts("(XEN) vprintk_early error\n"); | ||
return; | ||
} | ||
|
||
if ( sz == 0 ) | ||
return; | ||
|
||
_early_puts(buf, sz); | ||
} | ||
|
||
void early_printk(const char *fmt, ...) | ||
{ | ||
va_list args; | ||
va_start(args, fmt); | ||
vprintk_early("(XEN) ", fmt, args); | ||
va_end(args); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#ifndef __EARLY_PRINTK_H__ | ||
#define __EARLY_PRINTK_H__ | ||
|
||
#include <xen/string.h> | ||
|
||
#define early_puts(s) _early_puts((s), strlen((s))) | ||
void _early_puts(const char *s, size_t nr); | ||
void early_printk(const char *fmt, ...); | ||
|
||
#endif /* __EARLY_PRINTK_H__ */ |