flat assembler
Message board for the users of flat assembler.
Index
> Main > Real-flat mode. Some questions about it |
Author |
|
f0dder 03 Jul 2004, 15:26
Quote:
I believe himem.sys actually uses "real flat"/voodoo/whatever_name itself - but privalov is probably the best person to ask, I haven't dealt with this for quite some years Quote:
Mask out hardware IRQs and CLI. #3 - again, somebody else will have to confirm/deny, but I believe the base+limit "shadow part" of the segment/selector registers are only set in protected mode, so it should be safe. But play around I generally don't like voodoo mode, as it requires a rather "clean" system, and isn't compatible with protected operating systems. But it's useful for bootloaders etc. |
|||
03 Jul 2004, 15:26 |
|
vid 03 Jul 2004, 16:04
1. Yes, but you must use HIMEM.SYS to allocate memory. If it isn't used, you can use whole memory. But, if you detect HIMEM.SYS is loaded, it doesn't mean you can use flat-real mode, there can be also EMM386 loaded (which requires HIMEM.SYS loaded), which restricts you from using flat-real mode (it switches to V86 mode)
2. f0dder is right, also real-mode interrupt won't happen in protected mode, unless done so with protected-mode handler. 3. Due to docuemntation, "shadow part" (mainly limit) should be reset to default values (0FFFFh) every time when used, but in reality it didn't happen. That's why flat-real mode was sometimes called a "bug" and wasn't recommended. But many programs used it (even Ultima 7 runned under flat-real mode engine), so designers had to keep it. |
|||
03 Jul 2004, 16:04 |
|
Tomasz Grysztar 07 Jul 2004, 15:51
HIMEM.SYS itself turns the flat real mode on, so if you've got HIMEM.SYS loaded and processor is in pure real mode (not V86 one), you can use flat real mode advantages even without initializing. The nicest solution I had to use the flat real mode is:
1) first check whether processor is in V86 mode with "smsw" instruction, it's better to use "smsw" instead of "mov eax,cr0" because it is not privileged instruction and it won't be notices by Win32 system, for examples (if you check for protected mode with "mov eax,cr0" in Windows 3.11, you program will crash, Windows 95 will tell you that the program must be executed in DOS mode and ask whether you want to switch to DOS mode; use of "smsw" gives you an opportunity to display your own message in such cases) 2) install the interrupt 13 handler which turns the flat real mode on and returns - if processor is in real mode, but not in flat real mode, this exception will be invoked by processor when you try to access data above the 64 kilobyte limit. This way your flat real mode initialization routine will be executed only when it's really needed, that is only when there was no flat real mode already turn on (as in case of HIMEM.SYS loaded). Also it will help you in cases when there is some protected mode TSR loaded in system which constatly breaks your flat real mode by switching to protected mode and then back to limited real mode (I had this problem with CUbic Player) - in such case your exception handler will be invoked again when you use the flat real mode features and will restore you mode "just in time". Because interrupt 13 is also IRQ 5, you can read the IRQ status from PIC 1 to determine whether it was really exception and invoke the previous handler if it's IRQ. As for your doubts: you should have the IF flag cleared for all the time while you are switching to protected mode and back, so there cannot be any interrupt and there is no problem. When enabling flat real mode you should load all the data segment registers (DS, ES, etc.) with big descriptor, as HIMEM.SYS does, too. For a example of this flat real mode approach look at the sources of some of the old DOS versions of fasm, which were using this mode. |
|||
07 Jul 2004, 15:51 |
|
Cas 09 Jul 2004, 05:14
Thank you, guys... but there's something more...
1) If I don't have EMM386 or HIMEM loaded and I want to know how much memory I have, in order not to try and read or write a place that does not exist, what do I do? And what would happen if I addressed such a place? 2) Privalov, what do you mean with this: Quote: if you've got HIMEM.SYS loaded and processor is in pure real mode (not V86 one), you can use flat real mode advantages even without initializing. Does it mean that while HIMEM.SYS is on, I can ALWAYS address a 32 bit offset without having an exeption? 3) Suppose I have initialized ES with a 4GB limit and somebody (say, a TSR) executes this: Code: mov ax,es mov es,ax Does the ES register lose its huge limit feature? Thank you again! _________________ «Earth is my country; science is my religion» - Christian Huygens |
|||
09 Jul 2004, 05:14 |
|
Tomasz Grysztar 09 Jul 2004, 17:06
1) You should use the BIOS functions of interrupt 15h in such case -see the source of fasm for DOS to have an example
2) No, it's too risky to assume this. First, processor can be in V86 mode (like when some memory manager like EMM386 is enabled) and in such case you even cannot initialize flat real mode yourself. Second, as I said in my previous post, some protected mode TSR program may restore the limit for selectors again to 64 kilobytes even after HIMEM.SYS changed it 4 GB. 3) No when this is real mode code. For other cases, see 2) |
|||
09 Jul 2004, 17:06 |
|
Cas 11 Jul 2004, 03:37
Thank you! As soon as I disconnected I tried it and I understood the part about HIMEM. But there seems to be something abiguous in another part... for example...
Suppose I prepare a GDT with descriptor 1 at base 0 and limit 4G, and then I do this: Code: cli mov eax,cr0 or eax,1 mov cr0,eax mov ax,1000b ; P.L. = 0, GDT, descriptor 1 mov ds,ax ; load the descriptor (now DS = mov eax,cr0 ; return to real mode and eax,0fffeh mov cr0,eax sti mov ax,ds call output_ax_value_to_the_screen What do I have? 8 or 0? And if then I do this: Code: mov ax,0a000h mov ds,ax Does the base of DS change to 0a0000h and the limit stays at 4Gb or the limit is adjusted so I cannot address further than 4Gb or the limit is set to 64k? Based on what you told me, I suppose the base would change to 0a0000h and the limit would not change. Is that right? THANKS _________________ «Earth is my country; science is my religion» - Christian Huygens |
|||
11 Jul 2004, 03:37 |
|
Tomasz Grysztar 13 Jul 2004, 08:15
Quote: Based on what you told me, I suppose the base would change to 0a0000h and the limit would not change. Is that right? Yes, exactly. The limit part of selector can only be changed from protected mode. |
|||
13 Jul 2004, 08:15 |
|
Martin_Bian 30 Aug 2005, 09:33
In real flat, 4G memory block can be accessed with a unlimited segment register. The register may be DS,ES,GS or FS. I'm wanderring if the CS is possible to be configured as 4G limited? if that the program can run above 1M. If not, please tell me why. Thanks.
|
|||
30 Aug 2005, 09:33 |
|
Tomasz Grysztar 30 Aug 2005, 11:00
It's possible, but only with interrupts disabled - the problem with interrupts is that in real mode they always store only 16-bit IP on the stack, so after interrupt occurs when you've got EIP above 1M, it will go wrong.
|
|||
30 Aug 2005, 11:00 |
|
smiddy 30 Aug 2005, 11:22
You could rewrite the interrupts if you are ambitious enough...
|
|||
30 Aug 2005, 11:22 |
|
Martin_Bian 31 Aug 2005, 01:12
Interrupts is a big issue. But if interrupts are disable, is there any 16-bit C compiler can generate the code above 1M?
|
|||
31 Aug 2005, 01:12 |
|
rugxulo 09 Sep 2005, 05:13
Quote:
Try GRDB 6.9 (free symbolic debugger w/ TASM source -- seems to work under Win XP). Quote: - Support for debugging Flat Real applications http://members.tripod.com/~ladsoft/grdb.htm |
|||
09 Sep 2005, 05:13 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.