From b215841161dde4c8051af05219adce96308d5df3 Mon Sep 17 00:00:00 2001 From: superturbocat2001 Date: Thu, 12 Nov 2020 00:43:46 +0000 Subject: [PATCH] - Added new system functions to golang. - Renamed int40 file to syscalls.s. - Updated example with new functionality. git-svn-id: svn://kolibrios.org@8177 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/develop/golang/Makefile | 28 ++-- programs/develop/golang/colors.go | 20 +++ programs/develop/golang/main.go | 54 ++++++-- programs/develop/golang/os.go | 26 +++- programs/develop/golang/syscalls.s | 203 +++++++++++++++++++++++++++++ 5 files changed, 300 insertions(+), 31 deletions(-) create mode 100644 programs/develop/golang/colors.go create mode 100755 programs/develop/golang/syscalls.s diff --git a/programs/develop/golang/Makefile b/programs/develop/golang/Makefile index c5790bd178..5f23f51c7e 100644 --- a/programs/develop/golang/Makefile +++ b/programs/develop/golang/Makefile @@ -1,30 +1,24 @@ -SOURCES=int40.o os.go.o os.gox main.go.o - +PROGRAM=main +SOURCES=syscalls.o colors.go.o colors.gox os.go.o os.gox $(PROGRAM).go.o +LIBOBJ=os.go.o syscalls.o colors.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 - +clean: + rm *.o *.gox $(PROGRAM).kex link: - ld $(LDFLAGS) -o main.kex $(SOURCES) - $(OBJCOPY) *.kex -O binary - + ld $(LDFLAGS) -o $(PROGRAM).kex $(SOURCES) + $(OBJCOPY) $(PROGRAM).kex -O binary %.gox: %.go.o - $(OBJCOPY) -j .go_export $< $@ - + $(OBJCOPY) -j .go_export $< $@ %.go.o: %.go - $(GO) $(GOFLAGS) -o $@ -c $< - + $(GO) $(GOFLAGS) -o $@ -c $< %.o: %.s $(NASM) $< - - diff --git a/programs/develop/golang/colors.go b/programs/develop/golang/colors.go new file mode 100644 index 0000000000..f08f455e48 --- /dev/null +++ b/programs/develop/golang/colors.go @@ -0,0 +1,20 @@ +package colors + +const( + Black = 0x000000 + Gray = 0x808080 + Silver = 0xc0c0c0 + White = 0xffffff + Fuchsia = 0xff00ff + Purple = 0x800080 + Red = 0xff0000 + Maroon = 0x800000 + Yellow = 0xffff00 + Olive = 0x808000 + Lime = 0x00ff00 + Green = 0x008000 + Aqua = 0x00ffff + Teal = 0x008080 + Blue = 0x0000ff + Navy =0x000080 +) diff --git a/programs/develop/golang/main.go b/programs/develop/golang/main.go index 754833b685..bcf7f01442 100644 --- a/programs/develop/golang/main.go +++ b/programs/develop/golang/main.go @@ -1,19 +1,51 @@ package kernel import "os" +import "colors" +const ( + Btn1=2; + Btn2=3; + BtnExit=1; +) + +func RedrawAll(bar_pos int){ + btn_txt1:=" <- " + btn_txt2:=" -> " + str:="I love KolibriOS" + title:="Test Golang" + os.Redraw(1) + os.Window(500,250,420,200, title) + os.WriteText(32,32, 0x11000000 | colors.Green,str, 10) + os.DrawLine(32, 80, 150, 80, colors.Green) + os.CreateButton(32, 128, 80, 30, Btn1, colors.Blue); + os.CreateButton(300, 128, 80, 30, Btn2, colors.Blue); + os.WriteText(32,128, 0x11000000 | colors.White,btn_txt1, 10) + os.WriteText(320,128, 0x11000000 | colors.White,btn_txt2, 10) +} 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() + time := os.GetTime() + os.DebugOutStr("Time: ") + os.DebugOutHex(time) + var pos=32; + for true { + switch os.Event() { + case os.EVENT_REDRAW: + RedrawAll(pos) + break + case os.EVENT_BUTTON: + switch os.GetButtonID() { + case Btn1: + pos-=32 + RedrawAll(pos) + break + case Btn2: + pos+=32 + RedrawAll(pos); + break + case BtnExit: + os.Exit() + } } } } diff --git a/programs/develop/golang/os.go b/programs/develop/golang/os.go index d41c9348bb..29dcf71176 100644 --- a/programs/develop/golang/os.go +++ b/programs/develop/golang/os.go @@ -1,8 +1,28 @@ package os +const ( + EVENT_NONE = 0 /* Event queue is empty */ + EVENT_REDRAW = 1 /* Window and window elements should be redrawn */ + EVENT_KEY = 2 /* A key on the keyboard was pressed */ + EVENT_BUTTON = 3 /* A button was clicked with the mouse */ + EVENT_DESKTOP = 5 /* Desktop redraw finished */ + EVENT_MOUSE = 6 /* Mouse activity (movement, button press) was detected */ + EVENT_IPC = 7 /* Interprocess communication notify */ + EVENT_NETWORK = 8 /* Network event */ + EVENT_DEBUG = 9 /* Debug subsystem event */ + EVENT_IRQBEGIN = 16 +) func Sleep(uint32) -func Event() uint32 -func Button() uint32 +func GetTime()(time uint32) +func Event()(uint32) +func GetButtonID()(id int) +func CreateButton(x uint32, y uint32, xsize uint32, ysize uint32, id uint32, color uint32) func Exit() func Redraw(uint32) -func Window(uint32, uint32, uint32, uint32, string) +func Window(y uint32, x uint32, w uint32,h uint32, title string) +func WriteText(x uint32 ,y uint32 , color uint32, text string, len uint32) +func DrawLine(x1 uint32, y1 uint32, x2 uint32, y2 uint32, color uint32)(uint32) +func DrawBar(x uint32, y uint32, xsize uint32, ysize uint32, color uint32) +func DebugOutHex(uint32) +func DebugOutChar(byte) +func DebugOutStr(string) diff --git a/programs/develop/golang/syscalls.s b/programs/develop/golang/syscalls.s new file mode 100755 index 0000000000..6d7b2c27ae --- /dev/null +++ b/programs/develop/golang/syscalls.s @@ -0,0 +1,203 @@ + +SECTION .text + +[GLOBAL __start] +extern go.kernel.Load + +global go.os.Sleep +global go.os.Event +global go.os.GetButtonID +global go.os.CreateButton +global go.os.Exit +global go.os.Redraw +global go.os.Window +global go.os.WriteText +global go.os.GetTime +global go.os.DrawLine +global go.os.DrawBar +global go.os.DebugOutHex +global go.os.DebugOutChar +global go.os.DebugOutStr + +__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.GetButtonID: + mov eax,17 + int 0x40 + test al,al + jnz .no_button + shr eax,8 + ret +.no_button: + xor eax,eax + dec eax + 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 + +go.os.WriteText: + mov eax,4 + mov ebx,[esp+4] + shl ebx,16 + mov bx,[esp+8] + mov ecx,[esp+12] + mov edx,[esp+16] + mov esi,[esp+20] + int 0x40 + ret + +go.os.DrawLine: + push ebx + mov ebx,[esp+8] + shl ebx,16 + mov bx,[esp+16] + mov ecx,[esp+12] + shl ecx,16 + mov cx,[esp+20] + mov edx,[esp+24] + mov eax,38 + int 0x40 + pop ebx + ret + +go.os.DrawBar: + push ebx + mov eax,13 + mov ebx,[esp+8] + shl ebx,16 + mov bx,[esp+16] + mov ecx,[esp+12] + shl ecx,16 + mov cx,[esp+20] + mov edx,[esp+24] + int 0x40 + pop ebx + ret + +go.os.GetTime: + mov eax, 3 + int 0x40 + ret + +go.os.DebugOutHex: + mov eax, [esp+4] + mov edx, 8 + .new_char: + rol eax, 4 + movzx ecx, al + and cl, 0x0f + mov cl, [__hexdigits + ecx] + pushad + mov eax, 63 + mov ebx, 1 + int 0x40 + popad + dec edx + jnz .new_char + ret + +go.os.DebugOutChar: + mov al, [esp+4] + pushf + pushad + mov cl,al + mov eax,63 + mov ebx,1 + int 0x40 + popad + popf + ret + +go.os.DebugOutStr: + mov edx,[esp+4] + mov eax,63 + mov ebx,1 + m2: + mov cl, [edx] + test cl,cl + jz m1 + int 40h + inc edx + jmp m2 + m1: + ret + +go.os.CreateButton: + push ebx + push esi + mov ebx,[esp+12] + shl ebx,16 + mov bx,[esp+20] + mov ecx,[esp+16] + shl ecx,16 + mov cx,[esp+24] + mov edx,[esp+28] + mov esi,[esp+32] + mov eax,8 + int 0x40 + pop esi + pop ebx + ret + +SECTION .data +__hexdigits: + db '0123456789ABCDEF'