screen

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.
mansonbound

screen

Post by mansonbound »

hello,
i have a program loaded to 080000h in realmode
it switches then to pmode. That works fine.
at least i call the _main function, which is written in c (djgpp)

it looks like this:

char * message = "H A L L O ";
int main()
{
....
      movedata(datasel, message, screensel, 0, 10);
}

THE PROBLEM is: movedata works. But the pointer may hold the wrong adress. Cause 5 stupid signs are written to the screen.

When i take
char * message = "H A L L O ";

into the main() function it works!!!!
I know that local variables are on the stack. BUT:

a for(i=0....
causes the pc to hang! (i is declared local!!)
where can the problem be?
K.J.

Re: screen

Post by K.J. »

Could you maybe give some more info on this?

K.J.
mansonbound

Re: screen

Post by mansonbound »

sure....what kind of info?
K.J.

Re: screen

Post by K.J. »

Well, the source to your movedata function might help and all the values that you feed into the movedata function in your code:

movedata(datasel, message, screensel, 0, 10);
what's datasel equal, what's screensel equal, what's the 0 and 10 for?

Also, the commands you use to link your kernel might also help.

K.J.
K.J.

Re: screen

Post by K.J. »

Now that I think about it you're probably using the movedata from string.h(right?). If this is so try:


#include <string.h> // movedata()

#define      LINEAR_SEL      0x08
#define      SYS_DATA_SEL      0x18

int main(void)
{
     const char Msg[] = "h e l l o ";

     movedata(SYS_DATA_SEL, (unsigned)Msg,
           LINEAR_SEL, 0xB8000,
           sizeof(Msg));
     return 0;
};

Please note that I haven't tested the above code but found floating around on the 'net.

Still, please post the commands used to link your kernel, and the rest of your for(i=0.... loop.

K.J.
mansonbound

Re: screen

Post by mansonbound »

1st: movedata works (copied from an older version of this project)

2nd: i dont link against the libc:
ld -o loader.oos -e start --oformat binary -Ttext 0x0 $(OFILES)

where ofiles are the objectcodefiles produced by gcc -c ...

the problem is:
this works:

Code: Select all

int main()
{
        movedata(DATA_SEL, (unsigned)"H A L L O ", SCREEN_DATA_SEL, 0, 10);
        while(1);
}
this dont:

Code: Select all


char *message = "H A L L O ";
int main()
{
movedata(DATA_SEL, message, SCREEN_DATA_SEL, 0, 10);
        while(1);
}
movedata looks like this (altough it cant be the problem):

Code: Select all

/*
ssel...sourcesegment selector
s.......sourceoffset
dsel...destinationsegment selector
d.......destination offset
len.....how many bytes to copy

void movedata(unsigned ssel, unsigned s, unsigned dsel, unsigned d, unsigned len)
{
        asm(
        "pushw %%ds\n"
        "pushw %%ax\n"
        "popw  %%ds\n"
        "pushw %%es\n"
        "pushw %%bx\n"
        "popw  %%es\n"
        "moveloop: \n"
        "lodsb     \n"
        "stosb     \n"
        "loop moveloop\n"
        "popw   %%es\n"
        "popw   %%ds"
        ::"a" (ssel), "b" (dsel), "D" (d), "S" (s), "c" (len));
}
gdt looks like this (descriptor is a makro, that copies all the values into the gdt
1st one: nil
2nd one: kernel codeseg (yet not used)
3rd: kernel data (not used)
then stack, codeseg (for this program), dataseg(for this program (the loader)) and then the screensegment

       descriptor      0,0,0,0,0,0,0
       ;codeseg base 0 limit FFFFF, gran
       descriptor 8, 0FFFFh, 0, 0, 9Ah, 0CFh, 0
       ;dataseg base 0 limit FFFFF, gran
       descriptor 16, 0FFFFh, 0, 0, 092h, 0CFh, 0
       ;stackseg, base 70800h
       descriptor 24, 0F800h, 0800h, 07h, 092h, 040h, 0
       ;codeseg base 0x80000 limit FFFFF, gran
       descriptor 32, 0FFFFh, 0, 08h, 09Ah, 0CFh, 0
       ;dataseg base 0x80000 limit FFFFF, gran
       descriptor 40, 0FFFFh, 0, 08h, 092h, 0CFh, 0
       ;videoseg base 0xB8000 limit 4000
       descriptor 48, 0FA0h, 08000h, 0Bh, 092h, 040h, 0

you see the problem is: why doesnt it work when message is declared globally?
sonneveld

Re: screen

Post by sonneveld »

have you tried:

char message[] = "HALLO";

??

- Nick
K.J.

Re: screen

Post by K.J. »

Yeah, I think that you ought to try what Nick suggests, just change it to:

char message[] = "H A L L O ";

And if that doesn't work then I don't have a clue why it won't work when declared globaly :(. One thing I do suggest though is that if you are wanting to make a printf function then I suggest using something different than movedata.

K.J.
mansonbound

Re: screen

Post by mansonbound »

what else should i use to move datas?
when i change char *messge into message[] ... the pc reboots
also it does not make sense to me:

this c-code:

Code: Select all

char *global1="GLOBAL*";
char global2[]="GLOBAL[]";

int main()
{
        char *local1="LOCAL*";
        char local2[]="LOCAL[]";
}
assembles to:

Code: Select all

      .file      "test.c"
.globl _global1
      .section .text
LC0:
      .ascii "GLOBAL*\0"
      .section .data
      .p2align 2
_global1:
      .long      LC0
.globl _global2
_global2:
      .ascii "GLOBAL[]\0"
      .section .text
LC1:
      .ascii "LOCAL*\0"
LC2:
      .ascii "LOCAL[]\0"
      .p2align 4
.globl _main
_main:
      pushl      %ebp
      movl      %esp, %ebp
      subl      $24, %esp
      andl      $-16, %esp
      movl      $LC1, -4(%ebp)
      movl      LC2, %eax
      movl      LC2+4, %edx
      movl      %eax, -16(%ebp)
      movl      %edx, -12(%ebp)
      movl      %ebp, %esp
      popl      %ebp
      ret
      .ident      "GCC: (GNU) 3.0.3"
it seems that the only difference is that message[] will keep the real name (_message) in asm code.

So i took a look with the hexeditor and found that
H A L L O is contained in the file. I manually changed the sourceoffset in movedata to the offset read in the hexeditor.
And it worked. It also cant be a problem with the dataseg cause local  strings are also in it.
sonneveld

Re: screen

Post by sonneveld »

The only reason why I suggested it was that GCC normally sets constant strings as read only.  Presumably to save memory because you can lump similar strings together. I don't know a lot about compilers or linkers so I don't know which stage it actually does this.  Anyway.. if you set it as an array instead of a pointer, it won't set it as readonly.

I noticed you're using GCC v3.0.3.. have you tried the v2.9xx range?  v3 is pretty recent and some people have had problems with it still.

- Nick
K.J.

Re: screen

Post by K.J. »

What else should you use to move data? Do you mean "what else can I do for a printf type function?" if so then this is what I use, with a little bit of editing you should be able to easily make a printf type function:


main()
{
     char *vidmem = (char *) 0xb8000;
     char message[]="Hello";

     vidmem[0]=message[0];
     vidmem[1]=0x7; // for white on black text
     vidmem[2]=message[1];
     vidmem[3]=0x7;
     vidmem[4]=message[2];
     vidmem[5]=0x7;
     vidmem[6]=message[3];
     vidmem[7]=0x7;
     vidmem[8]=message[4];
     vidmem[9]=0x7;
};


K.J.
mansonbound

Re: screen

Post by mansonbound »

and wheres the difference?...if i move a block of data or every sign for itself?....also movedata is much faster and you can also use uit for other datatransfers.

BUT that is not the PROBLEM.
I tried gcc 2.952 & 2.953 ...it still doesnt work.
K.J.

Re: screen

Post by K.J. »

Does your bootloader set up your DS(data segment) and cs(code segment) properly(or at all)?

K.J.
mansonbound

Re: screen

Post by mansonbound »

the bootsector loads loader.oos (FAT FS) to 08000h:0
loader.oos then starts with

push cs
pop  ds

after switching to pmode:
       mov     ax, datasel
       mov     ds, ax
       mov     es, ax
       mov     fs, ax
       mov     ax, screensel
       mov     gs, ax
       mov     ax, stacksel
       mov     ss, ax
       mov     esp, stacksize
then calls main()
mansonbound

Re: screen

Post by mansonbound »

i can send you the code if want to have a look at it.
Post Reply