Page 1 of 1
Pmode screen printing, asm, using Flat assembler
Posted: Sat May 17, 2008 4:15 am
by kmtdk
Hi all out there, i have a littel problem i pmode.
When try to write to memory location: 0xb800, it dont.
after some time analysion what ´happend, I found out that a error happend using FASM.
i typede in the code:
mov edi,0xb8000
, but at runtime it was RDI=000000000008b800
even if i try this:
mov di,0xb800
it ends up beeing dÃffrent.
I Use BOCHS...
Can someone solve this problem
Posted: Sat May 17, 2008 5:47 am
by JamesM
Hi,
The linear address of the textmode framebuffer is 0xB8000 (note three zeroes!)
In real mode you access this with a segment selector of 0xB800, because segment selectors are shifted left 4 bits (one nibble, or that extra '0').
In pmode no such shifting takes place, so you must access 0xB8000 directly.
Hope this helps,
James
Posted: Sat May 17, 2008 6:02 am
by kmtdk
well, i have tried with directly, without, with 3 0's and 2 0's
but nothing helps
...
KMT
Posted: Sat May 17, 2008 6:06 am
by JamesM
So what code are you executing? can you post a snippet? I can't help you if you don't give me information!
Posted: Sat May 17, 2008 7:24 am
by Dex
Posted: Sat May 17, 2008 10:19 am
by svdmeer
Are your segment-registers and segment-descriptors setup right?
De base must be 0, otherwise an offset of 0xb8000 won't work.
Ofcourse you can a base > 0, but your offset will became different, a base of zero must work.
Did you setup the protected mode well?
What didn't work? Did only nothing appear on your screen, does the computer reboot or freeze?
Maybe (I don't think that's your problem) you are not in the right videomode. Execute the instructions "MOV AX,3" and "INT 0x10" (setting mode 3 textmode 80x25 color by calling the BIOS) before entering protected mode.
Re: Pmode screen printing, asm, using Flat assembler
Posted: Sat May 17, 2008 10:22 am
by svdmeer
kmtdk wrote:Hi all out there, i have a littel problem i pmode.
When try to write to memory location: 0xb800, it dont.
after some time analysion what ´happend, I found out that a error happend using FASM.
i typede in the code:
mov edi,0xb8000
, but at runtime it was RDI=000000000008b800
Can someone solve this problem
Hmmm strange.. I assume you like to use 32-bit code.
If FASM set to use 32-bit code and addressing?
Are your segmentdescriptors set to use 32-bit segments? Maybe you are using a 16-bit segment, what can explain the strange value of EDI.
Posted: Sun May 18, 2008 5:10 am
by kmtdk
I use the gdt from
http://www.brokenthorn.com/Resources/OSDev8.html,
and i had set a20.
The segement is 32 bit.
I dont know if Fasm is set to 32 bit, but i can use it.
the code, all or the printing.
the printing is all types, in- and directly.
i just attachmented the code, atfer the bootsector.
KMT
Posted: Sun May 18, 2008 10:14 am
by svdmeer
The code is a messy.
I assume the first part (in realmode) prints? The messages ver and kernmsg appear on screen?
And after the proctedmode switch?
The code you uploaded is does not contain the code from your question.
First the code is running in realmode, doing some realmode screen-writing. After that, it switches to 32-bit protectedmode. So first 16-bit code is needed, after the pm-switch 32-bit. But nowhere inside the code the assembler is told to use 32-bit or 16-bit code.
I don't use Fasm, so I don't know it's defaults, but Fasm uses 16-bit or 32-bit for all the code. When the first strings appear on screen, it seems Fasm uses 16-bit code. Your pm-part will not work, you need a directive to tell Fasm the piece of code after the far-jump to protected-mode codesegment is 32-bit.
When the first part of your program isn't working, maybe fasm is using 32-bit for the whole program.
Maybe you can temporary remove your printing-code, and use a really simple piece of test-code.
Testing in your real-mode part:
Code: Select all
mov ax,0xb800
mov es,ax
mov byte [es:0],'R'
mov byte [es:1],0x1f
In your protected-mode part:
Code: Select all
mov byte [0xb8004],'P'
mov byte [0xb8005],0x1f
Posted: Mon May 19, 2008 12:23 am
by TNick
Hello!
Did not had the time to take a proper look at your code. Anyway, at the beginning of your file you should insert
and, after "Stage3" label
Also, in setpmode, you set interrupt flag and you clear it again ... ?! And you go with the flag cleared untill the end. A IDT would be also usefull at one point ...
The purpose of use16 - use32 is that - when in protected mode - the CPU interprets instructions a 16 bit. Once you step in protected mode, CPU espects 32 bit instruction. But be carefull if you nest 16 and 32 bit code. For example, if you have Real Mode (16 bit) code at the start of the file, then code that is executed in Protected Mode (32 bit), and then some procs that you call in Real Mode, you should use "usexx" before each of them:
Code: Select all
org 0x1000
use16
; ... some real mode code
mov eax, cr0
or eax, 1
mov cr0, eax
jmp ChangeCS
ChangeCS:
use32
; ... some code
hlt
use16
EnableA20:
; ...
ret
;(assuming you get to 0x1000 by relocating yourself. If you read this pice of code from the disk, then this proc should obviously be placed in first sector.
ReadDisk16:
; ...
ret
Regards,
Nick
Posted: Mon May 19, 2008 5:42 am
by kmtdk
Hey and thanks for the help.
the problem was, that it lookede the code as 16 bit.
and i apologies for the bad upseting of the postede code.
KMT