flat assembler
Message board for the users of flat assembler.

Index > OS Construction > multi-stage bootloader on vmware workstation...

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
newport



Joined: 08 Jun 2012
Posts: 86
Location: Kentucky, USA
newport 18 Jun 2012, 02:53
hey guys,
i'm relatively new here and there seems to be a lot of experience within these boards so I'm hoping someone can help me out...
Basically, I'm wanting to develop my own OS from scratch without any outside (asm libraries or api's) that is not dependent on any existing OS design (eg: windows or linux). This simple OS would allow me to develop my own programming language of which I could continue writing the OS development and possible some internet integration.

Here's my problem...
I've successfully been able to make a blank "virtual" floppy using VMware onto which I have written my initial boot image to sector 1 (512 bytes)...from here I am lost...I have read just about every thread devoted to boot loaders on this board, OSDev, and several other boards, plus my books at home, and while some of them show me exactly what to do, none have answered my question...
Must the second sector of the disk be written to with the 2nd stage boot prior to the multi-stage bootloader be executed or can the "1st stage boot" load and write the second sector with an existing .bin on my harddrive?
and if so how do I calculate the exact address of the second sector of which boot1 should transfer too?

I hope this makes sense..I'm still trying to adjust to assembly jargon coming from a php background..so please bear with me. I want to really understand assembly but most tutorials just give you the how to without actually explaining why you do this or that and this is where I get confused. Thank you for your time and I look forward to your responses!

_________________
It's the desire to learn that leads to success...

http://www.webicomp.com


Last edited by newport on 18 Jun 2012, 03:57; edited 1 time in total
Post 18 Jun 2012, 02:53
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20416
Location: In your JS exploiting you and your system
revolution 18 Jun 2012, 03:49
Once your boot loader is running you can do whatever you want. There is no requirement to force the 2nd sector to be anything. Your code is executing and the CPU will do whatever you tell it to. If you want to make a file system that writes from the back end of the disk in reverse then you can. If you want to leave the 2nd sector completely unused then you can. If you want to follow the "usual" method of putting a partition table in sector 1 then you can.
Post 18 Jun 2012, 03:49
View user's profile Send private message Visit poster's website Reply with quote
newport



Joined: 08 Jun 2012
Posts: 86
Location: Kentucky, USA
newport 18 Jun 2012, 08:25
I found this awesome layout and information table describing sectors of floppies and HD's...It has helped me to understand more about disk structure..I thought I'd post the link and hope it helps someone else like it has me...

If anyone has any objections to the table or spots any misinformation - please comment on it...so we all know what is correct. Thanks!

Drive offset and Sector Conversions

_________________
It's the desire to learn that leads to success...

http://www.webicomp.com
Post 18 Jun 2012, 08:25
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20416
Location: In your JS exploiting you and your system
revolution 18 Jun 2012, 10:30
(Floppy Diskettes never have a Master Boot Record!)
That is false. There is no difference between floppy and hard disks for booting. The BIOS just simply loads the first sector and executes it. It is up to the boot code as to what format or function each of the sectors have.
Post 18 Jun 2012, 10:30
View user's profile Send private message Visit poster's website Reply with quote
newport



Joined: 08 Jun 2012
Posts: 86
Location: Kentucky, USA
newport 18 Jun 2012, 11:04
good looking out revolution!

_________________
It's the desire to learn that leads to success...

http://www.webicomp.com
Post 18 Jun 2012, 11:04
View user's profile Send private message Visit poster's website Reply with quote
newport



Joined: 08 Jun 2012
Posts: 86
Location: Kentucky, USA
newport 18 Jun 2012, 11:11
I'm still having a problem and I'm sure it's because of my limited knowledge and understanding..

but...

I create a bootsector.. which loads fine and displays my message on the screen....
Code:
format binary as 'img.flp'   ; VMware floppy format
use16;

   mov ax, 7C0h       ;0000:7C00
   mov ds, ax

   mov si, msg
get_msg:lodsb
   or al, al

   jz keys_hang
   mov ah, 0x0E

   int 0x10
   jmp get_msg

keys_hang:
        xor ax, ax

        mov ah, 0

        int 16h
        jz hang_end

hang_end:

        ;int 16h
        int 19h ;just reboots and displays message again
        ;I believe here the code should transfer to the 2nd stage but am unsure how to implement....without the int 19h of course...


msg   db 'Welcome to Newbie_OS BootLoader...', 13, 10
      db 'A newbie style boot loader...', 13, 10
      db ' ', 13, 10, 0


   times 510 - ($-$$) db 0

   db 0x55
   db 0xAA    


However calling the 2nd file remains a mystery...I've tried several of the examples listed within the boards..however nothing seems to work..guidance please.....?

_________________
It's the desire to learn that leads to success...

http://www.webicomp.com
Post 18 Jun 2012, 11:11
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20416
Location: In your JS exploiting you and your system
revolution 18 Jun 2012, 11:27
newport wrote:
However calling the 2nd file remains a mystery...
If you have more code on the disk that you want to load into memory then you need to load it with your boot sector code. The BIOS will only load the first sector, nothing else. After your boot code starts executing then you have to load the rest of the sectors yourself.
Post 18 Jun 2012, 11:27
View user's profile Send private message Visit poster's website Reply with quote
BAiC



Joined: 22 Mar 2011
Posts: 272
Location: California
BAiC 18 Jun 2012, 13:34
newport: your situation sounds like mine. I also have a background in web development with PHP being one of the last languages I mastered before diving into the deep end of OS development with assembly a couple years ago. I've been developing Mathis with the goal of a scripting language also.

Assembly, x86 in particular, requires every little step of an algorithm to be expressed explicitly. if you want your OS to work on anything more than an emulator (or virtual machine) then you'll need to look beyond the BIOS. I chose to implement my own drivers for disk access as well as my own File System. the latter of which is looking more like SQL than FAT.

by the way, VMware supports "*.img" files for the Floppy Image.

Stefan
Post 18 Jun 2012, 13:34
View user's profile Send private message Visit poster's website Reply with quote
newport



Joined: 08 Jun 2012
Posts: 86
Location: Kentucky, USA
newport 18 Jun 2012, 23:01
Thanks BAiC ! I was also thinking of my own filesystem and drivers...I guess great minds think alike huh? LOL! Anyways, that definitely is the road I'm wanting to travel, but I've reach a stumbling block of crossing from one section to the other... I'm still working on expanding the bootsector...when I get it done would you mind taking a look at it and try and help me understand where I'm going wrong. I want to try to do it as much as possible to get it work myself, but so far I've failed...I'll post my new code as soon as get time to complete it...Maybe I'll get lucky this time...who knows?

oh, and the .flp i use for vmware...I created a blank floppy(.flp) using vmware and just stuck with that...It never crossed my mind that .img would work as well. Thanks for the info!

_________________
It's the desire to learn that leads to success...

http://www.webicomp.com
Post 18 Jun 2012, 23:01
View user's profile Send private message Visit poster's website Reply with quote
newport



Joined: 08 Jun 2012
Posts: 86
Location: Kentucky, USA
newport 19 Jun 2012, 03:08
Ok guys..I'm bout at my wits end and officially a stroke candidate...
Nearly 24 hours later and I still can not load anything or execute beyond my bootsector...could someone please help me to understand where I am going wrong. This is what I have so far...

loadbootsector.asm
Code:
format binary as 'img.flp'
use16


; boot sector code
  include 'mbr_s1.asm'

  

;stage 2
  include 'mbr_s2.asm' 
    

mbr_s1.asm
Code:
   mov ax, 7C0h       ;0000:7C00
   mov ds, ax

   mov si, msg
get_msg:lodsb
   or al, al

   jz keys_hang
   mov ah, 0Eh

   int 10h
   jmp get_msg

keys_hang:
        xor ax, ax
        mov ah, 0
        ;int 16h
        jz hang_end

hang_end:

    xor ah, ah       ;0200:07C0
    mov ah, 02h      ;read disk sectors into memory
    mov al, 1        ;number of sectors to read/write
    mov ch, 0        ;cylinder number
    mov cl, 2        ;sector number
    mov dh, 0        ;head number
    mov dl, 0        ;drive number
    mov bx, 27C0h
    mov es, bx       ;points to the data buffer
    int 13h
    jmp 27C0h


msg   db 'Welcome to My_OS BootLoader...', 13, 10
      db 'A newbie style boot loader...', 13, 10
      db ' ', 13, 10, 0


   times 510 - ($-$$) db 0

   db 0x55
   db 0xAA   
    

mbr_s2.asm
Code:
org 27C0h

mov si, stage2msg


ld_msg:
      lodsb
      or al, al
      jz inf_lp
      mov ah, 0Eh
      int 10h
      jmp ld_msg

inf_lp:

      jmp inf_lp

stage2msg db 'Second Stage following boot sector....', 13, 10, 0

times 512 - ($-$$) db 0
    
Question

_________________
It's the desire to learn that leads to success...

http://www.webicomp.com
Post 19 Jun 2012, 03:08
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20416
Location: In your JS exploiting you and your system
revolution 19 Jun 2012, 05:52
Do you understand how the segmentation works?

ES:BX in your example points to:
0x27c0:0x27c0 ---> linear address of 0x27c00 (ES*0x10) + 0x27c0 (BX) = 0x2a3c0
Post 19 Jun 2012, 05:52
View user's profile Send private message Visit poster's website Reply with quote
newport



Joined: 08 Jun 2012
Posts: 86
Location: Kentucky, USA
newport 19 Jun 2012, 05:59
not entirely, but that particular address was just one that I tried. I originally had 0800h but that didn't work either. However when I replaced it with 7C0h as in the boot sector, it worked just now, so that gets me to wondering that before I can jump to the second stage, I need to relocate the boot sector in memory. Is this correct? or am I way off in left field. To be honest, i've been reading about segments and such and at this point am totally confused. Thanks for wanting to help!

Isn't it like [segment * 16] + offset = memory address?

_________________
It's the desire to learn that leads to success...

http://www.webicomp.com
Post 19 Jun 2012, 05:59
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20416
Location: In your JS exploiting you and your system
revolution 19 Jun 2012, 06:02
The BIOS will load your 2nd sector to address 0x2a3c0 because you have set ES and BX to point to there. But you jump to address 0x027c0 where there will be random data in memory.
Post 19 Jun 2012, 06:02
View user's profile Send private message Visit poster's website Reply with quote
newport



Joined: 08 Jun 2012
Posts: 86
Location: Kentucky, USA
newport 19 Jun 2012, 06:13
revolution wrote:
The BIOS will load your 2nd sector to address 0x2a3c0 because you have set ES and BX to point to there. But you jump to address 0x027c0 where there will be random data in memory.


so es:bx should point to the memory address but I need to jump to the linear address? correct?

while I'm here..

could 27C0h also be written as...

0027h:00C0h

???

I was trying to understand that book I got Assembly Step by Step but it just aint happnin...but if I'm correct in understanding what you are saying then yet another light has come on...

_________________
It's the desire to learn that leads to success...

http://www.webicomp.com
Post 19 Jun 2012, 06:13
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20416
Location: In your JS exploiting you and your system
revolution 19 Jun 2012, 06:20
Your jump address is affected by the CS segment register. After the BIOS jumps to your code CS==0x0000.

0x27c0 can be addressed in many ways. Here are some:
0x0000:0x27c0
0x0200:0x07c0
0x0070:0x20c0
0x0270:0x00c0
0x027c:0x0000

But not 0x0027:0x00c0
Post 19 Jun 2012, 06:20
View user's profile Send private message Visit poster's website Reply with quote
newport



Joined: 08 Jun 2012
Posts: 86
Location: Kentucky, USA
newport 19 Jun 2012, 06:26
thanks for the patience revolution...

so i just tried substituting what you had stated prior and I get a value out of range error....

it's a little confusing cause if bios loads the boot sector at 7C0h, this should in all rights be the first sector, however it isn't is it...it's like way on down the line...

so how would I do the formula in reverse order..say I wanted to jump to 100h for the second stage...?

_________________
It's the desire to learn that leads to success...

http://www.webicomp.com
Post 19 Jun 2012, 06:26
View user's profile Send private message Visit poster's website Reply with quote
BAiC



Joined: 22 Mar 2011
Posts: 272
Location: California
BAiC 19 Jun 2012, 06:28
if I may suggest something; why don't you place the second sector immediately after the first one?

edit: at 0x7E00, I mean.. (es=0, bx=0x7E00)
Post 19 Jun 2012, 06:28
View user's profile Send private message Visit poster's website Reply with quote
newport



Joined: 08 Jun 2012
Posts: 86
Location: Kentucky, USA
newport 19 Jun 2012, 06:30
BAiC wrote:
if I may suggest something; why don't you place the second sector immediately after the first one?

edit: at 0x7E00, I mean.. (es=0, bx=0x7E00)


so that would be 7E0h correct?

sorry I didn't see where you had the edit...

_________________
It's the desire to learn that leads to success...

http://www.webicomp.com
Post 19 Jun 2012, 06:30
View user's profile Send private message Visit poster's website Reply with quote
BAiC



Joined: 22 Mar 2011
Posts: 272
Location: California
BAiC 19 Jun 2012, 06:34
Code:
xor ax, ax
mov es, ax
mov bx, 0x7E00    

or
Code:
mov ax, 0x7E0
mov es, ax
xor bx, bx    
Post 19 Jun 2012, 06:34
View user's profile Send private message Visit poster's website Reply with quote
newport



Joined: 08 Jun 2012
Posts: 86
Location: Kentucky, USA
newport 19 Jun 2012, 06:41
sorry guys..I feel like such a dumbass...it ain't working...the cpu freezes before going to second stage....

_________________
It's the desire to learn that leads to success...

http://www.webicomp.com
Post 19 Jun 2012, 06:41
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >
Forum Rules:
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 vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.