Page 1 of 1

Transitioning to the Kernel & Writing to a CD

Posted: Wed Aug 11, 2010 1:24 pm
by LoneWolf10190
So, I have a bootloader set up, which handles any possible interrupt errors and hangs the system just before entering protected mode. I have read other posts on this forum about protected mode, and I have also read about 64-bit Long Mode. I have searched an innumerable amount of times for a solution to my dilemmas -- or at least plausible, understandable solutions -- but no luck. Here are my questions:

1.) How do I, from my bootloader program, call a Kernel (which will be implemented in ASM), and execute? Do I change the RIP register to point to the entry point of my Kernel in memory? Additionally, how would I get my Kernel's starting address (like, how would I put it into memory like the bootloader)? Also -- sorry to bombard the OSDev community with this welter of inquiries -- how do I get into Long Mode?
2.) I have searched the web time and time again, yet I find no solution. Back in my days of technological infancy :mrgreen: , I used to toy around with Batch programming, because that was what n00bs liked to call 'hacking.' [-X I had found a CD that had been deemed "great for hacking," so I inserted it into the drive, and rebooted my system like it told me. On start-up, the BIOS ran the CD-ROM and -- :!: WHAT :!: -- Ubuntu is running on my computer?! How in the world do I get a CD to boot up with my bootloader, so I can run it on my laptop? I do not want any Microsoft products to have to be on there; I want this to be a one-system Operating System, like Linux, lol. :)
3.) A very long way away: would it be possible to create a function that verifies an executable before it is executed on the system? I wanted to create a new EXE file format (don't ask :wink: ) and have the function parse the 128-byte header (which would contain the entry point and references to sections) to test the validity, and to gather information. Then, it would call this kind of thing (not actual code):

Code: Select all

ExecProc:
test rax, rax
jz __notvalidPUFF
lea rax, QWORD PTR [proc_addr]
push curr addr
push ...........
push ...........
mov rip, [rax]
; MAYBE I JUST NEED TO CALL THE INSTRUCTION ADDRESS FROM MEMORY??? (sure would make it a lot simpler)
So, any help would be GREATLY appreciated! Help an OSDev n00b like myself, please! [-o<
EDIT: Please correct me if I am wrong on any of this.

Re: Transitioning to the Kernel & Writing to a CD

Posted: Wed Aug 11, 2010 1:55 pm
by Combuster
Hi and welcome to the forums.

Your topic suffers from a problem. The first is equivalent from building a wall from mortars and bricks, the second is equivalent to building a skyscraper. You better use an existing skyscraper if you can't even build your own dog shed.

The second problem is that you sound like a wannabe. You explicitly don't want to use windows, but apparently no such constraint for linux. Apart from that, if you wrote your own bootloader, there's no linux or windows code involved in the final product. And your apparent surprise that you suddenly have a Linux distro running indicates you have little or no clue how systems really work.

Also the fact that you seem to be able to find the Tutorials section on the Wiki makes me believe you either did not use google, or are complete unable to make use of it. Provided that the wiki is well indexed, has a big link on top of the website, and is explicitly mentioned from the rules the search claim is just outrageous.

Bottom line, you want to build a skyscraper and you seem to be unable to make mortar. I expect you got the code (prebuilt?) of a bootloader from somewhere since you apparently lack the assembly skills to do know how to jump to address X.



Anyway, that's what you get from trying to look smart - it makes you look stupid.

I've posted the link to the answers to the problems you seem to be facing right now. I've also posted a link to the required knowledge, if you're at the level you're apparently at, you might want to get a feeling with how systems really work by installing gentoo or the like. Then work up your prograwith something that tests your allround skills - game development. Text based game, 2D game, 3D game. There's some nice sticky threads around this forum dealing with programming skills and everything.

Don't worry, there's a lot you can learn, but trying to learn by doing the big thing first just ends in frustration, on both your and our side.

Re: Transitioning to the Kernel & Writing to a CD

Posted: Wed Aug 11, 2010 2:16 pm
by LoneWolf10190
Hi Combuster,

I appreciate your response, as well as your blatancy and honesty. I do, in fact, know assembly and have the required knowledge. If you would have actually read my post, I had said that "back in my days of technological infancy, I..." OBVIOUSLY, I was referring to an earlier time period; about two years ago, to be specific. IN THAT TIME was when I had no idea what Ubuntu or Linux distros were. I have acquired much knowledge since then. Also, examine my post more attentively and you would see that I did NOT WANT AN OS THAT INCLUDES Windows OR Linux. I wanted to have my own SIMPLE loader for my system.
It is clear to me that you do not skim through posts very thoroughly.
Furthermore, if I had not the ASM skills to create a successful bootloader, why was I able to test it on my desktop's floppy drive and have it function flawlessly? All I was simply asking for was how to load the kernel I would have written into memory, and how to create an image to boot from a CD.
And saying that I'm a "wannabe" is a little much, don't you think? Shall I not speak formally in the forum, or would I not be "trying to sound so smart?" I can t4|k |yK3 7H|5 if it would better soothe your majesty. :roll:
But I'm not going to start a forum war with someone I don't know.
Thank you again for your response, and the links you have provided. Greatly appreciated. :^o

Re: Transitioning to the Kernel & Writing to a CD

Posted: Wed Aug 11, 2010 2:22 pm
by LoneWolf10190
Wait, perhaps my wiki search was too much of a skim.
Thanks for redirecting me there, because I wouldn't have gone back. I now see that there is a 'Bootable CD' tutorial available on the OSDev wiki. :lol:

Re: Transitioning to the Kernel & Writing to a CD

Posted: Sat Aug 14, 2010 11:26 am
by egos
Removed.

Re: Transitioning to the Kernel & Writing to a CD

Posted: Sat Aug 14, 2010 8:56 pm
by roboman
LoneWolf10190 wrote:1.) How do I, from my bootloader program, call a Kernel (which will be implemented in ASM), and execute? Do I change the RIP register to point to the entry point of my Kernel in memory? Additionally, how would I get my Kernel's starting address (like, how would I put it into memory like the bootloader)? Also -- sorry to bombard the OSDev community with this welter of inquiries
http://www.ctyme.com/intr/rb-0607.htm int13/ah=2 or you write something that does what int13/ah=2 does. You then know where your Kernel was loaded to and you jmp or call to that address.
LoneWolf10190 wrote: how do I get into Long Mode?
A few register changes, but the much bigger thing is deciding on and setting up rings, a new int system, paging and probably a few more things I'm not thinking of right now. You probably want to look at several working examples and see the details they decided on and guess at why.
LoneWolf10190 wrote:How in the world do I get a CD to boot up with my bootloader, so I can run it on my laptop? I do not want any Microsoft products to have to be on there; I want this to be a one-system Operating System, like Linux, lol. :)
The way it most often seems to get done is to get a working system booting off a floppy or hdd and then make an image of that floppy or hdd and burn it to the cd with a program that lets you burn bootable images to your cd in emulation mode. If you have noticed, most of the live cd's show up as an A drive or as your C drive and the system thinks they are write protected floppies or hdd's.

Re: Transitioning to the Kernel & Writing to a CD

Posted: Sat Aug 14, 2010 9:20 pm
by TylerH
A simple example of getting to long mode can be found on the Fasm examples page.

IMO, you should make a simple protected mode kernel, with flat segments and legacy paging first. After getting a pretty stable kernel, port it to long mode(most of which will be reimplementing paging to include PAE and PSE).

You change *ip with jmp(or call).