Page 1 of 1

stuck in the starting!!!

Posted: Mon Sep 30, 2002 7:46 am
by charisma
hi!!!

i am kinda amteur os dev. i jus started my codin some 1 week before. i have a decent knowledge in C and concepts of OS. asm is not my strong point.

i wrote this small hello-world kernel in C, making the kernel to boot with grub . then i tried my hand into writing clrscr() and printf functions. but unfortunately, my system freezes whenever it sees a function in my kernel. i am a bit stuck here. can anybody helpme out of this.

thnx in advance,
Charisma

Re:stuck in the starting!!!

Posted: Mon Sep 30, 2002 7:53 am
by Pype.Clicker
what exactly works/doesn't work ?

Re:stuck in the starting!!!

Posted: Mon Sep 30, 2002 8:23 am
by charisma
if i decalre vram inside the kernel main funtion and then try to write it into vram it works. when i write the same procedure in some other funtion and then call it from the kernel main funtion, its not working.

Re:stuck in the starting!!!

Posted: Tue Oct 01, 2002 1:33 am
by Pype.Clicker
kinda weird ... perhaps something with your stack size or with your arguments ... could you post the working "main" and the buggy "main+proc" function together with a short description of the execution environment (i.e. what segments are used, with their type, base and limit, at which address your code is loaded, etc.)

Re:stuck in the starting!!!

Posted: Tue Oct 01, 2002 1:56 am
by charisma
my program kernel.c with the asm calling program start.asm i am stating here...
the virtual address at which the kernel is loaded is 0xE0000000

-------------------
start.asm
------
;the initializations

   global KernelEntry
   extern tinymain
   extern _kernel_load_addr ;this is 0x00101000

   bits 32
   segment .text

;Multiboot header constants

F_PAGE_ALIGN equ 1<<0
F_MEM_FIELDS equ 1<<1

MAGIC       equ 0x1BADB002
FLAGS       equ F_PAGE_ALIGN | F_MEM_FIELDS
CHECKSUM   equ -(MAGIC + FLAGS)


KernelEntry:
   mov esp, _kernel_load_addr
   push ebx
   call init
   
   align 4
   dd MAGIC      ; Magic
   dd FLAGS      ; Flags
   dd CHECKSUM      ; Checksum



------------------------
kernel.c
----------------------------



#define WHITE_TXT 0x07


unsigned int k_printf(char *, unsigned int);

void init()
{
   char *vidmem = (char *) 0xb8000;
   unsigned int i=0;
   while(i < (80*25*2))
   {
      vidmem=' ';
      i++;
      vidmem=WHITE_TXT;
      i++;
   };//this works
   k_printf("Test",0); //this doesn't work :(
   while(1);
}


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=*message;
         *message++;
         i++;
         vidmem=WHITE_TXT;
         i++;
      };
   };

   return(1);
}

Re:stuck in the starting!!!

Posted: Tue Oct 01, 2002 2:06 am
by Pype.Clicker
hmm .. your stack initialisation routine seems weird to my sense . how do you ensure that it will have physical memory under 0x101000 ?
If there isn't, the CPU will raise a page fault when you have a stack overflow, but you have no PF handler ... and if you had one, you would have no stack to call it ... i guess this is where your triple fault comes from :)

try to have a

Code: Select all

.section bss
stack:
    resd STACK_SIZE
stack_top:

.section code
mov esp, stack_top
that will guarantee you a clean stack

Re:stuck in the starting!!!

Posted: Tue Oct 01, 2002 6:15 am
by Tom
Try loading your kernel at 0x1000 ( if you can, I don't know if grub allows you ) untill you run out of room, so you can learn for awhile and then worrie about the loading thing ;)