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