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 |
|
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 |
|||
19 May 2010, 00:26 |
|
Teehee 19 May 2010, 14:59
How will I know so many information?
there is some manual about gdt? I can't understand so many bytes togethers. I feel completly lost. |
|||
19 May 2010, 14:59 |
|
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. |
|||
19 May 2010, 18:35 |
|
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. [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! |
|||
19 May 2010, 18:43 |
|
Teehee 19 May 2010, 22:06
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. |
|||
19 May 2010, 22:06 |
|
baldr 20 May 2010, 11:05
Teehee,
Make sure your video card (or emulated one) supports it. VBE can prove to be useful. |
|||
20 May 2010, 11:05 |
|
Teehee 20 May 2010, 15:37
How can I do that?
|
|||
20 May 2010, 15:37 |
|
baldr 20 May 2010, 19:41
|
|||
20 May 2010, 19:41 |
|
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 |
|||
20 May 2010, 20:08 |
|
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 . . . |
|||
22 May 2010, 14:47 |
|
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? 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. |
|||
22 May 2010, 15:04 |
|
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.
|
|||
22 May 2010, 15:35 |
|
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. 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. |
|||
22 May 2010, 15:46 |
|
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. |
|||
22 May 2010, 17:39 |
|
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. |
|||
22 May 2010, 18:10 |
|
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 .. 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 |
|||
22 May 2010, 21:31 |
|
edfed 22 May 2010, 23:57
that can be the pixel count of one bank, you should switch banks to write other pixels.
|
|||
22 May 2010, 23:57 |
|
windwakr 23 May 2010, 02:50
Teehee wrote: ok, I made this and get a white pixel: The tutorial I linked to above explains all of this. |
|||
23 May 2010, 02:50 |
|
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 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 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 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) 2 values to check: * bpp (bits per pixel) can be 24 or 32 ("16M" is not really helpful) * bpsl (Byte's per scanline) |
|||
23 May 2010, 03:00 |
|
Goto page Previous 1, 2, 3, 4, 5, 6, 7 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.