diff --git a/arm-semi.c b/arm-semi.c
index 9549e6c..6874036 100644
--- a/arm-semi.c
+++ b/arm-semi.c
@@ -211,8 +211,11 @@ uint32_t do_arm_semihosting(CPUState *env)
          if (strcmp(s, ":tt") == 0) {
              if (ARG(1) < 4)
                  return STDIN_FILENO;
-            else
+            else if (ARG(1) == 4)
                  return STDOUT_FILENO;
+           else
+             return STDERR_FILENO; /* See newlib/libgloss
+                                      implementation.  */
          }
          if (use_gdb_syscalls()) {
              gdb_do_syscall(arm_semi_cb, "open,%s,%x,1a4", ARG(0),
