OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 23, 2024 6:30 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: screen again
PostPosted: Wed Feb 13, 2002 9:05 am 
Help!!

This problem is similar to previous screen one, but the offsets and data seem correct.

The kernel has a simple putchar function that prints a character to the screen,
-this works when "video.putchar('G',0x0900)"
-but now when "char mystring[]="GK";
                     video.putchar(mystring[0],0x0900)"

I'm using VC++ 6 sp5 to compile and link,
bochs with bfe visual debugger to run and debug.
It gets the right value from memory(47 for 'G') and puts it in the right place for the function, but then f**ks it up from there.

The kernel is loaded at 0x0010000 in memory and kernel data to 0x0011000.

The c++ kernel contains a class called video with a function putchar(char c, short color);
it increments the video memory ptr each time a char is printed

the class main creates video and calls putchar with an item of the string array.





below is the asm for the dissasembled kernel - not much;
note:(nop's used to split up code into sections)

PUSH           EBP                                    
MOV            EBP,ESP                                
SUB            ESP,0C                                  
LEA            ECX,DWORD PTR[EBP-08]                  
CALL           0000002E                                
NOP                                                    
MOV            AX,[2000]                              
ADD            DWORD PTR [EAX],EAX                    
MOV            WORD PTR [EBP-0C],AX                    
MOV            CL,BYTE PTR [00012002]                  
MOV            BYTE PTR [EBP-0A],CL                    
MOV            DL,BYTE PTR [EBP-0C]                    
MOV            BYTE PTR [EBP-01],DL                    
PUSH           00000900                                
MOV            AL,BYTE PTR [EBP-01]                    
PUSH           EAX                                    
LEA            ECX,DWORD PTR [EBP-08]  ;right value in right
                                                ;place entering function                
CALL           0000000D                                
NOP                                                    
JMP            0000003A                                
MOV            EAX,ECX                                
MOV            ECX,DWORD PTR [EAX]                    
MOV            WORD PTR [ECX],8002                    
RET                                                    
MOVSX          AX,WORD PTR [ESP+24]                    
ADD            AL,0B                                  
INC            ESP                                    
AND            AL,08                                  
MOV            EDX,DWORD PTR [ECX]                    
MOV            WORD PTR [EDX],AX                      
ADD            DWORD PTR [ECX],02                      
RET            0008  





apologies for the complicated example, if anyone would like more info shout.


Top
  
 
 Post subject: Re: screen again
PostPosted: Wed Feb 13, 2002 1:31 pm 
My suggestion is to not use Visual C++ because it's probably putting your data in the wrong place.

K.J.


Top
  
 
 Post subject: Re: screen again
PostPosted: Thu Feb 14, 2002 6:40 am 
ok, got some of it solved.

this is now working:
vidmem[0] = mystring[0];
vidmem[1]=0x0900;

its just the print to video memory through a function thats not working.
putchar('G'); //works
putchar(mystring[0]); //dosen't work

Its a c++ function could this be anything to do with it.
any ideas?


Top
  
 
 Post subject: Re: screen again
PostPosted: Thu Feb 14, 2002 5:16 pm 
Did you write the putchar function or is it the one included with VC++?

K.J.


Top
  
 
 Post subject: Re: screen again
PostPosted: Sat Feb 16, 2002 3:51 am 
Its just a really simple function that puts a character to 0xb8000 I've got it working now, but have come across another  problem.
When i add a variable unsigned short color to the screen class it stops working. I don't even have to initialise or use the variable, it just stops working.

Is this a result of using c++. What has to be done to safely use C++, i am not using any libs, and do not have any type.h file included.

Should I?


Top
  
 
 Post subject: Re: screen again
PostPosted: Sat Feb 16, 2002 7:33 am 
Its just a really simple function that puts a character to 0xb8000 I've got it working now, but have come across another  problem.

So it's doesn't come with VC++.

When i add a variable unsigned short color to the screen class it stops working. I don't even have to initialise or use the variable, it just stops working.

What exactly do you mean?

Should I?

Should you what?

K.J.


Top
  
 
 Post subject: Re: screen again
PostPosted: Sun Feb 17, 2002 1:41 am 
No it doesn't come with visual c++.

class Screen{
private:
     //unsigned short color;
     unsigned short *vidmem;
public:
     Screen();
     void addChar(char ch);
};

#define SCREEN_START 0xb8000
#define SCREEN_END   0xc0000
#include "screen.h"

Screen::Screen(){
     *vidmem = (unsigned short) 0xb8000;
     //color =  0x0900;
}

void Screen::addChar(char ch){
     //vidmem[0] = (unsigned short) (ch | color);
     vidmem[0] = ch | 0x0900;
     vidmem++;      
}


When i use ANY of the commented out lines the function addChar stops working.

Should I be including type information, like many of the type.h files i see in other peoples code.

Is this a possible result of using C++ or is there something not right in my code.


Top
  
 
 Post subject: Re: screen again
PostPosted: Sun Feb 17, 2002 4:20 am 
OK problem solved, stupid mistake shoud have been
vidmem = (unsigned short*) 0xb8000;

Visual Studio works fine for kernels so far. Got visual studio .net yesterday and it works fine too.

I'm using visual studio, because as a windows user thats what i'm used too. Plus visual studio does provide a better enviroment to develop in than editplus and djgpp. I've tried djgpp and have had problems with it, one being the entry point which you've found a way around with the assembly jump to main.

I've seen lots of posts in the past inquiring about how to use VC++ for kernel dev, so if anyone is interested in how i've got this far just shout or send me a mail or smthng.

A new version of Bochs and BFE has come out recently, it allows you to test your code with breaks points and step through its execution.

The reason I'm telling you this stuff, is because it has helped me, and might be able to help others. So if you wanted you could look into it for your webpage.

DJGPP isn't the only way to go. I'm not a giant MS fan, but I don't beleive all MS is ****, and all Open Source software is great. Its best to use what you find best for the job.

By the way, VC++ .NET is quite good, lots of new **** in there I haven't looked at yet.


Top
  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 92 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group