Bochs源码分析 - 11:《X86探索及编程》代码初步解释

本文详细分析了《X86探索及编程》中的boot.asm源码,包括org指令、clear_screen函数、字符串与数组的定义、print_message函数和load_module代码。通过解析汇编代码,了解如何在Bochs中模拟执行,并探讨了int 0x10中断、LBA与CHS模式转换以及配置文件的细节。
摘要由CSDN通过智能技术生成

前言

        现在我们来阅读邓志老师的《x86/x64体系探索及编程》,边阅读边将其代码放到bochs中运行,然后观察bochs的CPU是如何来模拟的。现在我们来详细分析ex3-2目录里面的内容。

boot.asm 代码解读

        自己在工作中经常看汇编代码,但是写汇编代码真的很少写过,我们现在一边分析着这段boot汇编代码一边回顾其如何编写。

; Int 19h 加载 sector 0 (MBR) 进入 BOOT_SEG 段, BOOT_SEG 定义为 0x7c00
         
        org BOOT_SEG
        
start:
        cli

; enable a20 line
        FAST_A20_ENABLE
        
        sti
        
; set BOOT_SEG environment
        mov ax, cs
        mov ds, ax
        mov ss, ax
        mov es, ax
        mov sp, BOOT_SEG                        ; 设 stack 底为 BOOT_SEG
        
        call clear_screen
        mov si, hello
        call print_message
        
        mov si, 20                              ; setup 模块在第20号扇区里
        mov di, SETUP_SEG - 2
        call load_module                        ; 使用 load_module() 读多个扇区
        
        mov si, SETUP_SEG
        call print_message
        
        mov si, word [load_message_table + eax * 2]
        call print_message
        
next:        
        jmp $

org 解读

        The bin format provides an additional directive to the list given in chapter 7ORG. The function of the ORG directive is to specify the origin address which NASM will assume the program begins at when it is loaded into memory.

For example, the following code will generate the longword 0x00000104:

        org     0x100 
        dd      label 
label:
</
Chapter 1 x86 体系结构与PC 系统概要.....................................1 1.1 x86 CPU 结构...............................................................................................................1 1.1.1 冯诺依曼架构和CISC 指令集......................................................................1 1.1.2 CPU 结构........................................................................................................1 1.1.3 CPU 工作模式................................................................................................2 1.2 x86 体系结构概览........................................................................................................3 1.3 PC 系统.........................................................................................................................5 1.3.1 PC 系统概述...................................................................................................5 2.3.2 总线拓扑.........................................................................................................6 2.3.3 存储器与I/O 编址.........................................................................................6 2.3.4 关于系统的启动与引导.................................................................................8 Chapter 2 Bochs 工程概述....................................................... 11 2.1 开源项目Bochs 介绍.................................................................................................11 2.2 版本2.2.1 源码组织..................................................................................................11 2.3 工程类结构.................................................................................................................12 2.4 主体框架结构分析.....................................................................................................13 2.4.1 Bochs 工程中的重要类................................................................................13 (1) VM 控制台界面类.............................................................................................13 (2) CPU 模拟............................................................................................................14 (3) Memory 模拟......................................................................................................14 (4).I/O device 模拟...................................................................................................15 2.4.2 入口函数main()及Win32 Gui 初始化........................................................15 2.5 Bochs 的工作方式......................................................................................................18 Chapter 3 CPU 类的源码分析...................................................20 3.1 CPU 类概述................................................................................................................20 3.1.1 CPU 逻辑结构框图......................................................................................20 3.1.2 类BX_CPU_C 成员归纳.............................................................................20 3.2 类BX_CPU_C 源码分析..........................................................................................21 3.2.1 CPU 特性声明..............................................................................................21 3.2.2 类bxInstruction_c 成员分析........................................................................22 3.2.3 类BX_CPU_C 源码注释.............................................................................22 3.3 通用寄存器.................................................................................................................29 3.3.1 数据结构与注释...........................................................................................29 3.3.2 通用寄存器归纳...........................................................................................30 3.4 段寄存器、全局寄存器GDI 和IDT ........................................................................31 3.4.1 数据结构与注释...........................................................................................31 3.4.2 段寄存器结构分析.......................................................................................33 3.5 CPU 状态字EFLAGS................................................................................................35 3.5.1 数据结构与注释...........................................................................................35
Bochs项目源码分析与注释 Table of Content Chapter 1 x86 体系结构与 PC 系统概要1 1.1 x86 CPU 结构1 1.1.1 冯诺依曼架构和CISC 指令集 1.1.2 CPU 结构 1.1.3 CPU 工作模式 1.2 x86 体系结构概览 1.3 PC 系统 1.3.1 PC 系统概述 2.3.2 总线拓扑 2.3.3 存储器与I/O 编址 2.3.4 关于系统的启动与引导 Chapter 2 Bochs 工程概述 2.1 开源项目Bochs 介绍........................................11 2.2 版本2.2.1 源码组织..................................................................................................11 2.3 工程类结构.................................................................................................................12 2.4 主体框架结构分析.....................................................................................................13 2.4.1 Bochs 工程中的重要类................................................................................13 (1) VM 控制台界面类.............................................................................................13 (2 ) CPU 模拟............................................................................................................14 (3) Memory 模拟......................................................................................................14 (4 ).I/O device 模拟...................................................................................................15 2.4.2 入口函数main()及Win32 Gui 初始化........................................................15 2.5 Bochs 的工作方式......................................................................................................18 Chapter 3 CPU 类的源码分析...................................................20 3.1 CPU 类概述................................................................................................................20 3.1.1 CPU 逻辑结构框图......................................................................................20 3.1.2 类BX_CPU_C 成员归纳.............................................................................20 3.2 类BX_CPU_C 源码分析..........................................................................................21 3.2.1 CPU 特性声明..............................................................................................21 3.2.2 类bxInstruction_c 成员分析........................................................................22 3.2.3 类BX_CPU_C 源码注释.............................................................................22 3.3 通用寄存器.................................................................................................................29 3.3.1 数据结构与注释...........................................................................................29 3.3.2 通用寄存器归纳...........................................................................................30 3.4 段寄存器、全局寄存器GDI 和IDT ........................................................................31 3.4.1 数据结构与注释...........................................................................................31 3.4.2 段寄存器结构分析.......................................................................................33 3.5 CPU 状态字EFLAGS................................................................................................35 3.5.1 数据结构与注释...........................................................................................35 Understanding the source code of bochs
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值