flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Help to start my own OS

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



Joined: 19 Mar 2008
Posts: 1651
baldr 18 May 2010, 23:11
Teehee,

Your GDT.limit==0x17, hence any selector >0x13 generates #GP (except NULL selectors being loaded into any segment register except cs and ss).

In fact, your GDT has only two valid descriptors: one DPL==0 for flat 32-bit e/r code (selector 8) and one DPL==0 for flat 32-bit r/w data (selector 0x10).

jmp 0800h:0000h is definitely outta limits. Correct far jump is jmp 8:8000h (jmp 8000h will do too, as edfed said). And it should be 32-bit, as we're already in PM.

Next problem is that mov word[0b8000h],7441h uses ds as default segment register, yet it is still 0.
Post 18 May 2010, 23:11
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4347
Location: Now
edfed 19 May 2010, 00:26
got it.

1/ the stack will be better if set in a completelly different memory zone.
2/ the gdt would not be the "supr optimised" one, for code reliability, use a clear gdt
3/ the first instruction in protected mode should be in 32bit mode.

then, it works.
Code:
    org 7C00h
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    mov ax, 1000h
    mov ss, ax
    mov sp, 0       ;aponta para o topo da pilha
    mov ax, cs
    mov ds, ax
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    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 [gdt+2]
        mov eax,cr0
        inc ax
        mov cr0,eax
        jmp gdt.code:@f

@@:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

use32
        jmp 8000h
        align 8                 ; aligner la prochaine instruciton sur une adresse multiple de 8 octets.
gdt:                            ;
dw 0                            ; aligner la partie 32 bits du pseudo descipteur sur un addrese
.taille dw @f-gdt-1             ; partie 16 bits du pseudo descipteur, taille de la gdt en octets
.linear dd gdt                  ; partie 32 bits du pseudo descripteur, adresse de base linéaire
.code=$-gdt                     ; première entrée dans la gdt (8*1)
dw 0ffffh,0                     ;   4 giga octets, base à l'adresse linéaire 0
db 0,10011010b,11001111b,0      ;   granularité = 4 kilo octets, segment de code, privilege 0, exécutable
.données=$-gdt                  ; second entry in gdt (8*2)
dw 0ffffh,0                     ;   4Gbytes, start at linear 0
db 0,10010010b,11001111b,0      ;   granularity = 4Kbytes, data segment, ring 0, read/write, present,etc...
@@:                             ; used for gdt.size calculation

        ; Fill this sector up 
libre =  510-(remplissage-$$)   ; define "free" bytes count
remplissage rb libre            ; reserve "free" bytes to make line below at offset 510
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

        ; BIOS signature at end of boot sector 
        dw 0xAA55

; Second+ disk sector(s)
org 8000h

    kernel:

        ; kernel code
        use32
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        mov ax,gdt.données
        mov ds,ax
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        mov word[0b8000h],7441h   ; print 'A'
        hlt
     @@:
        jmp @b

    


Last edited by edfed on 19 May 2010, 21:46; edited 1 time in total
Post 19 May 2010, 00:26
View user's profile Send private message Visit poster's website Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee 19 May 2010, 14:59
How will I know so many information? Sad
there is some manual about gdt?

I can't understand so many bytes togethers.

I feel completly lost.
Post 19 May 2010, 14:59
View user's profile Send private message Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee 19 May 2010, 18:35
ok, I did a research and now i'm understanding a lil bit on gdt.

But what I don't know is how to organize the GDT in the code.

edfed wrote:
Code:
gdt:
    dw 0                       
      .size dw @f-gdt-1       
      .linear dd gdt          
      .code=$-gdt             
    dw 0ffffh,0              
    db 0,10011010b,11001111b,0 
      .data=$-gdt             
    dw 0ffffh,0              
    db 0,10010010b,11001111b,0    

but how he knows what hes doing? why starts with dw 0? what that .size, .linear, .code, .data lines mean? why they are there? What's the meaning?

And why these two line sequences almost equal:
Code:
    dw 0ffffh,0              
    db 0,10011010b,11001111b,0 
      .data=$-gdt             
    dw 0ffffh,0              
    db 0,10010010b,11001111b,0    

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



Joined: 20 Feb 2006
Posts: 4347
Location: Now
edfed 19 May 2010, 18:43
ok, let say, dw 0 assume you are still aligned on 8 bytes boundary, and will align the dword part of pseudo descriptor on dword boundary (as stated in Intel's IA32 manuals). it is for optimal performance.

.size, .linear, .code and .data are labels, just in order to remember what is it. it speaks more than only dw @f-gdt-1

and the sequence is only the first two entries in gdt, the first is set as executable code descriptor, second is set as data descriptor.
all fields in this structure are description for some parameters.

refer to IA32 manual system programming manual for more details and explanations.


and don't plan on writing an os if such things are too much for your patience. Very Happy

[edit]
don't feel discouraged by the difficult compehension, it is normal, just read a lot, code lot more, and everything will be clean in your mind. welcome home!
Post 19 May 2010, 18:43
View user's profile Send private message Visit poster's website Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee 19 May 2010, 22:06
Smile

Next step, i'd like to do some video tests. I'd like to know:
1. how to set video mode to 1280x1024
2. how to plot a pixel on it.
Post 19 May 2010, 22:06
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 20 May 2010, 11:05
Teehee,

Make sure your video card (or emulated one) supports it. VBE can prove to be useful.
Post 20 May 2010, 11:05
View user's profile Send private message Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee 20 May 2010, 15:37
How can I do that?
Post 20 May 2010, 15:37
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 20 May 2010, 19:41
Teehee,

Google for "vbecore3.pdf". You may also try VESA site, there still are some free options.
Post 20 May 2010, 19:41
View user's profile Send private message Reply with quote
windwakr



Joined: 30 Jun 2004
Posts: 827
windwakr 20 May 2010, 20:08
I think this tutorial a good way to start understanding it:
http://www.monstersoft.com/tutorial1/VESA_intro.html

_________________
----> * <---- My star, won HERE
Post 20 May 2010, 20:08
View user's profile Send private message Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee 22 May 2010, 14:47
I tried to swicth to video mode, but i can't call INTs bc i'm in protected mode. so I get restart. How can I do that in PM?
Code:
.
.
.
mov ax, 4F02h  ; VESA set video mode
mov bx, 011Bh  ; 011Bh  = 1280x1024x16M
int 10h

hlt
.
.
.    
Post 22 May 2010, 14:47
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20363
Location: In your JS exploiting you and your system
revolution 22 May 2010, 15:04
Teehee wrote:
I tried to swicth to video mode, but i can't call INTs bc i'm in protected mode. so I get restart. How can I do that in PM?
You need a PM mode driver. You will have to visit the website of the manufacturer of your video card and download the specs. Then you can write the driver for your OS.

The only other way is to switch to RM each time you call BIOS int's and then switch back to PM. Not very efficient though if you need high performance.
Post 22 May 2010, 15:04
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4347
Location: Now
edfed 22 May 2010, 15:35
note that you are in real mode at startup, then, you can set the vesa mode before pm switch, and it will be ok.
Post 22 May 2010, 15:35
View user's profile Send private message Visit poster's website Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee 22 May 2010, 15:46
revolution wrote:
You need a PM mode driver. You will have to visit the website of the manufacturer of your video card and download the specs. Then you can write the driver for your OS.

But then it will work only in my card. Sad

Quote:
The only other way is to switch to RM each time you call BIOS int's and then switch back to PM. Not very efficient though if you need high performance.

How can I back to RM?

edfed wrote:
note that you are in real mode at startup, then, you can set the vesa mode before pm switch, and it will be ok.

I set PM in the boot file. There is no problem to switch video there?

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



Joined: 20 Feb 2006
Posts: 4347
Location: Now
edfed 22 May 2010, 17:39
to go back to protected mode, you should set entries to real mode segments in GDT, point to them using retf stack, invalidate protected mode in cr0, and do the retf, that will set segments to real mode adress space.
just look deeper in the fbrowser code.


there is not problem if you set video mode in boot sector.
Post 22 May 2010, 17:39
View user's profile Send private message Visit poster's website Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee 22 May 2010, 18:10
hmm, ok.

please help me to plot a pixel in PM (1280x1024x16M). I'm still lost. I need a code to understand that.
Post 22 May 2010, 18:10
View user's profile Send private message Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee 22 May 2010, 21:31
ok, I made this and get a white pixel:
Code:
mov dword[0xA0000], -1    

Can anyone give-me a reference about which byte is RGBA? (and other infos about pixel info)

[edit]
Something is wrong Crying or Very sad .. I can draw till 34 lines only. Why?

Code:
        mov ecx, 1280*1024 ; 1024 = lines; but draw 35 lines only
    @@: mov dword[0xA0000+ecx*4], -1
        dec ecx
        jnz @b      
Post 22 May 2010, 21:31
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4347
Location: Now
edfed 22 May 2010, 23:57
that can be the pixel count of one bank, you should switch banks to write other pixels.
Post 22 May 2010, 23:57
View user's profile Send private message Visit poster's website Reply with quote
windwakr



Joined: 30 Jun 2004
Posts: 827
windwakr 23 May 2010, 02:50
Teehee wrote:
ok, I made this and get a white pixel:
Code:
mov dword[0xA0000], -1    

Can anyone give-me a reference about which byte is RGBA? (and other infos about pixel info)

[edit]
Something is wrong Crying or Very sad .. I can draw till 34 lines only. Why?

Code:
        mov ecx, 1280*1024 ; 1024 = lines; but draw 35 lines only
    @@: mov dword[0xA0000+ecx*4], -1
        dec ecx
        jnz @b      



The tutorial I linked to above explains all of this.

_________________
----> * <---- My star, won HERE
Post 23 May 2010, 02:50
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1903
DOS386 23 May 2010, 03:00
Quote:
well, i supposed to do a simple OS with all functionality which a OS must have


Maybe you indeed don't really know ...

FYI: An OS is supposed to serve applications.

Quote:
What does bloat mean?


Absurdly large files, applications, and OS'es wasting space on HD's and bandwidth of internet connections Sad

Quote:
are you refering to the img size? how do you get that?


YES. PNGOUT, OPTIPNG, DEFLOPT. One day you can port them (or at least OPTIPNG which is open source) to your OS Smile

About VESA: A forum search gives 1'000'000'000 hits.

http://board.flatassembler.net/download.php?id=3913 (580 KiB)

http://board.flatassembler.net/download.php?id=3915 (46 KiB)

Quote:
Can anyone give-me a reference about which byte is RGBA?


RGBA is PNG (and a BMP hack), there is no RGBA in 32bpp VESA, only URGB (A=Alpha | U=Unused), IIRC the 8 highest bits are U and the 8 lowest B, just test $FF00'0000 , $00FF'0000 , $0000'FF00 and $0000'00FF Shocked

Quote:
I can draw till 34 lines only. Why?


At $000A'0000 there are only 64 KiB space. Either do B.S. (bad) or use the LFB (better) Wink

2 values to check:

* bpp (bits per pixel) can be 24 or 32 ("16M" is not really helpful)
* bpsl (Byte's per scanline)
Post 23 May 2010, 03:00
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.