Page 1 of 1

Random Assortment of Questions

Posted: Mon Jul 06, 2009 1:38 pm
by brodeur235
I'm on a vacation in which I spend long periods of time in a cottage, on a beautiful beach on a lake in southern Canada. One problem: I sort of go into withdrawal when I don't have an internet connection for a while (and I don't there), so I began designing the memory management portion of my os while I was there on paper, writing down questions I came up with. I've answered some of them with quick research but the others I'll post here.

1. How can I read from and write to hard disk without BIOS interrupts in asm?

2. How can process code call a kernel function? (my os uses paging. So how can a process address a function outside of it's virtual memory?)

Warning: possibly a really stupid question.
3. I have no way of testing this on the machine that I have access to now (If I did, I wouldn't ask) but as it is I really want to know now. How can I compile a C file to flat binary using GCC? Does it automatically do this?

Brodeur235

Re: Random Assortment of Questions

Posted: Mon Jul 06, 2009 1:53 pm
by madeofstaples
brodeur235 wrote:1. How can I read from and write to hard disk without BIOS interrupts in asm?
It depends on the hardware. You are probably looking for ATA/ATAPI information.
brodeur235 wrote:2. How can process code call a kernel function? (my os uses paging. So how can a process address a function outside of it's virtual memory?)
See System Calls
brodeur235 wrote:3. I have no way of testing this on the machine that I have access to now (If I did, I wouldn't ask) but as it is I really want to know now. How can I compile a C file to flat binary using GCC? Does it automatically do this?
See Linker Scripts

Re: Random Assortment of Questions

Posted: Mon Jul 06, 2009 11:35 pm
by brodeur235
My linker script isn't working. The 'ld' program doesn't recognize the -T option. Here are the sources:

begin.asm

Code: Select all

extern _main
call _main
kern.c

Code: Select all

void main()
{
	for(;;) { }
}
lkr.ld

Code: Select all

OUTPUT_FORMAT("binary")
ENTRY(begin)
bash script:

Code: Select all

echo Now compiling and linking your kernel . . .
echo 
echo Assembling "begin.asm" . . .
nasm begin.asm -f aout -o begin.o
echo Completed.
echo 
echo Compiling "kern.c" . . .
gcc kern.c -c -o kern.o
echo Completed.
echo 
echo Linking with script "lkr.ld" . . .
ld -o kernel.bin kern.o begin.o -T lkr.ld
echo Completed.
output:

Code: Select all

Now compiling and linking your kernel . . .

Assembling begin.asm . . .
Completed.

Compiling kern.c . . .
kern.c: In function 'main':
kern.c:2: warning: return type of 'main' is not 'int'
Completed.

Linking with script lkr.ld . . .
ld: unknown flag: -T
Completed.
What's the problem here?

Brodeur235

Re: Random Assortment of Questions

Posted: Tue Jul 07, 2009 1:29 am
by Combuster
GCC Cross-Compiler

This whole thread also defeats the smart questions rule, and the first post is nothing but couldn't-google-questions. That makes three violations in two posts. :(