ld: cannot perform PE operations on non PE output file error

后端 未结 1 1128
时光取名叫无心
时光取名叫无心 2021-02-04 20:27

I am new to operating system programming and I am reading a book which gives a simple example of kernel as follows:

main() {
   char *video_memory = 0xb8000;
           


        
1条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-04 21:22

    The first thing you'll need to is change the name of you function. If you call it main the MinGW version of GCC will insert a call to __main to do initialization. For example:

    start() {
       char *video_memory = 0xb8000;
       *video_memory = 'X';
    }
    

    This means you'll also have to edit kernel_entry.asm accordingly:

    [bits 32]
    [extern _start]
    call _start
    jmp $ 
    

    Next compile and assemble the two files as you did before, and link it with these commands:

    ld -T NUL -o kernel.tmp -Ttext 0x1000 kernel_entry.o kernel.o
    objcopy -O binary -j .text  kernel.tmp kernel.bin 
    

    The first command links the objects as a PECOFF executable, and then the second command converts it to a binary. Now combine the binary with the boot loader:

    copy /b boot_sect.bin+kernel.bin os-image
    

    0 讨论(0)
提交回复
热议问题