Author Topic: Program to demonstrate the use of paging tables please help me with the errors  (Read 3537 times)

Offline priyanshus1@gmail.com

  • Jr. Member
  • *
  • Posts: 2

dr0    equ 0
drw    equ 1
sr0    equ 2
srw    equ 3
ceo    equ 4
cer    equ 5
cco    equ 6
ccr    equ 7

SECTION .code
p_en proc far

mov eax,1000h
mov ebx,1000h
mov cl, drw
mov ch,0

call create_desc
or eax,eax
jl err

mov es,ax
mov edi,o
mov eax,0
mov ecx,1024
rep stosd
mov dword ptr es:[0],00002003h
mov dword ptr es:[0ffch],00003003h

;make first page table


mov eax,2000h
mov ebx,1000h
mov cl,drw
mov ch,0
call create_desc
or eax,eax
jl err
mov es,ax
mov edi,0
mov eax,00000003h
mov ecx,1024

TAB1:
   stosd
   add eax,1000h
   loop tab1
   ;activate paging
   mov eax,1000h
   mov cr3,eax
   pushfd
   cli
   mov eax,cr0
   bts eax,31
   mov cr0,eax
   jmp flu

flu:
   nop
   popfd
   ret

err:
   ret
   p_en endp
   end
   create_desc proc far
   push edx
   push eax
   call f1_gdt
   mov edx,eax
   pop eax
   or edx,edx
   jl err1

;determine base address:
mov dword ptr ds:[edx*8]+2,eax
rol eax,8
dec ebx
cmp ebx,0fffff h
ja p_gran
mov word ptr:ds[edx*8]+0,bx
rol ebx,16
mov byte ptr:ds[edx*8]+6,bl
ror ebx,16
and byte ptr ds:[edx*8]+6,ofh
or byte ptr ds:[edx*8]+6,40h
jmp seg_type
p_gran:
   shr ebx,12
   mov word ptr:ds[edx*8]+0,bx
   rol ebx,16
   mov byte ptr:ds[edx*8]+6,bl
   ror ebx,16
   and byte ptr ds:[edx*8]+6,ofh
   or byte ptr ds:[edx*8]+6,0c0h
seg_type:
   mov byte ptr ds:[edx*8]+5,0
   cmp al,ccr
   ja err1
   shl cl,1
   or byte ptr ds:[edx*8]+5,cl


privilege_level:
   movzx ax,ch
   mov bx, word ptr ss:[esp]+4
   arpl ax,bx
   shl al,5
   or byte ptr ds:[edx*8]+5,al
   or byte ptr ds:[edx*8]+5,90h
   mov ax,dx
   mov ax,3
   arpl ax,bx
   pop edx
   ret

err1:
   pop edx
   mov eax,0
   dec eax
   ret
   create_desc endp
   end

f1_gdt:
   porc far
   push ebx
   push ecx
   mov bx,ds
   movzx ebx,bx
   lsl ecx,ebx
   shr ecx,3
   jecxz l1
   mov eax,0

l2:
   inc eax
   cmp byte ptr ds:[eax*8]+5,0
   loopnz 12
   jnz l3

l1:
   pop ecx
   pop ebx
   ret

l3:
   pop ecx
   pop ebx
   mov eax,0
   dec eax
   ret

f1_gdt:
   endp
   end







« Last Edit: October 05, 2013, 04:30:10 PM by priyanshus1@gmail.com »

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2436
  • Country: us
"porc far"? This isn't even Masm code! What's it supposed to do? What OS is it supposed to run under? You've gotta be kidding!

There's a nice section in the Manual about differences between Masm and Nasm. Maybe that'll help you get started.

Best,
Frank


Offline priyanshus1@gmail.com

  • Jr. Member
  • *
  • Posts: 2
Frank,
I have updated the code will you please have a look

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2436
  • Country: us
What have you tried?

Best,
Frank