summaryrefslogtreecommitdiffstats
path: root/sbe
diff options
context:
space:
mode:
Diffstat (limited to 'sbe')
-rw-r--r--sbe/image/img_defs.mk1
-rw-r--r--sbe/sbefw/pool.C47
-rw-r--r--sbe/sbefw/pool.H35
-rw-r--r--sbe/sbefw/sbefwfiles.mk1
-rw-r--r--sbe/sbefw/vector375
5 files changed, 459 insertions, 0 deletions
diff --git a/sbe/image/img_defs.mk b/sbe/image/img_defs.mk
index 00cdbe35..2a1c4685 100644
--- a/sbe/image/img_defs.mk
+++ b/sbe/image/img_defs.mk
@@ -215,6 +215,7 @@ GCC-CFLAGS += -msoft-float -mcpu=405 -mmulhw
GCC-CFLAGS += -meabi -msdata=eabi
GCC-CFLAGS += -ffreestanding
GCC-CFLAGS += -fno-common
+GCC-CFLAGS += -fno-exceptions
GCC-CFLAGS += -fsigned-char
GCC-CFLAGS += -fno-inline-functions-called-once
GCC-CFLAGS += -ffixed-r11
diff --git a/sbe/sbefw/pool.C b/sbe/sbefw/pool.C
new file mode 100644
index 00000000..3f9709e3
--- /dev/null
+++ b/sbe/sbefw/pool.C
@@ -0,0 +1,47 @@
+#include <stdint.h>
+#include <sbetrace.H>
+#include <stddef.h>
+#include<pool.H>
+
+namespace SBEVECTORPOOL
+{
+
+vectorMemPool_t g_pool[G_POOLSIZE];
+
+vectorMemPool_t * allocMem()
+{
+ vectorMemPool_t *pool = NULL;
+ for( size_t idx = 0; idx < G_POOLSIZE; idx++ )
+ {
+ if( 0 == g_pool[idx].refCount )
+ {
+ pool = g_pool + idx;
+ g_pool[idx].refCount++;
+ break;
+ }
+ }
+ SBE_TRACE(" Giving pool 0x%08X", pool);
+ return pool;
+}
+
+void releaseMem( vectorMemPool_t * i_pool )
+{
+ do
+ {
+ if ( NULL == i_pool ) break;
+
+ if( 0 == i_pool->refCount )
+ {
+ //TODO via RTC 129166
+ // Assert here. This pool was not supposed to be in use.
+ // Currenty just keeping it as is as we can not do much till the
+ // time support for assert is in.
+ break;
+ }
+ SBE_TRACE(" Releasing pool 0x%08X", i_pool);
+ i_pool->refCount--;
+ SBE_TRACE(" In releaseMem() RefCount:%u", i_pool->refCount);
+ }while(0);
+}
+
+} // namesspace SBEVECTORPOOL
diff --git a/sbe/sbefw/pool.H b/sbe/sbefw/pool.H
new file mode 100644
index 00000000..2248c007
--- /dev/null
+++ b/sbe/sbefw/pool.H
@@ -0,0 +1,35 @@
+
+#ifndef SBE_VECTOR_POOL_H
+#define SBE_VECTOR_POOL_H
+
+namespace SBEVECTORPOOL
+{
+
+// Size of a block for a vector
+static const size_t G_BLOCKSIZE = 512;
+
+//Pool size
+static const size_t G_POOLSIZE = 4;
+
+typedef struct
+{
+ size_t refCount;
+ uint8_t data[G_BLOCKSIZE];
+}vectorMemPool_t;
+
+/**
+ * @brief Returns memory pool block.
+ *
+ * @return Memory block if available, NULL otherwise.
+ */
+vectorMemPool_t * allocMem();
+
+/**
+ * @brief Release memory pool block.
+ *
+ * @param[in] i_pool pool pointer.
+ */
+void releaseMem( vectorMemPool_t * i_pool );
+
+} // namespace SBEVECTORPOOL
+#endif //SBE_VECTOR_POOL_H
diff --git a/sbe/sbefw/sbefwfiles.mk b/sbe/sbefw/sbefwfiles.mk
index 22ac9b86..ff9990c5 100644
--- a/sbe/sbefw/sbefwfiles.mk
+++ b/sbe/sbefw/sbefwfiles.mk
@@ -6,6 +6,7 @@ SBEFW-CPP-SOURCES += sbecmdparser.C
SBEFW-CPP-SOURCES += sbecmdscomaccess.C
SBEFW-CPP-SOURCES += sbecmdiplcontrol.C
SBEFW-CPP-SOURCES += sbefifo.C
+SBEFW-CPP-SOURCES += pool.C
SBEFW-C-SOURCES =
SBEFW-S-SOURCES =
diff --git a/sbe/sbefw/vector b/sbe/sbefw/vector
new file mode 100644
index 00000000..e8a7397d
--- /dev/null
+++ b/sbe/sbefw/vector
@@ -0,0 +1,375 @@
+
+#ifndef stl_vector
+#define stl_vector
+
+/**
+ * @file vector
+ * @brief simple stl vector template class declaration.
+ */
+
+#include <stddef.h>
+
+#if !defined( __STDC_LIMIT_MACROS)
+#define __STDC_LIMIT_MACROS
+#endif
+#include <stdint.h>
+#include <pool.H>
+//TODO via RTC 129166
+// Add implementation for assert
+#define assert(X)
+namespace std
+{
+
+ /**
+ * @class vector
+ * subset of stl vector
+ * @note Does not support allocators, reverse iterators.
+ */
+ template <class T>
+ class vector
+ {
+ public:
+
+ typedef T * iterator;
+ typedef const T * const_iterator;
+ typedef T & reference;
+ typedef const T & const_reference;
+ typedef size_t size_type;
+ typedef T value_type;
+ typedef T * pointer;
+ typedef const T * const_pointer;
+
+ protected:
+
+ pointer iv_start;
+ pointer iv_finish;
+ SBEVECTORPOOL::vectorMemPool_t *iv_poolPtr;
+ public:
+
+ /**
+ * Constructor default
+ * @post The vector is created with storage of
+ * G_BLOCKSIZE bytes.
+ */
+ explicit vector(void)
+ {
+ iv_poolPtr = SBEVECTORPOOL::allocMem();
+ assert ( NULL != iv_poolPtr)
+ iv_start = ( T* )iv_poolPtr->data;
+ iv_finish = iv_start;
+ }
+
+
+ /**
+ * MOVE COPY CTOR create a vector from another vector
+ * @param[in] x source vector
+ * @post Vector of x.size() is created from x with same
+ * memory.
+ * size() == capacity() == x.size()
+ * @note move Copy construtor willuse shallow copy. So input
+ * as well as output vector will point to same data
+ */
+ vector(const vector<T>&& x)
+ {
+ iv_start = x.iv_start;
+ iv_finish = x.iv_finish;
+ iv_poolPtr = x.iv_poolPtr;
+ iv_poolPtr->refCount++;
+ }
+
+ /**
+ * Reserve space for atleast n elements
+ * @param[in] n Number of elements
+ * @note We are having fixed size vectors in ppe. Defining
+ * this function to avoid compile issues in standard
+ * library. This function is noop for less than 512
+ * bytes requirement. For more than 512 bytes, it will
+ * assert.
+ */
+ void reserve(size_type n)
+ {
+ assert(n < max_size());
+ return;
+ }
+ /**
+ * DTOR
+ * @post Storage released
+ */
+ __attribute__ ((always_inline))
+ ~vector()
+ {
+ clear(); // call dtors
+ SBEVECTORPOOL::releaseMem(iv_poolPtr);
+ }
+
+ /**
+ * Move Assignment operator.
+ * @param[in] x A vector.
+ * @return A vector (for the purpose of multiple assigns).
+ * @pre None.
+ * @post *this == x, this->capacity() == x.size().
+ * All previously obtained iterators are invalid.
+ */
+ vector<T>& operator=(const vector<T>&& x)
+ {
+ // Just check here for pool to make sure
+ // input vector and current vector are not same;
+ if( iv_poolPtr != x.iv_poolPtr)
+ {
+ clear();
+ SBEVECTORPOOL::releaseMem(iv_poolPtr);
+ iv_start = x.iv_start;
+ iv_finish = x.iv_finish;
+ iv_poolPtr = x.iv_poolPtr;
+ iv_poolPtr->refCount++;
+ }
+ return(*this);
+ }
+
+ // Iterators --------------------
+
+ /**
+ * Get iterator to the first vector element
+ * @return iterator of rist vector element
+ * @pre None.
+ * @post None.
+ */
+ __attribute__ ((always_inline))
+ iterator begin()
+ {
+ return (iv_start);
+ }
+
+ /**
+ * Get const_iterator to the first vector element
+ * @return const_iterator of rist vector element
+ * @pre None.
+ * @post None.
+ */
+ __attribute__ ((always_inline))
+ const_iterator begin() const
+ {
+ return (iv_start);
+ }
+
+ /**
+ * Get iterator to the last vector element + 1
+ * @return iterator
+ * @pre None.
+ * @post None.
+ */
+ __attribute__ ((always_inline))
+ iterator end()
+ {
+ return (iv_finish);
+ }
+
+ /**
+ * Get const_iterator to the last vector element + 1
+ * @return const_iterator
+ * @pre None.
+ * @post None.
+ */
+ __attribute__ ((always_inline))
+ const_iterator end() const
+ {
+ return (iv_finish);
+ }
+
+ // Capacity -----------------------------------------------
+
+ /**
+ * Get the number of elements in the container
+ * @return number of elements in the container
+ */
+ __attribute__ ((always_inline))
+ size_type size() const
+ {
+ return(iv_finish - iv_start);
+ }
+
+ /**
+ * Return the maximum potential size the container could reach.
+ * @return number of the maximum element count this container
+ * could reach
+ */
+ __attribute__ ((always_inline))
+ size_type max_size() const
+ {
+ return SBEVECTORPOOL::G_BLOCKSIZE/(sizeof(T));
+ }
+
+ /**
+ * Query for empty container
+ * @return bool, true if size()==0 else false.
+ * @pre none
+ * @post none
+ */
+ __attribute__ ((always_inline))
+ bool empty() const
+ {
+ return(size() == 0);
+ }
+
+ // - Element Access -----------------------------------
+
+ /**
+ * Access a mutable reference to an element in the container
+ * @param An index into the vector
+ * @return A reference to an element
+ * @pre 0 <= n < size()
+ * @post None.
+ */
+ __attribute__ ((always_inline))
+ reference operator[](size_type n)
+ {
+ assert(n < size());
+ return(*(iv_start + n));
+ }
+
+ /**
+ * Access a mutable reference to an element in the container
+ * @param[in] index An index into the vector
+ * @return A reference to an element
+ * @pre 0 <= n < size()
+ * @post None.
+ * @note no exception handling
+ */
+ __attribute__ ((always_inline))
+ reference at(size_type index)
+ {
+ assert(index < size());
+ return(*(iv_start + index));
+ }
+
+ /**
+ * Get an immutable reference to an element in the container
+ * @param[in] index An index into the vector
+ * @return A const_reference to an object or type T
+ * @pre 0 <= n < size()
+ * @post None.
+ */
+ __attribute__ ((always_inline))
+ const_reference operator[](size_type index) const
+ {
+ assert(index < size());
+ return(*(iv_start + index));
+ }
+
+ /**
+ * Get an immutable reference to an element in the container
+ * @param[in] index An index into the vector
+ * @return A const_reference to an object or type T
+ * @pre 0 <= n < size()
+ * @post None.
+ * @note no exception handling
+ */
+ __attribute__ ((always_inline))
+ const_reference at(size_type index) const
+ {
+ assert(index < size());
+ return(*(iv_start + index));
+ }
+
+ /**
+ * Get a mutable reference to the first element in the container
+ * @return reference to first element
+ * @pre none
+ * @post None
+ */
+ __attribute__ ((always_inline))
+ reference front()
+ {
+ return *iv_start;
+ }
+
+ /**
+ * Get an Immutable reference to the first element in the
+ * container
+ * @return const_reference to first element
+ * @pre none
+ * @post None
+ */
+ __attribute__ ((always_inline))
+ const_reference front() const
+ {
+ return *iv_start;
+ }
+
+ /**
+ * Get a mutable reference to the last element in the container
+ * @return reference to last element
+ * @pre none
+ * @post None
+ */
+ __attribute__ ((always_inline))
+ reference back()
+ {
+ return *(iv_finish-1);
+ }
+
+ /**
+ * Get an Immutable reference to the last element in the
+ * container
+ * @return reference to last element
+ * @pre none
+ * @post None
+ */
+ __attribute__ ((always_inline))
+ const_reference back() const
+ {
+ return *(iv_finish-1);
+ }
+
+ /**
+ * Add element to the back of the container
+ * @param[in] x reference to object used to create new element
+ * @pre none
+ * @post All previously obtained iterators are invalid.
+ */
+ __attribute__ ((always_inline))
+ void push_back(const T& x)
+ {
+ assert(max_size() > size())
+ new (iv_finish++) T(x);
+ }
+
+ /**
+ * Clear the vector
+ * @pre none.
+ * @post size() = 0, All previously obtained iterators are
+ * invalid
+ * @note capacity unchanged
+ */
+ void clear ()
+ {
+ while(iv_finish != iv_start)
+ {
+ --iv_finish;
+ (iv_finish)->~T();
+ }
+ }
+
+ /*
+ * Assign new content to the vector object
+ * @param[in] n number of elements to assign
+ * @param[in] x reference to element to copy in
+ */
+ void assign ( size_type n, const T& x)
+ {
+ assert(n < max_size());
+ clear();
+ for ( ; n> 0; n--)
+ push_back( x);
+ }
+
+ private:
+ vector(const vector<T>& x);
+ vector<T>& operator=(const vector<T>& x);
+};
+
+}; // end namespace std
+
+
+#endif
+/* vim: set filetype=cpp : */
OpenPOWER on IntegriCloud