From c063b0a54df3df85a41330a11f0eb3a3691cfe01 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Thu, 9 Mar 2006 15:35:00 +0000 Subject: [PATCH] * Added assembly code for inb() and outb(). * Print a small message at kernel boot time just to check that the kernel was properly loaded. --- build-kernel | 22 +++++++++++++++------- caca/caca_internals.h | 4 +++- cucul/cucul_internals.h | 4 +++- kernel/kernel.c | 10 ++++++++++ kernel/kernel.h | 21 +++++++++++++++++++-- 5 files changed, 50 insertions(+), 11 deletions(-) diff --git a/build-kernel b/build-kernel index 6423bb3..af36058 100755 --- a/build-kernel +++ b/build-kernel @@ -1,7 +1,7 @@ #! /bin/sh ## Kernel-mode libcaca compilation script -- Sam Hocevar -## $Id: build-dos 333 2006-03-07 12:39:34Z sam $ +## $Id$ set -x set -e @@ -15,16 +15,24 @@ LDFLAGS="-nostdlib -Wl,-N -Wl,-Ttext -Wl,100000" --enable-vga --disable-imlib2 --disable-doc \ --host i386 -(cd cucul && make) -(cd caca && make) +# We need this. +make clean -(cd src && make cacafire-aafire.o) +cd cucul && make && cd .. +cd caca && make && cd .. -(cd kernel && - gcc $CFLAGS -c multiboot.S -o multiboot.o - gcc $CFLAGS $CPPFLAGS -c kernel.c -o kernel.o) +cd src && make cacafire-aafire.o && cd .. + +cd kernel && + gcc $CFLAGS -c multiboot.S -o multiboot.o && + gcc $CFLAGS $CPPFLAGS -c kernel.c -o kernel.o && +cd .. gcc $LDFLAGS -o src/cacafire kernel/multiboot.o kernel/kernel.o src/cacafire-aafire.o caca/.libs/libcaca.a cucul/.libs/libcucul.a objcopy -O binary src/cacafire cacafire.boot +# For further development: create floppy images using the kernel +#gcc -traditional -c -o bootsect.o bootsect.S +#ld -Ttext 0x0 -s --oformat binary bootsect.o -o cacafire.img + diff --git a/caca/caca_internals.h b/caca/caca_internals.h index 04e6ca8..c05115b 100644 --- a/caca/caca_internals.h +++ b/caca/caca_internals.h @@ -26,7 +26,9 @@ # define CUSTOM_INTTYPES typedef unsigned char uint8_t; typedef unsigned short uint16_t; -typedef unsigned int uint32_t; +typedef unsigned long int uint32_t; +typedef long int intptr_t; +typedef long unsigned int uintptr_t; #endif #if !defined(_DOXYGEN_SKIP_ME) diff --git a/cucul/cucul_internals.h b/cucul/cucul_internals.h index a51df3c..0e0405e 100644 --- a/cucul/cucul_internals.h +++ b/cucul/cucul_internals.h @@ -26,7 +26,9 @@ # define CUSTOM_INTTYPES typedef unsigned char uint8_t; typedef unsigned short uint16_t; -typedef unsigned int uint32_t; +typedef unsigned long int uint32_t; +typedef long int intptr_t; +typedef long unsigned int uintptr_t; #endif struct cucul_context diff --git a/kernel/kernel.c b/kernel/kernel.c index c652330..091e4ff 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -29,8 +29,18 @@ static uint32_t *freemem = (uint32_t*) 0x00200000; /* Multiboot kernel entry point */ void cmain(unsigned long int magic, unsigned long int addr) { + static char const text[] = "Booting libcaca kernel..."; + char const *ptr = text; + char *video = (char*)0xB8000; + char *argv[] = { NULL }; int argc = 0; + + /* Print a text message to say hello */ + while(*ptr) + *video = *ptr++; video += 2; + + /* Launch the main program */ main(argc, argv); } diff --git a/kernel/kernel.h b/kernel/kernel.h index 3f690c2..7424e18 100644 --- a/kernel/kernel.h +++ b/kernel/kernel.h @@ -27,12 +27,29 @@ #define __BYTE_ORDER 1 #define __BIG_ENDIAN 2 +/* Assembly code for outb and inb */ +extern inline void outb(unsigned char val, unsigned short port); +extern inline unsigned char inb(unsigned short port); + +extern inline void outb(unsigned char val, unsigned short port) +{ + __asm__ __volatile__ ("outb %b0,%w1" : : "a" (val), "Nd" (port)); +} + +extern inline unsigned char inb(unsigned short port) +{ + unsigned char tmp; + __asm__ __volatile__ ("inb %w1,%0" : "=a" (tmp) : "Nd" (port)); + return tmp; +} + /* Various typedefs -- some are x86-specific */ #define CUSTOM_INTTYPES typedef unsigned char uint8_t; typedef unsigned short uint16_t; -typedef unsigned int uint32_t; -typedef unsigned int uintptr_t; +typedef unsigned long int uint32_t; +typedef long int intptr_t; +typedef long unsigned int uintptr_t; typedef unsigned int size_t;