SlideShare uma empresa Scribd logo
1 de 47
Kernel




Monolothic   Microkernel   Exokernel




  Hybrid
   When a computer is powered on, there is
    nothing running on the CPU. For a program to
    be set running, the binary image of the
    program must first be loaded into memory
    from a storage device.
   Bootstrapping: cold start to the point at
    which user-mode programs can be run.
   In FreeBSD, the binary image is in /vmunix or
    /boot/kernel/kernel
Kernel

Static Modules                 KLDs


Compiled in the kernel   Loaded during run time
   Some modules should be compiled in the
    kernel and can’t be loaded during run time.
     Those modules are ones that used before control
     turned to the user.
   Kernel Location
      /usr/src/sys/machine_type
   Kernel Configuration File
     /usr/src/sys/machine_type/conf
   By default, Kernel Configuration file is called
    GENERIC.
   Kernel Configuration file consists of set of
    modules.
   These modules consists of machine
    architecture, devices and set of options.
   Options are modes of compilation,
    communication restrictions, ports
    infrastructure, debugging options, .. etc
   It’s very important to compile the kernel with
    the modules which are needed at boot time
    since there is no control to the user to load
    them manually.
   Default Options are stored in DEFAULTS file.
   All the available options are located in the
    NOTES file in the same directory.
1.   One method is using the dmesg(8) utility
     and the man(1) commands. Most device
     drivers on FreeBSD have a manual page,
     listing supported hardware, and during the
     boot probe, found hardware will be listed.
2. Another method of finding hardware is by
   using the pciconf(8) utility which provides
   more verbose output.




   Using man ath will return the ath(4) manual
    page
   An include directive is available for use in
    configuration files. This allows another
    configuration file to be logically included in
    the current one, making it easy to maintain
    small changes relative to an existing file.
   Note: To build a file which contains all
    available options, as normally done for
    testing purposes, run the following command
    as root:

# cd /usr/src/sys/i386/conf && make LINT
   Compile Kernel
   Install Kernel
   New kernel will be installed in /boot/kernel
   For backup issues, old kernel stored in
    /boot/kernel.old
   You can load the old kernel by using single
    user mode at the FreeBSD booting page.
Unlike the older approach, this
make buildkernel      uses the new compiler residing
                                in /usr/obj.
                         This first compiles the new
                      compiler and a few related tools,
make buildworld        then uses the new compiler to
                     compile the rest of the new world.
                       The result ends up in /usr/obj.
                     Place the new kernel and kernel
                     modules onto the disk, making it
make installkernel
                     possible to boot with the newly
                             updated kernel.
                      Copies the world from /usr/obj.
make installworld     You now have a new kernel and
                            new world on disk.
1. Move to the directory of i386 kernel config files
   # cd /usr/src/sys/i386/conf
2. Create a copy of your kernel config file.
   # cp GENERIC MYKERNEL
3. Modify MYKERNEL configuration file.
   # ee MYKERNEL
4. Change to the /usr/src directory:
   # cd /usr/src
5. Compile the kernel:
   # make buildkernel KERNCONF=MYKERNEL
6. Install the new kernel:
   # make installkernel KERNCONF=MYKERNEL
   Kernel Loadable Modules result large
    flexibility in the kernel size since only needed
    KLD’s are loaded.
     We can use Binary file for total KLD’s indexing and
     make it easier for the user to determine what KLD’s
     can be loaded at boot time without the need for
     loading each one separately.
   Use kldstat to view them.
   All the kld’s are found in /boot/kernel
    directory.
   Use kldload to load kld’s.




   After loading
   Use kldunload to unload kld.
1. The bsd.kmod.mk makefile resides
 in /usr/src/share/mk/bsd.kmod.mk and
 takes all of the pain out of building and
 linking kernel modules properly.
2. you simply have to set two variables: the
 name of the kernel module itself via the
 “KMOD” variable; the source files configured
 via the intuitive “SRCS” variable.
3. Then, all you have to do is include
 <bsd.kmod.mk> to build the module.
 The Makefile for our introductory kernel
  module looks like this:
# Declare Name of kernel module
KMOD = hello_fsm
# Enumerate Source files for kernel module
SRCS = hello_fsm.c
# Include kernel module makefile
.include <bsd.kmod.mk>
   Create a new directory called kernel, under
    your home directory. Copy and paste the text
    in the last presentation into a file
    called Makefile. This will be your working
    base going forward.
   A kernel module allows dynamic functionality
    to be added to a running kernel. When a
    kernel module is inserted, the “load” event is
    fired. When a kernel module is removed, the
    “unload” event is fired. The kernel module is
    responsible for implementing an event
    handler that handles these cases.
The running kernel will pass in the event in
 the form of a symbolic constant defined in
 the/usr/include/sys/module.h
   (<sys/module.h>) header file.
The two main events you are concerned with
 are MOD_LOAD and MOD_UNLOAD.
   The module is responsible for configuring
    that call-back as well by using the
    DECLARE_MODULE macro.
   The DECLARE_MODULE macro is defined in
    the <sys/module.h> header
  DECLARE_MODULE takes four parameters in the
  following order:
1. name: Defines the name.
2. data: Specifies the name of
  the moduledata_t structure, which I’ve
  named hello_conf in my implementation.
  The moduledata_t type is defined at
  <sys/module.h>
3. sub: Sets the subsystem interface, which defines
  the module type.
4. order: Defines the modules initialization order
  within the defined subsystem
   The moduledata structure contains the name
    defined as a char variable and the event
    handler routine defined as
    a modeventhand_t structure which is defined
    at line 50 of <sys/module.h>. Finally,
    themoduledata structure has void pointer for
    any extra data, which you won’t be using.
   #include <sys/param.h>
   #include <sys/module.h>
   #include <sys/kernel.h>
   #include <sys/systm.h>
   /* The function called at load/unload. */
    static int event_handler(struct module *module, int event, void *arg)
{
 int e = 0;    /* Error, 0 for normal return status */
switch (event) {
case MOD_LOAD:
uprintf("Hello Free Software Magazine Readers! n");
break;
case MOD_UNLOAD:
uprintf("Bye Bye FSM reader, be sure to check http://www.google.com !n");
break;
default:
e = EOPNOTSUPP; /* Error, Operation Not Supported */
break;
}
return(e);
}
  This is where you set the name of the module
   and expose the event_handler routine to be
   called when loaded and unloaded from the
   kernel.
 /* The second argument of
   DECLARE_MODULE. */
  static moduledata_t hello_conf = {
    "hello_fsm", /* module name */
     event_handler, /* event handler */
     NULL /* extra data */
};
   DECLARE_MODULE(hello_fsm, hello_conf,
    SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
   make
Thank you

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

Ch1 linux basics
Ch1 linux basicsCh1 linux basics
Ch1 linux basics
 
Introduction To Linux Kernel Modules
Introduction To Linux Kernel ModulesIntroduction To Linux Kernel Modules
Introduction To Linux Kernel Modules
 
Linux IO
Linux IOLinux IO
Linux IO
 
Linux basics
Linux basics Linux basics
Linux basics
 
11 linux filesystem copy
11 linux filesystem copy11 linux filesystem copy
11 linux filesystem copy
 
Linux filesystemhierarchy
Linux filesystemhierarchyLinux filesystemhierarchy
Linux filesystemhierarchy
 
Kernel init
Kernel initKernel init
Kernel init
 
Linux basics
Linux basics Linux basics
Linux basics
 
OMFW 2012: Analyzing Linux Kernel Rootkits with Volatlity
OMFW 2012: Analyzing Linux Kernel Rootkits with VolatlityOMFW 2012: Analyzing Linux Kernel Rootkits with Volatlity
OMFW 2012: Analyzing Linux Kernel Rootkits with Volatlity
 
Basic Linux Internals
Basic Linux InternalsBasic Linux Internals
Basic Linux Internals
 
Linuxppt
LinuxpptLinuxppt
Linuxppt
 
Lecture 3 Perl & FreeBSD administration
Lecture 3 Perl & FreeBSD administrationLecture 3 Perl & FreeBSD administration
Lecture 3 Perl & FreeBSD administration
 
LINUX Admin Quick Reference
LINUX Admin Quick ReferenceLINUX Admin Quick Reference
LINUX Admin Quick Reference
 
De-Anonymizing Live CDs through Physical Memory Analysis
De-Anonymizing Live CDs through Physical Memory AnalysisDe-Anonymizing Live CDs through Physical Memory Analysis
De-Anonymizing Live CDs through Physical Memory Analysis
 
Linux
LinuxLinux
Linux
 
unixtoolbox
unixtoolboxunixtoolbox
unixtoolbox
 
Introduction to UNIX
Introduction to UNIXIntroduction to UNIX
Introduction to UNIX
 
Linux kernel architecture
Linux kernel architectureLinux kernel architecture
Linux kernel architecture
 
Linux scheduler
Linux schedulerLinux scheduler
Linux scheduler
 
Linux kernel architecture
Linux kernel architectureLinux kernel architecture
Linux kernel architecture
 

Destaque

Innova day motorsporttech_eng_b
Innova day motorsporttech_eng_bInnova day motorsporttech_eng_b
Innova day motorsporttech_eng_bFrancesco Baruffi
 
Rapid Control Prototyping
Rapid Control PrototypingRapid Control Prototyping
Rapid Control Prototypingguest0eeac7
 
you know databases, how hard can MySQL be?
you know databases, how hard can MySQL be?you know databases, how hard can MySQL be?
you know databases, how hard can MySQL be?sarahnovotny
 
Co jsme se naučili od spuštění Fakturoidu
Co jsme se naučili od spuštění FakturoiduCo jsme se naučili od spuštění Fakturoidu
Co jsme se naučili od spuštění Fakturoidujan korbel
 
Collaborative Assessment: Working Together Toward Institutional Change
Collaborative Assessment: Working Together Toward Institutional ChangeCollaborative Assessment: Working Together Toward Institutional Change
Collaborative Assessment: Working Together Toward Institutional ChangeElizabeth Nesius
 
Answergen bi ppt-apr 09 2015
Answergen bi   ppt-apr 09 2015Answergen bi   ppt-apr 09 2015
Answergen bi ppt-apr 09 2015TS Kumaresh
 
IGNITE MySQL - Backups Don't Make Me Money
IGNITE MySQL - Backups Don't Make Me MoneyIGNITE MySQL - Backups Don't Make Me Money
IGNITE MySQL - Backups Don't Make Me Moneysarahnovotny
 
Soc. Unit I, Packet 2
Soc. Unit I, Packet 2Soc. Unit I, Packet 2
Soc. Unit I, Packet 2NHSDAnderson
 
Dissertation on MF
Dissertation on MFDissertation on MF
Dissertation on MFPIYUSH JAIN
 
NGINX 101 - now with more Docker
NGINX 101 - now with more DockerNGINX 101 - now with more Docker
NGINX 101 - now with more Dockersarahnovotny
 
Oracle Exec Summary 7000 Unified Storage
Oracle Exec Summary 7000 Unified StorageOracle Exec Summary 7000 Unified Storage
Oracle Exec Summary 7000 Unified StorageDavid R. Klauser
 
Responding to student writing
Responding to student writingResponding to student writing
Responding to student writingElizabeth Nesius
 
all data everywhere
all data everywhereall data everywhere
all data everywheresarahnovotny
 
Tally Sheet Results - Technology Habits
Tally Sheet Results - Technology HabitsTally Sheet Results - Technology Habits
Tally Sheet Results - Technology Habitsleouy
 
Google Platform Overview (April 2014)
Google Platform Overview (April 2014)Google Platform Overview (April 2014)
Google Platform Overview (April 2014)Ido Green
 

Destaque (20)

Innova day motorsporttech_eng_b
Innova day motorsporttech_eng_bInnova day motorsporttech_eng_b
Innova day motorsporttech_eng_b
 
Rapid Control Prototyping
Rapid Control PrototypingRapid Control Prototyping
Rapid Control Prototyping
 
Plc day ppt
Plc day pptPlc day ppt
Plc day ppt
 
you know databases, how hard can MySQL be?
you know databases, how hard can MySQL be?you know databases, how hard can MySQL be?
you know databases, how hard can MySQL be?
 
Co jsme se naučili od spuštění Fakturoidu
Co jsme se naučili od spuštění FakturoiduCo jsme se naučili od spuštění Fakturoidu
Co jsme se naučili od spuštění Fakturoidu
 
Collaborative Assessment: Working Together Toward Institutional Change
Collaborative Assessment: Working Together Toward Institutional ChangeCollaborative Assessment: Working Together Toward Institutional Change
Collaborative Assessment: Working Together Toward Institutional Change
 
Answergen bi ppt-apr 09 2015
Answergen bi   ppt-apr 09 2015Answergen bi   ppt-apr 09 2015
Answergen bi ppt-apr 09 2015
 
Mohammed Farrag Resume
Mohammed Farrag ResumeMohammed Farrag Resume
Mohammed Farrag Resume
 
Aptso cosechas 2010
Aptso cosechas 2010Aptso cosechas 2010
Aptso cosechas 2010
 
IGNITE MySQL - Backups Don't Make Me Money
IGNITE MySQL - Backups Don't Make Me MoneyIGNITE MySQL - Backups Don't Make Me Money
IGNITE MySQL - Backups Don't Make Me Money
 
5th Grade
5th Grade5th Grade
5th Grade
 
Marathon
MarathonMarathon
Marathon
 
Soc. Unit I, Packet 2
Soc. Unit I, Packet 2Soc. Unit I, Packet 2
Soc. Unit I, Packet 2
 
Dissertation on MF
Dissertation on MFDissertation on MF
Dissertation on MF
 
NGINX 101 - now with more Docker
NGINX 101 - now with more DockerNGINX 101 - now with more Docker
NGINX 101 - now with more Docker
 
Oracle Exec Summary 7000 Unified Storage
Oracle Exec Summary 7000 Unified StorageOracle Exec Summary 7000 Unified Storage
Oracle Exec Summary 7000 Unified Storage
 
Responding to student writing
Responding to student writingResponding to student writing
Responding to student writing
 
all data everywhere
all data everywhereall data everywhere
all data everywhere
 
Tally Sheet Results - Technology Habits
Tally Sheet Results - Technology HabitsTally Sheet Results - Technology Habits
Tally Sheet Results - Technology Habits
 
Google Platform Overview (April 2014)
Google Platform Overview (April 2014)Google Platform Overview (April 2014)
Google Platform Overview (April 2014)
 

Semelhante a Lecture 5 Kernel Development

Linux Kernel Programming
Linux Kernel ProgrammingLinux Kernel Programming
Linux Kernel ProgrammingNalin Sharma
 
Building a linux kernel
Building a linux kernelBuilding a linux kernel
Building a linux kernelRaghu nath
 
Linux kernel driver tutorial vorlesung
Linux kernel driver tutorial vorlesungLinux kernel driver tutorial vorlesung
Linux kernel driver tutorial vorlesungdns -
 
Linux Kernel Development
Linux Kernel DevelopmentLinux Kernel Development
Linux Kernel DevelopmentPriyank Kapadia
 
Linux kernel modules
Linux kernel modulesLinux kernel modules
Linux kernel modulesHao-Ran Liu
 
Part 02 Linux Kernel Module Programming
Part 02 Linux Kernel Module ProgrammingPart 02 Linux Kernel Module Programming
Part 02 Linux Kernel Module ProgrammingTushar B Kute
 
Linuxdd[1]
Linuxdd[1]Linuxdd[1]
Linuxdd[1]mcganesh
 
Oracle11g On Fedora14
Oracle11g On Fedora14Oracle11g On Fedora14
Oracle11g On Fedora14kmsa
 
brief intro to Linux device drivers
brief intro to Linux device driversbrief intro to Linux device drivers
brief intro to Linux device driversAlexandre Moreno
 
Load module kernel
Load module kernelLoad module kernel
Load module kernelAbu Azzam
 
Linux Module Programming
Linux Module ProgrammingLinux Module Programming
Linux Module ProgrammingAmir Payberah
 
Managing Perl Installations: A SysAdmin's View
Managing Perl Installations: A SysAdmin's ViewManaging Perl Installations: A SysAdmin's View
Managing Perl Installations: A SysAdmin's ViewBaden Hughes
 
Fedora Atomic Workshop handout for Fudcon Pune 2015
Fedora Atomic Workshop handout for Fudcon Pune  2015Fedora Atomic Workshop handout for Fudcon Pune  2015
Fedora Atomic Workshop handout for Fudcon Pune 2015rranjithrajaram
 
Linux device driver
Linux device driverLinux device driver
Linux device driverchatsiri
 

Semelhante a Lecture 5 Kernel Development (20)

Linux Kernel Programming
Linux Kernel ProgrammingLinux Kernel Programming
Linux Kernel Programming
 
Building a linux kernel
Building a linux kernelBuilding a linux kernel
Building a linux kernel
 
Linux kernel driver tutorial vorlesung
Linux kernel driver tutorial vorlesungLinux kernel driver tutorial vorlesung
Linux kernel driver tutorial vorlesung
 
Linux Kernel Development
Linux Kernel DevelopmentLinux Kernel Development
Linux Kernel Development
 
Linux kernel modules
Linux kernel modulesLinux kernel modules
Linux kernel modules
 
Part 02 Linux Kernel Module Programming
Part 02 Linux Kernel Module ProgrammingPart 02 Linux Kernel Module Programming
Part 02 Linux Kernel Module Programming
 
Linuxdd[1]
Linuxdd[1]Linuxdd[1]
Linuxdd[1]
 
Oracle11g On Fedora14
Oracle11g On Fedora14Oracle11g On Fedora14
Oracle11g On Fedora14
 
Oracle11g on fedora14
Oracle11g on fedora14Oracle11g on fedora14
Oracle11g on fedora14
 
Linux kernel
Linux kernelLinux kernel
Linux kernel
 
brief intro to Linux device drivers
brief intro to Linux device driversbrief intro to Linux device drivers
brief intro to Linux device drivers
 
Linux kernel
Linux kernelLinux kernel
Linux kernel
 
Load module kernel
Load module kernelLoad module kernel
Load module kernel
 
Linux Module Programming
Linux Module ProgrammingLinux Module Programming
Linux Module Programming
 
Linux Device Driver’s
Linux Device Driver’sLinux Device Driver’s
Linux Device Driver’s
 
Managing Perl Installations: A SysAdmin's View
Managing Perl Installations: A SysAdmin's ViewManaging Perl Installations: A SysAdmin's View
Managing Perl Installations: A SysAdmin's View
 
Fedora Atomic Workshop handout for Fudcon Pune 2015
Fedora Atomic Workshop handout for Fudcon Pune  2015Fedora Atomic Workshop handout for Fudcon Pune  2015
Fedora Atomic Workshop handout for Fudcon Pune 2015
 
Studienarb linux kernel-dev
Studienarb linux kernel-devStudienarb linux kernel-dev
Studienarb linux kernel-dev
 
Linux device driver
Linux device driverLinux device driver
Linux device driver
 
Linux kernel modules
Linux kernel modulesLinux kernel modules
Linux kernel modules
 

Mais de Mohammed Farrag

Resume for Mohamed Farag
Resume for Mohamed FaragResume for Mohamed Farag
Resume for Mohamed FaragMohammed Farrag
 
Mum Article Recognition for Mohamed Farag
Mum Article Recognition for Mohamed FaragMum Article Recognition for Mohamed Farag
Mum Article Recognition for Mohamed FaragMohammed Farrag
 
Artificial Intelligence Programming in Art by Mohamed Farag
Artificial Intelligence Programming in Art by Mohamed FaragArtificial Intelligence Programming in Art by Mohamed Farag
Artificial Intelligence Programming in Art by Mohamed FaragMohammed Farrag
 
The practices, challenges and opportunities of board composition and leadersh...
The practices, challenges and opportunities of board composition and leadersh...The practices, challenges and opportunities of board composition and leadersh...
The practices, challenges and opportunities of board composition and leadersh...Mohammed Farrag
 
Confirmation letter info tech 2013(1)
Confirmation letter info tech 2013(1)Confirmation letter info tech 2013(1)
Confirmation letter info tech 2013(1)Mohammed Farrag
 

Mais de Mohammed Farrag (9)

Resume for Mohamed Farag
Resume for Mohamed FaragResume for Mohamed Farag
Resume for Mohamed Farag
 
Mum Article Recognition for Mohamed Farag
Mum Article Recognition for Mohamed FaragMum Article Recognition for Mohamed Farag
Mum Article Recognition for Mohamed Farag
 
Create 2015 Event
Create 2015 EventCreate 2015 Event
Create 2015 Event
 
Artificial Intelligence Programming in Art by Mohamed Farag
Artificial Intelligence Programming in Art by Mohamed FaragArtificial Intelligence Programming in Art by Mohamed Farag
Artificial Intelligence Programming in Art by Mohamed Farag
 
The practices, challenges and opportunities of board composition and leadersh...
The practices, challenges and opportunities of board composition and leadersh...The practices, challenges and opportunities of board composition and leadersh...
The practices, challenges and opportunities of board composition and leadersh...
 
Confirmation letter info tech 2013(1)
Confirmation letter info tech 2013(1)Confirmation letter info tech 2013(1)
Confirmation letter info tech 2013(1)
 
Google APPs and APIs
Google APPs and APIsGoogle APPs and APIs
Google APPs and APIs
 
FreeBSD Handbook
FreeBSD HandbookFreeBSD Handbook
FreeBSD Handbook
 
Master resume
Master resumeMaster resume
Master resume
 

Último

Narcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfNarcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfPrerana Jadhav
 
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxMan or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxDhatriParmar
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDhatriParmar
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Projectjordimapav
 
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
Unraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptxUnraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptx
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptxDhatriParmar
 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdfMr Bounab Samir
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSMae Pangan
 
How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17Celine George
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationdeepaannamalai16
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research DiscourseAnita GoswamiGiri
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataBabyAnnMotar
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operationalssuser3e220a
 
Mental Health Awareness - a toolkit for supporting young minds
Mental Health Awareness - a toolkit for supporting young mindsMental Health Awareness - a toolkit for supporting young minds
Mental Health Awareness - a toolkit for supporting young mindsPooky Knightsmith
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmStan Meyer
 
How to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseHow to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseCeline George
 
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Association for Project Management
 

Último (20)

Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of EngineeringFaculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
 
Narcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfNarcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdf
 
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxMan or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Project
 
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
Unraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptxUnraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptx
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdf
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHS
 
How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentation
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research Discourse
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped data
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operational
 
Mental Health Awareness - a toolkit for supporting young minds
Mental Health Awareness - a toolkit for supporting young mindsMental Health Awareness - a toolkit for supporting young minds
Mental Health Awareness - a toolkit for supporting young minds
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and Film
 
How to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseHow to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 Database
 
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
 

Lecture 5 Kernel Development

  • 1.
  • 2. Kernel Monolothic Microkernel Exokernel Hybrid
  • 3. When a computer is powered on, there is nothing running on the CPU. For a program to be set running, the binary image of the program must first be loaded into memory from a storage device.  Bootstrapping: cold start to the point at which user-mode programs can be run.  In FreeBSD, the binary image is in /vmunix or /boot/kernel/kernel
  • 4. Kernel Static Modules KLDs Compiled in the kernel Loaded during run time
  • 5. Some modules should be compiled in the kernel and can’t be loaded during run time.  Those modules are ones that used before control turned to the user.
  • 6. Kernel Location /usr/src/sys/machine_type  Kernel Configuration File /usr/src/sys/machine_type/conf  By default, Kernel Configuration file is called GENERIC.
  • 7. Kernel Configuration file consists of set of modules.  These modules consists of machine architecture, devices and set of options.  Options are modes of compilation, communication restrictions, ports infrastructure, debugging options, .. etc
  • 8. It’s very important to compile the kernel with the modules which are needed at boot time since there is no control to the user to load them manually.  Default Options are stored in DEFAULTS file.  All the available options are located in the NOTES file in the same directory.
  • 9. 1. One method is using the dmesg(8) utility and the man(1) commands. Most device drivers on FreeBSD have a manual page, listing supported hardware, and during the boot probe, found hardware will be listed.
  • 10. 2. Another method of finding hardware is by using the pciconf(8) utility which provides more verbose output.  Using man ath will return the ath(4) manual page
  • 11. An include directive is available for use in configuration files. This allows another configuration file to be logically included in the current one, making it easy to maintain small changes relative to an existing file.
  • 12.
  • 13. Note: To build a file which contains all available options, as normally done for testing purposes, run the following command as root: # cd /usr/src/sys/i386/conf && make LINT
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22. Compile Kernel  Install Kernel
  • 23. New kernel will be installed in /boot/kernel  For backup issues, old kernel stored in /boot/kernel.old  You can load the old kernel by using single user mode at the FreeBSD booting page.
  • 24. Unlike the older approach, this make buildkernel uses the new compiler residing in /usr/obj. This first compiles the new compiler and a few related tools, make buildworld then uses the new compiler to compile the rest of the new world. The result ends up in /usr/obj. Place the new kernel and kernel modules onto the disk, making it make installkernel possible to boot with the newly updated kernel. Copies the world from /usr/obj. make installworld You now have a new kernel and new world on disk.
  • 25. 1. Move to the directory of i386 kernel config files # cd /usr/src/sys/i386/conf 2. Create a copy of your kernel config file. # cp GENERIC MYKERNEL 3. Modify MYKERNEL configuration file. # ee MYKERNEL
  • 26. 4. Change to the /usr/src directory: # cd /usr/src 5. Compile the kernel: # make buildkernel KERNCONF=MYKERNEL 6. Install the new kernel: # make installkernel KERNCONF=MYKERNEL
  • 27. Kernel Loadable Modules result large flexibility in the kernel size since only needed KLD’s are loaded.  We can use Binary file for total KLD’s indexing and make it easier for the user to determine what KLD’s can be loaded at boot time without the need for loading each one separately.
  • 28. Use kldstat to view them.
  • 29. All the kld’s are found in /boot/kernel directory.
  • 30. Use kldload to load kld’s.  After loading
  • 31. Use kldunload to unload kld.
  • 32. 1. The bsd.kmod.mk makefile resides in /usr/src/share/mk/bsd.kmod.mk and takes all of the pain out of building and linking kernel modules properly.
  • 33. 2. you simply have to set two variables: the name of the kernel module itself via the “KMOD” variable; the source files configured via the intuitive “SRCS” variable. 3. Then, all you have to do is include <bsd.kmod.mk> to build the module.
  • 34.  The Makefile for our introductory kernel module looks like this: # Declare Name of kernel module KMOD = hello_fsm # Enumerate Source files for kernel module SRCS = hello_fsm.c # Include kernel module makefile .include <bsd.kmod.mk>
  • 35. Create a new directory called kernel, under your home directory. Copy and paste the text in the last presentation into a file called Makefile. This will be your working base going forward.
  • 36. A kernel module allows dynamic functionality to be added to a running kernel. When a kernel module is inserted, the “load” event is fired. When a kernel module is removed, the “unload” event is fired. The kernel module is responsible for implementing an event handler that handles these cases.
  • 37. The running kernel will pass in the event in the form of a symbolic constant defined in the/usr/include/sys/module.h (<sys/module.h>) header file. The two main events you are concerned with are MOD_LOAD and MOD_UNLOAD.
  • 38. The module is responsible for configuring that call-back as well by using the DECLARE_MODULE macro.  The DECLARE_MODULE macro is defined in the <sys/module.h> header
  • 39.  DECLARE_MODULE takes four parameters in the following order: 1. name: Defines the name. 2. data: Specifies the name of the moduledata_t structure, which I’ve named hello_conf in my implementation. The moduledata_t type is defined at <sys/module.h> 3. sub: Sets the subsystem interface, which defines the module type. 4. order: Defines the modules initialization order within the defined subsystem
  • 40. The moduledata structure contains the name defined as a char variable and the event handler routine defined as a modeventhand_t structure which is defined at line 50 of <sys/module.h>. Finally, themoduledata structure has void pointer for any extra data, which you won’t be using.
  • 41. #include <sys/param.h>  #include <sys/module.h>  #include <sys/kernel.h>  #include <sys/systm.h>
  • 42. /* The function called at load/unload. */ static int event_handler(struct module *module, int event, void *arg) { int e = 0; /* Error, 0 for normal return status */ switch (event) { case MOD_LOAD: uprintf("Hello Free Software Magazine Readers! n"); break; case MOD_UNLOAD: uprintf("Bye Bye FSM reader, be sure to check http://www.google.com !n"); break; default: e = EOPNOTSUPP; /* Error, Operation Not Supported */ break; } return(e); }
  • 43.  This is where you set the name of the module and expose the event_handler routine to be called when loaded and unloaded from the kernel.  /* The second argument of DECLARE_MODULE. */ static moduledata_t hello_conf = { "hello_fsm", /* module name */ event_handler, /* event handler */ NULL /* extra data */ };
  • 44. DECLARE_MODULE(hello_fsm, hello_conf, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
  • 45. make
  • 46.