Collect2.exe错误:ld返回5退出状态

时间:2019-09-21 15:26:36

标签: c operating-system mingw ld

我正在使用BootLoader和内核以及一个链接器创建一个操作系统。我想将这三个文件编译为1个文件,但这给了我一个无法解释的错误。例如我有boot.asm并将其编译为boot.o。但是我编译了boot.o,kmain.cpp,linker.ld,它给了我错误

这是我的boot.asm:

section .boot
bits 16
global boot
boot:
    mov ax, 0x2401
    int 0x15

    mov ax, 0x3
    int 0x10

    mov [disk],dl

    mov ah, 0x2    ;read sectors
    mov al, 6      ;sectors to read
    mov ch, 0      ;cylinder idx
    mov dh, 0      ;head idx
    mov cl, 2      ;sector idx
    mov dl, [disk] ;disk idx
    mov bx, copy_target;target pointer
    int 0x13
    cli
    lgdt [gdt_pointer]
    mov eax, cr0
    or eax,0x1
    mov cr0, eax
    mov ax, DATA_SEG
    mov ds, ax
    mov es, ax
    mov fs, ax
    mov gs, ax
    mov ss, ax
    jmp CODE_SEG:boot2
gdt_start:
    dq 0x0
gdt_code:
    dw 0xFFFF
    dw 0x0
    db 0x0
    db 10011010b
    db 11001111b
    db 0x0
gdt_data:
    dw 0xFFFF
    dw 0x0
    db 0x0
    db 10010010b
    db 11001111b
    db 0x0
gdt_end:
gdt_pointer:
    dw gdt_end - gdt_start
    dd gdt_start
disk:
    db 0x0
CODE_SEG equ gdt_code - gdt_start
DATA_SEG equ gdt_data - gdt_start

times 510 - ($-$$) db 0
dw 0xaa55
copy_target:
bits 32
    hello: db "Booting system...",0
boot2:
    mov esi,hello
    mov ebx,0xb8000
.loop:
    lodsb
    or al,al
    jz halt
    or eax,0x0F00
    mov word [ebx], ax
    add ebx,2
    jmp .loop
halt:
    mov esp,kernel_stack_top
    extern kmain
    call kmain
    cli
    hlt

section .bss
align 4
kernel_stack_bottom: equ $
    resb 16384 ; 16 KB
kernel_stack_top:

还有我的kmain.cpp:


extern "C" void kmain()
{
    const short color = 0x0F00;
    const char* hello = "Welcome to my third version of my first operating system but with C++!!";
    short* vga = (short*)0xb8000;
    for (int i = 0; i<16;++i)
        vga[i+80] = color | hello[i];
}

最后是我的linker.ld:

ENTRY(boot)
OUTPUT_FORMAT("binary")
SECTIONS {
    . = 0x7c00;
    .text :
    {
        *(.boot)
        *(.text)
    }
    .rodata :
    {
        *(.rodata)
    }
    .data :
    {
        *(.data)
    }
    .bss :
    {
        *(.bss)
    }
}

我只希望它编译这些。我已经在整个互联网上找到了。但没有有用的东西。请尽快回答。谢谢!!

0 个答案:

没有答案