歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> 學習Linux >> x01.0s.21: print "Loading...",loading

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

日期:2017/3/6 9:34:25   编辑:學習Linux

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


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


先把目標設低點,開機進入後,在屏幕上打印“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 winxp # 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 linux

當然,這只是作為參考。如是 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 makefile ! 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 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 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; } tools/build.c

效果圖如下:

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

http://xxxxxx/Linuxjc/1138597.html TechArticle

Copyright © Linux教程網 All Rights Reserved