Bona Fide OS Developer
View unanswered posts | View active topics It is currently Sat Jun 23, 2018 4:35 pm



Post new topic Reply to topic  [ 2 posts ] 
 Iterate through memory 
Author Message

Joined: Mon Oct 26, 2009 2:33 pm
Posts: 38
Location: United Kingdom
Post Iterate through memory
Hi All

Now that the forums have been de-spammed I can actually post and not feel like it's going to get swallowed up.

I've got a problem that's causing me a lot of headaches, but I hit a wall yesterday at about 11pm which my mind decided it couldn't work out.

Basically, I'm rewriting my bootloader (yes, again). This time I've written a C program on my linux box that takes a directory and writes it to floppy disk, marking a file starting $_ as bootable. Basically, I want to be able to drag-drop files into this folder and then write to disk, and not worry about where my kernel is on the disk. So I wrote my own very simple filesystem. So basically, I have my default bootloader which sits in the first 512 Byte sector of the disk. This 512 Bytes then searchs the FAT for a file marked as bootable, loads that into memory and voila hey presto it's all fan dabby dozy.

Now I've successfully loaded the FAT into memory (not particularly difficult) but now I need to iterate through that memory starting from one address, and incrementing by 37 bytes each time and checking whether that byte is 0 or non-zero.

The problem I'm having is that I've worked out the address for each 'bootable byte' but that is stored at a memory location (which in code is stored in [offset]), but I can't work out how to read from that location. Ideally what I need is something like

mov ax, [offset]
mov bx, [ax]

cmp bx, 1
jne dosomething:

The problem is obviously this doesnt work, long and short of it, I've got a pointer to a pointer and can't work out how to read through it.

There is probably a much much simpler way of doing things, but would appreciate some input.

And before anyone asks, I used my own filesystem because I can ;)

Thanks in advance.

_________________
Andy Esser
neogenix Broadcast


Thu Apr 29, 2010 7:15 am
Profile
Site Admin

Joined: Fri Jul 24, 2009 10:02 pm
Posts: 247
Location: Las Vegas, NV, US
Post Re: Iterate through memory
Wow, no one every replied to you? Odd.

As far as rewriting your bootloader, congrats! Every version is that much better :)

Now as far as referencing a pointer to a pointer in ASM I am still trying to understand your goal. First what is 'offset' and what is the 'base' address?

Assuming 'offset' = 0x10, then 'ax' will = 0x10 and 'bx' will be the value stored in memory at 0x10. If that value != 1, then you jump to the 'dosomething' label and continue there.

Code:
mov ax, [offset]
mov bx, [ax]

cmp bx, 1
jne dosomething


I'm a little rusty on assembly, I'll be honest. But maybe you can clarify what you're trying to do by explaining your code a little more?

Here's a nice summary of pointers in assembly: http://www.friedspace.com/assembly/pointers.php


Mon Mar 07, 2011 5:27 am
Profile
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 


Who is online

Users browsing this forum: No registered users and 1 guest


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 post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by Vjacheslav Trushkin and tweaked by the BF Team.