support for contiki-node simulation on 64-bit architectures (contributed by Jesper Karlsson and David Gustafsson)
This commit is contained in:
parent
eb2ecc69a2
commit
6150d13254
1 changed files with 99 additions and 31 deletions
|
@ -28,15 +28,39 @@
|
||||||
*
|
*
|
||||||
* This file is part of the Contiki operating system.
|
* This file is part of the Contiki operating system.
|
||||||
*
|
*
|
||||||
* @(#)$Id: cooja_mtarch.c,v 1.5 2007/04/02 08:47:28 fros4943 Exp $
|
* @(#)$Id: cooja_mtarch.c,v 1.6 2008/11/28 16:41:26 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#include <limits.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "sys/cooja_mt.h"
|
#include "sys/cooja_mt.h"
|
||||||
|
|
||||||
|
#ifndef __WORDSIZE
|
||||||
|
#define __WORDSIZE 32
|
||||||
|
#endif /* __WORDSIZE */
|
||||||
|
|
||||||
|
#ifndef ON_64BIT_ARCH
|
||||||
|
#if __WORDSIZE == 64
|
||||||
|
#define ON_64BIT_ARCH 1
|
||||||
|
#else /* ON_64BIT_ARCH */
|
||||||
|
#define ON_64BIT_ARCH 0
|
||||||
|
#endif /* __WORDSIZE == 64 */
|
||||||
|
#endif /* ON_64BIT_ARCH */
|
||||||
|
|
||||||
struct frame {
|
struct frame {
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
|
#if ON_64BIT_ARCH
|
||||||
|
unsigned long rbp;
|
||||||
|
unsigned long rdi;
|
||||||
|
unsigned long rsi;
|
||||||
|
unsigned long rdx;
|
||||||
|
unsigned long rcx;
|
||||||
|
unsigned long rbx;
|
||||||
|
unsigned long rax;
|
||||||
|
#else /* ON_64BIT_ARCH */
|
||||||
unsigned long ebp;
|
unsigned long ebp;
|
||||||
unsigned long edi;
|
unsigned long edi;
|
||||||
unsigned long esi;
|
unsigned long esi;
|
||||||
|
@ -44,6 +68,7 @@ struct frame {
|
||||||
unsigned long ecx;
|
unsigned long ecx;
|
||||||
unsigned long ebx;
|
unsigned long ebx;
|
||||||
unsigned long eax;
|
unsigned long eax;
|
||||||
|
#endif /* ON_64BIT_ARCH */
|
||||||
unsigned long retaddr;
|
unsigned long retaddr;
|
||||||
unsigned long retaddr2;
|
unsigned long retaddr2;
|
||||||
unsigned long data;
|
unsigned long data;
|
||||||
|
@ -69,7 +94,11 @@ cooja_mtarch_start(struct cooja_mtarch_thread *t,
|
||||||
f->retaddr = (unsigned long)function;
|
f->retaddr = (unsigned long)function;
|
||||||
f->data = (unsigned long)data;
|
f->data = (unsigned long)data;
|
||||||
t->sp = (unsigned long)&f->flags;
|
t->sp = (unsigned long)&f->flags;
|
||||||
|
#if ON_64BIT_ARCH
|
||||||
|
f->rbp = (unsigned long)&f->rax;
|
||||||
|
#else /* ON_64BIT_ARCH */
|
||||||
f->ebp = (unsigned long)&f->eax;
|
f->ebp = (unsigned long)&f->eax;
|
||||||
|
#endif /* ON_64BIT_ARCH */
|
||||||
}
|
}
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
static struct cooja_mtarch_thread *cooja_running_thread;
|
static struct cooja_mtarch_thread *cooja_running_thread;
|
||||||
|
@ -77,6 +106,17 @@ static struct cooja_mtarch_thread *cooja_running_thread;
|
||||||
void cooja_sw(void)
|
void cooja_sw(void)
|
||||||
{
|
{
|
||||||
/* Store registers */
|
/* Store registers */
|
||||||
|
#if ON_64BIT_ARCH
|
||||||
|
__asm__ (
|
||||||
|
"pushq %rax\n\t"
|
||||||
|
"pushq %rbx\n\t"
|
||||||
|
"pushq %rcx\n\t"
|
||||||
|
"pushq %rdx\n\t"
|
||||||
|
"pushq %rsi\n\t"
|
||||||
|
"pushq %rdi\n\t"
|
||||||
|
"pushq %rbp\n\t"
|
||||||
|
"pushq %rbp\n\t");
|
||||||
|
#else /* ON_64BIT_ARCH */
|
||||||
__asm__ (
|
__asm__ (
|
||||||
"pushl %eax\n\t"
|
"pushl %eax\n\t"
|
||||||
"pushl %ebx\n\t"
|
"pushl %ebx\n\t"
|
||||||
|
@ -86,16 +126,41 @@ void cooja_sw(void)
|
||||||
"pushl %edi\n\t"
|
"pushl %edi\n\t"
|
||||||
"pushl %ebp\n\t"
|
"pushl %ebp\n\t"
|
||||||
"pushl %ebp\n\t");
|
"pushl %ebp\n\t");
|
||||||
|
#endif /* ON_64BIT_ARCH */
|
||||||
|
|
||||||
/* Switch stack pointer */
|
/* Switch stack pointer */
|
||||||
|
#if ON_64BIT_ARCH
|
||||||
|
__asm__ ("movq %0, %%rax\n\t" : : "m" (cooja_running_thread));
|
||||||
|
__asm__ (
|
||||||
|
"movq 0(%rax), %rbx\n\t"
|
||||||
|
"movq %rsp, 0(%rax)\n\t"
|
||||||
|
"movq %rbx, %rsp\n\t"
|
||||||
|
);
|
||||||
|
#else /* ON_64BIT_ARCH */
|
||||||
__asm__ ("movl %0, %%eax\n\t" : : "m" (cooja_running_thread));
|
__asm__ ("movl %0, %%eax\n\t" : : "m" (cooja_running_thread));
|
||||||
__asm__ (
|
__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"
|
||||||
);
|
);
|
||||||
|
#endif /* ON_64BIT_ARCH */
|
||||||
|
|
||||||
/* Restore stored registers and return "our" way */
|
/* Restore previous registers */
|
||||||
|
#if ON_64BIT_ARCH
|
||||||
|
__asm__ (
|
||||||
|
"popq %rbp\n\t"
|
||||||
|
"popq %rbp\n\t"
|
||||||
|
"popq %rdi\n\t"
|
||||||
|
"popq %rsi\n\t"
|
||||||
|
"popq %rdx\n\t"
|
||||||
|
"popq %rcx\n\t"
|
||||||
|
"popq %rbx\n\t"
|
||||||
|
"popq %rax\n\t"
|
||||||
|
|
||||||
|
"leave\n\t"
|
||||||
|
"ret\n\t"
|
||||||
|
);
|
||||||
|
#else /* ON_64BIT_ARCH */
|
||||||
__asm__ (
|
__asm__ (
|
||||||
"popl %ebp\n\t"
|
"popl %ebp\n\t"
|
||||||
"popl %ebp\n\t"
|
"popl %ebp\n\t"
|
||||||
|
@ -109,7 +174,10 @@ void cooja_sw(void)
|
||||||
"leave\n\t"
|
"leave\n\t"
|
||||||
"ret\n\t"
|
"ret\n\t"
|
||||||
);
|
);
|
||||||
|
#endif /* ON_64BIT_ARCH */
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
cooja_mtarch_exec(struct cooja_mtarch_thread *t)
|
cooja_mtarch_exec(struct cooja_mtarch_thread *t)
|
||||||
|
|
Loading…
Reference in a new issue