Code: Select all
xor ax,ax
mov ds,ax
lgdt [gdtr]
; set PE [protected mode enable] bit and go
mov eax,cr0
or al,1
mov cr0,eax
jmp SYS_CODE_SEL:do_pm
[BITS 32]
do_pm:
mov ax,SYS_DATA_SEL
mov ds,ax
mov ss,ax
mov es,ax
mov fs,ax
.
.
.
.
.
.
SYS_CODE_SEL equ $-gdt
gdt1: dw 0xFFFF
dw 0
db 0
db 0x9A ; present, ring 0, code, non-conforming, readable
db 0xCF
db 0
SYS_DATA_SEL equ $-gdt
gdt2: dw 0xFFFF
dw 0
db 0
db 0x92 ; present, ring 0, data, expand-up, writable
db 0xCF
db 0
What is contained in esp as i havn't set it.
I'll jump to C code for rest of my kernel.I think c language uses this stack pointer.
Can u please explain the role of stack pointer .and what might happen if i don't set it.
As u see in the code both code and data selectors have same base and limit.But code segment is readable and data segment is writable.
Please explain how same memory can be both readable and writable as both code and data selectors
point to same memory.
Is there any possibility that i may overwrite my code as both code and data segments point to same memory.And if this possibility is true please suggest me what should i move in code and data selectors to avoid code overwriting by data.