parent
3b27d50edb
commit
f23f3a8a8d
12 changed files with 257 additions and 38 deletions
@ -0,0 +1,13 @@ |
||||
#include <stdint.h> |
||||
|
||||
#include <multiboot.h> |
||||
|
||||
uint32_t multiboot_getAddress() |
||||
{ |
||||
return 0; |
||||
} |
||||
|
||||
uint32_t multiboot_getMagic() |
||||
{ |
||||
return 0; |
||||
} |
@ -0,0 +1,23 @@ |
||||
#include <stdint.h> |
||||
|
||||
#include <multiboot.h> |
||||
|
||||
uint32_t multiboot_getAddress() |
||||
{ |
||||
uint32_t address = 0; |
||||
__asm__( |
||||
"movl %%ebx, %0;" |
||||
:"=r"(address) |
||||
); |
||||
return address; |
||||
} |
||||
|
||||
uint32_t multiboot_getMagic() |
||||
{ |
||||
uint32_t magic = 0; |
||||
__asm__( |
||||
"movl %%eax, %0;" |
||||
:"=r"(magic) |
||||
); |
||||
return magic; |
||||
} |
@ -0,0 +1,8 @@ |
||||
#ifndef __brados_printk_h__ |
||||
#define __brados_printk_h__ |
||||
|
||||
#include <video/vga.h> |
||||
|
||||
int printk(struct vgastate *term, const char *fmt, ...); |
||||
|
||||
#endif |
@ -0,0 +1,79 @@ |
||||
#ifndef __brados_multiboot_h__ |
||||
#define __brados_multiboot_h__ |
||||
|
||||
#include <stdint.h> |
||||
|
||||
// For more information on this structure, see:
|
||||
// http://www.gnu.org/software/grub/manual/multiboot/multiboot.html
|
||||
struct multiboot_header { |
||||
// Indicates the presence and validity of other fields
|
||||
uint32_t flags; |
||||
|
||||
// Present if bit 0 in 'flags' is set
|
||||
uint32_t mem_lower; |
||||
uint32_t mem_upper; |
||||
|
||||
// Present if bit 1 in 'flags' is set
|
||||
uint32_t boot_device; |
||||
|
||||
// Present if bit 2 in 'flags' is set
|
||||
uint32_t cmdline; |
||||
|
||||
// Present if bit 3 in 'flags' is set
|
||||
uint32_t mods_count; |
||||
uint32_t mods_addr; |
||||
|
||||
// Present if bits 4 or 5 are present in 'flags'
|
||||
// NOTE: Bits 4 and 5 are mutually exclusive. Bit 4 indicates fields
|
||||
// related to a.out kernel images, while bit 5 indicated fields related
|
||||
// to ELF kernel images. Since BRaDOS is an ELF kernel, the bit 5 field
|
||||
// names will be used.
|
||||
uint32_t shdr_num; // "tabsize" for an a.out kernel
|
||||
uint32_t shdr_size; // "strsize" for an a.out kernel
|
||||
uint32_t shdr_addr; // "addr" for an a.out kernel
|
||||
uint32_t shdr_shndx; // "reserved" for an a.out kernel
|
||||
|
||||
// Present if bit 6 in 'flags' is set
|
||||
uint32_t mmap_length; |
||||
uint32_t mmap_addr; |
||||
|
||||
// Present if bit 7 in 'flags' is set
|
||||
uint32_t drives_length; |
||||
uint32_t drives_addr; |
||||
|
||||
// Present if bit 8 in 'flags' is set
|
||||
uint32_t config_table; |
||||
|
||||
// Present if bit 9 in 'flags' is set
|
||||
uint32_t boot_loader_name; |
||||
|
||||
// Present if bit 10 in 'flags' is set
|
||||
uint32_t apm_table; |
||||
|
||||
// Present if bit 11 in 'flags' is set
|
||||
uint32_t vbe_control_info; |
||||
uint32_t vbe_mode_info; |
||||
uint16_t vbe_mode; |
||||
uint16_t vbe_interface_seg; |
||||
uint16_t vbe_interface_off; |
||||
uint16_t vbe_interface_len; |
||||
}; |
||||
|
||||
struct multiboot_mmap { |
||||
uint32_t size; |
||||
uint64_t base_addr; |
||||
uint64_t length; |
||||
uint32_t type; |
||||
}; |
||||
|
||||
struct multiboot_mod { |
||||
uint32_t mod_start; |
||||
uint32_t mod_end; |
||||
uint32_t string; |
||||
uint32_t reserved; |
||||
}; |
||||
|
||||
uint32_t multiboot_getAddress(); |
||||
uint32_t multiboot_getMagic(); |
||||
|
||||
#endif |
@ -0,0 +1,76 @@ |
||||
#include <stdarg.h> |
||||
#include <stddef.h> |
||||
|
||||
#include <brados/printk.h> |
||||
#include <brados/string.h> |
||||
#include <video/vga.h> |
||||
|
||||
const char *BASE16 = "0123456789ABCDEF"; |
||||
|
||||
static int printNum(struct vgastate *term, unsigned int num, unsigned int base) |
||||
{ |
||||
int numPrinted = 0; |
||||
int digit = num % base; |
||||
if (num >= base) |
||||
numPrinted += printNum(term, num / base, base); |
||||
term_putChar(term, BASE16[digit]); |
||||
numPrinted++; |
||||
return numPrinted; |
||||
} |
||||
|
||||
int printk(struct vgastate *term, const char *fmt, ...) |
||||
{ |
||||
int numPrinted = 0; |
||||
va_list args; |
||||
va_start(args, fmt); |
||||
|
||||
for (size_t i = 0; i < strlen(fmt); i++) { |
||||
if (fmt[i] == '%') { |
||||
int d; |
||||
unsigned int x; |
||||
char *s; |
||||
switch (fmt[i+1]) { |
||||
case '%': |
||||
term_putChar(term, '%'); |
||||
numPrinted++; |
||||
break; |
||||
case 'c': |
||||
term_putChar(term, (char) va_arg(args, int)); |
||||
numPrinted++; |
||||
break; |
||||
case 'i': |
||||
d = va_arg(args, int); |
||||
if (d < 0) { |
||||
term_putChar(term, '-'); |
||||
numPrinted++; |
||||
d *= -1; |
||||
} |
||||
numPrinted += printNum(term, (unsigned int) d, 10); |
||||
break; |
||||
case 's': |
||||
s = va_arg(args, char *); |
||||
term_writeStr(term, s); |
||||
numPrinted += strlen(s); |
||||
break; |
||||
case 'x': |
||||
x = va_arg(args, unsigned int); |
||||
term_writeStr(term, "0x"); |
||||
numPrinted += 2; |
||||
numPrinted += printNum(term, x, 16); |
||||
break; |
||||
default: |
||||
term_putChar(term, fmt[i+1]); |
||||
numPrinted++; |
||||
break; |
||||
} |
||||
|
||||
i++; |
||||
} else { |
||||
term_putChar(term, fmt[i]); |
||||
numPrinted++; |
||||
} |
||||
} |
||||
|
||||
va_end(args); |
||||
return numPrinted; |
||||
} |
Loading…
Reference in new issue