where is these variables defined? - Minix

This is a discussion on where is these variables defined? - Minix ; I am reading the source code of boothead.s in minix 3.1.1. There is one statement that is ".extern _caddr, _daddr, _runsize, _edata, _end" at line 39. I can't find where is these global variables defined ? Can you help me,Thanks....

+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 20 of 24

Thread: where is these variables defined?

  1. where is these variables defined?

    I am reading the source code of boothead.s in minix 3.1.1.
    There is one statement that is ".extern _caddr, _daddr, _runsize,
    _edata, _end" at line 39.
    I can't find where is these global variables defined ?
    Can you help me,Thanks.


  2. Re: where is these variables defined?

    go to www.swartzbaugh.net, at the link 'boothead.s'

    Christos



  3. Re: where is these variables defined?

    i have found where is these variables,especially _edata and _end
    defined in lib/end/edata.s and lib/end/end.s respectively.
    i have another question that ,in addtion to boothead.s , are there
    another files compiled in the secondary boot program?
    i think the secondary boot program involve boot.c,bootimage.c ,edata.s
    and end.s too.

    is right above?


  4. Re: where is these variables defined?

    see the Makefile at directory 'boot' for the 'recipe' that makes up boot
    (the Boot Monitor). Certainly the library files that participate are not
    listed there.

    Christos



  5. Re: where is these variables defined?

    at line 86 in boothead.s of minix 3.1.1, i read code:
    mov di, #_edata ! Start of bss is at end of data
    mov cx, #_end ! End of bss (begin of heap)

    but i can't find where _edata and _end are initialized.

    Are they initialized by compiler?

    Thanks.


  6. Re: where is these variables defined?

    at line 86 in boothead.s of minix 3.1.1, i read codes :
    mov di, #_edata ! Start of bss is at end of data
    mov cx, #_end ! End of bss (begin of heap)
    but i can't find where _edata and _end are initialized.
    are they initialized by compiler?

    Thanks.


  7. Re: where is these variables defined?

    at line 86 in boothead.s of minix 3.1.1, i read code:
    mov di, #_edata ! Start of bss is at end of data
    mov cx, #_end ! End of bss (begin of heap)

    but i can't find where _edata and _end are initialized.

    Are they initialized by compiler?

    Thanks.


  8. Re: where is these variables defined?

    yes they are compiler generated symbols

    Christos



  9. Re: where is these variables defined?

    >yes they are compiler generated symbols
    i can't understand why compile can generate some symbols. i think this
    very strange.

    i think _edata and _end are global variables, they should be first
    defined in some place(for example ,one file).

    can you interpret that more detailed.

    sorry for my bad english.

    Thank you very much. Christos .


  10. Re: where is these variables defined?

    lxbcyllt@jx163.com wrote:
    >> yes they are compiler generated symbols

    > i can't understand why compile can generate some symbols. i think this
    > very strange.


    No. The compiler does not generate symbols.

    > i think _edata and _end are global variables, they should be first
    > defined in some place(for example ,one file).


    Right, _edata and _end are global variables and are defined in
    /usr/src/lib/end/edata.s and /usr/src/lib/end/end.s.

    These symbols do not need initialization, but are only labels to mark
    the end of the data segment. The objects generated from the files in
    the /usr/src/lib/end/ directory are included in the libraries libe.a and
    end.a which are automatically included by the link phase of the compilation.

    These libraries are linked at the end of the object list so these labels
    are at the end of their respective segments.

    > can you interpret that more detailed.
    >
    > sorry for my bad english.
    >
    > Thank you very much. Christos .
    >


    Ciao
    Giovanni
    --
    A computer is like an air conditioner,
    it stops working when you open Windows.
    Registered Linux user #337974

  11. Re: where is these variables defined?

    The _edata and _end symbols are defined in libend. The source code is
    in /usr/src/lib/end. Now if you have look at /usr/lib/descr [this is
    the 'script' that defines how the compiler does its stuff] you'll find
    something like:

    # combine object files and libraries to an executable
    combine (.o .a) .out

    $ACK_LED $model -o $EXE $rtso $* $libs $A/$ARCH/end.a
    $ACK_CV -x -m$ARCH $EXE $OUT

    Now $ACK_LED is the ACK system linker, and you can see that
    $A/$ARCH/end.a [really /usr/lib/i386/end.a] is the last library in the
    link command, so the values of _edata and _end are set by the linker to
    point to the end of the executable image [more correctly: _edata points
    to the end of the data section, and _end points to the end of the
    entire image]. So if you know where to look the symbols *are* defined
    by one file :-)

    More generally, you can use the 'anm' command to peek inside libraries
    to find what symbols they define, and what symbols they need to import.
    If you 'anm /usr/lib/i386/end.a' you'll find that there are other
    symbols defined as well, including _etext that points to the end of the
    program text (code). There is a good manpage for anm you might like to
    read.

    Finally, the output of $ACK_LED needs to be converted into a minix
    executable. This is what the $ACK_CV command does.

    Regards, Michael


  12. Re: where is these variables defined?

    i don't what to say.

    just thanks to everyone helping me.

    i feel the ''comp.os.minix" is an ardent forum.


  13. Re: where is these variables defined?

    Sorry for my prolixity.

    I read the makefile at /boot and the file descr at /usr/lib.
    As a beginner, it is very difficult to understand the descr.

    But i has some questoin:
    1. In makefile, i read the code :
    boot: boothead.s boot.o bootimage.o rawfs86.o
    $(LD86) -o $@ boothead.s boot.o bootimage.o rawfs86.o $(LIBS)
    I doesn't find libe.a and end.a included in boot, when are they
    included in boot?

    2. Does the acd has some function on earth compared with ack? When the
    descr is executed by acd?

    3. Does the compiler cc has both compiling and linking function,if not
    ,who has the link function?

    4. Whether have some tools which can find which libs included in one
    executable?

    First .thanks.


  14. Re: where is these variables defined?

    I think my questions have some stupidity.

    But ...

    Sorry.


  15. Re: where is these variables defined?

    >
    > No. The compiler does not generate symbols.
    >


    The compiler does generate symbols. See for instance the comment at
    /include/limits.h

    Christos



  16. Re: where is these variables defined?

    Hi Christos,

    > The compiler does generate symbols. See for instance the comment at
    > /include/limits.h


    The term 'symbols' is being used with different meanings. The comment
    in /usr/include/limits.h, "_EM_WSIZE is a compiler-generated symbol
    giving the word size in bytes", is referring to a symbol processed by
    the C-preprocessor (that is, equivalent to a #define in source code, or
    -D= command line argument to cc). These 'symbols' are
    processed by the C preprocessor, so the compiler never sees them -- you
    can see this for yourself by running 'cc -E ...' on some source code
    (look at 'man cc' for details).

    So where are these 'predefined' symbols defined? They are defined by
    the (compiler driver) script /usr/lib/descr:

    # Predefined preprocessor flags.
    PREDEF = -D_EM_WSIZE=$W -D_EM_PSIZE=$P -D_EM_SSIZE=2 -D_EM_LSIZE=4 \
    -D_EM_FSIZE=4 -D_EM_DSIZE=8 -D__ACK__ -D_ACK

    Just prior to this definition there is:

    # The word and pointer sizes of the target.
    if $ARCH = i86
    W = 2; P = 2
    if $ARCH = i386
    W = 4; P = 4

    Regards,

    Michael


  17. Re: where is these variables defined?

    Your questions certainly aren't stupid - they are good questions to
    ask. Firstly, you *really* don't have to understand what /usr/lib/descr
    does - all of the complexity of compiling and linking programs is
    managed for you by the 'cc' command, and as a beginner you shouldn't
    really get too concerned if you don't understand it all.

    The ACK compiler is a collection of different programs, none of which
    are meant to be run directly from the command line (i.e. they are
    difficult to use directly). Some of these programs are:

    [Preprocessors]
    /usr/lib/cpp - Old style C preprocessor
    /usr/lib/cpp.ansi - New (ANSI) style C preprocessor

    [Language frontends, generating (compact) EM-code]
    /usr/lib/em_cemcom.ansi - convert C into EM-code
    /usr/lib/em_m2 - convert Modula-2 into EM-code
    /usr/lib/em_pc - convert Pascal into EM-code

    [Tools for converting between compact and readable EM-code]
    /usr/lib/em_decode
    /usr/lib/em_encode

    [EM-code optimisers]
    /usr/lib/em_ego - 'front-end' for all the programs in /usr/lib/ego
    /usr/lib/em_opt
    /usr/lib/em_opt2

    [EM-code needs to be converted into i386 assembly]
    /usr/lib/i386/cg

    [i386 assembler, generating object code]
    /usr/lib/i386/as

    [Linker, combining all the bits and pieces together]
    /usr/lib/em_led

    [Finally, build the minix executable image]
    /usr/lib/cv

    That's just a summary! As you can see there is a lot going on behind
    the scenes when you compile a program - but as an applications
    programmer you rarely need to delve into all the nitty-gritty and
    low-level details. The script /usr/lib/descr does all of this work for
    you. It's good to know it exists, but that's about all.

    Now onto your questions (question 1 is answer last):

    >2. Does the acd has some function on earth compared with ack? When the descr is executed by acd?


    The acd program is the 'ACK compiler driver'. It exists because trying
    to run the compiler manually is horribly tedious. As Bill Marcum has
    explained in another post, the acd program is also called 'cc', 'm2',
    and 'pc' (via hard links).

    There is a long, and comprehensive, manual page for acd. I've never had
    to read it all, but it is nice to know that it is all documented. From
    the manual page: "The description file is a program interpreted by the
    driver. It has variables, lists of files, argument passing commands,
    and rules for transforming input files". In other words, everything
    that acd does is explained by /usr/lib/descr.

    > 3. Does the compiler cc has both compiling and linking function, if not, who has the link function?


    The cc command can do both compiling and linking.

    > 4. Whether have some tools which can find which libs included in one executable?


    No. After linking object files and libraries together there is no way
    of finding out what the individual pieces were by just looking at the
    executable file.

    > 1. In makefile, i read the code :
    > boot: boothead.s boot.o bootimage.o rawfs86.o
    > $(LD86) -o $@ boothead.s boot.o bootimage.o rawfs86.o $(LIBS)
    > I doesn't find libe.a and end.a included in boot, when are they included in boot?


    The simple answer is 'when everything gets linked together, the ACK
    compiler always adds end.a and libe.a to the end of the link command'.

    But I think you're wanting a more detailed answer. So lets start
    'spelunking' through the code. Unravelling the definitions in
    /usr/src/boot/Makefile yields the command

    cc -mi86 -Was-ncc -.o -o boot boothead.s boot.o bootimage.o rawfs86.o
    -lsys

    [because LD86=exec cc -mi86 -Was-ncc -.o]

    The -mi86 option says to compile for the 8086, which corresponds to
    'real mode' when the system is starting up. The option -Was-ncc says to
    process the option -ncc when running the assembler. It gets explained
    in the cc(1) manual page, in the section 'Assembly Dialects'. The -.o
    option says to ignore all of the standard runtime startup code that is
    typically needed -- this is done since we're interested in building the
    boot program, and want to have complete control over the first
    instruction executed. You might like to read the cc(1) manual page for
    more details on all the options.

    Digging further into what happens quickly gets tedious. Instead of
    doing it manually, it is easiest to add the option '-v2' [see the
    acd(1) manual page], and let the compiler driver tell us what it is
    doing. This is what I did:

    > cd /usr/src/boot
    > make # generate all the dependencies
    > cc -v2 -mi86 -Was-ncc -.o -o boot boothead.s boot.o bootimage.o rawfs86.o -lsys


    [generated output]
    mkdir /tmp/acd197
    rm -f /tmp/acd197/a.ncc.s
    /usr/lib/asmconv -mi86 ncc ack boothead.s /tmp/acd197/b.ack.s
    /usr/lib/i86/as - -o /tmp/acd197/c.o /tmp/acd197/b.ack.s
    rm -f /tmp/acd197/b.ack.s
    /usr/lib/em_led -a0:2 -a1:2 -a2:2 -a3:2 -b0:0 -b1:0 -o /tmp/acd197/d
    /tmp/acd197/c.o boot.o bootimage.o rawfs86.o /usr/lib/i86/libsys.a
    /usr/lib/i86/libd.a /usr/lib/i86/libc.a /usr/lib/i86/libfp.a
    /usr/lib/i86/libe.a /usr/lib/i86/end.a
    /usr/lib/cv -x -mi86 /tmp/acd197/d boot
    rm -f /tmp/acd197/c.o
    rm -f /tmp/acd197/d
    rmdir /tmp/acd197

    You can see in the above output that boothead.s is first assembled
    (after converting the syntax into the right dialect) into the object
    file /tmp/acd197/c.o. The linker is then run, and you can see that
    libe.a and end.a are automatically included, along with several other
    libraries that are need to support the C runtime environment.

    And that is how the boot program is built...

    Regards, Michael


  18. Re: where is these variables defined?

    Mr. Michanel, thank you very much !!!!!!

    I think you must spend many time in writing these reply.
    I acquired a lot from your help.

    I don't what to say, just thanks again !!!!!!
    It is vrey nice to meet you.

    lxbcyllt.


  19. Re: where is these variables defined?

    Mr. Michael:
    Thank you very much !!!!!!

    I think you must spend many time in writing these reply.

    I read carefully these texts and acquired a lot from your help.

    I don't what to say, just thanks again !!!!!!

    It is vrey nice to meet you.

    lxbcyllt.


  20. Re: where is these variables defined?

    Christos Karayiannis wrote:
    >> No. The compiler does not generate symbols.
    >>

    >
    > The compiler does generate symbols. See for instance the comment at
    > /include/limits.h
    >
    > Christos
    >
    >


    Sorry. I was referring to ''symbols'' with a meaning that is not
    correct in all cases.

    I understood that the OP was intending ''variables''.

    Ciao
    Giovanni
    --
    A computer is like an air conditioner,
    it stops working when you open Windows.
    Registered Linux user #337974

+ Reply to Thread
Page 1 of 2 1 2 LastLast