文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>最简单的操作系统

最简单的操作系统

时间:2007-04-18  来源:mishuang

1. Makefile

all: boot head build

boot: boot.s
    as86 -o boot.o boot.s
    ld86 -o boot -d boot.o
   
head: head.s
    as86 -o head.o head.s
    ld86 -o head -d head.o
  
build: build.c boot head
    gcc -o build build.c
    ./build
  
clean:
    rm -f boot boot.o head head.o build image
 
2. boot.s

SYSSEG=0x1000
entry start
start:
   mov ax,#SYSSEG
   mov es,ax
   mov bx,#0
   mov dl,#0
   mov dh,#0
   mov ch,#0
   mov cl,#2
   mov al,#1
   mov ah,#2
   int 0x13
   jmpi 0,#SYSSEG

注:BIOS 0x13中断用法
ah=0x02 读磁盘扇区到内存
al=需读出扇区数
ch=磁盘柱面号低8位
cl=开始扇区(0-5);磁盘柱面号高2位(7-8)
dh=磁头号(若是硬盘最高位置为1)
ex:bx=数据缓冲区
在上面的例子中,cl=2,al=1也就是读磁盘第二扇区到0x1000:0

3. head.s

entry start
start:
   mov      ah,#0x03
   xor      bh,bh
   int      0x10
  
   mov      cx,#35
   mov      bx,#0x0007
   mov      bp,#msg
   mov      ax,#0x1301
   int      0x10
  
loop0:   jmp      loop0
msg:
   .byte   13,10
   .ascii "Operating System is Loading......"

4. build.c

#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
  
int main() 

   char buf[512];
   int image, fd;
  
   fd = open("./boot", O_RDONLY);
   read(fd, buf, 510);
   close(fd);

   buf[510] = 0x55;
   buf[511] = 0xaa;
  
   image = creat("./image", O_RDWR);
   lseek(image, 0, SEEK_SET);
   write(image, buf, 512);

   fd = open("./head", O_RDONLY);
   read(fd, buf, 512);
   close(fd);

   lseek(image, 512, SEEK_SET);
   write(image, buf, 512);
   close(image);
}

5. 启动
# qemu -fda image
该OS利用BIOS中断打印了一行
Operating System is Loading......

注1:在网上找的资源,作了些修改,加了个Makefile。粘Makfile文件时注意,将开头的空格替换为tab
注2:as86和ld86这两个命令在软件包bin86中
相关阅读 更多 +
排行榜 更多 +
步行僵尸2无限金币版

步行僵尸2无限金币版

体育竞技 下载
狐狸一号特殊任务无限金币版

狐狸一号特殊任务无限金币版

体育竞技 下载
忍者之雷复仇无限金币钻石版

忍者之雷复仇无限金币钻石版

体育竞技 下载