1 /* 2 * Copyright 2003-2006, Axel Dörfler, axeld@pinc-software.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7 #include <KernelExport.h> 8 #include <boot/platform.h> 9 #include <boot/partitions.h> 10 #include <boot/stdio.h> 11 #include <boot/stage2.h> 12 13 #include <string.h> 14 15 #include "Handle.h" 16 #include "rom_calls.h" 17 18 //#define TRACE_DEVICES 19 #ifdef TRACE_DEVICES 20 # define TRACE(x) dprintf x 21 #else 22 # define TRACE(x) ; 23 #endif 24 25 26 // exported from shell.S 27 extern uint8 gBootedFromImage; 28 extern uint8 gBootDriveAPI; // ATARI_BOOT_DRIVE_API_* 29 extern uint8 gBootDriveID; 30 extern uint32 gBootPartitionOffset; 31 32 #define SCRATCH_SIZE (2*4096) 33 static uint8 gScratchBuffer[SCRATCH_SIZE]; 34 35 36 // #pragma mark - 37 38 39 ExecDevice::ExecDevice(struct IORequest *ioRequest) 40 { 41 fIORequest = ioRequest; 42 fIOStdReq = (struct IOStdReq *)ioRequest; 43 } 44 45 46 ExecDevice::ExecDevice(size_t requestSize) 47 { 48 AllocRequest(requestSize); 49 } 50 51 52 ExecDevice::ExecDevice() 53 { 54 } 55 56 57 ExecDevice::~ExecDevice() 58 { 59 CloseDevice(fIORequest); 60 DeleteIORequest(fIORequest); 61 } 62 63 64 status_t 65 ExecDevice::AllocRequest(size_t requestSize) 66 { 67 struct MsgPort *inputPort = CreateMsgPort(); 68 if (inputPort == NULL) 69 panic("CreateMsgPort()"); 70 71 fIORequest = (struct IORequest *)CreateIORequest(inputPort, requestSize); 72 if (fIORequest == NULL) 73 panic("CreateIORequest()"); 74 fIOStdReq = (struct IOStdReq *)fIORequest; 75 return B_ERROR; 76 } 77 78 79 status_t 80 ExecDevice::Open(const char *name, unsigned long unit, unsigned long flags) 81 { 82 status_t err; 83 err = exec_error(OpenDevice((uint8 *)name, unit, fIORequest, flags)); 84 if (err < B_OK) 85 return err; 86 return B_OK; 87 } 88 89 90 ssize_t 91 ExecDevice::ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize) 92 { 93 fIOStdReq->io_Command = CMD_READ; 94 fIOStdReq->io_Length = bufferSize; 95 fIOStdReq->io_Data = buffer; 96 fIOStdReq->io_Offset = (uint32)pos; 97 status_t err = Do(); 98 if (err < B_OK) 99 return err; 100 return (ssize_t)fIOStdReq->io_Actual; 101 } 102 103 104 ssize_t 105 ExecDevice::WriteAt(void *cookie, off_t pos, const void *buffer, size_t bufferSize) 106 { 107 fIOStdReq->io_Command = CMD_WRITE; 108 fIOStdReq->io_Length = bufferSize; 109 fIOStdReq->io_Data = (void *)buffer; 110 fIOStdReq->io_Offset = (uint32)pos; 111 status_t err = Do(); 112 if (err < B_OK) 113 return err; 114 return (ssize_t)fIOStdReq->io_Actual; 115 } 116 117 118 off_t 119 ExecDevice::Size() const 120 { 121 122 // ToDo: fix this! 123 return 1024LL * 1024 * 1024 * 1024; 124 // 1024 GB 125 } 126 127 128 status_t 129 ExecDevice::Do() 130 { 131 status_t err; 132 err = exec_error(DoIO(fIORequest)); 133 return err; 134 } 135 136 137 status_t 138 ExecDevice::Clear() 139 { 140 fIOStdReq->io_Command = CMD_CLEAR; 141 status_t err = Do(); 142 if (err < B_OK) 143 return err; 144 return B_OK; 145 } 146 147 148 // #pragma mark - 149 150 151 status_t 152 platform_add_boot_device(struct stage2_args *args, NodeList *devicesList) 153 { 154 TRACE(("boot drive ID: %x\n", gBootDriveID)); 155 156 //TODO 157 gKernelArgs.boot_volume.SetBool(BOOT_VOLUME_BOOTED_FROM_IMAGE, 158 gBootedFromImage); 159 160 return B_OK; 161 } 162 163 164 status_t 165 platform_get_boot_partition(struct stage2_args *args, Node *bootDevice, 166 NodeList *list, boot::Partition **_partition) 167 { 168 169 //TODO 170 171 return B_ENTRY_NOT_FOUND; 172 } 173 174 175 status_t 176 platform_add_block_devices(stage2_args *args, NodeList *devicesList) 177 { 178 //TODO 179 return B_ERROR; 180 } 181 182 183 status_t 184 platform_register_boot_device(Node *device) 185 { 186 //TODO 187 188 return B_OK; 189 } 190 191