1 /* 2 * Copyright 2007, François Revol, revol@free.fr. 3 * Distributed under the terms of the MIT License. 4 * 5 * Copyright 2006, Ingo Weinhold <bonefish@cs.tu-berlin.de>. 6 * All rights reserved. Distributed under the terms of the MIT License. 7 */ 8 9 #include <arch_platform.h> 10 11 #include <new> 12 13 #include <KernelExport.h> 14 15 #include <boot/kernel_args.h> 16 //#include <platform/openfirmware/openfirmware.h> 17 #include <real_time_clock.h> 18 #include <util/kernel_cpp.h> 19 20 21 static M68KPlatform *sM68KPlatform; 22 23 24 // constructor 25 M68KPlatform::M68KPlatform(m68k_platform_type platformType) 26 : fPlatformType(platformType) 27 { 28 } 29 30 // destructor 31 M68KPlatform::~M68KPlatform() 32 { 33 } 34 35 // Default 36 M68KPlatform * 37 M68KPlatform::Default() 38 { 39 return sM68KPlatform; 40 } 41 42 43 // #pragma mark - Amiga 44 45 46 // #pragma mark - Apple 47 48 namespace BPrivate { 49 50 class M68KApple : public M68KPlatform { 51 public: 52 M68KApple(); 53 virtual ~M68KApple(); 54 55 virtual status_t Init(struct kernel_args *kernelArgs); 56 virtual status_t InitSerialDebug(struct kernel_args *kernelArgs); 57 virtual status_t InitPostVM(struct kernel_args *kernelArgs); 58 virtual status_t InitRTC(struct kernel_args *kernelArgs, 59 struct real_time_data *data); 60 61 virtual char SerialDebugGetChar(); 62 virtual void SerialDebugPutChar(char c); 63 64 //virtual void SetHardwareRTC(uint32 seconds); 65 //virtual uint32 GetHardwareRTC(); 66 67 virtual void ShutDown(bool reboot); 68 69 private: 70 int fRTC; 71 }; 72 73 } // namespace BPrivate 74 75 using BPrivate::M68KApple; 76 77 // constructor 78 M68KApple::M68KApple() 79 : M68KPlatform(M68K_PLATFORM_OPEN_FIRMWARE), 80 fRTC(-1) 81 { 82 } 83 84 // destructor 85 M68KApple::~M68KApple() 86 { 87 } 88 89 // Init 90 status_t 91 M68KApple::Init(struct kernel_args *kernelArgs) 92 { 93 return of_init( 94 (int(*)(void*))kernelArgs->platform_args.openfirmware_entry); 95 } 96 97 // InitSerialDebug 98 status_t 99 M68KApple::InitSerialDebug(struct kernel_args *kernelArgs) 100 { 101 return B_OK; 102 } 103 104 // InitPostVM 105 status_t 106 M68KApple::InitPostVM(struct kernel_args *kernelArgs) 107 { 108 return B_OK; 109 } 110 111 // InitRTC 112 status_t 113 M68KApple::InitRTC(struct kernel_args *kernelArgs, 114 struct real_time_data *data) 115 { 116 return B_OK; 117 } 118 119 // DebugSerialGetChar 120 char 121 M68KApple::SerialDebugGetChar() 122 { 123 int key; 124 return (char)key; 125 } 126 127 // DebugSerialPutChar 128 void 129 M68KApple::SerialDebugPutChar(char c) 130 { 131 } 132 133 // ShutDown 134 void 135 M68KApple::ShutDown(bool reboot) 136 { 137 if (reboot) { 138 of_interpret("reset-all", 0, 0); 139 } else { 140 // not standardized, so it might fail 141 of_interpret("shut-down", 0, 0); 142 } 143 } 144 145 146 // #pragma mark - Atari (Falcon) 147 148 149 namespace BPrivate { 150 151 class M68KAtari : public M68KPlatform { 152 public: 153 M68KAtari(); 154 virtual ~M68KAtari(); 155 156 virtual status_t Init(struct kernel_args *kernelArgs); 157 virtual status_t InitSerialDebug(struct kernel_args *kernelArgs); 158 virtual status_t InitPostVM(struct kernel_args *kernelArgs); 159 virtual status_t InitRTC(struct kernel_args *kernelArgs, 160 struct real_time_data *data); 161 162 virtual char SerialDebugGetChar(); 163 virtual void SerialDebugPutChar(char c); 164 165 //virtual void SetHardwareRTC(uint32 seconds); 166 //virtual uint32 GetHardwareRTC(); 167 168 virtual void ShutDown(bool reboot); 169 170 private: 171 int fRTC; 172 }; 173 174 } // namespace BPrivate 175 176 using BPrivate::M68KAtari; 177 178 // constructor 179 M68KAtari::M68KAtari() 180 : M68KPlatform(M68K_PLATFORM_OPEN_FIRMWARE), 181 fRTC(-1) 182 { 183 } 184 185 // destructor 186 M68KAtari::~M68KAtari() 187 { 188 } 189 190 // Init 191 status_t 192 M68KAtari::Init(struct kernel_args *kernelArgs) 193 { 194 return of_init( 195 (int(*)(void*))kernelArgs->platform_args.openfirmware_entry); 196 } 197 198 // InitSerialDebug 199 status_t 200 M68KAtari::InitSerialDebug(struct kernel_args *kernelArgs) 201 { 202 if (of_getprop(gChosen, "stdin", &fInput, sizeof(int)) == OF_FAILED) 203 return B_ERROR; 204 if (of_getprop(gChosen, "stdout", &fOutput, sizeof(int)) == OF_FAILED) 205 return B_ERROR; 206 207 return B_OK; 208 } 209 210 // InitPostVM 211 status_t 212 M68KAtari::InitPostVM(struct kernel_args *kernelArgs) 213 { 214 add_debugger_command("of_exit", &debug_command_of_exit, 215 "Exit to the Open Firmware prompt. No way to get back into the OS!"); 216 add_debugger_command("of_enter", &debug_command_of_enter, 217 "Enter a subordinate Open Firmware interpreter. Quitting it returns " 218 "to KDL."); 219 220 return B_OK; 221 } 222 223 // InitRTC 224 status_t 225 M68KAtari::InitRTC(struct kernel_args *kernelArgs, 226 struct real_time_data *data) 227 { 228 // open RTC 229 fRTC = of_open(kernelArgs->platform_args.rtc_path); 230 if (fRTC == OF_FAILED) { 231 dprintf("M68KAtari::InitRTC(): Failed open RTC device!\n"); 232 return B_ERROR; 233 } 234 235 return B_OK; 236 } 237 238 // DebugSerialGetChar 239 char 240 M68KAtari::SerialDebugGetChar() 241 { 242 int key; 243 if (of_interpret("key", 0, 1, &key) == OF_FAILED) 244 return 0; 245 return (char)key; 246 } 247 248 // DebugSerialPutChar 249 void 250 M68KAtari::SerialDebugPutChar(char c) 251 { 252 if (c == '\n') 253 of_write(fOutput, "\r\n", 2); 254 else 255 of_write(fOutput, &c, 1); 256 } 257 258 // ShutDown 259 void 260 M68KAtari::ShutDown(bool reboot) 261 { 262 if (reboot) { 263 of_interpret("reset-all", 0, 0); 264 } else { 265 // not standardized, so it might fail 266 of_interpret("shut-down", 0, 0); 267 } 268 } 269 270 271 // # pragma mark - 272 273 274 // static buffer for constructing the actual M68KPlatform 275 static char *sM68KPlatformBuffer[sizeof(M68KAtari)]; 276 277 status_t 278 arch_platform_init(struct kernel_args *kernelArgs) 279 { 280 #warning M68K: switch platform from kernel args 281 // only Atari supported for now 282 if (true) 283 sM68KPlatform = new(sM68KPlatformBuffer) M68KAtari; 284 285 return sM68KPlatform->Init(kernelArgs); 286 } 287 288 289 status_t 290 arch_platform_init_post_vm(struct kernel_args *kernelArgs) 291 { 292 return sM68KPlatform->InitPostVM(kernelArgs); 293 } 294 295 296 status_t 297 arch_platform_init_post_thread(struct kernel_args *kernelArgs) 298 { 299 return B_OK; 300 } 301