static void *map_first_meg(uintptr_t phys_addr, size_t len) { if (realmem_map) return realmem_map + phys_addr; realmem_map = valloc(1024 * 1024); if (!realmem_map) return ERROR_PTR; if (__djgpp_map_physical_memory(realmem_map, (1024 * 1024), 0)) { free(realmem_map); realmem_map = NULL; return ERROR_PTR; } return realmem_map + phys_addr; }
/* Attempts to mmap sufficient memory for the specified video mode * over the memory pointed to by vdriver_fbuf, which must be * page-aligned. Returns TRUE if successful, else FALSE. */ boolean_t vgahost_mmap_linear_fbuf (const vga_mode_t *mode) { boolean_t success_p; success_p = FALSE; /* Default */ if (mode->phys_base_addr != 0) /* do we have a linear frame buffer? */ { if (!__djgpp_map_physical_memory (vdriver_fbuf, ((mode->height * mode->row_bytes + DPMI_PAGE_SIZE - 1) & ~(DPMI_PAGE_SIZE - 1)), mode->phys_base_addr)) { success_p = TRUE; } else if (mode->screen_selector != 0 && try_to_use_fat_ds_vga_hack_p) { /* We failed to mmap it the DPMI 1.0 way, so we'll see if we * can use the fat %ds hack. */ if (__djgpp_nearptr_enable ()) { unsigned long executor_base = 0, fbuf_base = 0; if (!__dpmi_get_segment_base_address (dos_pm_ds, &executor_base) && !__dpmi_get_segment_base_address (mode->screen_selector, &fbuf_base)) { vdriver_fbuf = (uint8 *) (fbuf_base - executor_base); actually_using_fat_ds_vga_hack_p = TRUE; success_p = TRUE; } } } } if (success_p) { /* Cool beans. Note that the screen is in our address space. */ vga_screen_selector = dos_pm_ds; } return success_p; }