CPU simulator written in C

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Scott Moore

    #16
    Re: [OT] CPU simulator written in C

    /* frank */ wrote:
    [color=blue]
    > Case ha scritto:
    >[color=green]
    >> It's not that complicated.[/color]
    >
    >
    > Thanks a lot.
    >
    > I was searching only for a "starting input" .[/color]

    I write a lot of these. Here are some hints.

    1. I would skip the .asm part unless you have some sort of class
    assignment going on that requires it. Its an unecessary complication
    to have to assemble the code yourself. Better is to figgure out how
    to get a "straight binary image" from a standard assembler and use
    that. A binary image would contain only the code, without symbols
    and other window dressing.

    2. Contructing C structures or variables that contain the registers
    and flags for the target CPU, these will "overflow" in C without
    error. However, you will still need to make a routine that checks
    what flags were set during that operation. Typically this is done
    by examining the result and the operands, and checking if the result
    makes sense. For example, adding two positive numbers and getting
    a negative result means an overflow occurred.

    3. Although common instruction sets today can be quite large, say
    32 bits or more for an instruction, there is typically a much
    shorter section of the instruction that determines what instruction
    type is being processed. Your typical "execute" case statement
    will extract that field and form a case based on that. Be prepared
    for a large case statement on most current CPUs. This is good,
    because it means your emulator will be fast.

    Luck !

    --
    Samiam is Scott A. Moore

    Personal web site: http:/www.moorecad.co m/scott
    My electronics engineering consulting site: http://www.moorecad.com
    ISO 7185 Standard Pascal web site: http://www.moorecad.com/standardpascal
    Classic Basic Games web site: http://www.moorecad.com/classicbasic
    The IP Pascal web site, a high performance, highly portable ISO 7185 Pascal
    compiler system: http://www.moorecad.com/ippas

    Being right is more powerfull than large corporations or governments.
    The right argument may not be pervasive, but the facts eventually are.

    Comment

    • Case -

      #17
      Re: [OT] CPU simulator written in C

      Dan Pop wrote:
      [color=blue]
      > In <40d947dd$0$434 51$e4fe514c@new s.xs4all.nl> Case <no@no.no> writes:
      >
      >[color=green]
      >>The key idea is to map all parts of a CPU on C structures
      >>and routines. For example: the program counter (PC) can
      >>be simply mapped to an int variable.[/color]
      >
      >
      > An usigned integer type would be a much better choice for the program
      > counter. Ditto for the other integer registers.[/color]

      I didn't say what kind of int, so technically what you propose
      is covered by my statement ;-)

      Yes, you're right, the PC is best typed as unsigned. I'm not sure
      about the registers. Values in registers are seen as 2-s complement
      by instruction in at least some CPU's (e.g., MIPS has pairs of
      similar instructions for singed and unsigned register operand).

      Case

      Comment

      • Eric Sosman

        #18
        Re: [OT] CPU simulator written in C

        Case - wrote:[color=blue]
        > Dan Pop wrote:
        >[color=green]
        >> In <40d947dd$0$434 51$e4fe514c@new s.xs4all.nl> Case <no@no.no> writes:
        >>
        >>[color=darkred]
        >>> The key idea is to map all parts of a CPU on C structures
        >>> and routines. For example: the program counter (PC) can
        >>> be simply mapped to an int variable.[/color]
        >>
        >>
        >>
        >> An usigned integer type would be a much better choice for the program
        >> counter. Ditto for the other integer registers.[/color]
        >
        >
        > I didn't say what kind of int, so technically what you propose
        > is covered by my statement ;-)
        >
        > Yes, you're right, the PC is best typed as unsigned. I'm not sure
        > about the registers. Values in registers are seen as 2-s complement
        > by instruction in at least some CPU's (e.g., MIPS has pairs of
        > similar instructions for singed and unsigned register operand).[/color]

        Note that you must issue the occasional no-op when
        using instructions of the first type, to give the singed
        registers time to cool.

        --
        Eric.Sosman@sun .com

        Comment

        • RoSsIaCrIiLoIA

          #19
          Re: CPU simulator written in C

          for me it is difficult write a portable and *fast* x86 cpu in C
          (it has to execute an OS)
          I'm a beginner but I would 'solve' the problem in this way:

          _______________ _______________ _____
          #include <stdio.h>
          #include <stdint.h> /* or stddef don't remember for uintxx_t */

          struct r16{
          uint8_t rl; /* uintXX_t would be in the standard c c89 */
          uint8_t rh; /* so it is portable: it is ok in every cpu */
          }; /* but in the x86 cpu a register is good for
          signed
          and unsigned calculation */


          struct r32{
          struct r16 ac;
          uint16_t sn;
          };


          /* all global */
          struct r32 eax_={0}, ebx_={0}, ecx_={0}, edx_={0};

          /* they are static so until I don't write ={0} they are ={0} ie all 0
          at the start of prog */

          struct r32 esi_, edi_, ebp_, esp_, eip_;
          uint16_t cs_, ds_, es_, ss_, fs_, gs_, flags_;

          struct r32 *eax= &eax_, *ebx= &ebx_, *ecx= &ecx_, *edx= &edx_;
          struct r32 *esi= &esi_, *edi= &edi_, *ebp= &ebp_, *esp= &esp_,
          *eip = &eip_;
          uint16_t *cs=&cs_, *ds=&ds_, *es=&es_, *ss=&ss_, *fs=&fs_,
          *gs=&gs_, *falgs=&flags_;


          #define ax eax->ac
          #define al eax->ac.rl
          #define ah eax->ac.rh

          #define bx ebx->ac
          #define bl ebx->ac.rl
          #define bh ebx->ac.rh

          #define cx ecx->ac
          #define cl ecx->ac.rl
          #define ch ecx->ac.rh

          #define dx edx->ac
          #define dl edx->ac.rl
          #define dh edx->ac.rh

          #define sp esp->ac
          #define bp ebp->ac
          #define si esi->ac
          #define di edi->ac
          #define ip eip->ac
          #define U unsigned
          #define P printf

          void assign(struct r32* a, uint32_t b)
          {uint8_t l, h;
          /*--------------*/
          (*a).sn = (b>>16) & 0xFFFF;
          (*a).ac.rl = b & 0xFF;
          (*a).ac.rh = b>>8;
          }

          void Pr(struct r32* a)
          {uint32_t b;
          /*----------------*/
          b=(*a).sn;
          //P("a.sn=%u", (U) a.sn);
          b <<= 16;
          b |= ((uint32_t) (*a).ac.rh << 8 ) | (*a).ac.rl;
          printf("%x", (int) b);
          fflush(stdout);
          }

          void somma(struct r32* a,struct r32* b)
          {uint32_t bb, aa;
          /*----------------*/
          aa =(*a).sn; aa <<= 16;
          aa |= ((uint32_t) (*a).ac.rh << 8 ) | (*a).ac.rl;
          bb = b->sn; bb <<= 16;
          bb |= ((uint32_t) b->ac.rh << 8 ) | b->ac.rl;
          bb += aa;
          assign(a, bb);
          }

          /* it is difficult but main() has to
          1) read in a file in binary form a instructon
          2) perform that istruction in the program
          */

          int main(void)
          {
          assign( eax , 0xFEFEFEFE); assign( ebx , 0xFAFAFAFA);
          P("eax="); Pr(eax); P(" ebx="); Pr(ebx); P("\n");
          assign(ecx, 50000); assign(edx, 512341);
          somma(ecx, edx);
          P("ecx="); Pr(ecx); P(" edx="); Pr(edx); P("\n");
          printf("somma=% x", (int)(50000 + 512341) );
          return 0;
          }

          /*
          eax=fefefefe ebx=fafafafa
          ecx=894a5 edx=7d155
          somma=894a5
          */

          Comment

          • Gordon Burditt

            #20
            Re: CPU simulator written in C

            >This is not a Unix item but strictly a PC item as follows:[color=blue]
            >
            > union REGS {
            > struct WORDREGS x;
            > struct BYTEREGS h;
            > };
            >
            > struct WORDREGS {
            > unsigned int ax, bx, cx, dx;
            > unsigned int si, di, cflag, flags;
            > };
            >
            > struct BYTEREGS {
            > unsigned char al, ah, bl, bh;
            > unsigned char cl, ch, dl, dh;
            > };
            >
            >These structures allow C programs on PCs to access the CPU registers.
            >
            >AX,BX,CX,DX,SI ,DI,CF(carry flag),and FLAGS are all Intel 80x86
            >registers
            >AL/AH,BL/BH,CL/CH,DL/DH are pseudo 8 bit registers which are derived
            >from the
            >AL = Low half of AX, AH = High half of AX, etc.[/color]

            I have to really wonder about this design for a CPU emulator. Some
            of the registers listed above share storage (for example, ax consists
            of ah and al concatenated, and eax contains ax). Every time you
            change one register (e.g. eax, ax, al, or ah), you have to change
            all of them, or keep track of which one is more up to date. This
            tends to make things slow. and bug-prone, if you're not careful.
            Assembly code WILL occasionally make use of this fact, for example,
            loading ah with 0 to do an unsigned-extension of al into ax may be
            the fastest way to accomplish this.

            There may also be reasons for representing some of the registers as an
            array. For example, the field in a machine instruction that specifies
            a register may be consistent enough that isolating that field and using
            it as an array index may be useful.
            [color=blue]
            >The basic registers are 16 bits while the extended registers are 32
            >bits
            >EAX,EBX,ECX,ED X, etc.
            >
            >In addition you have the segment registers CS,DS,ES,SS and the
            >pointers
            >SP,BP plus the index registers SI,DI and on the 80386 and above you
            >also
            >have debug registers.
            >
            >In protected mode the segment registers become selector registers.[/color]

            There are a number of registers not mentioned above in the *86
            architecture (and this isn't complete either). I realize the above
            wasn't intended to be a complete list.

            - EFLAGS, EIP, EDI, ESI, ESP, EBP
            - Segment registers FS and GS
            - Floating point registers
            - Control registers
            - Machine specific registers
            - Portions of the "hidden" part of selector registers can become visible
            under the right circumstances.
            - GDTR, IDTR, Task register, and LDTR
            - MMX and XMM registers (which may overlap with others)


            Gordon L. Burditt

            Comment

            • Gordon Burditt

              #21
              Re: CPU simulator written in C

              ><OT>[color=blue]
              >Why not simply use the pc as an index in memory? This
              >would allow you to write memory[pc]. And doesn't this[/color]

              This is a great idea for simpler CPUs without memory management
              hardware, and especially for CPUs where the maximum addressable
              memory of the emulated CPU (e.g. Z80 or 8086) is small (e.g. 64k
              bytes or even 1MB) compared to the available RAM of the host CPU
              running the emulation.
              [color=blue]
              >perfectly match what a PC does, being an index into a
              >block of data?[/color]

              Yes, given the absence of memory management. Just Intel segment-register
              mappings don't make it THAT hard, but protected-mode memory management
              can make it much harder. With memory management, things get
              complicated all of a sudden, especially if it's allowed for a
              multi-byte integer fetch to straddle memory-management pages, and
              where multiple very-different addresses can refer to the same block
              of memory.
              [color=blue]
              ><\OT>[/color]

              Gordon L. Burditt

              Comment

              • Case -

                #22
                Re: CPU simulator written in C

                Gordon Burditt wrote:[color=blue][color=green]
                >><OT>
                >>Why not simply use the pc as an index in memory? This
                >>would allow you to write memory[pc]. And doesn't this[/color]
                >
                > This is a great idea for simpler CPUs without memory management
                > hardware, and especially for CPUs where the maximum addressable
                > memory of the emulated CPU (e.g. Z80 or 8086) is small (e.g. 64k
                > bytes or even 1MB) compared to the available RAM of the host CPU
                > running the emulation.
                >[color=green]
                >>perfectly match what a PC does, being an index into a
                >>block of data?[/color]
                >
                > Yes, given the absence of memory management. Just Intel segment-register
                > mappings don't make it THAT hard, but protected-mode memory management
                > can make it much harder. With memory management, things get
                > complicated all of a sudden, especially if it's allowed for a
                > multi-byte integer fetch to straddle memory-management pages, and
                > where multiple very-different addresses can refer to the same block
                > of memory.[/color]

                I didn't think of this in the context of OP's homework
                assignment. Thanks for the extra info! CPU (and virtual
                machine) design is and remains a very interesting subject.

                Case
                [color=blue][color=green]
                >><\OT>[/color][/color]

                Comment

                • John Cochran

                  #23
                  Re: [OT] CPU simulator written in C

                  In article <40D9C637.40305 05@sun.com>,
                  Eric Sosman <Eric.Sosman@Su n.COM> wrote:
                  SNIP....`[color=blue]
                  >
                  > I once worked on an actual machine whose program counter
                  >registers (there were two) were signed -- the explanation
                  >given was that the same circuitry implemented all the machine's
                  >registers, so the signedness of the PCs was just a by-product
                  >of parsimonious hardware design. However, only the low-order
                  >bits of the active PC participated in address generation; the
                  >sign bits and high-order bits were simply ignored.
                  >
                  > So far, just an amusing peculiarity. But the really odd
                  >thing was that the operation of "increment the program counter"
                  >was implemented as the arithmetic operation "add one to the
                  >program counter" -- so if the PC contained a negative value,
                  >the effect was that the program ran backwards! I got some
                  >diversion out of dreaming up a code sequence that executed
                  >in the usual fashion for a while and then negated the PC and
                  >"backed out" by re-executing the preceding instructions in
                  >reverse order ...[/color]

                  Huh?

                  0x8000 = -32768
                  0x8000 + 1 = 0x8001 = -32767
                  0x8001 + 1 = 0x8002 = -32766
                  ....

                  Show me where adding 1 to a negative binary number will cause the low
                  order bits to "run backwards" compared to adding 1 to an unsigned binary
                  number.

                  Comment

                  • osmium

                    #24
                    Re: CPU simulator written in C

                    Dan Pop

                    OP:> >> I tried to search con google with no success.

                    Osmium:> >You are searching with the wrong target word. The proper word is
                    emulate,[color=blue][color=green]
                    > >not simulate.[/color]
                    >[/color]
                    POP:> You're splitting hairs. Try googling for "8051 simulator".

                    If you think you will shock me by revealing that people sometimes use the
                    wrong word, you have failed miserably.

                    When using something such as google, where the basic commodity is the right
                    word spelled properly, it is best to use the right word if you know it. If
                    you consider that hair splitting, feel free to continue to think so.


                    Comment

                    • Dingo

                      #25
                      Re: [OT] CPU simulator written in C

                      jdc@smof.fiawol .org (John Cochran) wrote in message news:<cbd03v$hk e$1@smof.fiawol .org>...
                      [color=blue]
                      > 0x8000 = -32768
                      > 0x8000 + 1 = 0x8001 = -32767
                      > 0x8001 + 1 = 0x8002 = -32766
                      > ...
                      >
                      > Show me where adding 1 to a negative binary number will cause the low
                      > order bits to "run backwards" compared to adding 1 to an unsigned binary
                      > number.[/color]

                      Repeat your demonstration using sign and magnitude representation in
                      place of two's complement.

                      Comment

                      • RoSsIaCrIiLoIA

                        #26
                        Re: CPU simulator written in C

                        On Wed, 23 Jun 2004 19:10:38 GMT, RoSsIaCrIiLoIA <n@esiste.ee> wrote:
                        [color=blue]
                        >for me it is difficult write a portable and *fast* x86 cpu in C
                        >(it has to execute an OS)
                        >I'm a beginner but I would 'solve' the problem in this way:
                        >
                        >______________ _______________ ______
                        >#include <stdio.h>
                        >#include <stdint.h> /* or stddef don't remember for uintxx_t */
                        >
                        >struct r16{
                        > uint8_t rl; /* uintXX_t would be in the standard c c89 */
                        > uint8_t rh; /* so it is portable: it is ok in every cpu */
                        >}; /* but in the x86 cpu a register is good for
                        >signed
                        > and unsigned calculation */
                        >
                        >
                        >struct r32{
                        > struct r16 ac;
                        > uint16_t sn;
                        >};
                        >
                        >
                        >/* all global */
                        >struct r32 eax_={0}, ebx_={0}, ecx_={0}, edx_={0};
                        >
                        > /* they are static so until I don't write ={0} they are ={0} ie all 0
                        > at the start of prog */
                        >
                        >struct r32 esi_, edi_, ebp_, esp_, eip_;
                        >uint16_t cs_, ds_, es_, ss_, fs_, gs_, flags_;
                        >
                        >struct r32 *eax= &eax_, *ebx= &ebx_, *ecx= &ecx_, *edx= &edx_;
                        >struct r32 *esi= &esi_, *edi= &edi_, *ebp= &ebp_, *esp= &esp_,
                        > *eip = &eip_;
                        >uint16_t *cs=&cs_, *ds=&ds_, *es=&es_, *ss=&ss_, *fs=&fs_,
                        > *gs=&gs_, *falgs=&flags_;[/color]

                        But I prefer this:

                        #include <stdio.h>
                        #include <stdint.h> /* or stddef don't remember for uintxx_t */

                        struct r32{
                        uint32_t e;
                        uint16_t x;
                        uint8_t h;
                        uint8_t l;
                        };


                        /* all global */
                        struct r32 eax_={0}, ebx_={0}, ecx_={0}, edx_={0};
                        struct r32 esi_, edi_, ebp_, esp_, eip_;
                        uint16_t cs_, ds_, es_, ss_, fs_, gs_, flags_;

                        struct r32 *eax= &eax_, *ebx= &ebx_, *ecx= &ecx_, *edx= &edx_;
                        struct r32 *esi= &esi_, *edi= &edi_, *ebp= &ebp_, *esp= &esp_, *eip
                        = &eip_;
                        uint16_t *cs=&cs_, *ds=&ds_, *es=&es_, *ss=&ss_, *fs=&fs_,
                        *gs=&gs_, *falgs=&flags_;


                        #define ax eax->x
                        #define al eax->l
                        #define ah eax->h

                        #define bx ebx->x
                        #define bl ebx->l
                        #define bh ebx->h

                        #define cx ecx->x
                        #define cl ecx->l
                        #define ch ecx->h

                        #define dx edx->x
                        #define dl edx->l
                        #define dh edx->h

                        #define sp esp->x
                        #define bp ebp->x
                        #define si esi->x
                        #define di edi->x
                        #define ip eip->x
                        #define U unsigned
                        #define P printf

                        void assign(struct r32* a, uint32_t b)
                        {uint8_t l, h;
                        /*--------------*/
                        a->e = b;
                        a->x = (b>>16) & 0xFFFF;
                        a->h = (b>>8) & 0xFF;
                        a->l = b & 0xFF;
                        }


                        void Pr(struct r32* a)
                        {printf("%x", (int) a->e);
                        fflush(stdout);
                        }

                        void somma(struct r32* a,struct r32* b)
                        {assign(a, a->e + b->e);}

                        int main(void)
                        {
                        assign( eax , 0xFEFEFEFE); assign( ebx , 0xFAFAFAFA);
                        P("eax="); Pr(eax); P(" ebx="); Pr(ebx); P("\n");
                        assign(ecx, 50000); assign(edx, 512341);
                        somma(ecx, edx);
                        P("ecx="); Pr(ecx); P(" edx="); Pr(edx); P("\n");
                        printf("somma=% x", (int)(50000 + 512341) );
                        return 0;
                        }


                        Comment

                        • RoSsIaCrIiLoIA

                          #27
                          Re: CPU simulator written in C

                          On Thu, 24 Jun 2004 07:28:14 GMT, RoSsIaCrIiLoIA <n@esiste.ee> wrote:[color=blue]
                          >But I prefer this:
                          >
                          >#include <stdio.h>
                          >#include <stdint.h> /* or stddef don't remember for uintxx_t */
                          >
                          >struct r32{
                          > uint32_t e;
                          > uint16_t x;
                          > uint8_t h;
                          > uint8_t l;
                          >};
                          >
                          >
                          >/* all global */
                          >struct r32 eax_={0}, ebx_={0}, ecx_={0}, edx_={0};
                          >struct r32 esi_, edi_, ebp_, esp_, eip_;
                          >uint16_t cs_, ds_, es_, ss_, fs_, gs_, flags_;[/color]

                          better this:

                          #include <stdio.h>
                          #include <stdint.h> /* or stddef don't remember for uintxx_t */


                          /* all global */
                          uint32_t eax, ebx, ecx, edx;
                          uint32_t esi, edi, ebp, esp, eip;
                          uint16_t cs, ds, es, ss, fs, gs, flags;

                          union u{
                          uint32_t e;
                          uint16_t x;
                          uint8_t l;
                          };

                          #define ax (eax & 0xFFFF)
                          #define al (eax & 0xFF )
                          #define ah ( (eax >>8) & 0xFF )

                          #define bx (ebx & 0xFFFF)
                          #define bl (ebx & 0xFF )
                          #define bh ( (ebx >>8) & 0xFF )

                          #define cx (ecx & 0xFFFF)
                          #define cl (ecx & 0xFF )
                          #define ch ( (ecx >>8) & 0xFF )

                          #define dx (edx & 0xFFFF)
                          #define dl (edx & 0xFF )
                          #define dh ( (edx >>8) & 0xFF )

                          #define sp esp & 0xFFFF
                          #define bp ebp & 0xFFFF
                          #define si esi & 0xFFFF
                          #define di edi & 0xFFFF
                          #define ip eip & 0xFFFF
                          #define U unsigned
                          #define P printf

                          void inc_x(uint32_t* a)
                          {uint16_t r;
                          /*-------------*/
                          r = *a & 0xFFFF; ++r;
                          // P(" r=%x ", (int) r );
                          *a = *a & ((uint32_t) 0xFFFF0000 | r);
                          }

                          void inc_l(uint32_t* a)
                          {uint8_t r;
                          /*-------------*/
                          r = *a & 0xFF; ++r;
                          *a = *a & ((uint32_t)0xFF FFFF00 | r);
                          }

                          /* don't know if it is ok */
                          void inc_l1(uint32_t * a)
                          {++( (*(union u*)a).l );}

                          /* don't know if it is ok */
                          void inc_x1(uint32_t * a)
                          {++( (*(union u*)a).x );}

                          void inc_h(uint32_t* a)
                          {uint8_t r;
                          /*-------------*/
                          r = (*a>>8) & 0xFF; ++r;
                          *a = *a & ( 0xFFFF00FF | (uint32_t) r << 8 );
                          }

                          int main(void)
                          {
                          eax = 0xFEFEFEFE; ebx = 0xFAFAFAFA;
                          P("eax=0x%x ebx=Ox%x\n", (int) eax, (int) ebx);
                          ecx=50000; edx=512341;
                          ecx += edx;
                          printf("somma=0 x%x\n", (int)(50000 + 512341) );
                          eax=0xFFFFFFFF;
                          printf("eax=0x% x ", (int) eax );
                          inc_x(&eax); /* inc ax */
                          P("inc ax -> eax=0x%x ax=0x%x\n", (int) eax, (int) ax );

                          eax=0xFFFFFFFF;
                          printf("eax=0x% x ", (int) eax );
                          inc_x1(&eax); /* inc ax [& union] */
                          P("inc ax -> eax=0x%x ax=0x%x\n", (int) eax, (int) ax );

                          eax=0xFFFFFFFF;
                          printf("eax=0x% x ", (int) eax );
                          inc_l(&eax); /* inc al */
                          P("inc ax -> eax=0x%x al=0x%x\n", (int) eax, (int) al );

                          eax=0xFFFFFFFF;
                          printf("eax=0x% x ", (int) eax );
                          inc_h(&eax); /* inc ah */
                          P("inc ah -> eax=0x%x ah=0x%x\n", (int) eax, (int) ah );

                          return 0;
                          }

                          Comment

                          • Alex Fraser

                            #28
                            Re: [OT] CPU simulator written in C

                            "Case -" <no@no.no> wrote in message
                            news:40d9ce52$0 $62380$5fc3050@ dreader2.news.t iscali.nl...[color=blue]
                            > Dan Pop wrote:[color=green]
                            > > An usigned integer type would be a much better choice for the program
                            > > counter. Ditto for the other integer registers.[/color]
                            >
                            > I didn't say what kind of int, so technically what you propose
                            > is covered by my statement ;-)[/color]

                            ;-)
                            [color=blue]
                            > Yes, you're right, the PC is best typed as unsigned. I'm not sure
                            > about the registers. Values in registers are seen as 2-s complement
                            > by instruction in at least some CPU's (e.g., MIPS has pairs of
                            > similar instructions for singed and unsigned register operand).[/color]

                            It's straightforward to simulate a 2's complement CPU using unsigned
                            integers, with the semantics C guarantees. This is for the same reason that
                            2's complement is popular.

                            Alex


                            Comment

                            • Dan Pop

                              #29
                              Re: CPU simulator written in C

                              In <2juiteF15jauoU 1@uni-berlin.de> "osmium" <r124c4u102@com cast.net> writes:
                              [color=blue]
                              >Dan Pop
                              >
                              >OP:> >> I tried to search con google with no success.
                              >
                              >Osmium:> >You are searching with the wrong target word. The proper word is
                              >emulate,[color=green][color=darkred]
                              >> >not simulate.[/color]
                              >>[/color]
                              >POP:> You're splitting hairs. Try googling for "8051 simulator".
                              >
                              >If you think you will shock me by revealing that people sometimes use the
                              >wrong word, you have failed miserably.[/color]

                              Many of these people were vendors of such products. But, of course,
                              you know better than them...

                              If you were capable to conceive the notion that you might be wrong, the
                              google exercise would have been quite useful to you.

                              Contrary to your narrow ideas, there are many levels of software
                              CPU simulation, serving different purposes, and none of them is less
                              entitled to the name "simulation " than the others:

                              - sub-transistor level simulation: used for checking the correctness of
                              the chip design.

                              - transistor level simulation: used for checking the correctness of the
                              CPU implementation.

                              - gate level simulation: used for checking the correctness of the CPU
                              design.

                              - register to register transfer level simulation: used to evaluate the
                              CPU design performance.

                              - functional simulation, kernel mode: used for developing operating
                              system kernels and freestanding applications.

                              - functional simulation, user mode: used for developing hosted
                              applications (much faster than kernel mode simulation, as the OS kernel
                              functionality is provided by the simulator, instead of having the
                              simulated processor execute kernel code).

                              The last two simulation levels are *also* called emulation. In the case
                              of some very popular embedded control CPUs, hardware emulation is often
                              used for software development purposes instead of the real processor,
                              because it has much better debugging capabilities.

                              The Linux to Itanium port was done using "ski", a functional simulator
                              developed by HP and gcc as a cross-compiler on x86 hardware.
                              The kernel people used ski in kernel mode, the glibc people used it in
                              user mode. Everything was ready by the time Intel produced the first
                              silicon prototypes of Itanium. I don't remember anyone calling ski
                              "emulator", although it wouldn't have been technically incorrect.

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

                              Comment

                              • Case

                                #30
                                Re: [OT] CPU simulator written in C

                                Eric Sosman wrote:[color=blue]
                                > Case - wrote:
                                >[color=green]
                                >> Dan Pop wrote:
                                >>[color=darkred]
                                >>> In <40d947dd$0$434 51$e4fe514c@new s.xs4all.nl> Case <no@no.no> writes:
                                >>>
                                >>>
                                >>>> The key idea is to map all parts of a CPU on C structures
                                >>>> and routines. For example: the program counter (PC) can
                                >>>> be simply mapped to an int variable.
                                >>>
                                >>>
                                >>>
                                >>>
                                >>> An usigned integer type would be a much better choice for the program
                                >>> counter. Ditto for the other integer registers.[/color]
                                >>
                                >>
                                >>
                                >> I didn't say what kind of int, so technically what you propose
                                >> is covered by my statement ;-)
                                >>
                                >> Yes, you're right, the PC is best typed as unsigned. I'm not sure
                                >> about the registers. Values in registers are seen as 2-s complement
                                >> by instruction in at least some CPU's (e.g., MIPS has pairs of
                                >> similar instructions for singed and unsigned register operand).[/color]
                                >
                                >
                                > Note that you must issue the occasional no-op when
                                > using instructions of the first type, to give the singed
                                > registers time to cool.
                                >[/color]

                                Is this some kind of joke?

                                Case

                                Comment

                                Working...