dol: initial dol commit
[jump.git] / dol / src / dol / visitor / rtems / lib / appsupport.c
diff --git a/dol/src/dol/visitor/rtems/lib/appsupport.c b/dol/src/dol/visitor/rtems/lib/appsupport.c
new file mode 100644 (file)
index 0000000..7ced4a5
--- /dev/null
@@ -0,0 +1,136 @@
+///////////////////////////////////////////////////////////////////////////////\r
+// Copyright 2003 DEIS - Universita' di Bologna\r
+//\r
+// name         appsupport.c\r
+// author       DEIS - Universita' di Bologna\r
+//              Davide Bertozzi - dbertozzi@deis.unibo.it\r
+//              Mirko Loghi - mloghi@deis.unibo.it\r
+//              Federico Angiolini - fangiolini@deis.unibo.it\r
+//              Francesco Poletti - fpoletti@deis.unibo.it\r
+// portions by  Massimo Scardamaglia - mascard@vizzavi.it\r
+// info         Provides support for testbench compilation\r
+//\r
+///////////////////////////////////////////////////////////////////////////////\r
+#include <bsp.h>\r
+\r
+#include "appsupport.h"\r
+\r
+volatile char *time_low_ptr   = (char *)(SIMSUPPORT_BASE + GET_TIME_ADDRESS_LO);\r
+volatile char *time_high_ptr  = (char *)(SIMSUPPORT_BASE + GET_TIME_ADDRESS_HI);\r
+volatile char *time_stop_ptr  = (char *)(SIMSUPPORT_BASE + STOP_TIME_ADDRESS);\r
+volatile char *time_rel_ptr   = (char *)(SIMSUPPORT_BASE + RELEASE_TIME_ADDRESS);\r
+\r
+volatile char *cycle_low_ptr  = (char *)(SIMSUPPORT_BASE + GET_CYCLE_ADDRESS_LO);\r
+volatile char *cycle_high_ptr = (char *)(SIMSUPPORT_BASE + GET_CYCLE_ADDRESS_HI);\r
+volatile char *cycle_stop_ptr = (char *)(SIMSUPPORT_BASE + STOP_CYCLE_ADDRESS);\r
+volatile char *cycle_rel_ptr  = (char *)(SIMSUPPORT_BASE + RELEASE_CYCLE_ADDRESS);\r
+\r
+\r
+///////////////////////////////////////////////////////////////////////////////\r
+// pr - Allows printing debug info even without support from an OS. See\r
+//      user_swi.cpp for printable messages, or to create your own\r
+\r
+void pr(int proc, int msg_num, int num_arg)\r
+{\r
+#ifndef __OPTIMIZE__\r
+    __asm ("ldr r1, %0" : : "g" (proc) : "r1" );\r
+    __asm ("ldr r2, %0" : : "g" (msg_num) : "r2" );\r
+    __asm ("ldr r3, %0" : : "g" (num_arg) : "r3" );\r
+    __asm ("swi " SWI_PRINTstr);\r
+#else\r
+    __asm ("mov r1, %0" : : "g" (proc) : "r1" );\r
+    __asm ("mov r2, %0" : : "g" (msg_num) : "r2" );\r
+    __asm ("mov r3, %0" : : "g" (num_arg) : "r3" );\r
+    __asm ("swi " SWI_PRINTstr);\r
+#endif\r
+}\r
+\r
+///////////////////////////////////////////////////////////////////////////////\r
+// get_proc_id - Allows getting the processor's ID (from 1 onwards)\r
+unsigned int get_proc_id()\r
+{\r
+  char *ptr = (char *)(SIMSUPPORT_BASE + GET_CPU_ID_ADDRESS);\r
+  return (*(unsigned long int *)ptr);\r
+}\r
+\r
+///////////////////////////////////////////////////////////////////////////////\r
+// get_proc_num - Allows getting the number of processors in the platform\r
+unsigned int get_proc_num()\r
+{\r
+  char *ptr = (char *)(SIMSUPPORT_BASE + GET_CPU_CNT_ADDRESS);\r
+  return (*(unsigned long int *)ptr);\r
+}\r
+\r
+// ---------------------------\r
+// Frequency scaling functions\r
+// ---------------------------\r
+volatile unsigned int *freqdevice      = (unsigned int *)FREQ_BASE;\r
+\r
+///////////////////////////////////////////////////////////////////////////////\r
+// scale_this_core_frequency - Scales the frequency of the core on which\r
+//                             the application is running\r
+void scale_this_core_frequency(unsigned short int divider)\r
+{\r
+  freqdevice[get_proc_id() - 1] = divider;\r
+}\r
+///////////////////////////////////////////////////////////////////////////////\r
+// scale_device_frequency - Scales the frequency of any device in the system\r
+void scale_device_frequency(unsigned short int divider, int ID)\r
+{\r
+  freqdevice[ID] = divider;\r
+}\r
+///////////////////////////////////////////////////////////////////////////////\r
+// get_this_core_frequency - Gets the frequency divider of the core on which\r
+//                           the application is running\r
+unsigned short int get_this_core_frequency()\r
+{\r
+  return (freqdevice[get_proc_id() - 1]);\r
+}\r
+///////////////////////////////////////////////////////////////////////////////\r
+// get_device_frequency - Gets the frequency divider of any device in the system\r
+unsigned short int get_device_frequency(int ID)\r
+{\r
+  return (freqdevice[ID]);\r
+}\r
+\r
+///////////////////////////////////////////////////////////////////////////////\r
+// get_time - Allows getting the current simulation time\r
+unsigned long long int get_time()\r
+{\r
+  unsigned long long int time;\r
+  \r
+  *time_stop_ptr = 1;\r
+  time = (((unsigned long long int)(*(unsigned long int *)time_high_ptr)) << 32) + *(unsigned long int *)time_low_ptr;\r
+  *time_rel_ptr = 1;\r
+  \r
+  return (time);\r
+}\r
+\r
+///////////////////////////////////////////////////////////////////////////////\r
+// get_cycle - Allows getting the current simulation cycle\r
+unsigned long long int get_cycle1()\r
+{\r
+  unsigned long long int cycle;\r
+  \r
+  *cycle_stop_ptr = 1;\r
+  cycle = (((unsigned long long int)(*(unsigned long int *)cycle_high_ptr)) << 32) + *(unsigned long int *)cycle_low_ptr;\r
+  *cycle_rel_ptr = 1;\r
+  \r
+  return (cycle);\r
+}\r
+\r
+extern rtems_id timer_sem_id;\r
+unsigned long long int get_cycle()\r
+{\r
+  unsigned long long int cycle;\r
+  rtems_status_code rtems_status;\r
+\r
+  rtems_status = rtems_semaphore_obtain(timer_sem_id, RTEMS_WAIT, RTEMS_NO_TIMEOUT);\r
+  *cycle_stop_ptr = 1;\r
+  cycle = (((unsigned long long int)(*(unsigned long int *)cycle_high_ptr))\r
+           << 32) + *(unsigned long int *)cycle_low_ptr;\r
+  *cycle_rel_ptr = 1;\r
+  rtems_status =  rtems_semaphore_release(timer_sem_id);\r
+\r
+  return (cycle);\r
+}\r