mirror of
https://github.com/oliverschmidt/contiki.git
synced 2024-12-22 10:30:13 +00:00
new mulithreading switch function.
should work on both linux and win32 platforms
This commit is contained in:
parent
5bceecfbb0
commit
c06c28c668
@ -1,9 +1,38 @@
|
|||||||
/*
|
/*
|
||||||
* This file is ripped from x86/mtarch.c of the Contiki Multi-threading library.
|
* Copyright (c) 2005, Swedish Institute of Computer Science
|
||||||
* Fredrik Osterlind <fros@sics.se>
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the Institute nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* This file is part of the Contiki operating system.
|
||||||
|
*
|
||||||
|
* @(#)$Id: cooja_mtarch.c,v 1.5 2007/04/02 08:47:28 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
#include "sys/cooja_mt.h"
|
#include "sys/cooja_mt.h"
|
||||||
|
|
||||||
struct frame {
|
struct frame {
|
||||||
@ -19,19 +48,16 @@ struct frame {
|
|||||||
unsigned long retaddr2;
|
unsigned long retaddr2;
|
||||||
unsigned long data;
|
unsigned long data;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
cooja_mtarch_init(void)
|
cooja_mtarch_init(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
cooja_mtarch_start(struct cooja_mtarch_thread *t,
|
cooja_mtarch_start(struct cooja_mtarch_thread *t,
|
||||||
void (*function)(void *), void *data)
|
void (*function)(void *), void *data)
|
||||||
{
|
{
|
||||||
|
|
||||||
struct frame *f = (struct frame *)&t->stack[COOJA_MTARCH_STACKSIZE - sizeof(struct frame)/4];
|
struct frame *f = (struct frame *)&t->stack[COOJA_MTARCH_STACKSIZE - sizeof(struct frame)/4];
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -46,11 +72,12 @@ cooja_mtarch_start(struct cooja_mtarch_thread *t,
|
|||||||
f->ebp = (unsigned long)&f->eax;
|
f->ebp = (unsigned long)&f->eax;
|
||||||
}
|
}
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
__asm__ (
|
static struct cooja_mtarch_thread *cooja_running_thread;
|
||||||
"cooja_sw:\n\t"
|
/*--------------------------------------------------------------------------*/
|
||||||
"pushl %ebp\n\t"
|
void cooja_sw(void)
|
||||||
"movl %esp, %ebp\n\t"
|
{
|
||||||
|
/* Store registers */
|
||||||
|
__asm__ (
|
||||||
"pushl %eax\n\t"
|
"pushl %eax\n\t"
|
||||||
"pushl %ebx\n\t"
|
"pushl %ebx\n\t"
|
||||||
"pushl %ecx\n\t"
|
"pushl %ecx\n\t"
|
||||||
@ -58,13 +85,18 @@ __asm__ (
|
|||||||
"pushl %esi\n\t"
|
"pushl %esi\n\t"
|
||||||
"pushl %edi\n\t"
|
"pushl %edi\n\t"
|
||||||
"pushl %ebp\n\t"
|
"pushl %ebp\n\t"
|
||||||
"pushl %ebp\n\t"
|
"pushl %ebp\n\t");
|
||||||
|
|
||||||
"movl cooja_running_thread, %eax\n\t"
|
/* Switch stack pointer */
|
||||||
|
__asm__ ("movl %0, %%eax\n\t" : : "m" (cooja_running_thread));
|
||||||
|
__asm__ (
|
||||||
"movl 0(%eax), %ebx\n\t"
|
"movl 0(%eax), %ebx\n\t"
|
||||||
"movl %esp, 0(%eax)\n\t"
|
"movl %esp, 0(%eax)\n\t"
|
||||||
"movl %ebx, %esp\n\t"
|
"movl %ebx, %esp\n\t"
|
||||||
|
);
|
||||||
|
|
||||||
|
/* Restore stored registers and return "our" way */
|
||||||
|
__asm__ (
|
||||||
"popl %ebp\n\t"
|
"popl %ebp\n\t"
|
||||||
"popl %ebp\n\t"
|
"popl %ebp\n\t"
|
||||||
"popl %edi\n\t"
|
"popl %edi\n\t"
|
||||||
@ -77,8 +109,7 @@ __asm__ (
|
|||||||
"leave\n\t"
|
"leave\n\t"
|
||||||
"ret\n\t"
|
"ret\n\t"
|
||||||
);
|
);
|
||||||
/*--------------------------------------------------------------------------*/
|
}
|
||||||
static struct cooja_mtarch_thread *cooja_running_thread;
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
cooja_mtarch_exec(struct cooja_mtarch_thread *t)
|
cooja_mtarch_exec(struct cooja_mtarch_thread *t)
|
||||||
@ -91,7 +122,6 @@ cooja_mtarch_exec(struct cooja_mtarch_thread *t)
|
|||||||
void
|
void
|
||||||
cooja_mtarch_remove(void)
|
cooja_mtarch_remove(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
@ -103,13 +133,11 @@ cooja_mtarch_yield(void)
|
|||||||
void
|
void
|
||||||
cooja_mtarch_pstop(void)
|
cooja_mtarch_pstop(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
cooja_mtarch_pstart(void)
|
cooja_mtarch_pstart(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
int
|
int
|
||||||
|
Loading…
Reference in New Issue
Block a user