go32.tex 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600
  1. \chapter{The GO32 unit}
  2. This chapter of the documentation describe the GO32 unit for the Free Pascal
  3. compiler under \dos. It was donated by Thomas Schatzl
  4. (tom\_at\[email protected]), for which my thanks.
  5. This unit was first written for \dos by Florian Klaempfl.
  6. This chapter is divided in three sections. The first section is an
  7. introduction to the GO32 unit. The second section lists the pre-defined
  8. constants, types and variables. The third section describes the functions
  9. which appear in the interface part of the GO32 unit.
  10. \section{Introduction}
  11. These docs contain information about the GO32 unit. Only the GO32V2 DPMI
  12. mode is discussed by me here due to the fact that new applications shouldn't
  13. be created with the older GO32V1 model. The former is much more advanced and
  14. better. Additionally a lot of functions only work in DPMI mode anyway.
  15. I hope the following explanations and introductions aren't too confusing at
  16. all. If you notice an error or bug send it to the FPC mailing list or
  17. directly to me.
  18. So let's get started and happy and error free coding I wish you....
  19. \hfill Thomas Schatzl, 25. August 1998
  20. \section{Protected mode memory organization}
  21. \subsection{What is DPMI}
  22. The \dos Protected Mode Interface helps you with various aspects of protected
  23. mode programming. These are roughly divided into descriptor handling, access
  24. to \dos memory, management of interrupts and exceptions, calls to real mode
  25. functions and other stuff. Additionally it automatically provides swapping
  26. to disk for memory intensive applications.
  27. A DPMI host (either a Windows \dos box or CWSDPMI.EXE) provides these
  28. functions for your programs.
  29. \subsection{Selectors and descriptors}
  30. Descriptors are a bit like real mode segments; they describe (as the name
  31. implies) a memory area in protected mode. A descriptor contains information
  32. about segment length, its base address and the attributes of it (i.e. type,
  33. access rights, ...).
  34. These descriptors are stored internally in a so-called descriptor table,
  35. which is basically an array of such descriptors.
  36. Selectors are roughly an index into this table.
  37. Because these 'segments' can be up to 4 GB in size, 32 bits aren't
  38. sufficient anymore to describe a single memory location like in real mode.
  39. 48 bits are now needed to do this, a 32 bit address and a 16 bit sized
  40. selector. The GO32 unit provides the tseginfo record to store such a
  41. pointer.
  42. But due to the fact that most of the time data is stored and accessed in the
  43. \%ds selector, FPC assumes that all pointers point to a memory location of
  44. this selector. So a single pointer is still only 32 bits in size. This value
  45. represents the offset from the data segment base address to this memory
  46. location.
  47. \subsection{FPC specialities}
  48. The \%ds and \%es selector MUST always contain the same value or some system
  49. routines may crash when called. The \%fs selector is preloaded with the
  50. DOSMEMSELECTOR variable at startup, and it MUST be restored after use,
  51. because again FPC relys on this for some functions. Luckily we asm
  52. programmers can still use the \%gs selector for our own purposes, but for how
  53. long ?
  54. See also:
  55. % tseginfo, dosmemselector, \dos memory access,
  56. \seefl{get\_cs}{getcs},
  57. \seefl{get\_ds}{getds},
  58. \seefl{gett\_ss}{getss},
  59. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors},
  60. \seefl{free\_ldt\_descriptor}{freeldtdescriptor},
  61. \seefl{segment\_to\_descriptor}{segmenttodescriptor},
  62. \seefl{get\_next\_selector\_increment\_value}{getnextselectorincrementvalue},
  63. \seefl{get\_segment\_base\_address}{getsegmentbaseaddress},
  64. \seefl{set\_segment\_base\_address}{setsegmentbaseaddress},
  65. \seefl{set\_segment\_limit}{setsegmentlimit},
  66. \seefl{create\_code\_segment\_alias\_descriptor}{createcodesegmentaliasdescriptor}
  67. \subsection{\dos memory access}
  68. \dos memory is accessed by the predefined \var{dosmemselector} selector;
  69. the GO32 unit additionally provides some functions to help you with standard tasks,
  70. like copying memory from heap to \dos memory and the likes. Because of this
  71. it is strongly recommened to use them, but you are still free to use the
  72. provided standard memory accessing functions which use 48 bit pointers. The
  73. third, but only thought for compatibility purposes, is using the
  74. \var{mem[]}-arrays. These arrays map the whole 1 Mb \dos space. They shouldn't be
  75. used within new programs.
  76. To convert a segment:offset real mode address to a protected mode linear
  77. address you have to multiply the segment by 16 and add its offset. This
  78. linear address can be used in combination with the DOSMEMSELECTOR variable.
  79. See also:
  80. \seep{dosmemget},
  81. \seepl{dosmemput}{dosmemput},
  82. \seepl{dosmemmove}{dosmemmove},
  83. \seepl{dosmemfillchar}{dosmemfillchar},
  84. \seepl{dosmemfillword}{dosmemfillword},
  85. mem[]-arrays,
  86. \seepl{seg\_move}{segmove},
  87. \seepl{seg\_fillchar}{segfillchar},
  88. \seepl{seg\_fillword}{segfillword}.
  89. \subsection{I/O port access}
  90. The I/O port access is done via the various \seef{inportb}, \seep{outportb}
  91. functions
  92. which are available. Additionally Free Pascal supports the Turbo Pascal
  93. PORT[]-arrays but it is by no means recommened to use them, because they're
  94. only for compatibility purposes.
  95. See also: \seep{outportb}, \seef{inportb}, PORT[]-arrays
  96. \subsection{Processor access}
  97. These are some functions to access various segment registers (\%cs, \%ds, \%ss)
  98. which makes your work a bit easier.
  99. See also: \seefl{get\_cs}{getcs}, \seefl{get\_ds}{getds},
  100. \seefl{get\_ss}{getss}
  101. \subsection{Interrupt redirection}
  102. Interrupts are program interruption requests, which in one or another way
  103. get to the processor; there's a distinction between software and hardware
  104. interrupts. The former are explicitely called by an 'int' instruction and
  105. are a bit comparable to normal functions. Hardware interrupts come from
  106. external devices like the keyboard or mouse. These functions are called
  107. handlers.
  108. \subsection{Handling interrupts with DPMI}
  109. The interrupt functions are real-mode procedures; they normally can't be
  110. called in protected mode without the risk of an protection fault. So the
  111. DPMI host creates an interrupt descriptor table for the application.
  112. Initially all software interrupts (except for int 31h, 2Fh and 21h function
  113. 4Ch) or external hardware interrupts are simply directed to a handler that
  114. reflects the interrupt in real-mode, i.e. the DPMI host's default handlers
  115. switch the CPU to real-mode, issue the interrupt and switch back to
  116. protected mode. The contents of general registers and flags are passed to
  117. the real mode handler and the modified registers and flags are returned to
  118. the protected mode handler. Segment registers and stack pointer are not
  119. passed between modes.
  120. \subsection{Protected mode interrupts vs. Real mode interrupts}
  121. As mentioned before, there's a distinction between real mode interrupts and
  122. protected mode interrupts; the latter are protected mode programs, while the
  123. former must be real mode programs. To call a protected mode interrupt
  124. handler, an assembly 'int' call must be issued, while the other is called
  125. via the realintr() or intr() function. Consequently, a real mode interrupt
  126. then must either reside in \dos memory (<1MB) or the application must
  127. allocate a real mode callback address via the get\_rm\_callback() function.
  128. \subsection{Creating own interrupt handlers}
  129. Interrupt redirection with FPC pascal is done via the set\_pm\_interrupt() for
  130. protected mode interrupts or via the set\_rm\_interrupt() for real mode
  131. interrupts.
  132. \subsection{Disabling interrupts}
  133. The GO32 unit provides the two procedures disable() and enable() to disable
  134. and enable all interrupts.
  135. \subsection{Hardware interrupts}
  136. Hardware interrupts are generated by hardware devices when something unusual
  137. happens; this could be a keypress or a mouse move or any other action. This
  138. is done to minimize CPU time, else the CPU would have to check all installed
  139. hardware for data in a big loop (this method is called 'polling') and this
  140. would take much time.
  141. A standard IBM-PC has two interrupt controllers, that are responsible for
  142. these hardware interrupts: both allow up to 8 different interrupt sources
  143. (IRQs, interrupt requests). The second controller is connected to the first
  144. through IRQ 2 for compatibility reasons, e.g. if controller 1 gets an IRQ 2,
  145. he hands the IRQ over to controller 2. Because of this up to 15 different
  146. hardware interrupt sources can be handled.
  147. IRQ 0 through IRQ 7 are mapped to interrupts 8h to Fh and the second
  148. controller (IRQ 8 to 15) is mapped to interrupt 70h to 77h.
  149. All of the code and data touched by these handlers MUST be locked (via the
  150. various locking functions) to avoid page faults at interrupt time. Because
  151. hardware interrupts are called (as in real mode) with interrupts disabled,
  152. the handler has to enable them before it returns to normal program
  153. execution. Additionally a hardware interrupt must send an EOI (end of
  154. interrupt) command to the responsible controller; this is acomplished by
  155. sending the value 20h to port 20h (for the first controller) or A0h (for the
  156. second controller).
  157. The following example shows how to redirect the keyboard interrupt.
  158. \latex{\inputlisting{go32ex/keyclick.pp}}
  159. \html{\input{go32ex/keyclick.tex}}
  160. \subsection{Software interrupts}
  161. Ordinarily, a handler installed with
  162. \seefl{set\_pm\_interrupt}{setpminterrupt} only services software
  163. interrupts that are executed in protected mode; real mode software
  164. interrupts can be redirected by \seefl{set\_rm\_interrupt}{setrminterrupt}.
  165. See also \seefl{set\_rm\_interrupt}{setrminterrupt},
  166. \seefl{get\_rm\_interrupt}{getrminterrupt},
  167. \seefl{set\_pm\_interrupt}{setpminterrupt},
  168. \seefl{get\_pm\_interrupt}{getpminterrupt},
  169. \seefl{lock\_data}{lockdata},
  170. \seefl{lock\_code}{lockcode},
  171. \seep{enable},
  172. \seep{disable},
  173. \seepl{outportb}{outportb}
  174. Executing software interrupts
  175. Simply execute a realintr() call with the desired interrupt number and the
  176. supplied register data structure.
  177. But some of these interrupts require you to supply them a pointer to a
  178. buffer where they can store data to or obtain data from in memory. These
  179. interrupts are real mode functions and so they only can access the first Mb
  180. of linear address space, not FPC's data segment.
  181. For this reason FPC supplies a pre-initialized \dos memory location within
  182. the GO32 unit. This buffer is internally used for \dos functions too and so
  183. it's contents may change when calling other procedures. It's size can be
  184. obtained with \seefl{tb\_size}{tbsize} and it's linear address via
  185. \seefl{transfer\_buffer}{transferbuffer}.
  186. Another way is to allocate a completely new \dos memory area via the
  187. \seefl{global\_dos\_alloc}{globaldosalloc} function for your use and
  188. supply its real mode address.
  189. See also:
  190. \seefl{tb\_size}{tbsize},
  191. \seefl{transfer\_buffer}{transferbuffer}.
  192. \seefl{global\_dos\_alloc}{globaldosalloc},
  193. \seefl{global\_dos\_free}{globaldosfree},
  194. \seef{realintr}
  195. The following examples illustrate the use of software interrupts.
  196. \latex{\inputlisting{go32ex/softint.pp}}
  197. \html{\input{go32ex/softint.tex}}
  198. \latex{\inputlisting{go32ex/rmpm_int.pp}}
  199. \html{\input{go32ex/rmpm_int.tex}}
  200. \subsection{Real mode callbacks}
  201. The callback mechanism can be thought of as the converse of calling a real
  202. mode procedure (i.e. interrupt), which allows your program to pass
  203. information to a real mode program, or obtain services from it in a manner
  204. that's transparent to the real mode program.
  205. In order to make a real mode callback available, you must first get the real
  206. mode callback address of your procedure and the selector and offset of a
  207. register data structure. This real mode callback address (this is a
  208. segment:offset address) can be passed to a real mode program via a software
  209. interrupt, a \dos memory block or any other convenient mechanism.
  210. When the real mode program calls the callback (via a far call), the DPMI
  211. host saves the registers contents in the supplied register data structure,
  212. switches into protected mode, and enters the callback routine with the
  213. following conditions:
  214. \begin{itemize}
  215. \item interrupts disabled
  216. \item \var{\%CS:\%EIP} = 48 bit pointer specified in the original call to
  217. \seefl{get\_rm\_callback}{getrmcallback}
  218. \item \var{\%DS:\%ESI} = 48 bit pointer to to real mode \var{SS:SP}
  219. \item \var{\%ES:\%EDI} = 48 bit pointer of real mode register data
  220. structure.
  221. \item \var{\%SS:\%ESP} = locked protected mode stack
  222. \item All other registers undefined
  223. \end{itemize}
  224. The callback procedure can then extract its parameters from the real mode
  225. register data structure and/or copy parameters from the real mode stack to
  226. the protected mode stack. Recall that the segment register fields of the
  227. real mode register data structure contain segment or paragraph addresses
  228. that are not valid in protected mode. Far pointers passed in the real mode
  229. register data structure must be translated to virtual addresses before they
  230. can be used with a protected mode program.
  231. The callback procedure exits by executing an IRET with the address of the
  232. real mode register data structure in \var{\%ES:\%EDI}, passing information back to
  233. the real mode caller by modifying the contents of the real mode register
  234. data structure and/or manipulating the contents of the real mode stack. The
  235. callback procedure is responsible for setting the proper address for
  236. resumption of real mode execution into the real mode register data
  237. structure; typically, this is accomplished by extracting the return address
  238. from the real mode stack and placing it into the \var{\%CS:\%EIP} fields of the real
  239. mode register data structure. After the IRET, the DPMI host switches the CPU
  240. back into real mode, loads ALL registers with the contents of the real mode
  241. register data structure, and finally returns control to the real mode
  242. program.
  243. All variables and code touched by the callback procedure MUST be locked to
  244. prevent page faults.
  245. See also: \seefl{get\_rm\_callback}{getrmcallback},
  246. \seefl{free\_rm\_callback}{freermcallback},
  247. \seefl{lock\_code}{lockcode},
  248. \seefl{lock\_data}{lockdata}
  249. \section{Types, Variables and Constants}
  250. \subsection{Constants}
  251. \subsubsection{Constants returned by get\_run\_mode}
  252. Tells you under what memory environment (e.g. memory manager) the program
  253. currently runs.
  254. \begin{verbatim}
  255. rm_unknown = 0; { unknown }
  256. rm_raw = 1; { raw (without HIMEM) }
  257. rm_xms = 2; { XMS (for example with HIMEM, without EMM386) }
  258. rm_vcpi = 3; { VCPI (for example HIMEM and EMM386) }
  259. rm_dpmi = 4; { DPMI (for example \dos box or 386Max) }
  260. \end{verbatim}
  261. Note: GO32V2 {\em always} creates DPMI programs, so you need a suitable DPMI
  262. host like \file{CWSDPMI.EXE} or a Windows \dos box. So you don't need to check it,
  263. these constants are only useful in GO32V1 mode.
  264. \subsubsection{Processor flags constants}
  265. They are provided for a simple check with the flags identifier in the
  266. trealregs type. To check a single flag, simply do an AND operation with the
  267. flag you want to check. It's set if the result is the same as the flag
  268. value.
  269. \begin{verbatim}
  270. const carryflag = $001;
  271. parityflag = $004;
  272. auxcarryflag = $010;
  273. zeroflag = $040;
  274. signflag = $080;
  275. trapflag = $100;
  276. interruptflag = $200;
  277. directionflag = $400;
  278. overflowflag = $800;
  279. \end{verbatim}
  280. \subsection{Predefined types}
  281. \begin{verbatim}
  282. type tmeminfo = record
  283. available_memory : Longint;
  284. available_pages : Longint;
  285. available_lockable_pages : Longint;
  286. linear_space : Longint;
  287. unlocked_pages : Longint;
  288. available_physical_pages : Longint;
  289. total_physical_pages : Longint;
  290. free_linear_space : Longint;
  291. max_pages_in_paging_file : Longint;
  292. reserved : array[0..2] of Longint;
  293. end;
  294. \end{verbatim}
  295. Holds information about the memory allocation, etc.
  296. \begin{tabular}{ll}
  297. Record entry & Description \\ \hline
  298. \var{available\_memory} & Largest available free block in bytes. \\
  299. \var{available\_pages} & Maximum unlocked page allocation in pages \\
  300. \var{available\_lockable\_pages} & Maximum locked page allocation in pages. \\
  301. \var{linear\_space} & Linear address space size in pages. \\
  302. \var{unlocked\_pages} & Total number of unlocked pages. \\
  303. \var{available\_physical\_pages} & Total number of free pages.\\
  304. \var{total\_physical\_pages} & Total number of physical pages. \\
  305. \var{free\_linear\_space} & Free linear address space in pages.\\
  306. \var{max\_pages\_in\_paging\_file} & Size of paging file/partition in
  307. pages. \\
  308. \end{tabular}
  309. NOTE: The value of a field is -1 (0ffffffffh) if the value is unknown, it's
  310. only guaranteed, that \var{available\_memory} contains a valid value.
  311. The size of the pages can be determined by the get\_page\_size() function.
  312. \begin{verbatim}
  313. type
  314. trealregs = record
  315. case Integer of
  316. 1: { 32-bit }
  317. (EDI, ESI, EBP, Res, EBX, EDX, ECX, EAX: Longint;
  318. Flags, ES, DS, FS, GS, IP, CS, SP, SS: Word);
  319. 2: { 16-bit }
  320. (DI, DI2, SI, SI2, BP, BP2, R1, R2: Word;
  321. BX, BX2, DX, DX2, CX, CX2, AX, AX2: Word);
  322. 3: { 8-bit }
  323. (stuff: array[1..4] of Longint;
  324. BL, BH, BL2, BH2, DL, DH, DL2, DH2, CL,
  325. CH, CL2, CH2, AL, AH, AL2, AH2: Byte);
  326. 4: { Compat }
  327. (RealEDI, RealESI, RealEBP, RealRES, RealEBX,
  328. RealEDX, RealECX, RealEAX: Longint;
  329. RealFlags, RealES, RealDS, RealFS, RealGS,
  330. RealIP, RealCS, RealSP, RealSS: Word);
  331. end;
  332. registers = trealregs;
  333. \end{verbatim}
  334. These two types contain the data structure to pass register values to a
  335. interrupt handler or real mode callback.
  336. \begin{verbatim}
  337. type tseginfo = record
  338. offset : Pointer; segment : Word; end;
  339. \end{verbatim}
  340. This record is used to store a full 48-bit pointer. This may be either a
  341. protected mode selector:offset address or in real mode a segment:offset
  342. address, depending on application.
  343. See also: Selectors and descriptors, \dos memory access, Interrupt
  344. redirection
  345. \subsection{Variables.}
  346. \begin{verbatim}
  347. var dosmemselector : Word;
  348. \end{verbatim}
  349. Selector to the \dos memory. The whole \dos memory is automatically mapped to
  350. this single descriptor at startup. This selector is the recommened way to
  351. access \dos memory.
  352. \begin{verbatim}
  353. var int31error : Word;
  354. \end{verbatim}
  355. This variable holds the result of a DPMI interrupt call. Any nonzero value
  356. must be treated as a critical failure.
  357. \section{Functions and Procedures}
  358. \begin{functionl}{allocate\_ldt\_descriptors}{allocateldtdescriptors}
  359. \Declaration
  360. Function allocate\_ldt\_descriptors (count : Word) : Word;
  361. \Description
  362. Allocates a number of new descriptors.
  363. Parameters:
  364. \begin{description}
  365. \item[count:\ ] specifies the number of requested unique descriptors.
  366. \end{description}
  367. Return value: The base selector.
  368. Notes: The descriptors allocated must be initialized by the application with
  369. other function calls. This function returns descriptors with a limit and
  370. size value set to zero. If more than one descriptor was requested, the
  371. function returns a base selector referencing the first of a contiguous array
  372. of descriptors. The selector values for subsequent descriptors in the array
  373. can be calculated by adding the value returned by the
  374. \seefl{get\_next\_selector\_increment\_value}{getnextselectorincrementvalue}
  375. function.
  376. \Errors
  377. Check the \var{int31error} variable.
  378. \SeeAlso
  379. \seefl{free\_ldt\_descriptor}{freeldtdescriptor},
  380. \seefl{get\_next\_selector\_increment\_value}{getnextselectorincrementvalue},
  381. \seefl{segment\_to\_descriptor}{segmenttodescriptor},
  382. \seefl{create\_code\_segment\_alias\_descriptor}{createcodesegmentaliasdescriptor},
  383. \seefl{set\_segment\_limit}{setsegmentlimit},
  384. \seefl{set\_segment\_base\_address}{setsegmentbaseaddress}
  385. \end{functionl}
  386. \latex{\inputlisting{go32ex/sel_des.pp}}
  387. \html{\input{go32ex/sel_des.tex}}
  388. \begin{functionl}{allocate\_memory\_block}{allocatememoryblock}
  389. \Declaration
  390. Function allocate\_memory\_block (size:Longint) : Longint;
  391. \Description
  392. Allocates a block of linear memory.
  393. Parameters:
  394. \begin{description}
  395. \item[size:\ ] Size of requested linear memory block in bytes.
  396. \end{description}
  397. Returned values: blockhandle - the memory handle to this memory block. Linear
  398. address of the requested memory.
  399. Notes: WARNING: According to my DPMI docs this function is not implemented
  400. correctly. Normally you should also get a blockhandle to this block after
  401. successful operation. This handle is used to free the memory block
  402. afterwards or use this handle for other purposes. So this block can't be
  403. deallocated and is henceforth unusuable !
  404. This function doesn't allocate any descriptors for this block, it's the
  405. applications resposibility to allocate and initialize for accessing this
  406. memory.
  407. \Errors
  408. Check the \var{int31error} variable.
  409. \SeeAlso
  410. \seefl{free\_memory\_block}{freememoryblock}
  411. \end{functionl}
  412. \begin{procedure}{copyfromdos}
  413. \Declaration
  414. Procedure copyfromdos (var addr; len : Longint);
  415. \Description
  416. Copies data from the pre-allocated \dos memory transfer buffer to the heap.
  417. Parameters:
  418. \begin{description}
  419. \item[addr:\ ] data to copy to.
  420. \item[len:\ ] number of bytes to copy to heap.
  421. \end{description}
  422. Notes:
  423. Can only be used in conjunction with the \dos memory transfer buffer.
  424. \Errors
  425. Check the \var{int31error} variable.
  426. \SeeAlso
  427. \seefl{tb\_size}{tbsize}, \seefl{transfer\_buffer}{transferbuffer},
  428. \seep{copytodos}
  429. \end{procedure}
  430. \begin{procedure}{copytodos}
  431. \Declaration
  432. Procedure copytodos (var addr; len : Longint);
  433. \Description
  434. Copies data from heap to the pre-allocated \dos memory buffer.
  435. Parameters:
  436. \begin{description}
  437. \item[addr:\ ] data to copy from.
  438. \item[len:\ ] number of bytes to copy to \dos memory buffer.
  439. \end{description}
  440. Notes: This function fails if you try to copy more bytes than the transfer
  441. buffer is in size. It can only be used in conjunction with the transfer
  442. buffer.
  443. \Errors
  444. Check the \var{int31error} variable.
  445. \SeeAlso
  446. \seefl{tb\_size}{tbsize}, \seefl{transfer\_buffer}{transferbuffer},
  447. \seep{copyfromdos}
  448. \end{procedure}
  449. \begin{functionl}{create\_code\_segment\_alias\_descriptor}{createcodesegmentaliasdescriptor}
  450. \Declaration
  451. Function create\_code\_segment\_alias\_descriptor (seg : Word) : Word;
  452. \Description
  453. Creates a new descriptor that has the same base and limit as the specified
  454. descriptor.
  455. Parameters:
  456. \begin{description}
  457. \item[seg:\ ] selector.
  458. \end{description}
  459. Return values: The data selector (alias).
  460. Notes: In effect, the function returns a copy of the descriptor. The
  461. descriptor alias returned by this function will not track changes to the
  462. original descriptor. In other words, if an alias is created with this
  463. function, and the base or limit of the original segment is then changed, the
  464. two descriptors will no longer map the same memory.
  465. \Errors
  466. Check the \var{int31error} variable.
  467. \SeeAlso
  468. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors},
  469. \seefl{set\_segment\_limit}{setsegmentlimit},
  470. \seefl{set\_segment\_base\_address}{setsegmentbaseaddress}
  471. \end{functionl}
  472. \begin{procedure}{disable}
  473. \Declaration
  474. Procedure disable ;
  475. \Description
  476. Disables all hardware interrupts by execution a CLI instruction.
  477. Parameters: None.
  478. \Errors
  479. None.
  480. \SeeAlso
  481. \seep{enable}
  482. \end{procedure}
  483. \begin{procedure}{dosmemfillchar}
  484. \Declaration
  485. Procedure dosmemfillchar (seg, ofs : Word; count : Longint; c : char);
  486. \Description
  487. Sets a region of \dos memory to a specific byte value.
  488. Parameters:
  489. \begin{description}
  490. \item[seg:\ ] real mode segment.
  491. \item[ofs:\ ] real mode offset.
  492. \item[count:\ ] number of bytes to set.
  493. \item[c:\ ] value to set memory to.
  494. \end{description}
  495. Notes: No range check is performed.
  496. \Errors
  497. None.
  498. \SeeAlso
  499. \seep{dosmemput},
  500. \seep{dosmemget},
  501. \seep{dosmemmove}{dosmemmove},
  502. \seepl{dosmemfillword}{dosmemfillword},
  503. \seepl{seg\_move}{segmove},
  504. \seepl{seg\_fillchar}{segfillchar},
  505. \seepl{seg\_fillword}{segfillword}
  506. \end{procedure}
  507. \latex{\inputlisting{go32ex/textmess.pp}}
  508. \html{\input{go32ex/textmess.tex}}
  509. \begin{procedure}{dosmemfillword}
  510. \Declaration
  511. Procedure dosmemfillword (seg,ofs : Word; count : Longint; w : Word);
  512. \Description
  513. Sets a region of \dos memory to a specific word value.
  514. Parameters:
  515. \begin{description}
  516. \item[seg:\ ] real mode segment.
  517. \item[ofs:\ ] real mode offset.
  518. \item[count:\ ] number of words to set.
  519. \item[w:\ ] value to set memory to.
  520. \end{description}
  521. Notes: No range check is performed.
  522. \Errors
  523. None.
  524. \SeeAlso
  525. \seep{dosmemput},
  526. \seepl{dosmemget}{dosmemget},
  527. \seepl{dosmemmove}{dosmemmove},
  528. \seepl{dosmemfillchar}{dosmemfillchar},
  529. \seepl{seg\_move}{segmove},
  530. \seepl{seg\_fillchar}{segfillchar},
  531. \seepl{seg\_fillword}{segfillword}
  532. \end{procedure}
  533. \begin{procedure}{dosmemget}
  534. \Declaration
  535. Procedure dosmemget (seg : Word; ofs : Word; var data; count : Longint);
  536. \Description
  537. Copies data from the \dos memory onto the heap.
  538. Parameters:
  539. \begin{description}
  540. \item[seg:\ ] source real mode segment.
  541. \item[ofs:\ ] source real mode offset.
  542. \item[data:\ ] destination.
  543. \item[count:\ ] number of bytes to copy.
  544. \end{description}
  545. Notes: No range checking is performed.
  546. \Errors
  547. None.
  548. \SeeAlso
  549. \seep{dosmemput},
  550. \seep{dosmemmove},
  551. \seep{dosmemfillchar},
  552. \seep{dosmemfillword},
  553. \seepl{seg\_move}{segmove},
  554. \seepl{seg\_fillchar}{segfillchar},
  555. \seepl{seg\_fillword}{segfillword}
  556. \end{procedure}
  557. For an example, see \seefl{global\_dos\_alloc}{globaldosalloc}.
  558. \begin{procedure}{dosmemmove}
  559. \Declaration
  560. Procedure dosmemmove (sseg, sofs, dseg, dofs : Word; count : Longint);
  561. \Description
  562. Copies count bytes of data between two \dos real mode memory locations.
  563. Parameters:
  564. \begin{description}
  565. \item[sseg:\ ] source real mode segment.
  566. \item[sofs:\ ] source real mode offset.
  567. \item[dseg:\ ] destination real mode segment.
  568. \item[dofs:\ ] destination real mode offset.
  569. \item[count:\ ] number of bytes to copy.
  570. \end{description}
  571. Notes: No range check is performed in any way.
  572. \Errors
  573. None.
  574. \SeeAlso
  575. \seep{dosmemput},
  576. \seep{dosmemget},
  577. \seep{dosmemfillchar},
  578. \seep{dosmemfillword}
  579. \seepl{seg\_move}{segmove},
  580. \seepl{seg\_fillchar}{segfillchar},
  581. \seepl{seg\_fillword}{segfillword}
  582. \end{procedure}
  583. For an example, see \seepl{seg\_fillchar}{segfillchar}.
  584. \begin{procedure}{dosmemput}
  585. \Declaration
  586. Procedure dosmemput (seg : Word; ofs : Word; var data; count : Longint);
  587. \Description
  588. Copies heap data to \dos real mode memory.
  589. Parameters:
  590. \begin{description}
  591. \item[seg:\ ] destination real mode segment.
  592. \item[ofs:\ ] destination real mode offset.
  593. \item[data:\ ] source.
  594. \item[count:\ ] number of bytes to copy.
  595. \end{description}
  596. Notes: No range checking is performed.
  597. \Errors
  598. None.
  599. \SeeAlso
  600. \seep{dosmemget},
  601. \seep{dosmemmove},
  602. \seep{dosmemfillchar},
  603. \seep{dosmemfillword},
  604. \seepl{seg\_move}{segmove},
  605. \seepl{seg\_fillchar}{segfillchar},
  606. \seepl{seg\_fillword}{segfillword}
  607. \end{procedure}
  608. For an example, see \seefl{global\_dos\_alloc}{globaldosalloc}.
  609. \begin{procedure}{enable}
  610. \Declaration
  611. Procedure enable ;
  612. \Description
  613. Enables all hardware interrupts by executing a STI instruction.
  614. Parameters: None.
  615. \Errors
  616. None.
  617. \SeeAlso
  618. \seep{disable}
  619. \end{procedure}
  620. \begin{functionl}{free\_ldt\_descriptor}{freeldtdescriptor}
  621. \Declaration
  622. Function free\_ldt\_descriptor (des : Word) : boolean;
  623. \Description
  624. Frees a previously allocated descriptor.
  625. Parameters:
  626. \begin{description}
  627. \item[des:\ ] The descriptor to be freed.
  628. \end{description}
  629. Return value: \var{True} if successful, \var{False} otherwise.
  630. Notes: After this call this selector is invalid and must not be used for any
  631. memory operations anymore. Each descriptor allocated with
  632. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors} must be freed
  633. individually with this function,
  634. even if it was previously allocated as a part of a contiguous array of
  635. descriptors.
  636. \Errors
  637. Check the \var{int31error} variable.
  638. \SeeAlso
  639. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors},
  640. \seefl{get\_next\_selector\_increment\_value}{getnextselectorincrementvalue}
  641. \end{functionl}
  642. For an example, see
  643. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors}.
  644. \begin{functionl}{free\_memory\_block}{freememoryblock}
  645. \Declaration
  646. Function free\_memory\_block (blockhandle :
  647. Longint) : boolean;
  648. \Description
  649. Frees a previously allocated memory block.
  650. Parameters:
  651. \begin{description}
  652. \item{blockhandle:} the handle to the memory area to free.
  653. \end{description}
  654. Return value: \var{True} if successful, \var{false} otherwise.
  655. Notes: Frees memory that was previously allocated with
  656. \seefl{allocate\_memory\_block}{allocatememoryblock} .
  657. This function doesn't free any descriptors mapped to this block,
  658. it's the application's responsibility.
  659. \Errors
  660. Check \var{int31error} variable.
  661. \SeeAlso
  662. \seefl{allocate\_memory\_block}{allocatememoryblock}
  663. \end{functionl}
  664. \begin{functionl}{free\_rm\_callback}{freermcallback}
  665. \Declaration
  666. Function free\_rm\_callback (var intaddr : tseginfo) : boolean;
  667. \Description
  668. Releases a real mode callback address that was previously allocated with the
  669. \seefl{get\_rm\_callback}{getrmcallback} function.
  670. Parameters:
  671. \begin{description}
  672. \item[intaddr:\ ] real mode address buffer returned by
  673. \seefl{get\_rm\_callback}{getrmcallback} .
  674. \end{description}
  675. Return values: \var{True} if successful, \var{False} if not
  676. \Errors
  677. Check the \var{int31error} variable.
  678. \SeeAlso
  679. \seefl{set\_rm\_interrupt}{setrminterrupt},
  680. \seefl{get\_rm\_callback}{getrmcallback}
  681. \end{functionl}
  682. For an example, see \seefl{get\_rm\_callback}{getrmcallback}.
  683. \begin{functionl}{get\_cs}{getcs}
  684. \Declaration
  685. Function get\_cs : Word;
  686. \Description
  687. Returns the cs selector.
  688. Parameters: None.
  689. Return values: The content of the cs segment register.
  690. \Errors
  691. None.
  692. \SeeAlso
  693. \seefl{get\_ds}{getds}, \seefl{get\_ss}{getss}
  694. \end{functionl}
  695. For an example, see \seefl{set\_pm\_interrupt}{setpminterrupt}.
  696. \begin{functionl}{get\_descriptor\_access\_rights}{getdescriptoraccessrights}
  697. \Declaration
  698. Function get\_descriptor\_access\_rights (d : Word) : Longint;
  699. \Description
  700. Gets the access rights of a descriptor.
  701. Parameters:
  702. \begin{description}
  703. \item{d} selector to descriptor.
  704. \end{description}
  705. Return value: Access rights bit field.
  706. \Errors
  707. Check the \var{int31error} variable.
  708. \SeeAlso
  709. \seefl{set\_descriptor\_access\_rights}{setdescriptoraccessrights}
  710. \end{functionl}
  711. \begin{functionl}{get\_ds}{getds}
  712. \Declaration
  713. Function get\_ds : Word;
  714. \Description
  715. Returns the ds selector.
  716. Parameters: None.
  717. Return values: The content of the ds segment register.
  718. \Errors
  719. None.
  720. \SeeAlso
  721. \seefl{get\_cs}{getcs}, \seefl{get\_ss}{getss}
  722. \end{functionl}
  723. \begin{functionl}{get\_linear\_addr}{getlinearaddr}
  724. \Declaration
  725. Function get\_linear\_addr (phys\_addr : Longint; size : Longint) : Longint;
  726. \Description
  727. Converts a physical address into a linear address.
  728. Parameters:
  729. \begin{description}
  730. \item [phys\_addr:\ ] physical address of device.
  731. \item [size:\ ] Size of region to map in bytes.
  732. \end{description}
  733. Return value: Linear address that can be used to access the physical memory.
  734. Notes: It's the applications resposibility to allocate and set up a
  735. descriptor for access to the memory. This function shouldn't be used to map
  736. real mode addresses.
  737. \Errors
  738. Check the \var{int31error} variable.
  739. \SeeAlso
  740. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors}, \seefl{set\_segment\_limit}{setsegmentlimit},
  741. \seefl{set\_segment\_base\_address}{setsegmentbaseaddress}
  742. \end{functionl}
  743. \begin{functionl}{get\_meminfo}{getmeminfo}
  744. \Declaration
  745. Function get\_meminfo (var meminfo : tmeminfo) : boolean;
  746. \Description
  747. Returns information about the amount of available physical memory, linear
  748. address space, and disk space for page swapping.
  749. Parameters:
  750. \begin{description}
  751. \item[meminfo:\ ] buffer to fill memory information into.
  752. \end{description}
  753. Return values: Due to an implementation bug this function always returns
  754. \var{False}, but it always succeeds.
  755. Notes: Only the first field of the returned structure is guaranteed to
  756. contain a valid value. Any fields that are not supported by the DPMI host
  757. will be set by the host to \var{-1 (0FFFFFFFFH)} to indicate that the information
  758. is not available. The size of the pages used by the DPMI host can be
  759. obtained with the \seefl{get\_page\_size}{getpagesize} function.
  760. \Errors
  761. Check the \var{int31error} variable.
  762. \SeeAlso
  763. \seefl{get\_page\_size}{getpagesize}
  764. \end{functionl}
  765. \latex{\inputlisting{go32ex/meminfo.pp}}
  766. \html{\input{go32ex/meminfo.tex}}
  767. \begin{functionl}{get\_next\_selector\_increment\_value}{getnextselectorincrementvalue}
  768. \Declaration
  769. Function get\_next\_selector\_increment\_value : Word;
  770. \Description
  771. Returns the selector increment value when allocating multiple subsequent
  772. descriptors via \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors}.
  773. Parameters: None.
  774. Return value: Selector increment value.
  775. Notes: Because \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors} only returns the selector for the
  776. first descriptor and so the value returned by this function can be used to
  777. calculate the selectors for subsequent descriptors in the array.
  778. \Errors
  779. Check the \var{int31error} variable.
  780. \SeeAlso
  781. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors},
  782. \seefl{free\_ldt\_descriptor}{freeldtdescriptor}
  783. \end{functionl}
  784. \begin{functionl}{get\_page\_size}{getpagesize}
  785. \Declaration
  786. Function get\_page\_size : Longint;
  787. \Description
  788. Returns the size of a single memory page.
  789. Return value: Size of a single page in bytes.
  790. Notes: The returned size is typically 4096 bytes.
  791. \Errors
  792. Check the \var{int31error} variable.
  793. \SeeAlso
  794. \seefl{get\_meminfo}{getmeminfo}
  795. \end{functionl}
  796. For an example, see \seefl{get\_meminfo}{getmeminfo}.
  797. \begin{functionl}{get\_pm\_interrupt}{getpminterrupt}
  798. \Declaration
  799. Function get\_pm\_interrupt (vector : byte; var intaddr : tseginfo) : boolean;
  800. \Description
  801. Returns the address of a current protected mode interrupt handler.
  802. Parameters:
  803. \begin{description}
  804. \item[vector:\ ] interrupt handler number you want the address to.
  805. \item[intaddr:\ ] buffer to store address.
  806. \end{description}
  807. Return values: \var{True} if successful, \var{False} if not.
  808. Notes: The returned address is a protected mode selector:offset address.
  809. \Errors
  810. Check the \var{int31error} variable.
  811. \SeeAlso
  812. \seefl{set\_pm\_interrupt}{setpminterrupt},
  813. \seefl{set\_rm\_interrupt}{setrminterrupt}, \seefl{get\_rm\_interrupt}{getrminterrupt}
  814. \end{functionl}
  815. For an example, see \seefl{set\_pm\_interrupt}{setpminterrupt}.
  816. \begin{functionl}{get\_rm\_callback}{getrmcallback}
  817. \Declaration
  818. Function get\_rm\_callback (pm\_func : pointer; const reg : trealregs; var rmcb: tseginfo) : boolean;
  819. \Description
  820. Returns a unique real mode \var{segment:offset} address, known as a "real mode
  821. callback," that will transfer control from real mode to a protected mode
  822. procedure.
  823. Parameters:
  824. \begin{description}
  825. \item[pm\_func:\ ] pointer to the protected mode callback function.
  826. \item[reg:\ ] supplied registers structure.
  827. \item[rmcb:\ ] buffer to real mode address of callback function.
  828. \end{description}
  829. Return values: \var{True} if successful, otherwise \var{False}.
  830. Notes: Callback addresses obtained with this function can be passed by a
  831. protected mode program for example to an interrupt handler, device driver,
  832. or TSR, so that the real mode program can call procedures within the
  833. protected mode program or notify the protected mode program of an event. The
  834. contents of the supplied regs structure is not valid after function call,
  835. but only at the time of the actual callback.
  836. \Errors
  837. Check the \var{int31error} variable.
  838. \SeeAlso
  839. \seefl{free\_rm\_callback}{freermcallback}
  840. \end{functionl}
  841. \latex{\inputlisting{go32ex/callback.pp}}
  842. \html{\input{go32ex/callback.tex}}
  843. \begin{functionl}{get\_rm\_interrupt}{getrminterrupt}
  844. \Declaration
  845. Function get\_rm\_interrupt (vector : byte; var intaddr :
  846. tseginfo) : boolean;
  847. \Description
  848. Returns the contents of the current machine's real mode interrupt vector for
  849. the specified interrupt.
  850. Parameters:
  851. \begin{description}
  852. \item[vector:\ ] interrupt vector number.
  853. \item[intaddr:\ ] buffer to store real mode \var{segment:offset} address.
  854. \end{description}
  855. Return values: \var{True} if successful, \var{False} otherwise.
  856. Notes: The returned address is a real mode segment address, which isn't
  857. valid in protected mode.
  858. \Errors
  859. Check the \var{int31error} variable.
  860. \SeeAlso
  861. \seefl{set\_rm\_interrupt}{setrminterrupt},
  862. \seefl{set\_pm\_interrupt}{setpminterrupt},
  863. \seefl{get\_pm\_interrupt}{getpminterrupt}
  864. \end{functionl}
  865. \begin{functionl}{get\_run\_mode}{getrunmode}
  866. \Declaration
  867. Function get\_run\_mode : Word;
  868. \Description
  869. Returns the current mode your application runs with.
  870. Return values: One of the constants used by this function.
  871. \Errors
  872. None.
  873. \SeeAlso
  874. constants returned by \seefl{get\_run\_mode}{getrunmode}
  875. \end{functionl}
  876. \latex{\inputlisting{go32ex/getrunmd.pp}}
  877. \html{\input{go32ex/getrunmd.tex}}
  878. \begin{functionl}{get\_segment\_base\_address}{getsegmentbaseaddress}
  879. \Declaration
  880. Function get\_segment\_base\_address
  881. (d : Word) : Longint;
  882. \Description
  883. Returns the 32-bit linear base address from the descriptor table for the
  884. specified segment.
  885. Parameters:
  886. \begin{description}
  887. \item[d:\ ] selector of the descriptor you want the base address.
  888. \end{description}
  889. Return values: Linear base address of specified descriptor.
  890. \Errors
  891. Check the \var{int31error} variable.
  892. \SeeAlso
  893. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors},
  894. \seefl{set\_segment\_base\_address}{setsegmentbaseaddress},
  895. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors},
  896. \seefl{set\_segment\_limit}{setsegmentlimit},
  897. \seefl{get\_segment\_limit}{getsegmentlimit}
  898. \end{functionl}
  899. For an example, see
  900. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors}.
  901. \begin{functionl}{get\_segment\_limit}{getsegmentlimit}
  902. \Declaration
  903. Function get\_segment\_limit (d : Word) : Longint;
  904. \Description
  905. Returns a descriptors segment limit.
  906. Parameters:
  907. \begin{description}
  908. \item [d:\ ] selector.
  909. \end{description}
  910. Return value: Limit of the descriptor in bytes.
  911. \Errors
  912. Returns zero if descriptor is invalid.
  913. \SeeAlso
  914. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors},
  915. \seefl{set\_segment\_limit}{setsegmentlimit},
  916. \seefl{set\_segment\_base\_address}{setsegmentbaseaddress},
  917. \seefl{get\_segment\_base\_address}{getsegmentbaseaddress},
  918. \end{functionl}
  919. \begin{functionl}{get\_ss}{getss}
  920. \Declaration
  921. Function get\_ss : Word;
  922. \Description
  923. Returns the ss selector.
  924. Parameters: None.
  925. Return values: The content of the ss segment register.
  926. \Errors
  927. None.
  928. \SeeAlso
  929. \seefl{get\_ds}{getds}, \seefl{get\_cs}{getcs}
  930. \end{functionl}
  931. \begin{functionl}{global\_dos\_alloc}{globaldosalloc}
  932. \Declaration
  933. Function global\_dos\_alloc (bytes : Longint) : Longint;
  934. \Description
  935. Allocates a block of \dos real mode memory.
  936. Parameters:
  937. \begin{description}
  938. \item [bytes:\ ] size of requested real mode memory.
  939. \end{description}
  940. Return values: The low word of the returned value contains the selector to
  941. the allocated \dos memory block, the high word the corresponding real mode
  942. segment value. The offset value is always zero.
  943. This function allocates memory from \dos memory pool, i.e. memory below the 1
  944. MB boundary that is controlled by \dos. Such memory blocks are typically used
  945. to exchange data with real mode programs, TSRs, or device drivers. The
  946. function returns both the real mode segment base address of the block and
  947. one descriptor that can be used by protected mode applications to access the
  948. block. This function should only used for temporary buffers to get real mode
  949. information (e.g. interrupts that need a data structure in ES:(E)DI),
  950. because every single block needs an unique selector. The returned selector
  951. should only be freed by a \seefl{global\_dos\_free}{globaldosfree} call.
  952. \Errors
  953. Check the \var{int31error} variable.
  954. \SeeAlso
  955. \seefl{global\_dos\_free}{globaldosfree}
  956. \end{functionl}
  957. \latex{\inputlisting{go32ex/buffer.pp}}
  958. \html{\input{go32ex/buffer.tex}}
  959. \begin{functionl}{global\_dos\_free}{globaldosfree}
  960. \Declaration
  961. Function global\_dos\_free (selector :Word) : boolean;
  962. \Description
  963. Frees a previously allocated \dos memory block.
  964. Parameters:
  965. \begin{description}
  966. \item[selector:\ ] selector to the \dos memory block.
  967. \end{description}
  968. Return value: \var{True} if successful, \var{False} otherwise.
  969. Notes: The descriptor allocated for the memory block is automatically freed
  970. and hence invalid for further use. This function should only be used for
  971. memory allocated by \seefl{global\_dos\_alloc}{globaldosalloc}.
  972. \Errors
  973. Check the \var{int31error} variable.
  974. \SeeAlso
  975. \seefl{global\_dos\_alloc}{globaldosalloc}
  976. \end{functionl}
  977. For an example, see \seefl{global\_dos\_alloc}{globaldosalloc}.
  978. \begin{function}{inportb}
  979. \Declaration
  980. Function inportb (port : Word) : byte;
  981. \Description
  982. Reads 1 byte from the selected I/O port.
  983. Parameters:
  984. \begin{description}
  985. \item[port:\ ] the I/O port number which is read.
  986. \end{description}
  987. Return values: Current I/O port value.
  988. \Errors
  989. None.
  990. \SeeAlso
  991. \seep{outportb}, \seef{inportw}, \seef{inportl}
  992. \end{function}
  993. \begin{function}{inportl}
  994. \Declaration
  995. Function inportl (port : Word) : Longint;
  996. \Description
  997. Reads 1 longint from the selected I/O port.
  998. Parameters:
  999. \begin{description}
  1000. \item[port:\ ] the I/O port number which is read.
  1001. \end{description}
  1002. Return values: Current I/O port value.
  1003. \Errors
  1004. None.
  1005. \SeeAlso
  1006. \seep{outportb}, \seef{inportb}, \seef{inportw}
  1007. \end{function}
  1008. \begin{function}{inportw}
  1009. \Declaration
  1010. Function inportw (port : Word) : Word;
  1011. \Description
  1012. Reads 1 word from the selected I/O port.
  1013. Parameters:
  1014. \begin{description}
  1015. \item[port:\ ] the I/O port number which is read.
  1016. \end{description}
  1017. Return values: Current I/O port value.
  1018. \Errors
  1019. None.
  1020. \SeeAlso
  1021. \seep{outportw} \seef{inportb}, \seef{inportl}
  1022. \end{function}
  1023. \begin{functionl}{lock\_code}{lockcode}
  1024. \Declaration
  1025. Function lock\_code (functionaddr : pointer; size : Longint) : boolean;
  1026. \Description
  1027. Locks a memory range which is in the code segment selector.
  1028. Parameters:
  1029. \begin{description}
  1030. \item[functionaddr:\ ] address of the function to be locked.
  1031. \item[size:\ ] size in bytes to be locked.
  1032. \end{description}
  1033. Return values: \var{True} if successful, \var{False} otherwise.
  1034. \Errors
  1035. Check the \var{int31error} variable.
  1036. \SeeAlso
  1037. \seefl{lock\_linear\_region}{locklinearregion},
  1038. \seefl{lock\_data}{lockdata},
  1039. \seefl{unlock\_linear\_region}{unlocklinearregion},
  1040. \seefl{unlock\_data}{unlockdata},
  1041. \seefl{unlock\_code}{unlockcode}
  1042. \end{functionl}
  1043. For an example, see \seefl{get\_rm\_callback}{getrmcallback}.
  1044. \begin{functionl}{lock\_data}{lockdata}
  1045. \Declaration
  1046. Function lock\_data (var data; size : Longint) : boolean;
  1047. \Description
  1048. Locks a memory range which resides in the data segment selector.
  1049. Parameters:
  1050. \begin{description}
  1051. \item[data:\ ] address of data to be locked.
  1052. \item[size:\ ] length of data to be locked.
  1053. \end{description}
  1054. Return values: \var{True} if successful, \var{False} otherwise.
  1055. \Errors
  1056. Check the \var{int31error} variable.
  1057. \SeeAlso
  1058. \seefl{lock\_linear\_region}{locklinearregion},
  1059. \seefl{lock\_code}{lockcode},
  1060. \seefl{unlock\_linear\_region}{unlocklinearregion},
  1061. \seefl{unlock\_data}{unlockdata},
  1062. \seefl{unlock\_code}{unlockcode}
  1063. \end{functionl}
  1064. For an example, see \seefl{get\_rm\_callback}{getrmcallback}.
  1065. \begin{functionl}{lock\_linear\_region}{locklinearregion}
  1066. \Declaration
  1067. Function lock\_linear\_region (linearaddr, size : Longint) : boolean;
  1068. \Description
  1069. Locks a memory region to prevent swapping of it.
  1070. Parameters:
  1071. \begin{description}
  1072. \item[linearaddr:\ ] the linear address of the memory are to be locked.
  1073. \item[size:\ ] size in bytes to be locked.
  1074. \end{description}
  1075. Return value: \var{True} if successful, False otherwise.
  1076. \Errors
  1077. Check the \var{int31error} variable.
  1078. \SeeAlso
  1079. \seefl{lock\_data}{lockdata},
  1080. \seefl{lock\_code}{lockcode},
  1081. \seefl{unlock\_linear\_region}{unlocklinearregion},
  1082. \seefl{unlock\_data}{unlockdata},
  1083. \seefl{unlock\_code}{unlockcode}
  1084. \end{functionl}
  1085. \begin{procedure}{outportb}
  1086. \Declaration
  1087. Procedure outportb (port : Word; data : byte);
  1088. \Description
  1089. Sends 1 byte of data to the specified I/O port.
  1090. Parameters:
  1091. \begin{description}
  1092. \item[port:\ ] the I/O port number to send data to.
  1093. \item[data:\ ] value sent to I/O port.
  1094. \end{description}
  1095. Return values: None.
  1096. \Errors
  1097. None.
  1098. \SeeAlso
  1099. \seef{inportb}, \seep{outportl}, \seep{outportw}
  1100. \end{procedure}
  1101. \latex{\inputlisting{go32ex/outport.pp}}
  1102. \html{\input{go32ex/outport.tex}}
  1103. \begin{procedure}{outportl}
  1104. \Declaration
  1105. Procedure outportl (port : Word; data : Longint);
  1106. \Description
  1107. Sends 1 longint of data to the specified I/O port.
  1108. Parameters:
  1109. \begin{description}
  1110. \item[port:\ ] the I/O port number to send data to.
  1111. \item[data:\ ] value sent to I/O port.
  1112. \end{description}
  1113. Return values: None.
  1114. \Errors
  1115. None.
  1116. \SeeAlso
  1117. \seef{inportl}, \seep{outportw}, \seep{outportb}
  1118. \end{procedure}
  1119. For an example, see \seep{outportb}.
  1120. \begin{procedure}{outportw}
  1121. \Declaration
  1122. Procedure outportw (port : Word; data : Word);
  1123. \Description
  1124. Sends 1 word of data to the specified I/O port.
  1125. Parameters:
  1126. \begin{description}
  1127. \item[port:\ ] the I/O port number to send data to.
  1128. \item[data:\ ] value sent to I/O port.
  1129. \end{description}
  1130. Return values: None.
  1131. \Errors
  1132. None.
  1133. \SeeAlso
  1134. \seef{inportw}, \seep{outportl}, \seep{outportb}
  1135. \end{procedure}
  1136. For an example, see \seep{outportb}.
  1137. \begin{function}{realintr}
  1138. \Declaration
  1139. Function realintr (intnr: Word; var regs : trealregs) : boolean;
  1140. \Description
  1141. Simulates an interrupt in real mode.
  1142. Parameters:
  1143. \begin{description}
  1144. \item[intnr:\ ] interrupt number to issue in real mode.
  1145. \item[regs:\ ] registers data structure.
  1146. \end{description}
  1147. Return values: The supplied registers data structure contains the values
  1148. that were returned by the real mode interrupt. \var{True} if successful, \var{False} if
  1149. not.
  1150. Notes: The function transfers control to the address specified by the real
  1151. mode interrupt vector of intnr. The real mode handler must return by
  1152. executing an IRET.
  1153. \Errors
  1154. Check the \var{int31error} variable.
  1155. \SeeAlso
  1156. \end{function}
  1157. \latex{\inputlisting{go32ex/flags.pp}}
  1158. \html{\input{go32ex/flags.tex}}
  1159. \begin{procedurel}{seg\_fillchar}{segfillchar}
  1160. \Declaration
  1161. Procedure seg\_fillchar (seg : Word; ofs : Longint; count : Longint; c : char);
  1162. \Description
  1163. Sets a memory area to a specific value.
  1164. Parameters:
  1165. \begin{description}
  1166. \item[seg:\ ] selector to memory area.
  1167. \item[ofs:\ ] offset to memory.
  1168. \item[count:\ ] number of bytes to set.
  1169. \item[c:\ ] byte data which is set.
  1170. \end{description}
  1171. Return values: None.
  1172. Notes: No range check is done in any way.
  1173. \Errors
  1174. None.
  1175. \SeeAlso
  1176. \seepl{seg\_move}{segmove},
  1177. \seepl{seg\_fillword}{segfillword},
  1178. \seepl{dosmemfillchar}{dosmemfillchar},
  1179. \seepl{dosmemfillword}{dosmemfillword},
  1180. \seepl{dosmemget}{dosmemget},
  1181. \seepl{dosmemput}{dosmemput},
  1182. \seepl{dosmemmove}{dosmemmove}
  1183. \end{procedurel}
  1184. \latex{\inputlisting{go32ex/vgasel.pp}}
  1185. \html{\input{go32ex/vgasel.tex}}
  1186. \begin{procedurel}{seg\_fillword}{segfillword}
  1187. \Declaration
  1188. Procedure seg\_fillword (seg : Word; ofs : Longint; count : Longint; w :Word);
  1189. \Description
  1190. Sets a memory area to a specific value.
  1191. Parameters:
  1192. \begin{description}
  1193. \item[seg:\ ] selector to memory area.
  1194. \item[ofs:\ ] offset to memory.
  1195. \item[count:\ ] number of words to set.
  1196. \item[w:\ ] word data which is set.
  1197. \end{description}
  1198. Return values: None.
  1199. Notes: No range check is done in any way.
  1200. \Errors
  1201. None.
  1202. \SeeAlso
  1203. \seepl{seg\_move}{segmove},
  1204. \seepl{seg\_fillchar}{segfillchar},
  1205. \seepl{dosmemfillchar}{dosmemfillchar},
  1206. \seepl{dosmemfillword}{dosmemfillword},
  1207. \seepl{dosmemget}{dosmemget},
  1208. \seepl{dosmemput}{dosmemput},
  1209. \seepl{dosmemmove}{dosmemmove}
  1210. \end{procedurel}
  1211. For an example, see
  1212. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors}.
  1213. \begin{functionl}{segment\_to\_descriptor}{segmenttodescriptor}
  1214. \Declaration
  1215. Function segment\_to\_descriptor (seg : Word) : Word;
  1216. \Description
  1217. Maps a real mode segment (paragraph) address onto an descriptor that can be
  1218. used by a protected mode program to access the same memory.
  1219. Parameters:
  1220. \begin{description}
  1221. \item [seg:\ ] the real mode segment you want the descriptor to.
  1222. \end{description}
  1223. Return values: Descriptor to real mode segment address.
  1224. Notes: The returned descriptors limit will be set to 64 kB. Multiple calls
  1225. to this function with the same segment address will return the same
  1226. selector. Descriptors created by this function can never be modified or
  1227. freed. Programs which need to examine various real mode addresses using the
  1228. same selector should use the function
  1229. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors} and change
  1230. the base address as necessary.
  1231. \Errors
  1232. Check the \var{int31error} variable.
  1233. \SeeAlso
  1234. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors},
  1235. \seefl{free\_ldt\_descriptor}{freeldtdescriptor},
  1236. \seefl{set\_segment\_base\_address}{setsegmentbaseaddress}
  1237. \end{functionl}
  1238. For an example, see \seepl{seg\_fillchar}{segfillchar}.
  1239. \begin{procedurel}{seg\_move}{segmove}
  1240. \Declaration
  1241. Procedure seg\_move (sseg : Word; source : Longint; dseg : Word; dest :
  1242. Longint; count : Longint);
  1243. \Description
  1244. Copies data between two memory locations.
  1245. Parameters:
  1246. \begin{description}
  1247. \item[sseg:\ ] source selector.
  1248. \item[source:\ ] source offset.
  1249. \item[dseg:\ ] destination selector.
  1250. \item[dest:\ ] destination offset.
  1251. \item[count:\ ] size in bytes to copy.
  1252. \end{description}
  1253. Return values: None.
  1254. Notes: Overlapping is only checked if the source selector is equal to the
  1255. destination selector. No range check is done.
  1256. \Errors
  1257. None.
  1258. \SeeAlso
  1259. \seepl{seg\_fillchar}{segfillchar},
  1260. \seepl{seg\_fillword}{segfillword},
  1261. \seepl{dosmemfillchar}{dosmemfillchar},
  1262. \seepl{dosmemfillword}{dosmemfillword},
  1263. \seepl{dosmemget}{dosmemget},
  1264. \seepl{dosmemput}{dosmemput},
  1265. \seepl{dosmemmove}{dosmemmove}
  1266. \end{procedurel}
  1267. For an example, see
  1268. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors}.
  1269. \begin{functionl}{set\_descriptor\_access\_rights}{setdescriptoraccessrights}
  1270. \Declaration
  1271. Function set\_descriptor\_access\_rights (d : Word; w : Word) : Longint;
  1272. \Description
  1273. Sets the access rights of a descriptor.
  1274. Parameters:
  1275. \begin{description}
  1276. \item[d:\ ] selector.
  1277. \item[w:\ ] new descriptor access rights.
  1278. \end{description}
  1279. Return values: This function doesn't return anything useful.
  1280. \Errors
  1281. Check the \var{int31error} variable.
  1282. \SeeAlso
  1283. \seefl{get\_descriptor\_access\_rights}{getdescriptoraccessrights}
  1284. \end{functionl}
  1285. \begin{functionl}{set\_pm\_interrupt}{setpminterrupt}
  1286. \Declaration
  1287. Function set\_pm\_interrupt (vector : byte; const intaddr : tseginfo) : boolean;
  1288. \Description
  1289. Sets the address of the protected mode handler for an interrupt.
  1290. Parameters:
  1291. \begin{description}
  1292. \item[vector:\ ] number of protected mode interrupt to set.
  1293. \item[intaddr:\ ] selector:offset address to the interrupt vector.
  1294. \end{description}
  1295. Return values: \var{True} if successful, \var{False} otherwise.
  1296. Notes: The address supplied must be a valid \var{selector:offset}
  1297. protected mode address.
  1298. \Errors
  1299. Check the \var{int31error} variable.
  1300. \SeeAlso
  1301. \seefl{get\_pm\_interrupt}{getpminterrupt},
  1302. \seefl{set\_rm\_interrupt}{setrminterrupt},
  1303. \seefl{get\_rm\_interrupt}{getrminterrupt}
  1304. \end{functionl}
  1305. \latex{\inputlisting{go32ex/int_pm.pp}}
  1306. \html{\input{go32ex/int_pm.tex}}
  1307. \begin{functionl}{set\_rm\_interrupt}{setrminterrupt}
  1308. \Declaration
  1309. Function set\_rm\_interrupt (vector : byte; const intaddr :
  1310. tseginfo) : boolean;
  1311. \Description
  1312. Sets a real mode interrupt handler.
  1313. Parameters:
  1314. \begin{description}
  1315. \item[vector:\ ] the interrupt vector number to set.
  1316. \item[intaddr:\ ] address of new interrupt vector.
  1317. \end{description}
  1318. Return values: \var{True} if successful, otherwise \var{False}.
  1319. Notes: The address supplied MUST be a real mode segment address, not a
  1320. \var{selector:offset} address. So the interrupt handler must either reside in \dos
  1321. memory (below 1 Mb boundary) or the application must allocate a real mode
  1322. callback address with \seefl{get\_rm\_callback}{getrmcallback}.
  1323. \Errors
  1324. Check the \var{int31error} variable.
  1325. \SeeAlso
  1326. \seefl{get\_rm\_interrupt}{getrminterrupt},
  1327. \seefl{set\_pm\_interrupt}{setpminterrupt}, \seefl{get\_pm\_interrupt}{getpminterrupt},
  1328. \seefl{get\_rm\_callback}{getrmcallback}
  1329. \end{functionl}
  1330. \begin{functionl}{set\_segment\_base\_address}{setsegmentbaseaddress}
  1331. \Declaration
  1332. Function set\_segment\_base\_address (d : Word; s : Longint) : boolean;
  1333. \Description
  1334. Sets the 32-bit linear base address of a descriptor.
  1335. Parameters:
  1336. \begin{description}
  1337. \item[d:\ ] selector.
  1338. \item[s:\ ] new base address of the descriptor.
  1339. \end{description}
  1340. \Errors
  1341. Check the \var{int31error} variable.
  1342. \SeeAlso
  1343. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors},
  1344. \seefl{get\_segment\_base\_address}{getsegmentbaseaddress},
  1345. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors},
  1346. \seefl{set\_segment\_limit}{setsegmentlimit},
  1347. \seefl{get\_segment\_base\_address}{getsegmentbaseaddress},
  1348. \seefl{get\_segment\_limit}{getsegmentlimit}
  1349. \end{functionl}
  1350. \begin{functionl}{set\_segment\_limit}{setsegmentlimit}
  1351. \Declaration
  1352. Function set\_segment\_limit (d : Word; s : Longint) : boolean;
  1353. \Description
  1354. Sets the limit of a descriptor.
  1355. Parameters:
  1356. \begin{description}
  1357. \item[d:\ ] selector.
  1358. \item[s:\ ] new limit of the descriptor.
  1359. \end{description}
  1360. Return values: Returns \var{True} if successful, else \var{False}.
  1361. Notes: The new limit specified must be the byte length of the segment - 1.
  1362. Segment limits bigger than or equal to 1MB must be page aligned, they must
  1363. have the lower 12 bits set.
  1364. \Errors
  1365. Check the \var{int31error} variable.
  1366. \SeeAlso
  1367. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors},
  1368. \seefl{set\_segment\_base\_address}{setsegmentbaseaddress},
  1369. \seefl{get\_segment\_limit}{getsegmentlimit},
  1370. \seefl{set\_segment\_limit}{setsegmentlimit}
  1371. \end{functionl}
  1372. For an example, see
  1373. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors}.
  1374. \begin{functionl}{tb\_size}{tbsize}
  1375. \Declaration
  1376. Function tb\_size : Longint;
  1377. \Description
  1378. Returns the size of the pre-allocated \dos memory buffer.
  1379. Parameters: None.
  1380. Return values: The size of the pre-allocated \dos memory buffer.
  1381. Notes:
  1382. This block always seems to be 16k in size, but don't rely on this.
  1383. \Errors
  1384. None.
  1385. \SeeAlso
  1386. \seefl{transfer\_buffer}{transferbuffer}, \seep{copyfromdos}
  1387. \seep{copytodos}
  1388. \end{functionl}
  1389. \begin{functionl}{unlock\_code}{unlockcode}
  1390. \Declaration
  1391. Function unlock\_code (functionaddr : pointer; size : Longint) : boolean;
  1392. \Description
  1393. Unlocks a memory range which resides in the code segment selector.
  1394. Parameters:
  1395. \begin{description}
  1396. \item[functionaddr:\ ] address of function to be unlocked.
  1397. \item[size:\ ] size bytes to be unlocked.
  1398. \end{description}
  1399. Return value: \var{True} if successful, \var{False} otherwise.
  1400. \Errors
  1401. Check the \var{int31error} variable.
  1402. \SeeAlso
  1403. \seefl{unlock\_linear\_region}{unlocklinearregion},
  1404. \seefl{unlock\_data}{unlockdata},
  1405. \seefl{lock\_linear\_region}{locklinearregion},
  1406. \seefl{lock\_data}{lockdata},
  1407. \seefl{lock\_code}{lockcode}
  1408. \end{functionl}
  1409. For an example, see \seefl{get\_rm\_callback}{getrmcallback}.
  1410. \begin{functionl}{unlock\_data}{unlockdata}
  1411. \Declaration
  1412. Function unlock\_data (var data; size : Longint) : boolean;
  1413. \Description
  1414. Unlocks a memory range which resides in the data segment selector.
  1415. Paramters:
  1416. \begin{description}
  1417. \item[data:\ ] address of memory to be unlocked.
  1418. \item[size:\ ] size bytes to be unlocked.
  1419. \end{description}
  1420. Return values: \var{True} if successful, \var{False} otherwise.
  1421. \Errors
  1422. Check the \var{int31error} variable.
  1423. \SeeAlso
  1424. \seefl{unlock\_linear\_region}{unlocklinearregion},
  1425. \seefl{unlock\_code}{unlockcode},
  1426. \seefl{lock\_linear\_region}{locklinearregion},
  1427. \seefl{lock\_data}{lockdata},
  1428. \seefl{lock\_code}{lockcode}
  1429. \end{functionl}
  1430. For an example, see \seefl{get\_rm\_callback}{getrmcallback}.
  1431. \begin{functionl}{unlock\_linear\_region}{unlocklinearregion}
  1432. \Declaration
  1433. Function unlock\_linear\_region (linearaddr, size : Longint) : boolean;
  1434. \Description
  1435. Unlocks a previously locked linear region range to allow it to be swapped
  1436. out again if needed.
  1437. Parameters:
  1438. \begin{description}
  1439. \item[linearaddr:\ ] linear address of the memory to be unlocked.
  1440. \item[size:\ ] size bytes to be unlocked.
  1441. \end{description}
  1442. Return values: \var{True} if successful, \var{False} otherwise.
  1443. \Errors
  1444. Check the \var{int31error} variable.
  1445. \SeeAlso
  1446. \seefl{unlock\_data}{unlockdata},
  1447. \seefl{unlock\_code}{unlockcode},
  1448. \seefl{lock\_linear\_region}{locklinearregion},
  1449. \seefl{lock\_data}{lockdata},
  1450. \seefl{lock\_code}{lockcode}
  1451. \end{functionl}