0

I am using Windows 10 and Windows subsystem for linux. I have started creating my own Operating System in Assembly and C. I am following a tutorial. I got stuck into 2 problems.

Error 1: When I Link and create bin files, i am getting a warning: "ld: warning: cannot find entry symbol _start; defaulting to 0000000000001000" Does this matter?

Error 2: After compiling my code, there was no error. But when i boot my operating system, it shows an error: Disk read error!

Please help me.

Boot.asm

[org 0x7c00]
KERNEL_OFFSET equ 0x1000 
mov [BOOT_DRIVE], dl 

mov bp, 0x9000
mov sp, bp
mov si, MSG_REAL_MODE 
call print 
call load_kernel 
call switch_to_pm 

jmp $

%include "printstr.asm"
%include "diskload.asm"
[bits 16]

load_kernel :
mov si, MSG_LOAD_KERNEL 
call print
mov bx, KERNEL_OFFSET 
mov dh, 15 
mov dl, [ BOOT_DRIVE ]
call disk_load 
ret
[bits 32]

BEGIN_PM :
mov ebx, MSG_PROT_MODE 
call print_string_pm 
call KERNEL_OFFSET 


jmp $

BOOT_DRIVE db 0
MSG_REAL_MODE db " Started in 16 - bit Real Mode " , 0
MSG_PROT_MODE db " Successfully landed in 32 - bit Protected Mode " , 0
MSG_LOAD_KERNEL db " Loading kernel into memory. " , 0

times 510 -( $ - $$ ) db 0
dw 0xaa55

diskload.asm

disk_load :
push dx 

mov ah , 0x02 
mov al , dh ; 
mov ch , 0x00 
mov dh , 0x00 
mov cl , 0x02 

int 0x13 
jc disk_error 
pop dx 
cmp dh , al 
jne disk_error 
ret
disk_error :
mov si , DISK_ERROR_MSG
call prints
jmp $
; Variables
DISK_ERROR_MSG db " Disk read error !" , 0
prints:
lodsb           
    or  al, al  
    jz  printdones
    mov ah, 0eh     
    int 10h
    jmp prints      

printdones:
    ret

Compiling commands:

nasm boot.asm -f bin -o boot.bin
nasm kernel_entry.asm -f elf64 -o kernel_entry.o
gcc -ffreestanding -c kernel.c -o kernel.o
ld -o kernel.bin -Ttext 0x1000 kernel_entry.o kernel.o --oformat binary
cat boot.bin kernel.bin > os.iso

2 Answers2

0

ld: warning: cannot find entry symbol _start; defaulting to 0000000000001000

The effect of this error will be that the entry point address stored in the executable file will not be correct.

However, "raw" binary files only containing some memory content; they don't contain any additional information - such as the entry point - as an ELF or COFF file would do.

In other words: For "raw" binary files (--oformat binary) this warning message has no meaning at all.

But when i boot my operating system, it shows an error: Disk read error!

I'm not sure, but there are two possible errors:

  1. Are you sure that the ES register contains the correct value?
    (If you want to load your kernel into absolute address 0x1000, you have to set ES to 0.)

  2. Many drive types don't support reading too many sectors at once.
    (However a real 1440K drive should support reading 15 sectors starting at sector #2.)

Martin Rosenau
  • 17,897
  • 3
  • 19
  • 38
0

I had this problem too , the disk read error may be caused by your final os image being too small for 15 sectors read.

if you use qemu , try to resize your os image with :

qemu-img resize os.iso +20K

this is going to resize your image to 20 KB (you can put your own value instead of 20K).

I think qemu considers the os image as the whole disk , so you should resize it accordingly .

Amine Bensalem
  • 362
  • 3
  • 15
  • I tried, but not getting it. I am using Virtual Box and VMware. Let me check in qemu –  Dec 15 '19 at 13:36