target/profiling: Use the correct method to access registers
[fw/openocd] / src / target / arm_semihosting.c
index 115c7d4e498b44f2fc75b974b57b3d7e66e5d854..21b7809c285b04d09294df1c8606e6cfdec67e00 100644 (file)
@@ -18,7 +18,7 @@
  *   You should have received a copy of the GNU General Public License     *
  *   along with this program; if not, write to the                         *
  *   Free Software Foundation, Inc.,                                       *
- *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.           *
  ***************************************************************************/
 
 /**
@@ -48,7 +48,7 @@
 #include <helper/log.h>
 #include <sys/stat.h>
 
-static int open_modeflags[12] = {
+static const int open_modeflags[12] = {
        O_RDONLY,
        O_RDONLY | O_BINARY,
        O_RDWR,
@@ -323,7 +323,7 @@ static int do_semihosting(struct target *target)
                        if (l < s)
                                result = -1;
                        else {
-                               retval = target_write_buffer(target, a, s, (void *)arg);
+                               retval = target_write_buffer(target, a, s, (uint8_t *)arg);
                                if (retval != ERROR_OK)
                                        return retval;
                                result = 0;
@@ -374,9 +374,34 @@ static int do_semihosting(struct target *target)
                }
                return target_call_event_callbacks(target, TARGET_EVENT_HALTED);
 
+       case 0x12:      /* SYS_SYSTEM */
+               /* Provide SYS_SYSTEM functionality.  Uses the
+                * libc system command, there may be a reason *NOT*
+                * to use this, but as I can't think of one, I
+                * implemented it this way.
+                */
+               retval = target_read_memory(target, r1, 4, 2, params);
+               if (retval != ERROR_OK)
+                       return retval;
+               else {
+                       uint32_t len = target_buffer_get_u32(target, params+4);
+                       uint32_t c_ptr = target_buffer_get_u32(target, params);
+                       uint8_t cmd[256];
+                       if (len > 255) {
+                               result = -1;
+                               arm->semihosting_errno = EINVAL;
+                       } else {
+                               memset(cmd, 0x0, 256);
+                               retval = target_read_memory(target, c_ptr, 1, len, cmd);
+                               if (retval != ERROR_OK)
+                                       return retval;
+                               else
+                                       result = system((const char *)cmd);
+                       }
+               }
+               break;
        case 0x0d:      /* SYS_TMPNAM */
        case 0x10:      /* SYS_CLOCK */
-       case 0x12:      /* SYS_SYSTEM */
        case 0x17:      /* angel_SWIreason_EnterSVC */
        case 0x30:      /* SYS_ELAPSED */
        case 0x31:      /* SYS_TICKFREQ */