[Mona] GOの続き

GOの作者のKさんからいろいろフォローいただきました。とりあえず exe形式まで作る事ができたのでその手順を。

go_0020s, go_0020w, go_0023pを用意する

		"4incl    INC",
		"2incw    INC",

の下に

		"1int     INT", を追加
  • \go\toolw32において make する
  • gas2nask.exe 等が新しくビルドされているはず。
  • \go\toolw32\hello.c
#define SYSTEM_CALL_PRINT (0x0001)

#define SYSCALL_1(syscall_number, result, arg1)                                   \
    asm volatile("movl $%c1, %%ebx \n"                                            \
                 "movl %2  , %%esi \n"                                            \
                 "int  $0x80       \n"                                            \
                 "movl %%eax, %0   \n"                                            \
                 :"=m"(result)                                                    \
                 :"g"(syscall_number), "m"(arg1)                                  \
                 :"ebx", "esi"                                                    \
                 );
int print(const char* msg)
{
    int result;
    SYSCALL_1(SYSTEM_CALL_PRINT, result, msg);
    return result;
}

void _user_start()
{
    print("Hello");
}
  • cc1 -I. -Os -quiet -o helloc4.s helloc4.c
  • \go\toolw32\hello.s を編集 空白をなくす
movl 8(%ebp)  , %esi 
⇒movl 8(%ebp),%esi 
  • gas2nask -a hello.s hello.nas
  • nask hello.nas hello.obj hello.lst
  • ld -nTtext 0xA0000000 -e __user_start -Bstatic hello.obj -o hello.exe


このhello.exe を Monaで実行したところアドレスエラーで異常終了してしまいました。
obj2bim3, bim2bin3等々を使った方が良いのだろうか。


追記:ld --Mapオプションで出力してみた。

Memory Configuration

Name             Origin             Length             Attributes
*default*        0x00000000         0xffffffff

Linker script and memory map

                0x00400000                __image_base__ = 0x400000
                0x00000000                __dll__ = 0x0
                0x00001000                __section_alignment__ = 0x1000
                0x00000200                __file_alignment__ = 0x200
                0x00000004                __major_os_version__ = 0x4
                0x00000000                __minor_os_version__ = 0x0
                0x00000001                __major_image_version__ = 0x1
                0x00000000                __minor_image_version__ = 0x0
                0x00000004                __major_subsystem_version__ = 0x4
                0x00000000                __minor_subsystem_version__ = 0x0
                0x00000003                __subsystem__ = 0x3
                0x00200000                __size_of_stack_reserve__ = 0x200000
                0x00001000                __size_of_stack_commit__ = 0x1000
                0x00100000                __size_of_heap_reserve__ = 0x100000
                0x00001000                __size_of_heap_commit__ = 0x1000
                0x00000000                __loader_flags__ = 0x0
Address of section .text set to 0xa0000000
LOAD hello.obj

.text           0xa0000000      0x200
 *(.init)
 *(.text)
 .text          0xa0000000       0x2a hello.obj
                0xa000001b                _user_start
                0xa0000000                print
 *(SORT(.text$*))
 *(.glue_7t)
 *(.glue_7)
                0xa000002a                ___CTOR_LIST__ = .
                0xa000002a                __CTOR_LIST__ = .
                0xa000002a        0x4 LONG 0xffffffff
 *(SORT(.ctors.*))
 *(.ctors)
 *(.ctor)
                0xa000002e        0x4 LONG 0x0
                0xa0000032                ___DTOR_LIST__ = .
                0xa0000032                __DTOR_LIST__ = .
                0xa0000032        0x4 LONG 0xffffffff
 *(SORT(.dtors.*))
 *(.dtors)
 *(.dtor)
                0xa0000036        0x4 LONG 0x0
 *(.fini)
 *(.gcc_exc)
                0xa000003a                etext = .
 *(.gcc_except_table)

.data           0xa0001000      0x200
                0xa0001000                __data_start__ = .
 *(.data)
 .data          0xa0001000        0x6 hello.obj
 *(.data2)
 *(SORT(.data$*))
                0xa0001006                __data_end__ = .
 *(.data_cygwin_nocopy)

.rdata
 *(.rdata)
 *(SORT(.rdata$*))
 *(.eh_frame)

.pdata
 *(.pdata)

.bss            0xa0002000        0x0
                0xa0002000                __bss_start__ = .
 *(.bss)
 *(COMMON)
                0xa0002000                __bss_end__ = .

.edata
 *(.edata)

/DISCARD/
 *(.debug$S)
 *(.debug$T)
 *(.debug$F)
 *(.drectve)

.idata          0xa0002000      0x200
 SORT(*)(.idata$2)
 SORT(*)(.idata$3)
                0xa0002000        0x4 LONG 0x0
                0xa0002004        0x4 LONG 0x0
                0xa0002008        0x4 LONG 0x0
                0xa000200c        0x4 LONG 0x0
                0xa0002010        0x4 LONG 0x0
 SORT(*)(.idata$4)
 SORT(*)(.idata$5)
 SORT(*)(.idata$6)
 SORT(*)(.idata$7)

.CRT
 *(SORT(.CRT$*))

.endjunk        0xa0003000        0x0
                0xa0003000                end = .
                0xa0003000                _end = .
                0xa0003000                __end__ = .

.rsrc
 *(.rsrc)
 *(SORT(.rsrc$*))

.reloc
 *(.reloc)

.stab
 *(.stab)

.stabstr
 *(.stabstr)
OUTPUT(hello.exe pei-i386)