Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8171427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:27:28+00:00 2026-06-06T21:27:28+00:00

I am trying to make a simple kernel using C. Everything loads and works

  • 0

I am trying to make a simple kernel using C. Everything loads and works fine, and I can access the video memory and display characters, but when i try to implement a simple puts function for some reason it doesn’t work. I’ve tried my own code and other’s. Also, when I try to use a variable which is declared outside a function it doesn’t seem to work. This is my own code:

#define PUTCH(C, X) pos = putc(C, X, pos)
#define PUTSTR(C, X) pos = puts(C, X, pos)

int putc(char c, char color, int spos) {
    volatile char *vidmem = (volatile char*)(0xB8000);
    if (c == '\n') {
        spos += (160-(spos % 160));
    } else {
        vidmem[spos] = c;
        vidmem[spos+1] = color;
        spos += 2;
    }
    return spos;
}
int puts(char* str, char color, int spos) {
    while (*str != '\0') {
        spos = putc(*str, color, spos);
        str++;
    }
    return spos;
}
int kmain(void) {
    int pos = 0;
    PUTSTR("Hello, world!", 6);
    return 0;
}

The spos (starting position) stuff is because I can’t make a global position variable. putc works fine, but puts doesn’t. I also tried this:

unsigned int k_printf(char *message, unsigned int line) // the message and then the line #
{
    char *vidmem = (char *) 0xb8000;
    unsigned int i=0;

    i=(line*80*2);

    while(*message!=0)
    {
        if(*message=='\n') // check for a new line
        {
            line++;
            i=(line*80*2);
            *message++;
        } else {
            vidmem[i]=*message;
            *message++;
            i++;
            vidmem[i]=7;
            i++;
        };
    };

    return(1);
};

int kmain(void) {
    k_printf("Hello, world!", 0);
    return 0;
}

Why doesn’t this work? I tried using my puts implementation with my native GCC (without the color and spos data and using printf("%c")) and it worked fine.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T21:27:29+00:00Added an answer on June 6, 2026 at 9:27 pm

    Since you’re having an issue with global variables in general, the problem most likely has to-do with where the linker is placing your “Hello World” string literal in memory. This is due to the fact that string literals are typically stored in a read-only portion of global memory by the linker … You have not detailed exactly how you are compiling and linking your kernel, so I would attempt something like the following and see if that works:

    int kmain(void) 
    {
        char array[] = "Hello World\n";
        int pos = 0;
        puts(array, 0, pos);
        return 0;
    }
    

    This will allocate the character array on the stack rather than global memory, and avoid any issues with where the linker decides to place global variables.

    In general, when creating a simple kernel, you want to compile and link it as a flat binary with no dependencies on external OS libraries. If you’re working with a multiboot compliant boot-loader like GRUB, you may want to look at the bare-bones sample code from the multiboot specification pages.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a simple video chat using Flex framework and red5 server.
I'm trying to make simple script using jquery $post function to pass data to
I'm trying to make a simple Jabber client using the libstrophe library. It's going
I'm trying to make simple many-to-one association, using NHibernate.. I have class Recruit with
Trying to make a simple toggle menu, and I can't seem to hide/show the
Trying to make a simple client that consumes a web service using RemObjects SDK,
im currently trying to make a simple IRC Gui Client. Im using the SmartIrc4net
Iam trying to make a simple ordering using objectify and GAE. Unfortunatly it does't
I'm trying to compile a simple hello world kernel module but after the make
I'm trying to make simple http server, that can be pause and resume,, I've

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.