/* $Id: libaemb.h,v 1.3 2007-12-16 03:26:37 sybreon Exp $
|
/* $Id: libaemb.h,v 1.3 2007-12-16 03:26:37 sybreon Exp $
|
**
|
**
|
** AEMB2 CUSTOM LIBRARY
|
** AEMB2 CUSTOM LIBRARY
|
**
|
**
|
** Copyright (C) 2004-2007 Shawn Tan Ser Ngiap <shawn.tan@aeste.net>
|
** Copyright (C) 2004-2007 Shawn Tan Ser Ngiap <shawn.tan@aeste.net>
|
**
|
**
|
** 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 Lesser General Public License as
|
** under the terms of the GNU Lesser General Public License as
|
** published by the Free Software Foundation, either version 3 of the
|
** published by the Free Software Foundation, either version 3 of the
|
** License, or (at your option) any later version.
|
** License, or (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 Lesser General
|
** or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
|
** Public License for more details.
|
** Public License for more details.
|
**
|
**
|
** You should have received a copy of the GNU Lesser General Public
|
** You should have received a copy of the GNU Lesser General Public
|
** License along with AEMB. If not, see <http:**www.gnu.org/licenses/>.
|
** License along with AEMB. If not, see <http:**www.gnu.org/licenses/>.
|
*/
|
*/
|
|
|
#ifndef LIBAEMB_H
|
#ifndef LIBAEMB_H
|
#define LIBAEMB_H
|
#define LIBAEMB_H
|
|
|
#define AEMB_TXE 0x0100
|
#define AEMB_TXE 0x0100
|
#define AEMB_TXP 0x0400
|
#define AEMB_TXP 0x0400
|
#define AEMB_TX0 0x0300
|
#define AEMB_TX0 0x0300
|
#define AEMB_TX1 0x0700
|
#define AEMB_TX1 0x0700
|
#define AEMB_MSK 0x0F00
|
#define AEMB_MSK 0x0F00
|
|
|
#define AEMB_BIP 0x0008
|
#define AEMB_BIP 0x0008
|
#define AEMB_CCC 0x0004
|
#define AEMB_CCC 0x0004
|
#define AEMB_ITE 0x0002
|
#define AEMB_ITE 0x0002
|
#define AEMB_BLE 0x0001
|
#define AEMB_BLE 0x0001
|
|
|
|
|
// Linker symbols
|
// Linker symbols
|
extern void* _STACK_SIZE;
|
extern void* _STACK_SIZE;
|
extern void* _stack_end;
|
extern void* _stack_end;
|
|
|
|
|
void aemb_hook_init () asm ("_program_init");
|
void aemb_hook_init () asm ("_program_init");
|
void aemb_hook_clean () asm ("_program_clean");
|
void aemb_hook_clean () asm ("_program_clean");
|
|
|
inline void aemb_enable_interrupt ();
|
inline void aemb_enable_interrupt ();
|
inline void aemb_disable_interrupt ();
|
inline void aemb_disable_interrupt ();
|
inline int aemb_isthread1();
|
inline int aemb_isthread1();
|
inline int aemb_isthread0();
|
inline int aemb_isthread0();
|
inline int aemb_isthreaded();
|
inline int aemb_isthreaded();
|
|
|
/*!
|
/*!
|
* Assembly macro to enable MSR_IE
|
* Assembly macro to enable MSR_IE
|
*/
|
*/
|
void aemb_enable_interrupt ()
|
void aemb_enable_interrupt ()
|
{
|
{
|
int msr, tmp;
|
int msr, tmp;
|
asm volatile ("mfs %0, rmsr;"
|
asm volatile ("mfs %0, rmsr;"
|
"ori %1, %0, 0x02;"
|
"ori %1, %0, 0x02;"
|
"mts rmsr, %1;"
|
"mts rmsr, %1;"
|
: "=r"(msr)
|
: "=r"(msr)
|
: "r" (tmp)
|
: "r" (tmp)
|
);
|
);
|
}
|
}
|
|
|
/*!
|
/*!
|
* Assembly macro to disable MSR_IE
|
* Assembly macro to disable MSR_IE
|
*/
|
*/
|
void aemb_disable_interrupt ()
|
void aemb_disable_interrupt ()
|
{
|
{
|
int msr, tmp;
|
int msr, tmp;
|
asm volatile ("mfs %0, rmsr;"
|
asm volatile ("mfs %0, rmsr;"
|
"andi %1, %0, 0xFD;"
|
"andi %1, %0, 0xFD;"
|
"mts rmsr, %1;"
|
"mts rmsr, %1;"
|
: "=r"(msr)
|
: "=r"(msr)
|
: "r" (tmp)
|
: "r" (tmp)
|
);
|
);
|
}
|
}
|
|
|
/*!
|
/*!
|
* Bootstrap Hook Override
|
* Bootstrap Hook Override
|
*/
|
*/
|
|
|
void aemb_hook_init ()
|
void aemb_hook_init ()
|
{
|
{
|
int msr, tmp;
|
int msr, tmp;
|
int stk_end, stk_siz;
|
int stk_end, stk_siz;
|
|
|
/*
|
/*
|
// Check to see if hardware threads are enabled
|
// Check to see if hardware threads are enabled
|
if (((msr & AEMB_TXE) != AEMB_TXE) ||
|
if (((msr & AEMB_TXE) != AEMB_TXE) ||
|
// Check to see if second thread is started
|
// Check to see if second thread is started
|
((msr & AEMB_TX1) == AEMB_TX1)) return;
|
((msr & AEMB_TX1) == AEMB_TX1)) return;
|
*/
|
*/
|
//return;
|
//return;
|
asm volatile ("mfs %0, rmsr;"
|
asm volatile ("mfs %0, rmsr;"
|
// Check for BIP
|
// Check for BIP
|
"andi %1, %0, %5;"
|
"andi %1, %0, %5;"
|
"xori %1, %1, %5;"
|
"xori %1, %1, %5;"
|
"beqi %1, 44;"
|
"beqi %1, 44;"
|
|
|
// Check for TXE
|
// Check for TXE
|
"andi %1, %0, %2;"
|
"andi %1, %0, %2;"
|
"xori %1, %1, %2;"
|
"xori %1, %1, %2;"
|
"bnei %1, 36;"
|
"bnei %1, 36;"
|
|
|
// Check for TX1
|
// Check for TX1
|
"andi %1, %0, %3;"
|
"andi %1, %0, %3;"
|
"xori %1, %1, %3;"
|
"xori %1, %1, %3;"
|
"beqi %1, 20;"
|
"beqi %1, 20;"
|
|
|
// reallocate stack pointer for T0
|
// reallocate stack pointer for T0
|
"ori %1, r0, %4;"
|
"ori %1, r0, %4;"
|
"sra %1, %1;"
|
"sra %1, %1;"
|
"rsubk r1, %1, r1;"
|
"rsubk r1, %1, r1;"
|
|
|
// reboot the machine
|
// reboot the machine
|
//"brki r0, _crtinit;"
|
//"brki r0, _crtinit;"
|
"brid 0;"
|
"brid 0;"
|
"nop;"
|
"nop;"
|
|
|
// clear BIP
|
// clear BIP
|
"andni %1, %0, %5;"
|
"andni %1, %0, %5;"
|
"mts rmsr, %1;"
|
"mts rmsr, %1;"
|
|
|
:"=r"(msr), "=r"(tmp)
|
:"=r"(msr), "=r"(tmp)
|
:"i"(AEMB_TXE), "i"(AEMB_TX1), "i"(&_STACK_SIZE), "i"(AEMB_BIP)
|
:"i"(AEMB_TXE), "i"(AEMB_TX1), "i"(&_STACK_SIZE), "i"(AEMB_BIP)
|
);
|
);
|
|
|
}
|
}
|
|
|
/*!
|
/*!
|
Undo the changes made by programme init
|
Undo the changes made by programme init
|
*/
|
*/
|
|
|
void aemb_hook_clean ()
|
void aemb_hook_clean ()
|
{
|
{
|
int msr, tmp;
|
int msr, tmp;
|
int stk_end, stk_siz;
|
int stk_end, stk_siz;
|
|
|
/*
|
/*
|
// Check to see if hardware threads are enabled
|
// Check to see if hardware threads are enabled
|
if (((msr & AEMB_TXE) != AEMB_TXE) ||
|
if (((msr & AEMB_TXE) != AEMB_TXE) ||
|
// Check to see if second thread is started
|
// Check to see if second thread is started
|
((msr & AEMB_TX1) == AEMB_TX1)) return;
|
((msr & AEMB_TX1) == AEMB_TX1)) return;
|
*/
|
*/
|
return;
|
return;
|
asm volatile ("mfs %0, rmsr;"
|
asm volatile ("mfs %0, rmsr;"
|
"andi %1, %0, %2;"
|
"andi %1, %0, %2;"
|
"xori %1, %1, %2;"
|
"xori %1, %1, %2;"
|
"bnei %1, 28;"
|
"bnei %1, 28;"
|
"andi %1, %0, %3;"
|
"andi %1, %0, %3;"
|
"xori %1, %1, %3;"
|
"xori %1, %1, %3;"
|
"beqi %1, 16;"
|
"beqi %1, 16;"
|
|
|
// reallocate stack pointer for T0
|
// reallocate stack pointer for T0
|
"ori %1, r0, %4;"
|
"ori %1, r0, %4;"
|
"sra %1, %1;"
|
"sra %1, %1;"
|
"addk r1, %1, r1;"
|
"addk r1, %1, r1;"
|
|
|
:"=r"(msr), "=r"(tmp)
|
:"=r"(msr), "=r"(tmp)
|
:"i"(AEMB_TXE), "i"(AEMB_TX1), "i"(&_STACK_SIZE)
|
:"i"(AEMB_TXE), "i"(AEMB_TX1), "i"(&_STACK_SIZE)
|
);
|
);
|
|
|
|
|
}
|
}
|
|
|
/* Checks if it's T1, and returns 0 if true */
|
/* Checks if it's T1, and returns 0 if true */
|
|
|
int aemb_isthread1 ()
|
int aemb_isthread1 ()
|
{
|
{
|
int msr, tmp, res;
|
int msr, tmp, res;
|
asm volatile ("mfs %0, rmsr;"
|
asm volatile ("mfs %0, rmsr;"
|
"andi %1, %0, %3;"
|
"andi %1, %0, %3;"
|
"xori %1, %1, %3;"
|
"xori %1, %1, %3;"
|
:"=r"(msr), "=r"(tmp)
|
:"=r"(msr), "=r"(tmp)
|
:"i"(AEMB_TXE), "i"(AEMB_TXP)
|
:"i"(AEMB_TXE), "i"(AEMB_TXP)
|
);
|
);
|
return tmp;
|
return tmp;
|
}
|
}
|
|
|
/* Checks if it's T0, and returns 0 if true */
|
/* Checks if it's T0, and returns 0 if true */
|
|
|
int aemb_isthread0 ()
|
int aemb_isthread0 ()
|
{
|
{
|
int msr, tmp, res;
|
int msr, tmp, res;
|
asm volatile ("mfs %0, rmsr;"
|
asm volatile ("mfs %0, rmsr;"
|
"andi %1, %0, %3;"
|
"andi %1, %0, %3;"
|
"xori %1, %1, %2;"
|
"xori %1, %1, %2;"
|
:"=r"(msr), "=r"(tmp)
|
:"=r"(msr), "=r"(tmp)
|
:"i"(AEMB_TXP), "i"(AEMB_MSK)
|
:"i"(AEMB_TXP), "i"(AEMB_MSK)
|
);
|
);
|
return tmp;
|
return tmp;
|
}
|
}
|
|
|
/* Checks if TXE is available, and returns 0 if true */
|
/* Checks if TXE is available, and returns 0 if true */
|
|
|
int aemb_isthreaded ()
|
int aemb_isthreaded ()
|
{
|
{
|
int msr, tmp, res;
|
int msr, tmp, res;
|
asm volatile ("mfs %0, rmsr;"
|
asm volatile ("mfs %0, rmsr;"
|
"andi %1, %0, %2;"
|
"andi %1, %0, %2;"
|
"xori %1, %1, %2;"
|
"xori %1, %1, %2;"
|
:"=r"(msr), "=r"(tmp)
|
:"=r"(msr), "=r"(tmp)
|
:"i"(AEMB_TXE), "i"(AEMB_MSK)
|
:"i"(AEMB_TXE), "i"(AEMB_MSK)
|
);
|
);
|
return tmp;
|
return tmp;
|
}
|
}
|
|
|
#endif
|
#endif
|
|
|
/* $Log: not supported by cvs2svn $
|
/* $Log: not supported by cvs2svn $
|
/* Revision 1.1 2007/12/11 00:44:04 sybreon
|
/* Revision 1.1 2007/12/11 00:44:04 sybreon
|
/* initial import
|
/* initial import
|
/* */
|
/* */
|
|
|