LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 912|回复: 3

[問題] 關於bootsect之編譯

[复制链接]
发表于 2006-1-22 00:00:45 | 显示全部楼层 |阅读模式
用GNU assembly寫了個簡單bootsect,

.text
.global _start
_start:
jmpl $0x07C0, $main
main:
mov $100, %eax
loop1: jmp loop1


How can i use AS to procduce a raw binary file
with no header and started at location 0 ??

then i can put this file into the first sector of a floppy disk.

目的是想編譯出來的文件沒有header,
文件的最開頭就是第一句程序.
发表于 2006-1-23 11:53:54 | 显示全部楼层
as 编译出来的是 elf 格式文件,可以再使用 objcopy 就可以变成 binary 的,

把所有数据和代码都放到 .text 段去,as 生成 a.out 文件后:

  1. $ [b]objcopy -j .text -O binary a.out boot.sector[/b]
复制代码
回复 支持 反对

使用道具 举报

发表于 2006-1-24 11:23:34 | 显示全部楼层
只是as,不连接行吗!给你个bootload,摘录于Linux1.0核心游记之操作系统的引导块程序

文件名boot.s
____________________________________________


.text
entry _start
_start:
        jmpi boot,#0x07C0                       
boot:
        mov ax,cs
        mov es,ax
label2:
        call print_msg
        jmp label2
       
print_msg:
        mov        ah,#0x03       
        xor        bh,bh
        int        0x10       
        mov        cx,#29
        mov        bx,#0x0007               
        mov        bp,#msg
        mov        ax,#0x1301
        int        0x10
        ret
msg:
        .byte 13,10
        .ascii "Aha,I am a boot process !"
        .byte 13,10
.org 510
        .word 0xAA55


文件名 Makefile
_________________________________________

AS86 = as86 -0 -a
LD86 = ld86 -0 -d -s
OBJ  = boot

.s.o:
        $(AS86) -o $*.o $<

all(OBJ)

$(OBJ):boot.o
        $(LD86) -o $(OBJ) boot.o
boot.o:boot.s

disk(OBJ)
        dd if=./boot of=/dev/fd0 seek=0 bs=512 count=1
       
clean:
        rm -f *.o core
clobber:clean
        rm -f $(OBJ)
回复 支持 反对

使用道具 举报

发表于 2006-1-25 10:21:56 | 显示全部楼层
那是很古老的了,现在的内核已经不再使用 as86 。从 2.0 内核就有人把它们用 GNU as 格式汇编重写了。

在内核源码树中 arch/i386/boot/bootsect.S 就是一个很好的 bootsect 的例子,是 GNU as 的格式,不过这个 bootsect 在 linux 内核中已经不再起作用了,看看这一段代码就知道其内容就是打印几行错误消息然后进入死循环。内核开始执行的地方是 setup.S 。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表