xref: /haiku/src/system/kernel/util/kernel_cpp.cpp (revision 0562493379cd52eb7103531f895f10bb8e77c085)
1 /*
2  * Copyright 2003-2007, 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@users.sf.net.
8  */
9 
10 //!	C++ in the kernel
11 
12 
13 #include "util/kernel_cpp.h"
14 
15 #ifdef _BOOT_MODE
16 #	include <boot/platform.h>
17 #else
18 #	include <KernelExport.h>
19 #	include <stdio.h>
20 #endif
21 
22 #ifdef _LOADER_MODE
23 #	define panic printf
24 #	define dprintf printf
25 #	define kernel_debugger printf
26 #endif
27 
28 
29 // Always define the symbols needed when not linking against libgcc.a --
30 // we simply override them.
31 
32 // ... it doesn't seem to work with this symbol at least.
33 #ifndef USING_LIBGCC
34 #	if __GNUC__ >= 3
35 const std::nothrow_t std::nothrow = {};
36 #	else
37 const nothrow_t std::nothrow = {};
38 #	endif
39 #endif
40 
41 const mynothrow_t mynothrow = {};
42 
43 #if __GNUC__ == 2
44 
45 extern "C" void
46 __pure_virtual()
47 {
48 	panic("pure virtual function call\n");
49 }
50 
51 #elif __GNUC__ >= 3
52 
53 extern "C" void
54 __cxa_pure_virtual()
55 {
56 	panic("pure virtual function call\n");
57 }
58 
59 #endif
60 
61 // full C++ support in the kernel
62 #if (defined(_KERNEL_MODE) || defined(_LOADER_MODE)) && !defined(_BOOT_MODE)
63 
64 FILE *stderr = NULL;
65 
66 extern "C"
67 int
68 fprintf(FILE *f, const char *format, ...)
69 {
70 	// TODO: Introduce a vdprintf()...
71 	dprintf("fprintf(`%s',...)\n", format);
72 	return 0;
73 }
74 
75 #if __GNUC__ >= 3
76 
77 extern "C"
78 size_t
79 fwrite(const void *buffer, size_t size, size_t numItems, FILE *stream)
80 {
81 	dprintf("%.*s", int(size * numItems), (char*)buffer);
82 	return 0;
83 }
84 
85 extern "C"
86 int
87 fputs(const char *string, FILE *stream)
88 {
89 	dprintf("%s", string);
90 	return 0;
91 }
92 
93 extern "C"
94 int
95 fputc(int c, FILE *stream)
96 {
97 	dprintf("%c", c);
98 	return 0;
99 }
100 
101 #ifndef _LOADER_MODE
102 extern "C"
103 int
104 printf(const char *format, ...)
105 {
106 	// TODO: Introduce a vdprintf()...
107 	dprintf("printf(`%s',...)\n", format);
108 	return 0;
109 }
110 #endif
111 
112 extern "C"
113 int
114 puts(const char *string)
115 {
116 	return fputs(string, NULL);
117 }
118 
119 
120 #endif	// __GNUC__ >= 3
121 
122 #if __GNUC__ >= 4 && !defined(USING_LIBGCC)
123 
124 extern "C"
125 void
126 _Unwind_DeleteException()
127 {
128 	panic("_Unwind_DeleteException");
129 }
130 
131 extern "C"
132 void
133 _Unwind_Find_FDE()
134 {
135 	panic("_Unwind_Find_FDE");
136 }
137 
138 
139 extern "C"
140 void
141 _Unwind_GetDataRelBase()
142 {
143 	panic("_Unwind_GetDataRelBase");
144 }
145 
146 extern "C"
147 void
148 _Unwind_GetGR()
149 {
150 	panic("_Unwind_GetGR");
151 }
152 
153 extern "C"
154 void
155 _Unwind_GetIP()
156 {
157 	panic("_Unwind_GetIP");
158 }
159 
160 extern "C"
161 void
162 _Unwind_GetLanguageSpecificData()
163 {
164 	panic("_Unwind_GetLanguageSpecificData");
165 }
166 
167 extern "C"
168 void
169 _Unwind_GetRegionStart()
170 {
171 	panic("_Unwind_GetRegionStart");
172 }
173 
174 extern "C"
175 void
176 _Unwind_GetTextRelBase()
177 {
178 	panic("_Unwind_GetTextRelBase");
179 }
180 
181 extern "C"
182 void
183 _Unwind_RaiseException()
184 {
185 	panic("_Unwind_RaiseException");
186 }
187 
188 extern "C"
189 void
190 _Unwind_Resume()
191 {
192 	panic("_Unwind_Resume");
193 }
194 
195 extern "C"
196 void
197 _Unwind_Resume_or_Rethrow()
198 {
199 	panic("_Unwind_Resume_or_Rethrow");
200 }
201 
202 extern "C"
203 void
204 _Unwind_SetGR()
205 {
206 	panic("_Unwind_SetGR");
207 }
208 
209 extern "C"
210 void
211 _Unwind_SetIP()
212 {
213 	panic("_Unwind_SetIP");
214 }
215 
216 extern "C"
217 void
218 __deregister_frame_info()
219 {
220 	panic("__deregister_frame_info");
221 }
222 
223 extern "C"
224 void
225 __register_frame_info()
226 {
227 	panic("__register_frame_info");
228 }
229 
230 
231 #endif	// __GNUC__ >= 4
232 
233 extern "C"
234 void
235 abort()
236 {
237 	panic("abort() called!");
238 }
239 
240 extern "C"
241 void
242 debugger(const char *message)
243 {
244 	kernel_debugger(message);
245 }
246 
247 #endif	// _#if KERNEL_MODE
248