Changes rebased to lastest API changes for STACK_ALIGN

Signed-off-by: Himanshu Chauhan <hschauhan@nulltrace.org>
This commit is contained in:
Himanshu Chauhan
2011-05-29 09:01:23 +05:30
parent 8dfd1f4c0f
commit b9931b4c38
3 changed files with 44 additions and 23 deletions

View File

@@ -75,8 +75,7 @@ CFLAGS= -g \
-finline-functions \
-nostdinc \
-fno-builtin \
-fno-stack-protector \
-DSTAND_ALONE
-fno-stack-protector
# Enable stack-checking (disable if not required)
ifeq ($(STACK_CHECK),true)

View File

@@ -42,7 +42,7 @@ typedef long long int64_t;
typedef unsigned long size_t;
#define UINT32 uint32_t
#define STACK_ALIGN_SIZE sizeof(uint32_t)
#define NULL ((void *)(0))
/**
@@ -54,23 +54,40 @@ typedef unsigned long size_t;
#include "printk.h"
/* Critical region protection */
#define CRITICAL_STORE unsigned int status_reg
#define CRITICAL_START() \
__asm__ __volatile__("di %0\t\n" \
"ssnop\t\n" \
"ssnop\t\n" \
"ssnop\t\n" \
"ehb\t\n" \
:"=r"(status_reg));
extern uint32_t at_preempt_count;
#define CRITICAL_END() \
__asm__ __volatile__("ei %0\t\n" \
"ssnop\t\n" \
"ssnop\t\n" \
"ssnop\t\n" \
"ehb\t\n" \
::"r"(status_reg));
/* Critical region protection */
#define CRITICAL_STORE uint32_t status_reg
#define CRITICAL_START() \
do { \
extern uint32_t at_preempt_count; \
__asm__ __volatile__("di %0\t\n" \
"ehb\t\n" \
:"=r"(status_reg)); \
at_preempt_count++; \
}while(0);
#define CRITICAL_END() \
do { \
extern uint32_t at_preempt_count; \
if (at_preempt_count == 0) { \
printk("BUG: Preempt count is zero!\n"); \
for(;;); \
} \
at_preempt_count--; \
\
if (at_preempt_count == 0) { \
if (atomCurrentContext()) { \
printk("+"); \
__asm__ __volatile__("ei %0\t\n" \
"ehb\t\n" \
::"r"(status_reg));\
} else { \
printk("."); \
} \
} \
\
}while(0);
/* Uncomment to enable stack-checking */
/* #define ATOM_STACK_CHECKING */

View File

@@ -130,6 +130,9 @@ static uint8_t idle_thread_stack[IDLE_STACK_SIZE_BYTES] __attribute__((aligned (
/* Forward declarations */
static void main_thread_func (uint32_t data);
/* Global Data */
uint32_t at_preempt_count;
/**
* \b main
*
@@ -143,6 +146,8 @@ int main ( void )
{
int8_t status;
at_preempt_count = 0;
/**
* Note: to protect OS structures and data during initialisation,
* interrupts must remain disabled until the first thread
@@ -164,8 +169,8 @@ int main ( void )
* If you are not reusing the idle thread's stack during startup then
* you should pass in the correct size here.
*/
status = atomOSInit(&idle_thread_stack[IDLE_STACK_SIZE_BYTES],
IDLE_STACK_SIZE_BYTES);
status = atomOSInit(&idle_thread_stack[0],
IDLE_STACK_SIZE_BYTES, 0);
if (status == ATOM_OK)
{
/* FIXME: Enable the system tick timer */
@@ -175,8 +180,8 @@ int main ( void )
/* Create an application thread */
status = atomThreadCreate(&main_tcb,
TEST_THREAD_PRIO, main_thread_func, 0,
&main_thread_stack[MAIN_STACK_SIZE_BYTES],
MAIN_STACK_SIZE_BYTES);
&main_thread_stack[0],
MAIN_STACK_SIZE_BYTES, 0);
if (status == ATOM_OK)
{
mips_cpu_timer_enable();