xref: /haiku/src/system/boot/platform/u-boot/arch/ppc/arch_cpu.cpp (revision 6c4a44e36ba846c54467103f884d65dfa13e7fcb)
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 "board_config.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/ppc/arch_cpu.h>
20 #include <arch_kernel.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 //uint32 gTimeConversionFactor;
34 
35 
36 static void
37 calculate_cpu_conversion_factor()
38 {
39 	#warning U-Boot:TODO!
40 }
41 
42 
43 static status_t
44 check_cpu_features()
45 {
46 	uint32 msr;
47 
48 #if BOARD_CPU_TYPE_PPC440
49 	// the FPU is implemented as an Auxiliary Processing Unit,
50 	// so we must enable transfers by setting the DAPUIB bit to 0
51 	asm volatile(
52 		"mfccr0 %%r3\n"
53 		"\tlis %%r4,~(1<<(20-16))\n"
54 		"\tand %%r3,%%r3,%%r4\n"
55 		"\tmtccr0 %%r3"
56 		: : : "r3", "r4");
57 #endif
58 
59 	// we do need an FPU for vsnprintf to work
60 	// on Sam460ex at least U-Boot doesn't enable the FPU for us
61 	msr = get_msr();
62 	msr |= MSR_FP_AVAILABLE;
63 	msr = set_msr(msr);
64 
65 	if ((msr & MSR_FP_AVAILABLE) == 0) {
66 		// sadly panic uses vsnprintf which fails without FPU anyway
67 		panic("no FPU!");
68 		return B_ERROR;
69 	}
70 
71 	return B_OK;
72 }
73 
74 
75 //	#pragma mark -
76 
77 
78 extern "C" void
79 arch_spin(bigtime_t microseconds)
80 {
81 	for(bigtime_t i=0;i<microseconds;i=i+1)
82 	{
83 		/*
84 		asm volatile ("mov r0,r0");
85 		asm volatile ("mov r0,r0");
86 		*/
87 	}
88 	#warning U-Boot:PPC:TODO!!
89 }
90 
91 
92 extern "C" status_t
93 boot_arch_cpu_init(void)
94 {
95 	status_t err = check_cpu_features();
96 
97 	if (err != B_OK) {
98 		panic("You need a Pentium or higher in order to boot!\n");
99 		return err;
100 	}
101 
102 	calculate_cpu_conversion_factor();
103 
104 	gKernelArgs.num_cpus = 1;
105 		// this will eventually be corrected later on
106 
107 	return B_OK;
108 }
109 
110