Any C++ basic kernel example?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
platform
Member
Member
Posts: 32
Joined: Thu Jul 19, 2012 4:38 pm

Any C++ basic kernel example?

Post 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.
Nable
Member
Member
Posts: 453
Joined: Tue Nov 08, 2011 11:35 am

Re: Any C++ basic kernel example?

Post by Nable »

You won't believe but read http://wiki.osdev.org/C%2B%2B_Bare_Bones
platform
Member
Member
Posts: 32
Joined: Thu Jul 19, 2012 4:38 pm

Re: Any C++ basic kernel example?

Post by platform »

Nable wrote:You won't believe but read http://wiki.osdev.org/C%2B%2B_Bare_Bones
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.
Nable
Member
Member
Posts: 453
Joined: Tue Nov 08, 2011 11:35 am

Re: Any C++ basic kernel example?

Post by Nable »

Erm.. As for me, the article contains enough code for building some small testing environment.
platform
Member
Member
Posts: 32
Joined: Thu Jul 19, 2012 4:38 pm

Re: Any C++ basic kernel example?

Post 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.
Tosi
Member
Member
Posts: 255
Joined: Tue Jun 15, 2010 9:27 am
Location: Flyover State, United States
Contact:

Re: Any C++ basic kernel example?

Post 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.
platform
Member
Member
Posts: 32
Joined: Thu Jul 19, 2012 4:38 pm

Re: Any C++ basic kernel example?

Post 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.
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Any C++ basic kernel example?

Post 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? :lol:
For complex problem like kernel design, you test your idea by running thru the design documents and diagrams.
platform
Member
Member
Posts: 32
Joined: Thu Jul 19, 2012 4:38 pm

Re: Any C++ basic kernel example?

Post 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? :lol:
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.
platform
Member
Member
Posts: 32
Joined: Thu Jul 19, 2012 4:38 pm

Re: Any C++ basic kernel example?

Post 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?
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Any C++ basic kernel example?

Post 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)
platform
Member
Member
Posts: 32
Joined: Thu Jul 19, 2012 4:38 pm

Re: Any C++ basic kernel example?

Post 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.
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Any C++ basic kernel example?

Post 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.
Tosi
Member
Member
Posts: 255
Joined: Tue Jun 15, 2010 9:27 am
Location: Flyover State, United States
Contact:

Re: Any C++ basic kernel example?

Post 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.
rdos
Member
Member
Posts: 3307
Joined: Wed Oct 01, 2008 1:55 pm

Re: Any C++ basic kernel example?

Post 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.
Post Reply