1

I’m working on simple program to change memory bank configuration of old x86 16bit PC with MASM6.

Currently, when I execute the code from the main memory it hang up. It seems that it’s because the code itself is in the main memory. When the code is executed, code itself is destroyed due to the memory configuration is changed.

Therefore I want to move the code from main memory to video memory and want to execute it from the video memory.

Please give me advices about the following codes to move the code from main memory to video memory and execute it. Executing following code still makes the system hang up.

.MODEL SMALL
.STACK 100H

.DATA
 MSG DB ' Bank Configuration is Successfully Changed',0DH,0AH,'$'

.CODE

MAIN PROC

 MOV CX,OFFSET T_HERE - OFFSET F_HERE  
 MOV SI,OFFSET F_HERE    
 MOV DI,0B800H    
 REP MOVSB    
 JMP T_HERE

F_HERE:

 MOV AX,@DATA    
 MOV AX,0B800H    
 MOV DS,AX     

 MOV DX,03872H     
 MOV AX,0DH    
 OUT DX,AX

 MOV AH9    
 LEA DX,MSG    
 INT 21H

 MOV AH,4CH    
 INT 21H

T_HERE:     

MAIN ENDP

 END MAIN
ychh0
  • 27
  • 3
  • This seems weird to me (first AX value is not used): MOV AX,@DATA MOV AX,0B800H – Roman Hocke Mar 14 '19 at 09:41
  • Do I need to delete the line MOV AX,@DATA? I will try it. Thanks. – ychh0 Mar 14 '19 at 09:43
  • 3
    `JMP T_HERE` <-- There's nothing there that tells the CPU to jump to video memory. Anyway, could you eloborate more on the _actual_ problem (i.e. the bank configuration that you mention)? What excatly did you try to do? – Michael Mar 14 '19 at 09:44
  • You need to jump to a CS value that will give you a linear address in the video RAM. And to copy in the first place, you probably want DS=@DATA and ES=0B800H (vga base, if that's the right number of trailing zeros). Also, is this a DOS .exe? I don't see an `org` directive so I assume it's not a `.com` , and you use `int 21h` so it's not a boot sector. – Peter Cordes Mar 14 '19 at 09:50
  • I’m trying to change bank size from 1MB to 4MB. 3872H is register of memory controller and I want to write a new value to that register to change bank size. It seems that your right. How should I jump to the video memory? @Michael – ychh0 Mar 14 '19 at 09:53
  • Yes. This is EXE program. Would you please let me know more in detail how to do jump to CS value and so on? Frankly speaking I’m novice of programming. Thanks. @Peter Cordes – ychh0 Mar 14 '19 at 09:57
  • Google for `jmp far`. You need to understand x86 segmentation if you want to make this work, or do any kind of messing around with memory and copying code. – Peter Cordes Mar 14 '19 at 10:08
  • @PeterCordes :His MASM/TASM may not even support encoding a far jmp. He might have to do something like `db 0eah, 0, 0, 0, 0b8h` . But only after he has relocated the code properly. His `rep movsb`doesn't properly set up DS:SI and ES:DI to do the relocation. He doesn't copy the data section and then he has to worry about fixing up relocations. I'd start by doing this as a DOS .COM program instead of a DOS .EXE program. – Michael Petch Mar 14 '19 at 10:25
  • @MichaelPetch: Yeah, the apparent total lack of understanding of segments was why I told them to go look for guides / docs; a complete segmentation tutorial is too much to ask of an answer (although one might already exist). But I'm surprised that old assemblers might not support encoding a `jmp far`; wasn't that *more* essential back then than it is now? (Now 16-bit code is mostly only used for "toy" purposes like learning, or use-cases where 64k is fine, since if you need more space now you can just use 32-bit mode or unreal mode.) Or did they only do `far` for segments they knew about? – Peter Cordes Mar 14 '19 at 10:32
  • 1
    @PeterCordes :You might want to see this: https://stackoverflow.com/questions/32706833/how-to-code-a-far-absolute-jmp-call-instruction-in-masm – Michael Petch Mar 14 '19 at 10:34
  • @MichaelPetch: heh, that question still has my naive comments from 2015, before I knew as much about 16-bit or much of anything about differences between flavours of Intel syntax. >.< Anyway, for a case like this VGA one, MASM/TASM sound like inconvenient tools vs. NASM. – Peter Cordes Mar 14 '19 at 10:43
  • 1
    @PeterCordes : NASM doesn't generate DOS .EXE programs but it can do .COM. If trying to use something other than MASM/TASM then looking at FASM might be a better alternative since it has support for DOS EXE and COM. – Michael Petch Mar 14 '19 at 10:51
  • 4
    If you can't rely on RAM (because you maliciously corrupted the memory controller's configuration after firmware set it up in the only way that is "correct"); then you can't rely on a stack that is in RAM, can't rely on DOS functions that are in RAM, can't rely on an IVT or IRQ handlers that are in RAM, etc. Your own code being in RAM is only the tip of the iceberg (even if the CPU is so old that you don't have to also worry about caches, speculative execution, etc). This is why memory controller configuration is only changed by code in firmware at power-on (before anything uses RAM). – Brendan Mar 14 '19 at 11:54
  • Fun fact: 0xaa * 0x55 = 0x3872 – Michael Petch Mar 14 '19 at 15:02
  • 3
    If you are using something like the [WD7910](http://bitsavers.informatik.uni-stuttgart.de/components/westernDigital/_dataBooks/1992_SystemLogic_Imaging_Storage/08_WD7910.pdf), then changing the bank size will inevitably change how the memory appears to the CPU. BIOS and Video (0cxxxxh) segments are directed to the ROMs, so using the video ram is the only way to go. You'll have to reinitialise the whole memory afterwards, including the reshadowing the BIOS if it was. – Margaret Bloom Mar 14 '19 at 15:13
  • @MargaretBloom I'm treating WD76C10 and I think you’re right. Is there any standard process of reinitializing and reshadowing ? – ychh0 Mar 14 '19 at 18:57
  • @PeterCordes I will study more about it. And I found that using MASM may not directly support jmp far. I’ll try NASM. Thanks. – ychh0 Mar 14 '19 at 18:59
  • @ychh0: If you really want to create a `.exe` instead of a `.com`, FASM might be your best bet for a modern / sane assembler that can do that. I'm not sure if NASM can write an object-file format that some linker can turn into a 16-bit `.exe`, but it can't make a `.exe` directly. (FASM can). See MichaelPetch's comments. Otherwise I'd recommend NASM. (Just because I haven't used FASM; it's fine, too, AFAIK.) – Peter Cordes Mar 14 '19 at 20:40

0 Answers0