fixed linker and syscall

git-svn-id: svn://kolibrios.org@9053 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
pavelyakov 2021-07-12 12:28:41 +00:00
parent 716db38e51
commit 1979e6ff29
5 changed files with 99 additions and 174 deletions

View File

@ -1,18 +1,19 @@
PROGRAM=example PROGRAM=example
SOURCES=syscalls.o colors.go.o colors.gox os.go.o os.gox $(PROGRAM).go.o 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 LIBOBJ=os.go.o syscalls.o colors.go.o
GOFLAGS= -nostdlib -nostdinc -fno-stack-protector -fno-split-stack -static -m32 -g -I. GOFLAGS = -m32 -c -nostdlib -nostdinc -fno-stack-protector -fno-split-stack -static -fno-leading-underscore -fno-common -fno-pie -g -I.
GO=gccgo GO = gccgo
ASFLAGS= -felf GCC = gcc
ASFLAGS= -g -f elf32 -F dwarf
NASM= nasm $(ASFLAGS) NASM= nasm $(ASFLAGS)
OBJCOPY=objcopy OBJCOPY=objcopy
LDFLAGS=-T static.lds -n -m elf_i386 LDFLAGS=-n -T static.lds -m elf_i386 --no-ld-generated-unwind-info
all: $(SOURCES) link all: $(SOURCES) link
clean: clean:
rm *.o *.gox $(PROGRAM).kex rm -f *.o *.gox $(PROGRAM).kex
link: link:
ld $(LDFLAGS) -o $(PROGRAM).kex $(SOURCES) ld $(LDFLAGS) -o $(PROGRAM).kex $(SOURCES)
$(OBJCOPY) $(PROGRAM).kex -O binary $(OBJCOPY) $(PROGRAM).kex -O binary

View File

@ -10,25 +10,20 @@ const (
) )
func RedrawAll(bar_pos int){ func RedrawAll(bar_pos int){
btn_txt1:=" <- " os.Redraw(1)
btn_txt2:=" -> " os.Window(500,250,420,200, "Test Golang")
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.DrawLine(32, 80, 150, 80, colors.Green)
os.CreateButton(32, 128, 80, 30, Btn1, colors.Blue); os.CreateButton(32, 128, 80, 30, Btn1, colors.Blue);
os.CreateButton(300, 128, 80, 30, Btn2, colors.Blue); os.CreateButton(300, 128, 80, 30, Btn2, colors.Blue);
os.WriteText(32,128, 0x11000000 | colors.White,btn_txt1, 10) os.WriteText(32,128, 0x11000000 | colors.White," <- ")
os.WriteText(320,128, 0x11000000 | colors.White,btn_txt2, 10) os.WriteText(320,128, 0x11000000 | colors.White," -> ")
os.DrawBar(uint32(bar_pos), 90, 100, 30, colors.Red); os.DrawBar(bar_pos, 90, 100, 30, colors.Red);
} }
func Load() { func Load() {
time := os.GetTime() //time := os.GetTime()
os.DebugOutStr("Time: ") //os.DebugOutStr("Time: ")
os.DebugOutHex(time) //os.DebugOutHex(time)
var pos=32; var pos=32;
for true { for true {
switch os.Event() { switch os.Event() {

View File

@ -20,9 +20,10 @@ func CreateButton(x uint32, y uint32, xsize uint32, ysize uint32, id uint32, col
func Exit() func Exit()
func Redraw(uint32) func Redraw(uint32)
func Window(y uint32, x uint32, w uint32,h uint32, title 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 WriteText(x uint32 ,y uint32 , color uint32, text string)
func WriteText2(uint32 ,string ,uint32, uint32,uint32)
func DrawLine(x1 uint32, y1 uint32, x2 uint32, y2 uint32, color uint32)(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 DrawBar(x int, y int, xsize int, ysize int, color uint32)
func DebugOutHex(uint32) func DebugOutHex(uint32)
func DebugOutChar(byte) func DebugOutChar(byte)
func DebugOutStr(string) func DebugOutStr(string)

View File

@ -1,113 +1,31 @@
/*OUTPUT_FORMAT("binary")*/
ENTRY(__start)
SECTIONS SECTIONS
{ {
.text 0x000000: . = 0x00000;
.text :
{ {
LONG(0x554e454D); LONG(0x554e454D);
LONG(0x32305445); LONG(0x31305445);
LONG(1); LONG(1);
LONG(__start); LONG(go.kernel.Load);
LONG(___iend); LONG(__end);
LONG(___memsize); LONG(0x10000);
LONG(___stacktop); LONG(0x10000);
LONG(0);
LONG(0); LONG(0);
LONG(0); /* full path */
LONG(0); /*FIXME tls data */
*(.init)
*(.text) *(.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)
} }
.eh_frame : {
.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) *(.eh_frame)
___iend = . ;
} }
.group : {
bss ALIGN(16): *(.group)
{
*(.bss)
*(COMMON)
. = ALIGN(16);
___menuet__app_path_area = .;
. = . + 1024 + 16;
___stacktop = .;
___memsize = . ;
} }
.data : {
/DISCARD/ : *(.data)
{ }
*(.debug$S) .rodata : {
*(.debug$T) *(.rodata)
*(.debug$F) *(.rodata.*)
*(.drectve) }
*(.note.GNU-stack) __end = .;
*(.comment)
*(.debug_abbrev)
*(.debug_info)
*(.debug_line)
*(.debug_frame)
*(.debug_loc)
*(.debug_pubnames)
*(.debug_aranges)
*(.debug_ranges)
}
} }

View File

@ -1,9 +1,6 @@
SECTION .text SECTION .text
[GLOBAL __start]
extern go.kernel.Load
global go.os.Sleep global go.os.Sleep
global go.os.Event global go.os.Event
global go.os.GetButtonID global go.os.GetButtonID
@ -18,10 +15,7 @@ global go.os.DrawBar
global go.os.DebugOutHex global go.os.DebugOutHex
global go.os.DebugOutChar global go.os.DebugOutChar
global go.os.DebugOutStr global go.os.DebugOutStr
global go.os.WriteText2
__start:
call go.kernel.Load
ret
go.os.Sleep: go.os.Sleep:
push ebp push ebp
@ -35,12 +29,8 @@ go.os.Sleep:
go.os.Event: go.os.Event:
push ebp
mov ebp,esp
mov eax, 10 mov eax, 10
int 0x40 int 0x40
mov esp,ebp
pop ebp
ret ret
go.os.GetButtonID: go.os.GetButtonID:
@ -56,12 +46,8 @@ go.os.GetButtonID:
ret ret
go.os.Exit: go.os.Exit:
push ebp
mov ebp,esp
mov eax, -1 mov eax, -1
int 0x40 int 0x40
mov esp,ebp
pop ebp
ret ret
go.os.Redraw: go.os.Redraw:
@ -95,42 +81,66 @@ go.os.Window:
ret ret
go.os.WriteText: go.os.WriteText:
push ebp
mov ebp,esp
mov eax,4 mov eax,4
mov ebx,[esp+4] mov ebx,[ebp+8]
shl ebx,16 shl ebx,16
mov bx,[esp+8] mov bx,[ebp+12]
mov ecx,[esp+12] mov ecx,[ebp+16]
mov edx,[esp+16] mov edx,[ebp+20]
mov esi,[esp+20] mov esi,[ebp+24]
int 0x40 int 0x40
mov esp,ebp
pop ebp
ret ret
go.os.DrawLine: go.os.WriteText2:
push ebx push ebp
mov ebx,[esp+8] mov ebp,esp
mov eax,47
mov ebx,[ebp+8]
shl ebx,16 shl ebx,16
mov bx,[esp+16] mov ecx,[ebp+12]
mov ecx,[esp+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.os.DrawLine:
push ebp
mov ebp,esp
mov ebx,[ebp+8]
shl ebx,16
mov bx,[ebp+16]
mov ecx,[ebp+12]
shl ecx,16 shl ecx,16
mov cx,[esp+20] mov cx,[ebp+20]
mov edx,[esp+24] mov edx,[ebp+24]
mov eax,38 mov eax,38
int 0x40 int 0x40
pop ebx mov esp,ebp
pop ebp
ret ret
go.os.DrawBar: go.os.DrawBar:
push ebx push ebp
mov ebp,esp
mov eax,13 mov eax,13
mov ebx,[esp+8] mov ebx,[ebp+8]
shl ebx,16 shl ebx,16
mov bx,[esp+16] mov bx,[ebp+16]
mov ecx,[esp+12] mov ecx,[ebp+12]
shl ecx,16 shl ecx,16
mov cx,[esp+20] mov cx,[ebp+20]
mov edx,[esp+24] mov edx,[ebp+24]
int 0x40 int 0x40
pop ebx mov esp,ebp
pop ebp
ret ret
go.os.GetTime: go.os.GetTime:
@ -138,7 +148,7 @@ go.os.GetTime:
int 0x40 int 0x40
ret ret
go.os.DebugOutHex: go.os.DebugOutHex:
mov eax, [esp+4] mov eax, [esp+4]
mov edx, 8 mov edx, 8
.new_char: .new_char:
@ -155,7 +165,7 @@ go.os.DebugOutHex:
jnz .new_char jnz .new_char
ret ret
go.os.DebugOutChar: go.os.DebugOutChar:
mov al, [esp+4] mov al, [esp+4]
pushf pushf
pushad pushad
@ -182,20 +192,20 @@ go.os.DebugOutStr:
ret ret
go.os.CreateButton: go.os.CreateButton:
push ebx push ebp
push esi mov ebp,esp
mov ebx,[esp+12] mov eax, 8
shl ebx,16 mov ebx, [ebp+8]
mov bx,[esp+20] shl ebx, 16
mov ecx,[esp+16] mov bx, [ebp+16]
shl ecx,16 mov ecx, [ebp+12]
mov cx,[esp+24] shl ecx, 16
mov edx,[esp+28] mov cx, [ebp+20]
mov esi,[esp+32] mov edx, [ebp+24]
mov eax,8 mov esi, [ebp+28]
int 0x40 int 0x40
pop esi mov esp,ebp
pop ebx pop ebp
ret ret
SECTION .data SECTION .data