Hello,

This project is still alive even if I am not sending that much email to the mailing list.
I usually just complain on IRC when something goes wrong ;)

The good news is that a few days ago I was able to generate a NetBSD kernel ELF binary for the LatticeMico32 architecture.

Running it with Michael's qemu (-M milkymist -cpu lm32-full-mmu) was even printing some text "panic: something blabla" :-) That means that the kernel is booting untill the point where it registers the Milkymist console driver for the early printf callback and that the console driver is somehow working. Don't get me wrong, there are still a lot of things to fix before this boots up to user space and show the almighty "~ #"

Anyway, I was doing some crappy hack in Qemu because I wasn't aware of the fact that ELF binary can contain information about physical load address. Now it's all good, the ELF is linked to the virtual address 0xc0000000 but has a physical load address (where it will be loaded in memory by a bootloader or by qemu) of 0x40000000 which is the base address of DDR SDRAM in the Milkymist SoC.

So I get this:

$ ./obj/tooldir.Darwin-10.8.0-i386/bin/lm32--netbsd-readelf -l ./sys/arch/milkymist/compile/obj/GENERIC/netbsd

Elf file type is EXEC (Executable file)
Entry point 0xc0000000
There are 3 program headers, starting at offset 52

Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  LOAD           0x000098 0xc0000000 0x40000000 0xfc5f0 0xfc5f0 R E 0x8
  LOAD           0x0fc6c0 0xc00fc600 0x400fc5f0 0x063e0 0x063e0 RW 0x40
  LOAD           0x102ac0 0xc0102a00 0x401029d0 0x00000 0x0b700 RW 0x40

Now I have the following issue:

$ ./obj/tooldir.Darwin-10.8.0-i386/lm32--netbsd/bin/objdump -D ./sys/arch/milkymist/compile/obj/GENERIC/netbsd > netbsd.S

$ cat netbsd.S | grep -A1 v_putc
c0101a04 <v_putc>:
c0101a04:    c0 00 1b 28     *unknown*

qemu-mmu fallen$ ./lm32-softmmu/qemu-system-lm32 -M milkymist -cpu lm32-full-mmu -nographic -s -S -kernel /Users/fallen/dev/NetBSD/sys/arch/milkymist/compile/obj/GENERIC/netbsd

gdb-7.6.1 fallen$ ./gdb/gdb /Users/fallen/dev/NetBSD/sys/arch/milkymist/compile/obj/GENERIC/netbsd
GNU gdb (GDB) 7.6.1
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-apple-darwin10.8.0 --target=lm32-elf".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /Users/fallen/dev/NetBSD/sys/arch/milkymist/compile/obj/GENERIC/netbsd...(no debugging symbols found)...done.
(gdb) target remote :1234
Remote debugging using :1234
0x40000000 in ?? ()
(gdb) si
0x40000004 in ?? ()
(gdb) x/1x (0xc0101a04 - 0xc0000000 + 0x40000000)
0x40101a04:    0x00000000
(gdb) x/1x 0xc0101a04
0xc0101a04 <v_putc>:    0x00000000
(gdb) x/10i 0x40000000
   0x40000000:    xor r0,r0,r0
=> 0x40000004:    wcsr IE,r0
   0x40000008:    mvhi r1,0x100
   0x4000000c:    ori r1,r1,0x100
   0x40000010:    mvhi r1,0x4000
   0x40000014:    ori r1,r1,0x100
   0x40000018:    wcsr EBA,r1
   0x4000001c:    xor r2,r2,r2
   0x40000020:    bi 0x400003a4
   0x40000024:    nop
(gdb)

it seems I have offset issues maybe in the virtual addresses ...
physical segments seem to be contiguous, but the virtual segments does not seem contiguous. Therefore I found out that my phys_addr = virtual_addr - 0xc0000000 + 0x40000000 formula is wrong :(

By using the output of readelf -l as a hint I can find the content of my v_putc function pointer:

(gdb) x/1x (0xc0101a04 - 0xc00fc600 + 0x400fc5f0)
0x401019f4:    0xc0001b28

0xc0101a04 is the virtual address of v_putc symbol
0xc00fc600 is the virtual address of the beginning of .data section
0x400fc5f0 is the physical (load) address of the beginning of .data section

Any idea to help with that?

I am sending my linker script as attach file if it helps...

Cheers :)

--
Yann Sionneau
OUTPUT_FORMAT("elf32-lm32")
ENTRY(_start)

__DYNAMIC = 0;

MEMORY {
        sdram : ORIGIN = 0xc0000000, LENGTH = 0x8000000
}

SECTIONS
{
        .text 0xc0000000 : AT ( 0x40000000 )
        {
                _ftext = .;
                *(.text .stub .text.* .gnu.linkonce.t.*)
                _etext = .;
        } > sdram

        .rodata ADDR(.text) + SIZEOF(.text) : AT ( LOADADDR(.text) + 
SIZEOF(.text) )
        {
                . = ALIGN(4);
                _frodata = .;
                *(.rodata .rodata.* .gnu.linkonce.r.* link_set_*)
                *(.rodata1)
                _erodata = .;
        } > sdram

        link_set_modules : AT (LOADADDR(.rodata) + SIZEOF(.rodata) )
        {
                __start_link_set_modules = .;
                *(link_set_modules);
                __stop_link_set_modules = .;
        }

        link_set_domains : AT (LOADADDR(link_set_modules) + 
SIZEOF(link_set_modules) )
        {
                __start_link_set_domains = .;
                *(link_set_domains);
                __stop_link_set_domains = .;
        }

        link_set_bufq_strats : AT (LOADADDR(link_set_domains) + 
SIZEOF(link_set_domains) )
        {
                __start_link_set_bufq_strats = .;
                *(link_set_bufq_strats);
                __stop_link_set_bufq_strats = .;
        }

        link_set_evcnts : AT (LOADADDR(link_set_bufq_strats) + 
SIZEOF(link_set_bufq_strats) )
        {
                __start_link_set_evcnts = .;
                *(link_set_evcnts);
                __stop_link_set_evcnts = .;
        }

        link_set_prop_linkpools : AT (LOADADDR(link_set_evcnts) + 
SIZEOF(link_set_evcnts) )
        {
                __start_link_set_prop_linkpools = .;
                *(link_set_prop_linkpools);
                __stop_link_set_prop_linkpools = .;
        }
        
        link_set_sysctl_funcs : AT (LOADADDR(link_set_prop_linkpools) + 
SIZEOF(link_set_prop_linkpools) )
        {
                __start_link_set_sysctl_funcs = .;
                *(link_set_sysctl_funcs);
                __stop_link_set_sysctl_funcs = .;
        }

        link_set_dkwedge_methods : AT (LOADADDR(link_set_sysctl_funcs) + 
SIZEOF(link_set_sysctl_funcs) )
        {
                __start_link_set_dkwedge_methods = .;
                *(link_set_dkwedge_methods);
                __stop_link_set_dkwedge_methods = .;
        }

        /* We shouldn't have a .data section, however the GNU crapchain whines 
if we don't */
        .data : AT ( LOADADDR(link_set_dkwedge_methods) + 
SIZEOF(link_set_dkwedge_methods) )
        {
                . = ALIGN(4);
                _fdata = .;
                *(.data .data.* .gnu.linkonce.d.*)
                *(.data1)
                _gp = ALIGN(16);
                *(.sdata .sdata.* .gnu.linkonce.s.*)
                _edata = .;
        } > sdram

        .bss : AT ( LOADADDR(.data) + SIZEOF(.data) )
        {
                . = ALIGN(4);
                _fbss = .;
                *(.dynsbss)
                *(.sbss .sbss.* .gnu.linkonce.sb.*)
                *(.scommon)
                *(.dynbss)
                *(.bss .bss.* .gnu.linkonce.b.*)
                *(COMMON)
                . = ALIGN(4);
                _ebss = .;
                _end = .;
        } > sdram
}

PROVIDE(_fstack = ORIGIN(sdram) + LENGTH(sdram) - 4);
PROVIDE(_phy_do_real_tlb_miss_handling = _do_real_tlb_miss_handling - 
0xc0000000 + 0x40000000);
_______________________________________________
Devel mailing list
[email protected]
https://ssl.serverraum.org/lists/listinfo/devel

Reply via email to