]> git.sesse.net Git - pistorm/commitdiff
Some PiSCSI file system reloc changes
authorbeeanyew <beeanyew@gmail.com>
Fri, 11 Jun 2021 07:09:50 +0000 (09:09 +0200)
committerbeeanyew <beeanyew@gmail.com>
Fri, 11 Jun 2021 07:09:50 +0000 (09:09 +0200)
platforms/amiga/hunk-reloc.c
platforms/amiga/hunk-reloc.h
platforms/amiga/piscsi/device_driver_amiga/bootrom
platforms/amiga/piscsi/device_driver_amiga/bootrom.s
platforms/amiga/piscsi/device_driver_amiga/pi-scsi.device
platforms/amiga/piscsi/device_driver_amiga/piscsi-amiga-2.c
platforms/amiga/piscsi/piscsi.c
platforms/amiga/piscsi/piscsi.rom

index b19c900b95c1e4d3ec9688470d641e98fea6b542..e7c296dbbfa7896c646e0de5c4777303e99e77a4 100644 (file)
@@ -14,6 +14,8 @@
 #define lseek64 lseek
 #endif
 
+#define DEBUG_SPAMMY(...)
+//#define DEBUG_SPAMMY printf
 #define DEBUG(...)
 //#define DEBUG printf
 
@@ -55,10 +57,14 @@ int process_hunk(uint32_t index, struct hunk_info *info, FILE *f, struct hunk_re
     
     switch (index) {
         case HUNKTYPE_HEADER:
-            DEBUG("Processing hunk header.\n");
+            DEBUG("[HUNK_RELOC] Processing hunk HEADER.\n");
             do {
                 READLW(discard, f);
                 if (discard) {
+                    if (info->libnames[info->num_libs]) {
+                        free(info->libnames[info->num_libs]);
+                        info->libnames[info->num_libs] = NULL;
+                    }
                     info->libnames[info->num_libs] = malloc(discard * 4);
                     fread(info->libnames[info->num_libs], discard, 4, f);
                     info->num_libs++;
@@ -66,38 +72,48 @@ int process_hunk(uint32_t index, struct hunk_info *info, FILE *f, struct hunk_re
             } while (discard);
             
             READLW(info->table_size, f);
-            DEBUG("Table size: %d\n", info->table_size);
+            DEBUG("[HUNK_RELOC] [HEADER] Table size: %d\n", info->table_size);
             READLW(info->first_hunk, f);
             READLW(info->last_hunk, f);
             info->num_hunks = (info->last_hunk - info->first_hunk) + 1;
-            DEBUG("First: %d Last: %d Num: %d\n", info->first_hunk, info->last_hunk, info->num_hunks);
+            DEBUG("[HUNK_RELOC] [HEADER] First: %d Last: %d Num: %d\n", info->first_hunk, info->last_hunk, info->num_hunks);
+            if (info->hunk_sizes) {
+                free(info->hunk_sizes);
+                info->hunk_sizes = NULL;
+            }
+            if (info->hunk_offsets) {
+                free(info->hunk_offsets);
+                info->hunk_offsets = NULL;
+            }
             info->hunk_sizes = malloc(info->num_hunks * 4);
             info->hunk_offsets = malloc(info->num_hunks * 4);
             for (uint32_t i = 0; i < info->table_size; i++) {
                 READLW(info->hunk_sizes[i], f);
-                DEBUG("Hunk %d: %d (%.8X)\n", i, info->hunk_sizes[i] * 4, info->hunk_sizes[i] * 4);
+                DEBUG("[HUNK_RELOC] [HEADER] Hunk %d: %d (%.8X)\n", i, info->hunk_sizes[i] * 4, info->hunk_sizes[i] * 4);
             }
+            info->header_size = (uint32_t)ftell(f) - file_offset;
+            DEBUG("[HUNK_RELOC] [HEADER] ~~~~~~~~~~~ Hunk HEADER size is %d ~~~~~~~~~~~~.\n", info->header_size);
             return 0;
             break;
         case HUNKTYPE_CODE:
-            DEBUG("Hunk %d: CODE.\n", info->current_hunk);
+            DEBUG("[HUNK_RELOC] Hunk %d: CODE.\n", info->current_hunk);
             READLW(discard, f);
             info->hunk_offsets[info->current_hunk] = ftell(f) - file_offset;
-            DEBUG("Code hunk size: %d (%.8X)\n", discard * 4, discard * 4);
+            DEBUG("[HUNK_RELOC] [CODE] Code hunk size: %d (%.8X)\n", discard * 4, discard * 4);
             fseek(f, discard * 4, SEEK_CUR);
             return 0;
             break;
         case HUNKTYPE_HUNK_RELOC32:
-            DEBUG("Hunk %d: RELOC32.\n", info->current_hunk);
+            DEBUG("[HUNK_RELOC] Hunk %d: RELOC32.\n", info->current_hunk);
             DEBUG("Processing Reloc32 hunk.\n");
             do {
                 READLW(discard, f);
                 if (discard && discard != 0xFFFFFFFF) {
                     READLW(cur_hunk, f);
-                    DEBUG("Relocating %d offsets pointing to hunk %d.\n", discard, cur_hunk);
+                    DEBUG("[HUNK_RELOC] [RELOC32] Relocating %d offsets pointing to hunk %d.\n", discard, cur_hunk);
                     for(uint32_t i = 0; i < discard; i++) {
                         READLW(offs32, f);
-                        DEBUG("#%d: @%.8X in hunk %d\n", i + 1, offs32, cur_hunk);
+                        DEBUG_SPAMMY("[HUNK_RELOC] [RELOC32] #%d: @%.8X in hunk %d\n", i + 1, offs32, cur_hunk);
                         r[info->reloc_hunks].offset = offs32;
                         r[info->reloc_hunks].src_hunk = info->current_hunk;
                         r[info->reloc_hunks].target_hunk = cur_hunk;
@@ -108,8 +124,8 @@ int process_hunk(uint32_t index, struct hunk_info *info, FILE *f, struct hunk_re
             return 0;
             break;
         case HUNKTYPE_SYMBOL:
-            DEBUG("Hunk %d: SYMBOL.\n", info->current_hunk);
-            DEBUG("Processing Symbol hunk.\n");
+            DEBUG("[HUNK_RELOC] Hunk %d: SYMBOL.\n", info->current_hunk);
+            DEBUG("[HUNK_RELOC] [SYMBOL] Processing Symbol hunk.\n");
             READLW(discard, f);
             do {
                 if (discard) {
@@ -117,34 +133,34 @@ int process_hunk(uint32_t index, struct hunk_info *info, FILE *f, struct hunk_re
                     memset(sstr, 0x00, 256);
                     fread(sstr, discard, 4, f);
                     READLW(discard, f);
-                    DEBUG("Symbol: %s - %.8X\n", sstr, discard);
+                    DEBUG("[HUNK_RELOC] [SYMBOL] Symbol: %s - %.8X\n", sstr, discard);
                 }
                 READLW(discard, f);
             } while (discard);
             return 0;
             break;
         case HUNKTYPE_BSS:
-            DEBUG("Hunk %d: BSS.\n", info->current_hunk);
+            DEBUG("[HUNK_RELOC] Hunk %d: BSS.\n", info->current_hunk);
             READLW(discard, f);
             info->hunk_offsets[info->current_hunk] = ftell(f) - file_offset;
-            DEBUG("Skipping BSS hunk. Size: %d\n", discard * 4);
+            DEBUG("[HUNK_RELOC] [BSS] Skipping BSS hunk. Size: %d\n", discard * 4);
             add_size += (discard * 4);
             return 0;
         case HUNKTYPE_DATA:
-            DEBUG("Hunk %d: DATA.\n", info->current_hunk);
+            DEBUG("[HUNK_RELOC] Hunk %d: DATA.\n", info->current_hunk);
             READLW(discard, f);
             info->hunk_offsets[info->current_hunk] = ftell(f) - file_offset;
-            DEBUG("Skipping data hunk. Size: %d.\n", discard * 4);
+            DEBUG("[HUNK_RELOC] [DATA] Skipping data hunk. Size: %d.\n", discard * 4);
             fseek(f, discard * 4, SEEK_CUR);
             return 0;
             break;
         case HUNKTYPE_END:
-            DEBUG("END: Ending hunk %d.\n", info->current_hunk);
+            DEBUG("[HUNK_RELOC] END: Ending hunk %d.\n", info->current_hunk);
             info->current_hunk++;
             return 0;
             break;
         default:
-            DEBUG("Unknown hunk type %.8X! Can't process!\n", index);
+            DEBUG("[!!!HUNK_RELOC] Unknown hunk type %.8X! Can't process!\n", index);
             break;
     }
 
@@ -157,13 +173,13 @@ void reloc_hunk(struct hunk_reloc *h, uint8_t *buf, struct hunk_info *i) {
 
     uint32_t src = be32toh(*src_ptr);
     uint32_t dst = src + i->base_offset + rel;
-    DEBUG("%.8X -> %.8X\n", src, dst);
+    DEBUG_SPAMMY("[HUNK-RELOC] %.8X -> %.8X\n", src, dst);
     *src_ptr = htobe32(dst);
 }
 
 void process_hunks(FILE *in, struct hunk_info *h_info, struct hunk_reloc *r, uint32_t offset) {
     READLW(lw, in);
-    DEBUG("Hunk ID: %.8X (%s)\n", lw, hunk_id_name(lw));
+    DEBUG_SPAMMY("Hunk ID: %.8X (%s)\n", lw, hunk_id_name(lw));
 
     file_offset = offset;
     add_size = 0;
@@ -179,12 +195,12 @@ void process_hunks(FILE *in, struct hunk_info *h_info, struct hunk_reloc *r, uin
 }
 
 void reloc_hunks(struct hunk_reloc *r, uint8_t *buf, struct hunk_info *h_info) {
-    DEBUG("Relocating %d offsets.\n", h_info->reloc_hunks);
+    DEBUG("[HUNK-RELOC] Relocating %d offsets.\n", h_info->reloc_hunks);
     for (uint32_t i = 0; i < h_info->reloc_hunks; i++) {
-        DEBUG("Relocating offset %d.\n", i);
+        DEBUG_SPAMMY("[HUNK-RELOC] Relocating offset %d.\n", i);
         reloc_hunk(&r[i], buf, h_info);
     }
-    DEBUG("Done relocating offsets.\n");
+    DEBUG("[HUNK-RELOC] Done relocating offsets.\n");
 }
 
 struct LoadSegBlock {
index 8cb8c79c6bfc484ef5bdb021ba0b53b9df78190e..1e53492ce945490c822165cb6d225f8f908ab8b4 100644 (file)
@@ -13,7 +13,7 @@ struct hunk_info {
     uint8_t *libnames[256];
     uint32_t table_size, byte_size, alloc_size;
     uint32_t base_offset;
-    uint32_t first_hunk, last_hunk, num_hunks;
+    uint32_t first_hunk, last_hunk, num_hunks, header_size;
     uint32_t reloc_hunks;
     uint32_t *hunk_offsets;
     uint32_t *hunk_sizes;
index b178cfcbd1d452a84cd82052a0e325f60c74063b..83b3bbfa6be7c6a154e09f222f9ac9c6ad82b292 100644 (file)
Binary files a/platforms/amiga/piscsi/device_driver_amiga/bootrom and b/platforms/amiga/piscsi/device_driver_amiga/bootrom differ
index 19ba62a032fece7a94b5ccac9f2f2292248156e0..20145670b352e847a4afba3b9e110062e04fe268 100644 (file)
@@ -300,7 +300,7 @@ NoZ3:
             move.l  d0,a1
             move.l  #0,d1
             movea.l  4,a6
-            add.l #$02c,a1
+            add.l #$028,a1
             jsr InitResident(a6)        ; Initialize the PiSCSI driver
 
 SkipDriverLoad:
@@ -320,7 +320,7 @@ PartitionLoop:
             beq.w EndPartitions         ; If the next partition returns 0, there's no additional partitions
             move.l d0,a0
             jsr MakeDosNode(a6)
-            cmp.l #0,PiSCSIGetFSInfo      ; This does not work for some reason... not massively surprising...
+            cmp.l #0,PiSCSIGetFSInfo
             beq.s SkipLoadFS
 
             move.l d0,PiSCSILoadFS        ; Attempt to load the file system driver from data/fs
index 9c5553a6cf3e9e17d6a97ebc038fefbc954d6054..eaac293cec0986949460b8489bbc4337bf78224e 100644 (file)
Binary files a/platforms/amiga/piscsi/device_driver_amiga/pi-scsi.device and b/platforms/amiga/piscsi/device_driver_amiga/pi-scsi.device differ
index 8a28a7fff10f620bf0c1268a6994c4515f8b2cca..a325acb30f07a7706499a94b57b3ba8a9fb2bda5 100644 (file)
@@ -68,11 +68,6 @@ uint8_t is_open;
 #define READSHORT(cmd, var) var = *(volatile unsigned short *)(PISCSI_OFFSET + cmd);
 #define READLONG(cmd, var) var = *(volatile unsigned long *)(PISCSI_OFFSET + cmd);
 
-int __attribute__((no_reorder)) _start()
-{
-    return -1;
-}
-
 asm("romtag:                                \n"
     "       dc.w    "XSTR(RTC_MATCHWORD)"   \n"
     "       dc.l    romtag                  \n"
@@ -86,6 +81,11 @@ asm("romtag:                                \n"
     "       dc.l    _auto_init_tables       \n"
     "endcode:                               \n");
 
+int __attribute__((no_reorder)) _start()
+{
+    return -1;
+}
+
 char device_name[] = DEVICE_NAME;
 char device_id_string[] = DEVICE_ID_STRING;
 
index 433929e83f2bd30a5207bb237661c83cd8647676..263fb930c7bc58baa43140c26b137b762dd20bfb 100644 (file)
@@ -811,7 +811,7 @@ skip_disk:;
                 DEBUG("[PISCSI] Partition DOSType is %c%c%c/%d\n", dosID[0], dosID[1], dosID[2], dosID[3]);
                 for (i = 0; i < piscsi_num_fs; i++) {
                     if (rom_partition_dostype[rom_cur_partition] == filesystems[i].FS_ID) {
-                        node->dn_SegList = htobe32(((filesystems[i].handler) >> 2));
+                        node->dn_SegList = htobe32((((filesystems[i].handler) + filesystems[i].h_info.header_size) >> 2));
                         node->dn_GlobalVec = 0xFFFFFFFF;
                         goto fs_found;
                     }
index 1a1f79243f1d0e6d3631bc368f5f9b7643171fe0..59f9d6f2b3f267d2fc096710f7db8238fdce0afb 100644 (file)
Binary files a/platforms/amiga/piscsi/piscsi.rom and b/platforms/amiga/piscsi/piscsi.rom differ