Page 1 of 1

no functions in my sys, help

Posted: Sun Oct 21, 2007 2:36 pm
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.

Posted: Sun Oct 21, 2007 3:03 pm
by os64dev
i don't think gcc can do 16 bit code.

Posted: Sun Oct 21, 2007 3:10 pm
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");
} 

Posted: Sun Oct 21, 2007 3:12 pm
by iscalibar
i'am working with DJGPP compiler (gcc for dos), it dos the 16 bit code because the second kernel works normally

Posted: Sun Oct 21, 2007 3:24 pm
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.?

Posted: Sun Oct 21, 2007 3:44 pm
by iscalibar
my entrypoint is os_main

Posted: Sun Oct 21, 2007 3:46 pm
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?)

Posted: Sun Oct 21, 2007 4:59 pm
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.. ;)

Posted: Sun Oct 21, 2007 10:56 pm
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.

Posted: Sun Oct 21, 2007 11:53 pm
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

Posted: Mon Oct 22, 2007 1:35 am
by cg123
I don't suppose you have a stack set up?

Posted: Mon Oct 22, 2007 1:37 am
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"); 
}
?

Posted: Mon Oct 22, 2007 7:05 am
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:

Posted: Mon Oct 22, 2007 4:38 pm
by iscalibar
Thanks you for your help.