print string problem and screen mode switching

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
K.J.

print string problem and screen mode switching

Post by K.J. »

Okay, I've got two questions:
1.  I'm using NASM, DJGPP, LD, and John Fine's bootf02.zip bootsector and I can't get my C code to print a string on the screen. Below I have listed my C and ASM code along with the commands I use to compile and link them together.

// start of test.c
go()
{
 char mystring[] = "Hi OS";
 char *vidmem = (char *) 0xb8000;
     
 // displays 'This works' onscreen
 vidmem[0]='T';
 vidmem[1]=0x7;
 vidmem[2]='h';
 vidmem[3]=0x7;
 vidmem[4]='i';
 vidmem[5]=0x7;
 vidmem[6]='s';
 vidmem[7]=0x7;
 vidmem[8]=' ';
 vidmem[9]=0x7;
 vidmem[10]='w';
 vidmem[11]=0x7;
 vidmem[12]='o';
 vidmem[13]=0x7;
 vidmem[14]='r';
 vidmem[15]=0x7;
 vidmem[16]='k';
 vidmem[17]=0x7;
 vidmem[18]='s';
 vidmem[19]=0x7;

 // supposed to show 'Hi OS' but instead
 // shows '@@@@@'
 vidmem[20]=mystring[0];
 vidmem[21]=0x7;      
 vidmem[22]=mystring[1];
 vidmem[23]=0x7;
 vidmem[24]=mystring[2];
 vidmem[25]=0x7;
 vidmem[26]=mystring[3];
 vidmem[27]=0x7;
 vidmem[28]=mystring[4];
 vidmem[29]=0x7;
};
// end of test.c

; start of test.asm
[BITS 32]

[extern _go] ; this is in test.c

start:
 call _go ; call go from test.c

 jmp $
; end of test.asm

The commands I use to compile and link my code are:
gcc -c test.c -o test.o
nasmw -f coff test.asm -o test1.o
ld --oformat binary -e 0xFF800000 test1.o test.o


2.  My second question is how do I switch screen modes will in PMode? I know that in real mode I can use interrupt 10h, but it's a bios function so it doesn't work in PMode(at least I can't get it to), only real mode.

Thanks in advace,
K.J.
User avatar
df
Member
Member
Posts: 1076
Joined: Fri Oct 22, 2004 11:00 pm
Contact:

Re: print string problem and screen mode switching

Post by df »

is
ld --oformat binary -e 0xFF800000 test1.o test.o
correct?
-- Stu --
K.J.

Re: print string problem and screen mode switching

Post by K.J. »

That's what I use. The -e 0xFF800000 sets the entry address at FF800000 Hex because in the ASM example kernel(in bootf02.zip), the first line is, ORG 0xFF800000 because that's where the kernel is loaded in memory(is this right?). The --oformat binary outputs a binary file. After linking I rename the a.out(that's just what LD names it, it's not in aout format though) file to kernel.bin and copy it to my floppy.

K.J.
K.J.

Re: print string problem and screen mode switching

Post by K.J. »

BTW, I tried it without -e 0xFF800000 and got the exact same results. :(

K.J.
User avatar
df
Member
Member
Posts: 1076
Joined: Fri Oct 22, 2004 11:00 pm
Contact:

Re: print string problem and screen mode switching

Post by df »

its wrong unless you have already setup your memory mapping, or you have 4gig physical ram. try loading it to the 1mb mark.
0x1000000
-- Stu --
K.J.

Re: print string problem and screen mode switching

Post by K.J. »

Well, I tried -e 0x1000000 and got the same results :(, then I left out the -e whatever and instead tried -Ttext 0x100000. That just plain didn't work. My guess is that maybe I need to do something like -Tdata whatever but I think if I set that to 0x100000 that my data would come before my code, but I'm not sure. If someone could maybe just post a link or code for a simple kernel that reads a string and displays it, that might help(just no jloc please).

K.J.
User avatar
df
Member
Member
Posts: 1076
Joined: Fri Oct 22, 2004 11:00 pm
Contact:

Re: print string problem and screen mode switching

Post by df »

err... in your asm did you set up your GDT properly? then set your cs/ds/es/ss ?? coz yeah i gather your DS is out and not porinting to the correct place.
-- Stu --
K.J.

Re: print string problem and screen mode switching

Post by K.J. »

Well, I finaly fixed my kernel problem. I did so by using a linker script like this

OUTPUT_FORMAT("binary")
ENTRY(start)
SECTIONS
{
 .text 0xFF800000
 {
   *(.text)
 }
 .data
 {
   *(.data)
 }
 .bss
 {
   *(.bss)
 }
}

Know my kernel works like it should.
Thanks DF for the help :).

K.J.
dorip

Re: print string problem and screen mode switching

Post by dorip »

Yes, the same thig happens to me: the this works method works but the hi os method doesn't. I can't use a linker script because I use objs and ELINK, but what difference does that linker script make? What is the difference so I can apply it in the code.
K.J.

Re: print string problem and screen mode switching

Post by K.J. »

Well, I found that the defualt linker script set up a bunch of space between the text and data sections.

BTW, could you please post a link to where ELINK can be found?

K.J.
dorip

Re: print string problem and screen mode switching

Post by dorip »

http://users.rcn.com/eaj.pizzi/utils/
The best linker for os dev(in conjunction with the best linker BCC32 Borland C++ Builder 5.5).
dorip

Re: print string problem and screen mode switching

Post by dorip »

Hello, I need help.
K.J.

Re: print string problem and screen mode switching

Post by K.J. »

I think that you should contact the author of ELINK for help 'cause I think that this is an issue with ELINK.

K.J.
dorip

Re: print string problem and screen mode switching

Post by dorip »

What difference did the new script make. I'll try to modify the source of elink myself if you can tell me what you did with the script.
K.J.

Re: print string problem and screen mode switching

Post by K.J. »

Well here's the original script:

OUTPUT_FORMAT("coff-go32")
ENTRY(start)
SECTIONS
{
 .text  0x1000+SIZEOF_HEADERS : {
   *(.text)
   *(.gnu.linkonce.t*)
   *(.gnu.linkonce.r*)
   etext  =  . ; _etext = .;
   . = ALIGN(0x200);
 }
 .data  ALIGN(0x200) : {
   djgpp_first_ctor = . ;
   *(.ctor)
   djgpp_last_ctor = . ;
   djgpp_first_dtor = . ;
   *(.dtor)
   djgpp_last_dtor = . ;
   *(.data)
   *(.gnu.linkonce.d*)
   *(.gcc_exc*)
   ___EH_FRAME_BEGIN__ = . ;
   *(.eh_fram*)
   ___EH_FRAME_END__ = . ;
   LONG(0)
    edata  =  . ; _edata = .;
    . = ALIGN(0x200);
 }
 .bss  SIZEOF(.data) + ADDR(.data) :
 {                              
   _object.2 = . ;
   . += 24 ;
   *(.bss)
   *(COMMON)
    end = . ; _end = .;
    . = ALIGN(0x200);
 }
}


And I changed it to this:

OUTPUT_FORMAT("binary")
ENTRY(start)
SECTIONS
{
 .text  0xFF800000 : {
   *(.text)
 }
 .data  : {
   *(.data)
 }
 .bss  :
 {                              
   *(.bss)
 }
}


You'll have to change the 0xFF800000 to whereever your kernel is loaded into memory.

K.J.
Post Reply