免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: lmarsin
打印 上一主题 下一主题

学习linux内核时,模仿linux编写的操作系统 [复制链接]

论坛徽章:
0
21 [报告]
发表于 2010-03-24 18:37 |只看该作者
lz

我在 bochs 调试了你的代码,如下:

  1. 0009000a: (                    ): call .+0x010a             ; e80a01
  2. 0009000d: (                    ): mov ax, 0x0000            ; b80000
  3. 00090010: (                    ): mov ds, ax                ; 8ed8
  4. 00090012: (                    ): mov es, ax                ; 8ec0
  5. 00090014: (                    ): mov ah, 0x03              ; b403
  6. 00090016: (                    ): xor bh, bh                ; 30ff
  7. 00090018: (                    ): int 0x10                  ; cd10
  8. 0009001a: (                    ): mov word ptr ds:0x500, dx ; 89160005
  9. 0009001e: (                    ): mov ah, 0x88              ; b488
  10. 00090020: (                    ): int 0x15                  ; cd15            
  11. 00090022: (                    ): add ax, 0x0400            ; 050004          >> ax = 0
  12. 00090025: (                    ): shr ax, 0x02              ; c1e802
  13. 00090028: (                    ): shr ax, 0x0a              ; c1e80a
  14. 0009002b: (                    ): mov word ptr ds:0x502, ax ; a30205
  15. 0009002e: (                    ): cmp ax, 0x0004            ; 3d0400           >>>>
  16. 00090031: (                    ): jnl .+0x000d              ; 7d0d
  17. 00090033: (                    ): mov ax, 0x9000            ; b80090
  18. 00090036: (                    ): mov ds, ax                ; 8ed8
  19. 00090038: (                    ): mov si, 0x02ca            ; beca02
  20. 0009003b: (                    ): call .+0x00d9             ; e8d900
复制代码



错误在于:

00090020: (                    ): int 0x15                  ; cd15            
00090022: (                    ): add ax, 0x0400            ; 050004          >> ax = 0
00090025: (                    ): shr ax, 0x02              ; c1e802
00090028: (                    ): shr ax, 0x0a              ; c1e80a




你使用了 int 0x15 来进行获取 memory size, 它返回 memory 放在 ax,加上 0x400 是什么意思?

论坛徽章:
0
22 [报告]
发表于 2010-03-24 18:41 |只看该作者
用 int 0x15  来获取 memory 不是好办法呀

文档上说:

Notes: TSRs which wish to allocate extended memory to themselves often hook this call, and return a reduced memory size. They are then free to use the memory between the new and old sizes at will.. The standard BIOS only returns memory between 1MB and 16MB; use AH=C7h for memory beyond 16MB. Not all BIOSes correctly return the carry flag, making this call unreliable unless one first checks whether it is supported through a mechanism other than calling the function and testing CF. Due to applications not dealing with more than 24-bit descriptors (286), Windows 3.0 has problems when this function reports more than 15 MB. Some releases of HIMEM.SYS are therefore limited to use only 15 MB, even when this function reports more

论坛徽章:
0
23 [报告]
发表于 2010-03-24 18:46 |只看该作者
本帖最后由 mik 于 2010-03-24 18:48 编辑

int 0x15 后应该是乘以 0x400


(ax * 0x400 + 0x100000) / 0x100000

吧?



int 0x15
shr ax, 10

论坛徽章:
0
24 [报告]
发表于 2010-03-24 18:50 |只看该作者
可能那个image比较旧,用代码编译后的image试试

论坛徽章:
0
25 [报告]
发表于 2010-03-24 18:58 |只看该作者
代码是这样的
; 取得物理内存大小 (1M以上的扩展内存, KB)
    mov    ah, 0x88
    int    0x15

;;探测内存是否小于16M,如果小于,则提示并死机
    cmp    ax, 0x3C00
    jae    next
    mov    ax, SETUP_SEG
    mov    ds, ax  
    mov    si, mem_too_small             ;     
    call   print_msg                     ;
    jmp    $

论坛徽章:
36
IT运维版块每日发帖之星
日期:2016-04-10 06:20:00IT运维版块每日发帖之星
日期:2016-04-16 06:20:0015-16赛季CBA联赛之广东
日期:2016-04-16 19:59:32IT运维版块每日发帖之星
日期:2016-04-18 06:20:00IT运维版块每日发帖之星
日期:2016-04-19 06:20:00每日论坛发贴之星
日期:2016-04-19 06:20:00IT运维版块每日发帖之星
日期:2016-04-25 06:20:00IT运维版块每日发帖之星
日期:2016-05-06 06:20:00IT运维版块每日发帖之星
日期:2016-05-08 06:20:00IT运维版块每日发帖之星
日期:2016-05-13 06:20:00IT运维版块每日发帖之星
日期:2016-05-28 06:20:00每日论坛发贴之星
日期:2016-05-28 06:20:00
26 [报告]
发表于 2010-03-24 19:19 |只看该作者
lmarsin兄方便传个新的上来吗。想立马试一下。

论坛徽章:
0
27 [报告]
发表于 2010-03-24 20:21 |只看该作者
没问题啊,刚刚编译的,附件为新的image和2.4.2版本的bochs配置文件。
image.rar (14.85 KB, 下载次数: 172)

论坛徽章:
4
CU大牛徽章
日期:2013-03-13 15:29:07CU大牛徽章
日期:2013-03-13 15:29:49CU大牛徽章
日期:2013-03-13 15:30:192015年迎新春徽章
日期:2015-03-04 09:57:09
28 [报告]
发表于 2010-03-25 00:44 |只看该作者
N人啊

论坛徽章:
0
29 [报告]
发表于 2010-03-25 09:38 |只看该作者
哈哈,顶你一下,

论坛徽章:
0
30 [报告]
发表于 2010-03-25 09:42 |只看该作者
牛人!不过怎么会有那么多时间来做这个呢?
大概看了一下,代码还是不错的,至少注释比较多!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP