Where do i start??

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.
Berserk

Re:Where do i start??

Post by Berserk »

Hi,

How do i jump to my second stage loader from my BootSector in real mode??

Ciao ;)
note: i searched google, and nothing was found :(
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Where do i start??

Post by Pype.Clicker »

Berserk wrote: How do i jump to my second stage loader from my BootSector in real mode??
just know where you loaded it (segment:offset) and jmp segment:offset ...
note: i searched google, and nothing was found :(
seems you didn't searched very extensively ... 2 mins were enough to find a nicely commented 2-stages bootloader at http://www.dftech.cwc.net/osdev/Bootloader.html
...
Berserk

Re:Where do i start??

Post by Berserk »

Hey,

thanx, i got it working. Now for a question:

Do i have to make a new stack when i jump to my Second Stage Loader??

Or do i have to do something with the Stack??

Ciao ;)
Schol-R-LEA

Re:Where do i start??

Post by Schol-R-LEA »

Berserk wrote: Hey,

thanx, i got it working. Now for a question:

Do i have to make a new stack when i jump to my Second Stage Loader??

Or do i have to do something with the Stack??
While it can be argued that it is not absolutely necessary, it is a very wise idea to set up the stack at some point in the boot loader, the earlier the better; otherwise it will be wherever the BIOS set it up, which could be anywhere in lower memory (I think that there is supposed a standard location for it, but of course no one ever follows the standards...). Most boot loaders reset SS and SP as soon as is feasible, usually together with resetting the code segment (with a far jump) and and the data segment (usually matching it to the CS). For example my first-stage boot loader begins:

Code: Select all

;; constants
loader_base???equ 0x0000
%define loader_offset 0x7C00  ; cannot use EQU to give a value in an  ORG statement
stage2_entry???equ 0x1000???; the segment:offset to load the second stage into
stage2_offset???equ 0x0000???
stack_seg???equ 0x9000
stack_top???equ 0xFFFF

;; *** additional EQUs, macroes and comments snipped for space

[bits 16]
[org loader_offset]

entry:
???jmp loader_base:start   ; ensures that the CS is really at loader_base

start:
???cli
???mov ax, stack_seg
???mov ss, ax??????; and the stack at an arbitrarily high point past ES.
???mov ax, stack_top
???mov sp,  ax   ??????; put the stack pointer to the top of SS
???mov ax, cs
???mov ds, ax??????; set DS == CS
???sti??????; reset ints so BIOS calls can be used
You do want to give some thought as to where you put your stack segment, however, at least if you are going to be doing a lot of work in real mode. Make sure it is in a location that is well away from anything else you'll be using. I usually put the stack segment at 0x9000:0000 to start, with the stack pointer set to 0xFFFE, and then load the second stage at 1000:0000. Not the most memory efficient layout, perhaps, but convenient one for the most part.

If you've set it up in the first-stage loader, then it isn't necessary to do so again; it'll all get changed when you set up you switch to p-mode, anyway. If your loader is still in real mode in the second stage (which is a much easier than trying to stuff the GDT, etc. into the boot sector) and you haven't set up the stack, you probably shouldn't bother unless you are doing some elaborate work before switching to p-mode.

Once you are in p-mode, you should have already taken control of the stack, and you usually will only manipulate it for task-management purposes.

EDIT: I seem to have trailed of a bit on the second paragraph. I've finished what I was trying to say there now.
Berserk

Re:Where do i start??

Post by Berserk »

Thanks.

i just want to know a few things:

what is the purpose of the variable called variable??

Code: Select all

void ClearScreen(void)
{
 char* VideoMemory = (char*)0xB8000; //Pointer to Video Memory
   
 unsigned int variable = 0;
   
 while(variable < (80 * 25 * 2))
 {
  VideoMemory[variable] = 0x20;
  variable++;

  VideoMemory[variable] = 0x07;
  variable++;
 }
}
Also, what is the purpose of the variable called offset, and what is offset??

Code: Select all

void PutPixel(unsigned int xAxis, unsigned int yAxis, unsigned char PixelColour)
{
 unsigned char* VGA = (unsigned char*)0xA0000;
 unsigned short offset = 320 * yAxis + xAxis;

 VGA[offset] = PixelColour;
}
Also, Tom where did you get the mode 13 graphics lib from pk0.6?? Do you know any good links for mode 13 resources??

Ciao ;D
Tim

Re:Where do i start??

Post by Tim »

Bezerk, it looks like you're either lazy, or you don't know how to program. I hope that you're neither of those, because somebody who's lazy or who can't program isn't going to get very far in OS development.

I suggest you look carefully at your own question and answer it yourself.
Berserk

Re:Where do i start??

Post by Berserk »

Hey,

Yeh, i was in a bad mood :-[ Anyways, i found a good tutorial place.

Cyaz.
Berserk

Re:Where do i start??

Post by Berserk »

Hey,

What is the Simplest way to read from a floppy disk. I have seen all these complex functions with arguments and everything.

Could somebody show me the simplest way to read from a disk, with a function which takes no arguments.

Or does anybody know of any good tutorials??

Ciao ;)
NOTE: I Googled it, I keep on finding very complex functions.
tfurtado

Re:Where do i start??

Post by tfurtado »

Berserk, where is that 'good tutorial place'?
I would like to know.
Berserk

Re:Where do i start??

Post by Berserk »

Hey,

It was already mentioned: http://osdev.neopages.net

It's a really good web-site ;D

Ciao ;)
tfurtado

Re:Where do i start??

Post by tfurtado »

Thanks! I'll look at it.
What about your OS? In which state is its development?
Berserk

Re:Where do i start??

Post by Berserk »

Hey,

What is the Memory Location right after 0x7C00, i want to load my Second stage loader there. I want it to be right after the BootSector. And what are all these memory locations (e.g. 0x9000) how many are there. What is the maximum?? What are other places i can put the stack??

If you know any good tutorials it would be appreciated.

Now, i'm goin to bed ;D, Good Night. Cyaz in 24 hours ;)

Ciao ;)
note: Sorry i am in a big hurry.
PlayOS

Re:Where do i start??

Post by PlayOS »

hmm... that would be 0x7C01. But if you want to load you SSL after the boot code then you need 0x7E00, just as expected, 512 bytes after 0x7C00.

What do you mean, "What are all these memory locations", they are exactly that, MEMORY LOCATIONS, places to store data and code, you can stick your stack in any memory location you want. And as to how many memory locations there are, well to give you a hint, this calculation will tell you how many there are in your system, (MB OF RAM * 1024 * 1024) = number of memory locations.
Berserk

Re:Where do i start??

Post by Berserk »

Hey,

Ok, my system has 512mb of ram, so 512*1024*1027=536, 870, 912 - That's an awful lot of memory. So all this memory i am acessing is ram?? Where is the start off it, where is the end??

For example, how would i acess the end of it, would i just put 0x536870912?? or is there another way (or do i have to use hex :-\)

Is there a tutorial on this?? So the memory location after 0x7C00 is 0x7C01, so i just load my ssl to there, and put [ORG 0x7C01] at the top of my ssl, right??

Thanks for your help, I have nearly finished my BootProcess, and i am nearly ready to start PM (Protected Mode) Just another week or so ;D

Ciao ;)
Berserk

Re:Where do i start??

Post by Berserk »

Hey,

Sorry, did some typos and forgot to say somestuff. Of course it's written in hex, what was i thinking :-[

What would happen if i went over the limit, e.g. assumed the machine has 512mb ram, but it only has 128mb, and i tried to use more?? What would happen. And where is the absoloute start of the memory. I want to load the ssl there, is the start 0x0000?? And to acess it do i just write the number in hex?? For example, if i wanted to acess memory location 551318; would i just put 551318 in hex??

Ciao, all the other questions remain. Please help.....
Post Reply