Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* RE: [PATCH] Add support for scanf, gets in h8300 simulator
@ 2002-06-03  3:07 Andrew Volkov
  0 siblings, 0 replies; 6+ messages in thread
From: Andrew Volkov @ 2002-06-03  3:07 UTC (permalink / raw)
  To: Dhananjay R. Deshpande; +Cc: gdb-patches

Hi Dhananjay

>>Maybe now is time to change ugly "magic" 0xc4 vector to something more
>>correct(ex. trap  for h8s)? Because on many h8h/h8s chips, 
>vectors 0xc4 and
>> 0xc8 are busy under peripheries.
>
>There is a trapa instruction available in H8300/H and H8/S but 
>not in H8300. With current implementation, it will be same for 
>all. If we implement trapa for H8300/H and H8300/S, still we 
>will have to support the H8300/L with current implementation. 

Yes I told about move to trapa for h8s/h and for 0xc4/0xc8 for other.
Because on h8s/h you WILL have problems with this vectors. 

>Since nothing is actually written at 0xc4 and 0xc8, it should 
>not be a problem for code running on target using those 
>peripherals. Users can put there vector handler at those vectors.

H-m-m, I don't think its a good idea to mix application and debug code in
interrupt.
Especially when you could split it without pain.

Andrey




^ permalink raw reply	[flat|nested] 6+ messages in thread
* RE: [PATCH] Add support for scanf, gets in h8300 simulator
@ 2002-05-24  3:07 Dhananjay R. Deshpande
  0 siblings, 0 replies; 6+ messages in thread
From: Dhananjay R. Deshpande @ 2002-05-24  3:07 UTC (permalink / raw)
  To: Andrew Volkov; +Cc: gdb-patches

Hi,

>Hi,

>Maybe now is time to change ugly "magic" 0xc4 vector to something more
>correct(ex. trap  for h8s)? Because on many h8h/h8s chips, vectors 0xc4 and
> 0xc8 are busy under peripheries.

There is a trapa instruction available in H8300/H and H8/S but not in H8300. With current implementation, it will be same for all. If we implement trapa for H8300/H and H8300/S, still we will have to support the H8300/L with current implementation. Since nothing is actually written at 0xc4 and 0xc8, it should not be a problem for code running on target using those peripherals. Users can put there vector handler at those vectors.

Dhananjay

>Andrey Volkov


>-----Original Message-----
>From: Thomas Fitzsimmons [mailto:fitzsim@redhat.com]
>Sent: Friday, May 17, 2002 11:55 PM
>To: Dhananjay R. Deshpande
>Cc: newlib@sources.redhat.com; gdb-patches@sources.redhat.com
>Subject: RE: [PATCH] Add support for scanf, gets in h8300 simulator
>
>
>On Fri, 2002-05-17 at 08:47, Dhananjay R. Deshpande wrote:
>> Hi,
>> 
>> Resubmitting the patch as per suggestion from Thomas Fitzsimmons.	
>> 
>
>I'm going to change SYS_read to match the value found in
>libgloss/syscall.h (4), before committing this.
>
>Tom
>
>> For Simulator -
>> 2002-05-14 Dhananjay Deshpande <dhananjayd@kpit.com>
>> 	* include/opcode/h8300.h: Changed SYSCALL to 
>SYSCALL_WRITE and added generic 		  SYSCALL for 
>handling new syscalls.
>> 	* sim/h8300/compile.c: New generic SYSCALL magic trap 
>JSR @@0xC8 
>> 	* sim/h8300/syscall.h: #Define syscall number
>> 
>> For Newlib - 
>> 2002-05-14 Dhananjay Deshpande <dhananjayd@kpit.com>
>> 	* newlib/libc/sys/h8300hms/syscalls.c: Moved _read() to read.c
>> 	* newlib/libc/sys/h8300hms/read.c: New file. Magic trap 
>0xC8 for Simulator
>> 	* newlib/libs/sys/h8300hms/sys/syscall.h: #Define syscall number
>> 	* newlib/libc/sys/h8300hms/Makeile.in: include new file 
>read.c in lib.a
>> 
>> ===================================================================
>> *** include/opcode/h8300.h	Fri May 17 14:46:05 2002
>> --- include/opcode/h8300.h.new	Fri May 17 11:48:48 2002
>> ***************
>> *** 296,300 ****
>>   #define O_ILL 76
>>   #define O_ADDS 77
>> ! #define O_SYSCALL 78
>>   #define O_MOV_TO_REG 79
>>   #define O_TAS 80
>> --- 296,300 ----
>>   #define O_ILL 76
>>   #define O_ADDS 77
>> ! #define O_SYSCALL_WRITE 78
>>   #define O_MOV_TO_REG 79
>>   #define O_TAS 80
>> ***************
>> *** 305,309 ****
>>   #define O_STM 86
>>   #define O_STMAC 87
>> ! #define O_LAST 88
>>   #define SB 0
>>   #define SW 1
>> --- 305,310 ----
>>   #define O_STM 86
>>   #define O_STMAC 87
>> ! #define O_SYSCALL 88
>> ! #define O_LAST 89
>>   #define SB 0
>>   #define SW 1
>> ===================================================================
>> *** sim/h8300/compile.c	Fri May 17 14:45:22 2002
>> --- sim/h8300/compile.c.new	Fri May 17 11:46:55 2002
>> ***************
>> *** 35,38 ****
>> --- 35,39 ----
>>   #include "callback.h"
>>   #include "remote-sim.h"
>> + #include "syscall.h"
>>   
>>   #ifndef SIGTRAP
>> ***************
>> *** 433,437 ****
>>   		  dst->cycles = q->time;
>>   
>> ! 		  /* And a jsr to 0xc4 is turned into a magic trap.  */
>>   
>>   		  if (dst->opcode == O (O_JSR, SB))
>> --- 434,438 ----
>>   		  dst->cycles = q->time;
>>   
>> ! 		  /* And a jsr to 0xc4 and 0xc8 is turned into 
>a magic trap.  */
>>   
>>   		  if (dst->opcode == O (O_JSR, SB))
>> ***************
>> *** 439,442 ****
>> --- 440,448 ----
>>   		      if (dst->src.literal == 0xc4)
>>   			{
>> + 			  dst->opcode = O (O_SYSCALL_WRITE, SB);
>> + 			}
>> + 		      else
>> + 		      if (dst->src.literal == 0xc8)
>> + 			{
>>   			  dst->opcode = O (O_SYSCALL, SB);
>>   			}
>> ***************
>> *** 1265,1272 ****
>>   	  goto next;
>>   
>> ! 	case O (O_SYSCALL, SB):
>>   	  {
>>   	    char c = cpu.regs[2];
>>   	    sim_callback->write_stdout (sim_callback, &c, 1);
>>   	  }
>>   	  goto next;
>> --- 1271,1301 ----
>>   	  goto next;
>>   
>> ! 	case O (O_SYSCALL_WRITE, SB):
>>   	  {
>>   	    char c = cpu.regs[2];
>>   	    sim_callback->write_stdout (sim_callback, &c, 1);
>> + 	  }
>> + 	  goto next;
>> + 
>> + 	/* This is generic syscall handler. The syscall # is 
>passed in r0l */
>> + 	case O (O_SYSCALL, SB):
>> + 	  {
>> + 	    unsigned char syscall_number = cpu.regs[0] ;
>> + 	    switch (syscall_number)
>> + 	    {
>> + 		case SYS_read:
>> + 		    if (h8300hmode || h8300smode)
>> + 		    {
>> + 			cpu.regs[0] = sim_callback->read 
>(sim_callback, cpu.regs[1], (char *) (cpu.regs[2] + 
>cpu.memory) , cpu.regs[3]);
>> + 		    }
>> + 		    else
>> + 		    {
>> + 			cpu.regs[0] = sim_callback->read 
>(sim_callback, cpu.regs[1], (char *) ((unsigned 
>short)cpu.regs[2] + cpu.memory) , cpu.regs[3]);
>> + 		    }
>> + 		    break ;
>> + 
>> + 		default:
>> + 		    break ;
>> + 	    }
>>   	  }
>>   	  goto next;
>> ===================================================================
>> *** sim/h8300/syscall.h	Fri May 17 14:44:54 2002
>> --- sim/h8300/syscall.h.new	Fri May 17 11:31:18 2002
>> ***************
>> *** 0 ****
>> --- 1,3 ----
>> + /* This is copied from newlib */
>> + 
>> + #define	SYS_read	1
>> ===================================================================
>> *** newlib/libc/sys/h8300hms/syscalls.c	Fri May 17 14:53:56 2002
>> --- newlib/libc/sys/h8300hms/syscalls.c.new	Thu May 16 10:05:42 2002
>> ***************
>> *** 6,17 ****
>>   #include <errno.h>
>>   
>> - int _DEFUN(_read,(file, ptr, len),
>> - 	   int file _AND
>> - 	   char *ptr _AND
>> - 	   int len)
>> - {
>> -   return 0;
>> - }
>> - 
>>   
>>   int _DEFUN(_lseek,(file, ptr, dir),
>> --- 6,9 ----
>> ===================================================================
>> *** newlib/libc/sys/h8300hms/read.c	Fri May 17 14:32:40 2002
>> --- newlib/libc/sys/h8300hms/read.c.new	Fri May 17 14:32:00 2002
>> ***************
>> *** 0 ****
>> --- 1,27 ----
>> + #include "sys/syscall.h"
>> + 
>> + int _read(file, ptr, len)
>> +      int file;
>> +      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;
>> + }
>> + 
>> + 
>> ===================================================================
>> *** newlib/libc/sys/h8300hms/sys/syscall.h	Fri May 17 14:32:29 2002
>> --- newlib/libc/sys/h8300hms/sys/syscall.h.new	Fri May 
>17 11:16:44 2002
>> ***************
>> *** 0 ****
>> --- 1,2 ----
>> + 
>> + #define	SYS_read	1
>> ===================================================================
>> *** newlib/libc/sys/h8300hms/Makefile.in	Fri May 17 14:54:06 2002
>> --- newlib/libc/sys/h8300hms/Makefile.in.new	Tue May 14 10:54:46 2002
>> ***************
>> *** 85,89 ****
>>   noinst_LIBRARIES = lib.a
>>   
>> ! lib_a_SOURCES = syscalls.c write.c _exit.c sbrk.c misc.c crt1.c
>>   
>>   ACLOCAL_AMFLAGS = -I ../../..
>> --- 85,89 ----
>>   noinst_LIBRARIES = lib.a
>>   
>> ! lib_a_SOURCES = syscalls.c write.c read.c _exit.c sbrk.c 
>misc.c crt1.c
>>   
>>   ACLOCAL_AMFLAGS = -I ../../..
>> ***************
>> *** 99,103 ****
>>   LIBS = @LIBS@
>>   lib_a_LIBADD = 
>> ! lib_a_OBJECTS =  syscalls.o write.o _exit.o sbrk.o misc.o crt1.o
>>   CFLAGS = @CFLAGS@
>>   COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) 
>$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
>> --- 99,103 ----
>>   LIBS = @LIBS@
>>   lib_a_LIBADD = 
>> ! lib_a_OBJECTS =  syscalls.o write.o read.o _exit.o sbrk.o 
>misc.o crt1.o
>>   CFLAGS = @CFLAGS@
>>   COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) 
>$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
>> ===================================================================
>> 
>> Regards,
>> Dhananjay
>> 
>> > Hi,
>> > 
>> > >Syscalls are usually handled a little differently.  Have 
>you considered
>> > >keeping the O_SYSCALL macro as is, and passing the 
>syscall number to the
>> > >simulator in a designated register or memory location?  
>Then in the
>> > >simulator in compile.c, replace the 
>sim_callback->write_stdout call with
>> > >a switch statement that calls the appropriate 
>sim_callback based on the
>> > >contents of the "syscall" register.
>> > 
>> > I had implemented it in the same way earlier but passing 
>syscall number as parameter makes simulator incompatible with 
>previous builds of toolchain. This is because the current 
>implementation of _write syscall is not passing syscall number 
>as parameter. Any suggestion about this? 
>> > 
>> 
>> >This change would only make previous versions of newlib 
>(and binaries
>> >linked with them) incompatible with the new simulator.  So 
>people with
>> >old binaries can either use an older simulator, or 
>recompile newlib and
>> >relink their programs.  Either way, IMO it's not too much to ask in
>> >return for new syscalls.
>> 
>> >Alternatively, you could keep your O_SYSCALL_WRITE, and change your
>> >O_SYSCALL_READ to O_SYSCALL_GENERIC.  Then all new syscalls 
>would use
>> >the generic method, and old binaries would keep working.
>> 
>> >Tom
>> 
>> >-- 
>> >Thomas Fitzsimmons
>> >Red Hat Canada Limited        e-mail: fitzsim@redhat.com
>> >2323 Yonge Street, Suite 300
>> >Toronto, ON M4P2C9


^ permalink raw reply	[flat|nested] 6+ messages in thread
* RE: [PATCH] Add support for scanf, gets in h8300 simulator
@ 2002-05-18  1:36 Andrew Volkov
  0 siblings, 0 replies; 6+ messages in thread
From: Andrew Volkov @ 2002-05-18  1:36 UTC (permalink / raw)
  To: newlib, gdb-patches

Hi,

Maybe now is time to change ugly "magic" 0xc4 vector to something more
correct 
(ex. trap  for h8s)? Because on many h8h/h8s chips, vectors 0xc4 and 0xc8
are busy under peripheries.

Andrey Volkov



>-----Original Message-----
>From: Thomas Fitzsimmons [mailto:fitzsim@redhat.com]
>Sent: Friday, May 17, 2002 11:55 PM
>To: Dhananjay R. Deshpande
>Cc: newlib@sources.redhat.com; gdb-patches@sources.redhat.com
>Subject: RE: [PATCH] Add support for scanf, gets in h8300 simulator
>
>
>On Fri, 2002-05-17 at 08:47, Dhananjay R. Deshpande wrote:
>> Hi,
>> 
>> Resubmitting the patch as per suggestion from Thomas Fitzsimmons.	
>> 
>
>I'm going to change SYS_read to match the value found in
>libgloss/syscall.h (4), before committing this.
>
>Tom
>
>> For Simulator -
>> 2002-05-14 Dhananjay Deshpande <dhananjayd@kpit.com>
>> 	* include/opcode/h8300.h: Changed SYSCALL to 
>SYSCALL_WRITE and added generic 		  SYSCALL for 
>handling new syscalls.
>> 	* sim/h8300/compile.c: New generic SYSCALL magic trap 
>JSR @@0xC8 
>> 	* sim/h8300/syscall.h: #Define syscall number
>> 
>> For Newlib - 
>> 2002-05-14 Dhananjay Deshpande <dhananjayd@kpit.com>
>> 	* newlib/libc/sys/h8300hms/syscalls.c: Moved _read() to read.c
>> 	* newlib/libc/sys/h8300hms/read.c: New file. Magic trap 
>0xC8 for Simulator
>> 	* newlib/libs/sys/h8300hms/sys/syscall.h: #Define syscall number
>> 	* newlib/libc/sys/h8300hms/Makeile.in: include new file 
>read.c in lib.a
>> 
>> ===================================================================
>> *** include/opcode/h8300.h	Fri May 17 14:46:05 2002
>> --- include/opcode/h8300.h.new	Fri May 17 11:48:48 2002
>> ***************
>> *** 296,300 ****
>>   #define O_ILL 76
>>   #define O_ADDS 77
>> ! #define O_SYSCALL 78
>>   #define O_MOV_TO_REG 79
>>   #define O_TAS 80
>> --- 296,300 ----
>>   #define O_ILL 76
>>   #define O_ADDS 77
>> ! #define O_SYSCALL_WRITE 78
>>   #define O_MOV_TO_REG 79
>>   #define O_TAS 80
>> ***************
>> *** 305,309 ****
>>   #define O_STM 86
>>   #define O_STMAC 87
>> ! #define O_LAST 88
>>   #define SB 0
>>   #define SW 1
>> --- 305,310 ----
>>   #define O_STM 86
>>   #define O_STMAC 87
>> ! #define O_SYSCALL 88
>> ! #define O_LAST 89
>>   #define SB 0
>>   #define SW 1
>> ===================================================================
>> *** sim/h8300/compile.c	Fri May 17 14:45:22 2002
>> --- sim/h8300/compile.c.new	Fri May 17 11:46:55 2002
>> ***************
>> *** 35,38 ****
>> --- 35,39 ----
>>   #include "callback.h"
>>   #include "remote-sim.h"
>> + #include "syscall.h"
>>   
>>   #ifndef SIGTRAP
>> ***************
>> *** 433,437 ****
>>   		  dst->cycles = q->time;
>>   
>> ! 		  /* And a jsr to 0xc4 is turned into a magic trap.  */
>>   
>>   		  if (dst->opcode == O (O_JSR, SB))
>> --- 434,438 ----
>>   		  dst->cycles = q->time;
>>   
>> ! 		  /* And a jsr to 0xc4 and 0xc8 is turned into 
>a magic trap.  */
>>   
>>   		  if (dst->opcode == O (O_JSR, SB))
>> ***************
>> *** 439,442 ****
>> --- 440,448 ----
>>   		      if (dst->src.literal == 0xc4)
>>   			{
>> + 			  dst->opcode = O (O_SYSCALL_WRITE, SB);
>> + 			}
>> + 		      else
>> + 		      if (dst->src.literal == 0xc8)
>> + 			{
>>   			  dst->opcode = O (O_SYSCALL, SB);
>>   			}
>> ***************
>> *** 1265,1272 ****
>>   	  goto next;
>>   
>> ! 	case O (O_SYSCALL, SB):
>>   	  {
>>   	    char c = cpu.regs[2];
>>   	    sim_callback->write_stdout (sim_callback, &c, 1);
>>   	  }
>>   	  goto next;
>> --- 1271,1301 ----
>>   	  goto next;
>>   
>> ! 	case O (O_SYSCALL_WRITE, SB):
>>   	  {
>>   	    char c = cpu.regs[2];
>>   	    sim_callback->write_stdout (sim_callback, &c, 1);
>> + 	  }
>> + 	  goto next;
>> + 
>> + 	/* This is generic syscall handler. The syscall # is 
>passed in r0l */
>> + 	case O (O_SYSCALL, SB):
>> + 	  {
>> + 	    unsigned char syscall_number = cpu.regs[0] ;
>> + 	    switch (syscall_number)
>> + 	    {
>> + 		case SYS_read:
>> + 		    if (h8300hmode || h8300smode)
>> + 		    {
>> + 			cpu.regs[0] = sim_callback->read 
>(sim_callback, cpu.regs[1], (char *) (cpu.regs[2] + 
>cpu.memory) , cpu.regs[3]);
>> + 		    }
>> + 		    else
>> + 		    {
>> + 			cpu.regs[0] = sim_callback->read 
>(sim_callback, cpu.regs[1], (char *) ((unsigned 
>short)cpu.regs[2] + cpu.memory) , cpu.regs[3]);
>> + 		    }
>> + 		    break ;
>> + 
>> + 		default:
>> + 		    break ;
>> + 	    }
>>   	  }
>>   	  goto next;
>> ===================================================================
>> *** sim/h8300/syscall.h	Fri May 17 14:44:54 2002
>> --- sim/h8300/syscall.h.new	Fri May 17 11:31:18 2002
>> ***************
>> *** 0 ****
>> --- 1,3 ----
>> + /* This is copied from newlib */
>> + 
>> + #define	SYS_read	1
>> ===================================================================
>> *** newlib/libc/sys/h8300hms/syscalls.c	Fri May 17 14:53:56 2002
>> --- newlib/libc/sys/h8300hms/syscalls.c.new	Thu May 16 10:05:42 2002
>> ***************
>> *** 6,17 ****
>>   #include <errno.h>
>>   
>> - int _DEFUN(_read,(file, ptr, len),
>> - 	   int file _AND
>> - 	   char *ptr _AND
>> - 	   int len)
>> - {
>> -   return 0;
>> - }
>> - 
>>   
>>   int _DEFUN(_lseek,(file, ptr, dir),
>> --- 6,9 ----
>> ===================================================================
>> *** newlib/libc/sys/h8300hms/read.c	Fri May 17 14:32:40 2002
>> --- newlib/libc/sys/h8300hms/read.c.new	Fri May 17 14:32:00 2002
>> ***************
>> *** 0 ****
>> --- 1,27 ----
>> + #include "sys/syscall.h"
>> + 
>> + int _read(file, ptr, len)
>> +      int file;
>> +      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;
>> + }
>> + 
>> + 
>> ===================================================================
>> *** newlib/libc/sys/h8300hms/sys/syscall.h	Fri May 17 14:32:29 2002
>> --- newlib/libc/sys/h8300hms/sys/syscall.h.new	Fri May 
>17 11:16:44 2002
>> ***************
>> *** 0 ****
>> --- 1,2 ----
>> + 
>> + #define	SYS_read	1
>> ===================================================================
>> *** newlib/libc/sys/h8300hms/Makefile.in	Fri May 17 14:54:06 2002
>> --- newlib/libc/sys/h8300hms/Makefile.in.new	Tue May 14 10:54:46 2002
>> ***************
>> *** 85,89 ****
>>   noinst_LIBRARIES = lib.a
>>   
>> ! lib_a_SOURCES = syscalls.c write.c _exit.c sbrk.c misc.c crt1.c
>>   
>>   ACLOCAL_AMFLAGS = -I ../../..
>> --- 85,89 ----
>>   noinst_LIBRARIES = lib.a
>>   
>> ! lib_a_SOURCES = syscalls.c write.c read.c _exit.c sbrk.c 
>misc.c crt1.c
>>   
>>   ACLOCAL_AMFLAGS = -I ../../..
>> ***************
>> *** 99,103 ****
>>   LIBS = @LIBS@
>>   lib_a_LIBADD = 
>> ! lib_a_OBJECTS =  syscalls.o write.o _exit.o sbrk.o misc.o crt1.o
>>   CFLAGS = @CFLAGS@
>>   COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) 
>$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
>> --- 99,103 ----
>>   LIBS = @LIBS@
>>   lib_a_LIBADD = 
>> ! lib_a_OBJECTS =  syscalls.o write.o read.o _exit.o sbrk.o 
>misc.o crt1.o
>>   CFLAGS = @CFLAGS@
>>   COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) 
>$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
>> ===================================================================
>> 
>> Regards,
>> Dhananjay
>> 
>> > Hi,
>> > 
>> > >Syscalls are usually handled a little differently.  Have 
>you considered
>> > >keeping the O_SYSCALL macro as is, and passing the 
>syscall number to the
>> > >simulator in a designated register or memory location?  
>Then in the
>> > >simulator in compile.c, replace the 
>sim_callback->write_stdout call with
>> > >a switch statement that calls the appropriate 
>sim_callback based on the
>> > >contents of the "syscall" register.
>> > 
>> > I had implemented it in the same way earlier but passing 
>syscall number as parameter makes simulator incompatible with 
>previous builds of toolchain. This is because the current 
>implementation of _write syscall is not passing syscall number 
>as parameter. Any suggestion about this? 
>> > 
>> 
>> >This change would only make previous versions of newlib 
>(and binaries
>> >linked with them) incompatible with the new simulator.  So 
>people with
>> >old binaries can either use an older simulator, or 
>recompile newlib and
>> >relink their programs.  Either way, IMO it's not too much to ask in
>> >return for new syscalls.
>> 
>> >Alternatively, you could keep your O_SYSCALL_WRITE, and change your
>> >O_SYSCALL_READ to O_SYSCALL_GENERIC.  Then all new syscalls 
>would use
>> >the generic method, and old binaries would keep working.
>> 
>> >Tom
>> 
>> >-- 
>> >Thomas Fitzsimmons
>> >Red Hat Canada Limited        e-mail: fitzsim@redhat.com
>> >2323 Yonge Street, Suite 300
>> >Toronto, ON M4P2C9
>-- 
>Thomas Fitzsimmons
>Red Hat Canada Limited        e-mail: fitzsim@redhat.com
>2323 Yonge Street, Suite 300
>Toronto, ON M4P2C9
>


^ permalink raw reply	[flat|nested] 6+ messages in thread
* RE: [PATCH] Add support for scanf, gets in h8300 simulator
@ 2002-05-17  5:47 Dhananjay R. Deshpande
  2002-05-17 12:55 ` Thomas Fitzsimmons
  0 siblings, 1 reply; 6+ messages in thread
From: Dhananjay R. Deshpande @ 2002-05-17  5:47 UTC (permalink / raw)
  To: newlib, gdb-patches; +Cc: Thomas Fitzsimmons

Hi,

Resubmitting the patch as per suggestion from Thomas Fitzsimmons.	

For Simulator -
2002-05-14 Dhananjay Deshpande <dhananjayd@kpit.com>
	* include/opcode/h8300.h: Changed SYSCALL to SYSCALL_WRITE and added generic 		  SYSCALL for handling new syscalls.
	* sim/h8300/compile.c: New generic SYSCALL magic trap JSR @@0xC8 
	* sim/h8300/syscall.h: #Define syscall number

For Newlib - 
2002-05-14 Dhananjay Deshpande <dhananjayd@kpit.com>
	* newlib/libc/sys/h8300hms/syscalls.c: Moved _read() to read.c
	* newlib/libc/sys/h8300hms/read.c: New file. Magic trap 0xC8 for Simulator
	* newlib/libs/sys/h8300hms/sys/syscall.h: #Define syscall number
	* newlib/libc/sys/h8300hms/Makeile.in: include new file read.c in lib.a

===================================================================
*** include/opcode/h8300.h	Fri May 17 14:46:05 2002
--- include/opcode/h8300.h.new	Fri May 17 11:48:48 2002
***************
*** 296,300 ****
  #define O_ILL 76
  #define O_ADDS 77
! #define O_SYSCALL 78
  #define O_MOV_TO_REG 79
  #define O_TAS 80
--- 296,300 ----
  #define O_ILL 76
  #define O_ADDS 77
! #define O_SYSCALL_WRITE 78
  #define O_MOV_TO_REG 79
  #define O_TAS 80
***************
*** 305,309 ****
  #define O_STM 86
  #define O_STMAC 87
! #define O_LAST 88
  #define SB 0
  #define SW 1
--- 305,310 ----
  #define O_STM 86
  #define O_STMAC 87
! #define O_SYSCALL 88
! #define O_LAST 89
  #define SB 0
  #define SW 1
===================================================================
*** sim/h8300/compile.c	Fri May 17 14:45:22 2002
--- sim/h8300/compile.c.new	Fri May 17 11:46:55 2002
***************
*** 35,38 ****
--- 35,39 ----
  #include "callback.h"
  #include "remote-sim.h"
+ #include "syscall.h"
  
  #ifndef SIGTRAP
***************
*** 433,437 ****
  		  dst->cycles = q->time;
  
! 		  /* And a jsr to 0xc4 is turned into a magic trap.  */
  
  		  if (dst->opcode == O (O_JSR, SB))
--- 434,438 ----
  		  dst->cycles = q->time;
  
! 		  /* And a jsr to 0xc4 and 0xc8 is turned into a magic trap.  */
  
  		  if (dst->opcode == O (O_JSR, SB))
***************
*** 439,442 ****
--- 440,448 ----
  		      if (dst->src.literal == 0xc4)
  			{
+ 			  dst->opcode = O (O_SYSCALL_WRITE, SB);
+ 			}
+ 		      else
+ 		      if (dst->src.literal == 0xc8)
+ 			{
  			  dst->opcode = O (O_SYSCALL, SB);
  			}
***************
*** 1265,1272 ****
  	  goto next;
  
! 	case O (O_SYSCALL, SB):
  	  {
  	    char c = cpu.regs[2];
  	    sim_callback->write_stdout (sim_callback, &c, 1);
  	  }
  	  goto next;
--- 1271,1301 ----
  	  goto next;
  
! 	case O (O_SYSCALL_WRITE, SB):
  	  {
  	    char c = cpu.regs[2];
  	    sim_callback->write_stdout (sim_callback, &c, 1);
+ 	  }
+ 	  goto next;
+ 
+ 	/* This is generic syscall handler. The syscall # is passed in r0l */
+ 	case O (O_SYSCALL, SB):
+ 	  {
+ 	    unsigned char syscall_number = cpu.regs[0] ;
+ 	    switch (syscall_number)
+ 	    {
+ 		case SYS_read:
+ 		    if (h8300hmode || h8300smode)
+ 		    {
+ 			cpu.regs[0] = sim_callback->read (sim_callback, cpu.regs[1], (char *) (cpu.regs[2] + cpu.memory) , cpu.regs[3]);
+ 		    }
+ 		    else
+ 		    {
+ 			cpu.regs[0] = sim_callback->read (sim_callback, cpu.regs[1], (char *) ((unsigned short)cpu.regs[2] + cpu.memory) , cpu.regs[3]);
+ 		    }
+ 		    break ;
+ 
+ 		default:
+ 		    break ;
+ 	    }
  	  }
  	  goto next;
===================================================================
*** sim/h8300/syscall.h	Fri May 17 14:44:54 2002
--- sim/h8300/syscall.h.new	Fri May 17 11:31:18 2002
***************
*** 0 ****
--- 1,3 ----
+ /* This is copied from newlib */
+ 
+ #define	SYS_read	1
===================================================================
*** newlib/libc/sys/h8300hms/syscalls.c	Fri May 17 14:53:56 2002
--- newlib/libc/sys/h8300hms/syscalls.c.new	Thu May 16 10:05:42 2002
***************
*** 6,17 ****
  #include <errno.h>
  
- int _DEFUN(_read,(file, ptr, len),
- 	   int file _AND
- 	   char *ptr _AND
- 	   int len)
- {
-   return 0;
- }
- 
  
  int _DEFUN(_lseek,(file, ptr, dir),
--- 6,9 ----
===================================================================
*** newlib/libc/sys/h8300hms/read.c	Fri May 17 14:32:40 2002
--- newlib/libc/sys/h8300hms/read.c.new	Fri May 17 14:32:00 2002
***************
*** 0 ****
--- 1,27 ----
+ #include "sys/syscall.h"
+ 
+ int _read(file, ptr, len)
+      int file;
+      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;
+ }
+ 
+ 
===================================================================
*** newlib/libc/sys/h8300hms/sys/syscall.h	Fri May 17 14:32:29 2002
--- newlib/libc/sys/h8300hms/sys/syscall.h.new	Fri May 17 11:16:44 2002
***************
*** 0 ****
--- 1,2 ----
+ 
+ #define	SYS_read	1
===================================================================
*** newlib/libc/sys/h8300hms/Makefile.in	Fri May 17 14:54:06 2002
--- newlib/libc/sys/h8300hms/Makefile.in.new	Tue May 14 10:54:46 2002
***************
*** 85,89 ****
  noinst_LIBRARIES = lib.a
  
! lib_a_SOURCES = syscalls.c write.c _exit.c sbrk.c misc.c crt1.c
  
  ACLOCAL_AMFLAGS = -I ../../..
--- 85,89 ----
  noinst_LIBRARIES = lib.a
  
! lib_a_SOURCES = syscalls.c write.c read.c _exit.c sbrk.c misc.c crt1.c
  
  ACLOCAL_AMFLAGS = -I ../../..
***************
*** 99,103 ****
  LIBS = @LIBS@
  lib_a_LIBADD = 
! lib_a_OBJECTS =  syscalls.o write.o _exit.o sbrk.o misc.o crt1.o
  CFLAGS = @CFLAGS@
  COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
--- 99,103 ----
  LIBS = @LIBS@
  lib_a_LIBADD = 
! lib_a_OBJECTS =  syscalls.o write.o read.o _exit.o sbrk.o misc.o crt1.o
  CFLAGS = @CFLAGS@
  COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
===================================================================

Regards,
Dhananjay

> Hi,
> 
> >Syscalls are usually handled a little differently.  Have you considered
> >keeping the O_SYSCALL macro as is, and passing the syscall number to the
> >simulator in a designated register or memory location?  Then in the
> >simulator in compile.c, replace the sim_callback->write_stdout call with
> >a switch statement that calls the appropriate sim_callback based on the
> >contents of the "syscall" register.
> 
> I had implemented it in the same way earlier but passing syscall number as parameter makes simulator incompatible with previous builds of toolchain. This is because the current implementation of _write syscall is not passing syscall number as parameter. Any suggestion about this? 
> 

>This change would only make previous versions of newlib (and binaries
>linked with them) incompatible with the new simulator.  So people with
>old binaries can either use an older simulator, or recompile newlib and
>relink their programs.  Either way, IMO it's not too much to ask in
>return for new syscalls.

>Alternatively, you could keep your O_SYSCALL_WRITE, and change your
>O_SYSCALL_READ to O_SYSCALL_GENERIC.  Then all new syscalls would use
>the generic method, and old binaries would keep working.

>Tom

>-- 
>Thomas Fitzsimmons
>Red Hat Canada Limited        e-mail: fitzsim@redhat.com
>2323 Yonge Street, Suite 300
>Toronto, ON M4P2C9


^ permalink raw reply	[flat|nested] 6+ messages in thread
* [PATCH] Add support for scanf, gets in h8300 simulator
@ 2002-05-14  1:52 Dhananjay R. Deshpande
  0 siblings, 0 replies; 6+ messages in thread
From: Dhananjay R. Deshpande @ 2002-05-14  1:52 UTC (permalink / raw)
  To: newlib, gdb-patches

Hi,

This patch to gdb and newlib adds support for reading from STDIN in h8300 simulator. Currently functions like scanf and gets are not working with h8300 simulator, this patch shall provide that functionality.

For Simulator -
2002-05-14 Dhananjay Deshpande <dhananjayd@kpit.com>
	* include/opcode/h8300.h: Add #define for SYSCALL_READ
	* sim/h8300/compile.c: Convert magic trap 0xC8 into SYSCALL_READ

For Newlib - 
2002-05-14 Dhananjay Deshpande <dhananjayd@kpit.com>
	* newlib/libc/sys/h8300hms/syscalls.c: Moved _read() to read.c
	* newlib/libc/sys/h8300hms/read.c: New file. Magic trap 0xC8 for Simulator
	* newlib/libc/sys/h8300hms/Makeile.in: include new file read.c in lib.a

===================================================================
*** include/opcode/h8300.h	Tue May 14 11:25:29 2002
--- include/opcode/h8300.h.new	Tue May 14 11:25:19 2002
***************
*** 296,300 ****
  #define O_ILL 76
  #define O_ADDS 77
! #define O_SYSCALL 78
  #define O_MOV_TO_REG 79
  #define O_TAS 80
--- 296,300 ----
  #define O_ILL 76
  #define O_ADDS 77
! #define O_SYSCALL_WRITE 78
  #define O_MOV_TO_REG 79
  #define O_TAS 80
***************
*** 305,309 ****
  #define O_STM 86
  #define O_STMAC 87
! #define O_LAST 88
  #define SB 0
  #define SW 1
--- 305,310 ----
  #define O_STM 86
  #define O_STMAC 87
! #define O_SYSCALL_READ 88
! #define O_LAST 89
  #define SB 0
  #define SW 1

===================================================================
*** sim/h8300/compile.c	Tue May 14 11:19:24 2002
--- sim/h8300/compile.c.new	Tue May 14 11:19:19 2002
***************
*** 433,437 ****
  		  dst->cycles = q->time;
  
! 		  /* And a jsr to 0xc4 is turned into a magic trap.  */
  
  		  if (dst->opcode == O (O_JSR, SB))
--- 433,437 ----
  		  dst->cycles = q->time;
  
! 		  /* And a jsr to 0xc4 and 0xc8 is turned into a magic trap.  */
  
  		  if (dst->opcode == O (O_JSR, SB))
***************
*** 439,443 ****
  		      if (dst->src.literal == 0xc4)
  			{
! 			  dst->opcode = O (O_SYSCALL, SB);
  			}
  		    }
--- 439,448 ----
  		      if (dst->src.literal == 0xc4)
  			{
! 			  dst->opcode = O (O_SYSCALL_WRITE, SB);
! 			}
! 		      else
! 		      if (dst->src.literal == 0xc8)
! 			{
! 			  dst->opcode = O (O_SYSCALL_READ, SB);
  			}
  		    }
***************
*** 1267,1274 ****
  	  goto next;
  
! 	case O (O_SYSCALL, SB):
  	  {
  	    char c = cpu.regs[2];
  	    sim_callback->write_stdout (sim_callback, &c, 1);
  	  }
  	  goto next;
--- 1272,1292 ----
  	  goto next;
  
! 	case O (O_SYSCALL_WRITE, SB):
  	  {
  	    char c = cpu.regs[2];
  	    sim_callback->write_stdout (sim_callback, &c, 1);
+ 	  }
+ 	  goto next;
+ 
+ 	case O (O_SYSCALL_READ, SB):
+ 	  {
+ 	    if (h8300hmode)
+ 	    {
+ 	    	cpu.regs[0] = sim_callback->read (sim_callback, cpu.regs[1], (char *) (cpu.regs[2] + cpu.memory) , cpu.regs[3]);
+ 	    }
+ 	    else
+ 	    {
+ 	    	cpu.regs[0] = sim_callback->read (sim_callback, cpu.regs[1], (char *) ((unsigned short)cpu.regs[2] + cpu.memory) , cpu.regs[3]);
+ 	    }
  	  }
  	  goto next;

===================================================================
*** newlib/libc/sys/h8300hms/syscalls.c	Fri May 10 12:20:53 2002
--- newlib/libc/sys/h8300hms/syscalls.c.new	Tue May 14 10:49:33 2002
***************
*** 4,16 ****
  #include <sys/types.h>
  #include <sys/stat.h>
- #include <errno.h>
- 
- int _DEFUN(_read,(file, ptr, len),
- 	   int file _AND
- 	   char *ptr _AND
- 	   int len)
- {
-   return 0;
- }
  
  
--- 4,7 ----

===================================================================
*** newlib/libc/sys/h8300hms/read.c	Tue May 14 10:50:53 2002
--- newlib/libc/sys/h8300hms/read.c.new	Tue May 14 10:52:34 2002
***************
*** 0 ****
--- 1,25 ----
+ 
+ int _read(file, ptr, len)
+      int file;
+      char *ptr;
+      int len;
+ {
+ 	register int ret asm("r0") ;
+ 
+ 	// Type cast int as short so that we can copy 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.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;
+ }
+ 
+ 

===================================================================
*** newlib/libc/sys/h8300hms/Makefile.in	Fri May 10 12:20:53 2002
--- newlib/libc/sys/h8300hms/Makefile.in.new	Tue May 14 10:54:46 2002
***************
*** 85,89 ****
  noinst_LIBRARIES = lib.a
  
! lib_a_SOURCES = syscalls.c write.c _exit.c sbrk.c misc.c crt1.c
  
  ACLOCAL_AMFLAGS = -I ../../..
--- 85,89 ----
  noinst_LIBRARIES = lib.a
  
! lib_a_SOURCES = syscalls.c write.c read.c _exit.c sbrk.c misc.c crt1.c
  
  ACLOCAL_AMFLAGS = -I ../../..
***************
*** 99,103 ****
  LIBS = @LIBS@
  lib_a_LIBADD = 
! lib_a_OBJECTS =  syscalls.o write.o _exit.o sbrk.o misc.o crt1.o
  CFLAGS = @CFLAGS@
  COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
--- 99,103 ----
  LIBS = @LIBS@
  lib_a_LIBADD = 
! lib_a_OBJECTS =  syscalls.o write.o read.o _exit.o sbrk.o misc.o crt1.o
  CFLAGS = @CFLAGS@
  COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
===================================================================

Regards,
Dhananjay
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Free download of GNUSH and GNUH8 tool chains for Hitachi's SH and H8 Series.
The following site also offers free support to European customers.
Read more at http://www.kpit.com/products/support.htm
Latest versions of GNUSH and GNUH8 are released on Apr 1, 2002.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 


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

end of thread, other threads:[~2002-06-03 10:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-06-03  3:07 [PATCH] Add support for scanf, gets in h8300 simulator Andrew Volkov
  -- strict thread matches above, loose matches on Subject: below --
2002-05-24  3:07 Dhananjay R. Deshpande
2002-05-18  1:36 Andrew Volkov
2002-05-17  5:47 Dhananjay R. Deshpande
2002-05-17 12:55 ` Thomas Fitzsimmons
2002-05-14  1:52 Dhananjay R. Deshpande

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