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