Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* RE: PATCH : H8300 Simulator File I/O Implementation
@ 2002-12-23 22:59 D.Venkatasubramanian, Noida
  2002-12-24  6:51 ` Kazu Hirata
  0 siblings, 1 reply; 16+ messages in thread
From: D.Venkatasubramanian, Noida @ 2002-12-23 22:59 UTC (permalink / raw)
  To: gdb-patches, binutils, newlib

Hi All,

I had submitted a patch for providing File I/O Support for 
H8300 simulator. The message link is:

http://sources.redhat.com/ml/gdb-patches/2002-12/msg00013.html 

Could you point out if this patch is acceptable, or are there 
still some inconsistencies to be fixed. I would be willing to 
do any further changes required. 

Hope to get a indication soon.

Thanx and Regards,

Venky


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: PATCH : H8300 Simulator File I/O Implementation
  2002-12-23 22:59 PATCH : H8300 Simulator File I/O Implementation D.Venkatasubramanian, Noida
@ 2002-12-24  6:51 ` Kazu Hirata
  0 siblings, 0 replies; 16+ messages in thread
From: Kazu Hirata @ 2002-12-24  6:51 UTC (permalink / raw)
  To: dvenkat; +Cc: gdb-patches, binutils, newlib

Hi Venky,

> I had submitted a patch for providing File I/O Support for 
> H8300 simulator. The message link is:
> 
> http://sources.redhat.com/ml/gdb-patches/2002-12/msg00013.html 
> 
> Could you point out if this patch is acceptable, or are there 
> still some inconsistencies to be fixed. I would be willing to 
> do any further changes required. 

Not being the maintainer of the h8300 port other than in gcc...

I would split the gdb part of your patch into the opcodes part and the
rest because opcodes is part of binutils.

I am guessing that you probably don't need to change the order of
functions in newlib/libc/sys/h8300hms/syscalls.c.  You might want to
submit a patch with few or no formatting changes to make your real
changes exposed.  See the attached patch below.  Also, please use
"asm (...)" instead of "asm(...)".

For the gdb part, I would run 'indent' to see what it recommends.  One
thing it suggests should be to change

! 	    filename = (char *)malloc(sizeof(char) * len);

to something like

! 	    filename = (char *) malloc (sizeof (char) * len);

Some variables seem to be unused.

! 	case O (O_SYS_FSTAT, SB):
	     :
	     :
! 	    int i = 0;            /* Loop Counter */
! 	    int j = 0;            /* Temporary variable for Position in source */
! 	    int short_size = sizeof (short); /* Sizeof short */
! 	    int int_size = sizeof (int);     /* Sizeof int */

Here i, j, short_size, and int_size seem to be unused.

! 	case O (O_SYS_STAT, SB):
	     :
	     :
! 	    int j = 0;            /* Temporary variable for Position in source */
! 	    int short_size = sizeof (short); /* Sizeof short */
! 	    int int_size = sizeof (int);     /* Sizeof int */


Here j, short_size, and int_size seem to be unused.

Meanwhile, I'll try to run the simulator with your patch.  Thanks!

Kazu Hirata

Index: syscalls.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/sys/h8300hms/syscalls.c,v
retrieving revision 1.3
diff -c -r1.3 syscalls.c
*** syscalls.c	17 May 2002 20:13:38 -0000	1.3
--- syscalls.c	16 Dec 2002 23:32:08 -0000
***************
*** 4,9 ****
--- 4,10 ----
  #include <sys/types.h>
  #include <sys/stat.h>
  #include <errno.h>
+ #include "sys/syscall.h"
  
  
  int _DEFUN(_lseek,(file, ptr, dir),
***************
*** 11,23 ****
  	  int ptr _AND
  	  int dir)
  {
!   return 0;
  }
  
  int _DEFUN(_close,(file),
  	  int file)
  {
!   return -1;
  }
  
  int isatty(file)
--- 12,24 ----
  	  int ptr _AND
  	  int dir)
  {
!   asm ("jsr @@0xc8");
  }
  
  int _DEFUN(_close,(file),
  	  int file)
  {
!   asm ("jsr @@0xc9");
  }
  
  int isatty(file)
***************
*** 26,37 ****
    return 1;
  }
  
  int _DEFUN(_fstat,(file, st),
  	  int file _AND
  	  struct stat *st)
  {
!   st->st_mode = S_IFCHR;
!   return 0;
  }
  
  int
--- 27,45 ----
    return 1;
  }
  
+ int _DEFUN(_stat,(path, sbuf),
+ 	const char *path _AND
+ 	struct stat *st)
+ {
+   asm ("jsr @@0xca");
+ }
+ 
+ 
  int _DEFUN(_fstat,(file, st),
  	  int file _AND
  	  struct stat *st)
  {
!   asm ("jsr @@0xcb"); 
  }
  
  int
***************
*** 39,45 ****
       const char *path;
       int flags;
  {
!   return 0;
  }
  
  int
--- 47,53 ----
       const char *path;
       int flags;
  {
!   asm ("jsr @@0xc5");
  }
  
  int


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: PATCH : H8300 Simulator File I/O Implementation
  2003-03-04 16:08   ` Andrew Cagney
@ 2003-03-04 16:33     ` Kazu Hirata
  0 siblings, 0 replies; 16+ messages in thread
From: Kazu Hirata @ 2003-03-04 16:33 UTC (permalink / raw)
  To: ac131313; +Cc: gdb-patches

Hi Andrew,

> something that got dropped somewhere. Can you please add your self
> to GDB's write after approval list as `an obvious fix'.  Don't
> forget to post the change and changelog.

Do you mean gdb/MAINTAINERS?  I committed the attached patch as
obvious.

Kazu Hirata

2003-03-04  Kazu Hirata  <kazu@cs.umass.edu>

	* MAINTAINERS (Write after approval): Update my email address.

Index: MAINTAINERS
===================================================================
RCS file: /cvs/src/src/gdb/MAINTAINERS,v
retrieving revision 1.227
diff -u -r1.227 MAINTAINERS
--- MAINTAINERS	24 Feb 2003 22:21:13 -0000	1.227
+++ MAINTAINERS	4 Mar 2003 16:28:43 -0000
@@ -339,7 +339,7 @@
 Aldy Hernandez					aldyh@redhat.com
 Paul Hilfinger					hilfinger@gnat.com
 Matt Hiller					hiller@redhat.com
-Kazu Hirata					kazu@hxi.com
+Kazu Hirata					kazu@cs.umass.edu
 Jeff Holcomb					jeffh@redhat.com
 Don Howard					dhoward@redhat.com
 Martin Hunt					hunt@redhat.com


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: PATCH : H8300 Simulator File I/O Implementation
  2002-11-30 10:01 ` Kazu Hirata
@ 2003-03-04 16:08   ` Andrew Cagney
  2003-03-04 16:33     ` Kazu Hirata
  0 siblings, 1 reply; 16+ messages in thread
From: Andrew Cagney @ 2003-03-04 16:08 UTC (permalink / raw)
  To: Kazu Hirata; +Cc: gdb-patches

Kazu,
something that got dropped somewhere. Can you please add your self to 
GDB's write after approval list as `an obvious fix'.  Don't forget to 
post the change and changelog.

Andrew


^ permalink raw reply	[flat|nested] 16+ messages in thread

* RE: PATCH : H8300 Simulator File I/O Implementation
@ 2003-01-14  4:56 D.Venkatasubramanian, Noida
  0 siblings, 0 replies; 16+ messages in thread
From: D.Venkatasubramanian, Noida @ 2003-01-14  4:56 UTC (permalink / raw)
  To: J. Johnston, Kazu Hirata, gdb-patches, newlib; +Cc: D.Venkatasubramanian, Noida

Hi All,

Just as a reminder, are the changes done to the H8300 
simulator OK, is there something else that needs to be 
done. There hasn't been any activity after the final set 
of changes.

If OK, could someone apply the patches to newlib and the 
simulator.

Regards,

Venky



> -----Original Message-----
> From: D.Venkatasubramanian, Noida 
> Sent: Wednesday, January 08, 2003 10:33 AM
> To: Kazu Hirata; gdb-patches@sources.redhat.com;
> newlib@sources.redhat.com
> Subject: RE: PATCH : H8300 Simulator File I/O Implementation
> 
> 
> Hi Kazu, 
> > 
> > Hi Venky,
> > 
> > > ;int open(const char *pathname, int flags);
> > > ;Integer arguments have to be zero extended.
> > > ;The second argument is taken from the stack,
> > > ;hence it is not zero extended here.
> > 
> > By the second argument, do you mean flags?  If so, it is in 
> regster r1
> > or er1 in all variants of H8, I think.
> 
> I meant the flags, but as this function uses variable 
> arguments, I found the
> 
> flags on the starting position on the stack and R2. As the calling
> convention 
> for variable arguments seems to be different, I get the 
> parameter from the 
> stack. If there is some improvement that can be done, I would 
> be willing to 
> do the same heartily. :-)
> 
> > 
> > Kazu Hirata
> > 
> 
> Thanks and Regards,
> 
> Venky
> 


^ permalink raw reply	[flat|nested] 16+ messages in thread

* RE: PATCH : H8300 Simulator File I/O Implementation
@ 2003-01-08  5:08 D.Venkatasubramanian, Noida
  0 siblings, 0 replies; 16+ messages in thread
From: D.Venkatasubramanian, Noida @ 2003-01-08  5:08 UTC (permalink / raw)
  To: Kazu Hirata, gdb-patches, newlib

Hi Kazu, 
> 
> Hi Venky,
> 
> > ;int open(const char *pathname, int flags);
> > ;Integer arguments have to be zero extended.
> > ;The second argument is taken from the stack,
> > ;hence it is not zero extended here.
> 
> By the second argument, do you mean flags?  If so, it is in regster r1
> or er1 in all variants of H8, I think.

I meant the flags, but as this function uses variable arguments, I found the

flags on the starting position on the stack and R2. As the calling
convention 
for variable arguments seems to be different, I get the parameter from the 
stack. If there is some improvement that can be done, I would be willing to 
do the same heartily. :-)

> 
> Kazu Hirata
> 

Thanks and Regards,

Venky


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: PATCH : H8300 Simulator File I/O Implementation
  2003-01-03  8:30 D.Venkatasubramanian, Noida
  2003-01-07 22:00 ` Kazu Hirata
@ 2003-01-07 23:08 ` Andrew Cagney
  1 sibling, 0 replies; 16+ messages in thread
From: Andrew Cagney @ 2003-01-07 23:08 UTC (permalink / raw)
  To: D.Venkatasubramanian, Noida
  Cc: 'Kazu Hirata', 'gdb-patches@sources.redhat.com'

Venky,

I unfortunatly don't see a (C) assignment for you to the Free Software 
Foundation.  Would you be willing/able to assign your simulator changes 
to the Free Software Foundation?

I can follow this up off-line if the need be.

Andrew


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: PATCH : H8300 Simulator File I/O Implementation
  2003-01-03  8:30 D.Venkatasubramanian, Noida
@ 2003-01-07 22:00 ` Kazu Hirata
  2003-01-07 23:08 ` Andrew Cagney
  1 sibling, 0 replies; 16+ messages in thread
From: Kazu Hirata @ 2003-01-07 22:00 UTC (permalink / raw)
  To: dvenkat; +Cc: gdb-patches, newlib

Hi Venky,

> Based on my earlier mail:
> 
> http://sources.redhat.com/ml/gdb-patches/2002-12/msg00760.html
> 
> and subsequent ideas and suggestions from Kazu Hirata, I am 
> submitting the modified patches.

Thanks,

> ;int open(const char *pathname, int flags);
> ;Integer arguments have to be zero extended.
> ;The second argument is taken from the stack,
> ;hence it is not zero extended here.

By the second argument, do you mean flags?  If so, it is in regster r1
or er1 in all variants of H8, I think.

Kazu Hirata


^ permalink raw reply	[flat|nested] 16+ messages in thread

* RE: PATCH : H8300 Simulator File I/O Implementation
@ 2003-01-03  8:30 D.Venkatasubramanian, Noida
  2003-01-07 22:00 ` Kazu Hirata
  2003-01-07 23:08 ` Andrew Cagney
  0 siblings, 2 replies; 16+ messages in thread
From: D.Venkatasubramanian, Noida @ 2003-01-03  8:30 UTC (permalink / raw)
  To: 'Kazu Hirata', 'gdb-patches@sources.redhat.com',
	'newlib@sources.redhat.com'
  Cc: D.Venkatasubramanian, Noida

[-- Attachment #1: Type: text/plain, Size: 1706 bytes --]

Hi All,

Based on my earlier mail:

http://sources.redhat.com/ml/gdb-patches/2002-12/msg00760.html

and subsequent ideas and suggestions from Kazu Hirata, I am 
submitting the modified patches.

Changes:
1) Comments included in each .S file.
2) An include directive which had unintentionally crept in last 
time has been removed.
3) A commented C statement in my earlier patch removed in 
simulator patch.

Regards,

Venky


2003-01-03  D.Venkatasubramanian <dvenkat@noida.hcltech.com>

	* compile.c (decode): Added code for some more magic traps.
	* compile.c (sim_resume): Added support for File I/O system
	calls through callback to host_system.
	System calls provided support for :
	open, read, write, lseek, close, stat, fstat
	Only basic support for stat and fstat.


2003-01-03   D.Venkatasubramanian <dvenkat@noida.hcltech.com>

	* /libc/sys/h8300hms/syscalls.c: Removed functions _open, 
	_lseek, _close, _stat, _fstat.
	* /libc/sys/h8300hms/read.c: Removed.
	* /libc/sys/h8300hms/write.c: Removed.
	* /libc/sys/h8300hms/open.S: Hand coded assembly for 
	implementing _open removed from syscalls.c.
	* /libc/sys/h8300hms/read.S: Hand coded assembly for 
	implementing _open removed from read.c.
	* /libc/sys/h8300hms/write.S: Hand coded assembly for 
	implementing _open removed from write.c.
	* /libc/sys/h8300hms/lseek.S: Hand coded assembly for 
	implementing _open removed from syscalls.c.
	* /libc/sys/h8300hms/close.S: Hand coded assembly for 
	implementing _open removed from syscalls.c.
	* /libc/sys/h8300hms/fstat.S: Hand coded assembly for 
	implementing _open removed from syscalls.c.
	* /libc/sys/h8300hms/stat.S: Hand coded assembly for 
	implementing _open removed from syscalls.c.


[-- Attachment #2: ChangeLog.txt --]
[-- Type: text/plain, Size: 1310 bytes --]

2003-01-03  D.Venkatasubramanian <dvenkat@noida.hcltech.com>

	* compile.c (decode): Added code for some more magic traps.
	* compile.c (sim_resume): Added support for File I/O system
	calls through callback to host_system.
	System calls provided support for :
	open, read, write, lseek, close, stat, fstat
	Only basic support for stat and fstat.


2003-01-03   D.Venkatasubramanian <dvenkat@noida.hcltech.com>

	* /libc/sys/h8300hms/syscalls.c: Removed functions _open, 
	_lseek, _close, _stat, _fstat.
	* /libc/sys/h8300hms/read.c: Removed.
	* /libc/sys/h8300hms/write.c: Removed.
	* /libc/sys/h8300hms/open.S: Hand coded assembly for 
	implementing _open removed from syscalls.c.
	* /libc/sys/h8300hms/read.S: Hand coded assembly for 
	implementing _open removed from read.c.
	* /libc/sys/h8300hms/write.S: Hand coded assembly for 
	implementing _open removed from write.c.
	* /libc/sys/h8300hms/lseek.S: Hand coded assembly for 
	implementing _open removed from syscalls.c.
	* /libc/sys/h8300hms/close.S: Hand coded assembly for 
	implementing _open removed from syscalls.c.
	* /libc/sys/h8300hms/fstat.S: Hand coded assembly for 
	implementing _open removed from syscalls.c.
	* /libc/sys/h8300hms/stat.S: Hand coded assembly for 
	implementing _open removed from syscalls.c.

[-- Attachment #3: close.S --]
[-- Type: application/octet-stream, Size: 342 bytes --]

;int close(int fd);
;Integer arguments have to be zero extended.

#if defined(__H8300H__)
	.h8300h
#endif
#if defined(__H8300S__)
	.h8300s
#endif

	.section .text
	.align 2
	.global __close
__close:
#if defined(__H8300H__) || defined(__H8300S__)
#if __INT_MAX__ == 32767
	extu.l er0
#endif
#endif
	jsr @@0xc9
	rts
	.end

[-- Attachment #4: fstat.S --]
[-- Type: application/octet-stream, Size: 376 bytes --]

;int fstat(int filedes, struct stat *buf);
;Integer arguments have to be zero extended.

#if defined(__H8300H__)
	.h8300h
#endif
#if defined(__H8300S__)
	.h8300s
#endif

	.section .text
	.align 2
	.global __fstat
__fstat:
#if defined(__H8300H__) || defined(__H8300S__)
#if __INT_MAX__ == 32767
	extu.l	er0
#endif
#endif
	jsr @@0xcb
	rts
	.end
									

[-- Attachment #5: lseek.S --]
[-- Type: application/octet-stream, Size: 387 bytes --]

;off_t lseek(int fildes, off_t offset, int whence);
;Integer arguments have to be zero extended.

#if defined(__H8300H__)
	.h8300h
#endif
#if defined(__H8300S__)
	.h8300s
#endif

	.section .text
	.align 2
	.global __lseek
__lseek:
#if defined(__H8300H__) || defined(__H8300S__)
#if __INT_MAX__ == 32767
	extu.l er0
	extu.l er2
#endif
#endif
	jsr @@0xc8
	rts
	.end

[-- Attachment #6: newlib_patch.txt --]
[-- Type: text/plain, Size: 2277 bytes --]

*** newlib/libc/sys/h8300hms/syscalls.c.original	Sat Dec 28 16:37:10 2002
--- newlib/libc/sys/h8300hms/syscalls.c.modified	Fri Jan  3 11:10:01 2003
***************
*** 1,47 ****
  /* Operating system stubs, set up for the MRI simulator */
  
  #include <_ansi.h>
- #include <sys/types.h>
- #include <sys/stat.h>
  #include <errno.h>
  
- 
- int _DEFUN(_lseek,(file, ptr, dir),
- 	  int file _AND
- 	  int ptr _AND
- 	  int dir)
- {
-   return 0;
- }
- 
- int _DEFUN(_close,(file),
- 	  int file)
- {
-   return -1;
- }
- 
  int isatty(file)
       int file;
  {
    return 1;
  }
  
- int _DEFUN(_fstat,(file, st),
- 	  int file _AND
- 	  struct stat *st)
- {
-   st->st_mode = S_IFCHR;
-   return 0;
- }
- 
- int
- _open (path, flags)
-      const char *path;
-      int flags;
- {
-   return 0;
- }
- 
  int
  _unlink (path)
       const char *path;
--- 1,14 ----
*** newlib/libc/sys/h8300hms/Makefile.in.original	Mon Dec 30 16:07:12 2002
--- newlib/libc/sys/h8300hms/Makefile.in.modified	Tue Dec 31 14:29:23 2002
*************** INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLA
*** 89,95 ****
  
  noinst_LIBRARIES = lib.a
  
! lib_a_SOURCES = syscalls.c write.c _exit.c read.s sbrk.c misc.c crt1.c
  
  ACLOCAL_AMFLAGS = -I ../../..
  CONFIG_STATUS_DEPENDENCIES = $(newlib_basedir)/configure.host
--- 89,96 ----
  
  noinst_LIBRARIES = lib.a
  
! lib_a_SOURCES = syscalls.c open.s read.s write.s lseek.s close.s stat.s \
! fstat.s _exit.c sbrk.c misc.c crt1.c
  
  ACLOCAL_AMFLAGS = -I ../../..
  CONFIG_STATUS_DEPENDENCIES = $(newlib_basedir)/configure.host
*************** DEFS = @DEFS@ -I. -I$(srcdir) 
*** 103,109 ****
  CPPFLAGS = @CPPFLAGS@
  LIBS = @LIBS@
  lib_a_LIBADD = 
! lib_a_OBJECTS =  syscalls.o write.o _exit.o read.o sbrk.o misc.o crt1.o
  CFLAGS = @CFLAGS@
  COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
  CCLD = $(CC)
--- 104,111 ----
  CPPFLAGS = @CPPFLAGS@
  LIBS = @LIBS@
  lib_a_LIBADD = 
! lib_a_OBJECTS = syscalls.o open.o read.o write.o lseek.o close.o stat.o \
! fstat.o _exit.o sbrk.o misc.o crt1.o
  CFLAGS = @CFLAGS@
  COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
  CCLD = $(CC)

[-- Attachment #7: open.S --]
[-- Type: application/octet-stream, Size: 346 bytes --]

;int open(const char *pathname, int flags);
;Integer arguments have to be zero extended.
;The second argument is taken from the stack,
;hence it is not zero extended here.

#if defined(__H8300H__)
	.h8300h
#endif
#if defined(__H8300S__)
	.h8300s
#endif

	.section .text
	.align 2
	.global __open
__open:
	jsr @@0xc5
	rts
	.end

[-- Attachment #8: read.S --]
[-- Type: application/octet-stream, Size: 380 bytes --]

;ssize_t read(int fd, void *buf, size_t count);
;Integer arguments have to be zero extended.

#if defined(__H8300H__)
	.h8300h
#endif
#if defined(__H8300S__)
	.h8300s
#endif

	.section .text
	.align 2
	.global __read
__read:
#if defined(__H8300H__) || defined(__H8300S__)
#if __INT_MAX__ == 32767
	extu.l  er0
#endif
#endif
	jsr @@0xc6
	rts
	.end
									

[-- Attachment #9: simulator_patch.txt --]
[-- Type: text/plain, Size: 11411 bytes --]

*** sim/h8300/compile.c.original	Thu Dec 26 17:15:41 2002
--- sim/h8300/compile.c.modified	Fri Jan  3 11:07:21 2003
***************
*** 35,40 ****
--- 35,42 ----
  #include "gdb/callback.h"
  #include "gdb/remote-sim.h"
  #include "gdb/sim-h8300.h"
+ #include "sys/stat.h"
+ #include "sys/types.h"
  
  #ifndef SIGTRAP
  # define SIGTRAP 5
*************** decode (addr, data, dst)
*** 452,461 ****
  
  		  if (dst->opcode == O (O_JSR, SB))
  		    {
! 		      if (dst->src.literal == 0xc4)
  			{
! 			  dst->opcode = O (O_SYSCALL, SB);
  			}
  		    }
  
  		  dst->next_pc = addr + len / 2;
--- 454,484 ----
  
  		  if (dst->opcode == O (O_JSR, SB))
  		    {
! 		      switch (dst->src.literal)
  			{
! 			case 0xc5:
! 			  dst->opcode = O (O_SYS_OPEN, SB);
! 			  break;
! 			case 0xc6:
! 			  dst->opcode = O (O_SYS_READ, SB);
! 			  break;
! 			case 0xc7:
! 			  dst->opcode = O (O_SYS_WRITE, SB);
! 			  break;
! 			case 0xc8:
! 			  dst->opcode = O (O_SYS_LSEEK, SB);
! 			  break;
! 			case 0xc9:
! 			  dst->opcode = O (O_SYS_CLOSE, SB);
! 			  break;
! 			case 0xca:
! 			  dst->opcode = O (O_SYS_STAT, SB);
! 			  break;
! 			case 0xcb:
! 			  dst->opcode = O (O_SYS_FSTAT, SB);
! 			  break;
  			}
+ 		      /* End of Processing for system calls.  */
  		    }
  
  		  dst->next_pc = addr + len / 2;
*************** sim_resume (sd, step, siggnal)
*** 1392,1403 ****
  	    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,
--- 1415,1703 ----
  	    goto condtrue;
  	  goto next;
  
! 	  /* System call processing starts.  */
! 	case O (O_SYS_OPEN, SB):
  	  {
! 	    int len = 0;	/* Length of filename.  */
! 	    char *filename;	/* Filename would go here.  */
! 	    char temp_char;	/* Temporary character */
! 	    int mode = 0;	/* Mode bits for the file.  */
! 	    int open_return;	/* Return value of open, file descriptor.  */
! 	    int i;		/* Loop counter */
! 	    int filename_ptr;	/* Pointer to filename in cpu memory.  */
! 
! 	    /* Setting filename_ptr to first argument of open.  */
! 	    filename_ptr = h8300hmode ? GET_L_REG (0) : GET_W_REG (0);
! 
! 	    /* Trying to get mode.  */
! 	    if (h8300hmode || h8300smode)
! 	      {
! 		mode = GET_MEMORY_L (cpu.regs[7] + 4);
! 	      }
! 	    else
! 	      {
! 		mode = GET_MEMORY_W (cpu.regs[7] + 2);
! 	      }
! 
! 	    /* Trying to find the length of the filename.  */
! 	    temp_char = GET_MEMORY_B (cpu.regs[0]);
! 
! 	    len = 1;
! 	    while (temp_char != '\0')
! 	      {
! 		temp_char = GET_MEMORY_B (filename_ptr + len);
! 		len++;
! 	      }
! 
! 	    /* Allocating space for the filename.  */
! 	    filename = (char *) malloc (sizeof (char) * len);
! 
! 	    /* String copying the filename from memory.  */
! 	    for (i = 0; i < len; i++)
! 	      {
! 		temp_char = GET_MEMORY_B (filename_ptr + i);
! 		filename[i] = temp_char;
! 	      }
! 
! 	    /* Callback to open and return the file descriptor.  */
! 	    open_return = sim_callback->open (sim_callback, filename, mode);
! 
! 	    /* Return value in register 0.  */
! 	    cpu.regs[0] = open_return;
! 
! 	    /* Freeing memory used for filename. */
! 	    free (filename);
! 	  }
! 	  goto next;
! 
! 	case O (O_SYS_READ, SB):
! 	  {
! 	    char *char_ptr;	/* Where characters read would be stored.  */
! 	    int fd;		/* File descriptor */
! 	    int buf_size;	/* BUF_SIZE parameter in read.  */
! 	    int i = 0;		/* Temporary Loop counter */
! 	    int read_return = 0;	/* Return value from callback to
! 					   read.  */
! 
! 	    fd = h8300hmode ? GET_L_REG (0) : GET_W_REG (0);
! 	    buf_size = h8300hmode ? GET_L_REG (2) : GET_W_REG (2);
! 
! 	    char_ptr = (char *) malloc (sizeof (char) * buf_size);
! 
! 	    /* Callback to read and return the no. of characters read.  */
! 	    read_return =
! 	      sim_callback->read (sim_callback, fd, char_ptr, buf_size);
! 
! 	    /* The characters read are stored in cpu memory.  */
! 	    for (i = 0; i < buf_size; i++)
! 	      {
! 		SET_MEMORY_B ((cpu.regs[1] + (sizeof (char) * i)),
! 			      *(char_ptr + (sizeof (char) * i)));
! 	      }
! 
! 	    /* Return value in Register 0.  */
! 	    cpu.regs[0] = read_return;
! 
! 	    /* Freeing memory used as buffer.  */
! 	    free (char_ptr);
! 	  }
! 	  goto next;
! 
! 	case O (O_SYS_WRITE, SB):
! 	  {
! 	    int fd;		/* File descriptor */
! 	    char temp_char;	/* Temporary character */
! 	    int len;		/* Length of write, Parameter II to write.  */
! 	    int char_ptr;	/* Character Pointer, Parameter I of write.  */
! 	    char *ptr;		/* Where characters to be written are stored. 
! 				 */
! 	    int write_return;	/* Return value from callback to write.  */
! 	    int i = 0;		/* Loop counter */
! 
! 	    fd = h8300hmode ? GET_L_REG (0) : GET_W_REG (0);
! 	    char_ptr = h8300hmode ? GET_L_REG (1) : GET_W_REG (1);
! 	    len = h8300hmode ? GET_L_REG (2) : GET_W_REG (2);
! 
! 	    /* Allocating space for the characters to be written.  */
! 	    ptr = (char *) malloc (sizeof (char) * len);
! 
! 	    /* Fetching the characters from cpu memory.  */
! 	    for (i = 0; i < len; i++)
! 	      {
! 		temp_char = GET_MEMORY_B (char_ptr + i);
! 		ptr[i] = temp_char;
! 	      }
! 
! 	    /* Callback write and return the no. of characters written.  */
! 	    write_return = sim_callback->write (sim_callback, fd, ptr, len);
! 
! 	    /* Return value in Register 0.  */
! 	    cpu.regs[0] = write_return;
! 
! 	    /* Freeing memory used as buffer.  */
! 	    free (ptr);
! 	  }
! 	  goto next;
! 
! 	case O (O_SYS_LSEEK, SB):
! 	  {
! 	    int fd;		/* File descriptor */
! 	    int offset;		/* Offset */
! 	    int origin;		/* Origin */
! 	    int lseek_return;	/* Return value from callback to lseek.  */
! 
! 	    fd = h8300hmode ? GET_L_REG (0) : GET_W_REG (0);
! 	    offset = h8300hmode ? GET_L_REG (1) : GET_W_REG (1);
! 	    origin = h8300hmode ? GET_L_REG (2) : GET_W_REG (2);
! 
! 	    /* Callback lseek and return offset.  */
! 	    lseek_return =
! 	      sim_callback->lseek (sim_callback, fd, offset, origin);
! 
! 	    /* Return value in register 0.  */
! 	    cpu.regs[0] = lseek_return;
! 	  }
! 	  goto next;
! 
! 	case O (O_SYS_CLOSE, SB):
! 	  {
! 	    int fd;		/* File descriptor */
! 	    int close_return;	/* Return value from callback to close.  */
! 
! 	    fd = h8300hmode ? GET_L_REG (0) : GET_W_REG (0);
! 
! 	    /* Callback close and return.  */
! 	    close_return = sim_callback->close (sim_callback, fd);
! 
! 	    /* Return value in register 0.  */
! 	    cpu.regs[0] = close_return;
! 	  }
! 	  goto next;
! 
! 	case O (O_SYS_FSTAT, SB):
! 	  {
! 	    int fd;		/* File descriptor */
! 	    struct stat stat_rec;	/* Stat record */
! 	    int fstat_return;	/* Return value from callback to stat.  */
! 	    int stat_ptr;	/* Pointer to stat record.  */
! 	    char *temp_stat_ptr;	/* Temporary stat_rec pointer.  */
! 
! 	    fd = h8300hmode ? GET_L_REG (0) : GET_W_REG (0);
! 
! 	    /* Setting stat_ptr to second argument of stat.  */
! 	    stat_ptr = h8300hmode ? GET_L_REG (1) : GET_W_REG (1);
! 
! 	    /* Callback stat and return.  */
! 	    fstat_return = sim_callback->fstat (sim_callback, fd, &stat_rec);
! 
! 	    /* Have stat_ptr point to starting of stat_rec.  */
! 	    temp_stat_ptr = (char *) (&stat_rec);
! 
! 	    /* Setting up the stat structure returned.  */
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_dev);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_ino);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_mode);
! 	    stat_ptr += 4;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_nlink);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_uid);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_gid);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_rdev);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_size);
! 	    stat_ptr += 4;
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_atime);
! 	    stat_ptr += 8;
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_mtime);
! 	    stat_ptr += 8;
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_ctime);
! 
! 	    /* Return value in register 0.  */
! 	    cpu.regs[0] = fstat_return;
! 	  }
! 	  goto next;
! 
! 	case O (O_SYS_STAT, SB):
! 	  {
! 	    int len = 0;	/* Length of filename.  */
! 	    char *filename;	/* Filename would go here.  */
! 	    char temp_char;	/* Temporary character */
! 	    int filename_ptr;	/* Pointer to filename in cpu memory.  */
! 	    struct stat stat_rec;	/* Stat record */
! 	    int stat_return;	/* Return value from callback to stat */
! 	    int stat_ptr;	/* Pointer to stat record.  */
! 	    char *temp_stat_ptr;	/* Temporary stat_rec pointer.  */
! 	    int i = 0;		/* Loop Counter */
! 
! 	    /* Setting filename_ptr to first argument of open.  */
! 	    filename_ptr = h8300hmode ? GET_L_REG (0) : GET_W_REG (0);
! 
! 	    /* Trying to find the length of the filename.  */
! 	    temp_char = GET_MEMORY_B (cpu.regs[0]);
! 
! 	    len = 1;
! 	    while (temp_char != '\0')
! 	      {
! 		temp_char = GET_MEMORY_B (filename_ptr + len);
! 		len++;
! 	      }
! 
! 	    /* Allocating space for the filename.  */
! 	    filename = (char *) malloc (sizeof (char) * len);
! 
! 	    /* String copying the filename from memory.  */
! 	    for (i = 0; i < len; i++)
! 	      {
! 		temp_char = GET_MEMORY_B (filename_ptr + i);
! 		filename[i] = temp_char;
! 	      }
! 
! 	    /* Setting stat_ptr to second argument of stat.  */
! 	    /* stat_ptr = cpu.regs[1]; */
! 	    stat_ptr = h8300hmode ? GET_L_REG (1) : GET_W_REG (1);
! 
! 	    /* Callback stat and return.  */
! 	    stat_return =
! 	      sim_callback->stat (sim_callback, filename, &stat_rec);
! 
! 	    /* Have stat_ptr point to starting of stat_rec.  */
! 	    temp_stat_ptr = (char *) (&stat_rec);
! 
! 	    /* Freeing memory used for filename.  */
! 	    free (filename);
! 
! 	    /* Setting up the stat structure returned.  */
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_dev);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_ino);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_mode);
! 	    stat_ptr += 4;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_nlink);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_uid);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_gid);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_rdev);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_size);
! 	    stat_ptr += 4;
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_atime);
! 	    stat_ptr += 8;
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_mtime);
! 	    stat_ptr += 8;
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_ctime);
! 
! 	    /* Return value in register 0.  */
! 	    cpu.regs[0] = stat_return;
  	  }
  	  goto next;
+ 	  /* End of system call processing.  */
  
  	  ONOT (O_NOT, rd = ~rd; v = 0;);
  	  OSHIFTS (O_SHLL,

[-- Attachment #10: stat.S --]
[-- Type: application/octet-stream, Size: 234 bytes --]

;int stat(const char *file_name, struct stat *buf);

#if defined(__H8300H__)
	.h8300h
#endif
#if defined(__H8300S__)
	.h8300s
#endif

	.section .text
	.align 2
	.global __stat
__stat:
	jsr @@0xca
	rts
	.end
									

[-- Attachment #11: write.S --]
[-- Type: application/octet-stream, Size: 379 bytes --]

;ssize_t write(int fd, const void *buf, size_t count);
;Integer arguments have to be zero extended.

#if defined(__H8300H__)
	.h8300h
#endif

#if defined(__H8300S__)
	.h8300s
#endif

	.section .text
	.align 2
	.global __write
__write:
#if defined(__H8300H__) || defined(__H8300S__)
#if __INT_MAX__ == 32767
	extu.l	er0
#endif
#endif
	jsr @@0xc7
	rts
	.end

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: PATCH : H8300 Simulator File I/O Implementation
  2002-12-31  2:00 D.Venkatasubramanian, Noida
@ 2002-12-31  4:42 ` Kazu Hirata
  0 siblings, 0 replies; 16+ messages in thread
From: Kazu Hirata @ 2002-12-31  4:42 UTC (permalink / raw)
  To: dvenkat; +Cc: gdb-patches, newlib

Hi Venky,

> Based on some suggestions from Kazu Hirata, I have made some 
> changes. The patch to binutils has already been applied so I am 
> not attaching the same. The file newlib_patch.txt contains the 
> changes required in newlib/libc/sys/h8300hms/syscalls.c and 
> newlib/libc/sys/h8300hms/Makefile.in. the file 
> simulator_patch.txt contains the changes required in 
> sim/h8300/compile.c.

Thank you for the updates.  It would be nice if you could include a
one-line comment describing a prototype in each .S file like

  ; int _close (int file);

For one thing, doing so is sort of a convention for assembly functions
to be called by C.  Another reason is that H8 port uses registers for
argument passing, making it difficult to see exactly how many
arguments are being passed.  This may be good for you, too, as _lseek
requires two zero extensions, and you might want to remind yourself
which arguments are of int.

One nit picking: Do you still need the following in syscalls.c?

+ #include "sys/syscall.h"

Meanwhile, I'll try your patches.

Kazu Hirata


^ permalink raw reply	[flat|nested] 16+ messages in thread

* RE: PATCH : H8300 Simulator File I/O Implementation
@ 2002-12-31  2:00 D.Venkatasubramanian, Noida
  2002-12-31  4:42 ` Kazu Hirata
  0 siblings, 1 reply; 16+ messages in thread
From: D.Venkatasubramanian, Noida @ 2002-12-31  2:00 UTC (permalink / raw)
  To: Kazu Hirata, gdb-patches, newlib; +Cc: D.Venkatasubramanian, Noida

[-- Attachment #1: Type: text/plain, Size: 5449 bytes --]

Hi All,

Attached are patches and some new files that should add 
basic File I/O support to the H8300 simulator. This work 
is in continuation of the message I posted earlier :

http://sources.redhat.com/ml/gdb-patches/2002-12/msg00679.html

Based on some suggestions from Kazu Hirata, I have made some 
changes. The patch to binutils has already been applied so I am 
not attaching the same. The file newlib_patch.txt contains the 
changes required in newlib/libc/sys/h8300hms/syscalls.c and 
newlib/libc/sys/h8300hms/Makefile.in. the file 
simulator_patch.txt contains the changes required in 
sim/h8300/compile.c.

Some changes that were to be made to include/opcode/h8300.h have 
already been applied, hence that is not attached.

A listing of the major changes made are listed at the end of the 
mail. Two files read.c and write.c in newlib/libc/sys/h8300hms/ 
may be removed.

Any suggestions on these patches and how it could be improved are 
welcome. Please apply the patches if they are found appropriate.

Thanks Kazu for your invaluable suggestions.

Thanks and Regards,

Venky



ChangeLog entries :

Simulator Directory : sim/h8300/

2002-12-31  D.Venkatasubramanian <dvenkat@noida.hcltech.com>

	* compile.c (decode): Added code for some more magic traps.
	* compile.c (sim_resume): Added support for File I/O system
	calls through callback to host_system.
	System calls provided support for :
	open, read, write, lseek, close, stat, fstat
	Only basic support for stat and fstat.

Newlib Directory : newlib

2002-12-31   D.Venkatasubramanian <dvenkat@noida.hcltech.com>

        * /libc/sys/h8300hms/syscalls.c: Removed functions _open,
        _lseek, _close, _stat, _fstat.
        * /libc/sys/h8300hms/read.c: Removed.
        * /libc/sys/h8300hms/write.c: Removed.
        * /libc/sys/h8300hms/open.S: Hand coded assembly for
        implementing _open removed from syscalls.c.
        * /libc/sys/h8300hms/read.S: Hand coded assembly for
        implementing _read removed from read.c.
        * /libc/sys/h8300hms/write.S: Hand coded assembly for
        implementing _write removed from write.c.
        * /libc/sys/h8300hms/lseek.S: Hand coded assembly for
        implementing _lseek removed from syscalls.c.
        * /libc/sys/h8300hms/close.S: Hand coded assembly for
        implementing _close removed from syscalls.c.
        * /libc/sys/h8300hms/fstat.S: Hand coded assembly for
        implementing _fstat removed from syscalls.c.
        * /libc/sys/h8300hms/stat.S: Hand coded assembly for
        implementing _stat removed from syscalls.c.



PS:

Major changes made :

1) In newlib, the functions _open, _read, etc. present in 
newlib/libc/sys/h8300hms/syscalls.c have been removed from there.

2) These functiong are implemented directly in assembly as 
suggested by Kazu Hirata. The sizeof integers on H8300H and H8300S 
depends on whether -mint32 was given or not during compilation. And, 
also, to make sure that the contents of r0, r1, r2 are propagated
unchanged to the syscall even if the compiler optimization is not
turned on, the functions are implemented in assembly.
These files should be added to newlib/libc/sys/h8300hms/ directory.

Assembly files included :
open.S - implementation of _open
read.S - implementation of _read
write.S - implementation of _write
lseek.S - implementation of _lseek
close.S - implementation of _close
fstat.S - implementation of _fstat
stat.S - implementation of _stat

Once syscalls.c is removed, we could combine all the functions into a 
single syscalls.S file.

3) Change has to be made to Makefile.in in newlib/libc/sys/h8300hms/ 
directory.

Instead of the earlier entry:

lib_a_SOURCES = syscalls.c write.c _exit.c read.c sbrk.c misc.c crt1.c

It has been changed to:

lib_a_SOURCES = syscalls.c open.s read.s write.s lseek.s close.s stat.s \
fstat.s _exit.c sbrk.c misc.c crt1.c

Somehow, I have to specify open.s instead of open.S, even though the 
assembly files are named as open.S etc. Is this correct?

4) Files read.c and write.c are rendered redundant and hence should be 
removed.


Reading specs from
/export/venkat/gcc_release/h8300-elf/tools/bin/../lib/gcc-lib/h8300-elf/3.3/
specs
Configured with: /home/venkat/gcc_3_3/combined/configure
--prefix=/export/venkat/gcc_release/h8300-elf/tools/ --target=h8300-elf
--with-newlib --enable-languages=c,c++ --with-gnu-ld --with-gnu-as
--with-ld=/export/venkat/gcc_release/h8300-elf/tools/h8300-elf/bin/ld
--with-as=/export/venkat/gcc_release/h8300-elf/tools/h8300-elf/bin/as
--with-headers=/home/venkat/gcc_3_3/combined/newlib/libc/include/ :
(reconfigured) /home/venkat/gcc_3_3/combined/configure
--prefix=/export/venkat/gcc_release/h8300-elf/tools/ --target=h8300-elf
--with-newlib --enable-languages=c,c++ --with-gnu-ld --with-gnu-as
--with-ld=/export/venkat/gcc_release/h8300-elf/tools/h8300-elf/bin/ld
--with-as=/export/venkat/gcc_release/h8300-elf/tools/h8300-elf/bin/as
--with-headers=/home/venkat/gcc_3_3/combined/newlib/libc/include/ :
(reconfigured) /home/venkat/gcc_3_3/combined/configure
--prefix=/export/venkat/gcc_release/h8300-elf/tools/ --target=h8300-elf
--with-newlib --enable-languages=c,c++ --with-gnu-ld --with-gnu-as
--with-ld=/export/venkat/gcc_release/h8300-elf/tools/h8300-elf/bin/ld
--with-as=/export/venkat/gcc_release/h8300-elf/tools/h8300-elf/bin/as
--with-headers=/home/venkat/gcc_3_3/combined/newlib/libc/include/
Thread model: single
gcc version 3.3 20020925 (experimental)


[-- Attachment #2: close.S --]
[-- Type: application/octet-stream, Size: 273 bytes --]

#if defined(__H8300H__)
	.h8300h
#endif
#if defined(__H8300S__)
	.h8300s
#endif

	.section .text
	.align 2
	.global __close
__close:
#if defined(__H8300H__) || defined(__H8300S__)
#if __INT_MAX__ == 32767
	extu.l er0
#endif
#endif
	jsr @@0xc9
	rts
	.end

[-- Attachment #3: fstat.S --]
[-- Type: application/octet-stream, Size: 284 bytes --]

#if defined(__H8300H__)
	.h8300h
#endif
#if defined(__H8300S__)
	.h8300s
#endif

	.section .text
	.align 2
	.global __fstat
__fstat:
#if defined(__H8300H__) || defined(__H8300S__)
#if __INT_MAX__ == 32767
	extu.l	er0
#endif
#endif
	jsr @@0xcb
	rts
	.end
									

[-- Attachment #4: lseek.S --]
[-- Type: application/octet-stream, Size: 286 bytes --]

#if defined(__H8300H__)
	.h8300h
#endif
#if defined(__H8300S__)
	.h8300s
#endif

	.section .text
	.align 2
	.global __lseek
__lseek:
#if defined(__H8300H__) || defined(__H8300S__)
#if __INT_MAX__ == 32767
	extu.l er0
	extu.l er2
#endif
#endif
	jsr @@0xc8
	rts
	.end

[-- Attachment #5: open.S --]
[-- Type: application/octet-stream, Size: 168 bytes --]

#if defined(__H8300H__)
	.h8300h
#endif
#if defined(__H8300S__)
	.h8300s
#endif

	.section .text
	.align 2
	.global __open
__open:
	jsr @@0xc5
	rts
	.end

[-- Attachment #6: read.S --]
[-- Type: application/octet-stream, Size: 283 bytes --]

#if defined(__H8300H__)
	.h8300h
#endif
#if defined(__H8300S__)
	.h8300s
#endif

	.section .text
	.align 2
	.global __read
__read:
#if defined(__H8300H__) || defined(__H8300S__)
#if __INT_MAX__ == 32767
	extu.l  er0
#endif
#endif
	jsr @@0xc6
	rts
	.end
									

[-- Attachment #7: stat.S --]
[-- Type: application/octet-stream, Size: 179 bytes --]

#if defined(__H8300H__)
	.h8300h
#endif
#if defined(__H8300S__)
	.h8300s
#endif

	.section .text
	.align 2
	.global __stat
__stat:
	jsr @@0xca
	rts
	.end
									

[-- Attachment #8: write.S --]
[-- Type: application/octet-stream, Size: 275 bytes --]

#if defined(__H8300H__)
	.h8300h
#endif

#if defined(__H8300S__)
	.h8300s
#endif

	.section .text
	.align 2
	.global __write
__write:
#if defined(__H8300H__) || defined(__H8300S__)
#if __INT_MAX__ == 32767
	extu.l	er0
#endif
#endif
	jsr @@0xc7
	rts
	.end

[-- Attachment #9: simulator_patch.txt --]
[-- Type: text/plain, Size: 11449 bytes --]

*** sim/h8300/compile.c.original	Thu Dec 26 17:15:41 2002
--- sim/h8300/compile.c.modified	Tue Dec 31 14:11:58 2002
***************
*** 35,40 ****
--- 35,42 ----
  #include "gdb/callback.h"
  #include "gdb/remote-sim.h"
  #include "gdb/sim-h8300.h"
+ #include "sys/stat.h"
+ #include "sys/types.h"
  
  #ifndef SIGTRAP
  # define SIGTRAP 5
*************** decode (addr, data, dst)
*** 452,461 ****
  
  		  if (dst->opcode == O (O_JSR, SB))
  		    {
! 		      if (dst->src.literal == 0xc4)
  			{
! 			  dst->opcode = O (O_SYSCALL, SB);
  			}
  		    }
  
  		  dst->next_pc = addr + len / 2;
--- 454,484 ----
  
  		  if (dst->opcode == O (O_JSR, SB))
  		    {
! 		      switch (dst->src.literal)
  			{
! 			case 0xc5:
! 			  dst->opcode = O (O_SYS_OPEN, SB);
! 			  break;
! 			case 0xc6:
! 			  dst->opcode = O (O_SYS_READ, SB);
! 			  break;
! 			case 0xc7:
! 			  dst->opcode = O (O_SYS_WRITE, SB);
! 			  break;
! 			case 0xc8:
! 			  dst->opcode = O (O_SYS_LSEEK, SB);
! 			  break;
! 			case 0xc9:
! 			  dst->opcode = O (O_SYS_CLOSE, SB);
! 			  break;
! 			case 0xca:
! 			  dst->opcode = O (O_SYS_STAT, SB);
! 			  break;
! 			case 0xcb:
! 			  dst->opcode = O (O_SYS_FSTAT, SB);
! 			  break;
  			}
+ 		      /* End of Processing for system calls.  */
  		    }
  
  		  dst->next_pc = addr + len / 2;
*************** sim_resume (sd, step, siggnal)
*** 1392,1403 ****
  	    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,
--- 1415,1704 ----
  	    goto condtrue;
  	  goto next;
  
! 	  /* System call processing starts.  */
! 	case O (O_SYS_OPEN, SB):
  	  {
! 	    int len = 0;	/* Length of filename.  */
! 	    char *filename;	/* Filename would go here.  */
! 	    char temp_char;	/* Temporary character */
! 	    int mode = 0;	/* Mode bits for the file.  */
! 	    int open_return;	/* Return value of open, file descriptor.  */
! 	    int i;		/* Loop counter */
! 	    int filename_ptr;	/* Pointer to filename in cpu memory.  */
! 
! 	    /* Setting filename_ptr to first argument of open.  */
! 	    filename_ptr = h8300hmode ? GET_L_REG (0) : GET_W_REG (0);
! 
! 	    /* Trying to get mode.  */
! 	    if (h8300hmode || h8300smode)
! 	      {
! 		mode = GET_MEMORY_L (cpu.regs[7] + 4);
! 	      }
! 	    else
! 	      {
! 		mode = GET_MEMORY_W (cpu.regs[7] + 2);
! 	      }
! 
! 	    /* Trying to find the length of the filename.  */
! 	    temp_char = GET_MEMORY_B (cpu.regs[0]);
! 
! 	    len = 1;
! 	    while (temp_char != '\0')
! 	      {
! 		temp_char = GET_MEMORY_B (filename_ptr + len);
! 		len++;
! 	      }
! 
! 	    /* Allocating space for the filename.  */
! 	    filename = (char *) malloc (sizeof (char) * len);
! 
! 	    /* String copying the filename from memory.  */
! 	    for (i = 0; i < len; i++)
! 	      {
! 		temp_char = GET_MEMORY_B (filename_ptr + i);
! 		filename[i] = temp_char;
! 	      }
! 
! 	    /* Callback to open and return the file descriptor.  */
! 	    open_return = sim_callback->open (sim_callback, filename, mode);
! 
! 	    /* Return value in register 0.  */
! 	    cpu.regs[0] = open_return;
! 
! 	    /* Freeing memory used for filename. */
! 	    free (filename);
! 	  }
! 	  goto next;
! 
! 	case O (O_SYS_READ, SB):
! 	  {
! 	    char *char_ptr;	/* Where characters read would be stored.  */
! 	    int fd;		/* File descriptor */
! 	    int buf_size;	/* BUF_SIZE parameter in read.  */
! 	    int i = 0;		/* Temporary Loop counter */
! 	    int read_return = 0;	/* Return value from callback to
! 					   read.  */
! 
! 	    fd = h8300hmode ? GET_L_REG (0) : GET_W_REG (0);
! 	    buf_size = h8300hmode ? GET_L_REG (2) : GET_W_REG (2);
! 
! 	    char_ptr = (char *) malloc (sizeof (char) * buf_size);
! 
! 	    /* Callback to read and return the no. of characters read.  */
! 	    read_return =
! 	      sim_callback->read (sim_callback, fd, char_ptr, buf_size);
! 
! 	    /* The characters read are stored in cpu memory.  */
! 	    for (i = 0; i < buf_size; i++)
! 	      {
! 		SET_MEMORY_B ((cpu.regs[1] + (sizeof (char) * i)),
! 			      *(char_ptr + (sizeof (char) * i)));
! 	      }
! 
! 	    /* Return value in Register 0.  */
! 	    cpu.regs[0] = read_return;
! 
! 	    /* Freeing memory used as buffer.  */
! 	    free (char_ptr);
! 	  }
! 	  goto next;
! 
! 	case O (O_SYS_WRITE, SB):
! 	  {
! 	    int fd;		/* File descriptor */
! 	    char temp_char;	/* Temporary character */
! 	    int len;		/* Length of write, Parameter II to write.  */
! 	    int char_ptr;	/* Character Pointer, Parameter I of write.  */
! 	    char *ptr;		/* Where characters to be written are stored. 
! 				 */
! 	    int write_return;	/* Return value from callback to write.  */
! 	    int i = 0;		/* Loop counter */
! 
! 	    fd = h8300hmode ? GET_L_REG (0) : GET_W_REG (0);
! 	    char_ptr = h8300hmode ? GET_L_REG (1) : GET_W_REG (1);
! 	    len = h8300hmode ? GET_L_REG (2) : GET_W_REG (2);
! 
! 	    /* Allocating space for the characters to be written.  */
! 	    ptr = (char *) malloc (sizeof (char) * len);
! 
! 	    /* Fetching the characters from cpu memory.  */
! 	    for (i = 0; i < len; i++)
! 	      {
! 		temp_char = GET_MEMORY_B (char_ptr + i);
! 		ptr[i] = temp_char;
! 	      }
! 
! 	    /* Callback write and return the no. of characters written.  */
! 	    write_return = sim_callback->write (sim_callback, fd, ptr, len);
! 
! 	    /* Return value in Register 0.  */
! 	    cpu.regs[0] = write_return;
! 
! 	    /* Freeing memory used as buffer.  */
! 	    free (ptr);
! 	  }
! 	  goto next;
! 
! 	case O (O_SYS_LSEEK, SB):
! 	  {
! 	    int fd;		/* File descriptor */
! 	    int offset;		/* Offset */
! 	    int origin;		/* Origin */
! 	    int lseek_return;	/* Return value from callback to lseek.  */
! 
! 	    fd = h8300hmode ? GET_L_REG (0) : GET_W_REG (0);
! 	    offset = h8300hmode ? GET_L_REG (1) : GET_W_REG (1);
! 	    origin = h8300hmode ? GET_L_REG (2) : GET_W_REG (2);
! 
! 	    /* Callback lseek and return offset.  */
! 	    lseek_return =
! 	      sim_callback->lseek (sim_callback, fd, offset, origin);
! 
! 	    /* Return value in register 0.  */
! 	    cpu.regs[0] = lseek_return;
! 	  }
! 	  goto next;
! 
! 	case O (O_SYS_CLOSE, SB):
! 	  {
! 	    int fd;		/* File descriptor */
! 	    int close_return;	/* Return value from callback to close.  */
! 
! 	    fd = h8300hmode ? GET_L_REG (0) : GET_W_REG (0);
! 
! 	    /* Callback close and return.  */
! 	    close_return = sim_callback->close (sim_callback, fd);
! 
! 	    /* Return value in register 0.  */
! 	    cpu.regs[0] = close_return;
! 	  }
! 	  goto next;
! 
! 	case O (O_SYS_FSTAT, SB):
! 	  {
! 	    int fd;		/* File descriptor */
! 	    struct stat stat_rec;	/* Stat record */
! 	    int fstat_return;	/* Return value from callback to stat.  */
! 	    int stat_ptr;	/* Pointer to stat record.  */
! 	    char *temp_stat_ptr;	/* Temporary stat_rec pointer.  */
! 
! 	    fd = h8300hmode ? GET_L_REG (0) : GET_W_REG (0);
! 
! 	    /* Setting stat_ptr to second argument of stat.  */
! 	    /* stat_ptr = cpu.regs[1]; */
! 	    stat_ptr = h8300hmode ? GET_L_REG (1) : GET_W_REG (1);
! 
! 	    /* Callback stat and return.  */
! 	    fstat_return = sim_callback->fstat (sim_callback, fd, &stat_rec);
! 
! 	    /* Have stat_ptr point to starting of stat_rec.  */
! 	    temp_stat_ptr = (char *) (&stat_rec);
! 
! 	    /* Setting up the stat structure returned.  */
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_dev);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_ino);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_mode);
! 	    stat_ptr += 4;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_nlink);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_uid);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_gid);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_rdev);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_size);
! 	    stat_ptr += 4;
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_atime);
! 	    stat_ptr += 8;
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_mtime);
! 	    stat_ptr += 8;
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_ctime);
! 
! 	    /* Return value in register 0.  */
! 	    cpu.regs[0] = fstat_return;
! 	  }
! 	  goto next;
! 
! 	case O (O_SYS_STAT, SB):
! 	  {
! 	    int len = 0;	/* Length of filename.  */
! 	    char *filename;	/* Filename would go here.  */
! 	    char temp_char;	/* Temporary character */
! 	    int filename_ptr;	/* Pointer to filename in cpu memory.  */
! 	    struct stat stat_rec;	/* Stat record */
! 	    int stat_return;	/* Return value from callback to stat */
! 	    int stat_ptr;	/* Pointer to stat record.  */
! 	    char *temp_stat_ptr;	/* Temporary stat_rec pointer.  */
! 	    int i = 0;		/* Loop Counter */
! 
! 	    /* Setting filename_ptr to first argument of open.  */
! 	    filename_ptr = h8300hmode ? GET_L_REG (0) : GET_W_REG (0);
! 
! 	    /* Trying to find the length of the filename.  */
! 	    temp_char = GET_MEMORY_B (cpu.regs[0]);
! 
! 	    len = 1;
! 	    while (temp_char != '\0')
! 	      {
! 		temp_char = GET_MEMORY_B (filename_ptr + len);
! 		len++;
! 	      }
! 
! 	    /* Allocating space for the filename.  */
! 	    filename = (char *) malloc (sizeof (char) * len);
! 
! 	    /* String copying the filename from memory.  */
! 	    for (i = 0; i < len; i++)
! 	      {
! 		temp_char = GET_MEMORY_B (filename_ptr + i);
! 		filename[i] = temp_char;
! 	      }
! 
! 	    /* Setting stat_ptr to second argument of stat.  */
! 	    /* stat_ptr = cpu.regs[1]; */
! 	    stat_ptr = h8300hmode ? GET_L_REG (1) : GET_W_REG (1);
! 
! 	    /* Callback stat and return.  */
! 	    stat_return =
! 	      sim_callback->stat (sim_callback, filename, &stat_rec);
! 
! 	    /* Have stat_ptr point to starting of stat_rec.  */
! 	    temp_stat_ptr = (char *) (&stat_rec);
! 
! 	    /* Freeing memory used for filename.  */
! 	    free (filename);
! 
! 	    /* Setting up the stat structure returned.  */
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_dev);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_ino);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_mode);
! 	    stat_ptr += 4;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_nlink);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_uid);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_gid);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_rdev);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_size);
! 	    stat_ptr += 4;
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_atime);
! 	    stat_ptr += 8;
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_mtime);
! 	    stat_ptr += 8;
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_ctime);
! 
! 	    /* Return value in register 0.  */
! 	    cpu.regs[0] = stat_return;
  	  }
  	  goto next;
+ 	  /* End of system call processing.  */
  
  	  ONOT (O_NOT, rd = ~rd; v = 0;);
  	  OSHIFTS (O_SHLL,

[-- Attachment #10: newlib_patch.txt --]
[-- Type: text/plain, Size: 2541 bytes --]

*** newlib/libc/sys/h8300hms/syscalls.c.original	Sat Dec 28 16:37:10 2002
--- newlib/libc/sys/h8300hms/syscalls.c.modified	Tue Dec 31 14:15:44 2002
***************
*** 1,47 ****
  /* Operating system stubs, set up for the MRI simulator */
  
  #include <_ansi.h>
- #include <sys/types.h>
- #include <sys/stat.h>
  #include <errno.h>
  
  
- int _DEFUN(_lseek,(file, ptr, dir),
- 	  int file _AND
- 	  int ptr _AND
- 	  int dir)
- {
-   return 0;
- }
- 
- int _DEFUN(_close,(file),
- 	  int file)
- {
-   return -1;
- }
- 
  int isatty(file)
       int file;
  {
    return 1;
  }
  
- int _DEFUN(_fstat,(file, st),
- 	  int file _AND
- 	  struct stat *st)
- {
-   st->st_mode = S_IFCHR;
-   return 0;
- }
- 
- int
- _open (path, flags)
-      const char *path;
-      int flags;
- {
-   return 0;
- }
- 
  int
  _unlink (path)
       const char *path;
--- 1,16 ----
  /* Operating system stubs, set up for the MRI simulator */
  
  #include <_ansi.h>
  #include <errno.h>
+ #include "sys/syscall.h"
  
  
  int isatty(file)
       int file;
  {
    return 1;
  }
  
  int
  _unlink (path)
       const char *path;
*** newlib/libc/sys/h8300hms/Makefile.in.original	Mon Dec 30 16:07:12 2002
--- newlib/libc/sys/h8300hms/Makefile.in.modified	Tue Dec 31 14:29:23 2002
*************** INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLA
*** 89,95 ****
  
  noinst_LIBRARIES = lib.a
  
! lib_a_SOURCES = syscalls.c write.c _exit.c read.c sbrk.c misc.c crt1.c
  
  ACLOCAL_AMFLAGS = -I ../../..
  CONFIG_STATUS_DEPENDENCIES = $(newlib_basedir)/configure.host
--- 89,96 ----
  
  noinst_LIBRARIES = lib.a
  
! lib_a_SOURCES = syscalls.c open.s read.s write.s lseek.s close.s stat.s \
! fstat.s _exit.c sbrk.c misc.c crt1.c
  
  ACLOCAL_AMFLAGS = -I ../../..
  CONFIG_STATUS_DEPENDENCIES = $(newlib_basedir)/configure.host
*************** DEFS = @DEFS@ -I. -I$(srcdir) 
*** 103,109 ****
  CPPFLAGS = @CPPFLAGS@
  LIBS = @LIBS@
  lib_a_LIBADD = 
! lib_a_OBJECTS =  syscalls.o write.o _exit.o read.o sbrk.o misc.o crt1.o
  CFLAGS = @CFLAGS@
  COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
  CCLD = $(CC)
--- 104,111 ----
  CPPFLAGS = @CPPFLAGS@
  LIBS = @LIBS@
  lib_a_LIBADD = 
! lib_a_OBJECTS = syscalls.o open.o read.o write.o lseek.o close.o stat.o \
! fstat.o _exit.o sbrk.o misc.o crt1.o
  CFLAGS = @CFLAGS@
  COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
  CCLD = $(CC)

[-- Attachment #11: ChangeLog.txt --]
[-- Type: text/plain, Size: 1314 bytes --]

2002-12-31  D.Venkatasubramanian <dvenkat@noida.hcltech.com>

	* compile.c (decode): Added code for some more magic traps.
	* compile.c (sim_resume): Added support for File I/O system
	calls through callback to host_system.
	System calls provided support for :
	open, read, write, lseek, close, stat, fstat
	Only basic support for stat and fstat.


2002-12-31   D.Venkatasubramanian <dvenkat@noida.hcltech.com>

	* /libc/sys/h8300hms/syscalls.c: Removed functions _open, 
	_lseek, _close, _stat, _fstat.
	* /libc/sys/h8300hms/read.c: Removed.
	* /libc/sys/h8300hms/write.c: Removed.
	* /libc/sys/h8300hms/open.S: Hand coded assembly for 
	implementing _open removed from syscalls.c.
	* /libc/sys/h8300hms/read.S: Hand coded assembly for 
	implementing _read removed from read.c.
	* /libc/sys/h8300hms/write.S: Hand coded assembly for 
	implementing _write removed from write.c.
	* /libc/sys/h8300hms/lseek.S: Hand coded assembly for 
	implementing _lseek removed from syscalls.c.
	* /libc/sys/h8300hms/close.S: Hand coded assembly for 
	implementing _close removed from syscalls.c.
	* /libc/sys/h8300hms/fstat.S: Hand coded assembly for 
	implementing _fstat removed from syscalls.c.
	* /libc/sys/h8300hms/stat.S: Hand coded assembly for 
	implementing _stat removed from syscalls.c.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* RE: PATCH : H8300 Simulator File I/O Implementation
@ 2002-12-26 10:12 D.Venkatasubramanian, Noida
  0 siblings, 0 replies; 16+ messages in thread
From: D.Venkatasubramanian, Noida @ 2002-12-26 10:12 UTC (permalink / raw)
  To: D.Venkatasubramanian, Noida, Kazu Hirata, gdb-patches, binutils, newlib

[-- Attachment #1: Type: text/plain, Size: 1308 bytes --]

Hi All,

In reference to my earlier mail, I gave the ChangeLog incorrectly.

Ref : http://sources.redhat.com/ml/gdb-patches/2002-12/msg00679.html

The updated ChangeLog is given below.

Sorry for the slip ;-)

Regards,

Venky

For GDB/Simulator

Thu Dec 26 18:28:18 IST 2002  D.Venkatasubramanian
(dvenkat@noida.hcltech.com)

        * compile.c (decode): Added code for some more magic traps.
        * compile.c (sim_resume): Added support for File I/O system
        calls through callback to host_system.
        System calls provided support for :
        open, read, write, lseek, close, stat, fstat
        Only basic support for stat and fstat.

For newlib

Thu Dec 26 18:30:56 IST 2002 D.Venkatasubramanian
<dvenkat@noida.hcltech.com>

        * /libc/sys/h8300hms/syscalls.c: Support for various File I/O
        related system calls. Jump to magic vector locations, instead
        of dummy return values.
        * /libc/sys/h8300hms/read.c: Jump to magic vector location for
        supporting read system call.
        * /libc/sys/h8300hms/write.c: Jump to magic vector location for
        supporting write system call.


For binutils

Thu Dec 26 18:28:56 IST 2002 D.Venkatasubramanian
<dvenkat@noida.hcltech.com>

        *h8300.h: Added some more pseudo opcodes for system call processing.


[-- Attachment #2: ChangeLog.txt --]
[-- Type: text/plain, Size: 1056 bytes --]

Thu Dec 26 18:28:18 IST 2002  D.Venkatasubramanian (dvenkat@noida.hcltech.com)

        * compile.c (decode): Added code for some more magic traps.
        * compile.c (sim_resume): Added support for File I/O system
        calls through callback to host_system.
        System calls provided support for :
        open, read, write, lseek, close, stat, fstat
        Only basic support for stat and fstat.

Thu Dec 26 18:30:56 IST 2002 D.Venkatasubramanian <dvenkat@noida.hcltech.com>

        * /libc/sys/h8300hms/syscalls.c: Support for various File I/O
        related system calls. Jump to magic vector locations, instead
        of dummy return values.
        * /libc/sys/h8300hms/read.c: Jump to magic vector location for
        supporting read system call.
        * /libc/sys/h8300hms/write.c: Jump to magic vector location for
        supporting write system call.

Thu Dec 26 18:28:56 IST 2002 D.Venkatasubramanian <dvenkat@noida.hcltech.com>

        *h8300.h: Added some more pseudo opcodes for system call processing.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* RE: PATCH : H8300 Simulator File I/O Implementation
@ 2002-12-26  4:38 D.Venkatasubramanian, Noida
  0 siblings, 0 replies; 16+ messages in thread
From: D.Venkatasubramanian, Noida @ 2002-12-26  4:38 UTC (permalink / raw)
  To: Kazu Hirata, gdb-patches, binutils, newlib

[-- Attachment #1: Type: text/plain, Size: 2014 bytes --]



> -----Original Message-----
> From: Kazu Hirata [mailto:kazu@cs.umass.edu]
> 
> I would split the gdb part of your patch into the opcodes part and the
> rest because opcodes is part of binutils.

Done, I am attaching three patches, One for the simulator, one for 
binutils and one for newlib.

> 
> I am guessing that you probably don't need to change the order of
> functions in newlib/libc/sys/h8300hms/syscalls.c.  You might want to
> submit a patch with few or no formatting changes to make your real
> changes exposed.  See the attached patch below.  Also, please use
> "asm (...)" instead of "asm(...)".
> 
Done that too.

> For the gdb part, I would run 'indent' to see what it recommends.  One
> thing it suggests should be to change
> 
> ! 	    filename = (char *)malloc(sizeof(char) * len);
> 
> to something like
> 
> ! 	    filename = (char *) malloc (sizeof (char) * len);
> 
> Some variables seem to be unused.
> 
Made changes as suggested by indent.

Hope to have removed all the useless variables and indentation problems.

Thanks and Regards,

Venky

Mon Dec  26 16:44:35 IST 2002  D.Venkatasubramanian
(dvenkat@noida.hcltech.com)

	* compile.c (decode): Added code for some more magic traps.
	* compile.c (sim_resume): Added support for File I/O system
	calls through callback to host_system.
	System calls provided support for :
	 open, read, write, lseek, close, stat, fstat
	Only basic support for stat and fstat.

Mon Dec  26 16:47:01 IST 2002 D.Venkatasubramanian
<dvenkat@noida.hcltech.com>

	* /libc/sys/h8300hms/syscalls.c: Support for various File I/O
	related system calls. Jump to magic vector locations, instead
	of dummy return values.
	* /libc/sys/h8300hms/read.c: Jump to magic vector location for
	supporting read system call.
	* /libc/sys/h8300hms/write.c: Jump to magic vector location for
	supporting write system call.

Mon Dec  26 16:47:09 IST 2002 D.Venkatasubramanian
<dvenkat@noida.hcltech.com>

	*h8300.h: Added some more pseudo opcodes for system call processing.




[-- Attachment #2: simulator_patch.txt --]
[-- Type: text/plain, Size: 10792 bytes --]

*** sim/h8300/compile.c.original	Thu Dec 26 17:15:41 2002
--- sim/h8300/compile.c.modified	Thu Dec 26 17:34:15 2002
***************
*** 35,40 ****
--- 35,42 ----
  #include "gdb/callback.h"
  #include "gdb/remote-sim.h"
  #include "gdb/sim-h8300.h"
+ #include "sys/stat.h"
+ #include "sys/types.h"
  
  #ifndef SIGTRAP
  # define SIGTRAP 5
*************** decode (addr, data, dst)
*** 452,461 ****
  
  		  if (dst->opcode == O (O_JSR, SB))
  		    {
! 		      if (dst->src.literal == 0xc4)
  			{
! 			  dst->opcode = O (O_SYSCALL, SB);
  			}
  		    }
  
  		  dst->next_pc = addr + len / 2;
--- 454,484 ----
  
  		  if (dst->opcode == O (O_JSR, SB))
  		    {
! 		      switch (dst->src.literal)
  			{
! 			case 0xc5:
! 			  dst->opcode = O (O_SYS_OPEN, SB);
! 			  break;
! 			case 0xc6:
! 			  dst->opcode = O (O_SYS_READ, SB);
! 			  break;
! 			case 0xc7:
! 			  dst->opcode = O (O_SYS_WRITE, SB);
! 			  break;
! 			case 0xc8:
! 			  dst->opcode = O (O_SYS_LSEEK, SB);
! 			  break;
! 			case 0xc9:
! 			  dst->opcode = O (O_SYS_CLOSE, SB);
! 			  break;
! 			case 0xca:
! 			  dst->opcode = O (O_SYS_STAT, SB);
! 			  break;
! 			case 0xcb:
! 			  dst->opcode = O (O_SYS_FSTAT, SB);
! 			  break;
  			}
+ 		      /* End of Processing for system calls.  */
  		    }
  
  		  dst->next_pc = addr + len / 2;
*************** sim_resume (sd, step, siggnal)
*** 1392,1403 ****
  	    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,
--- 1415,1689 ----
  	    goto condtrue;
  	  goto next;
  
! 	  /* System call processing starts.  */
! 	case O (O_SYS_OPEN, SB):
  	  {
! 	    int len = 0;	/* Length of filename.  */
! 	    char *filename;	/* Filename would go here.  */
! 	    char temp_char;	/* Temporary character */
! 	    int mode = 0;	/* Mode bits for the file.  */
! 	    int open_return;	/* Return value of open, file descriptor.  */
! 	    int i;		/* Loop counter */
! 	    int filename_ptr;	/* Pointer to filename in cpu memory.  */
! 
! 	    /* Setting filename_ptr to first argument of open.  */
! 	    filename_ptr = cpu.regs[0];
! 
! 	    /* Trying to get mode.  */
! 	    if (h8300hmode || h8300smode)
! 	      {
! 		mode = GET_MEMORY_L (cpu.regs[7] + 8);
! 	      }
! 	    else
! 	      {
! 		mode = GET_MEMORY_W (cpu.regs[7] + 4);
! 	      }
! 
! 	    /* Trying to find the length of the filename.  */
! 	    temp_char = GET_MEMORY_B (cpu.regs[0]);
! 
! 	    len = 1;
! 	    while (temp_char != '\0')
! 	      {
! 		temp_char = GET_MEMORY_B (filename_ptr + len);
! 		len++;
! 	      }
! 
! 	    /* Allocating space for the filename.  */
! 	    filename = (char *) malloc (sizeof (char) * len);
! 
! 	    /* String copying the filename from memory.  */
! 	    for (i = 0; i < len; i++)
! 	      {
! 		temp_char = GET_MEMORY_B (filename_ptr + i);
! 		filename[i] = temp_char;
! 	      }
! 
! 	    /* Callback to open and return the file descriptor.  */
! 	    open_return = sim_callback->open (sim_callback, filename, mode);
! 
! 	    /* Return value in register 0.  */
! 	    cpu.regs[0] = open_return;
! 
! 	    /* Freeing memory used for filename. */
! 	    free (filename);
! 	  }
! 	  goto next;
! 
! 	case O (O_SYS_READ, SB):
! 	  {
! 	    char *char_ptr;	/* Where characters read would be stored.  */
! 	    int fd = cpu.regs[0];	/* File descriptor */
! 	    int buf_size = cpu.regs[2];	/* BUF_SIZE parameter in read.  */
! 	    int i = 0;		/* Temporary Loop counter */
! 	    int read_return = 0;	/* Return value from callback to
! 					   read.  */
! 
! 	    char_ptr = (char *) malloc (sizeof (char) * buf_size);
! 
! 	    /* Callback to read and return the no. of characters read.  */
! 	    read_return =
! 	      sim_callback->read (sim_callback, fd, char_ptr, buf_size);
! 
! 	    /* The characters read are stored in cpu memory.  */
! 	    for (i = 0; i < buf_size; i++)
! 	      {
! 		SET_MEMORY_B ((cpu.regs[1] + (sizeof (char) * i)),
! 			      *(char_ptr + (sizeof (char) * i)));
! 	      }
! 
! 	    /* Return value in Register 0.  */
! 	    cpu.regs[0] = read_return;
! 
! 	    /* Freeing memory used as buffer.  */
! 	    free (char_ptr);
! 	  }
! 	  goto next;
! 
! 	case O (O_SYS_WRITE, SB):
! 	  {
! 	    int fd = cpu.regs[0];	/* File descriptor */
! 	    char temp_char;	/* Temporary character */
! 	    int len = cpu.regs[2];	/* Length of write, Parameter II to
! 					   write.  */
! 	    int char_ptr = cpu.regs[1];	/* Character Pointer, Parameter I of
! 					   write.  */
! 	    char *ptr;		/* Where characters to be written are stored. 
! 				 */
! 	    int write_return;	/* Return value from callback to write.  */
! 	    int i = 0;		/* Loop counter */
! 
! 	    /* Allocating space for the characters to be written.  */
! 	    ptr = (char *) malloc (sizeof (char) * len);
! 
! 	    /* Fetching the characters from cpu memory.  */
! 	    for (i = 0; i < len; i++)
! 	      {
! 		temp_char = GET_MEMORY_B (char_ptr + i);
! 		ptr[i] = temp_char;
! 	      }
! 
! 	    /* Callback write and return the no. of characters written.  */
! 	    write_return = sim_callback->write (sim_callback, fd, ptr, len);
! 
! 	    /* Return value in Register 0.  */
! 	    cpu.regs[0] = write_return;
! 
! 	    /* Freeing memory used as buffer.  */
! 	    free (ptr);
! 	  }
! 	  goto next;
! 
! 	case O (O_SYS_LSEEK, SB):
! 	  {
! 	    int fd = cpu.regs[0];	/* File descriptor */
! 	    int offset = cpu.regs[1];	/* Offset */
! 	    int origin = cpu.regs[2];	/* Origin */
! 	    int lseek_return;	/* Return value from callback to lseek.  */
! 
! 	    /* Callback lseek and return offset.  */
! 	    lseek_return =
! 	      sim_callback->lseek (sim_callback, fd, offset, origin);
! 
! 	    /* Return value in register 0.  */
! 	    cpu.regs[0] = lseek_return;
! 	  }
! 	  goto next;
! 
! 	case O (O_SYS_CLOSE, SB):
! 	  {
! 	    int fd = cpu.regs[0];	/* File descriptor */
! 	    int close_return;	/* Return value from callback to close.  */
! 
! 	    /* Callback close and return.  */
! 	    close_return = sim_callback->close (sim_callback, fd);
! 
! 	    /* Return value in register 0.  */
! 	    cpu.regs[0] = close_return;
! 	  }
! 	  goto next;
! 
! 	case O (O_SYS_FSTAT, SB):
! 	  {
! 	    int fd = cpu.regs[0];	/* File descriptor */
! 	    struct stat stat_rec;	/* Stat record */
! 	    int fstat_return;	/* Return value from callback to stat.  */
! 	    int stat_ptr;	/* Pointer to stat record.  */
! 	    char *temp_stat_ptr;	/* Temporary stat_rec pointer.  */
! 
! 	    /* Setting stat_ptr to second argument of stat.  */
! 	    stat_ptr = cpu.regs[1];
! 
! 	    /* Callback stat and return.  */
! 	    fstat_return = sim_callback->fstat (sim_callback, fd, &stat_rec);
! 
! 	    /* Have stat_ptr point to starting of stat_rec.  */
! 	    temp_stat_ptr = (char *) (&stat_rec);
! 
! 	    /* Setting up the stat structure returned.  */
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_dev);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_ino);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_mode);
! 	    stat_ptr += 4;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_nlink);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_uid);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_gid);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_rdev);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_size);
! 	    stat_ptr += 4;
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_atime);
! 	    stat_ptr += 8;
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_mtime);
! 	    stat_ptr += 8;
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_ctime);
! 
! 	    /* Return value in register 0.  */
! 	    cpu.regs[0] = fstat_return;
! 	  }
! 	  goto next;
! 
! 	case O (O_SYS_STAT, SB):
! 	  {
! 	    int len = 0;	/* Length of filename.  */
! 	    char *filename;	/* Filename would go here.  */
! 	    char temp_char;	/* Temporary character */
! 	    int filename_ptr;	/* Pointer to filename in cpu memory.  */
! 	    struct stat stat_rec;	/* Stat record */
! 	    int stat_return;	/* Return value from callback to stat */
! 	    int stat_ptr;	/* Pointer to stat record.  */
! 	    char *temp_stat_ptr;	/* Temporary stat_rec pointer.  */
! 	    int i = 0;		/* Loop Counter */
! 
! 	    /* Setting filename_ptr to first argument of open.  */
! 	    filename_ptr = cpu.regs[0];
! 
! 	    /* Trying to find the length of the filename.  */
! 	    temp_char = GET_MEMORY_B (cpu.regs[0]);
! 
! 	    len = 1;
! 	    while (temp_char != '\0')
! 	      {
! 		temp_char = GET_MEMORY_B (filename_ptr + len);
! 		len++;
! 	      }
! 
! 	    /* Allocating space for the filename.  */
! 	    filename = (char *) malloc (sizeof (char) * len);
! 
! 	    /* String copying the filename from memory.  */
! 	    for (i = 0; i < len; i++)
! 	      {
! 		temp_char = GET_MEMORY_B (filename_ptr + i);
! 		filename[i] = temp_char;
! 	      }
! 
! 	    /* Setting stat_ptr to second argument of stat.  */
! 	    stat_ptr = cpu.regs[1];
! 
! 	    /* Callback stat and return.  */
! 	    stat_return =
! 	      sim_callback->stat (sim_callback, filename, &stat_rec);
! 
! 	    /* Have stat_ptr point to starting of stat_rec.  */
! 	    temp_stat_ptr = (char *) (&stat_rec);
! 
! 	    /* Freeing memory used for filename.  */
! 	    free (filename);
! 
! 	    /* Setting up the stat structure returned.  */
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_dev);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_ino);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_mode);
! 	    stat_ptr += 4;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_nlink);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_uid);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_gid);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_rdev);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_size);
! 	    stat_ptr += 4;
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_atime);
! 	    stat_ptr += 8;
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_mtime);
! 	    stat_ptr += 8;
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_ctime);
! 
! 	    /* Return value in register 0.  */
! 	    cpu.regs[0] = stat_return;
  	  }
  	  goto next;
+ 	  /* End of system call processing.  */
  
  	  ONOT (O_NOT, rd = ~rd; v = 0;);
  	  OSHIFTS (O_SHLL,

[-- Attachment #3: newlib_patch.txt --]
[-- Type: text/plain, Size: 3082 bytes --]

*** newlib/libc/sys/h8300hms/syscalls.c.original	Thu Nov 14 17:19:38 2002
--- newlib/libc/sys/h8300hms/syscalls.c.modified	Thu Dec 26 17:05:50 2002
***************
*** 4,9 ****
--- 4,10 ----
  #include <sys/types.h>
  #include <sys/stat.h>
  #include <errno.h>
+ #include "sys/syscall.h"
  
  
  int _DEFUN(_lseek,(file, ptr, dir),
*************** int _DEFUN(_lseek,(file, ptr, dir),
*** 11,23 ****
  	  int ptr _AND
  	  int dir)
  {
!   return 0;
  }
  
  int _DEFUN(_close,(file),
  	  int file)
  {
!   return -1;
  }
  
  int isatty(file)
--- 12,24 ----
  	  int ptr _AND
  	  int dir)
  {
!   asm ("jsr @@0xc8");
  }
  
  int _DEFUN(_close,(file),
  	  int file)
  {
!   asm ("jsr @@0xc9");
  }
  
  int isatty(file)
*************** int _DEFUN(_fstat,(file, st),
*** 30,37 ****
  	  int file _AND
  	  struct stat *st)
  {
!   st->st_mode = S_IFCHR;
!   return 0;
  }
  
  int
--- 31,37 ----
  	  int file _AND
  	  struct stat *st)
  {
!   asm ("jsr @@0xcb");
  }
  
  int
*************** _open (path, flags)
*** 39,45 ****
       const char *path;
       int flags;
  {
!   return 0;
  }
  
  int
--- 39,45 ----
       const char *path;
       int flags;
  {
!   asm ("jsr @@0xc5");
  }
  
  int
*************** _unlink (path)
*** 49,51 ****
--- 49,59 ----
    errno = EIO;
    return -1;
  }
+ 
+ int _DEFUN(_stat,(path, sbuf),
+ 	  const char *path _AND
+ 	  struct stat *st)
+ {
+   asm ("jsr @@0xca");
+ }
+ 
*** newlib/libc/sys/h8300hms/read.c.original	Thu Nov 14 17:20:04 2002
--- newlib/libc/sys/h8300hms/read.c.modified	Thu Dec 26 17:05:58 2002
*************** int _read(file, ptr, len)
*** 5,27 ****
       char *ptr;
       int len;
  {
! 	register int ret asm("r0") ;
! 
! 	/* Type cast int as short so that we can copy int values into 16 bit 
! 	   registers in case of -mint32 switch is given.
! 	   This is not going to affect data as file= 0 for stdin and len=1024 */
! 
! 	asm("mov.b %0, r0l"::  "i" (SYS_read)) ; /* Syscall Number */
! 	asm("mov.w %0, r1" :: "r"((short)file) :"r1", "r2", "r3") ;
! 	asm("mov.w %0, r3" :: "r"((short)len) :"r1", "r2", "r3") ;
! #ifdef __H8300__
! 	asm("mov.w %0, r2" :: "r"(ptr) :"r1", "r2", "r3") ;
! #else
! 	asm("mov.l %0, er2" :: "r"(ptr) :"r1", "er2", "r3") ;
! #endif
! 	// This is magic trap similar to _write for simulator
! 	asm("jsr @@0xc8") ;
!   return ret;
  }
  
  
--- 5,11 ----
       char *ptr;
       int len;
  {
!   asm ("jsr @@0xc6") ;
  }
  
  
*** newlib/libc/sys/h8300hms/write.c.original	Thu Nov 14 17:20:19 2002
--- newlib/libc/sys/h8300hms/write.c.modified	Thu Dec 26 17:06:06 2002
*************** int _write(file, ptr, len)
*** 5,16 ****
       char *ptr;
       int len;
  {
!   int todo;
!   
!   for (todo = 0; todo < len; todo++) 
!     {
!       asm("mov.b #0,r1l\n mov.b %0l,r2l\njsr @@0xc4"   :  : "r" (*ptr++)  : "r1", "r2");
!     }
!   return len;
  }
  
--- 5,10 ----
       char *ptr;
       int len;
  {
!   asm ("jsr @@0xc7");
  }
  

[-- Attachment #4: binutils_patch.txt --]
[-- Type: text/plain, Size: 616 bytes --]

*** include/opcode/h8300.h.original	Thu Nov 14 17:35:40 2002
--- include/opcode/h8300.h.modified	Mon Dec  2 17:11:07 2002
*************** struct h8_opcode 
*** 305,310 ****
--- 305,320 ----
  #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_LSEEK 104
+ #define O_SYS_CLOSE 105
+ #define O_SYS_STAT 106
+ #define O_SYS_FSTAT 107
+ /* End of System Call specific Changes.  */
  #define SB 0
  #define SW 1
  #define SL 2

^ permalink raw reply	[flat|nested] 16+ messages in thread

* RE: PATCH : H8300 Simulator File I/O Implementation
@ 2002-12-02  3:45 D.Venkatasubramanian, Noida
  0 siblings, 0 replies; 16+ messages in thread
From: D.Venkatasubramanian, Noida @ 2002-12-02  3:45 UTC (permalink / raw)
  To: Kazu Hirata, gdb-patches, binutils, newlib

[-- Attachment #1: Type: text/plain, Size: 2669 bytes --]


 
> Hi Venky,
> 
> You might want to send your patch to newlib@sources.redhat.com as
> well, possibly after separating the patch for individual projects
> (binutils, newlib, and gdb-patches)!?

Two diferent patches, the simulator_patch.txt for GDB and newlib_patch.txt
for
patching newlib sources. I have attached them.

Both contain the changes required in include/opcode/h8300.h.

To change include/opcode/h8300.h, do I need to send patch to some other
mailing 
list too?

> 
> ! 		  /* And a jsr to these locations are turned 
> into magic traps. */
>   		  if (dst->opcode == O (O_JSR, SB))
>   		    {
> ! 		      if (dst->src.literal == 0xc5)
> 
> This may be up to your preference, but what about "switch 
> (dst->src.literal)"?

Changed to a switch statement. (Just a matter of preference)

> 
> ! 	    /* Setting filename_ptr to first argument of open */
> ! 	    filename_ptr = cpu.regs[0];
> 
> I think the GNU coding standard prefers a complete sentence (well,
> except the subject) ending with a period and two spaces like
> 
>   /* Set filename_ptr to the first argument of open.   */

Changed the comment format.

> 
> ! 	    /* Allocating space for the filename */
> ! 	    filename = (char *)malloc(sizeof(char) * len);
> 
> Do you free this filename somewhere?

Freed the memory allocated.

> 
> Thanks,
> 
> Kazu Hirata
> 

Thanks a lot for taking a look at the patch and pointing out the
discrepancies,

Venky

PS : The start of this message thread can be found at

http://sources.redhat.com/ml/gdb/2002-11/msg00409.html


ChangeLog entry for compile.c in sim/h8300/

Mon Dec  2 16:44:35 IST 2002  D.Venkatasubramanian
(dvenkat@noida.hcltech.com)

	* compile.c (decode): Added code for some more magic traps.
	* compile.c (sim_resume): Added support for File I/O system
	calls through callback to host_system.
	System calls provided support for :
	        open
	        read
	        write
	        lseek
	        close
	        stat
	        fstat
	Only basic support for stat and fstat.



Change Log entry for files in newlib/

Mon Dec  2 16:47:01 IST 2002 D.Venkatasubramanian
<dvenkat@noida.hcltech.com>

	* /libc/sys/h8300hms/syscalls.c: Support for various File I/O
	related system calls. Jump to magic vector locations, instead
	of dummy return values.
	* /libc/sys/h8300hms/read.c: Jump to magic vector location for
	supporting read system call.
	* /libc/sys/h8300hms/write.c: Jump to magic vector location for
	supporting write system call.


Change Log entry for file in include/opcode

Mon Dec  2 16:47:09 IST 2002 D.Venkatasubramanian
<dvenkat@noida.hcltech.com>

	*h8300.h: Added some more pseudo opcodes for system call processing.


[-- Attachment #2: simulator_patch.txt --]
[-- Type: text/plain, Size: 12595 bytes --]

*** sim/h8300/compile.c.original	Thu Nov 14 17:36:40 2002
--- sim/h8300/compile.c.modified	Mon Dec  2 16:30:03 2002
***************
*** 35,40 ****
--- 35,42 ----
  #include "gdb/callback.h"
  #include "gdb/remote-sim.h"
  #include "gdb/sim-h8300.h"
+ #include "sys/stat.h"
+ #include "sys/types.h"
  
  #ifndef SIGTRAP
  # define SIGTRAP 5
*************** decode (addr, data, dst)
*** 448,461 ****
  		  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;
--- 450,483 ----
  		  dst->opcode = q->how;
  		  dst->cycles = q->time;
  
! 		  /* A jsr to these locations are turned into magic traps.  */
  		  if (dst->opcode == O (O_JSR, SB))
  		    {
! 		      switch (dst->src.literal)
! 		        {
! 		          case 0xc5:
! 		            dst->opcode = O (O_SYS_OPEN, SB);
! 		            break;
! 		          case 0xc6:
! 		            dst->opcode = O (O_SYS_READ, SB);
! 		            break;
! 		          case 0xc7:
! 		            dst->opcode = O (O_SYS_WRITE, SB);
! 		            break;
! 		          case 0xc8:
! 		            dst->opcode = O (O_SYS_LSEEK, SB);
! 		            break;
! 		          case 0xc9:
! 		            dst->opcode = O (O_SYS_CLOSE, SB);
! 		            break;
! 		          case 0xca:
! 		            dst->opcode = O (O_SYS_STAT, SB);
! 		            break;
! 		          case 0xcb:
! 		            dst->opcode = O (O_SYS_FSTAT, SB);
! 		            break;
! 		        }
! 		        /* End of Processing for system calls.  */
  		    }
  
  		  dst->next_pc = addr + len / 2;
*************** sim_resume (sd, step, siggnal)
*** 1392,1403 ****
  	    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,
--- 1414,1689 ----
  	    goto condtrue;
  	  goto next;
  
! 	/* System call processing starts.  */
! 	case O (O_SYS_OPEN, SB) :
! 	  {
! 	    int len = 0;        /* Length of filename */
! 	    char *filename ;    /* Filename would go here */
! 	    char temp_char;	/* Temporary character */
! 	    int mode = 0;       /* Mode bits for the file */
! 	    int open_return;    /* Return value of open, file descriptor */
! 	    int i;              /* Loop counter */
! 	    int filename_ptr;   /* Pointer to filename in cpu memory */
! 
! 	    /* Setting filename_ptr to first argument of open.  */
! 	    filename_ptr = cpu.regs[0];
! 
! 	    /* Trying to get mode.  */
! 	    if (h8300hmode || h8300smode)
! 	      {
! 	        mode = GET_MEMORY_L(cpu.regs[7] + 8);
! 	      }
! 	    else
! 	      {
! 	        mode = GET_MEMORY_W(cpu.regs[7] + 4);
! 	      }		
! 	    
! 	    /* Trying to find the length of the filename.  */
! 	    temp_char = GET_MEMORY_B(cpu.regs[0]);
! 
! 	    len = 1;
! 	    while (temp_char != '\0')
! 	      {
! 	        temp_char = GET_MEMORY_B (filename_ptr + len);
! 	        len++;
! 	      }
! 	    
! 	    /* Allocating space for the filename.  */
! 	    filename = (char *)malloc(sizeof(char) * len);
! 
! 	    /* String copying the filename from memory.  */
! 	    for (i = 0; i < len; i++)
! 	      {
! 	        temp_char = GET_MEMORY_B (filename_ptr + i);
! 	        filename[i] = temp_char;
! 	      }
!          
! 	    /* Callback to open and return the file descriptor.  */
! 	    open_return = sim_callback->open (sim_callback, filename, mode);
! 	    
! 	    /* Return value in register 0.  */
! 	    cpu.regs[0] = open_return;
! 
! 	    /* Freeing memory used for filename. */
! 	    free (filename);
! 	  }
! 	  goto next;
! 
! 	case O (O_SYS_READ, SB):
! 	  {
! 	    char *char_ptr ;            /* Where characters read would be stored.  */
! 	    int fd = cpu.regs[0];       /* File descriptor */
! 	    int buf_size = cpu.regs[2]; /* BUF_SIZE parameter in read */
! 	    int i = 0;                  /* Temporary Loop counter */
! 	    int read_return = 0;        /* Return value from callback to read  */
! 	  
! 	    char_ptr = (char *)malloc(sizeof(char) * buf_size);
! 	  
! 	    /* Callback to read and return the no. of characters read.  */
! 	    read_return = sim_callback->read (sim_callback, fd, char_ptr, buf_size);
! 	  
! 	    /* The characters read are stored in cpu memory.  */
! 	    for (i = 0; i < buf_size; i++)
! 	      {
! 	        SET_MEMORY_B ((cpu.regs[1] + (sizeof(char) * i)), *(char_ptr + (sizeof(char) * i)));
! 	      }
! 	  
! 	    /* Return value in Register 0.  */
! 	    cpu.regs[0] = read_return;
! 
! 	    /* Freeing memory used as buffer.  */
! 	    free (char_ptr);
! 	  }
! 	  goto next;
! 
! 	case O (O_SYS_WRITE, SB):
! 	  {
! 	    int fd = cpu.regs[0];       /* File descriptor */
! 	    char temp_char;             /* Temporary character */
! 	    int len = cpu.regs[2];      /* Length of write, Parameter II to write */
! 	    int char_ptr = cpu.regs[1]; /* Character Pointer, Parameter I of write */
! 	    char *ptr;                  /* Where characters to be written are stored */
! 	    int write_return;           /* Return value from write */
! 	    int i = 0;                  /* Loop counter */
! 
! 	    /* Allocating space for the characters to be written.  */
! 	    ptr = (char *)malloc(sizeof(char) * len);
! 	  
! 	    /* Fetching the characters from cpu memory.  */
! 	    for (i = 0; i < len; i++)
! 	      {
! 	        temp_char = GET_MEMORY_B (char_ptr + i);
! 	        ptr[i] = temp_char;
! 	      }
! 
! 	    /* Callback write and return the no. of characters written.  */
! 	    write_return = sim_callback->write (sim_callback, fd, ptr, len);
! 
! 	    /* Return value in Register 0.  */
! 	    cpu.regs[0] = write_return;
! 
! 	    /* Freeing memory used as buffer.  */
! 	    free (ptr);
! 	  }
! 	  goto next;
!  	   
! 	case O (O_SYS_LSEEK, SB):
! 	  {
! 	    int fd = cpu.regs[0];     /* File descriptor */
! 	    int offset = cpu.regs[1]; /* Offset */
! 	    int origin = cpu.regs[2]; /* Origin */
! 	    int lseek_return;         /* Return by lseek */
! 
! 	    /* Callback lseek and return offset.  */
! 	    lseek_return = sim_callback->lseek (sim_callback, fd, offset, origin);
! 
! 	    /* Return value in register 0.  */
! 	    cpu.regs[0] = lseek_return;
! 	  }
! 	  goto next;
! 
! 	case O (O_SYS_CLOSE, SB):
! 	  {
! 	    int fd = cpu.regs[0]; /* File descriptor */
! 	    int close_return;     /* Return by close */
! 
! 	    /* Callback close and return.  */
! 	    close_return = sim_callback->close (sim_callback, fd);
! 
! 	    /* Return value in register 0.  */
! 	    cpu.regs[0] = close_return;
! 	  }
! 	  goto next;
! 
! 	case O (O_SYS_FSTAT, SB):
! 	  {
! 	    int fd = cpu.regs[0]; /* File descriptor */
! 	    struct stat stat_rec; /* Stat record */
! 	    int fstat_return;     /* Return value of stat */
! 	    int stat_ptr;         /* Pointer to stat record */
! 	    char *temp_stat_ptr;  /* Temporary stat_rec pointer */
! 	    int buf_size = 0;     /* Temporary variable for buffer size */
! 	    int i = 0;            /* Loop Counter */
! 	    int j = 0;            /* Temporary variable for Position in source */
! 	    int short_size = sizeof (short); /* Sizeof short */
! 	    int int_size = sizeof (int);     /* Sizeof int */
! 		
! 	    /* Setting stat_ptr to second argument of stat.  */
! 	    stat_ptr = cpu.regs[1];
!   
! 	    /* Callback stat and return.  */
! 	    fstat_return = sim_callback->fstat (sim_callback, fd, &stat_rec);
! 
! 	    /* Have stat_ptr point to starting of stat_rec.  */
! 	    temp_stat_ptr = (char *)(&stat_rec);
! 
! 	    /* Setting up the stat structure returned.  */
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_dev);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_ino);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_mode);
! 	    stat_ptr += 4;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_nlink);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_uid);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_gid);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_rdev);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_size);
! 	    stat_ptr += 4;
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_atime);
! 	    stat_ptr += 8;
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_mtime);
! 	    stat_ptr += 8; 
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_ctime);
! 	  
! 	    /* Return value in register 0.  */
! 	    cpu.regs[0] = fstat_return;
! 	  }
! 	  goto next;
! 
! 	case O (O_SYS_STAT, SB):
  	  {
! 	    int len = 0;          /* Length of filename */
! 	    char *filename ;      /* Filename would go here */
! 	    char temp_char;	  /* Temporary character */
! 	    int filename_ptr;     /* Pointer to filename in cpu memory */
! 	    struct stat stat_rec; /* Stat record */
! 	    int stat_return;      /* Return value of stat */
! 	    int stat_ptr;         /* Pointer to stat record */
! 	    char *temp_stat_ptr;  /* Temporary stat_rec pointer */
! 	    int buf_size = 0;     /* Temporary variable for buffer size */
! 	    int i = 0;            /* Loop Counter */
! 	    int j = 0;            /* Temporary variable for Position in source */
! 	    int short_size = sizeof (short); /* Sizeof short */
! 	    int int_size = sizeof (int);     /* Sizeof int */
! 
! 	    /* Setting filename_ptr to first argument of open.  */
! 	    filename_ptr = cpu.regs[0];
! 
! 	    /* Trying to find the length of the filename.  */
! 	    temp_char = GET_MEMORY_B(cpu.regs[0]);
! 
! 	    len = 1;
! 	    while (temp_char != '\0')
! 	      {
! 	        temp_char = GET_MEMORY_B (filename_ptr + len);
! 	        len++;
! 	      }
! 	   
! 	    /* Allocating space for the filename.  */
! 	    filename = (char *)malloc(sizeof(char) * len);
! 
! 	    /* String copying the filename from memory.  */
! 	    for (i = 0; i < len; i++)
! 	      {
! 	        temp_char = GET_MEMORY_B (filename_ptr + i);
! 	        filename[i] = temp_char;
! 	      }
! 	   
! 	    /* Setting stat_ptr to second argument of stat.  */
! 	    stat_ptr = cpu.regs[1];
!   
! 	    /* Callback stat and return.  */
! 	    stat_return = sim_callback->stat (sim_callback, filename, &stat_rec);
! 
! 	    /* Have stat_ptr point to starting of stat_rec.  */
! 	    temp_stat_ptr = (char *)(&stat_rec);
! 
! 	    /* Freeing memory used for filename.  */
! 	    free (filename);
! 
! 	    /* Setting up the stat structure returned.  */
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_dev);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_ino);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_mode);
! 	    stat_ptr += 4;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_nlink);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_uid);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_gid);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_rdev);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_size);
! 	    stat_ptr += 4;
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_atime);
! 	    stat_ptr += 8;
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_mtime);
! 	    stat_ptr += 8; 
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_ctime);
! 	  
! 	    /* Return value in register 0.  */
! 	    cpu.regs[0] = stat_return;
  	  }
  	  goto next;
+ 	  /* End of system call processing.  */
  
  	  ONOT (O_NOT, rd = ~rd; v = 0;);
  	  OSHIFTS (O_SHLL,
*** include/opcode/h8300.h.original	Thu Nov 14 17:35:40 2002
--- include/opcode/h8300.h.modified	Mon Dec  2 17:11:07 2002
*************** struct h8_opcode 
*** 305,310 ****
--- 305,320 ----
  #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_LSEEK 104
+ #define O_SYS_CLOSE 105
+ #define O_SYS_STAT 106
+ #define O_SYS_FSTAT 107
+ /* End of System Call specific Changes.  */
  #define SB 0
  #define SW 1
  #define SL 2

[-- Attachment #3: simulator_ChangeLog.txt --]
[-- Type: text/plain, Size: 589 bytes --]

Mon Dec  2 16:44:35 IST 2002  D.Venkatasubramanian (dvenkat@noida.hcltech.com)

	* compile.c (decode): Added code for some more magic traps.
	* compile.c (sim_resume): Added support for File I/O system
	calls through callback to host_system.
	System calls provided support for :
	        open
	        read
	        write
	        lseek
	        close
	        stat
	        fstat
	Only basic support for stat and fstat.

Mon Dec  2 16:47:09 IST 2002 D.Venkatasubramanian <dvenkat@noida.hcltech.com>

	*h8300.h: Added some more pseudo opcodes for system call processing.

[-- Attachment #4: newlib_patch.txt --]
[-- Type: text/plain, Size: 3745 bytes --]

*** newlib/libc/sys/h8300hms/read.c.original	Thu Nov 14 17:20:04 2002
--- newlib/libc/sys/h8300hms/read.c.modified	Fri Nov 29 13:51:42 2002
*************** int _read(file, ptr, len)
*** 5,27 ****
       char *ptr;
       int len;
  {
! 	register int ret asm("r0") ;
! 
! 	/* Type cast int as short so that we can copy int values into 16 bit 
! 	   registers in case of -mint32 switch is given.
! 	   This is not going to affect data as file= 0 for stdin and len=1024 */
! 
! 	asm("mov.b %0, r0l"::  "i" (SYS_read)) ; /* Syscall Number */
! 	asm("mov.w %0, r1" :: "r"((short)file) :"r1", "r2", "r3") ;
! 	asm("mov.w %0, r3" :: "r"((short)len) :"r1", "r2", "r3") ;
! #ifdef __H8300__
! 	asm("mov.w %0, r2" :: "r"(ptr) :"r1", "r2", "r3") ;
! #else
! 	asm("mov.l %0, er2" :: "r"(ptr) :"r1", "er2", "r3") ;
! #endif
! 	// This is magic trap similar to _write for simulator
! 	asm("jsr @@0xc8") ;
!   return ret;
  }
  
  
--- 5,11 ----
       char *ptr;
       int len;
  {
!   asm("jsr @@0xc6") ;
  }
  
  
*** newlib/libc/sys/h8300hms/write.c.original	Thu Nov 14 17:20:19 2002
--- newlib/libc/sys/h8300hms/write.c.modified	Fri Nov 29 13:52:23 2002
*************** int _write(file, ptr, len)
*** 5,16 ****
       char *ptr;
       int len;
  {
!   int todo;
!   
!   for (todo = 0; todo < len; todo++) 
!     {
!       asm("mov.b #0,r1l\n mov.b %0l,r2l\njsr @@0xc4"   :  : "r" (*ptr++)  : "r1", "r2");
!     }
!   return len;
  }
  
--- 5,10 ----
       char *ptr;
       int len;
  {
!   asm("jsr @@0xc7");
  }
  
*** newlib/libc/sys/h8300hms/syscalls.c.original	Thu Nov 14 17:19:38 2002
--- newlib/libc/sys/h8300hms/syscalls.c.modified	Fri Nov 29 13:52:57 2002
***************
*** 4,23 ****
  #include <sys/types.h>
  #include <sys/stat.h>
  #include <errno.h>
  
  
  int _DEFUN(_lseek,(file, ptr, dir),
  	  int file _AND
  	  int ptr _AND
  	  int dir)
  {
!   return 0;
  }
  
  int _DEFUN(_close,(file),
  	  int file)
  {
!   return -1;
  }
  
  int isatty(file)
--- 4,31 ----
  #include <sys/types.h>
  #include <sys/stat.h>
  #include <errno.h>
+ #include "sys/syscall.h"
  
+ int
+ _open (path, flags)
+      const char *path;
+      int flags;
+ {
+   asm("jsr @@0xc5");
+ }
  
  int _DEFUN(_lseek,(file, ptr, dir),
  	  int file _AND
  	  int ptr _AND
  	  int dir)
  {
!   asm("jsr @@0xc8");
  }
  
  int _DEFUN(_close,(file),
  	  int file)
  {
!   asm("jsr @@0xc9");
  }
  
  int isatty(file)
*************** int isatty(file)
*** 26,45 ****
    return 1;
  }
  
! int _DEFUN(_fstat,(file, st),
! 	  int file _AND
! 	  struct stat *st)
  {
!   st->st_mode = S_IFCHR;
!   return 0;
  }
  
! int
! _open (path, flags)
!      const char *path;
!      int flags;
  {
!   return 0;
  }
  
  int
--- 34,52 ----
    return 1;
  }
  
! int _DEFUN(_stat,(path, sbuf),
! 	const char *path _AND
! 	struct stat *st)
  {
!   asm("jsr @@0xca");
  }
  
! 
! int _DEFUN(_fstat,(file, st),
!         int file _AND
!         struct stat *st)
  {
!   asm("jsr @@0xcb"); 
  }
  
  int
*** include/opcode/h8300.h.original	Thu Nov 14 17:35:40 2002
--- include/opcode/h8300.h.modified	Mon Dec  2 17:11:07 2002
*************** struct h8_opcode 
*** 305,310 ****
--- 305,320 ----
  #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_LSEEK 104
+ #define O_SYS_CLOSE 105
+ #define O_SYS_STAT 106
+ #define O_SYS_FSTAT 107
+ /* End of System Call specific Changes.  */
  #define SB 0
  #define SW 1
  #define SL 2

[-- Attachment #5: newlib_ChangeLog.txt --]
[-- Type: text/plain, Size: 583 bytes --]

Mon Dec  2 16:47:01 IST 2002 D.Venkatasubramanian <dvenkat@noida.hcltech.com>

	* /libc/sys/h8300hms/syscalls.c: Support for various File I/O
	related system calls. Jump to magic vector locations, instead
	of dummy return values.
	* /libc/sys/h8300hms/read.c: Jump to magic vector location for
	supporting read system call.
	* /libc/sys/h8300hms/write.c: Jump to magic vector location for
	supporting write system call.

Mon Dec  2 16:47:09 IST 2002 D.Venkatasubramanian <dvenkat@noida.hcltech.com>

	*h8300.h: Added some more pseudo opcodes for system call processing.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: PATCH : H8300 Simulator File I/O Implementation
  2002-11-29 21:31 D.Venkatasubramanian, Noida
@ 2002-11-30 10:01 ` Kazu Hirata
  2003-03-04 16:08   ` Andrew Cagney
  0 siblings, 1 reply; 16+ messages in thread
From: Kazu Hirata @ 2002-11-30 10:01 UTC (permalink / raw)
  To: dvenkat; +Cc: gdb-patches, binutils

Hi Venky,

You might want to send your patch to newlib@sources.redhat.com as
well, possibly after separating the patch for individual projects
(binutils, newlib, and gdb-patches)!?

! 		  /* And a jsr to these locations are turned into magic traps. */
  		  if (dst->opcode == O (O_JSR, SB))
  		    {
! 		      if (dst->src.literal == 0xc5)

This may be up to your preference, but what about "switch (dst->src.literal)"?

! 	    /* Setting filename_ptr to first argument of open */
! 	    filename_ptr = cpu.regs[0];

I think the GNU coding standard prefers a complete sentence (well,
except the subject) ending with a period and two spaces like

  /* Set filename_ptr to the first argument of open.   */

! 	    /* Allocating space for the filename */
! 	    filename = (char *)malloc(sizeof(char) * len);

Do you free this filename somewhere?

Thanks,

Kazu Hirata


^ permalink raw reply	[flat|nested] 16+ messages in thread

* RE: PATCH : H8300 Simulator File I/O Implementation
@ 2002-11-29 21:31 D.Venkatasubramanian, Noida
  2002-11-30 10:01 ` Kazu Hirata
  0 siblings, 1 reply; 16+ messages in thread
From: D.Venkatasubramanian, Noida @ 2002-11-29 21:31 UTC (permalink / raw)
  To: Kazu Hirata, gdb-patches; +Cc: gdb, binutils

[-- Attachment #1: Type: text/plain, Size: 1279 bytes --]

Hi All,
 
 >
 >I haven't looked at the patch carefully, but I think it would be nice
 >you could send your patch as an attachment as some lines are folded.

I am attaching the patch file.

 >
 >Could you fix the indentation?  The standard indentation is 2 spaces
 >for each levela like

Fixed.

 >
 >Kazu Hirata
 >

Regards,

Venky


Thu Nov 28 14:49:51 IST 2002  D.Venkatasubramanian
(dvenkat@noida.hcltech.com)

	* compile.c (decode): Added code for some more magic traps.
	* compile.c (sim_resume): Added support for File I/O system
	calls through callback to host_system. 
	System calls provided support for :
	open, read, write, lseek, close, stat, fstat
	Only basic support for stat and fstat.



Thu Nov 28 14:58:41 IST 2002 D.Venkatasubramanian
<dvenkat@noida.hcltech.com>

	*h8300.h: Added some more pseudo opcodes for system call processing.




Thu Nov 28 15:02:51 IST 2002 D.Venkatasubramanian
<dvenkat@noida.hcltech.com>

	* /libc/sys/h8300hms/syscalls.c: Support for various File I/O
	related system calls. Jump to magic vector locations, instead 
	of dummy return values.
	* /libc/sys/h8300hms/read.c: Jump to magic vector location for 
	supporting read system call.
	* /libc/sys/h8300hms/write.c: Jump to magic vector location for
	supporting write system call.


[-- Attachment #2: ChangeLog.txt --]
[-- Type: text/plain, Size: 971 bytes --]

Thu Nov 28 14:49:51 IST 2002  D.Venkatasubramanian (dvenkat@noida.hcltech.com)

	* compile.c (decode): Added code for some more magic traps.
	* compile.c (sim_resume): Added support for File I/O system
	calls through callback to host_system. 
	System calls provided support for :
	open, read, write, lseek, close, stat, fstat
	Only basic support for stat and fstat.



Thu Nov 28 14:58:41 IST 2002 D.Venkatasubramanian <dvenkat@noida.hcltech.com>

	*h8300.h: Added some more pseudo opcodes for system call processing.




Thu Nov 28 15:02:51 IST 2002 D.Venkatasubramanian <dvenkat@noida.hcltech.com>

	* /libc/sys/h8300hms/syscalls.c: Support for various File I/O
	related system calls. Jump to magic vector locations, instead 
	of dummy return values.
	* /libc/sys/h8300hms/read.c: Jump to magic vector location for 
	supporting read system call.
	* /libc/sys/h8300hms/write.c: Jump to magic vector location for
	supporting write system call.

[-- Attachment #3: patch.txt --]
[-- Type: text/plain, Size: 15318 bytes --]

*** sim/h8300/compile.c.original	Thu Nov 14 17:36:40 2002
--- sim/h8300/compile.c.modified	Sat Nov 30 10:37:42 2002
***************
*** 35,40 ****
--- 35,42 ----
  #include "gdb/callback.h"
  #include "gdb/remote-sim.h"
  #include "gdb/sim-h8300.h"
+ #include "sys/stat.h"
+ #include "sys/types.h"
  
  #ifndef SIGTRAP
  # define SIGTRAP 5
*************** decode (addr, data, dst)
*** 448,461 ****
  		  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;
--- 450,487 ----
  		  dst->opcode = q->how;
  		  dst->cycles = q->time;
  
! 		  /* And a jsr to these locations are turned into magic traps. */
  		  if (dst->opcode == O (O_JSR, SB))
  		    {
! 		      if (dst->src.literal == 0xc5)
! 		        {
! 		          dst->opcode = O (O_SYS_OPEN, SB);
! 		        }
! 		      else if (dst->src.literal == 0xc6)
! 		        {
! 		          dst->opcode = O (O_SYS_READ, SB);     
! 		        }
! 		      else if (dst->src.literal == 0xc7)
! 		        {
! 		          dst->opcode = O (O_SYS_WRITE, SB);
! 		        }
! 		      else if (dst->src.literal == 0xc8)
! 		        {
! 		          dst->opcode = O (O_SYS_LSEEK, SB);
! 		        }
! 		      else if (dst->src.literal == 0xc9)
! 		        {
! 		          dst->opcode = O (O_SYS_CLOSE, SB);
! 		        }
! 		      else if (dst->src.literal == 0xca)
! 		        {
! 		          dst->opcode = O (O_SYS_STAT, SB);
! 		        }  
! 		      else if (dst->src.literal == 0xcb)
! 		        {
! 		          dst->opcode = O (O_SYS_FSTAT, SB);
! 		        }
! 		      /* End of Processing for system calls */
  		    }
  
  		  dst->next_pc = addr + len / 2;
*************** sim_resume (sd, step, siggnal)
*** 1392,1403 ****
  	    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,
--- 1418,1679 ----
  	    goto condtrue;
  	  goto next;
  
! 	/* System call processing */
! 	case O (O_SYS_OPEN, SB) :
! 	  {
! 	    int len = 0;        /* Length of filename */
! 	    char *filename ;    /* Filename would go here */
! 	    char temp_char;	 /* Temporary character */
! 	    int mode = 0;       /* Mode bits for the file */
! 	    int open_return;    /* Return value of open, file descriptor */
! 	    int i;              /* Loop counter */
! 	    int filename_ptr;   /* Pointer to filename in cpu memory */
! 
! 	    /* Setting filename_ptr to first argument of open */
! 	    filename_ptr = cpu.regs[0];
! 
! 	    /* Trying to get mode */
! 	    if (h8300hmode || h8300smode)
! 	      {
! 	        mode = GET_MEMORY_L(cpu.regs[7] + 8);
! 	      }
! 	    else
! 	      {
! 	        mode = GET_MEMORY_W(cpu.regs[7] + 4);
! 	      }		
! 	    
! 	    /* Trying to find the length of the filename */
! 	    temp_char = GET_MEMORY_B(cpu.regs[0]);
! 
! 	    len = 1;
! 	    while (temp_char != '\0')
! 	      {
! 	        temp_char = GET_MEMORY_B (filename_ptr + len);
! 	        len++;
! 	      }
! 	    
! 	    /* Allocating space for the filename */
! 	    filename = (char *)malloc(sizeof(char) * len);
! 
! 	    /* String copying the filename from memory */
! 	    for (i = 0; i < len; i++)
! 	      {
! 	        temp_char = GET_MEMORY_B (filename_ptr + i);
! 	        filename[i] = temp_char;
! 	      }
!          
! 	    /* Callback to open and return the file descriptor */
! 	    open_return = sim_callback->open (sim_callback, filename, mode);
! 	    
! 	    /* Return value in register 0 */
! 	    cpu.regs[0] = open_return;
! 	  }
! 	  goto next;
! 
! 	case O (O_SYS_READ, SB):
! 	  {
! 	    char *char_ptr ;            /* Where characters read would be stored */
! 	    int fd = cpu.regs[0];       /* File descriptor */
! 	    int buf_size = cpu.regs[2]; /* BUF_SIZE parameter in read */
! 	    int i = 0;                  /* Temporary Loop counter */
! 	    int read_return = 0;        /* Return value from callback to read */
! 	  
! 	    char_ptr = (char *)malloc(sizeof(char) * buf_size);
! 	  
! 	    /* Callback to read and return the no. of characters read */
! 	    read_return = sim_callback->read (sim_callback, fd, char_ptr, buf_size);
! 	  
! 	    /* The characters read are stored in cpu memory */
! 	    for (i = 0; i < buf_size; i++)
! 	      {
! 	        SET_MEMORY_B ((cpu.regs[1] + (sizeof(char) * i)), *(char_ptr + (sizeof(char) * i)));
! 	      }
! 	  
! 	    /* Return value in Register 0 */
! 	    cpu.regs[0] = read_return;
! 	  }
! 	  goto next;
! 
! 	case O (O_SYS_WRITE, SB):
! 	  {
! 	    int fd = cpu.regs[0];       /* File descriptor */
! 	    char temp_char;             /* Temporary character */
! 	    int len = cpu.regs[2];      /* Length of write, Parameter II to write */
! 	    int char_ptr = cpu.regs[1]; /* Character Pointer, Parameter I of write */
! 	    char *ptr;                  /* This characters to be written are stored */
! 	    int write_return;           /* Return value from write */
! 	    int i = 0;                  /* Loop counter */
! 
! 	    /* Allocating space for the characters to be written */
! 	    ptr = (char *)malloc(sizeof(char) * len);
! 	  
! 	    /* Fetching the characters from cpu memory */
! 	    for (i = 0; i < len; i++)
! 	      {
! 	        temp_char = GET_MEMORY_B (char_ptr + i);
! 	        ptr[i] = temp_char;
! 	      }
! 
! 	    /* Callback write and return the no. of characters written */
! 	    write_return = sim_callback->write (sim_callback, fd, ptr, len);
! 
! 	    /* Return value in Register 0 */
! 	    cpu.regs[0] = write_return;
! 	  }
! 	  goto next;
!  	   
! 	case O (O_SYS_LSEEK, SB):
! 	  {
! 	    int fd = cpu.regs[0];     /* File descriptor */
! 	    int offset = cpu.regs[1]; /* Offset */
! 	    int origin = cpu.regs[2]; /* Origin */
! 	    int lseek_return;         /* Return by lseek */
! 
! 	    /* Callback lseek and return offset */
! 	    lseek_return = sim_callback->lseek (sim_callback, fd, offset, origin);
! 
! 	    /* Return value in register 0 */
! 	    cpu.regs[0] = lseek_return;
! 	  }
! 	  goto next;
! 
! 	case O (O_SYS_CLOSE, SB):
! 	  {
! 	    int fd = cpu.regs[0]; /* File descriptor */
! 	    int close_return;     /* Return by close */
! 
! 	    /* Callback close and return */
! 	    close_return = sim_callback->close (sim_callback, fd);
! 
! 	    /* Return value in register 0 */
! 	    cpu.regs[0] = close_return;
! 	  }
! 	  goto next;
! 
! 	case O (O_SYS_FSTAT, SB):
! 	  {
! 	    int fd = cpu.regs[0]; /* File descriptor */
! 	    struct stat stat_rec; /* Stat record */
! 	    int fstat_return;     /* Return value of stat */
! 	    int stat_ptr;         /* Pointer to stat record */
! 	    char *temp_stat_ptr;  /* Temporary stat_rec pointer */
! 	    int buf_size = 0;     /* Temporary variable for buffer size */
! 	    int i = 0;            /* Loop Counter */
! 	    int j = 0;            /* Temporary variable for Position in source */
! 	    int short_size = sizeof (short); /* Sizeof short */
! 	    int int_size = sizeof (int);     /* Sizeof int */
! 		
! 	    /* Setting stat_ptr to second argument of stat */
! 	    stat_ptr = cpu.regs[1];
!   
! 	    /* Callback stat and return */
! 	    fstat_return = sim_callback->fstat (sim_callback, fd, &stat_rec);
! 
! 	    /* Have stat_ptr point to starting of stat_rec */
! 	    temp_stat_ptr = (char *)(&stat_rec);
! 
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_dev);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_ino);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_mode);
! 	    stat_ptr += 4;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_nlink);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_uid);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_gid);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_rdev);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_size);
! 	    stat_ptr += 4;
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_atime);
! 	    stat_ptr += 8;
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_mtime);
! 	    stat_ptr += 8; 
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_ctime);
! 	  
! 	    /* Return value in register 0 */
! 	    cpu.regs[0] = fstat_return;
! 	  }
! 	  goto next;
! 
! 	case O (O_SYS_STAT, SB):
  	  {
! 	    int len = 0;          /* Length of filename */
! 	    char *filename ;      /* Filename would go here */
! 	    char temp_char;	  /* Temporary character */
! 	    int filename_ptr;     /* Pointer to filename in cpu memory */
! 	    struct stat stat_rec; /* Stat record */
! 	    int stat_return;      /* Return value of stat */
! 	    int stat_ptr;         /* Pointer to stat record */
! 	    char *temp_stat_ptr;  /* Temporary stat_rec pointer */
! 	    int buf_size = 0;     /* Temporary variable for buffer size */
! 	    int i = 0;            /* Loop Counter */
! 	    int j = 0;            /* Temporary variable for Position in source */
! 	    int short_size = sizeof (short); /* Sizeof short */
! 	    int int_size = sizeof (int);     /* Sizeof int */
! 
! 	    /* Setting filename_ptr to first argument of open */
! 	    filename_ptr = cpu.regs[0];
! 
! 	    /* Trying to find the length of the filename */
! 	    temp_char = GET_MEMORY_B(cpu.regs[0]);
! 
! 	    len = 1;
! 	    while (temp_char != '\0')
! 	      {
! 	        temp_char = GET_MEMORY_B (filename_ptr + len);
! 	        len++;
! 	      }
! 	   
! 	    /* Allocating space for the filename */
! 	    filename = (char *)malloc(sizeof(char) * len);
! 
! 	    /* String copying the filename from memory */
! 	    for (i = 0; i < len; i++)
! 	      {
! 	        temp_char = GET_MEMORY_B (filename_ptr + i);
! 	        filename[i] = temp_char;
! 	      }
! 	   
! 	    /* Setting stat_ptr to second argument of stat */
! 	    stat_ptr = cpu.regs[1];
!   
! 	    /* Callback stat and return */
! 	    stat_return = sim_callback->stat (sim_callback, filename, &stat_rec);
! 
! 	    /* Have stat_ptr point to starting of stat_rec */
! 	    temp_stat_ptr = (char *)(&stat_rec);
! 
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_dev);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_ino);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_mode);
! 	    stat_ptr += 4;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_nlink);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_uid);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_gid);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_W (stat_ptr, stat_rec.st_rdev);
! 	    stat_ptr += 2;
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_size);
! 	    stat_ptr += 4;
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_atime);
! 	    stat_ptr += 8;
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_mtime);
! 	    stat_ptr += 8; 
! 	    SET_MEMORY_L (stat_ptr, stat_rec.st_ctime);
! 	  
! 	    /* Return value in register 0 */
! 	    cpu.regs[0] = stat_return;
  	  }
  	  goto next;
+ 	  /* End of system call processing  */
  
  	  ONOT (O_NOT, rd = ~rd; v = 0;);
  	  OSHIFTS (O_SHLL,
*** newlib/libc/sys/h8300hms/read.c.original	Thu Nov 14 17:20:04 2002
--- newlib/libc/sys/h8300hms/read.c.modified	Fri Nov 29 13:51:42 2002
*************** int _read(file, ptr, len)
*** 5,27 ****
       char *ptr;
       int len;
  {
! 	register int ret asm("r0") ;
! 
! 	/* Type cast int as short so that we can copy int values into 16 bit 
! 	   registers in case of -mint32 switch is given.
! 	   This is not going to affect data as file= 0 for stdin and len=1024 */
! 
! 	asm("mov.b %0, r0l"::  "i" (SYS_read)) ; /* Syscall Number */
! 	asm("mov.w %0, r1" :: "r"((short)file) :"r1", "r2", "r3") ;
! 	asm("mov.w %0, r3" :: "r"((short)len) :"r1", "r2", "r3") ;
! #ifdef __H8300__
! 	asm("mov.w %0, r2" :: "r"(ptr) :"r1", "r2", "r3") ;
! #else
! 	asm("mov.l %0, er2" :: "r"(ptr) :"r1", "er2", "r3") ;
! #endif
! 	// This is magic trap similar to _write for simulator
! 	asm("jsr @@0xc8") ;
!   return ret;
  }
  
  
--- 5,11 ----
       char *ptr;
       int len;
  {
!   asm("jsr @@0xc6") ;
  }
  
  
*** newlib/libc/sys/h8300hms/write.c.original	Thu Nov 14 17:20:19 2002
--- newlib/libc/sys/h8300hms/write.c.modified	Fri Nov 29 13:52:23 2002
*************** int _write(file, ptr, len)
*** 5,16 ****
       char *ptr;
       int len;
  {
!   int todo;
!   
!   for (todo = 0; todo < len; todo++) 
!     {
!       asm("mov.b #0,r1l\n mov.b %0l,r2l\njsr @@0xc4"   :  : "r" (*ptr++)  : "r1", "r2");
!     }
!   return len;
  }
  
--- 5,10 ----
       char *ptr;
       int len;
  {
!   asm("jsr @@0xc7");
  }
  
*** newlib/libc/sys/h8300hms/syscalls.c.original	Thu Nov 14 17:19:38 2002
--- newlib/libc/sys/h8300hms/syscalls.c.modified	Fri Nov 29 13:52:57 2002
***************
*** 4,23 ****
  #include <sys/types.h>
  #include <sys/stat.h>
  #include <errno.h>
  
  
  int _DEFUN(_lseek,(file, ptr, dir),
  	  int file _AND
  	  int ptr _AND
  	  int dir)
  {
!   return 0;
  }
  
  int _DEFUN(_close,(file),
  	  int file)
  {
!   return -1;
  }
  
  int isatty(file)
--- 4,31 ----
  #include <sys/types.h>
  #include <sys/stat.h>
  #include <errno.h>
+ #include "sys/syscall.h"
  
+ int
+ _open (path, flags)
+      const char *path;
+      int flags;
+ {
+   asm("jsr @@0xc5");
+ }
  
  int _DEFUN(_lseek,(file, ptr, dir),
  	  int file _AND
  	  int ptr _AND
  	  int dir)
  {
!   asm("jsr @@0xc8");
  }
  
  int _DEFUN(_close,(file),
  	  int file)
  {
!   asm("jsr @@0xc9");
  }
  
  int isatty(file)
*************** int isatty(file)
*** 26,45 ****
    return 1;
  }
  
! int _DEFUN(_fstat,(file, st),
! 	  int file _AND
! 	  struct stat *st)
  {
!   st->st_mode = S_IFCHR;
!   return 0;
  }
  
! int
! _open (path, flags)
!      const char *path;
!      int flags;
  {
!   return 0;
  }
  
  int
--- 34,52 ----
    return 1;
  }
  
! int _DEFUN(_stat,(path, sbuf),
! 	const char *path _AND
! 	struct stat *st)
  {
!   asm("jsr @@0xca");
  }
  
! 
! int _DEFUN(_fstat,(file, st),
!         int file _AND
!         struct stat *st)
  {
!   asm("jsr @@0xcb"); 
  }
  
  int
*** include/opcode/h8300.h.original	Thu Nov 14 17:35:40 2002
--- include/opcode/h8300.h.modified	Fri Nov 29 14:00:57 2002
*************** struct h8_opcode 
*** 305,310 ****
--- 305,320 ----
  #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_LSEEK 104
+ #define O_SYS_CLOSE 105
+ #define O_SYS_STAT 106
+ #define O_SYS_FSTAT 107
+ /* End of Changes */
  #define SB 0
  #define SW 1
  #define SL 2

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2003-03-04 16:33 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-23 22:59 PATCH : H8300 Simulator File I/O Implementation D.Venkatasubramanian, Noida
2002-12-24  6:51 ` Kazu Hirata
  -- strict thread matches above, loose matches on Subject: below --
2003-01-14  4:56 D.Venkatasubramanian, Noida
2003-01-08  5:08 D.Venkatasubramanian, Noida
2003-01-03  8:30 D.Venkatasubramanian, Noida
2003-01-07 22:00 ` Kazu Hirata
2003-01-07 23:08 ` Andrew Cagney
2002-12-31  2:00 D.Venkatasubramanian, Noida
2002-12-31  4:42 ` Kazu Hirata
2002-12-26 10:12 D.Venkatasubramanian, Noida
2002-12-26  4:38 D.Venkatasubramanian, Noida
2002-12-02  3:45 D.Venkatasubramanian, Noida
2002-11-29 21:31 D.Venkatasubramanian, Noida
2002-11-30 10:01 ` Kazu Hirata
2003-03-04 16:08   ` Andrew Cagney
2003-03-04 16:33     ` Kazu Hirata

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox