gas で OS 自作入門 ipl その1

だいぶ前に OS 自作入門を参考に iTRON OS もどきを作ってみたのだが、なんとなく gas で書き直そうと思った。
YUKI.N さんのページを参考に、というかそのままパクったような感じですが、とりあえず hello world に相当するものを gas で書いてみた。

ipl.s

.globl start
.code16

start:
	jmp	 entry
	.byte 0x90

# fat bpb
	.ascii "TEST IPL"
	.word	512
	.byte	1
	.word	1
	.byte	2
	.word	244
	.word	2880
	.byte	0xf0
	.word	9
	.word	18
	.word	2
	.long	0
	.long	2880
	.byte	0
	.byte	0
	.byte	0x28
	.long	0xffffffff
	.ascii	"IPL 110105 "
	.ascii	"FAT12   "
	.space	18,0

entry:
	movw	$0, %ax
	movw	%ax, %ss
	movw	$0x7c00, %sp
	movw    %ax, %ds
	movw	%ax, %es
	movw	$msg, %si

putloop:
	movb	0(%si),	%al
	add		$1, %si
	cmpb	$0, %al
	je		fin
	movb	$0x0e, %ah      # put one char
	movw	$15, %bx        # color code
	int		$0x10           # call video bios
	jmp		putloop

fin:
	hlt
	jmp		fin

msg:	.ascii "xxx hello world xxx\n"
        .byte 0

.org	510
.byte	0x55, 0xaa

ipl.ls

OUTPUT_ARCH(i386)

SECTIONS {
        . = 0x7c00;
        .text : { *(.text) }
}

Makefile

TARGET=boot.img

all:$(TARGET)

.SUFFIXS: .s .o

.s.o:
        as $< -o $@

$(TARGET): ipl.o ipl.ls
        ld -T ipl.ls ipl.o -o out.elf
        objcopy -O binary out.elf $@

clean:
        rm -f *.o $(TARGET) out.elf

cygwin 環境でもリンクしたかったので、ld: cannot perform PE operations on non PE output file 'xxx' のエラーを回避するために ld する時にフォーマット object に指定しないようにした。