kern

changeset 4:0489a34ab348

- reverted the trunk back to hardware scrolling - added a missing include (ctype.h in term.c) - added a comment explaining what memset16 does - beefed up the README file
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 10 Dec 2010 03:44:34 +0200
parents a9176938bce1
children 633e35c64772
files README src/klibc/string.c src/term.c src/vid.c
diffstat 4 files changed, 46 insertions(+), 65 deletions(-) [+]
line diff
     1.1 --- a/README	Sat Dec 04 10:12:39 2010 +0200
     1.2 +++ b/README	Fri Dec 10 03:44:34 2010 +0200
     1.3 @@ -1,3 +1,43 @@
     1.4 -Code for article 1
     1.5 +Article 1 source code
     1.6 +---------------------
     1.7  Author: John Tsiombikas <nuclear@member.fsf.org>
     1.8 -License: GNU GPL v3 (or later).
     1.9 +
    1.10 +License: GNU GPL v3 or any later version published by the free software
    1.11 +    foundation. See COPYING for details.
    1.12 +
    1.13 +About
    1.14 +-----
    1.15 +This is the supplemental source code for the first part of the introduction to
    1.16 +kernel development articles. It deals with booting up from a multiboot-compliant
    1.17 +boot loader and using the VGA for text output.
    1.18 +
    1.19 +Compiling & Running
    1.20 +-------------------
    1.21 +To compile kernel image (kernel.elf) just type make (or gmake, if your default
    1.22 +make tool is not GNU make). A script called "run" is supplied that will use qemu
    1.23 +to run the kernel in a virtual machine.
    1.24 +
    1.25 +If you wish to boot up the kernel on your computer you need a multiboot
    1.26 +compliant boot loader like GRUB. Since you probably already have GRUB installed
    1.27 +if you're running a GNU/Linux distribution, just add an entry to the GRUB config
    1.28 +file (commonly /boot/grub/menu.lst) similar to this one and reboot:
    1.29 +
    1.30 +title My kernel
    1.31 +root (hdX,Y)  # where X is the disk number and Y the partition (first being 0)
    1.32 +kernel /path/to/kernel_code/kernel.elf    # change this to the actual path
    1.33 +
    1.34 +In case you are using GRUB 2 instead of the original GRUB, you'll have to
    1.35 +consult the documentation on how to modify the above into the GRUB 2 syntax.
    1.36 +
    1.37 +Disclaimer
    1.38 +----------
    1.39 +All programs contain bugs, and this sample code will undoubtedly have its share.
    1.40 +Running buggy kernel code on the real machine is very dangerous and may result
    1.41 +in data loss or even damage to your computer in extreme cases. The author
    1.42 +assumes no responsibility for any such eventuality. Run this code on your
    1.43 +computer at your own risk.
    1.44 +
    1.45 +Contact
    1.46 +-------
    1.47 +For any comments or suggestions regarding the articles or this supplemental
    1.48 +code, please contact me at nuclear@member.fsf.org
     2.1 --- a/src/klibc/string.c	Sat Dec 04 10:12:39 2010 +0200
     2.2 +++ b/src/klibc/string.c	Fri Dec 10 03:44:34 2010 +0200
     2.3 @@ -8,6 +8,9 @@
     2.4  	}
     2.5  }
     2.6  
     2.7 +/* Does the same thing as memset only with 16bit values.
     2.8 + * n in this case is the number of values, not the number of bytes.
     2.9 + */
    2.10  void memset16(void *s, int c, size_t n)
    2.11  {
    2.12  	short *ptr = s;
     3.1 --- a/src/term.c	Sat Dec 04 10:12:39 2010 +0200
     3.2 +++ b/src/term.c	Fri Dec 10 03:44:34 2010 +0200
     3.3 @@ -1,3 +1,4 @@
     3.4 +#include <ctype.h>
     3.5  #include "term.h"
     3.6  #include "vid.h"
     3.7  
     4.1 --- a/src/vid.c	Sat Dec 04 10:12:39 2010 +0200
     4.2 +++ b/src/vid.c	Fri Dec 10 03:44:34 2010 +0200
     4.3 @@ -1,5 +1,3 @@
     4.4 -#if 0
     4.5 -
     4.6  #include <string.h>
     4.7  #include "vid.h"
     4.8  #include "asmops.h"
     4.9 @@ -82,64 +80,3 @@
    4.10  	outb(CRTC_START_HIGH, CRTC_ADDR);
    4.11  	outb((start_addr >> 8) & 0xff, CRTC_DATA);
    4.12  }
    4.13 -#endif	/* 0 */
    4.14 -
    4.15 -#include <string.h>
    4.16 -#include "vid.h"
    4.17 -#include "asmops.h"
    4.18 -
    4.19 -#define WIDTH 80
    4.20 -#define HEIGHT 25
    4.21 -
    4.22 -/* CRTC ports */
    4.23 -#define CRTC_ADDR   0x3d4
    4.24 -#define CRTC_DATA   0x3d5
    4.25 -
    4.26 -/* CRTC registers */
    4.27 -#define CRTC_CURSOR_HIGH 0xe
    4.28 -#define CRTC_CURSOR_LOW  0xf
    4.29 -
    4.30 -/* construct a character with its attributes */
    4.31 -#define VMEM_CHAR(c, fg, bg) \
    4.32 -    ((uint16_t)(c) | (((uint16_t)(fg) & 0xf) << 8) | \
    4.33 -     (((uint16_t)(bg) & 0xf) << 12))
    4.34 -
    4.35 -#define CLEAR_CHAR	VMEM_CHAR(' ', LTGRAY, BLACK)
    4.36 -
    4.37 -/* pointer to the text mode video memory */
    4.38 -static uint16_t *vmem = (uint16_t*)0xb8000;
    4.39 -
    4.40 -void clear_scr(void)
    4.41 -{
    4.42 -    memset16(vmem, CLEAR_CHAR, WIDTH * HEIGHT);
    4.43 -}
    4.44 -
    4.45 -void set_char(char c, int x, int y, int fg, int bg)
    4.46 -{
    4.47 -    vmem[y * WIDTH + x] = VMEM_CHAR(c, fg, bg);
    4.48 -}
    4.49 -
    4.50 -void set_cursor(int x, int y)
    4.51 -{
    4.52 -	int loc;
    4.53 -    if(x < 0 || x >= WIDTH || y < 0 || y >= HEIGHT) {
    4.54 -        loc = 0xffff;
    4.55 -    } else {
    4.56 -        loc = y * WIDTH + x;
    4.57 -    }
    4.58 -
    4.59 -    /* tell the vga where we want the cursor by writing
    4.60 -     * to the "cursor address" register of the CRTC */
    4.61 -    outb(CRTC_CURSOR_LOW, CRTC_ADDR);
    4.62 -    outb(loc, CRTC_DATA);
    4.63 -    outb(CRTC_CURSOR_HIGH, CRTC_ADDR);
    4.64 -    outb(loc >> 8, CRTC_DATA);
    4.65 -}
    4.66 -
    4.67 -void scroll_scr(void)
    4.68 -{
    4.69 -    /* simple scrolling by manually copying memory */
    4.70 -    memmove(vmem, vmem + WIDTH, WIDTH * (HEIGHT - 1) * 2);
    4.71 -    memset16(vmem + WIDTH * (HEIGHT - 1), CLEAR_CHAR, WIDTH);
    4.72 -}
    4.73 -