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_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 #warning M68K: TODO: probe ourselves, we shouldnt trust the TOS! 40 41 const tos_cookie *c; 42 uint16 cpu_type, fpu_type, fpu_emul; 43 uint16 machine_type; 44 int fpu = 0; 45 46 c = tos_find_cookie('_CPU'); 47 if (!c) { 48 panic("can't get a cookie (_CPU)!"); 49 return EINVAL; 50 } 51 cpu_type = (uint16) c->ivalue; 52 53 dump_tos_cookies(); 54 55 #warning M68K: check for 020 + mmu 56 if (cpu_type < 30/*20*/) 57 return EINVAL; 58 59 #warning M68K: check cpu type passed to kern args 60 gKernelArgs.arch_args.cpu_type = 68000 + cpu_type; 61 gKernelArgs.arch_args.mmu_type = 68000 + cpu_type; 62 gKernelArgs.arch_args.has_lpstop = (cpu_type >= 60)?true:false; 63 64 c = tos_find_cookie('_FPU'); 65 if (!c) { 66 panic("can't get a cookie (_FPU)!"); 67 return EINVAL; 68 } 69 fpu_type = (uint16)(c->ivalue >> 16); 70 fpu_emul = (uint16)(c->ivalue); 71 72 // http://toshyp.atari.org/003007.htm#Cookie_2C_20_FPU 73 if (fpu_type & 0x10) 74 fpu = 68060; 75 else if (fpu_type & 0x8) 76 fpu = 68040; 77 else if (fpu_type & 0x6 == 0x6) 78 fpu = 68882; 79 else if (fpu_type & 0x6 == 0x4) 80 fpu = 68881; 81 else if (fpu_type & 0x6 == 0x2) 82 fpu = 68881; // not certain 83 else if (fpu_type & 0x4) { 84 panic("bad fpu"); 85 return EINVAL; 86 } 87 gKernelArgs.arch_args.fpu_type = fpu; 88 89 gKernelArgs.arch_args.platform = M68K_PLATFORM_ATARI; 90 91 c = tos_find_cookie('_MCH'); 92 if (!c) { 93 panic("can't get a cookie (_MCH)!"); 94 return EINVAL; 95 } 96 machine_type = (uint16)(c->ivalue >> 16); 97 gKernelArgs.arch_args.machine = machine_type; 98 99 return B_OK; 100 } 101 102 #warning M68K: move and implement system_time() 103 static bigtime_t gSystemTimeCounter = 0; //HACK 104 extern "C" bigtime_t 105 system_time(void) 106 { 107 // _hz_200 108 //return (*TOSVAR_hz_200) * 1000000LL / 200; 109 return gSystemTimeCounter++; 110 } 111 112 113 // #pragma mark - 114 115 116 extern "C" void 117 spin(bigtime_t microseconds) 118 { 119 bigtime_t time = system_time(); 120 while ((system_time() - time) < microseconds) 121 asm volatile ("nop;"); 122 } 123 124 125 extern "C" void 126 cpu_init() 127 { 128 if (check_cpu_features() != B_OK) 129 panic("You need a 68020 or higher in order to boot!\n"); 130 131 gKernelArgs.num_cpus = 1; 132 // this will eventually be corrected later on 133 // ...or not! 134 } 135 136