]> git.sesse.net Git - pistorm/blobdiff - platforms/amiga/piscsi/piscsi.h
Some non-working loading of file systems from disk for PiSCSI
[pistorm] / platforms / amiga / piscsi / piscsi.h
index 7940a4f887b5fcb4f7a4bed936a5620eed878a5a..b9384118cd504c7b1b35b63a50db21d5b51fcf43 100644 (file)
@@ -1,3 +1,9 @@
+// SPDX-License-Identifier: MIT
+
+#include <stdint.h>
+
+#include "platforms/amiga/hunk-reloc.h"
+
 #define        TDF_EXTCOM (1<<15)
 
 #define CMD_INVALID    0
 #define NSCMD_TD_FORMAT64 0xC003
 
 #define RDB_BLOCK_LIMIT 16
-#define RDB_IDENTIFIER 0x5244534B
 
-void piscsi_init();
-void piscsi_map_drive(char *filename, uint8_t index);
-
-void handle_piscsi_write(uint32_t addr, uint32_t val, uint8_t type);
-uint32_t handle_piscsi_read(uint32_t addr, uint8_t type);
+// RDSK
+#define RDB_IDENTIFIER 0x5244534B
+// PART
+#define PART_IDENTIFIER 0x50415254
+// FSHD
+#define        FS_IDENTIFIER 0x46534844
 
-void piscsi_block_op(uint8_t type, uint8_t num, uint32_t dest, uint32_t len);
+#define PISCSI_DRIVER_OFFSET 0x1000
+#define NUM_FILESYSTEMS 32
 
 struct piscsi_dev {
     uint32_t c;
@@ -63,34 +70,51 @@ struct piscsi_dev {
     uint64_t fs;
     int32_t fd;
     uint32_t lba;
-    // Will parse max eight partitions per disk
+    uint32_t num_partitions;
+    uint32_t fshd_offs;
+    uint32_t block_size;
     struct PartitionBlock *pb[16];
     struct RigidDiskBlock *rdb;
 };
 
-/*
-dosnode: \
+struct piscsi_fs {
+   struct FileSysHeaderBlock * fhb;
+   uint32_t FS_ID;
+   uint32_t handler;
+   struct hunk_reloc relocs[4096];
+   struct hunk_info h_info;
+   uint8_t *binary_data;
+};
+
 //  .long 0 /* dos disk name */
 //  .long 0 /* device file name */
 //  .long 0 /* unit */
 //  .long 0 /* flags */
-//  .long 16 /* length of node? */
-//  .long 128 /* longs in a block */
-//  .long 0
-//  .long 4 /* surfaces */
-//  .long 1 /* sectors per block */
-//  .long 256 /* blocks per track */
-//  .long 2 /* reserved bootblocks 256 = 128KB */
-//  .long 0
-//  .long 0
-//  .long 2  /* lowcyl FIXME */
-//  /*.long 2047*/ /* hicyl */
-//  .long 10 /* buffers */
-//  .long 0 /* MEMF_ANY */
-//  .long 0x0001fe00 /* MAXTRANS */
-//  .long 0x7ffffffe /* Mask */
-//  .long -1 /* boot prio */
-//  .long 0x444f5303 /* dostype: DOS3 */1
+struct DosEnvec {
+    uint32_t de_TableSize;          /* Size of Environment vector */
+    uint32_t de_SizeBlock;          /* in longwords: standard value is 128 */
+    uint32_t de_SecOrg;             /* not used; must be 0 */
+    uint32_t de_Surfaces;           /* # of heads (surfaces). drive specific */
+    uint32_t de_SectorPerBlock; /* not used; must be 1 */
+    uint32_t de_BlocksPerTrack; /* blocks per track. drive specific */
+    uint32_t de_Reserved;           /* DOS reserved blocks at start of partition. */
+    uint32_t de_PreAlloc;           /* DOS reserved blocks at end of partition */
+    uint32_t de_Interleave;     /* usually 0 */
+    uint32_t de_LowCyl;             /* starting cylinder. typically 0 */
+    uint32_t de_HighCyl;            /* max cylinder. drive specific */
+    uint32_t de_NumBuffers;     /* Initial # DOS of buffers.  */
+    uint32_t de_BufMemType;     /* type of mem to allocate for buffers */
+    uint32_t de_MaxTransfer;    /* Max number of bytes to transfer at a time */
+    uint32_t de_Mask;       /* Address Mask to block out certain memory */
+    int32_t  de_BootPri;            /* Boot priority for autoboot */
+    uint32_t de_DosType;            /* ASCII (HEX) string showing filesystem type;
+                             * 0X444F5300 is old filesystem,
+                             * 0X444F5301 is fast file system */
+    uint32_t de_Baud;       /* Baud rate for serial handler */
+    uint32_t de_Control;            /* Control word for handler/filesystem */
+    uint32_t de_BootBlocks;     /* Number of blocks containing boot code */
+
+};
 
 struct pihd_dosnode_data {
     uint32_t name_ptr;
@@ -105,7 +129,7 @@ struct pihd_dosnode_data {
     uint32_t blocks_per_track;
     uint32_t reserved_blocks;
     uint32_t pad2;
-    uint32_t pad3;
+    uint32_t interleave;
     uint32_t lowcyl;
     uint32_t highcyl;
     uint32_t buffers;
@@ -159,6 +183,20 @@ struct RigidDiskBlock {
     char    rdb_DriveInitName[40];
 };
 
+struct DeviceNode {
+    uint32_t    dn_Next;
+    uint32_t    dn_Type;
+    uint32_t    dn_Task;
+    uint32_t    dn_Lock;
+    uint8_t        *dn_Handler;
+    uint32_t    dn_StackSize;
+    int32_t     dn_Priority;
+    uint32_t    dn_Startup;
+    uint32_t    dn_SegList;
+    uint32_t    dn_GlobalVec;
+    uint8_t     *dn_Name;
+};
+
 struct PartitionBlock {
     uint32_t   pb_ID;
     uint32_t   pb_SummedLongs;
@@ -173,3 +211,59 @@ struct PartitionBlock {
     uint32_t   pb_Environment[20];
     uint32_t   pb_EReserved[12];
 };
+
+struct SCSICmd_ModeSense6 {
+    uint8_t opcode;
+    uint8_t reserved_dbd;
+    uint8_t pc_pagecode;
+    uint8_t subpage_code;
+    uint8_t alloc_len;
+    uint8_t control;
+};
+
+struct SCSICmd_RW10 {
+    uint8_t opcode;
+    uint8_t rdprotect_flags;
+    uint32_t block;
+    uint8_t res_groupnum;
+    uint16_t len;
+    uint8_t control;
+};
+
+struct FileSysHeaderBlock {
+    uint32_t   fhb_ID;
+    uint32_t   fhb_SummedLongs;
+    int32_t    fhb_ChkSum;
+    uint32_t   fhb_HostID;
+    uint32_t   fhb_Next;
+    uint32_t   fhb_Flags;
+    uint32_t   fhb_Reserved1[2];
+    uint32_t   fhb_DosType;
+    uint32_t   fhb_Version;
+    uint32_t   fhb_PatchFlags;
+    uint32_t   fhb_Type;
+    uint32_t   fhb_Task;
+    uint32_t   fhb_Lock;
+    uint32_t   fhb_Handler;
+    uint32_t   fhb_StackSize;
+    int32_t    fhb_Priority;
+    int32_t    fhb_Startup;
+    int32_t    fhb_SegListBlocks;
+    int32_t    fhb_GlobalVec;
+    uint32_t   fhb_Reserved2[23];
+    uint8_t    fhb_FileSysName[84];
+};
+
+void piscsi_init();
+void piscsi_shutdown();
+void piscsi_map_drive(char *filename, uint8_t index);
+void piscsi_unmap_drive(uint8_t index);
+struct piscsi_dev *piscsi_get_dev(uint8_t index);
+
+void handle_piscsi_write(uint32_t addr, uint32_t val, uint8_t type);
+uint32_t handle_piscsi_read(uint32_t addr, uint8_t type);
+
+void piscsi_find_filesystems(struct piscsi_dev *d);
+void piscsi_refresh_drives();
+
+int load_fs(struct piscsi_fs *fs, char *dosID);