Can dmd compile with my own runtime library?

doob doobnet at gmail.com
Thu Aug 23 06:27:21 PDT 2007


Huang F Guan Wrote:

> Hi, I'm an operating system developer. I've written a win32-compatible and POSIX operating system, just for fun, but it can run many windows api programs. My system is written in C, it is not readable and diffcult to manage. Now I am looking for the new techniques to rewrite this os.
> 
> I've ever thought for an own compiler and linker, it is so complicated to develop an advanced one. But DMD did it, the D language almost satisfied what I need. Yes, you see, I am trying to use it to develop an operating system in D language, and maybe it will be the first one written in D language. 
> 
> While I was using C++ developing an os, the compiler can output the platform-independent code. But DMD compiler can not do this, because it needs a runtime library based on the present platform. 
> 
> I have tried gdc, but I failed too. It prints the error below when I link:
> 
> ld: warning: cannot find entry symbol _mainCRTStartup; defaulting to 00401000
> hello.o(.text+0x18):hello.d: undefined reference to `_Dmodule_ref'
> hello.o(.text+0x23):hello.d: undefined reference to `_Dmodule_ref'
> hello.o(.data+0x0):hello.d: undefined reference to `_D10ModuleInfo6__vtblZ'
> hello.o(.data+0x30):hello.d: undefined reference to `_D6object12__ModuleInfoZ'
> 
> Now I am wondering how can I link a platform-independent executable file? 
> Do I need to rewrite the runtime library? 
> Or just I need to write a tiny runtime library like gc, moduleinit, object?
> 
> I hope you can help me solve these puzzles, thanks!
> 

I don't know if this is any help but with the following tutorial, looking at the titan source and a little thinking of my own I manged to compile(with gdc) and link a simple hello world kernel, booting under grub and vmware.

http://www.osdever.net/bkerndev/index.php 
On the third page it shows a boot file in assembler and a linker script.
On the above link in the assembler file where it says:

; This is an endless loop here. Make a note of this: Later on, we
; will insert an 'extern _main', followed by 'call _main', right
; before the 'jmp $'.
stublet:
    jmp $

you can add:

; This is an endless loop here. Make a note of this: Later on, we
; will insert an 'extern _main', followed by 'call _main', right
; before the 'jmp $'.
stublet:
        extern main
        call main
    jmp $

Note, do not use a _ in front of the function name like the comment says






More information about the Digitalmars-d mailing list