newbie needs help with c kernel
Posted: Fri Sep 27, 2002 11:22 am
Hi I am a newbie at os development and my c kernel wount boot, it only freezes.
c kernel
----------
#define WHITE 0x07
void clrscr();
unsigned int printf(char *text,unsigned int ln);
int _start() {
clrscr();
printf("test\nOS test",0);
return 0;
}
void clrscr()
{
char *video = (char *)0xb8000;
unsigned int nr = 0;
while (nr< (80*25*2))
{
video[nr]=' ';
nr++;
video[nr]= WHITE;
nr++;
};
};
unsigned int printf(char *text,unsigned int ln)
{
char *video = (char *)0xb8000;
unsigned int nr = 0;
nr = (ln*80*2);
while(*text!=0)
{
if(*text=='\n')
{
ln++;
nr= (ln*80*2);
*text++;
}
else
{
video[nr]=*text;
*text++;
nr++;
video[nr]= WHITE;
nr++;
};
};
return(1);
};
boot.asm (form bootf02)
------------
jmp 07C0h:start ; Goto start
;_______________________________________
; Here is where the boot program starts.
start:
; Update the segment registers
mov ax, cs ; Copy cs into ax
mov ds, ax ; cs->ax->ds
mov es, ax ; cs->ax->es
jmp Running ; Go to the running part of the bootsector
;____________________________________________
; This is where the boot program runs.
Running:
; Load the second stage loader.
reset: ; Reset the floppy drive
mov ax, 0 ;
mov dl, 0 ; Drive=0 (=A)
int 13h ;
jc reset
read:
mov ax, 1000h ; ES:BX = 1000:0000
mov es, ax ;
mov bx, 0 ;
mov ah, 2 ; Load disk data to ES:BX
mov al, 5 ; Load 5 sectors
mov ch, 0 ; Cylinder=0
mov cl, 2 ; Sector=2
mov dh, 0 ; Head=0
mov dl, 0 ; Drive=0
int 13h ; Read!
jc read
cli ; Stop BIOS interrups - because PMode can't use them in this manner
; Set Protected Mode ( PMode )
mov eax, CR0
or eax, 0x1
mov CR0, eax
; Start A20
.1: in al, 0x64
test al, 2
jnz .1
mov al, 0xD1
out 0x64, al
.2: in al, 0x64
and ax, byte 2
jnz .2
mov al, 0xDF
out 0x60, al
; PMode needs a jmp, so here it is
jmp pmode
;____________________________________________
; We are in protected mode here:
[bits 32]
pmode:
; jmp 1000h:0000 ; Jump to the C kernel
; This part makes sure the bootsector is 512 bytes.
times 510-($-$$) db 0
dw 0xAA55
; End of boot.asm
;____________________________________________
compiled as followed
--------------------------
nasm -f bin -o boot.bin boot.asm
gcc -c kernel.c -o kernel.o
ld -Ttext=0x100000 -o kernel.bin kernel.o -e 0x0
objcopy -R .note -R .comment -S -O binary kernel kernel.bin
PARTCOPY boot.bin 0 3 -f0 0
PARTCOPY boot.bin 3E 1C2 -f0 3E
c kernel
----------
#define WHITE 0x07
void clrscr();
unsigned int printf(char *text,unsigned int ln);
int _start() {
clrscr();
printf("test\nOS test",0);
return 0;
}
void clrscr()
{
char *video = (char *)0xb8000;
unsigned int nr = 0;
while (nr< (80*25*2))
{
video[nr]=' ';
nr++;
video[nr]= WHITE;
nr++;
};
};
unsigned int printf(char *text,unsigned int ln)
{
char *video = (char *)0xb8000;
unsigned int nr = 0;
nr = (ln*80*2);
while(*text!=0)
{
if(*text=='\n')
{
ln++;
nr= (ln*80*2);
*text++;
}
else
{
video[nr]=*text;
*text++;
nr++;
video[nr]= WHITE;
nr++;
};
};
return(1);
};
boot.asm (form bootf02)
------------
jmp 07C0h:start ; Goto start
;_______________________________________
; Here is where the boot program starts.
start:
; Update the segment registers
mov ax, cs ; Copy cs into ax
mov ds, ax ; cs->ax->ds
mov es, ax ; cs->ax->es
jmp Running ; Go to the running part of the bootsector
;____________________________________________
; This is where the boot program runs.
Running:
; Load the second stage loader.
reset: ; Reset the floppy drive
mov ax, 0 ;
mov dl, 0 ; Drive=0 (=A)
int 13h ;
jc reset
read:
mov ax, 1000h ; ES:BX = 1000:0000
mov es, ax ;
mov bx, 0 ;
mov ah, 2 ; Load disk data to ES:BX
mov al, 5 ; Load 5 sectors
mov ch, 0 ; Cylinder=0
mov cl, 2 ; Sector=2
mov dh, 0 ; Head=0
mov dl, 0 ; Drive=0
int 13h ; Read!
jc read
cli ; Stop BIOS interrups - because PMode can't use them in this manner
; Set Protected Mode ( PMode )
mov eax, CR0
or eax, 0x1
mov CR0, eax
; Start A20
.1: in al, 0x64
test al, 2
jnz .1
mov al, 0xD1
out 0x64, al
.2: in al, 0x64
and ax, byte 2
jnz .2
mov al, 0xDF
out 0x60, al
; PMode needs a jmp, so here it is
jmp pmode
;____________________________________________
; We are in protected mode here:
[bits 32]
pmode:
; jmp 1000h:0000 ; Jump to the C kernel
; This part makes sure the bootsector is 512 bytes.
times 510-($-$$) db 0
dw 0xAA55
; End of boot.asm
;____________________________________________
compiled as followed
--------------------------
nasm -f bin -o boot.bin boot.asm
gcc -c kernel.c -o kernel.o
ld -Ttext=0x100000 -o kernel.bin kernel.o -e 0x0
objcopy -R .note -R .comment -S -O binary kernel kernel.bin
PARTCOPY boot.bin 0 3 -f0 0
PARTCOPY boot.bin 3E 1C2 -f0 3E