Making portable execution errors

84 views Asked by At

Making portable execution errors.

I have two files: kernel.c and boot.asm:

boot.asm

[bits 32]

section .text
    align 4
    dd 0x1BADB002
    dd 0x00
    dd - (0x1BADB002 + 0x00)

global start

extern main

start:
    cli
    mov esp, stack_space
    jmp main

    hlt

stack_space:

kernel.c

char *vidmem = (char*)0xb8000; //змінна для відео пам'яті

void printString(void){
    const char *nameOS = "Welcome to CyberDOS";
    unsigned int i = 0, j = 0;
    while (nameOS[j] != '\0'){
        vidmem[i] = nameOS[j];
        vidmem[i+1] = 0x07;
        ++j;
        i += 2;

    }
}
void clearScreen(){
    unsigned int i = 0, j = 0;

    while (j < 80 * 25 * 2){//резервуємо 25 рядків по 80 символів
        vidmem[j] = ' ';
        vidmem[j+1] = 0x07;
        j += 2;
    }
    j = 0;
}   
void main(void){
    clearScreen();
    printString();
}

When I tried make executable file using this commands:

cd C:\Users\Ukraine\AppData\Local\bin\NASM
nasm -f elf32 C:\Users\Ukraine\Documents\Test\boot.asm -o C:\Users\Ukraine\Documents\Test\output\boot.o
gcc -m32 -c C:\Users\Ukraine\Documents\Test\kernel\kernel.c -o C:\Users\Ukraine\Documents\Test\output\kernel.o
cd C:\Users\Ukraine\Documents\Test\output

gcc -m32 -o kernel.exe -Wl,-e,start boot.o kernel.o
objcopy -O elf32-i386 C:\Users\Ukraine\Documents\Test\output\kernel.exe C:\Users\Ukraine\Documents\Test\output\kernel.elf
cd C:/Program Files/qemu/qemu-system-i386 -output output
cd C:\Users\Ukraine\Documents\Test
pause

I have an mistakes with asm file:

C:\Users\Ukraine\Documents\Test\output>gcc -m32 -o kernel.exe -Wl,-e,start boot.o kernel.o
C:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: boot.o: in function `start':
C:\Users\Ukraine\Documents\Test\boot.asm:(.text+0x13): undefined reference to `main'
collect2.exe: error: ld returned 1 exit status

I see that troubles with extern line, but nothing special I don't see.

0

There are 0 answers