From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26137 invoked by alias); 17 May 2002 12:47:07 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 26060 invoked from network); 17 May 2002 12:46:57 -0000 Received: from unknown (HELO sohm.kpit.com) (203.129.230.82) by sources.redhat.com with SMTP; 17 May 2002 12:46:57 -0000 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Subject: RE: [PATCH] Add support for scanf, gets in h8300 simulator content-class: urn:content-classes:message X-MimeOLE: Produced By Microsoft Exchange V6.0.5762.3 Date: Fri, 17 May 2002 05:47:00 -0000 Message-ID: <69595093233BB547BB70CF5E492B63F22F3246@sohm.kpit.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: From: "Dhananjay R. Deshpande" To: , Cc: "Thomas Fitzsimmons" X-SW-Source: 2002-05/txt/msg00707.txt.bz2 Hi, Resubmitting the patch as per suggestion from Thomas Fitzsimmons.=09 For Simulator - 2002-05-14 Dhananjay Deshpande * include/opcode/h8300.h: Changed SYSCALL to SYSCALL_WRITE and added gener= ic SYSCALL for handling new syscalls. * sim/h8300/compile.c: New generic SYSCALL magic trap JSR @@0xC8=20 * sim/h8300/syscall.h: #Define syscall number For Newlib -=20 2002-05-14 Dhananjay Deshpande * 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 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D *** 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 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D *** 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" =20=20 #ifndef SIGTRAP *************** *** 433,437 **** dst->cycles =3D q->time; =20=20 ! /* And a jsr to 0xc4 is turned into a magic trap. */ =20=20 if (dst->opcode =3D=3D O (O_JSR, SB)) --- 434,438 ---- dst->cycles =3D q->time; =20=20 ! /* And a jsr to 0xc4 and 0xc8 is turned into a magic trap. */ =20=20 if (dst->opcode =3D=3D O (O_JSR, SB)) *************** *** 439,442 **** --- 440,448 ---- if (dst->src.literal =3D=3D 0xc4) { + dst->opcode =3D O (O_SYSCALL_WRITE, SB); + } + else + if (dst->src.literal =3D=3D 0xc8) + { dst->opcode =3D O (O_SYSCALL, SB); } *************** *** 1265,1272 **** goto next; =20=20 ! case O (O_SYSCALL, SB): { char c =3D cpu.regs[2]; sim_callback->write_stdout (sim_callback, &c, 1); } goto next; --- 1271,1301 ---- goto next; =20=20 ! case O (O_SYSCALL_WRITE, SB): { char c =3D cpu.regs[2]; sim_callback->write_stdout (sim_callback, &c, 1); + } + goto next; +=20 + /* This is generic syscall handler. The syscall # is passed in r0l */ + case O (O_SYSCALL, SB): + { + unsigned char syscall_number =3D cpu.regs[0] ; + switch (syscall_number) + { + case SYS_read: + if (h8300hmode || h8300smode) + { + cpu.regs[0] =3D sim_callback->read (sim_callback, cpu.regs[1], (char *= ) (cpu.regs[2] + cpu.memory) , cpu.regs[3]); + } + else + { + cpu.regs[0] =3D sim_callback->read (sim_callback, cpu.regs[1], (char *= ) ((unsigned short)cpu.regs[2] + cpu.memory) , cpu.regs[3]); + } + break ; +=20 + default: + break ; + } } goto next; =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D *** 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 */ +=20 + #define SYS_read 1 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D *** 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 =20=20 - int _DEFUN(_read,(file, ptr, len), - int file _AND - char *ptr _AND - int len) - { - return 0; - } -=20 =20=20 int _DEFUN(_lseek,(file, ptr, dir), --- 6,9 ---- =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D *** 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" +=20 + int _read(file, ptr, len) + int file; + char *ptr; + int len; + { + register int ret asm("r0") ; +=20 + /* Type cast int as short so that we can copy int values into 16 bit=20 + registers in case of -mint32 switch is given. + This is not going to affect data as file=3D 0 for stdin and len=3D102= 4 */ +=20 + 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; + } +=20 +=20 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D *** 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 ---- +=20 + #define SYS_read 1 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D *** 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 =3D lib.a =20=20 ! lib_a_SOURCES =3D syscalls.c write.c _exit.c sbrk.c misc.c crt1.c =20=20 ACLOCAL_AMFLAGS =3D -I ../../.. --- 85,89 ---- noinst_LIBRARIES =3D lib.a =20=20 ! lib_a_SOURCES =3D syscalls.c write.c read.c _exit.c sbrk.c misc.c crt1.c =20=20 ACLOCAL_AMFLAGS =3D -I ../../.. *************** *** 99,103 **** LIBS =3D @LIBS@ lib_a_LIBADD =3D=20 ! lib_a_OBJECTS =3D syscalls.o write.o _exit.o sbrk.o misc.o crt1.o CFLAGS =3D @CFLAGS@ COMPILE =3D $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFL= AGS) $(CFLAGS) --- 99,103 ---- LIBS =3D @LIBS@ lib_a_LIBADD =3D=20 ! lib_a_OBJECTS =3D syscalls.o write.o read.o _exit.o sbrk.o misc.o crt1.o CFLAGS =3D @CFLAGS@ COMPILE =3D $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFL= AGS) $(CFLAGS) =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Regards, Dhananjay > Hi, >=20 > >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. >=20 > I had implemented it in the same way earlier but passing syscall number a= s parameter makes simulator incompatible with previous builds of toolchain.= This is because the current implementation of _write syscall is not passin= g syscall number as parameter. Any suggestion about this?=20 >=20 >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 >--=20 >Thomas Fitzsimmons >Red Hat Canada Limited e-mail: fitzsim@redhat.com >2323 Yonge Street, Suite 300 >Toronto, ON M4P2C9