Import backup from 2003-09-01

This commit is contained in:
Josh Holtrop 2003-09-01 22:00:00 -04:00
parent 594502f824
commit dae5569216
11 changed files with 130 additions and 61 deletions

View File

@ -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)); 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; unsigned char ret_val;
@ -35,7 +35,7 @@ void disable_ints()
void remap_pics(int pic1, int pic2) void remap_pics(int pic1, int pic2)
{ {
UCHAR a1, a2; byte a1, a2;
a1 = inportb(PIC1_DATA); a1 = inportb(PIC1_DATA);
a2 = inportb(PIC2_DATA); a2 = inportb(PIC2_DATA);

View File

@ -6,7 +6,7 @@
inline void outportb(unsigned int port, unsigned char value); inline void outportb(unsigned int port, unsigned char value);
inline void outportw(unsigned int port, unsigned int 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 enable_ints();
void disable_ints(); void disable_ints();
inline void restart(); inline void restart();

55
io.asm
View File

@ -1,6 +1,10 @@
;void writeCursorPosition(dword pos); %macro jzfar 1
;dword getCursorPosition(); jnz %%skip
jmp %1
%%skip:
%endmacro
[global _writeCursorPosition] [global _writeCursorPosition]
[global _getCursorPosition] [global _getCursorPosition]
@ -13,7 +17,7 @@
; ;
;void writeCursorPosition(int position) ;void writeCursorPosition(word pos)
; ;
_writeCursorPosition: _writeCursorPosition:
push ebp push ebp
@ -79,7 +83,7 @@ _getCursorPosition:
; ;
;void putc(int chr) ;int putc(int chr)
; ;
_putc: _putc:
push ebp push ebp
@ -177,9 +181,9 @@ printf_loop:
mov al, [ebx] mov al, [ebx]
inc ebx inc ebx
cmp al, 0 cmp al, 0
jz printf_done jzfar printf_done
cmp al, '%' cmp al, '%'
jz printf_percent jzfar printf_percent
cmp ecx, 1 cmp ecx, 1
jz printf_special jz printf_special
@ -196,6 +200,8 @@ printf_special:
jz printf_hex jz printf_hex
cmp al, '%' cmp al, '%'
jz printf_ppercent jz printf_ppercent
cmp al, 's'
jz printf_string
jmp printf_special_done jmp printf_special_done
printf_decimal: printf_decimal:
@ -218,6 +224,13 @@ printf_ppercent:
add esp, 4 add esp, 4
jmp printf_special_done jmp printf_special_done
printf_string:
mov eax, [esi]
push eax
call _puts
add esp, 4
jmp printf_special_done
printf_special_done printf_special_done
add esi, 4 ;point to next extra argument add esi, 4 ;point to next extra argument
jmp printf_loop jmp printf_loop
@ -272,7 +285,7 @@ console_cls_loop:
ret ret
; ;
;void putHex(dword number) ;int putHex(dword number)
; ;
_putHex: _putHex:
push ebp push ebp
@ -318,15 +331,39 @@ putHex_loop_end:
; ;
;void putDec(dword number) ;int putDec(dword number)
; ;
_putDec: _putDec:
ret 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

11
io.h
View File

@ -3,10 +3,15 @@
#ifndef __HIO_H__ #ifndef __HIO_H__
#define __HIO_H__ __HIO_H__ #define __HIO_H__ __HIO_H__
void writeCursorPosition(dword pos); void writeCursorPosition(word pos);
dword getCursorPosition(); word getCursorPosition();
void putc(byte chr); int putc(byte chr);
int printf(char *fmt, ...); int printf(char *fmt, ...);
int puts(char *str);
int putDec(dword number);
int putHex(dword number);
void console_cls();
void console_scroll();
#endif #endif

View File

@ -28,9 +28,7 @@
#define YELLOW_TXT 0x0E #define YELLOW_TXT 0x0E
#define BRWHITE_TXT 0x0F #define BRWHITE_TXT 0x0F
#define UCHAR unsigned char #define FREERAM_START 0x268000
#define USHORT unsigned short
#define UINT unsigned int
typedef unsigned char byte; typedef unsigned char byte;
typedef unsigned short word; typedef unsigned short word;

View File

@ -29,14 +29,6 @@ void k_init()
outportb(0x40, 0x2e); //msb outportb(0x40, 0x2e); //msb
enable_ints(); enable_ints();
video_init((ModeInfoBlock *) 0x90306); 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(); console_cls();
mm_init(); mm_init();
} }

29
mm.c
View File

@ -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() void mm_init()
{ {
@ -7,7 +13,28 @@ void mm_init()
memmap_entry *maps = (memmap_entry *) 0x92000; memmap_entry *maps = (memmap_entry *) 0x92000;
dword a; dword a;
for (a=0;a<(*memmap_entries);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);
} }

8
mm.h
View File

@ -11,6 +11,14 @@ typedef struct {
} __attribute__((packed)) memmap_entry; } __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

View File

@ -215,7 +215,7 @@ getmemmap_loop:
;mov ebx, 0x00000000 ;mov ebx, 0x00000000
mov edx, 0x534D4150 ;'SMAP' mov edx, 0x534D4150 ;'SMAP'
int 0x15 int 0x15
jc getmemmap_done jc getmemmap_carry
cmp eax, 0x534D4150 ;eax should be 'SMAP' on return... cmp eax, 0x534D4150 ;eax should be 'SMAP' on return...
jnz getmemmap_error jnz getmemmap_error
cmp ebx, 0 cmp ebx, 0
@ -245,6 +245,8 @@ getmemmap_error:
hlt hlt
jmp $ jmp $
getmemmap_carry:
dec edx
getmemmap_done: getmemmap_done:
pop edx pop edx
pop di pop di

View File

@ -22,7 +22,7 @@ void video_init(ModeInfoBlock *mib)
vid_ptr32 = (dword *) video_mode.PhysBasePtr; vid_ptr32 = (dword *) video_mode.PhysBasePtr;
} }
UINT tot = ((video_mode.XResolution) * (video_mode.YResolution)); dword tot = ((video_mode.XResolution) * (video_mode.YResolution));
int a; int a;
for (a = 0; a < tot; a++) for (a = 0; a < tot; a++)
{ {

64
video.h
View File

@ -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)) #define checkBoundsy(x) (x<0 ? x=0 : (x>=video_mode.YResolution ? x=video_mode.YResolution-1 : 0))
typedef struct{ typedef struct{
USHORT ModeAttributes; word ModeAttributes;
UCHAR WinAAttributes; byte WinAAttributes;
UCHAR WinBAttributes; byte WinBAttributes;
USHORT WinGranularity; word WinGranularity;
USHORT WinSize; word WinSize;
USHORT WinASegment; word WinASegment;
USHORT WinBSegment; word WinBSegment;
UINT WinFuncPtr; dword WinFuncPtr;
USHORT BytesPerScanLine; word BytesPerScanLine;
USHORT XResolution; word XResolution;
USHORT YResolution; word YResolution;
UCHAR XCharSize; byte XCharSize;
UCHAR YCharSize; byte YCharSize;
UCHAR NumberOfPlanes; byte NumberOfPlanes;
UCHAR BitsPerPixel; byte BitsPerPixel;
UCHAR NumberOfBanks; byte NumberOfBanks;
UCHAR MemoryModel; byte MemoryModel;
UCHAR BankSize; byte BankSize;
UCHAR NumberOfImagePages; byte NumberOfImagePages;
UCHAR Reserved1; byte Reserved1;
UCHAR RedMaskSize; byte RedMaskSize;
UCHAR RedFieldPosition; byte RedFieldPosition;
UCHAR GreenMaskSize; byte GreenMaskSize;
UCHAR GreenFieldPosition; byte GreenFieldPosition;
UCHAR BlueMaskSize; byte BlueMaskSize;
UCHAR BlueFieldPosition; byte BlueFieldPosition;
UCHAR RsvdMaskSize; byte RsvdMaskSize;
UCHAR RsvdFieldPosition; byte RsvdFieldPosition;
UCHAR DirectColorModeInfo; byte DirectColorModeInfo;
dword PhysBasePtr; dword PhysBasePtr;
UINT OffScreenMemOffset; dword OffScreenMemOffset;
USHORT OffScreenMemSize; word OffScreenMemSize;
UCHAR Reserved[206]; byte Reserved[206];
} ModeInfoBlock; } ModeInfoBlock;