[SOS] printk (just for fun...)
Christophe Lucas
c.lucas at ifrance.com
Ven 20 Aou 11:16:05 CEST 2004
Christophe Lucas (c.lucas at ifrance.com) wrote:
> Salut,
>
> Voici un petit patch implémentant une sorte de printf...
> A vous de voir.
Euh... Désolé, il y a quelques occurences d'un début de driver de
clavier dans le dernier patch, ca compilera donc pas ;-) ou très très
mal!!
Re!!
Bonne journée.
--
Amicalement/Regards
Christophe
-----------------------------------------------------------------
Christophe Lucas <c.lucas at ifrance.com> developer/sysadmin
Registered User #271267 http://odie.mcom.fr/~clucas/
RotomaLUG member (http://www.rotomalug.org) gpg dsa: 0x1E87C874
-----------------------------------------------------------------
Je suis en train de me tater (pas devant tout le monde bien sur) sur la
passage a testing au lieu de stable.
-+- WM sur debian-french: "masturbation mentale d'une queue de
cerise" -+-
-------------- section suivante --------------
diff -urbNB sos-a2-vanilla/drivers/x86_videomem.c sos-a2/drivers/x86_videomem.c
--- sos-a2-vanilla/drivers/x86_videomem.c 2004-06-28 10:28:02.000000000 +0200
+++ sos-a2/drivers/x86_videomem.c 2004-08-20 10:22:31.000000000 +0200
@@ -19,6 +19,8 @@
#include <sos/klibc.h>
#include <hwcore/ioports.h>
#include "x86_videomem.h"
/* The text video memory starts at address 0xB8000. Odd bytes are the
@@ -31,6 +33,7 @@
#define LINES 25
#define COLUMNS 80
+unsigned char currentX, currentY, currentAttribute ;
/** The structure of a character element in the video memory. @see
http://webster.cs.ucr.edu/AoA DOS edition chapter 23 */
@@ -53,6 +56,11 @@
#define CRT_REG_INDEX 0x3d4
#define CRT_REG_DATA 0x3d5
+ currentX = 0 ;
+ /* Pour la ligne du haut montrant interruptions et exceptions */
+ currentY = 1 ;
+ currentAttribute = SOS_X86_VIDEO_FG_YELLOW | SOS_X86_VIDEO_BG_BLUE ;
+
/* CRT index port => ask for access to register 0xa ("cursor
start") */
outb(0x0a, CRT_REG_INDEX);
@@ -83,15 +91,22 @@
const char *str)
{
unsigned video_offs = row*COLUMNS + col;
+ unsigned video_offs_base = video_offs ;
if (video_offs >= LINES*COLUMNS)
return -SOS_EINVAL;
- for ( ; str && *str && (video_offs < LINES*COLUMNS) ; str++, video_offs++)
- {
+ for ( ; str && *str && (video_offs < LINES*COLUMNS) ; str++, video_offs++) {
+ if( (unsigned char)*str == '\n' ) {
+ video_offs += COLUMNS - (video_offs - video_offs_base ) - col - 1 ;
+ } else {
(*video)[video_offs].character = (unsigned char)*str;
(*video)[video_offs].attribute = attribute;
}
+ }
+
+ currentX = (video_offs - row*COLUMNS) % COLUMNS ;
+ currentY = video_offs/COLUMNS - col ;
return SOS_OK;
}
@@ -126,3 +141,15 @@
return sos_x86_videomem_putstring(row, col, attribute, buff);
}
+
+sos_ret_t printk( const char *format, ... )
+{
+ char buff[256];
+ va_list ap;
+
+ va_start(ap, format);
+ vsnprintf(buff, sizeof(buff), format, ap);
+ va_end(ap);
+
+ return sos_x86_videomem_putstring( currentY, currentX, currentAttribute, buff);
+}
diff -urbNB sos-a2-vanilla/drivers/x86_videomem.h sos-a2/drivers/x86_videomem.h
--- sos-a2-vanilla/drivers/x86_videomem.h 2004-06-28 10:28:02.000000000 +0200
+++ sos-a2/drivers/x86_videomem.h 2004-08-20 09:49:33.000000000 +0200
@@ -95,4 +95,8 @@
const char *format, /* args */...)
__attribute__ ((format (printf, 4, 5)));
+
+sos_ret_t printk( const char *format, ... )
+ __attribute__ ((format (printf, 1, 2)));
+
#endif /* _SOS_X86_VIDEOMEM_H_ */
diff -urbNB sos-a2-vanilla/sos/main.c sos-a2/sos/main.c
--- sos-a2-vanilla/sos/main.c 2004-06-28 10:28:02.000000000 +0200
+++ sos-a2/sos/main.c 2004-08-20 10:19:55.000000000 +0200
@@ -28,7 +28,9 @@
#include <sos/assert.h>
#include <drivers/x86_videomem.h>
#include <drivers/bochs.h>
+sos_ui32_t clock_count = 0;
/* Helper function to display each bits of a 32bits integer on the
screen as dark or light carrets */
@@ -54,8 +56,6 @@
/* Clock IRQ handler */
static void clk_it(int intid)
{
- static sos_ui32_t clock_count = 0;
-
display_bits(0, 48,
SOS_X86_VIDEO_FG_LTGREEN | SOS_X86_VIDEO_BG_BLUE,
clock_count);
@@ -101,15 +101,18 @@
(unsigned)mbi->mem_upper);
else
/* Not loaded with grub */
- sos_x86_videomem_printf(1, 0,
+ /* sos_x86_videomem_printf(1, 0,
SOS_X86_VIDEO_FG_YELLOW | SOS_X86_VIDEO_BG_BLUE,
"Welcome to SOS");
+ */
+ printk( "Welcome to SOS\n" );
sos_bochs_putstring("Message in a bochs\n");
/* Setup CPU segmentation and IRQ subsystem */
sos_gdt_setup();
sos_idt_setup();
+ printk( "GDT and IDT are setup: ok\n");
/* Setup SOS IRQs and exceptions subsystem */
sos_exceptions_setup();
@@ -117,10 +120,16 @@
/* Configure the timer so as to raise the IRQ0 at a 100Hz rate */
sos_i8254_set_frequency(100);
+ printk("i8254 configure à 100Hz.\n");
/* Binding some HW interrupts and exceptions to software routines */
sos_irq_set_routine(SOS_IRQ_TIMER,
clk_it);
+ printk("Interruption timer (IRQ 0) captee.\n" );
+
sos_exception_set_routine(SOS_EXCEPT_DIVIDE_ERROR,
divide_ex);
/* Enabling the HW interrupts here, this will make the timer HW
Plus d'informations sur la liste de diffusion Sos