MLECO-2983: Preliminary support to allow semihosting

Adding basic support to allow applications to build with semihosting
support. Default state is always disabled.

Signed-off-by: Kshitij Sisodia <kshitij.sisodia@arm.com>
Change-Id: I1d34c3a246560aaffcb34eee801e1a87d887d559
diff --git a/scripts/cmake/toolchains/bare-metal-gcc.cmake b/scripts/cmake/toolchains/bare-metal-gcc.cmake
index 89201fb..a5688d6 100644
--- a/scripts/cmake/toolchains/bare-metal-gcc.cmake
+++ b/scripts/cmake/toolchains/bare-metal-gcc.cmake
@@ -85,11 +85,21 @@
     -mcpu=${CPU_NAME}
     -mfloat-abi=${FLOAT_ABI}
     -mlittle-endian
-    --specs=nosys.specs
     --stats
     "SHELL:-Xlinker --gc-sections"
     "$<$<CONFIG:RELEASE>:--no-debug>")
 
+function(configure_semihosting TARGET_NAME SEMIHOSTING)
+    if (${SEMIHOSTING})
+        target_link_options(${TARGET_NAME} PUBLIC "--specs=rdimon.specs")
+        target_compile_options(${TARGET_NAME} PUBLIC "--specs=rdimon.specs")
+        target_compile_definitions(${TARGET_NAME} PUBLIC USE_SEMIHOSTING)
+    else()
+        target_link_options(${TARGET_NAME} PUBLIC --specs=nosys.specs)
+        target_compile_options(${TARGET_NAME} PUBLIC "--specs=nosys.specs")
+    endif()
+endfunction()
+
 # Function to add a map file output for the linker to dump diagnostic information to.
 function(add_target_map_file TARGET_NAME MAP_FILE_PATH)
     target_link_options(${TARGET_NAME} PUBLIC