Author Topic: a bit offtopic..  (Read 7164 times)

nobody

  • Guest
a bit offtopic..
« on: August 20, 2007, 02:45:38 PM »
Yes, I'm sorry to bother you with this, but I think some of you know this, and since I didn't want to register in osdev just for one clarification I thought I'd post here.

I'm writing a "bootloader", Take a look at this:  http://www.osdever.net/tutorials/loading_sectors.php


[ QUOTE ]
al = Number of sectors to read (To be safe I wouldn't cross the cylinder boundary)
dh = Head to read from (aka side)   - Addressing registers eg: Town/City
dl = Drive to read from.      - Country
ch = Cylinder (aka track) to read from   - Street name
cl = Sector to read         - House number
es = Segment to put loaded data into   - Output address in eg: Street name
bx = Offset to put loaded data into   - House number in the street

An example to load the first sector of a floppy disk would be:
ah=2(Function number),al=1(1 sector to read),dh=1(First head)
dl=0(default for floppy drive),ch=1(First cylinder),cl=1(First sector)
es=1000h(Put the output at 1000h in memory), bx=0(Offset of 0)
[ END QUOTE ]


And here's the contradiction:

[ CODE ]
; Load kernel procedure
LoadKern:
        mov ah, 0x02    ; Read Disk Sectors
        mov al, 0x01    ; Read one sector only (512 bytes per sector)
        mov ch, 0x00    ; Track 0
        mov cl, 0x02    ; Sector 2
        mov dh, 0x00    ; Head 0
        mov dl, 0x00    ; Drive 0 (Floppy 1) (This can be replaced with the value in BootDrv)
        mov bx, 0x2000  ; Segment 0x2000
        mov es, bx      ;  again remember segments bust be loaded from non immediate data
        mov bx, 0x0000  ; Start of segment - offset value
.readsector
        int 0x13        ; Call BIOS Read Disk Sectors function
        jc .readsector  ; If there was an error, try again
[ END CODE ]

So, does the disk interrupt (0x13) treat 1's as first sector/head/cylinder or 0's ?! o_O

I'll be thankful for some clarification, despite the offtopicness (sorry).

nobody

  • Guest
Re: a bit offtopic..
« Reply #1 on: August 21, 2007, 06:43:23 PM »
When I tried this old ROM/BIOS code on Win2000 I was astounded that
it still worked. I thought Windows after W95 forbade us to access those low interrupts. Live and learn.

To answer your question (hopefully):
   al starts at 1 (how many sectors you want to read)
   ch first cylinder is 00h
   cl first sector is 01h  <--- this is the one that's different
   dh first head is 00h
   dl floppy disks use 00h to 07h
      hard drives use 08h to 0ffh

You probably know this but the most important byte here is AH.
If AH is set to 03h the process WRITES data directly to the drive without asking you if you're " really, really sure you want to
do this". As soon as you hit the key the disk sector(s) gets overwritten.
Austin

nobody

  • Guest
Re: a bit offtopic..
« Reply #2 on: August 21, 2007, 10:54:21 PM »
Thanks for the reply.

Well I'm not accessing anything from within an OS, but rather loading my future (and primitive) kernel into memory, and I'm offcourse doing it all under Qemu (x86 emulator) at this point.

Anyway, thank you for the reply, and why are these _very_ short tuts so buggy ? +_+ , thats annoying.

Thanks again.

nobody

  • Guest
Re: a bit offtopic..
« Reply #3 on: August 22, 2007, 11:08:03 PM »
> tried this old ROM/BIOS code on Win2000 I was astounded that it still worked.

Yeah ... sector access to FLOPPIES via INT 13 or DOS INT's might work ... but sector access to HD or doing anything via ports (ATA-controller) is crippled off ...

> I thought Windows after W95 forbade us to access those low interrupts. Live and learn

... or avoid "Windows" :-D