From 41566c18c94123db9f4342564240ca758a8e78e1 Mon Sep 17 00:00:00 2001 From: beeanyew Date: Fri, 11 Jun 2021 09:09:50 +0200 Subject: [PATCH] Some PiSCSI file system reloc changes --- platforms/amiga/hunk-reloc.c | 62 +++++++++++------- platforms/amiga/hunk-reloc.h | 2 +- .../amiga/piscsi/device_driver_amiga/bootrom | Bin 2124 -> 2124 bytes .../piscsi/device_driver_amiga/bootrom.s | 4 +- .../piscsi/device_driver_amiga/pi-scsi.device | Bin 2856 -> 2856 bytes .../device_driver_amiga/piscsi-amiga-2.c | 10 +-- platforms/amiga/piscsi/piscsi.c | 2 +- platforms/amiga/piscsi/piscsi.rom | Bin 16384 -> 16384 bytes 8 files changed, 48 insertions(+), 32 deletions(-) diff --git a/platforms/amiga/hunk-reloc.c b/platforms/amiga/hunk-reloc.c index b19c900..e7c296d 100644 --- a/platforms/amiga/hunk-reloc.c +++ b/platforms/amiga/hunk-reloc.c @@ -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 { diff --git a/platforms/amiga/hunk-reloc.h b/platforms/amiga/hunk-reloc.h index 8cb8c79..1e53492 100644 --- a/platforms/amiga/hunk-reloc.h +++ b/platforms/amiga/hunk-reloc.h @@ -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; diff --git a/platforms/amiga/piscsi/device_driver_amiga/bootrom b/platforms/amiga/piscsi/device_driver_amiga/bootrom index b178cfcbd1d452a84cd82052a0e325f60c74063b..83b3bbfa6be7c6a154e09f222f9ac9c6ad82b292 100644 GIT binary patch delta 14 WcmX>ja7JLmQbtCN&C3{k-pUIjh? delta 14 WcmX>ja7JLmQbtCd&C3{k-pb_GHJ diff --git a/platforms/amiga/piscsi/device_driver_amiga/bootrom.s b/platforms/amiga/piscsi/device_driver_amiga/bootrom.s index 19ba62a..2014567 100644 --- a/platforms/amiga/piscsi/device_driver_amiga/bootrom.s +++ b/platforms/amiga/piscsi/device_driver_amiga/bootrom.s @@ -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 diff --git a/platforms/amiga/piscsi/device_driver_amiga/pi-scsi.device b/platforms/amiga/piscsi/device_driver_amiga/pi-scsi.device index 9c5553a6cf3e9e17d6a97ebc038fefbc954d6054..eaac293cec0986949460b8489bbc4337bf78224e 100644 GIT binary patch delta 82 zcmZ1>wnA)zhMdwnA)zhFrmazf!M13=9k`KrGjw%?zZ#fS-YZoo}O?A%`p*kk19gQa}+P2CHNQ U(n3HiHhBuiY(|F72An?_0ZDBPGynhq diff --git a/platforms/amiga/piscsi/device_driver_amiga/piscsi-amiga-2.c b/platforms/amiga/piscsi/device_driver_amiga/piscsi-amiga-2.c index 8a28a7f..a325acb 100644 --- a/platforms/amiga/piscsi/device_driver_amiga/piscsi-amiga-2.c +++ b/platforms/amiga/piscsi/device_driver_amiga/piscsi-amiga-2.c @@ -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; diff --git a/platforms/amiga/piscsi/piscsi.c b/platforms/amiga/piscsi/piscsi.c index 433929e..263fb93 100644 --- a/platforms/amiga/piscsi/piscsi.c +++ b/platforms/amiga/piscsi/piscsi.c @@ -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; } diff --git a/platforms/amiga/piscsi/piscsi.rom b/platforms/amiga/piscsi/piscsi.rom index 1a1f79243f1d0e6d3631bc368f5f9b7643171fe0..59f9d6f2b3f267d2fc096710f7db8238fdce0afb 100644 GIT binary patch delta 1655 zcmb7EUuaup6#soUx9M$rm)@pnNYbvoY11^e)AWxmh-Ic1(HcewSrzqRx%N-e$Yj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