print string problem and screen mode switching
print string problem and screen mode switching
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.
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.
Re: print string problem and screen mode switching
is
correct?ld --oformat binary -e 0xFF800000 test1.o test.o
-- Stu --
Re: print string problem and screen mode switching
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
BTW, I tried it without -e 0xFF800000 and got the exact same results.
K.J.
K.J.
Re: print string problem and screen mode switching
its wrong unless you have already setup your memory mapping, or you have 4gig physical ram. try loading it to the 1mb mark.
0x1000000
0x1000000
-- Stu --
Re: print string problem and screen mode switching
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.
K.J.
Re: print string problem and screen mode switching
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 --
Re: print string problem and screen mode switching
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.
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.
Re: print string problem and screen mode switching
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.
Re: print string problem and screen mode switching
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.
BTW, could you please post a link to where ELINK can be found?
K.J.
Re: print string problem and screen mode switching
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).
The best linker for os dev(in conjunction with the best linker BCC32 Borland C++ Builder 5.5).
Re: print string problem and screen mode switching
I think that you should contact the author of ELINK for help 'cause I think that this is an issue with ELINK.
K.J.
K.J.
Re: print string problem and screen mode switching
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.
Re: print string problem and screen mode switching
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.
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.