DaemonForums  

Go Back   DaemonForums > Miscellaneous > Programming

Programming C, bash, Python, Perl, PHP, Java, you name it.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 22nd April 2009
bsdnewbie999 bsdnewbie999 is offline
Package Pilot
 
Join Date: May 2008
Posts: 145
Thanked 0 Times in 0 Posts
Default Assembly and kernel programming.

What's the different of assembly language and kernel programming? Any suggested sources??
Reply With Quote
  #2   (View Single Post)  
Old 22nd April 2009
drhowarddrfine drhowarddrfine is offline
VPN Cryptographer
 
Join Date: May 2008
Posts: 358
Thanked 9 Times in 8 Posts
Default

The first is a language and the second is not.

You write code for the kernel in the second case. It's usually done with C but a smattering of assembly language can be found.

In case you are confused about what the 'kernel' is, that's the core of the operating system that handles all system functions and communications between processes.

Last edited by drhowarddrfine; 22nd April 2009 at 02:28 PM.
Reply With Quote
  #3   (View Single Post)  
Old 22nd April 2009
indienick indienick is offline
Lisp Junkie
 
Join Date: Apr 2009
Location: London, ON, Canada
Posts: 27
Thanked 0 Times in 0 Posts
Default

I, like bsdnewbie999 am interested in programming for a BSD kernel, but I do not know where to start. (I am not trying to hijack this thread, mind you.)

I have just one, simple question: FreeBSD's online documentation has a few sections on programming kernel modules (syn. drivers), but would that knowledge carry over to other BSDs (namely OpenBSD)? Is the BSD kernel a standardized thing, across various BSDs?
Reply With Quote
  #4   (View Single Post)  
Old 22nd April 2009
jggimi's Avatar
jggimi jggimi is offline
More noise than signal
 
Join Date: May 2008
Location: USA
Posts: 3,886
Thanked 214 Times in 189 Posts
Default

BSDNewbie:

"Assemblers" have text files as input, as do "Compilers" -- and they both output executable binary objects. That is where their similarities end.

The difference is that the text file written in an "assembly language" or in "assembler" describe the specific CPU instructions to be placed in the binary output file. CPU instruction sets are hardware specific, and may be as simple or as complex as the instruction-set of the individual processor. The old PDP-8, one of the first processors I did programming for, had only 8 different instructions. The last OS built entirely from assembler language, that I dealt with regularly, was one for IBM's System/370, which still survives in their zSeries, if I recall correctly. It had several hundred different CPU instructions.

If you've never looked at a CPU instruction set, they commonly have instructions that are relatively simplistic, such as:

"copy a chunk of memory at this specified address into that CPU register, for later manipulation"

"add the values in these two registers together"

"copy a chunk of memory, for some number of bytes, from this address to that address"

"subtract 1 from this register value. If the register has reached zero, jump to that address, else execute the next instruction after this one"

"Issue the I/O instruction at this address to that hardware controller."

------------------------

indienick:

OpenBSD uses a "monolithic kernel" --- this is a big name to describe what just means, really, "built all into one single file". However, it has the capability to add kernel modules; emulators/kqemu is an example of a kernel module port/package for OpenBSD.
Reply With Quote
  #5   (View Single Post)  
Old 22nd April 2009
ocicat ocicat is offline
Administrator
 
Join Date: Apr 2008
Posts: 2,930
Thanked 190 Times in 160 Posts
Default

Quote:
Originally Posted by indienick View Post
...but I do not know where to start.
Begin by reading the kernel's source followed by reading it more. Unfortunately, you are seeing multiple issues at the same time:
  • Rarely if ever does the source of a large project make sense the first few trips through study. It will take awhile, & multiple reads.
  • The interaction between modules & functions may not be apparent for quite some time.
  • Projects (commercial or Open Source...) grow organically which means that the organization of the overall source base will take time to comprehend why things are as they are. Don't expect to understand it on the first pass.
Rarely is there a published roadmap which will gently guide you through the process. If you really want to learn the kernel, have the fortitude & tenacity to stick to it.

Last edited by ocicat; 22nd April 2009 at 04:14 PM.
Reply With Quote
  #6   (View Single Post)  
Old 22nd April 2009
BSDfan666 BSDfan666 is offline
Real Name: N/A, this is the interweb.
Helpful companion
 
Join Date: Apr 2008
Location: Ontario, Canada
Posts: 2,223
Thanked 193 Times in 184 Posts
Default

Quote:
Originally Posted by indienick View Post
I have just one, simple question: FreeBSD's online documentation has a few sections on programming kernel modules (syn. drivers), but would that knowledge carry over to other BSDs (namely OpenBSD)? Is the BSD kernel a standardized thing, across various BSDs?
The BSD projects may share some kernel level API's, but they've had a long time to diverge from each other.. no real effort was made to keep things compatible with each other.

FreeBSD for example has a totally different SCSI layer then the other BSD's.. They may still share some common code, it's becoming less easy to port drivers between them.. definitely not plug and play.

NetBSD and OpenBSD have a kernel module framework called lkm(4), it is supported by both.. but it simply offers a way for modules to be loaded, such modules are free to use kernel functions/symbols which again may not be available or compatible between the two systems.

Also, while OpenBSD does still support lkm(4).. it is not an active utilizer of it.. as jggimi said, the kernel is monolithic and all supported drivers are compiled into the default kernel binaries.

FreeBSD has deprecated lkm(4) in favour of their own framework.. they call it kld(4).

@bsdnewbie999, That kind of question could have been answered easily using a search engine.. was it really necessary to waste our time?

Last edited by BSDfan666; 22nd April 2009 at 04:02 PM.
Reply With Quote
  #7   (View Single Post)  
Old 22nd April 2009
indienick indienick is offline
Lisp Junkie
 
Join Date: Apr 2009
Location: London, ON, Canada
Posts: 27
Thanked 0 Times in 0 Posts
Default

BSDfan666, jggimi, thank you both, very much, for your responses.
Reply With Quote
  #8   (View Single Post)  
Old 22nd April 2009
TerryP's Avatar
TerryP TerryP is offline
Arp Constable
 
Join Date: May 2008
Location: USofA
Posts: 1,547
Thanked 112 Times in 104 Posts
Default

If you have an interest in kernels, I would suggest digging up John Lions' commentary on UNIX 6th Edition, with Source Code*. The book covers a very old version of UNIX, C, and PDP assembly; but it offers a *much* less complex beast to study then the modern BSD or Linux kernels have become.

The best introduction to the modern kernels that I know of, is to poke around the source code, see where things are located, and find out how something you are interested in works; exempli gratia learn how the system goes from CPU power on, to allowing multiple users to login**. Or perhaps study how the the kernel executes programs***. You can even poke around various sub systems and drivers; the implementation of FAT file systems is a nice and simple file system to study compared to modern FSes.


* http://en.wikipedia.org/wiki/Lions%2...th_Source_Code
** I found writing notes on that very fun and mildly educational.
*** Doing that is a fun exercise
__________________
My Journal

Thou shalt check the array bounds of all strings (indeed, all arrays), for surely where thou typest ``foo'' someone someday shall type ``supercalifragilisticexpialidocious''.
Reply With Quote
  #9   (View Single Post)  
Old 8th May 2009
Zmyrgel Zmyrgel is offline
Port Guard
 
Join Date: May 2008
Posts: 26
Thanked 0 Times in 0 Posts
Default

indienick, I asked pretty much the same question from Marc Balmer (OpenBSD dev) and he suggested that I read the Design and implementation of 4.4BSD operating system and the Advanced Unix programming in Unix environment. This should give pretty good basis and then the kernel code would slowly start to make sense

The first book has bit old information but most of it should describe how things work on OpenBSD too.
Reply With Quote
Old 17th May 2009
indienick indienick is offline
Lisp Junkie
 
Join Date: Apr 2009
Location: London, ON, Canada
Posts: 27
Thanked 0 Times in 0 Posts
Default

Wonderful! Thank you very much, Zmyrgel.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
learn assembly ephemera Book reviews 5 26th December 2012 06:29 PM
Undertaking computer science degree, which BSD for learning professional assembly? lionsong Programming 15 18th October 2009 11:26 PM
Java and AI-programming idefix Programming 4 7th February 2009 01:41 PM
c programming - Modules corey_james Programming 3 6th November 2008 08:49 PM
GUI Programming bsdnewbie999 Programming 6 17th August 2008 12:19 AM


All times are GMT. The time now is 10:10 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick