diff --git a/README.adoc b/README.adoc index 9b1f48a..9d0a032 100644 --- a/README.adoc +++ b/README.adoc @@ -3785,6 +3785,25 @@ Simulated exit code not 0! Exit code is 1 which we parse in link:run[] and then exit with the correct result ourselves... +==== gem5 syscall emulation mode program stdin + +gem5 shows its own stdout to terminal, and does not allow you to type stdin to programs. + +Instead, you must pass stdin non-interactively with the through a file with the `--se.py --input` option, e.g.: + +.... +printf a > f +./run --emulator gem5 --userland userland/c/getchar.c --static -- --input f +.... + +leads to gem5 output: + +.... +enter a character: you entered: a +.... + +Source: link:userland/c/getchar.c[] + ==== User mode vs full system benchmark Let's see if user mode runs considerably faster than full system or not. diff --git a/path_properties.py b/path_properties.py index cfcccf6..1ea427d 100644 --- a/path_properties.py +++ b/path_properties.py @@ -75,6 +75,7 @@ path_properties_tree = PrefixTree({ 'c': PrefixTree({ 'assert_fail.c': PrefixTree(value=PathProperties(exit_status=1)), 'false.c': PrefixTree(value=PathProperties(exit_status=1)), + 'getchar.c': PrefixTree(value=PathProperties(interactive=True)), 'infinite_loop.c': PrefixTree(value=PathProperties(more_than_1s=True)), }), 'kernel_modules': PrefixTree(value=PathProperties(requires_kernel_modules=True)), diff --git a/userland/c/getchar.c b/userland/c/getchar.c new file mode 100644 index 0000000..2430e29 --- /dev/null +++ b/userland/c/getchar.c @@ -0,0 +1,21 @@ +/* Get on character from stdin, and then print it back out. + * + * Same as getc(stdin). + * + * You have to press enter for the character to go through: + * https://stackoverflow.com/questions/1798511/how-to-avoid-pressing-enter-with-getchar + * + * Used at: + * https://stackoverflow.com/questions/556405/what-do-real-user-and-sys-mean-in-the-output-of-time1/53937376#53937376 + */ + +#include +#include + +int main(void) { + char c; + printf("enter a character: "); + c = getchar(); + printf("you entered: %c\n", c); + return EXIT_SUCCESS; +}