gcc - Compiling x86 and c with makefile -


i've been writing c 2-3 years , picked assembly use windows i've never needed use make files before i've used visual studio. i'm trying use cygwin , i686 cross compiler compile c , assembly files, , link them binary file representing operating system. new make files don't know how properly. i've got far makefile:

cc = i686-elf-gcc cc_flags = -c -std=gnu99 -ffreestanding -o2 -wall -wextra -i./include = i686-elf-as ld = i686-elf-gcc -t linker.ld -o myos.bin ld_flags = -ffreestanding -o2 -nostdlib -lgcc o_files = $(wildcard src/*.o)  all: $(o_files)     $(ld) $(ld_flags) $(o_files)  src/%.o: src/%.c     $(cc) $(cc_flags) -o $@ $<  src/%.o: src/%.asm     $(as) -o $@ $< 

i'm getting error stating linker can't find entry symbol _start nothing compiling. how fix this?

my src/linker.ld file defines _start entry point is:

entry(_start)  sections {         . = 1m;          .text block(4k) : align(4k)         {                 *(.multiboot)                 *(.text)         }          .rodata block(4k) : align(4k)         {                 *(.rodata)         }          .data block(4k) : align(4k)         {                 *(.data)         }          .bss block(4k) : align(4k)         {                 *(common)                 *(.bss)         } } 

the src/boot.asmfile i'm using defines _start label is:

# declare constants multiboot header. .set align,    1<<0             # align loaded modules on page boundaries .set meminfo,  1<<1             # provide memory map .set flags,    align | meminfo  # multiboot 'flag' field .set magic,    0x1badb002       # 'magic number' lets bootloader find header .set checksum, -(magic + flags) # checksum of above, prove multiboot  .section .multiboot .align 4 .long magic .long flags .long checksum  .section .bss .align 16 stack_bottom: .skip 16384 # 16 kib stack_top:  .section .text .global _start .type _start, @function _start:         mov $stack_top, %esp          call kernel_main          cli 1:      hlt         jmp 1b  .size _start, . - _start 

you need modify makefile this:

cc = i686-elf-gcc = i686-elf-as ld = i686-elf-gcc as_flags = ld_flags = -ffreestanding -nostdlib -lgcc -tlinker.ld cc_flags = -c -std=gnu99 -ffreestanding -o2 -wall -wextra -i./include  c_files := $(wildcard src/*.c) asm_files := $(wildcard src/*.asm) o_files := $(c_files:.c=.o) $(asm_files:.asm=.o) kernel_bin := myos.bin  all: $(kernel_bin)  clean:         rm -f $(kernel_bin) $(o_files)  $(kernel_bin): $(o_files)         $(ld) $(ld_flags) -o $@ $^  %.o: %.c         $(cc) $(cc_flags) -o $@ $<  %.o: %.asm         $(as) $(as_flags) -o $@ $< 

this makefile different in construct list of asm files , c files. cleaned ld_flags bit , added rule create myos.bin , clean object , bin files.

in current code you'd have makefile variables in them after expansion:

c_files   = src/string.c src/tty.c src/kernel.c asm_files = src/boot.asm o_files   = src/string.o src/tty.o src/kernel.o src/boot.o 

o_files derived concatenating both file lists , replacing .c , .asm extensions .o. list of objects need generated source files.

with gnu assembler customary use files .s extensions (or .s if want use c preprocessor) rather .asm


the reason _start label wasn't found because assembly files not being processed. means boot.asm not becoming boot.o , wasn't being linked @ all.


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -