OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Mar 29, 2024 9:31 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject: [Q] Went over 512 bytes (16-bit real mode). What's next?
PostPosted: Wed May 10, 2017 2:16 pm 
Offline
User avatar

Joined: Wed May 10, 2017 1:54 pm
Posts: 9
Hello everyone!

I was working in assembly (nasm, 16-bit real mode), and now I'm over 512 bytes.

At least I think I am, here's the assembler error:
Code:
boot.asm:38: panic: assertion output_ins.times >= 0 failed at asm/nasm.c:1342



I want to have a loader load the main kernel (Bootable program? What am I supposed to call this thing?), the main thing should then figure out filesystem stuff.

So... What should I do now?

I'm not really sure how to start with the loader.


Thanks :D

-Sophite


Top
 Profile  
 
 Post subject: Re: [Q] Went over 512 bytes (16-bit real mode). What's next
PostPosted: Wed May 10, 2017 3:00 pm 
Offline
Member
Member

Joined: Sun Feb 01, 2009 6:11 am
Posts: 1070
Location: Germany
Make your code smaller; or get enough code into the first 512 bytes that you can load the rest of the bootloader with it; or simply use an existing bootloader like GRUB because from your question I conclude that you're a beginner and shouldn't be writing a bootloader anyway. Writing a good bootloader is an advanced topic, and writing a bad bootloader is just a waste of time.

_________________
Developer of tyndur - community OS of Lowlevel (German)


Last edited by Kevin on Wed May 10, 2017 3:01 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: [Q] Went over 512 bytes (16-bit real mode). What's next
PostPosted: Wed May 10, 2017 3:00 pm 
Offline
Member
Member
User avatar

Joined: Sun Jul 14, 2013 6:01 pm
Posts: 442
write a boot loader:

1. bios places to DL the default the disk id (for example 0x80)

2. https://en.wikipedia.org/wiki/INT_13H

3. you just simply read the sectors (in 512 byte sizes) into the needed memory location. your ,,payload'' can begin on the disk from 512 byte.

4. jmp to that code.

_________________
Operating system for SUBLEQ cpu architecture:
http://users.atw.hu/gerigeri/DawnOS/download.html


Top
 Profile  
 
 Post subject: Re: [Q] Went over 512 bytes (16-bit real mode). What's next
PostPosted: Wed May 10, 2017 3:28 pm 
Offline
User avatar

Joined: Wed May 10, 2017 1:54 pm
Posts: 9
Kevin wrote:
Make your code smaller; or get enough code into the first 512 bytes that you can load the rest of the bootloader with it; or simply use an existing bootloader like GRUB because from your question I conclude that you're a beginner and shouldn't be writing a bootloader anyway. Writing a good bootloader is an advanced topic, and writing a bad bootloader is just a waste of time.


Geri wrote:
write a boot loader:

1. bios places to DL the default the disk id (for example 0x80)

2. https://en.wikipedia.org/wiki/INT_13H

3. you just simply read the sectors (in 512 byte sizes) into the needed memory location. your ,,payload'' can begin on the disk from 512 byte.

4. jmp to that code.



Thanks guys, I'll look into making it multiboot compliant.

Yes, I am quite new to this, thanks for the advice Kevin.


Top
 Profile  
 
 Post subject: Re: [Q] Went over 512 bytes (16-bit real mode). What's next
PostPosted: Wed May 10, 2017 10:21 pm 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8561
Location: At his keyboard!
Hi,

Sophite wrote:
So... What should I do now?


For my boot loaders, all I do is put code in the first sector that loads more sectors of the boot loader.

More specifically, I have code in the first sector that loads the second sector, then the second sector contains better error reporting (a bunch of ASCII strings and a routine to convert BIOS error codes into human readable error messages) and loads the third sector, then code in the third sector contains much better disk IO routines (LBA, multi-sector reads, etc) and loads the remainder of the boot loader.

Note that for NASM and "flat binary" you can create your own sections, which can be useful for controlling where things end up. For example, this is what I'm using for one of my boot loaders:

Code:
   SECTION .sector1 progbits start=0x0000 vstart=0x2000
   SECTION .sector2 progbits start=0x0200 vstart=0x2200
   SECTION .sector3 progbits start=0x0400 vstart=0x2400
   SECTION .publicKey progbits start=0x0600 vstart=0x2600
   SECTION .text progbits follows=.publicKey align=4 vfollows=.publicKey valign=4
   SECTION .data progbits follows=.text align=4 vfollows=.text valign=4
   SECTION .bss nobits follows=.data align=4


Note: my first sector also relocates itself from 0x00007C00 to 0x00002000, which is why I'm using "vstart=0x2000" and not "vstart=0x7C00".


Cheers,

Brendan

_________________
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.


Top
 Profile  
 
 Post subject: Re: [Q] Went over 512 bytes (16-bit real mode). What's next
PostPosted: Thu May 11, 2017 1:55 am 
Offline
Member
Member
User avatar

Joined: Thu Jul 12, 2012 7:29 am
Posts: 723
Location: Tallinn, Estonia
If you want a multiboot-compliant loader in 512 bytes, take a look.

_________________
Learn to read.


Top
 Profile  
 
 Post subject: Re: [Q] Went over 512 bytes (16-bit real mode). What's next
PostPosted: Thu May 11, 2017 2:10 am 
Offline
Member
Member

Joined: Wed Jun 17, 2015 9:40 am
Posts: 501
Location: Athens, Greece
Hi,


Sophite wrote:
I'll look into making it multiboot compliant.
I don't think there is much point into writing a multiboot-compliant bootloader yourself, since you could just as well use GRUB in this case.

If you want to write your own bootloader, I suggest you use GRUB and multiboot for some time (but don't tie your kernel to it), until you figure out how you can improve on it so it fits your OS better. Then write your bootloader using your improved boot specification and finally make the needed changes in your kernel so it adheres to your boot specification.

Hope this helps. :-)


Regards,
glauxosdever


Top
 Profile  
 
 Post subject: Re: [Q] Went over 512 bytes (16-bit real mode). What's next
PostPosted: Thu May 11, 2017 2:24 am 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8561
Location: At his keyboard!
Hi,

dozniak wrote:
If you want a multiboot-compliant loader in 512 bytes, take a look.


Nobody wants a multiboot-compliant loader that fits in 512 bytes, because the only way to make a multiboot-compliant loader fit in 512 bytes is to cripple it so badly that it becomes an unusable piece of trash.

  • Acceptable code to enable A20 (and test it actually worked)? No.
  • Acceptable code to obtain a memory map? No.
  • Actually complies with multi-boot specs (including setting video mode)? No.
  • No potentially false assumptions about the existence of random pieces of hardware that might not exist (PS/2 controller, floppy controller)? No.
  • Sanity checks (for OS's multi-boot header checksum, if RAM actually exists at 0x00100000, if the kernel is larger than RAM, ...)? No.
  • Nice descriptive error messages (so the user can figure out what went wrong, and what to do about it) for any/all problems? No.


Cheers,

Brendan

_________________
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.


Top
 Profile  
 
 Post subject: Re: [Q] Went over 512 bytes (16-bit real mode). What's next
PostPosted: Thu May 11, 2017 4:52 am 
Offline
Member
Member
User avatar

Joined: Thu Jul 12, 2012 7:29 am
Posts: 723
Location: Tallinn, Estonia
Brendan wrote:
Hi,

dozniak wrote:
If you want a multiboot-compliant loader in 512 bytes, take a look.


Nobody wants a multiboot-compliant loader that fits in 512 bytes, because the only way to make a multiboot-compliant loader fit in 512 bytes is to cripple it so badly that it becomes an unusable piece of trash.


I know that, Mr.knowitall.

Instead, you should've suggested to split the loader into two parts like grub does (stage1 to load the stage2 that does more, like reading fs modules and doing actual read and boot).

the 512 byte mboot loader was an interesting challenge and is still fun to read, so there, enjoy your righteousness.

_________________
Learn to read.


Top
 Profile  
 
 Post subject: Re: [Q] Went over 512 bytes (16-bit real mode). What's next
PostPosted: Thu May 11, 2017 8:35 pm 
Offline
User avatar

Joined: Wed May 10, 2017 1:54 pm
Posts: 9
dozniak wrote:
If you want a multiboot-compliant loader in 512 bytes, take a look.


Not making a bootloader, making the OS multiboot-bootable.


Top
 Profile  
 
 Post subject: Re: [Q] Went over 512 bytes (16-bit real mode). What's next
PostPosted: Thu May 11, 2017 9:58 pm 
Offline
Member
Member
User avatar

Joined: Tue Dec 25, 2007 6:03 am
Posts: 734
Location: Perth, Western Australia
If you're writing a kernel to be loaded by multiboot, then the 512 byte limit doesn't apply (and you shouldn't be writing real-mode code). Multiboot loads your entire image and starts you in protected mode.

_________________
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc


Top
 Profile  
 
 Post subject: Re: [Q] Went over 512 bytes (16-bit real mode). What's next
PostPosted: Fri May 12, 2017 12:53 am 
Offline
Member
Member
User avatar

Joined: Thu Jul 12, 2012 7:29 am
Posts: 723
Location: Tallinn, Estonia
Sophite wrote:
I'm not really sure how to start with the loader.


Sophite wrote:
Not making a bootloader, making the OS multiboot-bootable.


You may try learning to express yourself better.

There's OSDev Wiki article on how to make your kernel Multiboot-capable.

If you want to further support modular approach to support different filesystems and drivers in your multiboot kernel you have multiple ways:

* pass these components as multiboot modules, then load them in the kernel and use them to work with your filesystem
* invent your own image format and load that, then parse out the modules
* third option

_________________
Learn to read.


Top
 Profile  
 
 Post subject: Re: [Q] Went over 512 bytes (16-bit real mode). What's next
PostPosted: Fri May 12, 2017 6:48 am 
Offline
Member
Member

Joined: Thu Aug 13, 2015 4:57 pm
Posts: 384
dozniak wrote:
Sophite wrote:
I'm not really sure how to start with the loader.


Sophite wrote:
Not making a bootloader, making the OS multiboot-bootable.


You may try learning to express yourself better.


Dozniak, you conveniently left out the following part in the thread (between those two quotes):
Sophite wrote:
Kevin wrote:
or simply use an existing bootloader like GRUB

Thanks guys, I'll look into making it multiboot compliant.

Yes, I am quite new to this, thanks for the advice Kevin.


The "it" in "making _it_ multiboot compliant" is referring to the kernel I thought, not the bootloader Sophite was initially making. So the thread started with making a loader, Kevin suggested using GRUB (or something) and that means making the kernel MB compliant so it can be loaded and making your own loader can be skipped.

Sure, Sophite could have been more explicit, but I don't think it's nearly as bad as the two quotes you used make it out to be..


Top
 Profile  
 
 Post subject: Re: [Q] Went over 512 bytes (16-bit real mode). What's next
PostPosted: Sat May 13, 2017 1:40 am 
Offline
Member
Member

Joined: Wed Jun 17, 2015 9:40 am
Posts: 501
Location: Athens, Greece
Hi,


To be fair, I also thought the bootloader would be multiboot-compliant.

A suggestion: don't quote whole posts, but only the parts of these posts that are relevant to what you are talking about. This is the reason it wasn't apparent (at least to me) you were referring to the kernel.

Hope this helps. :-)


Regards,
glauxosdever


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: DotBot [Bot], Majestic-12 [Bot], TYDQSoft and 181 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