Changeset 2805


Ignore:
Timestamp:
Sep 1, 2006, 2:50:12 AM (19 years ago)
Author:
bird
Message:

restructuring.

Location:
trunk/libc
Files:
4 added
16 edited
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/libc/Config.kmk

    r2741 r2805  
    7474# Templates
    7575#
     76## @todo I need recursive inheritance!
    7677TEMPLATE_libc =
    7778TEMPLATE_libc_TOOL = GCC3
     
    8081TEMPLATE_libc_DEPS = $(LIBC-STD.H)
    8182TEMPLATE_libc_INST = usr/lib/
    82 TEMPLATE_libc_CFLAGS = $(TEMPLATE_lib_CFLAGS) -std=gnu99
     83TEMPLATE_libc_CFLAGS = $(TEMPLATE_lib_CFLAGS) -std=gnu99 -Wall -Wundef -Wmissing-prototypes
     84TEMPLATE_libc_CFLAGS.os2 = $(TEMPLATE_lib_CFLAGS.os2) -mstack-arg-probe
     85TEMPLATE_libc_CFLAGS.release = $(TEMPLATE_lib_CFLAGS.release) -O3 -mcpu=pentium
    8386
    8487TEMPLATE_libc.logstrict =
  • trunk/libc/include/InnoTekLIBC/fork.h

    r2787 r2805  
    566566     * management so multiple LIBC versions can share the same module lists. */
    567567    __LIBC_PFORKMODULE          pNext;
     568    /** The module handle. */
     569    unsigned                    hmod;
    568570    /** Reserved space to make it 32 byte aligned - must be zero. */
    569     unsigned                    auReserved[8];
     571    unsigned                    auReserved[7];
    570572} __LIBC_FORKMODULE;
    571573
     
    588590 * @returns 0 on normal process startup.
    589591 *
    590  * @returns 1 on forked child process startup.
     592 * @returns 1 on forked child process startup (not executable module).
    591593 *          The caller should respond by not calling any _DLL_InitTerm
    592  *          or similar constructs. If fExecutable the call will not
    593  *          return in this situation.
     594 *          or similar constructs.
    594595 *
    595596 * @returns negative on failure.
     
    599600 * @param   pModule     Pointer to the fork module structure for the
    600601 *                      module which is to registered.
    601  * @param   fExecutable Indicator that the call origins from crt0.s and
    602  *                      the final forking should start. The function
    603  *                      will not return if this flag is set and the process
    604  *                      was forked.
    605  *
    606  */
    607 int __libc_ForkRegisterModule(__LIBC_PFORKMODULE pModule, int fExecutable);
     602 */
     603int __libc_ForkRegisterModule(__LIBC_PFORKMODULE pModule);
    608604
    609605
  • trunk/libc/include/klibc/io.h

    r2742 r2805  
     1/* $Id: $ */
     2/** @file
     3 *
     4 * kLIBC I/O
     5 *
     6 * Copyright (c) 2006 knut st. osmundsen <bird@innotek.de>
     7 *
     8 *
     9 * This file is part of kLIBC.
     10 *
     11 * kLIBC is free software; you can redistribute it and/or modify
     12 * it under the terms of the GNU Lesser General Public License as published
     13 * by the Free Software Foundation; either version 2 of the License, or
     14 * (at your option) any later version.
     15 *
     16 * kLIBC is distributed in the hope that it will be useful,
     17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     19 * GNU Lesser General Public License for more details.
     20 *
     21 * You should have received a copy of the GNU Lesser General Public License
     22 * along with kLIBC; if not, write to the Free Software
     23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     24 *
     25 */
     26
    127#ifndef __klibc_io_h__
    228#define __klibc_io_h__
  • trunk/libc/include/klibc/logstrict.h

    r2745 r2805  
    282282/** Backend IO APIs. */
    283283#define __LIBC_LOG_GRP_BACK_IO      26
     284/** Backend OS/2 Files (the file handle class). */
     285#define __LIBC_LOG_GRP_BACK_OS2FILE 26
    284286/** Init/Term APIs and Events. */
    285287#define __LIBC_LOG_GRP_INITTERM     27
  • trunk/libc/src/kNIX/Makefile.kmk

    r2748 r2805  
    8888    $(PATH_LIBC_SRC)/kNIX/os2/b_ioFileControl.c \
    8989    $(PATH_LIBC_SRC)/kNIX/os2/b_ioFileOpen.c \
    90     $(PATH_LIBC_SRC)/kNIX/os2/b_ioFileSizeSet.c \
    91     $(PATH_LIBC_SRC)/kNIX/os2/b_ioSeek.c \
    9290    $(PATH_LIBC_SRC)/kNIX/os2/b_ldrClose.c \
    9391    $(PATH_LIBC_SRC)/kNIX/os2/b_ldrOpen.c \
     
    106104    $(PATH_LIBC_SRC)/kNIX/os2/b_signalPending.c \
    107105    $(PATH_LIBC_SRC)/kNIX/os2/b_signalQueue.c \
    108     $(PATH_LIBC_SRC)/kNIX/os2/b_signalSendPid.c \
    109106    $(PATH_LIBC_SRC)/kNIX/os2/b_signalStack.c \
    110107    $(PATH_LIBC_SRC)/kNIX/os2/b_signalSuspend.c \
     
    139136    $(PATH_LIBC_SRC)/kNIX/os2/filefind.c \
    140137    $(PATH_LIBC_SRC)/kNIX/os2/filesys.c \
     138    $(PATH_LIBC_SRC)/kNIX/os2/fhOS2File.c \
    141139    $(PATH_LIBC_SRC)/kNIX/os2/fs.c \
    142140    $(PATH_LIBC_SRC)/kNIX/os2/fsync.c \
    143141    $(PATH_LIBC_SRC)/kNIX/os2/getppid.c \
    144     $(PATH_LIBC_SRC)/kNIX/os2/heap.c \
    145     $(PATH_LIBC_SRC)/kNIX/os2/heapdump.c \
    146142    $(PATH_LIBC_SRC)/kNIX/os2/heaphigh.c \
    147     $(PATH_LIBC_SRC)/kNIX/os2/heapsize.c \
    148143    $(PATH_LIBC_SRC)/kNIX/os2/hooks.c \
    149144    $(PATH_LIBC_SRC)/kNIX/os2/libcfork.c \
     
    182177    $(PATH_LIBC_SRC)/kNIX/os2/__os_version.c \
    183178    $(PATH_LIBC_SRC)/kNIX/os2/__pipe.c \
    184     $(PATH_LIBC_SRC)/kNIX/os2/__read.c \
    185179    $(PATH_LIBC_SRC)/kNIX/os2/__read_kbd.c \
    186180    $(PATH_LIBC_SRC)/kNIX/os2/__select.c \
     
    191185    $(PATH_LIBC_SRC)/kNIX/os2/__wait.c \
    192186    $(PATH_LIBC_SRC)/kNIX/os2/__waitpid.c \
    193     $(PATH_LIBC_SRC)/kNIX/os2/__write.c \
    194187    $(PATH_LIBC_SRC)/kNIX/os2/386/appinit.s \
    195188    $(PATH_LIBC_SRC)/kNIX/os2/386/thunk0.s \
  • trunk/libc/src/kNIX/b_fs.h

    r2733 r2805  
    217217#pragma pack()
    218218
    219 
    220 /** @group Large File Support - API pointers.
    221  * Test if the function pointer is set before calling it.
    222  * For APIs which take a structure level parameter, check __pfnDosOpenL.
    223  * @{ */
    224 extern ULONG (* _System __libc_gpfnDosOpenL)(PCSZ pszFileName, PHFILE phFile, PULONG pulAction, LONGLONG llFileSize, ULONG ulAttribute, ULONG ulOpenFlags, ULONG ulOpenMode, PEAOP2 pEABuf);
    225 extern ULONG (* _System __libc_gpfnDosSetFilePtrL)(HFILE hFile, LONGLONG llOffset, ULONG ulOrigin, PLONGLONG pllPos);
    226 extern ULONG (* _System __libc_gpfnDosSetFileSizeL)(HFILE hFile, LONGLONG cbSize);
    227 extern ULONG (* _System __libc_gpfnDosSetFileLocksL)(HFILE hFile, __const__ FILELOCKL *pflUnlock, __const__ FILELOCKL *pflLock, ULONG ulTimeout, ULONG flFlags);
    228 /** @} */
    229219
    230220#endif /* _OS2EMX_H */
  • trunk/libc/src/kNIX/b_processGetResourceLimit.c

    r2748 r2805  
    8282        {
    8383#ifdef __OS2__
    84             int rc = __libc_back_sys_processGetResourceLimit(int iResId, struct rlimit *pLimit)
     84            int rc = __libc_back_sys_processGetResourceLimit(iResId, pLimit);
    8585            if (rc)
    8686                LIBCLOG_ERROR_RETURN_INT(rc);
  • trunk/libc/src/kNIX/b_signalSendPid.c

    r2742 r2805  
    3131#define __LIBC_LOG_GROUP __LIBC_LOG_GRP_BACK_SIGNAL
    3232#include "kNIX.h"
    33 #include <signal.h>
    34 #include <errno.h>
    35 #include <klibc/backend.h>
    36 #include <klibc/logstrict.h>
    3733#ifdef __OS2__ /* later on NT. */
    38 #include "b_signal.h"
     34# include "os2/b_signal.h"
    3935#endif
    4036
     
    7066     * Differ between others and our self.
    7167     */
    72     if (_sys_pid != pid)
     68    if (fibGetPid() != pid)
    7369        rc = __libc_back_signalSendPidOther(pid, iSignalNo, NULL);
    7470    else
  • trunk/libc/src/kNIX/filehandles.c

    r2794 r2805  
    22/** @file
    33 *
    4  * LIBC File Handles.
    5  *
    6  * Copyright (c) 2003-2006 knut st. osmundsen <bird-srcspam@anduin.net>
    7  *
    8  *
    9  * This file is part of InnoTek LIBC.
    10  *
    11  * InnoTek LIBC is free software; you can redistribute it and/or modify
     4 * kNIX File Handles.
     5 *
     6 * Copyright (c) 2006 knut st. osmundsen <bird@innotek.de>
     7 *
     8 *
     9 * This file is part of kLIBC.
     10 *
     11 * kLIBC is free software; you can redistribute it and/or modify
    1212 * it under the terms of the GNU Lesser General Public License as published
    1313 * by the Free Software Foundation; either version 2 of the License, or
    1414 * (at your option) any later version.
    1515 *
    16  * InnoTek LIBC is distributed in the hope that it will be useful,
     16 * kLIBC is distributed in the hope that it will be useful,
    1717 * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1818 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     
    2020 *
    2121 * You should have received a copy of the GNU Lesser General Public License
    22  * along with InnoTek LIBC; if not, write to the Free Software
     22 * along with kLIBC; if not, write to the Free Software
    2323 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    2424 *
     
    2929*   Header Files                                                               *
    3030*******************************************************************************/
    31 #include "libc-alias.h"
    3231#define __LIBC_LOG_GROUP    __LIBC_LOG_GRP_INITTERM
    33 #ifdef __OS2__
    34 # define INCL_BASE
    35 # define INCL_ERRORS
    36 # define INCL_FSMACROS
    37 # include <os2.h>
    38 #endif
    39 #ifdef __NT__
    40 # include <klibc/nt/nt.h>
    41 #endif
    4232#include "kNIX.h"
    43 #include <malloc.h>
    44 #include <string.h>
    45 #include <sys/fcntl.h>
    46 #include <errno.h>
    47 #include <klibc/io.h>
     33
    4834#include <InnoTekLIBC/fork.h>
    4935#include <InnoTekLIBC/sharedpm.h>
    5036#include <InnoTekLIBC/tcpip.h>
    51 #include <emx/umalloc.h>
    5237#include "b_fs.h"
    5338#include "b_dir.h"
    5439
    55 #include <klibc/backend.h>
    56 #include <klibc/logstrict.h>
    5740
    5841
  • trunk/libc/src/kNIX/kNIX.h

    r2748 r2805  
    2828#define __kNIX_h__
    2929
     30
    3031#include "libc-alias.h"
    3132#ifdef __OS2__
     33# include <klibc/os2/os2.h>
    3234# include "os2/kNIXConfig.h"
    3335#elif defined(__NT__)
     36# include <klibc/nt/nt.h>
    3437# include "nt/kNIXConfig.h"
    3538#else
    3639# error "Port me! (or get the config right)"
    3740#endif
     41#include <errno.h>
     42#include <malloc.h>
     43#include <string.h>
     44#include <signal.h>
     45#include <sys/fmutex.h>
     46#include <sys/fcntl.h>
     47#include <sys/resource.h>
     48#include <sys/time.h>
     49#include <sys/types.h>
    3850#include <klibc/io.h>
     51#include <klibc/umalloc.h>
    3952#include <klibc/backend.h>
    40 #include <sys/fmutex.h>
     53#ifdef __LIBC_LOG_GROUP
     54# include <klibc/logstrict.h>
     55#endif
     56
    4157
    4258__BEGIN_DECLS
     
    92108/** @} */
    93109
     110
     111/** @group Init Functions
     112 * @{ */
     113extern void             __init(int fFlags);
     114extern int              __init_dll(int fFlags, unsigned long hmod);
     115extern void /*volatile*/_sys_init_ret(void *stack) __attribute__((__noreturn__));
     116extern int              _sys_init_environ(const char *pszEnv);
     117extern void             _sys_init_largefileio(void);
     118extern int              __libc_fhInit(void);
     119/** @} */
     120
     121
    94122__END_DECLS
    95123
  • trunk/libc/src/kNIX/os2/fhOS2File.c

    r2742 r2805  
    2424 *
    2525 */
     26
     27
     28/*******************************************************************************
     29*   Header Files                                                               *
     30*******************************************************************************/
     31#define __LIBC_LOG_GROUP    __LIBC_LOG_GRP_BACK_OS2FILE
     32#include <klibc/os2/os2.h>
     33#include "../kNIX.h"
    2634
    2735
     
    9199        if (pvBufSafe)
    92100        {
    93             memcpy(pvBufSafe, pvBuf, cbRead); /* paranoia */
    94             rc = DosRead(pFH->hNative, pvBufSafe, cbRead, &cbActuallyRead);
     101            memcpy(pvBufSafe, pvBuf, cbToRead); /* paranoia */
     102            rc = DosRead(pFH->hNative, pvBufSafe, cbToRead, &cbActuallyRead);
    95103            memcpy(pvBuf, pvBufSafe, cbToRead);
    96104            free(pvBufSafe);
     
    100108    }
    101109    else
    102         rc = DosRead(pFH->hNative, pvBufSafe, cbRead, &cbActuallyRead);
     110        rc = DosRead(pFH->hNative, pvBuf, cbToRead, &cbActuallyRead);
    103111
    104112
     
    136144     */
    137145    int     rc;
    138     ULONG   cbWritten = 0;
     146    ULONG   cbActuallyWritten = 0;
    139147    if (    (pFH->fFlags & __LIBC_FH_TYPEMASK) == F_DEV
    140148        &&  (uintptr_t)pvBuf >= 512*1024*1024)
     
    143151        if (pvBufSafe)
    144152        {
    145             memcpy(pvBufSafe, pvBuf, cbWrite);
    146             rc = DosWrite(pFH->hNative, pvBufSafe, cbWrite, &cbWritten);
     153            memcpy(pvBufSafe, pvBuf, cbToWrite);
     154            rc = DosWrite(pFH->hNative, pvBufSafe, cbToWrite, &cbActuallyWritten);
    147155            free(pvBufSafe);
    148156        }
     
    151159    }
    152160    else
    153         rc = DosWrite(pFH->hNative, pvBufSafe, cbRead, &cbWritten);
     161        rc = DosWrite(pFH->hNative, pvBuf, cbToWrite, &cbActuallyWritten);
    154162
    155163
     
    160168        LIBCLOG_RETURN_MSG(0, "ret 0 *pcbWritten=%zu\n", *pcbWritten);
    161169    }
    162     *pcbRead = 0;
     170    *pcbWritten = 0;
    163171    if (rc > 0)
    164172        rc = -__libc_native2errno(rc);
     
    184192        LONGLONG    ll;
    185193        ULONG       ul;
    186     } u;
     194    }   u;
     195    int rc;
    187196#if OFF_MAX > LONG_MAX
    188197    if (__libc_gpfnDosSetFilePtrL)
    189         rc = __libc_gpfnDosSetFilePtrL(hFile, off, iMethod, &u.ll);
     198        rc = __libc_gpfnDosSetFilePtrL(pFH->fh, off, iMethod, &u.ll);
    190199    else
    191200    {
     
    196205        }
    197206        u.off = 0;
    198         rc = DosSetFilePtr(hFile, off, iMethod, &u.ul);
     207        rc = DosSetFilePtr(pFH->fh, off, iMethod, &u.ul);
    199208    }
    200209#else
    201210    {
    202211        u.off = 0;
    203         rc = DosSetFilePtr(hFile, off, iMethod, &u.ul);
     212        rc = DosSetFilePtr(pFH->fh, off, iMethod, &u.ul);
    204213    }
    205214#endif
     
    207216    if (__predict_true(!rc))
    208217    {
    209         poffActual = u.off;
     218        *poffActual = u.off;
    210219        LIBCLOG_RETURN_INT(0);
    211220    }
     
    321330     */
    322331    off_t   cbCur;
    323     int rc = getFileSize(fh, &cbCur);
     332    int rc = getFileSize(pFH->fh, &cbCur);
    324333    if (!rc)
    325334    {
     
    329338             * File size change needed.
    330339             */
    331             rc = setFileSize(fh, cbFile);
     340            rc = setFileSize(pFH->fh, cbFile);
    332341            if (!rc)
    333342            {
     
    356365                {
    357366                    ULONG cb = cbLeft >= sizeof(__libc_gachZeros) ? sizeof(__libc_gachZeros) : cbLeft;
    358                     rc = DosWrite(fh, &__libc_gachZeros[0], cb, &cb);
     367                    rc = DosWrite(pFH->fh, &__libc_gachZeros[0], cb, &cb);
    359368                    cbLeft -= cb;
    360369                }
    361                 int rc2 = fhOs2FileSeek(fh, offSaved, SEEK_SET, &offIgnored);
     370                int rc2 = fhOs2FileSeek(pFH, offSaved, SEEK_SET, &offIgnored);
    362371                if (!rc && !rc2)
    363372                {
     
    369378                 * Shit, we failed writing zeros. Try undo the expand operation.
    370379                 */
    371                 setFileSize(fh, cbCur);
     380                setFileSize(pFH->fh, cbCur);
    372381                if (rc2)
    373382                {
    374                     fhOs2FileSeek(fh, offSaved, SEEK_SET, &offIgnored);
     383                    fhOs2FileSeek(pFH, offSaved, SEEK_SET, &offIgnored);
    375384                    if (!rc)
    376385                        rc = rc2;
     
    400409static int fhOs2FileDuplicate(__LIBC_PFH pFH, int *pfhNew)
    401410{
     411    return -ENOSYS;
    402412}
    403413
     
    415425static int fhOs2FileFileControl(__LIBC_PFH pFH, int iRequest, int iArg, int *prc)
    416426{
    417 
     427    return -ENOSYS;
    418428}
    419429
     
    430440static int fhOs2FileIOControl(__LIBC_PFH pFH, int iIOControl, int iArg, int *prc)
    431441{
    432 
     442    return -ENOSYS;
    433443}
    434444
     
    449459static int fhOs2FileSelect(int cFHs, struct fd_set *pRead, struct fd_set *pWrite, struct fd_set *pExcept, struct timeval *tv, int *prc)
    450460{
    451 
     461    return -ENOSYS;
    452462}
    453463
  • trunk/libc/src/kNIX/os2/kNIX-os2.h

    r2739 r2805  
    2828#define __os2_kNIX_os2_h__
    2929
     30#include "../backend.h" /** @todo remove backend.h! */
     31
     32
     33#ifdef INCL_DOSFILEMGR
     34/** @group Large File Support - API pointers.
     35 * Test if the function pointer is set before calling it.
     36 * For APIs which take a structure level parameter, check __pfnDosOpenL.
     37 * @{ */
     38extern ULONG (* _System __libc_gpfnDosOpenL)(PCSZ pszFileName, PHFILE phFile, PULONG pulAction, LONGLONG llFileSize, ULONG ulAttribute, ULONG ulOpenFlags, ULONG ulOpenMode, PEAOP2 pEABuf);
     39extern ULONG (* _System __libc_gpfnDosSetFilePtrL)(HFILE hFile, LONGLONG llOffset, ULONG ulOrigin, PLONGLONG pllPos);
     40extern ULONG (* _System __libc_gpfnDosSetFileSizeL)(HFILE hFile, LONGLONG cbSize);
     41extern ULONG (* _System __libc_gpfnDosSetFileLocksL)(HFILE hFile, __const__ FILELOCKL *pflUnlock, __const__ FILELOCKL *pflLock, ULONG ulTimeout, ULONG flFlags);
     42/** @} */
     43#endif /* INCL_DOSFILEMGR */
    3044
    3145
  • trunk/libc/src/kNIX/os2/libcfork.c

    r2804 r2805  
    332332 * @returns 0 on normal process startup.
    333333 *
    334  * @returns 1 on forked child process startup.
     334 * @returns 1 on forked child process startup (not executable module).
    335335 *          The caller should respond by not calling any _DLL_InitTerm
    336  *          or similar constructs. If fExecutable the call will not
    337  *          return in this situation.
     336 *          or similar constructs.
    338337 *
    339338 * @returns negative on failure.
     
    343342 * @param   pModule     Pointer to the fork module structure for the
    344343 *                      module which is to registered.
    345  * @param   fExecutable Indicator that the call origins from crt0.s and
    346  *                      the final forking should start. The function
    347  *                      will not return if this flag is set and the process
    348  *                      was forked.
    349  */
    350 int __libc_ForkRegisterModule(__LIBC_PFORKMODULE pModule, int fExecutable)
    351 {
    352     LIBCLOG_ENTER("pModule=%p:{.uVersion=%#x, .pfnAtFork=%p, .papParent1=%p, .papChild1=%p, .pvDataSegBase=%p, .pvDataSegEnd=%p, .fFlags=%#x, .pNext=%p} fExecutable=%d\n",
     344 */
     345int __libc_ForkRegisterModule(__LIBC_PFORKMODULE pModule)
     346{
     347    LIBCLOG_ENTER("pModule=%p:{.uVersion=%#x, .pfnAtFork=%p, .papParent1=%p, .papChild1=%p, .pvDataSegBase=%p, .pvDataSegEnd=%p, .fFlags=%#x, .pNext=%p, .hmod=%#x}\n",
    353348                  (void *)pModule, pModule->uVersion, (void *)pModule->pfnAtFork, (void *)pModule->papParent1, (void *)pModule->papChild1,
    354                   (void *)pModule->pvDataSegBase, (void *)pModule->pvDataSegEnd, pModule->fFlags, (void *)pModule->pNext, fExecutable);
     349                  (void *)pModule->pvDataSegBase, (void *)pModule->pvDataSegEnd, pModule->fFlags, (void *)pModule->pNext, pModule->hmod);
    355350#ifdef DEBUG_LOGGING
    356351    forkLogModuleByAddr(pModule->pvDataSegBase);
     
    362357    PPIB                    pPib;
    363358    __LIBC_FORKXCPTREGREC2  XcptRegRec;
     359    const int               fExecutable = !!(pModule->fFlags & __LIBC_FORKMODULE_FLAGS_EXECUTABLE);
    364360
    365361    /*
  • trunk/libc/src/kNIX/os2/resource.c

    r2748 r2805  
    3030*   Header Files                                                               *
    3131*******************************************************************************/
     32#include <klibc/os2/os2.h>
    3233#include "../kNIX.h"
    33 #define INCL_FSMACROS
    34 #define INCL_DOSFILEMGR
    35 #define INCL_DOSPROCESS
    36 #define INCL_DOSMISC
    37 #define INCL_DOSERRORS
    38 #include <os2.h>
    39 #include <errno.h>
    40 #include <sys/types.h>
    41 #include <sys/time.h>
    42 #include <sys/resource.h>
    43 
    4434
    4535
     
    112102        }
    113103
    114         case RLIMIT_DATA:
    115             LIBC
    116104
    117105        /*
  • trunk/libc/src/libc/startup/Makefile.kmk

    r2717 r2805  
    3434libc_libc_startup_TEMPLATE = libcsub
    3535libc_libc_startup_SOURCES = \
    36     $(PATH_LIBC_SRC)/libc/startup/cleanup.c \
    3736    $(PATH_LIBC_SRC)/libc/startup/ctor1.c \
    3837    $(PATH_LIBC_SRC)/libc/startup/dtor1.c \
  • trunk/libc/src/libc/startup/os2/x86/crt0.s

    r2289 r2805  
    22/** @file
    33 *
    4  * Application entry point.
     4 * OS/2 crt0.
    55 *
    6  * This is the routine that gets control first. It should prepare
    7  * argc/argv/envp and call the main function.
     6 * Copyright (c) 2006 knut st. osmundsen <bird@innotek.de>
    87 *
    98 *
    10  * Copyright (c) 1992-1998 by Eberhard Mattes
    11  * Copyright (c) 2003 InnoTek Systemberatung GmbH
     9 * This file is part of kLIBC.
    1210 *
    13  *
    14  * This file is part of Innotek LIBC.
    15  *
    16  * Innotek LIBC is free software; you can redistribute it and/or modify
     11 * kLIBC is free software; you can redistribute it and/or modify
    1712 * it under the terms of the GNU Lesser General Public License as published
    1813 * by the Free Software Foundation; either version 2 of the License, or
    1914 * (at your option) any later version.
    2015 *
    21  * Innotek LIBC is distributed in the hope that it will be useful,
     16 * kLIBC is distributed in the hope that it will be useful,
    2217 * but WITHOUT ANY WARRANTY; without even the implied warranty of
    2318 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     
    2520 *
    2621 * You should have received a copy of the GNU Lesser General Public License
    27  * along with Innotek LIBC; if not, write to the Free Software
     22 * along with kLIBC; if not, write to the Free Software
    2823 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    2924 *
    3025 */
    3126
    32 #include <emx/asm386.h>
    3327
    34     .globl  __text
    35     .globl  __data
    36     .globl  ___data_start
    37     .globl  ___bss_start
     28#include <klibc/initterm.h>
    3829
    39     .text
    4030
    41 #if defined(HIGHMEM)
    42 #define FLAG_HIGHMEM    1
    43 #else
    44 #define FLAG_HIGHMEM    0
     31
     32/**
     33 * The OS/2 executable entry point.
     34 *
     35 * EAX = EBX = ECX = EDX = ESI = EDI = EBP = GS = 0.
     36 * CS = flat code selector.
     37 * DS = ES = SS = flat data selector.
     38 * FS = TIB selector.
     39 * EFLAGS=?
     40 *
     41 * @returns exit code to pass to DosExit(1, rc);
     42 * @param   hmod         [ebp +  8h]   The executable module handle.
     43 * @param   Reserved     [ebp + 0ch]   Reserved (probably 0).
     44 * @param   pszzEnv      [ebp + 10h]   Pointer to the environment data object.
     45 * @param   pszzCmdline  [ebp + 14h]   Pointer to the commandline.
     46 *
     47 */
     48.text
     49.global __text
     50__text:
     51    /* create stack frame */
     52    mov     %esp, %ebp
     53
     54#if !defined(NOFORK) && !defined(NOUNIX)
     55    /*
     56     * Update g_ForkModule.hmod and call __libc_ForkRegisterModule(&g_ForkModule) to
     57     * register the fork module. If we're forking, this call will never return.
     58     */
     59    mov     8(%ebp), %eax
     60    mov     %eax, g_ForkModule_hmod
     61
     62    pushl   $g_ForkModule
     63    call   ___libc_ForkRegisterModule
     64    addl    $4, %esp
    4565#endif
    4666
     67    /*
     68     * Call __libc_InitExe(hmod, &hmod, fFlags, &MainArgs) to initialized
     69     * the CRT and get the arguments for main().
     70     */
     71    pushl   0                           /* the main argument frame */
     72    pushl   0
     73    pushl   0
     74    movl    %esp, %ecx
     75    pushl   %ecx                        /* pMainFrame */
     76#if defined(HIGHMEM)
     77# define F1     __LIBC_INIT_FLAGS_MEM_HIGH
     78#else
     79# define F1     0
     80#endif
    4781#if defined(NOUNIX)
    48 #define FLAG_NOUNIX     2
     82# define F2     __LIBC_INIT_FLAGS_NO_UNIX
    4983#else
    50 #define FLAG_NOUNIX     0
     84# define F2     0
    5185#endif
     86#if defined(ARGS_RESP)
     87# define F3     __LIBC_INIT_FLAGS_EXPAND_RESPONSE_FILE
     88#else
     89# define F3     0
     90#endif
     91#if defined(ARGS_WILD)
     92# define F3     __LIBC_INIT_FLAGS_EXPAND_WILDCARDS
     93#else
     94# define F3     0
     95#endif
     96    pushl   (F1+F2+F3+F4)
     97    lea     8(%ebp), %edx
     98    pushl   %edx                        /* pvOS */
     99    movl    8(%ebp), %eax
     100    pushl   %eax                        /* hmod */
     101    call    ___libc_InitExe
     102    addl    %esp, $0x0c
    52103
    53 __text:
     104    /*
     105     * We can call main(). Should main return, invoke exit with the return code.
     106     *
     107     * Should some bright guy override exit() and make it return, we'll loop
     108     * eating 4 bytes of stack for each call to exit(). Eventually we'll crash
     109     * when we run out of stack.
     110     */
     111    call    _main
     112    addl    $0x0c, %esp
    54113
    55 #if !defined(NOFORK) && !defined(NOUNIX)
    56     /* Registering the fork module. If we're forking this call will not return. */
    57     pushl   $1
    58     pushl   $ForkModule
    59     call    ___libc_ForkRegisterModule
    60     addl    $8, %esp
    61 #endif
    62     pushl   $(FLAG_HIGHMEM + FLAG_NOUNIX)
    63     call    ___init_app
    64     /* esp points to main() call frame. */
    65     cld
    66 #ifdef ARGS_RESP
    67     lea     4(%esp), %eax               /* &argv */
    68     movl    %esp, %ecx                  /* &argc */
    69     pushl   %eax
    70     pushl   %ecx
    71     call    __response
    72     addl    $8, %esp
    73 #endif
    74 #ifdef ARGS_WILD
    75     lea     4(%esp), %eax               /* &argv */
    76     movl    %esp, %ecx                  /* &argc */
    77     pushl   %eax
    78     pushl   %ecx
    79     call    __wildcard
    80     addl    $8, %esp
    81 #endif
    82     call    __CRT_init
    83     call    _main
    84     addl    $3*4, %esp
    85114do_exit:
    86115    pushl   %eax
    87116    call    _exit
    88 1:  jmp     1b      /* Just in case exit() returns :-) */
     117    jmp     do_exit
    89118
    90119
    91     .data
     120
     121/**
     122 * __data_start (and __data) marks the start of the data segment.
     123 *
     124 * By convention required by emxbind, the datasegment starts with
     125 * a magic number followed by a pointer to the list of OS/2 DLL
     126 * references. When linking OMF this is not used by anyone.
     127 */
     128.data
     129.global ___data_start
     130.global __data
    92131___data_start:
    93132__data:
    94     .long   0xba0bab    // Magic number (error detection)
    95     .long   __os2dll    // list of OS/2 DLL references
    96 
    97     .stabs  "__os2dll", 21, 0, 0, 0xffffffff
    98     .stabs  "___CTOR_LIST__", 21, 0, 0, 0xffffffff
    99     .stabs  "___DTOR_LIST__", 21, 0, 0, 0xffffffff
    100     .stabs  "___crtinit1__", 21, 0, 0, 0xffffffff
    101     .stabs  "___crtexit1__", 21, 0, 0, 0xffffffff
    102     .stabs  "___eh_frame__", 21, 0, 0, 0xffffffff
    103     .stabs  "___eh_init__", 21, 0, 0, 0xffffffff
    104     .stabs  "___eh_term__", 21, 0, 0, 0xffffffff
     133    .long   0x00ba0bab                  /* Magic number (error detection). */
     134    .long   __os2dll                    /* List of OS/2 DLL references. */
    105135
    106136#if !defined(NOFORK) && !defined(NOUNIX)
    107     .stabs "___fork_parent1__", 21, 0, 0, 0xffffffff
    108     .stabs "___fork_child1__", 21, 0, 0, 0xffffffff
     137/**
     138 * The fork module structure.
     139 */
     140g_ForkModule:
     141    .long  0x00010000                   /* uVersion (__LIBC_FORK_MODULE_VERSION) */
     142    .long  __atfork_callback            /* pfnAtFork */
     143    .long  ___fork_parent1__            /* papParent1 */
     144    .long  ___fork_child1__             /* papChild1 */
     145    .long  ___data_start                /* pvDataSegBase */
     146    .long  _end                         /* pvDataSegEnd */
     147    .long  0x00000001                   /* fFlags - __LIBC_FORKMODULE_FLAGS_EXECUTABLE */
     148    .long  0                            /* pNext */
     149g_ForkModule_hmod:
     150    .long  0                            /* hmod */
     151    .long  0                            /* uReserved[7] */
     152    .long  0                            /* uReserved[7] */
     153    .long  0                            /* uReserved[7] */
     154    .long  0                            /* uReserved[7] */
     155    .long  0                            /* uReserved[7] */
     156    .long  0                            /* uReserved[7] */
     157    .long  0                            /* uReserved[7] */
     158#endif
    109159
    110 ForkModule:
    111     .long  0x00010000                   // uVersion (__LIBC_FORK_MODULE_VERSION)
    112     .long  __atfork_callback            // pfnAtFork
    113     .long  ___fork_parent1__            // papParent1
    114     .long  ___fork_child1__             // papChild1
    115     .long  ___data_start                // pvDataSegBase
    116     .long  _end                         // pvDataSegEnd
    117     .long  0x00000001                   // fFlags - __LIBC_FORKMODULE_FLAGS_EXECUTABLE
    118     .long  0                            // pNext
    119     .long  0                            // uReserved[8]
    120     .long  0                            // uReserved[8]
    121     .long  0                            // uReserved[8]
    122     .long  0                            // uReserved[8]
    123     .long  0                            // uReserved[8]
    124     .long  0                            // uReserved[8]
    125     .long  0                            // uReserved[8]
    126     .long  0                            // uReserved[8]
    127 #endif
    128     .stabs "__end",1,0,0,0              /* Force libend inclusion for -Zomf. */
    129160
    130     .bss
     161/**
     162 * __bss_start marks where the BSS segment starts.
     163 */
     164.bss
     165.global ___bss_start
    131166___bss_start:
    132167
     168
     169/**
     170 * Start all the a.out SETs the CRT and GCC are making use of.
     171 *
     172 *      _os2dll is used by emxbind/ld for dll imports.
     173 *      __CTOR_LIST__ and __DTOR_LIST__ are lists of static constructors and destructors.
     174 *      __crtinit1__ is the list of static crt init routines.
     175 *      __crtinit2__ is the list of static crt termination routines.
     176 *      __eh_frame__, __eh_init__ and __eh_term__ are GCC exception handling info.
     177 *      __fork_parent1__ and __fork_child1__ are lists with fork time callbacks.
     178 */
     179.stabs  "__os2dll",         21, 0, 0, 0xffffffff
     180.stabs  "___CTOR_LIST__",   21, 0, 0, 0xffffffff
     181.stabs  "___DTOR_LIST__",   21, 0, 0, 0xffffffff
     182.stabs  "___crtinit1__",    21, 0, 0, 0xffffffff
     183.stabs  "___crtexit1__",    21, 0, 0, 0xffffffff
     184.stabs  "___eh_frame__",    21, 0, 0, 0xffffffff
     185.stabs  "___eh_init__",     21, 0, 0, 0xffffffff
     186.stabs  "___eh_term__",     21, 0, 0, 0xffffffff
     187#if !defined(NOFORK) && !defined(NOUNIX)
     188.stabs "___fork_parent1__", 21, 0, 0, 0xffffffff
     189.stabs "___fork_child1__",  21, 0, 0, 0xffffffff
     190#endif
     191
     192
     193/**
     194 * Add a symbol table entry which drags _end in libend into OMF links.
     195 */
     196.stabs "__end",1,0,0,0
     197
Note: See TracChangeset for help on using the changeset viewer.