I wrote a simple C program with this code:
Code: Select all
char *vidmem = (char*)0xb8000;
void main()
{
int i=0;
vidmem[i]='A';
i++;
vidmem[i]=0x07;
for(;;);
}
Code: Select all
OUTPUT_FORMAT("binary")
phys = 0x00200000;
SECTIONS
{
.text phys : AT(phys) {
code = .;
*(.text)
. = ALIGN(4096);
}
.data : AT(phys + (data - code))
{
data = .;
*(.data)
. = ALIGN(4096);
}
.bss : AT(phys + (bss - code))
{
bss = .;
*(.bss)
. = ALIGN(4096);
}
end = .;
}
I used a program called raw2c that generates a string from the binary and gives me a pointer to it and the size of the string in order to include that binary in my kernel (no filesystems yet).
Getting it into RAM was just a matter of this code:
Code: Select all
unsigned char *destptr = (unsigned char*)0x200000;
memcpy(destptr, test, test_size);
Code: Select all
__asm__ ("jmp 200000");
Can any of you spot what is wrong? If not, are there any comprehensive documents on loading user programs within an OS? As far as I've seen, there aren't any, and this is tricky stuff.