home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR13 / DOS32V12.ZIP / DOS32.DOC < prev    next >
Text File  |  1993-10-22  |  11KB  |  312 lines

  1.                      DOS32  V1.2
  2.                                      Copyright  Adam Seychell   Oct\1993
  3.  
  4.  
  5.            A 386 32 bit dos extender for Assembly Programmers.
  6.  
  7.      Written By Adam Seychell.    (5 / SEP / 1993)
  8.  
  9.      email s921880@minyos.xx.rmit.oz.au
  10.  
  11.  
  12.  
  13.   Copying.
  14.  
  15.    Feel free to copy and distribute this program.
  16.     Use it in your programs any way you wish. I am
  17.     distributing this to get people more familiar with
  18.     protected mode programming.
  19.    However if you use this software I require that you
  20.     credit me for its use. Also if you write anything great
  21.     I would appreciate if you could send me a copy of it.
  22.     I have spent a lot of hours writting this DOS extender.
  23.  
  24.  
  25.           *********     FEATURES     **********
  26.  
  27.      * Supports DPMI        ( windows and OS/2 compatibility !!! )
  28.  
  29.      * Supports XMS
  30.  
  31.      * Supports No memory mangers    ( most powerful )
  32.  
  33.      * Data segment descriptors for
  34.                          2. A Flat memory model.
  35.                          3. Conventional memoryn block.
  36.                          4. An allocated extended memory block
  37.                               ( size is defined by you).
  38.  
  39.      * All selector values are stored in the code segment.
  40.  
  41.      * Functions to set/get protected mode interrupt
  42.           descriptor vectors.
  43.  
  44.      * Calling real mode interrupts is nearly as easy as
  45.      calling in real mode itself. Switches to V86 mode when
  46.      called.
  47.  
  48.      * Supports the SYSTEM BIOS COPY EXTENDED MEMORY BLOCK
  49.      function INT 15h, AH = 87h for real mode. So a real
  50.      mode TSR that calls this BIOS function (eg. HIMEM.SYS )
  51.      will be emulated the dos extender. This allows TSRs like
  52.      disk caches and ram drives to be running.
  53.  
  54.  
  55.  
  56.  
  57.  Introduction.
  58.  
  59.            DOS32.ASM is a 386 protected mode initialise
  60. program. The purpose of it is to make protected mode
  61. programming very easy. When I was writing DOS32.ASM my aim was
  62. to use full 32bit power of the 386 while making it as easy as
  63. possible to program.
  64.            The DOS32.ASM is meant to be assembled as an object
  65. file and then linked to you assembler program. You ASM file
  66. must follow the following rules. I tried to make this
  67. simple as possible.
  68.  
  69.  
  70.      * The segment of your 32 bit program must be named CODE32
  71.      * Pass V86 mode segment registers in the program segment.
  72.            ( see below for details)
  73.      * Must have a starting point called "START32:" in your
  74.           program segment.
  75.      * Requires you to load valid selectors in ES,GS,FS,SS,DS and
  76.      set the stack pointer ( ESP ). 
  77.      * Must terminate the program with INT 21h, AH = 4Ch.
  78.      * Requires a small include file to setup macros,
  79.      structures ect.
  80.  
  81.  
  82.    ****  DETAILS ON WHAT DOS32 DOES.  *****
  83.  
  84.   DOS32.ASM basicly contains code to set up segment descriptors
  85. in the LDT or GDT, enter/exit protected mode, allocated/free a
  86. extended memory block and call real mode interrupts. These
  87. parts of the DOS32.ASM will never have to be called directly
  88. form your program.
  89.  
  90. Your programs code and data segment descriptors have the same 
  91. base addresses. This base address in equal to the address of 
  92. the CODE32 segment. It is easier to program with only a single 
  93. code and data segment area.  The stack can be anywhere you 
  94. want it to be.
  95.  
  96.  
  97.                    DOS32  SERVICES
  98.  
  99. Note. If operating under DPMI then all DPMI services will be
  100. available.
  101.  
  102.  When not operating under DPMI there are two services in the
  103. dos extender to set and get the protected mode interrupt
  104. vectors. These will work exactly the same as the real DPMI services. 
  105.  
  106.  SET interrupt
  107.      ax  = 204h
  108.      bl  = interrupt number
  109.      edx = offset
  110.      cx  = selector
  111.      int 31h
  112.   returns:      carry set on error
  113.  
  114.  GET interrupt 
  115.      ax = 205h
  116.      bl = interrupt number
  117.      int 31h
  118.   returns:  edx = offset
  119.             cx  = selector
  120.  
  121. Also the Programible Interrupt Controllers ( 8259) base vector
  122. values can be obtained from the DPMI Get Version function, int 31h
  123. ax = 400h. If not running under DPMI then only the PIC bases
  124. are returned.
  125. DH = master PIC  ( pic 2 )
  126. DL = slave PIC   ( pic 1 )
  127.  
  128.  
  129.  
  130.  
  131. AVAILABLE DESCRIPTORS .
  132.      There are eight available descriptors for you program
  133. that DOS32.ASM initially sets up. The selector values for each
  134. descriptor is stored in the data segment under the labels:
  135.  
  136.  
  137. PSP_sel   :Data descriptor for the Program Segment Prefix
  138.                     Base = the real mode PSP segment.
  139.                     Limit = 100h
  140.  
  141. ENVIRONMENT_sel   :Data descriptor for the Program Environment
  142.                 Base = 16 multiplied by the word at offset 2Ch of the PSP.
  143.                 Limit = 100h
  144.  
  145. Data_sel        :Data descriptor for your program segment "CODE32"
  146.                           Base = the real mode program segment.
  147.                           Limit = 1MB  ( B=1 . i.e uses 32bit stack mode)
  148.  
  149. Code32_sel        :32 bit code descriptor for your program segment "CODE32"
  150.                           Base = the real mode program segment.
  151.                           Limit = 1MB
  152.  
  153. XMS_sel   :Data descriptor for the allocated extended memory block
  154.                   Base = the base address of the block
  155.                   Limit = Size of the allocated block ( see below)
  156.  
  157. BASE_sel        :Data descriptor for the free base memory
  158.                  Base = the unused base memory straight after
  159.                  MSDOS loads in you program.  (see below)
  160.                  Limit = 1Mb 
  161.  
  162.  
  163. VIDEO_sel          :Data descriptor for the video area.
  164.                       Base = A0000h
  165.                       Limit = 20000h
  166.  
  167. FLAT_DATA_sel      :Data descriptor for a flat memory model
  168.                       Base = 0
  169.                       Limit = FFFFFFFFh
  170.  
  171. FLAT_CODE32_sel    :32 bit code descriptor for a flat memory model
  172.                        Base = 0
  173.                        Limit = FFFFFFFFh
  174.  
  175.  
  176.  
  177.  The first instruction of you program will be executed is
  178. at offset "start32:" in your program segment with interrupts
  179. DISABLED.
  180.  
  181.  Your program is initially started with undefined selectors in 
  182. all the data segemnt registers ( ES,DS,FS,GS,SS).
  183. Thus your program must load valid selectors into ES,FS,GS,DS,SS if
  184. it's going to use any of them. 
  185. The stack pointer is also need to be loaded to a stack area.
  186. Initially there is a *SMALL* stack but I recomend to set your own. 
  187.  
  188.  
  189. Example of initalize with the stack in your program segment.
  190. ;----------------------------------------
  191. CODE32 SEGMENT USE32
  192. start32:       ; starting point
  193.      mov    ds,cs:[ Data_Sel]    ; Load all data Segment registers
  194.      mov    gs,cs:[ Flat_Sel]
  195.      mov    es,cs:[ Flat_Sel]
  196.      mov    fs,cs:[ XMS_Sel]
  197.      mov    ss,cs:[ Data_Sel]
  198.      mov    esp,OFFSET your_stack
  199.      sti                ; Can now enable interrupts safely
  200.         ...
  201.         ...    You program
  202.         ...
  203.         ...
  204.  
  205.         mov ah,4ch          ; terminate
  206.         int 21h
  207.  
  208. db 1000h (?)            ; set up some stack area
  209. your_stack:
  210. CODE32 ENDS
  211. ;----------------------------------------
  212.  
  213.  One more feature with DOS32.ASM is that in the program segment
  214. there are four labels with usful information about memory.
  215.  
  216.      1) "Base_Segment" will contain a real mode segment value
  217. of the start of free base memory.   i.e  The value stored in 
  218. this label * 16 = the base address of the BASE_sel descriptor.
  219.  
  220.      2) "PSP_segment". The real mode segment vlaue of the
  221. program segment prefix.
  222.  
  223.      3) "XMS_base". Contains the linear base address of the
  224. allocated extended memory block.
  225.  
  226.      4) "XMS_usage".  This location contains the number of bytes
  227. of the allocated extended memory block required by your program.
  228. DOS32.ASM will read the value of this  Label and attempt to
  229. allocate that amount of memory. If there isn't a enough free
  230. memory then DOS32 will allocate as mush as it can and
  231. return what was actually allocated back into this Label.
  232.  
  233. Notes
  234.       o     The XMS_sel descriptor Limit is set to this value.
  235.       o     The Memory allocated will never be greater than
  236.             lockable memory when in a virtual disk environment.
  237.       o     If the XMS driver nor DPMI is available then the
  238.           entire extended memory will be allocated by the xms
  239.           descriptor. base = 0100000h , limit = available ram.
  240.       o     If      XMS_usage is zero then no memory will be   
  241.           allocated and the XMS_sel will point to a invalid    
  242.           descriptor.
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249. Calling a Real mode interrupt:
  250.  
  251.      This is one of the most useful features of DOS32.ASM. The
  252. way the interrupt is called is through the macro "DOSINT"
  253. followed by the interrupt number. This macro actually consists
  254. of three instructions ( see DOS32.INC).
  255.           When the real mode interrupt is called, all the
  256. 32bit general registers and the 16bit flags ( except for ESP )
  257. are loaded with the same values they were in protected mode.
  258. Because in protected mode the segment registers cant be loaded
  259. with any value (except for valid selectors) a different method
  260. is used to pass the segment register values. 
  261.        The segment registers values MUST be passed from
  262. protected mode to the called real mode interrupt through several 
  263. labels in your program segment. See the file DOS32.INC for the
  264. declearation of these labes ( or locations ). 
  265. They are named:
  266.     Real_DS        ; holds the DS register when in V86 mode.
  267.     Real_ES        ; holds the ES register when in V86 mode.
  268.     Real_FS        ; and so on
  269.     Real_GS
  270.     Real_SS        ; These are already loaded by DSO32 with
  271.     Real_SP        ; V86 stack area. See below.
  272.  
  273.  
  274.         This is the easiest and most versatile way I could
  275. think how to do it.
  276.  
  277.  
  278.          eg . to print a string using dos func 9 int 21h
  279.  ;---------------------------------------------------------
  280.     mov        [Real_DS] ,seg test_message   ; pass DS register
  281.     mov        ah,9                
  282.     mov        dx,offset test_message
  283.     dosint    21h
  284.  
  285.     mov        ah,4ch                ; Terminate program
  286.     int        21h
  287.  
  288.     db test_mesg ' String message using dos func ah = 9'
  289.     db           '  in protected mode.',10,13,36
  290.  ;---------------------------------------------------------
  291.  
  292.  Just like using a real mode INT, all the general registers,
  293. flags and segment registers(stored in you program segment) will be
  294. returned with the values after the real mode interrupt call.
  295.  
  296.  
  297.                    V86 MODE STACK AREA 
  298.  
  299.        The only thing to left to say about the called real
  300. mode interrupt is that the stack is initaly set up by DOS32.ASM.
  301. Although you can set the V86 mode stack by simply loading the lables 
  302. [Real_SP] and [Real_SS], DOS32 already sets aside some a stack area .
  303.   The real mode stack space is defined by an equate in DOS32.ASM
  304. called "V86_stack_size". It is initially set to 200h and shouldn't 
  305. need to be changed. I thought this should be a safe value.
  306.  
  307.  
  308.  
  309.  
  310.    ****     I don't ever want to here of people complaining
  311. about the 640K limit for there own assembly programs !
  312.