forked from KolibriOS/kolibrios
golang: fixed build errors and some refactoring
git-svn-id: svn://kolibrios.org@9298 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
7a80e13e25
commit
227e2de7d9
26
programs/develop/golang/example/Makefile
Normal file
26
programs/develop/golang/example/Makefile
Normal file
@ -0,0 +1,26 @@
|
||||
PROGRAM=example
|
||||
OBJS=../syscalls.o colors.go.o colors.gox ../kos.go.o ../kos.gox $(PROGRAM).go.o
|
||||
GOFLAGS=-m32 -c -nostdlib -nostdinc -fno-stack-protector -fno-split-stack -static -fno-leading-underscore -fno-common -fno-pie -g -I.
|
||||
GO=gccgo
|
||||
ASFLAGS=-g -f elf32 -F dwarf
|
||||
NASM=nasm $(ASFLAGS)
|
||||
OBJCOPY=objcopy
|
||||
LDFLAGS=-n -T static.lds -m elf_i386 --no-ld-generated-unwind-info
|
||||
|
||||
all: $(OBJS) link
|
||||
|
||||
clean:
|
||||
rm -f $(OBJS) $(PROGRAM).kex
|
||||
|
||||
link:
|
||||
ld $(LDFLAGS) -o $(PROGRAM).kex $(OBJS)
|
||||
$(OBJCOPY) $(PROGRAM).kex -O binary
|
||||
|
||||
%.gox: %.go.o
|
||||
$(OBJCOPY) -j .go_export $< $@
|
||||
|
||||
%.go.o: %.go
|
||||
$(GO) $(GOFLAGS) -o $@ -c $<
|
||||
|
||||
%.o: %.asm
|
||||
$(NASM) $<
|
20
programs/develop/golang/example/colors.go
Normal file
20
programs/develop/golang/example/colors.go
Normal file
@ -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
|
||||
)
|
77
programs/develop/golang/example/example.go
Normal file
77
programs/develop/golang/example/example.go
Normal file
@ -0,0 +1,77 @@
|
||||
package example
|
||||
|
||||
import (
|
||||
"colors"
|
||||
"../kos"
|
||||
)
|
||||
|
||||
const (
|
||||
Btn1 = 2
|
||||
Btn2 = 3
|
||||
BtnExit = 1
|
||||
)
|
||||
|
||||
type Button struct { // structure gui button
|
||||
label string
|
||||
x int
|
||||
y int
|
||||
id int
|
||||
}
|
||||
|
||||
func NewButton() Button {
|
||||
object := Button{"Text", 0, 0, Btn1} // default data
|
||||
return object
|
||||
}
|
||||
|
||||
func (button *Button) make() {
|
||||
kos.CreateButton(button.x, button.y, len(button.label)*15, 30, button.id, colors.Blue)
|
||||
kos.WriteText(button.x, button.y, 0x11000000|colors.White, button.label)
|
||||
}
|
||||
|
||||
func RedrawAll(bar_pos int) {
|
||||
kos.Redraw(1)
|
||||
kos.Window(500, 250, 420, 200, "Example GoLang")
|
||||
kos.DrawLine(32, 80, 150, 80, colors.Green)
|
||||
kos.DrawBar(bar_pos, 90, 100, 30, colors.Red)
|
||||
|
||||
b1 := NewButton()
|
||||
b1.label = " <- "
|
||||
b1.x = 32
|
||||
b1.y = 128
|
||||
b1.id = Btn1
|
||||
b1.make()
|
||||
|
||||
b2 := NewButton()
|
||||
b2.label = " -> "
|
||||
b2.x = 310
|
||||
b2.y = 128
|
||||
b2.id = Btn2
|
||||
b2.make()
|
||||
}
|
||||
|
||||
func Main() {
|
||||
var pos = 160
|
||||
time := kos.GetTime()
|
||||
kos.DebugOutStr("Time: ")
|
||||
kos.DebugOutHex(time)
|
||||
for {
|
||||
switch kos.Event() {
|
||||
case kos.EVENT_REDRAW:
|
||||
RedrawAll(pos)
|
||||
break
|
||||
case kos.EVENT_BUTTON:
|
||||
switch kos.GetButtonID() {
|
||||
case Btn1:
|
||||
pos -= 32
|
||||
RedrawAll(pos)
|
||||
break
|
||||
case Btn2:
|
||||
pos += 32
|
||||
RedrawAll(pos)
|
||||
break
|
||||
case BtnExit:
|
||||
kos.Exit()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
31
programs/develop/golang/example/static.lds
Normal file
31
programs/develop/golang/example/static.lds
Normal file
@ -0,0 +1,31 @@
|
||||
SECTIONS
|
||||
{
|
||||
. = 0x00000;
|
||||
.text :
|
||||
{
|
||||
LONG(0x554e454D);
|
||||
LONG(0x31305445);
|
||||
LONG(1);
|
||||
LONG(go.example.Main);
|
||||
LONG(__end);
|
||||
LONG(0x10000);
|
||||
LONG(0x10000);
|
||||
LONG(0);
|
||||
LONG(0);
|
||||
*(.text)
|
||||
}
|
||||
.eh_frame : {
|
||||
*(.eh_frame)
|
||||
}
|
||||
.group : {
|
||||
*(.group)
|
||||
}
|
||||
.data : {
|
||||
*(.data)
|
||||
}
|
||||
.rodata : {
|
||||
*(.rodata)
|
||||
*(.rodata.*)
|
||||
}
|
||||
__end = .;
|
||||
}
|
34
programs/develop/golang/kos.go
Normal file
34
programs/develop/golang/kos.go
Normal file
@ -0,0 +1,34 @@
|
||||
package kos
|
||||
|
||||
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 GetTime()(time uint32)
|
||||
func Event()(int)
|
||||
func GetButtonID()(id int)
|
||||
func CreateButton(x int, y int, xsize int, ysize int, id int, color uint32)
|
||||
func Exit()
|
||||
func Redraw(int)
|
||||
func Window(y int, x int, w int,h int, title string)
|
||||
func WriteText(x int ,y int , color uint32, text string)
|
||||
func WriteText2(int ,int ,int, uint32,uint32)
|
||||
func DrawLine(x1 int, y1 int, x2 int, y2 int, color uint32)(uint32)
|
||||
func DrawBar(x int, y int, xsize int, ysize int, color uint32)
|
||||
func DebugOutHex(uint32)
|
||||
func DebugOutChar(byte)
|
||||
func DebugOutStr(string)
|
||||
|
||||
func Pointer2byteSlice(ptr uint32) *[]byte __asm__("__unsafe_get_addr")
|
||||
|
||||
//func Pointer2uint32(ptr interface{}) uint32 __asm__("__unsafe_get_addr")
|
1
programs/develop/golang/run.bat
Normal file
1
programs/develop/golang/run.bat
Normal file
@ -0,0 +1 @@
|
||||
qemu-system-i386 -fda C:\Users\rgimad\Documents\Programming_projects\KOS_IMAGES\latest_kolibri.img -boot a -m 512 -usbdevice tablet -drive file=fat:rw:.
|
327
programs/develop/golang/syscalls.asm
Normal file
327
programs/develop/golang/syscalls.asm
Normal file
@ -0,0 +1,327 @@
|
||||
|
||||
SECTION .text
|
||||
|
||||
global go.kos.Sleep
|
||||
global go.kos.Event
|
||||
global go.kos.GetButtonID
|
||||
global go.kos.CreateButton
|
||||
global go.kos.Exit
|
||||
global go.kos.Redraw
|
||||
global go.kos.Window
|
||||
global go.kos.WriteText
|
||||
global go.kos.GetTime
|
||||
global go.kos.DrawLine
|
||||
global go.kos.DrawBar
|
||||
global go.kos.DebugOutHex
|
||||
global go.kos.DebugOutChar
|
||||
global go.kos.DebugOutStr
|
||||
global go.kos.WriteText2
|
||||
|
||||
global runtime.memequal32..f
|
||||
runtime.memequal32..f:
|
||||
ret
|
||||
|
||||
global runtime.memequal8..f
|
||||
runtime.memequal8..f:
|
||||
ret
|
||||
|
||||
global runtime.memequal
|
||||
runtime.memequal:
|
||||
ret
|
||||
|
||||
global go.kos.SetByteString
|
||||
go.kos.SetByteString:
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
mov eax, [ebp+8]
|
||||
mov ebx, [ebp+12]
|
||||
mov ecx, [ebp+16]
|
||||
mov dh, [ebp+20]
|
||||
mov byte[eax+ecx], dh
|
||||
mov esp, ebp
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
global __go_runtime_error
|
||||
global __go_register_gc_roots
|
||||
global __unsafe_get_addr
|
||||
|
||||
__unsafe_get_addr:
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
mov eax, [ebp+8]
|
||||
mov esp, ebp
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
__go_register_gc_roots:
|
||||
__go_runtime_error:
|
||||
ret
|
||||
|
||||
global runtime.writeBarrier
|
||||
global runtime.gcWriteBarrier
|
||||
runtime.writeBarrier:
|
||||
mov eax, [esp+8]
|
||||
mov ebx, [esp+12]
|
||||
mov dword[eax], ebx
|
||||
ret
|
||||
|
||||
global runtime.strequal..f
|
||||
runtime.strequal..f:
|
||||
mov eax,[esp+8]
|
||||
mov ebx,[esp+16]
|
||||
mov ecx,0
|
||||
strcmp_loop:
|
||||
mov byte dl,[eax+ecx]
|
||||
mov byte dh,[ebx+ecx]
|
||||
inc ecx
|
||||
cmp dl,0
|
||||
je strcmp_end_0
|
||||
cmp byte dl,dh
|
||||
je strcmp_loop
|
||||
jl strcmp_end_1
|
||||
jg strcmp_end_2
|
||||
strcmp_end_0:
|
||||
cmp dh,0
|
||||
jne strcmp_end_1
|
||||
xor ecx,ecx
|
||||
ret
|
||||
strcmp_end_1:
|
||||
mov ecx,1
|
||||
ret
|
||||
strcmp_end_2:
|
||||
mov ecx,-1
|
||||
ret
|
||||
|
||||
runtime.gcWriteBarrier:
|
||||
mov eax, [esp+8]
|
||||
mov ebx, [esp+12]
|
||||
mov dword[eax], ebx
|
||||
ret
|
||||
|
||||
global runtime.goPanicIndex
|
||||
runtime.goPanicIndex:
|
||||
ret
|
||||
|
||||
global runtime.registerGCRoots
|
||||
runtime.registerGCRoots:
|
||||
ret
|
||||
|
||||
global memcmp
|
||||
memcmp:
|
||||
push ebp
|
||||
mov ebp,esp
|
||||
mov esi, [ebp+8] ; Move first pointer to esi
|
||||
mov edi, [ebp+12] ; Move second pointer to edi
|
||||
mov ecx, [ebp+16] ; Move length to ecx
|
||||
|
||||
cld ; Clear DF, the direction flag, so comparisons happen
|
||||
; at increasing addresses
|
||||
cmp ecx, ecx ; Special case: If length parameter to memcmp is
|
||||
; zero, don't compare any bytes.
|
||||
repe cmpsb ; Compare bytes at DS:ESI and ES:EDI, setting flags
|
||||
; Repeat this while equal ZF is set
|
||||
setz al
|
||||
mov esp,ebp
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
|
||||
go.kos.Sleep:
|
||||
push ebp
|
||||
mov ebp,esp
|
||||
mov eax, 5
|
||||
mov ebx, [ebp+8]
|
||||
int 0x40
|
||||
mov esp,ebp
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
|
||||
go.kos.Event:
|
||||
mov eax, 10
|
||||
int 0x40
|
||||
ret
|
||||
|
||||
go.kos.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.kos.Exit:
|
||||
mov eax, -1
|
||||
int 0x40
|
||||
ret
|
||||
|
||||
go.kos.Redraw:
|
||||
push ebp
|
||||
mov ebp,esp
|
||||
mov eax, 12
|
||||
mov ebx, [ebp+8]
|
||||
int 0x40
|
||||
mov esp,ebp
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
go.kos.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.kos.WriteText:
|
||||
push ebp
|
||||
mov ebp,esp
|
||||
mov eax,4
|
||||
mov ebx,[ebp+8]
|
||||
shl ebx,16
|
||||
mov bx,[ebp+12]
|
||||
mov ecx,[ebp+16]
|
||||
mov edx,[ebp+20]
|
||||
mov esi,[ebp+24]
|
||||
int 0x40
|
||||
mov esp,ebp
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
go.kos.WriteText2:
|
||||
push ebp
|
||||
mov ebp,esp
|
||||
mov eax,47
|
||||
mov ebx,[ebp+8]
|
||||
shl ebx,16
|
||||
mov ecx,[ebp+12]
|
||||
mov edx,[ebp+20]
|
||||
shl edx,16
|
||||
add edx, [ebp+24]
|
||||
mov esi,[ebp+28]
|
||||
int 0x40
|
||||
mov esp,ebp
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
go.kos.DrawLine:
|
||||
push ebp
|
||||
mov ebp,esp
|
||||
mov ebx,[ebp+8]
|
||||
shl ebx,16
|
||||
mov bx,[ebp+16]
|
||||
mov ecx,[ebp+12]
|
||||
shl ecx,16
|
||||
mov cx,[ebp+20]
|
||||
mov edx,[ebp+24]
|
||||
mov eax,38
|
||||
int 0x40
|
||||
mov esp,ebp
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
go.kos.DrawBar:
|
||||
push ebp
|
||||
mov ebp,esp
|
||||
mov eax,13
|
||||
mov ebx,[ebp+8]
|
||||
shl ebx,16
|
||||
mov bx,[ebp+16]
|
||||
mov ecx,[ebp+12]
|
||||
shl ecx,16
|
||||
mov cx,[ebp+20]
|
||||
mov edx,[ebp+24]
|
||||
int 0x40
|
||||
mov esp,ebp
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
go.kos.GetTime:
|
||||
mov eax, 3
|
||||
int 0x40
|
||||
ret
|
||||
|
||||
go.kos.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.kos.DebugOutChar:
|
||||
mov al, [esp+4]
|
||||
pushf
|
||||
pushad
|
||||
mov cl,al
|
||||
mov eax,63
|
||||
mov ebx,1
|
||||
int 0x40
|
||||
popad
|
||||
popf
|
||||
ret
|
||||
|
||||
go.kos.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.kos.CreateButton:
|
||||
push ebp
|
||||
mov ebp,esp
|
||||
mov eax, 8
|
||||
mov ebx, [ebp+8]
|
||||
shl ebx, 16
|
||||
mov bx, [ebp+16]
|
||||
mov ecx, [ebp+12]
|
||||
shl ecx, 16
|
||||
mov cx, [ebp+20]
|
||||
mov edx, [ebp+24]
|
||||
mov esi, [ebp+28]
|
||||
int 0x40
|
||||
mov esp,ebp
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
SECTION .data
|
||||
__hexdigits:
|
||||
db '0123456789ABCDEF'
|
||||
|
||||
__test:
|
||||
dd __hexdigits
|
||||
dd 15
|
Loading…
Reference in New Issue
Block a user