Link to home
Start Free TrialLog in
Avatar of ravipal
ravipal

asked on

TSR Guru needed

I have writen a TSR for DOS that displays the current files is use. This is done by traversing the DOS Systems File Table the pointer to which can be retrieved by an INT 21,34 call.
When the Hot Key is detected I need to build my own Stack for the TSR's local variables and functions. Otherwise it will use the foreground program's Stack and the results would be very unpredictable. I achive this with the following code.
1. _asm
2. {
3.    mov ss_register, ss
4.    mov sp_register, sp
5.    mov ax, offset my_stack[499]
6.    mov sp, ax
7.    mov ax, ds
8.    mov ss, ax
9. {
in line 3 & 4 i save the SS and SP in to my own variables. and in line 5 & 6 I move the SP to the top of my newly built Stack (my_stack). My doubt hear is that my_stack is a global variable. Hence I am actually creating this Stack in the Data Segment.
* Firstly is their any problems in doing this??

As to the size of the Stack I allocated 500 bytes taking into account the following local variables and one function which I am using in the code that uses this Stack.
    struct table_tag {
                        struct table_tag * table_previous;
                        struct table_tag * table_next;
                        long int _far * table_sft;
                        int table_sft_entries;
                     };
    typedef struct table_tag * TABLE_POINTER;
    TABLE_POINTER current_table, previous_table,          first_table;
    char * save_screen;
    char page_entry[21];
    long int _far * current_sft;
    char _far * table_sft_file;
    char _far * video_position;
    int no_of_elements, no_of_pages, page_tag_element,         general_counter,general2_counter;
    int table_sft_counter, key_press, key_scan,         element_counter;
/* and the function */
PaintPicture()
{
    int general_counter, general2_counter;
    char _far * video_position;
* Is 500 bytes adequet for these variables and one function??

I am using MS C ver 7. When I call the TSR through the Hotkey, the routine pops us and works fine. But when I exit the routine I get a runtime error "Stack Overflow" and the foreground program terminates to the DOS prompt. I cannot run any more programs thereafter. The COMMAND interpertor gives "Program too big" even for the simple MEM program. When I compile without Code Optimization and without Stack Probes, the program simply hangs along with the OS.

What is wrong in what I am doing? and how could I solve this problem?
Any help would be much apreciated.
Avatar of scrapdog
scrapdog
Flag of United States of America image

Did you restore the SS and SP to it's original values (in ss_register and sp_register) when the program finishes?
Avatar of ravipal
ravipal

ASKER

Hi scrapdog,

Yes I did restore the SS and SP, with the following code.

    _asm
    {
        mov ss, ss_register
        mov sp, sp_register
    }

Avatar of ravipal

ASKER

One more thing I fogot to mension. In side my routine I am building a Link List to link all the individual DOS System File Tables into one. For this I use the runtime function "maclloc".

Could their be any problem in using this function in side my TSR routine ??
ASKER CERTIFIED SOLUTION
Avatar of laeuchli
laeuchli

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ravipal

ASKER

Hi Scrapdog,

I am still waiting for your response...


Beats me...you probably know more than I do about TSRs!!

I was just checking if you restored SS and SP, because I know if you didn't that would cause problems.