你的位置:首页 > 操作系统

[操作系统]x01.0s.21: print Loading...


先把目标设低点,开机进入后,在屏幕上打印“Loading..."即可。由于要在 bochs 中运行,首先就是安装 bochs。Oldlinux 中有相关资源,可自行下载。winxp 和 linux 的配置脚本如下:

# for windows bochs configmegs : 32romimage: file=$BXSHARE/BIOS-bochs-latestvgaromimage: file=$BXSHARE/VGABIOS-lgpl-latestfloppya: 1_44="a.img", status=insertedfloppyb: 1_44="b.img", status=insertedata0-master: type=disk, path="c.img", cylinders=365, heads=16, spt=63boot: amouse: enabled=0

winxp
# for linux bochs configdisplay_library : sdlmegs : 32romimage : file=/usr/share/bochs/BIOS-bochs-latestvgaromimage : file=/usr/share/vgabios/vgabios.binfloppya: 1_44="a.img", status=insertedfloppyb: 1_44="b.img", status=insertedata0-master: type=disk, path="c.img", cylinders=365, heads=16, spt=63boot : amouse : enabled=0keyboard_mapping : enabled=1, map=/usr/share/bochs/keymaps/sdl-pc-us.map 

linux

当然,这只是作为参考。如是 winxp,建议直接在 bochs-sls1.0 中编译,用 dd 写入 /dev/fd1, 即 b.img;如是 ubuntu,我使用 eclipse,贪图智能提示而已,本质并无区别。github 中的代码为 Ubuntu 系统。由于要求简单,代码自然也简单,分别为 makefile, boot/bootsect.s, tools/build.c 如下:

# makefileAS86 = as86 -0 -a LD86 = ld86 -0AS = as LD = ld LDFLAGS = -s -x -MCC = gccCFLAGS = -Wall -O -fstrength-reduce -fomit-frame-pointer -nostdinc -IincludeCPP = gcc -E -nostdinc -IincludeROOT_DEV = /dev/hd1.c.s:  $(CC) $(CFLAGS) -S -o $*.s $<.s.o:  $(AS) -c -o $*.o $<.c.o:  $(CC) $(CFLAGS) -c -o $*.o $<  Image: boot/bootsect tools/build  tools/build boot/bootsect > Image  sync  boot/bootsect: boot/bootsect.s   $(AS86) -o boot/bootsect.o boot/bootsect.s   $(LD86) -o boot/bootsect boot/bootsect.o  tools/build: tools/build.c  gcc -o tools/build tools/build.c

makefile
! boot/bootsect.s.textentry startstart:  mov ax, #0x07c0  mov ds, ax  mov es, ax   mov ss, ax   mov sp, #0xff00    mov cx, #18  mov bx, #0x000c  mov bp, #msg  mov ax, #0x1301  int 0x10   die:  jmp die   msg:  .byte 13,10,13,10  .ascii "Loading..."  .byte 13,10,13,10    .org 510  .word 0xaa55  

boot/bootsect.s
/* * tools/build.c */ #include <stdio.h>#include <string.h>#include <sys/types.h>#include <sys/stat.h>#include <linux/fs.h>#include <unistd.h>#include <fcntl.h>#define MINIX_HEADER    32#define GCC_HEADER      1024#define SYS_SIZE      0x2000#define DEFAULT_MAJOR_ROOT  3 #define DEFAULT_MINOR_ROOT  1 #define SETUP_SECTS      4void die(char* str){  fprintf(stderr, "%s\n", str);  exit(1);}int main(int argc, char** argv){  int i, id, c;  char buf[1024];  char major_root, minor_root;    if (argc == 5) {  } else {    major_root = DEFAULT_MAJOR_ROOT;    minor_root = DEFAULT_MINOR_ROOT;  }  fprintf(stderr, "Root device is (%d, %d)\n", major_root, minor_root);  for (i = 0; i < sizeof buf; i++)    buf[i] = 0;      if ((id = open(argv[1], O_RDONLY, 0)) < 0)    die("Unable open bootsect");  if (read(id, buf, MINIX_HEADER) != MINIX_HEADER)    die("Unable read Minix header");  i = read(id, buf, sizeof buf);  fprintf(stderr, "bootsect is %d bytes.\n", i);  buf[508] = (char)major_root;  buf[509] = (char)minor_root;  if ((*(unsigned short*)(buf + 510)) != 0xaa55)    die("boot hasn't '0xaa55' flag.");  i = write(1, buf, 512);  if (i != 512)    die("write call failed.");  close(id);    return 0;}

tools/build.c

效果图如下:

        

源代码:https://github.com/chinax01/Lab