flat assembler
Message board for the users of flat assembler.

flat assembler > OS Construction > HelloWord from protected mode restars a comp

Author
Thread Post new topic Reply to topic
terex



Joined: 31 Dec 2003
Posts: 16
Location: Saint-Petersburg, Russia
There are many examples of code which switchs to pm and do anything there. I tried to wrote a DOS COM application (one segment for code, data & stack), and i have a trouble Sad This code, which must switch to segment-addressing protected mode does not do what a i wait. It just restarts a comp. Please help me to understand what is wrong in whis code:
Code:
; 2pm.asm

format binary

   use32
   org   0x100 ; DOS COM application

   ; clear screen
   mov   ax, 0x3
   int   0x10

   ; open A20-line
   in    al, 0x92
   or    al, 0x2
   out   0x92, al

   ; calculate linear address of protected mode entry point
   xor   eax, eax
   mov   ax, cs
   shl   eax, 0x4
   mov   ebx, eax
   add   eax, pm_entry_point
   mov   [pmep], eax

   ; calculate linear address of global descriptor table
   mov   eax, ebx
   add   eax, gdt
   mov   [gdtr_address], eax

   ; load global descriptor table
   lgdt  fword [gdtr]

   ; disable maskable interrupts
   cli

   ; disable non maskable interrupts
   in    al, 0x70
   or    al, 0x80
   out   0x70, al

   ; switch to protected mode
   mov   eax, cr0
   or    al, 0x1
   mov   cr0, eax

   ; load new selector to CS reister
   db    0x66  ; prefix to change operand capacity
   db    0xEA  ; opcod of JMP FAR command
   pmep  rd 1  ; 32-bit offset
   dw    00001000b ; selector of the first descriptor

; Global Descriptor Table
gdt: times 8 db 0x0

; Descriptors

; code segment descriptor: base = 0x0, size = 0xFFFFFFFF, 32bit, DPL=3
dCode  db 0xFF, 0xFF, 0x0, 0x0, 0x0, 10011100b, 11001111b, 0x0

; data segment descriptor: base = 0x0, size = 0xFFFFFFFF, 32bit, DPL=3
dData  db 0xFF, 0xFF, 0x0, 0x0, 0x0, 10010100b, 11001111b, 0x0

; video segment descripor: base =  0x0B80, size = 0xFFFF, 32bit, DPL=3
dVideo db 0FFh, 0FFh, 00h, 80h, 0Bh, 10010100b, 00000010b, 00h

; Global Descriptor Table Size
szgdt  db $ - gdt

; Data to be loaded into gdtr
gdtr:
gdtr_size dw szgdt - 1 ; size of global descriptor table
gdtr_address rd 1      ; linear address of global desriptor table

; message which will be printed with in protected mode
; (hello from pm, every symbol with attribute 0x7)
msg_hello_from_pm db 'h',7,'e',7,'l',7,'l',7,'o',7,' ',7,'f',7,'r',7,'o',7,'m',7,' ',7,'p',7,'m',7
szmsg_hello_from_pm dd  $ - msg_hello_from_pm ; size of string (include attributes)

align 0x4
pm_entry_point:

   ; linear address of message to ESI
   xor   esi, esi
   mov   si, ds
   shl   esi, 0x4
   add   esi, msg_hello_from_pm

   ; define symbolic names for segment selectors
   SDATA equ 00010000b ; dData segment selector
   SVIDEO equ 00011000b ; dVideo segment selector

   ; selector for dData segment to DS
   mov   ax, SDATA
   mov   ds, ax

   ; selector for a dVideo segment to ES
   mov   ax, SVIDEO
   mov   es, ax

   ; print 'hello from pm'
   xor   edi, edi ; position on the screen (relativy from base of dVideo segment 0B8000h)
   mov   ecx, [szmsg_hello_from_pm]
   rep   movsb

   jmp   $
    
Post 31 Dec 2003, 02:38
View user's profile Send private message Visit poster's website Reply with quote
terex



Joined: 31 Dec 2003
Posts: 16
Location: Saint-Petersburg, Russia
I found a mistake! It is here:
Code:
; print 'hello from pm' 
   xor   edi, edi 
   mov   ecx, [szmsg_hello_from_pm] 
   rep   movsb
    


We are in pmode now, but i use traditional real-mode addresation to put value by address szmsg_hello_from_pm into ecx. I rewrote it like this:
Code:
   xor   edi, edi 
   xor   eax, eax
   mov   ax, ds
   shl   eax, 0x4
   add   eax, szmsg_hello_from_pm
   mov   ecx, [ds:eax]
   rep   movsb
    

and everithing became fine!

_________________
sorry for my english
Post 02 Jan 2004, 01:32
View user's profile Send private message Visit poster's website Reply with quote
Mac2004



Joined: 15 Dec 2003
Posts: 313
Hi Terex!!

I found that you we're using 'use32' instruction in your code. You cannot use 16bit realmode ints like int 0x10 afterwards 'use32' instruction. This surely causes your computer to restart.

You need to use 'use16' instruction at the start and when reach actual pmode code 'use32' instruction is needed.

regards,
Mac2004
Post 30 Jun 2004, 06:31
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2019, Tomasz Grysztar.

Powered by rwasa.