OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Sep 17, 2019 3:04 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: boot-sector and bochs problems
PostPosted: Tue Sep 03, 2019 10:32 am 
Offline
Member
Member
User avatar

Joined: Tue Dec 11, 2018 3:13 pm
Posts: 34
I am simply trying to read from the data-region of the disk (which is, in fact, 33 sectors from the start. I am using a floppy-disk), and the boot-disk works, but is just a blank screen.

Is my use of segmentation off? shouldn't 0050:0000 and 0000:0500 be interchangeable?

Am I not reading from the correct part of the disk? I can open the image in a hex editor, and at offset 0x4200 (0x4200 / 512 (decimal) is 33 (decimal) is the exact same code found in the IO.ASM file that I wrote.

Also, as a sidenote: Using the bochs (GUI) debugger, when ever a 'mov cx, ...' or instruction happens, CX never changes its value in the debugger. (at least for me). is something wrong with my build of bochs, or is this correct behavior? same with the SP register. Only increments (INC, DEC, ADD, SUB, etc), change its value (on my end), never anything else. I don't know why lol

And please, forgive me if I am making one heck of a mistake and overlooking something important...

Code:
NULL   EQU 0

BOOTSEG   EQU 07C0H
LOADSEG   EQU 0AE0H ; ignore; not used

   JMP  SHORT RSTREG
   NOP

   DB "PEDOS1.0"
BPBV00:   DW 512      ; Bytes per Disk-sector
BPBV01:   DB 1      ; Disk-sector per disk-cluster
BPBV02:   DW 1      ; Reserved disk-sectors
BPBV03:   DB 2      ; how many FATS are on the disk
BPBV04:   DW 224
   DW 2880
   DB 0F0H
BPBV05:   DW 9
BPBV06:   DW 18
BPBV07:   DW 2
   DD 0
   DD 0
   DB 0
   DB 41
   DB 0
   DB "           "
   DB "FAT12   "

   ORG 7C00H
   
RSTREG:
   XOR  AX, AX
   MOV  DS, AX

   MOV  AX, WORD BOOTSEG
   CLI
   MOV  SS, AX
   MOV  SP, 1024
   STI
   
;   XOR  DX, DX
;   INT  13H
;

   PUSH 0050H
   POP  ES

   MOV  AX, 201 ; AH=02, AL=01; correct?
   MOV  CX, 33 ; CH=00, CL=33; correct?

; read the bochs sidenote: not sure if its related to actual hardware ; or just a bug in the ;debugger softare.

   XOR  DX, DX
   XOR  BX, BX
   INT  13H
   JC   SHORT DSKERR

   PUSH 0000H
   PUSH 0500H
   RETF

;
; If any errors have occurred during boot up,
; then alert the user, and halt the system, and
; retstart the system if requested.
;

DSKERR:
   LEA  SI, [ERRMSG]
PRNSTR:
   LODSB
   OR   AL, 0
   JZ   DSKHLT
   MOV  AH, 14
   MOV  BX, 7
   INT  16
   JMP  PRNSTR
DSKHLT:
   XOR  AX, AX
   INT  22
   INT  25

ERRMSG:   DB "Non-System disk or disk error...replace and try again when ready."
   DB NULL

DOSFLE:   DB "SHELL   SYS"
IOSFLE:   DB "IO      SYS"

   TIMES 510 - ($   - $$) DB 0

;
; End of the boot-sector.
;
   DW 0AA55H


Thanks for anything! :)


Top
 Profile  
 
 Post subject: Re: boot-sector and bochs problems
PostPosted: Tue Sep 03, 2019 1:21 pm 
Offline
Member
Member

Joined: Wed Aug 30, 2017 8:24 am
Posts: 239
saltlamp wrote:
Is my use of segmentation off? shouldn't 0050:0000 and 0000:0500 be interchangeable?
No, they aren't. They do resolve to the same linear address, though. But if you use CS-relative addressing in the loaded code, or if you copy CS into DS, you better get that segment correct to the value needed by the code.

Code:
   MOV  AX, 201 ; AH=02, AL=01; correct?
It would be if the 201 was hexadecimal. As it stands, however, you set AH to 0 and AL to 201, or 0xCB. According to RBIL that means you ordered a disk system reset.

Even if you had not made that blunder, though, you are deleting DX, and with that, DL, which BIOS gave you as the drive number to boot from. Don't do that. Preserve the DL!

Also, with NASM, you can directly order a far jump like this:
Code:
jmp 0:0x500
No need to fiddle with stack and far returns. You get to do that enough once you start with protected mode.

And one last thing before I go: The error message is misleading. You only print it if there was a disk error. So there is no possibility of the message occurring because its content was wrong.


Top
 Profile  
 
 Post subject: Re: boot-sector and bochs problems
PostPosted: Tue Sep 03, 2019 2:00 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 1636
saltlamp wrote:
Am I not reading from the correct part of the disk?

You are not. Well, you're not reading from the disk at all, but see the above post.

After you fix that, you should start getting disk read errors. That's because the sector you want to read is LBA 33, but you need to convert that value to CHS before you pass it to INT 0x13. For the standard formatting of a 1.44MB floppy disk, the geometry is (80,2,18). You can take that geometry and your desired LBA and put it into a calculator like this one to come up with the correct parameters. (Assuming the 1.44MB floppy disk, you want to pass (0,1,16) to INT 0x13.)

saltlamp wrote:
And please, forgive me if I am making one heck of a mistake and overlooking something important...

What's up with your ORG statement? I'm not familiar with every x86 assembler out there, but you probably want it at the top since the very first byte of your boot sector will be loaded to linear address 0x7C00.

What's up with your stack? It's only 512 bytes, that's not a lot of space.

Is there any particular reason you're using decimal for so many of your numbers? It's a bit jarring when comparing your code with BIOS documentation that almost exclusively uses hexadecimal. (Unfortunately, there's just enough inconsistency that it's hard to say you should always use one or the other...)


Top
 Profile  
 
 Post subject: Re: boot-sector and bochs problems
PostPosted: Tue Sep 03, 2019 9:48 pm 
Offline
Member
Member

Joined: Fri Aug 26, 2016 1:41 pm
Posts: 478
NASM's ORG is peculiar. You can only have one of them in a file (if you are outputting as bin format) and it doesn't matter where you place it in the file, it will act as if it was placed at the very beginning.


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 12 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