kernel problems

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
kernel

kernel problems

Post by kernel »

I have been trying to make a pmode OS in ASM and C for a while now, but I am unable to set a video mode damnit! Whenever i do "int 16" or "int 16h" or "int 0x16", the stuipd Kernel Crashes! Ive tried about everything, but I am still stuck. Could somebody give me a link or email me a small kernel or something that uses video modes? it doesnt have to be anything fancy, i just need something to learn from.

thanx :-\
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:kernel problems

Post by Pype.Clicker »

hmmm ... remember the INT16 is something from real world that cannot be called from protected mode (unless you setup a clean virtual mode - which is usually tricky as hell). Maybe VBE 3.0 (see this reference) might help you as it provides a complete modes enumeration and setup API for protected mode ...

As a last resort, you can try to program VGA hardware directly, but expect something *really* difficult to do ;)

I guess most projects do a short trip back to real mode when they need to switch video mode :(
crazybuddha

Re:kernel problems

Post by crazybuddha »

Here is some code for setting video modes 0x03 and 0x13 through the ports. I just had it lying around from something else I was working on. It's pretty junky, so accept it for what it's worth.

However, it has been tested under pmode and seems to work. It may give you something simple to work with. Also search this board for some good links.


Programming the VGA registers isn't hard. It's just a little weird how you access them. If you have trouble, let me know, and I'll see if I can explain it.

This isn't a 'real world' solution, but it does give a sense of programming the hardware

Note: I seem to recall when I read the values in from my BIOS and used those, this gave me trouble. I never bothered figuring out why. However, the port values given here worked just fine. So, YMMV


(Oh, and yes, there are some unnecessary bytes -- MISC register stuff, I believe -- in the mode values. I also never bothered to clean them out. ).

;-----------------------------------------------------------------------------
; SetMode
;
; call the macro like this
;
; SetMode mode13

; set the video mode -- only text mode 03h and graphic mode 13h supported
;-----------------------------------------------------------------------------???

%macro SetMode 1
???mov esi, %1
???call set_mode
%endmacro
???
set_mode:??????
???mov dx, 0x3c2??????; MISC register
???mov al, [esi]??????
???out dx, al??????
???inc esi?????????
???
???
???mov dx, 0x3da??????; STATUS reset
???mov al, [esi]??????; FIXME: not needed?
???out dx, al
???inc esi


???xor ecx, ecx??????; index counter
reg_loop:
???mov dx, 0x3c4??????; SEQUENCER
???mov al, cl??????; select register index???
???out dx, al??????; add delay?
???
???mov dx, 0x3c4??????; SEQUENCER
???inc dx?????????; select data register
???mov al, [esi]??????; send data byte
???out dx, al
???
???inc esi
???inc ecx
???cmp cl, 5??????; number of data bytes
???jl reg_loop??????; for this register
???

???
???mov ah, 0x0e??????; enable
???mov al, 0x11
???and ah, 0x7f
???mov dx, 0x3d4??????; CRTC
???out dx, ax
??????
???xor ecx, ecx
reg_loop2:
???mov dx, 0x3d4
???mov al, cl
???out dx, al??????
???
???mov dx, 0x3d4
???inc dx
???mov al, [esi]
???out dx, al??????
???
???inc esi
???inc ecx
???cmp cl, 25
???jl reg_loop2
???
???
???xor ecx, ecx
reg_loop3:
???mov dx, 0x3ce??????; GRAPHICS
???mov al, cl
???out dx, al?????????
???
???mov dx, 0x3ce??????; GRAPHICS
???inc dx
???mov al, [esi]
???out dx, al??????
???
???inc esi
???inc ecx
???cmp cl, 9
???jl reg_loop3


???
???mov dx, 0x3da??????; reading Internal Status
???in al, dx??????; sets AC to Index
???
???xor ecx, ecx
reg_loop4:
???mov dx, 0x3c0??????; ATTRIBUTE
???in ax, dx
???
???mov al, cl
???out dx, al??????
???
???mov al, [esi]
???out dx, al??????
??????
???inc esi
???inc ecx
???cmp cl, 21
???jl reg_loop4
???
???mov al, 0x20??????; set bit 5 of AC
???out dx, al??????; enables display
???

???ret???
???



;-----------------------------------------------------------------------------
; Initialized data
;-----------------------------------------------------------------------------




mode03???db 0x67, 0x00, 0x03, 0x00, 0x03, 0x00, 0x02
???db 0x5f, 0x4f, 0x50, 0x82, 0x55, 0x81, 0xbf, 0x1f, 0x00, 0x4f, 0x0d, 0x0e, 0x00, 0x00, 0x00, 0x00
???db 0x9c, 0x0e, 0x8f, 0x28, 0x01, 0x96, 0xb9, 0xa3, 0xff
???db 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x0e, 0x00, 0xff
???db 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f
???db 0x0c, 0x00, 0x0f, 0x08, 0x00


mode13 db 0x63, 0x00, 0x03, 0x01, 0x0f, 0x00, 0x0e
db 0x5f, 0x4f, 0x50, 0x82, 0x54, 0x80, 0xbf, 0x1f, 0x00, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
db 0x9c, 0x0e, 0x8f, 0x28, 0x40, 0x96, 0xb9, 0xa3, 0xff
db 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0f, 0xff
db 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
db 0x41, 0x00, 0x0f, 0x00, 0x00
kernel

Re:kernel problems

Post by kernel »

damn thats a lot of code :P
I'll try it!

Also, does anybody know where I can find the source for a simple Real Mode Kernel?
crazybuddha

Re:kernel problems

Post by crazybuddha »

Actually it's four versions of basically the same thing, so it could be tightened up. Perhaps that is something you will do and share the results with the rest of us.
kernel

Re:kernel problems

Post by kernel »

well, I didn't use that code, but I did find a way to make a small real-mode kernel. I can set the video mode just fine in my new kernel ;D

Im having trouble though with setting pixels. does the video memory for real mode start at 0xA0000?
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:kernel problems

Post by Pype.Clicker »

hum, video memory location is independent of real/protected mode: it's at 0xa0000 absolute physical address. Thus, in rmode, just have mov es, 0xa000 should allow you to write in it :)
Post Reply