• Please review our updated Terms and Rules here

How does MOVCPM.COM work?

Mike_Z

Veteran Member
Joined
Dec 1, 2013
Messages
1,713
Location
Near Milwaukee Wisconsin
I'm getting to the point of relocating CP/M from the starting 20K spot to higher memory. I'm not sure whether or not I can squeeze the cold start loader and my monitor program all into 2k or not, but if necessary I'll use 4K.

Anyway, I started to think about how MOVCPM.COM works. I seem to remember that either reading or being told that MOVCPM.COM has to be part of the original package with the CPM. And since I copied the OS from someone on the internet, I'm not sure whether the copy of my MOVCPM.COM will work or not.

How does MOVCPM.COM work? To move code from one block to another block without reassembling it, would require to change the instructions that have address's with them. Some instructions in the transfer group instructions like LHLD and some of the branch group, like JMP, etc.

So as long as these instructions are referencing addresses within the code being transferred all is OK, but what about if an instruction was addressing something external to the moved code? How does MOVCPM.COM handle that?

Am I on the right track here or not. Thanks Mike
 
Sort of. MOVCPM uses an early type of PRL format. Basically, CP/M is assembled twice; the second time is 100H bytes offset. The two binaries are compared and a bitmap constructed. A set bit implies that the high-order byte of an address is to be adjusted. Low order address bytes are not affected; hence, "Page relocatble file". Each byte in the bitmap corresponds to 8 bytes in the binary data. Simplicity itself. So everything to be moved in MOVCPM is part of the image and its relocation bitmap.
 
Hi Mike

My view is you're on the right track. I would guess that if the address is outside the CPM zone it'll be left as is, but since all of it is known I'm not sure how there would be a foreign address. And it's only absolute addresses that need to be MOVed, the relative addresses are OK as is. Also addresses pointing to buffers and constant strings. I've seen the CP/M 2.2 source code and there aren't many, and note that it uses jump tables for BIOS / BDOS calls anyway, so these are known vectors.

No doubt an expert will be along to put me right! ;)

But it's a transient program so you might try dissembling it with an origin of 0100h, for fun...

Edit: Like I said. Nice one, Chuck! You beat me to it (with a better answer).

Cheers
JonB
 
MOVCPM.COM contains three primary sections: 1) executable code for the program, 2) an image of CP/M, and 3) a relocation bitmap. For example, the table below documents how MOVCPM.COM for Altair CP/M 2.2 is laid out. Note that CP/M for a different machine may have a different bootloader size and/or BIOS size, and therefore, a slightly different layout within the file.

Offset in FileIn MemoryContent
0000h 0100hCPMOVE (code that “does” MOVCPM)
0701h-0702h0801h-0802hLength of “MODULE” (Bootloader + CCP + BDOS + BIOS)
0800h-087fh
0900h-097fh
0900h-097fh
0a00h-0a7fh
Bootloader (1[SUP]st[/SUP] 128 bytes)
Bootloader (2[SUP]nd[/SUP] 128 bytes)
0980h0a80hStart of CCP
1180h1280hStart of BDOS
1f80h2080hStart of BIOS
2580h2680hStart of relocation bitmap

The "Module" portion of MOVCPM (when MOVCPM is in memory) is the CP/M image written by SYSGEN to the boot tracks of the disk. In this case, the module runs from 900h to 267Fh. This puts the CP/M image in the same location and format as the SYSGEN program expects. Again, the starting address may vary slightly (e.g., 980h - A80h) and the length will vary based on the size of the BIOS for your particular CP/M.

The relocation bitmap has one bit corresponding to each byte in the module. If a bit is set, the corresponding byte must be updated based on where in memory CP/M is placed

In order to work with this relocation scheme, the CP/M image must be assembled so that the CCP starts at address 0000h. This leaves the BDOS starting at address 0800h and the BIOS starting at address 1600h. The bootloader is always assembled at address zero, however, relocation of the bootloader is still required as it references addresses corresponding to the final location of CP/M in memory. This CP/M image (the one assembled with the CCP starting at address zero) is the image in the module section of the file.

The bytes that must be relocated can be determined by assembling CP/M at two different addresses. The bytes that differ between the two object files are those bytes that must be updated for relocation. I have written a utility that runs on a PC and generates the bitmap for me. I then use a hex editor to patch the bitmap into the MOVCPM.COM file.

Mike
 
Mike - you probably should include the serial number area. Unless this matches with the system being run or the code check is disabled, you get the annoying "SYNCHRONIZATION ERROR" and a hard halt. Most of this should be detailed in the OEM guide.
 
I believe that, the serial number stuff is what I had remembered from an early discussion. Thanks for the information. I'm currently blending my old monitor program with my new Cold Start loader, and then to burn it to EEPROM. But I thought I'd get a head start on the moving CPM to higher memory, by boning up on it. Thanks a bunch Mike
 
The program portion of the MOVCPM.COM file is generated by the source file "CPMOVE.ASM." This file (we have the DRI original) clearly comments the serialization code spread throughout the source. This makes it easy to eliminate serialization checks when you're spinning your own MOVCPM.COM.

Mike
 
BTW, if you're just wanting to move your version of CP/M to higher memory, it's simpler just to rebuild CP/M from source rather than creating a MOVCPM. Especially if you're still changing BIOS code now and then.

Mike
 
Or, simply do a MOVCPM on ANY CP/M system, and save the image, then patch your BIOS and loader into that image; write to disk. Unless you're going to do it a lot, there's no reason to create a custom MOVCPM.

In my case, we had a ROM boot loader that worked only from Intel .HEX format. So, our disk image wasn't the simple type that most OEMs used.
 
Back
Top