added support for 64-bit architectures, as already added on the cooja mtarch clone (patch provided by Jesper Karlsson and David Gustafsson)
This commit is contained in:
parent
da8ee90ef3
commit
4275ff4a9c
128
cpu/x86/mtarch.c
128
cpu/x86/mtarch.c
|
@ -2,8 +2,29 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "sys/mt.h"
|
#include "sys/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;
|
||||||
|
@ -11,24 +32,22 @@ 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;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
mtarch_init(void)
|
mtarch_init(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
mtarch_start(struct mtarch_thread *t,
|
mtarch_start(struct mtarch_thread *t,
|
||||||
void (*function)(void *), void *data)
|
void (*function)(void *), void *data)
|
||||||
{
|
{
|
||||||
|
struct frame *f = (struct frame *)&t->stack[MTARCH_STACKSIZE - sizeof(struct frame)/sizeof(unsigned long)];
|
||||||
struct frame *f = (struct frame *)&t->stack[MTARCH_STACKSIZE - sizeof(struct frame)/4];
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for(i = 0; i < MTARCH_STACKSIZE; ++i) {
|
for(i = 0; i < MTARCH_STACKSIZE; ++i) {
|
||||||
|
@ -39,38 +58,89 @@ mtarch_start(struct 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 unsigned long spsave, sptmp;
|
|
||||||
static struct mtarch_thread *running_thread;
|
static struct mtarch_thread *running_thread;
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
static void
|
static void
|
||||||
sw(void)
|
sw(void)
|
||||||
{
|
{
|
||||||
|
/* 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__ (
|
||||||
|
"pushl %eax\n\t"
|
||||||
|
"pushl %ebx\n\t"
|
||||||
|
"pushl %ecx\n\t"
|
||||||
|
"pushl %edx\n\t"
|
||||||
|
"pushl %esi\n\t"
|
||||||
|
"pushl %edi\n\t"
|
||||||
|
"pushl %ebp\n\t"
|
||||||
|
"pushl %ebp\n\t");
|
||||||
|
#endif /* ON_64BIT_ARCH */
|
||||||
|
|
||||||
asm("pushl %eax");
|
/* Switch stack pointer */
|
||||||
asm("pushl %ebx");
|
#if ON_64BIT_ARCH
|
||||||
asm("pushl %ecx");
|
__asm__ ("movq %0, %%rax\n\t" : : "m" (running_thread));
|
||||||
asm("pushl %edx");
|
__asm__ (
|
||||||
asm("pushl %esi");
|
"movq (%rax), %rbx\n\t"
|
||||||
asm("pushl %edi");
|
"movq %rsp, (%rax)\n\t"
|
||||||
asm("pushl %ebp");
|
"movq %rbx, %rsp\n\t"
|
||||||
asm("pushl %ebp"); /* XXX: should push FPU flags here. */
|
);
|
||||||
asm("movl %esp, spsave");
|
#else /* ON_64BIT_ARCH */
|
||||||
|
__asm__ ("movl %0, %%eax\n\t" : : "m" (running_thread));
|
||||||
|
__asm__ (
|
||||||
|
"movl (%eax), %ebx\n\t"
|
||||||
|
"movl %esp, (%eax)\n\t"
|
||||||
|
"movl %ebx, %esp\n\t"
|
||||||
|
);
|
||||||
|
#endif /* ON_64BIT_ARCH */
|
||||||
|
|
||||||
sptmp = running_thread->sp;
|
/* Restore previous registers */
|
||||||
running_thread->sp = spsave;
|
#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__ (
|
||||||
|
"popl %ebp\n\t"
|
||||||
|
"popl %ebp\n\t"
|
||||||
|
"popl %edi\n\t"
|
||||||
|
"popl %esi\n\t"
|
||||||
|
"popl %edx\n\t"
|
||||||
|
"popl %ecx\n\t"
|
||||||
|
"popl %ebx\n\t"
|
||||||
|
"popl %eax\n\t"
|
||||||
|
|
||||||
|
"leave\n\t"
|
||||||
|
"ret\n\t"
|
||||||
|
);
|
||||||
|
#endif /* ON_64BIT_ARCH */
|
||||||
|
|
||||||
asm("movl sptmp, %esp");
|
|
||||||
asm("popl %ebp"); /* XXX: should pop FPU flags here. */
|
|
||||||
asm("popl %ebp");
|
|
||||||
asm("popl %edi");
|
|
||||||
asm("popl %esi");
|
|
||||||
asm("popl %edx");
|
|
||||||
asm("popl %ecx");
|
|
||||||
asm("popl %ebx");
|
|
||||||
asm("popl %eax");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
@ -85,7 +155,6 @@ mtarch_exec(struct mtarch_thread *t)
|
||||||
void
|
void
|
||||||
mtarch_remove(void)
|
mtarch_remove(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
|
@ -97,13 +166,11 @@ mtarch_yield(void)
|
||||||
void
|
void
|
||||||
mtarch_pstop(void)
|
mtarch_pstop(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
mtarch_pstart(void)
|
mtarch_pstart(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
int
|
int
|
||||||
|
@ -115,5 +182,6 @@ mtarch_stack_usage(struct mt_thread *t)
|
||||||
return MTARCH_STACKSIZE - i;
|
return MTARCH_STACKSIZE - i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
Loading…
Reference in a new issue