鱼C论坛

 找回密码
 立即注册
查看: 2303|回复: 3

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

[复制链接]
发表于 2013-2-9 14:56:46 | 显示全部楼层 |阅读模式
25鱼币
本帖最后由 张国祥 于 2013-2-9 14:58 编辑

我给虚拟机分配了64MB内存,使用15号中断探测内存并显示在屏幕上,乍看似乎是对的,但仔细一看,肯定有错,先上图:
shot.png
第8个ARDS结构的LengthLow(长度)已经达到1000000H,远超64MB,这是什么问题呢?再上代码(补充:此代码首先进入保护模式,接着通过retf进入ring3,再通过调用门回到ring0,再探测内存):
  1. %include "pm.inc"
  2. org 0100h
  3. jmp start
  4. ;enter pm,call data segment,ring0->ring3->ring0,check memory,clean,study page
  5. [SECTION .gdt]
  6. GDT_DESC:        Descriptor        0,0,0
  7. MAIN_DESC:        Descriptor        0,mainlen-1,DA_C+DA_32
  8. DATA_DESC:        Descriptor        0,datalen-1,DA_DRW+DA_DPL3
  9. STK_DESC:        Descriptor        0,TopOfStk+2,DA_DRW
  10. DISP_DESC:        Descriptor        0b8000h,0ffffh,DA_DRW+DA_DPL3

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

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

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

  16. gdtlim:        dw $-$-1
  17. dd 0

  18. SEL_MAIN                EQU                MAIN_DESC-$
  19. SEL_DATA                EQU                DATA_DESC-$+SA_RPL3
  20. SEL_STK                        EQU                STK_DESC-$
  21. SEL_DISP                EQU                DISP_DESC-$+SA_RPL3

  22. SEL_CODE3                EQU                CODE3_DESC-$+SA_RPL3
  23. SEL_STK3                EQU                STK3_DESC-$+SA_RPL3

  24. SEL_CODE0                EQU                CODE0_DESC-$

  25. SEL_TSS                        EQU                TSS_DESC-$
  26. SEL_CALL_GATE        EQU                CALL_GATE-$+SA_RPL3

  27. [SECTION .data1]
  28. data:
  29.         _Msg:                db "PM Now!",0
  30.         _Titles:        db        "BaseAddrL BaseAddrH LengthLow LengthHigh   Type",0ah,0ah,0
  31.         _MemMsg1:        db "AVL RAM:",0
  32.         _MemMsg2:        db "RAM Size:",0
  33.         _Cr:                db 0ah,0
  34.         _ARDSCnt:        dd 0
  35.         _DisPos:        dd 160*2+2*0
  36.         _MemAVL:        dd 0
  37.         _MemTotal:        dd 0
  38.         _MemCache:        times 512 db 0
  39.         
  40.         DataOst                Msg
  41.         DataOst                Titles
  42.         DataOst                MemMsg1
  43.         DataOst                MemMsg2
  44.         DataOst                Cr
  45.         DataOst                ARDSCnt
  46.         DataOst                DisPos
  47.         DataOst                MemAVL
  48.         DataOst                MemTotal
  49.         DataOst                MemCache
  50. datalen                equ        $-$

  51. [SECTION .stk]
  52. [BITS 32]
  53. stk:
  54.         times 512 db 0
  55. TopOfStk        equ        $-$-2

  56. [SECTION .stk3]
  57. [BITS 32]
  58. stk3:
  59.         times 512 db 0
  60. TopOfStk3        equ        $-$-2

  61. [SECTION .tss]
  62. ALIGN 32
  63. [BITS 32]
  64. tss:
  65.         dd 0
  66.         dd TopOfStk
  67.         dd SEL_STK
  68.         times 22 dd 0
  69.         dw 0
  70.         dw $-tss+2
  71.         db 0ffh
  72. tsslen                equ        $-$

  73. [SECTION .start]
  74. ALIGN 32
  75. [BITS 16]
  76. start:
  77.         mov ax,cs
  78.         mov ds,ax
  79.         mov es,ax
  80.         mov ss,ax
  81.         mov sp,0100h
  82.         
  83.         mov ebx,0
  84.         mov di,_MemCache
  85.         mov cx,20
  86.         mov edx,534d4150h
  87.         
  88. chk:
  89.         mov eax,0e820h
  90.         int 15h
  91.         jc chk_err
  92.         add di,20
  93.         inc dword [_ARDSCnt]
  94.         cmp ebx,0
  95.         je chk_ok
  96.         jmp chk
  97.                
  98. chk_err:
  99.         mov dword [_ARDSCnt],0
  100.                
  101. chk_ok:
  102.         DescInit        cs,main,MAIN_DESC
  103.         DescInit        ds,data,DATA_DESC
  104.         DescInit        ss,stk,STK_DESC
  105.         DescInit        cs,code3,CODE3_DESC
  106.         DescInit        ss,stk3,STK3_DESC
  107.         DescInit        cs,code0,CODE0_DESC
  108.         DescInit        ds,tss,TSS_DESC
  109.                
  110.         mov ax,ds
  111.         movzx eax,ax
  112.         shl eax,4
  113.         add eax,GDT_DESC
  114.         mov dword [gdtlim+2],eax
  115.         lgdt [gdtlim]
  116.                
  117.         cli
  118.         
  119.         in al,92h
  120.         or al,00000010b
  121.         out 92h,al
  122.         
  123.         mov eax,cr0
  124.         or eax,1
  125.         mov cr0,eax
  126.         
  127.         jmp dword SEL_MAIN:0
  128.         
  129. [SECTION .main]
  130. ALIGN 32
  131. [BITS 32]
  132. main:
  133.         mov ax,SEL_DATA
  134.         mov ds,ax
  135.         mov ax,SEL_DISP
  136.         mov gs,ax
  137.         mov ax,SEL_STK
  138.         mov ss,ax
  139.         mov sp,TopOfStk

  140.         mov esi,Msg
  141.         mov edi,0
  142.         mov ah,0ah
  143.         
  144. dispm:
  145.         mov al,[ds:esi]
  146.         cmp al,0
  147.         je disok
  148.         mov [gs:edi],ax
  149.         inc esi
  150.         add edi,2
  151.         jmp dispm
  152.         
  153. disok:
  154.         mov ax,SEL_TSS
  155.         ltr ax
  156.         
  157.         push SEL_STK3
  158.         push TopOfStk3
  159.         push SEL_CODE3
  160.         push 0
  161.         retf
  162. mainlen                equ        $-$

  163. [SECTION .code3]
  164. ALIGN 32
  165. [BITS 32]
  166. code3:
  167.         mov ah,0ah
  168.         mov al,'3'
  169.         mov [gs:20],ax
  170.         call SEL_CALL_GATE:0
  171. code3len        equ        $-$

  172. [SECTION .code0]
  173. ALIGN 32
  174. [BITS 32]
  175. code0:
  176.         mov ax,Titles
  177.         call DispStr

  178.         mov ecx,[ARDSCnt]
  179.         mov esi,MemCache
  180.         
  181. d0:
  182.         push ecx
  183.         mov ecx,5
  184.         
  185. d1:
  186.         mov eax,[ds:esi]
  187.         call DispInt
  188.         
  189.         mov edi,[DisPos]
  190.         mov al,'H'
  191.         mov ah,0ch
  192.         mov [gs:edi],ax
  193.         add esi,4
  194.         add edi,4
  195.         mov [DisPos],edi
  196.         loop d1
  197.         
  198.         mov ax,Cr
  199.         call DispStr

  200.         sub esi,4
  201.         cmp byte [ds:esi],1
  202.         jne noavl
  203.         sub esi,8
  204.         mov eax,[ds:esi]
  205.         add [MemAVL],eax
  206.         jmp c0
  207.         
  208. noavl:
  209.         sub esi,8
  210.         
  211. c0:
  212.         mov eax,[ds:esi]
  213.         add [MemTotal],eax
  214.         
  215.         add esi,12
  216.         pop ecx
  217.         loop d0

  218.         mov ax,Cr
  219.         call DispStr

  220.         mov ax,MemMsg1
  221.         call DispStr

  222.         mov eax,[MemAVL]
  223.         call DispInt
  224.         
  225.         mov ax,Cr
  226.         call DispStr
  227.         
  228.         mov ax,MemMsg2
  229.         call DispStr
  230.         
  231.         mov eax,[MemTotal]
  232.         call DispInt
  233.         
  234.         
  235.         
  236.         jmp $
  237. %include "library.inc"
  238. code0len        equ        $-$
复制代码
关于代码中引用的文件,通过附件:
code.rar (175.25 KB, 下载次数: 0)
问题有些长- -希望大家帮忙= =

小甲鱼最新课程 -> https://ilovefishc.com
 楼主| 发表于 2013-2-9 15:06:18 | 显示全部楼层
在帖子上的代码有问题,貌似不能同时显示两个$$,请大家以附件里的为准
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2013-2-10 23:11:51 | 显示全部楼层
顶起求助,谢谢
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2013-2-12 20:44:41 | 显示全部楼层
{:7_176:}再次顶起。
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-7-12 18:08

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表