Some questions about 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
Veldriss

Some questions about My OS

Post by Veldriss »

Hello everyone,
I discoverd this lovley forum a few days ago, have been going trough some off the many many good posts people have been writing. And i now feel ready to dive into writing my own OS.

I have choosen to try to write it in C. Since i have very good knowledge in PHP (pretty much the same as C i have been toled).

What i pretty much want to acive is writing a kernel that displays a text to the screen.
Ive understud that i need a Kernel.c, Link.ld, a bootloader(I will try to use GRUB), Loader.asm

Here is the following code inside off those files i have writen so far.

Kernel.c

Code: Select all

#include<stdio.h>

main()
{
   printf("Hi, Testing..");
}

Loader.asm

Code: Select all

; Loader.asm

[BITS 32] ; protected mode (Skyddad mode)

[global start] 
[extern _main] ; detta ?r min C kod

start:
call _main ; anropa int main fr?n C koden
cli ; 
hlt ; stanna maskinen

Link.ld

Code: Select all

/* Link.ld */

OUTPUT_FORMAT("binary")
ENTRY(start)
SECTIONS
{
    .text 0x100000 :
    {
        code = .; _code = .; __code = .;
        *(.text)
        . = ALIGN(4096);
    }

    .data :
    {
        data = .; _data = .; __data = .;
        *(.data)
        . = ALIGN(4096);
    }

    .bss :
    {
        bss = .; _bss = .; __bss = .;
        *(.bss)
        . = ALIGN(4096);
    }

    end = .; _end = .; __end = .;
}

Questions now are.
  • Will that Kernel.c acutally print that to the screen?
  • How would i compile all this? (I use Windows2k)
Very Happy for all awnsers :D

Regards Veldriss ;)
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Some questions about My OS

Post by Pype.Clicker »

Veldriss wrote: How would i compile all this? (I use Windows2k)
TimBot says: "use Cygwin"
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Some questions about My OS

Post by Pype.Clicker »

well, more precisely ...
1. even if it's close to Java or PHP in its expression syntax, C is a completely different beast. Make sure you properly understand the concepts of pointers, functions, global/local/static/automatic etc. variables and that you clearly get why sizeof("hello world") is 4 before you start an OS in C...

2. your kernel (as it is posted) will not work. Unlike a C application, a kernel do not have the standard library. Thus no 'printf' function, until you implemented it ...

3. once you get cygwin (if you plan using GRUB, you'll probably love using the ELF version of cygwin rather than its COFF version), use "gcc -c kernel.c ; nasm -felf loader.asm ; ld -T link.ld loader.o kernel.o -o kernel.bin"

never used cygwin myself, thus wait for RealTim (not the poor lil' TimBot i am) to check i didn't wrote stupid things for the last point.

oh, and btw, forget about those "glow" things: we're grown up and they do not display properly on anything other than Internet ExploZer
Veldriss

Re:Some questions about My OS

Post by Veldriss »

ok :D
So i asume i need to write my own include files with printing functions in?
Do you have any example of such a include? ;)

Regards Veldriss
october

Re:Some questions about My OS

Post by october »

You have to include the right multiboot header in your loader.asm (if you plan to load it with grub).


MULTIBOOT_PAGE_ALIGN equ 1<<0
MULTIBOOT_MEMORY_INFO equ 1<<1

MULTIBOOT_HEADER_MAGIC equ 0x1BADB002
MULTIBOOT_HEADER_FLAGS equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO
CHECKSUM equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)

; The Multiboot header (in NASM syntax)
align 4
dd MULTIBOOT_HEADER_MAGIC
dd MULTIBOOT_HEADER_FLAGS
dd CHECKSUM

this should work

ps: http://osdev.neopages.net/tutorials/grub.php?the_id=5
Veldriss

Re:Some questions about My OS

Post by Veldriss »

Oh.. Great Thanks alot! :D

Ive now rewrote my Kernel a bit and added printf function in it. so that it should work.

But ofcourse something else doesent work now >:(

i get the following error when i try to link my files together.

Code: Select all

$ ld -T test.ld -o Kernel.bin Loader.o Kernel.o
Loader.o: file not recognized: File format not recognized
The files contain..

Code: Select all

//Kernel.c
#include<stdio.h>

main()
{
   printf("Hi, Testing..");
}

Code: Select all

; Loader.asm

; For att kunna ha GRUB som boot loader behovs dessa rader
MULTIBOOT_PAGE_ALIGN  equ 1<<0
MULTIBOOT_MEMORY_INFO  equ 1<<1

MULTIBOOT_HEADER_MAGIC equ 0x1BADB002
MULTIBOOT_HEADER_FLAGS equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO
CHECKSUM equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
align 4
dd MULTIBOOT_HEADER_MAGIC
dd MULTIBOOT_HEADER_FLAGS
dd CHECKSUM


[BITS 32] ; protected mode (Skyddad mode)

[global start] 
[extern _main] ; detta ?r min C kod

start:
call _main ; anropa int main fr?n C koden
cli ; 
hlt ; stanna maskinen
Any idea what i have done wrong? :D

Regards Veldriss
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Some questions about My OS

Post by Pype.Clicker »

your asm and c object file must match. Maybe you can try -fcoff instead of -felf for nasm ...
Veldriss

Re:Some questions about My OS

Post by Veldriss »

Ohh!
Probly its a matter how i compile my .c files then.
The Tutorial i follow (but i do it in C) is this one http://www.invalidsoftware.net/os/

I compile my .C files like this

Code: Select all

gcc kernel.c -o kernel.o
And my .ASM file like this

Code: Select all

nasm -f coff Loader.asm -o Loader.o
I might have to compile the .C file diffrent? ???

Regards Veldriss
Post Reply