'hello world' OS

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Santanu Chatterjee

    #1

    'hello world' OS

    Hello all,

    I would like to know how an OS makes a computer boot up.
    For that, as a start I would like to see an e_ample (read the
    underscore as the letter before y, as the keyboard here is
    defective) C program (along with instructions on how to compile
    and usae it) that will take over when the computer boots and
    print "hello world" and reboots the machine when 'enter' is
    pressed. This will be something of a "hello world" OS (for me)
    (I have tried to go through the boot.S (not sure about the name)
    program in the Linu_ kernel source, but I could not understand
    it since I am not familiar with assembly language).

    I would be glad if someone could please point me in the right
    direction.

    Regards,
    Santanu
  • Case

    #2
    Re: 'hello world' OS

    Santanu Chatterjee wrote:[color=blue]
    > Hello all,
    >
    > I would like to know how an OS makes a computer boot up.
    > For that, as a start I would like to see an e_ample (read the
    > underscore as the letter before y, as the keyboard here is
    > defective) C program (along with instructions on how to compile
    > and usae it) that will take over when the computer boots and
    > print "hello world" and reboots the machine when 'enter' is
    > pressed. This will be something of a "hello world" OS (for me)
    > (I have tried to go through the boot.S (not sure about the name)
    > program in the Linu_ kernel source, but I could not understand
    > it since I am not familiar with assembly language).
    >
    > I would be glad if someone could please point me in the right
    > direction.[/color]

    Here's a program that waits for an 'x'. Using any other input
    for a program like this is dangerous and not standard C.

    #include <stdio.h>

    int main(void)
    {
    printf("hello world\n");
    while (getchar() != 'y' - 1)
    {
    }
    }

    HTH

    Case

    Comment

    • Richard Bos

      #3
      Re: 'hello world' OS

      santanu@softhom e.net (Santanu Chatterjee) wrote:
      [color=blue]
      > I would like to know how an OS makes a computer boot up.[/color]

      It doesn't. The ROM bootstrap loader does. _How_ it does this is
      completely system-dependent, and therefore you should ask about it in a
      newsgroup dedicated to the architecture you are interested in. There is
      no C program which can demonstrate this for more than a single
      architecture, and for most you will need low-level system calls, since
      the higher level functions used by ISO C are dependent on the very OS
      you want to replace.

      Richard

      Comment

      • Richard Bos

        #4
        Re: 'hello world' OS

        Case <no@no.no> wrote:
        [color=blue]
        > Santanu Chatterjee wrote:[color=green]
        > > I would like to know how an OS makes a computer boot up.[/color][/color]
        [color=blue]
        > Here's a program that waits for an 'x'. Using any other input
        > for a program like this is dangerous and not standard C.
        > #include <stdio.h>
        >
        > int main(void)
        > {
        > printf("hello world\n");
        > while (getchar() != 'y' - 1)
        > {
        > }
        > }[/color]

        Beautiful. Not only has it nothing whatsoever to do with the question,
        it is even wrong. (Hint: what makes you think the ISO C Standard
        mandates ASCII?)

        Richard

        Comment

        • Joona I Palaste

          #5
          Re: 'hello world' OS

          Richard Bos <rlb@hoekstra-uitgeverij.nl> scribbled the following:[color=blue]
          > Case <no@no.no> wrote:[color=green]
          >> Santanu Chatterjee wrote:[color=darkred]
          >> > I would like to know how an OS makes a computer boot up.[/color]
          >> Here's a program that waits for an 'x'. Using any other input
          >> for a program like this is dangerous and not standard C.
          >> #include <stdio.h>
          >>
          >> int main(void)
          >> {
          >> printf("hello world\n");
          >> while (getchar() != 'y' - 1)
          >> {
          >> }
          >> }[/color][/color]
          [color=blue]
          > Beautiful. Not only has it nothing whatsoever to do with the question,
          > it is even wrong. (Hint: what makes you think the ISO C Standard
          > mandates ASCII?)[/color]

          I figure there is no portable way whatsoever to guarantee an integer
          value corresponds to the character 'x' without actually using the
          character constant
          'x'
          either by itself, or as part of an array or string, at some point in
          the C source code.
          For characters corresponding to digits from 0 to 9 it can be done, but
          I don't think it can be done for any other characters.

          --
          /-- Joona Palaste (palaste@cc.hel sinki.fi) ------------- Finland --------\
          \-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
          "I will never display my bum in public again."
          - Homer Simpson

          Comment

          • Jeremy Yallop

            #6
            Re: 'hello world' OS

            Joona I Palaste wrote:[color=blue]
            > I figure there is no portable way whatsoever to guarantee an integer
            > value corresponds to the character 'x' without actually using the
            > character constant
            > 'x'
            > either by itself, or as part of an array or string, at some point in
            > the C source code.[/color]

            #include <string.h>
            #include <ctype.h>

            int is_x(int c) /* C locale */
            {
            return islower((unsign ed char)c)
            && strchr("abcdefg hijklmnopqrstuv wyz", c) == NULL;
            }

            Jeremy.

            Comment

            • Dan Pop

              #7
              Re: 'hello world' OS

              In <59c5c224.04063 00250.d87a880@p osting.google.c om> santanu@softhom e.net (Santanu Chatterjee) writes:
              [color=blue]
              >I would like to know how an OS makes a computer boot up.[/color]

              This is beyond the capabilities of any OS. At least the first stages
              of the booting procedure are handled by programs that are not OS-specific.
              These programs, are, however, heavily platform specific.
              [color=blue]
              >For that, as a start I would like to see an e_ample (read the
              >underscore as the letter before y, as the keyboard here is
              >defective) C program (along with instructions on how to compile
              >and usae it) that will take over when the computer boots and
              >print "hello world" and reboots the machine when 'enter' is
              >pressed.[/color]

              There is no way to write such a program in portable C. Because there is
              no OS, such a program would have to be written as a freestanding
              application, i.e. all its output must be generated by its own means,
              with no standard library support. And, with no standard library
              support, there is no portable way of generating any output.

              Furthermore, such a program may have to do things that cannot be done in
              C at all, like setting various CPU registers to appropriate values.
              [color=blue]
              >This will be something of a "hello world" OS (for me)
              >(I have tried to go through the boot.S (not sure about the name)
              >program in the Linu_ kernel source, but I could not understand
              >it since I am not familiar with assembly language).
              >
              >I would be glad if someone could please point me in the right
              >direction.[/color]

              The right direction is to start learning assembly programming. It cannot
              be bypassed when programming at this level, even if it's merely asm
              statements embedded in C code.

              And once you learn assembly, you'll discover that you have no need for C
              at all for implementing the program you have in mind.

              Dan
              --
              Dan Pop
              DESY Zeuthen, RZ group
              Email: Dan.Pop@ifh.de

              Comment

              • Thomas Matthews

                #8
                Re: 'hello world' OS

                Santanu Chatterjee wrote:
                [color=blue]
                > Hello all,
                >
                > I would like to know how an OS makes a computer boot up.[/color]
                A better place to discuss your issue is in news:comp.os.*.
                Another place is news:comp.arch. embedded.

                [color=blue]
                > For that, as a start I would like to see an e_ample (read the
                > underscore as the letter before y, as the keyboard here is
                > defective) C program (along with instructions on how to compile
                > and usae it) that will take over when the computer boots and
                > print "hello world" and reboots the machine when 'enter' is
                > pressed. This will be something of a "hello world" OS (for me)
                > (I have tried to go through the boot.S (not sure about the name)
                > program in the Linu_ kernel source, but I could not understand
                > it since I am not familiar with assembly language).[/color]
                The boot sequence is platform dependent and usually differs
                by platform and operating system.

                A common sequence is:
                1. Turn off all interrupts
                2. Perform diagnostics (i.e. memory testing, device testing)
                3. Initialize interrupt and other vectors.
                4. Initialize memory structure (including stacks).
                5. Initialize 'C' run-time library.
                6. Jump to "main" function in C program.

                Platforms with more complex operating systems would have different
                sequences (and more complicated ones). Much of the boot code is
                written in assembly language. The run-time environment for the
                high level language must be initialized before a high-level
                language can be executed.
                [color=blue]
                >
                > I would be glad if someone could please point me in the right
                > direction.
                >
                > Regards,
                > Santanu[/color]

                On many platforms, your executable program is loaded into memory
                and executed by the operating system. Your program has no idea
                how long the platform has been operational before your program
                is executed.


                --
                Thomas Matthews

                C++ newsgroup welcome message:

                C++ Faq: http://www.parashift.com/c++-faq-lite
                C Faq: http://www.eskimo.com/~scs/c-faq/top.html
                alt.comp.lang.l earn.c-c++ faq:

                Other sites:
                http://www.josuttis.com -- C++ STL Library book

                Comment

                • Case

                  #9
                  Re: 'hello world' OS

                  Richard Bos wrote:[color=blue]
                  > Case <no@no.no> wrote:
                  >
                  >[color=green]
                  >>Santanu Chatterjee wrote:
                  >>[color=darkred]
                  >>>I would like to know how an OS makes a computer boot up.[/color][/color]
                  >
                  >[color=green]
                  >>Here's a program that waits for an 'x'. Using any other input
                  >>for a program like this is dangerous and not standard C.
                  >>#include <stdio.h>
                  >>
                  >>int main(void)
                  >>{
                  >> printf("hello world\n");
                  >> while (getchar() != 'y' - 1)
                  >> {
                  >> }
                  >>}[/color]
                  >
                  >
                  > Beautiful. Not only has it nothing whatsoever to do with the question,
                  > it is even wrong. (Hint: what makes you think the ISO C Standard
                  > mandates ASCII?)[/color]

                  The OP is unable to type an 'x' that's why I used his
                  suggestion to get there. Thanks for pointing out that
                  it has nothing to do with the question, I did not know
                  that. And, on his OS, Linu_, ASCII is quit common, if
                  I'm right; but could you please confirm. BTW, do you
                  know a real world character set in which 'x' != 'y' - 1?

                  Case

                  Comment

                  • Joona I Palaste

                    #10
                    Re: 'hello world' OS

                    Jeremy Yallop <jeremy@jdyallo p.freeserve.co. uk> scribbled the following:[color=blue]
                    > Joona I Palaste wrote:[color=green]
                    >> I figure there is no portable way whatsoever to guarantee an integer
                    >> value corresponds to the character 'x' without actually using the
                    >> character constant
                    >> 'x'
                    >> either by itself, or as part of an array or string, at some point in
                    >> the C source code.[/color][/color]
                    [color=blue]
                    > #include <string.h>
                    > #include <ctype.h>[/color]
                    [color=blue]
                    > int is_x(int c) /* C locale */
                    > {
                    > return islower((unsign ed char)c)
                    > && strchr("abcdefg hijklmnopqrstuv wyz", c) == NULL;
                    > }[/color]

                    Quite clever. AFAIK, however, this can be only done for one character in
                    one C program. If we were trying to use such functions to identify *two*
                    characters, the best we could achieve would be knowing whether the input
                    is *either* of them, but we couldn't know *which*. If we used those
                    alphabet strings missing one letter, both letters would show up in each
                    other's alphabet strings. But if we used only one, missing two letters,
                    there would be no way to tell which one of them the input was.

                    --
                    /-- Joona Palaste (palaste@cc.hel sinki.fi) ------------- Finland --------\
                    \-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
                    "I said 'play as you've never played before', not 'play as IF you've never
                    played before'!"
                    - Andy Capp

                    Comment

                    • Richard Bos

                      #11
                      Re: 'hello world' OS

                      Case <no@no.no> wrote:
                      [color=blue]
                      > Richard Bos wrote:[color=green]
                      > > Case <no@no.no> wrote:
                      > >[color=darkred]
                      > >>Santanu Chatterjee wrote:
                      > >>
                      > >>>I would like to know how an OS makes a computer boot up.[/color]
                      > >[color=darkred]
                      > >>Here's a program that waits for an 'x'. Using any other input
                      > >>for a program like this is dangerous and not standard C.[/color][/color][/color]
                      [color=blue][color=green]
                      > > Beautiful. Not only has it nothing whatsoever to do with the question,
                      > > it is even wrong. (Hint: what makes you think the ISO C Standard
                      > > mandates ASCII?)[/color]
                      >
                      > The OP is unable to type an 'x' that's why I used his
                      > suggestion to get there.[/color]

                      Then first of all, you should learn to snip, because you made it look as
                      though you replied to that whole post; and second, how would a program
                      that _waits_ for an 'x' help someone who cannot _type_ an 'x'?
                      [color=blue]
                      > And, on his OS, Linu_, ASCII is quit common, if I'm right;[/color]

                      So bloody what? This is comp.lang.c, not comp.lang.c.lin ux.
                      [color=blue]
                      > BTW, do you know a real world character set in which 'x' != 'y' - 1?[/color]

                      No, but I do know one in which not all letters are consecutive.

                      Richard

                      Comment

                      • Dan Pop

                        #12
                        Re: 'hello world' OS

                        In <cbuc63$jc9$1@o ravannahka.hels inki.fi> Joona I Palaste <palaste@cc.hel sinki.fi> writes:
                        [color=blue]
                        >I figure there is no portable way whatsoever to guarantee an integer
                        >value corresponds to the character 'x' without actually using the
                        >character constant
                        >'x'
                        >either by itself, or as part of an array or string, at some point in
                        >the C source code.[/color]

                        I was about to say that '\U0078' would do in C99, but it appears to be
                        a constraint violation: you can't use UCNs for the members of the basic
                        source character set. Only the ASCII characters that aren't part of the
                        basic source character set can be represented with UCNs: $, @ and `.

                        Dan
                        --
                        Dan Pop
                        DESY Zeuthen, RZ group
                        Email: Dan.Pop@ifh.de

                        Comment

                        • Dan Pop

                          #13
                          Re: 'hello world' OS

                          In <40e2ac4e$0$347 62$e4fe514c@new s.xs4all.nl> Case <no@no.no> writes:
                          [color=blue]
                          >Santanu Chatterjee wrote:[color=green]
                          >> Hello all,
                          >>
                          >> I would like to know how an OS makes a computer boot up.
                          >> For that, as a start I would like to see an e_ample (read the
                          >> underscore as the letter before y, as the keyboard here is
                          >> defective) C program (along with instructions on how to compile
                          >> and usae it) that will take over when the computer boots and
                          >> print "hello world" and reboots the machine when 'enter' is
                          >> pressed. This will be something of a "hello world" OS (for me)
                          >> (I have tried to go through the boot.S (not sure about the name)
                          >> program in the Linu_ kernel source, but I could not understand
                          >> it since I am not familiar with assembly language).
                          >>
                          >> I would be glad if someone could please point me in the right
                          >> direction.[/color]
                          >
                          >Here's a program that waits for an 'x'. Using any other input
                          >for a program like this is dangerous and not standard C.
                          >
                          >#include <stdio.h>
                          >
                          >int main(void)
                          >{
                          > printf("hello world\n");
                          > while (getchar() != 'y' - 1)
                          > {
                          > }
                          >}[/color]

                          Now explain how is it supposed to work on a freestanding platform, where:

                          1. The name and interface of the startup function is
                          implementation-defined.

                          2. Neither printf nor getchar are available (they typically rely on the
                          existence of an OS, but there is none in our case).

                          3. #include <stdio.h> may stop the compilation process with a message like

                          test.c:1:20: stdio.h: No such file or directory

                          Dan
                          --
                          Dan Pop
                          DESY Zeuthen, RZ group
                          Email: Dan.Pop@ifh.de

                          Comment

                          • Dan Pop

                            #14
                            Re: 'hello world' OS

                            In <40e2afe9.51596 4965@news.indiv idual.net> rlb@hoekstra-uitgeverij.nl (Richard Bos) writes:
                            [color=blue]
                            >Case <no@no.no> wrote:
                            >[color=green]
                            >> Santanu Chatterjee wrote:[color=darkred]
                            >> > I would like to know how an OS makes a computer boot up.[/color][/color]
                            >[color=green]
                            >> Here's a program that waits for an 'x'. Using any other input
                            >> for a program like this is dangerous and not standard C.
                            >> #include <stdio.h>
                            >>
                            >> int main(void)
                            >> {
                            >> printf("hello world\n");
                            >> while (getchar() != 'y' - 1)
                            >> {
                            >> }
                            >> }[/color]
                            >
                            >Beautiful. Not only has it nothing whatsoever to do with the question,
                            >it is even wrong. (Hint: what makes you think the ISO C Standard
                            >mandates ASCII?)[/color]

                            It doesn't have to. EBCDIC satisfies the poster's assumption, as well.
                            Good luck finding a conforming hosted implementation whose execution
                            character set is not based on (i.e. an extension of) either ASCII
                            or EBCDIC.

                            Dan
                            --
                            Dan Pop
                            DESY Zeuthen, RZ group
                            Email: Dan.Pop@ifh.de

                            Comment

                            • Joona I Palaste

                              #15
                              Re: 'hello world' OS

                              Dan Pop <Dan.Pop@cern.c h> scribbled the following:[color=blue]
                              > In <cbuc63$jc9$1@o ravannahka.hels inki.fi> Joona I Palaste <palaste@cc.hel sinki.fi> writes:[color=green]
                              >>I figure there is no portable way whatsoever to guarantee an integer
                              >>value corresponds to the character 'x' without actually using the
                              >>character constant
                              >>'x'
                              >>either by itself, or as part of an array or string, at some point in
                              >>the C source code.[/color][/color]
                              [color=blue]
                              > I was about to say that '\U0078' would do in C99, but it appears to be
                              > a constraint violation: you can't use UCNs for the members of the basic
                              > source character set. Only the ASCII characters that aren't part of the
                              > basic source character set can be represented with UCNs: $, @ and `.[/color]

                              Now this question is perhaps off-topic for comp.lang.c, but I don't
                              understand *why* you can't use UCNs for members of the basic character
                              set. What is the rationale behind this constraint?

                              --
                              /-- Joona Palaste (palaste@cc.hel sinki.fi) ------------- Finland --------\
                              \-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
                              "The question of copying music from the Internet is like a two-barreled sword."
                              - Finnish rap artist Ezkimo

                              Comment

                              Working...