- 论坛徽章:
- 0
|
感谢大家热情的回复,我后来自己好好想了想,然后翻了翻资料,和同学讨论了下,貌似找到了问题的根源。
main.o的.text被ld贴到了512字节后面,但bios只会将第一个扇区读入内存,所以后面的压根就没有读入,自然一call就挂了。
不知道,我这样理解有没有错。
本来是想在写bootsector的时候就用C,看来还是不能偷懒阿,只有在loader再开始了。
我写了一个引导扇区的程序,想在其中调用用c写的函数,但是发现,一旦在汇编中调用了C的函数之后,系统就卡在那里不往下执行了,请问这怎么解决阿。
我是新手,还望大家多多帮忙阿。
boot.S:
#define MSG(x) leaw x,%si;call display
.code16
.section .text
.globl _start
_start:
movw $0x2000,%sp
movw %sp,%bp
#set video mode
movw $0x0003,%ax
int $0x10
MSG(sector_msg1)
call main
MSG(sector_msg2)
_endless_loop:jmp _endless_loop
sector_msg1:
.asciz "bootsector: looking for a loader... "
sector_msg2:
.asciz "found\n\r"
.globl test
test:
MSG(sector_msg2)
ret
display:
cld
movb $0xe,%ah /* use BIOS interrupt 10,e */
movb $0xf,%bl /* font color */
display_start:
lodsb
orb %al,%al
jz display_end
int $0x10
jmp display_start
display_end:
ret
.org 510
.word 0xaa55 |
main.c
extern void test();
void main()
{
test();
return;
}
|
链接脚本boot.ld:
OUTPUT_FORMAT("binary")
ENTRY(_start)
SECTIONS
{
.text 0x7c00:
{
*(.text)
}
}
|
Makefile:
CC=gcc
LD=ld
AS=as
LDSCRIPT=carrot.ld
DEBUG_DIR=./
INCLUDE_DIR=../include/
all:boot.img
boot.img:boot.bin
dd if=/dev/zero of=$(DEBUG_DIR)emptydisk.img bs=512 count=2880
dd if=boot.bin of=$(DEBUG_DIR)boot.img bs=512 count=1
dd if=$(DEBUG_DIR)emptydisk.img of=$(DEBUG_DIR)boot.img skip=1 seek=1 bs=512 count=2879
boot.bin:boot.o
$(LD) -Tboot.ld boot.o main.o -o boot.bin
boot.o:boot.S
$(CC) -c -I$(INCLUDE_DIR) -o boot.o boot.S
$(CC) -c -I$(INCLUDE_DIR) -o main.o main.c
clean:
rm -rf *.bin *.o $(INCLUDE_DIR)/boot.img |
[ 本帖最后由 破碎细胞 于 2009-2-19 17:18 编辑 ] |
|