Accessing Video Memory
Accessing Video Memory
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?
The printf function is attached below. How would I use it?
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Accessing Video Memory
it seems to me that you forgot the "attribute" byte that comes with the video memory ...
Re:Accessing Video Memory
right! test_ptr must be an unsigned word *test_ptr.
But why don't you initialize test_ptr to 0xB8000?!
But why don't you initialize test_ptr to 0xB8000?!
Re:Accessing Video Memory
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?
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
Monochrome display modes start at 0xb0000
Color display modes start at 0xb8000
Color display modes start at 0xb8000
Re:Accessing Video Memory
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?
Code: Select all
If your kernel's base is not 0, then substract the kernel base from the screen pointer's offset.
If this so, then maybe this is my problem?
Re:Accessing Video Memory
1:1 mapping means that every virtual address (when paging is setup) corresponds with the same physical address.I don't have paging set up yet. Whats 1:1 maping?
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.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?
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
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.
Re:Accessing Video Memory
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...
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
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
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
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.
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
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...