Contiki 2.5
mtarch.c
1 /*
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 2007/12/15 00:14:19 oliverschmidt Exp $
34  */
35 
36 #include <string.h>
37 
38 #include "sys/mtarch.h"
39 
40 unsigned char mtarch_asm_threadspreg;
41 unsigned char *mtarch_asm_threadzp;
42 unsigned char *mtarch_asm_threadstack;
43 
44 void mtarch_asm_start(void);
45 void mtarch_asm_yield(void);
46 void mtarch_asm_exec(void);
47 
48 /*--------------------------------------------------------------------------*/
49 void
51 {
52 }
53 /*--------------------------------------------------------------------------*/
54 void
56 {
57 }
58 /*--------------------------------------------------------------------------*/
59 void
60 mtarch_start(struct mtarch_thread *thread,
61  void (* function)(void *data),
62  void *data)
63 {
64  memset(thread->cpustack, 0, sizeof(thread->cpustack));
65  memset(thread->cstack, 0, sizeof(thread->cstack));
66 
67  /* Copy current zero page content as template. */
68  mtarch_asm_threadzp = thread->zp;
69  mtarch_asm_start();
70 
71  /* Create a CPU stack frame with the appropriate values. */
72  thread->cpustack[MTARCH_CPUSTACKSIZE - 2] = ((unsigned short)function) / 0x100; /* high byte of return address */
73  thread->cpustack[MTARCH_CPUSTACKSIZE - 3] = ((unsigned short)function) % 0x100; /* low byte of return address */
74  thread->cpustack[MTARCH_CPUSTACKSIZE - 4] = 0x21; /* processor flags */
75  thread->cpustack[MTARCH_CPUSTACKSIZE - 5] = /* a register */
76  thread->cpustack[MTARCH_CPUSTACKSIZE - 6] = /* x register */
77  thread->cpustack[MTARCH_CPUSTACKSIZE - 7] = 0x00; /* y register */
78  thread->spreg = MTARCH_CPUSTACKSIZE - 8;
79 
80  /* Setup the C stack with the data pointer. */
81  thread->cstack[MTARCH_CSTACKSIZE - 2] = ((unsigned short)data) / 0x100; /* high byte of data pointer */
82  thread->cstack[MTARCH_CSTACKSIZE - 3] = ((unsigned short)data) % 0x100; /* low byte of data pointer */
83 
84  /* Setup the C stack pointer. */
85  thread->zp[1] = ((size_t)&thread->cstack[MTARCH_CSTACKSIZE - 3]) / 0x100; /* high byte of C stack pointer */
86  thread->zp[0] = ((size_t)&thread->cstack[MTARCH_CSTACKSIZE - 3]) % 0x100; /* low byte of C stack pointer */
87 }
88 /*--------------------------------------------------------------------------*/
89 void
91 {
92  mtarch_asm_yield();
93 }
94 /*--------------------------------------------------------------------------*/
95 void
96 mtarch_exec(struct mtarch_thread *thread)
97 {
98  /* Switch processor stack. The call to mtarch_asm_switch() will not
99  return until the process that we switch to calls yield(). */
100  mtarch_asm_threadspreg = thread->spreg;
101 
102  mtarch_asm_threadstack = thread->cpustack;
103  mtarch_asm_threadzp = thread->zp;
104 
105  mtarch_asm_exec();
106 
107  thread->spreg = mtarch_asm_threadspreg;
108 }
109 /*--------------------------------------------------------------------------*/
110 void
111 mtarch_stop(struct mtarch_thread *thread)
112 {
113 }
114 /*--------------------------------------------------------------------------*/
115 void
116 mtarch_pstart(void)
117 {
118 }
119 /*--------------------------------------------------------------------------*/
120 void
121 mtarch_pstop(void)
122 {
123 }
124 /*--------------------------------------------------------------------------*/