How to execute PE apps in Kernel?
How to execute PE apps in Kernel?
Hello, i am developing an Operating System. Now i want to execute some PE files. I have no idea on the code. Can anyone please help me with the code? I am following OSDEV tutorials. Please help.
-
- Member
- Posts: 5516
- Joined: Mon Mar 25, 2013 7:01 pm
Re: How to execute PE apps in Kernel?
Which part of these steps do you need help with?
Since you're new here, I recommend reading this post to make sure you're familiar with the fundamentals of OS development. Welcome!
Since you're new here, I recommend reading this post to make sure you're familiar with the fundamentals of OS development. Welcome!
Re: How to execute PE apps in Kernel?
Do yourself a favor and start with ELF - much simpler to get a simpler implementation. If you're insistent on PE, though, Microsoft has good docs about the format. Be prepared to use paging to map pages to virtual addresses.
Re: How to execute PE apps in Kernel?
Sorry for late reply....
I have some knowledge on them i read them in Brokenthorn Entertainment and Even in OSdev Wiki, But i donot have idea on code. Please help me in coding it.
I have some knowledge on them i read them in Brokenthorn Entertainment and Even in OSdev Wiki, But i donot have idea on code. Please help me in coding it.
Re: How to execute PE apps in Kernel?
And sorry, now i migrated to program my OS in assembly.
But it would be helpful if i get assembly code.
Thanks in advance.
But it would be helpful if i get assembly code.
Thanks in advance.
Re: How to execute PE apps in Kernel?
Bad move.motosftos wrote:And sorry, now i migrated to program my OS in assembly.
Re: How to execute PE apps in Kernel?
This sounds like the guy who wanted to make a game, and had a good idea, so now he only needs someone to do the artwork, music, sounds, mechanics, and programming for him.motosftos wrote:Sorry for late reply....
I have some knowledge on them i read them in Brokenthorn Entertainment and Even in OSdev Wiki, But i donot have idea on code. Please help me in coding it.
If you have an understanding of the file formats and of your OS, no code is needed, since that would just be a description of how to connect the two. And if you lack understanding of either the file format or your OS, no code can help you fix that.
Executable file formats are mostly about mapping memory and then having the code execute. In order for the code to do anything useful, it needs to talk to your OS. So, in order for this to be important at all, you already need working pmem allocator, paging, vmem allocator, multitasking, FS driver, partition table driver, HDD driver, and this will more than likely include a working interrupt system and DMA allocator. By the time you have all of this, the executable file format should be but a side note.
Also, please be advised that all of this will only work, if you have new executables to run, linked against a libc that works for your OS. Emulating an existing OS's system call interface is going to be difficult at best. I mean, Korona's Managarm is compatible with Linux (no small feat), and ReactOS tries to be compatible with Windows, and that endeavour is still in progress.
Carpe diem!
Re: How to execute PE apps in Kernel?
I migrated to assembly because i don't have much knowledge compared to assembly.
@nullplan, I actually wanted to boot the kernel written in assembly.
I want to boot the kernel from stage2 bootloader.
I used and in Kernel written in assembly i used
but when i compile it with this,:-
ld -melf_i386 -Ttext=0x9000 -nostdlib --nmagic -o stage2.elf stage2.o os.o
i get
boot/stage2.asm:(.text+0xba): undefined reference to `_osstart'
So why i asked it. Please help.
@nullplan, I actually wanted to boot the kernel written in assembly.
I want to boot the kernel from stage2 bootloader.
I used
Code: Select all
extern _osstart
Code: Select all
Global _osstart:
ld -melf_i386 -Ttext=0x9000 -nostdlib --nmagic -o stage2.elf stage2.o os.o
i get
boot/stage2.asm:(.text+0xba): undefined reference to `_osstart'
So why i asked it. Please help.
Re: How to execute PE apps in Kernel?
Hi,
A simple thing that loading the kernel can be divided into many steps:
1. how your initializer code gets loaded by the firmware (first sector? EFI executable? to which address? in which CPU mode?)
2. how can you use the available environment to load a file from disk (can you use interrupts? do you need to load raw sectors or does the firmware provide file abstraction?)
3. how to parse that file (is it a PE or ELF executable at all? does it have more segments? what's phdr and bss?)
4. how to set up the environment for that executable (does it need stack? special mapping? is it position independent?)
5. how to pass control to that executable (what ABI? does it differ to the usual one? Linux kernel for example has a special kernel entry ABI, and GRUB gives you another.)
So many things to figure out and solve, and let me remind you, all of the above is needed and must be 100% correct before the CPU could start executing the first instruction at _osstart: label. And I haven't spoken about how to create that kernel executable (which is different to normal user space applications) before you could save it to disk for your loader to find. And everything I wrote so far are totally independent to in which language your kernel was written in. Could be Assembly, or could be C. I've even seen some (pretty good may I add) kernels written in Pascal.
Cheers,
bzt
Please don't get this the wrong way, but you are clearly not up to the task. Do yourself a favour, and start with some smaller projects first. Do experiments on each component, and when you're okay with them, only then try to put everything together into an OS. And learn. There's extremely huge amount of theory behind OSdev you must be familiar with. It is said that OSdev is the most difficult task a programmer can do, and they say that for a good reason.motosftos wrote:Hello, i am developing an Operating System.
No. You must have at least an idea what you want to do, nobody can help you with that. When the idea is clear, then, and only then you can start coding. These things are not magic, nobody is able to code something without knowing what and how it supposed to do. (And in that I don't mean "load the OS", I mean how it should exactly work to the smallest detail.)motosftos wrote:I have no idea on the code. Can anyone please help me with the code?
A simple thing that loading the kernel can be divided into many steps:
1. how your initializer code gets loaded by the firmware (first sector? EFI executable? to which address? in which CPU mode?)
2. how can you use the available environment to load a file from disk (can you use interrupts? do you need to load raw sectors or does the firmware provide file abstraction?)
3. how to parse that file (is it a PE or ELF executable at all? does it have more segments? what's phdr and bss?)
4. how to set up the environment for that executable (does it need stack? special mapping? is it position independent?)
5. how to pass control to that executable (what ABI? does it differ to the usual one? Linux kernel for example has a special kernel entry ABI, and GRUB gives you another.)
So many things to figure out and solve, and let me remind you, all of the above is needed and must be 100% correct before the CPU could start executing the first instruction at _osstart: label. And I haven't spoken about how to create that kernel executable (which is different to normal user space applications) before you could save it to disk for your loader to find. And everything I wrote so far are totally independent to in which language your kernel was written in. Could be Assembly, or could be C. I've even seen some (pretty good may I add) kernels written in Pascal.
Cheers,
bzt
Last edited by bzt on Tue Dec 17, 2019 7:36 am, edited 1 time in total.
Re: How to execute PE apps in Kernel?
Thanks @bzt.
Can you please refer me any sources to learn that in you tube? i have tried many, but they did not satisfy. I use to read OSdev but if they are visual(video), i can easily understand. -Sorry for bad english
Can you please refer me any sources to learn that in you tube? i have tried many, but they did not satisfy. I use to read OSdev but if they are visual(video), i can easily understand. -Sorry for bad english
Re: How to execute PE apps in Kernel?
I know that it wasn't your intention, but that's actually an insult. OSdev can't be learned from a youtube tutorial. Most of us spent years if not decades to learn the OSdev things, there are countless hours of painful trial-and-error experiments behind us to get the knowledge you seek. No youtube video can give you that.motosftos wrote:Can you please refer me any sources to learn that in you tube?
Start the old-fashioned way: buy a book, read it, try to understand it, then write small programs putting the theory you've learned into practice. Tannenbaum's Modern Operating Systems would be a good start, but there are many other perfect books. When you've understood the theory, and you gained some experience with it in practice, then start downloading and reading hardware specifications. Those are a different kind of beasts, but you also have to learn them and learn how to control them. Most specification is a PDF book. What is common in all quality OSdev materials, neither of them is a youtube video.
A good collection of related books: https://github.com/concerttttt/books/ (Modern Operating Systems included). Also books on C and C++ programming and compiler theory.
Cheers,
bzt
- iocoder
- Member
- Posts: 208
- Joined: Sun Oct 18, 2009 5:47 pm
- Libera.chat IRC: iocoder
- Location: Alexandria, Egypt | Ottawa, Canada
- Contact:
Re: How to execute PE apps in Kernel?
This really touched my heart. This article is a good start.motosftos wrote:Please help.
Re: How to execute PE apps in Kernel?
@bzt link is not working
Re: How to execute PE apps in Kernel?
It was when I wrote that post. That's not my repo, I'm afraid there's not much I can do about it. Use your search skills, that's what I did. I'm sure you can find those books elsewhere too.motosftos wrote:@bzt link is not working
Cheers,
bzt