Skip to main content

Posts

Showing posts from 2012

Fix Ubuntu Software Centter Start Up Problem

If you ever run into a problem on Ubuntu where by your system update, software center, or synaptic fail to run properly and you get the following bug report: E: Encountered a section with no Package: header E: Problem with MergeList /var/lib/apt/lists/mx.archive.ubuntu.com_ubuntu_dists_precise-updates_restricted_binary-i386_Packages E: The package lists or status file could not be parsed or opened. You can type the following terminal commands to fix the problem: sudo rm -r /var/lib/apt/lists/* sudo apt-get update The problem was caused by previous attempts to update but your internet network failing to retrieve needed files, which results in Ubuntu getting confused.
Hello everyone. I am always thankful for all of you who follow my blog and my Youtube channel. This post is to announce that from here forward, all my tutorial and source code can be found at: www.soliduscode.com
Okay so I have posted a number of Linux kernel programming videos over at my YouTube channe , however I find that I need a place to post a sample code and the make file to build a module. So here it is. The Makefile obj-m := solidusmodule.o KERNEL_DIR = /lib/modules/3.2.0-25-generic/build PWD := $(shell pwd) all: $(MAKE) -C $(KERNEL_DIR) SUBDIRS=$(PWD) modules clean: rm -rf *.o *.ko *.mod.* *.symvers *.order *~ #include #include #include // file_operations structure- which of course allows use to open/close,read/write to device #include //this is a char driver; makes cdev available #include //used to access semaphores; sychronizatoin behaviors #include //copy_to_user;copy_from_user //(1) Create a structure for our fake device struct fake_device { char data[100]; struct semaphore sem; } virtual_device; //(2) To later register our device we need a cdev object and some other variables struct cdev *mcdev; //m stands 'my' int major_number;

AVR Programming

Hello internet, i just recently posted a video  on how to interface an AVR microcontroller with and LCD Screen (HD44780). Please watch the video and do comment.

Introduction to Linux Kernel Device Drivers

If you toy with electronics, perhaps with microcontrollers (MCU), you might at some point in time decide to interface your microcontroller to your computer.  However, you will come to learn that it would not work for a variety of reasons: one being that you need correct voltage between the computer and the microcontroller, and the second, most critical, you need a way for the computer to recognize and speak to your device. Well, this is where device drivers are useful.  Device drivers are the software need for your computer applications to talk to your device.  The power of a device driver and the possibilities that lie with it can not fully be summarized by myself. So, so whatever reason you many want to write a device driver, in this post, along with others, I will demonstrate how to write a device driver. Major and Minor Numbers When we write a device driver, that device driver will become part of the kernel and it will have an identification number called a major numb

Introduction to Linux Kernel Programming

The Linux kernel is designed as a mixture of a monolithic binary image and a micro-kernel.  This combination allows for the best of both worlds.  On the monolithic side, all the code for the kernel to work with the user and hardware is already installed and ready for fast access, but the downside is that to add more functionality you need to rebuild the entire kernel.   In a different manner, a micro-kernel is composed of small pieces  of code that can be meshed today and more pieces can be added or removed as needed.  However, the downside to micro-kernel is a slower performance. Adding a module to the Kernel Linux is organized as both monolithic, one huge binary, and micro-kernel, as you can add more functionality to it.  The process of adding more functionality to the kernel can be illustrated by the crude image to the left. The process begins by using the command insmod with the name of the kernel module you want (which usually ends with extension *.ko).  From here, the mod

Writing a Scripting Language

One of the projects that I am working on is how to write a scripting language using c++.  At first thought, I imagined the task to be hard, but to my surprise it is quiet easy. In this post I will introduce the basics.  However, I do suggest you visit my youtube channel and watch the video series . token evaluation process  As you can see from the image to the left, my script engine basically takes a string expression, converts it to tokens, determines its meaning, and then compiles the effective byte code. Byte code is the instruction set for my script language.  It will tell our virtual machine or virtual process what an instruction is suppose to do. In more detail, the script engine does a recursive call with the tokens to successfully generate all the corresponding byte code. Source Code This link contains the source code and is version 1 of script.

The Additon & Subtraction in Assembly

There is not much difficulty when it comes to addition and subtraction in assembly programming. Simply, additon and substraction breaks down to the following: add eax , ecx ; eax = eax + ecx, result in eax add eax , DWORD [ ebp - 4 ] ; eax = eax + localVar1, result in eax add DWORD [ ebp - 4 ] , DWORD [ ebp -4 ] ; illegal, with all instruction both operands can never be memory add DWORD [ ebp - 4 ] , eax ; [ebp-4] = [ebp-4] + eax sub eax , ecx ; eax = eax - ecx, result in eax sub eax , DWORD [ ebp - 4 ] ; eax = eax - localVar1, result in eax sub DWORD [ ebp - 4 ] , DWORD [ ebp -4 ] ; illegal, with all instruction both operands can never be memory sub DWORD [ ebp - 4 ] , eax ; [ebp-4] = [ebp-4] - eax A simple program to display the message about an arithetic operation like "Math: 8 + 4 = ?" can be achived b

Please Support My Android Game

Hey everyone, I wrote a game for android called Space Cosmos Defender. Please check it out here  or just type "Space cosmos adventure" on your Google/Play market. Thank you all in advance. Here are some of the the screen-shots of my game. Main menu In game action More Action

Important Lessons to Remember from Assembly Language programming

Okay, so I have been writing assembly language programs for a little bit now and to be honest with everyone, not like it is not obvious, assembly can be very frustrating especially when you write code and it seems to make logical sense.  However, when you run the program, it either says segmentation fault, memory corruption issues, or the program displays a bunch of random text to the screen. Okay so, recently I have been trying to write an application that does something simple using assembly.  The goal was to write a program with Nasm and have it display the number of arguments passed to our program. From my previous posts, we know that ebp+4 contains the return address after the main method is executed.  We also now that ebp+8 is the first parameter passed to main,  ebp+12 is the second parameter, and so on and so on with 4 added to each time.  This is because from the C programming language the main method has a header declaration that is of the following syntax: int main(in
I wrote, with the help of  The Art of Java by Herbert Schildt and James Holmes , a custom parser that evaluates a numerical expression like: "10+32/2".  So the following is the code:   package com.soliduscode.eleanya; import java.util.logging.Handler; /** * * * @author ukaku * */ public class Parser { final int NONE =0; final int DELIMITER =1; final int VARIABLE = 2; final int NUMBER = 3; final int SYNTAX = 0; final int UNBALPARENS=1; final int NOEXP = 2; final int DIVBYZERO=3; final String EOE = "\0"; /**the expression*/ private String exp; /** expression index */ private int expIndex; /**Current token*/ private String token; /**The token type*/ private int tokenType; /** * Return the next token in the expression */ private void getToken(){ //clear values initially tokenType = NONE; token = ""; //check for endl of expression if(expIndex == exp.length()){ token = EOE; return; } //ski

Creating local variables In Assembly

Lets go over how to create local variables inside of a pure assembly source code. Much like always, you will start with a *.asm file that looks like this: source code SECTION .data SECTION .bss SECTION .text global main ;make main available to operating system(os) main: ;create the stack frame push ebp push mov ebp, esp ;destroy the stack frame mov esp, ebp pop ebp ret So, the above is the general layout of an NASM source file.  Our goal here is to create a local variable inside of the main method.  The only way to create a local variable is by using the stack.  Why?  Because we can only declare variable in storage locations and the only available storage locations are: text, bss, and data.  However, text section is only for code, so it is out of the question.  The bss and data sections are appealing, but to declare our "local" variable in these sections will defeat the purpose of these variables being local, t

Writing if statements in assembly language

Programs become more and more interesting when you have dynamic elements in them.  On such way of bringing your program to life is by adding logic.  In assembly, the task can seem dubious and awkward, but once you get a grip on the concept, it will be but second nature. So lets get started! //We want to write an equivalent program to this in assembly #include <stdio.h> int main(){ int x = 40; if( x > 10){ printf("x is greater than 10\n"); }else{ printf("x is lesser than 10\n"); } return 0; } To write this in assembly, consider the following: ;an equivalent program to this in assembly SECTION .data x: dd 40 msg1: db "x is greater than 10", 10, 0 msg2: db "x is lesser than 10", 10, 0 SECTION .text Here, all we did is create our variable x, and the respective message that we will display depending on the result of our if statement. Continually: ;an equivalent program to this in assembly SECTION .data x: dd 40 msg1: db "

NASM Assembly - Hello World

Whenever you start programming, there is usually the first program that prints the phrase "Hello world" to the screen.  Well, let us keep that tradition and write an entire assembly program that print that message to the screen. ;Our Assembly Program file SECTION .data SECTION .bss SECTION .text The preceding is the standard file format of an assembly program using the Netwide assembler, or NASM. To write something to the screen, we first need to store the value of what we want to render to the screen by declaring variables. ;Our Assembly Program file SECTION .data ourHelloMsg: db "Hello world, we are in assembly", 10, 0 ;our simple message SECTION .bss SECTION .text Next, we want to use some real world practical assembly coding to print this message to the screen.  We could simple using the Linux int80h instruction to tell the operating system to print this message (if you aren't sure what I mean by this, do not worry), however we will use the printf

NASM Programming

Many of you, if you are like me, might be interested in how assembly works.  You will be very surprised that assembly is very very easy, especially after you write a couple of simple programs.  But don't get me wrong, you will be frustrated at first, however that frustration, if you channel it right, will lead to serious life long learning and will give you a deeper appreciation of the beauty of assembly. For more tutorial on assembly and visualization of these information, visit my youtube channel . Okay so lets get started. We will be using Netwide Assembler (NASM) to write our program. The general format of NASM file is this: ;This is a comment SECTION .data ;declare variable here SECTION .bss ;declare actual, dynamic variable SECTION .text ;where your program code/assembly code lives ; Working with Data Section In your .data section, you can declare variables like this: nameOfVariable: db 32 ;this declares a variable names nameOfVariable with byte valu

C++ Smart Pointer

The following is the finalized code for a simple C++ smart pointer as demonstrated by my youtube video:  here Usage: void main(){      ...     Pointer<ObjectType> pointer(new ObjectType);     ... } /*  * Pointer.h  *  *  Created on: Mar 16, 2012  *      Author: ukaku  */ #ifndef POINTER_H_ #define POINTER_H_ #include <iostream> using namespace std ; /**  * Reference represents a counter that will be incremented or decremented as  * the number of references to a pecticular pointer is made;  *  * where data means: a symbol used to point to, or associate to another object  */ class ReferenceCounter { private :     int counter ; public :     ReferenceCounter ( ) {         counter = 0 ;   //initially set to zero     }     void increase ( ) {         counter ++;   //increase it     }     int decrease ( ) {         -- counter ;   //decrease it         if ( counter < 0 ) {             cout << "ReferenceCouner is <