Wierd all of the sudden

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
steve

Wierd all of the sudden

Post by steve »

This is my first post here, seems like a great site. Anyways, I have a basic kernel that handles interrupts and is starting to use paging. I'm starting to write my free function so i decided to test some things. Here's by main():

Code: Select all

    clear();
              
    interrupts();  
    sti();    
       
    tm=time_init();        
    paging_init();

    printk("startup date: %2d/%2d/%2d\n", tm.day, tm.month,   tm.year);
    printk("startup time: %2d:%2d:%2d\n\n", tm.hour, tm.min, tm.sec);
    
    char *test;
    char *test1;
    
    //printk("Location of `test': %x at initialization\n", test); 
    test = (char *)malloc(sizeof(char));    
    //printk("Location of `test': %x after malloc\n", test);
    test = "Hello World!";
    //printk("Location of `test': %x after assignment\n\n", test);
    //printk("Location of `test1': %x at initialization\n", test1);
    test1 = (char *)malloc(sizeof(char));  
    //printk("Location of `test1': %x after malloc\n", test1);
    test = "I'm Alive\n";
    //printk("Location of `test1': %x after assignment\n\n", test1); 
great, works like that. Now i uncomment the first printk, works, 2nd, works ... anyways when you uncomment the 6th one, bochs goes into spasms and says "load_seg_reg: GDT: SS: index(0015*8+7) > limit(000017)" I know it's not anything to do with the real code because i take that out and it works (I mean still produces the error). I look at my GDT and everything seems to be fine. What could be the problem? Everything worked before i put in the stuff with test and test1.
Curufir

Re:Wierd all of the sudden

Post by Curufir »

Code: Select all

[quote="steve"]
    test = (char *)malloc(sizeof(char));    
    test = "Hello World!";
These lines look kinda odd. You allocate space for 1 char, then use it for a string that's 13 bytes long. Chances are you've trashed your stack somewhere along the line.[/quote]
steve

Re:Wierd all of the sudden

Post by steve »

heh, well i changed it. Still doesn't work though. I even took out the mallocs and it still doesn't. The only way i can get it too work is by commenting out the last printk :-\
distantvoices
Member
Member
Posts: 1600
Joined: Wed Oct 18, 2006 11:59 am
Location: Vienna/Austria
Contact:

Re:Wierd all of the sudden

Post by distantvoices »

maybe your boot loader doesn't fetch all the blocks of your kernel into memory?

Looks like the image is cut off, and then, sweet gosh almighty, hell's stampede is on it's road in paradise.
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
steve

Re:Wierd all of the sudden

Post by steve »

Well there's my problem. My kernel is 9.2 kb, and i was only loading 9 kb of it. Can't believe I did that. Thanks for the help guys.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Wierd all of the sudden

Post by Pype.Clicker »

by the way, doing

Code: Select all

char *test=malloc(13);
test="Hello World";
never copied "hello world" into the freshly-allocated memory in C and it will never do.
Instead, the "test" pointer now points at the constant string and the memory you malloc'ated is now lost (e.g. you can't tell where it is any longer)

Oh, and btw, you should stay away from standard-lib names for your functions ... i rather suggest "kalloc" or "kmalloc" or "kmem_alloc", but "malloc" will simply confuse anyone working with you later :P
steve

Re:Wierd all of the sudden

Post by steve »

Thanks for the tips Pype. I'm now using kalloc, kfree and strcopy for assigning the variables.
Post Reply