Page 1 of 1
Accessing Video Memory
Posted: Wed Jan 29, 2003 12:01 am
by beyondsociety
I been trying for days to get a basic printf function to work and at the point of insanity, I'm asking for help.
The printf function is attached below. How would I use it?
Re:Accessing Video Memory
Posted: Wed Jan 29, 2003 1:50 am
by Pype.Clicker
it seems to me that you forgot the "attribute" byte that comes with the video memory ...
Re:Accessing Video Memory
Posted: Wed Jan 29, 2003 3:31 am
by drizzt
right! test_ptr must be an unsigned word *test_ptr.
But why don't you initialize test_ptr to 0xB8000?!
Re:Accessing Video Memory
Posted: Wed Jan 29, 2003 11:29 am
by beyondsociety
I don't really know what you mean?
Re:Accessing Video Memory
Posted: Wed Jan 29, 2003 11:44 am
by Whatever5k
Have a look at this:
http://www.mega-tokyo.com/os/os-faq-con ... #text_mode
There's an attribute byte indicating the colour of the character to print right after the character itself...
Video memory starts at address 0xB000. That's why drizzt was wondering why you don't use this address, but (0xB000 - 1MB).
Perhaps you use paging and you don't use 1:1 mapping?
Re:Accessing Video Memory
Posted: Thu Jan 30, 2003 8:47 am
by Slasher
Monochrome display modes start at 0xb0000
Color display modes start at 0xb8000
Re:Accessing Video Memory
Posted: Fri Jan 31, 2003 12:31 pm
by beyondsociety
Code: Select all
Video memory starts at address 0xB000. That's why drizzt was wondering why you don't use this address, but (0xB000 - 1MB).
Perhaps you use paging and you don't use 1:1 mapping?
I don't have paging set up yet. Whats 1:1 maping?
Code: Select all
If your kernel's base is not 0, then substract the kernel base from the screen pointer's offset.
What are they referring to when they say if your kernel base is not 0? Is determined by the Code and Data segment in the GDT?
If this so, then maybe this is my problem?
Re:Accessing Video Memory
Posted: Fri Jan 31, 2003 12:44 pm
by drizzt
I don't have paging set up yet. Whats 1:1 maping?
1:1 mapping means that every virtual address (when paging is setup) corresponds with the same physical address.
What are they referring to when they say if your kernel base is not 0? Is determined by the Code and Data segment in the GDT?
If this so, then maybe this is my problem?
If you want to write something in the screen you must put characters into the video memory buffer. This starts at
physical address 0xB8000 if you have a color display, otherwise, if you have a monochrome, at 0xB0000.
So if your data selector (placed into the register ds) is not 0-based you must subtract from the video mem address the base of your selector.
Re:Accessing Video Memory
Posted: Fri Jan 31, 2003 2:11 pm
by beyondsociety
Code: Select all
So if your data selector (placed into the register ds) is not 0-based you must subtract from the video mem address the base of your selector.
How would I check for this? Where would I look?
Re:Accessing Video Memory
Posted: Fri Jan 31, 2003 3:59 pm
by drizzt
When you setup your GDT you define your selectors. Before switching into pmode you must load a GDT with the "lgdt" instruction.
Then you set the PE bit on (bit 0 of cr0 register) and do a far jump to reload CS selector.
Finally you reload your segment registers with the opportune selectors. This is a short summary about what you have to do to switch into PMode (probably you know this...)
I help you to find the base of your data selector with an example...
Re:Accessing Video Memory
Posted: Fri Jan 31, 2003 4:01 pm
by drizzt
This is the structure of every GDT entry:
dw 0 ; limit 15:0
dw 0 ; base 15:0
db 0 ; base 23:16
db 0 ; access byte (descriptor type)
db 0 ; limit 19:16, flags
db 0 ; base 31:24
As you can see you can check the base of your selector simply looking at its definition; for example this is a 0-based selector:
DATA_SEL equ $-gdt ; 0x10
dw 0xFFFF ; Limit/Length
dw 0 ; Base 15:0
db 0 ; Base 23:16
db 0x92 ; present, ring 0, data, expand-up, writable
db 0xCF ; page-granular, 32-bit
db 0 ; Base 31:24
This one has base 0x100000:
DATA_SEL equ $-gdt ; 0x10
dw 0xFFFF ; Limit/Length
dw 0x0000 ; Base 15:0
db 0x10 ; Base 23:16
db 0x92 ; present, ring 0, data, expand-up, writable
db 0xCF ; page-granular, 32-bit
db 0 ; Base 31:24
Re:Accessing Video Memory
Posted: Sat Feb 01, 2003 10:19 am
by beyondsociety
Thanks for the help. I got it working. By the way, I decided to write some simpler code as the code posted above was an example from alt-os.development.
I noticed two problems: one, the attribute byte and the pointer accessing the video memory.
Second, I noticed that if I loaded my C kernel to 1MB, it didn't work. But if I loaded a lower address, it worked.
Weird huh? I have the A20 gate enabled. C kernel code attached below.
Re:Accessing Video Memory
Posted: Sat Feb 01, 2003 11:28 am
by Whatever5k
How is your kernel loaded, do you use GRUB? How do you link your kernel, and do you have an asm file - please post it...
Re:Accessing Video Memory
Posted: Sat Feb 01, 2003 10:00 pm
by beyondsociety
I figured it out. I was compiling my code wrong.