James Bryant

x01.0s.21: print "Loading..."

0
阅读(1356)

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

复制代码

# for windows bochs config megs : 32 romimage: file=$BXSHARE/BIOS-bochs-latest vgaromimage: file=$BXSHARE/VGABIOS-lgpl-latest floppya: 1_44="a.img", status=inserted floppyb: 1_44="b.img", status=inserted ata0-master: type=disk, path="c.img", cylinders=365, heads=16, spt=63 boot: a mouse: enabled=0

复制代码

复制代码

# for linux bochs config display_library : sdl megs : 32 romimage : file=/usr/share/bochs/BIOS-bochs-latest vgaromimage : file=/usr/share/vgabios/vgabios.bin floppya: 1_44="a.img", status=inserted floppyb: 1_44="b.img", status=inserted ata0-master: type=disk, path="c.img", cylinders=365, heads=16, spt=63 boot : a mouse : enabled=0 keyboard_mapping : enabled=1, map=/usr/share/bochs/keymaps/sdl-pc-us.map

复制代码

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

复制代码

# makefile AS86 = as86 -0 -a LD86 = ld86 -0 AS = as LD = ld LDFLAGS = -s -x -M CC = gcc CFLAGS = -Wall -O -fstrength-reduce -fomit-frame-pointer -nostdinc -Iinclude CPP = gcc -E -nostdinc -Iinclude ROOT_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

复制代码

复制代码

! boot/bootsect.s .text entry start start: 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

复制代码

复制代码

/* * tools/build.c */ #include  #include  #include  #include  #include  #include  #include  #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 4 void 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; }

复制代码

效果图如下:

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

Baidu
map