bmarcot / vega

vega -- The Unix-like Operating System for micro-controllers (ARM Cortex-M4)
6 stars 1 forks source link

Basic Kernel Library Functions #1

Open bmarcot opened 8 years ago

bmarcot commented 8 years ago

http://www.csee.umbc.edu/courses/undergraduate/CMSC421/fall02/burt/projects/howto_add_systemcall.html

Here is a few basic kernel library functions that might be useful. Refer to "man" pages for a detailed information. Note that you should use care to use cli() and sti(), since misuse of them can freeze your kernel with no error messages.

printk() NAME printk - print messages to console log

SYNOPSIS

include <linux/kernel.h>

   int printk(const char*fmt, ...)

_kmalloc(), kfree() _ NAME kmalloc, kfree - allocate and free pieces of memory

SYNOPSIS

include <linux/malloc.h>

   void * kmalloc (size_t size, int priority);
   void kfree (void * __ptr);

_cli(), sti() _ NAME cli, sti - disable/enable interrupts

SYNOPSIS

include <asm/system.h>

   extern void cli()
   extern void sti()

get_user(), put_user(), copy_from_user(), copy_to_user()
NAME get_user, put_user, copy_from_user, copy_to_user - copy data between kernel space and user space

SYNOPSIS

include <asm/uaccess.h>

   err = get_user ( x, addr );
   err = put_user ( x, addr );

   bytes_left = copy_from_user(void*to, const void *from,
                               unsigned long n );
   bytes_left = copy_to_user(void*to, const void *from,
                             unsigned long n );