go32.tex 55 KB

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