11e57a46299244793beb27e74be171d1540606999oliviermartin/** @file 21e57a46299244793beb27e74be171d1540606999oliviermartin 31e57a46299244793beb27e74be171d1540606999oliviermartin Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR> 4228fdff4bece78e53f44c79f5478dde7d51a8250Harry Liebel Copyright (c) 2013 - 2014, ARM Ltd. All rights reserved.<BR> 51e57a46299244793beb27e74be171d1540606999oliviermartin 61e57a46299244793beb27e74be171d1540606999oliviermartin This program and the accompanying materials 71e57a46299244793beb27e74be171d1540606999oliviermartin are licensed and made available under the terms and conditions of the BSD License 81e57a46299244793beb27e74be171d1540606999oliviermartin which accompanies this distribution. The full text of the license may be found at 91e57a46299244793beb27e74be171d1540606999oliviermartin http://opensource.org/licenses/bsd-license.php 101e57a46299244793beb27e74be171d1540606999oliviermartin 111e57a46299244793beb27e74be171d1540606999oliviermartin THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 121e57a46299244793beb27e74be171d1540606999oliviermartin WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 131e57a46299244793beb27e74be171d1540606999oliviermartin 141e57a46299244793beb27e74be171d1540606999oliviermartin**/ 151e57a46299244793beb27e74be171d1540606999oliviermartin 161e57a46299244793beb27e74be171d1540606999oliviermartin#ifndef __SEMIHOST_PRIVATE_H__ 171e57a46299244793beb27e74be171d1540606999oliviermartin#define __SEMIHOST_PRIVATE_H__ 181e57a46299244793beb27e74be171d1540606999oliviermartin 191e57a46299244793beb27e74be171d1540606999oliviermartintypedef struct { 201e57a46299244793beb27e74be171d1540606999oliviermartin CHAR8 *FileName; 21228fdff4bece78e53f44c79f5478dde7d51a8250Harry Liebel UINTN Mode; 22228fdff4bece78e53f44c79f5478dde7d51a8250Harry Liebel UINTN NameLength; 231e57a46299244793beb27e74be171d1540606999oliviermartin} SEMIHOST_FILE_OPEN_BLOCK; 241e57a46299244793beb27e74be171d1540606999oliviermartin 251e57a46299244793beb27e74be171d1540606999oliviermartintypedef struct { 26228fdff4bece78e53f44c79f5478dde7d51a8250Harry Liebel UINTN Handle; 271e57a46299244793beb27e74be171d1540606999oliviermartin VOID *Buffer; 28228fdff4bece78e53f44c79f5478dde7d51a8250Harry Liebel UINTN Length; 291e57a46299244793beb27e74be171d1540606999oliviermartin} SEMIHOST_FILE_READ_WRITE_BLOCK; 301e57a46299244793beb27e74be171d1540606999oliviermartin 311e57a46299244793beb27e74be171d1540606999oliviermartintypedef struct { 32228fdff4bece78e53f44c79f5478dde7d51a8250Harry Liebel UINTN Handle; 33228fdff4bece78e53f44c79f5478dde7d51a8250Harry Liebel UINTN Location; 341e57a46299244793beb27e74be171d1540606999oliviermartin} SEMIHOST_FILE_SEEK_BLOCK; 351e57a46299244793beb27e74be171d1540606999oliviermartin 361e57a46299244793beb27e74be171d1540606999oliviermartintypedef struct { 375521b5cc73e21957023b634cb7f75e415bba0225Ronald Cron VOID *Buffer; 385521b5cc73e21957023b634cb7f75e415bba0225Ronald Cron UINTN Identifier; 395521b5cc73e21957023b634cb7f75e415bba0225Ronald Cron UINTN Length; 405521b5cc73e21957023b634cb7f75e415bba0225Ronald Cron} SEMIHOST_FILE_TMPNAME_BLOCK; 415521b5cc73e21957023b634cb7f75e415bba0225Ronald Cron 425521b5cc73e21957023b634cb7f75e415bba0225Ronald Crontypedef struct { 431e57a46299244793beb27e74be171d1540606999oliviermartin CHAR8 *FileName; 44228fdff4bece78e53f44c79f5478dde7d51a8250Harry Liebel UINTN NameLength; 451e57a46299244793beb27e74be171d1540606999oliviermartin} SEMIHOST_FILE_REMOVE_BLOCK; 461e57a46299244793beb27e74be171d1540606999oliviermartin 471e57a46299244793beb27e74be171d1540606999oliviermartintypedef struct { 485521b5cc73e21957023b634cb7f75e415bba0225Ronald Cron CHAR8 *FileName; 495521b5cc73e21957023b634cb7f75e415bba0225Ronald Cron UINTN FileNameLength; 505521b5cc73e21957023b634cb7f75e415bba0225Ronald Cron CHAR8 *NewFileName; 515521b5cc73e21957023b634cb7f75e415bba0225Ronald Cron UINTN NewFileNameLength; 525521b5cc73e21957023b634cb7f75e415bba0225Ronald Cron} SEMIHOST_FILE_RENAME_BLOCK; 535521b5cc73e21957023b634cb7f75e415bba0225Ronald Cron 545521b5cc73e21957023b634cb7f75e415bba0225Ronald Crontypedef struct { 551e57a46299244793beb27e74be171d1540606999oliviermartin CHAR8 *CommandLine; 56228fdff4bece78e53f44c79f5478dde7d51a8250Harry Liebel UINTN CommandLength; 571e57a46299244793beb27e74be171d1540606999oliviermartin} SEMIHOST_SYSTEM_BLOCK; 581e57a46299244793beb27e74be171d1540606999oliviermartin 593402aac7d985bf8a9f9d3c639f3fe93609380513Ronald Cron#if defined(__CC_ARM) 601e57a46299244793beb27e74be171d1540606999oliviermartin 611e57a46299244793beb27e74be171d1540606999oliviermartin#if defined(__thumb__) 621e57a46299244793beb27e74be171d1540606999oliviermartin#define SWI 0xAB 631e57a46299244793beb27e74be171d1540606999oliviermartin#else 641e57a46299244793beb27e74be171d1540606999oliviermartin#define SWI 0x123456 651e57a46299244793beb27e74be171d1540606999oliviermartin#endif 661e57a46299244793beb27e74be171d1540606999oliviermartin 671e57a46299244793beb27e74be171d1540606999oliviermartin#define SEMIHOST_SUPPORTED TRUE 681e57a46299244793beb27e74be171d1540606999oliviermartin 691e57a46299244793beb27e74be171d1540606999oliviermartin__swi(SWI) 701e57a46299244793beb27e74be171d1540606999oliviermartinINT32 711e57a46299244793beb27e74be171d1540606999oliviermartin_Semihost_SYS_OPEN( 721e57a46299244793beb27e74be171d1540606999oliviermartin IN UINTN SWI_0x01, 731e57a46299244793beb27e74be171d1540606999oliviermartin IN SEMIHOST_FILE_OPEN_BLOCK *OpenBlock 741e57a46299244793beb27e74be171d1540606999oliviermartin ); 751e57a46299244793beb27e74be171d1540606999oliviermartin 761e57a46299244793beb27e74be171d1540606999oliviermartin__swi(SWI) 771e57a46299244793beb27e74be171d1540606999oliviermartinINT32 781e57a46299244793beb27e74be171d1540606999oliviermartin_Semihost_SYS_CLOSE( 791e57a46299244793beb27e74be171d1540606999oliviermartin IN UINTN SWI_0x02, 801e57a46299244793beb27e74be171d1540606999oliviermartin IN UINT32 *Handle 811e57a46299244793beb27e74be171d1540606999oliviermartin ); 821e57a46299244793beb27e74be171d1540606999oliviermartin 831e57a46299244793beb27e74be171d1540606999oliviermartin__swi(SWI) 841e57a46299244793beb27e74be171d1540606999oliviermartinVOID 851e57a46299244793beb27e74be171d1540606999oliviermartin_Semihost_SYS_WRITEC( 861e57a46299244793beb27e74be171d1540606999oliviermartin IN UINTN SWI_0x03, 871e57a46299244793beb27e74be171d1540606999oliviermartin IN CHAR8 *Character 881e57a46299244793beb27e74be171d1540606999oliviermartin ); 891e57a46299244793beb27e74be171d1540606999oliviermartin 901e57a46299244793beb27e74be171d1540606999oliviermartin__swi(SWI) 911e57a46299244793beb27e74be171d1540606999oliviermartinVOID 921e57a46299244793beb27e74be171d1540606999oliviermartin_Semihost_SYS_WRITE0( 931e57a46299244793beb27e74be171d1540606999oliviermartin IN UINTN SWI_0x04, 941e57a46299244793beb27e74be171d1540606999oliviermartin IN CHAR8 *String 951e57a46299244793beb27e74be171d1540606999oliviermartin ); 961e57a46299244793beb27e74be171d1540606999oliviermartin 971e57a46299244793beb27e74be171d1540606999oliviermartin__swi(SWI) 981e57a46299244793beb27e74be171d1540606999oliviermartinUINT32 991e57a46299244793beb27e74be171d1540606999oliviermartin_Semihost_SYS_WRITE( 1001e57a46299244793beb27e74be171d1540606999oliviermartin IN UINTN SWI_0x05, 1011e57a46299244793beb27e74be171d1540606999oliviermartin IN OUT SEMIHOST_FILE_READ_WRITE_BLOCK *WriteBlock 1021e57a46299244793beb27e74be171d1540606999oliviermartin ); 1031e57a46299244793beb27e74be171d1540606999oliviermartin 1041e57a46299244793beb27e74be171d1540606999oliviermartin__swi(SWI) 1051e57a46299244793beb27e74be171d1540606999oliviermartinUINT32 1061e57a46299244793beb27e74be171d1540606999oliviermartin_Semihost_SYS_READ( 1071e57a46299244793beb27e74be171d1540606999oliviermartin IN UINTN SWI_0x06, 1081e57a46299244793beb27e74be171d1540606999oliviermartin IN OUT SEMIHOST_FILE_READ_WRITE_BLOCK *ReadBlock 1091e57a46299244793beb27e74be171d1540606999oliviermartin ); 1101e57a46299244793beb27e74be171d1540606999oliviermartin 1111e57a46299244793beb27e74be171d1540606999oliviermartin__swi(SWI) 1121e57a46299244793beb27e74be171d1540606999oliviermartinCHAR8 1131e57a46299244793beb27e74be171d1540606999oliviermartin_Semihost_SYS_READC( 1141e57a46299244793beb27e74be171d1540606999oliviermartin IN UINTN SWI_0x07, 1151e57a46299244793beb27e74be171d1540606999oliviermartin IN UINTN Zero 1161e57a46299244793beb27e74be171d1540606999oliviermartin ); 1171e57a46299244793beb27e74be171d1540606999oliviermartin 1181e57a46299244793beb27e74be171d1540606999oliviermartin__swi(SWI) 1191e57a46299244793beb27e74be171d1540606999oliviermartinINT32 1201e57a46299244793beb27e74be171d1540606999oliviermartin_Semihost_SYS_SEEK( 1211e57a46299244793beb27e74be171d1540606999oliviermartin IN UINTN SWI_0x0A, 1221e57a46299244793beb27e74be171d1540606999oliviermartin IN SEMIHOST_FILE_SEEK_BLOCK *SeekBlock 1231e57a46299244793beb27e74be171d1540606999oliviermartin ); 1241e57a46299244793beb27e74be171d1540606999oliviermartin 1251e57a46299244793beb27e74be171d1540606999oliviermartin__swi(SWI) 1261e57a46299244793beb27e74be171d1540606999oliviermartinINT32 1271e57a46299244793beb27e74be171d1540606999oliviermartin_Semihost_SYS_FLEN( 1281e57a46299244793beb27e74be171d1540606999oliviermartin IN UINTN SWI_0x0C, 1291e57a46299244793beb27e74be171d1540606999oliviermartin IN UINT32 *Handle 1301e57a46299244793beb27e74be171d1540606999oliviermartin ); 1311e57a46299244793beb27e74be171d1540606999oliviermartin 1321e57a46299244793beb27e74be171d1540606999oliviermartin__swi(SWI) 1331e57a46299244793beb27e74be171d1540606999oliviermartinUINT32 1345521b5cc73e21957023b634cb7f75e415bba0225Ronald Cron_Semihost_SYS_TMPNAME( 1355521b5cc73e21957023b634cb7f75e415bba0225Ronald Cron IN UINTN SWI_0x0D, 1365521b5cc73e21957023b634cb7f75e415bba0225Ronald Cron IN SEMIHOST_FILE_TMPNAME_BLOCK *TmpNameBlock 1375521b5cc73e21957023b634cb7f75e415bba0225Ronald Cron ); 1385521b5cc73e21957023b634cb7f75e415bba0225Ronald Cron 1395521b5cc73e21957023b634cb7f75e415bba0225Ronald Cron__swi(SWI) 1405521b5cc73e21957023b634cb7f75e415bba0225Ronald CronUINT32 1411e57a46299244793beb27e74be171d1540606999oliviermartin_Semihost_SYS_REMOVE( 1421e57a46299244793beb27e74be171d1540606999oliviermartin IN UINTN SWI_0x0E, 1431e57a46299244793beb27e74be171d1540606999oliviermartin IN SEMIHOST_FILE_REMOVE_BLOCK *RemoveBlock 1441e57a46299244793beb27e74be171d1540606999oliviermartin ); 1451e57a46299244793beb27e74be171d1540606999oliviermartin 1461e57a46299244793beb27e74be171d1540606999oliviermartin__swi(SWI) 1471e57a46299244793beb27e74be171d1540606999oliviermartinUINT32 1485521b5cc73e21957023b634cb7f75e415bba0225Ronald Cron_Semihost_SYS_RENAME( 1495521b5cc73e21957023b634cb7f75e415bba0225Ronald Cron IN UINTN SWI_0x0F, 1505521b5cc73e21957023b634cb7f75e415bba0225Ronald Cron IN SEMIHOST_FILE_RENAME_BLOCK *RenameBlock 1515521b5cc73e21957023b634cb7f75e415bba0225Ronald Cron ); 1525521b5cc73e21957023b634cb7f75e415bba0225Ronald Cron 1535521b5cc73e21957023b634cb7f75e415bba0225Ronald Cron__swi(SWI) 1545521b5cc73e21957023b634cb7f75e415bba0225Ronald CronUINT32 1551e57a46299244793beb27e74be171d1540606999oliviermartin_Semihost_SYS_SYSTEM( 1561e57a46299244793beb27e74be171d1540606999oliviermartin IN UINTN SWI_0x12, 1571e57a46299244793beb27e74be171d1540606999oliviermartin IN SEMIHOST_SYSTEM_BLOCK *SystemBlock 1581e57a46299244793beb27e74be171d1540606999oliviermartin ); 1591e57a46299244793beb27e74be171d1540606999oliviermartin 1601e57a46299244793beb27e74be171d1540606999oliviermartin#define Semihost_SYS_OPEN(OpenBlock) _Semihost_SYS_OPEN(0x01, OpenBlock) 1611e57a46299244793beb27e74be171d1540606999oliviermartin#define Semihost_SYS_CLOSE(Handle) _Semihost_SYS_CLOSE(0x02, Handle) 1621e57a46299244793beb27e74be171d1540606999oliviermartin#define Semihost_SYS_WRITE0(String) _Semihost_SYS_WRITE0(0x04, String) 1631e57a46299244793beb27e74be171d1540606999oliviermartin#define Semihost_SYS_WRITEC(Character) _Semihost_SYS_WRITEC(0x03, Character) 1641e57a46299244793beb27e74be171d1540606999oliviermartin#define Semihost_SYS_WRITE(WriteBlock) _Semihost_SYS_WRITE(0x05, WriteBlock) 1651e57a46299244793beb27e74be171d1540606999oliviermartin#define Semihost_SYS_READ(ReadBlock) _Semihost_SYS_READ(0x06, ReadBlock) 1661e57a46299244793beb27e74be171d1540606999oliviermartin#define Semihost_SYS_READC() _Semihost_SYS_READC(0x07, 0) 1671e57a46299244793beb27e74be171d1540606999oliviermartin#define Semihost_SYS_SEEK(SeekBlock) _Semihost_SYS_SEEK(0x0A, SeekBlock) 1681e57a46299244793beb27e74be171d1540606999oliviermartin#define Semihost_SYS_FLEN(Handle) _Semihost_SYS_FLEN(0x0C, Handle) 1695521b5cc73e21957023b634cb7f75e415bba0225Ronald Cron#define Semihost_SYS_TMPNAME(TmpNameBlock) _Semihost_SYS_TMPNAME(0x0D, TmpNameBlock) 1701e57a46299244793beb27e74be171d1540606999oliviermartin#define Semihost_SYS_REMOVE(RemoveBlock) _Semihost_SYS_REMOVE(0x0E, RemoveBlock) 1715521b5cc73e21957023b634cb7f75e415bba0225Ronald Cron#define Semihost_SYS_RENAME(RenameBlock) _Semihost_SYS_RENAME(0x0F, RenameBlock) 1721e57a46299244793beb27e74be171d1540606999oliviermartin#define Semihost_SYS_SYSTEM(SystemBlock) _Semihost_SYS_SYSTEM(0x12, SystemBlock) 1731e57a46299244793beb27e74be171d1540606999oliviermartin 1741e57a46299244793beb27e74be171d1540606999oliviermartin#elif defined(__GNUC__) // __CC_ARM 1751e57a46299244793beb27e74be171d1540606999oliviermartin 1761e57a46299244793beb27e74be171d1540606999oliviermartin#define SEMIHOST_SUPPORTED TRUE 1771e57a46299244793beb27e74be171d1540606999oliviermartin 1781e57a46299244793beb27e74be171d1540606999oliviermartinUINT32 1791e57a46299244793beb27e74be171d1540606999oliviermartinGccSemihostCall ( 1801e57a46299244793beb27e74be171d1540606999oliviermartin IN UINT32 Operation, 1811e57a46299244793beb27e74be171d1540606999oliviermartin IN UINTN SystemBlockAddress 1821e57a46299244793beb27e74be171d1540606999oliviermartin ); // __attribute__ ((interrupt ("SVC"))); 1831e57a46299244793beb27e74be171d1540606999oliviermartin 1841e57a46299244793beb27e74be171d1540606999oliviermartin#define Semihost_SYS_OPEN(OpenBlock) GccSemihostCall(0x01, (UINTN)(OpenBlock)) 1851e57a46299244793beb27e74be171d1540606999oliviermartin#define Semihost_SYS_CLOSE(Handle) GccSemihostCall(0x02, (UINTN)(Handle)) 1861e57a46299244793beb27e74be171d1540606999oliviermartin#define Semihost_SYS_WRITE0(String) GccSemihostCall(0x04, (UINTN)(String)) 1871e57a46299244793beb27e74be171d1540606999oliviermartin#define Semihost_SYS_WRITEC(Character) GccSemihostCall(0x03, (UINTN)(Character)) 1881e57a46299244793beb27e74be171d1540606999oliviermartin#define Semihost_SYS_WRITE(WriteBlock) GccSemihostCall(0x05, (UINTN)(WriteBlock)) 1891e57a46299244793beb27e74be171d1540606999oliviermartin#define Semihost_SYS_READ(ReadBlock) GccSemihostCall(0x06, (UINTN)(ReadBlock)) 1901e57a46299244793beb27e74be171d1540606999oliviermartin#define Semihost_SYS_READC() GccSemihostCall(0x07, (UINTN)(0)) 1911e57a46299244793beb27e74be171d1540606999oliviermartin#define Semihost_SYS_SEEK(SeekBlock) GccSemihostCall(0x0A, (UINTN)(SeekBlock)) 1921e57a46299244793beb27e74be171d1540606999oliviermartin#define Semihost_SYS_FLEN(Handle) GccSemihostCall(0x0C, (UINTN)(Handle)) 1935521b5cc73e21957023b634cb7f75e415bba0225Ronald Cron#define Semihost_SYS_TMPNAME(TmpNameBlock) GccSemihostCall(0x0D, (UINTN)(TmpNameBlock)) 1941e57a46299244793beb27e74be171d1540606999oliviermartin#define Semihost_SYS_REMOVE(RemoveBlock) GccSemihostCall(0x0E, (UINTN)(RemoveBlock)) 1955521b5cc73e21957023b634cb7f75e415bba0225Ronald Cron#define Semihost_SYS_RENAME(RenameBlock) GccSemihostCall(0x0F, (UINTN)(RenameBlock)) 1961e57a46299244793beb27e74be171d1540606999oliviermartin#define Semihost_SYS_SYSTEM(SystemBlock) GccSemihostCall(0x12, (UINTN)(SystemBlock)) 1971e57a46299244793beb27e74be171d1540606999oliviermartin 1981e57a46299244793beb27e74be171d1540606999oliviermartin#else // __CC_ARM 1991e57a46299244793beb27e74be171d1540606999oliviermartin 2001e57a46299244793beb27e74be171d1540606999oliviermartin#define SEMIHOST_SUPPORTED FALSE 2011e57a46299244793beb27e74be171d1540606999oliviermartin 2021e57a46299244793beb27e74be171d1540606999oliviermartin#define Semihost_SYS_OPEN(OpenBlock) (-1) 2031e57a46299244793beb27e74be171d1540606999oliviermartin#define Semihost_SYS_CLOSE(Handle) (-1) 2041e57a46299244793beb27e74be171d1540606999oliviermartin#define Semihost_SYS_WRITE0(String) 2051e57a46299244793beb27e74be171d1540606999oliviermartin#define Semihost_SYS_WRITEC(Character) 2061e57a46299244793beb27e74be171d1540606999oliviermartin#define Semihost_SYS_WRITE(WriteBlock) (0) 2071e57a46299244793beb27e74be171d1540606999oliviermartin#define Semihost_SYS_READ(ReadBlock) ((ReadBlock)->Length) 2081e57a46299244793beb27e74be171d1540606999oliviermartin#define Semihost_SYS_READC() ('x') 2091e57a46299244793beb27e74be171d1540606999oliviermartin#define Semihost_SYS_SEEK(SeekBlock) (-1) 2101e57a46299244793beb27e74be171d1540606999oliviermartin#define Semihost_SYS_FLEN(Handle) (-1) 2115521b5cc73e21957023b634cb7f75e415bba0225Ronald Cron#define Semihost_SYS_TMPNAME(TmpNameBlock) (-1) 2121e57a46299244793beb27e74be171d1540606999oliviermartin#define Semihost_SYS_REMOVE(RemoveBlock) (-1) 2135521b5cc73e21957023b634cb7f75e415bba0225Ronald Cron#define Semihost_SYS_RENAME(RenameBlock) (-1) 2141e57a46299244793beb27e74be171d1540606999oliviermartin#define Semihost_SYS_SYSTEM(SystemBlock) (-1) 2151e57a46299244793beb27e74be171d1540606999oliviermartin 2161e57a46299244793beb27e74be171d1540606999oliviermartin#endif // __CC_ARM 2171e57a46299244793beb27e74be171d1540606999oliviermartin 2181e57a46299244793beb27e74be171d1540606999oliviermartin#endif //__SEMIHOST_PRIVATE_H__ 219