xref: /haiku/src/system/boot/platform/amiga_m68k/cpu.cpp (revision 2b76973fa2401f7a5edf68e6470f3d3210cbcff3)
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 "rom_calls.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_platform.h>
21 #include <arch_system_info.h>
22 
23 #include <string.h>
24 
25 
26 //#define TRACE_CPU
27 #ifdef TRACE_CPU
28 #	define TRACE(x) dprintf x
29 #else
30 #	define TRACE(x) ;
31 #endif
32 
33 #warning M68K: add set_vbr()
34 
35 
36 static status_t
37 check_cpu_features()
38 {
39 	uint16 flags = SysBase->AttnFlags;
40 	int cpu = 0;
41 	int fpu = 0;
42 
43 	// check fpu flags first, since they are also set for 040
44 
45 	if ((flags & AFF_68881) != 0)
46 			fpu = 68881;
47 	if ((flags & AFF_68882) != 0)
48 			fpu = 68882;
49 
50 	//if ((flags & AFF_68010) != 0)
51 	//	return B_ERROR;
52 	//if ((flags & AFF_68020) != 0)
53 	//	return B_ERROR;
54 	if ((flags & AFF_68030) != 0)
55 			cpu = 68030;
56 	if ((flags & AFF_68040) != 0)
57 			cpu = fpu = 68040;
58 	//if ((flags & AFF_FPU40) != 0)
59 	//		;
60 
61 	//panic("cpu %d fpu %d flags 0x%04x", cpu, fpu, flags);
62 	cpu = fpu = 68040; //XXX
63 	if (!cpu || !fpu)
64 		return B_ERROR;
65 
66 	gKernelArgs.arch_args.cpu_type = cpu;
67 	gKernelArgs.arch_args.mmu_type = cpu;
68 	gKernelArgs.arch_args.fpu_type = fpu;
69 
70 	//	if ((flags & AFF_68060) != 0) true
71 	gKernelArgs.arch_args.has_lpstop = false;
72 
73 	gKernelArgs.arch_args.platform = M68K_PLATFORM_AMIGA;
74 	gKernelArgs.arch_args.machine = 0; //XXX
75 
76 	return B_OK;
77 }
78 
79 #warning M68K: move and implement system_time()
80 static bigtime_t gSystemTimeCounter = 0; //HACK
81 extern "C" bigtime_t
82 system_time(void)
83 {
84 	return gSystemTimeCounter++;
85 }
86 
87 
88 //	#pragma mark -
89 
90 
91 extern "C" void
92 spin(bigtime_t microseconds)
93 {
94 	bigtime_t time = system_time();
95 	while ((system_time() - time) < microseconds)
96 		asm volatile ("nop;");
97 }
98 
99 
100 extern "C" void
101 cpu_init()
102 {
103 	if (check_cpu_features() != B_OK)
104 		panic("You need a 68030 or higher in order to boot!\n");
105 
106 	gKernelArgs.num_cpus = 1;
107 		// this will eventually be corrected later on
108 		// ...or not!
109 }
110 
111