Bona Fide OS Developer
View unanswered posts | View active topics It is currently Thu Mar 28, 2024 4:13 am



Post new topic Reply to topic  [ 9 posts ] 
 Can anyone help me? 
Author Message

Joined: Mon Feb 08, 2010 12:20 pm
Posts: 12
Post Can anyone help me?
I have my own written boot loader, but I don't have a physical floppy disk drive, and I do not wan to do it on HDD, because of the possible reason to destroy MBR.

So I want to use virtual PC - BOCHS, but how in this case, I can, using floppy IMG file, write MBR? Surfing on the internet, I caught some Python scripts, which are able
as they say, do what I have described here, but the Pythons language is unknown for me and scripts won't work.

Can anyone please give me some XP/linux scripts that are actually working and maybe tell me a method with whom help I can, using IMG file write desired MBR file?


Sat Feb 13, 2010 4:44 pm
Profile

Joined: Tue Jan 19, 2010 11:51 pm
Posts: 66
Post Re: Can anyone help me?
You missed the Window. Beats me.

I started mine in 1993 and switched to protected mode from DOS really easily. I just wrote a TASM program and ran it and took control. DOS lets you do whatever you want and runs in real mode.

I restarted it in 2003 and installed FreeDOS. I ran it as before and worked with a floppy drive. I wrote my HDD and CD-ROM code. My operating system now has it's own compiler, own CD-ROM image file maker/burned. I don't have a floppy drive anymore and removed all that code.

At one point I used LILO, the predicessor to GRUB as my master boot loader. I wrote my own master boot loader. It worked for Windows XP, but something's wrong on my current system and my boot loader won't boot Windows. It almost seems like the BIOS doesn't like something or Windows has antivirus or some shit. I just put a second hard drive in it and use the BIOS to dual boot.

You came too late to the game, kid. Good luck learning ASM and stuff. We all learned that as it happened.


Sat Feb 13, 2010 5:43 pm
Profile

Joined: Tue Jan 19, 2010 11:51 pm
Posts: 66
Post Re: Can anyone help me?
Mine's 64-bit, but nobody believes me because I use low resolution and color.


LoseThos can help you, but 16-bit support is weak because my assembler only needs to compile my boot loaders. My compiler is just 64-bit, not 32 or 16-bit. The transition from 16-bit to 32-bit to 64-bit in the start-up process must be done in ASM and mustn't do anything fancy in 16-bit mode. Just get to 64-bit ASAP and never look back.

You can use LoseThos: http://www.losethos.com It's public domain.


Sat Feb 13, 2010 5:47 pm
Profile

Joined: Sat Jul 25, 2009 9:15 am
Posts: 257
Post Re: Can anyone help me?
@Terry: OMG you got bragging rights but holy cow you lay it on yourself thick

@likesogunfire: what you want is easier then you think... think of a floppy IMG as a plain 1474560 file... make it a file full of zeros I suppose... The first sector is basically the first 512 bytes in that file... copy your bootloader there and you have a bootable image...

for future reference a 1.44MB floppy has:
2 heads
18 sectors
80 cylinders a.k.a. tracks

heads start at 0
sectors start at 1
cylinders start at 0

you should think of the floppy as follows:
- a floppy has 80 cylinders per side
- each cylinder has 18 sectors
- head 0 is one side and head 1 is the other side
- the very first sector starts at (head = 0, sector = 1, cylinder = 0)

going from sector to sector
Code:
if (head == 0) {
   head++;
} else {
   head = 0;
   if (sector != 18) {
      sector++
   } else {
      sector = 1;
      if (cylinder != 79) {
         cylinder++;
      } else {
         // error: impossible: trying to go beyond 2880 sectors
      }
   }
}


you can use the linux dd utility to write to your floppy image but for that you have to convert (head, sector, cylinder) indexing to flat sector indexing... I believe the equation for that is:
Code:
cylinder * 160 + head * 18 + sector - 1 = flat index


disclaimer: I am doing this off the top of my head so I might mistake out somewhere anywho if you image google "track sector head" you'll get some nice helpful pictures


Sat Feb 13, 2010 6:55 pm
Profile

Joined: Mon Feb 08, 2010 12:20 pm
Posts: 12
Post Re: Can anyone help me?
@DudeOfX; Thank you, I know how to use DD too in Linux, for floppy/flash/hdd
Code:
dd if=bootsectorfile.bin of=fd0 bs=512
and floppy now be bootable, but now i need to make bootable EXISTING file, so - how make file bootable?
How can i make this on floppy image file (which are for BOCHS and other virtual PC)? simulation Or do I have to do it in some hex editor, if so, can you give me an exmaple? Thanks


Sun Feb 14, 2010 7:46 am
Profile

Joined: Sat Jul 25, 2009 9:15 am
Posts: 257
Post Re: Can anyone help me?
creating a blank floppy image using dd
Code:
dd if=/dev/zero of=file.img bs=512 count=2880


injecting your bootloader into file using dd
Code:
dd if=boot.bin of=file.img bs=512 conv=notrunc


there is no magic... just common sense...


Sun Feb 14, 2010 10:18 am
Profile

Joined: Tue Jul 28, 2009 4:09 am
Posts: 58
Location: United Kingdom
Post Re: Can anyone help me?
Hey,

@likesogunfire: Apologies if I have misunderstood your requirements; however, if you mean you want to amend the boot sector of an existing floppy disk image, then that can be achieved very simply with dd. Your example;
Code:
dd if=bootsectorfile.bin of=fd0 bs=512

can easily be applied to a file. The Output and Input files of the dd command can be files, as well as devices. So, for example;
Code:
dd if=bootsectorfile.bin of=bootfloppy.img bs=512

should be valid.

Thanks,

James


Sun Feb 14, 2010 10:30 am
Profile

Joined: Mon Feb 08, 2010 12:20 pm
Posts: 12
Post Re: Can anyone help me?
Thank you so much for the help, both, DudeOfX and Agalloch :) The one that worked for me was the one that DudeOfX gave :)
If there will be some future misunderstandings I shall come back. Just to add, I wanted to ask, if this is true that to switch from real mode to protected I need A20 GATE, or is there anything else?...


Sun Feb 14, 2010 2:49 pm
Profile

Joined: Tue Jul 28, 2009 4:09 am
Posts: 58
Location: United Kingdom
Post Re: Can anyone help me?
Hey,

Sorry DudeOfX, didn't noticed you'd responded already at the time of my response.

In order to switch an IA-32 (x86, x86_32) processor from "Real Mode" to "Protected Mode", you need to follow the procedure the method described in the Intel Architecture Manuals. In the current edition, that process is described in Chapter 9, Section 9.9.1. The process involved preparing some basic data structures, switching into protected mode, and then doing a long jump in order to begin operating in the new environment.

Due to a legacy feature of computers, there is also the A20 gate you mention. It is a legacy feature of the 20-bit Address Bus featured in computers built from processors with larger Addresses busses, so that the processor would function as expected. If you want to know the details of why it is neccessary you can find the story easily on the internet, but basically, it is possible that the 21st (A20, it starts at A0) address bit is masked on the bus and needs to be enabled before protected mode will function correctly.

The two primary ways it is masked, are by a hack in the Keyboard Controller, which was used for no good reason to mask the bit, or by a processor pin in newer models. Most computers should be built so that either way, the code on this page...

http://www.nondot.org/sabre/os/files/Booting/enableA20.s

should unmask it, either because the keyboard controller is masking it, or because the chipset intercepts the commands and tells the processor to not mask the bit. However, this is not the fastest method, so you may also wish to look at the many other methods available, including a BIOS function that may be present. I try many methods in my bootloader, including determining whether the bit is already unmasked, which is becoming more and more common in general purpose computers.

Thanks,

James


Sun Feb 14, 2010 3:17 pm
Profile
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 


Who is online

Users browsing this forum: No registered users and 15 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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by Vjacheslav Trushkin and tweaked by the BF Team.