10

I'm developing software for the IBM PC with an 8086 processor. I want my program to use all available memory.

I know that I can use DOS int 21h function AH=48h to allocate all available conventional memory between 0 and 640K. But how do I allocate and use all RAM between 640K and 1024K?

Maybe there is not much RAM there, only video memory, which can be very small (less than 68K in total). Nevertheless, I want to use everything available.

As a historical curiosity, were there any IBM PC 8086 systems with more than 640K of RAM in use?

pts
  • 1,859
  • 9
  • 17
  • 5
    The IBM PC and XT used the 8088 processor. Software compatible with the 8086, but not hardware compatible. The AT used the 80286 processor. The PS/2 model 30 used the 8086 - that's the only machine in the PC line that I know of that used the 8086. So while it makes no real difference in software, really this should all be 8088. – manassehkatz-Moving 2 Codidact Dec 23 '22 at 16:07
  • 1
    Thank you for the clarification. In this question I'm interested in IBM PC and PS/2 systems (and also campatibles) using either the 8086 or 8088 processor. – pts Dec 23 '22 at 16:21
  • 1
    @pts Do the computers have memory past 640KB or not? That solely determines if there is anything you can use, and what kind of memory determines how you can use it. – Justme Dec 23 '22 at 16:43
  • 4
    @pts: Are you assuming that an 8086/88 machine would commonly be fitted with 1MB of motherboard RAM, because that would be simple and cheap? I have to tell you that in the pre-AT era, that much RAM was not cheap at all, and even in the AT and 386 eras, this would have been very unusual. It did start to happen in the 486 era. – John Dallman Dec 23 '22 at 17:14
  • 2
    Lots of non PC compatible MSDOS machines had more, and DOS dealt with this. Beyond that you've got EMS cards for banked memory which could go to several MB and some big apps used – Alan Cox Dec 23 '22 at 18:08
  • 3
    @JohnDallman: My motherboard, which was quite typical, used eighteen 256Kx1 and eighteen 64Kx1 chips, though it was also common to use eighteen 256Kx1, two 64Kx4, and one 64K1. I don't think any mass-market 8088-based machines still were being produced by the time that 768K would be cheaper than 640K. – supercat Dec 23 '22 at 20:36
  • I'm assuming that most 8086/8088 PCs had at most 640K RAM. But I want my program use all available RAM. – pts Dec 24 '22 at 01:38
  • Question unclear - Why would anyone possibly need more than 640k of memory? – pipe Dec 24 '22 at 01:47
  • 1

    were there any IBM PC 8086 systems with more than 640K of RAM in use?

    In 1985 my wife bought a KayPro 2000 laptop with 768K of RAM, which ran MS-DOS. I recall there was a 640K limit, but it was possible to use the extra memory as a RAM drive.

    – Simon Crase Dec 24 '22 at 03:53
  • 1
    Your programming language must support having memory in multiple locations. Many just expect a single bit chunk. You may want to consider supporting EMM. – Thorbjørn Ravn Andersen Dec 27 '22 at 00:56
  • @pts See (in German): Norbert Juffa, "Jedes Byte hilft." mc, April 1990, pp. 118-132. It describes how to utilize memory above 640K. The jist of it is to use a system driver MEMMAX.SYS to temporarily block the balance of low memory during system start and extend the chain of MCBs (memory control blocks) into high memory, marking the hole as an occupied block. Tested with 286-based PCs using C&T NEAT and also an SRAM memory extension card (128 or 256KB?) with configurable start address on an 8086-based Amstrad PC. Utility programs `MEMMAX.EXE and MEMUP.EXE to force programs into high memory – njuffa Dec 03 '23 at 19:13
  • 1
    On my Atari ST I had a hardware PC emulator that ran at 8Mhz with a V30 (80186 compatible). This allowed to emulate a quite capable PC-XT with Enhanced CGA. One very posiitve trait of that PC was that my Atari had 2MiB of memory. This meant that all the spaces between 640K and 1024K were filled with memory. This allowed a very comfortable MS-DOS working environment as one could use up to 736 KiB of DOS memory. Furthermore, these 736 KiB were all free as it was possible to load all drivers/TSR in HMA. If required EMS and/or a RAM_Disk was also possible. – Patrick Schlüter Dec 04 '23 at 07:42

2 Answers2

17

Assuming there is usable memory between 640K and 1024K (which would be rather unusual in an 8086 PC), I would recommend using DOS 5.0 or later and adding UMBs to the memory allocation strategy (there are two steps involved: add UMBs to the memory chain with 0x5803, then set the allocation strategy to include them with 0x5801). You would combine this with separate drivers to add UMBs — e.g. UMBHERC.SYS to repurpose a HGC’s video buffer, QRAM.SYS combined with a hardware EMS card, or even UMB.SYS if you have a memory board capable of backfilling RAM between 640K and 1024K.

A blunter strategy would be to try changing values in upper memory and seeing what sticks, but that would be far more fragile.

There are many discussions of adding upper memory to 8086 PCs on forums, see for example this thread using a Tandy 1000.

Another possibility is to add memory mapped between 0xA0000 and 0xB7FFF to the conventional memory allocation chains, either using memory expansion cards mapped to those addresses, or using video buffers if a compatible graphics card is installed and the corresponding video modes are never used (e.g. you have a VGA and only run text-mode programs). DR DOS’s MEMMAX can do this, as can many other memory management utilities.

As a historical curiosity, were there any IBM PC 8086 systems with more than 640K of RAM in use?

Yes, there have been quite a few. Any 8086 PC with an EMS board would qualify. In fact using an EMS board would be a much safer and time-appropriate solution to RAM problems on an 8086 PC.

(There have been many 8086 DOS systems with more than 640K of RAM directly accessible to DOS, as “conventional” memory in a contiguous block; see Who set the 640K limit?)

Sep Roland
  • 1,043
  • 5
  • 14
Stephen Kitt
  • 121,835
  • 17
  • 505
  • 462
  • If there is no memory, it can't be used or added to be allocatable in DOS. And certainly a system with 512 kB of RAM and an EMS card can't even have 640 kB as EMS card likely has only 64kB page when not used for EMS. Sure 512 kB plus megabytes of EMS is possible but the user programs need EMS support to use it. – Justme Dec 23 '22 at 11:01
  • 6
    Yes, which is why I also explain how to make UMBs available. “User programs need EMS support” — well yes of course, but the OP is talking about writing a program, so that program could support EMS if appropriate. – Stephen Kitt Dec 23 '22 at 11:12
  • 1
    Yes but you can't make UMBs available if there is no memory, only if there really is memory. And on a 8086 system, there likely is no device installed that can provide the memory. I see you changed the wording that if the assumption is there is memory, it can be taken into use, which is great. – Justme Dec 23 '22 at 11:23
  • FYI I don't care whether the memory is continuous or not. Lots of 1K chunks are also fine for me. – pts Dec 23 '22 at 16:04
  • @Justme: I would expect many expansion cards that were designed to bring a motherboard up to 640K could be fairly easily modified to add chunks of RAM anywhere in the upper address space by cutting some traces and adding some wires. It might be necessary to add something like a 74LS00 (quad NAND gate--about the cheapest electrically-compatible logic chip back then), but I doubt it. – supercat Dec 23 '22 at 20:38
11

The short answer is, there is no usable RAM there so you can't use any. If you have an MDA video card, it has only 4096 bytes of video memory, and for 80x25 screen, it uses 4000 bytes already, so there is 96 bytes that are not visible. If you need more memory then you need to add memory, either just plain memory cards that can provide memory, or an EMS card which can add paged memory.

The 8086 can only address 1024 kilobytes, and when making the 5150 PC, IBM decided to split that so that up to 640 kB of RAM is possible and the rest of the memory, 384 kB is reserved for system use and expansion cards.

Some non-IBM systems could allow to have more memory and start the expansion memory area later, but if they were compatible with PC graphics there could only be up to 64k or 96k more before the start of video memory area.

Typically there is only up to 640 kilobytes, either all of it on the motherboard or in some cases some of it in the expansion slots. You can't even assume you have the maximum amount installed.

So, assuming there is a video card installed, you can use it for reading and writing, but it would be slower to read and write than main memory and everything you store there will be visible on screen, as that is the purpose of video memory. Only later cards such a Hercules, EGA, and VGA had more memory than was needed to show one page.

So if there are no special RAM cards that add general memory to the 384k reserved area, then there is no memory.

Typically, you would not be able to use the video memory in any meaningful way to store arbitrary data, and that memory would typically not be visible to DOS, not without tricks.

Sep Roland
  • 1,043
  • 5
  • 14
Justme
  • 31,506
  • 1
  • 73
  • 145
  • 1
    If you, for example have a VGA card that is being used in CGA Mode, you might be able to set the map select register to 0, effectively mapping memory from $A0000 to $BFFFF into the PC's memory map. As long as you are only using CGA text mode, you might be able to use the (relatively slow) video memory from $A0000 to $B8000 as program or data memory. – tofro Dec 23 '22 at 12:29
  • @tofro That is not possible, except for maybe 32k only. That's because even if mapped to A0000-BFFFF, a VGA card does not have an 128k address space. It only has a 64k of address space so it will just be mapped twice. And the video card needs custom driver to set it show text mode from offset $8000, because it is not mapped to B8000 where it can show from offset 0. – Justme Dec 23 '22 at 13:15
  • Well it is possible, but probably only by by-passing the BIOS, so not exactly simple. SVGA cards often have 128k memory or even more. By setting the card's mapping register (not with the BIOS) to 0, then setting the mode to CGA (again not with the BIOS), you can map a full 128k into memory from A0000 to BFFFF and use only B8000 to BFFFF as video memory. "custom driver"? No - simply set a few registers, most programs in DOS won't use BIOS video output anyways but instead write directly to video memory. – tofro Dec 23 '22 at 14:28
  • 3
    @tofro This not about how much memory a card has, as even a VGA has 256kB. This is about how you can make the card show up in CPU memory space, and standard VGA can be mapped to A0000 and B0000 simultaneously in a 128k window but both 64k windows access the card identically, there is no way you can address the VGA memory in any other way. Maybe an SVGA card allows different areas of memory to be mapped to A0000 and B0000 windows, but realistically, finding an SVGA card that works in a 8086 system and using it specially to extend DOS memory to go past 640k is kind of stretch. – Justme Dec 23 '22 at 16:37
  • 3
    @Justme: I doubt it would be that hard to find a VGA card that could be adapted to suit the purpose, but it would probably be just as easy to find a purpose-designed RAM expansion card that would fit the bill. – supercat Dec 23 '22 at 20:39
  • 2
    All of the VGA's 256k of memory can be used at least in unchained mode. Turn off chain-4 mode to have access to 4 pages of 320x200x8bpp video memory. What's sent to the video output and visible on the screen doesn't have to be the same thing that's visible to the CPU at address A0000. The non-visible video memory could be used for things not related to graphics. Maybe not a typical non-AT setup though. – piiperi Reinstate Monica Dec 24 '22 at 03:08
  • 3
    "purpose-designed RAM expansion card that would fit the bill." - is the Lotus Intel Microsoft Expanded Memory Specification (already mentioned) which allowed bank switching of 16K pages in a 64K block of the upper memory. – Jasen Dec 24 '22 at 03:41
  • @Jasen: An Expanded Memory card may be software-configurable to map 64K of RAM into the 0xA000 range, but I think most of them are designed to use a higher range of pages with software that expects to access them specially, and may not be designed to expand base RAM. – supercat Dec 02 '23 at 21:16