add transfer size parameter to usbStorage out function
1 parent 7adf23b commit ae45fca6a859ec3af4db225496d5f4b931552311
@biosfood biosfood authored on 13 Nov 2023
Showing 3 changed files
View
3
■■
src/userland/scisi/include/scisi.h
} ScisiDevice;
 
typedef struct {
uint32_t size;
uint32_t transferSize;
uint8_t operationCode; // 0x12
uint8_t evpd; // probably 0
uint8_t pageCode; // must be 0 when evpd is 0
uint8_t allocationLengthHigh; // should be at least 5
} InquiryResponse;
 
typedef struct {
uint32_t size;
uint32_t transferSize;
uint8_t operationCode; // 0x25
uint8_t obsolete;
uint32_t LBAObsolete; // set to 0, must be inserted with MSB first.
uint16_t reserved;
} ReadCapacity10Response;
 
typedef struct {
uint32_t size;
uint32_t transferSize;
uint8_t operationCode; // 0x28
uint8_t protect; // leave at 0 for now
uint8_t lba[4]; // most significant byte first
uint8_t groupNumber; // probably 0
View
25
src/userland/scisi/main.c
ListElement *devices = NULL;
 
void doInquiry(ScisiDevice *device) {
InquiryCommand *command = malloc(sizeof(InquiryCommand));
command->size = sizeof(InquiryCommand) - 2*sizeof(uint32_t);
command->transferSize = 5;
command->operationCode = 0x12;
command->pageCode = 0;
command->evpd = 0;
command->allocationLengthHigh = 0;
InquiryResponse *response = malloc(sizeof(InquiryResponse));
response->size = sizeof(InquiryResponse) - sizeof(uint32_t);
request(device->serviceId, device->inFunction, device->in, U32(getPhysicalAddress(response)));
command->allocationLengthLow = 5 + response->additionalLength;
command->transferSize = command->allocationLengthLow;
request(device->serviceId, device->outFunction, device->out, U32(getPhysicalAddress(command)));
request(device->serviceId, device->inFunction, device->in, U32(getPhysicalAddress(response)));
free(command);
}
 
void readSize(ScisiDevice *device) {
ReadCapacity10Command *command = malloc(sizeof(ReadCapacity10Command));
command->size = sizeof(ReadCapacity10Command) - sizeof(uint32_t);
command->size = sizeof(ReadCapacity10Command) - 2*sizeof(uint32_t);
command->transferSize = sizeof(ReadCapacity10Response) - sizeof(uint32_t);
command->operationCode = 0x25;
command->control = 0;
 
request(device->serviceId, device->outFunction, device->out, U32(getPhysicalAddress(command)));
void *read(ScisiDevice *device, uint32_t address, uint16_t size) {
if (size == 0) {
return malloc(1);
}
uint32_t blockCount = (size-1) / device->blockSize + 1;
Read10Command *command = malloc(sizeof(Read10Command));
command->size = sizeof(Read10Command) - sizeof(uint32_t);
command->size = sizeof(Read10Command) - 2*sizeof(uint32_t);
command->transferSize = size;
command->operationCode = 0x28;
command->lba[0] = (uint8_t) (address >> 24);
command->lba[1] = (uint8_t) (address >> 16);
command->lba[2] = (uint8_t) (address >> 8);
command->lba[3] = (uint8_t) (address);
uint32_t blockCount = (size-1) / device->blockSize + 1;
command->transferLength[0] = (uint8_t) (blockCount >> 8);
command->transferLength[1] = (uint8_t) (blockCount);
 
command->control = 0;
request(device->serviceId, device->inFunction, device->in, U32(getPhysicalAddress(data)));
free(command);
return data + 1; // todo: ensure free will work on this
}
 
void *doRead(uint32_t deviceSize, uint32_t blockId) {
uint32_t deviceId = deviceSize & 0xFFFF;
ScisiDevice *device = listGet(devices, deviceId);
void *result = read(device, blockId, deviceSize >> 16);
printf("reading %i bytes from position %i from device %i: %x\n", deviceSize >> 16, blockId, deviceId, getPhysicalAddress(result));
return getPhysicalAddress(result);
}
 
REQUEST(registerMBR, "mbr", "register");
 
int32_t registerDevice(uint32_t in, uint32_t out, uint32_t serviceName, uint32_t serviceId) {
ScisiDevice *device = malloc(sizeof(ScisiDevice));
device->serviceId = serviceId;
if (buffer[510] == 0x55 && buffer[511] == 0xAA) {
printf("device %i is bootable!\n", device->id);
}
free(buffer - 4);
registerMBR(device->id, 0);
return 0;
}
 
int32_t main() {
createFunction("register", (void *)registerDevice);
createFunction("mbr_read", (void *)doRead);
return 0;
}
View
src/userland/usbStorage/main.c