Page 1 of 1

Reading File From Memory

Posted: Mon Jan 13, 2003 4:15 pm
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?

Re:Reading File From Memory

Posted: Mon Jan 13, 2003 4:20 pm
by jrfritz
Maybe it's because the text file is so big it puts it there?

Possibly?....

Re:Reading File From Memory

Posted: Mon Jan 13, 2003 4:22 pm
by jrfritz
EOF is a hex number...i'm getting it...

Ok here it is: 0x7F

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

Re:Reading File From Memory

Posted: Mon Jan 13, 2003 4:22 pm
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.

Re:Reading File From Memory

Posted: Mon Jan 13, 2003 4:24 pm
by jrfritz
OPPS here is correct:

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

Re:Reading File From Memory

Posted: Mon Jan 13, 2003 4:26 pm
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.

Re:Reading File From Memory

Posted: Mon Jan 13, 2003 4:29 pm
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.