libgloss/arm: monitor_stderr [PATCH]
Jeff Johnston
jjohnstn@redhat.com
Tue Aug 16 18:07:00 GMT 2005
Patch checked in. Thanks.
-- Jeff J.
Shaun Jackman wrote:
> 2005/8/5, Nick Clifton <nickc@redhat.com>:
>
>>Assuming that nobody from the kernel world has a problem with this, then
>>I would have no problem recommending that Jeff accepts it - with one
>>proviso however:
>
> ...
>
>>I think that you ought to add a comment to the code explaining the
>>situation (ie opening the same file name with different modes in order
>>to allow the kernel to choose whether to use one or two file
>>descriptors). Otherwise future programmers might come along and think
>>that this is a bug.
>>
>>Cheers
>> Nick
>
>
> I've added an explanatory comment.
>
> Cheers,
> Shaun
>
> 2005-08-04 Shaun Jackman <sjackman@gmail.com>
>
> * libgloss/syscalls.c (initialise_monitor_handles): Set
> monitor_stderr to the result of SWI_open(":tt", "a")
> instead of simply duplicating stdout.
>
> Index: libgloss/arm/syscalls.c
> ===================================================================
> RCS file: /cvs/src/src/libgloss/arm/syscalls.c,v
> retrieving revision 1.6
> diff -u -r1.6 syscalls.c
> --- libgloss/arm/syscalls.c 2 Aug 2005 19:17:21 -0000 1.6
> +++ libgloss/arm/syscalls.c 15 Aug 2005 23:05:07 -0000
> @@ -133,6 +133,16 @@
> {
> int i;
>
> + /* Open the standard file descriptors by opening the special
> + * teletype device, ":tt", read-only to obtain a descritpor for
> + * standard input and write-only to obtain a descriptor for standard
> + * output. Finally, open ":tt" in append mode to obtain a descriptor
> + * for standard error. Since this is a write mode, most kernels will
> + * probably return the same value as for standard output, but the
> + * kernel can differentiate the two using the mode flag and return a
> + * different descriptor for standard error.
> + */
> +
> #ifdef ARM_RDI_MONITOR
> int volatile block[3];
>
> @@ -144,7 +154,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;
> @@ -161,7 +176,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 ++)
> @@ -171,6 +193,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_stderr to the result of SWI_open(":tt", "a")
> instead of simply duplicating stdout.
>
> Index: libgloss/arm/syscalls.c
> ===================================================================
> RCS file: /cvs/src/src/libgloss/arm/syscalls.c,v
> retrieving revision 1.6
> diff -u -r1.6 syscalls.c
> --- libgloss/arm/syscalls.c 2 Aug 2005 19:17:21 -0000 1.6
> +++ libgloss/arm/syscalls.c 15 Aug 2005 23:05:07 -0000
> @@ -133,6 +133,16 @@
> {
> int i;
>
> + /* Open the standard file descriptors by opening the special
> + * teletype device, ":tt", read-only to obtain a descritpor for
> + * standard input and write-only to obtain a descriptor for standard
> + * output. Finally, open ":tt" in append mode to obtain a descriptor
> + * for standard error. Since this is a write mode, most kernels will
> + * probably return the same value as for standard output, but the
> + * kernel can differentiate the two using the mode flag and return a
> + * different descriptor for standard error.
> + */
> +
> #ifdef ARM_RDI_MONITOR
> int volatile block[3];
>
> @@ -144,7 +154,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;
> @@ -161,7 +176,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 ++)
> @@ -171,6 +193,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
More information about the Newlib
mailing list