kernel problems
Posted: Thu Jul 25, 2002 12:39 pm
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 :-\
Re:kernel problems
Posted: Thu Jul 25, 2002 2:42 pm
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