美文网首页
给i386写驱动 -2

给i386写驱动 -2

作者: 少女白洁 | 来源:发表于2019-03-11 02:51 被阅读0次

https://arjunsreedharan.org/post/82710718100/kernels-101-lets-write-a-kernel
神文档,可操作
写一下这个文档的理解过程

**How does an x86 machine boot**
Most registers of the x86 CPU have well defined values after power-on. The Instruction Pointer (EIP) register holds the memory address for the instruction being executed by the processor. EIP is hardcoded to the value **0xFFFFFFF0**. Thus, the x86 CPU is hardwired to begin execution at the physical address 0xFFFFFFF0\. It is in fact, the last 16 bytes of the 32-bit address space. This memory address is called reset vector.

商店以后,特别特殊的(E)IP寄存器,它上电以后固定是一堆(7个)F跟一个0,
上电以后IP从这里开始,那也就是只给留了16Byte的32位空间(每个Byte32位)呀,
这也就够一个跳转的,也就是reset跳转,这个七个f一个0就叫reset vector
Now, the chipset’s memory map makes sure that 0xFFFFFFF0 is mapped to a certain part of the BIOS, not to the RAM. Meanwhile, the BIOS copies itself to the RAM for faster access. This is called shadowing. The address 0xFFFFFFF0 will contain just a jump instruction to the address in memory where BIOS has copied itself.
既然这样,主板厂商在做BIOS的时候第一件事儿就是把它的代码复制到RAM上,这个过程叫Shadowing。
那七F一0地址就特别重要,基本一定BIOS复制过来的代码里,这个位置肯定是一个跳转呗。
Thus, the BIOS code starts its execution. BIOS first searches for a bootable device in the configured boot device order. It checks for a certain magic number to determine if the device is bootable or not. (whether bytes 511 and 512 of first sector are 0xAA55)
从七F一0跳转一下,跳到BIOS代码开始的地方,BIOS就这么跑起来了,
这时候BIOS就去找引导设备了,挨个存储设备看引导扇区,也就是它们的0扇区
Once the BIOS has found a bootable device, it copies the contents of the device’s first sector into RAM starting from physical address 0x7c00; and then jumps into the address and executes the code just loaded. This code is called the bootloader.
在哪个设备上看到0xAA55了,那就牛逼了,可以把这个扇区复制到RAM内存的0x7C00地址傻瓜,写成32位的话,其实是0x00007c00。
之后跳到这个7c00开始执行代码,这种占用一个扇区大小的代码叫bootloader
The bootloader then loads the kernel at the physical address 0x100000. The address 0x100000 is used as the start-address for all big kernels on x86 machines.
这个一扇区的代码,会把内核kernel加载到物理地址0x10 0000,这个地址不就是高位2低位0咩
据说在所有的大内核系统里面,都喜欢用这个地址来作为开始地址,可能也是IBM规定的
All x86 processors begin in a simplistic 16-bit mode called real mode. The GRUB bootloader makes the switch to 32-bit protected mode by setting the lowest bit of CR0 register to 1. Thus the kernel loads in 32-bit protected mode.
上电以后,都是16比特的实模式,可以通过grub来配置成保护模式,
做法就是把CR0的值配置成1,这样一整加载内核的时候就是按照32位加载了
Do note that in case of linux kernel, GRUB detects linux boot protocol and loads linux kernel in real mode. Linux kernel itself [makes the switch] to protected mode.
Linux的做法是,grub检测到启动协议,之后用16位的实模式来加载内核,
之后内核运行起来了,由Linux内核来切换到保护模式

话说这样有啥好处呀

相关文章

  • 给i386写驱动 -2

    https://arjunsreedharan.org/post/82710718100/kernels-101-...

  • 给i386写驱动 -1

    几个学习链接:https://www.cnblogs.com/LexMoon/p/How_to_Make_a_Co...

  • Ubuntu 卸载MySQL

    环境 Ubuntu 16.04 i386, MySQL 5.7.13 1.清除MySQL相关 2.重启Ubunt...

  • 静态包 重打包

    解包、打包步骤: 创建临时文件夹,用于存放解压后的.o文件,如i386:mkdir i386 取出i386平台的包...

  • Apple-Clang编译器-arch参数

    无参数clang -S test2.c -o test2.s i386clang -arch i386 -S t...

  • 使用PHP控制浏览器动作

    系统环境: Mac 原理: 1:使用php语言写控制脚本 2:脚本与chrome驱动(chromedriver)程...

  • 2020-11-16

    新建驱动image.png 给边缘设备分配驱动image.png 给该驱动分配设备image.png 安装边缘设备...

  • Linux驱动模块编译

    Linux 对大多数的驱动作了分类:块设备驱动、网络驱动、I 2 C 驱动、USB 驱动、SPI 驱动、音频驱动等...

  • framework 学习笔记18. input输入事件番外2(整

    1. 介绍:直入主题,对于安卓输入事件的描述可以理解为:(1)硬件捕捉并反馈事件给驱动;(2)通过监听(读取)驱动...

  • Struts2笔记

    Struts2笔记——Struts2的模型驱动(ModelDriven) 1. 模型驱动: 模型驱动是使用...

网友评论

      本文标题:给i386写驱动 -2

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