Kernel Normal Form

From Embedded Xinu
Revision as of 22:18, 26 June 2007 by Michael (talk | contribs) (→‎Example: An example file)
Jump to navigation Jump to search


  • Use tabs to indent code.
  • Use spaces to position comments that appear to the right of code.


  • For functions and control blocks, the brace goes on its own line.
  • Control blocks can be compressed to


  • Spaces around operators are recommended, around = are required.
  • The parenthesis following a keyword is always prefixed by a space.
  • Following a function call or declaration, there is no space between the name and the opening parenthesis.

Function Naming

  • Function names use Java style lowerCamelCase, following Java conventions on capitalization edge cases.
  • Avoid unnecessary abbreviation in function names as reasonable.

Global Variables

  • Global tables are named after the related structure with the suffix "tab", such as devicetab, processtab, etc.


  • The top of any file should contain a comment with the file name and major public functions (as well as the copyright once it is determined)
  • Functions should follow normal javadoc (doxygen in our case) style
  • Comments should be follow /* ... */ style and vary depending on line size


It should be noted that since HTML does not allow the tab character, this example should reflect someone who has their tab stop set to 4 spaces. USE THE \t CHARACTER.

/* exampleFile.c - exampleFile, fileLoaded, getIO                 */
/* Copyright (C) 2007, Marquette University. All rights reserved. */

#include <file.h>

/* End of file marker */
#define FILE_END 0x255

 * Processor Registers
#define zero, $0  /* hardwired zero  */
#define at,   $1  /* assembler temp. */
#define s0,   $16 /* callee saved    */

extern unsigned long long getData(int *register);

 * Load an example file into XINU.
 * @param fd descriptor of file to load
 * @param timeout how long to wait before error.
 * @return OK for success, SYSERR for failure to load
DEVCALL exampleFile(int fd, int timeout)
    int counter;             /* number of cycles we've been waiting   */
    unsigned long long data; /* 64-bits for storing a section of data */

    for ( counter = 0; counter < timeout; counter++ )
        data = getIO();

        /* TODO: perform operation on data */

        /* We have finished reading the file */
        if ( loadXinu(fd) == OK )
            { return OK; }

    return SYSERR;

 * Search for the end of the file
 * @param fd file descriptor to finish reading
 * @return OK if complete, SYSERR if incomplete
LOCAL fileLoaded(int fd)
    /* check for end of file marker */
    if ( filetab[fd].buffer == FILE_END )
        { return OK; }
        { return SYSERR; }

 * Read data from the s0 register through an assembly function.
 * @return data from register s0
unsigned long long getIO()
    unsigned long long data;

    data = getData(s0);

    return data;