Skip to content

Commit

Permalink
Merge pull request #271 from sifive/fake_serial_port
Browse files Browse the repository at this point in the history
tty.c: added a nop hint to nop_putc() so that post-processing can see…
  • Loading branch information
nategraff-sifive authored Jul 17, 2020
2 parents 5f32db1 + 6305652 commit 1db2ff1
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/tty.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,19 @@ METAL_CONSTRUCTOR(metal_tty_init) {
* provide a shim that eats all the characters so we can ensure that everything
* can link to metal_tty_putc. */
int nop_putc(int c) __attribute__((section(".text.metal.nop.putc")));
int nop_putc(int c) { return -1; }
// Use a customizable NOP hint instruction so that a post-processor parser can
// look for this instruction, and use the value in a0 as the character to be
// printed.
int nop_putc(int c) {
// The ABI states that c will be passed in a0. However, under an LTO
// (link-time-optimizer), it may choose to optimize in ways that would
// break this assumption. We want to ensure that the passed argument is
// truly in a0, for easier post-processing, and so there is a single
// 32-bit opcode to match against.
// So explicitly ensure that the argument is placed into a0 first.
__asm__ volatile("mv a0, %0; slli x0,a0,0x11" ::"r"(c));
return -1;
}
int metal_tty_putc(int c) __attribute__((weak, alias("nop_putc")));
#pragma message( \
"There is no default output device, metal_tty_putc() will throw away all input.")
Expand Down

0 comments on commit 1db2ff1

Please sign in to comment.