[SOS] [PATCH] printk .... euh qui marche c'est pas sûr :-)

Christophe Lucas c.lucas at ifrance.com
Mar 24 Aou 12:16:36 CEST 2004


Salut
Voilà.
(Merci pour les conseils)
Bonne journée.
-- 
Amicalement/Regards
-----------------------------------------------------------------
Christophe Lucas <c.lucas at ifrance.com>         developer/sysadmin
Registered User #271267                       gpg dsa: 0x1E87C874
RotomaLUG member                     http://odie.mcom.fr/~clucas/
-----------------------------------------------------------------
-------------- 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-24 09:56:15.000000000 +0200
@@ -20,6 +20,7 @@
 #include <hwcore/ioports.h>
 
 #include "x86_videomem.h"
+#include "bochs.h"
 
 /* The text video memory starts at address 0xB8000. Odd bytes are the
    ASCII value of the character, even bytes are attribute for the
@@ -43,6 +44,8 @@
 /** The base pointer for the video memory */
 static volatile x86_video_mem *video = (volatile x86_video_mem*)VIDEO;
 
+unsigned char	current_x, current_y, current_attribute ;
+
 
 sos_ret_t sos_x86_videomem_setup(void)
 {
@@ -60,6 +63,10 @@
   /* (RBIL Tables 708 & 654) CRT Register 0xa => bit 5 = cursor OFF */
   outb(1 << 5, CRT_REG_DATA);
 
+	current_x = 0 ;
+	current_y = 1 ; /* pour la visu des irq et exceptions */
+	current_attribute = SOS_X86_VIDEO_FG_YELLOW | SOS_X86_VIDEO_BG_BLUE ;
+  
   return SOS_OK;
 }
 
@@ -126,3 +133,108 @@
   
   return sos_x86_videomem_putstring(row, col, attribute, buff);
 }
+
+
+sos_ret_t printk( const char *format, ... )
+{
+	unsigned i ;
+	char buff[256];
+	va_list ap;
+
+	va_start(ap, format);
+	vsnprintf(buff, sizeof(buff), format, ap);
+	va_end(ap);
+
+	sos_bochs_printf("Avant de lire la chaine: %s\n", buff );
+	print_bochs_coords();
+	sos_bochs_printf("---------------------------------------\n");
+
+	for( i=0 ; i<strlen(buff) ; i++ ) {
+		putchar( buff[i] );
+	}
+	
+	return SOS_OK ;
+}
+
+unsigned char getX()
+{
+	return current_x ;
+}
+
+unsigned char getY()
+{
+	return current_y ;
+}
+
+void scroll_screen( int nb_line )
+{
+	unsigned i, offset ;
+
+	offset = LINES * COLUMNS - nb_line * 80 ;
+
+	for( i=0 ; i<LINES*COLUMNS ; i++ ) {
+		if( i < offset ) {
+			(*video)[i].character = (*video)[i+nb_line*80].character ;
+			(*video)[i].attribute = (*video)[i+nb_line*80].attribute ;
+		} else {
+			(*video)[i].character = 0 ;
+			(*video)[i].attribute = current_attribute ;
+		}
+	}
+
+	if( current_y < nb_line ) {
+		current_y = 0 ;
+	} else {
+		current_y -= nb_line ;
+		current_x = 0 ;
+	}
+	sos_bochs_printf("On scrolle\n");
+	print_bochs_coords();
+}
+
+void print_bochs_coords()
+{
+	sos_bochs_printf("current_x: %d - current_y: %d\n", current_x, current_y );
+}
+
+void gotoxy( int x, int y )
+{
+	current_x = x ;
+	current_y = y ;
+}
+
+
+sos_ret_t putchar( unsigned char car )
+{
+	if( current_x == COLUMNS ) {
+		if( current_y == LINES ) {
+			sos_bochs_printf("On est aussi en bout d'écran\n");
+			scroll_screen(1);
+		 } else { 
+			current_y++ ;
+			current_x = 0 ;
+		}
+	}
+	if( current_y == LINES ) {
+		scroll_screen(1);
+	}
+	if( car == '\n' ) {
+		if( current_y == LINES ) {
+			sos_bochs_printf( "On scrolle car on est en bout d'ecran\n");
+			scroll_screen( 1 ) ;
+		} else {
+			current_x = 0 ;
+			current_y++ ;
+		}
+	} else {
+		putchar_to_xy( current_x , current_y , car );
+		current_x++;
+	}
+	return SOS_OK ;
+}
+
+sos_ret_t putchar_to_xy( unsigned char x , unsigned char y , unsigned char car )
+{
+	return sos_x86_videomem_putchar( y , x , current_attribute , car );
+}
+
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-24 08:56:32.000000000 +0200
@@ -95,4 +95,15 @@
 				  const char *format, /* args */...)
      __attribute__ ((format (printf, 4, 5)));
 
+sos_ret_t printk( const char *format, ... )
+		     __attribute__ ((format (printf, 1, 2)));
+
+void scroll_screen( int nb_line );
+void print_bochs_coords() ;
+sos_ret_t putchar_to_xy( unsigned char x , unsigned char y , unsigned char car );
+sos_ret_t putchar( unsigned char car ) ;
+void gotoxy( int x, int y );
+			 
+
+
 #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-24 10:00:09.000000000 +0200
@@ -93,30 +93,30 @@
   /* Greetings from SOS */
   if (magic == MULTIBOOT_BOOTLOADER_MAGIC)
     /* Loaded with Grub */
-    sos_x86_videomem_printf(1, 0,
-			    SOS_X86_VIDEO_FG_YELLOW | SOS_X86_VIDEO_BG_BLUE,
-			    "Welcome From GRUB to %s%c RAM is %dMB (upper mem = 0x%x kB)",
+	printk("Welcome From GRUB to %s%c RAM is %dMB (upper mem = 0x%x kB)",
 			    "SOS", ',',
 			    (unsigned)(mbi->mem_upper >> 10) + 1,
 			    (unsigned)mbi->mem_upper);
   else
     /* Not loaded with grub */
-    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.\n");
 
   /* Setup SOS IRQs and exceptions subsystem */
   sos_exceptions_setup();
+  printk( "Exceptions are setup.\n");
   sos_irq_setup();
+  printk("IRQ are setup.\n");
 
   /* Configure the timer so as to raise the IRQ0 at a 100Hz rate */
   sos_i8254_set_frequency(100);
+  printk( "i8254 configured to 100Hz.\n");
 
   /* Binding some HW interrupts and exceptions to software routines */
   sos_irq_set_routine(SOS_IRQ_TIMER,


Plus d'informations sur la liste de diffusion Sos