From d5d02b6c979da4baeae3a35e7f149881203e6255 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sun, 6 Jun 2010 16:18:03 -0400 Subject: [PATCH] Allocate cdemu buffer in low mem instead of ebda. Using the low memory buffer gives more flexibility with the final location of the buffer. Don't allocate the buffer at all if no cdrom drives are present. --- src/biosvar.h | 2 -- src/cdrom.c | 33 ++++++++++++++++++--------------- src/post.c | 2 +- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/biosvar.h b/src/biosvar.h index ea2d67d..dce35af 100644 --- a/src/biosvar.h +++ b/src/biosvar.h @@ -234,8 +234,6 @@ struct extended_bios_data_area_s { // Stack space available for code that needs it. u8 extra_stack[512] __aligned(8); - - u8 cdemu_buf[2048 * !!CONFIG_CDROM_EMU]; } PACKED; // The initial size and location of EBDA diff --git a/src/cdrom.c b/src/cdrom.c index f7af425..655ee00 100644 --- a/src/cdrom.c +++ b/src/cdrom.c @@ -17,6 +17,9 @@ * CD emulation ****************************************************************/ +struct drive_s *cdemu_drive_gf VAR16VISIBLE; +u8 *cdemu_buf_fl VAR16VISIBLE; + static int cdemu_read(struct disk_op_s *op) { @@ -30,12 +33,12 @@ cdemu_read(struct disk_op_s *op) int count = op->count; op->count = 0; - u8 *cdbuf_far = (void*)offsetof(struct extended_bios_data_area_s, cdemu_buf); + u8 *cdbuf_fl = GET_GLOBAL(cdemu_buf_fl); if (op->lba & 3) { // Partial read of first block. dop.count = 1; - dop.buf_fl = MAKE_FLATPTR(ebda_seg, cdbuf_far); + dop.buf_fl = cdbuf_fl; int ret = process_op(&dop); if (ret) return ret; @@ -43,10 +46,7 @@ cdemu_read(struct disk_op_s *op) if (thiscount > count) thiscount = count; count -= thiscount; - memcpy_far(FLATPTR_TO_SEG(op->buf_fl) - , (void*)FLATPTR_TO_OFFSET(op->buf_fl) - , ebda_seg, cdbuf_far + (op->lba & 3) * 512 - , thiscount * 512); + memcpy_fl(op->buf_fl, cdbuf_fl + (op->lba & 3) * 512, thiscount * 512); op->buf_fl += thiscount * 512; op->count += thiscount; dop.lba++; @@ -69,14 +69,12 @@ cdemu_read(struct disk_op_s *op) if (count) { // Partial read on last block. dop.count = 1; - dop.buf_fl = MAKE_FLATPTR(ebda_seg, cdbuf_far); + dop.buf_fl = cdbuf_fl; int ret = process_op(&dop); if (ret) return ret; u8 thiscount = count; - memcpy_far(FLATPTR_TO_SEG(op->buf_fl) - , (void*)FLATPTR_TO_OFFSET(op->buf_fl) - , ebda_seg, cdbuf_far, thiscount * 512); + memcpy_fl(op->buf_fl, cdbuf_fl, thiscount * 512); op->count += thiscount; } @@ -106,22 +104,27 @@ process_cdemu_op(struct disk_op_s *op) } } -struct drive_s *cdemu_drive_gf VAR16VISIBLE; - void cdemu_setup(void) { if (!CONFIG_CDROM_EMU) return; + cdemu_drive_gf = NULL; + cdemu_buf_fl = NULL; + if (!Drives.cdcount) + return; struct drive_s *drive_g = malloc_fseg(sizeof(*drive_g)); - if (! drive_g) { + u8 *buf = malloc_low(CDROM_SECTOR_SIZE); + if (!drive_g || !buf) { warn_noalloc(); - cdemu_drive_gf = NULL; + free(drive_g); + free(buf); return; } - memset(drive_g, 0, sizeof(*drive_g)); cdemu_drive_gf = drive_g; + cdemu_buf_fl = buf; + memset(drive_g, 0, sizeof(*drive_g)); drive_g->type = DTYPE_CDEMU; drive_g->blksize = DISK_SECTOR_SIZE; drive_g->sectors = (u64)-1; diff --git a/src/post.c b/src/post.c index 25535e2..fc7acc5 100644 --- a/src/post.c +++ b/src/post.c @@ -217,7 +217,6 @@ post(void) // Initialize internal tables boot_setup(); drive_setup(); - cdemu_setup(); // Start hardware initialization (if optionrom threading) if (CONFIG_THREADS && CONFIG_THREAD_OPTIONROMS) @@ -250,6 +249,7 @@ post(void) boot_prep(); // Finalize data structures before boot + cdemu_setup(); pmm_finalize(); malloc_finalize(); memmap_finalize(); -- 2.39.5