problem in coding my OS

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Neoncore
Posts: 14
Joined: Sat Jun 25, 2011 1:49 pm

problem in coding my OS

Post 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.
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: problem in coding my OS

Post 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.
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: problem in coding my OS

Post 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.)
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
Neoncore
Posts: 14
Joined: Sat Jun 25, 2011 1:49 pm

Re: problem in coding my OS

Post 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?
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: problem in coding my OS

Post 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.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
Post Reply