📄 a16utils.asm
字号:
NAME BU_ASMTITLE BU_ASM.ASM -- ASM support for DOS BU_LIB;****************************************************************************;* Copyright (C) Intel Corporation 1994-1999;*;* All rights reserved. No part of this program or publication;* may be reproduced, transmitted, transcribed, stored in a;* retrieval system, or translated into any language or computer;* language, in any form or by any means, electronic, mechanical,;* magnetic, optical, chemical, manual, or otherwise, without;* the prior written permission of Intel Corporation.;****************************************************************************;; To assemble with MASM61 -- ml /c a16utils.asm;;****************************************************************************.286.MODEL large, cIFDEF MODEL_S.MODEL small, cENDIFIFDEF MODEL_M.MODEL medium, cENDIFIFDEF MODEL_L.MODEL large, cENDIFIFDEF MODEL_C.MODEL compact, cENDIFIFDEF MODEL_H.MODEL huge, cENDIF;--------------------------------------------------------------------GOREAL MACRO LOCAL here mov eax, cr0 and eax, 0fffffffeh mov cr0, eax jmp herehere:ENDM;--------------------------------------------------------------------GOPROT MACRO LOCAL here xor eax, eax xor edx, edx mov ax, ds shl eax, 4 lea edx, _gdt add eax, edx mov [_gdt_ptr+2], ax shr eax, 16 mov [_gdt_ptr+4], ax lgdt FWORD PTR _gdt_ptr mov eax, cr0 or eax, 1 mov cr0, eax jmp herehere:ENDM;--------------------------------------------------------------------.STACK.DATAPUBLIC _dAPAwake, _dAPDone, _dAPFuncPtr, _wProcNumber, _bSPValidPUBLIC _wCSegDS, _wCSegES, _wCSegSS, _wCSegSP, _wASegDS, _wASegESPUBLIC _dAPHltJmp emsfilename DB 'EMMXXXX0',0 _dAPAwake DD 0 _dAPDone DD 0 _dAPFuncPtr DD 0 _wProcNumber DW 0 _bSPValid DB 0 _wASegDS DW 0 _wASegES DW 0 _wCSegDS DW 0 _wCSegES DW 0 _wCSegSS DW 0 _wCSegSP DW 0 _block DW 0 _gdt_ptr DW 23 DD 0 _gdt DD 0 ; NULL descriptor DD 0 ; NULL descriptor ; 64K real mode style data segment DD 0ffffh ; base 0, limit 0xffff DD 00009200h ; data, CPL=0, 16-bit, 1 byte granularity, r/w ; 4G flat data segment DD 0ffffh ; base 0, limit 0xfffff DD 008f9200h ; data, CPL=0, 16-bit, 4K granularity, r/w _old_es DW 0 _old_ds DW 0 _old_fs DW 0 _old_gs DW 0 _dAPHltJmp DD 0 ; jump to halt location.CODEEXTERNDEF pascal cprint:procPUBLIC ems_presentems_present PROC C mov ah,3dh ; open file xor al,al ; read only operation mov dx,offset emsfilename ; look for EMMXXXX0 int 21h jc emserror1 ; if carry flag set, then no EMM driver mov di,ax ; save file handle mov bx,ax ; set up handle mov ax,4400h ; get device (channel) info int 21h mov ah,3eh ; close file mov bx,di ; close the file handle up int 21h jc emserror1 ; if carry flag set, then no driver is present test dx,10000000b ; if bit 7 not set, then the channel is a file jz emserror1 ; otherwise the channel is a device driver mov ax,1 ; 1 = EMS present retemserror1: xor ax,ax ; 0 = EMS not present retems_present ENDPPUBLIC vm86vm86 PROC C smsw ax and ax, 1 retvm86 ENDPPUBLIC _set_rows_set_rows PROC C rows:WORD cmp rows, 25 je set_25 cmp rows, 50 je set_50 cmp rows, 132 je set_132 jmp invalid_inputset_25: mov ah, 00 mov al, 03 int 10h mov ax, rows jmp end_set_rowsset_50: mov ah, 00 mov al, 03 int 10h xor bx, bx mov ah, 11h mov al, 12h int 10h mov ax, rows jmp end_set_rowsset_132: mov ah, 00 mov al, 14h int 10h xor bx, bx mov ah, 11h mov al, 12h int 10h mov ax, rows jmp end_set_rowsinvalid_input: xor ax, ax jmp end_set_rowsend_set_rows: ret_set_rows ENDPPUBLIC _cpuid_asm_cpuid_asm PROC C hv:DWORD, regs:PTR DWORDcheck_8086:.8086 pushf pop ax mov cx, ax and ax, 0fffh push ax popf pushf pop ax and ax, 0f000h cmp ax, 0f000h mov ax, 10h je end_cpuidcheck_80286:.286 or cx, 0f000h push cx popf pushf pop ax and ax, 0f000h mov ax, 20h jz end_cpuidcheck_80386:.386 mov bx, sp and sp, not 3 pushfd pop eax mov ecx, eax xor eax, 40000h push eax popfd pushfd pop eax cmp ecx, eax jne check_80486 mov ax, 30h mov sp, bx jmp end_cpuidcheck_80486:.486 pushfd pop ecx mov ecx, eax xor eax, 200000h push eax popfd pushfd pop eax xor eax, ecx mov ax, 40h je end_cpuidcheck_cpuid:.586 mov eax, hv cpuid push ebx IF @DataSize ; segment is far les bx, regs mov dword ptr es:[bx], eax pop eax mov dword ptr es:[bx + 4], eax mov dword ptr es:[bx + 8], ecx mov dword ptr es:[bx + 12], edx ELSE ; segment is near mov bx, regs mov dword ptr [bx], eax pop eax mov dword ptr [bx + 4], eax mov dword ptr [bx + 8], ecx mov dword ptr [bx + 12], edx ENDIF mov ax, 5end_cpuid: ret_cpuid_asm ENDP.386p;--------------------------------------------------------------------; Pentium Pro MSRs - from Pentium Pro Developer's Manual; January 1996 - Appendix C;; MTRRs: 200h - 20Fh, 250h, 258h - 259h, 268h - 26Fh, 2FFh;--------------------------------------------------------------------PUBLIC _read_msr_read_msr PROC C dmsr:DWORD, pqmsr:PTR DWORD pushad mov ecx, dmsr dw 320fh ; RDMSR les bx, pqmsr mov DWORD ptr es:[bx], eax mov DWORD ptr es:[bx + 4], edx popad ret_read_msr ENDP;--------------------------------------------------------------------PUBLIC _write_msr_write_msr PROC C dmsr:DWORD, pqmsr:PTR DWORD pushad les bx, pqmsr mov eax, DWORD ptr es:[bx] mov edx, DWORD ptr es:[bx + 4] mov ecx, dmsr dw 300fh ; WRMSR popad ret_write_msr ENDP;----------------------------------------------------------------------------; Procedure: dReadCR0 - Reads CR0 CPU Register;; Output: dx:ax and eax - Contents of CR0;; Registers: All registers preserved except EAX and EDX;----------------------------------------------------------------------------PUBLIC dReadCR0dReadCR0 PROC C mov eax, cr0 mov edx, eax shr edx, 16 ; upper 16 bits in dx retdReadCR0 ENDP;----------------------------------------------------------------------------; Procedure: dReadCR2 - Reads CR2 CPU Register;; Output: dx:ax and eax - Contents of CR2;; Registers: All registers preserved except EAX and EDX;----------------------------------------------------------------------------PUBLIC dReadCR2dReadCR2 PROC C mov eax, cr2 mov edx, eax shr edx, 16 ; upper 16 bits in dx retdReadCR2 ENDP;----------------------------------------------------------------------------; Procedure: dReadCR3 - Reads CR3 CPU Register;; Output: dx:ax and eax - Contents of CR3;; Registers: All registers preserved except EAX and EDX;----------------------------------------------------------------------------PUBLIC dReadCR3dReadCR3 PROC C mov eax, cr3 mov edx, eax shr edx, 16 ; upper 16 bits in dx retdReadCR3 ENDP.586;----------------------------------------------------------------------------; Procedure: dGetProcUpdateRev_asm - Reads PPP Update Revision via an MSR;; Output: dx:ax and eax - PPP Update Revision;; Registers: All registers preserved except EAX, ECX, and EDX;----------------------------------------------------------------------------PUBLIC _dGetProcUpdateRev_asm_dGetProcUpdateRev_asm PROC C mov ecx, 08Bh ; model specific register to write xor eax, eax xor edx, edx dw 300Fh ; WRMSR ==> load 0 to MSR at 8Bh mov eax, 1 cpuid mov ecx, 08Bh ; model specific register to read dw 320Fh ; RDMSR ==> EDX = (read) MSR 8Bh mov eax, edx ; return EAX shr edx, 16 ; return DX:AX ret_dGetProcUpdateRev_asm ENDP;--------------------------------------------------------------------PUBLIC iInterruptFlagStateiInterruptFlagState PROC pushf pop ax and ax, 200h shr ax, 9 retiInterruptFlagState ENDP;--------------------------------------------------------------------.586PPUBLIC vRealFsGsvRealFsGs PROC C ; TBD: verify this on an AMD K6-2 266 MHz ; Assert A20M# via system control port A (This is a ; system dependent feature). in al, 92h and al, 0fdh out 92h, al ; re-assert A20M# GOPROT mov ax, 8 mov gs, ax GOREAL mov ax, [_old_fs] ; restore original mov fs, ax mov ax, [_old_gs] ; restore original mov gs, ax sti retvRealFsGs ENDP;--------------------------------------------------------------------PUBLIC vFlatFsGsvFlatFsGs PROC C cli mov ax, fs mov [_old_fs], ax ; save original fs mov ax, gs mov [_old_gs], ax ; save original gs ; Deassert A20M# via system control port A (This is a ; system dependent feature) in al, 92h or al, 2 out 92h, al ; de-assert A20M# GOPROT mov ax, 10h mov fs, ax mov gs, ax GOREAL retvFlatFsGs ENDP
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -