Page 1 of 2
loading and running programs from turbo c++
Posted: Mon Aug 04, 2008 6:05 am
by renovatio
Hello, renovatio is an operating system written in asm and turbo c++. Up to now it has a CLI where you enter a file name and it tells you if it exists or not. Now i would like to load and run programs. Loading is very easy with int 13h. Running is very easy (from assembly) but from turbo c++?
i was thinking to do this:
Code: Select all
// 2000h:0h = the program
void run_prg(void)
{
prepare_segments();
asm {
jmp 2000h:0h //this gives me an error : "Expression syntax". The syntax is wrong but why?
}
}
thanks for helping me...
Re: loading and running programs from turbo c++
Posted: Mon Aug 04, 2008 7:30 am
by codemastersnake
Turboc++ is good for 16 bit real mode OS, But I think you should shift to gcc and ld.
Re: loading and running programs from turbo c++
Posted: Mon Aug 04, 2008 8:55 am
by inflater
Yeah, another helpful answer. "Switch to gcc". Only a "Linus Torvalds slave" aka the fanatic open-source linux developer would say that.
As for the code, try this:
jmp 2000h:0 or
jmp 2000:0 or
jmp far 2000h:0 or
Code: Select all
label kam; (this is a expression from pascal but it should exist something in c++ alike)
jmp dword ptr cs:kam
jmp get_away
kam:
dw 2000h
dw 0
get_away:
If at 0x2000:0 is present a binary-format executable, it should load. If it's EXE, you need to look at the exe specs (or any good boot sector code) to get CS:IP from the exe header.
If you want to return from your program, I suggest replacing the jmp opcode with "call". That way, if you will have your stack alright, you can return from your program and resume execution in your OS.
And people, stop posting your stupid linux propaganda. You're post-hunting and spamming the whole forum.
Regards
inflater
Re: loading and running programs from turbo c++
Posted: Mon Aug 04, 2008 8:59 am
by 01000101
I have never used TurboC++ and it's assembler syntaxes but maybe it dislikes the dual 'h' suffixes in that statement, try the '0x' prefix as an addition to the afore mentioned.
Re: loading and running programs from turbo c++
Posted: Mon Aug 04, 2008 9:02 am
by inflater
I don't think that turbo c++ will accept the prefix "0x" because it's from Borland and e.g. borland pascal (or turbo pascal) didn't like "0x" too. Correct me if I'm wrong with the C++ part.
Re: loading and running programs from turbo c++
Posted: Mon Aug 04, 2008 9:15 am
by renovatio
i tried changing the "0x" and "h" and the different combinations but i didn't work. anyone know the tasm syntax.
Re: loading and running programs from turbo c++
Posted: Mon Aug 04, 2008 9:22 am
by inflater
for "jmp 2000h:0", and
Code: Select all
push cs
push return_here (or push offset return_here)
push 2000h
push 0
retf
return_here:
...
for "call far 2000h:0".
That should do the trick. All what JMP does is: pop the two words off the stack and jump to them. CALL does the same as JMP, but plus, it will put the return CS:IP to the stack. In this method, I've "simulated" the JMP and CALL FAR opcodes.
Hope this helps.
Regards
inflater
Re: loading and running programs from turbo c++
Posted: Mon Aug 04, 2008 10:46 am
by renovatio
i tried all you suggested but it doesn't work... thanks anyway
Re: loading and running programs from turbo c++
Posted: Mon Aug 04, 2008 10:56 am
by inflater
Does the above code compile? Try debugging with bochs debugger: do a loop before the push retf opcodes, then trace the CS:IP if it's really coming to 0x2000:0 and if there is your application. If it comes to 0x2000:0 and it still doesn't work, something is wrong with your code.
Regards
inflater
Re: loading and running programs from turbo c++
Posted: Mon Aug 04, 2008 1:03 pm
by renovatio
Inflater: the compiler tells me the syntax is wrong... but i can't realize why...
Re: loading and running programs from turbo c++
Posted: Mon Aug 04, 2008 1:06 pm
by 01000101
can you post the 'exact' code, without any post-pasted comments.
Re: loading and running programs from turbo c++
Posted: Mon Aug 04, 2008 1:47 pm
by renovatio
yes of course... here is the code... i also wanted to say that the get_addr function, the load_dir, and the load_prg function worked perfectly... my problem is in "jmp 2000h:0h" (error: Expression Syntax). Thanks for helping me...
renova~1.cpp
Code: Select all
#include <screen.h>
#include <keyboa~1.h>
#include <disk.h>
#include <screen.h>
#include <keyboa~1.h>
#include <disk.h>
void main(void)
{
unsigned char file[10];
unsigned char resu;
for (; ; )
{
put_str("? ");
get_str(9, file);
put_str("\n\r");
load_dir();
resu = get_addr(file);
if (resu == 1)
{
load_prg();
asm jmp 2000h:0h
put_str("\n\r");
}
}
}
disk.h
Code: Select all
#include <string.h>
struct file
{
unsigned char name[10];
unsigned char size;
unsigned char sector;
unsigned char track;
unsigned char head;
};
struct file direntries[37];
unsigned char size;
unsigned char sector;
unsigned char track;
unsigned char head;
void load_dir(void)
{
asm {
mov ah, 2h
mov al, 1
lea bx, direntries
mov cl, 1
mov ch, 0
mov dl, 0
mov dh, 0
int 13h
}
}
unsigned char get_addr(unsigned char *file)
{
unsigned char curr;
unsigned char resu;
for (curr = 0; curr < 14; curr++)
{
resu = strcmp(direntries[curr].name, file);
if (resu == 0)
{
size = direntries[curr].size;
sector = direntries[curr].sector;
track = direntries[curr].track;
head = direntries[curr].head;
return 1;
}
}
return 0;
}
void load_prg(void)
{
asm {
mov ah, 2h
mov al, [size]
mov cl, [sector]
mov ch, [track]
mov dl, 0
mov dh, [head]
push es
mov bx, 2000h
mov es, bx
mov bx, 0h
int 13h
pop es
}
}
Re: loading and running programs from turbo c++
Posted: Mon Aug 04, 2008 2:04 pm
by Combuster
for starters, i would put all assembly within curly braces
so instead of
try
then try aforementioned alternatives if that doesn't work. (including those braces!)
Re: loading and running programs from turbo c++
Posted: Mon Aug 04, 2008 2:08 pm
by renovatio
i tried the following:
Code: Select all
asm jmp 2000h:0h
asm {
jmp 2000h:0h
}
jmp 2000h:0
jmp 0x2000:0
jmp 0x2000:0x0
Re: loading and running programs from turbo c++
Posted: Mon Aug 04, 2008 2:32 pm
by Combuster
read again: include those braces