发新话题
打印

那位高手知道linux启动盘的结构。。。。。

那位高手知道linux启动盘的结构。。。。。

我很想知道linux启动盘的相关知识比如:
  bootsect.s    setup.s 和内核
  存放在什么位置,从第几个扇区开始
  启动过程如何      

TOP

首先声明:下面是理解可能有误,忘高手指点,这也是我的目的,

第一扇区(从1开始计数)是bootsect.s的代码,可以看到第一个扇区的标志aa55
接下来4sector是setup.s的内容啦(可能还不够大?)。
再下就是head.s,再下就是压缩过的head.s
再下就是真正内核的内容,
后面是文件系统。

bootsect.s  (<512byte)                 
setup.s     ( 可以超过4*512byte )      
head.s      (调解压程序)
(
  head.s (另外一个)
  start_kernel
  .....
  end of linux kernel(最多508K)

文件系统


要不来一段intel的bootsect.s汇编吧。
原则:是去掉精华,留下糟粕---糟粕简单。
我写它的另外一个原因是因为看intel汇编顺眼。
不知道大家会不会怪我乱灌,
.model large
.code
start:
        jmp begin_mv       
        syssize        dw 7f00h
        sread        dw 1                        ; sectors read of current track
        head        dw 0                        ; current head
        track        dw 0                        ; current track
        msg1        db 13,10
                db 'Loading'
        root_dev         dw 0
begin_mv:
        ; mov boot sector from 7c00 ==>90000
        mov        ax,7c0h                ;
        mov        ds,ax                ; ds = 7c0
        mov        ax,9000h        ;
        mov        es,ax                ; es = 9000
       
        mov        cx,256                ; count = 512byte 1 sector
        sub        si,si                ; si = 0
        sub        di,di                ; di = 0
        cld                        ; cx --
        rep                        ;
        movsw                        ; ds:si ==> es:di  7c00==>90000 512bytes
       
        ; init ss , sp
        mov         ss,ax                ; ss = 9000
        mov        dx,3ff4h        ;
        mov        sp,dx                ; sp = 3ff4
       
        db 0eah
        dw $+4
        dw 9000h                ; jmp 9000:go       
        ; end of boot sector move
go:
        mov        es,ax                ;  es = 9000
        mov        ax,9000h        ;
        mov        ds,ax                ;  ds = 9000h
       
        ; read 2K setup code from floppy to 0x90200       
load_setup:
        mov        ah,2                ; we wanna read
        mov         al,4                ; read 4 sector 2k
        mov        dx,0                ; drive a:,head 0;
        mov        cx,2                ; track 0, begin sector 2(note: we count sector from 1)
        mov        bx,200h                ; bx = 512
        int        13h                ; read from disk ==>es:bx offset = 0x90200 len = 4*512byte
        jnc        ok_load_setup        ; OK
        xor        dl, dl                ; reset FDC
        xor        ah, ah
        int        13h
        jmp        load_setup        ; try again
        ; end of read 2K code       
ok_load_setup:
        mov        ah,3                ; read the position of cursor
        xor        bh,bh                ; page = bh = 0
        int        10h                ; return ch: begin line. dx: (line,col)
       
        mov        cx,9                ; string len
        mov        bx,7                ; attribute of the display       
        mov        bp,offset msg1        ; es:bp  es = 9000
        mov        ax,1301h        ; write string, move cursor
        int        10h

        ; read 508K from floppy to memory.
        mov        ax,1000h        ;
        mov        es,ax                ; memory begin at 0x10000;
        xor        bx,bx                ; bx is the point of memory
        mov        sread,6
        call        read_it                ; input es as the address
        ; end of read 508K
       
        ; kill_motor
        mov dx,3f2h
        xor al, al
        out dx,al
        ; set root_dev and jmp to setup.s
        mov        ax,021ch        ; 1.44M disk
root_defined:
        mov        root_dev,ax        ;
       
        mov ax,43c0h
        mov ds,ax
        mov ax,0b800h
        mov es,ax
        xor si,si
        xor di,di
        mov cx,512
        rep
        movsw       
       
        die: jmp die
        db 0eah
        dw 0200h
        dw 9000h
        ; end of the boot sect and jmp to setup.s
       
read_it:
        mov ax,es
        sub ax,1000h
        cmp ax,syssize               
        jnbe end_read
        call read_one_sector               
        inc sread
        cmp sread,19                        ; we only support 1.44M floppy 18 sectors       
        jne mem_boundary_chk                ;
        mov sread,1                        ; begin from 1
        inc head                        ;
        cmp head,2                        ; end of the head
        jne mem_boundary_chk       
        mov head,0
        inc track                       
mem_boundary_chk:
        clc                                ; clear cf
        add        bx,512                        ;
        jnc        read_it                        ;
        mov ax,es
        add ah,10h
        mov es,ax
        xor bx,bx
        jmp read_it       
end_read:       
        ret
       
read_one_sector:
        push bx
        mov        ax, 0e2eh         ; print "."
        mov        bx, 7
        int        10h
        pop bx        
        ; set cl = start sector
        mov        cx,sread
        ; set ch = track number
        mov        dx,track
        mov        ch,dl       
        ; set the drive and head
        mov        dx,head
        mov        dh,dl
        and        dx,0100h
        ;
        mov        ax,0201h        ; read one sector
        int        13h                ; from disk ==> es:bx
        jc        bad_rt       
        ret
bad_rt:       
        xor ah,ah
        xor dl,dl
        int 13h                ; reset FDC
        push bx
        mov        ax, 0e2ah         ; print "*"
        mov        bx, 7
        int        10h
        pop bx
        jmp read_one_sector       
org 510
boot_flag        dw 0AA55h       
end start




验证: 看源码;
可以做一张启动盘,然后用winhex之类的软件直接看磁盘。

顺便庆祝一下,我是中几会员啦!hehe~~
      

TOP

发新话题