On Tuesday, 27 October 2015 at 12:13:13 UTC, guodemone wrote:
sorry,My english is poot.

file asm.h

[...]

Can ldc work with C header files? I don't think it can but I could be wrong.

Here's how I build my 32-bit bootloader and link with my kernel main (you will have to replace names etc.):

---
nasm -felf -o kickstart32.o kickstart32.s (I don't have an asm.h)
gdc -m32 -gdwarf-2 -nostdlib -fPIC -c -o kernel32.main.o kmain.d
ld -nodefaultlibs -melf_i386 -z max-page-size=0x1000 -T linker32.ld -o kernel32.bin kickstart32.o kernel32.main.o
---

For this build setup you will need a linker script. Here's mine in case you don't have one. 'kickstart' is the entry point in my kickstart.s. Replace names and offsets as required for your code.


---
/* Use -melf_i386 or -melf64_x86-64
 * to specify the architecture
* ld -nodefaultlibs -melf_i386 -z max-page-size=0x1000 -T <linker_script> -o <output_binary>
*/
ENTRY (kickstart)

SECTIONS{
    . = 0x00100000;

    .text :{
        code = .; _code = .; __code = .;
        *(.text)
        *(.rodata)
    }

    .rodata ALIGN (0x1000) : {
        *(.rodata)
    }

    .data ALIGN (0x1000) : {
        data = .; _data = .; __data = .;
        *(.data)
        start_ctors = .; *(.ctors)   end_ctors = .;
        start_dtors = .; *(.dtors)   end_dtors = .;
    }

    .bss : {
        sbss = .;
        bss = .; _bss = .; __bss = .;
        *(COMMON)
        *(.bss)
        ebss = .;
    }
    end = .; _end = .; __end = .;
}
---

I got a lot of info from these sites:

https://www.cs.cmu.edu/~410-s07/p4/p4-boot.pdf
https://en.wikibooks.org/wiki/X86_Assembly/Bootloaders

http://wiki.osdev.org/Bare_bones

(NOTE: wiki.osdev.org has a lot of incorrect information, but it was useful as a starting point when I got stuck moving to a 64-bit kernel)


bye,
lobo

Reply via email to