From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6753 invoked by alias); 30 Nov 2002 05:31:37 -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 6529 invoked from network); 30 Nov 2002 05:31:34 -0000 Received: from unknown (HELO ngate.noida.hcltech.com) (202.54.110.230) by sources.redhat.com with SMTP; 30 Nov 2002 05:31:34 -0000 Received: from exch-01.noida.hcltech.com (exch-01 [204.160.254.29]) by ngate.noida.hcltech.com (8.9.3/8.9.3) with ESMTP id KAA16725; Sat, 30 Nov 2002 10:57:27 +0530 Received: by exch-01.noida.hcltech.com with Internet Mail Service (5.5.2653.19) id ; Sat, 30 Nov 2002 10:56:49 +0530 Message-ID: From: "D.Venkatasubramanian, Noida" To: Kazu Hirata , gdb-patches@sources.redhat.com Cc: gdb@sources.redhat.com, binutils@sources.redhat.com Subject: RE: PATCH : H8300 Simulator File I/O Implementation Date: Fri, 29 Nov 2002 21:31:00 -0000 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----_=_NextPart_000_01C29831.14DF8E90" X-SW-Source: 2002-11/txt/msg00758.txt.bz2 This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_000_01C29831.14DF8E90 Content-Type: text/plain; charset="iso-8859-1" Content-length: 1279 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 *h8300.h: Added some more pseudo opcodes for system call processing. Thu Nov 28 15:02:51 IST 2002 D.Venkatasubramanian * /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. ------_=_NextPart_000_01C29831.14DF8E90 Content-Type: text/plain; name="ChangeLog.txt" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="ChangeLog.txt" Content-length: 956 Thu Nov 28 14:49:51 IST 2002 D.Venkatasubramanian (dvenkat@noida.hcltech.c= om) * 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.=20 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 *h8300.h: Added some more pseudo opcodes for system call processing. Thu Nov 28 15:02:51 IST 2002 D.Venkatasubramanian * /libc/sys/h8300hms/syscalls.c: Support for various File I/O related system calls. Jump to magic vector locations, instead=20 of dummy return values. * /libc/sys/h8300hms/read.c: Jump to magic vector location for=20 supporting read system call. * /libc/sys/h8300hms/write.c: Jump to magic vector location for supporting write system call. ------_=_NextPart_000_01C29831.14DF8E90 Content-Type: text/plain; name="patch.txt" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="patch.txt" Content-length: 15461 *** 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" =20=20 #ifndef SIGTRAP # define SIGTRAP 5 *************** decode (addr, data, dst) *** 448,461 **** dst->opcode =3D q->how; dst->cycles =3D q->time; =20=20 ! /* And a jsr to 0xc4 is turned into a magic trap. */ !=20 if (dst->opcode =3D=3D O (O_JSR, SB)) { ! if (dst->src.literal =3D=3D 0xc4) ! { ! dst->opcode =3D O (O_SYSCALL, SB); ! } } =20=20 dst->next_pc =3D addr + len / 2; --- 450,487 ---- dst->opcode =3D q->how; dst->cycles =3D q->time; =20=20 ! /* And a jsr to these locations are turned into magic traps. */ if (dst->opcode =3D=3D O (O_JSR, SB)) { ! if (dst->src.literal =3D=3D 0xc5) ! { ! dst->opcode =3D O (O_SYS_OPEN, SB); ! } ! else if (dst->src.literal =3D=3D 0xc6) ! { ! dst->opcode =3D O (O_SYS_READ, SB);=20=20=20=20=20 ! } ! else if (dst->src.literal =3D=3D 0xc7) ! { ! dst->opcode =3D O (O_SYS_WRITE, SB); ! } ! else if (dst->src.literal =3D=3D 0xc8) ! { ! dst->opcode =3D O (O_SYS_LSEEK, SB); ! } ! else if (dst->src.literal =3D=3D 0xc9) ! { ! dst->opcode =3D O (O_SYS_CLOSE, SB); ! } ! else if (dst->src.literal =3D=3D 0xca) ! { ! dst->opcode =3D O (O_SYS_STAT, SB); ! }=20=20 ! else if (dst->src.literal =3D=3D 0xcb) ! { ! dst->opcode =3D O (O_SYS_FSTAT, SB); ! } ! /* End of Processing for system calls */ } =20=20 dst->next_pc =3D addr + len / 2; *************** sim_resume (sd, step, siggnal) *** 1392,1403 **** goto condtrue; 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; =20=20 ONOT (O_NOT, rd =3D ~rd; v =3D 0;); OSHIFTS (O_SHLL, --- 1418,1679 ---- goto condtrue; goto next; =20=20 ! /* System call processing */ ! case O (O_SYS_OPEN, SB) : ! { ! int len =3D 0; /* Length of filename */ ! char *filename ; /* Filename would go here */ ! char temp_char; /* Temporary character */ ! int mode =3D 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 */ !=20 ! /* Setting filename_ptr to first argument of open */ ! filename_ptr =3D cpu.regs[0]; !=20 ! /* Trying to get mode */ ! if (h8300hmode || h8300smode) ! { ! mode =3D GET_MEMORY_L(cpu.regs[7] + 8); ! } ! else ! { ! mode =3D GET_MEMORY_W(cpu.regs[7] + 4); ! }=09=09 !=20=09=20=20=20=20 ! /* Trying to find the length of the filename */ ! temp_char =3D GET_MEMORY_B(cpu.regs[0]); !=20 ! len =3D 1; ! while (temp_char !=3D '\0') ! { ! temp_char =3D GET_MEMORY_B (filename_ptr + len); ! len++; ! } !=20=09=20=20=20=20 ! /* Allocating space for the filename */ ! filename =3D (char *)malloc(sizeof(char) * len); !=20 ! /* String copying the filename from memory */ ! for (i =3D 0; i < len; i++) ! { ! temp_char =3D GET_MEMORY_B (filename_ptr + i); ! filename[i] =3D temp_char; ! } !=20=20=20=20=20=20=20=20=20=20 ! /* Callback to open and return the file descriptor */ ! open_return =3D sim_callback->open (sim_callback, filename, mode); !=20=09=20=20=20=20 ! /* Return value in register 0 */ ! cpu.regs[0] =3D open_return; ! } ! goto next; !=20 ! case O (O_SYS_READ, SB): ! { ! char *char_ptr ; /* Where characters read would be stored= */ ! int fd =3D cpu.regs[0]; /* File descriptor */ ! int buf_size =3D cpu.regs[2]; /* BUF_SIZE parameter in read */ ! int i =3D 0; /* Temporary Loop counter */ ! int read_return =3D 0; /* Return value from callback to read = */ !=20=09=20=20 ! char_ptr =3D (char *)malloc(sizeof(char) * buf_size); !=20=09=20=20 ! /* Callback to read and return the no. of characters read */ ! read_return =3D sim_callback->read (sim_callback, fd, char_ptr, buf_= size); !=20=09=20=20 ! /* The characters read are stored in cpu memory */ ! for (i =3D 0; i < buf_size; i++) ! { ! SET_MEMORY_B ((cpu.regs[1] + (sizeof(char) * i)), *(char_ptr + (= sizeof(char) * i))); ! } !=20=09=20=20 ! /* Return value in Register 0 */ ! cpu.regs[0] =3D read_return; ! } ! goto next; !=20 ! case O (O_SYS_WRITE, SB): ! { ! int fd =3D cpu.regs[0]; /* File descriptor */ ! char temp_char; /* Temporary character */ ! int len =3D cpu.regs[2]; /* Length of write, Parameter II to wr= ite */ ! int char_ptr =3D cpu.regs[1]; /* Character Pointer, Parameter I of w= rite */ ! char *ptr; /* This characters to be written are sto= red */ ! int write_return; /* Return value from write */ ! int i =3D 0; /* Loop counter */ !=20 ! /* Allocating space for the characters to be written */ ! ptr =3D (char *)malloc(sizeof(char) * len); !=20=09=20=20 ! /* Fetching the characters from cpu memory */ ! for (i =3D 0; i < len; i++) ! { ! temp_char =3D GET_MEMORY_B (char_ptr + i); ! ptr[i] =3D temp_char; ! } !=20 ! /* Callback write and return the no. of characters written */ ! write_return =3D sim_callback->write (sim_callback, fd, ptr, len); !=20 ! /* Return value in Register 0 */ ! cpu.regs[0] =3D write_return; ! } ! goto next; !=20=20=09=20=20=20 ! case O (O_SYS_LSEEK, SB): ! { ! int fd =3D cpu.regs[0]; /* File descriptor */ ! int offset =3D cpu.regs[1]; /* Offset */ ! int origin =3D cpu.regs[2]; /* Origin */ ! int lseek_return; /* Return by lseek */ !=20 ! /* Callback lseek and return offset */ ! lseek_return =3D sim_callback->lseek (sim_callback, fd, offset, orig= in); !=20 ! /* Return value in register 0 */ ! cpu.regs[0] =3D lseek_return; ! } ! goto next; !=20 ! case O (O_SYS_CLOSE, SB): ! { ! int fd =3D cpu.regs[0]; /* File descriptor */ ! int close_return; /* Return by close */ !=20 ! /* Callback close and return */ ! close_return =3D sim_callback->close (sim_callback, fd); !=20 ! /* Return value in register 0 */ ! cpu.regs[0] =3D close_return; ! } ! goto next; !=20 ! case O (O_SYS_FSTAT, SB): ! { ! int fd =3D 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 =3D 0; /* Temporary variable for buffer size */ ! int i =3D 0; /* Loop Counter */ ! int j =3D 0; /* Temporary variable for Position in source= */ ! int short_size =3D sizeof (short); /* Sizeof short */ ! int int_size =3D sizeof (int); /* Sizeof int */ !=20=09=09 ! /* Setting stat_ptr to second argument of stat */ ! stat_ptr =3D cpu.regs[1]; !=20=20=20 ! /* Callback stat and return */ ! fstat_return =3D sim_callback->fstat (sim_callback, fd, &stat_rec); !=20 ! /* Have stat_ptr point to starting of stat_rec */ ! temp_stat_ptr =3D (char *)(&stat_rec); !=20 ! SET_MEMORY_W (stat_ptr, stat_rec.st_dev); ! stat_ptr +=3D 2; ! SET_MEMORY_W (stat_ptr, stat_rec.st_ino); ! stat_ptr +=3D 2; ! SET_MEMORY_L (stat_ptr, stat_rec.st_mode); ! stat_ptr +=3D 4; ! SET_MEMORY_W (stat_ptr, stat_rec.st_nlink); ! stat_ptr +=3D 2; ! SET_MEMORY_W (stat_ptr, stat_rec.st_uid); ! stat_ptr +=3D 2; ! SET_MEMORY_W (stat_ptr, stat_rec.st_gid); ! stat_ptr +=3D 2; ! SET_MEMORY_W (stat_ptr, stat_rec.st_rdev); ! stat_ptr +=3D 2; ! SET_MEMORY_L (stat_ptr, stat_rec.st_size); ! stat_ptr +=3D 4; ! SET_MEMORY_L (stat_ptr, stat_rec.st_atime); ! stat_ptr +=3D 8; ! SET_MEMORY_L (stat_ptr, stat_rec.st_mtime); ! stat_ptr +=3D 8;=20 ! SET_MEMORY_L (stat_ptr, stat_rec.st_ctime); !=20=09=20=20 ! /* Return value in register 0 */ ! cpu.regs[0] =3D fstat_return; ! } ! goto next; !=20 ! case O (O_SYS_STAT, SB): { ! int len =3D 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 =3D 0; /* Temporary variable for buffer size */ ! int i =3D 0; /* Loop Counter */ ! int j =3D 0; /* Temporary variable for Position in source= */ ! int short_size =3D sizeof (short); /* Sizeof short */ ! int int_size =3D sizeof (int); /* Sizeof int */ !=20 ! /* Setting filename_ptr to first argument of open */ ! filename_ptr =3D cpu.regs[0]; !=20 ! /* Trying to find the length of the filename */ ! temp_char =3D GET_MEMORY_B(cpu.regs[0]); !=20 ! len =3D 1; ! while (temp_char !=3D '\0') ! { ! temp_char =3D GET_MEMORY_B (filename_ptr + len); ! len++; ! } !=20=09=20=20=20 ! /* Allocating space for the filename */ ! filename =3D (char *)malloc(sizeof(char) * len); !=20 ! /* String copying the filename from memory */ ! for (i =3D 0; i < len; i++) ! { ! temp_char =3D GET_MEMORY_B (filename_ptr + i); ! filename[i] =3D temp_char; ! } !=20=09=20=20=20 ! /* Setting stat_ptr to second argument of stat */ ! stat_ptr =3D cpu.regs[1]; !=20=20=20 ! /* Callback stat and return */ ! stat_return =3D sim_callback->stat (sim_callback, filename, &stat_re= c); !=20 ! /* Have stat_ptr point to starting of stat_rec */ ! temp_stat_ptr =3D (char *)(&stat_rec); !=20 ! SET_MEMORY_W (stat_ptr, stat_rec.st_dev); ! stat_ptr +=3D 2; ! SET_MEMORY_W (stat_ptr, stat_rec.st_ino); ! stat_ptr +=3D 2; ! SET_MEMORY_L (stat_ptr, stat_rec.st_mode); ! stat_ptr +=3D 4; ! SET_MEMORY_W (stat_ptr, stat_rec.st_nlink); ! stat_ptr +=3D 2; ! SET_MEMORY_W (stat_ptr, stat_rec.st_uid); ! stat_ptr +=3D 2; ! SET_MEMORY_W (stat_ptr, stat_rec.st_gid); ! stat_ptr +=3D 2; ! SET_MEMORY_W (stat_ptr, stat_rec.st_rdev); ! stat_ptr +=3D 2; ! SET_MEMORY_L (stat_ptr, stat_rec.st_size); ! stat_ptr +=3D 4; ! SET_MEMORY_L (stat_ptr, stat_rec.st_atime); ! stat_ptr +=3D 8; ! SET_MEMORY_L (stat_ptr, stat_rec.st_mtime); ! stat_ptr +=3D 8;=20 ! SET_MEMORY_L (stat_ptr, stat_rec.st_ctime); !=20=09=20=20 ! /* Return value in register 0 */ ! cpu.regs[0] =3D stat_return; } goto next; + /* End of system call processing */ =20=20 ONOT (O_NOT, rd =3D ~rd; v =3D 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") ; !=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 =20=20 --- 5,11 ---- char *ptr; int len; { ! asm("jsr @@0xc6") ; } =20=20 =20=20 *** 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; !=20=20=20 ! for (todo =3D 0; todo < len; todo++)=20 ! { ! asm("mov.b #0,r1l\n mov.b %0l,r2l\njsr @@0xc4" : : "r" (*ptr++) = : "r1", "r2"); ! } ! return len; } =20=20 --- 5,10 ---- char *ptr; int len; { ! asm("jsr @@0xc7"); } =20=20 *** 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 #include #include =20=20 =20=20 int _DEFUN(_lseek,(file, ptr, dir), int file _AND int ptr _AND int dir) { ! return 0; } =20=20 int _DEFUN(_close,(file), int file) { ! return -1; } =20=20 int isatty(file) --- 4,31 ---- #include #include #include + #include "sys/syscall.h" =20=20 + int + _open (path, flags) + const char *path; + int flags; + { + asm("jsr @@0xc5"); + } =20=20 int _DEFUN(_lseek,(file, ptr, dir), int file _AND int ptr _AND int dir) { ! asm("jsr @@0xc8"); } =20=20 int _DEFUN(_close,(file), int file) { ! asm("jsr @@0xc9"); } =20=20 int isatty(file) *************** int isatty(file) *** 26,45 **** return 1; } =20=20 ! int _DEFUN(_fstat,(file, st), ! int file _AND ! struct stat *st) { ! st->st_mode =3D S_IFCHR; ! return 0; } =20=20 ! int ! _open (path, flags) ! const char *path; ! int flags; { ! return 0; } =20=20 int --- 34,52 ---- return 1; } =20=20 ! int _DEFUN(_stat,(path, sbuf), ! const char *path _AND ! struct stat *st) { ! asm("jsr @@0xca"); } =20=20 !=20 ! int _DEFUN(_fstat,(file, st), ! int file _AND ! struct stat *st) { ! asm("jsr @@0xcb");=20 } =20=20 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=20 *** 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 ------_=_NextPart_000_01C29831.14DF8E90--