xref: /haiku/src/system/boot/platform/atari_m68k/cpu.cpp (revision 39a7a69b07164907ed3f706b722ef03141543d00)
1 /*
2  * Copyright 2008-2010, François Revol, revol@free.fr. All rights reserved.
3  * Distributed under the terms of the MIT License.
4 */
5 
6 
7 #include "cpu.h"
8 #include "toscalls.h"
9 
10 #include <OS.h>
11 #include <boot/platform.h>
12 #include <boot/stdio.h>
13 #include <boot/kernel_args.h>
14 #include <boot/stage2.h>
15 #include <arch/cpu.h>
16 #include <arch_kernel.h>
17 #include <arch_platform.h>
18 #include <arch_system_info.h>
19 
20 #include <string.h>
21 
22 
23 //#define TRACE_CPU
24 #ifdef TRACE_CPU
25 #	define TRACE(x) dprintf x
26 #else
27 #	define TRACE(x) ;
28 #endif
29 
30 #warning M68K: add set_vbr()
31 
32 
33 static status_t
check_cpu_features()34 check_cpu_features()
35 {
36 #warning M68K: TODO: probe ourselves, we shouldnt trust the TOS!
37 
38 	const tos_cookie *c;
39 	uint16 cpu_type, fpu_type, fpu_emul;
40 	uint16 machine_type;
41 	int fpu = 0;
42 
43 	c = tos_find_cookie('_CPU');
44 	if (!c) {
45 		panic("can't get a cookie (_CPU)!");
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 #warning M68K: check cpu type passed to kern args
57 	gKernelArgs.arch_args.cpu_type = 68000 + cpu_type;
58 	gKernelArgs.arch_args.mmu_type = 68000 + cpu_type;
59 	gKernelArgs.arch_args.has_lpstop = (cpu_type >= 60)?true:false;
60 
61 	c = tos_find_cookie('_FPU');
62 	if (!c) {
63 		panic("can't get a cookie (_FPU)!");
64 		return EINVAL;
65 	}
66 	fpu_type = (uint16)(c->ivalue >> 16);
67 	fpu_emul = (uint16)(c->ivalue);
68 
69 	// http://toshyp.atari.org/003007.htm#Cookie_2C_20_FPU
70 	if (fpu_type & 0x10)
71 		fpu = 68060;
72 	else if (fpu_type & 0x8)
73 		fpu = 68040;
74 	else if ((fpu_type & 0x6) == 0x6)
75 		fpu = 68882;
76 	else if ((fpu_type & 0x6) == 0x4)
77 		fpu = 68881;
78 	else if ((fpu_type & 0x6) == 0x2)
79 		fpu = 68881; // not certain
80 	else if (fpu_type & 0x4) {
81 		panic("bad fpu");
82 		return EINVAL;
83 	}
84 	gKernelArgs.arch_args.fpu_type = fpu;
85 
86 	gKernelArgs.arch_args.platform = M68K_PLATFORM_ATARI;
87 
88 	c = tos_find_cookie('_MCH');
89 	if (!c) {
90 		panic("can't get a cookie (_MCH)!");
91 		return EINVAL;
92 	}
93 	machine_type = (uint16)(c->ivalue >> 16);
94 	gKernelArgs.arch_args.machine = machine_type;
95 
96 	return B_OK;
97 }
98 
99 #warning M68K: move and implement system_time()
100 static bigtime_t gSystemTimeCounter = 0; //HACK
101 extern "C" bigtime_t
system_time(void)102 system_time(void)
103 {
104 	// _hz_200
105 	//return (*TOSVAR_hz_200) * 1000000LL / 200;
106 	return gSystemTimeCounter++;
107 }
108 
109 
110 //	#pragma mark -
111 
112 
113 extern "C" void
spin(bigtime_t microseconds)114 spin(bigtime_t microseconds)
115 {
116 	bigtime_t time = system_time();
117 	while ((system_time() - time) < microseconds)
118 		asm volatile ("nop;");
119 }
120 
121 
122 extern "C" void
cpu_init()123 cpu_init()
124 {
125 	if (check_cpu_features() != B_OK)
126 		panic("You need a 68020 or higher in order to boot!\n");
127 
128 	gKernelArgs.num_cpus = 1;
129 		// this will eventually be corrected later on
130 		// ...or not!
131 }
132 
133 
134 extern "C" void
platform_load_ucode(BootVolume & volume)135 platform_load_ucode(BootVolume& volume)
136 {
137 }
138 
139