summaryrefslogtreecommitdiffstats
path: root/physmap.c
diff options
context:
space:
mode:
authorRudolf Marek <r.marek@assembler.cz>2017-12-29 16:30:49 +0100
committerNico Huber <nico.h@gmx.de>2018-01-06 22:38:58 +0000
commit25fde40f8594b1c13ba7a4c3a605b96b200a4e11 (patch)
tree8e19343934bcd9be2503441b556ccf4e0871fed2 /physmap.c
parent73c882086fe7d6fac9859e2faa93ec56cc96b9bd (diff)
downloadflashrom-25fde40f8594b1c13ba7a4c3a605b96b200a4e11.tar.gz
flashrom-25fde40f8594b1c13ba7a4c3a605b96b200a4e11.tar.bz2
flashrom-25fde40f8594b1c13ba7a4c3a605b96b200a4e11.zip
Fix the documentation and DOS port
Update the DOS cross-compile documentation, and workaround issue with valloc() with the latest DJGPP. Change-Id: I909c5635aec5076440d2fde73d943f8ad10b8051 Signed-off-by: Rudolf Marek <r.marek@assembler.cz> Reviewed-on: https://review.coreboot.org/23039 Reviewed-by: Nico Huber <nico.h@gmx.de> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'physmap.c')
-rw-r--r--physmap.c31
1 files changed, 21 insertions, 10 deletions
diff --git a/physmap.c b/physmap.c
index a261ccd51..3338b6209 100644
--- a/physmap.c
+++ b/physmap.c
@@ -38,29 +38,40 @@
#ifdef __DJGPP__
#include <dpmi.h>
+#include <malloc.h>
#include <sys/nearptr.h>
+#define ONE_MEGABYTE (1024 * 1024)
#define MEM_DEV "dpmi"
-static void *realmem_map;
+static void *realmem_map_aligned;
static void *map_first_meg(uintptr_t phys_addr, size_t len)
{
- if (realmem_map)
- return realmem_map + phys_addr;
+ void *realmem_map;
+ size_t pagesize;
- realmem_map = valloc(1024 * 1024);
+ if (realmem_map_aligned)
+ return realmem_map_aligned + phys_addr;
+
+ /* valloc() from DJGPP 2.05 does not work properly */
+ pagesize = getpagesize();
+
+ realmem_map = malloc(ONE_MEGABYTE + pagesize);
if (!realmem_map)
return ERROR_PTR;
- if (__djgpp_map_physical_memory(realmem_map, (1024 * 1024), 0)) {
+ realmem_map_aligned = (void *)(((size_t) realmem_map +
+ (pagesize - 1)) & ~(pagesize - 1));
+
+ if (__djgpp_map_physical_memory(realmem_map_aligned, ONE_MEGABYTE, 0)) {
free(realmem_map);
- realmem_map = NULL;
+ realmem_map_aligned = NULL;
return ERROR_PTR;
}
- return realmem_map + phys_addr;
+ return realmem_map_aligned + phys_addr;
}
static void *sys_physmap(uintptr_t phys_addr, size_t len)
@@ -72,7 +83,7 @@ static void *sys_physmap(uintptr_t phys_addr, size_t len)
if (!__djgpp_nearptr_enable())
return ERROR_PTR;
- if ((phys_addr + len - 1) < (1024 * 1024)) {
+ if ((phys_addr + len - 1) < ONE_MEGABYTE) {
/* We need to use another method to map first 1MB. */
return map_first_meg(phys_addr, len);
}
@@ -97,8 +108,8 @@ void sys_physunmap_unaligned(void *virt_addr, size_t len)
/* There is no known way to unmap the first 1 MB. The DPMI server will
* do this for us on exit.
*/
- if ((virt_addr >= realmem_map) &&
- ((virt_addr + len) <= (realmem_map + (1024 * 1024)))) {
+ if ((virt_addr >= realmem_map_aligned) &&
+ ((virt_addr + len) <= (realmem_map_aligned + ONE_MEGABYTE))) {
return;
}