Linux Kernel (v 0.11)源代码解读-bootsect.s

 

Study Linux Kernel Notes(v 0.11)                        Shawn.Xie
                                                        Shawshie@msn.com
                                                       
1.  bootsect.s

1.1  BIOS booting

      x86 CPU 的第一条指令从0xFFFF0开始(??)

      有空的时候要研究BIOS

      BIOS将启动的设备的第一个扇区512个字节读到内存的0x7C00的地方

      -----------------------------------------------------------------
       注意:这里的一节为16 Bytes ??
      -----------------------------------------------------------------

      hard disk                RAM
    / floppy disk                ~ ~ ~  ~
    / CD-ROM                   |          |
    /...                       |          |
      +------------+  ------>  +----------+
      |  512 Bytes |           |          |
      |            |  copy to  |          |
      +------------+  ------>  +----------+ 0x7C00 (BOOTSEG 0x7C0 31KB)
                               |          |
                               |          |
                               +----------+

      以上移动由BIOS完成。

      ----------------------------------------------------------------
       entry start       ! 告知连接程序,程序从start 标号开始执行。
                         ! 连接之后,下一条指令放置于.bin文件的
                         ! 第一个位置。
       start:
                         !...
      ----------------------------------------------------------------

1.2  BootSect booting

    1.2.1  BootSect Booting Sequence Overview

                       RAM
                         ~ ~ ~ ~ ~
                       |           |
                       +           + 0x0009 ff00  <--- SP
                       |           |    CS & DS & ES & SS = 0x9000
    boot disk          |           |
     ~ ~ ~ ~ ~         |           |
    |         |        |           |
    +---------+ -----> +-----------+
    |    2~5  |  (2)   |   Setup   |
    |  section| copy to|   Module  | ## (3) run here ##
    +---------+ -----> +-----------+ 0x0009 0200
    |         |      +>|           | ## (2) run here ##
     ~ ~ ~ ~ ~       | +-----------+ 0x0009 0000 (INITSEG 0x9000 576KB)
                     | |           |
    boot disk        | |           |
    begin at         | +-----------+ 0x0004 0000 (ENDSEG 0x4000 256KB)
    track :0         | |  System   |
    sector:0         | |  Module   |
                     | +-----------+ 0x0001 0000 (SYSSEG 0x1000 64KB)
                  (1)| |           |
                     | +-----------+ 0x0000 7E00
                     +-|           | ## (1) run here ##
                       +-----------+ 0x0000 7C00 (BOOTSEG 0x7C0 31KB)
                       |           |
                       |           |
                       +-----------+

    1.2.2  BootSect Detail

      1. Copy itself to 0x0009 0000.

      2. Go 0x0009 0000 to run, and reset every segment here.

      3. Call BIOS int13 to load the sectors(2~5) on the hard disk to
      0x0009 0200, which is the Setup Module.

      4. Call BIOS int13 to read the floppy disk parameters, and save
      the sector number per track in the global varible "sectors".

      5. Call BIOS int10 to print "Loading system ..." to the screen.

      6. Read System Module to 0x0001 0000. We can descript it in
      detail in the following.

      7. Kill flobby drive motor.

      8. Get the booting device and record it in 0x000901fc, then
      jump to 0x0009 0200.

     2.1.2.1 Read System Module in detail

     Input Parameter : AX = 0x1000 (System Segment Location)

              AX is 64KB aligned?
                   +--------------------------------------+
                   | Y                                    |N
        BX=0; Sread=0; Sectors=?(read by 4)               Dead Loop
     +------------>|
     |        EX is below 0x4000?  /*4*64KB的数据是否还没有读完*/
     |             +--------------------------------------+
     |             | Y                                    |N
     |        AX = sectors-sread;                         Ret
     |        CX = AX << 9(*512) + BX; /* 如果此次操作完成     */
     |             |                   /* ES段内将读入的字节数 */
     |             |
     |        CX carring bit or equal 0?
     |             +--------------------------------------+
     |             | Y                                    |N
     |        AX = -BX >> 9 /*ES段内还可以读入的扇区数*/     |
     |             +--------------------------------------+
     |        Read Disk
     |             |
     |        AX += sread /*当前磁道已经读取的扇区数*/
     |             |
     |        AX == sectors? /*当前扇区读完了没有*/
     |             +-----------------------------------+
     |             | N <-------------------------+     |Y
     |        sread = AX;                        |     head == 0?
     |        /*上次已读扇区数*512 字节*/          |     +--------+
     |        /*调整当前段内数据开始位置*/          |     | N      | Y
     |        BX >= 64KB?                        |     track++; head++;
     |             +------------------+          |     +--------+
     |             | N                | Y        |     AX = 0;
     |             |                  ES+=0x1000 |     |
     +-------------+------------------+          +-----+

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值