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.
problem in coding my OS
Re: problem in coding my OS
This seems a clear sign of stack problem.
A quick look into the boot loader:
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.
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
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.
- xenos
- 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
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.)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.
Re: problem in coding my OS
i did try to add stack
is it right or wrong way?
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:
Re: problem in coding my OS
Hello,
That bootloader disables interrupts and keeps them disabled. Unless you have already added support for interrupts, get rid of your STI instruction.
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();}
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}