From b9a45ff5fe7b91fe12503155ee62563866f24c05 Mon Sep 17 00:00:00 2001 From: pavelyakov Date: Sun, 3 May 2020 09:30:20 +0000 Subject: [PATCH] GOLANG: addition git-svn-id: svn://kolibrios.org@7858 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/develop/golang/Makefile | 30 ++++++++ programs/develop/golang/int40.s | 86 ++++++++++++++++++++++ programs/develop/golang/link.ld | 28 +++++++ programs/develop/golang/main.go | 19 +++++ programs/develop/golang/os.go | 8 ++ programs/develop/golang/static.lds | 113 +++++++++++++++++++++++++++++ 6 files changed, 284 insertions(+) create mode 100644 programs/develop/golang/Makefile create mode 100755 programs/develop/golang/int40.s create mode 100644 programs/develop/golang/link.ld create mode 100644 programs/develop/golang/main.go create mode 100644 programs/develop/golang/os.go create mode 100644 programs/develop/golang/static.lds diff --git a/programs/develop/golang/Makefile b/programs/develop/golang/Makefile new file mode 100644 index 0000000000..c5790bd178 --- /dev/null +++ b/programs/develop/golang/Makefile @@ -0,0 +1,30 @@ +SOURCES=int40.o os.go.o os.gox main.go.o + +GOFLAGS= -nostdlib -nostdinc -fno-stack-protector -fno-split-stack -static -m32 -g -I. +GO=gccgo +ASFLAGS= -felf +NASM= nasm $(ASFLAGS) +OBJCOPY=objcopy + +LDFLAGS=-T static.lds -n -m elf_i386 + + +all: $(SOURCES) link + +clean: + rm *.o *.gox main + +link: + ld $(LDFLAGS) -o main.kex $(SOURCES) + $(OBJCOPY) *.kex -O binary + +%.gox: %.go.o + $(OBJCOPY) -j .go_export $< $@ + +%.go.o: %.go + $(GO) $(GOFLAGS) -o $@ -c $< + +%.o: %.s + $(NASM) $< + + diff --git a/programs/develop/golang/int40.s b/programs/develop/golang/int40.s new file mode 100755 index 0000000000..37fd4ed779 --- /dev/null +++ b/programs/develop/golang/int40.s @@ -0,0 +1,86 @@ + +SECTION .text + +[GLOBAL __start] +extern go.kernel.Load + +global go.os.Sleep +global go.os.Event +global go.os.Button +global go.os.Exit +global go.os.Redraw +global go.os.Window + +__start: + call go.kernel.Load + ret + +go.os.Sleep: + push ebp + mov ebp,esp + mov eax, 5 + mov ebx, [ebp+8] + int 0x40 + mov esp,ebp + pop ebp + ret + + +go.os.Event: + push ebp + mov ebp,esp + mov eax, 10 + int 0x40 + mov esp,ebp + pop ebp + ret + +go.os.Button: + push ebp + mov ebp,esp + mov eax, 17 + int 0x40 + mov esp,ebp + pop ebp + ret + +go.os.Exit: + push ebp + mov ebp,esp + mov eax, -1 + int 0x40 + mov esp,ebp + pop ebp + ret + + +go.os.Redraw: + push ebp + mov ebp,esp + mov eax, 12 + mov ebx, [ebp+8] + int 0x40 + mov esp,ebp + pop ebp + ret + +go.os.Window: + push ebp + mov ebp,esp + mov ebx, [ebp+8] + shl ebx, 16 + or ebx, [ebp+16] + mov ecx, [ebp+12] + shl ecx, 16 + or ecx, [ebp+20] + mov edx, 0x14 + shl edx, 24 + or edx, 0xFFFFFF + mov esi, 0x808899ff + mov edi, [ebp+24] + xor eax, eax + int 0x40 + mov esp,ebp + pop ebp + ret + diff --git a/programs/develop/golang/link.ld b/programs/develop/golang/link.ld new file mode 100644 index 0000000000..5514ad9400 --- /dev/null +++ b/programs/develop/golang/link.ld @@ -0,0 +1,28 @@ +ENTRY(start) +SECTIONS +{ + .text 0x0000000: { + *(.text) + } +.rdata ALIGN(16) : + { + *(.rdata) + *(SORT(.rdata$*)) + ___RUNTIME_PSEUDO_RELOC_LIST__ = .; + __RUNTIME_PSEUDO_RELOC_LIST__ = .; + *(.rdata_runtime_pseudo_reloc) + ___RUNTIME_PSEUDO_RELOC_LIST_END__ = .; + __RUNTIME_PSEUDO_RELOC_LIST_END__ = .; + } + + .data : { + *(.data) + } + + .bss : { + *(.bss) + } + + + end = .; +} diff --git a/programs/develop/golang/main.go b/programs/develop/golang/main.go new file mode 100644 index 0000000000..754833b685 --- /dev/null +++ b/programs/develop/golang/main.go @@ -0,0 +1,19 @@ +package kernel +import "os" + + +func Load() { +x := "test" + for true { + switch os.Event() { + + case 1: + os.Redraw(1) + os.Window(50,250,450,200,x) + os.Redraw(2) + os.Sleep(100) + case 3: + os.Exit() + } + } +} diff --git a/programs/develop/golang/os.go b/programs/develop/golang/os.go new file mode 100644 index 0000000000..d41c9348bb --- /dev/null +++ b/programs/develop/golang/os.go @@ -0,0 +1,8 @@ +package os + +func Sleep(uint32) +func Event() uint32 +func Button() uint32 +func Exit() +func Redraw(uint32) +func Window(uint32, uint32, uint32, uint32, string) diff --git a/programs/develop/golang/static.lds b/programs/develop/golang/static.lds new file mode 100644 index 0000000000..eae5668bca --- /dev/null +++ b/programs/develop/golang/static.lds @@ -0,0 +1,113 @@ +/*OUTPUT_FORMAT("binary")*/ + +ENTRY(__start) +SECTIONS +{ + .text 0x000000: + { + LONG(0x554e454D); + LONG(0x32305445); + LONG(1); + LONG(__start); + LONG(___iend); + LONG(___memsize); + LONG(___stacktop); + LONG(0); + LONG(0); /* full path */ + LONG(0); /*FIXME tls data */ + + *(.init) + *(.text) + *(SORT(.text$*)) + *(.text.*) + *(.glue_7t) + *(.glue_7) + ___CTOR_LIST__ = .; __CTOR_LIST__ = . ; + LONG (-1);*(.ctors); *(.ctor); *(SORT(.ctors.*)); LONG (0); + ___DTOR_LIST__ = .; __DTOR_LIST__ = . ; + LONG (-1); *(.dtors); *(.dtor); *(SORT(.dtors.*)); LONG (0); + *(.fini) + /* ??? Why is .gcc_exc here? */ + *(.gcc_exc) + PROVIDE (etext = .); + *(.gcc_except_table) + } + + .rdata ALIGN(16) : + { + *(.rdata) + *(SORT(.rdata$*)) + ___RUNTIME_PSEUDO_RELOC_LIST__ = .; + __RUNTIME_PSEUDO_RELOC_LIST__ = .; + *(.rdata_runtime_pseudo_reloc) + ___RUNTIME_PSEUDO_RELOC_LIST_END__ = .; + __RUNTIME_PSEUDO_RELOC_LIST_END__ = .; + } + .CRT ALIGN(16) : + { + ___crt_xc_start__ = . ; + *(SORT(.CRT$XC*)) /* C initialization */ + ___crt_xc_end__ = . ; + ___crt_xi_start__ = . ; + *(SORT(.CRT$XI*)) /* C++ initialization */ + ___crt_xi_end__ = . ; + ___crt_xl_start__ = . ; + *(SORT(.CRT$XL*)) /* TLS callbacks */ + /* ___crt_xl_end__ is defined in the TLS Directory support code */ + ___crt_xp_start__ = . ; + *(SORT(.CRT$XP*)) /* Pre-termination */ + ___crt_xp_end__ = . ; + ___crt_xt_start__ = . ; + *(SORT(.CRT$XT*)) /* Termination */ + ___crt_xt_end__ = . ; + } + + .data ALIGN(16) : + { + __data_start__ = . ; + *(.data) + *(.data2) + *(SORT(.data$*)) + *(.jcr) + __CRT_MT = .; + LONG(0); + __data_end__ = . ; + *(.data_cygwin_nocopy) + } + + .eh_frame ALIGN(16) : + { + *(.eh_frame) + ___iend = . ; + } + + bss ALIGN(16): + { + *(.bss) + *(COMMON) + . = ALIGN(16); + ___menuet__app_path_area = .; + . = . + 1024 + 16; + ___stacktop = .; + ___memsize = . ; + } + + /DISCARD/ : + { + *(.debug$S) + *(.debug$T) + *(.debug$F) + *(.drectve) + *(.note.GNU-stack) + *(.comment) + *(.debug_abbrev) + *(.debug_info) + *(.debug_line) + *(.debug_frame) + *(.debug_loc) + *(.debug_pubnames) + *(.debug_aranges) + *(.debug_ranges) + } + +}