flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Help to start my own OS

Goto page 1, 2, 3, 4, 5, 6, 7  Next
Author
Thread Post new topic Reply to topic
Teehee



Joined: 05 Aug 2009
Posts: 568
Location: Brazil
Teehee
Hi, guys.

Can I have some help to start my own OS?

I just like to do a simple OS with interface (windows, buttons, etc - check my inteface sketch below).

Just for fun and knowledge.

But I REALLY don't know how to start. Sad

[soundtrack]help me in my dream! *glowing eyes*[/soundtrack]


Description:
Filesize: 8.24 KB
Viewed: 2301 Time(s)

interface.PNG



_________________
Sorry if bad english.
Post 12 May 2010, 22:28
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
> Can I have some help to start my own OS?
> I just like to do a simple OS with interface (windows

What is your "OS" supposed to do ?

http://wiki.osdev.org/Getting_Started#The_Hard_Truth
http://wiki.osdev.org/Beginner_Mistakes

I'm going to write more later Smile

Hint: bloat is your enemy in OS development (see attach) Wink


Description: 8'433 -> 629 Byte's (factor 13.4)
Filesize: 629 Bytes
Viewed: 2290 Time(s)

OS629.PNG


Post 13 May 2010, 02:04
View user's profile Send private message Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 568
Location: Brazil
Teehee
Hey, DOS.

DOS386 wrote:
>What is your "OS" supposed to do ?

well, i supposed to do a simple OS with all functionality which a OS must have.

DOS386 wrote:
http://wiki.osdev.org/Getting_Started#The_Hard_Truth
http://wiki.osdev.org/Beginner_Mistakes

I'm going to write more later Smile

Good text!

DOS386 wrote:
Hint: bloat is your enemy in OS development (see attach) Wink

What does bloat mean? Embarassed are you refering to the img size? Smile how do you get that?

_________________
Sorry if bad english.
Post 13 May 2010, 14:57
View user's profile Send private message Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 619
cod3b453
You can set up 32 bit protected mode with ring 0 only, VESA graphics and just the interrupts for a mouse driver fairly quickly but if you want "all the functionality" this is a lot bigger.

A good start is:

- Intel and AMD manuals for system and application programming
- Ralph Brown Interrupt List
- Enabling A20
- Remapping PIC

Good luck
Post 13 May 2010, 16:40
View user's profile Send private message Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 568
Location: Brazil
Teehee
I have these boot file and 'hello world' kernel file:

boot.asm:
Code:
org 7C00h

; 07C0:0000 até 07C0:01FF --- Local onde foi carregado o bootloader
; 07C0:0200 até 07C0:03FF --- Pilha
; 0800:0000 em diante     --- Kernel

    ;inicialização da pilha
    mov ax, 07C0h
    mov ss, ax
    mov sp, 03FEh  ;aponta para o topo da pilha

    ;seta segmento de dados
    xor ax, ax
    mov ds, ax

    ;altera o modo de vídeo
    mov ah, 00h      ;subfucao para setar modo de vídeo
    mov al, 03h  ;03h = 80x25, 16 cores
    int 10h           ;interrupt de vídeo

    ;le dados do disquete
    mov ah, 02h        ;subfunção de leitura
    mov al, 1                ;numero de setores para ler
    mov ch, 0            ;trilha ( cylinder )
    mov cl, 2           ;setor
    mov dh, 0         ;cabeça
    mov dl, 0               ;drive ( 00h = A: )
    mov bx, 0800h    ;ES:BX aponta para o local da memória_
    mov es, bx           ;onde vai ser escrito os dados
    mov bx, 0         ;0800:0000h ( ES = 0800h, BX = 0000h )
    int 13h               ;interrupt de disquete

    jmp 0800h:0000h
    ;pula para o local onde está o kernel
    ;e passa a execução para ele
    

kernel.asm:
Code:
org 0000h

       push cs                 ;CS = endereço do programa atual
   pop  ds                 ;DS = CS
    call clearscreen        ;chama procedure de limpar a tela
   lea  si, [Mensagem]     ;SI = endereço da mensagem
 mov  ah, 0Eh            ;subfuncao para imprimir caractere

    loop:
     mov  al, [si]           ;move para AL o caractere em SI
     cmp  al, 0h             ;compara com 0 ( fim da string )
    jz   exit               ;caso terminou, pule para ‘terminou’
    int  10h                ;interrupção de video
     inc  si                 ;próximo caractere
 jmp  loop               ;repete o processo ate achar o 0

    exit:
       mov  ah, 0h             ;subfuncao de aguardar tecla
        int  16h                ;interrupção de teclado
   mov  ax, 0040h          ;método de reboot consiste em setar_
       mov  ds, ax             ;o valor do endereço 0040:0072h_
       mov  word[0072h], 1234h ;para 1234h e pular para o endereço_
       jmp  0FFFFh:0000h   ;FFFF:0000h

    clearscreen:             ;procedure de limpar a tela
 pusha                   ;coloca todos os reg na pilha
       mov  ah, 06h            ;subfuncao de rolar a tela pra cima
 mov  al, 0              ;limpa a tela
       mov  bh, 00001111b      ;seta as cores ( fundo_texto )
      mov  ch, 0              ;linha do canto sup. esq.
   mov  cl, 0              ;coluna do canto sup. esq.
  mov  dh, 19h            ;linha do canto inf. dir. ( 25 )
    mov  dl, 50h            ;coluna do canto inf. dir. ( 80 )
   int  10h                ;interrupção de vídeo
    popa                    ;repõe os valores dos registradores
        ret                     ;retorna para o código

    Mensagem db 'Hello World from OS!',0 ;nossa string que vai ser exibida
    


It's ok? can I start from here? if yes, how can I test it without restart my PC everytime?

_________________
Sorry if bad english.
Post 13 May 2010, 17:40
View user's profile Send private message Reply with quote
ManOfSteel



Joined: 02 Feb 2005
Posts: 1154
ManOfSteel
Teehee wrote:
can I start from here?

There's a beginning for everything...

Teehee wrote:
how can I test it without restart my PC everytime?

http://bochs.sourceforge.net/ OR http://www.qemu.org/
Post 13 May 2010, 17:52
View user's profile Send private message Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 568
Location: Brazil
Teehee
If I understand i need to create a .img file, put it into a floppydisk and so bochs can emulate it. But how do i create the img file?
Post 13 May 2010, 18:31
View user's profile Send private message Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 619
cod3b453
You can also use VirtualBox or VMWare.

You can compile code to a disk image, luckily floppy disks are quite easy:
Code:
        format binary as 'img'

        ; First sector (boot)
        org 0x7C00

        ; Boot Sector code here

        ; Fill this sector up
        rb (0x7DFE - $)

        ; BIOS signature at end of boot sector
        dw 0xAA55

        ; Second+ disk sector(s)
        org 0x8000
kernel:

        ; kernel code here

        ; Fill the disk image up (1.4Mb)
        times (0x0167E00 - ($ - kernel)) db 0    
Note that your boot sector will need to load more sectors as your kernel grows in size.
Post 13 May 2010, 18:59
View user's profile Send private message Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 568
Location: Brazil
Teehee
cod3b453, Woohoo! Very Happy


Description:
Filesize: 21.55 KB
Viewed: 2222 Time(s)

bochs.PNG



_________________
Sorry if bad english.
Post 13 May 2010, 20:19
View user's profile Send private message Reply with quote
ManOfSteel



Joined: 02 Feb 2005
Posts: 1154
ManOfSteel
Or you can assemble separate files (but keep them sector aligned) and merge them using copy /b boot+kernel my_os.img.
Post 13 May 2010, 21:25
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4242
Location: 2018
edfed
or you can assemble multiple files, and use HxD to write them where you want on a drive.
Post 13 May 2010, 22:18
View user's profile Send private message Visit poster's website Reply with quote
Coddy41



Joined: 18 Jan 2009
Posts: 384
Location: Ohio, USA
Coddy41
nice Teehee, you might be interested in OS Devs "Baby Steps" since you've
made it that far might as well start on step 4

http://wiki.osdev.org/Babystep4

I for one thought they were handy Smile I wish you luck Very Happy
Post 14 May 2010, 01:02
View user's profile Send private message Visit poster's website Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 568
Location: Brazil
Teehee
Oh, so I can't use BIOS interrupts in Protected Mode? Shocked

well, i just need to know how to set Protected Mode. Smile

_________________
Sorry if bad english.
Post 14 May 2010, 22:56
View user's profile Send private message Reply with quote
ManOfSteel



Joined: 02 Feb 2005
Posts: 1154
ManOfSteel
Teehee wrote:
so I can't use BIOS interrupts in Protected Mode?

Well, you can always switch between RM and PM and call BIOS interrupts while in RM, but it's not advisable and I would never talk about it myself. Ahem... Embarassed

Teehee wrote:
i just need to know how to set Protected Mode

edfed is such a nice person, he already wrote an example for you before you even asked. Wink
Post 15 May 2010, 00:33
View user's profile Send private message Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler
You should use grub. Here's a way to make a bootable floppy img when you compile.
Code:
format binary as 'img'

file '../precompiled grub/stage1'

file '../precompiled grub/stage2'

times 156 + 1024 db 0  ; You may need to change this to make sure you kernel is on a sector boundary
include 'kernel.asm'   ; If you want a non-flat binary kernel(elf, PE, or some other crap), compile it separately, and change include to file and the path to the path to the image
times 1474560 + $$ - $ db 0
    
Post 15 May 2010, 01:56
View user's profile Send private message Reply with quote
Mac2004



Joined: 15 Dec 2003
Posts: 313
Mac2004
Here's my example of loading plain binary file from a floppy disk. I'am
using partcopy to write the image on the floppy disk.


http://board.flatassembler.net/topic.php?t=6529

regards,
MAc2004
Post 15 May 2010, 06:58
View user's profile Send private message Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 568
Location: Brazil
Teehee
in PM i'm getting restart everytime. is it because I cannot use INT but i'm using it to print text and reading key to restart?
Post 18 May 2010, 18:44
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
Teehee wrote:
in PM i'm getting restart everytime. is it because I cannot use INT but i'm using it to print text and reading key to restart?
Probably you're right. Real-address mode code will have hard time even if you manage to transfer control to it in PM. Then, why you should at all? Use text frame buffer at 0xB8000 for output and poll 8042 KBC for input via 0x60/0x64 ports (RBIL is a must, but datasheet for your MoBo's SuperIO won't harm either).

Can anybody explain to me, why would-be OS developers loathe real-address mode so much right from the start? Yes, segmentation issues can seem cumbersome and 1 MiB limitation looks goofy, but protected mode is way more complex to understand, much less to master. In return, RM offers friendly playground with rich APIs and almost unhindered freedom.
Post 18 May 2010, 19:45
View user's profile Send private message Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 568
Location: Brazil
Teehee
Here my code:

image.asm:
Code:
format binary as 'img'

; First sector (boot)
org 7C00h

        ; Boot Sector code

      include 'boot.asm'

    ; Fill this sector up 
      rb (0x7DFE - $)

 ; BIOS signature at end of boot sector 
     dw 0xAA55

; Second+ disk sector(s)
org 0000h

    kernel:

   ; kernel code

   include 'kernel.asm'

  ; Fill the disk image up (1.4Mb)
    times (0x0167E00 - ($ - kernel)) db 0    

boot.asm:
Code:
;org 7C00h

; 07C0:0000 até 07C0:01FF --- Local onde foi carregado o bootloader
; 07C0:0200 até 07C0:03FF --- Pilha
; 0800:0000 em diante     --- Kernel

    ;inicialização da pilha
    mov ax, 07C0h
    mov ss, ax
    mov sp, 03FEh    ;aponta para o topo da pilha

    ;seta segmento de dados
    xor ax, ax
    mov ds, ax

    ;altera o modo de vídeo
    mov ah, 00h      ;subfucao para setar modo de vídeo
    mov al, 03h  ;03h = 80x25, 16 cores
    int 10h           ;interrupt de vídeo

    ;le dados do disquete
    mov ah, 02h        ;subfunção de leitura
    mov al, 1                ;numero de setores para ler
    mov ch, 0            ;trilha ( cylinder )
    mov cl, 2           ;setor
    mov dh, 0         ;cabeça
    mov dl, 0               ;drive ( 00h = A: )
    mov bx, 0800h    ;ES:BX aponta para o local da memória_
    mov es, bx           ;onde vai ser escrito os dados
    mov bx, 0         ;0800:0000h ( ES = 0800h, BX = 0000h )
    int 13h               ;interrupt de disquete

; set PM mode (Protected Mode)
boot:       cli
 lgdt [pmgdt]
        mov eax,cr0
 inc ax
      mov cr0,eax
 mov ax,16
   jmp 8:@f

pmgdt:  dw 23,pmgdt-3 
      db 0 
       dw 0ffffh,0,9a00h,0cfh 
     dw 0ffffh,0,9200h,0cfh 
@@:
    jmp 0800h:0000h
    ;pula para o local onde está o kernel
    ;e passa a execução para ele    

kernel.asm:
Code:
 use32
       mov word[0b8000h],7441h   ; print 'A'
     hlt
     @@:
 jmp @b    


For some reason I'm getting restart when I try to jump to kernel.

_________________
Sorry if bad english.
Post 18 May 2010, 22:22
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4242
Location: 2018
edfed
Code:
        jmp 8:@f

pmgdt:  dw 23,pmgdt-3 
        db 0 
        dw 0ffffh,0,9a00h,0cfh 
        dw 0ffffh,0,9200h,0cfh 
@@:
    ##############jmp 0800h:0000h############# 
    


you cannot jump to 800h:xxx
that means jump to segment selector 800h in gdt.
that is not what you want to do, forget about real mode, it is protected mode.

you should do it:
Code:
jmp 8000h
    

because CS is already at descriptor 8, that starts at 0 linear.
then, your kernel is not org 0 but org 8000h
you should provide a segment wich starts at 8000h to say, org 0, and do call segment8000h:0
Post 18 May 2010, 23:06
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2, 3, 4, 5, 6, 7  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.