What are the basic kernel operations which require assembly?

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
anadon
Posts: 7
Joined: Thu Jan 05, 2012 8:12 pm

What are the basic kernel operations which require assembly?

Post by anadon »

What are the basic kernel operations which require assembly?

I'm looking around and learning what I can about assembly. I've got the basic concepts, and will be practicing as well. But, I want to know what to keep an eye out for in terms of parts of the kernel which should be done in assembly. More specifically, amd64. Very specifically--Intel i7 740QM.

I know this is beginner, but hey, its where I'm at.

And yes, my C is fine.

Thanks!
anadon
Posts: 7
Joined: Thu Jan 05, 2012 8:12 pm

Re: What are the basic kernel operations which require assem

Post by anadon »

I have the manual for the processor, but its so big I am not going through it all that fast...
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re: What are the basic kernel operations which require assem

Post by bubach »

It really depends. With an advanced bootloader you could get away with very little. But why do you even ask? It's the kind of thing you'll know when you get there, and have read the wiki & tutorials..
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: What are the basic kernel operations which require assem

Post by Brendan »

Hi,
anadon wrote:What are the basic kernel operations which require assembly?
A (possibly partial) list:
  • CPU mode switches. Needed at least once in boot code intended for BIOS (but more likely to be much more). Possibly not needed at all when booting from UEFI.
  • The task switch code in the scheduler (not the code that decides which task to switch to, but the small piece that actually does the final switch)
  • Interrupt handler entry and exit (but not necessarily the interrupt handler itself)
  • Kernel API entry and exit (but not necessarily the kernel API itself)
  • Special purpose CPU instructions. This typically means inline assembly macros/wrappers around instructions like CLI/STI, RDSTC, RDMSR/WRMSR, CPUID, IN, OUT, FXSAVE, LGDT/LIDT, MOV to/from CRn, HLT, INVLPG, etc.
  • Anything that needs to guarantee atomicity (e.g. for things like spinlocks, lock-free algorithms, etc); unless you can use something like atomic built-ins instead
That's everything I can think of at the moment.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
anadon
Posts: 7
Joined: Thu Jan 05, 2012 8:12 pm

Re: What are the basic kernel operations which require assem

Post by anadon »

Good list!
anadon
Posts: 7
Joined: Thu Jan 05, 2012 8:12 pm

Re: What are the basic kernel operations which require assem

Post by anadon »

I would like to be able to code more on it--it's fun. But I can't go as fast as I want to. No hurry, but I'd like to go faster.
huh
Posts: 13
Joined: Wed Jan 25, 2012 10:05 am

Re: What are the basic kernel operations which require assem

Post by huh »

All software NEEDS assembly, or more specifically, all software NEEDS to be run as binary. if you compile some c code there are 3 steps to make an executable:
1: make the c code into assembly (all code , even java, need to go to this stage)
2: assemble, build to .o or .bin file
2: link
the last step is not needed. if you write in c you will be able to use the asm(""); keyword, now you can write in at&t syntax (or type .intel_syntax to change to intel syntax).
PS: as you know, scripting languages are not compiled at all, they are interpreted
PS: the last ps was pointless
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: What are the basic kernel operations which require assem

Post by Solar »

@ huh:

You're wrong. While some compilers work with an intermediate Assembly stage, this is by no means imperative. GCC, for example, works with GENERIC, GIMPLE, and RTL - no Assembly involved. If you use the "-S" option, the Assembly output is artificially generated from the intermediary binary representation.

Anyway, this was not what the OP asked about.
Every good solution is obvious once you've found it.
huh
Posts: 13
Joined: Wed Jan 25, 2012 10:05 am

Re: What are the basic kernel operations which require assem

Post by huh »

Here are some of the basic things a kernel could do:
printing functions, set the screen mode, get keyboard inupt, some sort of command line, cursor movment, mm (memory management): simple functions like cleaning registers to managing RAM.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: What are the basic kernel operations which require assem

Post by Solar »

Second fail at second attempt. The question was. "What are the basic kernel operations which require assembly?", and it has been answered.

Half the things you listed can be done in any system programming language.
Every good solution is obvious once you've found it.
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: What are the basic kernel operations which require assem

Post by bluemoon »

And half of the things he listed aren't kernel operations. :roll:
Post Reply