Hello, i have a project for developping an operating system, i have create all source files and i compeled them but it dosn't work, why?? please help me .
I use DJGPP compiler and LD linker.
boot.asm:
[BITS 16]
[global start]
[extern _main]
jmp 07c0h:start
msg db "Welcom hateM",0
start:
mov ax, cs
mov ds, ax
mov es, ax
mov ah,02h
mov al,'H'
int 10h
mov ah,02h
mov al,'H'
int 10h
mov ah,02h
mov al,'H'
int 10h
mov ah,02h
mov al,'H'
int 10h
mov si, msg
call printt
xor ax,ax
mov ax,09c0h
mov es,ax
mov bx,0
mov ah,02h
mov al,5
mov ch,0
mov cl,2
mov dh,0
mov dl,0
int 13h
call _main
printt:
lodsb
cmp al,0
je donee
mov ah,0eh
int 10h
jmp printt
donee:
ret
times 510-($-$$) db 0
dw 0xAA55
system.c (kernel):
#include <dos.h>
#define WHITE 0x07;
unsigned int putchh(char x);
int main(void){
int i;
char *str="Je suis Hatem in My OS .";
for(i=0;i<15;i++){
putchh(str);
}
for (;;);
return 0;
}
unsigned int putchh(char x){
union REGS regs;
regs.h.ah=0x2;
regs.h.al=x;
__asm__(
"int $0x10\n"
);
return 1;
}
compile.bat:
nasm -f aout boot.asm -o boot.o
gcc -c system.c -o system.o
ld.exe -Ttext 0x07c0 link.ld -o kernel.bin --oformat binary boot.o system.o
Where is the probleme, why it compiled but don't work?
Why this dosn't work ???
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
First of all, you are trying to build a 16-bit os with a 32-bit compiler. There are several other scary things about your style, but the essence is that you miss one or more keystones in your understanding of the architecture.
I suggest you start working through the Babystep Tutorials and then Bran's Kernel Development Tutorial. After that, I hope you will see what goes wrong with your own code.
I suggest you start working through the Babystep Tutorials and then Bran's Kernel Development Tutorial. After that, I hope you will see what goes wrong with your own code.
Your problem is the "combination" of the regs union and the piece of assembly. These two won't mix and gcc doesn't know that the values in regs union should end in the registers. You have two options:
1.
Use a function (I don't know the name of the function b.t.w.) that handles the regs union and a bios call.
2.
Set the registers using assembly... You may have some trouble with the variable x, but that can be solved this way:
Something like this. For more information, or if this code doesn't compile work (don't blame me, I haven't tested it) I sugest you google for inline assembly in gcc.
Good luck!
1.
Use a function (I don't know the name of the function b.t.w.) that handles the regs union and a bios call.
2.
Set the registers using assembly... You may have some trouble with the variable x, but that can be solved this way:
Code: Select all
asm ("mov $0x02, ah\n"
"mov %0, al\n"
"int $0x10\n"
:
:"=m" (x)
: "%ax");
Good luck!