OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Mar 19, 2024 3:58 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 37 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
 Post subject:
PostPosted: Wed Jun 13, 2007 9:13 pm 
Offline
Member
Member
User avatar

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

Zacariaz wrote:
The links doesnt seem to work anymore, would it be possible to optain the code otherwise?


My links at the top of this topic should work again now.

I had a mysterious "htdocs/temp" directory and forgot what it was for, then updated my web site (starting with renaming the "htdocs" directory to "old-htdocs")... ;)


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:
PostPosted: Thu Jun 14, 2007 1:49 am 
Offline
Member
Member
User avatar

Joined: Tue May 22, 2007 2:36 pm
Posts: 1069
wow, thanks.

Ragards


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 02, 2007 11:21 pm 
Offline
Member
Member

Joined: Thu Aug 30, 2007 9:09 pm
Posts: 102
Brendan, your link is down again... this time to your whole site. I was so enthusiastic about seeing it too.

I've almost completely written the code for this myself, but was hoping to see what you had in case I'd buggered anything up. I'd heard somewhere about the work you did to figure this out so I knew it was possible. I currently have a working 32-bit bootloader that I'm branching off of before I start the OS.

My 64b bootloader currently does it in this order:

int 10 cls
int 13 load 7e00-fcff
lgdt
a20
cr3
msr
cr4
cr0
jmp 0x8:start64
idtr

I *think* I only have to:

14) Modify the gdt code segments as per wikipedia's comments on bits 21 and 22.

15) Set up the PD/PT stuff and mask off the current code so it's not in paged memory (since I'm still in the boot sector code)

16) Use [bits 64] starting from start64.

After that I plan to pack in some vesa hooks to get that out of the bios, and perhaps try to get the real value of highmem somehow. My understanding is that both bios int 0x12 and int 0x15 fail to go over 64MB.

That should be all for the bootloader. I promise to share once it's done.

_________________
There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies.
- C. A. R. Hoare


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 05, 2007 1:26 am 
Offline
Member
Member
User avatar

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

Avarok wrote:
Brendan, your link is down again... this time to your whole site. I was so enthusiastic about seeing it too.


My website is mostly offline, and will remain (mostly) offline for a while - I'm redoing my boot code (putting an abstraction layer between the boot code and OS's startup code, so that it can be booted from PC BIOS, LinuxBIOS, EFI, OpenFirmware or directly from ROM without changing any of the OS's startup code). I've also been playing an online game recently, and have been getting more and more annoyed at stupid search engines that ignore my "robots.txt" file and decide to download my entire site (causing huge amounts of lag, usually while I'm trying hard not to get eaten by a dragon or something)... ;)

Avarok wrote:
I've almost completely written the code for this myself, but was hoping to see what you had in case I'd buggered anything up. I'd heard somewhere about the work you did to figure this out so I knew it was possible. I currently have a working 32-bit bootloader that I'm branching off of before I start the OS.


Some general notes...

First, the main idea is to prepare everything in advance (while in real mode) then set both PE and PG in CR0 at the same time (after the MSR's, CR3, etc are setup) to go directly from real mode to long mode. By the look of what you've posted (the list of things your bootloader currently does) you already understand this and are doing well.

Secondly, use something like Bochs for debugging. A black screen while the computer resets isn't much fun, while a full interactive debugger that allows you to step through everything an instruction at a time is much much more useful.

Lastly, when I say "prepare everything in advance (while in real mode)" I really do mean *everything*. My old code was stuck ontop of my old boot code, which was around 100 KB of real mode code that loaded a boot image (containing everything the OS needs after switching to long mode or protected mode), did all the memory detection, setup a default video mode, started other CPUs and obtained CPU capabilities/features/bugs, detected NUMA areas, etc. It even had a full physical memory manager so that page tables, etc could be dynamically allocated.

I guess what I'm trying to say is that the BIOS is (mostly) entirely useless once you switch to long mode, so you need to do all of the BIOS related stuff beforehand. The alternative would be to preserve the BIOS"s state (memory areas, PIC settings, etc) and constantly switch between long mode and real mode (without dropping IRQs, etc) until you're ready, which seems much less sensible to me.

Avarok wrote:
After that I plan to pack in some vesa hooks to get that out of the bios, and perhaps try to get the real value of highmem somehow. My understanding is that both bios int 0x12 and int 0x15 fail to go over 64MB.


Int 0x12 will only tell you the amount of contiguous RAM below the EBDA - never more than 640 KB. Int 0x15 has several different functions for memory detection (at least 6 different functions that may or may not be supported by the BIOS). The best of them is "int 0x15, eax = 0xE820" which will be present/supported on all computers that support long mode, and does report all areas (not just usable RAM) above and below 4 GB. This makes things easy if your OS is "long mode only".


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:
PostPosted: Wed Sep 05, 2007 3:56 am 
Offline
Member
Member

Joined: Thu Aug 30, 2007 9:09 pm
Posts: 102
:? At the moment, I seem to be unable to cross the mov cr0, eax; jmp 0x18:start64; threshold.

I doc'd up my 32-bit boot.asm with a 16 -> 32 -> 64 using the same method as I was for straight 16 -> 64 and it doesn't seem to work either.

I'm pretty certain though that it's something wrong with my paging code. Once I got bochs set up, I'm going to do some more reading.

Off the top, anyone know if you need to:

1) set up paging for *all of memory*
2) set up paging at least in the currently executing code segment
3) just set up 1 PD and 1 PT with 1 entry
4) just set the paging bits and populate cr3 with a pointer to a 0'd out page

some other state?

_________________
There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies.
- C. A. R. Hoare


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 05, 2007 8:29 am 
Offline
Member
Member
User avatar

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

Avarok wrote:
Off the top, anyone know if you need to:

1) set up paging for *all of memory*
2) set up paging at least in the currently executing code segment
3) just set up 1 PD and 1 PT with 1 entry
4) just set the paging bits and populate cr3 with a pointer to a 0'd out page


You don't need to setup paging for all of memory, only for everything you access after enabling paging/long mode.

For testing purposes it's easiest to limit the things you access after enabling paging/long mode by using a "jmp $" like this:
Code:
    mov cr0, eax
    jmp 0x18:start64

    bits 64

start64:
    jmp $

In this case you only need to make sure that the paging structures for these 3 instructions are correct (CR3, the PML4 entry, the PDPT entry, the page directory entry and the page table entry). Also note that for the "mov cr0,eax" this page must be identity mapped (as the CPU will use paging to get the instruction immediately after the "mov cr0,eax").

Avarok wrote:
At the moment, I seem to be unable to cross the mov cr0, eax; jmp 0x18:start64; threshold.


It should be relatively easy to find the problem. Change your code so it's more like this:

Code:
    mov ecx,0               ; <- add this infinite loop
.wait:                        ; <- add this infinite loop
    jecxz .wait                 ; <- add this infinite loop

   mov cr0,eax
   jmp 0x18:start64


Now start (the debugging version of) Bochs, and when it gets to the infinite loop press "control + C" to enter the debugger. Now you can type in "set ecx = 1" to break out of the infinite loop and single step or continue. You can also examine the state of the CPU (e.g. "dump_cpu"), and walk the paging structures like the CPU would - e.g. start by seeing what CR3 contains, then look at the PML4 and make sure it's correct, then look at the page directory pointer table and make sure it's correct, etc (all the way down to the physical page). You can also use this method to manually check the GDT entry (e.g. "info gdt 3" to see what Bochs thinks of the third GDT entry).

Another faster check would be to use "x" (to dump the contents of memory at the specified linear address) and "xp" (to dump the contents of memory at the specified physical address). For an identity mapped page you should get the same data at the same (physical and linear) address.


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:
PostPosted: Tue May 20, 2008 1:55 am 
Offline

Joined: Mon Dec 04, 2006 5:34 pm
Posts: 22
Hi,

I currently use recommended stuff to switch from 16bit to 64bit in my bootloader, and I was interesting in reducing this process.

However the links are down (as said by Avarok), I think it would be a good idea if you could either post that on [http://www.osdev.org/wiki/X86-64#Enabling_Long_Mode_directly the wiki page] or anywhere else so people like me can see how it's done (I get an idea from what was posted here, but I still don't see how that's implemented).


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 20, 2008 7:15 am 
Offline
Member
Member
User avatar

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

MagicalTux wrote:
However the links are down (as said by Avarok), I think it would be a good idea if you could either post that on [http://www.osdev.org/wiki/X86-64#Enabling_Long_Mode_directly the wiki page] or anywhere else so people like me can see how it's done (I get an idea from what was posted here, but I still don't see how that's implemented).


The original server was replaced with something more modern, and since then the only web page on it was an "Under Construction" page.

I've just restored the old "htdocs/temp" directory (from 3 years ago), so the links, etc should work again now.

Note: I didn't originally intend to provide this "temp" directory indefinately.... ;)


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:
PostPosted: Tue May 20, 2008 3:33 pm 
Offline
Member
Member
User avatar

Joined: Wed Feb 07, 2007 1:45 pm
Posts: 1401
Location: Eugene, OR, US
Once the code is safely in the wiki, you won't have to. :wink:

I was also wondering about your old "as safe as can be humanly attained" memory manual probing code. You posted a link or two to it on these forums, too. Are you interested/willing to have that posted permanently in the wiki, too?

(I just rewrote the Memory Detection page in the wiki, so I tried to look at your code, to see if I should include it in that page.)


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 21, 2008 11:39 pm 
Offline
Member
Member
User avatar

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

bewing wrote:
I was also wondering about your old "as safe as can be humanly attained" memory manual probing code. You posted a link or two to it on these forums, too. Are you interested/willing to have that posted permanently in the wiki, too?


Sure - see this post... ;)


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: Switching from real mode to long mode directly..
PostPosted: Mon Jun 30, 2008 7:42 pm 
Offline

Joined: Fri Nov 24, 2006 10:55 pm
Posts: 20
Location: C eh, N eh, D eh
For anyone who's interested, I've written this into a simple bootloader and posted it here, on the wiki. Now we don't have to rely on Brendan's hosting.


Top
 Profile  
 
 Post subject: Re: Switching from real mode to long mode directly..
PostPosted: Sun May 08, 2011 3:02 pm 
Offline

Joined: Wed Feb 16, 2011 6:19 pm
Posts: 11
Hello,

I have some questions that maybe somebody can reply.

Is is possible to return to real mode directly from long mode (to call bios in true real mode ?)
Is paging can be disabled in long mode ? (to use one single segment ?)

Thank you very much

Pierre


Top
 Profile  
 
 Post subject: Re: Switching from real mode to long mode directly..
PostPosted: Sun May 08, 2011 4:10 pm 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
1) It might well work the same way as entering long mode, but there's no precedence that I know of.
2) No. Reading the manuals would also have gotten you this answer.

_________________
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]


Top
 Profile  
 
 Post subject: Re: Switching from real mode to long mode directly..
PostPosted: Sun May 08, 2011 5:12 pm 
Offline

Joined: Wed Feb 16, 2011 6:19 pm
Posts: 11
Thank you very much for your answer.

I'll try to do it, if it works I maybe try to port my OS to 64 bits :D

No I have not read the manual because reading so lot of documentation in english is not easy for me :cry:


Top
 Profile  
 
 Post subject: Re: Switching from real mode to long mode directly..
PostPosted: Mon May 09, 2011 12:23 am 
Offline
Member
Member
User avatar

Joined: Fri Mar 07, 2008 5:36 pm
Posts: 2111
Location: Bucharest, Romania
No, you can only switch to paged protected mode. However, switching to long mode works from both real mode and non-paged protected mode.

_________________
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 37 posts ]  Go to page Previous  1, 2, 3  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 18 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