[Q] Went over 512 bytes (16-bit real mode). What's next?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
Sophite
Posts: 9
Joined: Wed May 10, 2017 1:54 pm

[Q] Went over 512 bytes (16-bit real mode). What's next?

Post by Sophite »

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: Select all

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
Kevin
Member
Member
Posts: 1071
Joined: Sun Feb 01, 2009 6:11 am
Location: Germany
Contact:

Re: [Q] Went over 512 bytes (16-bit real mode). What's next

Post by Kevin »

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.
Last edited by Kevin on Wed May 10, 2017 3:01 pm, edited 1 time in total.
Developer of tyndur - community OS of Lowlevel (German)
User avatar
Geri
Member
Member
Posts: 442
Joined: Sun Jul 14, 2013 6:01 pm

Re: [Q] Went over 512 bytes (16-bit real mode). What's next

Post by Geri »

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
User avatar
Sophite
Posts: 9
Joined: Wed May 10, 2017 1:54 pm

Re: [Q] Went over 512 bytes (16-bit real mode). What's next

Post by Sophite »

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.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: [Q] Went over 512 bytes (16-bit real mode). What's next

Post by Brendan »

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: Select all

	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.
User avatar
dozniak
Member
Member
Posts: 723
Joined: Thu Jul 12, 2012 7:29 am
Location: Tallinn, Estonia

Re: [Q] Went over 512 bytes (16-bit real mode). What's next

Post by dozniak »

If you want a multiboot-compliant loader in 512 bytes, take a look.
Learn to read.
glauxosdever
Member
Member
Posts: 501
Joined: Wed Jun 17, 2015 9:40 am
Libera.chat IRC: glauxosdever
Location: Athens, Greece

Re: [Q] Went over 512 bytes (16-bit real mode). What's next

Post by glauxosdever »

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
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: [Q] Went over 512 bytes (16-bit real mode). What's next

Post by Brendan »

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.
User avatar
dozniak
Member
Member
Posts: 723
Joined: Thu Jul 12, 2012 7:29 am
Location: Tallinn, Estonia

Re: [Q] Went over 512 bytes (16-bit real mode). What's next

Post by dozniak »

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.
User avatar
Sophite
Posts: 9
Joined: Wed May 10, 2017 1:54 pm

Re: [Q] Went over 512 bytes (16-bit real mode). What's next

Post by Sophite »

dozniak wrote:If you want a multiboot-compliant loader in 512 bytes, take a look.
Not making a bootloader, making the OS multiboot-bootable.
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: [Q] Went over 512 bytes (16-bit real mode). What's next

Post by thepowersgang »

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
User avatar
dozniak
Member
Member
Posts: 723
Joined: Thu Jul 12, 2012 7:29 am
Location: Tallinn, Estonia

Re: [Q] Went over 512 bytes (16-bit real mode). What's next

Post by dozniak »

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.
LtG
Member
Member
Posts: 384
Joined: Thu Aug 13, 2015 4:57 pm

Re: [Q] Went over 512 bytes (16-bit real mode). What's next

Post by LtG »

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..
glauxosdever
Member
Member
Posts: 501
Joined: Wed Jun 17, 2015 9:40 am
Libera.chat IRC: glauxosdever
Location: Athens, Greece

Re: [Q] Went over 512 bytes (16-bit real mode). What's next

Post by glauxosdever »

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
Post Reply