go32.tex 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501
  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. \functionl{allocate\_ldt\_descriptors}{allocateldtdescriptors}{(count : Word)}{Word}
  359. {Allocates a number of new descriptors.
  360. Parameters:
  361. \begin{description}
  362. \item[count:\ ] specifies the number of requested unique descriptors.
  363. \end{description}
  364. Return value: The base selector.
  365. Notes: The descriptors allocated must be initialized by the application with
  366. other function calls. This function returns descriptors with a limit and
  367. size value set to zero. If more than one descriptor was requested, the
  368. function returns a base selector referencing the first of a contiguous array
  369. of descriptors. The selector values for subsequent descriptors in the array
  370. can be calculated by adding the value returned by the
  371. \seefl{get\_next\_selector\_increment\_value}{getnextselectorincrementvalue}
  372. function.
  373. }
  374. { Check the \var{int31error} variable. }
  375. {
  376. \seefl{free\_ldt\_descriptor}{freeldtdescriptor},
  377. \seefl{get\_next\_selector\_increment\_value}{getnextselectorincrementvalue},
  378. \seefl{segment\_to\_descriptor}{segmenttodescriptor},
  379. \seefl{create\_code\_segment\_alias\_descriptor}{createcodesegmentaliasdescriptor},
  380. \seefl{set\_segment\_limit}{setsegmentlimit},
  381. \seefl{set\_segment\_base\_address}{setsegmentbaseaddress}
  382. }
  383. \latex{\inputlisting{go32ex/sel_des.pp}}
  384. \html{\input{go32ex/sel_des.tex}}
  385. \functionl{allocate\_memory\_block}{allocatememoryblock}{(size:Longint)}{Longint}
  386. {Allocates a block of linear memory.
  387. Parameters:
  388. \begin{description}
  389. \item[size:\ ] Size of requested linear memory block in bytes.
  390. \end{description}
  391. Returned values: blockhandle - the memory handle to this memory block. Linear
  392. address of the requested memory.
  393. Notes: WARNING: According to my DPMI docs this function is not implemented
  394. correctly. Normally you should also get a blockhandle to this block after
  395. successful operation. This handle is used to free the memory block
  396. afterwards or use this handle for other purposes. So this block can't be
  397. deallocated and is henceforth unusuable !
  398. This function doesn't allocate any descriptors for this block, it's the
  399. applications resposibility to allocate and initialize for accessing this
  400. memory.
  401. }{ Check the \var{int31error} variable.}
  402. { \seefl{free\_memory\_block}{freememoryblock} }
  403. \procedure{copyfromdos}{(var addr; len : Longint)}{
  404. Copies data from the pre-allocated \dos memory transfer buffer to the heap.
  405. Parameters:
  406. \begin{description}
  407. \item[addr:\ ] data to copy to.
  408. \item[len:\ ] number of bytes to copy to heap.
  409. \end{description}
  410. Notes:
  411. Can only be used in conjunction with the \dos memory transfer buffer.
  412. }{Check the \var{int31error} variable.}
  413. {\seefl{tb\_size}{tbsize}, \seefl{transfer\_buffer}{transferbuffer},
  414. \seep{copytodos}}
  415. \procedure{copytodos}{(var addr; len : Longint)}
  416. {Copies data from heap to the pre-allocated \dos memory buffer.
  417. Parameters:
  418. \begin{description}
  419. \item[addr:\ ] data to copy from.
  420. \item[len:\ ] number of bytes to copy to \dos memory buffer.
  421. \end{description}
  422. Notes: This function fails if you try to copy more bytes than the transfer
  423. buffer is in size. It can only be used in conjunction with the transfer
  424. buffer.
  425. }
  426. { Check the \var{int31error} variable.}
  427. {\seefl{tb\_size}{tbsize}, \seefl{transfer\_buffer}{transferbuffer},
  428. \seep{copyfromdos}}
  429. \functionl{create\_code\_segment\_alias\_descriptor}
  430. {createcodesegmentaliasdescriptor}{(seg : Word)}{Word}
  431. {
  432. Creates a new descriptor that has the same base and limit as the specified
  433. descriptor.
  434. Parameters:
  435. \begin{description}
  436. \item[seg:\ ] selector.
  437. \end{description}
  438. Return values: The data selector (alias).
  439. Notes: In effect, the function returns a copy of the descriptor. The
  440. descriptor alias returned by this function will not track changes to the
  441. original descriptor. In other words, if an alias is created with this
  442. function, and the base or limit of the original segment is then changed, the
  443. two descriptors will no longer map the same memory.
  444. }
  445. {Check the \var{int31error} variable.}
  446. {
  447. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors},
  448. \seefl{set\_segment\_limit}{setsegmentlimit},
  449. \seefl{set\_segment\_base\_address}{setsegmentbaseaddress} }
  450. \Procedure{disable}
  451. {Disables all hardware interrupts by execution a CLI instruction.
  452. Parameters: None.
  453. }{None.}{\seep{enable}}
  454. \procedure{dosmemfillchar}{(seg, ofs : Word; count : Longint; c : char)}
  455. {Sets a region of \dos memory to a specific byte value.
  456. Parameters:
  457. \begin{description}
  458. \item[seg:\ ] real mode segment.
  459. \item[ofs:\ ] real mode offset.
  460. \item[count:\ ] number of bytes to set.
  461. \item[c:\ ] value to set memory to.
  462. \end{description}
  463. Notes: No range check is performed.
  464. }
  465. { None.}{
  466. \seep{dosmemput},
  467. \seep{dosmemget},
  468. \seep{dosmemmove}{dosmemmove},
  469. \seepl{dosmemfillword}{dosmemfillword},
  470. \seepl{seg\_move}{segmove},
  471. \seepl{seg\_fillchar}{segfillchar},
  472. \seepl{seg\_fillword}{segfillword} }
  473. \latex{\inputlisting{go32ex/textmess.pp}}
  474. \html{\input{go32ex/textmess.tex}}
  475. \procedure{dosmemfillword}{(seg,ofs : Word; count : Longint; w : Word)}
  476. {Sets a region of \dos memory to a specific word value.
  477. Parameters:
  478. \begin{description}
  479. \item[seg:\ ] real mode segment.
  480. \item[ofs:\ ] real mode offset.
  481. \item[count:\ ] number of words to set.
  482. \item[w:\ ] value to set memory to.
  483. \end{description}
  484. Notes: No range check is performed.
  485. }{ None.}{
  486. \seep{dosmemput},
  487. \seepl{dosmemget}{dosmemget},
  488. \seepl{dosmemmove}{dosmemmove},
  489. \seepl{dosmemfillchar}{dosmemfillchar},
  490. \seepl{seg\_move}{segmove},
  491. \seepl{seg\_fillchar}{segfillchar},
  492. \seepl{seg\_fillword}{segfillword} }
  493. \procedure{dosmemget}{(seg : Word; ofs : Word; var data; count : Longint)}
  494. {Copies data from the \dos memory onto the heap.
  495. Parameters:
  496. \begin{description}
  497. \item[seg:\ ] source real mode segment.
  498. \item[ofs:\ ] source real mode offset.
  499. \item[data:\ ] destination.
  500. \item[count:\ ] number of bytes to copy.
  501. \end{description}
  502. Notes: No range checking is performed.
  503. }{ None. }
  504. {\seep{dosmemput},
  505. \seep{dosmemmove},
  506. \seep{dosmemfillchar},
  507. \seep{dosmemfillword},
  508. \seepl{seg\_move}{segmove},
  509. \seepl{seg\_fillchar}{segfillchar},
  510. \seepl{seg\_fillword}{segfillword} }
  511. For an example, see \seefl{global\_dos\_alloc}{globaldosalloc}.
  512. \procedure{dosmemmove}{(sseg, sofs, dseg, dofs : Word; count : Longint)}
  513. {Copies count bytes of data between two \dos real mode memory locations.
  514. Parameters:
  515. \begin{description}
  516. \item[sseg:\ ] source real mode segment.
  517. \item[sofs:\ ] source real mode offset.
  518. \item[dseg:\ ] destination real mode segment.
  519. \item[dofs:\ ] destination real mode offset.
  520. \item[count:\ ] number of bytes to copy.
  521. \end{description}
  522. Notes: No range check is performed in any way.
  523. }
  524. { None.}
  525. {\seep{dosmemput},
  526. \seep{dosmemget},
  527. \seep{dosmemfillchar},
  528. \seep{dosmemfillword}
  529. \seepl{seg\_move}{segmove},
  530. \seepl{seg\_fillchar}{segfillchar},
  531. \seepl{seg\_fillword}{segfillword} }
  532. For an example, see \seepl{seg\_fillchar}{segfillchar}.
  533. \procedure{dosmemput}{(seg : Word; ofs : Word; var data; count : Longint)}
  534. {Copies heap data to \dos real mode memory.
  535. Parameters:
  536. \begin{description}
  537. \item[seg:\ ] destination real mode segment.
  538. \item[ofs:\ ] destination real mode offset.
  539. \item[data:\ ] source.
  540. \item[count:\ ] number of bytes to copy.
  541. \end{description}
  542. Notes: No range checking is performed.
  543. }{ None. }
  544. {\seep{dosmemget},
  545. \seep{dosmemmove},
  546. \seep{dosmemfillchar},
  547. \seep{dosmemfillword},
  548. \seepl{seg\_move}{segmove},
  549. \seepl{seg\_fillchar}{segfillchar},
  550. \seepl{seg\_fillword}{segfillword} }
  551. For an example, see \seefl{global\_dos\_alloc}{globaldosalloc}.
  552. \Procedure{enable}{
  553. Enables all hardware interrupts by executing a STI instruction.
  554. Parameters: None.
  555. }{None.}{ \seep{disable} }
  556. \functionl{free\_ldt\_descriptor}{freeldtdescriptor}{(des : Word)}{boolean}
  557. {Frees a previously allocated descriptor.
  558. Parameters:
  559. \begin{description}
  560. \item[des:\ ] The descriptor to be freed.
  561. \end{description}
  562. Return value: \var{True} if successful, \var{False} otherwise.
  563. Notes: After this call this selector is invalid and must not be used for any
  564. memory operations anymore. Each descriptor allocated with
  565. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors} must be freed
  566. individually with this function,
  567. even if it was previously allocated as a part of a contiguous array of
  568. descriptors.
  569. }{Check the \var{int31error} variable.}{
  570. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors},
  571. \seefl{get\_next\_selector\_increment\_value}{getnextselectorincrementvalue}
  572. }
  573. For an example, see
  574. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors}.
  575. \functionl{free\_memory\_block}{freememoryblock}{(blockhandle :
  576. Longint)}{boolean}
  577. {Frees a previously allocated memory block.
  578. Parameters:
  579. \begin{description}
  580. \item{blockhandle:} the handle to the memory area to free.
  581. \end{description}
  582. Return value: \var{True} if successful, \var{false} otherwise.
  583. Notes: Frees memory that was previously allocated with
  584. \seefl{allocate\_memory\_block}{allocatememoryblock} .
  585. This function doesn't free any descriptors mapped to this block,
  586. it's the application's responsibility.
  587. }
  588. { Check \var{int31error} variable.}
  589. {\seefl{allocate\_memory\_block}{allocatememoryblock} }
  590. \functionl{free\_rm\_callback}{freermcallback}{(var intaddr : tseginfo)}{boolean}
  591. {
  592. Releases a real mode callback address that was previously allocated with the
  593. \seefl{get\_rm\_callback}{getrmcallback} function.
  594. Parameters:
  595. \begin{description}
  596. \item[intaddr:\ ] real mode address buffer returned by
  597. \seefl{get\_rm\_callback}{getrmcallback} .
  598. \end{description}
  599. Return values: \var{True} if successful, \var{False} if not
  600. }{ Check the \var{int31error} variable.}
  601. {
  602. \seefl{set\_rm\_interrupt}{setrminterrupt},
  603. \seefl{get\_rm\_callback}{getrmcallback}
  604. }
  605. For an example, see \seefl{get\_rm\_callback}{getrmcallback}.
  606. \Functionl{get\_cs}{getcs}{Word}{
  607. Returns the cs selector.
  608. Parameters: None.
  609. Return values: The content of the cs segment register.
  610. }{None.}{ \seefl{get\_ds}{getds}, \seefl{get\_ss}{getss}}
  611. For an example, see \seefl{set\_pm\_interrupt}{setpminterrupt}.
  612. \functionl{get\_descriptor\_access\_rights}{getdescriptoraccessrights}
  613. {(d : Word)}{Longint}
  614. {Gets the access rights of a descriptor.
  615. Parameters:
  616. \begin{description}
  617. \item{d} selector to descriptor.
  618. \end{description}
  619. Return value: Access rights bit field.
  620. }
  621. {Check the \var{int31error} variable.}{
  622. \seefl{set\_descriptor\_access\_rights}{setdescriptoraccessrights}}
  623. \Functionl{get\_ds}{getds}{Word}
  624. {Returns the ds selector.
  625. Parameters: None.
  626. Return values: The content of the ds segment register.
  627. }{ None.}{ \seefl{get\_cs}{getcs}, \seefl{get\_ss}{getss}}
  628. \functionl{get\_linear\_addr}{getlinearaddr}
  629. {(phys\_addr : Longint; size : Longint)}{Longint}
  630. {Converts a physical address into a linear address.
  631. Parameters:
  632. \begin{description}
  633. \item [phys\_addr:\ ] physical address of device.
  634. \item [size:\ ] Size of region to map in bytes.
  635. \end{description}
  636. Return value: Linear address that can be used to access the physical memory.
  637. Notes: It's the applications resposibility to allocate and set up a
  638. descriptor for access to the memory. This function shouldn't be used to map
  639. real mode addresses.
  640. }
  641. { Check the \var{int31error} variable.}
  642. {
  643. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors}, \seefl{set\_segment\_limit}{setsegmentlimit},
  644. \seefl{set\_segment\_base\_address}{setsegmentbaseaddress} }
  645. \functionl{get\_meminfo}{getmeminfo}{(var meminfo : tmeminfo)}{boolean}
  646. { Returns information about the amount of available physical memory, linear
  647. address space, and disk space for page swapping.
  648. Parameters:
  649. \begin{description}
  650. \item[meminfo:\ ] buffer to fill memory information into.
  651. \end{description}
  652. Return values: Due to an implementation bug this function always returns
  653. \var{False}, but it always succeeds.
  654. Notes: Only the first field of the returned structure is guaranteed to
  655. contain a valid value. Any fields that are not supported by the DPMI host
  656. will be set by the host to \var{-1 (0FFFFFFFFH)} to indicate that the information
  657. is not available. The size of the pages used by the DPMI host can be
  658. obtained with the \seefl{get\_page\_size}{getpagesize} function.
  659. }
  660. {Check the \var{int31error} variable.}
  661. {\seefl{get\_page\_size}{getpagesize} }
  662. \latex{\inputlisting{go32ex/meminfo.pp}}
  663. \html{\input{go32ex/meminfo.tex}}
  664. \Functionl{get\_next\_selector\_increment\_value}
  665. {getnextselectorincrementvalue}{Word}
  666. {Returns the selector increment value when allocating multiple subsequent
  667. descriptors via \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors}.
  668. Parameters: None.
  669. Return value: Selector increment value.
  670. Notes: Because \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors} only returns the selector for the
  671. first descriptor and so the value returned by this function can be used to
  672. calculate the selectors for subsequent descriptors in the array.
  673. }{ Check the \var{int31error} variable.}
  674. { \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors},
  675. \seefl{free\_ldt\_descriptor}{freeldtdescriptor} }
  676. \Functionl{get\_page\_size}{getpagesize}{ Longint}
  677. { Returns the size of a single memory page.
  678. Return value: Size of a single page in bytes.
  679. Notes: The returned size is typically 4096 bytes.
  680. }
  681. { Check the \var{int31error} variable.}
  682. { \seefl{get\_meminfo}{getmeminfo} }
  683. For an example, see \seefl{get\_meminfo}{getmeminfo}.
  684. \functionl{get\_pm\_interrupt}{getpminterrupt}
  685. {(vector : byte; var intaddr : tseginfo)}{boolean}
  686. {Returns the address of a current protected mode interrupt handler.
  687. Parameters:
  688. \begin{description}
  689. \item[vector:\ ] interrupt handler number you want the address to.
  690. \item[intaddr:\ ] buffer to store address.
  691. \end{description}
  692. Return values: \var{True} if successful, \var{False} if not.
  693. Notes: The returned address is a protected mode selector:offset address.
  694. }
  695. { Check the \var{int31error} variable.}
  696. { \seefl{set\_pm\_interrupt}{setpminterrupt},
  697. \seefl{set\_rm\_interrupt}{setrminterrupt}, \seefl{get\_rm\_interrupt}{getrminterrupt} }
  698. For an example, see \seefl{set\_pm\_interrupt}{setpminterrupt}.
  699. \functionl{get\_rm\_callback}{getrmcallback}
  700. {(pm\_func : pointer; const reg : trealregs; var rmcb: tseginfo)}{boolean}
  701. {
  702. Returns a unique real mode \var{segment:offset} address, known as a "real mode
  703. callback," that will transfer control from real mode to a protected mode
  704. procedure.
  705. Parameters:
  706. \begin{description}
  707. \item[pm\_func:\ ] pointer to the protected mode callback function.
  708. \item[reg:\ ] supplied registers structure.
  709. \item[rmcb:\ ] buffer to real mode address of callback function.
  710. \end{description}
  711. Return values: \var{True} if successful, otherwise \var{False}.
  712. Notes: Callback addresses obtained with this function can be passed by a
  713. protected mode program for example to an interrupt handler, device driver,
  714. or TSR, so that the real mode program can call procedures within the
  715. protected mode program or notify the protected mode program of an event. The
  716. contents of the supplied regs structure is not valid after function call,
  717. but only at the time of the actual callback.
  718. }{Check the \var{int31error} variable.}
  719. {\seefl{free\_rm\_callback}{freermcallback} }
  720. \latex{\inputlisting{go32ex/callback.pp}}
  721. \html{\input{go32ex/callback.tex}}
  722. \functionl{get\_rm\_interrupt}{getrminterrupt}{(vector : byte; var intaddr :
  723. tseginfo)}{boolean}
  724. {Returns the contents of the current machine's real mode interrupt vector for
  725. the specified interrupt.
  726. Parameters:
  727. \begin{description}
  728. \item[vector:\ ] interrupt vector number.
  729. \item[intaddr:\ ] buffer to store real mode \var{segment:offset} address.
  730. \end{description}
  731. Return values: \var{True} if successful, \var{False} otherwise.
  732. Notes: The returned address is a real mode segment address, which isn't
  733. valid in protected mode.
  734. }
  735. { Check the \var{int31error} variable.}
  736. { \seefl{set\_rm\_interrupt}{setrminterrupt},
  737. \seefl{set\_pm\_interrupt}{setpminterrupt},
  738. \seefl{get\_pm\_interrupt}{getpminterrupt} }
  739. \Functionl{get\_run\_mode}{getrunmode}{Word}
  740. {Returns the current mode your application runs with.
  741. Return values: One of the constants used by this function.
  742. }
  743. {None. }
  744. { constants returned by \seefl{get\_run\_mode}{getrunmode} }
  745. \latex{\inputlisting{go32ex/getrunmd.pp}}
  746. \html{\input{go32ex/getrunmd.tex}}
  747. \functionl{get\_segment\_base\_address}{getsegmentbaseaddress}{
  748. (d : Word)}{Longint}
  749. { Returns the 32-bit linear base address from the descriptor table for the
  750. specified segment.
  751. Parameters:
  752. \begin{description}
  753. \item[d:\ ] selector of the descriptor you want the base address.
  754. \end{description}
  755. Return values: Linear base address of specified descriptor.
  756. }
  757. { Check the \var{int31error} variable.}
  758. {
  759. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors},
  760. \seefl{set\_segment\_base\_address}{setsegmentbaseaddress},
  761. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors},
  762. \seefl{set\_segment\_limit}{setsegmentlimit},
  763. \seefl{get\_segment\_limit}{getsegmentlimit}
  764. }
  765. For an example, see
  766. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors}.
  767. \functionl{get\_segment\_limit}{getsegmentlimit}{(d : Word)}{Longint}
  768. {Returns a descriptors segment limit.
  769. Parameters:
  770. \begin{description}
  771. \item [d:\ ] selector.
  772. \end{description}
  773. Return value: Limit of the descriptor in bytes.
  774. }{ Returns zero if descriptor is invalid. }
  775. {\seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors},
  776. \seefl{set\_segment\_limit}{setsegmentlimit},
  777. \seefl{set\_segment\_base\_address}{setsegmentbaseaddress},
  778. \seefl{get\_segment\_base\_address}{getsegmentbaseaddress},
  779. }
  780. \Functionl{get\_ss}{getss}{Word}{
  781. Returns the ss selector.
  782. Parameters: None.
  783. Return values: The content of the ss segment register.
  784. }{ None.}{ \seefl{get\_ds}{getds}, \seefl{get\_cs}{getcs}}
  785. \functionl{global\_dos\_alloc}{globaldosalloc}{(bytes : Longint)}{Longint}
  786. {Allocates a block of \dos real mode memory.
  787. Parameters:
  788. \begin{description}
  789. \item [bytes:\ ] size of requested real mode memory.
  790. \end{description}
  791. Return values: The high word of the returned value contains the selector to
  792. the allocated \dos memory block, the low word the corresponding real mode
  793. segment value. The offset value is always zero.
  794. This function allocates memory from \dos memory pool, i.e. memory below the 1
  795. MB boundary that is controlled by \dos. Such memory blocks are typically used
  796. to exchange data with real mode programs, TSRs, or device drivers. The
  797. function returns both the real mode segment base address of the block and
  798. one descriptor that can be used by protected mode applications to access the
  799. block. This function should only used for temporary buffers to get real mode
  800. information (e.g. interrupts that need a data structure in ES:(E)DI),
  801. because every single block needs an unique selector. The returned selector
  802. should only be freed by a \seefl{global\_dos\_free}{globaldosfree} call.
  803. }{ Check the \var{int31error} variable.}
  804. { \seefl{global\_dos\_free}{globaldosfree} }
  805. \latex{\inputlisting{go32ex/buffer.pp}}
  806. \html{\input{go32ex/buffer.tex}}
  807. \functionl{global\_dos\_free}{globaldosfree}{(selector :Word)}{boolean}
  808. {Frees a previously allocated \dos memory block.
  809. Parameters:
  810. \begin{description}
  811. \item[selector:\ ] selector to the \dos memory block.
  812. \end{description}
  813. Return value: \var{True} if successful, \var{False} otherwise.
  814. Notes: The descriptor allocated for the memory block is automatically freed
  815. and hence invalid for further use. This function should only be used for
  816. memory allocated by \seefl{global\_dos\_alloc}{globaldosalloc}.
  817. }
  818. { Check the \var{int31error} variable.}
  819. {\seefl{global\_dos\_alloc}{globaldosalloc} }
  820. For an example, see \seefl{global\_dos\_alloc}{globaldosalloc}.
  821. \function{inportb}{(port : Word)}{byte}
  822. {Reads 1 byte from the selected I/O port.
  823. Parameters:
  824. \begin{description}
  825. \item[port:\ ] the I/O port number which is read.
  826. \end{description}
  827. Return values: Current I/O port value.
  828. }{ None. }
  829. {\seep{outportb}, \seef{inportw}, \seef{inportl}}
  830. \function{inportl}{(port : Word)}{Longint}{
  831. Reads 1 longint from the selected I/O port.
  832. Parameters:
  833. \begin{description}
  834. \item[port:\ ] the I/O port number which is read.
  835. \end{description}
  836. Return values: Current I/O port value.
  837. }{None. }
  838. {\seep{outportb}, \seef{inportb}, \seef{inportw} }
  839. \function{inportw}{(port : Word)}{Word}{
  840. Reads 1 word from the selected I/O port.
  841. Parameters:
  842. \begin{description}
  843. \item[port:\ ] the I/O port number which is read.
  844. \end{description}
  845. Return values: Current I/O port value.
  846. }{ None. }
  847. {\seep{outportw} \seef{inportb}, \seef{inportl} }
  848. \functionl{lock\_code}{lockcode}{(functionaddr : pointer; size : Longint)}
  849. {boolean}
  850. {Locks a memory range which is in the code segment selector.
  851. Parameters:
  852. \begin{description}
  853. \item[functionaddr:\ ] address of the function to be locked.
  854. \item[size:\ ] size in bytes to be locked.
  855. \end{description}
  856. Return values: \var{True} if successful, \var{False} otherwise.
  857. }{Check the \var{int31error} variable.}{
  858. \seefl{lock\_linear\_region}{locklinearregion},
  859. \seefl{lock\_data}{lockdata},
  860. \seefl{unlock\_linear\_region}{unlocklinearregion},
  861. \seefl{unlock\_data}{unlockdata},
  862. \seefl{unlock\_code}{unlockcode} }
  863. For an example, see \seefl{get\_rm\_callback}{getrmcallback}.
  864. \functionl{lock\_data}{lockdata}{(var data; size : Longint)}{boolean}
  865. {Locks a memory range which resides in the data segment selector.
  866. Parameters:
  867. \begin{description}
  868. \item[data:\ ] address of data to be locked.
  869. \item[size:\ ] length of data to be locked.
  870. \end{description}
  871. Return values: \var{True} if successful, \var{False} otherwise.
  872. }
  873. { Check the \var{int31error} variable.}{
  874. \seefl{lock\_linear\_region}{locklinearregion},
  875. \seefl{lock\_code}{lockcode},
  876. \seefl{unlock\_linear\_region}{unlocklinearregion},
  877. \seefl{unlock\_data}{unlockdata},
  878. \seefl{unlock\_code}{unlockcode} }
  879. For an example, see \seefl{get\_rm\_callback}{getrmcallback}.
  880. \functionl{lock\_linear\_region}{locklinearregion}{(linearaddr, size : Longint)}{boolean}
  881. {Locks a memory region to prevent swapping of it.
  882. Parameters:
  883. \begin{description}
  884. \item[linearaddr:\ ] the linear address of the memory are to be locked.
  885. \item[size:\ ] size in bytes to be locked.
  886. \end{description}
  887. Return value: \var{True} if successful, False otherwise.
  888. }
  889. { Check the \var{int31error} variable.}
  890. {
  891. \seefl{lock\_data}{lockdata},
  892. \seefl{lock\_code}{lockcode},
  893. \seefl{unlock\_linear\_region}{unlocklinearregion},
  894. \seefl{unlock\_data}{unlockdata},
  895. \seefl{unlock\_code}{unlockcode}}
  896. \procedure{outportb}{(port : Word; data : byte)}
  897. {Sends 1 byte of data to the specified I/O port.
  898. Parameters:
  899. \begin{description}
  900. \item[port:\ ] the I/O port number to send data to.
  901. \item[data:\ ] value sent to I/O port.
  902. \end{description}
  903. Return values: None.
  904. }{ None. }{\seef{inportb}, \seep{outportl}, \seep{outportw} }
  905. \latex{\inputlisting{go32ex/outport.pp}}
  906. \html{\input{go32ex/outport.tex}}
  907. \procedure{outportl}{(port : Word; data : Longint)}
  908. {Sends 1 longint of data to the specified I/O port.
  909. Parameters:
  910. \begin{description}
  911. \item[port:\ ] the I/O port number to send data to.
  912. \item[data:\ ] value sent to I/O port.
  913. \end{description}
  914. Return values: None.
  915. }{None. }{\seef{inportl}, \seep{outportw}, \seep{outportb}}
  916. For an example, see \seep{outportb}.
  917. \procedure{outportw}{(port : Word; data : Word)}
  918. {Sends 1 word of data to the specified I/O port.
  919. Parameters:
  920. \begin{description}
  921. \item[port:\ ] the I/O port number to send data to.
  922. \item[data:\ ] value sent to I/O port.
  923. \end{description}
  924. Return values: None.
  925. }{ None. }
  926. {\seef{inportw}, \seep{outportl}, \seep{outportb}}
  927. For an example, see \seep{outportb}.
  928. \function{realintr}{(intnr: Word; var regs : trealregs)}{ boolean}
  929. {Simulates an interrupt in real mode.
  930. Parameters:
  931. \begin{description}
  932. \item[intnr:\ ] interrupt number to issue in real mode.
  933. \item[regs:\ ] registers data structure.
  934. \end{description}
  935. Return values: The supplied registers data structure contains the values
  936. that were returned by the real mode interrupt. \var{True} if successful, \var{False} if
  937. not.
  938. Notes: The function transfers control to the address specified by the real
  939. mode interrupt vector of intnr. The real mode handler must return by
  940. executing an IRET.
  941. }
  942. { Check the \var{int31error} variable.}
  943. {}
  944. \latex{\inputlisting{go32ex/flags.pp}}
  945. \html{\input{go32ex/flags.tex}}
  946. \procedurel{seg\_fillchar}{segfillchar}
  947. {(seg : Word; ofs : Longint; count : Longint; c : char)}{
  948. Sets a memory area to a specific value.
  949. Parameters:
  950. \begin{description}
  951. \item[seg:\ ] selector to memory area.
  952. \item[ofs:\ ] offset to memory.
  953. \item[count:\ ] number of bytes to set.
  954. \item[c:\ ] byte data which is set.
  955. \end{description}
  956. Return values: None.
  957. Notes: No range check is done in any way.
  958. }{ None. }
  959. {\seepl{seg\_move}{segmove},
  960. \seepl{seg\_fillword}{segfillword},
  961. \seepl{dosmemfillchar}{dosmemfillchar},
  962. \seepl{dosmemfillword}{dosmemfillword},
  963. \seepl{dosmemget}{dosmemget},
  964. \seepl{dosmemput}{dosmemput},
  965. \seepl{dosmemmove}{dosmemmove} }
  966. \latex{\inputlisting{go32ex/vgasel.pp}}
  967. \html{\input{go32ex/vgasel.tex}}
  968. \procedurel{seg\_fillword}{segfillword}
  969. {(seg : Word; ofs : Longint; count : Longint; w :Word)}
  970. {
  971. Sets a memory area to a specific value.
  972. Parameters:
  973. \begin{description}
  974. \item[seg:\ ] selector to memory area.
  975. \item[ofs:\ ] offset to memory.
  976. \item[count:\ ] number of words to set.
  977. \item[w:\ ] word data which is set.
  978. \end{description}
  979. Return values: None.
  980. Notes: No range check is done in any way.
  981. }{None. }
  982. {
  983. \seepl{seg\_move}{segmove},
  984. \seepl{seg\_fillchar}{segfillchar},
  985. \seepl{dosmemfillchar}{dosmemfillchar},
  986. \seepl{dosmemfillword}{dosmemfillword},
  987. \seepl{dosmemget}{dosmemget},
  988. \seepl{dosmemput}{dosmemput},
  989. \seepl{dosmemmove}{dosmemmove} }
  990. For an example, see
  991. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors}.
  992. \functionl{segment\_to\_descriptor}{segmenttodescriptor}{(seg : Word)}{Word}
  993. {
  994. Maps a real mode segment (paragraph) address onto an descriptor that can be
  995. used by a protected mode program to access the same memory.
  996. Parameters:
  997. \begin{description}
  998. \item [seg:\ ] the real mode segment you want the descriptor to.
  999. \end{description}
  1000. Return values: Descriptor to real mode segment address.
  1001. Notes: The returned descriptors limit will be set to 64 kB. Multiple calls
  1002. to this function with the same segment address will return the same
  1003. selector. Descriptors created by this function can never be modified or
  1004. freed. Programs which need to examine various real mode addresses using the
  1005. same selector should use the function
  1006. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors} and change
  1007. the base address as necessary.
  1008. }{ Check the \var{int31error} variable. }
  1009. {\seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors},
  1010. \seefl{free\_ldt\_descriptor}{freeldtdescriptor},
  1011. \seefl{set\_segment\_base\_address}{setsegmentbaseaddress}
  1012. }
  1013. For an example, see \seepl{seg\_fillchar}{segfillchar}.
  1014. \procedurel{seg\_move}{segmove}{(sseg : Word; source : Longint; dseg : Word; dest :
  1015. Longint; count : Longint)}
  1016. {Copies data between two memory locations.
  1017. Parameters:
  1018. \begin{description}
  1019. \item[sseg:\ ] source selector.
  1020. \item[source:\ ] source offset.
  1021. \item[dseg:\ ] destination selector.
  1022. \item[dest:\ ] destination offset.
  1023. \item[count:\ ] size in bytes to copy.
  1024. \end{description}
  1025. Return values: None.
  1026. Notes: Overlapping is only checked if the source selector is equal to the
  1027. destination selector. No range check is done.
  1028. }
  1029. { None.}
  1030. {
  1031. \seepl{seg\_fillchar}{segfillchar},
  1032. \seepl{seg\_fillword}{segfillword},
  1033. \seepl{dosmemfillchar}{dosmemfillchar},
  1034. \seepl{dosmemfillword}{dosmemfillword},
  1035. \seepl{dosmemget}{dosmemget},
  1036. \seepl{dosmemput}{dosmemput},
  1037. \seepl{dosmemmove}{dosmemmove} }
  1038. For an example, see
  1039. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors}.
  1040. \functionl{set\_descriptor\_access\_rights}{setdescriptoraccessrights}
  1041. {(d : Word; w : Word)}{Longint}
  1042. {
  1043. Sets the access rights of a descriptor.
  1044. Parameters:
  1045. \begin{description}
  1046. \item[d:\ ] selector.
  1047. \item[w:\ ] new descriptor access rights.
  1048. \end{description}
  1049. Return values: This function doesn't return anything useful.
  1050. }
  1051. { Check the \var{int31error} variable.}
  1052. {
  1053. \seefl{get\_descriptor\_access\_rights}{getdescriptoraccessrights} }
  1054. \functionl{set\_pm\_interrupt}{setpminterrupt}
  1055. {(vector : byte; const intaddr : tseginfo)}{boolean}
  1056. {Sets the address of the protected mode handler for an interrupt.
  1057. Parameters:
  1058. \begin{description}
  1059. \item[vector:\ ] number of protected mode interrupt to set.
  1060. \item[intaddr:\ ] selector:offset address to the interrupt vector.
  1061. \end{description}
  1062. Return values: \var{True} if successful, \var{False} otherwise.
  1063. Notes: The address supplied must be a valid \var{selector:offset}
  1064. protected mode address.
  1065. }{ Check the \var{int31error} variable.}
  1066. {\seefl{get\_pm\_interrupt}{getpminterrupt},
  1067. \seefl{set\_rm\_interrupt}{setrminterrupt},
  1068. \seefl{get\_rm\_interrupt}{getrminterrupt} }
  1069. \latex{\inputlisting{go32ex/int_pm.pp}}
  1070. \html{\input{go32ex/int_pm.tex}}
  1071. \functionl{set\_rm\_interrupt}{setrminterrupt}{(vector : byte; const intaddr :
  1072. tseginfo)}{boolean}
  1073. {Sets a real mode interrupt handler.
  1074. Parameters:
  1075. \begin{description}
  1076. \item[vector:\ ] the interrupt vector number to set.
  1077. \item[intaddr:\ ] address of new interrupt vector.
  1078. \end{description}
  1079. Return values: \var{True} if successful, otherwise \var{False}.
  1080. Notes: The address supplied MUST be a real mode segment address, not a
  1081. \var{selector:offset} address. So the interrupt handler must either reside in \dos
  1082. memory (below 1 Mb boundary) or the application must allocate a real mode
  1083. callback address with \seefl{get\_rm\_callback}{getrmcallback}.
  1084. }
  1085. { Check the \var{int31error} variable.}
  1086. {
  1087. \seefl{get\_rm\_interrupt}{getrminterrupt},
  1088. \seefl{set\_pm\_interrupt}{setpminterrupt}, \seefl{get\_pm\_interrupt}{getpminterrupt},
  1089. \seefl{get\_rm\_callback}{getrmcallback} }
  1090. \functionl{set\_segment\_base\_address}{setsegmentbaseaddress}
  1091. {(d : Word; s : Longint)}{boolean}
  1092. {Sets the 32-bit linear base address of a descriptor.
  1093. Parameters:
  1094. \begin{description}
  1095. \item[d:\ ] selector.
  1096. \item[s:\ ] new base address of the descriptor.
  1097. \end{description}
  1098. }
  1099. { Check the \var{int31error} variable.}
  1100. {
  1101. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors},
  1102. \seefl{get\_segment\_base\_address}{getsegmentbaseaddress},
  1103. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors},
  1104. \seefl{set\_segment\_limit}{setsegmentlimit},
  1105. \seefl{get\_segment\_base\_address}{getsegmentbaseaddress},
  1106. \seefl{get\_segment\_limit}{getsegmentlimit}
  1107. }
  1108. \functionl{set\_segment\_limit}{setsegmentlimit}{(d : Word; s : Longint)}{boolean}
  1109. {Sets the limit of a descriptor.
  1110. Parameters:
  1111. \begin{description}
  1112. \item[d:\ ] selector.
  1113. \item[s:\ ] new limit of the descriptor.
  1114. \end{description}
  1115. Return values: Returns \var{True} if successful, else \var{False}.
  1116. Notes: The new limit specified must be the byte length of the segment - 1.
  1117. Segment limits bigger than or equal to 1MB must be page aligned, they must
  1118. have the lower 12 bits set.
  1119. }
  1120. { Check the \var{int31error} variable.}
  1121. {\seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors},
  1122. \seefl{set\_segment\_base\_address}{setsegmentbaseaddress},
  1123. \seefl{get\_segment\_limit}{getsegmentlimit},
  1124. \seefl{set\_segment\_limit}{setsegmentlimit}
  1125. }
  1126. For an example, see
  1127. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors}.
  1128. \Functionl{tb\_size}{tbsize}{Longint}
  1129. {Returns the size of the pre-allocated \dos memory buffer.
  1130. Parameters: None.
  1131. Return values: The size of the pre-allocated \dos memory buffer.
  1132. Notes:
  1133. This block always seems to be 16k in size, but don't rely on this.
  1134. }
  1135. {None.}
  1136. {\seefl{transfer\_buffer}{transferbuffer}, \seep{copyfromdos}
  1137. \seep{copytodos}}
  1138. \functionl{unlock\_code}{unlockcode}
  1139. {(functionaddr : pointer; size : Longint)}{boolean}
  1140. {Unlocks a memory range which resides in the code segment selector.
  1141. Parameters:
  1142. \begin{description}
  1143. \item[functionaddr:\ ] address of function to be unlocked.
  1144. \item[size:\ ] size bytes to be unlocked.
  1145. \end{description}
  1146. Return value: \var{True} if successful, \var{False} otherwise.
  1147. }{ Check the \var{int31error} variable.}
  1148. {\seefl{unlock\_linear\_region}{unlocklinearregion},
  1149. \seefl{unlock\_data}{unlockdata},
  1150. \seefl{lock\_linear\_region}{locklinearregion},
  1151. \seefl{lock\_data}{lockdata},
  1152. \seefl{lock\_code}{lockcode} }
  1153. For an example, see \seefl{get\_rm\_callback}{getrmcallback}.
  1154. \functionl{unlock\_data}{unlockdata}{(var data; size : Longint)}{boolean}
  1155. {Unlocks a memory range which resides in the data segment selector.
  1156. Paramters:
  1157. \begin{description}
  1158. \item[data:\ ] address of memory to be unlocked.
  1159. \item[size:\ ] size bytes to be unlocked.
  1160. \end{description}
  1161. Return values: \var{True} if successful, \var{False} otherwise.
  1162. }
  1163. { Check the \var{int31error} variable.}
  1164. {\seefl{unlock\_linear\_region}{unlocklinearregion},
  1165. \seefl{unlock\_code}{unlockcode},
  1166. \seefl{lock\_linear\_region}{locklinearregion},
  1167. \seefl{lock\_data}{lockdata},
  1168. \seefl{lock\_code}{lockcode} }
  1169. For an example, see \seefl{get\_rm\_callback}{getrmcallback}.
  1170. \functionl{unlock\_linear\_region}{unlocklinearregion}
  1171. {(linearaddr, size : Longint)}{boolean}
  1172. {Unlocks a previously locked linear region range to allow it to be swapped
  1173. out again if needed.
  1174. Parameters:
  1175. \begin{description}
  1176. \item[linearaddr:\ ] linear address of the memory to be unlocked.
  1177. \item[size:\ ] size bytes to be unlocked.
  1178. \end{description}
  1179. Return values: \var{True} if successful, \var{False} otherwise.
  1180. }
  1181. { Check the \var{int31error} variable.}{
  1182. \seefl{unlock\_data}{unlockdata},
  1183. \seefl{unlock\_code}{unlockcode},
  1184. \seefl{lock\_linear\_region}{locklinearregion},
  1185. \seefl{lock\_data}{lockdata},
  1186. \seefl{lock\_code}{lockcode}}