linux0.11源码阅读笔记1-启动流程-bootsect.s

一.概述:

源码阅读笔记是一个新的系列,也是自己在沉淀一段时间后的新发现,开始对linux底层的一次新探索。这个系列的每一节基本上都会是一个linux0.11的源代码文件,并附上我自己的理解与这些源码所涉及的知识点。本节的主角是linux0.11中涉及启动流程的部分,源代码部分是bootsect.s。

二.bootsect.s流程图与功能分析

这个流程图不是很严谨,因为ok_load_setup部分并不是一个独立的模块,里面又包含很多函数调用,故出现了多次。
这里写图片描述

bootsect.s的功能其实就是加载数据,将磁盘上的程序数据(启动程序,系统程序)加载到内存中,并在这个过程中对这1MB的内存进行规划,之后跳转到setup程序。

三.源代码分析

该部分知识点

1.理解BIOS所做的事情

将磁盘上0磁道0扇区的数据加载到内存0x07c0处,设置CS=0xFFFF,IP=0X0000

2.熟悉汇编

10号中断,13号中断

源代码部分”!”为linus当时的注释,”!!”为我为了自己理解所添加的注释

代码

1.初始化与start部分

该部分的内存变化
1)BIOS将代码加载到0x07c0处
这里写图片描述
2)执行start部分后的内存
这里写图片描述

!
! SYS_SIZE is the number of clicks (16 bytes) to be loaded.
! 0x3000 is 0x30000 bytes = 196kB, more than enough for current
! versions of linux
!
SYSSIZE = 0x3000
!
!   bootsect.s      (C) 1991 Linus Torvalds
!
! bootsect.s is loaded at 0x7c00 by the bios-startup routines, and moves
! iself out of the way to address 0x90000, and jumps there.
!
! It then loads 'setup' directly after itself (0x90200), and the system
! at 0x10000, using BIOS interrupts. 
!
! NOTE! currently system is at most 8*65536 bytes long. This should be no
! problem, even in the future. I want to keep it simple. This 512 kB
! kernel size should be enough, especially as this doesn't contain the
! buffer cache as in minix
!
! The loader has been made as simple as possible, and continuos
! read errors will result in a unbreakable loop. Reboot by hand. It
! loads pretty fast by getting whole sectors at a time whenever possible.

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

SETUPLEN = 4                ! nr of setup-sectors !!setup程序占用的扇区个数
BOOTSEG  = 0x07c0           ! original address of boot-sector   !!计算机启动的时候BIOS将bootsect加载到的内存区域
INITSEG  = 0x9000           ! we move boot here - out of the way !!我们将bootsect程序要移动到的内存其实地址
SETUPSEG = 0x9020           ! setup starts here                 !!setup程序开始的地方,简单计算下,9020H是段地址,转化成物理地址就是90200H也就是90000H+200H(512)
SYSSEG   = 0x1000           ! system loaded at 0x10000 (65536). !!系统加载到的内存其实地址
ENDSEG   = SYSSEG + SYSSIZE     ! where to stop loading         !!系统结束的内存地址

! ROOT_DEV: 0x000 - same type of floppy 
  • 4
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值