Page 1 of 1
Any C++ basic kernel example?
Posted: Tue Jul 24, 2012 8:51 am
by platform
Hey, before writting my kernel, I want to test something. So, I wish somebody would give me a kernel example (written in C++). I only need that this kernel has a basic input/output library, so I could add some commands.
Here, there are a lot of OSdevelopers, there might be a simple open-sourced kernel like the one that I am looking for.
Thanks.
Re: Any C++ basic kernel example?
Posted: Tue Jul 24, 2012 10:04 am
by Nable
Re: Any C++ basic kernel example?
Posted: Tue Jul 24, 2012 10:16 am
by platform
I have read that before, but know I don't want to create a kernel. I only want to test something. When I will have tested that, I will start to create the kernel.
Re: Any C++ basic kernel example?
Posted: Tue Jul 24, 2012 10:19 am
by Nable
Erm.. As for me, the article contains enough code for building some small testing environment.
Re: Any C++ basic kernel example?
Posted: Tue Jul 24, 2012 10:45 am
by platform
Nable wrote:Erm.. As for me, the article contains enough code for building some small testing environment.
I need a little bit more and it has to be faster, because if the test fails, I am going to change my idea of how the kernel should be.
Re: Any C++ basic kernel example?
Posted: Tue Jul 24, 2012 11:09 am
by Tosi
This isn't a place to ask for code.
Either code it yourself, or find some existing implementation and port it.
Writing to screen is exceedingly easy if you stick to the basics.
Remember, if you can do it in C, you can do it in C++ with little to no change to the code.
Re: Any C++ basic kernel example?
Posted: Tue Jul 24, 2012 11:13 am
by platform
Tosi wrote:This isn't a place to ask for code.
Either code it yourself, or find some existing implementation and port it.
Writing to screen is exceedingly easy if you stick to the basics.
Remember, if you can do it in C, you can do it in C++ with little to no change to the code.
Ok, I am going to port my C kernel to C++. Thanks.
Re: Any C++ basic kernel example?
Posted: Tue Jul 24, 2012 11:19 am
by bluemoon
platform wrote:I need a little bit more and it has to be faster, because if the test fails, I am going to change my idea of how the kernel should be.
No, you don't have to implement it to test your idea, you're not writing linux huh?
For complex problem like kernel design, you test your idea by running thru the design documents and diagrams.
Re: Any C++ basic kernel example?
Posted: Tue Jul 24, 2012 11:40 am
by platform
bluemoon wrote:platform wrote:I need a little bit more and it has to be faster, because if the test fails, I am going to change my idea of how the kernel should be.
No, you don't have to implement it to test your idea, you're not writing linux huh?
For complex problem like kernel design, you test your idea by running thru the design documents and diagrams.
It's not the idea what needs to be tested, I only want to test how a c++ program that I have runs in a minimal kernel.
Re: Any C++ basic kernel example?
Posted: Tue Jul 24, 2012 11:55 am
by platform
By the way, I have tested many times the C++ Bare bones and:
loader.s:18: Error: junk at end of line, first unrecognized character is `,'
Can anybody tell me what is the mistake that I have commited?
Re: Any C++ basic kernel example?
Posted: Tue Jul 24, 2012 1:33 pm
by bluemoon
The C++ barebone tutorial is about writing kernel in C++, not about running C++ program with your kernel.
In order to run user-space application (in particular with C++ runtime, and a reasonable set of syscall), the kernel itself already require lots of features.
I consider my kernel a very minimum just to run a C program:
Code: Select all
$ cat testapp/main.c
#include <stdint.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
int main ( int argc, char *argv[] ) {
int pid = (int)getpid();
for (int i=0;i<pid+3;i++) {
printf (" PID[%d]: Hello again! counter=%d\n", pid, i);
usleep((useconds_t) (1000000));
}
return (int)0xBADC0DE0+ (int)pid;
}
SLOC Directory SLOC-by-Language (Sorted)
4958 kernel ansic=2205,asm=1354,cpp=1253,sh=146
679 boot asm=679
430 drivers ansic=288,sh=142
338 libgloss asm=226,sh=112
143 mkinitrd cpp=143
124 testapp sh=112,ansic=12
92 mkdiskimage cpp=92
This requires over 5000 lines of code, which is comparable to the scale of a 3D engine with scene management and particle dynamics.
If you are having trouble building the barebone, I very doubt looking into codebase of such amount would provide any reasonable insight.
A more productive way is that you go thru the tutorials and ask questions.
platform wrote:By the way, I have tested many times the C++ Bare bones and:
loader.s:18: Error: junk at end of line, first unrecognized character is `,'
I copy&paste the code and it assemble without error, have you verify that your browser do not insert junk when copy&paste?
Try type it by hand, you are not suggested to copy&paste anyway.
(Hint: check loader.s line 18 to see any hidden character, then delete the whole line and type it by hand)
Re: Any C++ basic kernel example?
Posted: Tue Jul 24, 2012 4:43 pm
by platform
bluemoon wrote:The C++ barebone tutorial is about writing kernel in C++, not about running C++ program with your kernel.
In order to run user-space application (in particular with C++ runtime, and a reasonable set of syscall), the kernel itself already require lots of features.
I consider my kernel a very minimum just to run a C program:
Code: Select all
$ cat testapp/main.c
#include <stdint.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
int main ( int argc, char *argv[] ) {
int pid = (int)getpid();
for (int i=0;i<pid+3;i++) {
printf (" PID[%d]: Hello again! counter=%d\n", pid, i);
usleep((useconds_t) (1000000));
}
return (int)0xBADC0DE0+ (int)pid;
}
SLOC Directory SLOC-by-Language (Sorted)
4958 kernel ansic=2205,asm=1354,cpp=1253,sh=146
679 boot asm=679
430 drivers ansic=288,sh=142
338 libgloss asm=226,sh=112
143 mkinitrd cpp=143
124 testapp sh=112,ansic=12
92 mkdiskimage cpp=92
This requires over 5000 lines of code, which is comparable to the scale of a 3D engine with scene management and particle dynamics.
If you are having trouble building the barebone, I very doubt looking into codebase of such amount would provide any reasonable insight.
A more productive way is that you go thru the tutorials and ask questions.
platform wrote:By the way, I have tested many times the C++ Bare bones and:
loader.s:18: Error: junk at end of line, first unrecognized character is `,'
I copy&paste the code and it assemble without error, have you verify that your browser do not insert junk when copy&paste?
Try type it by hand, you are not suggested to copy&paste anyway.
(Hint: check loader.s line 18 to see any hidden character, then delete the whole line and type it by hand)
First of all, thanks, but I think that the error is not a typing error. I have typed the loader.s code three times, I have copied and pasted to (two times), I have looked for hidden characters and not, that can't be the problem, as far as I'am concerned.
I have read the loader.s code of the C Bare Bones (not C++), and I get the same error. In that article the author said:
"I get Error: junk at end of line, first unrecognized character is ',' ...
Chances are the GNU as you use is not targeted at ELF - it chokes on the .comm stack, STACKSIZE, 32 line, as three arguments to .comm are only supported for ELF targets. Try setting up a GCC Cross-Compiler."
So, have I to set up a GCC Cross-Compiler? I thought that I have installed a lot of packages which let me compile in "32 bit mode" on a 64 system... But well, I have read the article and it says that there is a Debian package to set up that, but when I type "apt-get update" my system can't find that package... (yes, I have added it to the sources list...).
I sincerely don't understand anything... I have a 32 bit Ubuntu in a virtual machine... And when I try to assembly the loader.s on it, the error is the same! Then the error hasn't relation with the architecture, has it?
So, what I am supposed to do? That means that you, user "bluemoon", has reason and I have typed badly the code?
Thanks.
Re: Any C++ basic kernel example?
Posted: Wed Jul 25, 2012 1:43 am
by bluemoon
There is an article on wiki that guide you build a gcc cross compiler from source. IMO cross compiler, while not strictly required, put you on the same environment with many genius on this forum, and easier to get helped.
platform wrote:So, what I am supposed to do? That means that you, user "bluemoon", has reason and I have typed badly the code?
Note that I can only point to possible suspect of the cause. If you verified there was no typo then the issue should be elsewhere. Troubleshooting is a trial&error task.
Re: Any C++ basic kernel example?
Posted: Wed Jul 25, 2012 3:08 am
by Tosi
If I recall correctly I had problems with the GCC that came with Ubuntu (both the x86 and x86_64 versions).
In this case, you really should build a cross compiler.
Re: Any C++ basic kernel example?
Posted: Wed Jul 25, 2012 12:31 pm
by rdos
You can use the C++ classlibrary of RDOS. If you are going to write a Java script implementation on top of some OS you cannot use the tutorial as it doesn't have the support you require. An alternative is to use Linux and write the Javascript code as a replacement for command-line, and then bundle them much like Android does.