⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testmem.asm

📁 dos下testmemory程序
💻 ASM
字号:
.model small,c
.stack
data segment use16
;;============================
code16 segment public use16 'code'
  assume  cs:code16, ds:code16
.486p
start:
      
      
   cli
     lea     esi,GdtDesc
      db      66h  
      lgdt fword ptr cs:[si]

                   call A20_Enable

                    mov     eax, cr0
                    or      eax, 00000001h                     ; Set PE bit (bit #0) & MP bit (bit #1)
                    mov     cr0, eax                           ; Activate protected mode
                    sti
                    
                    ;
                    ; Now we're in Protected16
                    ; Set up the selectors for protected mode entry
                    ;
                    mov     ax, SYS_DATA_SEL
                    mov     ds, ax
                    mov     es, ax
                    mov     fs, ax
                    mov     gs, ax
                    mov     ss, ax
                    
                    	    mov esi, offset NemInitLinearAddress
                    jmp     fword ptr cs:[si]    
             ;;;============================================

;;===============A20 services
A20_Enable proc near 

  push ax
  push bx
  push cx
  cli 

  call WaitIBE 
  mov dx,64h
  mov al,0D1h    ; the next data will be put into output port
  out dx,al

  call WaitIBE 
  mov dx,60h
  mov al,0DFh    ; Enable GateA20
  out dx,al

  call WaitIBE 
  mov dx,64h
  mov al,0ffh     ;none cmd
  out dx,al
  call WaitIBE
  
  sti
  pop cx
  pop bx
  pop ax
  ret    
A20_Enable endp

WaitIBE proc near
   push dx
   mov dx,64h
 wait0:
   in al,dx
   test al,02h
   jnz wait0
   pop dx
   ret
WaitIBE endp

;;===============A20 End

code16 ends

protect_mode segment para public use32 'code'

  assume cs:protect_mode, ds:protect_mode
  
    PCIE_CON  equ 0cf8H
    PCIE_DATA equ 0cfch
    PCIE_Address equ 0000h    ; example bus0 dev28 fun0
    PCIEXBAR   dd   0
  
ProtectedModeEntryPoint PROC NEAR PUBLIC


       mov dx,PCIE_CON
       mov eax,80000048h
       out dx,eax
       mov dx,PCIE_DATA
       in eax,dx
       and eax,0f0000000h
       mov PCIEXBAR,eax
       
  ;     mov  ebx,0             ;; read pcie bus0 dev28 fun0, 4k areas

       mov edx,PCIE_Address
       mov cl,12
       shl edx,cl
       mov esi,PCIEXBAR
       add esi,edx
;     loop_256:
       add esi,ebx

       push esi
        shr esi,16
       pop esi

       mov eax,dword ptr [esi]   ; ch extended register 0-fh, cl register 0-0ffh
 ;      mov Reg_value,eax
       call print_hex
;       add bl,1
;       cmp bl,2
;       jbe loop_256
;       add bh,1
;       mov bl,0
;       cmp bh,01h
;       jbe loop_256
     
;;;;;;;;;;;;;;;;
     exit:
        mov ax,4c00h
        int 21h
ProtectedModeEntryPoint ENDP

    print_hex proc near
         push edx
       push ecx
       mov ebx,eax
       mov ch,8
       mov cl,4
    lo:
      rol ebx,cl
      mov dl,bl
      and dl,0fh
      add dl,30h
      cmp dl,39h
      jbe char0
      add dl,7
      
    char0:
      mov ah,2
      int 21h
      dec ch
      jnz lo
       
       pop ecx
       pop edx
        ret
    print_hex endp

 align 10h
                    PUBLIC  BootGDTtable     
;
; GDT[0]: 0x00: Null entry, never used.
;
NULL_SEL            equ     $ - GDT_BASE               ; Selector [0]
GDT_BASE:
BootGDTtable        DD      0
                    DD      0
;
; Linear data segment descriptor
;
LINEAR_SEL          equ     $ - GDT_BASE               ; Selector [0x8]
                    DW      0FFFFh                     ; limit 0xFFFFF
                    DW      0                          ; base 0
                    DB      0
                    DB      092h                       ; present, ring 0, data, expand-up, writable
                    DB      0CFh                       ; page-granular, 32-bit
                    DB      0
;
; Linear code segment descriptor
;
LINEAR_CODE_SEL     equ     $ - GDT_BASE               ; Selector [0x10]
                    DW      0FFFFh                     ; limit 0xFFFFF
                    DW      0                          ; base 0
                    DB      0
                    DB      09Bh                       ; present, ring 0, data, expand-up, not-writable
                    DB      0CFh                       ; page-granular, 32-bit
                    DB      0
;
; System data segment descriptor
;
SYS_DATA_SEL        equ     $ - GDT_BASE               ; Selector [0x18]
                    DW      0FFFFh                     ; limit 0xFFFFF
                    DW      0                          ; base 0
                    DB      0
                    DB      093h                       ; present, ring 0, data, expand-up, not-writable
                    DB      0CFh                       ; page-granular, 32-bit
                    DB      0

;
; System code segment descriptor
;
SYS_CODE_SEL        equ     $ - GDT_BASE               ; Selector [0x20]
                    DW      0FFFFh                     ; limit 0xFFFFF
                    DW      0                          ; base 0
                    DB      0
                    DB      09Ah                       ; present, ring 0, data, expand-up, writable
                    DB      0CFh                       ; page-granular, 32-bit
                    DB      0
;
; Spare segment descriptor
;
SYS16_CODE_SEL      equ     $ - GDT_BASE               ; Selector [0x28]
                    DW      0FFFFh                     ; limit 0xFFFF
                    DW      0                          ; base 0xF000
                    DB      0Fh
                    DB      09Bh                       ; present, ring 0, code, expand-up, writable
                    DB      00h                       ; byte-granular, 16-bit
                    DB      0
;
; Spare segment descriptor
;
SYS16_DATA_SEL      equ     $ - GDT_BASE               ; Selector [0x30]
                    DW      0FFFFh                     ; limit 0xFFFF
                    DW      0                          ; base 0
                    DB      0
                    DB      093h                       ; present, ring 0, data, expand-up, not-writable
                    DB      00h                        ; byte-granular, 16-bit
                    DB      0

;
; Spare segment descriptor
;
SPARE5_SEL          equ     $ - GDT_BASE               ; Selector [0x38]
                    DW      0                          ; limit 0
                    DW      0                          ; base 0
                    DB      0
                    DB      0                          ; present, ring 0, data, expand-up, writable
                    DB      0                          ; page-granular, 32-bit
                    DB      0
GDT_SIZE            EQU     $ - BootGDTtable            ; Size, in bytes

GdtDesc:                                                ; GDT descriptor
OffsetGDTDesc       EQU     $ - start
                    DW      GDT_SIZE - 1                ; GDT limit
                    DD      OFFSET BootGDTtable ; GDT base address

 NemInitLinearAddress   LABEL   FWORD
NemInitLinearOffset    LABEL   DWORD
                    DD      OFFSET ProtectedModeEntryPoint              ; Offset of our 32 bit code
                    DW      LINEAR_CODE_SEL
                    
protect_mode ends
end start

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -