内核编写内核编写
🈲

内核编写

Last edited time
Mar 19, 2023 08:25 AM
Created
Apr 11, 2022 05:38 AM
Tags
 
加电复位后,ROM-BIOS将读取硬盘0面0道1扇区(主引导扇区Main Boot Sector,MBR),共512字节

8086 CPU(实模式)

20根地址线:0x00000~0xFFFFF
DRAM:0x00000~0x9FFFF
ROM:0xF0000~0xFFFFF
外围设备:0xA0000~0xEFFFF
起始地址
结束地址
大小
用途
FFFFF
16B
BIOS入口地址,此地址也属于BIOS区域
FFFEF
64KB-16B
BIOS区域
EFFFF
160KB
映射硬件适配器的ROM或内存映射式I/O
C7FFF
32KB
显示器适配BIOS
BFFFF
32KB
用于文本模式显示适配器
B7FFF
32KB
用于黑白显示器适配器
AFFFF
64KB
用于彩色显示器适配器
9FFFF
1KB
EBDA,扩展BIOS区域
9FBFF
约608KB
可用区域
07DFF
512B
MBR被BIOS加载到此处
07BFF
约30KB
可用区域
004FF
256B
BIOS Data Area (BIOS数据区)
003FF
1KB
interrupt Vector Table(中断向量表)
 
reset
CS=0xFFF IP=0x0000
指向物理地址:0xFFFF0 (ROM)
 
指令指向顺序:低地址到高地址推进
 
 
 

ROM

硬件诊断、检测和初始化。
提供一套软件例程,让人民不必了解硬件的细节的情况控制I/O设备
基本输入输出系统(Base Input & Output System,BIOS)
 
读取主引导扇区到 0x0000:0x7c00 (0x07c00) 并jmp

实模式

  1. 主引导扇区
    1. 512字节 最后两个字节应当是0x55和0xAA
      jmp 0x0000:0x7c00 ROM-BIOS将引导扇区加载到此处
     

    显卡和显存

    1. 图形模式
    1. 文本模式(80x25 25行,80字符) 0xB8000~0xBFFFF
     

    寄存器

    标志寄存器FLAGS

     

    相关工具

     

    Bochs

    Netwide Assembler(NASM)

    是一款基于英特尔x86 架构的汇编与反汇编工具
    nasm xx.asm -o xx.o 汇编文件编译成二进制文件
     
    usage: nasm [-@ response file] [-o outfile] [-f format] [-l listfile]
                [options...] [--] filename
        or nasm -v   for version info
    
        -t          assemble in SciTech TASM compatible mode
        -g          generate debug information in selected format
        -E (or -e)  preprocess only (writes output to stdout by default)
        -a          don't preprocess (assemble only)
        -M          generate Makefile dependencies on stdout
        -MG         d:o, missing files assumed generated
        -MF <file>  set Makefile dependency file
        -MD <file>  assemble and generate dependencies
        -MT <file>  dependency target name
        -MQ <file>  dependency target name (quoted)
        -MP         emit phony target
    
        -Z<file>    redirect error messages to file
        -s          redirect error messages to stdout
    
        -F format   select a debugging format
    
        -I<path>    adds a pathname to the include file path
        -O<digit>   optimize branch offsets
                    -O0: No optimization
                    -O1: Minimal optimization
                    -Ox: Multipass optimization (default)
    
        -P<file>    pre-includes a file
        -D<macro>[=<value>] pre-defines a macro
        -U<macro>   undefines a macro
        -X<format>  specifies error reporting format (gnu or vc)
        -w+foo      enables warning foo (equiv. -Wfoo)
        -w-foo      disable warning foo (equiv. -Wno-foo)
    
    --prefix,--postfix
      this options prepend or append the given argument to all
      extern and global variables
    
    Warnings:
        error                   treat warnings as errors (default off)
        macro-params            macro calls with wrong parameter count (default on)
        macro-selfref           cyclic macro references (default off)
        macro-defaults          macros with more default than optional parameters (default on)
        orphan-labels           labels alone on lines without trailing `:' (default on)
        number-overflow         numeric constant does not fit (default on)
        gnu-elf-extensions      using 8- or 16-bit relocation in ELF32, a GNU extension (default off)
        float-overflow          floating point overflow (default on)
        float-denorm            floating point denormal (default off)
        float-underflow         floating point underflow (default off)
        float-toolong           too many digits in floating-point number (default on)
        user                    %warning directives (default on)
        lock                    lock prefix on unlockable instructions (default on)
        hle                     invalid hle prefixes (default on)
    
    response files should contain command line parameters, one per line.
    
    For a list of valid output formats, use -hf.
    For a list of debug formats, use -f <form> -y.
     

    dd Convert and copy a file

    编程语言支持

     

    Loading Comments...