From: beeanyew Date: Fri, 11 Jun 2021 07:09:50 +0000 (+0200) Subject: Some PiSCSI file system reloc changes X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=41566c18c94123db9f4342564240ca758a8e78e1;p=pistorm Some PiSCSI file system reloc changes --- 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 b178cfc..83b3bbf 100644 Binary files a/platforms/amiga/piscsi/device_driver_amiga/bootrom and b/platforms/amiga/piscsi/device_driver_amiga/bootrom differ 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 9c5553a..eaac293 100644 Binary files a/platforms/amiga/piscsi/device_driver_amiga/pi-scsi.device and b/platforms/amiga/piscsi/device_driver_amiga/pi-scsi.device differ 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 1a1f792..59f9d6f 100644 Binary files a/platforms/amiga/piscsi/piscsi.rom and b/platforms/amiga/piscsi/piscsi.rom differ