@@ -1,90 +1,115 @@ | |||||
/* | |||||
/* | |||||
* libcaca | |||||
* libcaca Colour ASCII-Art library | |||||
* Copyright (c) 2006 Sam Hocevar <sam@hocevar.net> | |||||
* 2009 Jean-Yves Lamoureux <jylam@lnxscene.org> | |||||
* All Rights Reserved | |||||
* | |||||
* $Id: kernel.h 4154 2009-12-20 13:33:11Z jylam $ | |||||
* | |||||
* This library is free software. It comes without any warranty, to | |||||
* the extent permitted by applicable law. You can redistribute it | |||||
* and/or modify it under the terms of the Do What The Fuck You Want | |||||
* To Public License, Version 2, as published by Sam Hocevar. See | |||||
* http://sam.zoy.org/wtfpl/COPYING for more details. | |||||
*/ | |||||
/* | |||||
*'freely' inspired by http://jojo.ouvaton.org/dossiers/boot_sector/tutorial02.html | *'freely' inspired by http://jojo.ouvaton.org/dossiers/boot_sector/tutorial02.html | ||||
* (actually, that's mostly copied, with minor compilation fixes) | * (actually, that's mostly copied, with minor compilation fixes) | ||||
*/ | */ | ||||
#include "kernel.h" | #include "kernel.h" | ||||
#include "klibc.h" | #include "klibc.h" | ||||
#define GDTBASE 0x800 /* Physical address of GDT */ | |||||
#define GDTSIZE 0xFF /* Maximum table size (in entries) */ | |||||
/* Segment descriptor */ | |||||
struct gdtdesc { | |||||
u16 lim0_15; | |||||
u16 base0_15; | |||||
u8 base16_23; | |||||
u8 acces; | |||||
u8 lim16_19 : 4; | |||||
u8 other : 4; | |||||
u8 base24_31; | |||||
} __attribute__ ((packed)); | |||||
/* GDTR register */ | |||||
struct gdtr { | |||||
u16 limite ; | |||||
u32 base ; | |||||
} __attribute__ ((packed)); | |||||
#define GDTBASE 0x800 /* Physical address of GDT */ | |||||
#define GDTSIZE 0xFF /* Maximum table size (in entries) */ | |||||
/* Segment descriptor */ | |||||
struct gdtdesc | |||||
{ | |||||
u16 lim0_15; | |||||
u16 base0_15; | |||||
u8 base16_23; | |||||
u8 acces; | |||||
u8 lim16_19:4; | |||||
u8 other:4; | |||||
u8 base24_31; | |||||
} __attribute__ ((packed)); | |||||
/* GDTR register */ | |||||
struct gdtr | |||||
{ | |||||
u16 limite; | |||||
u32 base; | |||||
} __attribute__ ((packed)); | |||||
struct gdtr kgdtr; | struct gdtr kgdtr; | ||||
struct gdtdesc kgdt[GDTSIZE] = {{0, 0, 0, 0, 0, 0, 0}}; | |||||
struct gdtdesc kgdt[GDTSIZE] = { {0, 0, 0, 0, 0, 0, 0} }; | |||||
unsigned int kgdtptr = 1; | unsigned int kgdtptr = 1; | ||||
void init_code_desc(u32 base, u32 limite, struct gdtdesc* desc); | |||||
void init_data_desc(u32 base, u32 limite, struct gdtdesc* desc); | |||||
void init_code_desc(u32 base, u32 limite, struct gdtdesc *desc); | |||||
void init_data_desc(u32 base, u32 limite, struct gdtdesc *desc); | |||||
void add_gdt_desc(struct gdtdesc desc); | void add_gdt_desc(struct gdtdesc desc); | ||||
void init_gdt(void); | void init_gdt(void); | ||||
void init_gdt_desc(u32 base, u32 limite, u8 acces, u8 other, struct gdtdesc* desc) { | |||||
desc->lim0_15 = (limite & 0xffff); | |||||
desc->base0_15 = (base & 0xffff); | |||||
desc->base16_23 = (base & 0xff0000)>>16; | |||||
desc->acces = acces; | |||||
desc->lim16_19 = (limite & 0xf0000)>>16; | |||||
desc->other = (other & 0xf); | |||||
desc->base24_31 = (base & 0xff000000)>>24; | |||||
return; | |||||
void init_gdt_desc(u32 base, u32 limite, u8 acces, u8 other, | |||||
struct gdtdesc *desc) | |||||
{ | |||||
desc->lim0_15 = (limite & 0xffff); | |||||
desc->base0_15 = (base & 0xffff); | |||||
desc->base16_23 = (base & 0xff0000) >> 16; | |||||
desc->acces = acces; | |||||
desc->lim16_19 = (limite & 0xf0000) >> 16; | |||||
desc->other = (other & 0xf); | |||||
desc->base24_31 = (base & 0xff000000) >> 24; | |||||
return; | |||||
} | } | ||||
void init_code_desc(u32 base, u32 limite, struct gdtdesc* desc) { | |||||
init_gdt_desc(base, limite, 0x9B, 0x0D, desc); | |||||
void init_code_desc(u32 base, u32 limite, struct gdtdesc *desc) | |||||
{ | |||||
init_gdt_desc(base, limite, 0x9B, 0x0D, desc); | |||||
} | } | ||||
void init_data_desc(u32 base, u32 limite, struct gdtdesc* desc) { | |||||
init_gdt_desc(base, limite, 0x93, 0x0D, desc); | |||||
void init_data_desc(u32 base, u32 limite, struct gdtdesc *desc) | |||||
{ | |||||
init_gdt_desc(base, limite, 0x93, 0x0D, desc); | |||||
} | } | ||||
void add_gdt_desc(struct gdtdesc desc) { | |||||
kgdt[kgdtptr] = desc; | |||||
kgdtptr++; | |||||
void add_gdt_desc(struct gdtdesc desc) | |||||
{ | |||||
kgdt[kgdtptr] = desc; | |||||
kgdtptr++; | |||||
} | } | ||||
void init_gdt(void) { | |||||
struct gdtdesc code, data, stack; | |||||
/* initialisation des descripteurs de segment */ | |||||
init_code_desc(0x0, 0xFFFFF, &code); | |||||
init_data_desc(0x0, 0xFFFFF, &data); | |||||
init_gdt_desc(0, 0x10, 0x97, 0x0D, &stack); | |||||
add_gdt_desc(code); | |||||
add_gdt_desc(data); | |||||
add_gdt_desc(stack); | |||||
/* initialisation de la structure pour GDTR */ | |||||
kgdtr.limite = GDTSIZE*8; | |||||
kgdtr.base = GDTBASE; | |||||
/* recopie de la GDT a son adresse */ | |||||
memcpy((void*)kgdtr.base, kgdt, kgdtr.limite); | |||||
/* chargement du registre GDTR */ | |||||
asm("lgdtl (kgdtr)"); | |||||
/* initialisation des segments */ | |||||
asm(" movw $0x10,%ax \n \ | |||||
void init_gdt(void) | |||||
{ | |||||
struct gdtdesc code, data, stack; | |||||
/* initialisation des descripteurs de segment */ | |||||
init_code_desc(0x0, 0xFFFFF, &code); | |||||
init_data_desc(0x0, 0xFFFFF, &data); | |||||
init_gdt_desc(0, 0x10, 0x97, 0x0D, &stack); | |||||
add_gdt_desc(code); | |||||
add_gdt_desc(data); | |||||
add_gdt_desc(stack); | |||||
/* initialisation de la structure pour GDTR */ | |||||
kgdtr.limite = GDTSIZE * 8; | |||||
kgdtr.base = GDTBASE; | |||||
/* recopie de la GDT a son adresse */ | |||||
memcpy((void *)kgdtr.base, kgdt, kgdtr.limite); | |||||
/* chargement du registre GDTR */ | |||||
asm("lgdtl (kgdtr)"); | |||||
/* initialisation des segments */ | |||||
asm(" movw $0x10,%ax \n \ | |||||
movw %ax, %ds \n \ | movw %ax, %ds \n \ | ||||
movw %ax, %es \n \ | movw %ax, %es \n \ | ||||
movw %ax, %fs \n \ | movw %ax, %fs \n \ | ||||
@@ -97,5 +122,3 @@ void init_gdt(void) { | |||||
ljmp $0x08,$next \n \ | ljmp $0x08,$next \n \ | ||||
next: \n"); | next: \n"); | ||||
} | } | ||||
@@ -1,34 +1,52 @@ | |||||
/* | |||||
/* | |||||
* libcaca | |||||
* libcaca Colour ASCII-Art library | |||||
* Copyright (c) 2006 Sam Hocevar <sam@hocevar.net> | |||||
* 2009 Jean-Yves Lamoureux <jylam@lnxscene.org> | |||||
* All Rights Reserved | |||||
* | |||||
* $Id: kernel.h 4154 2009-12-20 13:33:11Z jylam $ | |||||
* | |||||
* This library is free software. It comes without any warranty, to | |||||
* the extent permitted by applicable law. You can redistribute it | |||||
* and/or modify it under the terms of the Do What The Fuck You Want | |||||
* To Public License, Version 2, as published by Sam Hocevar. See | |||||
* http://sam.zoy.org/wtfpl/COPYING for more details. | |||||
*/ | |||||
/* | |||||
*'freely' inspired by http://jojo.ouvaton.org/dossiers/boot_sector/tutorial02.html | *'freely' inspired by http://jojo.ouvaton.org/dossiers/boot_sector/tutorial02.html | ||||
* (actually, that's mostly copied, with minor compilation fixes) | * (actually, that's mostly copied, with minor compilation fixes) | ||||
*/ | */ | ||||
#include "kernel.h" | #include "kernel.h" | ||||
#include "klibc.h" | #include "klibc.h" | ||||
#define IDTBASE 0 /* GDT Physical address */ | |||||
#define IDTSIZE 256 /* Max descriptor count */ | |||||
#define INTGATE 0x8E00 /* Interruptions */ | |||||
#define TRAPGATE 0x8F00 /* Syscalls */ | |||||
#define TASKGATE 0x8500 /* Task switching */ | |||||
#define IDTBASE 0 /* GDT Physical address */ | |||||
#define IDTSIZE 256 /* Max descriptor count */ | |||||
#define INTGATE 0x8E00 /* Interruptions */ | |||||
#define TRAPGATE 0x8F00 /* Syscalls */ | |||||
#define TASKGATE 0x8500 /* Task switching */ | |||||
/* segment descriptor */ | /* segment descriptor */ | ||||
struct idtdesc { | |||||
u16 offset0_15; | |||||
u16 select; | |||||
struct idtdesc | |||||
{ | |||||
u16 offset0_15; | |||||
u16 select; | |||||
u16 type; | u16 type; | ||||
u16 offset16_31; | |||||
} __attribute__ ((packed)); | |||||
u16 offset16_31; | |||||
} __attribute__ ((packed)); | |||||
/* IDTR register */ | /* IDTR register */ | ||||
struct idtr { | |||||
u16 limite; | |||||
u32 base; | |||||
} __attribute__ ((packed)); | |||||
struct idtr | |||||
{ | |||||
u16 limite; | |||||
u32 base; | |||||
} __attribute__ ((packed)); | |||||
struct idtr kidtr; | struct idtr kidtr; | ||||
/* IDT table */ | /* IDT table */ | ||||
struct idtdesc kidt[IDTSIZE] = {{0, 0, 0, 0}}; | |||||
struct idtdesc kidt[IDTSIZE] = { {0, 0, 0, 0} }; | |||||
/* pointer on a free IDT entry */ | /* pointer on a free IDT entry */ | ||||
unsigned int kidtptr = 0; | unsigned int kidtptr = 0; | ||||
@@ -64,69 +82,73 @@ void k_irq7(void); | |||||
void k_irq8(void); | void k_irq8(void); | ||||
void init_idt_desc(u32 offset, u16 select, u16 type, struct idtdesc* desc) { | |||||
desc->offset0_15 = (offset & 0xffff); | |||||
desc->select = select; | |||||
desc->type = type; | |||||
desc->offset16_31 = (offset & 0xffff0000) >> 16; | |||||
return; | |||||
void init_idt_desc(u32 offset, u16 select, u16 type, struct idtdesc *desc) | |||||
{ | |||||
desc->offset0_15 = (offset & 0xffff); | |||||
desc->select = select; | |||||
desc->type = type; | |||||
desc->offset16_31 = (offset & 0xffff0000) >> 16; | |||||
return; | |||||
} | } | ||||
void add_idt_desc(struct idtdesc desc) { | |||||
kidt[kidtptr++] = desc; | |||||
return; | |||||
void add_idt_desc(struct idtdesc desc) | |||||
{ | |||||
kidt[kidtptr++] = desc; | |||||
return; | |||||
} | } | ||||
void init_idt(void) { | |||||
struct idtdesc desc; | |||||
int i; | |||||
for(i=0;i<IDTSIZE;i++) { | |||||
init_idt_desc((u32)default_int, 0x08, INTGATE, &desc); | |||||
add_idt_desc(desc); | |||||
} | |||||
init_idt_desc((u32)k_int0, 0x08, INTGATE, &kidt[0]); | |||||
init_idt_desc((u32)k_int1, 0x08, INTGATE, &kidt[1]); | |||||
init_idt_desc((u32)k_int2, 0x08, INTGATE, &kidt[2]); | |||||
init_idt_desc((u32)k_int3, 0x08, INTGATE, &kidt[3]); | |||||
init_idt_desc((u32)k_int4, 0x08, INTGATE, &kidt[4]); | |||||
init_idt_desc((u32)k_int5, 0x08, INTGATE, &kidt[5]); | |||||
init_idt_desc((u32)k_int6, 0x08, INTGATE, &kidt[6]); | |||||
init_idt_desc((u32)k_int7, 0x08, INTGATE, &kidt[7]); | |||||
init_idt_desc((u32)k_int8, 0x08, INTGATE, &kidt[8]); | |||||
init_idt_desc((u32)k_int9, 0x08, INTGATE, &kidt[9]); | |||||
init_idt_desc((u32)k_int10, 0x08, INTGATE, &kidt[10]); | |||||
init_idt_desc((u32)k_int11, 0x08, INTGATE, &kidt[11]); | |||||
init_idt_desc((u32)k_int12, 0x08, INTGATE, &kidt[12]); | |||||
init_idt_desc((u32)k_int13, 0x08, INTGATE, &kidt[13]); | |||||
init_idt_desc((u32)k_int14, 0x08, INTGATE, &kidt[14]); | |||||
init_idt_desc((u32)k_int15, 0x08, INTGATE, &kidt[15]); | |||||
init_idt_desc((u32)k_int16, 0x08, INTGATE, &kidt[16]); | |||||
init_idt_desc((u32)k_int17, 0x08, INTGATE, &kidt[17]); | |||||
init_idt_desc((u32)k_int18, 0x08, INTGATE, &kidt[18]); | |||||
init_idt_desc((u32)k_irq0, 0x08, INTGATE, &kidt[32]); | |||||
init_idt_desc((u32)k_irq1, 0x08, INTGATE, &kidt[33]); | |||||
init_idt_desc((u32)k_irq2, 0x08, INTGATE, &kidt[34]); | |||||
init_idt_desc((u32)k_irq3, 0x08, INTGATE, &kidt[35]); | |||||
init_idt_desc((u32)k_irq4, 0x08, INTGATE, &kidt[36]); | |||||
init_idt_desc((u32)k_irq5, 0x08, INTGATE, &kidt[37]); | |||||
init_idt_desc((u32)k_irq6, 0x08, INTGATE, &kidt[38]); | |||||
init_idt_desc((u32)k_irq7, 0x08, INTGATE, &kidt[39]); | |||||
init_idt_desc((u32)k_irq8, 0x08, INTGATE, &kidt[40]); | |||||
kidtr.limite = IDTSIZE*8; | |||||
kidtr.base = IDTBASE; | |||||
memcpy((void*)kidtr.base, kidt, kidtr.limite); | |||||
void init_idt(void) | |||||
{ | |||||
struct idtdesc desc; | |||||
int i; | |||||
for (i = 0; i < IDTSIZE; i++) | |||||
{ | |||||
init_idt_desc((u32) default_int, 0x08, INTGATE, &desc); | |||||
add_idt_desc(desc); | |||||
} | |||||
init_idt_desc((u32) k_int0, 0x08, INTGATE, &kidt[0]); | |||||
init_idt_desc((u32) k_int1, 0x08, INTGATE, &kidt[1]); | |||||
init_idt_desc((u32) k_int2, 0x08, INTGATE, &kidt[2]); | |||||
init_idt_desc((u32) k_int3, 0x08, INTGATE, &kidt[3]); | |||||
init_idt_desc((u32) k_int4, 0x08, INTGATE, &kidt[4]); | |||||
init_idt_desc((u32) k_int5, 0x08, INTGATE, &kidt[5]); | |||||
init_idt_desc((u32) k_int6, 0x08, INTGATE, &kidt[6]); | |||||
init_idt_desc((u32) k_int7, 0x08, INTGATE, &kidt[7]); | |||||
init_idt_desc((u32) k_int8, 0x08, INTGATE, &kidt[8]); | |||||
init_idt_desc((u32) k_int9, 0x08, INTGATE, &kidt[9]); | |||||
init_idt_desc((u32) k_int10, 0x08, INTGATE, &kidt[10]); | |||||
init_idt_desc((u32) k_int11, 0x08, INTGATE, &kidt[11]); | |||||
init_idt_desc((u32) k_int12, 0x08, INTGATE, &kidt[12]); | |||||
init_idt_desc((u32) k_int13, 0x08, INTGATE, &kidt[13]); | |||||
init_idt_desc((u32) k_int14, 0x08, INTGATE, &kidt[14]); | |||||
init_idt_desc((u32) k_int15, 0x08, INTGATE, &kidt[15]); | |||||
init_idt_desc((u32) k_int16, 0x08, INTGATE, &kidt[16]); | |||||
init_idt_desc((u32) k_int17, 0x08, INTGATE, &kidt[17]); | |||||
init_idt_desc((u32) k_int18, 0x08, INTGATE, &kidt[18]); | |||||
init_idt_desc((u32) k_irq0, 0x08, INTGATE, &kidt[32]); | |||||
init_idt_desc((u32) k_irq1, 0x08, INTGATE, &kidt[33]); | |||||
init_idt_desc((u32) k_irq2, 0x08, INTGATE, &kidt[34]); | |||||
init_idt_desc((u32) k_irq3, 0x08, INTGATE, &kidt[35]); | |||||
init_idt_desc((u32) k_irq4, 0x08, INTGATE, &kidt[36]); | |||||
init_idt_desc((u32) k_irq5, 0x08, INTGATE, &kidt[37]); | |||||
init_idt_desc((u32) k_irq6, 0x08, INTGATE, &kidt[38]); | |||||
init_idt_desc((u32) k_irq7, 0x08, INTGATE, &kidt[39]); | |||||
init_idt_desc((u32) k_irq8, 0x08, INTGATE, &kidt[40]); | |||||
kidtr.limite = IDTSIZE * 8; | |||||
kidtr.base = IDTBASE; | |||||
memcpy((void *)kidtr.base, kidt, kidtr.limite); | |||||
#define printf(format, ...) { char __str[255]; sprintf (__str, format, __VA_ARGS__); print(__str);} | #define printf(format, ...) { char __str[255]; sprintf (__str, format, __VA_ARGS__); print(__str);} | ||||
printf("Loading IDT from 0x%x\n", kidtr); | printf("Loading IDT from 0x%x\n", kidtr); | ||||
#undef printf | #undef printf | ||||
asm("lidtl (kidtr)"); | asm("lidtl (kidtr)"); | ||||
} | |||||
} |
@@ -1,112 +1,185 @@ | |||||
/* | |||||
* libcaca | |||||
* libcaca Colour ASCII-Art library | |||||
* Copyright (c) 2006 Sam Hocevar <sam@hocevar.net> | |||||
* 2009 Jean-Yves Lamoureux <jylam@lnxscene.org> | |||||
* All Rights Reserved | |||||
* | |||||
* $Id: kernel.h 4154 2009-12-20 13:33:11Z jylam $ | |||||
* | |||||
* This library is free software. It comes without any warranty, to | |||||
* the extent permitted by applicable law. You can redistribute it | |||||
* and/or modify it under the terms of the Do What The Fuck You Want | |||||
* To Public License, Version 2, as published by Sam Hocevar. See | |||||
* http://sam.zoy.org/wtfpl/COPYING for more details. | |||||
*/ | |||||
#include "kernel.h" | #include "kernel.h" | ||||
#include "klibc.h" | #include "klibc.h" | ||||
#include "drivers/timer.h" | #include "drivers/timer.h" | ||||
void idt_default_int(void) { | |||||
print("!! Unknown interrupt\n"); | |||||
void idt_default_int(void) | |||||
{ | |||||
print("!! Unknown interrupt\n"); | |||||
} | } | ||||
void idt_int0(void) { | |||||
print("!! Divide by 0\n "); | |||||
void idt_int0(void) | |||||
{ | |||||
print("!! Divide by 0\n "); | |||||
} | } | ||||
void idt_int1(void) { | |||||
print("!! Debug exception "); | |||||
void idt_int1(void) | |||||
{ | |||||
print("!! Debug exception "); | |||||
} | } | ||||
void idt_int2(void) { | |||||
print("!! NMI "); | |||||
void idt_int2(void) | |||||
{ | |||||
print("!! NMI "); | |||||
} | } | ||||
void idt_int3(void) { | |||||
print("!! Breakpoint "); | |||||
void idt_int3(void) | |||||
{ | |||||
print("!! Breakpoint "); | |||||
} | } | ||||
void idt_int4(void) { | |||||
print("!! Overflow "); | |||||
void idt_int4(void) | |||||
{ | |||||
print("!! Overflow "); | |||||
} | } | ||||
void idt_int5(void) { | |||||
print("!! BoundCheck "); | |||||
void idt_int5(void) | |||||
{ | |||||
print("!! BoundCheck "); | |||||
} | } | ||||
void idt_int6(void) { | |||||
print("!! Invalid Opcode "); | |||||
void idt_int6(void) | |||||
{ | |||||
print("!! Invalid Opcode "); | |||||
} | } | ||||
void idt_int7(void) { | |||||
print("!! Coprocessor not available "); | |||||
void idt_int7(void) | |||||
{ | |||||
print("!! Coprocessor not available "); | |||||
} | } | ||||
void idt_int8(void) { | |||||
print("!! Double Fault "); | |||||
void idt_int8(void) | |||||
{ | |||||
print("!! Double Fault "); | |||||
} | } | ||||
void idt_int9(void) { | |||||
print("!! Coprocessor segment overrun "); | |||||
void idt_int9(void) | |||||
{ | |||||
print("!! Coprocessor segment overrun "); | |||||
} | } | ||||
void idt_int10(void) { | |||||
print("!! Invalid TSS "); | |||||
void idt_int10(void) | |||||
{ | |||||
print("!! Invalid TSS "); | |||||
} | } | ||||
void idt_int11(void) { | |||||
print("!! Segment not present "); | |||||
void idt_int11(void) | |||||
{ | |||||
print("!! Segment not present "); | |||||
} | } | ||||
void idt_int12(void) { | |||||
print("!! Stack exception "); | |||||
void idt_int12(void) | |||||
{ | |||||
print("!! Stack exception "); | |||||
} | } | ||||
void idt_int13(void) { | |||||
print("!! General protection exception "); | |||||
void idt_int13(void) | |||||
{ | |||||
print("!! General protection exception "); | |||||
} | } | ||||
void idt_int14(void) { | |||||
print("!! Page fault "); | |||||
void idt_int14(void) | |||||
{ | |||||
print("!! Page fault "); | |||||
} | } | ||||
void idt_int15(void) { | |||||
print("!! Intel reserved int "); | |||||
void idt_int15(void) | |||||
{ | |||||
print("!! Intel reserved int "); | |||||
} | } | ||||
void idt_int16(void) { | |||||
print("!! Coprocessor error "); | |||||
void idt_int16(void) | |||||
{ | |||||
print("!! Coprocessor error "); | |||||
} | } | ||||
void idt_int17(void) { | |||||
print("!! Intel reserved (2) "); | |||||
void idt_int17(void) | |||||
{ | |||||
print("!! Intel reserved (2) "); | |||||
} | } | ||||
void idt_int18(void) { | |||||
print("i18 "); | |||||
void idt_int18(void) | |||||
{ | |||||
print("i18 "); | |||||
} | } | ||||
/* Used by Channel0 timer */ | /* Used by Channel0 timer */ | ||||
void idt_irq0(void) { | |||||
void idt_irq0(void) | |||||
{ | |||||
ticks++; | ticks++; | ||||
} | } | ||||
void idt_irq2(void) { | |||||
print("IRQ 2"); | |||||
void idt_irq2(void) | |||||
{ | |||||
print("IRQ 2"); | |||||
} | } | ||||
void idt_irq3(void) { | |||||
print("IRQ 3"); | |||||
void idt_irq3(void) | |||||
{ | |||||
print("IRQ 3"); | |||||
} | } | ||||
void idt_irq4(void) { | |||||
print("IRQ 4"); | |||||
void idt_irq4(void) | |||||
{ | |||||
print("IRQ 4"); | |||||
} | } | ||||
void idt_irq5(void) { | |||||
print("IRQ 5"); | |||||
void idt_irq5(void) | |||||
{ | |||||
print("IRQ 5"); | |||||
} | } | ||||
void idt_irq6(void) { | |||||
print("IRQ 6"); | |||||
void idt_irq6(void) | |||||
{ | |||||
print("IRQ 6"); | |||||
} | } | ||||
void idt_irq7(void) { | |||||
print("IRQ 7"); | |||||
void idt_irq7(void) | |||||
{ | |||||
print("IRQ 7"); | |||||
} | } | ||||
void idt_irq8(void) { | |||||
print("IRQ 8"); | |||||
void idt_irq8(void) | |||||
{ | |||||
print("IRQ 8"); | |||||
} | } | ||||
extern unsigned char kbdmap[]; | extern unsigned char kbdmap[]; | ||||
/* Keyboard irq is 1 */ | /* Keyboard irq is 1 */ | ||||
void kbd_int(void) { | |||||
unsigned char i; | |||||
do { | |||||
i=inb(0x64); | |||||
} while((i & 0x01) == 0); | |||||
i=inb(0x60); | |||||
i--; | |||||
if(i<0x80){ | |||||
putcar(kbdmap[i*4]); | |||||
} | |||||
} | |||||
void kbd_int(void) | |||||
{ | |||||
unsigned char i; | |||||
do | |||||
{ | |||||
i = inb(0x64); | |||||
} | |||||
while ((i & 0x01) == 0); | |||||
i = inb(0x60); | |||||
i--; | |||||
if (i < 0x80) | |||||
{ | |||||
putcar(kbdmap[i * 4]); | |||||
} | |||||
} |
@@ -1,3 +1,20 @@ | |||||
/* | |||||
* libcaca | |||||
* libcaca Colour ASCII-Art library | |||||
* Copyright (c) 2006 Sam Hocevar <sam@hocevar.net> | |||||
* 2009 Jean-Yves Lamoureux <jylam@lnxscene.org> | |||||
* All Rights Reserved | |||||
* | |||||
* $Id: kernel.h 4154 2009-12-20 13:33:11Z jylam $ | |||||
* | |||||
* This library is free software. It comes without any warranty, to | |||||
* the extent permitted by applicable law. You can redistribute it | |||||
* and/or modify it under the terms of the Do What The Fuck You Want | |||||
* To Public License, Version 2, as published by Sam Hocevar. See | |||||
* http://sam.zoy.org/wtfpl/COPYING for more details. | |||||
*/ | |||||
#include "klibc.h" | #include "klibc.h" | ||||
#define PIC_MASTER_ICW1 0x20 | #define PIC_MASTER_ICW1 0x20 | ||||
@@ -9,32 +26,32 @@ | |||||
void init_pic(void) | void init_pic(void) | ||||
{ | { | ||||
/* MASTER */ | |||||
outbp(PIC_MASTER_ICW1,0x11); // Init 8259A-1 | |||||
/* MASTER */ | |||||
outbp(PIC_MASTER_ICW1, 0x11); // Init 8259A-1 | |||||
/* ICW2 - start vector = 32 */ | /* ICW2 - start vector = 32 */ | ||||
outbp(PIC_MASTER_ICW2,0x20); // IRQ 0-7 mapped to 0x20-0x27 | |||||
outbp(PIC_MASTER_ICW2, 0x20); // IRQ 0-7 mapped to 0x20-0x27 | |||||
/* IICW3 */ | /* IICW3 */ | ||||
outbp(PIC_MASTER_ICW2,0x04); // 8259A-1 has slave | |||||
outbp(PIC_MASTER_ICW2, 0x04); // 8259A-1 has slave | |||||
/* ICW4 */ | /* ICW4 */ | ||||
outbp(PIC_MASTER_ICW2,0x01); | |||||
outbp(PIC_MASTER_ICW2, 0x01); | |||||
/* Int mask */ | /* Int mask */ | ||||
outbp(PIC_MASTER_ICW2,0xFF); | |||||
/* SLAVE */ | |||||
outbp(PIC_SLAVE_ICW1,0x11); | |||||
/* ICW2 - start vector = 96 */ | |||||
outbp(PIC_SLAVE_ICW2,0x70); | |||||
/* ICW3 */ | |||||
outbp(PIC_SLAVE_ICW2,0x02); | |||||
/* ICW4 */ | |||||
outbp(PIC_SLAVE_ICW2,0x01); | |||||
/* Int Mask */ | |||||
outbp(PIC_SLAVE_ICW2,0xFF); | |||||
/* Unmask irqs */ | |||||
outbp(0x21,0xFD); | |||||
outbp(PIC_MASTER_ICW2, 0xFF); | |||||
/* SLAVE */ | |||||
outbp(PIC_SLAVE_ICW1, 0x11); | |||||
/* ICW2 - start vector = 96 */ | |||||
outbp(PIC_SLAVE_ICW2, 0x70); | |||||
/* ICW3 */ | |||||
outbp(PIC_SLAVE_ICW2, 0x02); | |||||
/* ICW4 */ | |||||
outbp(PIC_SLAVE_ICW2, 0x01); | |||||
/* Int Mask */ | |||||
outbp(PIC_SLAVE_ICW2, 0xFF); | |||||
/* Unmask irqs */ | |||||
outbp(0x21, 0xFD); | |||||
} | } | ||||
static unsigned int cached_irq_mask = 0xffff; | static unsigned int cached_irq_mask = 0xffff; | ||||
@@ -45,29 +62,31 @@ static unsigned int cached_irq_mask = 0xffff; | |||||
void disable_interrupt(char irq) | void disable_interrupt(char irq) | ||||
{ | { | ||||
unsigned int mask = 1 << irq; | |||||
cached_irq_mask |= mask; | |||||
if (irq & 8) { | |||||
outb(0xA1, cached_A1); | |||||
} else { | |||||
outb(0x21, cached_21); | |||||
unsigned int mask = 1 << irq; | |||||
cached_irq_mask |= mask; | |||||
if (irq & 8) | |||||
{ | |||||
outb(0xA1, cached_A1); | |||||
} | |||||
else | |||||
{ | |||||
outb(0x21, cached_21); | |||||
} | } | ||||
} | } | ||||
void enable_interrupt(char irq) | void enable_interrupt(char irq) | ||||
{ | { | ||||
unsigned int mask = ~(1 << irq); | |||||
cached_irq_mask &= mask; | |||||
if (irq & 8) { | |||||
outb(0xA1, cached_A1); | |||||
} else { | |||||
outb(0x21, cached_21); | |||||
unsigned int mask = ~(1 << irq); | |||||
cached_irq_mask &= mask; | |||||
if (irq & 8) | |||||
{ | |||||
outb(0xA1, cached_A1); | |||||
} | |||||
else | |||||
{ | |||||
outb(0x21, cached_21); | |||||
} | } | ||||
} | } | ||||
@@ -1,19 +1,33 @@ | |||||
/* | |||||
* libcaca | |||||
* libcaca Colour ASCII-Art library | |||||
* Copyright (c) 2006 Sam Hocevar <sam@hocevar.net> | |||||
* 2009 Jean-Yves Lamoureux <jylam@lnxscene.org> | |||||
* All Rights Reserved | |||||
* | |||||
* $Id: kernel.h 4154 2009-12-20 13:33:11Z jylam $ | |||||
* | |||||
* This library is free software. It comes without any warranty, to | |||||
* the extent permitted by applicable law. You can redistribute it | |||||
* and/or modify it under the terms of the Do What The Fuck You Want | |||||
* To Public License, Version 2, as published by Sam Hocevar. See | |||||
* http://sam.zoy.org/wtfpl/COPYING for more details. | |||||
*/ | |||||
#include "kernel.h" | #include "kernel.h" | ||||
#include "klibc.h" | #include "klibc.h" | ||||
extern int kmain(void); | extern int kmain(void); | ||||
/* Entry point | |||||
* bootsect.asm loaded this file at 0x0100:0x0, which is mapped | |||||
* at 0x8:0x1000 (selector+8bytes, offset 1000 (0x100 + 0x0) | |||||
*/ | |||||
/* Entry point bootsect.asm loaded this file at 0x0100:0x0, which is mapped | |||||
at 0x8:0x1000 (selector+8bytes, offset 1000 (0x100 + 0x0) */ | |||||
/* 0x1000 */ | /* 0x1000 */ | ||||
void _start(void) { | |||||
void _start(void) | |||||
{ | |||||
clearscreen(); | |||||
clearscreen(); | |||||
init_gdt(); | init_gdt(); | ||||
print("Loading IDT\n"); | print("Loading IDT\n"); | ||||
init_idt(); | init_idt(); | ||||
@@ -21,10 +35,11 @@ void _start(void) { | |||||
init_pic(); | init_pic(); | ||||
print("Running kmain()\n"); | print("Running kmain()\n"); | ||||
sti; | sti; | ||||
kmain(); /* Call kernel's kmain() */ | |||||
while(1) { /* Never return */ | |||||
print("hlt;\n"); | |||||
kmain(); /* Call kernel's kmain() */ | |||||
while (1) | |||||
{ /* Never return */ | |||||
print("hlt;\n"); | |||||
} | } | ||||
} | } | ||||
@@ -1 +1,19 @@ | |||||
/* | |||||
* libcaca | |||||
* libcaca Colour ASCII-Art library | |||||
* Copyright (c) 2006 Sam Hocevar <sam@hocevar.net> | |||||
* 2009 Jean-Yves Lamoureux <jylam@lnxscene.org> | |||||
* All Rights Reserved | |||||
* | |||||
* $Id: kernel.h 4154 2009-12-20 13:33:11Z jylam $ | |||||
* | |||||
* This library is free software. It comes without any warranty, to | |||||
* the extent permitted by applicable law. You can redistribute it | |||||
* and/or modify it under the terms of the Do What The Fuck You Want | |||||
* To Public License, Version 2, as published by Sam Hocevar. See | |||||
* http://sam.zoy.org/wtfpl/COPYING for more details. | |||||
*/ | |||||
extern int _start(void); | extern int _start(void); |
@@ -1,3 +1,18 @@ | |||||
/* | |||||
* libcaca | |||||
* libcaca Colour ASCII-Art library | |||||
* Copyright (c) 2006 Sam Hocevar <sam@hocevar.net> | |||||
* 2009 Jean-Yves Lamoureux <jylam@lnxscene.org> | |||||
* All Rights Reserved | |||||
* | |||||
* $Id: kernel.h 4154 2009-12-20 13:33:11Z jylam $ | |||||
* | |||||
* This library is free software. It comes without any warranty, to | |||||
* the extent permitted by applicable law. You can redistribute it | |||||
* and/or modify it under the terms of the Do What The Fuck You Want | |||||
* To Public License, Version 2, as published by Sam Hocevar. See | |||||
* http://sam.zoy.org/wtfpl/COPYING for more details. | |||||
*/ | |||||
#include "kernel.h" | #include "kernel.h" | ||||
#include "klibc.h" | #include "klibc.h" | ||||
@@ -20,7 +35,7 @@ int floppy_get_info(struct floppy_info *floppy_info) | |||||
"2.88mb 3.5in" | "2.88mb 3.5in" | ||||
}; | }; | ||||
memcpy(floppy_info->drive[0].type, drive_type[a], | memcpy(floppy_info->drive[0].type, drive_type[a], | ||||
strlen(drive_type[a]) + 1); | strlen(drive_type[a]) + 1); | ||||
memcpy(floppy_info->drive[1].type, drive_type[b], | memcpy(floppy_info->drive[1].type, drive_type[b], | ||||
@@ -29,7 +44,7 @@ int floppy_get_info(struct floppy_info *floppy_info) | |||||
floppy_info->count = 0; | floppy_info->count = 0; | ||||
if (a != 0) | if (a != 0) | ||||
floppy_info->count++; | floppy_info->count++; | ||||
if (b != 0) | |||||
if (b != 0) | |||||
floppy_info->count++; | floppy_info->count++; | ||||
return 0; | return 0; | ||||
@@ -1,14 +1,32 @@ | |||||
struct floppy_drive { | |||||
/* | |||||
* libcaca | |||||
* libcaca Colour ASCII-Art library | |||||
* Copyright (c) 2006 Sam Hocevar <sam@hocevar.net> | |||||
* 2009 Jean-Yves Lamoureux <jylam@lnxscene.org> | |||||
* All Rights Reserved | |||||
* | |||||
* $Id: kernel.h 4154 2009-12-20 13:33:11Z jylam $ | |||||
* | |||||
* This library is free software. It comes without any warranty, to | |||||
* the extent permitted by applicable law. You can redistribute it | |||||
* and/or modify it under the terms of the Do What The Fuck You Want | |||||
* To Public License, Version 2, as published by Sam Hocevar. See | |||||
* http://sam.zoy.org/wtfpl/COPYING for more details. | |||||
*/ | |||||
struct floppy_drive | |||||
{ | |||||
char type[16]; | char type[16]; | ||||
u8 status; | |||||
u8 status; | |||||
}; | }; | ||||
struct floppy_info { | |||||
int count; | |||||
struct floppy_info | |||||
{ | |||||
int count; | |||||
struct floppy_drive drive[2]; | struct floppy_drive drive[2]; | ||||
}; | }; | ||||
int floppy_get_info(struct floppy_info *floppy_info); | int floppy_get_info(struct floppy_info *floppy_info); | ||||
void floppy_print_info(struct floppy_info *floppy_info); | void floppy_print_info(struct floppy_info *floppy_info); | ||||
int floppy_get_status(void); | |||||
int floppy_get_status(void); |
@@ -1,101 +1,117 @@ | |||||
/* | |||||
* libcaca | |||||
* libcaca Colour ASCII-Art library | |||||
* Copyright (c) 2006 Sam Hocevar <sam@hocevar.net> | |||||
* 2009 Jean-Yves Lamoureux <jylam@lnxscene.org> | |||||
* All Rights Reserved | |||||
* | |||||
* $Id: kernel.h 4154 2009-12-20 13:33:11Z jylam $ | |||||
* | |||||
* This library is free software. It comes without any warranty, to | |||||
* the extent permitted by applicable law. You can redistribute it | |||||
* and/or modify it under the terms of the Do What The Fuck You Want | |||||
* To Public License, Version 2, as published by Sam Hocevar. See | |||||
* http://sam.zoy.org/wtfpl/COPYING for more details. | |||||
*/ | |||||
#include "kernel.h" | #include "kernel.h" | ||||
unsigned char kbdmap[] = { | unsigned char kbdmap[] = { | ||||
0x1B, 0x1B, 0x1B, 0x1B, /* esc (0x01) */ | |||||
'1', '!', '1', '1', | |||||
'2', '@', '2', '2', | |||||
'3', '#', '3', '3', | |||||
'4', '$', '4', '4', | |||||
'5', '%', '5', '5', | |||||
'6', '^', '6', '6', | |||||
'7', '&', '7', '7', | |||||
'8', '*', '8', '8', | |||||
'9', '(', '9', '9', | |||||
'0', ')', '0', '0', | |||||
'-', '_', '-', '-', | |||||
'=', '+', '=', '=', | |||||
0x08, 0x08, 0x7F, 0x08, /* backspace */ | |||||
0x09, 0x09, 0x09, 0x09, /* tab */ | |||||
'q', 'Q', 'q', 'q', | |||||
'w', 'W', 'w', 'w', | |||||
'e', 'E', 'e', 'e', | |||||
'r', 'R', 'r', 'r', | |||||
't', 'T', 't', 't', | |||||
'y', 'Y', 'y', 'y', | |||||
'u', 'U', 'u', 'u', | |||||
'i', 'I', 'i', 'i', | |||||
'o', 'O', 'o', 'o', | |||||
'p', 'P', 'p', 'p', | |||||
'[', '{', '[', '[', | |||||
']', '}', ']', ']', | |||||
0x0A, 0x0A, 0x0A, 0x0A, /* enter */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* ctrl */ | |||||
'a', 'A', 'a', 'a', | |||||
's', 'S', 's', 's', | |||||
'd', 'D', 'd', 'd', | |||||
'f', 'F', 'f', 'f', | |||||
'g', 'G', 'g', 'g', | |||||
'h', 'H', 'h', 'h', | |||||
'j', 'J', 'j', 'j', | |||||
'k', 'K', 'k', 'k', | |||||
'l', 'L', 'l', 'l', | |||||
';', ':', ';', ';', | |||||
0x27, 0x22, 0x27, 0x27, /* '" */ | |||||
'`', '~', '`', '`', /* `~ */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* Lshift (0x2a) */ | |||||
'\\', '|', '\\', '\\', | |||||
'z', 'Z', 'z', 'z', | |||||
'x', 'X', 'x', 'x', | |||||
'c', 'C', 'c', 'c', | |||||
'v', 'V', 'v', 'v', | |||||
'b', 'B', 'b', 'b', | |||||
'n', 'N', 'n', 'n', | |||||
'm', 'M', 'm', 'm', | |||||
0x2C, 0x3C, 0x2C, 0x2C, /* ,< */ | |||||
0x2E, 0x3E, 0x2E, 0x2E, /* .> */ | |||||
0x2F, 0x3F, 0x2F, 0x2F, /* /? */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* Rshift (0x36) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x37) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x38) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x39) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x3a) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x3b) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x3c) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x3d) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x3e) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x3f) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x40) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x41) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x42) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x43) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x44) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x45) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x46) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x47) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x48) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x49) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x4a) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x4b) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x4c) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x4d) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x4e) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x4f) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x50) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x51) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x52) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x53) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x54) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x55) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x56) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x57) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x58) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x59) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x5a) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x5b) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x5c) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x5d) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x5e) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x5f) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x60) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF /* (0x61) */ | |||||
0x1B, 0x1B, 0x1B, 0x1B, /* esc (0x01) */ | |||||
'1', '!', '1', '1', | |||||
'2', '@', '2', '2', | |||||
'3', '#', '3', '3', | |||||
'4', '$', '4', '4', | |||||
'5', '%', '5', '5', | |||||
'6', '^', '6', '6', | |||||
'7', '&', '7', '7', | |||||
'8', '*', '8', '8', | |||||
'9', '(', '9', '9', | |||||
'0', ')', '0', '0', | |||||
'-', '_', '-', '-', | |||||
'=', '+', '=', '=', | |||||
0x08, 0x08, 0x7F, 0x08, /* backspace */ | |||||
0x09, 0x09, 0x09, 0x09, /* tab */ | |||||
'q', 'Q', 'q', 'q', | |||||
'w', 'W', 'w', 'w', | |||||
'e', 'E', 'e', 'e', | |||||
'r', 'R', 'r', 'r', | |||||
't', 'T', 't', 't', | |||||
'y', 'Y', 'y', 'y', | |||||
'u', 'U', 'u', 'u', | |||||
'i', 'I', 'i', 'i', | |||||
'o', 'O', 'o', 'o', | |||||
'p', 'P', 'p', 'p', | |||||
'[', '{', '[', '[', | |||||
']', '}', ']', ']', | |||||
0x0A, 0x0A, 0x0A, 0x0A, /* enter */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* ctrl */ | |||||
'a', 'A', 'a', 'a', | |||||
's', 'S', 's', 's', | |||||
'd', 'D', 'd', 'd', | |||||
'f', 'F', 'f', 'f', | |||||
'g', 'G', 'g', 'g', | |||||
'h', 'H', 'h', 'h', | |||||
'j', 'J', 'j', 'j', | |||||
'k', 'K', 'k', 'k', | |||||
'l', 'L', 'l', 'l', | |||||
';', ':', ';', ';', | |||||
0x27, 0x22, 0x27, 0x27, /* '" */ | |||||
'`', '~', '`', '`', /* `~ */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* Lshift (0x2a) */ | |||||
'\\', '|', '\\', '\\', | |||||
'z', 'Z', 'z', 'z', | |||||
'x', 'X', 'x', 'x', | |||||
'c', 'C', 'c', 'c', | |||||
'v', 'V', 'v', 'v', | |||||
'b', 'B', 'b', 'b', | |||||
'n', 'N', 'n', 'n', | |||||
'm', 'M', 'm', 'm', | |||||
0x2C, 0x3C, 0x2C, 0x2C, /* ,< */ | |||||
0x2E, 0x3E, 0x2E, 0x2E, /* .> */ | |||||
0x2F, 0x3F, 0x2F, 0x2F, /* /? */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* Rshift (0x36) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x37) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x38) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x39) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x3a) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x3b) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x3c) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x3d) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x3e) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x3f) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x40) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x41) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x42) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x43) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x44) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x45) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x46) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x47) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x48) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x49) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x4a) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x4b) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x4c) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x4d) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x4e) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x4f) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x50) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x51) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x52) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x53) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x54) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x55) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x56) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x57) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x58) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x59) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x5a) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x5b) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x5c) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x5d) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x5e) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x5f) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF, /* (0x60) */ | |||||
0xFF, 0xFF, 0xFF, 0xFF /* (0x61) */ | |||||
}; | }; |
@@ -1,4 +1,19 @@ | |||||
/* | |||||
* libcaca | |||||
* libcaca Colour ASCII-Art library | |||||
* Copyright (c) 2006 Sam Hocevar <sam@hocevar.net> | |||||
* 2009 Jean-Yves Lamoureux <jylam@lnxscene.org> | |||||
* All Rights Reserved | |||||
* | |||||
* $Id: kernel.h 4154 2009-12-20 13:33:11Z jylam $ | |||||
* | |||||
* This library is free software. It comes without any warranty, to | |||||
* the extent permitted by applicable law. You can redistribute it | |||||
* and/or modify it under the terms of the Do What The Fuck You Want | |||||
* To Public License, Version 2, as published by Sam Hocevar. See | |||||
* http://sam.zoy.org/wtfpl/COPYING for more details. | |||||
*/ | |||||
#include "kernel.h" | #include "kernel.h" | ||||
#include "klibc.h" | #include "klibc.h" | ||||
#include "memory.h" | #include "memory.h" | ||||
@@ -0,0 +1,15 @@ | |||||
/* | |||||
* libcaca | |||||
* libcaca Colour ASCII-Art library | |||||
* Copyright (c) 2006 Sam Hocevar <sam@hocevar.net> | |||||
* 2009 Jean-Yves Lamoureux <jylam@lnxscene.org> | |||||
* All Rights Reserved | |||||
* | |||||
* $Id: kernel.h 4154 2009-12-20 13:33:11Z jylam $ | |||||
* | |||||
* This library is free software. It comes without any warranty, to | |||||
* the extent permitted by applicable law. You can redistribute it | |||||
* and/or modify it under the terms of the Do What The Fuck You Want | |||||
* To Public License, Version 2, as published by Sam Hocevar. See | |||||
* http://sam.zoy.org/wtfpl/COPYING for more details. | |||||
*/ |
@@ -1,11 +1,19 @@ | |||||
/* | /* | ||||
* processor.c | |||||
* | |||||
* libcaca | |||||
* libcaca Colour ASCII-Art library | |||||
* Copyright (c) 2006 Sam Hocevar <sam@hocevar.net> | |||||
* 2009 Jean-Yves Lamoureux <jylam@lnxscene.org> | |||||
* All Rights Reserved | |||||
* | * | ||||
* Created by Jean-Yves Lamoureux on 12/19/09. | |||||
* Copyright 2009 Frob. All rights reserved. | |||||
* $Id: kernel.h 4154 2009-12-20 13:33:11Z jylam $ | |||||
* | * | ||||
* This library is free software. It comes without any warranty, to | |||||
* the extent permitted by applicable law. You can redistribute it | |||||
* and/or modify it under the terms of the Do What The Fuck You Want | |||||
* To Public License, Version 2, as published by Sam Hocevar. See | |||||
* http://sam.zoy.org/wtfpl/COPYING for more details. | |||||
*/ | */ | ||||
#include "kernel.h" | #include "kernel.h" | ||||
#include "klibc.h" | #include "klibc.h" | ||||
#include "processor.h" | #include "processor.h" | ||||
@@ -14,7 +22,7 @@ | |||||
int processor_get_info(struct processor_info *processor_info) | int processor_get_info(struct processor_info *processor_info) | ||||
{ | { | ||||
processor_info->id = 0; | processor_info->id = 0; | ||||
/* Vendor String */ | /* Vendor String */ | ||||
int code = CPUID_GETVENDORSTRING; | int code = CPUID_GETVENDORSTRING; | ||||
unsigned int where[5]; | unsigned int where[5]; | ||||
@@ -1,81 +1,99 @@ | |||||
/* | |||||
* libcaca | |||||
* libcaca Colour ASCII-Art library | |||||
* Copyright (c) 2006 Sam Hocevar <sam@hocevar.net> | |||||
* 2009 Jean-Yves Lamoureux <jylam@lnxscene.org> | |||||
* All Rights Reserved | |||||
* | |||||
* $Id: kernel.h 4154 2009-12-20 13:33:11Z jylam $ | |||||
* | |||||
* This library is free software. It comes without any warranty, to | |||||
* the extent permitted by applicable law. You can redistribute it | |||||
* and/or modify it under the terms of the Do What The Fuck You Want | |||||
* To Public License, Version 2, as published by Sam Hocevar. See | |||||
* http://sam.zoy.org/wtfpl/COPYING for more details. | |||||
*/ | |||||
enum cpuid_requests { | |||||
enum cpuid_requests | |||||
{ | |||||
CPUID_GETVENDORSTRING, | CPUID_GETVENDORSTRING, | ||||
CPUID_GETFEATURES, | CPUID_GETFEATURES, | ||||
CPUID_GETTLB, | CPUID_GETTLB, | ||||
CPUID_GETSERIAL, | CPUID_GETSERIAL, | ||||
CPUID_INTELEXTENDED=0x80000000, | |||||
CPUID_INTELEXTENDED = 0x80000000, | |||||
CPUID_INTELFEATURES, | CPUID_INTELFEATURES, | ||||
CPUID_INTELBRANDSTRING, | CPUID_INTELBRANDSTRING, | ||||
CPUID_INTELBRANDSTRINGMORE, | CPUID_INTELBRANDSTRINGMORE, | ||||
CPUID_INTELBRANDSTRINGEND, | CPUID_INTELBRANDSTRINGEND, | ||||
}; | }; | ||||
enum { | |||||
CPUID_FEAT_ECX_SSE3 = 1 << 0, | |||||
CPUID_FEAT_ECX_PCLMUL = 1 << 1, | |||||
CPUID_FEAT_ECX_DTES64 = 1 << 2, | |||||
CPUID_FEAT_ECX_MONITOR = 1 << 3, | |||||
CPUID_FEAT_ECX_DS_CPL = 1 << 4, | |||||
CPUID_FEAT_ECX_VMX = 1 << 5, | |||||
CPUID_FEAT_ECX_SMX = 1 << 6, | |||||
CPUID_FEAT_ECX_EST = 1 << 7, | |||||
CPUID_FEAT_ECX_TM2 = 1 << 8, | |||||
CPUID_FEAT_ECX_SSSE3 = 1 << 9, | |||||
CPUID_FEAT_ECX_CID = 1 << 10, | |||||
CPUID_FEAT_ECX_FMA = 1 << 12, | |||||
CPUID_FEAT_ECX_CX16 = 1 << 13, | |||||
CPUID_FEAT_ECX_ETPRD = 1 << 14, | |||||
CPUID_FEAT_ECX_PDCM = 1 << 15, | |||||
CPUID_FEAT_ECX_DCA = 1 << 18, | |||||
CPUID_FEAT_ECX_SSE4_1 = 1 << 19, | |||||
CPUID_FEAT_ECX_SSE4_2 = 1 << 20, | |||||
CPUID_FEAT_ECX_x2APIC = 1 << 21, | |||||
CPUID_FEAT_ECX_MOVBE = 1 << 22, | |||||
CPUID_FEAT_ECX_POPCNT = 1 << 23, | |||||
CPUID_FEAT_ECX_XSAVE = 1 << 26, | |||||
CPUID_FEAT_ECX_OSXSAVE = 1 << 27, | |||||
CPUID_FEAT_ECX_AVX = 1 << 28, | |||||
CPUID_FEAT_EDX_FPU = 1 << 0, | |||||
CPUID_FEAT_EDX_VME = 1 << 1, | |||||
CPUID_FEAT_EDX_DE = 1 << 2, | |||||
CPUID_FEAT_EDX_PSE = 1 << 3, | |||||
CPUID_FEAT_EDX_TSC = 1 << 4, | |||||
CPUID_FEAT_EDX_MSR = 1 << 5, | |||||
CPUID_FEAT_EDX_PAE = 1 << 6, | |||||
CPUID_FEAT_EDX_MCE = 1 << 7, | |||||
CPUID_FEAT_EDX_CX8 = 1 << 8, | |||||
CPUID_FEAT_EDX_APIC = 1 << 9, | |||||
CPUID_FEAT_EDX_SEP = 1 << 11, | |||||
CPUID_FEAT_EDX_MTRR = 1 << 12, | |||||
CPUID_FEAT_EDX_PGE = 1 << 13, | |||||
CPUID_FEAT_EDX_MCA = 1 << 14, | |||||
CPUID_FEAT_EDX_CMOV = 1 << 15, | |||||
CPUID_FEAT_EDX_PAT = 1 << 16, | |||||
CPUID_FEAT_EDX_PSE36 = 1 << 17, | |||||
CPUID_FEAT_EDX_PSN = 1 << 18, | |||||
CPUID_FEAT_EDX_CLF = 1 << 19, | |||||
CPUID_FEAT_EDX_DTES = 1 << 21, | |||||
CPUID_FEAT_EDX_ACPI = 1 << 22, | |||||
CPUID_FEAT_EDX_MMX = 1 << 23, | |||||
CPUID_FEAT_EDX_FXSR = 1 << 24, | |||||
CPUID_FEAT_EDX_SSE = 1 << 25, | |||||
CPUID_FEAT_EDX_SSE2 = 1 << 26, | |||||
CPUID_FEAT_EDX_SS = 1 << 27, | |||||
CPUID_FEAT_EDX_HTT = 1 << 28, | |||||
CPUID_FEAT_EDX_TM1 = 1 << 29, | |||||
CPUID_FEAT_EDX_IA64 = 1 << 30, | |||||
CPUID_FEAT_EDX_PBE = 1 << 31 | |||||
enum | |||||
{ | |||||
CPUID_FEAT_ECX_SSE3 = 1 << 0, | |||||
CPUID_FEAT_ECX_PCLMUL = 1 << 1, | |||||
CPUID_FEAT_ECX_DTES64 = 1 << 2, | |||||
CPUID_FEAT_ECX_MONITOR = 1 << 3, | |||||
CPUID_FEAT_ECX_DS_CPL = 1 << 4, | |||||
CPUID_FEAT_ECX_VMX = 1 << 5, | |||||
CPUID_FEAT_ECX_SMX = 1 << 6, | |||||
CPUID_FEAT_ECX_EST = 1 << 7, | |||||
CPUID_FEAT_ECX_TM2 = 1 << 8, | |||||
CPUID_FEAT_ECX_SSSE3 = 1 << 9, | |||||
CPUID_FEAT_ECX_CID = 1 << 10, | |||||
CPUID_FEAT_ECX_FMA = 1 << 12, | |||||
CPUID_FEAT_ECX_CX16 = 1 << 13, | |||||
CPUID_FEAT_ECX_ETPRD = 1 << 14, | |||||
CPUID_FEAT_ECX_PDCM = 1 << 15, | |||||
CPUID_FEAT_ECX_DCA = 1 << 18, | |||||
CPUID_FEAT_ECX_SSE4_1 = 1 << 19, | |||||
CPUID_FEAT_ECX_SSE4_2 = 1 << 20, | |||||
CPUID_FEAT_ECX_x2APIC = 1 << 21, | |||||
CPUID_FEAT_ECX_MOVBE = 1 << 22, | |||||
CPUID_FEAT_ECX_POPCNT = 1 << 23, | |||||
CPUID_FEAT_ECX_XSAVE = 1 << 26, | |||||
CPUID_FEAT_ECX_OSXSAVE = 1 << 27, | |||||
CPUID_FEAT_ECX_AVX = 1 << 28, | |||||
CPUID_FEAT_EDX_FPU = 1 << 0, | |||||
CPUID_FEAT_EDX_VME = 1 << 1, | |||||
CPUID_FEAT_EDX_DE = 1 << 2, | |||||
CPUID_FEAT_EDX_PSE = 1 << 3, | |||||
CPUID_FEAT_EDX_TSC = 1 << 4, | |||||
CPUID_FEAT_EDX_MSR = 1 << 5, | |||||
CPUID_FEAT_EDX_PAE = 1 << 6, | |||||
CPUID_FEAT_EDX_MCE = 1 << 7, | |||||
CPUID_FEAT_EDX_CX8 = 1 << 8, | |||||
CPUID_FEAT_EDX_APIC = 1 << 9, | |||||
CPUID_FEAT_EDX_SEP = 1 << 11, | |||||
CPUID_FEAT_EDX_MTRR = 1 << 12, | |||||
CPUID_FEAT_EDX_PGE = 1 << 13, | |||||
CPUID_FEAT_EDX_MCA = 1 << 14, | |||||
CPUID_FEAT_EDX_CMOV = 1 << 15, | |||||
CPUID_FEAT_EDX_PAT = 1 << 16, | |||||
CPUID_FEAT_EDX_PSE36 = 1 << 17, | |||||
CPUID_FEAT_EDX_PSN = 1 << 18, | |||||
CPUID_FEAT_EDX_CLF = 1 << 19, | |||||
CPUID_FEAT_EDX_DTES = 1 << 21, | |||||
CPUID_FEAT_EDX_ACPI = 1 << 22, | |||||
CPUID_FEAT_EDX_MMX = 1 << 23, | |||||
CPUID_FEAT_EDX_FXSR = 1 << 24, | |||||
CPUID_FEAT_EDX_SSE = 1 << 25, | |||||
CPUID_FEAT_EDX_SSE2 = 1 << 26, | |||||
CPUID_FEAT_EDX_SS = 1 << 27, | |||||
CPUID_FEAT_EDX_HTT = 1 << 28, | |||||
CPUID_FEAT_EDX_TM1 = 1 << 29, | |||||
CPUID_FEAT_EDX_IA64 = 1 << 30, | |||||
CPUID_FEAT_EDX_PBE = 1 << 31 | |||||
}; | }; | ||||
struct processor_info { | |||||
int id; | |||||
struct processor_info | |||||
{ | |||||
int id; | |||||
char vendor[13]; | char vendor[13]; | ||||
unsigned int features; | unsigned int features; | ||||
}; | }; | ||||
int processor_get_info(struct processor_info *processor_info); | int processor_get_info(struct processor_info *processor_info); | ||||
void processor_print_info(struct processor_info *processor_info); | |||||
void processor_print_info(struct processor_info *processor_info); |
@@ -1,3 +1,18 @@ | |||||
/* | |||||
* libcaca | |||||
* libcaca Colour ASCII-Art library | |||||
* Copyright (c) 2006 Sam Hocevar <sam@hocevar.net> | |||||
* 2009 Jean-Yves Lamoureux <jylam@lnxscene.org> | |||||
* All Rights Reserved | |||||
* | |||||
* $Id: kernel.h 4154 2009-12-20 13:33:11Z jylam $ | |||||
* | |||||
* This library is free software. It comes without any warranty, to | |||||
* the extent permitted by applicable law. You can redistribute it | |||||
* and/or modify it under the terms of the Do What The Fuck You Want | |||||
* To Public License, Version 2, as published by Sam Hocevar. See | |||||
* http://sam.zoy.org/wtfpl/COPYING for more details. | |||||
*/ | |||||
#include "kernel.h" | #include "kernel.h" | ||||
#include "klibc.h" | #include "klibc.h" | ||||
@@ -7,36 +22,27 @@ u32 ticks = 0; | |||||
void timer_phase(int hz) | void timer_phase(int hz) | ||||
{ | { | ||||
unsigned int divisor = 1193180 / hz; /* Calculate our divisor */ | |||||
/* | |||||
0x43 is the Mode/Command register | |||||
From http://wiki.osdev.org/Programmable_Interval_Timer#Read_Back_Status_Byte : | |||||
Bits Usage | |||||
6 and 7 Select channel : | |||||
0 0 = Channel 0 | |||||
0 1 = Channel 1 | |||||
1 0 = Channel 2 | |||||
1 1 = Read-back command (8254 only) | |||||
4 and 5 Access mode : | |||||
0 0 = Latch count value command | |||||
0 1 = Access mode: lobyte only | |||||
1 0 = Access mode: hibyte only | |||||
1 1 = Access mode: lobyte/hibyte | |||||
1 to 3 Operating mode : | |||||
0 0 0 = Mode 0 (interrupt on terminal count) | |||||
0 0 1 = Mode 1 (hardware re-triggerable one-shot) | |||||
0 1 0 = Mode 2 (rate generator) | |||||
0 1 1 = Mode 3 (square wave generator) | |||||
1 0 0 = Mode 4 (software triggered strobe) | |||||
1 0 1 = Mode 5 (hardware triggered strobe) | |||||
1 1 0 = Mode 2 (rate generator, same as 010b) | |||||
1 1 1 = Mode 3 (square wave generator, same as 011b) | |||||
0 BCD/Binary mode: 0 = 16-bit binary, 1 = four-digit BCD | |||||
unsigned int divisor = 1193180 / hz; /* Calculate our divisor */ | |||||
/* | |||||
0x43 is the Mode/Command register | |||||
From | |||||
http://wiki.osdev.org/Programmable_Interval_Timer#Read_Back_Status_Byte | |||||
: Bits Usage 6 and 7 Select channel : 0 0 = Channel 0 0 1 = Channel 1 | |||||
1 0 = Channel 2 1 1 = Read-back command (8254 only) 4 and 5 Access mode | |||||
: 0 0 = Latch count value command 0 1 = Access mode: lobyte only 1 0 = | |||||
Access mode: hibyte only 1 1 = Access mode: lobyte/hibyte 1 to 3 | |||||
Operating mode : 0 0 0 = Mode 0 (interrupt on terminal count) 0 0 1 = | |||||
Mode 1 (hardware re-triggerable one-shot) 0 1 0 = Mode 2 (rate | |||||
generator) 0 1 1 = Mode 3 (square wave generator) 1 0 0 = Mode 4 | |||||
(software triggered strobe) 1 0 1 = Mode 5 (hardware triggered strobe) | |||||
1 1 0 = Mode 2 (rate generator, same as 010b) 1 1 1 = Mode 3 (square | |||||
wave generator, same as 011b) 0 BCD/Binary mode: 0 = 16-bit binary, 1 = | |||||
four-digit BCD | |||||
*/ | */ | ||||
unsigned short command = 0b00110110; | |||||
unsigned short command = 0 b00110110; | |||||
outb(0x43, command); | outb(0x43, command); | ||||
outb(0x40, divisor & 0xFF); /* Set low byte of divisor */ | |||||
outb(0x40, divisor >> 8); /* Set high byte of divisor */ | |||||
} | |||||
outb(0x40, divisor & 0xFF); /* Set low byte of divisor */ | |||||
outb(0x40, divisor >> 8); /* Set high byte of divisor */ | |||||
} |
@@ -1,2 +1,18 @@ | |||||
/* | |||||
* libcaca | |||||
* libcaca Colour ASCII-Art library | |||||
* Copyright (c) 2006 Sam Hocevar <sam@hocevar.net> | |||||
* 2009 Jean-Yves Lamoureux <jylam@lnxscene.org> | |||||
* All Rights Reserved | |||||
* | |||||
* $Id: kernel.h 4154 2009-12-20 13:33:11Z jylam $ | |||||
* | |||||
* This library is free software. It comes without any warranty, to | |||||
* the extent permitted by applicable law. You can redistribute it | |||||
* and/or modify it under the terms of the Do What The Fuck You Want | |||||
* To Public License, Version 2, as published by Sam Hocevar. See | |||||
* http://sam.zoy.org/wtfpl/COPYING for more details. | |||||
*/ | |||||
extern u32 ticks; | extern u32 ticks; | ||||
void timer_phase(int hz); | |||||
void timer_phase(int hz); |
@@ -1,8 +1,8 @@ | |||||
/* | |||||
* libcaca | |||||
/* | |||||
* libcaca | |||||
* libcaca Colour ASCII-Art library | * libcaca Colour ASCII-Art library | ||||
* Copyright (c) 2006 Sam Hocevar <sam@zoy.org> | |||||
* 2006-2009 Jean-Yves Lamoureux <jylam@lnxscene.org> | |||||
* Copyright (c) 2006 Sam Hocevar <sam@hocevar.net> | |||||
* 2009 Jean-Yves Lamoureux <jylam@lnxscene.org> | |||||
* All Rights Reserved | * All Rights Reserved | ||||
* | * | ||||
* $Id$ | * $Id$ | ||||
@@ -14,11 +14,6 @@ | |||||
* http://sam.zoy.org/wtfpl/COPYING for more details. | * http://sam.zoy.org/wtfpl/COPYING for more details. | ||||
*/ | */ | ||||
/* | |||||
* This file contains replacement functions for the standard C library | |||||
* that must be used when building libcaca and libcaca into a kernel. | |||||
*/ | |||||
#include "config.h" | #include "config.h" | ||||
#include "caca_types.h" | #include "caca_types.h" | ||||
@@ -1,7 +1,8 @@ | |||||
/* | /* | ||||
* libcaca Canvas for ultrafast compositing of Unicode letters | |||||
* libcaca | |||||
* libcaca Colour ASCII-Art library | * libcaca Colour ASCII-Art library | ||||
* Copyright (c) 2006 Sam Hocevar <sam@zoy.org> | |||||
* Copyright (c) 2006 Sam Hocevar <sam@hocevar.net> | |||||
* 2009 Jean-Yves Lamoureux <jylam@lnxscene.org> | |||||
* All Rights Reserved | * All Rights Reserved | ||||
* | * | ||||
* $Id$ | * $Id$ | ||||
@@ -13,11 +14,6 @@ | |||||
* http://sam.zoy.org/wtfpl/COPYING for more details. | * http://sam.zoy.org/wtfpl/COPYING for more details. | ||||
*/ | */ | ||||
/* | |||||
* This file contains replacement functions for the standard C library | |||||
* that must be used when building libcaca and libcaca into a kernel. | |||||
*/ | |||||
@@ -1,3 +1,19 @@ | |||||
/* | |||||
* libcaca | |||||
* libcaca Colour ASCII-Art library | |||||
* Copyright (c) 2006 Sam Hocevar <sam@hocevar.net> | |||||
* 2009 Jean-Yves Lamoureux <jylam@lnxscene.org> | |||||
* All Rights Reserved | |||||
* | |||||
* $Id: kernel.h 4154 2009-12-20 13:33:11Z jylam $ | |||||
* | |||||
* This library is free software. It comes without any warranty, to | |||||
* the extent permitted by applicable law. You can redistribute it | |||||
* and/or modify it under the terms of the Do What The Fuck You Want | |||||
* To Public License, Version 2, as published by Sam Hocevar. See | |||||
* http://sam.zoy.org/wtfpl/COPYING for more details. | |||||
*/ | |||||
#include "config.h" | #include "config.h" | ||||
#include "caca_types.h" | #include "caca_types.h" | ||||
@@ -1,3 +1,25 @@ | |||||
/* | |||||
* libcaca | |||||
* libcaca Colour ASCII-Art library | |||||
* Copyright (c) 2006 Sam Hocevar <sam@hocevar.net> | |||||
* 2009 Jean-Yves Lamoureux <jylam@lnxscene.org> | |||||
* All Rights Reserved | |||||
* | |||||
* $Id: kernel.h 4154 2009-12-20 13:33:11Z jylam $ | |||||
* | |||||
* This library is free software. It comes without any warranty, to | |||||
* the extent permitted by applicable law. You can redistribute it | |||||
* and/or modify it under the terms of the Do What The Fuck You Want | |||||
* To Public License, Version 2, as published by Sam Hocevar. See | |||||
* http://sam.zoy.org/wtfpl/COPYING for more details. | |||||
*/ | |||||
/* | |||||
* This file contains replacement functions for the standard C library | |||||
* that must be used when building libcaca and libcaca into a kernel. | |||||
*/ | |||||
/* Various typedefs -- some are x86-specific */ | /* Various typedefs -- some are x86-specific */ | ||||
#define CUSTOM_INTTYPES | #define CUSTOM_INTTYPES | ||||
@@ -16,10 +38,10 @@ | |||||
#define __BYTE_ORDER 1 | #define __BYTE_ORDER 1 | ||||
#define __BIG_ENDIAN 2 | #define __BIG_ENDIAN 2 | ||||
typedef unsigned char u8; | |||||
typedef unsigned short u16; | |||||
typedef unsigned int u32; | |||||
typedef unsigned long int u64; | |||||
typedef unsigned char u8; | |||||
typedef unsigned short u16; | |||||
typedef unsigned int u32; | |||||
typedef unsigned long int u64; | |||||
#ifndef size_t | #ifndef size_t | ||||
typedef unsigned int size_t; | typedef unsigned int size_t; | ||||
@@ -29,12 +51,14 @@ typedef struct file | |||||
void *mem; | void *mem; | ||||
} FILE; | } FILE; | ||||
struct timeval { | |||||
struct timeval | |||||
{ | |||||
int tv_sec; | int tv_sec; | ||||
int tv_usec; | int tv_usec; | ||||
}; | }; | ||||
struct timezone { | |||||
struct timezone | |||||
{ | |||||
int tz_minuteswest; | int tz_minuteswest; | ||||
int tz_dsttime; | int tz_dsttime; | ||||
}; | }; | ||||
@@ -48,7 +72,7 @@ int rand(void); | |||||
int abs(int j); | int abs(int j); | ||||
void exit(int status); | void exit(int status); | ||||
void srand(unsigned int s); | void srand(unsigned int s); | ||||
int atexit(void (*function)(void)); | |||||
int atexit(void (*function) (void)); | |||||
FILE *stdin, *stdout, *stderr; | FILE *stdin, *stdout, *stderr; | ||||
/* string.h functions */ | /* string.h functions */ | ||||
@@ -63,11 +87,11 @@ char *strdup(const char *s); | |||||
char *strchr(const char *s, int c); | char *strchr(const char *s, int c); | ||||
/* stdarg.h functions */ | /* stdarg.h functions */ | ||||
typedef void * va_list; | |||||
typedef void *va_list; | |||||
#define va_start(v,a) v = (void *)((uintptr_t)(&a) + sizeof(a)) | #define va_start(v,a) v = (void *)((uintptr_t)(&a) + sizeof(a)) | ||||
#define va_end(v) | #define va_end(v) | ||||
int vsnprintf(char *str, size_t size, const char *format, va_list ap); | int vsnprintf(char *str, size_t size, const char *format, va_list ap); | ||||
/* va_arg*/ | |||||
/* va_arg */ | |||||
#define args_list char * | #define args_list char * | ||||
#define _arg_stack_size(type) (((sizeof(type)-1)/sizeof(int)+1)*sizeof(int)) | #define _arg_stack_size(type) (((sizeof(type)-1)/sizeof(int)+1)*sizeof(int)) | ||||
#define args_start(ap, fmt) do { \ | #define args_start(ap, fmt) do { \ | ||||
@@ -78,15 +102,15 @@ ap = (char *)((unsigned int)&fmt + _arg_stack_size(&fmt)); \ | |||||
/* stdio.h functions */ | /* stdio.h functions */ | ||||
FILE *fopen(const char *path, const char *mode); | FILE *fopen(const char *path, const char *mode); | ||||
int feof(FILE *stream); | |||||
char *fgets(char *s, int size, FILE *stream); | |||||
size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream); | |||||
int fclose(FILE *fp); | |||||
int feof(FILE * stream); | |||||
char *fgets(char *s, int size, FILE * stream); | |||||
size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE * stream); | |||||
int fclose(FILE * fp); | |||||
int printf(const char *format, ...); | int printf(const char *format, ...); | ||||
int fprintf(FILE *stream, const char *format, ...); | |||||
int fflush(FILE *stream); | |||||
int fprintf(FILE * stream, const char *format, ...); | |||||
int fflush(FILE * stream); | |||||
int sprintf(char *str, const char *format, ...); | int sprintf(char *str, const char *format, ...); | ||||
int sscanf(const char *str, const char *format, ...); | int sscanf(const char *str, const char *format, ...); | ||||
void itoa(int n, char s[]); | void itoa(int n, char s[]); | ||||
@@ -109,13 +133,13 @@ double sin(double x); | |||||
double sqrt(double x); | double sqrt(double x); | ||||
/* errno.h functions */ | /* errno.h functions */ | ||||
#define ENOENT 2 /* No such file or directory */ | |||||
#define ENOMEM 12 /* Out of memory */ | |||||
#define EBUSY 16 /* Device or resource busy */ | |||||
#define ENODEV 19 /* No such device */ | |||||
#define EINVAL 22 /* Invalid argument */ | |||||
#define ENOTTY 25 /* Not a typewriter */ | |||||
#define ENOSYS 38 /* Function not implemented */ | |||||
#define ENOENT 2 /* No such file or directory */ | |||||
#define ENOMEM 12 /* Out of memory */ | |||||
#define EBUSY 16 /* Device or resource busy */ | |||||
#define ENODEV 19 /* No such device */ | |||||
#define EINVAL 22 /* Invalid argument */ | |||||
#define ENOTTY 25 /* Not a typewriter */ | |||||
#define ENOSYS 38 /* Function not implemented */ | |||||
extern int errno; | extern int errno; | ||||
/* arpa/inet.h functions */ | /* arpa/inet.h functions */ | ||||