changtimwu / changtimwu.github.com

Tim's testing/practice notes
7 stars 2 forks source link

z80 related #32

Open changtimwu opened 8 years ago

changtimwu commented 8 years ago

setjmp/longjmp/malloc works

maybe we have co-routine even channel?

https://github.com/danluu/setjmp-longjmp-ucontext-snippets

changtimwu commented 8 years ago

minimal setjmp/longjmp example https://github.com/danluu/setjmp-longjmp-ucontext-snippets/blob/master/setjmp.c

setjmp/longjmp based coroutine proof of concept https://github.com/danluu/setjmp-longjmp-ucontext-snippets/blob/master/coop.c

changtimwu commented 8 years ago
static void test1(void)
{
    int a=3;
    int b=4;
    char *m = (char *)malloc(128);
    println("f2 &a=%p, &b=%p, m=%p",  &a, &b, m);
}

static test0(void)
{
    int a=3;
    int b=4;
    char *m = (char *)malloc(128);
    println("f1 &a=%p, &b=%p, m=%p",  &a, &b, m);
    test1();
}
f1 &a=0xefef, &b=0xefed, m=0x7fa8
f2 &a=0xefe3, &b=0xefe1, m=0x802e
f2 &a=0xefef, &b=0xefed, m=0x80b4
changtimwu commented 8 years ago

according to the memory map report (*.map) CODE is for all the function body. addr 0x200 is determined by sdcc option --code-loc 0x200

Area                                    Addr        Size        Decimal Bytes (Attributes)
--------------------------------        ----        ----        ------- ----- ------------
_CODE                               00000200    000071E8 =       29160. bytes (REL,CON)

DATA starts right after CODE it's for uninitialized global

Area                                    Addr        Size        Decimal Bytes (Attributes)
--------------------------------        ----        ----        ------- ----- ------------
_DATA                               000076C5    000008DD =        2269. bytes (REL,CON)
  Value  Global                              Global Defined In Module
      -----  --------------------------------   ------------------------
     00007753  _uip_buf                           uip
     00007B53  _uip_appdata                       uip
     00007B55  _uip_len                           uip
     00007B57  _uip_flags                         uip
     00007B58  _uip_conn                          uip
     00007B5A  _uip_conns                         uip
     00007C9A  _uip_listenports                   uip
     00007CB8  _uip_stat                          uip
     00007D46  _hs                                httpd

HEAP start from 0x7FA2... size 0x3FF(1023byte) is fixed by SDCC

Area                                    Addr        Size        Decimal Bytes (Attributes)
--------------------------------        ----        ----        ------- ----- ------------
_HEAP                               00007FA2    000003FF =        1023. bytes (REL,CON)
Value  Global                              Global Defined In Module
-----  --------------------------------   ------------------------
00007FA2  __sdcc_heap_start

INITIALIZED is for global vars with initial value.

Area                                    Addr        Size        Decimal Bytes (Attributes)
--------------------------------        ----        ----        ------- ----- ------------
_INITIALIZED                        000083A1    0000002F =          47. bytes (REL,CON)
      Value  Global                              Global Defined In Module
      -----  --------------------------------   ------------------------
     000083A1  _mycntr                            main
     000083A2  _gcnt                              main
     000083A4  _gtick                             main
     000083AC  _g_tx_rmu                          httpd
     000083AE  _g_wait_rmu                        httpd
     000083B0  _g_tx_resp                         httpd
     000083B2  _g_next_rmu                        httpd
     000083B4  _g_rmu_buf_tx_len                  httpd
     000083B6  _g_hs                              httpd
     000083B8  _cgitab                            cgi
changtimwu commented 8 years ago