flat assembler
Message board for the users of flat assembler.

Index > Main > Write to memory adress

Author
Thread Post new topic Reply to topic
VelcroMan



Joined: 14 Feb 2010
Posts: 7
Location: Sweden
VelcroMan
Hi there, i'm looking at some documents regarding the video memory.
I'm experimenting with a small bootloader/bootsector.

The document author uses nasm, and fasm's syntax is different in that case i think.

In nasm you would write a character like this:
Code:
mov 0B8000, 'N'
mov 0B8001, 1Bh    


I tried to rewrite it for fasm and ended up with this:
Code:
mov byte [0B8000h], 'N'
mov byte [0B8001h], 1Bh    


Am i wrong with my rewrite here? The reason i'm asking is that i don't see the character, and i need to know if it's my character output that doesn't work, or if the bootloader stops earlier Wink

If that code is correct, i have a problem elsewhere. Here is the full code if anyone would like to help: http://pastebin.com/m662156c2
It builds without problems
Post 14 Feb 2010, 08:55
View user's profile Send private message MSN Messenger Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17344
Location: In your JS exploiting you and your system
revolution
I don't think you SS and DS are correct:
Code:
        mov ax, 08h                     ;Store the code segment adress in ax
        mov ss, ax                      ;Fill the stack segment register with the adress
        mov ds, ax                      ;Fill the data segment register with the adress    
You will need to load them with a different descriptor. 0x10 maybe?

BTW: your syntax above is correct.
Post 14 Feb 2010, 08:59
View user's profile Send private message Visit poster's website Reply with quote
VelcroMan



Joined: 14 Feb 2010
Posts: 7
Location: Sweden
VelcroMan
revolution wrote:
I don't think you SS and DS are correct:
Code:
        mov ax, 08h                     ;Store the code segment adress in ax
        mov ss, ax                      ;Fill the stack segment register with the adress
        mov ds, ax                      ;Fill the data segment register with the adress    
You will need to load them with a different descriptor. 0x10 maybe?

BTW: your syntax above is correct.


Changing the value to 10h or similiar does not fix the problem. As the syntax is correct there must be a problem elsewhere. I don't really know where though..

This is document/tutorial i'm reading: http://www.osdever.net/tutorials/view/the-world-of-protected-mode
Post 14 Feb 2010, 09:04
View user's profile Send private message MSN Messenger Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17344
Location: In your JS exploiting you and your system
revolution
VelcroMan: There is lots of PM setup/entry code in this forum. Have you tried searching here? Lots of people have posted working code similar to yours.
Post 14 Feb 2010, 09:07
View user's profile Send private message Visit poster's website Reply with quote
VelcroMan



Joined: 14 Feb 2010
Posts: 7
Location: Sweden
VelcroMan
I fixed the error(s) in the code so it works fine now.
I downloaded the sourcecode for the article and looked through it, and there were a few changes not shown in the article, so i hade a few errors.

If anyone are interested, a working fasm version of http://www.osdever.net/tutorials/view/the-world-of-protected-mode is avliable here: http://pastebin.com/f2c5ee886

And thank you revolution for your help Smile
Post 14 Feb 2010, 09:30
View user's profile Send private message MSN Messenger Reply with quote
asmmsa



Joined: 06 Feb 2010
Posts: 45
asmmsa
bootloaders run in real mode, to u have to use segment registers to pass > 65k address.

try:
mov ax,0xb800
mov ds,ax
mov [0],0x1B70
Post 14 Feb 2010, 10:11
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
asmmsa wrote:
bootloaders run in real mode, to u have to use segment registers to pass > 65k address.


Don't you see the code enabling PM ???? Evil or Very Mad

Code:
        mov byte [ds:0B8000h], 'N'
        mov byte [ds:0B8001h], 1Bh
    


This is good, just the "ds:" prefix is unnecessary as it is the default anyway Wink

Code:
        
        mov esp, 90000h         ;500h to 9FFFFh are free memory.
    


This is good but unnecessary as long as you don't use the stack.

Quote:

; Same as in the code segment, except that we have read/write


A few bits have different meaning Wink

Quote:

We want to expand down, so this bit should be cleard.


WRONG.

http://www.sudleyplace.com/dpmione/expanddown.html

Quote:

is from 64KB - 1 (0FFFFh) to 1MB - 1 (0FFFFFh) inclusive


The MA$M syntax is horrible, again Sad
Post 14 Feb 2010, 12:02
View user's profile Send private message Reply with quote
asmmsa



Joined: 06 Feb 2010
Posts: 45
asmmsa
Quote:
This is good, just the "ds:" prefix is unnecessary as it is the default anyway Wink

actually, fasm should add DS override prefix to instruction when writing ds:

ok i didnt even saw this code, my mistake.

db gdt_end - gdt should be - 1, its not size but sizie -1, for unknown reasons.

#
cli ;Disable interrups

you dont disable int 2, it can appear as any other one.
i belive you should do something witn port IO wich APIC to disable routing interrupts to current cpu, interrupt flag is useless, i think so.


you should also check if cpu support protected mode, but only when you write something serious, here you dont have to.


#
mov ax, 08h ;Store the code segment adress in ax
#
mov ss, ax ;Fill the stack segment register with the adress
#
mov ds, ax ;Fill the data segment register with the adress
you store 0x08 segment in ss and ds, it goes only to cs.

#
mov esp, 90000h ;500h to 9FFFFh are free memory. Our bootloader originates at 7C00h, so if we put our stack at 90000h we have enough memory (FFFFh) and out code have a lot of room

why you assume this address holds ram, not memory mapped something?

#
hang: ;Hang the cpu
#
jmp hang


try jmp $, shorter. or cli + hlt, shouldnt be interrupted, if nmi fires just use jmp $.
Post 14 Feb 2010, 13:39
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-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.