张国祥 发表于 2013-2-9 14:56:46

15号中断0e8号功能问题:探测内存,求助= =

本帖最后由 张国祥 于 2013-2-9 14:58 编辑

我给虚拟机分配了64MB内存,使用15号中断探测内存并显示在屏幕上,乍看似乎是对的,但仔细一看,肯定有错,先上图:

第8个ARDS结构的LengthLow(长度)已经达到1000000H,远超64MB,这是什么问题呢?再上代码(补充:此代码首先进入保护模式,接着通过retf进入ring3,再通过调用门回到ring0,再探测内存):
%include "pm.inc"
org 0100h
jmp start
;enter pm,call data segment,ring0->ring3->ring0,check memory,clean,study page

GDT_DESC:      Descriptor      0,0,0
MAIN_DESC:      Descriptor      0,mainlen-1,DA_C+DA_32
DATA_DESC:      Descriptor      0,datalen-1,DA_DRW+DA_DPL3
STK_DESC:      Descriptor      0,TopOfStk+2,DA_DRW
DISP_DESC:      Descriptor      0b8000h,0ffffh,DA_DRW+DA_DPL3

CODE3_DESC:      Descriptor      0,code3len-1,DA_C+DA_32+DA_DPL3
STK3_DESC:      Descriptor      0,TopOfStk3+2,DA_DRW+DA_DPL3

CODE0_DESC:      Descriptor      0,code0len-1,DA_C+DA_32

TSS_DESC:      Descriptor      0,tsslen-1,DA_386TSS
CALL_GATE:      Gate                SEL_CODE0,0,0,DA_386CGate+DA_DPL3

gdtlim:      dw $-$-1
dd 0

SEL_MAIN                EQU                MAIN_DESC-$
SEL_DATA                EQU                DATA_DESC-$+SA_RPL3
SEL_STK                        EQU                STK_DESC-$
SEL_DISP                EQU                DISP_DESC-$+SA_RPL3

SEL_CODE3                EQU                CODE3_DESC-$+SA_RPL3
SEL_STK3                EQU                STK3_DESC-$+SA_RPL3

SEL_CODE0                EQU                CODE0_DESC-$

SEL_TSS                        EQU                TSS_DESC-$
SEL_CALL_GATE      EQU                CALL_GATE-$+SA_RPL3


data:
      _Msg:                db "PM Now!",0
      _Titles:      db      "BaseAddrL BaseAddrH LengthLow LengthHigh   Type",0ah,0ah,0
      _MemMsg1:      db "AVL RAM:",0
      _MemMsg2:      db "RAM Size:",0
      _Cr:                db 0ah,0
      _ARDSCnt:      dd 0
      _DisPos:      dd 160*2+2*0
      _MemAVL:      dd 0
      _MemTotal:      dd 0
      _MemCache:      times 512 db 0
      
      DataOst                Msg
      DataOst                Titles
      DataOst                MemMsg1
      DataOst                MemMsg2
      DataOst                Cr
      DataOst                ARDSCnt
      DataOst                DisPos
      DataOst                MemAVL
      DataOst                MemTotal
      DataOst                MemCache
datalen                equ      $-$



stk:
      times 512 db 0
TopOfStk      equ      $-$-2



stk3:
      times 512 db 0
TopOfStk3      equ      $-$-2


ALIGN 32

tss:
      dd 0
      dd TopOfStk
      dd SEL_STK
      times 22 dd 0
      dw 0
      dw $-tss+2
      db 0ffh
tsslen                equ      $-$


ALIGN 32

start:
      mov ax,cs
      mov ds,ax
      mov es,ax
      mov ss,ax
      mov sp,0100h
      
      mov ebx,0
      mov di,_MemCache
      mov cx,20
      mov edx,534d4150h
      
chk:
      mov eax,0e820h
      int 15h
      jc chk_err
      add di,20
      inc dword
      cmp ebx,0
      je chk_ok
      jmp chk
               
chk_err:
      mov dword ,0
               
chk_ok:
      DescInit      cs,main,MAIN_DESC
      DescInit      ds,data,DATA_DESC
      DescInit      ss,stk,STK_DESC
      DescInit      cs,code3,CODE3_DESC
      DescInit      ss,stk3,STK3_DESC
      DescInit      cs,code0,CODE0_DESC
      DescInit      ds,tss,TSS_DESC
               
      mov ax,ds
      movzx eax,ax
      shl eax,4
      add eax,GDT_DESC
      mov dword ,eax
      lgdt
               
      cli
      
      in al,92h
      or al,00000010b
      out 92h,al
      
      mov eax,cr0
      or eax,1
      mov cr0,eax
      
      jmp dword SEL_MAIN:0
      

ALIGN 32

main:
      mov ax,SEL_DATA
      mov ds,ax
      mov ax,SEL_DISP
      mov gs,ax
      mov ax,SEL_STK
      mov ss,ax
      mov sp,TopOfStk

      mov esi,Msg
      mov edi,0
      mov ah,0ah
      
dispm:
      mov al,
      cmp al,0
      je disok
      mov ,ax
      inc esi
      add edi,2
      jmp dispm
      
disok:
      mov ax,SEL_TSS
      ltr ax
      
      push SEL_STK3
      push TopOfStk3
      push SEL_CODE3
      push 0
      retf
mainlen                equ      $-$


ALIGN 32

code3:
      mov ah,0ah
      mov al,'3'
      mov ,ax
      call SEL_CALL_GATE:0
code3len      equ      $-$


ALIGN 32

code0:
      mov ax,Titles
      call DispStr

      mov ecx,
      mov esi,MemCache
      
d0:
      push ecx
      mov ecx,5
      
d1:
      mov eax,
      call DispInt
      
      mov edi,
      mov al,'H'
      mov ah,0ch
      mov ,ax
      add esi,4
      add edi,4
      mov ,edi
      loop d1
      
      mov ax,Cr
      call DispStr

      sub esi,4
      cmp byte ,1
      jne noavl
      sub esi,8
      mov eax,
      add ,eax
      jmp c0
      
noavl:
      sub esi,8
      
c0:
      mov eax,
      add ,eax
      
      add esi,12
      pop ecx
      loop d0

      mov ax,Cr
      call DispStr

      mov ax,MemMsg1
      call DispStr

      mov eax,
      call DispInt
      
      mov ax,Cr
      call DispStr
      
      mov ax,MemMsg2
      call DispStr
      
      mov eax,
      call DispInt
      
      
      
      jmp $
%include "library.inc"
code0len      equ      $-$
关于代码中引用的文件,通过附件:

问题有些长- -希望大家帮忙= =

张国祥 发表于 2013-2-9 15:06:18

在帖子上的代码有问题,貌似不能同时显示两个$$,请大家以附件里的为准

张国祥 发表于 2013-2-10 23:11:51

顶起求助,谢谢

张国祥 发表于 2013-2-12 20:44:41

{:7_176:}再次顶起。
页: [1]
查看完整版本: 15号中断0e8号功能问题:探测内存,求助= =