# HG changeset patch # User John Tsiombikas # Date 1291945474 -7200 # Node ID 0489a34ab348d9c41f4651f2a5940027ec68a2cf # Parent a9176938bce1dfddeb613032d6db0884f92a9ece - 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 diff -r a9176938bce1 -r 0489a34ab348 README --- a/README Sat Dec 04 10:12:39 2010 +0200 +++ b/README Fri Dec 10 03:44:34 2010 +0200 @@ -1,3 +1,43 @@ -Code for article 1 +Article 1 source code +--------------------- Author: John Tsiombikas -License: GNU GPL v3 (or later). + +License: GNU GPL v3 or any later version published by the free software + foundation. See COPYING for details. + +About +----- +This is the supplemental source code for the first part of the introduction to +kernel development articles. It deals with booting up from a multiboot-compliant +boot loader and using the VGA for text output. + +Compiling & Running +------------------- +To compile kernel image (kernel.elf) just type make (or gmake, if your default +make tool is not GNU make). A script called "run" is supplied that will use qemu +to run the kernel in a virtual machine. + +If you wish to boot up the kernel on your computer you need a multiboot +compliant boot loader like GRUB. Since you probably already have GRUB installed +if you're running a GNU/Linux distribution, just add an entry to the GRUB config +file (commonly /boot/grub/menu.lst) similar to this one and reboot: + +title My kernel +root (hdX,Y) # where X is the disk number and Y the partition (first being 0) +kernel /path/to/kernel_code/kernel.elf # change this to the actual path + +In case you are using GRUB 2 instead of the original GRUB, you'll have to +consult the documentation on how to modify the above into the GRUB 2 syntax. + +Disclaimer +---------- +All programs contain bugs, and this sample code will undoubtedly have its share. +Running buggy kernel code on the real machine is very dangerous and may result +in data loss or even damage to your computer in extreme cases. The author +assumes no responsibility for any such eventuality. Run this code on your +computer at your own risk. + +Contact +------- +For any comments or suggestions regarding the articles or this supplemental +code, please contact me at nuclear@member.fsf.org diff -r a9176938bce1 -r 0489a34ab348 src/klibc/string.c --- a/src/klibc/string.c Sat Dec 04 10:12:39 2010 +0200 +++ b/src/klibc/string.c Fri Dec 10 03:44:34 2010 +0200 @@ -8,6 +8,9 @@ } } +/* Does the same thing as memset only with 16bit values. + * n in this case is the number of values, not the number of bytes. + */ void memset16(void *s, int c, size_t n) { short *ptr = s; diff -r a9176938bce1 -r 0489a34ab348 src/term.c --- a/src/term.c Sat Dec 04 10:12:39 2010 +0200 +++ b/src/term.c Fri Dec 10 03:44:34 2010 +0200 @@ -1,3 +1,4 @@ +#include #include "term.h" #include "vid.h" diff -r a9176938bce1 -r 0489a34ab348 src/vid.c --- a/src/vid.c Sat Dec 04 10:12:39 2010 +0200 +++ b/src/vid.c Fri Dec 10 03:44:34 2010 +0200 @@ -1,5 +1,3 @@ -#if 0 - #include #include "vid.h" #include "asmops.h" @@ -82,64 +80,3 @@ outb(CRTC_START_HIGH, CRTC_ADDR); outb((start_addr >> 8) & 0xff, CRTC_DATA); } -#endif /* 0 */ - -#include -#include "vid.h" -#include "asmops.h" - -#define WIDTH 80 -#define HEIGHT 25 - -/* CRTC ports */ -#define CRTC_ADDR 0x3d4 -#define CRTC_DATA 0x3d5 - -/* CRTC registers */ -#define CRTC_CURSOR_HIGH 0xe -#define CRTC_CURSOR_LOW 0xf - -/* construct a character with its attributes */ -#define VMEM_CHAR(c, fg, bg) \ - ((uint16_t)(c) | (((uint16_t)(fg) & 0xf) << 8) | \ - (((uint16_t)(bg) & 0xf) << 12)) - -#define CLEAR_CHAR VMEM_CHAR(' ', LTGRAY, BLACK) - -/* pointer to the text mode video memory */ -static uint16_t *vmem = (uint16_t*)0xb8000; - -void clear_scr(void) -{ - memset16(vmem, CLEAR_CHAR, WIDTH * HEIGHT); -} - -void set_char(char c, int x, int y, int fg, int bg) -{ - vmem[y * WIDTH + x] = VMEM_CHAR(c, fg, bg); -} - -void set_cursor(int x, int y) -{ - int loc; - if(x < 0 || x >= WIDTH || y < 0 || y >= HEIGHT) { - loc = 0xffff; - } else { - loc = y * WIDTH + x; - } - - /* tell the vga where we want the cursor by writing - * to the "cursor address" register of the CRTC */ - outb(CRTC_CURSOR_LOW, CRTC_ADDR); - outb(loc, CRTC_DATA); - outb(CRTC_CURSOR_HIGH, CRTC_ADDR); - outb(loc >> 8, CRTC_DATA); -} - -void scroll_scr(void) -{ - /* simple scrolling by manually copying memory */ - memmove(vmem, vmem + WIDTH, WIDTH * (HEIGHT - 1) * 2); - memset16(vmem + WIDTH * (HEIGHT - 1), CLEAR_CHAR, WIDTH); -} -