xref: /haiku/src/system/kernel/arch/arm/arch_thread.cpp (revision 1c09002cbee8e797a0f8bbfc5678dfadd39ee1a7)
1 /*
2  * Copyright 2003-2010, Haiku Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  * 		Axel Dörfler <axeld@pinc-software.de>
7  * 		Ingo Weinhold <bonefish@cs.tu-berlin.de>
8  * 		François Revol <revol@free.fr>
9  *
10  * Copyright 2001, Travis Geiselbrecht. All rights reserved.
11  * Distributed under the terms of the NewOS License.
12  */
13 
14 
15 #include <thread.h>
16 #include <arch_thread.h>
17 
18 #include <arch_cpu.h>
19 #include <arch/thread.h>
20 #include <boot/stage2.h>
21 #include <kernel.h>
22 #include <thread.h>
23 #include <vm/vm_types.h>
24 #include <vm/VMAddressSpace.h>
25 #include <arch_vm.h>
26 //#include <arch/vm_translation_map.h>
27 
28 #include <string.h>
29 
30 #warning M68K: writeme!
31 // Valid initial arch_thread state. We just memcpy() it when initializing
32 // a new thread structure.
33 static struct arch_thread sInitialState;
34 
35 Thread *gCurrentThread;
36 
37 
38 status_t
39 arch_thread_init(struct kernel_args *args)
40 {
41 	// Initialize the static initial arch_thread state (sInitialState).
42 	// Currently nothing to do, i.e. zero initialized is just fine.
43 
44 	return B_OK;
45 }
46 
47 
48 status_t
49 arch_team_init_team_struct(Team *team, bool kernel)
50 {
51 	// Nothing to do. The structure is empty.
52 	return B_OK;
53 }
54 
55 
56 status_t
57 arch_thread_init_thread_struct(Thread *thread)
58 {
59 	// set up an initial state (stack & fpu)
60 	memcpy(&thread->arch_info, &sInitialState, sizeof(struct arch_thread));
61 
62 	return B_OK;
63 }
64 
65 
66 status_t
67 arch_thread_init_kthread_stack(Thread *t, int (*start_func)(void),
68 	void (*entry_func)(void), void (*exit_func)(void))
69 {
70 /*	addr_t *kstack = (addr_t *)t->kernel_stack_base;
71 	addr_t *kstackTop = (addr_t *)t->kernel_stack_base;
72 
73 	// clear the kernel stack
74 #ifdef DEBUG_KERNEL_STACKS
75 #	ifdef STACK_GROWS_DOWNWARDS
76 	memset((void *)((addr_t)kstack + KERNEL_STACK_GUARD_PAGES * B_PAGE_SIZE), 0,
77 		KERNEL_STACK_SIZE);
78 #	else
79 	memset(kstack, 0, KERNEL_STACK_SIZE);
80 #	endif
81 #else
82 	memset(kstack, 0, KERNEL_STACK_SIZE);
83 #endif
84 
85 	// space for frame pointer and return address, and stack frames must be
86 	// 16 byte aligned
87 	kstackTop -= 2;
88 	kstackTop = (addr_t*)((addr_t)kstackTop & ~0xf);
89 
90 	// LR, CR, r2, r13-r31, f13-f31, as pushed by m68k_context_switch()
91 	kstackTop -= 22 + 2 * 19;
92 
93 	// let LR point to m68k_kernel_thread_root()
94 	kstackTop[0] = (addr_t)&m68k_kernel_thread_root;
95 
96 	// the arguments of m68k_kernel_thread_root() are the functions to call,
97 	// provided in registers r13-r15
98 	kstackTop[3] = (addr_t)entry_func;
99 	kstackTop[4] = (addr_t)start_func;
100 	kstackTop[5] = (addr_t)exit_func;
101 
102 	// save this stack position
103 	t->arch_info.sp = (void *)kstackTop;
104 */
105 #warning ARM:WRITEME
106 	return B_OK;
107 }
108 
109 
110 status_t
111 arch_thread_init_tls(Thread *thread)
112 {
113 	// TODO: Implement!
114 	return B_OK;
115 }
116 
117 
118 void
119 arch_thread_context_switch(Thread *from, Thread *to)
120 {
121 /*	addr_t newPageDirectory;
122 
123 	newPageDirectory = (addr_t)m68k_next_page_directory(from, to);
124 
125 	if ((newPageDirectory % B_PAGE_SIZE) != 0)
126 		panic("arch_thread_context_switch: bad pgdir 0x%lx\n", newPageDirectory);
127 #warning M68K: export from arch_vm.c
128 	m68k_set_pgdir(newPageDirectory);
129 	m68k_context_switch(&from->arch_info.sp, to->arch_info.sp);*/
130 #warning ARM:WRITEME
131 
132 }
133 
134 
135 void
136 arch_thread_dump_info(void *info)
137 {
138 	struct arch_thread *at = (struct arch_thread *)info;
139 
140 	dprintf("\tsp: %p\n", at->sp);
141 }
142 
143 
144 status_t
145 arch_thread_enter_userspace(Thread *thread, addr_t entry, void *arg1, void *arg2)
146 {
147 	panic("arch_thread_enter_uspace(): not yet implemented\n");
148 	return B_ERROR;
149 }
150 
151 
152 bool
153 arch_on_signal_stack(Thread *thread)
154 {
155 	return false;
156 }
157 
158 
159 status_t
160 arch_setup_signal_frame(Thread *thread, struct sigaction *sa, int sig, int sigMask)
161 {
162 	return B_ERROR;
163 }
164 
165 
166 int64
167 arch_restore_signal_frame(void)
168 {
169 	return 0;
170 }
171 
172 
173 void
174 arch_check_syscall_restart(Thread *thread)
175 {
176 }
177 
178 
179 /**	Saves everything needed to restore the frame in the child fork in the
180  *	arch_fork_arg structure to be passed to arch_restore_fork_frame().
181  *	Also makes sure to return the right value.
182  */
183 
184 void
185 arch_store_fork_frame(struct arch_fork_arg *arg)
186 {
187 }
188 
189 
190 /** Restores the frame from a forked team as specified by the provided
191  *	arch_fork_arg structure.
192  *	Needs to be called from within the child team, ie. instead of
193  *	arch_thread_enter_uspace() as thread "starter".
194  *	This function does not return to the caller, but will enter userland
195  *	in the child team at the same position where the parent team left of.
196  */
197 
198 void
199 arch_restore_fork_frame(struct arch_fork_arg *arg)
200 {
201 }
202 
203