Page 13 of 16

Re: Newlib

Posted: Thu Nov 13, 2014 2:05 pm
by Serge
pascualle
Странно. Я думаю у тебя изменены локальные файлы.

Code: Select all

yacc  glcpp/glcpp-parse.y
Этой строчки при сборке не должно было быть. Скорее всего у тебя другие glcpp-parse.c и glcpp-lex.c. Проверь дерево Mesa на модификацию.

Re: Newlib

Posted: Thu Nov 13, 2014 2:12 pm
by Serge
Лог сборки Mesa

Re: Newlib

Posted: Thu Nov 13, 2014 2:48 pm
by pascualle
ок, удалю вечером все, соберусь по чистому и отпишусь

upd:
удалил все, взял последнюю,

Code: Select all

D:\kolibri\contrib
At revision: 5176
версию

Запустил все собирать как писал раньше, ошибка все та же...
Пока идей нет

Re: Newlib

Posted: Wed Nov 26, 2014 4:21 am
by Serge
pascualle
Проблема решилась ?
Мне не удалось воспроизвести ошибку. Для проверки сделал экспорт contrib #5141 и собрал под msys и debian linux. Разницы нет, всё собирается (хотя mesa линкуется несколько раз, где-то косяк с зависимостями)

Re: Newlib

Posted: Wed Nov 26, 2014 10:44 am
by pascualle
(правка: удалено по причине не верной информации сообщения)

Re: Newlib

Posted: Wed Nov 26, 2014 3:35 pm
by Serge
pascualle
Чудеса. У меня есть и yacc и bison. Я знаю, что они не должны вызываться. Сам писал мейкфайлы.
Ты можешь сделать лог полной сборки mesa с yacc и bison?

Re: Newlib

Posted: Thu Nov 27, 2014 6:47 am
by Serge
В #5190 добавил разбивку командной строки на параметры
Скомпилированные DLL и библиотеки импорта
Spoiler:
cmdline.png
cmdline.png (9.28 KiB)
Viewed 10999 times

Re: Newlib

Posted: Thu Nov 27, 2014 12:23 pm
by pascualle
Serge,
нашел причину: затесался cygwin/bin в переменную PATH
(моя беда -- другим наука)

Re: Newlib

Posted: Fri Aug 28, 2015 11:16 pm
by ashmew2
Hello,

I've been playing with newlib and the cross compiler for some time now. I decided to write some C and assembly code that would enable us to have "wrappers" for calling assembly libraries (http.obj, box_lib.obj and others) directly from C. Since I don't use Windows, I'm trying to avoid the MS COFF format, and sticking to the COFF format.

dll.asm :

Code: Select all

 __DEBUG__       = 1
__DEBUG_LEVEL__ = 1

format coff
use32                                   ; Tell compiler to use 32 bit instructions


include 'struct.inc'
include 'proc32.inc'
include 'macros.inc'
purge section,mov,add,sub
include 'debug-fdo.inc'

include 'network.inc'
include 'http.inc'
include 'dll.inc'
	
public init_network as '_init_network'
public dll.Load as '_dll_load'
	
section '.flat' code	
	
proc init_network
	
	mcall 68,11
	
	stdcall dll.Load, @IMPORT
	;; stdcall new_dll_load, @IMPORT
        test    eax, eax
        jnz     error
	
	mov eax, 0xAABBCCDD
	mcall -1
	
error:	
	mov eax, 0xEEFF8899
	mcall -1
endp	
	
@IMPORT:
library lib_http,               'http.obj'

import  lib_http, \
        HTTP_get,               'get', \
        HTTP_post,              'post', \
        HTTP_receive,           'receive', \
        HTTP_find_header_field, 'find_header_field', \
        HTTP_free,              'free', \
        HTTP_escape,            'escape'
dll.c

Code: Select all

extern void init_network(void);

int main()
{
  __asm__ volatile("int3"::);
  init_network();
  __asm__ volatile("int3"::);

  return 0;
}
Compiling with :


alias kgcc='~/i586-kos32/kos32/bin/i586-kos32-gcc -I/home/user/kolibrios/contrib/sdk/sources/newlib/libc/include'

fasm dll.asm dll.obj
kgcc dll.c dll.obj -o DLLFILE

Shifting this DLLFILE to KolibriOS. The program starts running, but the address for the CALL instruction in the final executable is wrong. It points to a few bytes before the address of where dll.Load procedure is loaded. In my case, The dll.Load is at address 0xC460 but the STDCALL dll.Load line calls the address 0xC44A .

Using mtdbg, if I fix the address from 0xC44A to 0xC460, the library loading seems to work fine (evident from correct value loaded into EAX). What could be going wrong?

Thanks.

Re: Newlib

Posted: Sat Aug 29, 2015 1:59 am
by ashmew2
Hi again.

I've written some code to interface C with our assembly network library procedures and it feels good to see C being able to load libraries at run time. Binary for Kolibri is also attached to post.

dllhttp.asm:

Code: Select all

 __DEBUG__       = 1
__DEBUG_LEVEL__ = 1

format coff
use32                                   ; Tell compiler to use 32 bit instructions


include 'struct.inc'
include 'proc32.inc'
include 'macros.inc'
purge section,mov,add,sub
include 'debug-fdo.inc'

include 'network.inc'
include 'http.inc'
include 'dll.inc'
	
virtual at 0
        http_msg http_msg
end virtual

public init_network as '_init_network'
public open_site as '_open_site'
public dll.Load as '_dll_load'
public dll.Link as '_dll_link'
public dll.Init as '_dll_init'
public mem.Alloc as '_mem_alloc'
public mem.ReAlloc as '_mem_realloc'

section '.flat' code	
	
proc init_network
	
	mcall 68,11
	
	stdcall dll.Load, @IMPORT
	;; stdcall new_dll_load, @IMPORT
        test    eax, eax
        jnz     error
	
	mov eax, 0xAABBCCDD
	ret
	
error:	
	mov eax, 0xEEFF8899
	mcall -1
endp	
	
proc open_site
	mov eax, identifier
	invoke  HTTP_get, sz_url, 0, 0, 0
        test    eax, eax
        jz      error2
        mov     [identifier], eax

  .again:
        invoke  HTTP_receive, [identifier]
        test    eax, eax
        jnz     .again
	
	mov eax, [identifier]
	add eax, 32
	mov ebx, [eax]
	
	int3
	DEBUGF 1, "The content is : %s", ebx
	ret
	
error2:
	mcall -1
endp	

@IMPORT:
	
library lib_http,               'http.obj'

import  lib_http, \
        HTTP_get,               'get', \
        HTTP_post,              'post', \
        HTTP_receive,           'receive', \
        HTTP_find_header_field, 'find_header_field', \
        HTTP_free,              'free', \
        HTTP_escape,            'escape'

public HTTP_get as '_http_get'
public HTTP_post as '_http_post'
public HTTP_receive as '_http_receive'
public HTTP_find_header_field as '_http_find_header_field'
public HTTP_free as '_http_free'
public HTTP_escape as '_http_escape'
	
sz_url                  db 'http://www.ashmew2.me'
identifier              dd 0
include_debug_strings
dllhttp.c:

Code: Select all

extern void init_network(void);
extern void open_site(void);

#define NULL 0

int main()
{

  __asm__ volatile("int3"::);

  init_network();
  open_site();

  return 0;
}




Compile/Link as usual and run the binary.

To get your hands dirty without compiling, this is how you should run the binary in MTDBG:

Code: Select all

  load dllhttpbin
  g
  bp c463
  g
  r eip=c479
  g
  d eax
  <Now keep pressing d to see the site's content>
  g

Re: Newlib

Posted: Tue Sep 01, 2015 11:29 pm
by ashmew2
Fixed the address issue for CALL instructions by moving the line

Code: Select all

section '.flat' code
to before the line where we include all .inc files

This fixes the issue and I was able to create a wrapper for calling http.obj procedures as C functions.
Thank you for the cross compiler, Serge. It has really made life easier ;)

Re: Newlib

Posted: Sat Jan 30, 2016 5:04 pm
by AlexKaz
Здравствуйте. У меня Linux Mint 32bit. Поставил mingw под wine 1.8, закинул libiconv-2 в ~/.wine/drive_c/MinGW/msys/1.0/home/autobuild/tools/win32/bin/, в ~/.wine/drive_d/ - папочку kolibri/sdk (как в статье "Пишем на языке С/C++ в Windows под KolibriOS / Хабрахабр"). Получаю ошибки при компиляции libc и примера:

$ export PATH=$PATH:/home/autobuild/tools/win32/bin
$ cd /d/kolibri/contrib/sdk/sources/newlib/libc
$ make shared
kos32-gcc -c -O2 -fno-ident -fomit-frame-pointer -fexceptions -DBUILD_DLL -DMISSING_SYSCALL_NAMES -D_IEEE_LIBM -DHAVE_RENAME -I ./include -o crt/crtdll.o crt/crtdll.c
make: *** [crt/crtdll.o] Error 1

$ cd /d/work
$ make
kos32-gcc -c -O2 -fomit-frame-pointer -fno-ident -U__WIN32__ -U_Win32 -U_WIN32 -
U__MINGW32__ -U_MSC_VER -I/d/kolibri/contrib/sdk/sources/newlib/libc/include -o
simple.o simple.c
make: *** [simple.o] Error 1

Re: Newlib

Posted: Sat Jan 30, 2016 5:33 pm
by Serge
AlexKaz
Не знаю чем помочь. Wine я не пользовался. А Msys установлен, или только папка есть ?
Если надо я могу написать, как собрать косскомпилятор.

Re: Newlib

Posted: Sat Jan 30, 2016 5:47 pm
by AlexKaz
Оо, всё отлично, понадобилось скопировать все библиотеки из ~/.wine/drive_c/MinGW/bin/ в ~/.wine/drive_c/MinGW/msys/1.0/home/autobuild/tools/win32/bin/ =) и fasm.exe воткнуть туда же..

Re: Newlib

Posted: Wed Mar 09, 2016 6:02 pm
by ashmew2
Hi

This is regarding the isspace() function in C:

If I build the spacer.c file with this process:

kos32-gcc -c -I/home/bob/kolibrios/contrib/sdk/sources/newlib/libc/include -g -U_Win32 -U_WIN32 -U__MINGW32__ space.c kolibri_debug.c

kos32-ld space.o kolibri_debug.o -T/home/bob/kolibrios/contrib/sdk/sources/newlib/libc/app.lds -nostdlib -static --image-base 0 -lgcc -L/home/autobuild/tools/win32/mingw32/lib /home/autobuild/tools/win32/lib/libdll.a /home/autobuild/tools/win32/lib/libapp.a /home/autobuild/tools/win32/lib/libc.dll.a -static -o spacer

objcopy -O binary spacer

If I run this file on Kolibri, isspace() shows False for all integers in 0-10 except 0.
10 should be true. Right?
It also returns true for isspace('a').

I checked the implementation of isspace.c / isspace() function, and it seems like it does

Code: Select all

#define _S 010

int _DEFUN(isspace,(c),int c)
{
	return(__ctype_ptr__[c+1] & _S);
}
Is this correct?