This is the mail archive of the
gdb@sources.redhat.com
mailing list for the GDB project.
File I/O in H8300 Simulator
- From: "D.Venkatasubramanian, Noida" <dvenkat at noida dot hcltech dot com>
- To: Kazu Hirata <kazu at cs dot umass dot edu>, gdb at sources dot redhat dot com
- Date: Mon, 28 Oct 2002 16:00:49 +0530
- Subject: File I/O in H8300 Simulator
Hi All,
I was intending to add File I/O support to the H8300 simulator
code. And the system calls that I was intending to modify were
creat, open, read, write, seek and close.
Since the support for read was present in the newlib, I started
out with adding reading from stdin support in the sim. I am
submitting a patch which does the same.
I was thinking of adopting a similar strategy for handling the
other system calls, (branch to some location like 0xc5, 0xc6 etc.)
for different system calls and handle these through simulator. For
these system calls, I need to do some modifications on newlib too.
I may need to change the current implementation of read and write
again to handle host files.
Please let me know, if this is OK.
Thanks and Regards,
Venky
*** include/opcode/h8300.h.original Thu Oct 24 15:56:06 2002
--- include/opcode/h8300.h.modified Mon Oct 28 12:40:18 2002
*************** struct h8_opcode
*** 305,310 ****
--- 305,317 ----
#define O_STM 86
#define O_STMAC 87
#define O_LAST 88
+ /* Change made for System Call processing */
+ #define O_SYS_CREAT 100
+ #define O_SYS_OPEN 101
+ #define O_SYS_READ 102
+ #define O_SYS_WRITE 103
+ #define O_SYS_SEEK 104
+ /* End of Changes */
#define SB 0
#define SW 1
#define SL 2
*** sim/h8300/compile.c.original Mon Oct 28 13:03:12 2002
--- sim/h8300/compile.c.modified Mon Oct 28 13:03:20 2002
*************** decode (addr, data, dst)
*** 448,464 ****
dst->opcode = q->how;
dst->cycles = q->time;
! /* And a jsr to 0xc4 is turned into a magic trap. */
if (dst->opcode == O (O_JSR, SB))
{
if (dst->src.literal == 0xc4)
{
! dst->opcode = O (O_SYSCALL, SB);
}
}
!
! dst->next_pc = addr + len / 2;
return;
}
else
--- 448,469 ----
dst->opcode = q->how;
dst->cycles = q->time;
! /* And a jsr to 0xc4 or 0xc8 is turned into a magic trap.
*/
! /* System Call Processing */
if (dst->opcode == O (O_JSR, SB))
{
if (dst->src.literal == 0xc4)
{
! dst->opcode = O (O_SYS_WRITE, SB);
! }
! else if (dst->src.literal == 0xc8)
! {
! dst->opcode = O (O_SYS_READ, SB);
}
}
!
! dst->next_pc = addr + len / 2;
return;
}
else
*************** sim_resume (sd, step, siggnal)
*** 1392,1405 ****
goto condtrue;
goto next;
! case O (O_SYSCALL, SB):
{
char c = cpu.regs[2];
sim_callback->write_stdout (sim_callback, &c, 1);
}
goto next;
! ONOT (O_NOT, rd = ~rd; v = 0;);
OSHIFTS (O_SHLL,
c = rd & hm; v = 0; rd <<= 1,
c = rd & (hm >> 1); v = 0; rd <<= 2);
--- 1397,1418 ----
goto condtrue;
goto next;
! /* System Call Processing */
! case O (O_SYS_WRITE, SB):
{
char c = cpu.regs[2];
sim_callback->write_stdout (sim_callback, &c, 1);
}
goto next;
+ case O (O_SYS_READ, SB):
+ {
+ char d ;
+ sim_callback->read_stdin (sim_callback, &d, 1);
+ SET_MEMORY_B (cpu.regs[2], d);
+ }
+ goto next;
! ONOT (O_NOT, rd = ~rd; v = 0;);
OSHIFTS (O_SHLL,
c = rd & hm; v = 0; rd <<= 1,
c = rd & (hm >> 1); v = 0; rd <<= 2);
Change Log entries
Mon Oct 28 14:12:42 IST 2002 D.Venkatasubramanian
<dvenkat@noida.hcltech.com>
* compile.c (decode): Added code to recognize a read system
call and modified to recognize write system call.
* compile.c (sim_resume): Added code for handling read system
call and modified code for write.
Mon Oct 28 12:41:37 IST 2002 D.Venkatasubramanian
<dvenkat@noida.hcltech.com>
* h8300.h : Added some # defines for system call processing.
These system calls are being introduced as pseudo opcodes
for system call handling in the simulator. This is similar
to the O_SYSCALL entry already present.