i've some trouble after have switched to protected mode: all is working fine, except for the stack. I've created a GDT, with a code, and data/stack segment descriptors. Segment limit is at 0xFFFFFF, granularity at 4K. For some reason, if i set "esp" register to a value greater than 0xffff, (major than 64K), all the stack read/write operations fail.
I attach the pm mode setup steps, and gdt.
Code: Select all
jmp $8, $protected
/* clear 16 bit pipeline garbage */
.code32
protected:
mov $datasel, %ax
mov %ax, %ds
mov %ax, %ss
mov %ax, %fs
mov %ax, %es
movl $0x10000, %esp
mov $videosel, %ax
mov %ax, %gs
call _kmain
gdtinfo: .word (gdtend - gdt -1)
.long gdt
gdt: .long 0 /* null descriptor, as per convention gdt0 is 0 */
.long 0
.equ codesel, .- gdt
desc_code: /* 32bit Flat Data, 0-4GB Writable */
.word 0xFFFF /* segment limit 0:15 */
.word 0 /* base address 0:15 */
.byte 0 /* base address 16:23 */
.byte 0x9A /* 1xP|2xDPL|1xS|4xtype 0x9A = 1|0 0|1|1010 */
.byte 0xCF /* 1xG|1xD/B|1x0|1xAVL|4xlimit 0xCF = 1|1|0|0|1111 */
.byte 0 /* base address 24:31 */
.equ datasel, .- gdt
desc_data:
.word 0xFFFF /* segment limit 0:15 */
.word 0 /* base address 0:15 */
.byte 0 /* base address 16:23 */
.byte 0x92 /* 1xP|2xDPL|1xS|4xtype 0x92 = 1|0 0|1|0010 */
.byte 0xCF /* 1xG|1xD/B|1x0|1xAVL|4xlimit 0xCF = 1|1|0|0|1111 */
.byte 0 /* base address 24:31 */
.equ videosel, .- gdt
desc_video:
.word 3999 /* segment limit 0:15 */
.word 0x8000 /* base address 0:15 */
.byte 0x0b /* base address 16:23 */
.byte 0x92 /* 1xP|2xDPL|1xS|4xtype 0x92 = 1|0 0|1|0010 */
.byte 0x00 /* 1xG|1xD/B|1x0|1xAVL|4xlimit 0x00 = 0|0|0|0|0000 */
.byte 0 /* base address 24:31 */
gdtend:
Every help or suggestion is very appreciated.
Angelo
[/code]