I get reboots just after "or al, 1 / mov cr0, eax"
Posted: Sun Jul 18, 2004 11:00 pm
Hi, guys! I'm so glad that I found this site! I think it'll be my home and I get a lot of good friends here that like to code.
I develop OS. I write code using only nasm and test it under bochs. Generally, I love Unix and have one OS on my PC - FreeBSD - multimedia, internet, excellent environment for development - that's all I need! So, I know that obviosly I can't even complete 1/1000 of any modern usable OS code before I die. Thus I'm not going to reinvent a bicycle, I'm just _trying_ to make a little mobile OS that boots from a floppy (hdd expected in future, I've got no docs on it yet). My OS doesn't use BIOS at all, it does all things itself (sure, boot sector loading is a bios job). What force that forwards me? I don't know. Maybe it's a feeling of myself like of creator of something strong and almost alive virtual creature? This magic when you hear the floppy drive snore and imagine how you've coded this via ports... And imagination of enormous complicated CPU engine working you commands... But for all... I feel that computer _eats_ my health - that's reality truth. One should choose between body health and deep computer life.
Well. Thanks if you read that. It's my first message here.
The problem.
I have monolithic kernel written straight from very first floppy sector.
When BIOS loads this sector I load the rest of kernel image and switch CPU to very lazy PM.
After it I jump (not me as a people, you know) to kernel's entry point and tune PM to more complicated mode so that continue initialization.
I tested my OS on some i386, i486, i586 - works fine. But on some Celerons and PIV I get immediate reboots after setting PE bit and before any instruction the far jmp is points to. (I figured it out by setting control points - endless loops.) On some i686 all things go right. I was surprised when my OS started on PIV with 266MHz memory bus speed! Things are very hard for me because at my computer (PIII Celeron/Coppermine 900MHz) I can't catch the problem - I have no reboots.
Please help me to solve this. Here is fragment of my OS that reflects the problem. Compile it and write image to 1.44 floppy. Boot from it and you'll see if your computer reboots or not. If not then you not encounter the problem that other computers do. I stuck with this problem and it hurts me a lot. We all know here how hard the programming is. So, guys, I need your support and I promise to support others here.
;-------------------------------------------------------------
; Compile: %nasm thisfile.asm -o fd
; Insert a floppy
; Write (as root): #dd if=fd of=/dev/fd0
org 0x7C00 ; Expecting to be loaded at 7C00 by BIOS
bits 16
real:
cli
xor ax, ax
mov ss, ax
mov sp, 0x7C00 ; Temp stack just under myself
call real_open_A20 ; For 32 bit address space
call real_init_gdt ; Load GDTR
mov eax, cr0
or al, 0x1 ; cr0 |= PE
mov cr0, eax
; If I place 'jmp $' here all computers stop here normally
jmp 0x10: protected
real_open_A20:
.l1: in al, 0x64
test al, 0x2
jnz .l1
mov al, 0xD1
out 0x64, al
.l2: in al, 0x64
test al, 0x2
jnz .l2
mov al, 0xDF
out 0x60, al
ret
real_init_gdt:
lgdt [.gdtr]
ret
.gdt0 dw 0x0000, 0x0000, 0x0000, 0x0000
.data dw 0xFFFF, 0x0000, 0x9200, 0x00CF
.code dw 0xFFFF, 0x0000, 0x9800, 0x00CF
.gdtr dw $ - .gdt0 - 1
dd .gdt0
bits 32
protected:
; Wherever I place 'jmp $' after the 'protected' label,
; on some computers I get reboot to hell.
; (In that case CS:IP is never points to 'jmp $'
; - something happens before)
mov ax, 0x8
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
mov esp, 0x7C00
jmp $
times 512 - 2 - ($ - $$) db 0 ; Fill the rest of sector
dw 0xAA55 ; Bootable sector sign
times 1474560 - ($ - $$) db 0 ; Fill the rest of floppy
;-------------------------------------------------------------
Sorry for such a long message. But it's my first here.
And my English wants to be better too - isn't my first language.
Best regards,
Yuri Grebenkin
[email protected]
I develop OS. I write code using only nasm and test it under bochs. Generally, I love Unix and have one OS on my PC - FreeBSD - multimedia, internet, excellent environment for development - that's all I need! So, I know that obviosly I can't even complete 1/1000 of any modern usable OS code before I die. Thus I'm not going to reinvent a bicycle, I'm just _trying_ to make a little mobile OS that boots from a floppy (hdd expected in future, I've got no docs on it yet). My OS doesn't use BIOS at all, it does all things itself (sure, boot sector loading is a bios job). What force that forwards me? I don't know. Maybe it's a feeling of myself like of creator of something strong and almost alive virtual creature? This magic when you hear the floppy drive snore and imagine how you've coded this via ports... And imagination of enormous complicated CPU engine working you commands... But for all... I feel that computer _eats_ my health - that's reality truth. One should choose between body health and deep computer life.
Well. Thanks if you read that. It's my first message here.
The problem.
I have monolithic kernel written straight from very first floppy sector.
When BIOS loads this sector I load the rest of kernel image and switch CPU to very lazy PM.
After it I jump (not me as a people, you know) to kernel's entry point and tune PM to more complicated mode so that continue initialization.
I tested my OS on some i386, i486, i586 - works fine. But on some Celerons and PIV I get immediate reboots after setting PE bit and before any instruction the far jmp is points to. (I figured it out by setting control points - endless loops.) On some i686 all things go right. I was surprised when my OS started on PIV with 266MHz memory bus speed! Things are very hard for me because at my computer (PIII Celeron/Coppermine 900MHz) I can't catch the problem - I have no reboots.
Please help me to solve this. Here is fragment of my OS that reflects the problem. Compile it and write image to 1.44 floppy. Boot from it and you'll see if your computer reboots or not. If not then you not encounter the problem that other computers do. I stuck with this problem and it hurts me a lot. We all know here how hard the programming is. So, guys, I need your support and I promise to support others here.
;-------------------------------------------------------------
; Compile: %nasm thisfile.asm -o fd
; Insert a floppy
; Write (as root): #dd if=fd of=/dev/fd0
org 0x7C00 ; Expecting to be loaded at 7C00 by BIOS
bits 16
real:
cli
xor ax, ax
mov ss, ax
mov sp, 0x7C00 ; Temp stack just under myself
call real_open_A20 ; For 32 bit address space
call real_init_gdt ; Load GDTR
mov eax, cr0
or al, 0x1 ; cr0 |= PE
mov cr0, eax
; If I place 'jmp $' here all computers stop here normally
jmp 0x10: protected
real_open_A20:
.l1: in al, 0x64
test al, 0x2
jnz .l1
mov al, 0xD1
out 0x64, al
.l2: in al, 0x64
test al, 0x2
jnz .l2
mov al, 0xDF
out 0x60, al
ret
real_init_gdt:
lgdt [.gdtr]
ret
.gdt0 dw 0x0000, 0x0000, 0x0000, 0x0000
.data dw 0xFFFF, 0x0000, 0x9200, 0x00CF
.code dw 0xFFFF, 0x0000, 0x9800, 0x00CF
.gdtr dw $ - .gdt0 - 1
dd .gdt0
bits 32
protected:
; Wherever I place 'jmp $' after the 'protected' label,
; on some computers I get reboot to hell.
; (In that case CS:IP is never points to 'jmp $'
; - something happens before)
mov ax, 0x8
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
mov esp, 0x7C00
jmp $
times 512 - 2 - ($ - $$) db 0 ; Fill the rest of sector
dw 0xAA55 ; Bootable sector sign
times 1474560 - ($ - $$) db 0 ; Fill the rest of floppy
;-------------------------------------------------------------
Sorry for such a long message. But it's my first here.
And my English wants to be better too - isn't my first language.
Best regards,
Yuri Grebenkin
[email protected]