Begginer's problem with OS
Posted: Sat Jul 21, 2007 12:24 pm
Hello!
I am completely newbie to os dev. I've read many articles, tutorials etc. about asm, c and os theory. So, I've started to make my own OS
Now I have bootloader thats loads kernel, then GDT, enter PMODE and jumping to kernel. But:
First: I run mu os with QEMU. But If I enter to kernel I have page fault(In host OS).
Second: I don't have idea how to link asm and c. Where is something like linker manual? I cannot find it.
Here is code:
Bootloader:
Kernel:
And how I build and run:
Ufff... end.
Thanks for reading my post. Cheers
Ps. Sorry for my English I learning it only 2 years
I am completely newbie to os dev. I've read many articles, tutorials etc. about asm, c and os theory. So, I've started to make my own OS
Now I have bootloader thats loads kernel, then GDT, enter PMODE and jumping to kernel. But:
First: I run mu os with QEMU. But If I enter to kernel I have page fault(In host OS).
Second: I don't have idea how to link asm and c. Where is something like linker manual? I cannot find it.
Here is code:
Bootloader:
Code: Select all
org 7C00h;
BITS 16
start:
; Wacky stuff...
cli
xor ax, ax
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ax, 0x2000
mov ss, ax
mov sp, 0x200
sti
; loading kernel
mov ah, 2
mov al, 10
mov ch, 0
mov cl ,2
xor dh, dh
xor dl, dl
mov bx, 8000h
mov es, bx
xor bx, bx
int 13h
;GDT stuff
cli
;pusha
lgdt [gdt_toc]
;popa
; GDT stuff end
;GO PMODE!
mov eax, cr0
or eax, 1
mov cr0, eax
mov ax, 0x10
mov ss, ax
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
jmp 0x08:apm
BITS 32
gdt:
; null descriptor
dd 0
dd 0
;gdt code:
dw 0FFFFh ; lilit low word
dw 0 ; base low word
db 0 ; base middle
db 10011010b ; access ;
db 11001111b ;granularity ;
db 0 ; base high word
;gdt data:
dw 0FFFFh ; lilit low word
dw 0 ; base low word
db 0 ; base middle
db 10010010b ; access ;
db 11001111b ;granularity ;
db 0
gdt_end:
gdt_toc:
dw gdt_end - gdt - 1
dd gdt
apm:
mov ax, 0x10
mov ss, ax
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov esp, 0x90000
hang:
jmp 0x08:0x80000
times 510 - ($ - start) db 0
db 55h
db 0AAh
Code: Select all
[BITS 32]
start:
jmp start
Code: Select all
nasm boot.asm -f bin -o boot.bin
nasm kernel.asm -f bin -o kernel.bin
cat boot.bin kernel.bin > image.img
qemu -fda image.img
Thanks for reading my post. Cheers
Ps. Sorry for my English I learning it only 2 years