- 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
This commit is contained in:
superturbocat2001 2020-11-12 00:43:46 +00:00
parent c2b9713bb9
commit b215841161
5 changed files with 300 additions and 31 deletions

View File

@ -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) $<

View 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
)

View File

@ -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()
}
}
}
}

View File

@ -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)

View File

@ -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'