1
From d5d02b6c979da4baeae3a35e7f149881203e6255 Mon Sep 17 00:00:00 2001
2
From: Kevin O'Connor <kevin@koconnor.net>
3
Date: Sun, 6 Jun 2010 16:18:03 -0400
4
Subject: [PATCH 34/54] Allocate cdemu buffer in low mem instead of ebda.
6
Using the low memory buffer gives more flexibility with the final
7
location of the buffer.
9
Don't allocate the buffer at all if no cdrom drives are present.
12
src/cdrom.c | 33 ++++++++++++++++++---------------
14
3 files changed, 19 insertions(+), 18 deletions(-)
16
diff --git a/src/biosvar.h b/src/biosvar.h
17
index ea2d67d..dce35af 100644
20
@@ -234,8 +234,6 @@ struct extended_bios_data_area_s {
22
// Stack space available for code that needs it.
23
u8 extra_stack[512] __aligned(8);
25
- u8 cdemu_buf[2048 * !!CONFIG_CDROM_EMU];
28
// The initial size and location of EBDA
29
diff --git a/src/cdrom.c b/src/cdrom.c
30
index f7af425..655ee00 100644
35
****************************************************************/
37
+struct drive_s *cdemu_drive_gf VAR16VISIBLE;
38
+u8 *cdemu_buf_fl VAR16VISIBLE;
41
cdemu_read(struct disk_op_s *op)
43
@@ -30,12 +33,12 @@ cdemu_read(struct disk_op_s *op)
45
int count = op->count;
47
- u8 *cdbuf_far = (void*)offsetof(struct extended_bios_data_area_s, cdemu_buf);
48
+ u8 *cdbuf_fl = GET_GLOBAL(cdemu_buf_fl);
51
// Partial read of first block.
53
- dop.buf_fl = MAKE_FLATPTR(ebda_seg, cdbuf_far);
54
+ dop.buf_fl = cdbuf_fl;
55
int ret = process_op(&dop);
58
@@ -43,10 +46,7 @@ cdemu_read(struct disk_op_s *op)
59
if (thiscount > count)
62
- memcpy_far(FLATPTR_TO_SEG(op->buf_fl)
63
- , (void*)FLATPTR_TO_OFFSET(op->buf_fl)
64
- , ebda_seg, cdbuf_far + (op->lba & 3) * 512
66
+ memcpy_fl(op->buf_fl, cdbuf_fl + (op->lba & 3) * 512, thiscount * 512);
67
op->buf_fl += thiscount * 512;
68
op->count += thiscount;
70
@@ -69,14 +69,12 @@ cdemu_read(struct disk_op_s *op)
72
// Partial read on last block.
74
- dop.buf_fl = MAKE_FLATPTR(ebda_seg, cdbuf_far);
75
+ dop.buf_fl = cdbuf_fl;
76
int ret = process_op(&dop);
80
- memcpy_far(FLATPTR_TO_SEG(op->buf_fl)
81
- , (void*)FLATPTR_TO_OFFSET(op->buf_fl)
82
- , ebda_seg, cdbuf_far, thiscount * 512);
83
+ memcpy_fl(op->buf_fl, cdbuf_fl, thiscount * 512);
84
op->count += thiscount;
87
@@ -106,22 +104,27 @@ process_cdemu_op(struct disk_op_s *op)
91
-struct drive_s *cdemu_drive_gf VAR16VISIBLE;
96
if (!CONFIG_CDROM_EMU)
98
+ cdemu_drive_gf = NULL;
99
+ cdemu_buf_fl = NULL;
100
+ if (!Drives.cdcount)
103
struct drive_s *drive_g = malloc_fseg(sizeof(*drive_g));
105
+ u8 *buf = malloc_low(CDROM_SECTOR_SIZE);
106
+ if (!drive_g || !buf) {
108
- cdemu_drive_gf = NULL;
113
- memset(drive_g, 0, sizeof(*drive_g));
114
cdemu_drive_gf = drive_g;
115
+ cdemu_buf_fl = buf;
116
+ memset(drive_g, 0, sizeof(*drive_g));
117
drive_g->type = DTYPE_CDEMU;
118
drive_g->blksize = DISK_SECTOR_SIZE;
119
drive_g->sectors = (u64)-1;
120
diff --git a/src/post.c b/src/post.c
121
index 25535e2..fc7acc5 100644
124
@@ -217,7 +217,6 @@ post(void)
125
// Initialize internal tables
130
// Start hardware initialization (if optionrom threading)
131
if (CONFIG_THREADS && CONFIG_THREAD_OPTIONROMS)
132
@@ -250,6 +249,7 @@ post(void)
135
// Finalize data structures before boot