Chinaunix首页 | 论坛 | 博客
  • 博客访问: 371280
  • 博文数量: 80
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1767
  • 用 户 组: 普通用户
  • 注册时间: 2013-01-24 16:18
个人简介

为啥不能追求自己的爱好一辈子呢

文章分类

全部博文(80)

文章存档

2017年(1)

2015年(2)

2014年(18)

2013年(59)

分类: C/C++

2013-01-29 11:01:55

 引导操作系统的grub可以与操作系统写在一起,前些日子看了30天自制操作系统之后,简单的看了一下光盘的自制操作系统的用法,我没有用它自带的软件来编译这个程序。我用的流通性更大的nasm,在linux下可以用dd把内容copy到虚拟光驱的第一个扇区,在windows下我用了WinImage(英文版),在Image菜单下,有一个boot sector properties里面点击[open]把 用nasm编译好的程序载入进去。保存成img或者ima文件就可以拉。

    然后可以用virtualbox或者vm载入这个虚拟镜像就可以看到神奇的事情发生啦。

以下是代码:欢迎爱好操作系统的人一同讨论哈,我也是菜鸟。


点击(此处)折叠或打开

  1. ;----------------------------------------------------------------------
  2. ; 简单的打印一个H
  3. ;----------------------------------------------------------------------
  4.  org 0x7c00 ;bios 将会把程序load到内存的这个位置。
  5. ; 这是入口函数
  6. entry:
  7.  jmp short begin ; jump over the DOS boot record data

  8. ; ----------------------------------------------------------------------
  9. ; 下面是标准的磁盘属性
  10. ; ----------------------------------------------------------------------
  11. DB      0x90            ;0002h - 0EH for INT13 AH=42 READ
    DB      "HARIBOTE"      ;0003h - OEM name & DOS version (8 chars)
    DW      512             ;000Bh - Bytes/sector
    DB      1               ;000Dh - Sectors/cluster
    DW      1               ;000Eh - Reserved (boot) sectors
    DB      2               ;0010h - FAT copies 
    DW      224             ;0011h - Root directory entries 
    DW      2880            ;0013h - Sectors in volume, < 32MB 
    DB      0xf0            ;0015h - Media descriptor 
    DW      9               ;0016h - Sectors per FAT 
    DW      18              ;0018h - Sectors per track 
    DW      2               ;001Ah - Number of Heads 
    DD      0               ;001Ch - Hidden sectors 
    DD      2880            ;0020h - Total number of sectors 
    DB      0,0,0x29        ;0024h - Physical drive no. 
                            ;0025h - Reserved (FAT32) 
                            ;0026h - Extended boot record sig 
    DD      0xffffffff      ;0027h - Volume serial number (random) 
    DB      "HARIBOTEOS "   ;002Bh - Volume label (11 chars) 
    DB      "FAT12   "      ;0036h - File System ID (8 chars) 
    RESB    18              ; 

  12. ;------------------------------------------------------------------------

  13. ; --------------------------------------------
  14. ; 调用bios中断打印字母
  15. ; --------------------------------------------
  16. ; boot code begins at 0x003E
  17. begin:
  18.  mov ah, 0x0e                 ; Function to print a character to the screen
  19.  mov al, 'H'                  ; Which character to print
  20.  mov bl, 7                    ; color/style to use for the character
  21.  int 0x10                     ; print the character
  22. hang:
  23.  jmp hang                     ; just loop forever.
  24. ;---------------------------------------------需要一个扇区的内容,如果不够填充0,最后两个字节是固定的
  25. size equ $ - entry
  26. %if size+2 > 512
  27.   %error "code is too large for boot sector"
  28. %endif
  29.  times (512 - size - 2) db 0
  30.  db 0x55, 0xAA 

编译逻辑:
1. 使用nasm编译上面的代码:

点击(此处)折叠或打开

  1. nasm -o bootloader.bin bootloader.asm
2. 打开winImage, File->New 创建一个img,点击save按钮,save例如桌面叫做 simple.ima.
3. 点击 Image->boot section properties->open 把刚刚生成的bootloader.bin加载进去点击OK。出来点击保存,把刚才的操作保存住。
4.打开virtualbox,点击新建,名称填入例如os,类型选择linux,版本选择Other Linux(32-bit),点击下一步,后边选择不添加
  虚拟磁盘。然后点击创建。
5. 在生成的os,右键选择设置,选择存储,在中间下面有一个+号的,添加存储控制器,选择添加软盘控制器。
6.在新出现的 控制器: Floppy   右侧点击+选择磁盘,把生成的simple.ima添加进去。点击确定。

7.双击os,就可以看到奇迹发生了。


阅读(3962) | 评论(0) | 转发(0) |
6

上一篇:没有了

下一篇:自制操作系统之三(第一个程序)

给主人留下些什么吧!~~