This is the mail archive of the gdb-prs@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

pending/983: PATCH : H8300 Simulator File I/O Implementation


>Number:         983
>Category:       pending
>Synopsis:       PATCH : H8300 Simulator File I/O Implementation
>Confidential:   yes
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          change-request
>Submitter-Id:   unknown
>Arrival-Date:   Fri Jan 31 05:08:01 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     
>Release:        
>Organization:
>Environment:
>Description:
 Dear All,
 
 I have been studying the h8300 simulator and have implemented/supported
 some File I/O system calls on the same through callback mechanism. I have 
 done some amount of testing for the same using different h8300-elf-gcc 
 cross-compiler options such as "-mh" "-mh -mint32" "-ms -ms2600 -mint32" 
 and of course the basic compiler, and have found the changes to be quite
 stable.
 
 IMHO, having File I/O on this simulator would be very useful for testing 
 purposes , even though no native O/S may be actually running on the 
 microcontroller.
 
 I would request you to review this patch and apply it if it is found 
 suitable. Please give suggestions, if improvements can be made or some 
 problems are found.
 
 Thanx and Regards,
 
 Venky
 
 ___________________________ChangeLog Entries__________________________
 
 Change Log Entry for simulator in directory sim/h8300/
 
 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.
 
 
 
 Change Log Entry for opcodes added in include/opcodes
 
 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.
 
 
 
 Change Log Entry for changes in newlib
 
 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.
 
 
 ____________________Patches_________________________
 
 
 *** sim/h8300/compile.c.original	Thu Nov 14 17:36:40 2002
 --- sim/h8300/compile.c.modified	Tue Nov 26 15:49:09 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,488 ----
   		  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,
 --- 1419,1680 ----
   	    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;
 ! 
 !           /* 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,
 *** include/opcode/h8300.h.original	Thu Nov 14 17:35:40 2002
 --- include/opcode/h8300.h.modified	Tue Nov 12 17:03:16 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
 *** newlib/libc/sys/h8300hms/syscalls.c.original	Thu Nov 14 17:19:38
 2002
 --- newlib/libc/sys/h8300hms/syscalls.c.modified	Thu Nov 14 17:26:58
 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
 *** newlib/libc/sys/h8300hms/read.c.original	Thu Nov 14 17:20:04 2002
 --- newlib/libc/sys/h8300hms/read.c.modified	Thu Nov 14 16:45:37 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  8 10:38:19 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");
   }
 
   
 
>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]