1.I heard only (physical) memory from 640K to 1M are for hardware devices,so I can use memory 1M to FFFF:FFFF freely after boot up.Is that right?Or is there any way to detect allocation of memory after boot up?
2.Does anyone have an simple introduction about how to use bochs?I don't want to test my code by reseting by computer every 30 seconds!!
3.How can I use bios interrupt functions after switching into pmode?
Question about Memory alloc.&Bochs
Re:Question about Memory alloc.&Bochs
Yes and no. It is true that on any x86 CPU you're likely to be using, you can access the High Memory Area - the (64KB - 16 byte) area between FFFF:000F and FFFF:FFFF, and that no devices are commonly mapped to those locations. There's a catch, however: access to the HMA is disabled by default at boot up.STURM wrote: 1.I heard only (physical) memory from 640K to 1M are for hardware devices,so I can use memory 1M to FFFF:FFFF freely after boot up.Is that right?
It comes down to a matter of backward compatibility. The original 8086 and 8088 had only 20 address lines, a0 through a19, precisiely enough to address 1 MB. Thus, while the segment:offset system used to name addresses could go up to FFFF:FFFF (absolute address FFFFF, or 1MB + 65520 Bytes), the actual address space was limited to FFFF:000F (1M exactly). Addresses higher than that wrapped around; such that FFFF:0010 == 0000:0000.
When IBM built the PC/AT around the 80286 (the first x86 with more than 20 address lines), they were concerned that some programs which depended on the wrap-around location would fail with the new addressing scheme. Thus, they did what at the time seemed like a great idea: they hooked the 21st address line (A20) to an unused switch on the keyboard controller, and set it to default at boot up as off.
They expected that it would stay off; they had arbitrarily decided not to let the users access the memory above 1M, ever (remember, at the time IBM still thought of the PC line as a kind of fancy terminal for connecting to their real computers with). As it happens, though, some programmers at Lotus found that they could in fact reset the A20 line, and pretty soon the trick spread around. Eventually, it was incorporated into MS-DOS as the HIMEM.SYS driver. Still, the disabled A20 line was the standard, and all later hardware continued to leave it disabled at boot time, in order to remain backwards-compatible, long after the issues involved were a matter if history.
The practical upshot is that before accessing any memory above 1M, you have to peform the Rite of Opening the A20 Line, with the appropriate burnt offerings and hymns of supplication to the God of Backward Compatibility. What's more, the necessary ritual is different on different models of PC, though most these days suppport it through the BIOS (INT 15, AX=2401).
For details on how to access the A20 line, see any of the several threads here on the subject, and/or any of the following pages (esp. the first, which details several variants and pitfalls):
http://www.win.tue.nl/~aeb/linux/kbd/A20.html
http://www.phys.uu.nl/~mjanssen/control.php?chapter=9
http://osdev.neopages.net/tutorials/a20.php
You can't, at least not directly. What you'd need to do, IIUC, is set up a v86 mode task. Then, when you need to execute the BIOS call, you would switch to the v86 task first, then execute the interrupt, and then return to p-mode - a rather complex process. While there are some things you'll want or need to do this for - VESA BIOS calls, for example - it would be better to create your own p-mode device drivers for most things, anyway. See the many threads here on v86 mode and SVGA vdeo programming for more details.3.How can I use bios interrupt functions after switching into pmode?