【操作系统实验二】操作系统的引导

一、修改bootsect.s完成相应功能

1.打开目录到下图

实验楼

2.修改bootsect.s源文件

图片描述

图片描述

3.编译:

cd oslab/linux-0.11/boot                  //进入源文件所在目录
as86 -0 -a -o bootsect.o bootsect.s       //生成bootsect.oz中间文件
ld86 -0 -s -o bootsect bootsect.o    //生成bootsect文件
ls -l                                      //列出当前目录      
dd bs=1 if=bootsect of=Image skip=32      //生成image文件(去掉文件头的bootsect)

实验楼

4.运行:

将boot/Image文件拷贝到linux-0.11目录下

双击shiyanlou/oslab/oslab下的run如下图所示

实验楼

二、修改setup.s完成对应功能

  1. 修改setuo.s、build.c

图片描述

图片描述

图片描述

2.编译:linux-0.11目录下打开命令行

make BootImage

3.运行:

双击run

实验楼

读取硬件参数并且显示出来

3.1修改setup.s文件,文件末尾放以下代码:

print_hex:

    mov bp,sp
    mov    cx,#4        
    mov    dx,(bp+4)     
    print_digit:
    rol    dx,#4        
    mov    ax,#0xe0f     
    and    al,dl     
    add    al,#0x30    
    cmp    al,#0x3a
    jl    outp       
    add    al,#0x07     
outp: 
    int    0x10
    loop    print_digit
    ret

print_nl:
    mov    ax,#0xe0d     ! CR
    int    0x10
    mov    al,#0xa     ! LF
    int    0x10
    ret

3.2添加信息字段memery_size

memery_size:
    .byte 13,10
    .ascii "Memory Size:"

3.3.添加获取内存及显示文字字段

! Get memory size (extended mem, kB)

    mov    ah,#0x88
    int    0x15
    mov    [2],ax

    mov    ax,cs
    mov    ds,ax
    mov    es,ax
! Print some inane message

    mov    ah,#0x03        ! read cursor pos
    xor    bh,bh
    int    0x10

    mov    cx,#14
    mov    bx,#0x0007        ! page 0, attribute 7 (normal)
    mov    bp,#memory1
    mov    ax,#0x1301        ! write string, move cursor
    int    0x10
    mov ax,#INITSEG
    mov ds,ax
    push [2]
    call print_hex
    pop [2]
    call print_nl

编译运行如图所示

实验楼

setup.s

!
!    setup.s        (C) 1991 Linus Torvalds
!
! setup.s is responsible for getting the system data from the BIOS,
! and putting them into the appropriate places in system memory.
! both setup.s and system has been loaded by the bootblock.
!
! This code asks the bios for memory/disk/other parameters, and
! puts them in a "safe" place: 0x90000-0x901FF, ie where the
! boot-block used to be. It is then up to the protected mode
! system to read them from there before the area is overwritten
! for buffer-blocks.
!

! NOTE! These had better be the same as in bootsect.s!

INITSEG  = 0x9000    ! we move boot here - out of the way
SYSSEG   = 0x1000    ! system loaded at 0x10000 (65536).
SETUPSEG = 0x9020    ! this is the current segment

.globl begtext, begdata, begbss, endtext, enddata, endbss
.text
begtext:
.data
begdata:
.bss
begbss:
.text

entry start
start:
       mov           ax,cs
       mov          ds,ax
       mov          es,ax
! Print some inane message

    mov    ah,#0x03        ! read cursor pos
    xor    bh,bh
    int    0x10

    mov    cx,#26
    mov    bx,#0x0007        ! page 0, attribute 7 (normal)
    mov    bp,#msg1
    mov    ax,#0x1301        ! write string, move cursor
    int    0x10
! ok, the read went well so we get current cursor position and save it for
! posterity.

    mov    ax,#INITSEG    ! this is done in bootsect already, but...
    mov    ds,ax
    mov    ah,#0x03    ! read cursor pos
    xor    bh,bh
    int    0x10        ! save it in known place, con_init fetches
    mov    [0],dx        ! it from 0x90000.



! Get memory size (extended mem, kB)

    mov    ah,#0x88
    int    0x15
    mov    [2],ax

       mov           ax,cs
       mov           ds,ax
       mov           es,ax
! Print memory size

    mov    ah,#0x03        ! read cursor pos
    xor    bh,bh
    int    0x10

    mov    cx,#14
    mov    bx,#0x0007        ! page 0, attribute 7 (normal)
    mov    bp,#memory_size
    mov    ax,#0x1301        ! write string, move cursor
    int    0x10

       mov   ax,#INITSEG
       mov   ds,ax
       push  [2]
       call     print_hex
       pop    [2]
       call     print_nl


! Get video-card data:

    mov    ah,#0x0f
    int    0x10
    mov    [4],bx        ! bh = display page
    mov    [6],ax        ! al = video mode, ah = window width


msg1:
    .byte 13,10
    .ascii "Now we are in SETUP ..."
    .byte 13,10,13,10

memory_size:
    .byte 13,10
    .ascii "memery size: "

print_hex:

       mov bp,sp
       mov     cx,#4
       mov      dx,(bp)
print_digit:
       rol   dx,#4
       mov   ax,#0xe0f
       and     al,dl
       add   al,#0x30
       cmp   al,#0x3a
       jl  outp
       add al,#0x07
outp:
        int  0x10
        loop  print_digit
         ret
print_nl:
       mov   ax,#0xe0d
       int     0x10
       mov    al,#0xa
       int  0x10
       ret

.text
endtext:
.data
enddata:
.bss
endbss:

发表评论

电子邮件地址不会被公开。 必填项已用*标注