no functions in my sys, help

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
iscalibar
Posts: 7
Joined: Sat Aug 18, 2007 10:58 am

no functions in my sys, help

Post by iscalibar »

Hy, i'am in the begining of developping my own OS, i create a kernel but it dosn't work so explain me what hapen .
This is the kernel:

void hatem(char c);
int os_main(void){
hatem('C');
hatem('C');
hatem('C');
hatem('C');
for (;;);
return 0;
}
void hatem(char c){
asm (".intel_syntax noprefix");
asm("mov al,c");
asm("mov ah,0x0e");
asm("int 0x10");
}

it dosn't work but a kernel without function work normally.
this is a kernel without a function:

int os_main(void){
asm (".intel_syntax noprefix");
asm("mov al,'M'");
asm("mov ah,0x0e");
asm("int 0x10");
asm("mov al,'y'");
asm("mov ah,0x0e");
asm("int 0x10");
asm("mov al,'O'");
asm("mov ah,0x0e");
asm("int 0x10");
asm("mov al,'S'");
asm("mov ah,0x0e");
asm("int 0x10");
for (;;);
return 0;
}
i'am working with gcc complier on windows, help.
User avatar
os64dev
Member
Member
Posts: 553
Joined: Sat Jan 27, 2007 3:21 pm
Location: Best, Netherlands

Post by os64dev »

i don't think gcc can do 16 bit code.
Author of COBOS
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Post by neon »

Hy, i'am in the begining of developping my own OS, i create a kernel but it dosn't work so explain me what hapen .
What doesn't work?

Does it call the function? Does it crash inside of the function? ...Returning from the function? Is the parameter passed to it valid within the function?

Please provide more details. ;)

Also, please use code tags when posting code. It makes your code look alot nicer and preserves formatting:

Code: Select all

void hatem(char c);

int os_main(void) {
   hatem('C');
   hatem('C');
   hatem('C');
   hatem('C');
   for (;;);
   return 0;
}

void hatem(char c) {
   asm (".intel_syntax noprefix");
   asm("mov al,c");
   asm("mov ah,0x0e");
   asm("int 0x10");
} 
Last edited by neon on Sun Oct 21, 2007 3:14 pm, edited 1 time in total.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
iscalibar
Posts: 7
Joined: Sat Aug 18, 2007 10:58 am

Post by iscalibar »

i'am working with DJGPP compiler (gcc for dos), it dos the 16 bit code because the second kernel works normally
User avatar
os64dev
Member
Member
Posts: 553
Joined: Sat Jan 27, 2007 3:21 pm
Location: Best, Netherlands

Post by os64dev »

what is your entrypoint, osmain or a fixed address. If it is the latter then you have to check whether the address is still correct. Otherwise you are not starting osmain but a random piece of code.

Do you have a stack setup, etc.?
Author of COBOS
iscalibar
Posts: 7
Joined: Sat Aug 18, 2007 10:58 am

Post by iscalibar »

my entrypoint is os_main
User avatar
JAAman
Member
Member
Posts: 879
Joined: Wed Oct 27, 2004 11:00 pm
Location: WA

Post by JAAman »

iscalibar wrote:i'am working with DJGPP compiler (gcc for dos), it dos the 16 bit code because the second kernel works normally
first, no, DJGPP cannot produce RMode code (and can produce mostly-correct 16bit PMode code) -- therefore, while it is possible to create a 16bit portion of code that might work, it will break eventually -- your only options are to:

1) (not recommended) switch to a RMode compiler (best DJGPP can do is 16bit PMode code -- and even that isnt completely right) -- but there arent many options here, as most compilers target PMode, because it is more common, and much better to use

2) (highly recommended) switch into PMode, and use a much better development environment, much better performance, and the proper target environment for your compiler (no matter what compiler you use)

[quote
it dos the 16 bit code because the second kernel works normally
[/quote]
that doesnt mean its doing it correctly: GCC (on which DJGPP is based) cannot -- i repeat cannot -- correctly produce 16bit RMode code




as for your problem, it could be because of improper use of the compiler, but it stack is also a very good suspect (did you assign memory for you stack? is it overflowing and trashing something?)
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Post by Brynet-Inc »

Contrary to popular belief, It's possible to create a simple boot program using GCC.. 8)

Code: Select all

[brynet@ttyp2]~/boot: $ cat boot.c
asm(".code16");
asm(".type start, @function");
void start(void) {
        asm("mov $0xe,%ah");
        asm("mov $0x0,%bh");
        asm("mov $0x7,%bl");
        asm("mov $0x41,%al");
        asm("int $0x10");
        for(;;);
}
asm(". = 0x200 - 2");
asm(".word 0xaa55");
[brynet@ttyp2]~/boot: $ gcc -c boot.c -o boot.bin -fomit-frame-pointer
[brynet@ttyp2]~/boot: $ objcopy --output-target=binary boot.bin
[brynet@ttyp2]~/boot: $ objdump --target=binary -m i8086 -D boot.bin
boot.bin:     file format binary

Disassembly of section .data:

00000000 <.data>:
   0:   b4 0e                   mov    $0xe,%ah
   2:   b7 00                   mov    $0x0,%bh
   4:   b3 07                   mov    $0x7,%bl
   6:   b0 41                   mov    $0x41,%al
   8:   cd 10                   int    $0x10
   a:   eb fe                   jmp    0xa
        ...
 1fc:   00 00                   add    %al,(%bx,%si)
 1fe:   55                      push   %bp
 1ff:   aa                      stos   %al,%es:(%di)
[brynet@ttyp2]~/boot: $ ls -lhm *.bin
-rw-r--r--  1 brynet  brynet   512B Oct 21 18:33 boot.bin
[brynet@ttyp2]~/boot: $ file boot.bin
boot.bin: x86 boot sector
[brynet@ttyp2]~/boot: $
It should print the ASCII character 'A' on the screen.. :) - but it's not very practical.. limited as well.. ;)
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Post by Candy »

Brynet-Inc wrote:Contrary to popular belief, It's possible to create a simple boot program using GCC.. 8)

It should print the ASCII character 'A' on the screen.. :) - but it's not very practical.. limited as well.. ;)
You're not leaving the C compiler anything to do - not to mention the littering of your program with asm() statements with assembler commands in them.
User avatar
os64dev
Member
Member
Posts: 553
Joined: Sat Jan 27, 2007 3:21 pm
Location: Best, Netherlands

Post by os64dev »

@brynet-inc
That is exactly what the iscalibar is doing, and therefore it works. It also gives an answer to the problem. At the moment he using functions is fails. If you could try to do that also to verify our thesis. That is is indeed djgpp
Author of COBOS
cg123
Member
Member
Posts: 41
Joined: Wed Sep 27, 2006 2:34 pm

Post by cg123 »

I don't suppose you have a stack set up?
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

Should this

Code: Select all

void hatem(char c){ 
asm (".intel_syntax noprefix"); 
asm("mov al,c"); 
asm("mov ah,0x0e"); 
asm("int 0x10"); 
}
Not be this:

Code: Select all

void hatem(char c){ 
asm (".intel_syntax noprefix"); 
asm("mov al,%0"::"r" (c)); 
asm("mov ah,0x0e"); 
asm("int 0x10"); 
}
?
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Post by Brynet-Inc »

Candy wrote:You're not leaving the C compiler anything to do
Note entirely true.. It's creating an infinite loop *whistles*
Candy wrote:...not to mention the littering of your program with asm() statements with assembler commands in them.
I never said it was pretty... in fact I didn't even think it'd work while I was writing it :lol:
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
iscalibar
Posts: 7
Joined: Sat Aug 18, 2007 10:58 am

Post by iscalibar »

Thanks you for your help.
Post Reply