![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-09-15 04:43 |
47,812 topics / 349,917 posts / today 0 new / 48,268 members |
| DOS开发编程 & 发展交流 (开发室) » [Help] About DJGPP protected mode? |
| Printable Version 951 / 7 |
| Floor1 forzhanghua | Posted 2003-09-26 00:00 |
| 初级用户 Posts 21 Credits 169 | |
|
I’m a beginner learning DJGPP. All the introductions emphasize that it can access 4G of space at one time. I feel its syntax is about the same as C, but when I programmed in C before, I allocated memory through arrays or pointers, so in DJGPP, how should I access such a large address space?
I noticed that after an error, DJ reports a segment address and an offset. How are these things set? Please give me some guidance, experts! Thanks |
|
| Floor2 ATLaS | Posted 2003-09-26 00:00 |
| 初级用户 Posts 29 Credits 169 | |
|
You should use the _far* family of functions in sys/farptr.h to access memory. The following function prototypes are from the libc help documentation of djgpp v2.0x.
#include unsigned char _farpeekb(unsigned short selector, unsigned long offset); unsigned short _farpeekw(unsigned short selector, unsigned long offset); unsigned long _farpeekl(unsigned short selector, unsigned long offset); void _farpokeb(unsigned short sel, unsigned long off, unsigned char val); void _farpokew(unsigned short sel, unsigned long off, unsigned short val); void _farpokel(unsigned short sel, unsigned long off, unsigned long val); void _farsetsel(unsigned short selector); unsigned short _fargetsel(void); void _farnspokeb(unsigned long offset, unsigned char value); void _farnspokew(unsigned long offset, unsigned short value); void _farnspokel(unsigned long offset, unsigned long value); unsigned char _farnspeekb(unsigned long offset); unsigned short _farnspeekw(unsigned long offset); unsigned long _farnspeekl(unsigned long offset); Assume the memory address you want to access is: unsigned long ulAddr = 0x0000a000; Use _farpokeb(_dos_ds, ulAddr, byte) to write one byte, and use _farpeekb() to read one byte. _dos_ds is a system predefined value, so just use it directly. If you want to access a continuous memory address range, then you can: unsigned int i, wLen = 0x1000; _farsetsel(_dos_ds); for (i = 0; i < wLen; i++) { printf("0x%02hX\t", _farnpeekb(ulAddr + i); } ps: I suggest you read the djgpp faq carefully. If you asked this kind of question on the djgpp mailing list, they would only answer you with faq 10.2 or 18.x. |
|
| Floor3 lemonhall | Posted 2003-09-28 00:00 |
| 高级用户 Posts 183 Credits 639 | |
|
Hmm, how did you do it before in C??
Using the MALLOC and FREE functions to allocate memory, right? I believe that’s what you did. Then keep using them now, they will still be your old friends. As for pointers, DJGPP has not abandoned the concept of pointers in C. But note that this is the pointer concept of the C language, not the concept as implemented by TC and the like. (Of course, every language always depends on its implementation to a greater or lesser extent.) So, you can still use “C language pointers” =================================================== So what is protected mode? It is actually an evolution in programming, another abstraction (ABSTRACT). It abstracts the memory access mechanism of 80386 and above machines, freeing countless programmers from the heavy memory access mechanism (from the shackles of the lower level). So, congratulations. You can use abstracted methods to access 4G of memory now, instead of using complicated memory paging access techniques (in fact this is not possible, because under DOS7.1 you can only use 2G at most, and in the WINXP series 4G is accessible, but half of that is reserved for the system) ==================================================== So, how do you access this memory? Very simple: Use the MALLOC function and allocate a 2G block of memory to a pointer. (Of course, your machine won’t have that much memory, so first try some big number like 20M, which would have been unimaginable before) Please note: there is one difference between this pointer and the pointers you used before. That is, there is no distinction between near and far. (Things like FAR MALLOC and FAR FREE are no longer needed.) In this way, your pointer can map directly to your memory, and there is no need to care about shackles like 640K or 1M anymore. What are you waiting for, go try it! =============================================== Also, there is another technical detail, namely: After allocation through the MALLOC function, please do not try to use functions like MEM to check the remaining amount of memory . Even though you allocated 20M or more, in fact they have not been initialized (actually it’s not exactly like that, but explaining it this way makes it easier for everyone to understand). Only when you actually write 20M of content into it will it really be allocated and used. To put it simply, after using MALLOC to call large memory, then using a function like MEM to check memory allocation, you will not see any change. This is very different from using TC before (I really don’t know what they were thinking, dizzy) Completed on 2003/09/26 |
|
| Floor4 lemonhall | Posted 2003-09-28 00:00 |
| 高级用户 Posts 183 Credits 639 | |
|
ATLaS
It’s clear that you have a solid foundation in programming with DJGPP and the like. Are you interested in joining my group? Take part in the Chinese localization work for DJGPP. Right now we are writing a Chinese DJGPP FAQ and a DJGPP user guide (one is a translation, the other is a complete rewrite) If you’re interested, reply to the thread. |
|
| Floor5 ATLaS | Posted 2003-09-29 00:00 |
| 初级用户 Posts 29 Credits 169 | |
|
to lemonhall:
Hehe, sure! Some time ago I really did spend some time studying djgpp. I originally had a project I planned to do under djgpp, but because of the multithreading issue, plus schedule requirements, I switched back to watcom c. But I’ve always remained quite interested in djgpp. Is there any specific work I can help with (because of work, my progress may be a bit slow, hehe)? |
|
| Floor6 lemonhall | Posted 2003-09-29 00:00 |
| 高级用户 Posts 183 Credits 639 | |
|
The specific work is to write a DJGPP usage guide. You’re relatively familiar with memory and protected mode, so could you take charge of writing that part?
Write a first draft and let me have a look. Send it to my mailbox: lemonhall@vip.sina.com My website has changed address: http://lemonhall.533.net/ Go take a look. There haven’t been many updates lately. |
|
| Floor7 ATLaS | Posted 2003-09-29 00:00 |
| 初级用户 Posts 29 Credits 169 | |
|
These parts are explained fairly clearly enough in the faq, right? Then I’ll try using some small examples to explain the differences between djgpp and borland c/watcom c? I could include the external interrupt part too, what do you think? But please don’t rush me on the schedule, I’ve got a lot of work stuff too.
![]() My email is atlas_wang@hotmail.com。 |
|
| Floor8 lemonhall | Posted 2003-09-30 00:00 |
| 高级用户 Posts 183 Credits 639 | |
|
Right, just use short articles to explain it. It needs to be somewhat different from the FAQ, thanks
|
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |