Page 1 of 1

problem in coding my OS

Posted: Sat Jun 25, 2011 2:14 pm
by Neoncore
i use the following-> boot loader: <http://www.programmersheaven.com/download/42655/download.aspx>
kernel tutorial: <http://wiki.osdev.org/Fasm-TCC_BareBones>
Virtual machine: <QEMU Manager for windows>

the kernel loads and it works but i have to add a infinite loop into the last function i call or it will crash i also can't call functions like how it works into normal but rather as sequence.

i can call this way func1 call func2 call func3 etc..
but i can call that way mainfunction -> call clear screen,return -> call draw text,return.

Re: problem in coding my OS

Posted: Sat Jun 25, 2011 3:10 pm
by bluemoon
This seems a clear sign of stack problem.
A quick look into the boot loader:

Code: Select all

mov ax, 0
mov ss, ax
mov sp, 0x7000
and later right before jmp kernel...
shl esp, 4
This seems to put the stack into somewhere to surprise you.

The example kernel did not setup a stack, you may want to do it as the boot loader give you junk in esp.

And what do you expect the computer do after the last function? It will continue to run that's why you want to put infinite loop there, and better with HLT in the loop.

Re: problem in coding my OS

Posted: Sat Jun 25, 2011 3:52 pm
by xenos
bluemoon wrote:And what do you expect the computer do after the last function? It will continue to run that's why you want to put infinite loop there, and better with HLT in the loop.
But make sure you don't HLT it with interrupts turned off. QEMU will stop refreshing the screen if that happens, so it might not display some of the output, even if you wrote it to the screen before that HLT. (QEMU does not display changes immediately, it takes a while before the screen is refreshed. Although this period is too short to notice, it is enouh to run into a HLT at the end of your code and make the screen freeze before the last refresh.)

Re: problem in coding my OS

Posted: Sat Jun 25, 2011 6:03 pm
by Neoncore
i did try to add stack

Code: Select all

;  Tutorial: A small kernel with Fasm & TCC
;  By Tommy.
 
        format elf
        use32
 
;
; Equates
;
MULTIBOOT_PAGE_ALIGN        equ (1 shl 0)
MULTIBOOT_MEMORY_INFO       equ (1 shl 1)
MULTIBOOT_AOUT_KLUDGE       equ (1 shl 16)
MULTIBOOT_HEADER_MAGIC      equ 0x1BADB002
MULTIBOOT_HEADER_FLAGS      equ MULTIBOOT_PAGE_ALIGN or MULTIBOOT_MEMORY_INFO
MULTIBOOT_CHECKSUM          equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
 
        section '.text' executable
;
; Multiboot header
;
dd MULTIBOOT_HEADER_MAGIC
dd MULTIBOOT_HEADER_FLAGS
dd MULTIBOOT_CHECKSUM
;
; Kernel entry point.
;
        public  _start
        extrn   Startup
_start:
        cli                             ; Clear interrupts
        mov esp, stack_end              ; Build Stack
        sti                             ; Restore interrupts
        cld                             ; The default direction for string operations
                                        ; will be 'up' - incrementing address in RAM
        call    Startup                 ; Call the main kernel function.
@@:
        jmp     @b
;
; Stack entry point.
;
        section '.bss' executable

stack_begin:
    rb 4096  ; Reserve 4 KiB stack space
stack_end:
is it right or wrong way?

Re: problem in coding my OS

Posted: Mon Jun 27, 2011 9:33 am
by neon
Hello,

That bootloader disables interrupts and keeps them disabled. Unless you have already added support for interrupts, get rid of your STI instruction.