• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

Linux Kernel development

zman099

n00b
Joined
Feb 9, 2006
Messages
49
just wondering if anyone is into kernel development or in the field of making device drivers for linux. Also wondering if anyone knows a place where i can get good books on the topic.


Thanks
 
Heh, seems to be that time of the year. I began looking at the same thing in FreeBSD a few days ago. :)
(Of course, the documentation I find won't be of much use to you, so I can't really help.)
 
i bought the book called linux kernel development by robert love, it a pretty good book, but you have to know C pretty well to get things
 
I recently did a school project doing linux device drivers. For general information on how devices in linux work, the linux device driver book mentioned above will do you good and get you started. If you try to make a device for a type of device that uses layering in the kernel, be prepared for a tough time since the interfaces are too specific for books and the documentation in the kernel source is pretty atrocious(I also think the general coding style is horrible and makes things significantly harder).
 
Geshtar,

how did you end up learning this stuff then? man when i read this book, i end up using google a lot to look up these terms. I want to learn this stuff, but i'm not very good with C.
 
zman099 said:
Geshtar,

how did you end up learning this stuff then? man when i read this book, i end up using google a lot to look up these terms. I want to learn this stuff, but i'm not very good with C.

You better get good quick :p You should also immediately start learning assembly. Low level programming is powerful, but it sucks.



heres a little prog i wrote to compare 2 names in assembly lol. It was a school project, too bad i couldnt use a class implementation like java and skip it all by saying *- if(str1.equals(str2)) { -* lol:
Code:
;

TITLE CMPNAMES (EXE) COMPARES 2 NAMES ENTERED BY A USER AND ASKS TO REPEAT
;**************************************************************************
;	PROGRAMMER: 	CHRIS GARNER
;	DATE:		11-14-2005
;	DESCRITPION	THIS PROGRAM TAKES 2 NAMES IN FROM THE USER,
;			COMPARES THEM, AND THEN GIVES OUTPUT ACCORDING TO
;			WHETHER THEY MATCH OR NOT. EITHER WAY THE USER HAS
;			THE CHOICE TO TRY AGAIN.
;*************************************************************************
	.MODEL SMALL
	.STACK 1024
;*************************************************************************
	.DATA

PROMPT1		DB	'Please enter the first name: $'
PROMPT2		DB	'Please enter the second name: $'
PROMPTSAME	DB	'You entered the same name twice. Would you like to enter two more names (Y/N)? $'
PROMPTDIF	DB	'You entered 2 different names. Would you like to enter two more names (Y/N)? $'
SAME		DB	?

PARLIST1	LABEL		BYTE
MAXLENG1	DB		31
ACTLENG1	DB		?
NAME1		DB		32 DUP('*'), '$'

PARLIST2	LABEL		BYTE
MAXLENG2	DB		31
ACTLENG2	DB		?
NAME2		DB		32 DUP('*'), '$'
;**************************************************************************


;**************************************************************************
	.386
	.CODE
MAIN	PROC	FAR

     ;SETUP REGISTERS
	MOV	AX,@data
	MOV	DS,AX
	MOV	ES,AX
	

     ;START PROGRAM
	CALL CLRSCRN			;CLEAR THE SCREEN

	CALL SET_CURSOR_1		;SET CURSOR FOR
	CALL PROMPT_FOR_NAME_1		;   FIRST PROMPT
	CALL NAME_1_IN			;   AND ACCEPT FIRST NAME

	CALL SET_CURSOR_2		;SET CURSOR FOR
	CALL PROMPT_FOR_NAME_2		;   FIRST PROMPT
	CALL NAME_2_IN			;   AND ACCEPT SECOND NAME

	CALL COMPARE			;OFF TO THE COMPARISON
	CALL SAME_NAMES			;IF THE NAMES ARE EQUAL, CALL THIS PROC

     ;END PROGRAM
	MOV	AX,4C00H
	INT	21H

MAIN	ENDP
;**************************************************************************



;**************************************************************************
CLRSCRN 		PROC	NEAR
	PUSHA

	MOV	AH, 06H			;SCROLL PAGE UP
	MOV	AL, 00H			;FULL SCREEN SCROLL
	MOV 	BH, 00000111		;BG = BLACK, FG = GREY
	MOV	CH, 00D	 		;TOP LEFT X
	MOV	CL, 00D			;TOP LEFT Y
	MOV	DH, 24D			;BOT LEFT X
	MOV	DL, 79D			;BOT LEFT Y
	INT	10H			;MAKE IT HAPPEN

	POPA
	RET
CLRSCRN	    	ENDP
;-------------------------------------------------------------------------
SET_CURSOR_1	PROC	NEAR
	PUSHA

	MOV	AH, 02H			;REQUEST CURSOR SET
	MOV	BH, 0			;PAGE NUMBER
	MOV	DH, 02D			;ROW FOR CURSOR
	MOV	DL, 00D			;COL FOR CURSOR
	INT	10H			;MAKE IT HAPPEN

	POPA
	RETN
SET_CURSOR_1 ENDP
;--------------------------------------------------------------------------
PROMPT_FOR_NAME_1	PROC	NEAR
	PUSHA

	MOV	AH, 09H			;REQUEST DISPLAY
	LEA	DX, PROMPT1		;LOAD PROMP1 TO GET READY FOR DISPLAY
	INT	21H			;MAKE IT HAPPEN

	POPA
	RETN
PROMPT_FOR_NAME_1	ENDP
;--------------------------------------------------------------------------
NAME_1_IN	PROC	NEAR
	PUSHA

	MOV	AH, 0AH			;REQUEST KB INPUT
	LEA	DX, PARLIST1		;LOAD ADDY INTO DX
	INT	21H			;MAKE IT HAPPEN

	POPA
	RET
NAME_1_IN	ENDP
;-------------------------------------------------------------------------
SET_CURSOR_2	PROC	NEAR
	PUSHA

	MOV	AH, 02H			;REQUEST CURSOR SET
	MOV	BH, 0			;PAGE NUMBER
	MOV	DH, 03D			;ROW FOR CURSOR
	MOV	DL, 00D			;COL FOR CURSOR
	INT	10H			;MAKE IT HAPPEN

	POPA
	RETN
SET_CURSOR_2 ENDP
;--------------------------------------------------------------------------
PROMPT_FOR_NAME_2	PROC	NEAR
	PUSHA

	MOV	AH, 09H			;REQUEST DISPLAY
	LEA	DX, PROMPT2		;LOAD PROMP1 TO GET READY FOR DISPLAY
	INT	21H			;MAKE IT HAPPEN

	POPA
	RETN
PROMPT_FOR_NAME_2	ENDP
;--------------------------------------------------------------------------
NAME_2_IN	PROC	NEAR
	PUSHA

	MOV	AH, 0AH			;REQUEST KB INPUT
	LEA	DX, PARLIST2		;LOAD ADDY INTO DX
	INT	21H			;MAKE IT HAPPEN

	POPA
	RET
NAME_2_IN	ENDP
;--------------------------------------------------------------------------
COMPARE	PROC	NEAR
	PUSHA

	MOV	AH, ACTLENG1		;AH = LENGTH OF NAME1
	CMP	AH, ACTLENG2		;COMPARE LENGTHS OF NAMES
	JNE	DIFFERENT		;JUMP HERE IF LENGTHS ARE NOT EQUAL
	JMP	COMPARE_LETTERS		;JUMP HERE IF LENGTSH ARE EQUAL

	COMPARE_LETTERS:
		LEA	SI, NAME1	;SI = NAME1 OFFSET
		LEA	DI, NAME2	;DI = NAME2 OFFSET
		MOVZX	CX, ACTLENG1	;CX = NAME1'S LENGTH
		REPE	CMPSB		;REPEAT ON EQUAL BYTES
		JNZ	DIFFERENT	;IF BYTES ARENT EQUAL, THEN JUMP
		JMP	END_COMPARE	;IF BYTES ARE ALL EQUAL, RETURN TO MAIN

	DIFFERENT:
		CALL DIFFERENT		;CALLS PROC TO TELL THEM NAMES ARE NOT EQUAL

	END_COMPARE:
		POPA
		RETN
COMPARE	ENDP
;--------------------------------------------------------------------------
DIFFERENT	PROC	NEAR
	PUSHA

	MOV	AH, 02H			;REQUEST CURSOR SET
	MOV	BH, 00D			;PAGE NUMBER
	MOV	DH, 10D			;ROW FOR CURSOR
	MOV	DL, 00D			;COL FOR CURSOR
	INT	10H			;MAKE IT HAPPEN

	MOV	AH, 09H			;REQUEST DISPLAY
	LEA	DX, PROMPTDIF		;LOAD PROMPDIF TO GET READY FOR DISPLAY
	INT	21H			;MAKE IT HAPPEN

	MOV	AH, 10H			;REQUEST SINGLE CHAR TO ENTER
	INT	16H			;MAKE IT HAPPEN
	MOV	AH,'Y'			;SET AH = Y
	CMP	AH,AL			;COMPARE AH TO WHAT THEY ENTERED
	JNE	CHECK_CASE
	CHECK_CASE:			;MAKE IT CASE INSENSITIVE
		MOV	AH, 'y'		;
		CMP	AH,AL		;
		JE	MAIN		;

FINISH:
	MOV	AH, 02H			;REQUEST CURSOR SET
	MOV	BH, 00D			;PAGE NUMBER
	MOV	DH, 23D			;ROW FOR CURSOR
	MOV	DL, 00D			;COL FOR CURSOR
	INT	10H			;MAKE IT HAPPEN

	MOV	AX, 4C00H
	INT	21H

	POPA
	RETN
DIFFERENT	ENDP
;--------------------------------------------------------------------------
SAME_NAMES	PROC	NEAR
	PUSHA

	MOV	AH, 02H			;REQUEST CURSOR SET
	MOV	BH, 00D			;PAGE NUMBER
	MOV	DH, 10D			;ROW FOR CURSOR
	MOV	DL, 00D			;COL FOR CURSOR
	INT	10H			;MAKE IT HAPPEN

	MOV	AH, 09H			;REQUEST DISPLAY
	LEA	DX, PROMPTSAME		;LOAD PROMPDIF TO GET READY FOR DISPLAY
	INT	21H			;MAKE IT HAPPEN

	MOV	AH, 10H			;REQUEST SINGLE CHAR TO ENTER
	INT	16H			;MAKE IT HAPPEN
	MOV	AH,'Y'			;SET AH = Y
	CMP	AH,AL			;COMPARE AH TO WHAT THEY ENTERED
	JE	MAIN			


	MOV	AH, 02H			;REQUEST CURSOR SET
	MOV	BH, 00D			;PAGE NUMBER
	MOV	DH, 23D			;ROW FOR CURSOR
	MOV	DL, 00D			;COL FOR CURSOR
	INT	10H			;MAKE IT HAPPEN

	MOV	AX,4C00H
	INT	21H

	POPA
SAME_NAMES	ENDP
;**************************************************************************
	END MAIN
 
zman099 said:
Geshtar,

how did you end up learning this stuff then? man when i read this book, i end up using google a lot to look up these terms. I want to learn this stuff, but i'm not very good with C.

I would say that device drivers are the most difficult part of the kernel since there are so many things involved. It will be even more difficult if you are not fluent in C....especially since comments are scarce and they generally don't follow good coding practices IMO (down with the false prophets K&R!)

I also would hope you have some general knowledge of operating system design and preferably linux specifically since you will need some other knowledge of important data structures in the kernel. I did this project as part of an operating systems class that used linux for all the homework assignments so that certainly helped me since it was late in the semester.

I kinda break it up into 4 areas that were involved when I did a driver.

1) the books explaining the basic device driver structures/procedures for linux. This will give you background on on all the basic functions, what you need to do to make modules, load/unload, and information on things such as iomapping procedures, etc.

2) Knowledge of the interface (PCI, RS232, USB, whatever) protocols/specifications.

3) Building on 2), you will want to see what stuff is already existing in the linux kernel for the interface, and how to use it. This is the worst part since you will have to end up poking through the source that has very very very few comments explaining things. This is what nearly killed my project and where I spent probably 75% of my time.

4) A device that you have access to its specifications for its side of the interface (Unless you are making your own device, this is a lot harder than it sounds. Finding devices with open specs out there can be very hard these days since companies are all so protective of their so called 'IP'. You don't want to have to try and reverse engineer a device specification on your first attempt at making a driver).

If you just can't figure specifics of things out, I would suggest going to forums with large communities(like gentoo, fedora, or debian) and try to find someone that already knows about the kind of devices you are working on, so you can ask about ambiguities.

Oh yeah, debugging is a bitch too I might add, since you will either be restricted to printk()'s or have to spend time learning the kernel debug tools of which there are several (I didn't have time in my project to try them, which probably made things harder since it left me with only printk).

That's about all I can say on the subject. I know after my project I am in no hurry to try and make another one for quite a while. Hope it helps.
 
actually i have to refresh again first on C before i continue on to reading these books. Should take me about 2 weeks to get the hang of things again.

Thanks for the help
 
Back
Top