Reading File From Memory

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
whyme_t

Reading File From Memory

Post by whyme_t »

I wanted to read some files from memory before I write a floppy driver.

I got grub to load a text file for me, it loads it at 0x106000, and tells me it is 0x2c bytes in size.

Code: Select all

unsigned char *mem ;
char c ;
unsigned int i ;
for(i=0; i<0x2c; i++)
{
   mem = (unsigned char *)0x106000 ;
   c = mem[i] ;
   std::cout.put(c) ;
}
This code doesn't work, but by reading beyond 0x2c, I discovered that the text in the file is actually located at 0x107000.

Why is this?

It's a regular text file created with TextPad, no header information (as far as i know!), I've tested with both DOS ASCII format and ANSI, both produce the same.

-EDIT: How do you detect EOF?
jrfritz

Re:Reading File From Memory

Post by jrfritz »

Maybe it's because the text file is so big it puts it there?

Possibly?....
jrfritz

Re:Reading File From Memory

Post by jrfritz »

EOF is a hex number...i'm getting it...

Ok here it is: 0x7F

if ( text == 0x7F ) then
end of file = TRUE;
whyme_t

Re:Reading File From Memory

Post by whyme_t »

This is the text file ;)

Code: Select all

Test file.
Hello World!.
Does this work?
Just 3 lines, hence the size of the file 0x2c.
jrfritz

Re:Reading File From Memory

Post by jrfritz »

OPPS here is correct:

if ( currentcharacter == 0x7F ) then
end of file = TRUE;
Tim

Re:Reading File From Memory

Post by Tim »

whyme_t wrote:-EDIT: How do you detect EOF?
You go beyond the end of the file. GRUB tells you the length as well as the base address of all the modules it loads. Where did you get the number 0x106000 from? You should find that in the multiboot module list.
whyme_t

Re:Reading File From Memory

Post by whyme_t »

before grub loads the kernel it displays the base address and size in bytes. I wrote it down and used that. But The text in the file is definitely at 0x107000.
Post Reply