30天自制操作系统-Hello OS

0.准备

  • 代码使用的书本中的,使用8G的fat32格式u盘 ,不过对于Hello OS程序来言,开头的文件格式不需要也可以,只不过调用bios的输出字符函数(int 0x10)。并未读取u盘内的数据。
  • fat32文件格式的书写,可以使用winhex工具,先点击工具->打开磁盘->选择你的u盘。然后再查看->模板管理器->选择Boot Sector FAT32->应用。得到u盘fat32文件格式,里面的一些具体项可以百度得到,这里提供一篇博客写得比较详细的:FAT32文件系统学习(1) —— BPB的理解

1. helloOS的代码:

; haribote-ipl
; TAB=4
 
		ORG		0x7c00
 
		JMP	short	entry
		nop
		DB		'MSDOS5.0'	
		DW		512	
		DB 		8
		DW		36
		DB		2
		DW		0
		DW		0
		db 		0xf8
		dw		0
		dw		63
		dw		255
		dd		1	
		dd		15727634
		dd 		15330	
		dw		0
		dw		0
		dd		2
		dw		1
		dw		6
		times	12	db 0
		db		80h
		db		0
		db		29h
		dd		18467
		DB		"NO NAME    "	
		DB		"FAT32   "
entry:
		MOV		AX,0			
		MOV		SS,AX
		MOV		ES, AX
		MOV		SP,0x7c00
		MOV		DS,AX
 
 
		MOV		SI,msg
		call 		putloop
		jmp		fin
putloop:
		MOV		AL,[SI]
		ADD		SI,1			
		CMP		AL,0
		JE		over	
		MOV		AH,0x0e			
		MOV		BX,15			
		INT		0x10			
		JMP		putloop
over:
		ret
fin:
		HLT					
		JMP		fin	
msg:
		DB		0x0a, 0x0a	
		DB		"hello os"
		DB		0x0a			
		DB		0
 
;		RESB		0x7dfe-$		
		times 		510 - ($ - $$) db 0
		DB		0x55, 0xaa

再windows上用nasm工具生成ipl10.bin

nasm ipl10.nas -o ipl10.bin

可以使用winhex查看生成的二进制信息:

使用dd工具将ipl10.bin写入u盘,百度搜索dd for windows即可下载。

首先获得u盘在windows下的信息,如下图:

图中的removeable to media就是我的u盘了

然后使用命令将ipl10.bin写入u盘,重启F12(我的笔记本电脑,每个人的电脑都不一样)选择u盘启动

dd if=helloOS\ipl10.bin of=\\.\Volume{19572513-924e-11e8-afeb-806e6f6e6963}

2. 结果

ubuntu:

对于只用启动区显示hello os完全不需要fat32文件格式,只需如下代码:

; haribote-ipl
; TAB=4

		ORG		0x7c00

		JMP	short	entry
entry:
		MOV		AX,0			
		MOV		SS,AX
		MOV		ES, AX
		MOV		SP,0x7c00
		MOV		DS,AX


		MOV		SI,msg
		call 		putloop
		jmp		fin
putloop:
		MOV		AL,[SI]
		ADD		SI,1			
		CMP		AL,0
		JE		over	
		MOV		AH,0x0e			
		MOV		BX,15			
		INT		0x10			
		JMP		putloop
over:
		ret
fin:
		HLT					
		JMP		fin	
msg:
		DB		0x0a, 0x0a	
		DB		"hello os"
		DB		0x0a			
		DB		0

;		RESB		0x7dfe-$		
		times 		510 - ($ - $$) db 0
		DB		0x55, 0xaa

对于intel格式汇编,在ubuntu中使用nasm编译器

nasm hellos.nas -o hellos.bin

接着用fdisk -l查看u盘的设备号,我的是/dev/sdb4,就用dd写入u盘

dd if=helloos.bin of=/dev/sdb4 bs=512 count=1

重启电脑,选择u盘启动,屏幕显示hello os!

  • 2
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值