Where do i start??

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.
Berserk

Re:Where do i start??

Post by Berserk »

Ok,

So this lets you acess more than 1mb of memory in Real Mode, so the Kernel can be as big as i want it to be?

Cool function. But what do i do? Do i take the code from the REALINTIT file and put it in my BootSector? (Put the inline asm in my BootSector)

Well, i'll try it.

Thanks mate, i'll tell you when i'm done.
(It'll be soon)
Berserk

Re:Where do i start??

Post by Berserk »

i am clueless on this code, please give me a hint. Please..... i don't know how to convert the inline asm to asm, far out.....

And i am going to rephrase my other question and say exactly what i want, Here is goes:

What i want are 3 asm functions, i will compile these under nasm, then i will link them to my 'C' Kernel.

These Functions look like this (NOTE: There is no code, because i am clueless on how to do this)

Code: Select all

[GLOBAL _SwitchToRealMode]
[GLOBAL _SwitchToProtectedMode]
[GLOBAL _ChangeGraphicsMode]

_SwitchToRealMode:
;I need code so i can switch to real mode from my kernel

_SwitchToProtectedMode:
;I need code to switch back to protected mode while my kernel is loaded.

_ChangeGraphicsMode:
;Function to change grapgics mode while in Real Mode, that is why i want to make these functions.
There, NOTE: i am using the example Kernel + BootSector made by PlayOS, i am using this so i can learn some functions, which i have, after i do this, i will start my own BS & KERNEL;

Please PlayOS, if you could explain the 4Gb thing better, i understand what it does, but i need some help with puting it into the BootSector.

Please mate help me, an if anybody knows how to do the question that i have been asking for a couple of days now (above) Please help......

Excuse me if i sound rude sometimes...it's just because i try and type this up as quickly as possible, i don't proof read it ;D

ciao 8)
PlayOS

Re:Where do i start??

Post by PlayOS »

Here is what you need to do as a list:

1. Enable the A20 Gate
2. Load a Minimal GDT, the one with my example is fine
3. Set the PE (PMode Bit)
4. Jump temporarily into PMode
5. Set FS and GS to point to the 4GB Data Segment (0x10 in my example)
6. Disable the PE Bit again
7. Jump back into Real Mode

OK, here are the steps all put together

Code: Select all

     ; DISABLE INTERRUPTS
     CLI

     ; ENABLE THE A20 GATE
     CALL EMPTY_8042
     MOV AL, 0x0D1
     OUT 0x64, AL

     CALL EMPTY_8042
     MOV AL, 0x0DF
     OUT 0x60, AL

     CALL EMPTY_8042
     JMP A20_GATEDONE

EMPTY_8042:

     MOV AL, 0x0D0
     IN AL, 0x64
     TEST AL, 2
     JNZ EMPTY_8042
     RET

     LGDT [GDTR_PTR]

     MOV EAX, CR0
     OR  AL, 1
     MOV CR0, EAX

     JMP 0x08:ENTER_TEMP_PMODE

[BITS 32]
ENTER_TEMP_PMODE:

     MOV AX, 0x10
     MOV FS, AX
     MOV GS, AX

     ; REMOVE PE (PMODE) BIT
     MOV EAX, CR0
     AND AL, 0xFE
     MOV CR0, EAX

     ; JUMP BACK TO REAL MODE
     JMP 0x0000:ENTER_RMODE

[BITS 16]
ENTER_RMODE:

     ; RENABLE INTERRUPTS
     STI
OK, now to use FS and GS, you need to load them with the value 0, like this

Code: Select all

     XOR AX, AX
     MOV FS, AX
     MOV GS, AX
This is because Real mode addressing still applies (ie: segment * 16 + offset) so if you have 0 in FS and you do this

Code: Select all

     MOV DWORD [FS:0x200000], 0x12345678
you will be storing 0x12345678 into the DWORD at 2MB, I am not going to explain exactly why this works, that part I will expect you to do, this way you will learn.

So just put this code into your boot sector, you could probably make this a function and just call it, because once this is called you will not need to enable the A20 gate or the GDT, this will all still be valid when you go into PMode to stay.

Let me know how you go with this.
Tom

Re:Where do i start??

Post by Tom »

Berserk...why would you need the a20 now? ( just wondering )

( Berserk...if you would have made your own user name here I think you would have had 5 stars ( stars don't matter to me...but it does to alot of people ??? )

:'( :'(...berserk...for all the time you've been here I actually thought that was your name ( I thought it was spanish or something )...of all the silly things I've thought...that was funnier than my 4yr old ideas:'( :'(

Back on topic 8)

You kernel probly won't get bigger than 1 Meg for a while
Mine is avraging around 11k ( 11k * 2 = amount of sectors used on the floppy....or 512 * 2 = 1k, so 11k = 512 * 2 + 11....good to learn this stuff to see how big your kernel is so you know how much extra sectors to load...if your kernel is 5k, it takes 5024(5k) = 5 sectors * 2 )
Berserk

Re:Where do i start??

Post by Berserk »

Hey,

Firstly, What is a Five Star Member, and what does it do??

Secondly, (Sorry PlayOS) But i never asked for this new enhancement, it is too much for a beginner like me, i'll leave it until later.

All i asked for is the source code for a couple of functions that i can link to my kernel. These functions switch to Real Mode from PMode temporarily, then change the graphics mode using int 10h then switch back to PMode while my Kernel is loaded.

This is all i ask for, so please, could somebody help out.

I am just a beginner, and i don't need to be able to load more than i meg (just yet)

Ciao ;D

P.S. And no i am not Spanish. What makes you think that i am?
PlayOS

Re:Where do i start??

Post by PlayOS »

It isn't exactly that advanced what I have given you. I don't think. :-\

You are basically asking people for v86 mode code which isn't easy or small. If you cannot understand what I have given you then you will not understand v86 mode.

Anyway the code I have given you does exactly what you want, except for the video mode switch. It goes RMode -> PMode -> RMode -> PMode isn't that what you want?

I don't understand what you are asking for. ???
Berserk

Re:Where do i start??

Post by Berserk »

Hey,

I don't want to use v86, i was just aking about it, i didn't know it was so hard to program.

As for the code, i can not seem to put it into the bootsector, i keep geting nasm errors, so i edited the code, and finally no errors, but it doesn't do anything, it doesn't even want to load the Kernel (i think)

Here is the Code (NOTE: i am using your example bootsector):

Code: Select all

Ahh, the message is too long with the code, so i have attached it to the message ;D

Ahh, don't know how to attach, guess i can't cos i'm not a member. I'm going to post it in another message (BELOW)
There,

What i want to do is this:

Start in RMode, Load the Kernel, Go to PMode, then when i want to: go to Rmode, change the graphics mode using int 10h, then go back to Pmode, and execute the rest of the Kernel code.

And i want it to be a linked asm function, linked to my kernel.

That is all i ask.

Please, understand, i don't know assembler, i only no interupts and other basic things, i am just starting off.

Ciao 8)
Berserk

Re:Where do i start??

Post by Berserk »

Code: Select all

[BITS 16]
[ORG 0x7c00]

   jmp      0x0000:Start_Boot

Start_Boot:
   xor      ax, ax
   mov      ds, ax
   mov      es, ax
   mov      fs, ax
   mov      gs, ax

   mov      byte [BootDrive], dl

   cli
   mov      ax, 0x9000
   mov      ss, ax
   mov      sp, 0xfffe
   sti

   mov      ax, 0x0003
   int      0x10

CLI

CALL EMPTY_8042
MOV AL, 0x0D1
OUT 0x64, AL

CALL EMPTY_8042
MOV AL, 0x0DF
OUT 0x60, AL

CALL EMPTY_8042

EMPTY_8042:

MOV AL, 0x0D0
IN AL, 0x64
TEST AL, 2
JNZ EMPTY_8042
RET

LGDT [GDTR_PTR]

MOV EAX, CR0
OR AL, 1
MOV CR0, EAX

JMP 0x08:ENTER_TEMP_PMODE

[BITS 32]
ENTER_TEMP_PMODE:

MOV AX, 0x10
MOV FS, AX
MOV GS, AX

MOV EAX, CR0
AND AL, 0xFE
MOV CR0, EAX

JMP 0x0000:ENTER_RMODE

[BITS 16]
ENTER_RMODE:

STI


   push   word 0            push   word 0x2000         push   word 10            push   word 0x0002         push   word 0            call   _ReadDisk

   cmp      al, 0
   je      KernelOK
   jmp      KernelReadError
KernelOK:
   cli

   mov      eax, cr0
   or      eax, 1
   mov      cr0, eax

   jmp      0x08:EnterPMode

Hang16:
   jmp    Hang16

KernelReadError:
   push   strKernelLoadError
   push   0x00
   call   _PrintMsg
   jmp    Hang16

[BITS 32]
EnterPMode:

   mov      ax, 0x10         ; Data Segment
   mov      ds, ax
   mov      es, ax
   mov      fs, ax
   mov      gs, ax
   mov      ss, ax
   mov      esp, 0x200000

   jmp      0x20000   

Hang32:
   jmp      Hang32

[BITS 16]

_ReadDisk:
   pusha                     ; Push AX, BX, CX, DX, DI, SI, BP
   push   es
   mov      bp, sp               ; Setup Stack Frame
   sub      sp, 2               ; 2 Bytes Local Storage
   mov      word [bp - 2], 0      ; Number of Attempts to Read Disk
.ReadDiskAgain
   mov      cx, word [bp - 2]      ; Get the attempt count
   cmp      cx, 30               ; Only retry functions 30 times
   je      .DiskReadError         ; Jump to Error Exit (AL = 1)
   inc      cx                  ; Increment the count
   mov      word [bp - 2], cx      ; Save the new count
   xor      ax, ax               ; Clear AX
   int      0x13               ; Call reset function
   jc      .ReadDiskAgain         ; Try again if it failed
   cld                        ; Clear the direction flag
   mov      dx, word [bp + 20]      ; Get the side number
   shl      dx, 8               ; DH = side number
   mov      dl, byte [BootDrive]   ; Set the Boot Drive Number
   mov      cx, word [bp + 22]      ; CH = Track #, CL = First Sector
   mov      ax, word [bp + 24]      ; Get the sector count (AL = sector count)
   mov      ah, 0x02            ; Read sector(s) function
   mov      bx, word [bp + 26]      ; Get the segment
   mov      es, bx
   mov      bx, word [bp + 28]      ; Get the offset
   int      0x13               ; Reads the Sectors
   jc      .ReadDiskAgain
   mov      sp, bp               ; Restore the Stack Frame
   pop      es                  ; Restore the registers
   popa
   mov      al, 0
   ret      10                  ; Return and Clean the Stack
.DiskReadError:
   mov      sp, bp               ; Restore the Stack Frame
   pop      es                  ; Restore the registers
   popa
   mov      al, 1
   ret      10                  ; Return and Clean the Stack


_PrintMsg:
   push   es                  ; Save Regs
   push   di
   push   bp
   mov      bp, sp               ; Get a Pointer to the Stack
   mov      ax, word [bp + 8]      ; Get the Message Segment
   mov      es, ax
   mov      di, word [bp + 10]      ; Get the Message Offset
PrintMsgLoop:
   mov      al, byte [es:di]      ; Get a Byte
   or      al, al               ; Test for the Zero Terminator
   jz      EndPrintMsg            ; Quit on Zero Terminator
   mov      ah, 0x0e            ; BIOS Write Character Function Number
   mov      bx, 0x000f            ; White on Black Characters
   int      0x10               ; Display the Character
   inc      di                  ; Increment Offset
   jmp      PrintMsgLoop         ; Do Next Character
EndPrintMsg:
   pop      bp                  ; Restore Regs
   pop      di
   pop      es
   ret      4                  ; Return and Remove 4 Bytes from the Stack

BootDrive   db 0               ; Holds the BootDrive #

GDTR_PTR
   dw 0xffff
   dd 0x00010000

GDTR_BASE_ENTRIES
   ; 0x00 - Null Segment Descriptor
   dd 0
   dd 0

   ; 0x08 - Code Segment Descriptor
   db 11111111b   ; 7:0 of Limit
   db 11111111b   ; 15:8 of Limit
   db 00000000b   ; 7:0 of Base
   db 00000000b   ; 15:8 of Base
   db 00000000b   ; 23:16 of Base
   db 10011010b   ; Present | DPL = 0 | Code or Data Seg | Code Seg | Non-Conforming | Readable | Not Accessed
   db 11001111b   ; 4KB Granular | 32-Bit | Reserved | Avl = 0 | 20:16 of Limit
   db 00000000b   ; 32:24 of Base

   ; 0x10 - Data Segment Descriptor
   db 11111111b   ; 7:0 of Limit
   db 11111111b   ; 15:8 of Limit
   db 00000000b   ; 7:0 of Base
   db 00000000b   ; 15:8 of Base
   db 00000000b   ; 23:16 of Base
   db 10010010b   ; Present | DPL = 0 | Code or Data Seg | Data Seg | Expand Up | Writable | Not Accessed
   db 11001111b   ; 4KB Granular | 32-Bit | Reserved | Avl = 0 | 20:16 of Limit
   db 00000000b   ; 32:24 of Base


strKernelLoadError   db 'ERROR: Unable to Load Kernel!', 10, 13, 'Press Ctrl + Alt + Del to Reboot...', 10, 13, 0

; Fill this code out to 510 bytes
Fill times 510-($-$$) db 0
BootSignature dw 0xaa55

NOTE: I have removed most comments so it could fit ;D
jcout_bsi

Re:Where do i start??

Post by jcout_bsi »

Schol-R-LEA wrote: I believe that the VBE 3.0 Standards document on VESA's web site has an appendix with some initialization examples, but I don't know how useful they are. I'm going to try and read through it later today myself. There's supposed to be a tutorial page as well, but it appears to be empty (or perhaps member's-only access).

EDIT: I found a few more links:

MonsterSoft Tutorials covering p-mode and real mode VESA programming/ While I haven't read it all yet, the "Introduction to VESA Programming" looks to be is a good place to start, and the whole document can be (see the downloaded for offline reading.

Several useful ;tutorials can be found here, as someone pointed out earlier in the book thread.

A thread called SuperVGA/VESA Programmer's Notes from the comp.graphics archive.

Programmer's Heaven has a tutorial in mode 13 that may prove useful.

GameDev has a lot of general graphics programming material, and while most of it is specific to Windows, it may still demonstrate techniques which are more widely applicable. Other game-programming sites may also be useful for general graphics-related material.

Lastly, I strongly recommend reading (or better still, downloading and then reading) the online version of Abrash's Grpahics Programming Black Book. While much of it assumes a DOS or Windows environment, and much of it is quite dated, it should still be largely applicable.

I have not read through most of these, and cannot verify their accuracy or usefulness. YMMV.
One of the most usefull sites on graphics programming in assembly i have ever seen. HIGHLY RECOMMENDED!!!
Berserk

Re:Where do i start??

Post by Berserk »

I am not looking to put in VESA, i just want to be able to change graphics modes (using VGA) from my kernel.

Ahhhhh.......Please Please, Somebody help.

My Question is stated alot of times in previous posts.

So Please go back and read it.

Ciao 8)
grey wolf

Re:Where do i start??

Post by grey wolf »

the links for VESA graphics programing more than likely have the information you're looking for.
Berserk

Re:Where do i start??

Post by Berserk »

Unfortunately, i could not find what i am looking for.

Please, i have been asking this question for a long time, If you know the answer, Please answer it, the Question is above.

Please, Please, i need to know :'(
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:Where do i start??

Post by Pype.Clicker »

Code: Select all

switch_mode:
     cli
     pushad
     mov ebx,[ebp+8] ;; get back the argument
     mov ecx, .temp_real_mode
     add ecx, CODE_SEGMENT_BASE_ADDRESS

     mov dl,0x0f
     and dl,cl
     shr ecx,4  ;; compute an offset & a segment out of the linear address.
     mov byte [.rm_offset],dl
     mov word[.rm_segment],cx
     jmp .pipeline_flush
.pipeline_flush:
     mov eax,cr0
     mov edx,eax
     and eax,0x7fff fffe
     mov cr0,eax
db JMP_FAR_OPCODE
.rm_offset db 0,0
.rm_segment dw 0

[code 16]
.temp_real_mode:
     ;; set up a valid stack segment and pointer for real mode
     mov ax,bx
     int 0x10
     
     mov cr0,edx
[code 32]
     jmp CODE32_SELECTOR : .back2pmode

.back2pmode:
     popad
     sti
never tested, though ... but it should do it B)
Tim

Re:Where do i start??

Post by Tim »

Bezerk: stop demanding information. Learn yourself. Instead of asking people for links, find them yourself. In any case, the information you've been given is more than enough.

If you can't make graphics mode work, don't bother. Get everything else working first. Write an operating system and start doing the graphics stuff in, say, two years time (seriously). Once you learn OS development properly, graphics mode will become obvious.
jcout_bsi

Re:Where do i start??

Post by jcout_bsi »

Berzerk e-mail [email protected]
Post Reply