美文网首页
linux-0.11 源码分析1

linux-0.11 源码分析1

作者: 滩主 | 来源:发表于2019-04-11 16:56 被阅读0次

项目地址

https://github.com/yuanxinyu/Linux-0.11

反汇编命令

alias lb='od -t x1 -A n'
alias obj16='objdump -d -m i8086'
alias obj32='objdump -d -m i386'
alias bin16='objdump -D -b binary -m i8086'
alias bin32='objdump -D -b binary -m i386'
objcopy --dump-section .text=kernel.text kernel.bin

gdb

make debug
gdb -ex 'set architecture i8086' -ex 'target remote localhost:1234' -ex 'b *0x7c00'
  1. hardware set cs 0xf000 ip 0xfff0 that is the address of BIOS


    boot.png
地址分布
  • 0x7c00 31KB
  • 0x10000 64KB
  • 0x90000 576KB

gdb kernel

gdb tools/system
set architecture i8086
br *0x7c00
c
x/i $eip

# 单步调试
stepi
nexti

x/32b $cs*16+$pc
i r
# 查看内存地址处的值
x/16x 0x90000

gdb -ex 'set architecture i8086' -ex 'target remote localhost:1234' -ex 'b *0x7c00' -ex 'c'

x/512x 0x7c00
x/2x 0x7c00+0x1fe

# 跳过bootsect和setup的5个扇区,看kernel
lb Image -j 2560 | head

comment

若需要从硬盘设备启动系统,那么通常需要使用其他多操作系统引导程序来引导系统加载。比如:Shoelace、LILO或Grub等多操作系统引导程序。此时bootsect.s所完成的任务会由这些程序来完成。bootsect程序就不会被执行了。因为如果从硬盘启动系统,那么通常内核映像文件Image会存放在活动分区的根文件系统中。因此你就需要知道内核映像文件Image处于文件系统中的位置以及是什么文件系统。即你的引导扇区程序需要能够识别并访问文件系统,并从中读取内核映像文件

16bit 汇编

.code16
as --32 -o bootsect.o bootsect.s
ld -m elf_i386 -Ttext 0 -o bootsect bootsect.o
objcopy -R .pdr -R .comment -R.note -S -O binary bootsect
as --32 -o setup.o setup.s
ld -m elf_i386 -Ttext 0 -o setup setup.o
objcopy -R .pdr -R .comment -R.note -S -O binary setup


objcopy --dump-section .text=boot.text bootsect
head -c512 bootsect | md5sum

objcopy转换elf文件为bin文件
objcopy -O binary -R .note -R .comment -S boot.elf boot.bin
#接着将 boot.elf 转换为 boot.bin
#使用 -O binary (或--out-target=binary) 输出为原始的二进制文件
#使用 -R .note  (或--remove-section)    输出文件中不要.note这个section,缩小了文件尺寸
#使用 -S        (或 --strip-all)        输出文件中不要重定位信息和符号信息,缩小了文件尺寸
objcopy把一种目标文件中的内容复制到另一种类型的目标文件中

qemu -fda 1.img -hda los.img

unknow question

  • 内存分页
  • 根文件系统
  • 内核栈
  • gdb BIOS

史前文明(BIOS)

  • set cs ip
  • 16bit汇编 实模式寻址 cs:ip
  • 自检
  • 构建中断向量表(中断服务例程)
  • int 19h(Load Disk No. 0, track 0 of 1 sector into memory at 0x07C00)

BIOS AND OS Rule

  • OS designers have to put the starting program in the boot sector (0 side 0, track 1 in the floppy disk sectors); the remaining program can be loaded into memory in order
  • BIOS loading the boot sector into 0x07C00, regardless of what this sector really does. If there is an error, it only reports the mistake and does nothing

硬件 BIOS OS三者的关系

  • OS和BIOS作为软件必须依赖硬件实现自身功能
  • 有必要了解一下BIOS开创的史前文明,这里已经把硬件搞了一个遍?并且在内存约定区域做了很多标记,给OS使用
  • OS登上舞台后,利用BIOS之前的沉淀,快速上手,打通与硬件的各种交互机制

以硬盘设备为线索,搞懂操作系统从识别到建立复杂的设备管理机制

  • BIOS系统自检,如何识别硬盘设备?硬盘参数表,以及为内核做了哪些铺垫?0x41 0x46中断 ata 标准 搜索关键词:保护模式下读写磁盘
  • 内核如何接受设备管理,最原始的设备访问方式
  • 现代操作系统的设备管理,发展历程,为什么会这样

los目标

  • 支持时钟中断、键盘中断
  • 支持列出多个硬盘设备,支持硬盘读写,并统计耗时
    目前阻塞在启动盘上,开机dl寄存器的值很奇怪,怀疑是usb端口的问题,现在把机械硬盘重新插好,基于机械硬盘启动查看dl寄存器的值

相关文章

网友评论

      本文标题:linux-0.11 源码分析1

      本文链接:https://www.haomeiwen.com/subject/nmukfqtx.html