RGMP 4.0 update from Qiang Yu

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5305 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2012-11-04 15:12:55 +00:00
parent 0c0168ccc0
commit 793e3d7571
14 changed files with 500 additions and 251 deletions

View File

@ -391,7 +391,7 @@
#define AFIO_MAPR2_TIM14_REMAP (1 << 9) /* Bit 9: TIM14 remapping */
#define AFIO_MAPR2_FSMC_NADV (1 << 10) /* Bit 10: NADV connect/disconnect */
#ifdef CONFIG_STM32_VALUELINE
# define AFIO_MAPR2_TIM76_DAC_DMA_REMAP (1 << 11) /* Bit 11: TIM67_DAC DMA remapping */
# define AFIO_MAPR2_TIM67_DAC_DMA_REMAP (1 << 11) /* Bit 11: TIM67_DAC DMA remapping */
# define AFIO_MAPR2_TIM12_REMAP (1 << 12) /* Bit 12: TIM12 remapping */
# define AFIO_MAPR2_MISC_REMAP (1 << 13) /* Bit 13: Miscellaneous features remapping */
#endif

View File

@ -46,7 +46,6 @@
#include <nuttx/sched.h>
struct up_wait {
struct up_wait *next;
_TCB *task;

View File

@ -44,12 +44,13 @@
#ifndef __ASSEMBLY__
#include <rgmp/spinlock.h>
#include <arch/types.h>
#include <rgmp/trap.h>
#include <rgmp/arch/arch.h>
struct xcptcontext {
struct Trapframe *tf;
struct rgmp_context ctx;
// for signal using
unsigned int save_eip;
unsigned int save_eflags;
@ -63,12 +64,14 @@ extern int nest_irq;
static inline irqstate_t irqsave(void)
{
return pushcli();
unsigned long flags;
local_irq_save(flags);
return flags;
}
static inline void irqrestore(irqstate_t flags)
{
popcli(flags);
local_irq_restore(flags);
}
#endif /* !__ASSEMBLY__ */

View File

@ -57,6 +57,200 @@ extern "C" {
#include <rgmp/math.h>
// following functions are not implemented by RGMP math library
// don't use them
// declared here for cmath
/* General Functions ********************************************************/
float ceilf (float x);
#if CONFIG_HAVE_DOUBLE
//double ceil (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double ceill (long double x);
#endif
float floorf(float x);
#if CONFIG_HAVE_DOUBLE
//double floor (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double floorl(long double x);
#endif
float fabsf (float x);
#if CONFIG_HAVE_DOUBLE
//double fabs (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double fabsl (long double x);
#endif
float modff (float x, float *iptr);
#if CONFIG_HAVE_DOUBLE
//double modf (double x, double *iptr);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double modfl (long double x, long double *iptr);
#endif
float fmodf (float x, float div);
#if CONFIG_HAVE_DOUBLE
//double fmod (double x, double div);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double fmodl (long double x, long double div);
#endif
/* Exponential and Logarithmic Functions ************************************/
float powf (float b, float e);
#if CONFIG_HAVE_DOUBLE
//double pow (double b, double e);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double powl (long double b, long double e);
#endif
float expf (float x);
#if CONFIG_HAVE_DOUBLE
//double exp (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double expl (long double x);
#endif
float logf (float x);
#if CONFIG_HAVE_DOUBLE
//double log (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double logl (long double x);
#endif
float log10f(float x);
#if CONFIG_HAVE_DOUBLE
//double log10 (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double log10l(long double x);
#endif
float log2f (float x);
#if CONFIG_HAVE_DOUBLE
//double log2 (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double log2l (long double x);
#endif
float sqrtf (float x);
#if CONFIG_HAVE_DOUBLE
//double sqrt (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double sqrtl (long double x);
#endif
float ldexpf(float x, int n);
#if CONFIG_HAVE_DOUBLE
double ldexp (double x, int n);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double ldexpl(long double x, int n);
#endif
float frexpf(float x, int *exp);
#if CONFIG_HAVE_DOUBLE
double frexp (double x, int *exp);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double frexpl(long double x, int *exp);
#endif
/* Trigonometric Functions **************************************************/
float sinf (float x);
#if CONFIG_HAVE_DOUBLE
//double sin (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double sinl (long double x);
#endif
float cosf (float x);
#if CONFIG_HAVE_DOUBLE
//double cos (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double cosl (long double x);
#endif
float tanf (float x);
#if CONFIG_HAVE_DOUBLE
//double tan (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double tanl (long double x);
#endif
float asinf (float x);
#if CONFIG_HAVE_DOUBLE
//double asin (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double asinl (long double x);
#endif
float acosf (float x);
#if CONFIG_HAVE_DOUBLE
//double acos (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double acosl (long double x);
#endif
float atanf (float x);
#if CONFIG_HAVE_DOUBLE
//double atan (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double atanl (long double x);
#endif
float atan2f(float y, float x);
#if CONFIG_HAVE_DOUBLE
//double atan2 (double y, double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double atan2l(long double y, long double x);
#endif
float sinhf (float x);
#if CONFIG_HAVE_DOUBLE
//double sinh (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double sinhl (long double x);
#endif
float coshf (float x);
#if CONFIG_HAVE_DOUBLE
//double cosh (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double coshl (long double x);
#endif
float tanhf (float x);
#if CONFIG_HAVE_DOUBLE
//double tanh (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double tanhl (long double x);
#endif
#undef EXTERN
#ifdef __cplusplus
}

View File

@ -58,9 +58,6 @@
* use _Bool8 as the underlying type.
*/
#ifndef CONFIG_ARCH_RGMP
#define bool _Bool8
#endif
#define true 1
#define false 0
@ -82,8 +79,6 @@
* as the underlying type.
*/
#ifndef CONFIG_ARCH_RGMP
typedef uint8_t _Bool8;
#endif
#endif /* __ARCH_RGMP_INCLUDE_STDBOOL_H */

View File

@ -42,8 +42,11 @@
#ifndef __ASSEMBLY__
#include <rgmp/arch/hpet.h>
#ifdef __cplusplus
extern "C" {
#endif
#include <rgmp/arch/hpet.h>
static inline void up_mdelay(uint32_t msec)
{
@ -52,9 +55,13 @@ static inline void up_mdelay(uint32_t msec)
static inline void up_udelay(uint32_t usec)
{
hpet_udelay(usec*1000);
hpet_ndelay(usec*1000);
}
#ifdef __cplusplus
}
#endif
#endif /* !__ASSEMBLY__ */
#endif

View File

@ -42,18 +42,21 @@ RGMP_ARCH_CSRCS := $(addprefix $(CONFIG_RGMP_SUBARCH)/,$(RGMP_ARCH_CSRCS))
CFLAGS += -I$(TOPDIR)/sched -I$(TOPDIR)/fs
ASRCS = $(RGMP_ARCH_ASRCS)
CSRCS = nuttx.c rgmp.c bridge.c $(RGMP_ARCH_CSRCS)
CSRCS = nuttx.c cxx.c $(RGMP_ARCH_CSRCS)
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS)
LINKSRCS = rgmp.c bridge.c
LINKOBJS = $(LINKSRCS:.c=$(OBJEXT))
LDFLAGS += -T$(RGMPLKSCPT)
LDPATHS = $(addprefix -L$(TOPDIR)/,$(dir $(LINKLIBS)))
LDLIBS = $(patsubst lib%,-l%,$(basename $(notdir $(LINKLIBS))))
LDPATHS += -L$(RGMPLIBDIR)
LDLIBS += -lrgmp -lm -ltest $(shell gcc -print-libgcc-file-name)
LDLIBS += -lrgmp $(shell $(CC) -print-libgcc-file-name)
all: libarch$(LIBEXT)
@ -74,9 +77,9 @@ libarch$(LIBEXT): $(OBJS)
# Generate the final NuttX binary by linking the host-specific objects with the NuttX
# specific objects (with munged names)
nuttx$(EXEEXT):
nuttx$(EXEEXT): $(LINKOBJS)
@echo "LD: nuttx$(EXEEXT)"
@$(LD) $(LDFLAGS) $(LDPATHS) --start-group $(LDLIBS) --end-group -o $(TOPDIR)/$@
@$(LD) $(LDFLAGS) $(LDPATHS) $(LINKOBJS) --start-group $(LDLIBS) $(EXTRA_LIBS) --end-group -o $(TOPDIR)/$@
@$(OBJDUMP) -S $(TOPDIR)/$@ > $(TOPDIR)/nuttx.asm
@$(NM) -n $(TOPDIR)/$@ > $(TOPDIR)/nuttx.sym
@$(OBJCOPY) -S -O binary $(TOPDIR)/$@ nuttx.img
@ -88,14 +91,15 @@ export_head:
# Dependencies
.depend: Makefile $(SRCS)
@$(MKDEP) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
.depend: Makefile $(SRCS) $(LINKSRCS)
@$(MKDEP) $(CC) -- $(CFLAGS) -- $(SRCS) $(LINKSRCS) >Make.dep
@touch $@
depend: .depend
clean:
@rm $(TOPDIR)/kernel.img nuttx.img
@rm -f $(TOPDIR)/arch/rgmp/src/x86/*.o
@rm -f $(TOPDIR)/kernel.img nuttx.img
@rm -f libarch$(LIBEXT) *~ .*.swp
$(call CLEAN)

View File

@ -44,25 +44,37 @@
#include <fs_internal.h>
#include <queue.h>
#include <arch/irq.h>
#include <rgmp/rtos.h>
#include <rgmp/bridge.h>
#include <rgmp/string.h>
#include <rgmp/stdio.h>
struct bridge {
struct rgmp_bridge *b;
sem_t rd_lock;
sem_t wr_lock;
};
static ssize_t up_bridge_read(struct file *filp, char *buffer, size_t len)
{
struct rgmp_bridge *b;
ssize_t ret;
struct bridge *b = filp->f_inode->i_private;
b = filp->f_inode->i_private;
return rgmp_bridge_read(b, buffer, len);
sem_wait(&b->rd_lock);
ret = rgmp_bridge_read(b->b, buffer, len, 0);
sem_post(&b->rd_lock);
return ret;
}
static ssize_t up_bridge_write(struct file *filp, const char *buffer, size_t len)
{
struct rgmp_bridge *b;
ssize_t ret;
struct bridge *b = filp->f_inode->i_private;
b = filp->f_inode->i_private;
return rgmp_bridge_write(b, (char *)buffer, len);
sem_wait(&b->wr_lock);
ret = rgmp_bridge_write(b->b, (char *)buffer, len, 0);
sem_post(&b->wr_lock);
return ret;
}
static int up_bridge_open(struct file *filp)
@ -75,30 +87,45 @@ static int up_bridge_close(struct file *filp)
return 0;
}
static const struct file_operations up_bridge_fops =
{
static const struct file_operations up_bridge_fops = {
.read = up_bridge_read,
.write = up_bridge_write,
.open = up_bridge_open,
.close = up_bridge_close,
};
void up_register_bridges(void)
int rtos_bridge_init(struct rgmp_bridge *b)
{
int err;
struct bridge *bridge;
char path[30] = {'/', 'd', 'e', 'v', '/'};
struct rgmp_bridge *b;
for (b=bridge_list.next; b!=NULL; b=b->next) {
if ((bridge = kmalloc(sizeof(*bridge))) == NULL)
goto err0;
bridge->b = b;
if ((err = sem_init(&bridge->rd_lock, 0, 1)) == ERROR)
goto err1;
if ((err = sem_init(&bridge->wr_lock, 0, 1)) == ERROR)
goto err1;
// make rgmp_bridge0 to be the console
if (strcmp(b->vdev->name, "rgmp_bridge0") == 0)
strlcpy(path+5, "console", 25);
strlcpy(path + 5, "console", 25);
else
strlcpy(path+5, b->vdev->name, 25);
err = register_driver(path, &up_bridge_fops, 0666, b);
if (err == ERROR)
strlcpy(path + 5, b->vdev->name, 25);
if ((err = register_driver(path, &up_bridge_fops, 0666, bridge)) == ERROR) {
cprintf("NuttX: register bridge %s fail\n", b->vdev->name);
}
goto err1;
}
return 0;
err1:
kfree(bridge);
err0:
return -1;
}

19
arch/rgmp/src/cxx.c Normal file
View File

@ -0,0 +1,19 @@
#include <rgmp/assert.h>
#include <rgmp/stdio.h>
int stderr = 2;
void __stack_chk_fail_local(void)
{
panic("stack check fail\n");
}
int __sprintf_chk(char *str, int flag, size_t strlen, const char *format)
{
return snprintf(str, strlen, format);
}
int dl_iterate_phdr(void* arg1, void* arg2)
{
return -1;
}

View File

@ -38,13 +38,12 @@
****************************************************************************/
#include <rgmp/boot.h>
#include <rgmp/pmap.h>
#include <rgmp/cxx.h>
#include <rgmp/memlayout.h>
#include <rgmp/allocator.h>
#include <rgmp/assert.h>
#include <rgmp/spinlock.h>
#include <rgmp/string.h>
#include <rgmp/arch/arch.h>
#include <rgmp/arch/console.h>
#include <nuttx/sched.h>
#include <nuttx/kmalloc.h>
@ -67,37 +66,34 @@ static inline void up_switchcontext(_TCB *ctcb, _TCB *ntcb)
{
// do nothing if two tasks are the same
if (ctcb == ntcb)
return;
return;
// this function can not be called in interrupt
if (up_interrupt_context()) {
panic("%s: try to switch context in interrupt\n", __func__);
panic("%s: try to switch context in interrupt\n", __func__);
}
// start switch
current_task = ntcb;
rgmp_context_switch(ctcb?&ctcb->xcp.tf:NULL, ntcb->xcp.tf);
rgmp_context_switch(ctcb ? &ctcb->xcp.ctx : NULL, &ntcb->xcp.ctx);
}
void up_initialize(void)
{
extern pidhash_t g_pidhash[];
extern void up_register_bridges(void);
extern void vnet_initialize(void);
extern void vdev_init(void);
extern void nuttx_arch_init(void);
// intialize the current_task to g_idletcb
current_task = g_pidhash[PIDHASH(0)].tcb;
// setup console
up_register_bridges();
// OS memory alloc system is ready
use_os_kmalloc = 1;
#ifdef CONFIG_NET_VNET
// setup vnet device
vnet_initialize();
#endif
// rgmp vdev init
vdev_init();
nuttx_arch_init();
nuttx_arch_init();
// enable interrupt
local_irq_enable();
@ -110,8 +106,9 @@ void up_idle(void)
void up_allocate_heap(void **heap_start, size_t *heap_size)
{
void *boot_freemem = boot_alloc(0, sizeof(int));
*heap_start = boot_freemem;
*heap_size = KERNBASE + boot_param.mem_size - (uint32_t)boot_freemem;
*heap_size = KERNBASE + kmem_size - (uint32_t)boot_freemem;
}
int up_create_stack(_TCB *tcb, size_t stack_size)
@ -128,16 +125,16 @@ int up_create_stack(_TCB *tcb, size_t stack_size)
uint32_t *stack_alloc_ptr = (uint32_t*)kmalloc(adj_stack_size);
if (stack_alloc_ptr) {
/* This is the address of the last word in the allocation */
/* This is the address of the last word in the allocation */
adj_stack_ptr = &stack_alloc_ptr[adj_stack_words - 1];
adj_stack_ptr = &stack_alloc_ptr[adj_stack_words - 1];
/* Save the values in the TCB */
/* Save the values in the TCB */
tcb->adj_stack_size = adj_stack_size;
tcb->stack_alloc_ptr = stack_alloc_ptr;
tcb->adj_stack_ptr = (void *)((unsigned int)adj_stack_ptr & ~7);
ret = OK;
tcb->adj_stack_size = adj_stack_size;
tcb->stack_alloc_ptr = stack_alloc_ptr;
tcb->adj_stack_ptr = (void *)((unsigned int)adj_stack_ptr & ~7);
ret = OK;
}
return ret;
}
@ -164,7 +161,7 @@ int up_use_stack(_TCB *tcb, void *stack, size_t stack_size)
void up_release_stack(_TCB *dtcb)
{
if (dtcb->stack_alloc_ptr) {
free(dtcb->stack_alloc_ptr);
free(dtcb->stack_alloc_ptr);
}
dtcb->stack_alloc_ptr = NULL;
@ -199,43 +196,43 @@ void up_block_task(_TCB *tcb, tstate_t task_state)
{
/* Verify that the context switch can be performed */
if ((tcb->task_state < FIRST_READY_TO_RUN_STATE) ||
(tcb->task_state > LAST_READY_TO_RUN_STATE)) {
warn("%s: task sched error\n", __func__);
return;
(tcb->task_state > LAST_READY_TO_RUN_STATE)) {
warn("%s: task sched error\n", __func__);
return;
}
else {
_TCB *rtcb = current_task;
bool switch_needed;
_TCB *rtcb = current_task;
bool switch_needed;
/* Remove the tcb task from the ready-to-run list. If we
* are blocking the task at the head of the task list (the
* most likely case), then a context switch to the next
* ready-to-run task is needed. In this case, it should
* also be true that rtcb == tcb.
*/
switch_needed = sched_removereadytorun(tcb);
/* Remove the tcb task from the ready-to-run list. If we
* are blocking the task at the head of the task list (the
* most likely case), then a context switch to the next
* ready-to-run task is needed. In this case, it should
* also be true that rtcb == tcb.
*/
switch_needed = sched_removereadytorun(tcb);
/* Add the task to the specified blocked task list */
sched_addblocked(tcb, (tstate_t)task_state);
/* Add the task to the specified blocked task list */
sched_addblocked(tcb, (tstate_t)task_state);
/* Now, perform the context switch if one is needed */
if (switch_needed) {
_TCB *nexttcb;
// this part should not be executed in interrupt context
if (up_interrupt_context()) {
panic("%s: %d\n", __func__, __LINE__);
}
// If there are any pending tasks, then add them to the g_readytorun
// task list now. It should be the up_realease_pending() called from
// sched_unlock() to do this for disable preemption. But it block
// itself, so it's OK.
if (g_pendingtasks.head) {
warn("Disable preemption failed for task block itself\n");
sched_mergepending();
}
nexttcb = (_TCB*)g_readytorun.head;
// context switch
up_switchcontext(rtcb, nexttcb);
/* Now, perform the context switch if one is needed */
if (switch_needed) {
_TCB *nexttcb;
// this part should not be executed in interrupt context
if (up_interrupt_context()) {
panic("%s: %d\n", __func__, __LINE__);
}
// If there are any pending tasks, then add them to the g_readytorun
// task list now. It should be the up_realease_pending() called from
// sched_unlock() to do this for disable preemption. But it block
// itself, so it's OK.
if (g_pendingtasks.head) {
warn("Disable preemption failed for task block itself\n");
sched_mergepending();
}
nexttcb = (_TCB*)g_readytorun.head;
// context switch
up_switchcontext(rtcb, nexttcb);
}
}
}
@ -259,31 +256,31 @@ void up_unblock_task(_TCB *tcb)
{
/* Verify that the context switch can be performed */
if ((tcb->task_state < FIRST_BLOCKED_STATE) ||
(tcb->task_state > LAST_BLOCKED_STATE)) {
warn("%s: task sched error\n", __func__);
return;
(tcb->task_state > LAST_BLOCKED_STATE)) {
warn("%s: task sched error\n", __func__);
return;
}
else {
_TCB *rtcb = current_task;
_TCB *rtcb = current_task;
/* Remove the task from the blocked task list */
sched_removeblocked(tcb);
/* Remove the task from the blocked task list */
sched_removeblocked(tcb);
/* Reset its timeslice. This is only meaningful for round
* robin tasks but it doesn't here to do it for everything
*/
/* Reset its timeslice. This is only meaningful for round
* robin tasks but it doesn't here to do it for everything
*/
#if CONFIG_RR_INTERVAL > 0
tcb->timeslice = CONFIG_RR_INTERVAL / MSEC_PER_TICK;
tcb->timeslice = CONFIG_RR_INTERVAL / MSEC_PER_TICK;
#endif
// Add the task in the correct location in the prioritized
// g_readytorun task list.
if (sched_addreadytorun(tcb) && !up_interrupt_context()) {
/* The currently active task has changed! */
_TCB *nexttcb = (_TCB*)g_readytorun.head;
// context switch
up_switchcontext(rtcb, nexttcb);
}
// Add the task in the correct location in the prioritized
// g_readytorun task list.
if (sched_addreadytorun(tcb) && !up_interrupt_context()) {
/* The currently active task has changed! */
_TCB *nexttcb = (_TCB*)g_readytorun.head;
// context switch
up_switchcontext(rtcb, nexttcb);
}
}
}
@ -298,11 +295,11 @@ void up_release_pending(void)
/* Merge the g_pendingtasks list into the g_readytorun task list */
if (sched_mergepending()) {
/* The currently active task has changed! */
_TCB *nexttcb = (_TCB*)g_readytorun.head;
/* The currently active task has changed! */
_TCB *nexttcb = (_TCB*)g_readytorun.head;
// context switch
up_switchcontext(rtcb, nexttcb);
// context switch
up_switchcontext(rtcb, nexttcb);
}
}
@ -311,54 +308,54 @@ void up_reprioritize_rtr(_TCB *tcb, uint8_t priority)
/* Verify that the caller is sane */
if (tcb->task_state < FIRST_READY_TO_RUN_STATE ||
tcb->task_state > LAST_READY_TO_RUN_STATE
tcb->task_state > LAST_READY_TO_RUN_STATE
#if SCHED_PRIORITY_MIN > UINT8_MIN
|| priority < SCHED_PRIORITY_MIN
|| priority < SCHED_PRIORITY_MIN
#endif
#if SCHED_PRIORITY_MAX < UINT8_MAX
|| priority > SCHED_PRIORITY_MAX
|| priority > SCHED_PRIORITY_MAX
#endif
) {
warn("%s: task sched error\n", __func__);
return;
) {
warn("%s: task sched error\n", __func__);
return;
}
else {
_TCB *rtcb = current_task;
bool switch_needed;
_TCB *rtcb = current_task;
bool switch_needed;
/* Remove the tcb task from the ready-to-run list.
* sched_removereadytorun will return true if we just
* remove the head of the ready to run list.
*/
switch_needed = sched_removereadytorun(tcb);
/* Remove the tcb task from the ready-to-run list.
* sched_removereadytorun will return true if we just
* remove the head of the ready to run list.
*/
switch_needed = sched_removereadytorun(tcb);
/* Setup up the new task priority */
tcb->sched_priority = (uint8_t)priority;
/* Setup up the new task priority */
tcb->sched_priority = (uint8_t)priority;
/* Return the task to the specified blocked task list.
* sched_addreadytorun will return true if the task was
* added to the new list. We will need to perform a context
* switch only if the EXCLUSIVE or of the two calls is non-zero
* (i.e., one and only one the calls changes the head of the
* ready-to-run list).
*/
switch_needed ^= sched_addreadytorun(tcb);
/* Return the task to the specified blocked task list.
* sched_addreadytorun will return true if the task was
* added to the new list. We will need to perform a context
* switch only if the EXCLUSIVE or of the two calls is non-zero
* (i.e., one and only one the calls changes the head of the
* ready-to-run list).
*/
switch_needed ^= sched_addreadytorun(tcb);
/* Now, perform the context switch if one is needed */
if (switch_needed && !up_interrupt_context()) {
_TCB *nexttcb;
// If there are any pending tasks, then add them to the g_readytorun
// task list now. It should be the up_realease_pending() called from
// sched_unlock() to do this for disable preemption. But it block
// itself, so it's OK.
if (g_pendingtasks.head) {
warn("Disable preemption failed for reprioritize task\n");
sched_mergepending();
/* Now, perform the context switch if one is needed */
if (switch_needed && !up_interrupt_context()) {
_TCB *nexttcb;
// If there are any pending tasks, then add them to the g_readytorun
// task list now. It should be the up_realease_pending() called from
// sched_unlock() to do this for disable preemption. But it block
// itself, so it's OK.
if (g_pendingtasks.head) {
warn("Disable preemption failed for reprioritize task\n");
sched_mergepending();
}
nexttcb = (_TCB*)g_readytorun.head;
// context switch
up_switchcontext(rtcb, nexttcb);
nexttcb = (_TCB*)g_readytorun.head;
// context switch
up_switchcontext(rtcb, nexttcb);
}
}
}
@ -390,26 +387,26 @@ void up_assert(const uint8_t *filename, int line)
// which will stop the OS
// if in user space just terminate the task
if (up_interrupt_context() || current_task->pid == 0) {
panic("%s: %d\n", __func__, __LINE__);
panic("%s: %d\n", __func__, __LINE__);
}
else {
exit(EXIT_FAILURE);
exit(EXIT_FAILURE);
}
}
void up_assert_code(const uint8_t *filename, int line, int code)
{
fprintf(stderr, "Assertion failed at file:%s line: %d error code: %d\n",
filename, line, code);
filename, line, code);
// in interrupt context or idle task means kernel error
// which will stop the OS
// if in user space just terminate the task
if (up_interrupt_context() || current_task->pid == 0) {
panic("%s: %d\n", __func__, __LINE__);
panic("%s: %d\n", __func__, __LINE__);
}
else {
exit(EXIT_FAILURE);
exit(EXIT_FAILURE);
}
}
@ -420,38 +417,38 @@ void up_schedule_sigaction(_TCB *tcb, sig_deliver_t sigdeliver)
{
/* Refuse to handle nested signal actions */
if (!tcb->xcp.sigdeliver) {
int flags;
int flags;
/* Make sure that interrupts are disabled */
flags = pushcli();
/* Make sure that interrupts are disabled */
local_irq_save(flags);
// First, handle some special cases when the signal is
// being delivered to the currently executing task.
if (tcb == current_task) {
// CASE 1: We are not in an interrupt handler and
// a task is signalling itself for some reason.
if (!up_interrupt_context()) {
// In this case just deliver the signal now.
sigdeliver(tcb);
}
// CASE 2: We are in an interrupt handler AND the
// interrupted task is the same as the one that
// must receive the signal.
else {
tcb->xcp.sigdeliver = sigdeliver;
// First, handle some special cases when the signal is
// being delivered to the currently executing task.
if (tcb == current_task) {
// CASE 1: We are not in an interrupt handler and
// a task is signalling itself for some reason.
if (!up_interrupt_context()) {
// In this case just deliver the signal now.
sigdeliver(tcb);
}
// CASE 2: We are in an interrupt handler AND the
// interrupted task is the same as the one that
// must receive the signal.
else {
tcb->xcp.sigdeliver = sigdeliver;
}
}
// Otherwise, we are (1) signaling a task is not running
// from an interrupt handler or (2) we are not in an
// interrupt handler and the running task is signalling
// some non-running task.
else {
tcb->xcp.sigdeliver = sigdeliver;
push_xcptcontext(&tcb->xcp);
// Otherwise, we are (1) signaling a task is not running
// from an interrupt handler or (2) we are not in an
// interrupt handler and the running task is signalling
// some non-running task.
else {
tcb->xcp.sigdeliver = sigdeliver;
push_xcptcontext(&tcb->xcp);
}
popcli(flags);
local_irq_restore(flags);
}
}
@ -461,7 +458,7 @@ void up_schedule_sigaction(_TCB *tcb, sig_deliver_t sigdeliver)
bool up_interrupt_context(void)
{
if (nest_irq)
return true;
return true;
return false;
}
@ -496,6 +493,16 @@ void up_sigdeliver(struct Trapframe *tf)
local_irq_disable();
}
#if defined(CONFIG_HAVE_CXX) && defined(CONFIG_HAVE_CXXINITIALIZE)
void up_cxxinitialize(void)
{
rgmp_cxx_init();
}
#endif

View File

@ -38,7 +38,7 @@
****************************************************************************/
#include <rgmp/trap.h>
#include <rgmp/mmu.h>
#include <rgmp/rtos.h>
#include <rgmp/arch/arch.h>
#include <nuttx/config.h>
@ -56,9 +56,9 @@ int nest_irq = 0;
// the default time is 10ms
#ifdef CONFIG_MSEC_PER_TICK
unsigned int rtos_tick_time = CONFIG_MSEC_PER_TICK;
const unsigned int rtos_tick_time = CONFIG_MSEC_PER_TICK;
#else
unsigned int rtos_tick_time = 10;
const unsigned int rtos_tick_time = 10;
#endif
void rtos_entry(void)
@ -76,80 +76,71 @@ void rtos_free_page(void *page)
free(page);
}
void *rtos_kmalloc(int size)
{
return kmalloc(size);
}
void rtos_kfree(void *addr)
{
kfree(addr);
}
/**
* The interrupt can be nested. The pair of rtos_enter_interrupt()
* and rtos_exit_interrupt() make sure the context switch is
* performed only in the last IRQ exit.
*/
void rtos_enter_interrupt(struct Trapframe *tf)
void rtos_enter_interrupt(void)
{
nest_irq++;
}
void rtos_exit_interrupt(struct Trapframe *tf)
void rtos_exit_interrupt(void)
{
local_irq_disable();
nest_irq--;
if (!nest_irq) {
_TCB *rtcb = current_task;
_TCB *ntcb;
_TCB *rtcb = current_task;
_TCB *ntcb;
if (rtcb->xcp.sigdeliver) {
rtcb->xcp.tf = tf;
push_xcptcontext(&rtcb->xcp);
}
ntcb = (_TCB*)g_readytorun.head;
// switch needed
if (rtcb != ntcb) {
rtcb->xcp.tf = tf;
current_task = ntcb;
rgmp_pop_tf(ntcb->xcp.tf);
}
if (rtcb->xcp.sigdeliver) {
rtcb->xcp.ctx.tf = current_regs;
push_xcptcontext(&rtcb->xcp);
}
ntcb = (_TCB*)g_readytorun.head;
// switch needed
if (rtcb != ntcb) {
rtcb->xcp.ctx.tf = current_regs;
current_task = ntcb;
rgmp_switch_to(&ntcb->xcp.ctx);
}
}
}
void rtos_timer_isr(struct Trapframe *tf)
void rtos_timer_isr(void *data)
{
sched_process_timer();
}
/**
* RTOS mutex operation
*/
const int rtos_mutex_size = sizeof(sem_t);
void rtos_mutex_init(void *lock)
{
sem_init(lock, 0, 1);
}
int rtos_mutex_lock(void *lock)
{
return sem_wait(lock);
}
int rtos_mutex_unlock(void *lock)
{
return sem_post(lock);
}
/**
* RTOS semaphore operation
*/
const int rtos_semaphore_size = sizeof(sem_t);
void rtos_sem_init(void *sem, int val)
int rtos_sem_init(struct semaphore *sem, int val)
{
sem_init(sem, 0, val);
if ((sem->sem = kmalloc(sizeof(sem_t))) == NULL)
return -1;
return sem_init(sem->sem, 0, val);
}
int rtos_sem_up(void *sem)
int rtos_sem_up(struct semaphore *sem)
{
return sem_post(sem);
return sem_post(sem->sem);
}
int rtos_sem_down(void *sem)
int rtos_sem_down(struct semaphore *sem)
{
return sem_wait(sem);
return sem_wait(sem->sem);
}
void rtos_stop_running(void)
@ -161,8 +152,16 @@ void rtos_stop_running(void)
nuttx_arch_exit();
while(1) {
arch_hlt();
arch_hlt();
}
}
int rtos_vnet_init(struct rgmp_vnet *vnet)
{
extern int vnet_init(struct rgmp_vnet *vnet);
return vnet_init(vnet);
}

View File

@ -37,7 +37,7 @@
*
****************************************************************************/
#include <rgmp/pmap.h>
#include <rgmp/mmu.h>
#include <rgmp/string.h>
#include <rgmp/arch/fpu.h>
@ -75,32 +75,27 @@ void up_initial_state(_TCB *tcb)
{
struct Trapframe *tf;
if (tcb->pid != 0) {
tf = (struct Trapframe *)tcb->adj_stack_ptr-1;
memset(tf, 0, sizeof(struct Trapframe));
tf->tf_fpu = rgmp_fpu_init_regs;
tf->tf_eflags = 0x00000202;
tf->tf_cs = GD_KT;
tf->tf_ds = GD_KD;
tf->tf_es = GD_KD;
tf->tf_eip = (uint32_t)tcb->start;
tcb->xcp.tf = tf;
if (tcb->pid) {
tf = (struct Trapframe *)tcb->adj_stack_ptr - 1;
rgmp_setup_context(&tcb->xcp.ctx, tf, tcb->start, 1);
}
else
rgmp_setup_context(&tcb->xcp.ctx, NULL, NULL, 0);
}
void push_xcptcontext(struct xcptcontext *xcp)
{
xcp->save_eip = xcp->tf->tf_eip;
xcp->save_eflags = xcp->tf->tf_eflags;
xcp->save_eip = xcp->ctx.tf->tf_eip;
xcp->save_eflags = xcp->ctx.tf->tf_eflags;
// set up signal entry with interrupts disabled
xcp->tf->tf_eip = (uint32_t)up_sigentry;
xcp->tf->tf_eflags = 0;
xcp->ctx.tf->tf_eip = (uint32_t)up_sigentry;
xcp->ctx.tf->tf_eflags = 0;
}
void pop_xcptcontext(struct xcptcontext *xcp)
{
xcp->tf->tf_eip = xcp->save_eip;
xcp->tf->tf_eflags = xcp->save_eflags;
xcp->ctx.tf->tf_eip = xcp->save_eip;
xcp->ctx.tf->tf_eflags = xcp->save_eflags;
}

View File

@ -57,7 +57,6 @@
#include <arch/com.h>
#include <rgmp/trap.h>
#include <rgmp/arch/console.h>
/****************************************************************************
* Pre-processor Definitions
@ -129,7 +128,7 @@ static int up_setup(struct uart_dev_s *dev);
static void up_shutdown(struct uart_dev_s *dev);
static int up_attach(struct uart_dev_s *dev);
static void up_detach(struct uart_dev_s *dev);
static irqreturn_t up_com_int_handler(struct Trapframe *tf, void *dev_id);
static irqreturn_t up_com_int_handler(int irq, void *dev_id);
static int up_ioctl(struct file *filep, int cmd, unsigned long arg);
static int up_receive(struct uart_dev_s *dev, unsigned int *status);
static void up_rxint(struct uart_dev_s *dev, bool enable);
@ -345,7 +344,7 @@ static void up_detach(struct uart_dev_s *dev)
*
****************************************************************************/
static irqreturn_t up_com_int_handler(struct Trapframe *tf, void *dev_id)
static irqreturn_t up_com_int_handler(int irq, void *dev_id)
{
struct uart_dev_s *dev = dev_id;
struct up_dev_s *priv = dev->priv;
@ -622,6 +621,7 @@ void up_serialinit(void)
* writes
*
****************************************************************************/
extern void cons_putc(int c);
int up_putc(int ch)
{

View File

@ -39,11 +39,11 @@
.globl up_sigentry
up_sigentry:
subl $172, %esp # 172 is the size of TrapFrame
subl $172, %esp # 172 is the size of Trapframe without cross ring part
pushl %esp
movl %esp, %eax
call up_sigdeliver
addl $8, %esp # skip parameter and current_task
addl $8, %esp # skip parameter and tf_curregs
frstor 0(%esp)
addl $108, %esp
popal