xref: /haiku/src/system/boot/platform/amiga_m68k/cpu.cpp (revision 39a7a69b07164907ed3f706b722ef03141543d00)
14ae92968SFrançois Revol /*
24ae92968SFrançois Revol  * Copyright 2004-2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
34ae92968SFrançois Revol  * Distributed under the terms of the MIT License.
44ae92968SFrançois Revol  */
54ae92968SFrançois Revol 
64ae92968SFrançois Revol 
74ae92968SFrançois Revol #include "cpu.h"
87ddba3d2SFrançois Revol #include "rom_calls.h"
94ae92968SFrançois Revol 
104ae92968SFrançois Revol #include <OS.h>
114ae92968SFrançois Revol #include <boot/platform.h>
124ae92968SFrançois Revol #include <boot/stdio.h>
134ae92968SFrançois Revol #include <boot/kernel_args.h>
144ae92968SFrançois Revol #include <boot/stage2.h>
154ae92968SFrançois Revol #include <arch/cpu.h>
164ae92968SFrançois Revol #include <arch_kernel.h>
174ae92968SFrançois Revol #include <arch_platform.h>
184ae92968SFrançois Revol #include <arch_system_info.h>
194ae92968SFrançois Revol 
204ae92968SFrançois Revol #include <string.h>
214ae92968SFrançois Revol 
224ae92968SFrançois Revol 
234ae92968SFrançois Revol //#define TRACE_CPU
244ae92968SFrançois Revol #ifdef TRACE_CPU
254ae92968SFrançois Revol #	define TRACE(x) dprintf x
264ae92968SFrançois Revol #else
274ae92968SFrançois Revol #	define TRACE(x) ;
284ae92968SFrançois Revol #endif
294ae92968SFrançois Revol 
304ae92968SFrançois Revol #warning M68K: add set_vbr()
314ae92968SFrançois Revol 
324ae92968SFrançois Revol 
334ae92968SFrançois Revol static status_t
check_cpu_features()344ae92968SFrançois Revol check_cpu_features()
354ae92968SFrançois Revol {
364cbffbf5SFrançois Revol 	uint16 flags = SysBase->AttnFlags;
3714016c7cSFrançois Revol 	int cpu = 0;
3814016c7cSFrançois Revol 	int fpu = 0;
3914016c7cSFrançois Revol 
4014016c7cSFrançois Revol 	// check fpu flags first, since they are also set for 040
4114016c7cSFrançois Revol 
424cbffbf5SFrançois Revol 	if ((flags & AFF_68881) != 0)
4314016c7cSFrançois Revol 			fpu = 68881;
444cbffbf5SFrançois Revol 	if ((flags & AFF_68882) != 0)
4514016c7cSFrançois Revol 			fpu = 68882;
4614016c7cSFrançois Revol 
474cbffbf5SFrançois Revol 	//if ((flags & AFF_68010) != 0)
4814016c7cSFrançois Revol 	//	return B_ERROR;
494cbffbf5SFrançois Revol 	//if ((flags & AFF_68020) != 0)
5014016c7cSFrançois Revol 	//	return B_ERROR;
514cbffbf5SFrançois Revol 	if ((flags & AFF_68030) != 0)
5214016c7cSFrançois Revol 			cpu = 68030;
534cbffbf5SFrançois Revol 	if ((flags & AFF_68040) != 0)
5414016c7cSFrançois Revol 			cpu = fpu = 68040;
554cbffbf5SFrançois Revol 	//if ((flags & AFF_FPU40) != 0)
5614016c7cSFrançois Revol 	//		;
5714016c7cSFrançois Revol 
584cbffbf5SFrançois Revol 	//panic("cpu %d fpu %d flags 0x%04x", cpu, fpu, flags);
592e74287aSFrançois Revol 	cpu = fpu = 68040; //XXX
6014016c7cSFrançois Revol 	if (!cpu || !fpu)
614ae92968SFrançois Revol 		return B_ERROR;
6214016c7cSFrançois Revol 
6314016c7cSFrançois Revol 	gKernelArgs.arch_args.cpu_type = cpu;
6414016c7cSFrançois Revol 	gKernelArgs.arch_args.mmu_type = cpu;
6514016c7cSFrançois Revol 	gKernelArgs.arch_args.fpu_type = fpu;
6614016c7cSFrançois Revol 
674cbffbf5SFrançois Revol 	//	if ((flags & AFF_68060) != 0) true
6814016c7cSFrançois Revol 	gKernelArgs.arch_args.has_lpstop = false;
6914016c7cSFrançois Revol 
7014016c7cSFrançois Revol 	gKernelArgs.arch_args.platform = M68K_PLATFORM_AMIGA;
7114016c7cSFrançois Revol 	gKernelArgs.arch_args.machine = 0; //XXX
7214016c7cSFrançois Revol 
7314016c7cSFrançois Revol 	return B_OK;
744ae92968SFrançois Revol }
754ae92968SFrançois Revol 
764ae92968SFrançois Revol #warning M68K: move and implement system_time()
774ae92968SFrançois Revol static bigtime_t gSystemTimeCounter = 0; //HACK
784ae92968SFrançois Revol extern "C" bigtime_t
system_time(void)794ae92968SFrançois Revol system_time(void)
804ae92968SFrançois Revol {
814ae92968SFrançois Revol 	return gSystemTimeCounter++;
824ae92968SFrançois Revol }
834ae92968SFrançois Revol 
844ae92968SFrançois Revol 
854ae92968SFrançois Revol //	#pragma mark -
864ae92968SFrançois Revol 
874ae92968SFrançois Revol 
884ae92968SFrançois Revol extern "C" void
spin(bigtime_t microseconds)894ae92968SFrançois Revol spin(bigtime_t microseconds)
904ae92968SFrançois Revol {
914ae92968SFrançois Revol 	bigtime_t time = system_time();
924ae92968SFrançois Revol 	while ((system_time() - time) < microseconds)
934ae92968SFrançois Revol 		asm volatile ("nop;");
944ae92968SFrançois Revol }
954ae92968SFrançois Revol 
964ae92968SFrançois Revol 
974ae92968SFrançois Revol extern "C" void
cpu_init()984ae92968SFrançois Revol cpu_init()
994ae92968SFrançois Revol {
1004ae92968SFrançois Revol 	if (check_cpu_features() != B_OK)
10114016c7cSFrançois Revol 		panic("You need a 68030 or higher in order to boot!\n");
1024ae92968SFrançois Revol 
1034ae92968SFrançois Revol 	gKernelArgs.num_cpus = 1;
1044ae92968SFrançois Revol 		// this will eventually be corrected later on
1054ae92968SFrançois Revol 		// ...or not!
1064ae92968SFrançois Revol }
1074ae92968SFrançois Revol 
108*39a7a69bSJérôme Duval 
109*39a7a69bSJérôme Duval extern "C" void
platform_load_ucode(BootVolume & volume)110*39a7a69bSJérôme Duval platform_load_ucode(BootVolume& volume)
111*39a7a69bSJérôme Duval {
112*39a7a69bSJérôme Duval }
113*39a7a69bSJérôme Duval 
114