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

 

Study Linux Kernel Notes(v 0.11)                        Shawn.Xie
                                                        [email protected]
                                                       
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 |     |
     +-------------+------------------+          +-----+

 

你可能感兴趣的:(LINUX专题,linux,disk,system,module,parameters,input)