/* $Id: stack.hh,v 1.8 2008-04-28 20:29:15 sybreon Exp $
|
/* $Id: stack.hh,v 1.8 2008-04-28 20:29:15 sybreon Exp $
|
**
|
**
|
** AEMB2 HI-PERFORMANCE CPU
|
** AEMB2 HI-PERFORMANCE CPU
|
** Copyright (C) 2004-2007 Shawn Tan Ser Ngiap
|
** Copyright (C) 2004-2007 Shawn Tan Ser Ngiap
|
**
|
**
|
** This file is part of AEMB.
|
** This file is part of AEMB.
|
**
|
**
|
** AEMB is free software: you can redistribute it and/or modify it
|
** AEMB is free software: you can redistribute it and/or modify it
|
** under the terms of the GNU General Public License as published by
|
** under the terms of the GNU General Public License as published by
|
** the Free Software Foundation, either version 3 of the License, or
|
** the Free Software Foundation, either version 3 of the License, or
|
** (at your option) any later version.
|
** (at your option) any later version.
|
**
|
**
|
** AEMB is distributed in the hope that it will be useful, but WITHOUT
|
** AEMB is distributed in the hope that it will be useful, but WITHOUT
|
** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
** or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
** or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
** License for more details.
|
** License for more details.
|
**
|
**
|
** You should have received a copy of the GNU General Public License
|
** You should have received a copy of the GNU General Public License
|
** along with AEMB. If not, see .
|
** along with AEMB. If not, see .
|
*/
|
*/
|
|
|
/**
|
/**
|
Basic stack related functions
|
Basic stack related functions
|
@file stack.hh
|
@file stack.hh
|
*/
|
*/
|
|
|
#ifndef _AEMB_STACK_HH
|
#ifndef _AEMB_STACK_HH
|
#define _AEMB_STACK_HH
|
#define _AEMB_STACK_HH
|
|
|
#ifdef __cplusplus
|
#ifdef __cplusplus
|
extern "C" {
|
extern "C" {
|
#endif
|
#endif
|
|
|
/**
|
/**
|
Reads the size of the memory space allocated for the stack in bytes.
|
Reads the size of the memory space allocated for the stack in bytes.
|
@return size of stack
|
@return size of stack
|
*/
|
*/
|
|
|
inline int aembGetStackSize()
|
inline int aembGetStackSize()
|
{
|
{
|
int tmp;
|
int tmp;
|
asm ("la %0, r0, _STACK_SIZE":"=r"(tmp));
|
asm ("la %0, r0, _STACK_SIZE":"=r"(tmp));
|
return tmp;
|
return tmp;
|
}
|
}
|
|
|
/**
|
/**
|
Reads the end of the memory space allocated for the stack. This is
|
Reads the end of the memory space allocated for the stack. This is
|
where the stack ends.
|
where the stack ends.
|
@return end of stack
|
@return end of stack
|
*/
|
*/
|
|
|
inline int aembGetStackEnd()
|
inline int aembGetStackEnd()
|
{
|
{
|
int tmp;
|
int tmp;
|
asm ("la %0, r0, _stack_end":"=r"(tmp));
|
asm ("la %0, r0, _stack_end":"=r"(tmp));
|
return tmp;
|
return tmp;
|
}
|
}
|
|
|
/**
|
/**
|
Reads the top of the memory space allocated for the stack. This is
|
Reads the top of the memory space allocated for the stack. This is
|
where the stack starts.
|
where the stack starts.
|
@return top of stack
|
@return top of stack
|
*/
|
*/
|
|
|
inline int aembGetStackTop()
|
inline int aembGetStackTop()
|
{
|
{
|
int tmp;
|
int tmp;
|
asm ("la %0, r0, _stack":"=r"(tmp));
|
asm ("la %0, r0, _stack":"=r"(tmp));
|
return tmp;
|
return tmp;
|
}
|
}
|
|
|
/**
|
/**
|
Reads register R1 which is the designated stack pointer.
|
Reads register R1 which is the designated stack pointer.
|
@return stack pointer
|
@return stack pointer
|
*/
|
*/
|
|
|
inline int aembGetStack()
|
inline int aembGetStack()
|
{
|
{
|
int tmp;
|
int tmp;
|
asm ("addk %0, r0, r1":"=r"(tmp));
|
asm ("addk %0, r0, r1":"=r"(tmp));
|
return tmp;
|
return tmp;
|
}
|
}
|
|
|
/**
|
/**
|
Sets register R1 to the new stack pointer.
|
Sets register R1 to the new stack pointer.
|
@param stk new stack pointer
|
@param stk new stack pointer
|
@return new stack pointer
|
@return new stack pointer
|
*/
|
*/
|
|
|
inline int aembSetStack(int stk)
|
inline int aembSetStack(int stk)
|
{
|
{
|
asm ("addk r1, r0, %0"::"r"(stk));
|
asm ("addk r1, r0, %0"::"r"(stk));
|
return stk;
|
return stk;
|
}
|
}
|
|
|
/**
|
/**
|
Duplicates the stack
|
Duplicates the stack
|
@param newp new stack pointer
|
@param newp new stack pointer
|
@param oldp old stack pointer
|
@param oldp old stack pointer
|
@param endp end of the stack
|
@param endp end of the stack
|
*/
|
*/
|
|
|
inline void aembDupStack(unsigned int *newp, unsigned int *oldp, unsigned int *endp)
|
inline void aembDupStack(unsigned int *newp, unsigned int *oldp, unsigned int *endp)
|
{
|
{
|
while (oldp < endp)
|
while (oldp < endp)
|
{
|
{
|
// copy the stack content
|
// copy the stack content
|
*newp = *oldp;
|
*newp = *oldp;
|
// this increments 1 word (not 1 byte)
|
// this increments 1 word (not 1 byte)
|
newp++;
|
newp++;
|
oldp++;
|
oldp++;
|
}
|
}
|
}
|
}
|
|
|
#ifdef __cplusplus
|
#ifdef __cplusplus
|
}
|
}
|
#endif
|
#endif
|
|
|
#endif
|
#endif
|
|
|
/*
|
/*
|
$Log: not supported by cvs2svn $
|
$Log: not supported by cvs2svn $
|
Revision 1.7 2008/04/27 16:33:42 sybreon
|
Revision 1.7 2008/04/27 16:33:42 sybreon
|
License change to GPL3.
|
License change to GPL3.
|
|
|
Revision 1.6 2008/04/27 16:04:42 sybreon
|
Revision 1.6 2008/04/27 16:04:42 sybreon
|
Minor cosmetic changes.
|
Minor cosmetic changes.
|
|
|
Revision 1.5 2008/04/26 19:31:35 sybreon
|
Revision 1.5 2008/04/26 19:31:35 sybreon
|
Made headers C compatible.
|
Made headers C compatible.
|
|
|
Revision 1.4 2008/04/26 18:04:31 sybreon
|
Revision 1.4 2008/04/26 18:04:31 sybreon
|
Updated software to freeze T0 and run T1.
|
Updated software to freeze T0 and run T1.
|
|
|
Revision 1.3 2008/04/23 14:19:39 sybreon
|
Revision 1.3 2008/04/23 14:19:39 sybreon
|
Fixed minor bugs.
|
Fixed minor bugs.
|
Initial use of hardware mutex.
|
Initial use of hardware mutex.
|
|
|
Revision 1.2 2008/04/20 16:35:53 sybreon
|
Revision 1.2 2008/04/20 16:35:53 sybreon
|
Added C/C++ compatible #ifdef statements
|
Added C/C++ compatible #ifdef statements
|
|
|
Revision 1.1 2008/04/09 19:48:37 sybreon
|
Revision 1.1 2008/04/09 19:48:37 sybreon
|
Added new C++ files
|
Added new C++ files
|
|
|
*/
|
*/
|
|
|