- 论坛徽章:
- 0
|
/*
* 以下的代码其实是从linux2.4的i386的bootsect.s中取出的片段,要实现的功能是将它自己人0x07c00移动到0x90000,
*我的想法是在经过ljmp $INITSEG, $go 后在打印一个字符串,确定移动工作是成功的,但是实际上,加上这句后机器就
*一直不动了,就如同运行了 jmp . 一样.但是如果不要ljmp $INITSEG, $go 却是正确的,可以打印出字串.
*
*我找了很久都没有找到问题,我想是不是我的Makefile 有问题呢,也或者我编译方法不对?
现在将我的代码和makefile都列出来,请知道问题的仁兄帮忙解答!!!先谢谢了
*/
SETUPSECS = 4 /* default nr of setup-sectors */
BOOTSEG = 0x07C0 /* original address of boot-sector */
INITSEG = 0x9000 /* we move boot here - out of the way */
SETUPSEG = 0x9020 /* setup starts here */
.code16
.text
.global _start
_start:
movw $BOOTSEG, %ax
movw %ax, %ds
movw $INITSEG, %ax
movw %ax, %es
movw $256, %cx
subw %si, %si
subw %di, %di
cld
rep
movsw
/***************加上下面这句,就出问题了******************/
ljmp $INITSEG, $go
go:
movw $0x4000-12, %di # 0x4000 is an arbitrary value >=
# length of bootsect + length of
# setup + room for stack;
# 12 is disk parm size.
movw %ax, %ds # ax and es already contain INITSEG
movw %ax, %ss
movw %di, %sp # put stack at INITSEG:0x4000-12.
/*以下找码打印字符串*/
movw $msg,%ax
movw %ax,%bp
movw $33 ,%cx
movw $0x1301,%ax
movw $0x00c,%bx
movb $0,%dl
int $0x10
ljmp $0xf000,$0xfff0
jmp .
msg: .asciz "MMOS is named after my little son"
.org 510
boot_flag: .word 0xAA55
/*************以写是Makefile******************************************/
CC =gcc
LD =ld
OBJCOPY =objcopy
all: mmos.img clean
mmos.img: bootsect.bin
@dd if=bootsect.bin of=mmos.img bs=512 count=1
@dd if=/dev/zero of=mmos.img skip=1 seek=1 bs=512 count=2879
bootsect.bin:bootsect.s
$(CC) -c -g bootsect.s
$(LD) bootsect.o -o bootsect.elf -e c -Tboot_x86.ld
@$(OBJCOPY) -R .pdr -R .comment -R .note -S -O binary bootsect.elf bootsect.bin
clean:
@rm -rf *~ *.o *.elf *.bin
cleanall:
@rm -rf *.img
/******************以下是连接脚本文件*****************************************/
SECTIONS
{
. =0x7c00;
.text :
{
_ftext = .;
} = 0
} |
|