ウォンツテック

そでやまのーと

nchaosという2年くらい前に書いてたkernel(ほとんどブートのみ)を1から書き直そうと思い、さらにどうせならgas(GNU as)で書き直そうとしたのだが、何故かnasmと違ってバイナリに余分なものがたくさん引っ付いている。。リンカが正常に働いていないのか原因は良くわからない。コードは以下のような感じで512byteに収めたいんだけどasでコンパイルすると2000byteくらいに膨れ上がってしまう。これだとqemuで起動する時にbootバイナリとして認識してくれずエラーになる。(コンパイル環境はlinuxでnasmで書いた似たようなコードは正常に動く)

/*
 *  @File                bootacient.s
 *  @Brief               The initial boot section of Sodex
 *
 *  @Author              Sodex 2007/4/5
 *  @Revision    0.1
 *      Copyright (C) 2007 Sodex
 *  License  suspension
 */

BOOTSEG                 = 0x07C0
INITSEG                 = 0x9000
SYSSEG                  = 0x1000

.align 4
.code16
.text

.global _start
_start:

                jmpl    $BOOTSEG, $start2

start2:
                movw    %cs, %ax
                movw    %ax, %ds
                movw    %ax, %es
                movw    %ax, %ss
                movw    $0x7c00, %sp
                sti
                cld

                xorw    %si, %si
                xorw    %di, %di
                movw    $BOOTSEG, %ax
                movw    %ax, %ds
                movw    $INITSEG, %ax
                movw    %ax, %es
                movw    $0x100, %cx
                cld
                rep     movsw
                jmpl    $INITSEG, $start3

start3:
                movb    $0x3, %al   # Clear the display
                movb    $0, %ah
                int     $0x10
                movw    $os_start_mes, %si
                call    printstr

                jmp     hangdisplay
                movb    $0, %ah
                int     $0x10
                movw    $os_start_mes, %si
                call    printstr

                jmp     hang

printstr:
                pushw   %ax
printstr_start:
        lodsb
                cmpb    $0, %al
                jz      printstr_end
                movb    $0x0e, %ah
                movb    $0, %bh
                int     $0x10
                jmp      printstr_start
printstr_end:
                popw    %ax
                ret

hang:
                jmp     hang

os_start_mes:
                .ascii  "Hello. This is sodex, starting main boot loader...\r\n"
                .byte   0

                .org 510
                .word 0xAA55