MP3 1.0
This is the Doxygen document for ECE391 MP3.
Loading...
Searching...
No Matches
lib.h
Go to the documentation of this file.
1
11#ifndef _LIB_H
12#define _LIB_H
13
14#define VIDEO 0xB8000
15#define USER_VIDEO 0xB9000
16#define NUM_COLS 80
17#define NUM_ROWS 25
18#define FOUR_KB (0x1000)
19
20// Colors
21#define PINK 0x0D
22#define WHITE 0x07
23#define DARK_GREEN 0x02
24#define DARK_BLUE 0x01 // This is really hard to read on black background
25#define BACKGROUND 0x10 // Changes the background to blue and text to black??
26#define BRIGHT_WHITE 0x0F
27#define YELLOW 0xE
28#define ORANGE 0xC
29#define CYAN 0xB
30#define GREEN 0xA
31#define LAVENDER 0x9
32#define FADED_ORANGE 0x6
33#define FADED_PINK 0x5
34#define RED 0x4
35
36#define PROG_EXEC_VIRT_ADDR (0x08000000)
37#define FOUR_MB (0x400000)
38
39#include "types.h"
40
41#define CURSOR_COMMAND 0x3D4
42#define CURSOR_DATA 0x3D5
43
45
50
51/*reset_position just clears the screen_x and screen_y.
52 Function: set curser back to beginning of screen
53*/
54void reset_position(void);
55
56/* void clear(void);
57 * Inputs: void
58 * Return Value: none
59 * Function: Clears current video memory, whether it be the active terminal or the executing one */
60void clear(void);
61
62/* void kclear(char * kvideo_mem);
63 * Inputs: kvideo_mem - the base address of the 4kB chunk to be cleared
64 * Return Value: none
65 * Function: Clears video memory at specified address */
66void kclear(char * kvideo_mem);
67
68/* standard string concatenation code
69 * Function: concatenates source string to the end of the destination string
70 * Returns the destination pointer */
71char* strcat(char* destination, const char* source);
72
73/* Standard printf().
74 * Only supports the following format strings:
75 * %% - print a literal '%' character
76 * %x - print a number in hexadecimal
77 * %u - print a number as an unsigned integer
78 * %d - print a number as a signed integer
79 * %c - print a character
80 * %s - print a string
81 * %#x - print a number in 32-bit aligned hexadecimal, i.e.
82 * print 8 hexadecimal digits, zero-padded on the left.
83 * For example, the hex number "E" would be printed as
84 * "0000000E".
85 * Note: This is slightly different than the libc specification
86 * for the "#" modifier (this implementation doesn't add a "0x" at
87 * the beginning), but I think it's more flexible this way.
88 * Also note: %x is the only conversion specifier that can use
89 * the "#" modifier to alter output. */
90int32_t printf(int8_t *format, ...);
91
92/* int32_t puts(int8_t* s);
93 * Inputs: int_8* s = pointer to a string of characters
94 * Return Value: Number of bytes written
95 * Function: Output a string to the video memory, whether that be the active terminal or the executing one */
97
98/* void putc(uint8_t c);
99 * Inputs: uint_8* c = character to print
100 * Return Value: void
101 * Function: Output a character to the video memory, whether that be the active terminal or the executing one */
102void putc(uint8_t c);
103
104/* void kputc(uint8_t c);
105 * Inputs: uint_8* c = character to print
106 * Return Value: void
107 * Function: Output a character to the display memory ALWAYS*/
108void kputc(uint8_t c);
109
110/* int8_t* itoa(uint32_t value, int8_t* buf, int32_t radix);
111 * Inputs: uint32_t value = number to convert
112 * int8_t* buf = allocated buffer to place string in
113 * int32_t radix = base system. hex, oct, dec, etc.
114 * Return Value: number of bytes written
115 * Function: Convert a number to its ASCII representation, with base "radix" */
116int8_t* itoa(uint32_t value, int8_t* buf, int32_t radix);
117
118/* int8_t* strrev(int8_t* s);
119 * Inputs: int8_t* s = string to reverse
120 * Return Value: reversed string
121 * Function: reverses a string s */
122int8_t* strrev(int8_t* s);
123
124/* uint32_t strlen(const int8_t* s);
125 * Inputs: const int8_t* s = string to take length of
126 * Return Value: length of string s
127 * Function: return length of string s */
128uint32_t strlen(const int8_t* s);
129
130/* void* memset(void* s, int32_t c, uint32_t n);
131 * Inputs: void* s = pointer to memory
132 * int32_t c = value to set memory to
133 * uint32_t n = number of bytes to set
134 * Return Value: new string
135 * Function: set n consecutive bytes of pointer s to value c */
136void* memset(void* s, int32_t c, uint32_t n);
137
138/* void* memset_word(void* s, int32_t c, uint32_t n);
139 * Description: Optimized memset_word
140 * Inputs: void* s = pointer to memory
141 * int32_t c = value to set memory to
142 * uint32_t n = number of bytes to set
143 * Return Value: new string
144 * Function: set lower 16 bits of n consecutive memory locations of pointer s to value c */
145void* memset_word(void* s, int32_t c, uint32_t n);
146
147/* void* memset_dword(void* s, int32_t c, uint32_t n);
148 * Inputs: void* s = pointer to memory
149 * int32_t c = value to set memory to
150 * uint32_t n = number of bytes to set
151 * Return Value: new string
152 * Function: set n consecutive memory locations of pointer s to value c */
153void* memset_dword(void* s, int32_t c, uint32_t n);
154
155/* void* memcpy(void* dest, const void* src, uint32_t n);
156 * Inputs: void* dest = destination of copy
157 * const void* src = source of copy
158 * uint32_t n = number of byets to copy
159 * Return Value: pointer to dest
160 * Function: copy n bytes of src to dest */
161void* memcpy(void* dest, const void* src, uint32_t n);
162
163/* void* memmove(void* dest, const void* src, uint32_t n);
164 * Description: Optimized memmove (used for overlapping memory areas)
165 * Inputs: void* dest = destination of move
166 * const void* src = source of move
167 * uint32_t n = number of byets to move
168 * Return Value: pointer to dest
169 * Function: move n bytes of src to dest */
170void* memmove(void* dest, const void* src, uint32_t n);
171
172/* int32_t strncmp(const int8_t* s1, const int8_t* s2, uint32_t n)
173 * Inputs: const int8_t* s1 = first string to compare
174 * const int8_t* s2 = second string to compare
175 * uint32_t n = number of bytes to compare
176 * Return Value: A zero value indicates that the characters compared
177 * in both strings form the same string.
178 * A value greater than zero indicates that the first
179 * character that does not match has a greater value
180 * in str1 than in str2; And a value less than zero
181 * indicates the opposite.
182 * Function: compares string 1 and string 2 for equality */
183int32_t strncmp(const int8_t* s1, const int8_t* s2, uint32_t n);
184
185/* int8_t* strcpy(int8_t* dest, const int8_t* src)
186 * Inputs: int8_t* dest = destination string of copy
187 * const int8_t* src = source string of copy
188 * Return Value: pointer to dest
189 * Function: copy the source string into the destination string */
190int8_t* strcpy(int8_t* dest, const int8_t* src);
191
192/* int8_t* strcpy(int8_t* dest, const int8_t* src, uint32_t n)
193 * Inputs: int8_t* dest = destination string of copy
194 * const int8_t* src = source string of copy
195 * uint32_t n = number of bytes to copy
196 * Return Value: pointer to dest
197 * Function: copy n bytes of the source string into the destination string */
198int8_t* strncpy(int8_t* dest, const int8_t* src, uint32_t n);
199
200/* void test_interrupts(void)
201 * Inputs: void
202 * Return Value: void
203 * Function: increments video memory. To be used to test rtc */
204void test_interrupts(void); // Gets rid of implicit declaration warning
205
206//******** START OF CODE NICK ADDED *******//
207// These are only used in CP1&2 tests
208
209/* void cputc(uint8_t c);
210 * Inputs: uint_8* c = character to print, but w/ color
211 * Return Value: void
212 * Function: Output a character to the console
213 * Has far less security than the usual putc, since we only use it in our testsuite */
214void cputc(uint8_t color, uint8_t c);
215
216/* Non-Standard printf(). -> Has color
217 * Only supports the following format strings:
218 * %% - print a literal '%' character
219 * %x - print a number in hexadecimal
220 * %u - print a number as an unsigned integer
221 * %d - print a number as a signed integer
222 * %c - print a character
223 * %s - print a string
224 * %#x - print a number in 32-bit aligned hexadecimal, i.e.
225 * print 8 hexadecimal digits, zero-padded on the left.
226 * For example, the hex number "E" would be printed as
227 * "0000000E".
228 * Note: This is slightly different than the libc specification
229 * for the "#" modifier (this implementation doesn't add a "0x" at
230 * the beginning), but I think it's more flexible this way.
231 * Also note: %x is the only conversion specifier that can use
232 * the "#" modifier to alter output. */
233int32_t cprintf(int8_t color, int8_t *format, ...);
234
235/* int32_t cputs(int8_t* s);
236 * Inputs: int_8* s = pointer to a string of characters
237 * Return Value: Number of bytes written
238 * Function: Output a string to the console
239 * Has far less security than the usual putc, since we only use it in our testsuite */
240int32_t cputs(uint8_t color, int8_t* s);
241
242//******** END OF CODE NICK ADDED *******//
243
250void updateCursor(int x,int y);
251
252void switchColor(int color);
253
254/* Port read functions */
255/* Inb reads a byte and returns its value as a zero-extended 32-bit
256 * unsigned int */
257static inline uint32_t inb(port) {
258 uint32_t val;
259 asm volatile (" \n\
260 xorl %0, %0 \n\
261 inb (%w1), %b0 \n\
262 "
263 : "=a"(val)
264 : "d"(port)
265 : "memory"
266 );
267 return val;
268}
269
270/* Reads two bytes from two consecutive ports, starting at "port",
271 * concatenates them little-endian style, and returns them zero-extended
272 * */
273static inline uint32_t inw(port) {
274 uint32_t val;
275 asm volatile (" \n\
276 xorl %0, %0 \n\
277 inw (%w1), %w0 \n\
278 "
279 : "=a"(val)
280 : "d"(port)
281 : "memory"
282 );
283 return val;
284}
285
286/* Reads four bytes from four consecutive ports, starting at "port",
287 * concatenates them little-endian style, and returns them */
288static inline uint32_t inl(port) {
289 uint32_t val;
290 asm volatile ("inl (%w1), %0"
291 : "=a"(val)
292 : "d"(port)
293 : "memory"
294 );
295 return val;
296}
297
298/* Writes a byte to a port */
299#define outb(data, port) \
300do { \
301 asm volatile ("outb %b1, (%w0)" \
302 : \
303 : "d"(port), "a"(data) \
304 : "memory", "cc" \
305 ); \
306} while (0)
307
308/* Writes two bytes to two consecutive ports */
309#define outw(data, port) \
310do { \
311 asm volatile ("outw %w1, (%w0)" \
312 : \
313 : "d"(port), "a"(data) \
314 : "memory", "cc" \
315 ); \
316} while (0)
317
318/* Writes four bytes to four consecutive ports */
319#define outl(data, port) \
320do { \
321 asm volatile ("outl %l1, (%w0)" \
322 : \
323 : "d"(port), "a"(data) \
324 : "memory", "cc" \
325 ); \
326} while (0)
327
328/* Clear interrupt flag - disables interrupts on this processor */
329#define cli() \
330do { \
331 asm volatile ("cli" \
332 : \
333 : \
334 : "memory", "cc" \
335 ); \
336} while (0)
337
338/* Save flags and then clear interrupt flag
339 * Saves the EFLAGS register into the variable "flags", and then
340 * disables interrupts on this processor */
341#define cli_and_save(flags) \
342do { \
343 asm volatile (" \n\
344 pushfl \n\
345 popl %0 \n\
346 cli \n\
347 " \
348 : "=r"(flags) \
349 : \
350 : "memory", "cc" \
351 ); \
352} while (0)
353
354/* Set interrupt flag - enable interrupts on this processor */
355#define sti() \
356do { \
357 asm volatile ("sti" \
358 : \
359 : \
360 : "memory", "cc" \
361 ); \
362} while (0)
363
364/* Restore flags
365 * Puts the value in "flags" into the EFLAGS register. Most often used
366 * after a cli_and_save_flags(flags) */
367#define restore_flags(flags) \
368do { \
369 asm volatile (" \n\
370 pushl %0 \n\
371 popfl \n\
372 " \
373 : \
374 : "r"(flags) \
375 : "memory", "cc" \
376 ); \
377} while (0)
378
379#endif /* _LIB_H */
void cputc(uint8_t color, uint8_t c)
Definition: lib.c:706
int PCB_initialized
Definition: lib.h:49
void updateCursor(int x, int y)
updates cursor location to x,y. Also updates the cursor on the screen if necessary
Definition: lib.c:869
int32_t puts(int8_t *s)
Definition: lib.c:218
void reset_position(void)
Definition: lib.c:21
int8_t * strcpy(int8_t *dest, const int8_t *src)
Definition: lib.c:658
int32_t printf(int8_t *format,...)
Definition: lib.c:105
int8_t * strrev(int8_t *s)
Definition: lib.c:445
int8_t * strncpy(int8_t *dest, const int8_t *src, uint32_t n)
Definition: lib.c:674
void * memset_dword(void *s, int32_t c, uint32_t n)
Definition: lib.c:540
int32_t strncmp(const int8_t *s1, const int8_t *s2, uint32_t n)
Definition: lib.c:637
int keyboard_on
Definition: lib.h:48
char * strcat(char *destination, const char *source)
Definition: lib.c:79
char * video_mem
Definition: lib.h:44
int8_t * itoa(uint32_t value, int8_t *buf, int32_t radix)
Definition: lib.c:409
void * memcpy(void *dest, const void *src, uint32_t n)
Definition: lib.c:560
static uint32_t inb(port)
Definition: lib.h:257
void * memset(void *s, int32_t c, uint32_t n)
Definition: lib.c:477
void switchColor(int color)
Switch the color of the text.
Definition: lib.c:897
static uint32_t inw(port)
Definition: lib.h:273
static uint32_t inl(port)
Definition: lib.h:288
int screen_y
Definition: lib.h:47
void * memmove(void *dest, const void *src, uint32_t n)
Definition: lib.c:606
void test_interrupts(void)
Definition: lib.c:691
void putc(uint8_t c)
Definition: lib.c:231
void kclear(char *kvideo_mem)
Definition: lib.c:68
void kputc(uint8_t c)
Definition: lib.c:324
int32_t cputs(uint8_t color, int8_t *s)
Definition: lib.c:852
void clear(void)
Definition: lib.c:31
int screen_x
Definition: lib.h:46
void * memset_word(void *s, int32_t c, uint32_t n)
Definition: lib.c:520
int32_t cprintf(int8_t color, int8_t *format,...)
Definition: lib.c:738
uint32_t strlen(const int8_t *s)
Definition: lib.c:464
Defines to use the familiar explicitly-sized types in this OS.
int int32_t
Definition: types.h:18
unsigned int uint32_t
Definition: types.h:19
unsigned char uint8_t
Definition: types.h:25
char int8_t
Definition: types.h:24