go32.tex 51 KB

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