This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

libgloss/arm: monitor_stderr [PATCH]


libgloss for ARM remaps user space file descriptors to ARM kernel
space file descriptors to support descriptors 0, 1, and 2 being their
usual stdin, stdout, and stderr. monitor_stdin is set to the result of
SWI_open(":tt", "r") and monitor_stdout is set to the result of
SWI_open(":tt", "w"). monitor_stderr is set to the same value as
monitor_stdout. This results in libgloss mapping both descriptors 1
and 2 to the same value, making it impossible for the kernel to
distinguish the two.

A patch I've been using and sitting on for a while sets monitor_stderr
to the result of SWI_open(":tt", "a"). Since "a" is a write mode like
"w", most ARM kernels should act sensibly, I'm hoping. The GDB
simulator, for example, returns 1 for both "w" and "a", so it behaves
exactly the same with this patch as without. However, a kernel in the
know can now return 1 for "w" and 2 for "a". 

If someone knows of an ARM kernel that does *not* work with this
patch, I'd like to know how the kernel responds to the
SWI_open(":tt", "a") call so that I can work around it.

Cheers,
Shaun

2005-08-04  Shaun Jackman  <sjackman@gmail.com>

	* libgloss/syscalls.c (initialise_monitor_handles): Set
	monitor_stdout to the result of SWI_open(":tt", "a")
	instead of simply duplicating stdout.

Index: syscalls.c
===================================================================
RCS file: /cvs/src/src/libgloss/arm/syscalls.c,v
retrieving revision 1.5
diff -u -r1.5 syscalls.c
--- syscalls.c	18 Jul 2005 16:18:17 -0000	1.5
+++ syscalls.c	4 Aug 2005 17:18:22 -0000
@@ -145,7 +145,12 @@
   block[0] = (int) ":tt";
   block[2] = 3;     /* length of filename */
   block[1] = 4;     /* mode "w" */
-  monitor_stdout = monitor_stderr = do_AngelSWI
(AngelSWI_Reason_Open, (void *) block);
+  monitor_stdout = do_AngelSWI (AngelSWI_Reason_Open, (void *) block);
+
+  block[0] = (int) ":tt";
+  block[2] = 3;     /* length of filename */
+  block[1] = 8;     /* mode "a" */
+  monitor_stderr = do_AngelSWI (AngelSWI_Reason_Open, (void *) block);
 #else
   int fh;
   const char * name;
@@ -162,7 +167,14 @@
        : "=r"(fh)
        : "i" (SWI_Open),"r"(name)
        : "r0","r1");
-  monitor_stdout = monitor_stderr = fh;
+  monitor_stdout = fh;
+
+  name = ":tt";
+  asm ("mov r0,%2; mov r1, #8; swi %a1; mov %0, r0"
+       : "=r"(fh)
+       : "i" (SWI_Open),"r"(name)
+       : "r0","r1");
+  monitor_stderr = fh;
 #endif
 
   for (i = 0; i < MAX_OPEN_FILES; i ++)
@@ -172,6 +184,8 @@
   openfiles[0].pos = 0;
   openfiles[1].handle = monitor_stdout;
   openfiles[1].pos = 0;
+  openfiles[2].handle = monitor_stderr;
+  openfiles[2].pos = 0;
 }
 
 static int
2005-08-04  Shaun Jackman  <sjackman@gmail.com>

	* libgloss/syscalls.c (initialise_monitor_handles): Set
	monitor_stdout to the result of SWI_open(":tt", "a")
	instead of simply duplicating stdout.

Index: syscalls.c
===================================================================
RCS file: /cvs/src/src/libgloss/arm/syscalls.c,v
retrieving revision 1.5
diff -u -r1.5 syscalls.c
--- syscalls.c	18 Jul 2005 16:18:17 -0000	1.5
+++ syscalls.c	4 Aug 2005 17:18:22 -0000
@@ -145,7 +145,12 @@
   block[0] = (int) ":tt";
   block[2] = 3;     /* length of filename */
   block[1] = 4;     /* mode "w" */
-  monitor_stdout = monitor_stderr = do_AngelSWI (AngelSWI_Reason_Open, (void *) block);
+  monitor_stdout = do_AngelSWI (AngelSWI_Reason_Open, (void *) block);
+
+  block[0] = (int) ":tt";
+  block[2] = 3;     /* length of filename */
+  block[1] = 8;     /* mode "a" */
+  monitor_stderr = do_AngelSWI (AngelSWI_Reason_Open, (void *) block);
 #else
   int fh;
   const char * name;
@@ -162,7 +167,14 @@
        : "=r"(fh)
        : "i" (SWI_Open),"r"(name)
        : "r0","r1");
-  monitor_stdout = monitor_stderr = fh;
+  monitor_stdout = fh;
+
+  name = ":tt";
+  asm ("mov r0,%2; mov r1, #8; swi %a1; mov %0, r0"
+       : "=r"(fh)
+       : "i" (SWI_Open),"r"(name)
+       : "r0","r1");
+  monitor_stderr = fh;
 #endif
 
   for (i = 0; i < MAX_OPEN_FILES; i ++)
@@ -172,6 +184,8 @@
   openfiles[0].pos = 0;
   openfiles[1].handle = monitor_stdout;
   openfiles[1].pos = 0;
+  openfiles[2].handle = monitor_stderr;
+  openfiles[2].pos = 0;
 }
 
 static int

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]