Author Topic: problem with text in pmode  (Read 20173 times)

nobody

  • Guest
problem with text in pmode
« on: October 17, 2004, 10:31:27 PM »
after i have booted up gone into pmode i am not able to write strings to the screen with the loop below... i am able to set values in al manually for the stosw operation... but am not able to load values from within the program... why is this?

...boot loader...

[BITS 32]
clear_pipe:
        mov ax,0x10
        mov ds,ax
   mov es,ax
        mov ss,ax
        mov esp,0x90000
p:
   mov esi,msg
   mov edi,0xb8000
pc:
   lodsb
   mov ah,0x1f
   stosw
   or al,al
   jne pc
endofprog:
   jmp endofprog
msg db "if you cannot see this then something is wrong",0

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: problem with text in pmode
« Reply #1 on: October 17, 2004, 11:18:49 PM »
What's the origin of the code where this appears? It wants to be zero - assuming selector 0x10 refers to a descriptor with base=0... If this is still part of a bootsector at org 7C00h, there's your problem...

Best,
Frank

nobody

  • Guest
Re: problem with text in pmode
« Reply #2 on: October 18, 2004, 03:53:07 AM »
the bootloader loads this block of code to 0x10000.... here is the bootloader

org 0x7c00
start:
reset:         ;reset drive
   xor ax,ax
   mov bx,ax
   int 0x13
   jc reset
read:         ;load sectors off drive
   xor ax,ax
   mov bx,ax
   mov dx,ax
   mov ax,0x1000
   mov es,ax
   mov ax,0x210
   mov cx,0x2
   int 0x13
   jc read
off:         ;turn off floppy motor
   mov dx,0x3F2
   mov al,0xc0
   out dx,al
pmode:
   jmp 0x1000:0
        cli      ;disable interrupts and clear direction flag
   cld
   in al,0x92   ;enable a20
        or al,2
        out 0x80,al
        out 0x92,al
        xor ax, ax      ;move ds 0
        mov ds, ax
        lgdt [gdt_desc]      ;load gdt
        mov eax,cr0      ;set cr0 0 bit
   or eax,1
   mov cr0,eax
        jmp dword 0x8:0x10000   ;jmp to loaded code
gdt:
   dd 0x0      ;gdt null 0x0
        dd 0x0
        dw 0xffff   ;gdt data 0x8
        dw 0x0
        db 0x0
        db 0x9a
        db 0xcf
        db 0x0
        dw 0xffff   ;gdt code 0x010
        dw 0x0
        db 0x0
        db 0x92
        db 0xcf
        db 0x0
gdt_end:
gdt_desc:
        dw gdt_end - gdt - 1
        dd gdt
   times 510-($-$$) db 0
   dw 0x0aa55

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: problem with text in pmode
« Reply #3 on: October 18, 2004, 10:46:25 AM »
So the "jumped to" code should be assembled at "org 0x10000", right? If you can get a character on screen by putting it in al as an immediate, everything's working so far - you've loaded the "second stage" where you intended to put it... and it was on the floppy where you intended... two things that are likely to go wrong. So if you can't get the character you intend by "mov esi, msg"/"lodsb", "msg" must have the wrong value. You don't *show* any "org" directive in that code - Nasm would default to "org 0", so the value calculated for "msg" would be its offset into the file - a couple dozen bytes. You need "msg" to be 10000h + a couple dozen...

That's the only thing I can think of - everything else looks great!

Best,
Frank

P.S. You *are* copying the terminating zero to the screen (or will be, when it works) - probably not really what you want, but it shouldn't do any harm.