From 94903138ac9a9c35fbdb24bbd90d9c94213395f3 Mon Sep 17 00:00:00 2001 From: Matt Fleming Date: Thu, 8 Dec 2011 14:34:57 +0000 Subject: [PATCH] disk: Add .disk_init() to firmware struct Each firmware has its own method of initialising a disk so allow each firmware backend to implement a separate disk_init() function. Make all the assembly callers of fs_init() jump through pm_fs_init(), which allows us to restrict the com32sys_t arguments to only those callers that really need it, e.g. the .asm files. Signed-off-by: Matt Fleming --- com32/include/syslinux/firmware.h | 4 ++++ com32/lib/syslinux/firmware.c | 1 + core/diskstart.inc | 2 +- core/extern.inc | 2 +- core/fs/diskio.c | 20 +++++++++++--------- core/fs/fs.c | 20 +++++++++----------- core/include/disk.h | 4 ++-- core/isolinux.asm | 2 +- core/pxelinux.asm | 2 +- 9 files changed, 31 insertions(+), 26 deletions(-) diff --git a/com32/include/syslinux/firmware.h b/com32/include/syslinux/firmware.h index edb0f94..2a7d066 100644 --- a/com32/include/syslinux/firmware.h +++ b/com32/include/syslinux/firmware.h @@ -1,11 +1,15 @@ #ifndef _SYSLINUX_FIRMWARE_H #define _SYSLINUX_FIRMWARE_H +#include +#include + struct firmware { void (*init)(void); int (*scan_memory)(scan_memory_callback_t, void *); void (*adjust_screen)(void); void (*cleanup)(void); + struct disk *(*disk_init)(struct disk_private *); }; extern struct firmware *firmware; diff --git a/com32/lib/syslinux/firmware.c b/com32/lib/syslinux/firmware.c index e5dc68b..1b8e1b0 100644 --- a/com32/lib/syslinux/firmware.c +++ b/com32/lib/syslinux/firmware.c @@ -11,6 +11,7 @@ struct firmware bios_fw = { .scan_memory = bios_scan_memory, .adjust_screen = bios_adjust_screen, .cleanup = bios_cleanup_hardware, + .disk_init = bios_disk_init, }; void syslinux_register_bios(void) diff --git a/core/diskstart.inc b/core/diskstart.inc index c8f7936..0c27d57 100644 --- a/core/diskstart.inc +++ b/core/diskstart.inc @@ -503,7 +503,7 @@ expand_super: mov si,[bsHeads] mov di,[bsSecPerTrack] movzx ebp,word [MaxTransfer] - pm_call fs_init + pm_call pm_fs_init pm_call load_env32 popad diff --git a/core/extern.inc b/core/extern.inc index da3d894..72afe7a 100644 --- a/core/extern.inc +++ b/core/extern.inc @@ -32,7 +32,7 @@ extern mem_init ; fs.c - extern fs_init, pm_searchdir, getfssec, getfsbytes + extern pm_fs_init, pm_searchdir, getfssec, getfsbytes extern pm_mangle_name, pm_load_config extern pm_open_file, pm_close_file extern SectorSize, SectorShift diff --git a/core/fs/diskio.c b/core/fs/diskio.c index 6683816..1644eae 100644 --- a/core/fs/diskio.c +++ b/core/fs/diskio.c @@ -8,6 +8,8 @@ #include #include +#include + #define RETRY_COUNT 6 static inline sector_t chs_max(const struct disk *disk) @@ -298,13 +300,17 @@ void getoneblk(struct disk *disk, char *buf, block_t block, int block_size) } -struct disk *disk_init(uint8_t devno, bool cdrom, sector_t part_start, - uint16_t bsHeads, uint16_t bsSecPerTrack, - uint32_t MaxTransfer) +struct disk *bios_disk_init(com32sys_t *regs) { static struct disk disk; static __lowmem struct edd_disk_params edd_params; com32sys_t ireg, oreg; + uint8_t devno = regs->edx.b[0]; + bool cdrom = regs->edx.b[1]; + sector_t part_start = regs->ecx.l | ((sector_t)regs->ebx.l << 32); + uint16_t bsHeads = regs->esi.w[0]; + uint16_t bsSecPerTrack = regs->edi.w[0]; + uint32_t MaxTransfer = regs->ebp.l; bool ebios; int sector_size; unsigned int hard_max_transfer; @@ -402,16 +408,12 @@ struct disk *disk_init(uint8_t devno, bool cdrom, sector_t part_start, * * NOTE: the disk cache needs to be revamped to support multiple devices... */ -struct device * device_init(uint8_t devno, bool cdrom, sector_t part_start, - uint16_t bsHeads, uint16_t bsSecPerTrack, - uint32_t MaxTransfer) +struct device * device_init(void *args) { static struct device dev; static __hugebss char diskcache[128*1024]; - dev.disk = disk_init(devno, cdrom, part_start, - bsHeads, bsSecPerTrack, MaxTransfer); - + dev.disk = firmware->disk_init(args); dev.cache_data = diskcache; dev.cache_size = sizeof diskcache; diff --git a/core/fs/fs.c b/core/fs/fs.c index a4fb4f7..c2d17dc 100644 --- a/core/fs/fs.c +++ b/core/fs/fs.c @@ -428,22 +428,16 @@ void pm_close_file(com32sys_t *regs) * invoke the fs-specific init function; * initialize the cache if we need one; * finally, get the current inode for relative path looking. + * + * ops is a ptr list for several fs_ops */ __bss16 uint16_t SectorSize, SectorShift; -void fs_init(com32sys_t *regs) +void fs_init(const struct fs_ops **ops, void *args) { static struct fs_info fs; /* The actual filesystem buffer */ - uint8_t disk_devno = regs->edx.b[0]; - uint8_t disk_cdrom = regs->edx.b[1]; - sector_t disk_offset = regs->ecx.l | ((sector_t)regs->ebx.l << 32); - uint16_t disk_heads = regs->esi.w[0]; - uint16_t disk_sectors = regs->edi.w[0]; - uint32_t maxtransfer = regs->ebp.l; int blk_shift = -1; struct device *dev = NULL; - /* ops is a ptr list for several fs_ops */ - const struct fs_ops **ops = (const struct fs_ops **)regs->eax.l; /* Initialize malloc() */ mem_init(); @@ -463,8 +457,7 @@ void fs_init(com32sys_t *regs) fs.fs_dev = NULL; } else { if (!dev) - dev = device_init(disk_devno, disk_cdrom, disk_offset, - disk_heads, disk_sectors, maxtransfer); + dev = device_init(args); fs.fs_dev = dev; } /* invoke the fs-specific init code */ @@ -496,3 +489,8 @@ void fs_init(com32sys_t *regs) SectorShift = fs.sector_shift; SectorSize = fs.sector_size; } + +void pm_fs_init(com32sys_t *regs) +{ + fs_init(regs->eax.l, regs); +} diff --git a/core/include/disk.h b/core/include/disk.h index ac23e92..dd37715 100644 --- a/core/include/disk.h +++ b/core/include/disk.h @@ -31,7 +31,7 @@ extern void read_sectors(char *, sector_t, int); extern void getoneblk(struct disk *, char *, block_t, int); /* diskio.c */ -struct disk *disk_init(uint8_t, bool, sector_t, uint16_t, uint16_t, uint32_t); -struct device *device_init(uint8_t, bool, sector_t, uint16_t, uint16_t, uint32_t); +struct disk *bios_disk_init(com32sys_t *); +struct device *device_init(void *); #endif /* DISK_H */ diff --git a/core/isolinux.asm b/core/isolinux.asm index bc6878b..cb64d8a 100644 --- a/core/isolinux.asm +++ b/core/isolinux.asm @@ -1166,7 +1166,7 @@ init_fs: mov ebx,[Hidden+4] mov si,[bsHeads] mov di,[bsSecPerTrack] - pm_call fs_init + pm_call pm_fs_init pm_call load_env32 popad diff --git a/core/pxelinux.asm b/core/pxelinux.asm index e4c2f83..d990553 100644 --- a/core/pxelinux.asm +++ b/core/pxelinux.asm @@ -222,7 +222,7 @@ adhcp_copy: ; mov eax,ROOT_FS_OPS xor ebp,ebp - pm_call fs_init + pm_call pm_fs_init pm_call load_env32 section .rodata -- 2.7.4