交流
商城
MCN
登入
注册
首页
提问
分享
讨论
建议
公告
动态
发表新帖
发表新帖
7 bios预制中断
分享
未结
0
2784
李延
LV6
2022-06-24
悬赏:20积分
# 1 说明 前面我们介绍了中断机制,在我们启动机器时,bios会预置一些中断,帮助我们在引导程序中调用硬件。我们将主要内容进行介绍。 这些中断一般只在引导程序中调用,在之后我们都会覆盖bios的中断向量表。所以只需了解即可。 # 2 中断向量表 [bios中断.pdf](https://www.lioyan.cn/data//bios中断.pdf) 这里我们主要介绍 - 0x10 显示相关的中断 - 0x13磁盘相关的中断 # 3 0x10 中断 0x10 是关于 屏幕显示相关中断,在之前我们已经使用它在屏幕打印了hellow word。 这次我们将它封装为一个方法进行调用 ```asm .code16 .global _start .equ BOOTSEG, 0x07c0 # original address of boot-sector _start: mov $BOOTSEG,%ax mov %ax,%es mov %ax,%ss mov %ax,%ds mov $0x400,%sp # 设置栈指针 mov $14,%cx mov $msg1,%bx call print mov $14,%cx mov $msg2,%bx call print ret # 打印字符串函数,bx 传输字符串地址,cx 传输字符串长度 print: push %bx # 两个参数入栈 push %cx # 获取 光标位置,会被保存在bx寄存器中 mov $0x03, %ah xor %bh, %bh int $0x10 # 打印字符 pop %cx # 从栈中取出参数 pop %bp mov $0x0007, %bx mov $0x1301, %ax int $0x10 # 将光标移动到下一行的首列 mov $0,%dl add $1, %dh mov $0x02, %ah int $0x10 ret msg1: .string "Hello, World1!" msg2: .string "Hello, World2!" .org 510 boot_flag: .word 0xAA55 ``` 结果:  # 4 0x13中断 0x13 是关于磁盘的操作。可以读写磁盘内容。我们本节使用它对磁盘进行读取。 首先我们用上一节的打印函数写一段代码 ```asm .code16 .global _start .equ BOOTSEG, 0x07c0 # original address of boot-sector _start: mov $BOOTSEG,%ax mov %ax,%es mov %ax,%ss mov %ax,%ds mov $0x400,%sp # 设置栈指针 mov $18,%cx mov $attachment_msg1,%bx call print mov $18,%cx mov $attachment_msg2,%bx call print ret # 打印字符串函数,bx 传输字符串地址,cx 传输字符串长度 print: push %bx # 两个参数入栈 push %cx # 获取 光标位置,会被保存在bx寄存器中 mov $0x03, %ah xor %bh, %bh int $0x10 # 打印字符 pop %cx # 从栈中取出参数 pop %bp mov $0x0007, %bx mov $0x1301, %ax int $0x10 # 将关闭移动到下一行的首列 mov $0,%dl add $1, %dh mov $0x02, %ah int $0x10 ret msg1: .string "Hello, World1!" msg2: .string "Hello, World2!" .org 510 boot_flag: .word 0xAA55 attachment_msg1: .string "attachment print1!" attachment_msg2: .string "attachment print2!" ``` 我们看到这里我们打印了attachment_msg1、attachment_msg2 函数,但这两个函数是在512字节后面声明的,应该不会被加载到内存中。我们看一下执行结果  我们看到果然是两个空字符串。所以这里就需要我们字节将这两个字符读取出来。 ```asm .code16 .global _start .equ BOOTSEG, 0x07c0 # original address of boot-sector .equ BOOTSEG, 0x07c0 # original address of boot-sector _start: mov $BOOTSEG,%ax mov %ax,%es mov %ax,%ss mov %ax,%ds mov $0x400,%sp # 设置栈指针 mov $0x0000, %dx # drive 0, head 0 mov $0x0002, %cx # sector 2, track 0 mov $0x0400, %bx # 将读取的内容放到栈后面 .equ AX, 0x0201 mov $AX, %ax # al 读取1个扇区 int $0x13 # read it mov $18,%cx mov $0x400,%bx call print mov $18,%cx mov $0x413,%bx call print ret # 打印字符串函数,bx 传输字符串地址,cx 传输字符串长度 print: push %bx # 两个参数入栈 push %cx # 获取 光标位置,会被保存在bx寄存器中 mov $0x03, %ah xor %bh, %bh int $0x10 # 打印字符 pop %cx # 从栈中取出参数 pop %bp mov $0x0007, %bx mov $0x1301, %ax int $0x10 # 将关闭移动到下一行的首列 mov $0,%dl add $1, %dh mov $0x02, %ah int $0x10 ret msg1: .string "Hello, World1!" msg2: .string "Hello, World2!" .org 510 boot_flag: .word 0xAA55 attachment_msg1: .string "attachment print1!" attachment_msg2: .string "attachment print2!" ``` 结果 
回帖
消灭零回复
提交回复
热议榜
java 相关知识分享
8
好的程序员与不好的程序员
6
写给工程师的十条精进原则
5
spring boot以jar包运行配置的logback日志文件没生成
5
一步一步分析SpringBoot启动源码(一)
5
MockMvc测试
5
【吐槽向】是不是有个吐槽的板块比较好玩
4
logstash jdbc同步mysql多表数据到elasticsearch
3
IntelliJ IDEA 优质License Server
3
.gitignore忽略规则
3
SpringBoot启动源码分析
3
一步一步分析SpringBoot启动源码(三)
3
2
一步一步分析SpringBoot启动源码(二)
2
积分不够将无法发表新帖
2
官方产品
Meta-Boot - 基于MCN
MCN - 快速构建SpringBoot应用
微信扫码关注公众号