OSDev.org

The Place to Start for Operating System Developers
It is currently Tue May 14, 2024 2:33 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: I'm unable to initialize IDE controller on bochs
PostPosted: Sun Aug 20, 2023 2:15 am 
Offline

Joined: Sun Aug 20, 2023 2:05 am
Posts: 1
My code:
Code:
%macro outb 2
   mov dx, %1
   mov al, %2
   out dx, al
%endmacro

%macro inb 2
   mov dx, %1
   in al, dx
   mov %2, al
%endmacro

[bits 32]

section .text

extern bootloader
extern disk_error
extern kernel_not_loaded_error

global load_kernel_test
load_kernel_test:
   mov byte [0x2000], 0xEB
   mov byte [0x2001], 0xFE
   mov byte [0x2002], 0x00
   mov byte [0x2003], 0x00
   ret

global load_kernel
load_kernel:
   outb 0x1F6, 0xA0

   outb 0x1F2, 1
   outb 0x1F3, 0x00
   outb 0x1F4, 0x49
   outb 0x1F5, 0x00

   outb 0x1F7, 0x20

   inb 0x1F7, al
   test al, 0x40
   jz .take_a_nap
   
   mov edi, kernel_start
.read_loop:
   inb 0x1F0, al
   stosb
   inb 0x1F7, al
   test al, 0x40
   jz .read_loop

   inb 0x1F7, al
   test al, 0x01
   jnz .error_occured
.take_a_nap:
   sub edi, kernel_start
   ret
.error_occured:
   call disk_error
   ret

global call_kernel
call_kernel:
   jmp kernel_start
   ret

global check_kernel
check_kernel:
   cmp byte [kernel_start], 0xEB
   jne kernel_not_loaded_error
   jmp call_kernel

section .rodata:
kernel_start equ 0x2000


I'm reading 50th sector from the disk 0 on the IDE controller. disk_error doesn't run on real hardware but kernel_not_loaded_error does. On bochs both error labels are being executed. load_kernel_test is for loading my kernel from the code and it works so I assume that it's the IDE loading problem. My bochs configuration:
Code:
cpu: count=2, reset_on_triple_fault=0

display_library: x, options="gui_debug"

megs: 512

clock: sync=realtime, time0=local

ata0-master: type=disk, path="build/floppy.img", mode=flat
boot: c

log: ./bochsout.txt

mouse: enabled=0

magic_break: enabled=1


floppy.img is fat12 file system that contains bootsector, stage2.bin and kernel.bin. kernel.bin is on offset 0x6400 on the file system (sector size is 512B).


Top
 Profile  
 
 Post subject: Re: I'm unable to initialize IDE controller on bochs
PostPosted: Wed Aug 23, 2023 8:52 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5158
zielonykid1234 wrote:
Code:
   outb 0x1F6, 0xA0

   outb 0x1F2, 1
   outb 0x1F3, 0x00
   outb 0x1F4, 0x49
   outb 0x1F5, 0x00

You selected CHS, but 73/0/0 isn't a valid CHS address. How did you come up with these values? Were you trying to use LBA?

zielonykid1234 wrote:
Code:
   inb 0x1F0, al

Using byte accesses on this port is (usually) undefined behavior. You must use word accesses here.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot], Kaius, SemrushBot [Bot] and 39 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group