x01.0s.21: print "Loading...",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=0winxp# 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.cmakefile! 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