blob: dc8e3cd3ab8d1d7298b1a2dae02d032d0044802f [file] [log] [blame]
kthacker62e146c2006-04-17 15:11:35 +00001/*
2 * Copyright (c) 2004, Adam Dunkels.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the Institute nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * This file is part of the Contiki operating system.
30 *
31 * Author: Adam Dunkels <adam@sics.se>
32 *
33 * $Id: mtarch.c,v 1.1 2006/04/17 15:11:55 kthacker Exp $
34 */
35#include "mtarch.h"
36#include <string.h>
37
38unsigned char mtarch_asm_threadspreg;
39unsigned char *mtarch_asm_threadsp;
40unsigned char *mtarch_asm_threadzp;
41unsigned char *mtarch_asm_threadstack;
42
43void mtarch_asm_start(void);
44void mtarch_asm_exec(void);
45
46
47/*--------------------------------------------------------------------------*/
48void
49mtarch_start(struct mtarch_thread *thread,
50 void (* function)(void *data),
51 void *data)
52{
53 memset(thread->cpustack, 0, sizeof(thread->cpustack));
54 memset(thread->cstack, 0, sizeof(thread->cstack));
55
56 /* Create a CPU stack frame with the appropriate values... */
57 thread->cpustack[MTARCH_CPUSTACKSIZE - 2] = ((unsigned short)function) >> 8; /* high byte of return address. */
58 thread->cpustack[MTARCH_CPUSTACKSIZE - 3] = ((unsigned short)function) & 0xff; /* low byte of return address. */
59 thread->cpustack[MTARCH_CPUSTACKSIZE - 4] = 0x21; /* processor flags. */
60 thread->cpustack[MTARCH_CPUSTACKSIZE - 5] = /* a register */
61 thread->cpustack[MTARCH_CPUSTACKSIZE - 6] = /* x register */
62 thread->cpustack[MTARCH_CPUSTACKSIZE - 7] = 0; /* y register */
63 thread->spreg = MTARCH_CPUSTACKSIZE - 8;
64
65 /* Setup the C stack with the data pointer. */
66 thread->sp = &thread->cstack[MTARCH_CSTACKSIZE - 1];
67
68 mtarch_asm_threadzp = &(thread->zp);
69 mtarch_asm_start();
70}
71/*--------------------------------------------------------------------------*/
72void
73mtarch_exec(struct mtarch_thread *thread)
74{
75 /* Switch processor stack. The call to mtarch_asm_switch() will not
76 return until the process that we switch to calls yield(). */
77 mtarch_asm_threadspreg = thread->spreg;
78 mtarch_asm_threadsp = thread->sp;
79
80 mtarch_asm_threadstack = &(thread->cpustack[0]);
81 mtarch_asm_threadzp = &(thread->zp[0]);
82
83 mtarch_asm_exec();
84
85 thread->sp = mtarch_asm_threadsp;
86 thread->spreg = mtarch_asm_threadspreg;
87}
88/*--------------------------------------------------------------------------*/
89void
90mtarch_init(void) {
91
92}
93/*--------------------------------------------------------------------------*/
94void
95mtarch_remove(void)
96{
97
98}