File tree Expand file tree Collapse file tree 4 files changed +28
-9
lines changed Expand file tree Collapse file tree 4 files changed +28
-9
lines changed Original file line number Diff line number Diff line change @@ -8,14 +8,10 @@ The timer is easy to configure. First we'll declare an `init_timer()` on `cpu/ti
88implement it on ` cpu/timer.c ` . It is just a matter of computing the clock frequency and
99sending the bytes to the appropriate ports.
1010
11- ## se printa gibberish, pq? mirar primero si se arregla con un kprint_int
12- ## yo tenia una funcion que printaba enteros??!!! pero al rever. hacerla ahora bien y
13- ## en el proximo episodio limpiar codigo y crear una libc
14-
11+ We will now fix ` kernel/utils.c int_to_ascii() ` to print the numbers in the correct order.
12+ For that, we need to implement ` reverse() ` and ` strlen() ` .
1513
1614Finally, go back to the ` kernel/kernel.c ` and do two things. Enable interrupts again
1715(very important!) and then initialize the timer interrupt.
1816
19- Go ` make run ` and you'll see the clock ticking! Unfortunately we are not printing the correct values
20- on screen, so we'll go ahead to ` drivers/screen.c ` and add a new ` kprint_int() ` method, also declaring
21- it on ` drivers/screen.h `
17+ Go ` make run ` and you'll see the clock ticking!
Original file line number Diff line number Diff line change 11#include "timer.h"
22#include "../drivers/screen.h"
3+ #include "../kernel/util.h"
34#include "isr.h"
45
56u32 tick = 0 ;
67
78static void timer_callback (registers_t regs ) {
89 tick ++ ;
910 kprint ("Tick: " );
10- kprint (tick );
11+
12+ char * tick_ascii ;
13+ int_to_ascii (tick , tick_ascii );
14+ kprint (tick_ascii );
1115 kprint ("\n" );
1216}
1317
Original file line number Diff line number Diff line change @@ -26,5 +26,22 @@ void int_to_ascii(int n, char str[]) {
2626 if (sign < 0 ) str [i ++ ] = '-' ;
2727 str [i ] = '\0' ;
2828
29- /* TODO: implement "reverse" */
29+ reverse (str );
30+ }
31+
32+ /* K&R */
33+ void reverse (char s []) {
34+ int c , i , j ;
35+ for (i = 0 , j = strlen (s )- 1 ; i < j ; i ++ , j -- ) {
36+ c = s [i ];
37+ s [i ] = s [j ];
38+ s [j ] = c ;
39+ }
40+ }
41+
42+ /* K&R */
43+ int strlen (char s []) {
44+ int i = 0 ;
45+ while (s [i ] != '\0' ) ++ i ;
46+ return i ;
3047}
Original file line number Diff line number Diff line change 66void memory_copy (char * source , char * dest , int nbytes );
77void memory_set (u8 * dest , u8 val , u32 len );
88void int_to_ascii (int n , char str []);
9+ void reverse (char s []);
10+ int strlen (char s []);
911
1012#endif
You can’t perform that action at this time.
0 commit comments