C++ Bare Bones kmain.cpp Error

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.
jpal
Posts: 3
Joined: Sat Jan 12, 2013 10:35 am

Re: C++ Bare Bones kmain.cpp Error

Post by jpal »

Use this code:
#include <stdint.h>

using namespace std;

extern "C" uint32_t magic;
extern "C" void *mbd;

extern "C" void kmain(void)
{


if ( magic != 0x2BADB002 )
{
/* Something went not according to specs. Print an error */
/* message and halt, but do *not* rely on the multiboot */
/* data structure. */
}

/* You could either use multiboot.h */
/* (http://www.gnu.org/software/grub/manual ... boot_002eh) */
/* or do your offsets yourself. The following is merely an example. */
//char * boot_loader_name =(char*) ((long*)mbd)[16];

/* Print a letter to screen to see everything is working: */
unsigned char *videoram = (unsigned char *) 0xb8000;
videoram[0] = 65; /* character 'A' */
videoram[1] = 0x07; /* light grey (7) on black (0). */
}
User avatar
Griwes
Member
Member
Posts: 374
Joined: Sat Jul 30, 2011 10:07 am
Libera.chat IRC: Griwes
Location: Wrocław/Racibórz, Poland
Contact:

Re: C++ Bare Bones kmain.cpp Error

Post by Griwes »

Code: Select all

using namespace std;
Do you always use code you don't understand? Because presence of this line in your code proves you have no idea what it does.

It's funny how many people in the world put that line in their code without thinking about it or even knowing what it does... well, less funny when problems arise because of this.
Reaver Project :: Repository :: Ohloh project page
<klange> This is a horror story about what happens when you need a hammer and all you have is the skulls of the damned.
<drake1> as long as the lock is read and modified by atomic operations
User avatar
BMW
Member
Member
Posts: 286
Joined: Mon Nov 05, 2012 8:31 pm
Location: New Zealand

Re: C++ Bare Bones kmain.cpp Error

Post by BMW »

cxzuk wrote:I believe the argument is that the wiki should not provide a copy&paste operating system, but provide descriptions of theories, designs and structures.

Whether thats a good goal for the wiki, or if the errorsome code hinders learning of these? Im not sure.
I certainly don't call the bare bones tutorial an "operating system". All it does is print "A" on the screen. If someone wants to copy&paste it, its not much use until they develop it further.

I think the tutorial should definitely work if people follow the instructions. Especially since it is such a simple tutorial. Making a purposeful error in a tutorial will just cause people to post posts saying "The tutorial doesn't work!!!".
Currently developing Lithium OS (LiOS).

Recursive paging saves lives.
"I want to change the world, but they won't give me the source code."
Post Reply