home *** CD-ROM | disk | FTP | other *** search
/ Software Collection (I) / TOOLS.iso / b04 / 22.img / EBIOS / EBIOS.AS_ / EBIOS.AS
Encoding:
Text File  |  1992-01-04  |  13.2 KB  |  516 lines

  1. PAGE 58,132
  2. ;******************************************************************************
  3. TITLE ebios.asm -
  4. ;******************************************************************************
  5. ;
  6. ;   (C) Copyright MICROSOFT Corp., 1988-1990
  7. ;
  8. ;   Title:    ebios.asm -
  9. ;
  10. ;   Version:    1.00
  11. ;
  12. ;   Date:    21-Dec-1988
  13. ;
  14. ;   Author:    RAP
  15. ;
  16. ;------------------------------------------------------------------------------
  17. ;
  18. ;   Change log:
  19. ;
  20. ;      DATE    REV            DESCRIPTION
  21. ;   ----------- --- -----------------------------------------------------------
  22. ;   21-Dec-1988 RAP
  23. ;
  24. ;==============================================================================
  25.     .386p
  26.  
  27. ;******************************************************************************
  28. ;                  I N C L U D E S
  29. ;******************************************************************************
  30.  
  31. .XLIST
  32.     INCLUDE VMM.INC
  33.     INCLUDE Debug.INC
  34.  
  35.     Create_EBIOS_Service_Table EQU 1    ; EBIOS service table created
  36.     INCLUDE EBIOS.INC
  37.     INCLUDE SYSINFO.INC
  38.     INCLUDE v86mmgr.inc
  39.     INCLUDE arena.asm
  40. .LIST
  41.  
  42. ;******************************************************************************
  43. ;         V I R T U A L     D E V I C E   D E C L A R A T I O N
  44. ;******************************************************************************
  45.  
  46. Declare_Virtual_Device EBIOS, 1, 0, EBIOS_Control, EBIOS_Device_ID, EBIOS_Init_Order
  47.  
  48. ;
  49. ; High 16 bits is real EBIOS start segment address
  50. ; Low 16 bits is above segment address rounded down to a page boundary
  51. ;
  52. EBIOS_page equ EBIOS_DDB.DDB_Reference_Data
  53.  
  54. VxD_DATA_SEG
  55.  
  56.     public    EB_Unused_Start,EB_Unused_Size,EB_Num_Pages,EB_NoMap
  57. EB_Unused_Start dd    0
  58. EB_Unused_Size    dd    0
  59. EB_Num_Pages    dd    0
  60.  
  61. EB_NoMap    db    0    ; != 0 if we don't need to do any maps for page
  62.  
  63. VxD_DATA_ENDS
  64.  
  65. VxD_ICODE_SEG
  66.  
  67. ;******************************************************************************
  68. ;
  69. ;   EBIOS_Device_Init
  70. ;
  71. ;   DESCRIPTION:
  72. ;
  73. ;   ENTRY:        EBX = SYS VM's handle
  74. ;
  75. ;   EXIT:        Carry clear if no error
  76. ;
  77. ;   USES:        Nothing
  78. ;
  79. ;   ASSUMES:
  80. ;
  81. ;==============================================================================
  82.  
  83. BeginProc EBIOS_Device_Init
  84.  
  85.     push    ebp
  86.     mov    ebp, esp
  87.     sub    esp, 9*4            ; reverve 9 dwords for array
  88.     mov    edi, esp
  89.     VMMCall _Get_Device_V86_Pages_Array <0, edi, 0>
  90.  
  91.     mov    edx, [EBIOS_page]
  92.     movzx    edx, dx             ; Just page number
  93.     mov    ecx, 1                ; Default size is one
  94.  
  95.     VMMCall _GetFirstV86Page
  96.     xchg    edx, eax
  97.     cmp    eax, edx            ;Q: below first V86 page?
  98.     ja    short chk_page_assignment   ;    N:
  99.     ;
  100.     ; EBIOS device starts <= FirstV86Page, assumed size of 1 is "correct".
  101.     ;    We do not need to do any mapping for this page.
  102.     ;
  103.     mov    [EB_Num_Pages],ecx
  104.     inc    [EB_NoMap]
  105.     add    eax, ecx
  106.     dec    eax
  107.     cmp    eax, edx            ;Q: all pages?
  108.     jbe    init_ChkPart            ;    Y: don't need to assign them!
  109.     sub    eax, edx            ;    N: eax = # of pages above
  110.     mov    ecx, eax            ;       ecx = # of pages to assign
  111.     mov    eax, edx
  112.     inc    eax                ;       eax = first page to assign
  113.     jmp    DEBFAR chk_page_assignment2
  114.  
  115. chk_page_assignment:
  116.     cmp    eax,0A0h            ; Above 640k boundary?
  117.     jb    short ComputeSz         ; No
  118.     ;
  119.     ; EBIOS is > A000:0. It may be in a UMB. Check it out. If it is in a UMB
  120.     ;    we do not need to manage it as V86MMGR will take care of it.
  121.     ;    Assumed size of 1 is "correct".
  122.     ;
  123.     mov    [EB_Num_Pages],ecx
  124.     push    eax
  125.  
  126.     VxDCall V86MMGR_Get_Version
  127.  
  128.     cmp    eax,030Ah
  129.     jb    short chk_page_assignment2p    ; We'll have to manage page.
  130.     pop    ecx
  131.     xor    ebx,ebx             ; Global check
  132.  
  133.     VxDCall V86MMGR_GetPgStatus
  134.  
  135.     xchg    ecx,eax
  136.     test    ecx,V86PS_UMB            ; UMB page?
  137.     mov    ecx,[EB_Num_Pages]
  138.     jz    short chk_page_assignment2    ; No we have to manage it
  139.     inc    [EB_NoMap]
  140.     jmp    DEBFAR init_ChkPart
  141.  
  142. ComputeSz:
  143.     mov    edx,eax
  144.  
  145.     VMMCall _GetLastV86Page
  146.     xchg    eax,edx
  147.     cmp    eax,edx
  148. IFDEF DEBUG
  149.     ja    short EB10
  150.     debug_out "EBIOS page is above FirstV86Page and below or = LastV86Page????"
  151. EB10:
  152. ENDIF
  153.     jbe    DEBFAR Ebios_Fatal
  154.     cmp    eax,96h
  155.     jb    short SetDefCnt
  156.     mov    ecx,0A0h
  157.     sub    ecx,eax
  158. SetDefCnt:
  159.     mov    [EB_Num_Pages],ecx
  160.     jmp    short chk_page_assignment2
  161.  
  162. chk_page_assignment2p:
  163.     pop    eax
  164. chk_page_assignment2:
  165. chk_pages:
  166.     bt    [edi], eax            ;Q: page assigned?
  167.     jc    short page_assigned        ;    Y: error!
  168.     inc    eax
  169.     loop    chk_pages
  170.                         ; all pages are free, so assign them
  171.  
  172.     mov    eax, [EBIOS_page]
  173.     movzx    eax, ax             ; Just page number
  174.     VMMCall _Assign_Device_V86_Pages <eax, [EB_Num_Pages], 0, 0>   ;global
  175.  
  176.     or    eax,eax
  177. IFDEF DEBUG
  178.     jnz    short EDID10
  179.     debug_out "_Assign_Device_V86_Pages failed for EBIOS page."
  180. EDID10:
  181. ENDIF
  182.     jz    short Ebios_Fatal
  183. init_ChkPart:
  184.     mov    edx, [EBIOS_page]
  185.  
  186.     VMMCall _GetFirstV86Page
  187.  
  188.     cmp    dx, ax                ;Q: below first V86 page?
  189.     jb    short init_done         ;  Y:
  190.     cmp    dx, 0A0h            ;Q: Above A0h?
  191.     jae    short init_done         ;  Y:
  192.     test    edx,0FFFF0000h            ;Q: partial EBIOS situation?
  193.     jz    short init_done         ;  N:
  194.     mov    eax,edx
  195.     shr    eax,16                ; Size in paras of unused part
  196.     movzx    edx,dx
  197.     shl    edx,8                ; Page number to segment
  198.     mov    [EB_Unused_Start],edx
  199.     mov    [EB_Unused_Size],eax
  200. init_done:
  201.     mov    esp, ebp
  202.     pop    ebp
  203.  
  204. no_EBIOS:
  205.     clc
  206.     ret
  207.  
  208. page_assigned:
  209. IFDEF DEBUG
  210.     shl    esi, 5
  211.     add    eax, esi
  212.     Debug_Out 'EBIOS: page already assigned (#eax)'
  213. ENDIF
  214. Ebios_Fatal:
  215.     Fatal_Error
  216.  
  217. EndProc EBIOS_Device_Init
  218.  
  219. VxD_ICODE_ENDS
  220.  
  221. VxD_LOCKED_CODE_SEG
  222.  
  223. ;******************************************************************************
  224. ;
  225. ;   EBIOS_Control
  226. ;
  227. ;   DESCRIPTION:    dispatch control messages to the correct handlers
  228. ;
  229. ;   ENTRY:
  230. ;
  231. ;   EXIT:        Carry clear if no error
  232. ;
  233. ;   USES:
  234. ;
  235. ;==============================================================================
  236.  
  237. BeginProc EBIOS_Control
  238.  
  239.     Control_Dispatch Device_Init, EBIOS_Device_Init
  240.     Control_Dispatch Sys_VM_Init, <short EBIOS_Map_pages>
  241.     Control_Dispatch Create_VM,   <short EBIOS_Map_pages>
  242.     clc
  243.     ret
  244.  
  245. EndProc EBIOS_Control
  246.  
  247. VxD_LOCKED_CODE_ENDS
  248.  
  249.  
  250. VxD_CODE_SEG
  251.  
  252. BeginDoc
  253. ;******************************************************************************
  254. ;
  255. ;   EBIOS_Get_Version
  256. ;
  257. ;   DESCRIPTION:    Get EBIOS device version and location/size of EBIOS pages
  258. ;
  259. ;   ENTRY:
  260. ;
  261. ;   EXIT:        IF Carry clear
  262. ;            EAX is version
  263. ;            EDX is page #
  264. ;            ECX is # of pages
  265. ;            ELSE EBIOS device not installed, and EBIOS pages are
  266. ;            not allocated
  267. ;
  268. ;   USES:    FLAGS,EAX,ECX,EDX
  269. ;
  270. ;==============================================================================
  271. EndDoc
  272.  
  273. BeginProc EBIOS_Get_Version, SERVICE
  274.  
  275.     mov    eax, 200h
  276.     mov    edx, [EBIOS_page]
  277.     movzx    edx, dx             ; Just page number
  278.     mov    ecx, [EB_Num_Pages]
  279.     clc
  280.     ret
  281.  
  282. EndProc EBIOS_Get_Version
  283.  
  284. BeginDoc
  285. ;******************************************************************************
  286. ;
  287. ;   EBIOS_Get_Unused_Mem  **<EBIOS  VERSION must be >= 2.00>**
  288. ;
  289. ;   DESCRIPTION:    Get information about part of the EBIOS region which
  290. ;            is not used by EBIOS.
  291. ;
  292. ;            On some machines the EBIOS region is not a multiple
  293. ;            of pages in size on a page boundary. Because of the
  294. ;            requirement for the EBIOS region to be rounded to page
  295. ;            boundaries (system performance related issue), part of
  296. ;            the EBIOS region may be unused. This service IDs this
  297. ;            region.
  298. ;
  299. ;            NOTE: That in cases where the EBIOS region is below
  300. ;              FirstV86Page this service must return with
  301. ;              carry set.
  302. ;
  303. ;            The use of this service is intended for the DOSMGR
  304. ;            device so that the unused portion of the EBIOS region
  305. ;            can be assigned to one of the VMs (typically the SYS VM)
  306. ;            and get used for something. This only occurs if the region
  307. ;            is contiguous with the main V86 memory (start of unused
  308. ;            region is (LastV86Page + 1) SHL 12). NOTE HOWEVER that
  309. ;            it is UP TO THE CALLER to evaluate this. This service
  310. ;            must not fail to ID the unused EBIOS region just because
  311. ;            LastV86Page + 1 doesn't butt up against the unused EBIOS
  312. ;            region.
  313. ;
  314. ;   ENTRY:        None
  315. ;
  316. ;   EXIT:        Carry Clear
  317. ;            EAX = SEGMENT address of start of unused EBIOS region
  318. ;            ECX = size of region in PARAGRAPHS (may be 0 indicating
  319. ;                  that there is no unused EBIOS region).
  320. ;            Zero Flag Set
  321. ;                Unused EBIOS region is GLOBAL. The region is in
  322. ;                the SAME physical page in ALL VMs.
  323. ;            Zero Flag Clear
  324. ;                Unused EBIOS region is LOCAL. The region is in
  325. ;                a different physical page in each VM.
  326. ;            Carry Set
  327. ;            EBIOS device not installed, OR All EBIOS memory
  328. ;            is used by EBIOS (no unused EBIOS memory).
  329. ;
  330. ;   USES:
  331. ;    EAX,ECX,FLAGS
  332. ;
  333. ;==============================================================================
  334. EndDoc
  335.  
  336. BeginProc EBIOS_Get_Unused_Mem, SERVICE
  337.  
  338.     xor    eax,eax         ; SET ZERO (also clear carry),
  339.                     ;   EBIOS is global
  340.     mov    eax,[EB_Unused_Start]
  341.     mov    ecx,[EB_Unused_Size]    ; Is 0 if no unused EBIOS
  342.     ret
  343.  
  344. EndProc EBIOS_Get_Unused_Mem
  345.  
  346. ;******************************************************************************
  347. ;
  348. ;   EBIOS_Map_pages
  349. ;
  350. ;   DESCRIPTION:    Map EBIOS pages into the VM
  351. ;
  352. ;   ENTRY:        EBX = Handle of VM being initialized
  353. ;
  354. ;   EXIT:
  355. ;
  356. ;   USES:
  357. ;
  358. ;==============================================================================
  359.  
  360. BeginProc EBIOS_Map_pages
  361.  
  362.     cmp    [EB_NoMap],0        ; Need to map?
  363.     jne    short EB_Map_Done    ; No
  364.     mov    eax, [EBIOS_page]
  365.     movzx    eax, ax         ; Just page number
  366.     VMMCall _PhysIntoV86 <eax, ebx, eax, [EB_Num_Pages], 0>
  367. EB_Map_Done:
  368.     clc
  369.     ret
  370.  
  371. EndProc EBIOS_Map_pages
  372.  
  373. VxD_CODE_ENDS
  374.  
  375.  
  376. ;******************************************************************************
  377. ;******************************************************************************
  378. ;
  379. ; Real mode initialization code
  380. ;
  381. ;******************************************************************************
  382.  
  383. VxD_REAL_INIT_SEG
  384.  
  385. BeginProc ebios_init
  386.  
  387.     test    bx, Duplicate_Device_ID
  388.     jnz    no_ebios_fnd        ; don't load if an ebios device has already
  389.                     ; loaded!
  390.  
  391.     stc                ; set carry so that if the BIOS doesn't
  392.                     ; modify anything, then we will recognize
  393.                     ; a failure
  394.     ;
  395.     ; Some machines have EBIOS but do not implement the EBIOS int 15h APIs.
  396.     ;
  397. IFNDEF    ARBEBIOS
  398.     mov    ah, 0C0h
  399.     int    15h
  400.     jc    short no_StdEbios_fnd  ; jump if carry signifies no support
  401.     or    ah, ah
  402.     jnz    short no_StdEbios_fnd  ; jump if ah wasn't set to 0
  403.     test    es:[bx.SD_feature1], SF1_EBIOS_allocated
  404.     jz    short no_StdEbios_fnd
  405.     xor    ax, ax
  406.     mov    es, ax
  407.     mov    ah, 0C1h        ; get segment adr of EBIOS
  408.     int    15h
  409.     jc    short no_StdEbios_fnd
  410.     mov    ax, es            ; get EBIOS segment address
  411.     or    ax, ax
  412.     jz    short no_StdEbios_fnd    ; jump if es = 0
  413.  
  414. ;
  415. ;   Make sure Int 12h agrees with the EBIOS start.  If not then there is no
  416. ;   unused memory in the EBIOS page
  417. ;
  418.     push    ax
  419.     int    12h
  420.     shl    ax, 10-4        ; Convert size from K to segment (*1024/16)
  421.     pop    dx
  422.     cmp    dx, ax            ; Q: End of DOS land = Start of EBIOS?
  423.     mov    ax, dx            ; (does not change flags)
  424.     je    SHORT DOEbios        ; Must exactly match to use extra
  425.     xor    dx, dx            ; Eat whole page -- No partial EBIOS free
  426.  
  427.     ;
  428.     ; AX = para address of EBIOS
  429.     ;
  430. DOEbios:
  431.     shr    ax, 8            ; convert to a page #
  432.     and    dx, 0000000011111111B  ; Para offset to REAL start of EBIOS
  433. ELSE
  434.     ;
  435.     ; Under ARBEBIOS Always EBIOS at page 9F
  436.     ;
  437. DOEbios:
  438.     mov    ax, 9Fh
  439.     xor    dx, dx
  440. ENDIF
  441.     shl    edx, 16         ; Para offset to REAL start in high 16 bits
  442.     mov    dx, ax            ; REF data is EBIOS page # and offset
  443.     mov    bx, OFFSET exc_ebios_page
  444.     mov    cx, 1            ; Default size is 1 page
  445.     cmp    ax, 096h        ; In last 40K of 640K DOS land?
  446.     jb    short NoPrivMark    ; NO, is low memory EBIOS page
  447.     cmp    ax, 0A0h        ; Above or = A0 (probably in a UMB)?
  448.     jae    short NoPrivMark    ; Yes, no private mark
  449.     mov    cx, 0A0h
  450.     sub    cx, ax            ; Size in pages
  451.     push    bx
  452. PMrkLp:
  453.     mov    [bx], ax        ; Mark page as private to EBIOS
  454.     inc    bx
  455.     inc    bx
  456.     loop    PMrkLp
  457.     pop    bx
  458.     jmp    short YesPrivMark
  459.  
  460. NoPrivMark:
  461.     xor    bx, bx            ; No priv mark if low mem EBIOS
  462. YesPrivMark:
  463.     xor    si, si
  464.     mov    ax, Device_Load_Ok
  465.     jmp    short init_exit
  466.  
  467.     ;
  468.     ; Try to detect HOSEBAG EBIOS machines by checking to see if DOS 640k
  469.     ;    land doesn't actually end at 640k (A000) like it should
  470.     ;
  471.     ;    NOTE THAT THERE ARE SOME MACHINES THAT IMPLEMENT THE INT 15 API
  472.     ;    BUT LIE!!!!!! LIKE AT&T.
  473.     ;
  474. no_StdEbios_fnd:
  475.     mov    ax,5100h        ; Get current PSP (win386 PSP)
  476.     int    21h
  477.     mov    es,bx
  478.     mov    ax,word ptr es:[2]
  479.     cmp    ax,0A000h        ; Ends at 640k like it should?
  480.     jae    short no_ebios_fnd  ; Yes, no EBIOS
  481.     cmp    ax,9600h        ; This is 600k ( > 40k EBIOS is very unlikely)
  482.     jb    short no_ebios_fnd
  483.     cmp    ax,9FFFh        ; Is it exactly one paragraph?
  484.     jne    short DOEbios        ; No, assume EBIOS
  485.     ;
  486.     ; The end of DOS land is one paragraph short of A000h. This might be
  487.     ;    due to a guy like DOS 5 who has a wraith arena here for linking
  488.     ;    in the high memory UMBs. Check if the paragraph contains an arena
  489.     ;    signature and an owner of 8 (magic "system owner").
  490.     ;
  491.     push    es
  492.     mov    es,ax
  493.     cmp    es:[arena_signature],arena_signature_normal
  494.     jne    short DoEbiosP
  495.     cmp    es:[arena_owner],8
  496. DoEbiosP:
  497.     pop    es
  498.     jne    short DOEbios
  499. no_ebios_fnd:
  500.     xor    bx, bx
  501.     xor    si, si
  502.     xor    edx, edx        ; ref data is 0
  503.     mov    ax, Abort_Device_Load OR No_Fail_Message
  504. init_exit:
  505.     ret
  506.  
  507. exc_ebios_page    dw  0, 0, 0, 0, 0, 0, 0, 0, 0
  508.  
  509. EndProc ebios_init
  510.  
  511.  
  512. VxD_REAL_INIT_ENDS
  513.  
  514.  
  515.     END ebios_init
  516.