Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1291952
  • 博文数量: 632
  • 博客积分: 2778
  • 博客等级: 大尉
  • 技术积分: 3387
  • 用 户 组: 普通用户
  • 注册时间: 2012-05-31 09:09
个人简介

123

文章分类

全部博文(632)

文章存档

2014年(36)

2013年(33)

2012年(563)

分类:

2012-10-29 11:08:55


点击(此处)折叠或打开

  1. ...
  2. sread: .word 1+SETUPLEN ! sectors read of current track
  3. head: .word 0 ! current head
  4. track: .word 0 ! current track

  5. read_it:
  6. mov ax,es
  7. test ax,#0x0fff
  8. die: jne die ! es must be at 64kB boundary
  9. xor bx,bx ! bx is starting address within segment
  10. rp_read:
  11. mov ax,es
  12. cmp ax,#ENDSEG ! have we loaded all yet?
  13. jb ok1_read
  14. ret
  15. ok1_read:
  16. seg cs
  17. mov ax,sectors
  18. sub ax,sread
  19. mov cx,ax
  20. shl cx,#9
  21. add cx,bx
  22. jnc ok2_read
  23. je ok2_read
  24. xor ax,ax
  25. sub ax,bx
  26. shr ax,#9
  27. ok2_read:
  28. call read_track
  29. mov cx,ax
  30. add ax,sread
  31. seg cs
  32. cmp ax,sectors
  33. jne ok3_read
  34. mov ax,#1
  35. sub ax,head
  36. jne ok4_read
  37. inc track
  38. ok4_read:
  39. mov head,ax
  40. xor ax,ax
  41. ok3_read:
  42. mov sread,ax
  43. shl cx,#9
  44. add bx,cx
  45. jnc rp_read
  46. mov ax,es
  47. add ax,#0x1000
  48. mov es,ax
  49. xor bx,bx
  50. jmp rp_read

  51. read_track:
  52. push ax
  53. push bx
  54. push cx
  55. push dx
  56. mov dx,track
  57. mov cx,sread
  58. inc cx
  59. mov ch,dl
  60. mov dx,head
  61. mov dh,dl
  62. mov dl,#0
  63. and dx,#0x0100
  64. mov ah,#2
  65. int 0x13
  66. jc bad_rt
  67. pop dx
  68. pop cx
  69. pop bx
  70. pop ax
  71. ret
  72. ...
第2行:sread 表示在0磁道内已经读过的sector。我们知道之前已经从磁道0读取过两部分代码:
init segment和setup segment。其中init是512字节即1个sector长度,setup segment是4个sector长度。
所以内核数据要从磁道0的5个sector之后读起。
第8行:test ax, #0x0fff 这里会拿ax与#0x0fff做位与。所以如果是64KB为边界的话结果就是0.
第13行:读到ENDSEG = SYSSEG + SYSSIZE为止。而SYSSEG = 0x1000, SYSSIZE = 0x3000. 所以从0x1000:0x0000读到0x4000:0x0000为止,即192KB。
第19~22行,第58~67行:
int 0x13的用法 - ah: 0x02表示把磁盘扇区数据读到内存  al: 需要读的扇区数量
                 ch: 磁道号的低8位                   cl: 开始扇区(0~5位), 磁道号高两位(6~7)
                 dh: 磁头号                          dl: 驱动器号
                 es:bx -> 指向数据缓冲区. 读取出错的话CF置位
所以第一次读的时候al = ax - sread. 表示读取磁道0从init seg和setup seg后面开始的内核数据。
bx这时候=0.所以数据读到0x1000:0x0000.

               
阅读(600) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~