Re: Semihosting output on ARM7TDMI

Grant Edwards
2001-08-14T08:46:00Z

On Tue, Aug 14, 2001 at 11:33:02AM -0400, Andrew Cagney wrote:
> > It looks like it needs to be changed so that it is
> > pre-initialized so that stdin, stdout, and stderr are
> > "pre-opened". I think you'll need to change the code in
> > rdi-share/hsys.c HostSysInit() so that fds 0,1,2, are
> > initialized to map to FILE pointers stdin, stdout, stderr.
>
> Almost. The theory is right.
>
> For output the ``struct ui_file'' objects gdb_std*, normally target
> output is sent to gdb_stdtarg (one day I'll remember to rename it to
> gdb_targout).

Er, wha?

The routines in rdi-remote/hsys.c have no idea that gdb is "up
there" somewhere.

The RDI file table is in a structure defined like so:

typedef struct {
FILE *FileTable[HSYS_FOPEN_MAX] ;
char FileFlags[HSYS_FOPEN_MAX] ;
char *TempNames[UNIQUETEMPS];
} OSblock;

The initialization (rdi-remote/hsys.c) looks like this

77 /* Set up the state block, filetable and register the C lib callback fn */
78 int HostSysInit(const struct Dbg_HostosInterface *hostif, char **cmdline,
79 hsys_state **stateptr)
80 {
81 ChannelCallback HandleMessageFPtr = (ChannelCallback) HandleSysMessage;
82 int i;
83 *stateptr = (hsys_state *)malloc(sizeof(hsys_state));
84
85 if (*stateptr == NULL) return RDIError_OutOfStore;
86
87 (*stateptr)->hostif=hostif;
88 (*stateptr)->last_errno=0;
89 (*stateptr)->OSptr=(OSblock *)malloc(sizeof(OSblock));
90 if ((*stateptr)->OSptr == NULL) return RDIError_OutOfStore;
91 for (i=0; i<UNIQUETEMPS; i++) (*stateptr)->OSptr->TempNames[i]=NULL;
92 for (i=0; i<HSYS_FOPEN_MAX; i++) {
93 (*stateptr)->OSptr->FileTable[i]=NULL;
94 (*stateptr)->OSptr->FileFlags[i]=0;
95 }
96 (*stateptr)->CommandLine=cmdline;
97
98 return Adp_ChannelRegisterRead(CI_CLIB, (ChannelCallback)HandleMessageFPtr,
99 *stateptr);
100 }

I think that it might work if the lines below were added
somewhere after the second for() loop:

(*stateptr)->OSptr->FileTable[0] = stdin;
(*stateptr)->OSptr->FileTable[1] = stdout;
(*stateptr)->OSptr->FileTable[2] = stderr;

I don't think that FileFlags[n] needs to be initialized to
anything other than zero, but I'm not sure about that.

It would be possible to make these routines "gdb aware" but
they aren't at the moment -- semi-hosting requests are handled
below the gdb<->RDI interface.

> For input, things get messy, if you look at remote.c and fixme's from me
> there are hopefully enough hints on how it can be done, in theory. It
> is made complicated by the fact that there is an event look wanting a
> look-in.

I think you're looking at the wrong target. ;)