Win下操作系统快捷开发环境的搭建 0.00

Win下操作系统快捷开发环境的搭建

 视频 http://pan.baidu.com/s/1boDTQKB


https://pan.baidu.com/s/1aLr3G9RbGJowNuiMvpXD3Q

(新新链接,欢迎品尝!)

开发自己的操作系统内核,这个愿望我从上大学的时候就有了。可是一直到近几年,学习了川合秀实先生的《30天自制操作系统》一书,自己才觉得有了那么一点意思:其实开发操作系统内核也不算难吗!为什么以前没有这种感觉,而就在那一阵鼓捣他的那个系统的时候有了快感呢?其实自己还真的总结了一下,原来就是他那make run命令的功效了。于是自己突发奇想,也想在Win下搭建一个类似的开发环境。好了,我的废话已经够多的了,现在就把自己的Makefile呈现给大家吧。

# 我自己写的Makefile,呵呵,是不是挺蹩脚的,没办法水平有限了。

default :

nasm -f elf boot.asm -o boot.o

gcc -m32 -c -o kernel.o kernel.c

ld -T link.ld -m i386pe -nostdlib boot.o kernel.o -o kernel

objcopy -I pe-i386 -O elf32-i386 kernel

winmount -M "C:\Documents and Settings\Administrator\VirtualBox VMs\ll\NewVirtualDisk1.vdi"  -drv:Z

ping /n 10 127.0.0.1 > nul

copy kernel z:\.

ping /n 2 127.0.0.1 > nul

winmount -unmountall

  

run:

make default

start VirtualBox.exe

clean:

del *.o

del kernel

del *.bin

有了这个你也可以一键运行自己正在开发的内核,这里面与川合秀实先生最大的不同,相比看过他那本书的盆友们一定知道吧。对了就是没有使用自己写的启动引导程序,愿意很简单了,第一,我觉的自己水平有限,写的那个Bootloader连同跟grub相比,那简直就什么也不算,将来如果自己开发的真的很牛叉,也要用强大的引导程序的吗;第二,可以省略掉很多进入保护模式的汇编代码,这样就可以专注开发系统内核,而不比从自己写引导程序的时候就让开发操作系统内核的梦想挂了(外行热多年来自己的感受)。

文归正传,在运行上面的Make前,我们都需要做些什么准备呢。

1.一大堆软件的下载了

至少包括:一键U盘装系统、winmount、grub4dos、

Mingw、nasm、 VirtualBox。

2.安装这一大堆软件,并配置之,这主要是把每个软件的执行路径都加在系统的Path中(别告诉我不会哈)。

3.用一键U盘装系统制作一个启动U盘,然后在用启动U盘制作一个能启动的ISO文件,这个有点绕远,其实就是想在接下来的虚拟系统中,能用一键U盘装系统的工具集。

4.创建VirtualBox虚拟系统,虚拟的硬盘用.vdi格式的,这个不是必须,只是我觉得好用。

5.在虚拟硬盘上安装grub4dos

这个有点麻烦要详细的叙述一下

启动虚拟机,进入那个ISO的操作系统,也就用一键U盘装系统的那个iso做一个引导系统(如果不会使用虚拟机VirtualBox,网上有许多资料了,自己学习下吧),之前创建的vdi格式的虚拟硬盘上分一个Ntfs的分区,并格式化,这里用的DISKGENIUS.EXE,在一键u盘系统中有的。用Bootice(也在系统中)安装引导程序(这个很简单的,如果不会在网上查查吧),本人选择的是Nt5.0的,也就是Ntldr+boot.ini 把自己机子(不会用的win8+吧,那就上网上搜一下,下载之)次就用到了winmount了),打开这个软件,可写方式加载虚拟硬盘文件*.vdi,然后顺便把grldr+menu.lst拷贝到虚拟硬盘上

两个配置文件如下:不要害怕红的自己加上的

Boot.ini

[boot loader]

timeout=5

default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS

[operating systems]

multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Professional" /noexecute=optin /fastdetect

c:\grldr="Grub for Dos!"

 

Menu.lst

# This is a sample menu.lst file. You should make some changes to it.

# The old install method of booting via the stage-files has been removed.

# Please install GRLDR boot strap code to MBR with the bootlace.com

# utility under DOS/Win9x or Linux.

color blue/green yellow/red white/magenta white/magenta

timeout 10

default /default

default 5

title find and load NTLDR of Windows NT/2K/XP

fallback 1

find --set-root --ignore-floppies --ignore-cd /ntldr

map () (hd0)

map (hd0) ()

map --rehook

find --set-root --ignore-floppies --ignore-cd /ntldr

chainloader /ntldr

savedefault --wait=2

title find and load BOOTMGR of Windows VISTA

fallback 2

find --set-root --ignore-floppies --ignore-cd /bootmgr

map () (hd0)

map (hd0) ()

map --rehook

find --set-root --ignore-floppies --ignore-cd /bootmgr

chainloader /bootmgr

savedefault --wait=2

title find and load CMLDR, the Recovery Console of Windows NT/2K/XP

fallback 3

find --set-root --ignore-floppies --ignore-cd /cmldr

map () (hd0)

map (hd0) ()

map --rehook

find --set-root --ignore-floppies --ignore-cd /cmldr

chainloader /cmldr

#####################################################################

# write string "cmdcons" to memory 0000:7C03 in 2 steps:

#####################################################################

# step 1. Write 4 chars "cmdc" at 0000:7C03

write 0x7C03 0x63646D63

# step 2. Write 3 chars "ons" and an ending null at 0000:7C07

write 0x7C07 0x00736E6F

savedefault --wait=2

title find and load IO.SYS of Windows 9x/Me

fallback 4

find --set-root /io.sys

chainloader /io.sys

savedefault --wait=2

title My OS

 

root (hd0,0)

#  右边那个kernel是自己内核的名字,可以改动

kernel /kernel

title find and boot 0PE.ISO

fallback 5

find --set-root /0PE/0PE.ISO

map /0PE/0PE.ISO (0xff) || map --mem /0PE/0PE.ISO (0xff)

map --hook

chainloader (0xff)

savedefault --wait=2

title find and boot MicroPE.ISO

fallback 6

find --set-root /boot/MicroPE.ISO

map /boot/MicroPE.ISO (0xff) || map --mem /boot/MicroPE.ISO (0xff)

map --hook

chainloader (0xff)

savedefault --wait=2

title Parted Magic ISO

fallback 7

find --set-root /pmagic.iso

map /pmagic.iso (0xff) || map --mem /pmagic.iso (0xff)

map --hook

chainloader (0xff)

savedefault --wait=2

title Ultimate Boot CD ISO

fallback 8

find --set-root /ubcd.iso

map /ubcd.iso (0xff) || map --mem /ubcd.iso (0xff)

map --hook

chainloader (0xff)

savedefault --wait=2

title commandline

commandline

title floppy (fd0)

chainloader (fd0)+1

rootnoverify (fd0)

title back to dos

quit

title reboot

reboot

title halt

halt

title MAXDOS.IMG

find --set-root --ignore-floppies /boot/MAXDOS.IMG

map --mem /boot/MAXDOS.IMG (fd0)

map --hook

chainloader (fd0)+1

rootnoverify (fd0)

此时的系统就可以启动一下试试了,用时先把启动顺序改为硬盘就行了,不改也行,先启动那个一键启动盘,然后从中选择从硬盘启动。

Boot.asm kernel.c link.ld 这三个文件是从这篇文章(跟我一起写操作系统(二)——史上最简单的内核

,网上搜下就行了),前两个是内核文件,后一个是链接时用的,后一个应该可以改成ld -Ttext 0x100000  -m i386pe -nostdlib boot.o kernel.o -o kernel,

Boot.asm 红线处有改动否则win下无法链接成功

[GLOBAL start]

[EXTERN _kernel_main]         ; 内核入口函数, EXTERN表明此符号在外部定义

start:

  cli                        ; 禁用中断

  call _kernel_main           ; 调用内核入口函数

  jmp $                      ; 无限循环

  

猜你喜欢

转载自blog.csdn.net/weixin_39410618/article/details/75195181
今日推荐