From adda605e2e2a75e04437f9c1c16d34ce22ae71de Mon Sep 17 00:00:00 2001 From: "Sergey Semyonov (Serge)" Date: Mon, 18 Jan 2016 17:02:08 +0000 Subject: [PATCH] newlib: rework console initialization. git-svn-id: svn://kolibrios.org@6074 a494cfbc-eb01-0410-851d-a64ba20cac60 --- contrib/sdk/sources/newlib/app.lds | 11 ++++++----- contrib/sdk/sources/newlib/libc/crt/crt1.c | 9 +++++++++ contrib/sdk/sources/newlib/libc/crt/crtbegin.c | 15 --------------- contrib/sdk/sources/newlib/libc/crt/crtdll.c | 12 ++++++++++-- contrib/sdk/sources/newlib/libc/stdio/printf.c | 10 ---------- contrib/sdk/sources/newlib/libc/stdio/puts.c | 9 --------- contrib/sdk/sources/newlib/libc/sys/conio.c | 6 +++--- contrib/sdk/sources/newlib/static.lds | 2 +- 8 files changed, 29 insertions(+), 45 deletions(-) delete mode 100644 contrib/sdk/sources/newlib/libc/crt/crtbegin.c diff --git a/contrib/sdk/sources/newlib/app.lds b/contrib/sdk/sources/newlib/app.lds index db673473a8..9054b2027c 100644 --- a/contrib/sdk/sources/newlib/app.lds +++ b/contrib/sdk/sources/newlib/app.lds @@ -14,7 +14,7 @@ SECTIONS LONG(___stacktop); LONG(___cmdline); LONG(___pgmname); /* full path */ - LONG(0); /*FIXME tls data */ + LONG(__subsystem__); LONG(__idata_start) LONG(__idata_end) LONG(_main) @@ -65,7 +65,7 @@ SECTIONS ___crt_xt_end__ = . ; } - .data ALIGN(64) : + .data ALIGN(16) : { PROVIDE ( __data_start__ = .) ; *(.data) @@ -74,17 +74,17 @@ SECTIONS *(.jcr) __CRT_MT = .; LONG(0); - PROVIDE ( __data_end__ = .) ; + PROVIDE ( __data_end__ = .) ; *(.data_cygwin_nocopy) ___iend = . ; } - .eh_frame BLOCK(16) : +/* .eh_frame BLOCK(16) : { PROVIDE (___EH_FRAME_BEGIN__ = .) ; *(.eh_frame*) } - +*/ .idata ALIGN(16): { __idata_start = .; @@ -120,6 +120,7 @@ SECTIONS *(.drectve) *(.note.GNU-stack) *(.comment) + *(.eh_frame) *(.debug_abbrev) *(.debug_info) *(.debug_line) diff --git a/contrib/sdk/sources/newlib/libc/crt/crt1.c b/contrib/sdk/sources/newlib/libc/crt/crt1.c index a778c96a84..048308bf3f 100644 --- a/contrib/sdk/sources/newlib/libc/crt/crt1.c +++ b/contrib/sdk/sources/newlib/libc/crt/crt1.c @@ -29,8 +29,12 @@ struct app_hdr int stacktop; char *cmdline; char *path; + int __subsystem__; }; +void __init_conio(); +void __fini_conio(); + extern int main (int, char **, char **); /* NOTE: The code for initializing the _argv, _argc, and environ variables @@ -177,6 +181,8 @@ __crt_startup (void) init_reent(); init_stdio(); + if(header->__subsystem__ == 3) + __init_conio(); if( header->cmdline[0] != 0) { @@ -196,6 +202,9 @@ __crt_startup (void) retval = main(argc, argv, NULL); done: + if(header->__subsystem__ == 3) + __fini_conio(); + exit (retval); } diff --git a/contrib/sdk/sources/newlib/libc/crt/crtbegin.c b/contrib/sdk/sources/newlib/libc/crt/crtbegin.c deleted file mode 100644 index c31fe3e5ee..0000000000 --- a/contrib/sdk/sources/newlib/libc/crt/crtbegin.c +++ /dev/null @@ -1,15 +0,0 @@ - -extern void _pei386_runtime_relocator (void); - -int DllStartup(void *module, int reason) -{ - _pei386_runtime_relocator(); - return 1; -}; - -void ___dll_start () - -{ - _pei386_runtime_relocator(); - -} diff --git a/contrib/sdk/sources/newlib/libc/crt/crtdll.c b/contrib/sdk/sources/newlib/libc/crt/crtdll.c index b5a8eac48d..a09fe374c5 100644 --- a/contrib/sdk/sources/newlib/libc/crt/crtdll.c +++ b/contrib/sdk/sources/newlib/libc/crt/crtdll.c @@ -29,7 +29,7 @@ struct app_hdr int stacktop; char *cmdline; char *path; - int reserved; + int __subsystem__; void *__idata_start; void *__idata_end; int (*main)(int argc, char **argv, char **envp); @@ -38,7 +38,8 @@ struct app_hdr void _pei386_runtime_relocator (void); void init_loader(void *libc_image); void init_reent(); - +void __init_conio(); +void __fini_conio(); int link_app(); void* get_entry_point(void *raw); int (*entry)(int, char **, char **); @@ -182,6 +183,10 @@ libc_crt_startup (void *libc_base) _tls_map[0] = 0xE0; init_reent(); init_stdio(); + + if(header->__subsystem__ == 3) + __init_conio(); + __do_global_ctors(); // __appenv = load_file("/sys/system.env", &__appenv_size); @@ -209,6 +214,9 @@ libc_crt_startup (void *libc_base) retval = header->main(argc, argv, NULL); done: + if(header->__subsystem__ == 3) + __fini_conio(); + exit (retval); } diff --git a/contrib/sdk/sources/newlib/libc/stdio/printf.c b/contrib/sdk/sources/newlib/libc/stdio/printf.c index ca67093e45..3327856071 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/printf.c +++ b/contrib/sdk/sources/newlib/libc/stdio/printf.c @@ -22,8 +22,6 @@ #include #include "local.h" -int __gui_mode; - int _DEFUN(_printf_r, (ptr, fmt), struct _reent *ptr _AND @@ -57,11 +55,3 @@ _DEFUN(printf, (fmt), } #endif /* ! _REENT_ONLY */ - -extern int __gui_mode; - -extern void __attribute__ ((constructor)) __init_conio(); -static void __attribute__ ((constructor)) init_printf() -{ - __gui_mode = (int)&__init_conio; -} diff --git a/contrib/sdk/sources/newlib/libc/stdio/puts.c b/contrib/sdk/sources/newlib/libc/stdio/puts.c index 2029cf0101..f498e37b69 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/puts.c +++ b/contrib/sdk/sources/newlib/libc/stdio/puts.c @@ -139,12 +139,3 @@ _DEFUN(puts, (s), } #endif - -extern int __gui_mode; - -extern void __attribute__ ((constructor)) __init_conio(); -static void __attribute__ ((constructor)) init_puts() -{ - __gui_mode = (int)&__init_conio; -} - diff --git a/contrib/sdk/sources/newlib/libc/sys/conio.c b/contrib/sdk/sources/newlib/libc/sys/conio.c index 47124725ee..6297895e87 100644 --- a/contrib/sdk/sources/newlib/libc/sys/conio.c +++ b/contrib/sdk/sources/newlib/libc/sys/conio.c @@ -21,19 +21,19 @@ static int console_write(const char *path, const void *buff, return count; }; -void __attribute__ ((constructor)) __init_conio() +void __init_conio() { __io_handle *ioh; load_libconsole(); - con_init(80, 25, 80, 250, "Console application"); + con_init(80, 25, 80, 500, "Console application"); ioh = &__io_tab[STDOUT_FILENO]; ioh->mode = _WRITE|_ISTTY; ioh->write = &console_write; }; -static void __attribute__ ((destructor)) __fini_conio() +void __fini_conio() { con_exit(0); } diff --git a/contrib/sdk/sources/newlib/static.lds b/contrib/sdk/sources/newlib/static.lds index 43ff453696..82c30481e9 100644 --- a/contrib/sdk/sources/newlib/static.lds +++ b/contrib/sdk/sources/newlib/static.lds @@ -14,7 +14,7 @@ SECTIONS LONG(___stacktop); LONG(___cmdline); LONG(___pgmname); /* full path */ - LONG(0); /*FIXME tls data */ + LONG(__subsystem__); *(.init) *(.text)