1 /* 2 * Copyright 2003-2010, Axel Dörfler, axeld@pinc-software.de. 3 * Copyright 2011, Alexander von Gluck, kallisti5@unixzen.com 4 * Copyright 2019, Adrien Destugues, pulkomandy@pulkomandy.tk 5 * Distributed under the terms of the MIT License. 6 */ 7 8 9 #include "start.h" 10 11 #include "machine.h" 12 13 14 extern "C" void _start(uint32 _unused1, uint32 _unused2, 15 void *openFirmwareEntry); 16 17 // XCOFF "entry-point" is actually a pointer to the real code 18 extern "C" void *_coff_start; 19 void *_coff_start = (void *)&_start; 20 21 // GCC defined globals 22 extern uint8 __bss_start; 23 extern uint8 _end; 24 25 26 static void 27 clear_bss(void) 28 { 29 memset(&__bss_start, 0, &_end - &__bss_start); 30 } 31 32 33 void 34 determine_machine(void) 35 { 36 gMachine = MACHINE_UNKNOWN; 37 38 intptr_t root = of_finddevice("/"); 39 char buffer[64]; 40 int length; 41 42 // TODO : Probe other OpenFirmware platforms and set gMachine as needed 43 44 if ((length = of_getprop(root, "device_type", buffer, sizeof(buffer) - 1)) 45 != OF_FAILED) { 46 buffer[length] = '\0'; 47 if (!strcasecmp("chrp", buffer)) 48 gMachine = MACHINE_CHRP; 49 else if (!strcasecmp("bootrom", buffer)) 50 gMachine = MACHINE_MAC; 51 } else 52 gMachine = MACHINE_MAC; 53 54 if ((length = of_getprop(root, "model", buffer, sizeof(buffer) - 1)) 55 != OF_FAILED) { 56 buffer[length] = '\0'; 57 if (!strcasecmp("pegasos", buffer)) 58 gMachine |= MACHINE_PEGASOS; 59 } 60 61 if ((length = of_getprop(root, "name", buffer, sizeof(buffer) - 1)) 62 != OF_FAILED) { 63 buffer[length] = '\0'; 64 if (!strcasecmp("openbiosteam,openbios", buffer)) 65 gMachine |= MACHINE_QEMU; 66 } 67 } 68 69 70 extern "C" void __attribute__((section(".text.start"))) 71 _start(uint32 _unused1, uint32 _unused3, void *openFirmwareEntry) 72 { 73 // According to the PowerPC bindings, OpenFirmware should have created 74 // a stack of 32kB or higher for us at this point 75 76 clear_bss(); 77 call_ctors(); 78 // call C++ constructors before doing anything else 79 80 start(openFirmwareEntry); 81 } 82