Page 1 of 1
How to execute PE apps in Kernel?
Posted: Fri Nov 29, 2019 11:36 pm
by motosftos
Re: How to execute PE apps in Kernel?
Posted: Sat Nov 30, 2019 2:23 am
by Octocontrabass
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!
Re: How to execute PE apps in Kernel?
Posted: Tue Dec 03, 2019 9:00 pm
by thosakwe
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?
Posted: Mon Dec 16, 2019 8:15 am
by motosftos
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.
Re: How to execute PE apps in Kernel?
Posted: Mon Dec 16, 2019 8:16 am
by motosftos
And sorry, now i migrated to program my OS in assembly.
But it would be helpful if i get assembly code.
Thanks in advance.
Re: How to execute PE apps in Kernel?
Posted: Mon Dec 16, 2019 9:05 am
by iansjack
motosftos wrote:And sorry, now i migrated to program my OS in assembly.
Bad move.
Re: How to execute PE apps in Kernel?
Posted: Mon Dec 16, 2019 11:02 am
by nullplan
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.
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.
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.
Re: How to execute PE apps in Kernel?
Posted: Tue Dec 17, 2019 6:11 am
by motosftos
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.
Re: How to execute PE apps in Kernel?
Posted: Tue Dec 17, 2019 7:25 am
by bzt
Hi,
motosftos wrote:Hello, i am developing an Operating System.
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:I have no idea on the code. Can anyone please help me with the code?
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.)
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
Re: How to execute PE apps in Kernel?
Posted: Tue Dec 17, 2019 7:33 am
by motosftos
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
Re: How to execute PE apps in Kernel?
Posted: Tue Dec 17, 2019 7:44 am
by bzt
motosftos wrote:Can you please refer me any sources to learn that in you tube?
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.
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
Re: How to execute PE apps in Kernel?
Posted: Thu Dec 19, 2019 6:45 am
by motosftos
Thanks
Re: How to execute PE apps in Kernel?
Posted: Thu Dec 19, 2019 10:02 am
by iocoder
This really touched my heart.
This article is a good start.
Re: How to execute PE apps in Kernel?
Posted: Thu Jan 23, 2020 6:26 am
by motosftos
@bzt link is not working
Re: How to execute PE apps in Kernel?
Posted: Thu Jan 23, 2020 10:15 am
by bzt
motosftos wrote:@bzt link is not working
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.
Cheers,
bzt