xref: /haiku/src/system/kernel/arch/arm/arch_thread.cpp (revision 93e30a47bed879ad448b3e2d9e10333d3f2e60ae)
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 
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 void
67 arch_thread_init_kthread_stack(Thread* thread, void* _stack, void* _stackTop,
68 	void (*function)(void*), const void* data)
69 {
70 #warning ARM:WRITEME
71 }
72 
73 
74 status_t
75 arch_thread_init_tls(Thread *thread)
76 {
77 	// TODO: Implement!
78 	return B_OK;
79 }
80 
81 
82 void
83 arch_thread_context_switch(Thread *from, Thread *to)
84 {
85 	#if 0
86 	addr_t newPageDirectory;
87 
88 	newPageDirectory = (addr_t)m68k_next_page_directory(from, to);
89 
90 	if ((newPageDirectory % B_PAGE_SIZE) != 0)
91 		panic("arch_thread_context_switch: bad pgdir 0x%lx\n",
92 			newPageDirectory);
93 	#warning M68K: export from arch_vm.c
94 	m68k_set_pgdir(newPageDirectory);
95 	m68k_context_switch(&from->arch_info.sp, to->arch_info.sp);
96 	#endif
97 
98 	#warning ARM:WRITEME
99 }
100 
101 
102 void
103 arch_thread_dump_info(void *info)
104 {
105 	struct arch_thread *at = (struct arch_thread *)info;
106 
107 	dprintf("\tsp: %p\n", at->sp);
108 }
109 
110 
111 status_t
112 arch_thread_enter_userspace(Thread *thread, addr_t entry,
113 	void *arg1, void *arg2)
114 {
115 	panic("arch_thread_enter_uspace(): not yet implemented\n");
116 	return B_ERROR;
117 }
118 
119 
120 bool
121 arch_on_signal_stack(Thread *thread)
122 {
123 	return false;
124 }
125 
126 
127 status_t
128 arch_setup_signal_frame(Thread *thread, struct sigaction *sa,
129 	struct signal_frame_data *signalFrameData)
130 {
131 	return B_ERROR;
132 }
133 
134 
135 int64
136 arch_restore_signal_frame(struct signal_frame_data* signalFrameData)
137 {
138 	return 0;
139 }
140 
141 
142 void
143 arch_check_syscall_restart(Thread *thread)
144 {
145 }
146 
147 
148 /**	Saves everything needed to restore the frame in the child fork in the
149  *	arch_fork_arg structure to be passed to arch_restore_fork_frame().
150  *	Also makes sure to return the right value.
151  */
152 void
153 arch_store_fork_frame(struct arch_fork_arg *arg)
154 {
155 }
156 
157 
158 /** Restores the frame from a forked team as specified by the provided
159  *	arch_fork_arg structure.
160  *	Needs to be called from within the child team, ie. instead of
161  *	arch_thread_enter_uspace() as thread "starter".
162  *	This function does not return to the caller, but will enter userland
163  *	in the child team at the same position where the parent team left of.
164  */
165 void
166 arch_restore_fork_frame(struct arch_fork_arg *arg)
167 {
168 }
169