ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SheepShaver/src/Unix/main_unix.cpp
(Generate patch)

Comparing SheepShaver/src/Unix/main_unix.cpp (file contents):
Revision 1.55 by gbeauche, 2005-01-30T18:49:48Z vs.
Revision 1.56 by gbeauche, 2005-01-30T21:19:07Z

# Line 105 | Line 105
105   #include "xpram.h"
106   #include "timer.h"
107   #include "adb.h"
108 #include "sony.h"
109 #include "disk.h"
110 #include "cdrom.h"
111 #include "scsi.h"
108   #include "video.h"
113 #include "audio.h"
114 #include "ether.h"
115 #include "serial.h"
116 #include "clip.h"
117 #include "extfs.h"
109   #include "sys.h"
110   #include "macos_util.h"
111   #include "rom_patches.h"
112   #include "user_strings.h"
113   #include "vm_alloc.h"
114   #include "sigsegv.h"
124 #include "thunks.h"
115  
116   #define DEBUG 0
117   #include "debug.h"
# Line 456 | Line 446 | static void usage(const char *prg_name)
446   int main(int argc, char **argv)
447   {
448          char str[256];
459        int16 i16;
449          int rom_fd;
450          FILE *proc_file;
451          const char *rom_path;
# Line 909 | Line 898 | int main(int argc, char **argv)
898          }
899          delete[] rom_tmp;
900  
901 <        // Load NVRAM
902 <        XPRAMInit();
914 <
915 <        // Load XPRAM default values if signature not found
916 <        if (XPRAM[0x130c] != 0x4e || XPRAM[0x130d] != 0x75
917 <         || XPRAM[0x130e] != 0x4d || XPRAM[0x130f] != 0x63) {
918 <                D(bug("Loading XPRAM default values\n"));
919 <                memset(XPRAM + 0x1300, 0, 0x100);
920 <                XPRAM[0x130c] = 0x4e;   // "NuMc" signature
921 <                XPRAM[0x130d] = 0x75;
922 <                XPRAM[0x130e] = 0x4d;
923 <                XPRAM[0x130f] = 0x63;
924 <                XPRAM[0x1301] = 0x80;   // InternalWaitFlags = DynWait (don't wait for SCSI devices upon bootup)
925 <                XPRAM[0x1310] = 0xa8;   // Standard PRAM values
926 <                XPRAM[0x1311] = 0x00;
927 <                XPRAM[0x1312] = 0x00;
928 <                XPRAM[0x1313] = 0x22;
929 <                XPRAM[0x1314] = 0xcc;
930 <                XPRAM[0x1315] = 0x0a;
931 <                XPRAM[0x1316] = 0xcc;
932 <                XPRAM[0x1317] = 0x0a;
933 <                XPRAM[0x131c] = 0x00;
934 <                XPRAM[0x131d] = 0x02;
935 <                XPRAM[0x131e] = 0x63;
936 <                XPRAM[0x131f] = 0x00;
937 <                XPRAM[0x1308] = 0x13;
938 <                XPRAM[0x1309] = 0x88;
939 <                XPRAM[0x130a] = 0x00;
940 <                XPRAM[0x130b] = 0xcc;
941 <                XPRAM[0x1376] = 0x00;   // OSDefault = MacOS
942 <                XPRAM[0x1377] = 0x01;
943 <        }
944 <
945 <        // Set boot volume
946 <        i16 = PrefsFindInt32("bootdrive");
947 <        XPRAM[0x1378] = i16 >> 8;
948 <        XPRAM[0x1379] = i16 & 0xff;
949 <        i16 = PrefsFindInt32("bootdriver");
950 <        XPRAM[0x137a] = i16 >> 8;
951 <        XPRAM[0x137b] = i16 & 0xff;
952 <
953 <        // Create BootGlobs at top of Mac memory
954 <        memset(RAMBaseHost + RAMSize - 4096, 0, 4096);
955 <        BootGlobsAddr = RAMBase + RAMSize - 0x1c;
956 <        WriteMacInt32(BootGlobsAddr - 5 * 4, RAMBase + RAMSize);        // MemTop
957 <        WriteMacInt32(BootGlobsAddr + 0 * 4, RAMBase);                          // First RAM bank
958 <        WriteMacInt32(BootGlobsAddr + 1 * 4, RAMSize);
959 <        WriteMacInt32(BootGlobsAddr + 2 * 4, (uint32)-1);                       // End of bank table
960 <
961 <        // Init thunks
962 <        if (!ThunksInit())
963 <                goto quit;
964 <
965 <        // Init drivers
966 <        SonyInit();
967 <        DiskInit();
968 <        CDROMInit();
969 <        SCSIInit();
970 <
971 <        // Init external file system
972 <        ExtFSInit();
973 <
974 <        // Init ADB
975 <        ADBInit();
976 <
977 <        // Init audio
978 <        AudioInit();
979 <
980 <        // Init network
981 <        EtherInit();
982 <
983 <        // Init serial ports
984 <        SerialInit();
985 <
986 <        // Init Time Manager
987 <        TimerInit();
988 <
989 <        // Init clipboard
990 <        ClipInit();
991 <
992 <        // Init video
993 <        if (!VideoInit())
994 <                goto quit;
995 <
996 <        // Install ROM patches
997 <        if (!PatchROM()) {
998 <                ErrorAlert(GetString(STR_UNSUPPORTED_ROM_TYPE_ERR));
901 >        // Initialize everything
902 >        if (!InitAll())
903                  goto quit;
904 <        }
904 >        D(bug("Initialization complete\n"));
905  
906          // Clear caches (as we loaded and patched code) and write protect ROM
907   #if !EMULATED_PPC
# Line 1005 | Line 909 | int main(int argc, char **argv)
909   #endif
910          vm_protect(ROMBaseHost, ROM_AREA_SIZE, VM_PAGE_READ | VM_PAGE_EXECUTE);
911  
1008        // Initialize Kernel Data
1009        memset(kernel_data, 0, sizeof(KernelData));
1010        if (ROMType == ROMTYPE_NEWWORLD) {
1011                uint32 of_dev_tree = SheepMem::Reserve(4 * sizeof(uint32));
1012                Mac_memset(of_dev_tree, 0, 4 * sizeof(uint32));
1013                uint32 vector_lookup_tbl = SheepMem::Reserve(128);
1014                uint32 vector_mask_tbl = SheepMem::Reserve(64);
1015                memset((uint8 *)kernel_data + 0xb80, 0x3d, 0x80);
1016                Mac_memset(vector_lookup_tbl, 0, 128);
1017                Mac_memset(vector_mask_tbl, 0, 64);
1018                kernel_data->v[0xb80 >> 2] = htonl(ROM_BASE);
1019                kernel_data->v[0xb84 >> 2] = htonl(of_dev_tree);                        // OF device tree base
1020                kernel_data->v[0xb90 >> 2] = htonl(vector_lookup_tbl);
1021                kernel_data->v[0xb94 >> 2] = htonl(vector_mask_tbl);
1022                kernel_data->v[0xb98 >> 2] = htonl(ROM_BASE);                           // OpenPIC base
1023                kernel_data->v[0xbb0 >> 2] = htonl(0);                                          // ADB base
1024                kernel_data->v[0xc20 >> 2] = htonl(RAMSize);
1025                kernel_data->v[0xc24 >> 2] = htonl(RAMSize);
1026                kernel_data->v[0xc30 >> 2] = htonl(RAMSize);
1027                kernel_data->v[0xc34 >> 2] = htonl(RAMSize);
1028                kernel_data->v[0xc38 >> 2] = htonl(0x00010020);
1029                kernel_data->v[0xc3c >> 2] = htonl(0x00200001);
1030                kernel_data->v[0xc40 >> 2] = htonl(0x00010000);
1031                kernel_data->v[0xc50 >> 2] = htonl(RAMBase);
1032                kernel_data->v[0xc54 >> 2] = htonl(RAMSize);
1033                kernel_data->v[0xf60 >> 2] = htonl(PVR);
1034                kernel_data->v[0xf64 >> 2] = htonl(CPUClockSpeed);                      // clock-frequency
1035                kernel_data->v[0xf68 >> 2] = htonl(BusClockSpeed);                      // bus-frequency
1036                kernel_data->v[0xf6c >> 2] = htonl(TimebaseSpeed);                      // timebase-frequency
1037        } else if (ROMType == ROMTYPE_GOSSAMER) {
1038                kernel_data->v[0xc80 >> 2] = htonl(RAMSize);
1039                kernel_data->v[0xc84 >> 2] = htonl(RAMSize);
1040                kernel_data->v[0xc90 >> 2] = htonl(RAMSize);
1041                kernel_data->v[0xc94 >> 2] = htonl(RAMSize);
1042                kernel_data->v[0xc98 >> 2] = htonl(0x00010020);
1043                kernel_data->v[0xc9c >> 2] = htonl(0x00200001);
1044                kernel_data->v[0xca0 >> 2] = htonl(0x00010000);
1045                kernel_data->v[0xcb0 >> 2] = htonl(RAMBase);
1046                kernel_data->v[0xcb4 >> 2] = htonl(RAMSize);
1047                kernel_data->v[0xf60 >> 2] = htonl(PVR);
1048                kernel_data->v[0xf64 >> 2] = htonl(CPUClockSpeed);                      // clock-frequency
1049                kernel_data->v[0xf68 >> 2] = htonl(BusClockSpeed);                      // bus-frequency
1050                kernel_data->v[0xf6c >> 2] = htonl(TimebaseSpeed);                      // timebase-frequency
1051        } else {
1052                kernel_data->v[0xc80 >> 2] = htonl(RAMSize);
1053                kernel_data->v[0xc84 >> 2] = htonl(RAMSize);
1054                kernel_data->v[0xc90 >> 2] = htonl(RAMSize);
1055                kernel_data->v[0xc94 >> 2] = htonl(RAMSize);
1056                kernel_data->v[0xc98 >> 2] = htonl(0x00010020);
1057                kernel_data->v[0xc9c >> 2] = htonl(0x00200001);
1058                kernel_data->v[0xca0 >> 2] = htonl(0x00010000);
1059                kernel_data->v[0xcb0 >> 2] = htonl(RAMBase);
1060                kernel_data->v[0xcb4 >> 2] = htonl(RAMSize);
1061                kernel_data->v[0xf80 >> 2] = htonl(PVR);
1062                kernel_data->v[0xf84 >> 2] = htonl(CPUClockSpeed);                      // clock-frequency
1063                kernel_data->v[0xf88 >> 2] = htonl(BusClockSpeed);                      // bus-frequency
1064                kernel_data->v[0xf8c >> 2] = htonl(TimebaseSpeed);                      // timebase-frequency
1065        }
1066
1067        // Initialize extra low memory
1068        D(bug("Initializing Low Memory...\n"));
1069        Mac_memset(0, 0, 0x3000);
1070        WriteMacInt32(XLM_SIGNATURE, FOURCC('B','a','a','h'));                  // Signature to detect SheepShaver
1071        WriteMacInt32(XLM_KERNEL_DATA, KernelDataAddr);                                 // For trap replacement routines
1072        WriteMacInt32(XLM_PVR, PVR);                                                                    // Theoretical PVR
1073        WriteMacInt32(XLM_BUS_CLOCK, BusClockSpeed);                                    // For DriverServicesLib patch
1074        WriteMacInt16(XLM_EXEC_RETURN_OPCODE, M68K_EXEC_RETURN);                // For Execute68k() (RTS from the executed 68k code will jump here and end 68k mode)
1075        WriteMacInt32(XLM_ZERO_PAGE, SheepMem::ZeroPage());                             // Pointer to read-only page with all bits set to 0
1076 #if !EMULATED_PPC
1077        WriteMacInt32(XLM_TOC, (uint32)TOC);                                                            // TOC pointer of emulator
1078 #endif
1079        WriteMacInt32(XLM_ETHER_INIT, NativeFunction(NATIVE_ETHER_INIT));       // DLPI ethernet driver functions
1080        WriteMacInt32(XLM_ETHER_TERM, NativeFunction(NATIVE_ETHER_TERM));
1081        WriteMacInt32(XLM_ETHER_OPEN, NativeFunction(NATIVE_ETHER_OPEN));
1082        WriteMacInt32(XLM_ETHER_CLOSE, NativeFunction(NATIVE_ETHER_CLOSE));
1083        WriteMacInt32(XLM_ETHER_WPUT, NativeFunction(NATIVE_ETHER_WPUT));
1084        WriteMacInt32(XLM_ETHER_RSRV, NativeFunction(NATIVE_ETHER_RSRV));
1085        WriteMacInt32(XLM_VIDEO_DOIO, NativeFunction(NATIVE_VIDEO_DO_DRIVER_IO));
1086        D(bug("Low Memory initialized\n"));
1087
912          // Start 60Hz thread
913          tick_thread_cancel = false;
914          tick_thread_active = (pthread_create(&tick_thread, NULL, tick_func, NULL) == 0);
# Line 1185 | Line 1009 | static void Quit(void)
1009          }
1010   #endif
1011  
1012 <        // Save NVRAM
1013 <        XPRAMExit();
1190 <
1191 <        // Exit clipboard
1192 <        ClipExit();
1193 <
1194 <        // Exit Time Manager
1195 <        TimerExit();
1196 <
1197 <        // Exit serial
1198 <        SerialExit();
1199 <
1200 <        // Exit network
1201 <        EtherExit();
1202 <
1203 <        // Exit audio
1204 <        AudioExit();
1205 <
1206 <        // Exit ADB
1207 <        ADBExit();
1208 <
1209 <        // Exit video
1210 <        VideoExit();
1211 <
1212 <        // Exit external file system
1213 <        ExtFSExit();
1214 <
1215 <        // Exit drivers
1216 <        SCSIExit();
1217 <        CDROMExit();
1218 <        DiskExit();
1219 <        SonyExit();
1220 <
1221 <        // Delete thunks
1222 <        ThunksExit();
1012 >        // Deinitialize everything
1013 >        ExitAll();
1014  
1015          // Delete SheepShaver globals
1016          SheepMem::Exit();
# Line 1500 | Line 1291 | void MakeExecutable(int dummy, uint32 st
1291   }
1292  
1293  
1503 /*
1504 *  Patch things after system startup (gets called by disk driver accRun routine)
1505 */
1506
1507 void PatchAfterStartup(void)
1508 {
1509        ExecuteNative(NATIVE_VIDEO_INSTALL_ACCEL);
1510        InstallExtFS();
1511 }
1512
1513
1294   /*
1295   *  NVRAM watchdog thread (saves NVRAM every minute)
1296   */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines