“操作系统与Linux内核导读(北京航空航天大学)”实验报告

操作系统的引导

本地环境配置失败了。

实验目标

了解操作系统的引导启动过程。

回答问题

  1. 启动的时候必须以 16 位模式(模拟 8086)启动,然后才能切换到 32 位保护模式(和 64 位长模式)。

    改进方法的话,可以让 CPU 在启动时就以 32 / 64 位实模式启动,然后在进入操作系统之后切换到保护模式。

修改 bootsect.s

图片描述

图片描述

图片描述

可以看见启动信息修改成功了

图片描述

从这里往后的实验和前面的实验不是同一天做的,所以之前改的自定义启动信息没了

输出环境信息

    
! print stuff
! cursor
    mov ax, cs
    mov es, ax
    mov bp, #msg_cursor
    mov cx, #14
    call puts
    mov dx, [0]
    call print_hex
    call new_line

! memory
    mov bp, #msg_memory
    mov cx, #15
    call puts
    mov dx, [2]
    call print_hex
    mov bp, #msg_kib
    mov cx, #3
    call puts
    
! cylinder
    mov bp, #msg_cylinders
    mov cx, #12
    call puts
    mov dx, [4]
    call print_hex
    
! heads
    mov bp, #msg_heads
    mov cx, #8
    call puts
    mov dx, [6]
    call print_hex
    
! sectors
    mov bp, #msg_sectors
    mov cx, 10
    call puts
    mov dx, [12]
    call print_hex

! halt here
halt:
    jmp halt
    
msg_cursor:
    ! 14 bytes
    .byte 13,10
    .ascii "Cursor pos: "
msg_memory:
    ! 15 bytes
    .byte 13,10
    .ascii "Memory size: "
msg_cylinders:
    ! 12 bytes
    .byte 13,10
    .ascii "Cylinder: "
msg_heads:
    ! 8 bytes
    .byte 13,10
    .ascii "Head: "
msg_sectors:
    ! 10 bytes
    .byte 13,10
    .ascii "Sector: "
msg_kib:
    ! 3 bytes
    .ascii "KiB"

! print    a string in memory
! cx    string length
! es:bp    string position
puts:
    push ax
    push bx
    push dx
    push cx

    mov ah, #0x03
    xor bh, bh
    int 0x10
    pop cx
    mov bx, #0x0007
    mov ax, #0x1301
    int 0x10
    pop dx
    pop bx
    pop ax
    ret
    

! print a 4-byte hexadecimal number located at dx
! does things like this:
! 
! dx |--------|--------|
!     ^^^^ Print these 4 bits
!    <---| shift left 4 bits every time
print_hex:
    ! push used registers
    push ax
    push bx
    push cx
    
    mov cx, #4
    ! initialize interrupt params
    mov bx, #0x01f0
    mov ah, #0x0e
    
print_digit:
    mov al, dh
    and al, #0xf0
    shr al, #4
    add al, #0x30
    cmp al, #0x3a
    jl print_digit_p
    add al, #0x07
print_digit_p:
    int 0x10
    shl dx, #4
    
    loop print_digit

    pop cx
    pop bx
    pop ax
    ret

new_line:
    push ax
    mov ax, #0x0e0d
    int 0x10
    mov al, #0x0a
    int 0x10
    pop ax
    ret
copy

图片描述

输出截图,试验机之后卡住了所以没办法把 "S" 改成 "Sector"(……)

体会

  • x86 系统的引导启动受到很多历史遗留因素的制约(向前兼容,向前兼容.jpg),因此过程比较繁琐。
  • 汇编调试好难。
最新评论
暂无评论~