- 論壇徽章:
- 0
|
感謝大家熱情的回復(fù),我后來自己好好想了想,然后翻了翻資料,和同學(xué)討論了下,貌似找到了問題的根源。
main.o的.text被ld貼到了512字節(jié)后面,但bios只會將第一個扇區(qū)讀入內(nèi)存,所以后面的壓根就沒有讀入,自然一call就掛了。
不知道,我這樣理解有沒有錯。
本來是想在寫bootsector的時候就用C,看來還是不能偷懶阿,只有在loader再開始了。
我寫了一個引導(dǎo)扇區(qū)的程序,想在其中調(diào)用用c寫的函數(shù),但是發(fā)現(xiàn),一旦在匯編中調(diào)用了C的函數(shù)之后,系統(tǒng)就卡在那里不往下執(zhí)行了,請問這怎么解決阿。
我是新手,還望大家多多幫忙阿。
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 |
[ 本帖最后由 破碎細(xì)胞 于 2009-2-19 17:18 編輯 ] |
|