xref: /haiku/src/system/boot/platform/atari_m68k/cpu.cpp (revision 020cbad9d40235a2c50a81a42d69912a5ff8fbc4)
1 /*
2  * Copyright 2004-2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * calculate_cpu_conversion_factor() was written by Travis Geiselbrecht and
6  * licensed under the NewOS license.
7  */
8 
9 
10 #include "cpu.h"
11 #include "toscalls.h"
12 
13 #include <OS.h>
14 #include <boot/platform.h>
15 #include <boot/stdio.h>
16 #include <boot/kernel_args.h>
17 #include <boot/stage2.h>
18 #include <arch/cpu.h>
19 #include <arch_kernel.h>
20 #include <arch_system_info.h>
21 
22 #include <string.h>
23 
24 
25 //#define TRACE_CPU
26 #ifdef TRACE_CPU
27 #	define TRACE(x) dprintf x
28 #else
29 #	define TRACE(x) ;
30 #endif
31 
32 #warning M68K: add set_vbr()
33 
34 
35 static status_t
36 check_cpu_features()
37 {
38 #warning M68K: TODO: probe ourselves, we shouldn't trust the TOS!
39 
40 	const tos_cookie *c;
41 	uint16 cpu_type, fpu_type, fpu_emul;
42 
43 	c = tos_find_cookie('_CPU');
44 	if (!c) {
45 		panic("can't get a cookie (_CPU)! Mum, I'm hungry!");
46 		return EINVAL;
47 	}
48 	cpu_type = (uint16) c->ivalue;
49 
50 	dump_tos_cookies();
51 
52 #warning M68K: check for 020 + mmu
53 	if (cpu_type < 30/*20*/)
54 		return EINVAL;
55 
56 	gKernelArgs.arch_args.has_lpstop = (cpu_type >= 60)?true:false;
57 #warning M68K: add cpu type to kern args
58 
59 	c = tos_find_cookie('_FPU');
60 	if (!c) {
61 		panic("can't get a cookie (_FPU)! Mum, I'm hungry!");
62 		return EINVAL;
63 	}
64 	fpu_type = (uint16)(c->ivalue >> 16);
65 	fpu_emul = (uint16)(c->ivalue);
66 
67 #warning M68K: check for fpu in detail
68 	if (fpu_type < 2 || fpu_type > 9) {
69 		panic("bad fpu");
70 		return EINVAL;
71 	}
72 
73 	return B_OK;
74 }
75 
76 #warning M68K: move and implement system_time()
77 static bigtime_t gSystemTimeCounter = 0; //HACK
78 extern "C" bigtime_t
79 system_time(void)
80 {
81 	return gSystemTimeCounter++;
82 }
83 
84 
85 //	#pragma mark -
86 
87 
88 extern "C" void
89 spin(bigtime_t microseconds)
90 {
91 	bigtime_t time = system_time();
92 	while ((system_time() - time) < microseconds)
93 		asm volatile ("nop;");
94 }
95 
96 
97 extern "C" void
98 cpu_init()
99 {
100 	if (check_cpu_features() != B_OK)
101 		panic("You need a 68020 or higher in order to boot!\n");
102 
103 	gKernelArgs.num_cpus = 1;
104 		// this will eventually be corrected later on
105 		// ...or not!
106 }
107 
108