初めてのGO
謎の実験中。
1.GOのサイト。http://community.osdev.info/index.php?GO
2.ダウンロード (http://k.hideyosi.com/go_0020w.lzh)win32用実行バイナリセット
3.Hello.c
要点はebx=1にしてesiに文字列をセットする、そしてint0x80
#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"); }
4.コンパイル(gas形式に)
cc1 -I. -Os -quiet -o hello.s hello.c
hello.s
.file "hello.c" .text .balign 2 .globl _print .def _print; .scl 2; .type 32; .endef _print: pushl %ebp movl %esp, %ebp pushl %esi pushl %ebx pushl %ecx /APP movl $1, %ebx movl 8(%ebp) , %esi int $0x80 movl %eax, -12(%ebp) /NO_APP movl -12(%ebp), %eax popl %edx popl %ebx popl %esi popl %ebp ret .data LC0: .ascii "Hello\0" .text .balign 2 .globl __user_start .def __user_start; .scl 2; .type 32; .endef __user_start: pushl %ebp movl %esp, %ebp pushl $LC0 call _print leave ret
5.nask形式に変換
gas2nask -a hello.s hello.nas skip:movl 8(%ebp) , %esi skip:int $0x80
むむ最適化されてしまったっぽいな。
さてどうしようかな。gasは(ry
追記:\go_0020b\funcs\m_gasnas.cか。