go32.tex 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613
  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 four sections. The first two sections are an
  7. introduction to the GO32 unit. The third section lists the pre-defined
  8. constants, types and variables. The last 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 go32v2 version 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. Functions that handle hardware
  107. interrupts are called 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{\lstinputlisting{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{\lstinputlisting{go32ex/softint.pp}}
  197. \html{\input{go32ex/softint.tex}}
  198. \latex{\lstinputlisting{go32ex/rmpmint.pp}}
  199. \html{\input{go32ex/rmpmint.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 settings:
  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{FPCtable}{ll}{Record description}
  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{FPCtable}
  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{\lstinputlisting{go32ex/seldes.pp}}
  387. \html{\input{go32ex/seldes.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 can then be used to free the memory block
  402. afterwards or use this handle for other purposes. Since the function isn't
  403. implemented correctly, and doesn't return a blockhandle, the block can't be
  404. deallocated and is hence unusuable !
  405. This function doesn't allocate any descriptors for this block, it's the
  406. applications resposibility to allocate and initialize for accessing this
  407. memory.
  408. \Errors
  409. Check the \var{int31error} variable.
  410. \SeeAlso
  411. \seefl{free\_memory\_block}{freememoryblock}
  412. \end{functionl}
  413. \begin{procedure}{copyfromdos}
  414. \Declaration
  415. Procedure copyfromdos (var addr; len : Longint);
  416. \Description
  417. Copies data from the pre-allocated \dos memory transfer buffer to the heap.
  418. Parameters:
  419. \begin{description}
  420. \item[addr:\ ] data to copy to.
  421. \item[len:\ ] number of bytes to copy to heap.
  422. \end{description}
  423. Notes:
  424. Can only be used in conjunction with the \dos memory transfer buffer.
  425. \Errors
  426. Check the \var{int31error} variable.
  427. \SeeAlso
  428. \seefl{tb\_size}{tbsize}, \seefl{transfer\_buffer}{transferbuffer},
  429. \seep{copytodos}
  430. \end{procedure}
  431. \begin{procedure}{copytodos}
  432. \Declaration
  433. Procedure copytodos (var addr; len : Longint);
  434. \Description
  435. Copies data from heap to the pre-allocated \dos memory buffer.
  436. Parameters:
  437. \begin{description}
  438. \item[addr:\ ] data to copy from.
  439. \item[len:\ ] number of bytes to copy to \dos memory buffer.
  440. \end{description}
  441. Notes: This function fails if you try to copy more bytes than the transfer
  442. buffer is in size. It can only be used in conjunction with the transfer
  443. buffer.
  444. \Errors
  445. Check the \var{int31error} variable.
  446. \SeeAlso
  447. \seefl{tb\_size}{tbsize}, \seefl{transfer\_buffer}{transferbuffer},
  448. \seep{copyfromdos}
  449. \end{procedure}
  450. \begin{functionl}{create\_code\_segment\_alias\_descriptor}{createcodesegmentaliasdescriptor}
  451. \Declaration
  452. Function create\_code\_segment\_alias\_descriptor (seg : Word) : Word;
  453. \Description
  454. Creates a new descriptor that has the same base and limit as the specified
  455. descriptor.
  456. Parameters:
  457. \begin{description}
  458. \item[seg:\ ] Descriptor.
  459. \end{description}
  460. Return values: The data selector (alias).
  461. Notes: In effect, the function returns a copy of the descriptor. The
  462. descriptor alias returned by this function will not track changes to the
  463. original descriptor. In other words, if an alias is created with this
  464. function, and the base or limit of the original segment is then changed, the
  465. two descriptors will no longer map the same memory.
  466. \Errors
  467. Check the \var{int31error} variable.
  468. \SeeAlso
  469. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors},
  470. \seefl{set\_segment\_limit}{setsegmentlimit},
  471. \seefl{set\_segment\_base\_address}{setsegmentbaseaddress}
  472. \end{functionl}
  473. \begin{procedure}{disable}
  474. \Declaration
  475. Procedure disable ;
  476. \Description
  477. Disables all hardware interrupts by execution a CLI instruction.
  478. Parameters: None.
  479. \Errors
  480. None.
  481. \SeeAlso
  482. \seep{enable}
  483. \end{procedure}
  484. \begin{procedure}{dosmemfillchar}
  485. \Declaration
  486. Procedure dosmemfillchar (seg, ofs : Word; count : Longint; c : char);
  487. \Description
  488. Sets a region of \dos memory to a specific byte value.
  489. Parameters:
  490. \begin{description}
  491. \item[seg:\ ] real mode segment.
  492. \item[ofs:\ ] real mode offset.
  493. \item[count:\ ] number of bytes to set.
  494. \item[c:\ ] value to set memory to.
  495. \end{description}
  496. Notes: No range check is performed.
  497. \Errors
  498. None.
  499. \SeeAlso
  500. \seep{dosmemput},
  501. \seep{dosmemget},
  502. \seep{dosmemmove}{dosmemmove},
  503. \seepl{dosmemfillword}{dosmemfillword},
  504. \seepl{seg\_move}{segmove},
  505. \seepl{seg\_fillchar}{segfillchar},
  506. \seepl{seg\_fillword}{segfillword}
  507. \end{procedure}
  508. \latex{\lstinputlisting{go32ex/textmess.pp}}
  509. \html{\input{go32ex/textmess.tex}}
  510. \begin{procedure}{dosmemfillword}
  511. \Declaration
  512. Procedure dosmemfillword (seg,ofs : Word; count : Longint; w : Word);
  513. \Description
  514. Sets a region of \dos memory to a specific word value.
  515. Parameters:
  516. \begin{description}
  517. \item[seg:\ ] real mode segment.
  518. \item[ofs:\ ] real mode offset.
  519. \item[count:\ ] number of words to set.
  520. \item[w:\ ] value to set memory to.
  521. \end{description}
  522. Notes: No range check is performed.
  523. \Errors
  524. None.
  525. \SeeAlso
  526. \seep{dosmemput},
  527. \seepl{dosmemget}{dosmemget},
  528. \seepl{dosmemmove}{dosmemmove},
  529. \seepl{dosmemfillchar}{dosmemfillchar},
  530. \seepl{seg\_move}{segmove},
  531. \seepl{seg\_fillchar}{segfillchar},
  532. \seepl{seg\_fillword}{segfillword}
  533. \end{procedure}
  534. \begin{procedure}{dosmemget}
  535. \Declaration
  536. Procedure dosmemget (seg : Word; ofs : Word; var data; count : Longint);
  537. \Description
  538. Copies data from the \dos memory onto the heap.
  539. Parameters:
  540. \begin{description}
  541. \item[seg:\ ] source real mode segment.
  542. \item[ofs:\ ] source real mode offset.
  543. \item[data:\ ] destination.
  544. \item[count:\ ] number of bytes to copy.
  545. \end{description}
  546. Notes: No range checking is performed.
  547. \Errors
  548. None.
  549. \SeeAlso
  550. \seep{dosmemput},
  551. \seep{dosmemmove},
  552. \seep{dosmemfillchar},
  553. \seep{dosmemfillword},
  554. \seepl{seg\_move}{segmove},
  555. \seepl{seg\_fillchar}{segfillchar},
  556. \seepl{seg\_fillword}{segfillword}
  557. \end{procedure}
  558. For an example, see \seefl{global\_dos\_alloc}{globaldosalloc}.
  559. \begin{procedure}{dosmemmove}
  560. \Declaration
  561. Procedure dosmemmove (sseg, sofs, dseg, dofs : Word; count : Longint);
  562. \Description
  563. Copies count bytes of data between two \dos real mode memory locations.
  564. Parameters:
  565. \begin{description}
  566. \item[sseg:\ ] source real mode segment.
  567. \item[sofs:\ ] source real mode offset.
  568. \item[dseg:\ ] destination real mode segment.
  569. \item[dofs:\ ] destination real mode offset.
  570. \item[count:\ ] number of bytes to copy.
  571. \end{description}
  572. Notes: No range check is performed in any way.
  573. \Errors
  574. None.
  575. \SeeAlso
  576. \seep{dosmemput},
  577. \seep{dosmemget},
  578. \seep{dosmemfillchar},
  579. \seep{dosmemfillword}
  580. \seepl{seg\_move}{segmove},
  581. \seepl{seg\_fillchar}{segfillchar},
  582. \seepl{seg\_fillword}{segfillword}
  583. \end{procedure}
  584. For an example, see \seepl{seg\_fillchar}{segfillchar}.
  585. \begin{procedure}{dosmemput}
  586. \Declaration
  587. Procedure dosmemput (seg : Word; ofs : Word; var data; count : Longint);
  588. \Description
  589. Copies heap data to \dos real mode memory.
  590. Parameters:
  591. \begin{description}
  592. \item[seg:\ ] destination real mode segment.
  593. \item[ofs:\ ] destination real mode offset.
  594. \item[data:\ ] source.
  595. \item[count:\ ] number of bytes to copy.
  596. \end{description}
  597. Notes: No range checking is performed.
  598. \Errors
  599. None.
  600. \SeeAlso
  601. \seep{dosmemget},
  602. \seep{dosmemmove},
  603. \seep{dosmemfillchar},
  604. \seep{dosmemfillword},
  605. \seepl{seg\_move}{segmove},
  606. \seepl{seg\_fillchar}{segfillchar},
  607. \seepl{seg\_fillword}{segfillword}
  608. \end{procedure}
  609. For an example, see \seefl{global\_dos\_alloc}{globaldosalloc}.
  610. \begin{procedure}{enable}
  611. \Declaration
  612. Procedure enable ;
  613. \Description
  614. Enables all hardware interrupts by executing a STI instruction.
  615. Parameters: None.
  616. \Errors
  617. None.
  618. \SeeAlso
  619. \seep{disable}
  620. \end{procedure}
  621. \begin{functionl}{free\_ldt\_descriptor}{freeldtdescriptor}
  622. \Declaration
  623. Function free\_ldt\_descriptor (des : Word) : boolean;
  624. \Description
  625. Frees a previously allocated descriptor.
  626. Parameters:
  627. \begin{description}
  628. \item[des:\ ] The descriptor to be freed.
  629. \end{description}
  630. Return value: \var{True} if successful, \var{False} otherwise.
  631. Notes: After this call this selector is invalid and must not be used for any
  632. memory operations anymore. Each descriptor allocated with
  633. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors} must be freed
  634. individually with this function,
  635. even if it was previously allocated as a part of a contiguous array of
  636. descriptors.
  637. \Errors
  638. Check the \var{int31error} variable.
  639. \SeeAlso
  640. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors},
  641. \seefl{get\_next\_selector\_increment\_value}{getnextselectorincrementvalue}
  642. \end{functionl}
  643. For an example, see
  644. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors}.
  645. \begin{functionl}{free\_memory\_block}{freememoryblock}
  646. \Declaration
  647. Function free\_memory\_block (blockhandle :
  648. Longint) : boolean;
  649. \Description
  650. Frees a previously allocated memory block.
  651. Parameters:
  652. \begin{description}
  653. \item{blockhandle:} the handle to the memory area to free.
  654. \end{description}
  655. Return value: \var{True} if successful, \var{false} otherwise.
  656. Notes: Frees memory that was previously allocated with
  657. \seefl{allocate\_memory\_block}{allocatememoryblock} .
  658. This function doesn't free any descriptors mapped to this block,
  659. it's the application's responsibility.
  660. \Errors
  661. Check \var{int31error} variable.
  662. \SeeAlso
  663. \seefl{allocate\_memory\_block}{allocatememoryblock}
  664. \end{functionl}
  665. \begin{functionl}{free\_rm\_callback}{freermcallback}
  666. \Declaration
  667. Function free\_rm\_callback (var intaddr : tseginfo) : boolean;
  668. \Description
  669. Releases a real mode callback address that was previously allocated with the
  670. \seefl{get\_rm\_callback}{getrmcallback} function.
  671. Parameters:
  672. \begin{description}
  673. \item[intaddr:\ ] real mode address buffer returned by
  674. \seefl{get\_rm\_callback}{getrmcallback} .
  675. \end{description}
  676. Return values: \var{True} if successful, \var{False} if not
  677. \Errors
  678. Check the \var{int31error} variable.
  679. \SeeAlso
  680. \seefl{set\_rm\_interrupt}{setrminterrupt},
  681. \seefl{get\_rm\_callback}{getrmcallback}
  682. \end{functionl}
  683. For an example, see \seefl{get\_rm\_callback}{getrmcallback}.
  684. \begin{functionl}{get\_cs}{getcs}
  685. \Declaration
  686. Function get\_cs : Word;
  687. \Description
  688. Returns the cs selector.
  689. Parameters: None.
  690. Return values: The content of the cs segment register.
  691. \Errors
  692. None.
  693. \SeeAlso
  694. \seefl{get\_ds}{getds}, \seefl{get\_ss}{getss}
  695. \end{functionl}
  696. For an example, see \seefl{set\_pm\_interrupt}{setpminterrupt}.
  697. \begin{functionl}{get\_descriptor\_access\_rights}{getdescriptoraccessrights}
  698. \Declaration
  699. Function get\_descriptor\_access\_rights (d : Word) : Longint;
  700. \Description
  701. Gets the access rights of a descriptor.
  702. Parameters:
  703. \begin{description}
  704. \item{d} selector to descriptor.
  705. \end{description}
  706. Return value: Access rights bit field.
  707. \Errors
  708. Check the \var{int31error} variable.
  709. \SeeAlso
  710. \seefl{set\_descriptor\_access\_rights}{setdescriptoraccessrights}
  711. \end{functionl}
  712. \begin{functionl}{get\_ds}{getds}
  713. \Declaration
  714. Function get\_ds : Word;
  715. \Description
  716. Returns the ds selector.
  717. Parameters: None.
  718. Return values: The content of the ds segment register.
  719. \Errors
  720. None.
  721. \SeeAlso
  722. \seefl{get\_cs}{getcs}, \seefl{get\_ss}{getss}
  723. \end{functionl}
  724. \begin{functionl}{get\_linear\_addr}{getlinearaddr}
  725. \Declaration
  726. Function get\_linear\_addr (phys\_addr : Longint; size : Longint) : Longint;
  727. \Description
  728. Converts a physical address into a linear address.
  729. Parameters:
  730. \begin{description}
  731. \item [phys\_addr:\ ] physical address of device.
  732. \item [size:\ ] Size of region to map in bytes.
  733. \end{description}
  734. Return value: Linear address that can be used to access the physical memory.
  735. Notes: It's the applications resposibility to allocate and set up a
  736. descriptor for access to the memory. This function shouldn't be used to map
  737. real mode addresses.
  738. \Errors
  739. Check the \var{int31error} variable.
  740. \SeeAlso
  741. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors}, \seefl{set\_segment\_limit}{setsegmentlimit},
  742. \seefl{set\_segment\_base\_address}{setsegmentbaseaddress}
  743. \end{functionl}
  744. \begin{functionl}{get\_meminfo}{getmeminfo}
  745. \Declaration
  746. Function get\_meminfo (var meminfo : tmeminfo) : boolean;
  747. \Description
  748. Returns information about the amount of available physical memory, linear
  749. address space, and disk space for page swapping.
  750. Parameters:
  751. \begin{description}
  752. \item[meminfo:\ ] buffer to fill memory information into.
  753. \end{description}
  754. Return values: Due to an implementation bug this function always returns
  755. \var{False}, but it always succeeds.
  756. Notes: Only the first field of the returned structure is guaranteed to
  757. contain a valid value. Any fields that are not supported by the DPMI host
  758. will be set by the host to \var{-1 (0FFFFFFFFH)} to indicate that the information
  759. is not available. The size of the pages used by the DPMI host can be
  760. obtained with the \seefl{get\_page\_size}{getpagesize} function.
  761. \Errors
  762. Check the \var{int31error} variable.
  763. \SeeAlso
  764. \seefl{get\_page\_size}{getpagesize}
  765. \end{functionl}
  766. \latex{\lstinputlisting{go32ex/meminfo.pp}}
  767. \html{\input{go32ex/meminfo.tex}}
  768. \begin{functionl}{get\_next\_selector\_increment\_value}{getnextselectorincrementvalue}
  769. \Declaration
  770. Function get\_next\_selector\_increment\_value : Word;
  771. \Description
  772. Returns the selector increment value when allocating multiple subsequent
  773. descriptors via \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors}.
  774. Parameters: None.
  775. Return value: Selector increment value.
  776. Notes: Because \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors} only returns the selector for the
  777. first descriptor and so the value returned by this function can be used to
  778. calculate the selectors for subsequent descriptors in the array.
  779. \Errors
  780. Check the \var{int31error} variable.
  781. \SeeAlso
  782. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors},
  783. \seefl{free\_ldt\_descriptor}{freeldtdescriptor}
  784. \end{functionl}
  785. \begin{functionl}{get\_page\_size}{getpagesize}
  786. \Declaration
  787. Function get\_page\_size : Longint;
  788. \Description
  789. Returns the size of a single memory page.
  790. Return value: Size of a single page in bytes.
  791. Notes: The returned size is typically 4096 bytes.
  792. \Errors
  793. Check the \var{int31error} variable.
  794. \SeeAlso
  795. \seefl{get\_meminfo}{getmeminfo}
  796. \end{functionl}
  797. For an example, see \seefl{get\_meminfo}{getmeminfo}.
  798. \begin{functionl}{get\_pm\_interrupt}{getpminterrupt}
  799. \Declaration
  800. Function get\_pm\_interrupt (vector : byte; var intaddr : tseginfo) : boolean;
  801. \Description
  802. Returns the address of a current protected mode interrupt handler.
  803. Parameters:
  804. \begin{description}
  805. \item[vector:\ ] interrupt handler number you want the address to.
  806. \item[intaddr:\ ] buffer to store address.
  807. \end{description}
  808. Return values: \var{True} if successful, \var{False} if not.
  809. Notes: The returned address is a protected mode selector:offset address.
  810. \Errors
  811. Check the \var{int31error} variable.
  812. \SeeAlso
  813. \seefl{set\_pm\_interrupt}{setpminterrupt},
  814. \seefl{set\_rm\_interrupt}{setrminterrupt}, \seefl{get\_rm\_interrupt}{getrminterrupt}
  815. \end{functionl}
  816. For an example, see \seefl{set\_pm\_interrupt}{setpminterrupt}.
  817. \begin{functionl}{get\_rm\_callback}{getrmcallback}
  818. \Declaration
  819. Function get\_rm\_callback (pm\_func : pointer; const reg : trealregs; var rmcb: tseginfo) : boolean;
  820. \Description
  821. Returns a unique real mode \var{segment:offset} address, known as a "real mode
  822. callback," that will transfer control from real mode to a protected mode
  823. procedure.
  824. Parameters:
  825. \begin{description}
  826. \item[pm\_func:\ ] pointer to the protected mode callback function.
  827. \item[reg:\ ] supplied registers structure.
  828. \item[rmcb:\ ] buffer to real mode address of callback function.
  829. \end{description}
  830. Return values: \var{True} if successful, otherwise \var{False}.
  831. Notes: Callback addresses obtained with this function can be passed by a
  832. protected mode program for example to an interrupt handler, device driver,
  833. or TSR, so that the real mode program can call procedures within the
  834. protected mode program or notify the protected mode program of an event. The
  835. contents of the supplied regs structure is not valid after function call,
  836. but only at the time of the actual callback.
  837. \Errors
  838. Check the \var{int31error} variable.
  839. \SeeAlso
  840. \seefl{free\_rm\_callback}{freermcallback}
  841. \end{functionl}
  842. \latex{\lstinputlisting{go32ex/callback.pp}}
  843. \html{\input{go32ex/callback.tex}}
  844. \begin{functionl}{get\_rm\_interrupt}{getrminterrupt}
  845. \Declaration
  846. Function get\_rm\_interrupt (vector : byte; var intaddr :
  847. tseginfo) : boolean;
  848. \Description
  849. Returns the contents of the current machine's real mode interrupt vector for
  850. the specified interrupt.
  851. Parameters:
  852. \begin{description}
  853. \item[vector:\ ] interrupt vector number.
  854. \item[intaddr:\ ] buffer to store real mode \var{segment:offset} address.
  855. \end{description}
  856. Return values: \var{True} if successful, \var{False} otherwise.
  857. Notes: The returned address is a real mode segment address, which isn't
  858. valid in protected mode.
  859. \Errors
  860. Check the \var{int31error} variable.
  861. \SeeAlso
  862. \seefl{set\_rm\_interrupt}{setrminterrupt},
  863. \seefl{set\_pm\_interrupt}{setpminterrupt},
  864. \seefl{get\_pm\_interrupt}{getpminterrupt}
  865. \end{functionl}
  866. \begin{functionl}{get\_run\_mode}{getrunmode}
  867. \Declaration
  868. Function get\_run\_mode : Word;
  869. \Description
  870. Returns the current mode your application runs with.
  871. Return values: One of the constants used by this function.
  872. \Errors
  873. None.
  874. \SeeAlso
  875. constants returned by \seefl{get\_run\_mode}{getrunmode}
  876. \end{functionl}
  877. \latex{\lstinputlisting{go32ex/getrunmd.pp}}
  878. \html{\input{go32ex/getrunmd.tex}}
  879. \begin{functionl}{get\_segment\_base\_address}{getsegmentbaseaddress}
  880. \Declaration
  881. Function get\_segment\_base\_address
  882. (d : Word) : Longint;
  883. \Description
  884. Returns the 32-bit linear base address from the descriptor table for the
  885. specified segment.
  886. Parameters:
  887. \begin{description}
  888. \item[d:\ ] selector of the descriptor you want the base address of.
  889. \end{description}
  890. Return values: Linear base address of specified descriptor.
  891. \Errors
  892. Check the \var{int31error} variable.
  893. \SeeAlso
  894. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors},
  895. \seefl{set\_segment\_base\_address}{setsegmentbaseaddress},
  896. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors},
  897. \seefl{set\_segment\_limit}{setsegmentlimit},
  898. \seefl{get\_segment\_limit}{getsegmentlimit}
  899. \end{functionl}
  900. For an example, see
  901. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors}.
  902. \begin{functionl}{get\_segment\_limit}{getsegmentlimit}
  903. \Declaration
  904. Function get\_segment\_limit (d : Word) : Longint;
  905. \Description
  906. Returns a descriptors segment limit.
  907. Parameters:
  908. \begin{description}
  909. \item [d:\ ] selector.
  910. \end{description}
  911. Return value: Limit of the descriptor in bytes.
  912. \Errors
  913. Returns zero if descriptor is invalid.
  914. \SeeAlso
  915. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors},
  916. \seefl{set\_segment\_limit}{setsegmentlimit},
  917. \seefl{set\_segment\_base\_address}{setsegmentbaseaddress},
  918. \seefl{get\_segment\_base\_address}{getsegmentbaseaddress},
  919. \end{functionl}
  920. \begin{functionl}{get\_ss}{getss}
  921. \Declaration
  922. Function get\_ss : Word;
  923. \Description
  924. Returns the ss selector.
  925. Parameters: None.
  926. Return values: The content of the ss segment register.
  927. \Errors
  928. None.
  929. \SeeAlso
  930. \seefl{get\_ds}{getds}, \seefl{get\_cs}{getcs}
  931. \end{functionl}
  932. \begin{functionl}{global\_dos\_alloc}{globaldosalloc}
  933. \Declaration
  934. Function global\_dos\_alloc (bytes : Longint) : Longint;
  935. \Description
  936. Allocates a block of \dos real mode memory.
  937. Parameters:
  938. \begin{description}
  939. \item [bytes:\ ] size of requested real mode memory.
  940. \end{description}
  941. Return values: The low word of the returned value contains the selector to
  942. the allocated \dos memory block, the high word the corresponding real mode
  943. segment value. The offset value is always zero.
  944. This function allocates memory from \dos memory pool, i.e. memory below the 1
  945. MB boundary that is controlled by \dos. Such memory blocks are typically used
  946. to exchange data with real mode programs, TSRs, or device drivers. The
  947. function returns both the real mode segment base address of the block and
  948. one descriptor that can be used by protected mode applications to access the
  949. block. This function should only used for temporary buffers to get real mode
  950. information (e.g. interrupts that need a data structure in ES:(E)DI),
  951. because every single block needs an unique selector. The returned selector
  952. should only be freed by a \seefl{global\_dos\_free}{globaldosfree} call.
  953. \Errors
  954. Check the \var{int31error} variable.
  955. \SeeAlso
  956. \seefl{global\_dos\_free}{globaldosfree}
  957. \end{functionl}
  958. \latex{\lstinputlisting{go32ex/buffer.pp}}
  959. \html{\input{go32ex/buffer.tex}}
  960. \begin{functionl}{global\_dos\_free}{globaldosfree}
  961. \Declaration
  962. Function global\_dos\_free (selector :Word) : boolean;
  963. \Description
  964. Frees a previously allocated \dos memory block.
  965. Parameters:
  966. \begin{description}
  967. \item[selector:\ ] selector to the \dos memory block.
  968. \end{description}
  969. Return value: \var{True} if successful, \var{False} otherwise.
  970. Notes: The descriptor allocated for the memory block is automatically freed
  971. and hence invalid for further use. This function should only be used for
  972. memory allocated by \seefl{global\_dos\_alloc}{globaldosalloc}.
  973. \Errors
  974. Check the \var{int31error} variable.
  975. \SeeAlso
  976. \seefl{global\_dos\_alloc}{globaldosalloc}
  977. \end{functionl}
  978. For an example, see \seefl{global\_dos\_alloc}{globaldosalloc}.
  979. \begin{function}{inportb}
  980. \Declaration
  981. Function inportb (port : Word) : byte;
  982. \Description
  983. Reads 1 byte from the selected I/O port.
  984. Parameters:
  985. \begin{description}
  986. \item[port:\ ] the I/O port number which is read.
  987. \end{description}
  988. Return values: Current I/O port value.
  989. \Errors
  990. None.
  991. \SeeAlso
  992. \seep{outportb}, \seef{inportw}, \seef{inportl}
  993. \end{function}
  994. \begin{function}{inportl}
  995. \Declaration
  996. Function inportl (port : Word) : Longint;
  997. \Description
  998. Reads 1 longint from the selected I/O port.
  999. Parameters:
  1000. \begin{description}
  1001. \item[port:\ ] the I/O port number which is read.
  1002. \end{description}
  1003. Return values: Current I/O port value.
  1004. \Errors
  1005. None.
  1006. \SeeAlso
  1007. \seep{outportb}, \seef{inportb}, \seef{inportw}
  1008. \end{function}
  1009. \begin{function}{inportw}
  1010. \Declaration
  1011. Function inportw (port : Word) : Word;
  1012. \Description
  1013. Reads 1 word from the selected I/O port.
  1014. Parameters:
  1015. \begin{description}
  1016. \item[port:\ ] the I/O port number which is read.
  1017. \end{description}
  1018. Return values: Current I/O port value.
  1019. \Errors
  1020. None.
  1021. \SeeAlso
  1022. \seep{outportw} \seef{inportb}, \seef{inportl}
  1023. \end{function}
  1024. \begin{functionl}{lock\_code}{lockcode}
  1025. \Declaration
  1026. Function lock\_code (functionaddr : pointer; size : Longint) : boolean;
  1027. \Description
  1028. Locks a memory range which is in the code segment selector.
  1029. Parameters:
  1030. \begin{description}
  1031. \item[functionaddr:\ ] address of the function to be locked.
  1032. \item[size:\ ] size in bytes to be locked.
  1033. \end{description}
  1034. Return values: \var{True} if successful, \var{False} otherwise.
  1035. \Errors
  1036. Check the \var{int31error} variable.
  1037. \SeeAlso
  1038. \seefl{lock\_linear\_region}{locklinearregion},
  1039. \seefl{lock\_data}{lockdata},
  1040. \seefl{unlock\_linear\_region}{unlocklinearregion},
  1041. \seefl{unlock\_data}{unlockdata},
  1042. \seefl{unlock\_code}{unlockcode}
  1043. \end{functionl}
  1044. For an example, see \seefl{get\_rm\_callback}{getrmcallback}.
  1045. \begin{functionl}{lock\_data}{lockdata}
  1046. \Declaration
  1047. Function lock\_data (var data; size : Longint) : boolean;
  1048. \Description
  1049. Locks a memory range which resides in the data segment selector.
  1050. Parameters:
  1051. \begin{description}
  1052. \item[data:\ ] address of data to be locked.
  1053. \item[size:\ ] length of data to be locked.
  1054. \end{description}
  1055. Return values: \var{True} if successful, \var{False} otherwise.
  1056. \Errors
  1057. Check the \var{int31error} variable.
  1058. \SeeAlso
  1059. \seefl{lock\_linear\_region}{locklinearregion},
  1060. \seefl{lock\_code}{lockcode},
  1061. \seefl{unlock\_linear\_region}{unlocklinearregion},
  1062. \seefl{unlock\_data}{unlockdata},
  1063. \seefl{unlock\_code}{unlockcode}
  1064. \end{functionl}
  1065. For an example, see \seefl{get\_rm\_callback}{getrmcallback}.
  1066. \begin{functionl}{lock\_linear\_region}{locklinearregion}
  1067. \Declaration
  1068. Function lock\_linear\_region (linearaddr, size : Longint) : boolean;
  1069. \Description
  1070. Locks a memory region to prevent swapping of it.
  1071. Parameters:
  1072. \begin{description}
  1073. \item[linearaddr:\ ] the linear address of the memory are to be locked.
  1074. \item[size:\ ] size in bytes to be locked.
  1075. \end{description}
  1076. Return value: \var{True} if successful, False otherwise.
  1077. \Errors
  1078. Check the \var{int31error} variable.
  1079. \SeeAlso
  1080. \seefl{lock\_data}{lockdata},
  1081. \seefl{lock\_code}{lockcode},
  1082. \seefl{unlock\_linear\_region}{unlocklinearregion},
  1083. \seefl{unlock\_data}{unlockdata},
  1084. \seefl{unlock\_code}{unlockcode}
  1085. \end{functionl}
  1086. \begin{procedure}{outportb}
  1087. \Declaration
  1088. Procedure outportb (port : Word; data : byte);
  1089. \Description
  1090. Sends 1 byte of data to the specified I/O port.
  1091. Parameters:
  1092. \begin{description}
  1093. \item[port:\ ] the I/O port number to send data to.
  1094. \item[data:\ ] value sent to I/O port.
  1095. \end{description}
  1096. Return values: None.
  1097. \Errors
  1098. None.
  1099. \SeeAlso
  1100. \seef{inportb}, \seep{outportl}, \seep{outportw}
  1101. \end{procedure}
  1102. \latex{\lstinputlisting{go32ex/outport.pp}}
  1103. \html{\input{go32ex/outport.tex}}
  1104. \begin{procedure}{outportl}
  1105. \Declaration
  1106. Procedure outportl (port : Word; data : Longint);
  1107. \Description
  1108. Sends 1 longint of data to the specified I/O port.
  1109. Parameters:
  1110. \begin{description}
  1111. \item[port:\ ] the I/O port number to send data to.
  1112. \item[data:\ ] value sent to I/O port.
  1113. \end{description}
  1114. Return values: None.
  1115. \Errors
  1116. None.
  1117. \SeeAlso
  1118. \seef{inportl}, \seep{outportw}, \seep{outportb}
  1119. \end{procedure}
  1120. For an example, see \seep{outportb}.
  1121. \begin{procedure}{outportw}
  1122. \Declaration
  1123. Procedure outportw (port : Word; data : Word);
  1124. \Description
  1125. Sends 1 word of data to the specified I/O port.
  1126. Parameters:
  1127. \begin{description}
  1128. \item[port:\ ] the I/O port number to send data to.
  1129. \item[data:\ ] value sent to I/O port.
  1130. \end{description}
  1131. Return values: None.
  1132. \Errors
  1133. None.
  1134. \SeeAlso
  1135. \seef{inportw}, \seep{outportl}, \seep{outportb}
  1136. \end{procedure}
  1137. For an example, see \seep{outportb}.
  1138. \begin{function}{realintr}
  1139. \Declaration
  1140. Function realintr (intnr: Word; var regs : trealregs) : boolean;
  1141. \Description
  1142. Simulates an interrupt in real mode.
  1143. Parameters:
  1144. \begin{description}
  1145. \item[intnr:\ ] interrupt number to issue in real mode.
  1146. \item[regs:\ ] registers data structure.
  1147. \end{description}
  1148. Return values: The supplied registers data structure contains the values
  1149. that were returned by the real mode interrupt. \var{True} if successful, \var{False} if
  1150. not.
  1151. Notes: The function transfers control to the address specified by the real
  1152. mode interrupt vector of intnr. The real mode handler must return by
  1153. executing an IRET.
  1154. \Errors
  1155. Check the \var{int31error} variable.
  1156. \SeeAlso
  1157. \end{function}
  1158. \latex{\lstinputlisting{go32ex/flags.pp}}
  1159. \html{\input{go32ex/flags.tex}}
  1160. \begin{procedurel}{seg\_fillchar}{segfillchar}
  1161. \Declaration
  1162. Procedure seg\_fillchar (seg : Word; ofs : Longint; count : Longint; c : char);
  1163. \Description
  1164. Sets a memory area to a specific value.
  1165. Parameters:
  1166. \begin{description}
  1167. \item[seg:\ ] selector to memory area.
  1168. \item[ofs:\ ] offset to memory.
  1169. \item[count:\ ] number of bytes to set.
  1170. \item[c:\ ] byte data which is set.
  1171. \end{description}
  1172. Return values: None.
  1173. Notes: No range check is done in any way.
  1174. \Errors
  1175. None.
  1176. \SeeAlso
  1177. \seepl{seg\_move}{segmove},
  1178. \seepl{seg\_fillword}{segfillword},
  1179. \seepl{dosmemfillchar}{dosmemfillchar},
  1180. \seepl{dosmemfillword}{dosmemfillword},
  1181. \seepl{dosmemget}{dosmemget},
  1182. \seepl{dosmemput}{dosmemput},
  1183. \seepl{dosmemmove}{dosmemmove}
  1184. \end{procedurel}
  1185. \latex{\lstinputlisting{go32ex/vgasel.pp}}
  1186. \html{\input{go32ex/vgasel.tex}}
  1187. \begin{procedurel}{seg\_fillword}{segfillword}
  1188. \Declaration
  1189. Procedure seg\_fillword (seg : Word; ofs : Longint; count : Longint; w :Word);
  1190. \Description
  1191. Sets a memory area to a specific value.
  1192. Parameters:
  1193. \begin{description}
  1194. \item[seg:\ ] selector to memory area.
  1195. \item[ofs:\ ] offset to memory.
  1196. \item[count:\ ] number of words to set.
  1197. \item[w:\ ] word data which is set.
  1198. \end{description}
  1199. Return values: None.
  1200. Notes: No range check is done in any way.
  1201. \Errors
  1202. None.
  1203. \SeeAlso
  1204. \seepl{seg\_move}{segmove},
  1205. \seepl{seg\_fillchar}{segfillchar},
  1206. \seepl{dosmemfillchar}{dosmemfillchar},
  1207. \seepl{dosmemfillword}{dosmemfillword},
  1208. \seepl{dosmemget}{dosmemget},
  1209. \seepl{dosmemput}{dosmemput},
  1210. \seepl{dosmemmove}{dosmemmove}
  1211. \end{procedurel}
  1212. For an example, see
  1213. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors}.
  1214. \begin{functionl}{segment\_to\_descriptor}{segmenttodescriptor}
  1215. \Declaration
  1216. Function segment\_to\_descriptor (seg : Word) : Word;
  1217. \Description
  1218. Maps a real mode segment (paragraph) address onto an descriptor that can be
  1219. used by a protected mode program to access the same memory.
  1220. Parameters:
  1221. \begin{description}
  1222. \item [seg:\ ] the real mode segment you want the descriptor to.
  1223. \end{description}
  1224. Return values: Descriptor to real mode segment address.
  1225. Notes: The returned descriptors limit will be set to 64 kB. Multiple calls
  1226. to this function with the same segment address will return the same
  1227. selector. Descriptors created by this function can never be modified or
  1228. freed. Programs which need to examine various real mode addresses using the
  1229. same selector should use the function
  1230. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors} and change
  1231. the base address as necessary.
  1232. \Errors
  1233. Check the \var{int31error} variable.
  1234. \SeeAlso
  1235. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors},
  1236. \seefl{free\_ldt\_descriptor}{freeldtdescriptor},
  1237. \seefl{set\_segment\_base\_address}{setsegmentbaseaddress}
  1238. \end{functionl}
  1239. For an example, see \seepl{seg\_fillchar}{segfillchar}.
  1240. \begin{procedurel}{seg\_move}{segmove}
  1241. \Declaration
  1242. Procedure seg\_move (sseg : Word; source : Longint; dseg : Word; dest :
  1243. Longint; count : Longint);
  1244. \Description
  1245. Copies data between two memory locations.
  1246. Parameters:
  1247. \begin{description}
  1248. \item[sseg:\ ] source selector.
  1249. \item[source:\ ] source offset.
  1250. \item[dseg:\ ] destination selector.
  1251. \item[dest:\ ] destination offset.
  1252. \item[count:\ ] size in bytes to copy.
  1253. \end{description}
  1254. Return values: None.
  1255. Notes: Overlapping is only checked if the source selector is equal to the
  1256. destination selector. No range check is done.
  1257. \Errors
  1258. None.
  1259. \SeeAlso
  1260. \seepl{seg\_fillchar}{segfillchar},
  1261. \seepl{seg\_fillword}{segfillword},
  1262. \seepl{dosmemfillchar}{dosmemfillchar},
  1263. \seepl{dosmemfillword}{dosmemfillword},
  1264. \seepl{dosmemget}{dosmemget},
  1265. \seepl{dosmemput}{dosmemput},
  1266. \seepl{dosmemmove}{dosmemmove}
  1267. \end{procedurel}
  1268. For an example, see
  1269. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors}.
  1270. \begin{functionl}{set\_descriptor\_access\_rights}{setdescriptoraccessrights}
  1271. \Declaration
  1272. Function set\_descriptor\_access\_rights (d : Word; w : Word) : Longint;
  1273. \Description
  1274. Sets the access rights of a descriptor.
  1275. Parameters:
  1276. \begin{description}
  1277. \item[d:\ ] selector.
  1278. \item[w:\ ] new descriptor access rights.
  1279. \end{description}
  1280. Return values: This function doesn't return anything useful.
  1281. \Errors
  1282. Check the \var{int31error} variable.
  1283. \SeeAlso
  1284. \seefl{get\_descriptor\_access\_rights}{getdescriptoraccessrights}
  1285. \end{functionl}
  1286. \begin{functionl}{set\_pm\_interrupt}{setpminterrupt}
  1287. \Declaration
  1288. Function set\_pm\_interrupt (vector : byte; const intaddr : tseginfo) : boolean;
  1289. \Description
  1290. Sets the address of the protected mode handler for an interrupt.
  1291. Parameters:
  1292. \begin{description}
  1293. \item[vector:\ ] number of protected mode interrupt to set.
  1294. \item[intaddr:\ ] selector:offset address to the interrupt vector.
  1295. \end{description}
  1296. Return values: \var{True} if successful, \var{False} otherwise.
  1297. Notes: The address supplied must be a valid \var{selector:offset}
  1298. protected mode address.
  1299. \Errors
  1300. Check the \var{int31error} variable.
  1301. \SeeAlso
  1302. \seefl{get\_pm\_interrupt}{getpminterrupt},
  1303. \seefl{set\_rm\_interrupt}{setrminterrupt},
  1304. \seefl{get\_rm\_interrupt}{getrminterrupt}
  1305. \end{functionl}
  1306. \latex{\lstinputlisting{go32ex/intpm.pp}}
  1307. \html{\input{go32ex/intpm.tex}}
  1308. \begin{functionl}{set\_rm\_interrupt}{setrminterrupt}
  1309. \Declaration
  1310. Function set\_rm\_interrupt (vector : byte; const intaddr :
  1311. tseginfo) : boolean;
  1312. \Description
  1313. Sets a real mode interrupt handler.
  1314. Parameters:
  1315. \begin{description}
  1316. \item[vector:\ ] the interrupt vector number to set.
  1317. \item[intaddr:\ ] address of new interrupt vector.
  1318. \end{description}
  1319. Return values: \var{True} if successful, otherwise \var{False}.
  1320. Notes: The address supplied MUST be a real mode segment address, not a
  1321. \var{selector:offset} address. So the interrupt handler must either reside in \dos
  1322. memory (below 1 Mb boundary) or the application must allocate a real mode
  1323. callback address with \seefl{get\_rm\_callback}{getrmcallback}.
  1324. \Errors
  1325. Check the \var{int31error} variable.
  1326. \SeeAlso
  1327. \seefl{get\_rm\_interrupt}{getrminterrupt},
  1328. \seefl{set\_pm\_interrupt}{setpminterrupt}, \seefl{get\_pm\_interrupt}{getpminterrupt},
  1329. \seefl{get\_rm\_callback}{getrmcallback}
  1330. \end{functionl}
  1331. \begin{functionl}{set\_segment\_base\_address}{setsegmentbaseaddress}
  1332. \Declaration
  1333. Function set\_segment\_base\_address (d : Word; s : Longint) : boolean;
  1334. \Description
  1335. Sets the 32-bit linear base address of a descriptor.
  1336. Parameters:
  1337. \begin{description}
  1338. \item[d:\ ] selector.
  1339. \item[s:\ ] new base address of the descriptor.
  1340. \end{description}
  1341. \Errors
  1342. Check the \var{int31error} variable.
  1343. \SeeAlso
  1344. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors},
  1345. \seefl{get\_segment\_base\_address}{getsegmentbaseaddress},
  1346. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors},
  1347. \seefl{set\_segment\_limit}{setsegmentlimit},
  1348. \seefl{get\_segment\_base\_address}{getsegmentbaseaddress},
  1349. \seefl{get\_segment\_limit}{getsegmentlimit}
  1350. \end{functionl}
  1351. \begin{functionl}{set\_segment\_limit}{setsegmentlimit}
  1352. \Declaration
  1353. Function set\_segment\_limit (d : Word; s : Longint) : boolean;
  1354. \Description
  1355. Sets the limit of a descriptor.
  1356. Parameters:
  1357. \begin{description}
  1358. \item[d:\ ] selector.
  1359. \item[s:\ ] new limit of the descriptor.
  1360. \end{description}
  1361. Return values: Returns \var{True} if successful, else \var{False}.
  1362. Notes: The new limit specified must be the byte length of the segment - 1.
  1363. Segment limits bigger than or equal to 1MB must be page aligned, they must
  1364. have the lower 12 bits set.
  1365. \Errors
  1366. Check the \var{int31error} variable.
  1367. \SeeAlso
  1368. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors},
  1369. \seefl{set\_segment\_base\_address}{setsegmentbaseaddress},
  1370. \seefl{get\_segment\_limit}{getsegmentlimit},
  1371. \seefl{set\_segment\_limit}{setsegmentlimit}
  1372. \end{functionl}
  1373. For an example, see
  1374. \seefl{allocate\_ldt\_descriptors}{allocateldtdescriptors}.
  1375. \begin{functionl}{tb\_size}{tbsize}
  1376. \Declaration
  1377. Function tb\_size : Longint;
  1378. \Description
  1379. Returns the size of the pre-allocated \dos memory buffer.
  1380. Parameters: None.
  1381. Return values: The size of the pre-allocated \dos memory buffer.
  1382. Notes:
  1383. This block always seems to be 16k in size, but don't rely on this.
  1384. \Errors
  1385. None.
  1386. \SeeAlso
  1387. \seefl{transfer\_buffer}{transferbuffer}, \seep{copyfromdos}
  1388. \seep{copytodos}
  1389. \end{functionl}
  1390. \begin{functionl}{transfer\_buffer}{transferbuffer}
  1391. \Declaration
  1392. Function transfer\_buffer : Longint;
  1393. \Description
  1394. \var{transfer\_buffer} returns the offset of the transfer buffer.
  1395. \Errors
  1396. None.
  1397. \SeeAlso
  1398. \seefl{tb\_size}{tbsize}
  1399. \end{functionl}
  1400. \begin{functionl}{unlock\_code}{unlockcode}
  1401. \Declaration
  1402. Function unlock\_code (functionaddr : pointer; size : Longint) : boolean;
  1403. \Description
  1404. Unlocks a memory range which resides in the code segment selector.
  1405. Parameters:
  1406. \begin{description}
  1407. \item[functionaddr:\ ] address of function to be unlocked.
  1408. \item[size:\ ] size bytes to be unlocked.
  1409. \end{description}
  1410. Return value: \var{True} if successful, \var{False} otherwise.
  1411. \Errors
  1412. Check the \var{int31error} variable.
  1413. \SeeAlso
  1414. \seefl{unlock\_linear\_region}{unlocklinearregion},
  1415. \seefl{unlock\_data}{unlockdata},
  1416. \seefl{lock\_linear\_region}{locklinearregion},
  1417. \seefl{lock\_data}{lockdata},
  1418. \seefl{lock\_code}{lockcode}
  1419. \end{functionl}
  1420. For an example, see \seefl{get\_rm\_callback}{getrmcallback}.
  1421. \begin{functionl}{unlock\_data}{unlockdata}
  1422. \Declaration
  1423. Function unlock\_data (var data; size : Longint) : boolean;
  1424. \Description
  1425. Unlocks a memory range which resides in the data segment selector.
  1426. Paramters:
  1427. \begin{description}
  1428. \item[data:\ ] address of memory to be unlocked.
  1429. \item[size:\ ] size bytes to be unlocked.
  1430. \end{description}
  1431. Return values: \var{True} if successful, \var{False} otherwise.
  1432. \Errors
  1433. Check the \var{int31error} variable.
  1434. \SeeAlso
  1435. \seefl{unlock\_linear\_region}{unlocklinearregion},
  1436. \seefl{unlock\_code}{unlockcode},
  1437. \seefl{lock\_linear\_region}{locklinearregion},
  1438. \seefl{lock\_data}{lockdata},
  1439. \seefl{lock\_code}{lockcode}
  1440. \end{functionl}
  1441. For an example, see \seefl{get\_rm\_callback}{getrmcallback}.
  1442. \begin{functionl}{unlock\_linear\_region}{unlocklinearregion}
  1443. \Declaration
  1444. Function unlock\_linear\_region (linearaddr, size : Longint) : boolean;
  1445. \Description
  1446. Unlocks a previously locked linear region range to allow it to be swapped
  1447. out again if needed.
  1448. Parameters:
  1449. \begin{description}
  1450. \item[linearaddr:\ ] linear address of the memory to be unlocked.
  1451. \item[size:\ ] size bytes to be unlocked.
  1452. \end{description}
  1453. Return values: \var{True} if successful, \var{False} otherwise.
  1454. \Errors
  1455. Check the \var{int31error} variable.
  1456. \SeeAlso
  1457. \seefl{unlock\_data}{unlockdata},
  1458. \seefl{unlock\_code}{unlockcode},
  1459. \seefl{lock\_linear\_region}{locklinearregion},
  1460. \seefl{lock\_data}{lockdata},
  1461. \seefl{lock\_code}{lockcode}
  1462. \end{functionl}