Bona Fide OS Development

Iterate through memory
Page 1 of 1

Author:  AndyEsser [ Thu Apr 29, 2010 7:15 am ]
Post subject:  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.

Author:  brenden [ Mon Mar 07, 2011 5:27 am ]
Post subject:  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.

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:

Page 1 of 1 All times are UTC - 6 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group