Added framework as a flattened directory

Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
diff --git a/framework/psasim/test/Makefile b/framework/psasim/test/Makefile
new file mode 100644
index 0000000..07d1586
--- /dev/null
+++ b/framework/psasim/test/Makefile
@@ -0,0 +1,12 @@
+INCLUDE := -I../include/ -I./psa_manifest
+
+.PHONY: all clean
+
+all:
+	psa_autogen manifest.json
+	$(CC) psa_ff_bootstrap_TEST_PARTITION.c -lpsaff -o partition
+	$(CC) client.c -lpsaff -o client
+
+clean:
+	rm -rf psa_manifest
+	rm -f client partition psa_ff_bootstrap_TEST_PARTITION.c
diff --git a/framework/psasim/test/client.c b/framework/psasim/test/client.c
new file mode 100644
index 0000000..c768a71
--- /dev/null
+++ b/framework/psasim/test/client.c
@@ -0,0 +1,48 @@
+/* psasim test client */
+
+/*
+ *  Copyright The Mbed TLS Contributors
+ *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+ */
+
+#include <psa/client.h>
+#include "psa_manifest/sid.h"
+#include <stdio.h>
+#include <unistd.h>
+
+int main()
+{
+
+    const char *text = "FOOBARCOOL!!";
+
+    char output[100] = { 0 };
+    printf("My PID is %d\n", getpid());
+
+    printf("The version of the service is %u\n", psa_version(PSA_SID_SHA256_SID));
+    psa_handle_t h = psa_connect(PSA_SID_SHA256_SID, 1);
+
+    if (h < 0) {
+        printf("Couldn't connect %d\n", h);
+        return 1;
+    } else {
+        int type = 2;
+        puts("Calling!");
+        puts("Trying without invec");
+        printf("Answer to my call was %d (no invec)\n", psa_call(h, type, NULL, 0, NULL, 0));
+        psa_invec invecs[1];
+        psa_outvec outvecs[1];
+        invecs[0].base = text;
+        invecs[0].len = 24;
+        outvecs[0].base = output;
+        outvecs[0].len = 99;
+
+        printf("My iovec size should be %lu\n", invecs[0].len);
+        printf("Answer to my call was %d (with invec)\n", psa_call(h, type, invecs, 1, outvecs, 1));
+        printf("Here's the payload I recieved: %s\n", output);
+        printf("Apparently the server wrote %lu bytes in outvec %d\n", outvecs[0].len, 0);
+        puts("Closing handle");
+        psa_close(h);
+    }
+
+    return 0;
+}
diff --git a/framework/psasim/test/manifest.json b/framework/psasim/test/manifest.json
new file mode 100644
index 0000000..0ab83ef
--- /dev/null
+++ b/framework/psasim/test/manifest.json
@@ -0,0 +1,29 @@
+{
+   "psa_framework_version":1.0,
+   "name":"TEST_PARTITION",
+   "type":"PSA-ROT",
+   "priority":"LOW",
+   "entry_point":"psa_sha256_main",
+   "stack_size":"0x400",
+   "heap_size":"0x100",
+   "services":[
+      {
+         "name":"PSA_SID_SHA256",
+         "sid":"0x0000F000",
+         "signal":"PSA_SHA256",
+         "non_secure_clients": "true",
+         "minor_version":1,
+         "minor_policy":"STRICT"
+      }
+   ],
+   "irqs": [
+        {
+                "source": "SIGINT",
+                "signal": "SIGINT_SIG"
+        },
+        {
+                "source": "SIGTSTP",
+                "signal": "SIGSTP_SIG"
+        }
+   ]
+}
diff --git a/framework/psasim/test/server.c b/framework/psasim/test/server.c
new file mode 100644
index 0000000..bbd90f2
--- /dev/null
+++ b/framework/psasim/test/server.c
@@ -0,0 +1,105 @@
+/* psasim test server */
+
+/*
+ *  Copyright The Mbed TLS Contributors
+ *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+ */
+
+#include <psa/service.h>
+#include "psa_manifest/manifest.h"
+#include <unistd.h>
+#include <stdio.h>
+
+void printbits(uint32_t num)
+{
+    for (int i = 0; i < 32; i++) {
+        if ((num >> (31-i) & 0x1)) {
+            printf("1");
+        } else {
+            printf("0");
+        }
+    }
+    printf("\n");
+}
+
+#define BUF_SIZE 25
+
+int psa_sha256_main()
+{
+    psa_status_t ret = PSA_ERROR_PROGRAMMER_ERROR;
+    psa_msg_t msg = { -1 };
+    char foo[BUF_SIZE] = { 0 };
+    const int magic_num = 66;
+
+    puts("Starting");
+
+    while (1) {
+        puts("Calling psa_wait");
+        psa_signal_t signals = psa_wait(PSA_WAIT_ANY, PSA_BLOCK);
+
+        if (signals > 0) {
+            printbits(signals);
+        }
+
+        if (signals & PSA_SHA256_SIGNAL) {
+            puts("Oooh a signal!");
+
+            if (PSA_SUCCESS == psa_get(PSA_SHA256_SIGNAL, &msg)) {
+                printf("My handle is %d\n", msg.handle);
+                printf("My rhandle is %p\n", (int *) msg.rhandle);
+                switch (msg.type) {
+                    case PSA_IPC_CONNECT:
+                        puts("Got a connection message");
+                        psa_set_rhandle(msg.handle, (void *) &magic_num);
+                        ret = PSA_SUCCESS;
+                        break;
+                    case PSA_IPC_DISCONNECT:
+                        puts("Got a disconnection message");
+                        ret = PSA_SUCCESS;
+                        break;
+
+                    default:
+                        printf("Got an IPC call of type %d\n", msg.type);
+                        ret = 42;
+                        size_t size = msg.in_size[0];
+
+                        if ((size > 0) && (size <= sizeof(foo))) {
+                            psa_read(msg.handle, 0, foo, 6);
+                            foo[(BUF_SIZE-1)] = '\0';
+                            printf("Reading payload: %s\n", foo);
+                            psa_read(msg.handle, 0, foo+6, 6);
+                            foo[(BUF_SIZE-1)] = '\0';
+                            printf("Reading payload: %s\n", foo);
+                        }
+
+                        size = msg.out_size[0];
+                        if ((size > 0)) {
+                            puts("Writing response");
+                            psa_write(msg.handle, 0, "RESP", 4);
+                            psa_write(msg.handle, 0, "ONSE", 4);
+                        }
+
+                        if (msg.client_id > 0) {
+                            psa_notify(msg.client_id);
+                        } else {
+                            puts("Client is non-secure, so won't notify");
+                        }
+
+                }
+
+                psa_reply(msg.handle, ret);
+            } else {
+                puts("Failed to retrieve message");
+            }
+        } else if (SIGSTP_SIG & signals) {
+            puts("Recieved SIGSTP signal. Gonna EOI it.");
+            psa_eoi(SIGSTP_SIG);
+        } else if (SIGINT_SIG & signals) {
+            puts("Handling interrupt!\n");
+            puts("Gracefully quitting");
+            psa_panic();
+        } else {
+            puts("No signal asserted");
+        }
+    }
+}