POV-Ray : Newsgroups : povray.off-topic : Tell me it isn't so! : Re: Tell me it isn't C Server Time
15 Nov 2024 02:27:28 EST (-0500)
  Re: Tell me it isn't C  
From: Darren New
Date: 23 Jul 2009 13:05:46
Message: <4a68986a$1@news.povray.org>
Invisible wrote:
> One assumes that if you don't need foo(), you wouldn't bother including 
> the header file. 

You may use printf() without using sprintf(), fprintf(), and vprintf(). But 
they're all in the same header file.

In any case, I'm telling you what's *correct*, regardless of whether you 
think it's good style. :-)

>> Sort of. That's called "linking." Then there's "loading", which is 
>> when you put it into memory and *again* adjust a bunch of addresses.
> 
> Right. So what you're saying is that there's actually a second linking 
> stage each time final executable is run?

No, there's loading. :-) If the software does both steps, then it's a 
"linking loader".

But yes, there can be multiple linking phases, especially with DLLs and such.

If you have code compiled to run at 0x100 and you copy it from disk to 
memory at 0x300, you need to add 0x200 to every address that points into the 
program. That's loading. Often not needed nowadays with CPUs that can handle 
code that uses only relative offsets.

> In summary... you can't call the OS from C. You can only write C wrapper 
> functions around the assembly code that calls the OS. (And the wrapper 
> then of course looks like a normal C function...)

Right. Generally speaking.

I've always wondered why people think C is good for writing kernel-level 
code, as the only facility in C that actually deals with the sorts of things 
you do in a kernel is "volatile".

>> It's an instruction that invokes an indirect branch.
> 
> I see. So that's the mechanism on the IA32 platform, is it? (I thought 
> only the BIOS uses this method...)

I believe so. I stopped paying attention around the 286 era.

> Interestingly enough, the Motorola 68000 does in fact have two modes of 
> operation: "user mode" and "supervisor mode". I have no idea what the 
> distinction is.

Some opcodes in user mode will cause a software interrupt instead of doing 
what they do in supervisor mode. For example, trying to turn off the 
interrupts will "trap" instead of turning off the interrupts. (Really? 
68000? Not 68020?)

> the MMU-enabled variant of the CPU could support memory protection if 
> you wanted.

Yes. There's actually two things you need for demand-paged VM. You need 
virtual addressing (which the 68010 supported, I think), and you need 
restartable instructions (which the 68020 supported). If you try to store 
four bytes, and the first two bytes get stored and the second two hit a page 
that has to be swapped in, you're kind of hosed if your processor doesn't 
deal with that properly. (Say, by checking before you store anything that 
all the pages are available, or "unwriting" the failed write, or something.)

> And finally, it's perfectly possible to make a multiuser OS without 
> memory protection. It just won't have any memory protection.

You can do the memory protection in software, tho. Not *too* uncommon.

-- 
   Darren New, San Diego CA, USA (PST)
   "We'd like you to back-port all the changes in 2.0
    back to version 1.0."
   "We've done that already. We call it 2.0."


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.