diff --git a/Functions.c b/Functions.c index b64a250..9c669a4 100644 --- a/Functions.c +++ b/Functions.c @@ -13,7 +13,7 @@ inline void outportw(unsigned int port, unsigned int value) // Output a word to asm volatile ("outw %%ax,%%dx"::"d" (port), "a" (value)); }; -inline UCHAR inportb(unsigned short port) +inline byte inportb(unsigned short port) { unsigned char ret_val; @@ -35,7 +35,7 @@ void disable_ints() void remap_pics(int pic1, int pic2) { - UCHAR a1, a2; + byte a1, a2; a1 = inportb(PIC1_DATA); a2 = inportb(PIC2_DATA); diff --git a/functions.h b/functions.h index d6644c8..7ad6b1d 100644 --- a/functions.h +++ b/functions.h @@ -6,7 +6,7 @@ inline void outportb(unsigned int port, unsigned char value); inline void outportw(unsigned int port, unsigned int value); -inline UCHAR inportb(unsigned short port); +inline byte inportb(unsigned short port); void enable_ints(); void disable_ints(); inline void restart(); diff --git a/io.asm b/io.asm index 5119c80..d96abde 100644 --- a/io.asm +++ b/io.asm @@ -1,6 +1,10 @@ -;void writeCursorPosition(dword pos); -;dword getCursorPosition(); +%macro jzfar 1 + jnz %%skip + jmp %1 +%%skip: + +%endmacro [global _writeCursorPosition] [global _getCursorPosition] @@ -13,7 +17,7 @@ ; -;void writeCursorPosition(int position) +;void writeCursorPosition(word pos) ; _writeCursorPosition: push ebp @@ -79,7 +83,7 @@ _getCursorPosition: ; -;void putc(int chr) +;int putc(int chr) ; _putc: push ebp @@ -177,9 +181,9 @@ printf_loop: mov al, [ebx] inc ebx cmp al, 0 - jz printf_done + jzfar printf_done cmp al, '%' - jz printf_percent + jzfar printf_percent cmp ecx, 1 jz printf_special @@ -196,6 +200,8 @@ printf_special: jz printf_hex cmp al, '%' jz printf_ppercent + cmp al, 's' + jz printf_string jmp printf_special_done printf_decimal: @@ -218,6 +224,13 @@ printf_ppercent: add esp, 4 jmp printf_special_done +printf_string: + mov eax, [esi] + push eax + call _puts + add esp, 4 + jmp printf_special_done + printf_special_done add esi, 4 ;point to next extra argument jmp printf_loop @@ -272,7 +285,7 @@ console_cls_loop: ret ; -;void putHex(dword number) +;int putHex(dword number) ; _putHex: push ebp @@ -318,15 +331,39 @@ putHex_loop_end: ; -;void putDec(dword number) +;int putDec(dword number) ; _putDec: ret +; +;int puts(char *str) +; +_puts: + push ebp + mov ebp, esp + push esi + push eax + mov esi, [ebp+8] ;esi = ptr to string +puts_loop: + lodsb + cmp al, 0 + jz puts_done + push eax + call _putc + add esp, 4 + jmp puts_loop + +puts_done: + pop eax + pop esi + pop ebp + ret + + - diff --git a/io.h b/io.h index 0b747bd..581bb73 100644 --- a/io.h +++ b/io.h @@ -3,10 +3,15 @@ #ifndef __HIO_H__ #define __HIO_H__ __HIO_H__ -void writeCursorPosition(dword pos); -dword getCursorPosition(); -void putc(byte chr); +void writeCursorPosition(word pos); +word getCursorPosition(); +int putc(byte chr); int printf(char *fmt, ...); +int puts(char *str); +int putDec(dword number); +int putHex(dword number); +void console_cls(); +void console_scroll(); #endif diff --git a/k_defines.h b/k_defines.h index ec6e61f..ee8da76 100644 --- a/k_defines.h +++ b/k_defines.h @@ -28,9 +28,7 @@ #define YELLOW_TXT 0x0E #define BRWHITE_TXT 0x0F -#define UCHAR unsigned char -#define USHORT unsigned short -#define UINT unsigned int +#define FREERAM_START 0x268000 typedef unsigned char byte; typedef unsigned short word; diff --git a/kernel.c b/kernel.c index 51af019..cf59244 100644 --- a/kernel.c +++ b/kernel.c @@ -29,14 +29,6 @@ void k_init() outportb(0x40, 0x2e); //msb enable_ints(); video_init((ModeInfoBlock *) 0x90306); - int a; - for (a=0;a<768;a+=10) - { - video_horiz(a, 2, 1021, 0); - video_vert(a, 2, 765, 0x0000FFFF); - } - video_rect(10, 10, 100, 100, 0x00FFFFFF); - video_rectf(11, 11, 99, 99, 0x00FFFF00); console_cls(); mm_init(); } diff --git a/mm.c b/mm.c index 6d7868e..9aad6e6 100644 --- a/mm.c +++ b/mm.c @@ -1,5 +1,11 @@ +// mm.c +// 09/01/03 Josh Holtrop + +// 0x368000 is first available byte (this is right after the kernel @ 1mb and the initrd @ 2mb, 1440kb. +pageblock *first_pageblock = (pageblock *) 0; +dword totalmem = 0; void mm_init() { @@ -7,7 +13,28 @@ void mm_init() memmap_entry *maps = (memmap_entry *) 0x92000; dword a; for (a=0;a<(*memmap_entries);a++) - printf("Entry %x:\tBase: %x\n\t\tLimit: %x\n\t\tAttributes: %x\n", a, maps[a].base.lowdword, maps[a].limit.lowdword, maps[a].attributes); + { + if (maps[a].attributes == 1) // (1) mem free to OS + { + if ((maps[a].base.lowdword + maps[a].limit.lowdword) > (FREERAM_START+4096)) //goes past where we start freeram + { + if (first_pageblock == 0) //no pageblock page set up yet + { + if (maps[a].base.lowdword < (FREERAM_START+4096)) + { + first_pageblock = (pageblock *) FREERAM_START; + } + } + else + { + } + } + totalmem += maps[a].limit.lowdword; + } + } + printf("Total memory available to OS: %x", totalmem); } + + diff --git a/mm.h b/mm.h index d49c2ce..874ce93 100644 --- a/mm.h +++ b/mm.h @@ -11,6 +11,14 @@ typedef struct { } __attribute__((packed)) memmap_entry; +typedef struct { + dword base; + dword length; //in pages + dword flags; + dword link; +} __attribute__ ((packed)) pageblock; //16 byte pageblock entry - 512 entries = 1 page + + diff --git a/stage2.asm b/stage2.asm index a3184cd..769dcb3 100644 --- a/stage2.asm +++ b/stage2.asm @@ -215,7 +215,7 @@ getmemmap_loop: ;mov ebx, 0x00000000 mov edx, 0x534D4150 ;'SMAP' int 0x15 - jc getmemmap_done + jc getmemmap_carry cmp eax, 0x534D4150 ;eax should be 'SMAP' on return... jnz getmemmap_error cmp ebx, 0 @@ -245,6 +245,8 @@ getmemmap_error: hlt jmp $ +getmemmap_carry: + dec edx getmemmap_done: pop edx pop di diff --git a/video.c b/video.c index fd8d2ce..63f684f 100644 --- a/video.c +++ b/video.c @@ -22,7 +22,7 @@ void video_init(ModeInfoBlock *mib) vid_ptr32 = (dword *) video_mode.PhysBasePtr; } - UINT tot = ((video_mode.XResolution) * (video_mode.YResolution)); + dword tot = ((video_mode.XResolution) * (video_mode.YResolution)); int a; for (a = 0; a < tot; a++) { diff --git a/video.h b/video.h index f6ad54b..46e4f64 100644 --- a/video.h +++ b/video.h @@ -14,42 +14,42 @@ void video_psetp(int pixel, dword color); #define checkBoundsy(x) (x<0 ? x=0 : (x>=video_mode.YResolution ? x=video_mode.YResolution-1 : 0)) typedef struct{ - USHORT ModeAttributes; - UCHAR WinAAttributes; - UCHAR WinBAttributes; - USHORT WinGranularity; - USHORT WinSize; - USHORT WinASegment; - USHORT WinBSegment; - UINT WinFuncPtr; - USHORT BytesPerScanLine; + word ModeAttributes; + byte WinAAttributes; + byte WinBAttributes; + word WinGranularity; + word WinSize; + word WinASegment; + word WinBSegment; + dword WinFuncPtr; + word BytesPerScanLine; - USHORT XResolution; - USHORT YResolution; - UCHAR XCharSize; - UCHAR YCharSize; - UCHAR NumberOfPlanes; - UCHAR BitsPerPixel; - UCHAR NumberOfBanks; - UCHAR MemoryModel; - UCHAR BankSize; - UCHAR NumberOfImagePages; - UCHAR Reserved1; + word XResolution; + word YResolution; + byte XCharSize; + byte YCharSize; + byte NumberOfPlanes; + byte BitsPerPixel; + byte NumberOfBanks; + byte MemoryModel; + byte BankSize; + byte NumberOfImagePages; + byte Reserved1; - UCHAR RedMaskSize; - UCHAR RedFieldPosition; - UCHAR GreenMaskSize; - UCHAR GreenFieldPosition; - UCHAR BlueMaskSize; - UCHAR BlueFieldPosition; - UCHAR RsvdMaskSize; - UCHAR RsvdFieldPosition; - UCHAR DirectColorModeInfo; + byte RedMaskSize; + byte RedFieldPosition; + byte GreenMaskSize; + byte GreenFieldPosition; + byte BlueMaskSize; + byte BlueFieldPosition; + byte RsvdMaskSize; + byte RsvdFieldPosition; + byte DirectColorModeInfo; dword PhysBasePtr; - UINT OffScreenMemOffset; - USHORT OffScreenMemSize; - UCHAR Reserved[206]; + dword OffScreenMemOffset; + word OffScreenMemSize; + byte Reserved[206]; } ModeInfoBlock;