diff --git a/.cproject b/.cproject index c611a22..815670f 100644 --- a/.cproject +++ b/.cproject @@ -67,7 +67,7 @@ - + diff --git a/.gitignore b/.gitignore index 52e078a..9dd6869 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ t t.c *.o +*.so .depen* /sys/sde/objgfx40.cpp /sys/sde/ogFont.cpp diff --git a/.project b/.project index 7bd8870..e87f5c8 100644 --- a/.project +++ b/.project @@ -3,6 +3,8 @@ UbixOS + UbixOS Kernel + UbixOS Libc diff --git a/DEBUG.md b/DEBUG.md new file mode 100644 index 0000000..a6d239a --- /dev/null +++ b/DEBUG.md @@ -0,0 +1,3 @@ +#DEBUG_EXEC - Exec Debug +#DEBUG_VFS - VFS DEBUG +#DEBUG_SYSCTL - SYSCTL DEBUG diff --git a/DEBUG_INFO b/DEBUG_INFO deleted file mode 100644 index a6d239a..0000000 --- a/DEBUG_INFO +++ /dev/null @@ -1,3 +0,0 @@ -#DEBUG_EXEC - Exec Debug -#DEBUG_VFS - VFS DEBUG -#DEBUG_SYSCTL - SYSCTL DEBUG diff --git a/Dump/hybos/README.txt b/Dump/hybos/README.txt index 6f0e2f2..4e5a00e 100644 --- a/Dump/hybos/README.txt +++ b/Dump/hybos/README.txt @@ -1,210 +1,210 @@ -OSD demo code - Interim release (January, 2003) - -I am working a new set of kernels, but it's slow going, so here -are the old kernels with some bug fixes and improvements. - -Location of these files: http://www.execpc.com/~geezer/osd/code - -The GRUB bootloader is GPL, all other files are PUBLIC DOMAIN -(no copyright). You may do whatever you want with them. - -================================================================ -QUICK START -================================================================ -1. Make sure you have all the software tools you need. You need NASM: - http://nasm.sourceforge.net - - You need the GNU C compiler (GCC), including binutils, GNU Make, - and sed. Users of DOS and Win9x should get GCC for DOS (DJGPP): - http://www.delorie.com/djgpp - - Find a mirror site near you and download the following - packages (NNN is version number): - compiler v2gnu/gccNNNNb.zip - binutils v2gnu/bnuNNNNb.zip - libraries v2/djdevNNN.zip - Make v2gnu/makNNNNb.zip - sed v2gnu/sedNNb.zip - CWSDPMI v2misc/csdpmiN.zip - - Users of WinNT/Win2000/WinXP should get GCC for Win32 (MinGW): - http://mingw.sourceforge.net - - Users of Linux can use the GNU tools that come with Linux. If - they're not already installed, check the CD-ROMs or FTP site - from where you got Linux. - - DOS and Windows users also need John Fine's Partial Copy (PARTCOPY): - http://www.execpc.com/~geezer/johnfine/#zero - -2. Create a formatted floppy disk with the GRUB bootloader - installed on it. The procedure to do this is described below. - -3. Got your tools? Got your GRUB floppy? Then you're ready to - build and install the demo kernels. - - If you're using DJGPP, type make -f dj.mak install - - If you're using MinGW, type make -f ming.mak install - - If you're using Linux, type make -f linux.mak install - -Hopefully, everything will work properly. If it does, you'll be -left with a bootable GRUB floppy with 7 demo kernels on it -(OSD 3 - OSD 9). - -================================================================ -MAKING A BOOTABLE FLOPPY DISK WITH THE GRUB BOOTLOADER ON IT -================================================================ -GRUB is a GPLed bootloader. - -Home page: http://www.gnu.org/software/grub -Binaries: ftp://alpha.gnu.org/gnu/grub/grub-0.90-i386-pc.tar.gz -Source code: ftp://alpha.gnu.org/gnu/grub/grub-0.90.tar.gz -HOW-TOs: http://www.washingdishes.freeuk.com/grubtut.html - http://www.execpc.com/~geezer/osd/boot/grub-how.txt - -1. You will need - - Two 1.44 meg floppy disks, one of them formatted with a - filesystem that GRUB recognizes (e.g. FAT12 or ext2). - The other floppy (the "unformatted" floppy) may contain - a filesystem, but it will be destroyed. - - The GRUB binaries: files "stage1" and "stage2". These are - in the OSD distribution, in the directory "boot/grub". - - A "menu.lst" configuration file for GRUB. Again, this - is provided with OSD in the "boot/grub" directory. - -2. On the formatted floppy disk, create the subdirectory - "/boot/grub/", and copy the files "stage1", "stage2", and - "menu.lst" into this subdirectory. - -3. Concatenate the binary files "stage1" and "stage2" into a - single binary file named "boot": - (DOS/Windows): copy /b stage1 + stage2 boot - (Linux): cat stage1 stage2 >boot - -4. Write the file "boot" directly to the unformatted floppy. - This is a sector-level write that does not use (and will - destroy) any filesystem present on the disk: - (DOS/Windows): partcopy boot 0 168000 -f0 - (Linux): cat boot >/dev/fd0 - - PARTCOPY will display an error message because "boot" is - much shorter than 0x168000 bytes, but this is OK. - -5. Boot your PC from the unformatted floppy disk. - -6. After GRUB has started, eject the unformatted floppy and - insert the formatted floppy, containing the "stage1", - "stage2", and "menu.lst" files, all in the "/boot/grub/" - subdirectory. Type: - setup (fd0) - -7. The formatted floppy is now bootable. Do not move, modify, - or delete the file "/boot/grub/stage2" on this floppy. - -================================================================ -BUGS/GOTCHAS/"IT DOESN'T WORK!" -================================================================ -- DJGPP crashes under Windows XP - The DJGPP team is working on a way to fix this. If you have - any flavor of WindowsNT (including WindowsXP) use MinGW - instead of DJGPP. - -- Will CygWin work instead of MinGW? - Probably, but I haven't tested it. - -- 'make -f ming.mak clean' doesn't delete .o files in /lib/ - I know, but I can't figure out how to fix it. Make sure - these files get deleted if you switch between MinGW and - DJGPP. The linkers can't distinguish between DJGPP COFF - .o files and Win32 PE COFF .o files, but they ARE different, - and your kernels will crash if you mix the two COFF types. - -- BFD: Dwarf Error: Abbrev offset (1075154) greater than or - equal to .debug_abbrev size (3198). - This is a bug in new versions of DJGPP. It's ugly, but you - can ignore it. - -- Do not use MinGW GCC 2.x with NASM - MinGW based on GCC 2.95.2 stores the BSS size in the wrong - field of the section header. Because of this bug, this - version of MinGW will not interoperate with other toolchains, - including NASM, Microsoft compilers, and Borland compilers. - -- Screen fills with errors when compiling under Linux - There are two possible causes for this: - 1. Linux GCC chokes on DOS-style newlines in the source code. - Run all source code files and makefiles through 'fromdos' - to convert the DOS newlines (CR-LF) to UNIX newlines (LF). - 2. There is no newline at the very end of the file. - -- ld: krnl.x: Not enough room for program headers, try linking with -N - This error occurs if you do not use AT() in the linker script - when making an ELF kernel. - -- Exception 10 (bad TSS) - If the NT bit in the EFLAGS register is set, IRET will attempt - a TSS-based task-switch, instead of a normal IRET. Code was - added to osd9/kstart.asm to prevent this. (GRUB 0.90 leaves - the NT bit set when it jumps to the kernel.) - -- Errors from GRUB: - 'Error: Loading below 1M not supported' - 'Error 28: Selected item won't fit into memory' - These errors are usually caused by improperly-linked ELF - kernels. If your kernel is ELF, try this: - objdump --private-headers -h krnl.x - The vaddr and paddr fields for each program header (segment) - must be at or above 1 meg (00100000h) but smaller than your - RAM size. If you have readelf, you can also do this: - readelf --segments krnl.x - If you find a segment with bad values of VirtAddr or - PhysAddr, look at the section-to-segment mapping to see - which section is causing the problem. - -================================================================ -DEMO CODE OVERVIEW -================================================================ -osd3 mixing C and asm, C calling convention, underscores - (xxx - current code does not demonstrate these very well) - -osd4 putch() and kprintf() - -osd5 C library code moved to separate directory - -osd6 software interrupts, exception handlers in asm and C - -osd7 hardware interrupts, reprogramming the 8259 interrupt - controller chips, simple keyboard driver - -osd8 multitasking preliminaries: multiple (virtual) consoles - backed with video memory, ANSI/VT escapes for moving - the cursor and changing text color. Improved keyboard - driver; can press Ctrl+Alt+Del to reboot. - -osd9 cooperative multitasking with setjmp() and longjump() - (static tasks; linked into the kernel at compile-time) - -================================================================ -WHAT CHANGED? -================================================================ -- Updated GRUB to version 0.90 -- Wrote MinGW makefiles, and fixed code to work with MinGW - based on GCC 3.x (and generate error message for GCC 2.x) -- Fixed definition of MAKEFILE in lib/linux.mak -- BIG changes to linker script - - Unified ELF/DJGPP COFF/Win32 PE COFF linker scripts into one - - Added AT() statements so ELF kernels link properly, and - work properly - - Now handling .rodata section properly, so ELF kernels work - properly (including multiple .rodata sections with GCC 3.x) -- Rewrote setjmp() and longjmp() because they were buggy (though, - strangely enough, the bug did not manifest itself) -- Added code to osd9/kstart.asm to zero NT bit in EFLAGS, - preventing exception 10 -- Now enabling interrupts for each task in function init_tasks() - of osd9/sched.c. In previous code, interrupts were disabled - for all tasks except the idle task, making the blinking - character in the upper left corner of the screen appear to - blink much more slowly than 18 Hz. +OSD demo code - Interim release (January, 2003) + +I am working a new set of kernels, but it's slow going, so here +are the old kernels with some bug fixes and improvements. + +Location of these files: http://www.execpc.com/~geezer/osd/code + +The GRUB bootloader is GPL, all other files are PUBLIC DOMAIN +(no copyright). You may do whatever you want with them. + +================================================================ +QUICK START +================================================================ +1. Make sure you have all the software tools you need. You need NASM: + http://nasm.sourceforge.net + + You need the GNU C compiler (GCC), including binutils, GNU Make, + and sed. Users of DOS and Win9x should get GCC for DOS (DJGPP): + http://www.delorie.com/djgpp + + Find a mirror site near you and download the following + packages (NNN is version number): + compiler v2gnu/gccNNNNb.zip + binutils v2gnu/bnuNNNNb.zip + libraries v2/djdevNNN.zip + Make v2gnu/makNNNNb.zip + sed v2gnu/sedNNb.zip + CWSDPMI v2misc/csdpmiN.zip + + Users of WinNT/Win2000/WinXP should get GCC for Win32 (MinGW): + http://mingw.sourceforge.net + + Users of Linux can use the GNU tools that come with Linux. If + they're not already installed, check the CD-ROMs or FTP site + from where you got Linux. + + DOS and Windows users also need John Fine's Partial Copy (PARTCOPY): + http://www.execpc.com/~geezer/johnfine/#zero + +2. Create a formatted floppy disk with the GRUB bootloader + installed on it. The procedure to do this is described below. + +3. Got your tools? Got your GRUB floppy? Then you're ready to + build and install the demo kernels. + + If you're using DJGPP, type make -f dj.mak install + + If you're using MinGW, type make -f ming.mak install + + If you're using Linux, type make -f linux.mak install + +Hopefully, everything will work properly. If it does, you'll be +left with a bootable GRUB floppy with 7 demo kernels on it +(OSD 3 - OSD 9). + +================================================================ +MAKING A BOOTABLE FLOPPY DISK WITH THE GRUB BOOTLOADER ON IT +================================================================ +GRUB is a GPLed bootloader. + +Home page: http://www.gnu.org/software/grub +Binaries: ftp://alpha.gnu.org/gnu/grub/grub-0.90-i386-pc.tar.gz +Source code: ftp://alpha.gnu.org/gnu/grub/grub-0.90.tar.gz +HOW-TOs: http://www.washingdishes.freeuk.com/grubtut.html + http://www.execpc.com/~geezer/osd/boot/grub-how.txt + +1. You will need + - Two 1.44 meg floppy disks, one of them formatted with a + filesystem that GRUB recognizes (e.g. FAT12 or ext2). + The other floppy (the "unformatted" floppy) may contain + a filesystem, but it will be destroyed. + - The GRUB binaries: files "stage1" and "stage2". These are + in the OSD distribution, in the directory "boot/grub". + - A "menu.lst" configuration file for GRUB. Again, this + is provided with OSD in the "boot/grub" directory. + +2. On the formatted floppy disk, create the subdirectory + "/boot/grub/", and copy the files "stage1", "stage2", and + "menu.lst" into this subdirectory. + +3. Concatenate the binary files "stage1" and "stage2" into a + single binary file named "boot": + (DOS/Windows): copy /b stage1 + stage2 boot + (Linux): cat stage1 stage2 >boot + +4. Write the file "boot" directly to the unformatted floppy. + This is a sector-level write that does not use (and will + destroy) any filesystem present on the disk: + (DOS/Windows): partcopy boot 0 168000 -f0 + (Linux): cat boot >/dev/fd0 + + PARTCOPY will display an error message because "boot" is + much shorter than 0x168000 bytes, but this is OK. + +5. Boot your PC from the unformatted floppy disk. + +6. After GRUB has started, eject the unformatted floppy and + insert the formatted floppy, containing the "stage1", + "stage2", and "menu.lst" files, all in the "/boot/grub/" + subdirectory. Type: + setup (fd0) + +7. The formatted floppy is now bootable. Do not move, modify, + or delete the file "/boot/grub/stage2" on this floppy. + +================================================================ +BUGS/GOTCHAS/"IT DOESN'T WORK!" +================================================================ +- DJGPP crashes under Windows XP + The DJGPP team is working on a way to fix this. If you have + any flavor of WindowsNT (including WindowsXP) use MinGW + instead of DJGPP. + +- Will CygWin work instead of MinGW? + Probably, but I haven't tested it. + +- 'make -f ming.mak clean' doesn't delete .o files in /lib/ + I know, but I can't figure out how to fix it. Make sure + these files get deleted if you switch between MinGW and + DJGPP. The linkers can't distinguish between DJGPP COFF + .o files and Win32 PE COFF .o files, but they ARE different, + and your kernels will crash if you mix the two COFF types. + +- BFD: Dwarf Error: Abbrev offset (1075154) greater than or + equal to .debug_abbrev size (3198). + This is a bug in new versions of DJGPP. It's ugly, but you + can ignore it. + +- Do not use MinGW GCC 2.x with NASM + MinGW based on GCC 2.95.2 stores the BSS size in the wrong + field of the section header. Because of this bug, this + version of MinGW will not interoperate with other toolchains, + including NASM, Microsoft compilers, and Borland compilers. + +- Screen fills with errors when compiling under Linux + There are two possible causes for this: + 1. Linux GCC chokes on DOS-style newlines in the source code. + Run all source code files and makefiles through 'fromdos' + to convert the DOS newlines (CR-LF) to UNIX newlines (LF). + 2. There is no newline at the very end of the file. + +- ld: krnl.x: Not enough room for program headers, try linking with -N + This error occurs if you do not use AT() in the linker script + when making an ELF kernel. + +- Exception 10 (bad TSS) + If the NT bit in the EFLAGS register is set, IRET will attempt + a TSS-based task-switch, instead of a normal IRET. Code was + added to osd9/kstart.asm to prevent this. (GRUB 0.90 leaves + the NT bit set when it jumps to the kernel.) + +- Errors from GRUB: + 'Error: Loading below 1M not supported' + 'Error 28: Selected item won't fit into memory' + These errors are usually caused by improperly-linked ELF + kernels. If your kernel is ELF, try this: + objdump --private-headers -h krnl.x + The vaddr and paddr fields for each program header (segment) + must be at or above 1 meg (00100000h) but smaller than your + RAM size. If you have readelf, you can also do this: + readelf --segments krnl.x + If you find a segment with bad values of VirtAddr or + PhysAddr, look at the section-to-segment mapping to see + which section is causing the problem. + +================================================================ +DEMO CODE OVERVIEW +================================================================ +osd3 mixing C and asm, C calling convention, underscores + (xxx - current code does not demonstrate these very well) + +osd4 putch() and kprintf() + +osd5 C library code moved to separate directory + +osd6 software interrupts, exception handlers in asm and C + +osd7 hardware interrupts, reprogramming the 8259 interrupt + controller chips, simple keyboard driver + +osd8 multitasking preliminaries: multiple (virtual) consoles + backed with video memory, ANSI/VT escapes for moving + the cursor and changing text color. Improved keyboard + driver; can press Ctrl+Alt+Del to reboot. + +osd9 cooperative multitasking with setjmp() and longjump() + (static tasks; linked into the kernel at compile-time) + +================================================================ +WHAT CHANGED? +================================================================ +- Updated GRUB to version 0.90 +- Wrote MinGW makefiles, and fixed code to work with MinGW + based on GCC 3.x (and generate error message for GCC 2.x) +- Fixed definition of MAKEFILE in lib/linux.mak +- BIG changes to linker script + - Unified ELF/DJGPP COFF/Win32 PE COFF linker scripts into one + - Added AT() statements so ELF kernels link properly, and + work properly + - Now handling .rodata section properly, so ELF kernels work + properly (including multiple .rodata sections with GCC 3.x) +- Rewrote setjmp() and longjmp() because they were buggy (though, + strangely enough, the bug did not manifest itself) +- Added code to osd9/kstart.asm to zero NT bit in EFLAGS, + preventing exception 10 +- Now enabling interrupts for each task in function init_tasks() + of osd9/sched.c. In previous code, interrupts were disabled + for all tasks except the idle task, making the blinking + character in the upper left corner of the screen appear to + blink much more slowly than 18 Hz. diff --git a/Dump/hybos/__experimental/README.txt b/Dump/hybos/__experimental/README.txt index fba9e05..d2b1a8d 100644 --- a/Dump/hybos/__experimental/README.txt +++ b/Dump/hybos/__experimental/README.txt @@ -1,87 +1,87 @@ -Sector-level disk I/O code for various OSes - -This code is public domain (no copyright). -You can do whatever you want with it. - -Chris Giese http://www.execpc.com/~geezer - -================================================================ -BUILD -================================================================ -After a successful build, the executable is named 'diskio.exe' - -DOS - Turbo C++ 1.0 or Turbo C++ 3.0: - make - -DOS - Watcom C: - wmake /f watcom16.mak - -32-bit DOS - DJGPP: - make -f djgpp.mak - -32-bit DOS - Watcom C with CauseWay DOS extender: - wmake /f watcom32.mak - -NOTE: 32-bit code built with Watcom C does not yet work. - -Windows NT - MinGW or CygWin: - make -f win-nt.mak - -NOTE: Windows NT version is not tested. - -Linux - GCC: - xxx - to do - -If you have Windows9x, build and run this code as a DOS program, -not a Win32 program. - -================================================================ -API -================================================================ -/* disk_t, open_disk(), read_sector(), write_sector() */ -#include "diskio.h" - -int main(void) { - unsigned long lba_sector_num; - unsigned char buf[512]; - unsigned drive; - disk_t disk; - -/* drive values for floppies: - 0 for A:, 1 for B:, etc. -drive values for hard drives: - 0x80 for first hard drive, 0x81 for second hard drive, etc. */ - drive = 0; -/* read hard drive partition table or floppy boot sector */ - lba_sector_num = 0; - if(open_disk(&disk, drive) == 0) - if(read_sector(&disk, lba_sector_num, buf) == 0) - /* success */; - return 0; } - -================================================================ -TO DO -================================================================ -Test if code writes to disk properly - -Test Windows NT version -- See if the following work with Windows NT: - - 1.44 meg FAT12 floppy (my guess: YES) - - 1.68 meg FAT12 floppy (my guess: YES) - - 1.44 meg non-FAT (e.g. ext2) floppy (my guess: YES) - - 1.68 meg non-FAT floppy (my guess: NO) -- Is there a Windows NT ioctl() to get floppy disk geometry? - Does it work for non-FAT floppy disks? (How do I make NT read - a 1.68 meg non-FAT floppy?) - -Make it work with Linux - -Make it work with 32-bit Watcom C - -Maybe add a disk cache - -Maybe support disks with sector size other than 512 bytes -(e.g. 2048-byte CD-ROM sectors)? - -Any way to access CD-ROM with INT 13h functions? -WITHOUT booting from the CD-ROM? +Sector-level disk I/O code for various OSes + +This code is public domain (no copyright). +You can do whatever you want with it. + +Chris Giese http://www.execpc.com/~geezer + +================================================================ +BUILD +================================================================ +After a successful build, the executable is named 'diskio.exe' + +DOS - Turbo C++ 1.0 or Turbo C++ 3.0: + make + +DOS - Watcom C: + wmake /f watcom16.mak + +32-bit DOS - DJGPP: + make -f djgpp.mak + +32-bit DOS - Watcom C with CauseWay DOS extender: + wmake /f watcom32.mak + +NOTE: 32-bit code built with Watcom C does not yet work. + +Windows NT - MinGW or CygWin: + make -f win-nt.mak + +NOTE: Windows NT version is not tested. + +Linux - GCC: + xxx - to do + +If you have Windows9x, build and run this code as a DOS program, +not a Win32 program. + +================================================================ +API +================================================================ +/* disk_t, open_disk(), read_sector(), write_sector() */ +#include "diskio.h" + +int main(void) { + unsigned long lba_sector_num; + unsigned char buf[512]; + unsigned drive; + disk_t disk; + +/* drive values for floppies: + 0 for A:, 1 for B:, etc. +drive values for hard drives: + 0x80 for first hard drive, 0x81 for second hard drive, etc. */ + drive = 0; +/* read hard drive partition table or floppy boot sector */ + lba_sector_num = 0; + if(open_disk(&disk, drive) == 0) + if(read_sector(&disk, lba_sector_num, buf) == 0) + /* success */; + return 0; } + +================================================================ +TO DO +================================================================ +Test if code writes to disk properly + +Test Windows NT version +- See if the following work with Windows NT: + - 1.44 meg FAT12 floppy (my guess: YES) + - 1.68 meg FAT12 floppy (my guess: YES) + - 1.44 meg non-FAT (e.g. ext2) floppy (my guess: YES) + - 1.68 meg non-FAT floppy (my guess: NO) +- Is there a Windows NT ioctl() to get floppy disk geometry? + Does it work for non-FAT floppy disks? (How do I make NT read + a 1.68 meg non-FAT floppy?) + +Make it work with Linux + +Make it work with 32-bit Watcom C + +Maybe add a disk cache + +Maybe support disks with sector size other than 512 bytes +(e.g. 2048-byte CD-ROM sectors)? + +Any way to access CD-ROM with INT 13h functions? +WITHOUT booting from the CD-ROM? diff --git a/Dump/hybos/__experimental/demo.c b/Dump/hybos/__experimental/demo.c index 4a20581..7704645 100644 --- a/Dump/hybos/__experimental/demo.c +++ b/Dump/hybos/__experimental/demo.c @@ -1,94 +1,94 @@ -/***************************************************************************** -Sector-level disk I/O code for various OSes -This code is public domain (no copyright). -You can do whatever you want with it. -*****************************************************************************/ -#include /* printf(), putchar() */ -#include "diskio.h" -/***************************************************************************** -*****************************************************************************/ -#define BPERL 16 /* byte/line for dump */ - -static void dump(unsigned char *data, unsigned count) -{ - unsigned char byte1, byte2; - - while(count != 0) - { - for(byte1 = 0; byte1 < BPERL; byte1++) - { - if(count == 0) - break; - printf("%02X ", data[byte1]); - count--; - } - printf("\t"); - for(byte2 = 0; byte2 < byte1; byte2++) - { - if(data[byte2] < ' ') - putchar('.'); - else - putchar(data[byte2]); - } - printf("\n"); - data += BPERL; - } -} -/***************************************************************************** -*****************************************************************************/ -int main(void) -{ - unsigned char buf[512], *ptab_rec; - unsigned i = 0; - disk_t disk; - - printf("Looking for FAT (DOS) disk or partition...\n"); -/* check if floppy in A: drive */ - if(open_disk(&disk, 0) == 0) - { -/* read bootsector, check if FAT */ - if(read_sector(&disk, 0, buf) == 0) - { - if(is_fat_bootsector(buf)) - goto OK; - } - } -/* scan hard drives for FAT partition */ - for(i = 0x80; i < 0x82; i++) - { - if(open_disk(&disk, i) != 0) - continue; -/* read MBR */ - if(read_sector(&disk, 0, buf) != 0) - continue; -/* find FAT partition */ - for(i = 0; i < 4; i++) - { - ptab_rec = buf + 446 + 16 * i; -/* make sure it's FAT */ - if(ptab_rec[4] == 0x01 || /* FAT 12 */ - ptab_rec[4] == 0x04 || /* FAT 16 <32meg */ - ptab_rec[4] == 0x06 || /* FAT 16 >=32meg */ - ptab_rec[4] == 0x0E) /* LBA type 0x06 */ - { -/* xxx - note if FAT16 or FAT12 */ - disk.partition_start = LE32(ptab_rec + 8); - goto OK; - } - } - } - printf("No FAT partitions found on any disk\n"); - return 1; -OK: - if(disk.drive_num >= 0x80) - printf("Partition #%u on ", i); - printf("INT 13h disk number 0x%02X:\n", disk.drive_num); - if(read_sector(&disk, 0, buf) != 0) - printf("Error reading bootsector\n"); - else - { - printf("Hex dump of bootsector:\n"); - dump(buf, 64); - } - return 0; -} +/***************************************************************************** +Sector-level disk I/O code for various OSes +This code is public domain (no copyright). +You can do whatever you want with it. +*****************************************************************************/ +#include /* printf(), putchar() */ +#include "diskio.h" +/***************************************************************************** +*****************************************************************************/ +#define BPERL 16 /* byte/line for dump */ + +static void dump(unsigned char *data, unsigned count) +{ + unsigned char byte1, byte2; + + while(count != 0) + { + for(byte1 = 0; byte1 < BPERL; byte1++) + { + if(count == 0) + break; + printf("%02X ", data[byte1]); + count--; + } + printf("\t"); + for(byte2 = 0; byte2 < byte1; byte2++) + { + if(data[byte2] < ' ') + putchar('.'); + else + putchar(data[byte2]); + } + printf("\n"); + data += BPERL; + } +} +/***************************************************************************** +*****************************************************************************/ +int main(void) +{ + unsigned char buf[512], *ptab_rec; + unsigned i = 0; + disk_t disk; + + printf("Looking for FAT (DOS) disk or partition...\n"); +/* check if floppy in A: drive */ + if(open_disk(&disk, 0) == 0) + { +/* read bootsector, check if FAT */ + if(read_sector(&disk, 0, buf) == 0) + { + if(is_fat_bootsector(buf)) + goto OK; + } + } +/* scan hard drives for FAT partition */ + for(i = 0x80; i < 0x82; i++) + { + if(open_disk(&disk, i) != 0) + continue; +/* read MBR */ + if(read_sector(&disk, 0, buf) != 0) + continue; +/* find FAT partition */ + for(i = 0; i < 4; i++) + { + ptab_rec = buf + 446 + 16 * i; +/* make sure it's FAT */ + if(ptab_rec[4] == 0x01 || /* FAT 12 */ + ptab_rec[4] == 0x04 || /* FAT 16 <32meg */ + ptab_rec[4] == 0x06 || /* FAT 16 >=32meg */ + ptab_rec[4] == 0x0E) /* LBA type 0x06 */ + { +/* xxx - note if FAT16 or FAT12 */ + disk.partition_start = LE32(ptab_rec + 8); + goto OK; + } + } + } + printf("No FAT partitions found on any disk\n"); + return 1; +OK: + if(disk.drive_num >= 0x80) + printf("Partition #%u on ", i); + printf("INT 13h disk number 0x%02X:\n", disk.drive_num); + if(read_sector(&disk, 0, buf) != 0) + printf("Error reading bootsector\n"); + else + { + printf("Hex dump of bootsector:\n"); + dump(buf, 64); + } + return 0; +} diff --git a/Dump/hybos/__experimental/diskio.h b/Dump/hybos/__experimental/diskio.h index 71ff36c..90247e3 100644 --- a/Dump/hybos/__experimental/diskio.h +++ b/Dump/hybos/__experimental/diskio.h @@ -1,59 +1,59 @@ -/***************************************************************************** -Sector-level disk I/O code for various OSes -This code is public domain (no copyright). -You can do whatever you want with it. - -EXPORTS (API): -DEBUG(), BPS, LE16(), LE32(), disk_t, -int read_sector(disk_t *disk, unsigned long lba, unsigned char *buf); -int write_sector(disk_t *disk, unsigned long lba, unsigned char *buf); -int is_fat_bootsector(unsigned char *buf); -int open_disk(disk_t *disk, unsigned drive_num); -*****************************************************************************/ -#ifndef __DISKIO_H -#define __DISKIO_H - -#ifdef __cplusplus -extern "C" -{ -#endif - -#if 0 -#define DEBUG(X) X -#else -#define DEBUG(X) /* nothing */ -#endif - -#define BPS 512 /* bytes/sector */ - -/* these assume little endian CPU like x86 */ -#define LE16(X) *(uint16_t *)(X) -#define LE32(X) *(uint32_t *)(X) - -/* STDINT.H -these assume sizeof(short)==2 and sizeof(long)==4 */ -typedef unsigned short uint16_t; -typedef unsigned long uint32_t; - -typedef struct -{ - unsigned char drive_num; -/* CHS disk geometry (heads and sectors are used only if use_lba==0) */ - unsigned use_lba : 1; - unsigned char heads; - unsigned char sectors; -/* LBA sector address of partition start (hard disk only) */ - unsigned long partition_start; -} disk_t; - -/* these are in DISKIO.C */ -int read_sector(disk_t *disk, unsigned long lba, unsigned char *buf); -int write_sector(disk_t *disk, unsigned long lba, unsigned char *buf); -int is_fat_bootsector(unsigned char *buf); -int open_disk(disk_t *disk, unsigned drive_num); - -#ifdef __cplusplus -} -#endif - -#endif +/***************************************************************************** +Sector-level disk I/O code for various OSes +This code is public domain (no copyright). +You can do whatever you want with it. + +EXPORTS (API): +DEBUG(), BPS, LE16(), LE32(), disk_t, +int read_sector(disk_t *disk, unsigned long lba, unsigned char *buf); +int write_sector(disk_t *disk, unsigned long lba, unsigned char *buf); +int is_fat_bootsector(unsigned char *buf); +int open_disk(disk_t *disk, unsigned drive_num); +*****************************************************************************/ +#ifndef __DISKIO_H +#define __DISKIO_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +#if 0 +#define DEBUG(X) X +#else +#define DEBUG(X) /* nothing */ +#endif + +#define BPS 512 /* bytes/sector */ + +/* these assume little endian CPU like x86 */ +#define LE16(X) *(uint16_t *)(X) +#define LE32(X) *(uint32_t *)(X) + +/* STDINT.H +these assume sizeof(short)==2 and sizeof(long)==4 */ +typedef unsigned short uint16_t; +typedef unsigned long uint32_t; + +typedef struct +{ + unsigned char drive_num; +/* CHS disk geometry (heads and sectors are used only if use_lba==0) */ + unsigned use_lba : 1; + unsigned char heads; + unsigned char sectors; +/* LBA sector address of partition start (hard disk only) */ + unsigned long partition_start; +} disk_t; + +/* these are in DISKIO.C */ +int read_sector(disk_t *disk, unsigned long lba, unsigned char *buf); +int write_sector(disk_t *disk, unsigned long lba, unsigned char *buf); +int is_fat_bootsector(unsigned char *buf); +int open_disk(disk_t *disk, unsigned drive_num); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/Dump/hybos/__experimental/djgpp.c b/Dump/hybos/__experimental/djgpp.c index ee35e57..70f04b5 100644 --- a/Dump/hybos/__experimental/djgpp.c +++ b/Dump/hybos/__experimental/djgpp.c @@ -1,131 +1,131 @@ -/***************************************************************************** -Sector-level disk I/O code for DOS, using DJGPP. -This code is public domain (no copyright). -You can do whatever you want with it. - -EXPORTS: -int lba_biosdisk(int cmd, int drive, unsigned long lba, - int nsects, void *buf); -int get_hd_geometry(disk_t *disk); -*****************************************************************************/ -#include /* dosmemget(), dosmemput() */ -#include /* memset() */ -#include /* printf() */ -#include /* _DISK_... */ -#include /* __dpmi_regs, __dpmi_int() */ -#include /* _go32_info_block, __tb */ -#include "diskio.h" -#include "dos.h" /* peekb() */ -/***************************************************************************** -*****************************************************************************/ -int lba_biosdisk(int cmd, int drive, unsigned long lba, int nsects, void *buf) -{ - struct - { - unsigned char pkt_len __attribute__((packed)); - unsigned char res0 __attribute__((packed)); - unsigned char nsects __attribute__((packed)); - unsigned char res1 __attribute__((packed)); - unsigned short buf_off __attribute__((packed)); - unsigned short buf_seg __attribute__((packed)); - unsigned long lba31_0 __attribute__((packed)); - unsigned long lba63_32 __attribute__((packed)); - } lba_cmd_pkt; - unsigned tries, err = 0; - __dpmi_regs regs; - - if(cmd != _DISK_READ && cmd != _DISK_WRITE) - return 0x100; -/* make sure the DJGPP transfer buffer (in conventional memory) -is big enough */ - if(BPS * nsects + sizeof(lba_cmd_pkt) > - _go32_info_block.size_of_transfer_buffer) - return 0x100; -/* make sure drive and BIOS support LBA */ - regs.x.bx = 0x55AA; - regs.h.dl = drive; - regs.h.ah = 0x41; - __dpmi_int(0x13, ®s); - if(regs.x.flags & 0x0001) /* carry bit (CY) is set */ - return 0x100; -/* fill out the INT 13h AH=4xh command packet */ - memset(&lba_cmd_pkt, 0, sizeof(lba_cmd_pkt)); - lba_cmd_pkt.pkt_len = sizeof(lba_cmd_pkt); - lba_cmd_pkt.nsects = nsects; -/* use start of transfer buffer for data transferred by BIOS disk I/O... */ - lba_cmd_pkt.buf_off = 0; - lba_cmd_pkt.buf_seg = __tb >> 4; - lba_cmd_pkt.lba31_0 = lba; -/* ...use end of transfer buffer for the command packet itself */ - dosmemput(&lba_cmd_pkt, sizeof(lba_cmd_pkt), - __tb + BPS * nsects); -/* fill out registers for INT 13h AH=4xh */ - regs.x.ds = (__tb + BPS * nsects) >> 4; - regs.x.si = (__tb + BPS * nsects) & 0x0F; - regs.h.dl = drive; -/* if writing, store the data */ - if(cmd == _DISK_WRITE) - dosmemput(buf, BPS * nsects, __tb); -/* make 3 attempts */ - for(tries = 3; tries != 0; tries--) - { - regs.h.ah = (cmd == _DISK_READ) ? 0x42 : 0x43; - __dpmi_int(0x13, ®s); - err = regs.h.ah; - if((regs.x.flags & 0x0001) == 0) - { -/* if reading, load the data */ - if(cmd == _DISK_READ) - dosmemget(__tb, BPS * nsects, buf); - return 0; - } -/* reset disk */ - regs.h.ah = _DISK_RESET; - __dpmi_int(0x13, ®s); - } - DEBUG(printf("lba_biosdisk(): error 0x%02X\n", err);) - return err; -} -/***************************************************************************** -*****************************************************************************/ -int get_hd_geometry(disk_t *disk) -{ - __dpmi_regs regs; - -/* make sure hard drive exists */ - if(disk->drive_num - 0x80 >= peekb(0x40, 0x75)) - { - printf("get_hd_geometry(): hd 0x%02X does not exist\n", - disk->drive_num); - return -1; - } -/* use LBA if drive and BIOS support it */ - regs.h.ah = 0x41; - regs.x.bx = 0x55AA; - regs.h.dl = disk->drive_num; - __dpmi_int(0x13, ®s); - if((regs.x.flags & 0x0001) == 0 && regs.x.bx == 0xAA55) - { - disk->use_lba = 1; - DEBUG(printf("get_hd_geometry(): using LBA for hd 0x%02X\n", - disk->drive_num);) - return 0; - } -/* get geometry from BIOS */ - regs.h.ah = 0x08; - regs.h.dl = disk->drive_num; - __dpmi_int(0x13, ®s); - if(regs.x.flags & 0x0001) - { - printf("get_hd_geometry(): error getting geometry " - "for hard drive 0x%02X\n", disk->drive_num); - return -1; - } - disk->heads = regs.h.dh + 1; - disk->sectors = regs.h.cl & 0x3F; - DEBUG(printf("get_hd_geometry() for hd 0x%02X: " - "CHS=?:%u:%u (from INT 13h AH=08h)\n", - disk->drive_num, - disk->heads, disk->sectors);) - return 0; -} +/***************************************************************************** +Sector-level disk I/O code for DOS, using DJGPP. +This code is public domain (no copyright). +You can do whatever you want with it. + +EXPORTS: +int lba_biosdisk(int cmd, int drive, unsigned long lba, + int nsects, void *buf); +int get_hd_geometry(disk_t *disk); +*****************************************************************************/ +#include /* dosmemget(), dosmemput() */ +#include /* memset() */ +#include /* printf() */ +#include /* _DISK_... */ +#include /* __dpmi_regs, __dpmi_int() */ +#include /* _go32_info_block, __tb */ +#include "diskio.h" +#include "dos.h" /* peekb() */ +/***************************************************************************** +*****************************************************************************/ +int lba_biosdisk(int cmd, int drive, unsigned long lba, int nsects, void *buf) +{ + struct + { + unsigned char pkt_len __attribute__((packed)); + unsigned char res0 __attribute__((packed)); + unsigned char nsects __attribute__((packed)); + unsigned char res1 __attribute__((packed)); + unsigned short buf_off __attribute__((packed)); + unsigned short buf_seg __attribute__((packed)); + unsigned long lba31_0 __attribute__((packed)); + unsigned long lba63_32 __attribute__((packed)); + } lba_cmd_pkt; + unsigned tries, err = 0; + __dpmi_regs regs; + + if(cmd != _DISK_READ && cmd != _DISK_WRITE) + return 0x100; +/* make sure the DJGPP transfer buffer (in conventional memory) +is big enough */ + if(BPS * nsects + sizeof(lba_cmd_pkt) > + _go32_info_block.size_of_transfer_buffer) + return 0x100; +/* make sure drive and BIOS support LBA */ + regs.x.bx = 0x55AA; + regs.h.dl = drive; + regs.h.ah = 0x41; + __dpmi_int(0x13, ®s); + if(regs.x.flags & 0x0001) /* carry bit (CY) is set */ + return 0x100; +/* fill out the INT 13h AH=4xh command packet */ + memset(&lba_cmd_pkt, 0, sizeof(lba_cmd_pkt)); + lba_cmd_pkt.pkt_len = sizeof(lba_cmd_pkt); + lba_cmd_pkt.nsects = nsects; +/* use start of transfer buffer for data transferred by BIOS disk I/O... */ + lba_cmd_pkt.buf_off = 0; + lba_cmd_pkt.buf_seg = __tb >> 4; + lba_cmd_pkt.lba31_0 = lba; +/* ...use end of transfer buffer for the command packet itself */ + dosmemput(&lba_cmd_pkt, sizeof(lba_cmd_pkt), + __tb + BPS * nsects); +/* fill out registers for INT 13h AH=4xh */ + regs.x.ds = (__tb + BPS * nsects) >> 4; + regs.x.si = (__tb + BPS * nsects) & 0x0F; + regs.h.dl = drive; +/* if writing, store the data */ + if(cmd == _DISK_WRITE) + dosmemput(buf, BPS * nsects, __tb); +/* make 3 attempts */ + for(tries = 3; tries != 0; tries--) + { + regs.h.ah = (cmd == _DISK_READ) ? 0x42 : 0x43; + __dpmi_int(0x13, ®s); + err = regs.h.ah; + if((regs.x.flags & 0x0001) == 0) + { +/* if reading, load the data */ + if(cmd == _DISK_READ) + dosmemget(__tb, BPS * nsects, buf); + return 0; + } +/* reset disk */ + regs.h.ah = _DISK_RESET; + __dpmi_int(0x13, ®s); + } + DEBUG(printf("lba_biosdisk(): error 0x%02X\n", err);) + return err; +} +/***************************************************************************** +*****************************************************************************/ +int get_hd_geometry(disk_t *disk) +{ + __dpmi_regs regs; + +/* make sure hard drive exists */ + if(disk->drive_num - 0x80 >= peekb(0x40, 0x75)) + { + printf("get_hd_geometry(): hd 0x%02X does not exist\n", + disk->drive_num); + return -1; + } +/* use LBA if drive and BIOS support it */ + regs.h.ah = 0x41; + regs.x.bx = 0x55AA; + regs.h.dl = disk->drive_num; + __dpmi_int(0x13, ®s); + if((regs.x.flags & 0x0001) == 0 && regs.x.bx == 0xAA55) + { + disk->use_lba = 1; + DEBUG(printf("get_hd_geometry(): using LBA for hd 0x%02X\n", + disk->drive_num);) + return 0; + } +/* get geometry from BIOS */ + regs.h.ah = 0x08; + regs.h.dl = disk->drive_num; + __dpmi_int(0x13, ®s); + if(regs.x.flags & 0x0001) + { + printf("get_hd_geometry(): error getting geometry " + "for hard drive 0x%02X\n", disk->drive_num); + return -1; + } + disk->heads = regs.h.dh + 1; + disk->sectors = regs.h.cl & 0x3F; + DEBUG(printf("get_hd_geometry() for hd 0x%02X: " + "CHS=?:%u:%u (from INT 13h AH=08h)\n", + disk->drive_num, + disk->heads, disk->sectors);) + return 0; +} diff --git a/Dump/hybos/__experimental/djgpp.mak b/Dump/hybos/__experimental/djgpp.mak index a8e153f..b5d3d96 100644 --- a/Dump/hybos/__experimental/djgpp.mak +++ b/Dump/hybos/__experimental/djgpp.mak @@ -1,28 +1,28 @@ -# Makefile for 32-bit DOS - DJGPP - -# defines -# MAKEDEP =makefile -CC =gcc -g -O2 -Wall -W -LD =gcc -g -OBJS =demo.o dos.o djgpp.o - -# targets -all: diskio.exe - -clean: - deltree /y *.exe *.obj *.o *.err - -# implicit rules -.c.o: - $(CC) -c -o$@ $< - -# dependencies -demo.o: demo.c $(MAKEDEP) diskio.h - -dos.o: dos.c $(MAKEDEP) diskio.h dos.h - -djgpp.o: djgpp.c $(MAKEDEP) diskio.h dos.h - -# explicit rules -diskio.exe: $(OBJS) $(MAKEDEP) - $(LD) -o$@ $(OBJS) +# Makefile for 32-bit DOS - DJGPP + +# defines +# MAKEDEP =makefile +CC =gcc -g -O2 -Wall -W +LD =gcc -g +OBJS =demo.o dos.o djgpp.o + +# targets +all: diskio.exe + +clean: + deltree /y *.exe *.obj *.o *.err + +# implicit rules +.c.o: + $(CC) -c -o$@ $< + +# dependencies +demo.o: demo.c $(MAKEDEP) diskio.h + +dos.o: dos.c $(MAKEDEP) diskio.h dos.h + +djgpp.o: djgpp.c $(MAKEDEP) diskio.h dos.h + +# explicit rules +diskio.exe: $(OBJS) $(MAKEDEP) + $(LD) -o$@ $(OBJS) diff --git a/Dump/hybos/__experimental/dos.c b/Dump/hybos/__experimental/dos.c index 71f1446..c101dae 100644 --- a/Dump/hybos/__experimental/dos.c +++ b/Dump/hybos/__experimental/dos.c @@ -1,256 +1,256 @@ -/***************************************************************************** -Sector-level disk I/O code for DOS. -This code is public domain (no copyright). -You can do whatever you want with it. - -EXPORTS: -int read_sector(disk_t *disk, unsigned long lba, unsigned char *buf); -int write_sector(disk_t *disk, unsigned long lba, unsigned char *buf); -int is_fat_bootsector(unsigned char *buf); -int open_disk(disk_t *disk, unsigned drive_num); -*****************************************************************************/ -#include /* printf() */ -/*#include */ /* _DISK_..., diskinfo_t, _bios_disk() */ -#include "diskio.h" -#include "dos.h" /* peekw() */ - -/* IMPORTS -from _16BIT.C, DJGPP, or ??? */ -int lba_biosdisk(int cmd, int drive, unsigned long lba, int nsects, void *buf); -int get_hd_geometry(disk_t *disk); - -/* xxx - I'm not sure of the Turbo C version where these were -introduced. They are present in Turbo C++ 3.0 (__TURBOC__ == 0x401) -but not in Turbo C++ 1.0 (__TURBOC__ == 0x296) */ -#if defined(__TURBOC__) -#if __TURBOC__<0x300 - -struct diskinfo_t -{ - unsigned drive, head, track, sector, nsectors; - void far *buffer; -}; - -unsigned _bios_disk(unsigned cmd, struct diskinfo_t *info) -{ - struct SREGS sregs; - union REGS regs; - -/* biosdisk() returns the 8-bit error code left in register AH by -the call to INT 13h. It does NOT return a combined, 16-bit error -code + number of sectors transferred, as described in the online help. - - return biosdisk(cmd, info->drive, info->head, info->track, - info->sector, info->nsectors, info->buffer); -*/ - regs.h.ah = cmd; - regs.h.al = info->nsectors; - regs.x.bx = FP_OFF(info->buffer); - regs.h.ch = info->track; - regs.h.cl = (info->track / 256) * 64 + (info->sector & 0x3F); - regs.h.dh = info->head; - regs.h.dl = info->drive; - sregs.es = FP_SEG(info->buffer); - int86x(0x13, ®s, ®s, &sregs); - return regs.x.ax; -} -#endif -#endif -/***************************************************************************** -*****************************************************************************/ -int read_sector(disk_t *disk, unsigned long lba, unsigned char *buf) -{ - struct diskinfo_t cmd; - unsigned tries, err; - - lba += disk->partition_start; - cmd.drive = disk->drive_num; -/* use LBA if available */ - if(disk->use_lba) - { - return lba_biosdisk(_DISK_READ, - disk->drive_num, lba, 1, buf); - } -/* use CHS _bios_disk() */ - cmd.sector = (unsigned)(lba % disk->sectors + 1); - cmd.head = (unsigned)((lba / disk->sectors) % disk->heads); - cmd.track = (unsigned)((lba / disk->sectors) / disk->heads); - cmd.nsectors = 1; - cmd.buffer = buf; -/* make 3 attempts */ - for(tries = 3; tries != 0; tries--) - { - err = _bios_disk(_DISK_READ, &cmd); - err >>= 8; -/* 0x11=="CRC/ECC corrected data error" */ - if(err == 0 || err == 0x11) - return 0; -/* reset disk */ - _bios_disk(_DISK_RESET, &cmd); - } - DEBUG(printf("read_sector(): error 0x%02X\n", err);) - return err; -} -/***************************************************************************** -*****************************************************************************/ -int write_sector(disk_t *disk, unsigned long lba, unsigned char *buf) -{ - struct diskinfo_t cmd; - unsigned tries, err; - - lba += disk->partition_start; - cmd.drive = disk->drive_num; -/* use LBA if available */ - if(disk->use_lba) - { - return lba_biosdisk(_DISK_WRITE, - disk->drive_num, lba, 1, buf); - } -/* use CHS _bios_disk() */ - cmd.sector = (unsigned)(lba % disk->sectors + 1); - cmd.head = (unsigned)((lba / disk->sectors) % disk->heads); - cmd.track = (unsigned)((lba / disk->sectors) / disk->heads); - cmd.nsectors = 1; - cmd.buffer = buf; -/* make 3 attempts */ - for(tries = 3; tries != 0; tries--) - { - err = _bios_disk(_DISK_WRITE, &cmd); - err >>= 8; -/* 0x11=="CRC/ECC corrected data error" */ - if(err == 0 || err == 0x11) - return 0; -/* reset disk */ - _bios_disk(_DISK_RESET, &cmd); - } - DEBUG(printf("write_sector(): error 0x%02X\n", err);) - return err; -} -/***************************************************************************** -*****************************************************************************/ -int is_fat_bootsector(unsigned char *buf) -{ - int temp, ok = 1; - - DEBUG(printf("check_if_fat_bootsector:\n");) -/* must start with 16-bit JMP or 8-bit JMP plus NOP */ - if(buf[0] == 0xE9) - /* OK */; - else if(buf[0] == 0xEB && buf[2] == 0x90) - /* OK */; - else - { - DEBUG(printf("\tMissing JMP/NOP\n");) - ok = 0; - } - temp = buf[13]; - if(temp == 0 || ((temp - 1) & temp) != 0) - { - DEBUG(printf("\tSectors per cluster (%u) " - "is not a power of 2\n", temp);) - ok = 0; - } - temp = buf[16]; - temp = LE16(buf + 24); - if(temp == 0 || temp > 63) - { - DEBUG(printf("\tInvalid number of sectors (%u)\n", temp);) - ok = 0; - } - temp = LE16(buf + 26); - if(temp == 0 || temp > 255) - { - DEBUG(printf("\tInvalid number of heads (%u)\n", temp);) - ok = 0; - } - return ok; -} -/***************************************************************************** -*****************************************************************************/ -static void probe_floppy_geometry(disk_t *disk) -{ - unsigned sectors, heads; - unsigned char buf[BPS]; - -/* scan upwards for sector number where read fails */ - disk->sectors = 64 + 1; - for(sectors = 1; sectors <= 64; sectors++) - { - if(read_sector(disk, sectors - 1, buf) != 0) - break; - } - disk->sectors = sectors - 1; -#if 1 -disk->heads = 2; -#else -/* scan upwards for head number where read fails -xxx - this probing for number of heads doesn't work */ - disk->heads = 16 + 1; - for(heads = 1; heads < 16; heads++) - { - if(read_sector(disk, heads * disk->sectors, buf) != 0) - break; - } - disk->heads = heads; -#endif -/* reset drive by reading sector 0 */ - (void)read_sector(disk, 0, buf); - DEBUG(printf("probe_floppy_geometry() for fd 0x%02X: " - "CHS=?:%u:%u\n", disk->drive_num, - disk->heads, disk->sectors);) -} -/***************************************************************************** -*****************************************************************************/ -int open_disk(disk_t *disk, unsigned drive_num) -{ - unsigned char buf[BPS]; - unsigned num_fds; - int err; - - disk->drive_num = drive_num; - disk->partition_start = 0; /* assume floppy */ - disk->use_lba = 0; /* assume CHS */ -/* hard disk */ - if(disk->drive_num >= 0x80) - return get_hd_geometry(disk); -/* make sure floppy drive exists */ - num_fds = peekw(0x40, 0x10); - if(num_fds & 0x0001) - num_fds = ((num_fds / 64) & 3) + 1; - else - num_fds = 0; - if(disk->drive_num >= num_fds) - { - printf("open_disk(): fd 0x%02X does not exist\n", - disk->drive_num); - return -1; - } -/* temporary values to make read_sector(0) work */ - disk->heads = disk->sectors = 1; - err = read_sector(disk, 0, buf); - if(err != 0) - return err; -/* if it's a FAT (DOS) disk, we get can reliable geometry info -from the BIOS parameter block (BPB) in the bootsector */ - if(is_fat_bootsector(buf)) - { - disk->heads = LE16(buf + 26); - disk->sectors = LE16(buf + 24); - DEBUG(printf("open_disk() for fd 0x%02X: " - "CHS=?:%u:%u (from BPB)\n", - disk->drive_num, - disk->heads, disk->sectors);) - return 0; - } -#if 0 -/* ...otherwise, do slow probe */ - probe_floppy_geometry(disk); -#else -/* ...or just assume some values */ - disk->heads = 2; - disk->sectors = 18; - DEBUG(printf("open_disk() for fd 0x%02X: " - "assuming CHS=?:2:18\n", disk->drive_num);) -#endif - return 0; -} +/***************************************************************************** +Sector-level disk I/O code for DOS. +This code is public domain (no copyright). +You can do whatever you want with it. + +EXPORTS: +int read_sector(disk_t *disk, unsigned long lba, unsigned char *buf); +int write_sector(disk_t *disk, unsigned long lba, unsigned char *buf); +int is_fat_bootsector(unsigned char *buf); +int open_disk(disk_t *disk, unsigned drive_num); +*****************************************************************************/ +#include /* printf() */ +/*#include */ /* _DISK_..., diskinfo_t, _bios_disk() */ +#include "diskio.h" +#include "dos.h" /* peekw() */ + +/* IMPORTS +from _16BIT.C, DJGPP, or ??? */ +int lba_biosdisk(int cmd, int drive, unsigned long lba, int nsects, void *buf); +int get_hd_geometry(disk_t *disk); + +/* xxx - I'm not sure of the Turbo C version where these were +introduced. They are present in Turbo C++ 3.0 (__TURBOC__ == 0x401) +but not in Turbo C++ 1.0 (__TURBOC__ == 0x296) */ +#if defined(__TURBOC__) +#if __TURBOC__<0x300 + +struct diskinfo_t +{ + unsigned drive, head, track, sector, nsectors; + void far *buffer; +}; + +unsigned _bios_disk(unsigned cmd, struct diskinfo_t *info) +{ + struct SREGS sregs; + union REGS regs; + +/* biosdisk() returns the 8-bit error code left in register AH by +the call to INT 13h. It does NOT return a combined, 16-bit error +code + number of sectors transferred, as described in the online help. + + return biosdisk(cmd, info->drive, info->head, info->track, + info->sector, info->nsectors, info->buffer); +*/ + regs.h.ah = cmd; + regs.h.al = info->nsectors; + regs.x.bx = FP_OFF(info->buffer); + regs.h.ch = info->track; + regs.h.cl = (info->track / 256) * 64 + (info->sector & 0x3F); + regs.h.dh = info->head; + regs.h.dl = info->drive; + sregs.es = FP_SEG(info->buffer); + int86x(0x13, ®s, ®s, &sregs); + return regs.x.ax; +} +#endif +#endif +/***************************************************************************** +*****************************************************************************/ +int read_sector(disk_t *disk, unsigned long lba, unsigned char *buf) +{ + struct diskinfo_t cmd; + unsigned tries, err; + + lba += disk->partition_start; + cmd.drive = disk->drive_num; +/* use LBA if available */ + if(disk->use_lba) + { + return lba_biosdisk(_DISK_READ, + disk->drive_num, lba, 1, buf); + } +/* use CHS _bios_disk() */ + cmd.sector = (unsigned)(lba % disk->sectors + 1); + cmd.head = (unsigned)((lba / disk->sectors) % disk->heads); + cmd.track = (unsigned)((lba / disk->sectors) / disk->heads); + cmd.nsectors = 1; + cmd.buffer = buf; +/* make 3 attempts */ + for(tries = 3; tries != 0; tries--) + { + err = _bios_disk(_DISK_READ, &cmd); + err >>= 8; +/* 0x11=="CRC/ECC corrected data error" */ + if(err == 0 || err == 0x11) + return 0; +/* reset disk */ + _bios_disk(_DISK_RESET, &cmd); + } + DEBUG(printf("read_sector(): error 0x%02X\n", err);) + return err; +} +/***************************************************************************** +*****************************************************************************/ +int write_sector(disk_t *disk, unsigned long lba, unsigned char *buf) +{ + struct diskinfo_t cmd; + unsigned tries, err; + + lba += disk->partition_start; + cmd.drive = disk->drive_num; +/* use LBA if available */ + if(disk->use_lba) + { + return lba_biosdisk(_DISK_WRITE, + disk->drive_num, lba, 1, buf); + } +/* use CHS _bios_disk() */ + cmd.sector = (unsigned)(lba % disk->sectors + 1); + cmd.head = (unsigned)((lba / disk->sectors) % disk->heads); + cmd.track = (unsigned)((lba / disk->sectors) / disk->heads); + cmd.nsectors = 1; + cmd.buffer = buf; +/* make 3 attempts */ + for(tries = 3; tries != 0; tries--) + { + err = _bios_disk(_DISK_WRITE, &cmd); + err >>= 8; +/* 0x11=="CRC/ECC corrected data error" */ + if(err == 0 || err == 0x11) + return 0; +/* reset disk */ + _bios_disk(_DISK_RESET, &cmd); + } + DEBUG(printf("write_sector(): error 0x%02X\n", err);) + return err; +} +/***************************************************************************** +*****************************************************************************/ +int is_fat_bootsector(unsigned char *buf) +{ + int temp, ok = 1; + + DEBUG(printf("check_if_fat_bootsector:\n");) +/* must start with 16-bit JMP or 8-bit JMP plus NOP */ + if(buf[0] == 0xE9) + /* OK */; + else if(buf[0] == 0xEB && buf[2] == 0x90) + /* OK */; + else + { + DEBUG(printf("\tMissing JMP/NOP\n");) + ok = 0; + } + temp = buf[13]; + if(temp == 0 || ((temp - 1) & temp) != 0) + { + DEBUG(printf("\tSectors per cluster (%u) " + "is not a power of 2\n", temp);) + ok = 0; + } + temp = buf[16]; + temp = LE16(buf + 24); + if(temp == 0 || temp > 63) + { + DEBUG(printf("\tInvalid number of sectors (%u)\n", temp);) + ok = 0; + } + temp = LE16(buf + 26); + if(temp == 0 || temp > 255) + { + DEBUG(printf("\tInvalid number of heads (%u)\n", temp);) + ok = 0; + } + return ok; +} +/***************************************************************************** +*****************************************************************************/ +static void probe_floppy_geometry(disk_t *disk) +{ + unsigned sectors, heads; + unsigned char buf[BPS]; + +/* scan upwards for sector number where read fails */ + disk->sectors = 64 + 1; + for(sectors = 1; sectors <= 64; sectors++) + { + if(read_sector(disk, sectors - 1, buf) != 0) + break; + } + disk->sectors = sectors - 1; +#if 1 +disk->heads = 2; +#else +/* scan upwards for head number where read fails +xxx - this probing for number of heads doesn't work */ + disk->heads = 16 + 1; + for(heads = 1; heads < 16; heads++) + { + if(read_sector(disk, heads * disk->sectors, buf) != 0) + break; + } + disk->heads = heads; +#endif +/* reset drive by reading sector 0 */ + (void)read_sector(disk, 0, buf); + DEBUG(printf("probe_floppy_geometry() for fd 0x%02X: " + "CHS=?:%u:%u\n", disk->drive_num, + disk->heads, disk->sectors);) +} +/***************************************************************************** +*****************************************************************************/ +int open_disk(disk_t *disk, unsigned drive_num) +{ + unsigned char buf[BPS]; + unsigned num_fds; + int err; + + disk->drive_num = drive_num; + disk->partition_start = 0; /* assume floppy */ + disk->use_lba = 0; /* assume CHS */ +/* hard disk */ + if(disk->drive_num >= 0x80) + return get_hd_geometry(disk); +/* make sure floppy drive exists */ + num_fds = peekw(0x40, 0x10); + if(num_fds & 0x0001) + num_fds = ((num_fds / 64) & 3) + 1; + else + num_fds = 0; + if(disk->drive_num >= num_fds) + { + printf("open_disk(): fd 0x%02X does not exist\n", + disk->drive_num); + return -1; + } +/* temporary values to make read_sector(0) work */ + disk->heads = disk->sectors = 1; + err = read_sector(disk, 0, buf); + if(err != 0) + return err; +/* if it's a FAT (DOS) disk, we get can reliable geometry info +from the BIOS parameter block (BPB) in the bootsector */ + if(is_fat_bootsector(buf)) + { + disk->heads = LE16(buf + 26); + disk->sectors = LE16(buf + 24); + DEBUG(printf("open_disk() for fd 0x%02X: " + "CHS=?:%u:%u (from BPB)\n", + disk->drive_num, + disk->heads, disk->sectors);) + return 0; + } +#if 0 +/* ...otherwise, do slow probe */ + probe_floppy_geometry(disk); +#else +/* ...or just assume some values */ + disk->heads = 2; + disk->sectors = 18; + DEBUG(printf("open_disk() for fd 0x%02X: " + "assuming CHS=?:2:18\n", disk->drive_num);) +#endif + return 0; +} diff --git a/Dump/hybos/__experimental/dos.c~ b/Dump/hybos/__experimental/dos.c~ index 8b0703a..0ce7f4a 100644 --- a/Dump/hybos/__experimental/dos.c~ +++ b/Dump/hybos/__experimental/dos.c~ @@ -1,256 +1,256 @@ -/***************************************************************************** -Sector-level disk I/O code for DOS. -This code is public domain (no copyright). -You can do whatever you want with it. - -EXPORTS: -int read_sector(disk_t *disk, unsigned long lba, unsigned char *buf); -int write_sector(disk_t *disk, unsigned long lba, unsigned char *buf); -int is_fat_bootsector(unsigned char *buf); -int open_disk(disk_t *disk, unsigned drive_num); -*****************************************************************************/ -#include /* printf() */ -#include /* _DISK_..., diskinfo_t, _bios_disk() */ -#include "diskio.h" -#include "dos.h" /* peekw() */ - -/* IMPORTS -from _16BIT.C, DJGPP, or ??? */ -int lba_biosdisk(int cmd, int drive, unsigned long lba, int nsects, void *buf); -int get_hd_geometry(disk_t *disk); - -/* xxx - I'm not sure of the Turbo C version where these were -introduced. They are present in Turbo C++ 3.0 (__TURBOC__ == 0x401) -but not in Turbo C++ 1.0 (__TURBOC__ == 0x296) */ -#if defined(__TURBOC__) -#if __TURBOC__<0x300 - -struct diskinfo_t -{ - unsigned drive, head, track, sector, nsectors; - void far *buffer; -}; - -unsigned _bios_disk(unsigned cmd, struct diskinfo_t *info) -{ - struct SREGS sregs; - union REGS regs; - -/* biosdisk() returns the 8-bit error code left in register AH by -the call to INT 13h. It does NOT return a combined, 16-bit error -code + number of sectors transferred, as described in the online help. - - return biosdisk(cmd, info->drive, info->head, info->track, - info->sector, info->nsectors, info->buffer); -*/ - regs.h.ah = cmd; - regs.h.al = info->nsectors; - regs.x.bx = FP_OFF(info->buffer); - regs.h.ch = info->track; - regs.h.cl = (info->track / 256) * 64 + (info->sector & 0x3F); - regs.h.dh = info->head; - regs.h.dl = info->drive; - sregs.es = FP_SEG(info->buffer); - int86x(0x13, ®s, ®s, &sregs); - return regs.x.ax; -} -#endif -#endif -/***************************************************************************** -*****************************************************************************/ -int read_sector(disk_t *disk, unsigned long lba, unsigned char *buf) -{ - struct diskinfo_t cmd; - unsigned tries, err; - - lba += disk->partition_start; - cmd.drive = disk->drive_num; -/* use LBA if available */ - if(disk->use_lba) - { - return lba_biosdisk(_DISK_READ, - disk->drive_num, lba, 1, buf); - } -/* use CHS _bios_disk() */ - cmd.sector = (unsigned)(lba % disk->sectors + 1); - cmd.head = (unsigned)((lba / disk->sectors) % disk->heads); - cmd.track = (unsigned)((lba / disk->sectors) / disk->heads); - cmd.nsectors = 1; - cmd.buffer = buf; -/* make 3 attempts */ - for(tries = 3; tries != 0; tries--) - { - err = _bios_disk(_DISK_READ, &cmd); - err >>= 8; -/* 0x11=="CRC/ECC corrected data error" */ - if(err == 0 || err == 0x11) - return 0; -/* reset disk */ - _bios_disk(_DISK_RESET, &cmd); - } - DEBUG(printf("read_sector(): error 0x%02X\n", err);) - return err; -} -/***************************************************************************** -*****************************************************************************/ -int write_sector(disk_t *disk, unsigned long lba, unsigned char *buf) -{ - struct diskinfo_t cmd; - unsigned tries, err; - - lba += disk->partition_start; - cmd.drive = disk->drive_num; -/* use LBA if available */ - if(disk->use_lba) - { - return lba_biosdisk(_DISK_WRITE, - disk->drive_num, lba, 1, buf); - } -/* use CHS _bios_disk() */ - cmd.sector = (unsigned)(lba % disk->sectors + 1); - cmd.head = (unsigned)((lba / disk->sectors) % disk->heads); - cmd.track = (unsigned)((lba / disk->sectors) / disk->heads); - cmd.nsectors = 1; - cmd.buffer = buf; -/* make 3 attempts */ - for(tries = 3; tries != 0; tries--) - { - err = _bios_disk(_DISK_WRITE, &cmd); - err >>= 8; -/* 0x11=="CRC/ECC corrected data error" */ - if(err == 0 || err == 0x11) - return 0; -/* reset disk */ - _bios_disk(_DISK_RESET, &cmd); - } - DEBUG(printf("write_sector(): error 0x%02X\n", err);) - return err; -} -/***************************************************************************** -*****************************************************************************/ -int is_fat_bootsector(unsigned char *buf) -{ - int temp, ok = 1; - - DEBUG(printf("check_if_fat_bootsector:\n");) -/* must start with 16-bit JMP or 8-bit JMP plus NOP */ - if(buf[0] == 0xE9) - /* OK */; - else if(buf[0] == 0xEB && buf[2] == 0x90) - /* OK */; - else - { - DEBUG(printf("\tMissing JMP/NOP\n");) - ok = 0; - } - temp = buf[13]; - if(temp == 0 || ((temp - 1) & temp) != 0) - { - DEBUG(printf("\tSectors per cluster (%u) " - "is not a power of 2\n", temp);) - ok = 0; - } - temp = buf[16]; - temp = LE16(buf + 24); - if(temp == 0 || temp > 63) - { - DEBUG(printf("\tInvalid number of sectors (%u)\n", temp);) - ok = 0; - } - temp = LE16(buf + 26); - if(temp == 0 || temp > 255) - { - DEBUG(printf("\tInvalid number of heads (%u)\n", temp);) - ok = 0; - } - return ok; -} -/***************************************************************************** -*****************************************************************************/ -static void probe_floppy_geometry(disk_t *disk) -{ - unsigned sectors, heads; - unsigned char buf[BPS]; - -/* scan upwards for sector number where read fails */ - disk->sectors = 64 + 1; - for(sectors = 1; sectors <= 64; sectors++) - { - if(read_sector(disk, sectors - 1, buf) != 0) - break; - } - disk->sectors = sectors - 1; -#if 1 -disk->heads = 2; -#else -/* scan upwards for head number where read fails -xxx - this probing for number of heads doesn't work */ - disk->heads = 16 + 1; - for(heads = 1; heads < 16; heads++) - { - if(read_sector(disk, heads * disk->sectors, buf) != 0) - break; - } - disk->heads = heads; -#endif -/* reset drive by reading sector 0 */ - (void)read_sector(disk, 0, buf); - DEBUG(printf("probe_floppy_geometry() for fd 0x%02X: " - "CHS=?:%u:%u\n", disk->drive_num, - disk->heads, disk->sectors);) -} -/***************************************************************************** -*****************************************************************************/ -int open_disk(disk_t *disk, unsigned drive_num) -{ - unsigned char buf[BPS]; - unsigned num_fds; - int err; - - disk->drive_num = drive_num; - disk->partition_start = 0; /* assume floppy */ - disk->use_lba = 0; /* assume CHS */ -/* hard disk */ - if(disk->drive_num >= 0x80) - return get_hd_geometry(disk); -/* make sure floppy drive exists */ - num_fds = peekw(0x40, 0x10); - if(num_fds & 0x0001) - num_fds = ((num_fds / 64) & 3) + 1; - else - num_fds = 0; - if(disk->drive_num >= num_fds) - { - printf("open_disk(): fd 0x%02X does not exist\n", - disk->drive_num); - return -1; - } -/* temporary values to make read_sector(0) work */ - disk->heads = disk->sectors = 1; - err = read_sector(disk, 0, buf); - if(err != 0) - return err; -/* if it's a FAT (DOS) disk, we get can reliable geometry info -from the BIOS parameter block (BPB) in the bootsector */ - if(is_fat_bootsector(buf)) - { - disk->heads = LE16(buf + 26); - disk->sectors = LE16(buf + 24); - DEBUG(printf("open_disk() for fd 0x%02X: " - "CHS=?:%u:%u (from BPB)\n", - disk->drive_num, - disk->heads, disk->sectors);) - return 0; - } -#if 0 -/* ...otherwise, do slow probe */ - probe_floppy_geometry(disk); -#else -/* ...or just assume some values */ - disk->heads = 2; - disk->sectors = 18; - DEBUG(printf("open_disk() for fd 0x%02X: " - "assuming CHS=?:2:18\n", disk->drive_num);) -#endif - return 0; -} +/***************************************************************************** +Sector-level disk I/O code for DOS. +This code is public domain (no copyright). +You can do whatever you want with it. + +EXPORTS: +int read_sector(disk_t *disk, unsigned long lba, unsigned char *buf); +int write_sector(disk_t *disk, unsigned long lba, unsigned char *buf); +int is_fat_bootsector(unsigned char *buf); +int open_disk(disk_t *disk, unsigned drive_num); +*****************************************************************************/ +#include /* printf() */ +#include /* _DISK_..., diskinfo_t, _bios_disk() */ +#include "diskio.h" +#include "dos.h" /* peekw() */ + +/* IMPORTS +from _16BIT.C, DJGPP, or ??? */ +int lba_biosdisk(int cmd, int drive, unsigned long lba, int nsects, void *buf); +int get_hd_geometry(disk_t *disk); + +/* xxx - I'm not sure of the Turbo C version where these were +introduced. They are present in Turbo C++ 3.0 (__TURBOC__ == 0x401) +but not in Turbo C++ 1.0 (__TURBOC__ == 0x296) */ +#if defined(__TURBOC__) +#if __TURBOC__<0x300 + +struct diskinfo_t +{ + unsigned drive, head, track, sector, nsectors; + void far *buffer; +}; + +unsigned _bios_disk(unsigned cmd, struct diskinfo_t *info) +{ + struct SREGS sregs; + union REGS regs; + +/* biosdisk() returns the 8-bit error code left in register AH by +the call to INT 13h. It does NOT return a combined, 16-bit error +code + number of sectors transferred, as described in the online help. + + return biosdisk(cmd, info->drive, info->head, info->track, + info->sector, info->nsectors, info->buffer); +*/ + regs.h.ah = cmd; + regs.h.al = info->nsectors; + regs.x.bx = FP_OFF(info->buffer); + regs.h.ch = info->track; + regs.h.cl = (info->track / 256) * 64 + (info->sector & 0x3F); + regs.h.dh = info->head; + regs.h.dl = info->drive; + sregs.es = FP_SEG(info->buffer); + int86x(0x13, ®s, ®s, &sregs); + return regs.x.ax; +} +#endif +#endif +/***************************************************************************** +*****************************************************************************/ +int read_sector(disk_t *disk, unsigned long lba, unsigned char *buf) +{ + struct diskinfo_t cmd; + unsigned tries, err; + + lba += disk->partition_start; + cmd.drive = disk->drive_num; +/* use LBA if available */ + if(disk->use_lba) + { + return lba_biosdisk(_DISK_READ, + disk->drive_num, lba, 1, buf); + } +/* use CHS _bios_disk() */ + cmd.sector = (unsigned)(lba % disk->sectors + 1); + cmd.head = (unsigned)((lba / disk->sectors) % disk->heads); + cmd.track = (unsigned)((lba / disk->sectors) / disk->heads); + cmd.nsectors = 1; + cmd.buffer = buf; +/* make 3 attempts */ + for(tries = 3; tries != 0; tries--) + { + err = _bios_disk(_DISK_READ, &cmd); + err >>= 8; +/* 0x11=="CRC/ECC corrected data error" */ + if(err == 0 || err == 0x11) + return 0; +/* reset disk */ + _bios_disk(_DISK_RESET, &cmd); + } + DEBUG(printf("read_sector(): error 0x%02X\n", err);) + return err; +} +/***************************************************************************** +*****************************************************************************/ +int write_sector(disk_t *disk, unsigned long lba, unsigned char *buf) +{ + struct diskinfo_t cmd; + unsigned tries, err; + + lba += disk->partition_start; + cmd.drive = disk->drive_num; +/* use LBA if available */ + if(disk->use_lba) + { + return lba_biosdisk(_DISK_WRITE, + disk->drive_num, lba, 1, buf); + } +/* use CHS _bios_disk() */ + cmd.sector = (unsigned)(lba % disk->sectors + 1); + cmd.head = (unsigned)((lba / disk->sectors) % disk->heads); + cmd.track = (unsigned)((lba / disk->sectors) / disk->heads); + cmd.nsectors = 1; + cmd.buffer = buf; +/* make 3 attempts */ + for(tries = 3; tries != 0; tries--) + { + err = _bios_disk(_DISK_WRITE, &cmd); + err >>= 8; +/* 0x11=="CRC/ECC corrected data error" */ + if(err == 0 || err == 0x11) + return 0; +/* reset disk */ + _bios_disk(_DISK_RESET, &cmd); + } + DEBUG(printf("write_sector(): error 0x%02X\n", err);) + return err; +} +/***************************************************************************** +*****************************************************************************/ +int is_fat_bootsector(unsigned char *buf) +{ + int temp, ok = 1; + + DEBUG(printf("check_if_fat_bootsector:\n");) +/* must start with 16-bit JMP or 8-bit JMP plus NOP */ + if(buf[0] == 0xE9) + /* OK */; + else if(buf[0] == 0xEB && buf[2] == 0x90) + /* OK */; + else + { + DEBUG(printf("\tMissing JMP/NOP\n");) + ok = 0; + } + temp = buf[13]; + if(temp == 0 || ((temp - 1) & temp) != 0) + { + DEBUG(printf("\tSectors per cluster (%u) " + "is not a power of 2\n", temp);) + ok = 0; + } + temp = buf[16]; + temp = LE16(buf + 24); + if(temp == 0 || temp > 63) + { + DEBUG(printf("\tInvalid number of sectors (%u)\n", temp);) + ok = 0; + } + temp = LE16(buf + 26); + if(temp == 0 || temp > 255) + { + DEBUG(printf("\tInvalid number of heads (%u)\n", temp);) + ok = 0; + } + return ok; +} +/***************************************************************************** +*****************************************************************************/ +static void probe_floppy_geometry(disk_t *disk) +{ + unsigned sectors, heads; + unsigned char buf[BPS]; + +/* scan upwards for sector number where read fails */ + disk->sectors = 64 + 1; + for(sectors = 1; sectors <= 64; sectors++) + { + if(read_sector(disk, sectors - 1, buf) != 0) + break; + } + disk->sectors = sectors - 1; +#if 1 +disk->heads = 2; +#else +/* scan upwards for head number where read fails +xxx - this probing for number of heads doesn't work */ + disk->heads = 16 + 1; + for(heads = 1; heads < 16; heads++) + { + if(read_sector(disk, heads * disk->sectors, buf) != 0) + break; + } + disk->heads = heads; +#endif +/* reset drive by reading sector 0 */ + (void)read_sector(disk, 0, buf); + DEBUG(printf("probe_floppy_geometry() for fd 0x%02X: " + "CHS=?:%u:%u\n", disk->drive_num, + disk->heads, disk->sectors);) +} +/***************************************************************************** +*****************************************************************************/ +int open_disk(disk_t *disk, unsigned drive_num) +{ + unsigned char buf[BPS]; + unsigned num_fds; + int err; + + disk->drive_num = drive_num; + disk->partition_start = 0; /* assume floppy */ + disk->use_lba = 0; /* assume CHS */ +/* hard disk */ + if(disk->drive_num >= 0x80) + return get_hd_geometry(disk); +/* make sure floppy drive exists */ + num_fds = peekw(0x40, 0x10); + if(num_fds & 0x0001) + num_fds = ((num_fds / 64) & 3) + 1; + else + num_fds = 0; + if(disk->drive_num >= num_fds) + { + printf("open_disk(): fd 0x%02X does not exist\n", + disk->drive_num); + return -1; + } +/* temporary values to make read_sector(0) work */ + disk->heads = disk->sectors = 1; + err = read_sector(disk, 0, buf); + if(err != 0) + return err; +/* if it's a FAT (DOS) disk, we get can reliable geometry info +from the BIOS parameter block (BPB) in the bootsector */ + if(is_fat_bootsector(buf)) + { + disk->heads = LE16(buf + 26); + disk->sectors = LE16(buf + 24); + DEBUG(printf("open_disk() for fd 0x%02X: " + "CHS=?:%u:%u (from BPB)\n", + disk->drive_num, + disk->heads, disk->sectors);) + return 0; + } +#if 0 +/* ...otherwise, do slow probe */ + probe_floppy_geometry(disk); +#else +/* ...or just assume some values */ + disk->heads = 2; + disk->sectors = 18; + DEBUG(printf("open_disk() for fd 0x%02X: " + "assuming CHS=?:2:18\n", disk->drive_num);) +#endif + return 0; +} diff --git a/Dump/hybos/__experimental/dos.h b/Dump/hybos/__experimental/dos.h index d604379..a7493ba 100644 --- a/Dump/hybos/__experimental/dos.h +++ b/Dump/hybos/__experimental/dos.h @@ -1,65 +1,65 @@ -/***************************************************************************** -Sector-level disk I/O code for DOS. -This code is public domain (no copyright). -You can do whatever you want with it. - -EXPORTS: -peekb(), peekw() -*****************************************************************************/ -#ifndef __DISKIO_DOS_H -#define __DISKIO_DOS_H - -#ifdef __cplusplus -extern "C" -{ -#endif - -/********************************* TURBO C **********************************/ -#if defined(__TURBOC__) -#include /* peekb(), peek() */ - -#define peekw(S,O) peek(S,O) - -/* xxx - I'm not sure of the Turbo C version where these were -introduced. They are present in Turbo C++ 3.0 (__TURBOC__ == 0x401) -but not in Turbo C++ 1.0 (__TURBOC__ == 0x296) */ -#if __TURBOC__<0x300 -#define _DISK_RESET 0 /* controller hard reset */ -#define _DISK_STATUS 1 /* status of last operation */ -#define _DISK_READ 2 /* read sectors */ -#define _DISK_WRITE 3 /* write sectors */ -#define _DISK_VERIFY 4 /* verify sectors */ -#define _DISK_FORMAT 5 /* format track */ -#endif - -/********************************* DJGPP ************************************/ -#elif defined(__DJGPP__) -#include /* _farpeek[b|w]() */ -#include /* _dos_ds */ - -#define peekb(S,O) _farpeekb(_dos_ds, 16uL * (S) + (O)) -#define peekw(S,O) _farpeekw(_dos_ds, 16uL * (S) + (O)) - -/******************************** WATCOM C **********************************/ -#elif defined(__WATCOMC__) - -#if defined(__386__) -/* CauseWay DOS extender only */ -#define peekb(S,O) *(unsigned char *)(16uL * (S) + (O)) -#define peekw(S,O) *(unsigned short *)(16uL * (S) + (O)) -#else -#include /* MK_FP() */ -#define peekb(S,O) *(unsigned char far *)MK_FP(S,O) -#define peekw(S,O) *(unsigned short far *)MK_FP(S,O) -#endif - -/****************************************************************************/ -#else -#error Not Turbo C, not DJGPP, not Watcom C. Sorry. -#endif - -#ifdef __cplusplus -} -#endif - -#endif +/***************************************************************************** +Sector-level disk I/O code for DOS. +This code is public domain (no copyright). +You can do whatever you want with it. + +EXPORTS: +peekb(), peekw() +*****************************************************************************/ +#ifndef __DISKIO_DOS_H +#define __DISKIO_DOS_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +/********************************* TURBO C **********************************/ +#if defined(__TURBOC__) +#include /* peekb(), peek() */ + +#define peekw(S,O) peek(S,O) + +/* xxx - I'm not sure of the Turbo C version where these were +introduced. They are present in Turbo C++ 3.0 (__TURBOC__ == 0x401) +but not in Turbo C++ 1.0 (__TURBOC__ == 0x296) */ +#if __TURBOC__<0x300 +#define _DISK_RESET 0 /* controller hard reset */ +#define _DISK_STATUS 1 /* status of last operation */ +#define _DISK_READ 2 /* read sectors */ +#define _DISK_WRITE 3 /* write sectors */ +#define _DISK_VERIFY 4 /* verify sectors */ +#define _DISK_FORMAT 5 /* format track */ +#endif + +/********************************* DJGPP ************************************/ +#elif defined(__DJGPP__) +#include /* _farpeek[b|w]() */ +#include /* _dos_ds */ + +#define peekb(S,O) _farpeekb(_dos_ds, 16uL * (S) + (O)) +#define peekw(S,O) _farpeekw(_dos_ds, 16uL * (S) + (O)) + +/******************************** WATCOM C **********************************/ +#elif defined(__WATCOMC__) + +#if defined(__386__) +/* CauseWay DOS extender only */ +#define peekb(S,O) *(unsigned char *)(16uL * (S) + (O)) +#define peekw(S,O) *(unsigned short *)(16uL * (S) + (O)) +#else +#include /* MK_FP() */ +#define peekb(S,O) *(unsigned char far *)MK_FP(S,O) +#define peekw(S,O) *(unsigned short far *)MK_FP(S,O) +#endif + +/****************************************************************************/ +#else +#error Not Turbo C, not DJGPP, not Watcom C. Sorry. +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/Dump/hybos/__experimental/dos16.c b/Dump/hybos/__experimental/dos16.c index d849321..0499ad2 100644 --- a/Dump/hybos/__experimental/dos16.c +++ b/Dump/hybos/__experimental/dos16.c @@ -1,114 +1,114 @@ -/***************************************************************************** -Sector-level disk I/O code for DOS, using 16-bit compiler. -This code is public domain (no copyright). -You can do whatever you want with it. - -EXPORTS: -int lba_biosdisk(int cmd, int drive, unsigned long lba, - int nsects, void *buf); -int get_hd_geometry(disk_t *disk); -*****************************************************************************/ -#include /* memset() */ -#include /* printf() */ -#include /* _DISK_... */ -/* union REGS, struct SREGS, int86(), int86x() */ -#include /* FP_SEG(), FP_OFF() */ -#include "diskio.h" -#include "dos.h" /* peekb() */ -/***************************************************************************** -*****************************************************************************/ -int lba_biosdisk(int cmd, int drive, unsigned long lba, int nsects, void *buf) -{ - struct - { - unsigned char pkt_len; - unsigned char res0; - unsigned char nsects; - unsigned char res1; - unsigned short buf_off; - unsigned short buf_seg; - unsigned long lba31_0; - unsigned long lba63_32; - } lba_cmd_pkt; - unsigned tries, err = 0; - struct SREGS sregs; - union REGS regs; - - if(cmd != _DISK_READ && cmd != _DISK_WRITE) - return 0x100; -/* make sure drive and BIOS support LBA */ - regs.x.bx = 0x55AA; - regs.h.dl = drive; - regs.h.ah = 0x41; - int86x(0x13, ®s, ®s, &sregs); - if(regs.x.cflag) - return 0x100; -/* fill out the INT 13h AH=4xh command packet */ - memset(&lba_cmd_pkt, 0, sizeof(lba_cmd_pkt)); - lba_cmd_pkt.pkt_len = sizeof(lba_cmd_pkt); - lba_cmd_pkt.nsects = nsects; - lba_cmd_pkt.buf_off = FP_OFF(buf); - lba_cmd_pkt.buf_seg = FP_SEG(buf); - lba_cmd_pkt.lba31_0 = lba; -/* fill out registers for INT 13h AH=4xh */ - sregs.ds = FP_SEG(&lba_cmd_pkt); - regs.x.si = FP_OFF(&lba_cmd_pkt); - regs.h.dl = drive; -/* make 3 attempts */ - for(tries = 3; tries != 0; tries--) - { - regs.h.ah = (cmd == _DISK_READ) ? 0x42 : 0x43; - int86x(0x13, ®s, ®s, &sregs); - err = regs.h.ah; - if(!regs.x.cflag) - return 0; -/* reset disk */ - regs.h.ah = _DISK_RESET; - int86x(0x13, ®s, ®s, &sregs); - } - DEBUG(printf("lba_biosdisk(): error 0x%02X\n", err);) - return err; -} -/***************************************************************************** -*****************************************************************************/ -int get_hd_geometry(disk_t *disk) -{ - union REGS regs; - -/* make sure hard drive exists */ - if(disk->drive_num - 0x80 >= peekb(0x40, 0x75)) - { - printf("get_hd_geometry(): hd 0x%02X does not exist\n", - disk->drive_num); - return -1; - } -/* use LBA if drive and BIOS support it */ - regs.h.ah = 0x41; - regs.x.bx = 0x55AA; - regs.h.dl = disk->drive_num; - int86(0x13, ®s, ®s); - if(!regs.x.cflag && regs.x.bx == 0xAA55) - { - disk->use_lba = 1; - DEBUG(printf("get_hd_geometry(): using LBA for hd 0x%02X\n", - disk->drive_num);) - return 0; - } -/* get geometry from BIOS */ - regs.h.ah = 0x08; - regs.h.dl = disk->drive_num; - int86(0x13, ®s, ®s); - if(regs.x.cflag) - { - printf("get_hd_geometry(): error getting geometry " - "for hard drive 0x%02X\n", disk->drive_num); - return -1; - } - disk->heads = regs.h.dh + 1; - disk->sectors = regs.h.cl & 0x3F; - DEBUG(printf("get_hd_geometry() for hd 0x%02X: " - "CHS=?:%u:%u (from INT 13h AH=08h)\n", - disk->drive_num, - disk->heads, disk->sectors);) - return 0; -} +/***************************************************************************** +Sector-level disk I/O code for DOS, using 16-bit compiler. +This code is public domain (no copyright). +You can do whatever you want with it. + +EXPORTS: +int lba_biosdisk(int cmd, int drive, unsigned long lba, + int nsects, void *buf); +int get_hd_geometry(disk_t *disk); +*****************************************************************************/ +#include /* memset() */ +#include /* printf() */ +#include /* _DISK_... */ +/* union REGS, struct SREGS, int86(), int86x() */ +#include /* FP_SEG(), FP_OFF() */ +#include "diskio.h" +#include "dos.h" /* peekb() */ +/***************************************************************************** +*****************************************************************************/ +int lba_biosdisk(int cmd, int drive, unsigned long lba, int nsects, void *buf) +{ + struct + { + unsigned char pkt_len; + unsigned char res0; + unsigned char nsects; + unsigned char res1; + unsigned short buf_off; + unsigned short buf_seg; + unsigned long lba31_0; + unsigned long lba63_32; + } lba_cmd_pkt; + unsigned tries, err = 0; + struct SREGS sregs; + union REGS regs; + + if(cmd != _DISK_READ && cmd != _DISK_WRITE) + return 0x100; +/* make sure drive and BIOS support LBA */ + regs.x.bx = 0x55AA; + regs.h.dl = drive; + regs.h.ah = 0x41; + int86x(0x13, ®s, ®s, &sregs); + if(regs.x.cflag) + return 0x100; +/* fill out the INT 13h AH=4xh command packet */ + memset(&lba_cmd_pkt, 0, sizeof(lba_cmd_pkt)); + lba_cmd_pkt.pkt_len = sizeof(lba_cmd_pkt); + lba_cmd_pkt.nsects = nsects; + lba_cmd_pkt.buf_off = FP_OFF(buf); + lba_cmd_pkt.buf_seg = FP_SEG(buf); + lba_cmd_pkt.lba31_0 = lba; +/* fill out registers for INT 13h AH=4xh */ + sregs.ds = FP_SEG(&lba_cmd_pkt); + regs.x.si = FP_OFF(&lba_cmd_pkt); + regs.h.dl = drive; +/* make 3 attempts */ + for(tries = 3; tries != 0; tries--) + { + regs.h.ah = (cmd == _DISK_READ) ? 0x42 : 0x43; + int86x(0x13, ®s, ®s, &sregs); + err = regs.h.ah; + if(!regs.x.cflag) + return 0; +/* reset disk */ + regs.h.ah = _DISK_RESET; + int86x(0x13, ®s, ®s, &sregs); + } + DEBUG(printf("lba_biosdisk(): error 0x%02X\n", err);) + return err; +} +/***************************************************************************** +*****************************************************************************/ +int get_hd_geometry(disk_t *disk) +{ + union REGS regs; + +/* make sure hard drive exists */ + if(disk->drive_num - 0x80 >= peekb(0x40, 0x75)) + { + printf("get_hd_geometry(): hd 0x%02X does not exist\n", + disk->drive_num); + return -1; + } +/* use LBA if drive and BIOS support it */ + regs.h.ah = 0x41; + regs.x.bx = 0x55AA; + regs.h.dl = disk->drive_num; + int86(0x13, ®s, ®s); + if(!regs.x.cflag && regs.x.bx == 0xAA55) + { + disk->use_lba = 1; + DEBUG(printf("get_hd_geometry(): using LBA for hd 0x%02X\n", + disk->drive_num);) + return 0; + } +/* get geometry from BIOS */ + regs.h.ah = 0x08; + regs.h.dl = disk->drive_num; + int86(0x13, ®s, ®s); + if(regs.x.cflag) + { + printf("get_hd_geometry(): error getting geometry " + "for hard drive 0x%02X\n", disk->drive_num); + return -1; + } + disk->heads = regs.h.dh + 1; + disk->sectors = regs.h.cl & 0x3F; + DEBUG(printf("get_hd_geometry() for hd 0x%02X: " + "CHS=?:%u:%u (from INT 13h AH=08h)\n", + disk->drive_num, + disk->heads, disk->sectors);) + return 0; +} diff --git a/Dump/hybos/__experimental/makefile b/Dump/hybos/__experimental/makefile index 97c6819..abe55e0 100644 --- a/Dump/hybos/__experimental/makefile +++ b/Dump/hybos/__experimental/makefile @@ -1,32 +1,32 @@ -# Makefile for Turbo C++ 1.0 -# For old Turbo MAKE 3.0, this file MUST be named 'makefile' - -# defines -# MAKEDEP =makefile -MODEL =s -CC =tcc -v -m$(MODEL) -w -O2 -d -Z -vi -1 -LIBDIR =c:\tc\lib -LD =tlink /v /x -OBJS =demo.obj dos.obj dos16.obj - -# targets -all: diskio.exe - -clean: - deltree /y *.exe *.obj *.o *.err - -# implicit rules -.c.obj: - $(CC) -c -o$*.obj $< - -# dependencies -demo.o: demo.c $(MAKEDEP) diskio.h - -dos.o: dos.c $(MAKEDEP) diskio.h dos.h - -dos16.o: dos16.c $(MAKEDEP) diskio.h dos.h - -# explicit rules -diskio.exe: $(OBJS) $(MAKEDEP) - $(LD) $(LIBDIR)\c0$(MODEL).obj $(OBJS),$.,,$(LIBDIR)\c$(MODEL).lib - +# Makefile for Turbo C++ 1.0 +# For old Turbo MAKE 3.0, this file MUST be named 'makefile' + +# defines +# MAKEDEP =makefile +MODEL =s +CC =tcc -v -m$(MODEL) -w -O2 -d -Z -vi -1 +LIBDIR =c:\tc\lib +LD =tlink /v /x +OBJS =demo.obj dos.obj dos16.obj + +# targets +all: diskio.exe + +clean: + deltree /y *.exe *.obj *.o *.err + +# implicit rules +.c.obj: + $(CC) -c -o$*.obj $< + +# dependencies +demo.o: demo.c $(MAKEDEP) diskio.h + +dos.o: dos.c $(MAKEDEP) diskio.h dos.h + +dos16.o: dos16.c $(MAKEDEP) diskio.h dos.h + +# explicit rules +diskio.exe: $(OBJS) $(MAKEDEP) + $(LD) $(LIBDIR)\c0$(MODEL).obj $(OBJS),$.,,$(LIBDIR)\c$(MODEL).lib + diff --git a/Dump/hybos/__experimental/watcom16.mak b/Dump/hybos/__experimental/watcom16.mak index 0c61cc3..56693c3 100644 --- a/Dump/hybos/__experimental/watcom16.mak +++ b/Dump/hybos/__experimental/watcom16.mak @@ -1,28 +1,28 @@ -# Makefile for DOS - Watcom C - -# defines -# MAKEDEP =watcom16.mak -CC =wcc -3 -s -d2 -hw -ox -w=9 -zc -ms -OBJS =demo.obj dos.obj dos16.obj - -# targets -all: diskio.exe - -clean: - deltree /y *.exe *.obj *.o *.err - -# implicit rules -.c.obj: - $(CC) -fo=$@ $[. - -# dependencies -demo.o: demo.c $(MAKEDEP) diskio.h - -dos.o: dos.c $(MAKEDEP) diskio.h dos.h - -dos16.o: dos16.c $(MAKEDEP) diskio.h dos.h - -# explicit rules -diskio.exe: $(OBJS) $(MAKEDEP) - wlink D W A SYSTEM dos NAME $@ FILE demo.obj FILE dos.obj FILE dos16.obj - +# Makefile for DOS - Watcom C + +# defines +# MAKEDEP =watcom16.mak +CC =wcc -3 -s -d2 -hw -ox -w=9 -zc -ms +OBJS =demo.obj dos.obj dos16.obj + +# targets +all: diskio.exe + +clean: + deltree /y *.exe *.obj *.o *.err + +# implicit rules +.c.obj: + $(CC) -fo=$@ $[. + +# dependencies +demo.o: demo.c $(MAKEDEP) diskio.h + +dos.o: dos.c $(MAKEDEP) diskio.h dos.h + +dos16.o: dos16.c $(MAKEDEP) diskio.h dos.h + +# explicit rules +diskio.exe: $(OBJS) $(MAKEDEP) + wlink D W A SYSTEM dos NAME $@ FILE demo.obj FILE dos.obj FILE dos16.obj + diff --git a/Dump/hybos/__experimental/watcom32.c b/Dump/hybos/__experimental/watcom32.c index 978b34e..921a8af 100644 --- a/Dump/hybos/__experimental/watcom32.c +++ b/Dump/hybos/__experimental/watcom32.c @@ -1,117 +1,117 @@ -/***************************************************************************** -Sector-level disk I/O code for DOS, using 32-bit Watcom C -with CauseWay DOS extender. -This code is public domain (no copyright). -You can do whatever you want with it. - -xxx - This code doesn't work - -EXPORTS: -int lba_biosdisk(int cmd, int drive, unsigned long lba, - int nsects, void *buf); -int get_hd_geometry(disk_t *disk); -*****************************************************************************/ -#include /* memset() */ -#include /* printf() */ -#include /* _DISK_... */ -/* union REGS, struct SREGS, int386(), int386x() */ -#include /* FP_SEG(), FP_OFF() */ -#include "diskio.h" -#include "dos.h" /* peekb() */ -/***************************************************************************** -*****************************************************************************/ -int lba_biosdisk(int cmd, int drive, unsigned long lba, int nsects, void *buf) -{ - struct - { - unsigned char pkt_len; - unsigned char res0; - unsigned char nsects; - unsigned char res1; - unsigned short buf_off; - unsigned short buf_seg; - unsigned long lba31_0; - unsigned long lba63_32; - } lba_cmd_pkt; - unsigned tries, err = 0; - struct SREGS sregs; - union REGS regs; - - if(cmd != _DISK_READ && cmd != _DISK_WRITE) - return 0x100; -/* make sure drive and BIOS support LBA */ - regs.w.bx = 0x55AA; - regs.h.dl = drive; - regs.h.ah = 0x41; - int386x(0x13, ®s, ®s, &sregs); - if(regs.w.cflag) - return 0x100; -/* fill out the INT 13h AH=4xh command packet */ - memset(&lba_cmd_pkt, 0, sizeof(lba_cmd_pkt)); - lba_cmd_pkt.pkt_len = sizeof(lba_cmd_pkt); - lba_cmd_pkt.nsects = nsects; - lba_cmd_pkt.buf_off = FP_OFF(buf); - lba_cmd_pkt.buf_seg = FP_SEG(buf); - lba_cmd_pkt.lba31_0 = lba; -/* fill out registers for INT 13h AH=4xh */ - sregs.ds = FP_SEG(&lba_cmd_pkt); - regs.w.si = FP_OFF(&lba_cmd_pkt); - regs.h.dl = drive; -/* make 3 attempts */ - for(tries = 3; tries != 0; tries--) - { - regs.h.ah = (cmd == _DISK_READ) ? 0x42 : 0x43; - int386x(0x13, ®s, ®s, &sregs); - err = regs.h.ah; - if(!regs.w.cflag) - return 0; -/* reset disk */ - regs.h.ah = _DISK_RESET; - int386x(0x13, ®s, ®s, &sregs); - } - DEBUG(printf("lba_biosdisk(): error 0x%02X\n", err);) - return err; -} -/***************************************************************************** -*****************************************************************************/ -int get_hd_geometry(disk_t *disk) -{ - union REGS regs; - -/* make sure hard drive exists */ - if(disk->drive_num - 0x80 >= peekb(0x40, 0x75)) - { - printf("get_hd_geometry(): hd 0x%02X does not exist\n", - disk->drive_num); - return -1; - } -/* use LBA if drive and BIOS support it */ - regs.h.ah = 0x41; - regs.w.bx = 0x55AA; - regs.h.dl = disk->drive_num; - int386(0x13, ®s, ®s); - if(!regs.w.cflag && regs.w.bx == 0xAA55) - { - disk->use_lba = 1; - DEBUG(printf("get_hd_geometry(): using LBA for hd 0x%02X\n", - disk->drive_num);) - return 0; - } -/* get geometry from BIOS */ - regs.h.ah = 0x08; - regs.h.dl = disk->drive_num; - int386(0x13, ®s, ®s); - if(!regs.w.cflag) - { - printf("get_hd_geometry(): error getting geometry " - "for hard drive 0x%02X\n", disk->drive_num); - return -1; - } - disk->heads = regs.h.dh + 1; - disk->sectors = regs.h.cl & 0x3F; - DEBUG(printf("get_hd_geometry() for hd 0x%02X: " - "CHS=?:%u:%u (from INT 13h AH=08h)\n", - disk->drive_num, - disk->heads, disk->sectors);) - return 0; -} +/***************************************************************************** +Sector-level disk I/O code for DOS, using 32-bit Watcom C +with CauseWay DOS extender. +This code is public domain (no copyright). +You can do whatever you want with it. + +xxx - This code doesn't work + +EXPORTS: +int lba_biosdisk(int cmd, int drive, unsigned long lba, + int nsects, void *buf); +int get_hd_geometry(disk_t *disk); +*****************************************************************************/ +#include /* memset() */ +#include /* printf() */ +#include /* _DISK_... */ +/* union REGS, struct SREGS, int386(), int386x() */ +#include /* FP_SEG(), FP_OFF() */ +#include "diskio.h" +#include "dos.h" /* peekb() */ +/***************************************************************************** +*****************************************************************************/ +int lba_biosdisk(int cmd, int drive, unsigned long lba, int nsects, void *buf) +{ + struct + { + unsigned char pkt_len; + unsigned char res0; + unsigned char nsects; + unsigned char res1; + unsigned short buf_off; + unsigned short buf_seg; + unsigned long lba31_0; + unsigned long lba63_32; + } lba_cmd_pkt; + unsigned tries, err = 0; + struct SREGS sregs; + union REGS regs; + + if(cmd != _DISK_READ && cmd != _DISK_WRITE) + return 0x100; +/* make sure drive and BIOS support LBA */ + regs.w.bx = 0x55AA; + regs.h.dl = drive; + regs.h.ah = 0x41; + int386x(0x13, ®s, ®s, &sregs); + if(regs.w.cflag) + return 0x100; +/* fill out the INT 13h AH=4xh command packet */ + memset(&lba_cmd_pkt, 0, sizeof(lba_cmd_pkt)); + lba_cmd_pkt.pkt_len = sizeof(lba_cmd_pkt); + lba_cmd_pkt.nsects = nsects; + lba_cmd_pkt.buf_off = FP_OFF(buf); + lba_cmd_pkt.buf_seg = FP_SEG(buf); + lba_cmd_pkt.lba31_0 = lba; +/* fill out registers for INT 13h AH=4xh */ + sregs.ds = FP_SEG(&lba_cmd_pkt); + regs.w.si = FP_OFF(&lba_cmd_pkt); + regs.h.dl = drive; +/* make 3 attempts */ + for(tries = 3; tries != 0; tries--) + { + regs.h.ah = (cmd == _DISK_READ) ? 0x42 : 0x43; + int386x(0x13, ®s, ®s, &sregs); + err = regs.h.ah; + if(!regs.w.cflag) + return 0; +/* reset disk */ + regs.h.ah = _DISK_RESET; + int386x(0x13, ®s, ®s, &sregs); + } + DEBUG(printf("lba_biosdisk(): error 0x%02X\n", err);) + return err; +} +/***************************************************************************** +*****************************************************************************/ +int get_hd_geometry(disk_t *disk) +{ + union REGS regs; + +/* make sure hard drive exists */ + if(disk->drive_num - 0x80 >= peekb(0x40, 0x75)) + { + printf("get_hd_geometry(): hd 0x%02X does not exist\n", + disk->drive_num); + return -1; + } +/* use LBA if drive and BIOS support it */ + regs.h.ah = 0x41; + regs.w.bx = 0x55AA; + regs.h.dl = disk->drive_num; + int386(0x13, ®s, ®s); + if(!regs.w.cflag && regs.w.bx == 0xAA55) + { + disk->use_lba = 1; + DEBUG(printf("get_hd_geometry(): using LBA for hd 0x%02X\n", + disk->drive_num);) + return 0; + } +/* get geometry from BIOS */ + regs.h.ah = 0x08; + regs.h.dl = disk->drive_num; + int386(0x13, ®s, ®s); + if(!regs.w.cflag) + { + printf("get_hd_geometry(): error getting geometry " + "for hard drive 0x%02X\n", disk->drive_num); + return -1; + } + disk->heads = regs.h.dh + 1; + disk->sectors = regs.h.cl & 0x3F; + DEBUG(printf("get_hd_geometry() for hd 0x%02X: " + "CHS=?:%u:%u (from INT 13h AH=08h)\n", + disk->drive_num, + disk->heads, disk->sectors);) + return 0; +} diff --git a/Dump/hybos/__experimental/watcom32.mak b/Dump/hybos/__experimental/watcom32.mak index f5164c6..842bda8 100644 --- a/Dump/hybos/__experimental/watcom32.mak +++ b/Dump/hybos/__experimental/watcom32.mak @@ -1,30 +1,30 @@ -# Makefile for 32-bit DOS - Watcom C -# (using CauseWay DOS extender) -# xxx - the resulting DISKIO.EXE doesn't work (!) - -# defines -# MAKEDEP =watcom32.mak -CC =wcc386 -3 -s -d2 -hw -ox -w=9 -zc -mf -OBJS =demo.obj dos.obj watcom32.obj - -# targets -all: diskio.exe - -clean: - deltree /y *.exe *.obj *.o *.err - -# implicit rules -.c.obj: - $(CC) -fo=$@ $[. - -# dependencies -demo.o: demo.c $(MAKEDEP) diskio.h - -dos.o: dos.c $(MAKEDEP) diskio.h dos.h - -watcom32.o: watcom32.c $(MAKEDEP) diskio.h dos.h - -# explicit rules -diskio.exe: $(OBJS) $(MAKEDEP) - wlink D W A SYSTEM causeway NAME $@ FILE demo.obj FILE dos.obj FILE watcom32.obj - +# Makefile for 32-bit DOS - Watcom C +# (using CauseWay DOS extender) +# xxx - the resulting DISKIO.EXE doesn't work (!) + +# defines +# MAKEDEP =watcom32.mak +CC =wcc386 -3 -s -d2 -hw -ox -w=9 -zc -mf +OBJS =demo.obj dos.obj watcom32.obj + +# targets +all: diskio.exe + +clean: + deltree /y *.exe *.obj *.o *.err + +# implicit rules +.c.obj: + $(CC) -fo=$@ $[. + +# dependencies +demo.o: demo.c $(MAKEDEP) diskio.h + +dos.o: dos.c $(MAKEDEP) diskio.h dos.h + +watcom32.o: watcom32.c $(MAKEDEP) diskio.h dos.h + +# explicit rules +diskio.exe: $(OBJS) $(MAKEDEP) + wlink D W A SYSTEM causeway NAME $@ FILE demo.obj FILE dos.obj FILE watcom32.obj + diff --git a/Dump/hybos/__experimental/win-nt.c b/Dump/hybos/__experimental/win-nt.c index 6d97a0c..d8705c3 100644 --- a/Dump/hybos/__experimental/win-nt.c +++ b/Dump/hybos/__experimental/win-nt.c @@ -1,125 +1,125 @@ -/***************************************************************************** -Sector-level disk I/O code for Windows NT. -This code is public domain (no copyright). -You can do whatever you want with it. - -EXPORTS: -int read_sector(disk_t *disk, unsigned long lba, unsigned char *buf); -int open_disk(disk_t *disk, unsigned drive_num); -int is_fat_bootsector(unsigned char *buf); - -Tim Robinson helped with this code. -(Bugs are due to Giese :) -*****************************************************************************/ -#include -/* FILE, fopen(), setvbuf(), fseek(), fread(), fclose(), printf(), sprintf() */ -#include -#include "diskio.h" -/***************************************************************************** -*****************************************************************************/ -static FILE *do_open(unsigned drive_num) -{ - char dev_name[64]; - FILE *f; - -/* form internal drive name */ - if(drive_num < 0x80) - sprintf(dev_name, "\\\\.\\%c:", drive_num + 'A'); - else - sprintf(dev_name, "\\\\.\\PhysicalDrive%u", - drive_num - 0x80); -/* open the drive */ - f = fopen(dev_name, "r+b"); - if(f == NULL) - printf("do_open(): drive 0x%02X (%s) does not exist\n", - drive_num, dev_name); - return f; -} -/***************************************************************************** -*****************************************************************************/ -int read_sector(disk_t *disk, unsigned long lba, unsigned char *buf) -{ - unsigned err; - FILE *f; - - lba += disk->partition_start; - f = do_open(disk->drive_num); - if(f == NULL) - return -1; -/* seek, read, close */ - setvbuf(f, NULL, _IOFBF, BPS); - fseek(f, lba * BPS, SEEK_SET); - err = fread(buf, 1, BPS, f); - fclose(f); - return (err == BPS) ? 0 : -1; -} -/***************************************************************************** -*****************************************************************************/ -int open_disk(disk_t *disk, unsigned drive_num) -{ - OSVERSIONINFO win_version; - unsigned char buf[BPS]; - unsigned err = 0; - FILE *f; - -/* check for NT */ - win_version.dwOSVersionInfoSize = sizeof(win_version); - GetVersionEx(&win_version); - if(win_version.dwPlatformId != VER_PLATFORM_WIN32_NT) - { - printf("Sorry, Windows NT required\n" - "Windows 9x users should use the " - "DOS version of this program\n\n"); - return -1; - } - disk->drive_num = drive_num; - disk->partition_start = 0; /* assume floppy */ - disk->use_lba = 0; /* assume CHS */ -/* open the drive, to make sure it exists */ - f = do_open(disk->drive_num); - if(f == NULL) - return -1; - fclose(f); -/* no CHS geometry - NT uses LBA for everything */ - return 0; -} -/***************************************************************************** -is_fat_bootsector() is not used in this file, but still used in DEMO.C -*****************************************************************************/ -int is_fat_bootsector(unsigned char *buf) -{ - int temp, ok = 1; - - DEBUG(printf("check_if_fat_bootsector:\n");) -/* must start with 16-bit JMP or 8-bit JMP plus NOP */ - if(buf[0] == 0xE9) - /* OK */; - else if(buf[0] == 0xEB && buf[2] == 0x90) - /* OK */; - else - { - DEBUG(printf("\tMissing JMP/NOP\n");) - ok = 0; - } - temp = buf[13]; - if(temp == 0 || ((temp - 1) & temp) != 0) - { - DEBUG(printf("\tSectors per cluster (%u) " - "is not a power of 2\n", temp);) - ok = 0; - } - temp = buf[16]; - temp = LE16(buf + 24); - if(temp == 0 || temp > 63) - { - DEBUG(printf("\tInvalid number of sectors (%u)\n", temp);) - ok = 0; - } - temp = LE16(buf + 26); - if(temp == 0 || temp > 255) - { - DEBUG(printf("\tInvalid number of heads (%u)\n", temp);) - ok = 0; - } - return ok; -} +/***************************************************************************** +Sector-level disk I/O code for Windows NT. +This code is public domain (no copyright). +You can do whatever you want with it. + +EXPORTS: +int read_sector(disk_t *disk, unsigned long lba, unsigned char *buf); +int open_disk(disk_t *disk, unsigned drive_num); +int is_fat_bootsector(unsigned char *buf); + +Tim Robinson helped with this code. +(Bugs are due to Giese :) +*****************************************************************************/ +#include +/* FILE, fopen(), setvbuf(), fseek(), fread(), fclose(), printf(), sprintf() */ +#include +#include "diskio.h" +/***************************************************************************** +*****************************************************************************/ +static FILE *do_open(unsigned drive_num) +{ + char dev_name[64]; + FILE *f; + +/* form internal drive name */ + if(drive_num < 0x80) + sprintf(dev_name, "\\\\.\\%c:", drive_num + 'A'); + else + sprintf(dev_name, "\\\\.\\PhysicalDrive%u", + drive_num - 0x80); +/* open the drive */ + f = fopen(dev_name, "r+b"); + if(f == NULL) + printf("do_open(): drive 0x%02X (%s) does not exist\n", + drive_num, dev_name); + return f; +} +/***************************************************************************** +*****************************************************************************/ +int read_sector(disk_t *disk, unsigned long lba, unsigned char *buf) +{ + unsigned err; + FILE *f; + + lba += disk->partition_start; + f = do_open(disk->drive_num); + if(f == NULL) + return -1; +/* seek, read, close */ + setvbuf(f, NULL, _IOFBF, BPS); + fseek(f, lba * BPS, SEEK_SET); + err = fread(buf, 1, BPS, f); + fclose(f); + return (err == BPS) ? 0 : -1; +} +/***************************************************************************** +*****************************************************************************/ +int open_disk(disk_t *disk, unsigned drive_num) +{ + OSVERSIONINFO win_version; + unsigned char buf[BPS]; + unsigned err = 0; + FILE *f; + +/* check for NT */ + win_version.dwOSVersionInfoSize = sizeof(win_version); + GetVersionEx(&win_version); + if(win_version.dwPlatformId != VER_PLATFORM_WIN32_NT) + { + printf("Sorry, Windows NT required\n" + "Windows 9x users should use the " + "DOS version of this program\n\n"); + return -1; + } + disk->drive_num = drive_num; + disk->partition_start = 0; /* assume floppy */ + disk->use_lba = 0; /* assume CHS */ +/* open the drive, to make sure it exists */ + f = do_open(disk->drive_num); + if(f == NULL) + return -1; + fclose(f); +/* no CHS geometry - NT uses LBA for everything */ + return 0; +} +/***************************************************************************** +is_fat_bootsector() is not used in this file, but still used in DEMO.C +*****************************************************************************/ +int is_fat_bootsector(unsigned char *buf) +{ + int temp, ok = 1; + + DEBUG(printf("check_if_fat_bootsector:\n");) +/* must start with 16-bit JMP or 8-bit JMP plus NOP */ + if(buf[0] == 0xE9) + /* OK */; + else if(buf[0] == 0xEB && buf[2] == 0x90) + /* OK */; + else + { + DEBUG(printf("\tMissing JMP/NOP\n");) + ok = 0; + } + temp = buf[13]; + if(temp == 0 || ((temp - 1) & temp) != 0) + { + DEBUG(printf("\tSectors per cluster (%u) " + "is not a power of 2\n", temp);) + ok = 0; + } + temp = buf[16]; + temp = LE16(buf + 24); + if(temp == 0 || temp > 63) + { + DEBUG(printf("\tInvalid number of sectors (%u)\n", temp);) + ok = 0; + } + temp = LE16(buf + 26); + if(temp == 0 || temp > 255) + { + DEBUG(printf("\tInvalid number of heads (%u)\n", temp);) + ok = 0; + } + return ok; +} diff --git a/Dump/hybos/__experimental/win-nt.mak b/Dump/hybos/__experimental/win-nt.mak index c43eb97..e647cc5 100644 --- a/Dump/hybos/__experimental/win-nt.mak +++ b/Dump/hybos/__experimental/win-nt.mak @@ -1,26 +1,26 @@ -# Makefile for Windows NT - MinGW/CygWin - -# defines -# MAKEDEP =makefile -CC =gcc -g -O2 -Wall -W -LD =gcc -g -OBJS =demo.o win-nt.o - -# targets -all: diskio.exe - -clean: - deltree /y *.exe *.obj *.o *.err - -# implicit rules -.c.o: - $(CC) -c -o$@ $< - -# dependencies -demo.o: demo.c $(MAKEDEP) diskio.h - -win-nt.o: win-nt.c $(MAKEDEP) diskio.h - -# explicit rules -diskio.exe: $(OBJS) $(MAKEDEP) - $(LD) -o$@ $(OBJS) +# Makefile for Windows NT - MinGW/CygWin + +# defines +# MAKEDEP =makefile +CC =gcc -g -O2 -Wall -W +LD =gcc -g +OBJS =demo.o win-nt.o + +# targets +all: diskio.exe + +clean: + deltree /y *.exe *.obj *.o *.err + +# implicit rules +.c.o: + $(CC) -c -o$@ $< + +# dependencies +demo.o: demo.c $(MAKEDEP) diskio.h + +win-nt.o: win-nt.c $(MAKEDEP) diskio.h + +# explicit rules +diskio.exe: $(OBJS) $(MAKEDEP) + $(LD) -o$@ $(OBJS) diff --git a/Dump/hybos/boot/grub/mbchk.c b/Dump/hybos/boot/grub/mbchk.c index fcb2485..f0ae915 100644 --- a/Dump/hybos/boot/grub/mbchk.c +++ b/Dump/hybos/boot/grub/mbchk.c @@ -1,166 +1,166 @@ -/***************************************************************************** -This was lifted from the GRUB source code. -GRUB is available under the GNU general public license from - http://www.gnu.org/software/grub - ftp://alpha.gnu.org/gnu/grub -*****************************************************************************/ -#include "mltiboot.h" -#include - -static int quiet; -/***************************************************************************** -*****************************************************************************/ -static int -check_multiboot (const char *filename, FILE *fp) -{ - multiboot_header_t *mbh = 0; - int i; - char buf[8192]; - - if (fread (buf, 1, 8192, fp) < 0) - { - fprintf (stderr, "%s: Read error.\n", filename); - return 0; - } - - for (i = 0; i < 8192 - sizeof (multiboot_header_t); i++) - { - unsigned long magic = *((unsigned long *) (buf + i)); - - if (magic == MULTIBOOT_HEADER_MAGIC) - { - mbh = (multiboot_header_t *) (buf + i); - break; - } - } - - if (! mbh) - { - fprintf (stderr, "%s: No Multiboot header.\n", filename); - return 0; - } - - if (! quiet) - printf ("%s: The Multiboot header is found at the offset %d.\n", - filename, i); - - /* Check for the checksum. */ - if (mbh->magic + mbh->flags + mbh->checksum != 0) - { - fprintf (stderr, - "%s: Bad checksum (0x%lx).\n", - filename, mbh->checksum); - return 0; - } - - /* Reserved flags must be zero. */ - if (mbh->flags & ~0x00010003) - { - fprintf (stderr, - "%s: Non-zero is found in reserved flags (0x%lx).\n", - filename, mbh->flags); - return 0; - } - - if (! quiet) - { - printf ("%s: Page alignment is turned %s.\n", - filename, (mbh->flags & 0x1)? "on" : "off"); - printf ("%s: Memory information is turned %s.\n", - filename, (mbh->flags & 0x2)? "on" : "off"); - printf ("%s: Address fields is turned %s.\n", - filename, (mbh->flags & 0x10000)? "on" : "off"); - } - - /* Check for the address fields. */ - if (mbh->flags & 0x10000) - { - -printf("header_addr = 0x%lX\n", mbh->header_addr); -printf("load_addr = 0x%lX\n", mbh->load_addr); -printf("load_end_addr = 0x%lX\n", mbh->load_end_addr); -printf("bss_end_addr = 0x%lX\n", mbh->bss_end_addr); -printf("entry_addr = 0x%lX\n", mbh->entry_addr); - - if (mbh->header_addr < mbh->load_addr) - { - fprintf (stderr, - "%s: header_addr is less than " - "load_addr (0x%lx > 0x%lx).\n", - filename, mbh->header_addr, mbh->load_addr); - return 0; - } - - if (mbh->load_addr >= mbh->load_end_addr) - { - fprintf (stderr, - "%s: load_addr is not less than load_end_addr" - " (0x%lx >= 0x%lx).\n", - filename, mbh->load_addr, mbh->load_end_addr); - return 0; - } - - if (mbh->load_end_addr > mbh->bss_end_addr) - { - fprintf (stderr, - "%s: load_end_addr is greater than bss_end_addr" - " (0x%lx > 0x%lx).\n", - filename, mbh->load_end_addr, mbh->bss_end_addr); - return 0; - } - - if (mbh->load_addr > mbh->entry_addr) - { - fprintf (stderr, - "%s: load_addr is greater than entry_addr" - " (0x%lx > 0x%lx).\n", - filename, mbh->load_addr, mbh->entry_addr); - return 0; - } - - if (mbh->load_end_addr <= mbh->entry_addr) - { - fprintf (stderr, - "%s: load_end_addr is not less than entry_addr" - " (0x%lx <= 0x%lx).\n", - filename, mbh->load_end_addr, mbh->entry_addr); - return 0; - } - - /* This is a GRUB-specific limitation. */ - if (mbh->load_addr < 0x100000) - { - fprintf (stderr, - "%s: Cannot be loaded at less than 1MB by GRUB" - " (0x%lx).\n", - filename, mbh->load_addr); - return 0; - } - } - - if (! quiet) - printf ("%s: All checks passed.\n", filename); - - return 1; -} -/***************************************************************************** -*****************************************************************************/ -int main(unsigned arg_c, char *arg_v[]) -{ - FILE *file; - - if(arg_c < 2) - { - printf("Checks if file is Multiboot compatible\n"); - return 1; - } - file = fopen(arg_v[1], "rb"); - if(file == NULL) - { - printf("Can't open file '%s'\n", arg_v[1]); - return 2; - } - check_multiboot(arg_v[1], file); - fclose(file); - return 0; -} +/***************************************************************************** +This was lifted from the GRUB source code. +GRUB is available under the GNU general public license from + http://www.gnu.org/software/grub + ftp://alpha.gnu.org/gnu/grub +*****************************************************************************/ +#include "mltiboot.h" +#include + +static int quiet; +/***************************************************************************** +*****************************************************************************/ +static int +check_multiboot (const char *filename, FILE *fp) +{ + multiboot_header_t *mbh = 0; + int i; + char buf[8192]; + + if (fread (buf, 1, 8192, fp) < 0) + { + fprintf (stderr, "%s: Read error.\n", filename); + return 0; + } + + for (i = 0; i < 8192 - sizeof (multiboot_header_t); i++) + { + unsigned long magic = *((unsigned long *) (buf + i)); + + if (magic == MULTIBOOT_HEADER_MAGIC) + { + mbh = (multiboot_header_t *) (buf + i); + break; + } + } + + if (! mbh) + { + fprintf (stderr, "%s: No Multiboot header.\n", filename); + return 0; + } + + if (! quiet) + printf ("%s: The Multiboot header is found at the offset %d.\n", + filename, i); + + /* Check for the checksum. */ + if (mbh->magic + mbh->flags + mbh->checksum != 0) + { + fprintf (stderr, + "%s: Bad checksum (0x%lx).\n", + filename, mbh->checksum); + return 0; + } + + /* Reserved flags must be zero. */ + if (mbh->flags & ~0x00010003) + { + fprintf (stderr, + "%s: Non-zero is found in reserved flags (0x%lx).\n", + filename, mbh->flags); + return 0; + } + + if (! quiet) + { + printf ("%s: Page alignment is turned %s.\n", + filename, (mbh->flags & 0x1)? "on" : "off"); + printf ("%s: Memory information is turned %s.\n", + filename, (mbh->flags & 0x2)? "on" : "off"); + printf ("%s: Address fields is turned %s.\n", + filename, (mbh->flags & 0x10000)? "on" : "off"); + } + + /* Check for the address fields. */ + if (mbh->flags & 0x10000) + { + +printf("header_addr = 0x%lX\n", mbh->header_addr); +printf("load_addr = 0x%lX\n", mbh->load_addr); +printf("load_end_addr = 0x%lX\n", mbh->load_end_addr); +printf("bss_end_addr = 0x%lX\n", mbh->bss_end_addr); +printf("entry_addr = 0x%lX\n", mbh->entry_addr); + + if (mbh->header_addr < mbh->load_addr) + { + fprintf (stderr, + "%s: header_addr is less than " + "load_addr (0x%lx > 0x%lx).\n", + filename, mbh->header_addr, mbh->load_addr); + return 0; + } + + if (mbh->load_addr >= mbh->load_end_addr) + { + fprintf (stderr, + "%s: load_addr is not less than load_end_addr" + " (0x%lx >= 0x%lx).\n", + filename, mbh->load_addr, mbh->load_end_addr); + return 0; + } + + if (mbh->load_end_addr > mbh->bss_end_addr) + { + fprintf (stderr, + "%s: load_end_addr is greater than bss_end_addr" + " (0x%lx > 0x%lx).\n", + filename, mbh->load_end_addr, mbh->bss_end_addr); + return 0; + } + + if (mbh->load_addr > mbh->entry_addr) + { + fprintf (stderr, + "%s: load_addr is greater than entry_addr" + " (0x%lx > 0x%lx).\n", + filename, mbh->load_addr, mbh->entry_addr); + return 0; + } + + if (mbh->load_end_addr <= mbh->entry_addr) + { + fprintf (stderr, + "%s: load_end_addr is not less than entry_addr" + " (0x%lx <= 0x%lx).\n", + filename, mbh->load_end_addr, mbh->entry_addr); + return 0; + } + + /* This is a GRUB-specific limitation. */ + if (mbh->load_addr < 0x100000) + { + fprintf (stderr, + "%s: Cannot be loaded at less than 1MB by GRUB" + " (0x%lx).\n", + filename, mbh->load_addr); + return 0; + } + } + + if (! quiet) + printf ("%s: All checks passed.\n", filename); + + return 1; +} +/***************************************************************************** +*****************************************************************************/ +int main(unsigned arg_c, char *arg_v[]) +{ + FILE *file; + + if(arg_c < 2) + { + printf("Checks if file is Multiboot compatible\n"); + return 1; + } + file = fopen(arg_v[1], "rb"); + if(file == NULL) + { + printf("Can't open file '%s'\n", arg_v[1]); + return 2; + } + check_multiboot(arg_v[1], file); + fclose(file); + return 0; +} diff --git a/Dump/hybos/boot/grub/menu.lst b/Dump/hybos/boot/grub/menu.lst index 3f86aa1..ea308ac 100644 --- a/Dump/hybos/boot/grub/menu.lst +++ b/Dump/hybos/boot/grub/menu.lst @@ -1,39 +1,39 @@ -# boot the first entry by default -# default 0 -# if there's a problem booting the default entry, boot the second entry -# fallback 1 -# boot default after 30 sec -# timeout 30 - -title OSD 3 - root (fd0) - kernel /osd3.x - -title OSD 4 - root (fd0) - kernel /osd4.x - -title OSD 5 - root (fd0) - kernel /osd5.x - -title OSD 6 - root (fd0) - kernel /osd6.x - -title OSD 7 - root (fd0) - kernel /osd7.x - -title OSD 8 - root (fd0) - kernel /osd8.x - -title OSD 9 - root (fd0) - kernel /osd9.x - -title Boot from C: drive - root (hd0,1) - makeactive - chainloader +1 +# boot the first entry by default +# default 0 +# if there's a problem booting the default entry, boot the second entry +# fallback 1 +# boot default after 30 sec +# timeout 30 + +title OSD 3 + root (fd0) + kernel /osd3.x + +title OSD 4 + root (fd0) + kernel /osd4.x + +title OSD 5 + root (fd0) + kernel /osd5.x + +title OSD 6 + root (fd0) + kernel /osd6.x + +title OSD 7 + root (fd0) + kernel /osd7.x + +title OSD 8 + root (fd0) + kernel /osd8.x + +title OSD 9 + root (fd0) + kernel /osd9.x + +title Boot from C: drive + root (hd0,1) + makeactive + chainloader +1 diff --git a/Dump/hybos/boot/grub/mltiboot.h b/Dump/hybos/boot/grub/mltiboot.h index 6c2efdb..f8afac9 100644 --- a/Dump/hybos/boot/grub/mltiboot.h +++ b/Dump/hybos/boot/grub/mltiboot.h @@ -1,115 +1,115 @@ -/* multiboot.h - the header for Multiboot */ -/* Copyright (C) 1999 Free Software Foundation, Inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -/* Macros. */ - -/* The magic number for the Multiboot header. */ -#define MULTIBOOT_HEADER_MAGIC 0x1BADB002 - -/* The flags for the Multiboot header. */ -#define MULTIBOOT_HEADER_FLAGS 0x00010003 - -/* The magic number passed by a Multiboot-compliant boot loader. */ -#define MULTIBOOT_BOOTLOADER_MAGIC 0x2BADB002 - -/* The size of our stack (16KB). */ -#define STACK_SIZE 0x4000 - -/* C symbol format. HAVE_ASM_USCORE is defined by configure. */ -#ifdef HAVE_ASM_USCORE -# define EXT_C(sym) _ ## sym -#else -# define EXT_C(sym) sym -#endif - -#ifndef ASM -/* Do not include here in boot.S. */ - -/* Types. */ - -/* The Multiboot header. */ -typedef struct multiboot_header -{ - unsigned long magic; - unsigned long flags; - unsigned long checksum; - unsigned long header_addr; - unsigned long load_addr; - unsigned long load_end_addr; - unsigned long bss_end_addr; - unsigned long entry_addr; -} multiboot_header_t; - -/* The symbol table for a.out. */ -typedef struct aout_symbol_table -{ - unsigned long tabsize; - unsigned long strsize; - unsigned long addr; - unsigned long reserved; -} aout_symbol_table_t; - -/* The section header table for ELF. */ -typedef struct elf_section_header_table -{ - unsigned long num; - unsigned long size; - unsigned long addr; - unsigned long shndx; -} elf_section_header_table_t; - -/* The Multiboot information. */ -typedef struct multiboot_info -{ - unsigned long flags; - unsigned long mem_lower; - unsigned long mem_upper; - unsigned long boot_device; - unsigned long cmdline; - unsigned long mods_count; - unsigned long mods_addr; - union - { - aout_symbol_table_t aout_sym; - elf_section_header_table_t elf_sec; - } u; - unsigned long mmap_length; - unsigned long mmap_addr; -} multiboot_info_t; - -/* The module structure. */ -typedef struct module -{ - unsigned long mod_start; - unsigned long mod_end; - unsigned long string; - unsigned long reserved; -} module_t; - -/* The memory map. Be careful that the offset 0 is base_addr_low - but no size. */ -typedef struct memory_map -{ - unsigned long size; - unsigned long base_addr_low; - unsigned long base_addr_high; - unsigned long length_low; - unsigned long length_high; - unsigned long type; -} memory_map_t; - -#endif /* ! ASM */ +/* multiboot.h - the header for Multiboot */ +/* Copyright (C) 1999 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + +/* Macros. */ + +/* The magic number for the Multiboot header. */ +#define MULTIBOOT_HEADER_MAGIC 0x1BADB002 + +/* The flags for the Multiboot header. */ +#define MULTIBOOT_HEADER_FLAGS 0x00010003 + +/* The magic number passed by a Multiboot-compliant boot loader. */ +#define MULTIBOOT_BOOTLOADER_MAGIC 0x2BADB002 + +/* The size of our stack (16KB). */ +#define STACK_SIZE 0x4000 + +/* C symbol format. HAVE_ASM_USCORE is defined by configure. */ +#ifdef HAVE_ASM_USCORE +# define EXT_C(sym) _ ## sym +#else +# define EXT_C(sym) sym +#endif + +#ifndef ASM +/* Do not include here in boot.S. */ + +/* Types. */ + +/* The Multiboot header. */ +typedef struct multiboot_header +{ + unsigned long magic; + unsigned long flags; + unsigned long checksum; + unsigned long header_addr; + unsigned long load_addr; + unsigned long load_end_addr; + unsigned long bss_end_addr; + unsigned long entry_addr; +} multiboot_header_t; + +/* The symbol table for a.out. */ +typedef struct aout_symbol_table +{ + unsigned long tabsize; + unsigned long strsize; + unsigned long addr; + unsigned long reserved; +} aout_symbol_table_t; + +/* The section header table for ELF. */ +typedef struct elf_section_header_table +{ + unsigned long num; + unsigned long size; + unsigned long addr; + unsigned long shndx; +} elf_section_header_table_t; + +/* The Multiboot information. */ +typedef struct multiboot_info +{ + unsigned long flags; + unsigned long mem_lower; + unsigned long mem_upper; + unsigned long boot_device; + unsigned long cmdline; + unsigned long mods_count; + unsigned long mods_addr; + union + { + aout_symbol_table_t aout_sym; + elf_section_header_table_t elf_sec; + } u; + unsigned long mmap_length; + unsigned long mmap_addr; +} multiboot_info_t; + +/* The module structure. */ +typedef struct module +{ + unsigned long mod_start; + unsigned long mod_end; + unsigned long string; + unsigned long reserved; +} module_t; + +/* The memory map. Be careful that the offset 0 is base_addr_low + but no size. */ +typedef struct memory_map +{ + unsigned long size; + unsigned long base_addr_low; + unsigned long base_addr_high; + unsigned long length_low; + unsigned long length_high; + unsigned long type; +} memory_map_t; + +#endif /* ! ASM */ diff --git a/Dump/hybos/include/__nocompile_fcntl.h b/Dump/hybos/include/__nocompile_fcntl.h index 48de3c3..832446e 100644 --- a/Dump/hybos/include/__nocompile_fcntl.h +++ b/Dump/hybos/include/__nocompile_fcntl.h @@ -1,79 +1,79 @@ -/** - * fcntl.h - * - * access constants for _open. Note that this file is not complete - * and should not be used (yet) - */ - -#ifndef __STRICT_ANSI__ -#ifndef _FCNTL_H - -#define _FCNTL_H - -/** - * File access modes - */ -#define _O_RDONLY 0 /* read only */ -#define _O_WRONLY 1 /* write only */ -#define _O_RDWR 2 /* read and write */ - -/** - * Mask for access mode bits in the _open flags - */ -#define _O_ACCMODE (_O_RDONLY|_O_WRONLY|_O_RDWR) -#define _O_APPEND 0x0008 /* append output to end of file */ -#define _O_RANDOM 0x0010 -#define _O_SEQUENTIAL 0x0020 -#define _O_TEMPORARY 0x0040 /* make the file dissappear after closing */ -#define _O_NOINHERIT 0x0080 -#define _O_CREAT 0x0100 /* create file if it doesn't exist */ -#define _O_TRUNC 0x0200 /* truncate file to zero bytes if it exists */ -#define _O_EXCL 0x0400 /* open only if the file does not exist */ - -#define _O_SHORT_LIVED 0x1000 - -#define _O_TEXT 0x4000 /* crlf in file == lf in memory (\r\n == \n) */ -#define _O_BINARY 0x8000 /* input and output is not translated */ -#define _O_RAW _O_BINARY /* compatability */ - -/** - * XXX - * The following special mode(s) are only available to the - * kernel. Modules (even kernel-level modules) and other - * binaries will never be allowed to use these special modes. - * - * Modules which are compiled into the kernel may use these - * special modes (mainly at boot). - */ -#define _O_DEV 0x9000 /* XXX: special device links (files) */ -#define _O_SWAP 0x9100 /* swap */ - -#ifndef _NO_OLDNAMES - -/** - * POSIX/Non-ANSI names for increased portability - */ -#define O_RDONLY _O_RDONLY -#define O_WRONLY _O_WRONLY -#define O_RDWR _O_RDWR -#define O_ACCMODE _O_ACCMODE -#define O_APPEND _O_APPEND -#define O_CREAT _O_CREAT -#define O_TRUNC _O_TRUNC -#define O_EXCL _O_EXCL -#define O_TEXT _O_TEXT -#define O_BINARY _O_BINARY -#define O_TEMPORARY _O_TEMPORARY -#define O_NOINHERIT _O_NOINHERIT -#define O_SEQUENTIAL _O_SEQUENTIAL -#define O_RANDOM _O_RANDOM - -#define O_DEV _O_DEV -#define O_SWAP _O_SWAP - -#endif /* ! _NO_OLDNAMES */ - -#endif /* ! _FCNTL_H */ - -#endif /* ! __STRICT_ANSI__ */ - +/** + * fcntl.h + * + * access constants for _open. Note that this file is not complete + * and should not be used (yet) + */ + +#ifndef __STRICT_ANSI__ +#ifndef _FCNTL_H + +#define _FCNTL_H + +/** + * File access modes + */ +#define _O_RDONLY 0 /* read only */ +#define _O_WRONLY 1 /* write only */ +#define _O_RDWR 2 /* read and write */ + +/** + * Mask for access mode bits in the _open flags + */ +#define _O_ACCMODE (_O_RDONLY|_O_WRONLY|_O_RDWR) +#define _O_APPEND 0x0008 /* append output to end of file */ +#define _O_RANDOM 0x0010 +#define _O_SEQUENTIAL 0x0020 +#define _O_TEMPORARY 0x0040 /* make the file dissappear after closing */ +#define _O_NOINHERIT 0x0080 +#define _O_CREAT 0x0100 /* create file if it doesn't exist */ +#define _O_TRUNC 0x0200 /* truncate file to zero bytes if it exists */ +#define _O_EXCL 0x0400 /* open only if the file does not exist */ + +#define _O_SHORT_LIVED 0x1000 + +#define _O_TEXT 0x4000 /* crlf in file == lf in memory (\r\n == \n) */ +#define _O_BINARY 0x8000 /* input and output is not translated */ +#define _O_RAW _O_BINARY /* compatability */ + +/** + * XXX + * The following special mode(s) are only available to the + * kernel. Modules (even kernel-level modules) and other + * binaries will never be allowed to use these special modes. + * + * Modules which are compiled into the kernel may use these + * special modes (mainly at boot). + */ +#define _O_DEV 0x9000 /* XXX: special device links (files) */ +#define _O_SWAP 0x9100 /* swap */ + +#ifndef _NO_OLDNAMES + +/** + * POSIX/Non-ANSI names for increased portability + */ +#define O_RDONLY _O_RDONLY +#define O_WRONLY _O_WRONLY +#define O_RDWR _O_RDWR +#define O_ACCMODE _O_ACCMODE +#define O_APPEND _O_APPEND +#define O_CREAT _O_CREAT +#define O_TRUNC _O_TRUNC +#define O_EXCL _O_EXCL +#define O_TEXT _O_TEXT +#define O_BINARY _O_BINARY +#define O_TEMPORARY _O_TEMPORARY +#define O_NOINHERIT _O_NOINHERIT +#define O_SEQUENTIAL _O_SEQUENTIAL +#define O_RANDOM _O_RANDOM + +#define O_DEV _O_DEV +#define O_SWAP _O_SWAP + +#endif /* ! _NO_OLDNAMES */ + +#endif /* ! _FCNTL_H */ + +#endif /* ! __STRICT_ANSI__ */ + diff --git a/Dump/hybos/include/__nocompile_signal.h b/Dump/hybos/include/__nocompile_signal.h index 5aef646..6e23448 100644 --- a/Dump/hybos/include/__nocompile_signal.h +++ b/Dump/hybos/include/__nocompile_signal.h @@ -1,83 +1,83 @@ -/** - * fcntl.h - * - * access constants for _open. Note that this file is not complete - * and should not be used (yet) - */ - -#ifndef _SIGNAL_H -#define _SIGNAL_H - -/** - * The actual signal values. Using other values with signal - * produces a SIG_ERR return value. - * - * NOTE: SIGINT is produced when the user presses Ctrl-C - * SIGILL has not been tested - * SIGFPE - * SIGSEGV - * SIGTERM comes from what kind of termination request exactly? - * SIGBREAK is produced by pressing Ctrl-Break - * SIGABRT is produced by calling abort - */ -#define SIGINT 2 /* Interactive attention */ -#define SIGILL 4 /* Illegal instruction */ -#define SIGFPE 8 /* Floating point error */ -#define SIGSEGV 11 /* Segmentation violation */ -#define SIGTERM 15 /* Termination request */ -#define SIGBREAK 21 /* Ctrl-Break */ -#define SIGABRT 22 /* Abnormal termination (abort) */ - -#define NSIG 23 /* maximum signal number + 1 */ - -#ifndef RC_INVOKED -#ifndef _SIG_ATOMIC_T_DEFINED -typedef int sig_atomic_t; -#define _SIG_ATOMIC_T_DEFINED -#endif /* ! _SIG_ATOMIC_T_DEFINED */ - -/** - * The prototypes (below) are the easy part. The hard part is figuring - * out what signals are available and what numbers they are assigned - * along with appropriate values of SIG_DFL and SIG_IGN. - */ - -/** - * A pointer to a signal handler function. A signal handler takes a - * single int, which is the signal it handles. - */ -typedef void (*__p_sig_fn_t)(int); - -/** - * These are special values of signal handler pointers which are - * used to send a signal to the default handler (SIG_DFL), ignore - * the signal (SIG_IGN), or indicate an error return (SIG_ERR). - */ -#define SIG_DFL ((__p_sig_fn_t) 0) -#define SIG_IGN ((__p_sig_fn_t) 1) -#define SIG_ERR ((__p_sig_fn_t) -1) - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * Call signal to set the signal handler for signal sig to the - * function pointed to by handler. Returns a pointer to the - * previous handler, or SIG_ERR if an error occurs. Initially - * unhandled signals defined above will return SIG_DFL. - */ -_CRTIMP __p_sig_fn_t __cdecl signal(int, __p_sig_fn_t); - -/** - * Raise the signal indicated by sig. Returns non-zero on success. - */ -_CRTIMP int __cdecl raise (int); - -#ifdef __cplusplus -} -#endif - -#endif /* ! RC_INVOKED */ -#endif /* ! _SIGNAL_H */ - +/** + * fcntl.h + * + * access constants for _open. Note that this file is not complete + * and should not be used (yet) + */ + +#ifndef _SIGNAL_H +#define _SIGNAL_H + +/** + * The actual signal values. Using other values with signal + * produces a SIG_ERR return value. + * + * NOTE: SIGINT is produced when the user presses Ctrl-C + * SIGILL has not been tested + * SIGFPE + * SIGSEGV + * SIGTERM comes from what kind of termination request exactly? + * SIGBREAK is produced by pressing Ctrl-Break + * SIGABRT is produced by calling abort + */ +#define SIGINT 2 /* Interactive attention */ +#define SIGILL 4 /* Illegal instruction */ +#define SIGFPE 8 /* Floating point error */ +#define SIGSEGV 11 /* Segmentation violation */ +#define SIGTERM 15 /* Termination request */ +#define SIGBREAK 21 /* Ctrl-Break */ +#define SIGABRT 22 /* Abnormal termination (abort) */ + +#define NSIG 23 /* maximum signal number + 1 */ + +#ifndef RC_INVOKED +#ifndef _SIG_ATOMIC_T_DEFINED +typedef int sig_atomic_t; +#define _SIG_ATOMIC_T_DEFINED +#endif /* ! _SIG_ATOMIC_T_DEFINED */ + +/** + * The prototypes (below) are the easy part. The hard part is figuring + * out what signals are available and what numbers they are assigned + * along with appropriate values of SIG_DFL and SIG_IGN. + */ + +/** + * A pointer to a signal handler function. A signal handler takes a + * single int, which is the signal it handles. + */ +typedef void (*__p_sig_fn_t)(int); + +/** + * These are special values of signal handler pointers which are + * used to send a signal to the default handler (SIG_DFL), ignore + * the signal (SIG_IGN), or indicate an error return (SIG_ERR). + */ +#define SIG_DFL ((__p_sig_fn_t) 0) +#define SIG_IGN ((__p_sig_fn_t) 1) +#define SIG_ERR ((__p_sig_fn_t) -1) + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Call signal to set the signal handler for signal sig to the + * function pointed to by handler. Returns a pointer to the + * previous handler, or SIG_ERR if an error occurs. Initially + * unhandled signals defined above will return SIG_DFL. + */ +_CRTIMP __p_sig_fn_t __cdecl signal(int, __p_sig_fn_t); + +/** + * Raise the signal indicated by sig. Returns non-zero on success. + */ +_CRTIMP int __cdecl raise (int); + +#ifdef __cplusplus +} +#endif + +#endif /* ! RC_INVOKED */ +#endif /* ! _SIGNAL_H */ + diff --git a/Dump/hybos/include/_malloc.h b/Dump/hybos/include/_malloc.h index b8c68da..63699dc 100644 --- a/Dump/hybos/include/_malloc.h +++ b/Dump/hybos/include/_malloc.h @@ -1,37 +1,37 @@ -#ifndef __TL__MALLOC_H -#define __TL__MALLOC_H - -#ifdef __cplusplus -extern "C" -{ -#endif - -/* 500K */ -#define HEAP_SIZE 500000uL - -#include <_size_t.h> -/*#include <_null.h>*/ - -#define MALLOC_MAGIC 0x6D92 /* must be < 0x8000 */ - -typedef struct _malloc /* Turbo C DJGPP */ -{ - size_t size; /* 2 bytes 4 bytes */ - struct _malloc *next; /* 2 bytes 4 bytes */ - unsigned magic : 15; /* 2 bytes total 4 bytes total */ - unsigned used : 1; -} malloc_t; /* total 6 bytes 12 bytes */ - -extern malloc_t *_heap_bot, *_heap_top; - -static void dump_heap(void); -static void *kbrk(int *delta); -void *kmalloc(size_t size); -void kfree(void *blk); -void *krealloc(void *blk, size_t size); - -#ifdef __cplusplus -} -#endif - -#endif +#ifndef __TL__MALLOC_H +#define __TL__MALLOC_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +/* 500K */ +#define HEAP_SIZE 500000uL + +#include <_size_t.h> +/*#include <_null.h>*/ + +#define MALLOC_MAGIC 0x6D92 /* must be < 0x8000 */ + +typedef struct _malloc /* Turbo C DJGPP */ +{ + size_t size; /* 2 bytes 4 bytes */ + struct _malloc *next; /* 2 bytes 4 bytes */ + unsigned magic : 15; /* 2 bytes total 4 bytes total */ + unsigned used : 1; +} malloc_t; /* total 6 bytes 12 bytes */ + +extern malloc_t *_heap_bot, *_heap_top; + +static void dump_heap(void); +static void *kbrk(int *delta); +void *kmalloc(size_t size); +void kfree(void *blk); +void *krealloc(void *blk, size_t size); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/Dump/hybos/include/_null.h_ b/Dump/hybos/include/_null.h_ index 6207940..2385d95 100644 --- a/Dump/hybos/include/_null.h_ +++ b/Dump/hybos/include/_null.h_ @@ -1,18 +1,18 @@ -#ifndef __TL__NULL_H -#define __TL__NULL_H - -#ifdef __cplusplus -extern "C" -{ -#endif - -#ifndef _NULL -#define _NULL -#define NULL 0 -#endif - -#ifdef __cplusplus -} -#endif - -#endif +#ifndef __TL__NULL_H +#define __TL__NULL_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +#ifndef _NULL +#define _NULL +#define NULL 0 +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/Dump/hybos/include/_printf.h b/Dump/hybos/include/_printf.h index c967f10..77217b7 100644 --- a/Dump/hybos/include/_printf.h +++ b/Dump/hybos/include/_printf.h @@ -1,19 +1,19 @@ -#ifndef __TL__PRINTF_H -#define __TL__PRINTF_H - -#ifdef __cplusplus -extern "C" -{ -#endif - -#include <_va_list.h> - -typedef int (*fnptr_t)(unsigned c, void **helper); - -int do_printf(const char *fmt, va_list args, fnptr_t fn, void *ptr); - -#ifdef __cplusplus -} -#endif - -#endif +#ifndef __TL__PRINTF_H +#define __TL__PRINTF_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +#include <_va_list.h> + +typedef int (*fnptr_t)(unsigned c, void **helper); + +int do_printf(const char *fmt, va_list args, fnptr_t fn, void *ptr); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/Dump/hybos/include/_size_t.h b/Dump/hybos/include/_size_t.h index bebd416..8f4dc5a 100644 --- a/Dump/hybos/include/_size_t.h +++ b/Dump/hybos/include/_size_t.h @@ -1,18 +1,18 @@ -#ifndef __TL__SIZE_T_H -#define __TL__SIZE_T_H - -#ifdef __cplusplus -extern "C" -{ -#endif - -#ifndef _SIZE_T -#define _SIZE_T -typedef unsigned size_t; -#endif - -#ifdef __cplusplus -} -#endif - -#endif +#ifndef __TL__SIZE_T_H +#define __TL__SIZE_T_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +#ifndef _SIZE_T +#define _SIZE_T +typedef unsigned size_t; +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/Dump/hybos/include/_va_list.h b/Dump/hybos/include/_va_list.h index fe5b164..c62f7c4 100644 --- a/Dump/hybos/include/_va_list.h +++ b/Dump/hybos/include/_va_list.h @@ -1,15 +1,15 @@ -#ifndef __TL__VA_LIST_H -#define __TL__VA_LIST_H - -#ifdef __cplusplus -extern "C" -{ -#endif - -typedef unsigned char *va_list; - -#ifdef __cplusplus -} -#endif - -#endif +#ifndef __TL__VA_LIST_H +#define __TL__VA_LIST_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef unsigned char *va_list; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/Dump/hybos/include/asm.inc b/Dump/hybos/include/asm.inc index 3ba45fc..694d8cf 100644 --- a/Dump/hybos/include/asm.inc +++ b/Dump/hybos/include/asm.inc @@ -1,30 +1,30 @@ -%ifndef __TL_ASM_INC -%define __TL_ASM_INC 1 - -; macros to handle leading underscores added by DOS/Windows compilers -%macro IMP 1 -%ifdef UNDERBARS - EXTERN _%1 - %define %1 _%1 -%else - EXTERN %1 -%endif -%endmacro - -%macro EXP 1 - GLOBAL $_%1 - $_%1: - GLOBAL $%1 - $%1: -%endmacro - -DS_MAGIC equ 3544DA2Ah - -MULTIBOOT_PAGE_ALIGN equ 1<<0 -MULTIBOOT_MEMORY_INFO equ 1<<1 -MULTIBOOT_AOUT_KLUDGE equ 1<<16 -MULTIBOOT_HEADER_MAGIC equ 0x1BADB002 -MULTIBOOT_HEADER_FLAGS equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO | MULTIBOOT_AOUT_KLUDGE -MULTIBOOT_CHECKSUM equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS) - -%endif +%ifndef __TL_ASM_INC +%define __TL_ASM_INC 1 + +; macros to handle leading underscores added by DOS/Windows compilers +%macro IMP 1 +%ifdef UNDERBARS + EXTERN _%1 + %define %1 _%1 +%else + EXTERN %1 +%endif +%endmacro + +%macro EXP 1 + GLOBAL $_%1 + $_%1: + GLOBAL $%1 + $%1: +%endmacro + +DS_MAGIC equ 3544DA2Ah + +MULTIBOOT_PAGE_ALIGN equ 1<<0 +MULTIBOOT_MEMORY_INFO equ 1<<1 +MULTIBOOT_AOUT_KLUDGE equ 1<<16 +MULTIBOOT_HEADER_MAGIC equ 0x1BADB002 +MULTIBOOT_HEADER_FLAGS equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO | MULTIBOOT_AOUT_KLUDGE +MULTIBOOT_CHECKSUM equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS) + +%endif diff --git a/Dump/hybos/include/char.h b/Dump/hybos/include/char.h index 9ae9311..3e5b50b 100644 --- a/Dump/hybos/include/char.h +++ b/Dump/hybos/include/char.h @@ -1,24 +1,24 @@ -#ifndef _CHAR_H -#define _CHAR_H - -#include - -long atoi(const char *nptr); -bool isalnum(const char c); -bool isalpha(const char c); -bool isascii(const unsigned char c); -bool iscsym(const char c); -bool iscsymf(const char c); -bool isctrl(const char c); -bool isdigit(const char c); -bool isgraph(const unsigned char c); -bool islowwer(const char c); -bool isprint(const char c); -bool ispunct(const char c); -bool isspace(const char c); -bool isupper(const char c); -bool isxdigit(const char c); -int tolower(int c); -int toupper(int c); - -#endif /* !defined(_CHAR_H) */ +#ifndef _CHAR_H +#define _CHAR_H + +#include + +long atoi(const char *nptr); +bool isalnum(const char c); +bool isalpha(const char c); +bool isascii(const unsigned char c); +bool iscsym(const char c); +bool iscsymf(const char c); +bool isctrl(const char c); +bool isdigit(const char c); +bool isgraph(const unsigned char c); +bool islowwer(const char c); +bool isprint(const char c); +bool ispunct(const char c); +bool isspace(const char c); +bool isupper(const char c); +bool isxdigit(const char c); +int tolower(int c); +int toupper(int c); + +#endif /* !defined(_CHAR_H) */ diff --git a/Dump/hybos/include/conio.h b/Dump/hybos/include/conio.h index abc6575..0368744 100644 --- a/Dump/hybos/include/conio.h +++ b/Dump/hybos/include/conio.h @@ -1,60 +1,60 @@ -#ifndef __TL_CONIO_H -#define __TL_CONIO_H - -#ifdef __cplusplus -extern "C" -{ -#endif - -/* "bucky bits" -0x0100 is reserved for non-ASCII keys, so start with 0x200 */ -#define KBD_META_ALT 0x0200 /* Alt is pressed */ -#define KBD_META_CTRL 0x0400 /* Ctrl is pressed */ -#define KBD_META_SHIFT 0x0800 /* Shift is pressed */ -#define KBD_META_ANY (KBD_META_ALT | KBD_META_CTRL | KBD_META_SHIFT) -#define KBD_META_CAPS 0x1000 /* CapsLock is on */ -#define KBD_META_NUM 0x2000 /* NumLock is on */ -#define KBD_META_SCRL 0x4000 /* ScrollLock is on */ - -/* "ASCII" values for non-ASCII keys. All of these are user-defined. - -Hrrm. Unicode defines code pages for pseudographics (e.g. box-drawing -characters). I wonder it defines anything for keys like these? - -function keys: */ -#define KEY_F1 0x80 -#define KEY_F2 (KEY_F1 + 1) -#define KEY_F3 (KEY_F2 + 1) -#define KEY_F4 (KEY_F3 + 1) -#define KEY_F5 (KEY_F4 + 1) -#define KEY_F6 (KEY_F5 + 1) -#define KEY_F7 (KEY_F6 + 1) -#define KEY_F8 (KEY_F7 + 1) -#define KEY_F9 (KEY_F8 + 1) -#define KEY_F10 (KEY_F9 + 1) -#define KEY_F11 (KEY_F10 + 1) -#define KEY_F12 (KEY_F11 + 1) -/* cursor keys */ -#define KEY_INS 0x90 -#define KEY_DEL (KEY_INS + 1) -#define KEY_HOME (KEY_DEL + 1) -#define KEY_END (KEY_HOME + 1) -#define KEY_PGUP (KEY_END + 1) -#define KEY_PGDN (KEY_PGUP + 1) -#define KEY_LFT (KEY_PGDN + 1) -#define KEY_UP (KEY_LFT + 1) -#define KEY_DN (KEY_UP + 1) -#define KEY_RT (KEY_DN + 1) -/* print screen/sys rq and pause/break */ -#define KEY_PRNT (KEY_RT + 1) -#define KEY_PAUSE (KEY_PRNT + 1) -/* these return a value but they could also act as additional bucky keys */ -#define KEY_LWIN (KEY_PAUSE + 1) -#define KEY_RWIN (KEY_LWIN + 1) -#define KEY_MENU (KEY_RWIN + 1) - -#ifdef __cplusplus -} -#endif - -#endif +#ifndef __TL_CONIO_H +#define __TL_CONIO_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +/* "bucky bits" +0x0100 is reserved for non-ASCII keys, so start with 0x200 */ +#define KBD_META_ALT 0x0200 /* Alt is pressed */ +#define KBD_META_CTRL 0x0400 /* Ctrl is pressed */ +#define KBD_META_SHIFT 0x0800 /* Shift is pressed */ +#define KBD_META_ANY (KBD_META_ALT | KBD_META_CTRL | KBD_META_SHIFT) +#define KBD_META_CAPS 0x1000 /* CapsLock is on */ +#define KBD_META_NUM 0x2000 /* NumLock is on */ +#define KBD_META_SCRL 0x4000 /* ScrollLock is on */ + +/* "ASCII" values for non-ASCII keys. All of these are user-defined. + +Hrrm. Unicode defines code pages for pseudographics (e.g. box-drawing +characters). I wonder it defines anything for keys like these? + +function keys: */ +#define KEY_F1 0x80 +#define KEY_F2 (KEY_F1 + 1) +#define KEY_F3 (KEY_F2 + 1) +#define KEY_F4 (KEY_F3 + 1) +#define KEY_F5 (KEY_F4 + 1) +#define KEY_F6 (KEY_F5 + 1) +#define KEY_F7 (KEY_F6 + 1) +#define KEY_F8 (KEY_F7 + 1) +#define KEY_F9 (KEY_F8 + 1) +#define KEY_F10 (KEY_F9 + 1) +#define KEY_F11 (KEY_F10 + 1) +#define KEY_F12 (KEY_F11 + 1) +/* cursor keys */ +#define KEY_INS 0x90 +#define KEY_DEL (KEY_INS + 1) +#define KEY_HOME (KEY_DEL + 1) +#define KEY_END (KEY_HOME + 1) +#define KEY_PGUP (KEY_END + 1) +#define KEY_PGDN (KEY_PGUP + 1) +#define KEY_LFT (KEY_PGDN + 1) +#define KEY_UP (KEY_LFT + 1) +#define KEY_DN (KEY_UP + 1) +#define KEY_RT (KEY_DN + 1) +/* print screen/sys rq and pause/break */ +#define KEY_PRNT (KEY_RT + 1) +#define KEY_PAUSE (KEY_PRNT + 1) +/* these return a value but they could also act as additional bucky keys */ +#define KEY_LWIN (KEY_PAUSE + 1) +#define KEY_RWIN (KEY_LWIN + 1) +#define KEY_MENU (KEY_RWIN + 1) + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/Dump/hybos/include/ctype.h b/Dump/hybos/include/ctype.h index ac9d411..76b980d 100644 --- a/Dump/hybos/include/ctype.h +++ b/Dump/hybos/include/ctype.h @@ -1,44 +1,44 @@ -#ifndef __TL_CTYPE_H -#define __TL_CTYPE_H - -#ifdef __cplusplus -extern "C" -{ -#endif - -extern char _ctype[]; - -typedef enum {false = 0, true = !0} bool; - -#define CT_UP 0x01 /* upper case */ -#define CT_LOW 0x02 /* lower case */ -#define CT_DIG 0x04 /* digit */ -#define CT_CTL 0x08 /* control */ -#define CT_PUN 0x10 /* punctuation */ -#define CT_WHT 0x20 /* white space (space/cr/lf/tab) */ -#define CT_HEX 0x40 /* hex digit */ -#define CT_SP 0x80 /* hard space (0x20) */ - -/* without the cast to unsigned, DJGPP complains (using -Wall) */ -#define isalnum(c) ((_ctype + 1)[(unsigned)(c)] & (CT_UP | CT_LOW | CT_DIG)) -#define isalpha(c) ((_ctype + 1)[(unsigned)(c)] & (CT_UP | CT_LOW)) -#define iscntrl(c) ((_ctype + 1)[(unsigned)(c)] & (CT_CTL)) -#define isdigit(c) ((_ctype + 1)[(unsigned)(c)] & (CT_DIG)) -#define isgraph(c) ((_ctype + 1)[(unsigned)(c)] & (CT_PUN | CT_UP | CT_LOW | CT_DIG)) -#define islower(c) ((_ctype + 1)[(unsigned)(c)] & (CT_LOW)) -#define isprint(c) ((_ctype + 1)[(unsigned)(c)] & (CT_PUN | CT_UP | CT_LOW | CT_DIG | CT_SP)) -#define ispunct(c) ((_ctype + 1)[(unsigned)(c)] & (CT_PUN)) -#define isspace(c) ((_ctype + 1)[(unsigned)(c)] & (CT_WHT)) -#define isupper(c) ((_ctype + 1)[(unsigned)(c)] & (CT_UP)) -#define isxdigit(c) ((_ctype + 1)[(unsigned)(c)] & (CT_DIG | CT_HEX)) -#define isascii(c) ((unsigned)(c) <= 0x7F) -#define toascii(c) ((unsigned)(c) & 0x7F) - -#define tolower(c) (isupper(c) ? c + 'a' - 'A' : c) -#define toupper(c) (islower(c) ? c + 'A' - 'a' : c) - -#ifdef __cplusplus -} -#endif - -#endif +#ifndef __TL_CTYPE_H +#define __TL_CTYPE_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +extern char _ctype[]; + +typedef enum {false = 0, true = !0} bool; + +#define CT_UP 0x01 /* upper case */ +#define CT_LOW 0x02 /* lower case */ +#define CT_DIG 0x04 /* digit */ +#define CT_CTL 0x08 /* control */ +#define CT_PUN 0x10 /* punctuation */ +#define CT_WHT 0x20 /* white space (space/cr/lf/tab) */ +#define CT_HEX 0x40 /* hex digit */ +#define CT_SP 0x80 /* hard space (0x20) */ + +/* without the cast to unsigned, DJGPP complains (using -Wall) */ +#define isalnum(c) ((_ctype + 1)[(unsigned)(c)] & (CT_UP | CT_LOW | CT_DIG)) +#define isalpha(c) ((_ctype + 1)[(unsigned)(c)] & (CT_UP | CT_LOW)) +#define iscntrl(c) ((_ctype + 1)[(unsigned)(c)] & (CT_CTL)) +#define isdigit(c) ((_ctype + 1)[(unsigned)(c)] & (CT_DIG)) +#define isgraph(c) ((_ctype + 1)[(unsigned)(c)] & (CT_PUN | CT_UP | CT_LOW | CT_DIG)) +#define islower(c) ((_ctype + 1)[(unsigned)(c)] & (CT_LOW)) +#define isprint(c) ((_ctype + 1)[(unsigned)(c)] & (CT_PUN | CT_UP | CT_LOW | CT_DIG | CT_SP)) +#define ispunct(c) ((_ctype + 1)[(unsigned)(c)] & (CT_PUN)) +#define isspace(c) ((_ctype + 1)[(unsigned)(c)] & (CT_WHT)) +#define isupper(c) ((_ctype + 1)[(unsigned)(c)] & (CT_UP)) +#define isxdigit(c) ((_ctype + 1)[(unsigned)(c)] & (CT_DIG | CT_HEX)) +#define isascii(c) ((unsigned)(c) <= 0x7F) +#define toascii(c) ((unsigned)(c) & 0x7F) + +#define tolower(c) (isupper(c) ? c + 'a' - 'A' : c) +#define toupper(c) (islower(c) ? c + 'A' - 'a' : c) + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/Dump/hybos/include/esh/esh.h b/Dump/hybos/include/esh/esh.h index 298da0c..5e71d8e 100644 --- a/Dump/hybos/include/esh/esh.h +++ b/Dump/hybos/include/esh/esh.h @@ -1,33 +1,33 @@ -/** - * esh.h - */ - -#ifndef _ESH_H -#define _ESH_H - -#define MAX_LEN 512 /* maximum length of a command */ -#define MAX_PARAMS 20 /* maximum ammount of parameters a command may have */ -#define COMMAND_COUNT 6 /* number of commands supported */ - -typedef struct ESHELL_COMMANDS -{ - int minparams; /* number of required parameters */ - int maxparams; /* number of maximum parameters supported */ - char command[MAX_LEN]; /* command entry */ - char params[MAX_PARAMS][MAX_LEN]; /* parameters for command [index]["entry"] */ - char description[MAX_LEN]; -} ESHCOMMANDS; - -typedef struct ESHELL_CURR_COMMAND -{ - int count; - char param[MAX_PARAMS][MAX_LEN]; - char value[MAX_PARAMS][MAX_LEN]; -} ESHCURRCOMMAND; - -void keyDown(unsigned key); -void keyUp(unsigned key); -void processCommand(char *line, int count); - -#endif /* _ESH_H */ - +/** + * esh.h + */ + +#ifndef _ESH_H +#define _ESH_H + +#define MAX_LEN 512 /* maximum length of a command */ +#define MAX_PARAMS 20 /* maximum ammount of parameters a command may have */ +#define COMMAND_COUNT 6 /* number of commands supported */ + +typedef struct ESHELL_COMMANDS +{ + int minparams; /* number of required parameters */ + int maxparams; /* number of maximum parameters supported */ + char command[MAX_LEN]; /* command entry */ + char params[MAX_PARAMS][MAX_LEN]; /* parameters for command [index]["entry"] */ + char description[MAX_LEN]; +} ESHCOMMANDS; + +typedef struct ESHELL_CURR_COMMAND +{ + int count; + char param[MAX_PARAMS][MAX_LEN]; + char value[MAX_PARAMS][MAX_LEN]; +} ESHCURRCOMMAND; + +void keyDown(unsigned key); +void keyUp(unsigned key); +void processCommand(char *line, int count); + +#endif /* _ESH_H */ + diff --git a/Dump/hybos/include/esh/esh.h~ b/Dump/hybos/include/esh/esh.h~ index 134afeb..06508e7 100644 --- a/Dump/hybos/include/esh/esh.h~ +++ b/Dump/hybos/include/esh/esh.h~ @@ -1,32 +1,32 @@ -/** - * esh.h - */ - -#ifndef _ESH_H -#define _ESH_H - -#define MAX_LEN 512 /* maximum length of a command */ -#define MAX_PARAMS 20 /* maximum ammount of parameters a command may have */ -#define COMMAND_COUNT 6 /* number of commands supported */ - -typedef struct ESHELL_COMMANDS -{ - int minparams; /* number of required parameters */ - int maxparams; /* number of maximum parameters supported */ - char command[MAX_LEN]; /* command entry */ - char params[MAX_PARAMS][MAX_LEN]; /* parameters for command [index]["entry"] */ -} ESHCOMMANDS; - -typedef struct ESHELL_CURR_COMMAND -{ - int count; - char param[MAX_PARAMS][MAX_LEN]; - char value[MAX_PARAMS][MAX_LEN]; -} ESHCURRCOMMAND; - -void keyDown(unsigned key); -void keyUp(unsigned key); -void processCommand(char *line, int count); - -#endif /* _ESH_H */ - +/** + * esh.h + */ + +#ifndef _ESH_H +#define _ESH_H + +#define MAX_LEN 512 /* maximum length of a command */ +#define MAX_PARAMS 20 /* maximum ammount of parameters a command may have */ +#define COMMAND_COUNT 6 /* number of commands supported */ + +typedef struct ESHELL_COMMANDS +{ + int minparams; /* number of required parameters */ + int maxparams; /* number of maximum parameters supported */ + char command[MAX_LEN]; /* command entry */ + char params[MAX_PARAMS][MAX_LEN]; /* parameters for command [index]["entry"] */ +} ESHCOMMANDS; + +typedef struct ESHELL_CURR_COMMAND +{ + int count; + char param[MAX_PARAMS][MAX_LEN]; + char value[MAX_PARAMS][MAX_LEN]; +} ESHCURRCOMMAND; + +void keyDown(unsigned key); +void keyUp(unsigned key); +void processCommand(char *line, int count); + +#endif /* _ESH_H */ + diff --git a/Dump/hybos/include/fat.h b/Dump/hybos/include/fat.h index af93578..aa9454d 100644 --- a/Dump/hybos/include/fat.h +++ b/Dump/hybos/include/fat.h @@ -1,84 +1,84 @@ -#ifndef _FAT_H -#define _FAT_H - -typedef unsigned char uint8_t; -typedef unsigned short uint16_t; -typedef unsigned long uint32_t; - -/** - * FAT12 and FAT16 bootsector - */ -typedef struct __FAT_BOOTSECTOR /* MUST be packed */ -{ - uint8_t jump[3]; /* 16-bit JMP to boot code, or 8-bit JMP + NOP */ - uint8_t oem_id[8]; /* e.g., 'MSWIN4.0' */ - uint16_t bytes_per_sector; /* typically 512 */ - uint8_t sectors_per_cluster; - uint16_t num_boot_sectors; /* typically 1 */ - uint8_t num_fats; /* typically 2 */ - uint16_t num_root_dir_ents; - uint16_t total_sectors; /* 16-bit; 0 if num sectors > 65535 */ - uint8_t media_ID_byte; /* typically 0F0h */ - uint16_t sectors_per_fat; - uint16_t sectors_per_track; - uint16_t heads; - uint32_t hidden_sectors; /* LBA partition start */ - uint32_t total_sectors_large; /* 32-bit; 0 if num sectors < 65536 */ - uint8_t boot_code[474]; - uint8_t magic[2]; /* 55h, 0AAh */ -} FAT_BOOTSECTOR; /* 512 bytes total */ - -/** - * FAT directory entries - * - * As far as I know, this should be valid for FAT12/16/32 - * Entries are 32 bytes long - */ -typedef struct __FAT_DIRSTRUCT /* MUST be packed */ -{ - uint8_t name[8]; /* all caps, pad right with spaces */ - uint8_t ext[3]; /* all caps, pad right with spaces */ - uint8_t attrib; /* attribute byte */ - uint8_t reserved; /* 0 */ - uint8_t ctime_ms; /* file creation time, 10ms units */ - uint16_t ctime; /* file creation time, in DOS format */ - uint16_t cdate; /* file creation date, in DOS format */ - uint16_t adate; /* DOS date of last file access */ - uint16_t st_clust_msw; /* high 16 bits of starting cluster (FAT32) */ - uint16_t mtime; /* DOS time of last file modification */ - uint16_t mdate; /* DOS date of last file modification */ - uint16_t st_clust; /* starting cluster */ - uint32_t file_size; /* in bytes */ -} FAT_DIRSTRUCT; /* 32 bytes total */ - -/** - * DOS time and date structs - */ -typedef struct __DOS_TIME /* MUST be packed */ -{ - unsigned two_secs : 5; /* low 5 bits: 2-second increments */ - unsigned minutes : 6; /* middle 6 bits: minutes */ - unsigned hours : 5; /* high 5 bits: hours (0-23) */ -} DOS_TIME; /* 2 bytes total */ - -typedef struct __DOS_DATE /* MUST be packed */ -{ - unsigned date : 5; /* low 5 bits: date (1-31) */ - unsigned month : 4; /* middle 4 bits: month (1-12) */ - unsigned year : 7; /* high 7 bits: year - 1980 */ -} DOS_DATE; /* 2 bytes total */ - -/** - * DOS File attributes - */ -typedef struct __DOS_ATTRIB /* MUST be packed */ -{ - int read_only : 1; /* b0 */ - int hidden : 1; - int system : 1; - int volume_label : 1; - int directory : 1; - int reserved : 2; /* b6, b7 */ -} DOS_ATTRIB; /* 1 byte total */ - -#endif /* ! _FAT_H */ +#ifndef _FAT_H +#define _FAT_H + +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned long uint32_t; + +/** + * FAT12 and FAT16 bootsector + */ +typedef struct __FAT_BOOTSECTOR /* MUST be packed */ +{ + uint8_t jump[3]; /* 16-bit JMP to boot code, or 8-bit JMP + NOP */ + uint8_t oem_id[8]; /* e.g., 'MSWIN4.0' */ + uint16_t bytes_per_sector; /* typically 512 */ + uint8_t sectors_per_cluster; + uint16_t num_boot_sectors; /* typically 1 */ + uint8_t num_fats; /* typically 2 */ + uint16_t num_root_dir_ents; + uint16_t total_sectors; /* 16-bit; 0 if num sectors > 65535 */ + uint8_t media_ID_byte; /* typically 0F0h */ + uint16_t sectors_per_fat; + uint16_t sectors_per_track; + uint16_t heads; + uint32_t hidden_sectors; /* LBA partition start */ + uint32_t total_sectors_large; /* 32-bit; 0 if num sectors < 65536 */ + uint8_t boot_code[474]; + uint8_t magic[2]; /* 55h, 0AAh */ +} FAT_BOOTSECTOR; /* 512 bytes total */ + +/** + * FAT directory entries + * + * As far as I know, this should be valid for FAT12/16/32 + * Entries are 32 bytes long + */ +typedef struct __FAT_DIRSTRUCT /* MUST be packed */ +{ + uint8_t name[8]; /* all caps, pad right with spaces */ + uint8_t ext[3]; /* all caps, pad right with spaces */ + uint8_t attrib; /* attribute byte */ + uint8_t reserved; /* 0 */ + uint8_t ctime_ms; /* file creation time, 10ms units */ + uint16_t ctime; /* file creation time, in DOS format */ + uint16_t cdate; /* file creation date, in DOS format */ + uint16_t adate; /* DOS date of last file access */ + uint16_t st_clust_msw; /* high 16 bits of starting cluster (FAT32) */ + uint16_t mtime; /* DOS time of last file modification */ + uint16_t mdate; /* DOS date of last file modification */ + uint16_t st_clust; /* starting cluster */ + uint32_t file_size; /* in bytes */ +} FAT_DIRSTRUCT; /* 32 bytes total */ + +/** + * DOS time and date structs + */ +typedef struct __DOS_TIME /* MUST be packed */ +{ + unsigned two_secs : 5; /* low 5 bits: 2-second increments */ + unsigned minutes : 6; /* middle 6 bits: minutes */ + unsigned hours : 5; /* high 5 bits: hours (0-23) */ +} DOS_TIME; /* 2 bytes total */ + +typedef struct __DOS_DATE /* MUST be packed */ +{ + unsigned date : 5; /* low 5 bits: date (1-31) */ + unsigned month : 4; /* middle 4 bits: month (1-12) */ + unsigned year : 7; /* high 7 bits: year - 1980 */ +} DOS_DATE; /* 2 bytes total */ + +/** + * DOS File attributes + */ +typedef struct __DOS_ATTRIB /* MUST be packed */ +{ + int read_only : 1; /* b0 */ + int hidden : 1; + int system : 1; + int volume_label : 1; + int directory : 1; + int reserved : 2; /* b6, b7 */ +} DOS_ATTRIB; /* 1 byte total */ + +#endif /* ! _FAT_H */ diff --git a/Dump/hybos/include/keyboard.h b/Dump/hybos/include/keyboard.h index 403422c..872788c 100644 --- a/Dump/hybos/include/keyboard.h +++ b/Dump/hybos/include/keyboard.h @@ -1,415 +1,415 @@ -#ifndef _KEYBOARD_H -#define _KEYBOARD_H - -/** - * For now we will default to __KB_IBM_PC_XT - */ -#define __KB_IBM_PC_XT - - -/** - * Just in case we were defined someplace else - */ -#ifdef __KB_IBM_PC_XT -#undef __KB_IBM_PC_AT -#undef __KB_IBM_PS2 -#elif defined(__KB_IBM_PC_AT) -#undef __KB_IBM_PC_XT -#undef __KB_IBM_PS2 -#else -#undef __KB_IBM_PC_AT -#undef __KB_IBM_PC_XT -#define __KB_IBM_PC_XT -#endif - - -#ifdef __KB_IBM_PC_XT -/** - * Set 1 Scancodes - * - * IBM PC XT - * - * __KB_IBM_PC_XT must be defined to use these - */ -#define KEY_ESC 0x01 -#define KEY_F1 0x3B -#define KEY_F2 0x3C -#define KEY_F3 0x3D -#define KEY_F4 0x3E -#define KEY_F5 0x3F -#define KEY_F6 0x40 -#define KEY_F7 0x41 -#define KEY_F8 0x42 -#define KEY_F9 0x43 -#define KEY_F10 0x44 -#define KEY_F11 0x57 -#define KEY_F12 0x58 -#define KEY_TILDA 0x29 -#define KEY_1 0x02 -#define KEY_2 0x03 -#define KEY_3 0x04 -#define KEY_4 0x05 -#define KEY_5 0x06 -#define KEY_6 0x07 -#define KEY_7 0x08 -#define KEY_8 0x09 -#define KEY_9 0x0A -#define KEY_0 0x0B -#define KEY_MINUS 0x0C -#define KEY_PLUS 0x0D -#define KEY_BKSLASH 0x2B -#define KEY_BKSPACE 0x0E -#define KEY_TAB 0x0F -#define KEY_Q 0x10 -#define KEY_W 0x11 -#define KEY_E 0x12 -#define KEY_R 0x13 -#define KEY_T 0x14 -#define KEY_Y 0x15 -#define KEY_U 0x16 -#define KEY_I 0x17 -#define KEY_O 0x18 -#define KEY_P 0x19 -#define KEY_LBRACKET 0x1A -#define KEY_RBRACKET 0x1B -#define KEY_ENTER 0x1C -#define KEY_CAPS 0x3A -#define KEY_A 0x1E -#define KEY_S 0x1F -#define KEY_D 0x20 -#define KEY_F 0x21 -#define KEY_G 0x22 -#define KEY_H 0x23 -#define KEY_J 0x24 -#define KEY_K 0x25 -#define KEY_L 0x26 -#define KEY_SEMICOLON 0x27 -#define KEY_QUOTE 0x28 -#define KEY_LSHIFT 0x2A -#define KEY_Z 0x2C -#define KEY_X 0x2D -#define KEY_C 0x2E -#define KEY_V 0x2F -#define KEY_B 0x30 -#define KEY_N 0x31 -#define KEY_M 0x32 -#define KEY_COMMA 0x33 -#define KEY_PERIOD 0x34 -#define KEY_SLASH 0x35 -#define KEY_RSHIFT 0x36 -#define KEY_LCTRL 0x1D -#define KEY_LWIN 0x5B -#define KEY_LALT 0x38 -#define KEY_SPACE 0x39 -#define KEY_RALT 0x38 -#define KEY_RWIN 0x5C -#define KEY_MENU 0x5D -#define KEY_RCTRL 0x1D -#define KEY_SCRLCK 0x46 /* scroll lock */ - -/** - * Keypad - */ -#define KEYP_NUMLCK 0x45 -#define KEYP_SLASH 0x35 -#define KEYP_ASTERISK 0x37 -#define KEYP_MINUS 0x4A -#define KEYP_7 0x47 -#define KEYP_8 0x48 -#define KEYP_9 0x49 -#define KEYP_PLUS 0x4E -#define KEYP_4 0x4B -#define KEYP_5 0x4C -#define KEYP_6 0x4D -#define KEYP_1 0x4F -#define KEYP_2 0x50 -#define KEYP_3 0x51 -#define KEYP_ENTER 0x1C -#define KEYP_0 0x52 -#define KEYP_PERIOD 0x53 - -/** - * Insert, Home, Page Up cluster - */ -#define KEY_INSERT 0x52 -#define KEY_HOME 0x47 -#define KEY_PGUP 0x49 -#define KEY_DEL 0x53 -#define KEY_END 0x4F -#define KEY_PGDOWN 0x51 - -/** - * Arrow key cluster - */ -#define KEY_UP 0x48 -#define KEY_LEFT 0x4B -#define KEY_DOWN 0x50 -#define KEY_RIGHT 0x4D - -/** - * FIXME: Experimental - */ -//#define KEY_PRTSCR 0xE02AE037 /* print screen */ -//#define KEY_PAUSE 0xE11D45E19DC5 /* pause/break */ - -#endif /* defined(__KB_IBM_PC_XT) */ - -#ifdef __KB_IBM_PC_AT -/** - * Set 2 Scancodes - * - * IBM PC AT - * - * __KB_IBM_PC_AT must be defined to use these - */ -#define KEY_ESC 0x76 -#define KEY_F1 0x05 -#define KEY_F2 0x06 -#define KEY_F3 0x04 -#define KEY_F4 0x0C -#define KEY_F5 0x03 -#define KEY_F6 0x0B -#define KEY_F7 0x83 -#define KEY_F8 0x0A -#define KEY_F9 0x01 -#define KEY_F10 0x09 -#define KEY_F11 0x78 -#define KEY_F12 0x07 -#define KEY_TILDA 0x0E -#define KEY_1 0x16 -#define KEY_2 0x1E -#define KEY_3 0x26 -#define KEY_4 0x25 -#define KEY_5 0x2E -#define KEY_6 0x36 -#define KEY_7 0x3D -#define KEY_8 0x3E -#define KEY_9 0x46 -#define KEY_0 0x45 -#define KEY_MINUS 0x4E -#define KEY_PLUS 0x55 -#define KEY_BKSLASH 0x5D -#define KEY_BKSPACE 0x66 -#define KEY_TAB 0x0D -#define KEY_Q 0x15 -#define KEY_W 0x1D -#define KEY_E 0x24 -#define KEY_R 0x2D -#define KEY_T 0x2C -#define KEY_Y 0x35 -#define KEY_U 0x3C -#define KEY_I 0x43 -#define KEY_O 0x44 -#define KEY_P 0x4D -#define KEY_LBRACKET 0x54 -#define KEY_RBRACKET 0x5B -#define KEY_ENTER 0x5A -#define KEY_CAPS 0x58 -#define KEY_A 0x1C -#define KEY_S 0x1B -#define KEY_D 0x23 -#define KEY_F 0x2B -#define KEY_G 0x34 -#define KEY_H 0x33 -#define KEY_J 0x3B -#define KEY_K 0x42 -#define KEY_L 0x4B -#define KEY_SEMICOLON 0x4C -#define KEY_QUOTE 0x52 -#define KEY_LSHIFT 0x12 -#define KEY_Z 0x1A -#define KEY_X 0x22 -#define KEY_C 0x21 -#define KEY_V 0x2A -#define KEY_B 0x32 -#define KEY_N 0x31 -#define KEY_M 0x3A -#define KEY_COMMA 0x41 -#define KEY_PERIOD 0x49 -#define KEY_SLASH 0x4A -#define KEY_RSHIFT 0x59 -#define KEY_LCTRL 0x14 -#define KEY_LWIN 0xE01F -#define KEY_LALT 0x11 -#define KEY_SPACE 0x29 -#define KEY_RALT 0xE011 -#define KEY_RWIN 0xE027 -#define KEY_MENU 0xE02F -#define KEY_RCTRL 0xE014 -#define KEY_SCRLCK 0x7E /* scroll lock */ - -/** - * Keypad - */ -#define KEYP_NUMLCK 0x77 -#define KEYP_SLASH 0xE04A -#define KEYP_ASTERISK 0x7C -#define KEYP_MINUS 0x7B -#define KEYP_7 0x6C -#define KEYP_8 0x75 -#define KEYP_9 0x7D -#define KEYP_PLUS 0x79 -#define KEYP_4 0x6B -#define KEYP_5 0x73 -#define KEYP_6 0x74 -#define KEYP_1 0x69 -#define KEYP_2 0x72 -#define KEYP_3 0x7A -#define KEYP_ENTER 0xE05A -#define KEYP_0 0x70 -#define KEYP_PERIOD 0x71 - -/** - * Insert, Home, Page Up cluster - */ -#define KEY_INSERT 0xE070 -#define KEY_HOME 0xE06C -#define KEY_PGUP 0xE07D -#define KEY_DEL 0xE071 -#define KEY_END 0xE069 -#define KEY_PGDOWN 0xE07A - -/** - * Arrow key cluster - */ -#define KEY_UP 0xE075 -#define KEY_LEFT 0xE06B -#define KEY_DOWN 0xE072 -#define KEY_RIGHT 0xE074 - -/** - * FIXME: Experimental - */ -#define KEY_PRTSCR 0xE012E07C /* print screen */ -#define KEY_PAUSE 0xE11477E1F014F077 /* pause/break */ - -#endif /* defined(__KB_IBM_PC_AT) */ - -#ifdef __KB_IBM_PS2 -/** - * Set 1 Scancodes - * - * IBM PC XT - * - * __KB_IBM_PS2 must be defined to use these - */ -#define KEY_ESC 0x08 -#define KEY_F1 0x07 -#define KEY_F2 0x0F -#define KEY_F3 0x17 -#define KEY_F4 0x1F -#define KEY_F5 0x27 -#define KEY_F6 0x2F -#define KEY_F7 0x37 -#define KEY_F8 0x3F -#define KEY_F9 0x47 -#define KEY_F10 0x4F -#define KEY_F11 0x56 -#define KEY_F12 0x5E -#define KEY_TILDA 0x0E -#define KEY_1 0x16 -#define KEY_2 0x1E -#define KEY_3 0x26 -#define KEY_4 0x25 -#define KEY_5 0x2E -#define KEY_6 0x36 -#define KEY_7 0x3D -#define KEY_8 0x3E -#define KEY_9 0x46 -#define KEY_0 0x45 -#define KEY_MINUS 0x4E -#define KEY_PLUS 0x55 -#define KEY_BKSLASH 0x5C -#define KEY_BKSPACE 0x66 -#define KEY_TAB 0x0D -#define KEY_Q 0x15 -#define KEY_W 0x1D -#define KEY_E 0x24 -#define KEY_R 0x2D -#define KEY_T 0x2C -#define KEY_Y 0x35 -#define KEY_U 0x3C -#define KEY_I 0x43 -#define KEY_O 0x44 -#define KEY_P 0x4D -#define KEY_LBRACKET 0x54 -#define KEY_RBRACKET 0x5B -#define KEY_ENTER 0x5A -#define KEY_CAPS 0x14 -#define KEY_A 0x1C -#define KEY_S 0x1B -#define KEY_D 0x23 -#define KEY_F 0x2B -#define KEY_G 0x34 -#define KEY_H 0x33 -#define KEY_J 0x3B -#define KEY_K 0x42 -#define KEY_L 0x4B -#define KEY_SEMICOLON 0x4C -#define KEY_QUOTE 0x52 -#define KEY_LSHIFT 0x12 -#define KEY_Z 0x1A -#define KEY_X 0x22 -#define KEY_C 0x21 -#define KEY_V 0x2A -#define KEY_B 0x32 -#define KEY_N 0x31 -#define KEY_M 0x3A -#define KEY_COMMA 0x41 -#define KEY_PERIOD 0x49 -#define KEY_SLASH 0x4A -#define KEY_RSHIFT 0x59 -#define KEY_LCTRL 0x11 -#define KEY_LWIN 0x8B -#define KEY_LALT 0x19 -#define KEY_SPACE 0x29 -#define KEY_RALT 0x39 -#define KEY_RWIN 0x8C -#define KEY_MENU 0x8D -#define KEY_RCTRL 0x58 -#define KEY_SCRLCK 0x5F /* scroll lock */ -#define KEY_PRTSCR 0x57 /* print screen */ -#define KEY_PAUSE 0x62 /* pause/break */ - -/** - * Keypad - */ -#define KEYP_NUMLCK 0x76 -#define KEYP_SLASH 0x77 -#define KEYP_ASTERISK 0x7E -#define KEYP_MINUS 0x84 -#define KEYP_7 0x6C -#define KEYP_8 0x75 -#define KEYP_9 0x7D -#define KEYP_PLUS 0x7C -#define KEYP_4 0x6B -#define KEYP_5 0x73 -#define KEYP_6 0x74 -#define KEYP_1 0x69 -#define KEYP_2 0x72 -#define KEYP_3 0x7A -#define KEYP_ENTER 0x79 -#define KEYP_0 0x70 -#define KEYP_PERIOD 0x71 - -/** - * Insert, Home, Page Up cluster - */ -#define KEY_INSERT 0x67 -#define KEY_HOME 0x6E -#define KEY_PGUP 0x6F -#define KEY_DEL 0x64 -#define KEY_END 0x65 -#define KEY_PGDOWN 0x6D - -/** - * Arrow key cluster - */ -#define KEY_UP 0x63 -#define KEY_LEFT 0x61 -#define KEY_DOWN 0x60 -#define KEY_RIGHT 0x6A - -#endif /* defined(__KB_IBM_PS2) */ - -#endif /* ! _KEYBOARD_H */ +#ifndef _KEYBOARD_H +#define _KEYBOARD_H + +/** + * For now we will default to __KB_IBM_PC_XT + */ +#define __KB_IBM_PC_XT + + +/** + * Just in case we were defined someplace else + */ +#ifdef __KB_IBM_PC_XT +#undef __KB_IBM_PC_AT +#undef __KB_IBM_PS2 +#elif defined(__KB_IBM_PC_AT) +#undef __KB_IBM_PC_XT +#undef __KB_IBM_PS2 +#else +#undef __KB_IBM_PC_AT +#undef __KB_IBM_PC_XT +#define __KB_IBM_PC_XT +#endif + + +#ifdef __KB_IBM_PC_XT +/** + * Set 1 Scancodes + * + * IBM PC XT + * + * __KB_IBM_PC_XT must be defined to use these + */ +#define KEY_ESC 0x01 +#define KEY_F1 0x3B +#define KEY_F2 0x3C +#define KEY_F3 0x3D +#define KEY_F4 0x3E +#define KEY_F5 0x3F +#define KEY_F6 0x40 +#define KEY_F7 0x41 +#define KEY_F8 0x42 +#define KEY_F9 0x43 +#define KEY_F10 0x44 +#define KEY_F11 0x57 +#define KEY_F12 0x58 +#define KEY_TILDA 0x29 +#define KEY_1 0x02 +#define KEY_2 0x03 +#define KEY_3 0x04 +#define KEY_4 0x05 +#define KEY_5 0x06 +#define KEY_6 0x07 +#define KEY_7 0x08 +#define KEY_8 0x09 +#define KEY_9 0x0A +#define KEY_0 0x0B +#define KEY_MINUS 0x0C +#define KEY_PLUS 0x0D +#define KEY_BKSLASH 0x2B +#define KEY_BKSPACE 0x0E +#define KEY_TAB 0x0F +#define KEY_Q 0x10 +#define KEY_W 0x11 +#define KEY_E 0x12 +#define KEY_R 0x13 +#define KEY_T 0x14 +#define KEY_Y 0x15 +#define KEY_U 0x16 +#define KEY_I 0x17 +#define KEY_O 0x18 +#define KEY_P 0x19 +#define KEY_LBRACKET 0x1A +#define KEY_RBRACKET 0x1B +#define KEY_ENTER 0x1C +#define KEY_CAPS 0x3A +#define KEY_A 0x1E +#define KEY_S 0x1F +#define KEY_D 0x20 +#define KEY_F 0x21 +#define KEY_G 0x22 +#define KEY_H 0x23 +#define KEY_J 0x24 +#define KEY_K 0x25 +#define KEY_L 0x26 +#define KEY_SEMICOLON 0x27 +#define KEY_QUOTE 0x28 +#define KEY_LSHIFT 0x2A +#define KEY_Z 0x2C +#define KEY_X 0x2D +#define KEY_C 0x2E +#define KEY_V 0x2F +#define KEY_B 0x30 +#define KEY_N 0x31 +#define KEY_M 0x32 +#define KEY_COMMA 0x33 +#define KEY_PERIOD 0x34 +#define KEY_SLASH 0x35 +#define KEY_RSHIFT 0x36 +#define KEY_LCTRL 0x1D +#define KEY_LWIN 0x5B +#define KEY_LALT 0x38 +#define KEY_SPACE 0x39 +#define KEY_RALT 0x38 +#define KEY_RWIN 0x5C +#define KEY_MENU 0x5D +#define KEY_RCTRL 0x1D +#define KEY_SCRLCK 0x46 /* scroll lock */ + +/** + * Keypad + */ +#define KEYP_NUMLCK 0x45 +#define KEYP_SLASH 0x35 +#define KEYP_ASTERISK 0x37 +#define KEYP_MINUS 0x4A +#define KEYP_7 0x47 +#define KEYP_8 0x48 +#define KEYP_9 0x49 +#define KEYP_PLUS 0x4E +#define KEYP_4 0x4B +#define KEYP_5 0x4C +#define KEYP_6 0x4D +#define KEYP_1 0x4F +#define KEYP_2 0x50 +#define KEYP_3 0x51 +#define KEYP_ENTER 0x1C +#define KEYP_0 0x52 +#define KEYP_PERIOD 0x53 + +/** + * Insert, Home, Page Up cluster + */ +#define KEY_INSERT 0x52 +#define KEY_HOME 0x47 +#define KEY_PGUP 0x49 +#define KEY_DEL 0x53 +#define KEY_END 0x4F +#define KEY_PGDOWN 0x51 + +/** + * Arrow key cluster + */ +#define KEY_UP 0x48 +#define KEY_LEFT 0x4B +#define KEY_DOWN 0x50 +#define KEY_RIGHT 0x4D + +/** + * FIXME: Experimental + */ +//#define KEY_PRTSCR 0xE02AE037 /* print screen */ +//#define KEY_PAUSE 0xE11D45E19DC5 /* pause/break */ + +#endif /* defined(__KB_IBM_PC_XT) */ + +#ifdef __KB_IBM_PC_AT +/** + * Set 2 Scancodes + * + * IBM PC AT + * + * __KB_IBM_PC_AT must be defined to use these + */ +#define KEY_ESC 0x76 +#define KEY_F1 0x05 +#define KEY_F2 0x06 +#define KEY_F3 0x04 +#define KEY_F4 0x0C +#define KEY_F5 0x03 +#define KEY_F6 0x0B +#define KEY_F7 0x83 +#define KEY_F8 0x0A +#define KEY_F9 0x01 +#define KEY_F10 0x09 +#define KEY_F11 0x78 +#define KEY_F12 0x07 +#define KEY_TILDA 0x0E +#define KEY_1 0x16 +#define KEY_2 0x1E +#define KEY_3 0x26 +#define KEY_4 0x25 +#define KEY_5 0x2E +#define KEY_6 0x36 +#define KEY_7 0x3D +#define KEY_8 0x3E +#define KEY_9 0x46 +#define KEY_0 0x45 +#define KEY_MINUS 0x4E +#define KEY_PLUS 0x55 +#define KEY_BKSLASH 0x5D +#define KEY_BKSPACE 0x66 +#define KEY_TAB 0x0D +#define KEY_Q 0x15 +#define KEY_W 0x1D +#define KEY_E 0x24 +#define KEY_R 0x2D +#define KEY_T 0x2C +#define KEY_Y 0x35 +#define KEY_U 0x3C +#define KEY_I 0x43 +#define KEY_O 0x44 +#define KEY_P 0x4D +#define KEY_LBRACKET 0x54 +#define KEY_RBRACKET 0x5B +#define KEY_ENTER 0x5A +#define KEY_CAPS 0x58 +#define KEY_A 0x1C +#define KEY_S 0x1B +#define KEY_D 0x23 +#define KEY_F 0x2B +#define KEY_G 0x34 +#define KEY_H 0x33 +#define KEY_J 0x3B +#define KEY_K 0x42 +#define KEY_L 0x4B +#define KEY_SEMICOLON 0x4C +#define KEY_QUOTE 0x52 +#define KEY_LSHIFT 0x12 +#define KEY_Z 0x1A +#define KEY_X 0x22 +#define KEY_C 0x21 +#define KEY_V 0x2A +#define KEY_B 0x32 +#define KEY_N 0x31 +#define KEY_M 0x3A +#define KEY_COMMA 0x41 +#define KEY_PERIOD 0x49 +#define KEY_SLASH 0x4A +#define KEY_RSHIFT 0x59 +#define KEY_LCTRL 0x14 +#define KEY_LWIN 0xE01F +#define KEY_LALT 0x11 +#define KEY_SPACE 0x29 +#define KEY_RALT 0xE011 +#define KEY_RWIN 0xE027 +#define KEY_MENU 0xE02F +#define KEY_RCTRL 0xE014 +#define KEY_SCRLCK 0x7E /* scroll lock */ + +/** + * Keypad + */ +#define KEYP_NUMLCK 0x77 +#define KEYP_SLASH 0xE04A +#define KEYP_ASTERISK 0x7C +#define KEYP_MINUS 0x7B +#define KEYP_7 0x6C +#define KEYP_8 0x75 +#define KEYP_9 0x7D +#define KEYP_PLUS 0x79 +#define KEYP_4 0x6B +#define KEYP_5 0x73 +#define KEYP_6 0x74 +#define KEYP_1 0x69 +#define KEYP_2 0x72 +#define KEYP_3 0x7A +#define KEYP_ENTER 0xE05A +#define KEYP_0 0x70 +#define KEYP_PERIOD 0x71 + +/** + * Insert, Home, Page Up cluster + */ +#define KEY_INSERT 0xE070 +#define KEY_HOME 0xE06C +#define KEY_PGUP 0xE07D +#define KEY_DEL 0xE071 +#define KEY_END 0xE069 +#define KEY_PGDOWN 0xE07A + +/** + * Arrow key cluster + */ +#define KEY_UP 0xE075 +#define KEY_LEFT 0xE06B +#define KEY_DOWN 0xE072 +#define KEY_RIGHT 0xE074 + +/** + * FIXME: Experimental + */ +#define KEY_PRTSCR 0xE012E07C /* print screen */ +#define KEY_PAUSE 0xE11477E1F014F077 /* pause/break */ + +#endif /* defined(__KB_IBM_PC_AT) */ + +#ifdef __KB_IBM_PS2 +/** + * Set 1 Scancodes + * + * IBM PC XT + * + * __KB_IBM_PS2 must be defined to use these + */ +#define KEY_ESC 0x08 +#define KEY_F1 0x07 +#define KEY_F2 0x0F +#define KEY_F3 0x17 +#define KEY_F4 0x1F +#define KEY_F5 0x27 +#define KEY_F6 0x2F +#define KEY_F7 0x37 +#define KEY_F8 0x3F +#define KEY_F9 0x47 +#define KEY_F10 0x4F +#define KEY_F11 0x56 +#define KEY_F12 0x5E +#define KEY_TILDA 0x0E +#define KEY_1 0x16 +#define KEY_2 0x1E +#define KEY_3 0x26 +#define KEY_4 0x25 +#define KEY_5 0x2E +#define KEY_6 0x36 +#define KEY_7 0x3D +#define KEY_8 0x3E +#define KEY_9 0x46 +#define KEY_0 0x45 +#define KEY_MINUS 0x4E +#define KEY_PLUS 0x55 +#define KEY_BKSLASH 0x5C +#define KEY_BKSPACE 0x66 +#define KEY_TAB 0x0D +#define KEY_Q 0x15 +#define KEY_W 0x1D +#define KEY_E 0x24 +#define KEY_R 0x2D +#define KEY_T 0x2C +#define KEY_Y 0x35 +#define KEY_U 0x3C +#define KEY_I 0x43 +#define KEY_O 0x44 +#define KEY_P 0x4D +#define KEY_LBRACKET 0x54 +#define KEY_RBRACKET 0x5B +#define KEY_ENTER 0x5A +#define KEY_CAPS 0x14 +#define KEY_A 0x1C +#define KEY_S 0x1B +#define KEY_D 0x23 +#define KEY_F 0x2B +#define KEY_G 0x34 +#define KEY_H 0x33 +#define KEY_J 0x3B +#define KEY_K 0x42 +#define KEY_L 0x4B +#define KEY_SEMICOLON 0x4C +#define KEY_QUOTE 0x52 +#define KEY_LSHIFT 0x12 +#define KEY_Z 0x1A +#define KEY_X 0x22 +#define KEY_C 0x21 +#define KEY_V 0x2A +#define KEY_B 0x32 +#define KEY_N 0x31 +#define KEY_M 0x3A +#define KEY_COMMA 0x41 +#define KEY_PERIOD 0x49 +#define KEY_SLASH 0x4A +#define KEY_RSHIFT 0x59 +#define KEY_LCTRL 0x11 +#define KEY_LWIN 0x8B +#define KEY_LALT 0x19 +#define KEY_SPACE 0x29 +#define KEY_RALT 0x39 +#define KEY_RWIN 0x8C +#define KEY_MENU 0x8D +#define KEY_RCTRL 0x58 +#define KEY_SCRLCK 0x5F /* scroll lock */ +#define KEY_PRTSCR 0x57 /* print screen */ +#define KEY_PAUSE 0x62 /* pause/break */ + +/** + * Keypad + */ +#define KEYP_NUMLCK 0x76 +#define KEYP_SLASH 0x77 +#define KEYP_ASTERISK 0x7E +#define KEYP_MINUS 0x84 +#define KEYP_7 0x6C +#define KEYP_8 0x75 +#define KEYP_9 0x7D +#define KEYP_PLUS 0x7C +#define KEYP_4 0x6B +#define KEYP_5 0x73 +#define KEYP_6 0x74 +#define KEYP_1 0x69 +#define KEYP_2 0x72 +#define KEYP_3 0x7A +#define KEYP_ENTER 0x79 +#define KEYP_0 0x70 +#define KEYP_PERIOD 0x71 + +/** + * Insert, Home, Page Up cluster + */ +#define KEY_INSERT 0x67 +#define KEY_HOME 0x6E +#define KEY_PGUP 0x6F +#define KEY_DEL 0x64 +#define KEY_END 0x65 +#define KEY_PGDOWN 0x6D + +/** + * Arrow key cluster + */ +#define KEY_UP 0x63 +#define KEY_LEFT 0x61 +#define KEY_DOWN 0x60 +#define KEY_RIGHT 0x6A + +#endif /* defined(__KB_IBM_PS2) */ + +#endif /* ! _KEYBOARD_H */ diff --git a/Dump/hybos/include/keymap.h b/Dump/hybos/include/keymap.h index ae39ba0..0194ba8 100644 --- a/Dump/hybos/include/keymap.h +++ b/Dump/hybos/include/keymap.h @@ -1,142 +1,142 @@ -/* keymap.h - defines for keymapping Author: Marcus Hampel - */ -#ifndef _SYS__KEYMAP_H -#define _SYS__KEYMAP_H - -#define C(c) ((c) & 0x1F) /* Map to control code */ -#define A(c) ((c) | 0x80) /* Set eight bit (ALT) */ -#define CA(c) A(C(c)) /* Control-Alt */ -#define L(c) ((c) | HASCAPS) /* Add "Caps Lock has effect" attribute */ - -#define EXT 0x0100 /* Normal function keys */ -#define CTRL 0x0200 /* Control key */ -#define SHIFT 0x0400 /* Shift key */ -#define ALT 0x0800 /* Alternate key */ -#define EXTKEY 0x1000 /* extended keycode */ -#define HASCAPS 0x8000 /* Caps Lock has effect */ - -/* Numeric keypad */ -#define HOME (0x01 + EXT) -#define END (0x02 + EXT) -#define UP (0x03 + EXT) -#define DOWN (0x04 + EXT) -#define LEFT (0x05 + EXT) -#define RIGHT (0x06 + EXT) -#define PGUP (0x07 + EXT) -#define PGDN (0x08 + EXT) -#define MID (0x09 + EXT) -#define NMIN (0x0A + EXT) -#define PLUS (0x0B + EXT) -#define INSRT (0x0C + EXT) - -/* Alt + Numeric keypad */ -#define AHOME (0x01 + ALT) -#define AEND (0x02 + ALT) -#define AUP (0x03 + ALT) -#define ADOWN (0x04 + ALT) -#define ALEFT (0x05 + ALT) -#define ARIGHT (0x06 + ALT) -#define APGUP (0x07 + ALT) -#define APGDN (0x08 + ALT) -#define AMID (0x09 + ALT) -#define ANMIN (0x0A + ALT) -#define APLUS (0x0B + ALT) -#define AINSRT (0x0C + ALT) - -/* Ctrl + Numeric keypad */ -#define CHOME (0x01 + CTRL) -#define CEND (0x02 + CTRL) -#define CUP (0x03 + CTRL) -#define CDOWN (0x04 + CTRL) -#define CLEFT (0x05 + CTRL) -#define CRIGHT (0x06 + CTRL) -#define CPGUP (0x07 + CTRL) -#define CPGDN (0x08 + CTRL) -#define CMID (0x09 + CTRL) -#define CNMIN (0x0A + CTRL) -#define CPLUS (0x0B + CTRL) -#define CINSRT (0x0C + CTRL) - -/* Lock keys */ -#define CALOCK (0x0D + EXT) /* caps lock */ -#define NLOCK (0x0E + EXT) /* number lock */ -#define SLOCK (0x0F + EXT) /* scroll lock */ - -/* Function keys */ -#define F1 (0x10 + EXT) -#define F2 (0x11 + EXT) -#define F3 (0x12 + EXT) -#define F4 (0x13 + EXT) -#define F5 (0x14 + EXT) -#define F6 (0x15 + EXT) -#define F7 (0x16 + EXT) -#define F8 (0x17 + EXT) -#define F9 (0x18 + EXT) -#define F10 (0x19 + EXT) -#define F11 (0x1A + EXT) -#define F12 (0x1B + EXT) - -/* Alt+Fn */ -#define AF1 (0x10 + ALT) -#define AF2 (0x11 + ALT) -#define AF3 (0x12 + ALT) -#define AF4 (0x13 + ALT) -#define AF5 (0x14 + ALT) -#define AF6 (0x15 + ALT) -#define AF7 (0x16 + ALT) -#define AF8 (0x17 + ALT) -#define AF9 (0x18 + ALT) -#define AF10 (0x19 + ALT) -#define AF11 (0x1A + ALT) -#define AF12 (0x1B + ALT) - -/* Ctrl+Fn */ -#define CF1 (0x10 + CTRL) -#define CF2 (0x11 + CTRL) -#define CF3 (0x12 + CTRL) -#define CF4 (0x13 + CTRL) -#define CF5 (0x14 + CTRL) -#define CF6 (0x15 + CTRL) -#define CF7 (0x16 + CTRL) -#define CF8 (0x17 + CTRL) -#define CF9 (0x18 + CTRL) -#define CF10 (0x19 + CTRL) -#define CF11 (0x1A + CTRL) -#define CF12 (0x1B + CTRL) - -/* Shift+Fn */ -#define SF1 (0x10 + SHIFT) -#define SF2 (0x11 + SHIFT) -#define SF3 (0x12 + SHIFT) -#define SF4 (0x13 + SHIFT) -#define SF5 (0x14 + SHIFT) -#define SF6 (0x15 + SHIFT) -#define SF7 (0x16 + SHIFT) -#define SF8 (0x17 + SHIFT) -#define SF9 (0x18 + SHIFT) -#define SF10 (0x19 + SHIFT) -#define SF11 (0x1A + SHIFT) -#define SF12 (0x1B + SHIFT) - -/* Alt+Shift+Fn */ -#define ASF1 (0x10 + ALT + SHIFT) -#define ASF2 (0x11 + ALT + SHIFT) -#define ASF3 (0x12 + ALT + SHIFT) -#define ASF4 (0x13 + ALT + SHIFT) -#define ASF5 (0x14 + ALT + SHIFT) -#define ASF6 (0x15 + ALT + SHIFT) -#define ASF7 (0x16 + ALT + SHIFT) -#define ASF8 (0x17 + ALT + SHIFT) -#define ASF9 (0x18 + ALT + SHIFT) -#define ASF10 (0x19 + ALT + SHIFT) -#define ASF11 (0x1A + ALT + SHIFT) -#define ASF12 (0x1B + ALT + SHIFT) - -#define MAP_COLS 6 /* Number of columns in keymap */ -#define NR_SCAN_CODES 0x80 /* Number of scan codes (rows in keymap) */ - -typedef unsigned short keymap_t[NR_SCAN_CODES * MAP_COLS]; - -#define KEY_MAGIC "KMAZ" /* Magic number of keymap file */ - -#endif /* _SYS__KEYMAP_H */ +/* keymap.h - defines for keymapping Author: Marcus Hampel + */ +#ifndef _SYS__KEYMAP_H +#define _SYS__KEYMAP_H + +#define C(c) ((c) & 0x1F) /* Map to control code */ +#define A(c) ((c) | 0x80) /* Set eight bit (ALT) */ +#define CA(c) A(C(c)) /* Control-Alt */ +#define L(c) ((c) | HASCAPS) /* Add "Caps Lock has effect" attribute */ + +#define EXT 0x0100 /* Normal function keys */ +#define CTRL 0x0200 /* Control key */ +#define SHIFT 0x0400 /* Shift key */ +#define ALT 0x0800 /* Alternate key */ +#define EXTKEY 0x1000 /* extended keycode */ +#define HASCAPS 0x8000 /* Caps Lock has effect */ + +/* Numeric keypad */ +#define HOME (0x01 + EXT) +#define END (0x02 + EXT) +#define UP (0x03 + EXT) +#define DOWN (0x04 + EXT) +#define LEFT (0x05 + EXT) +#define RIGHT (0x06 + EXT) +#define PGUP (0x07 + EXT) +#define PGDN (0x08 + EXT) +#define MID (0x09 + EXT) +#define NMIN (0x0A + EXT) +#define PLUS (0x0B + EXT) +#define INSRT (0x0C + EXT) + +/* Alt + Numeric keypad */ +#define AHOME (0x01 + ALT) +#define AEND (0x02 + ALT) +#define AUP (0x03 + ALT) +#define ADOWN (0x04 + ALT) +#define ALEFT (0x05 + ALT) +#define ARIGHT (0x06 + ALT) +#define APGUP (0x07 + ALT) +#define APGDN (0x08 + ALT) +#define AMID (0x09 + ALT) +#define ANMIN (0x0A + ALT) +#define APLUS (0x0B + ALT) +#define AINSRT (0x0C + ALT) + +/* Ctrl + Numeric keypad */ +#define CHOME (0x01 + CTRL) +#define CEND (0x02 + CTRL) +#define CUP (0x03 + CTRL) +#define CDOWN (0x04 + CTRL) +#define CLEFT (0x05 + CTRL) +#define CRIGHT (0x06 + CTRL) +#define CPGUP (0x07 + CTRL) +#define CPGDN (0x08 + CTRL) +#define CMID (0x09 + CTRL) +#define CNMIN (0x0A + CTRL) +#define CPLUS (0x0B + CTRL) +#define CINSRT (0x0C + CTRL) + +/* Lock keys */ +#define CALOCK (0x0D + EXT) /* caps lock */ +#define NLOCK (0x0E + EXT) /* number lock */ +#define SLOCK (0x0F + EXT) /* scroll lock */ + +/* Function keys */ +#define F1 (0x10 + EXT) +#define F2 (0x11 + EXT) +#define F3 (0x12 + EXT) +#define F4 (0x13 + EXT) +#define F5 (0x14 + EXT) +#define F6 (0x15 + EXT) +#define F7 (0x16 + EXT) +#define F8 (0x17 + EXT) +#define F9 (0x18 + EXT) +#define F10 (0x19 + EXT) +#define F11 (0x1A + EXT) +#define F12 (0x1B + EXT) + +/* Alt+Fn */ +#define AF1 (0x10 + ALT) +#define AF2 (0x11 + ALT) +#define AF3 (0x12 + ALT) +#define AF4 (0x13 + ALT) +#define AF5 (0x14 + ALT) +#define AF6 (0x15 + ALT) +#define AF7 (0x16 + ALT) +#define AF8 (0x17 + ALT) +#define AF9 (0x18 + ALT) +#define AF10 (0x19 + ALT) +#define AF11 (0x1A + ALT) +#define AF12 (0x1B + ALT) + +/* Ctrl+Fn */ +#define CF1 (0x10 + CTRL) +#define CF2 (0x11 + CTRL) +#define CF3 (0x12 + CTRL) +#define CF4 (0x13 + CTRL) +#define CF5 (0x14 + CTRL) +#define CF6 (0x15 + CTRL) +#define CF7 (0x16 + CTRL) +#define CF8 (0x17 + CTRL) +#define CF9 (0x18 + CTRL) +#define CF10 (0x19 + CTRL) +#define CF11 (0x1A + CTRL) +#define CF12 (0x1B + CTRL) + +/* Shift+Fn */ +#define SF1 (0x10 + SHIFT) +#define SF2 (0x11 + SHIFT) +#define SF3 (0x12 + SHIFT) +#define SF4 (0x13 + SHIFT) +#define SF5 (0x14 + SHIFT) +#define SF6 (0x15 + SHIFT) +#define SF7 (0x16 + SHIFT) +#define SF8 (0x17 + SHIFT) +#define SF9 (0x18 + SHIFT) +#define SF10 (0x19 + SHIFT) +#define SF11 (0x1A + SHIFT) +#define SF12 (0x1B + SHIFT) + +/* Alt+Shift+Fn */ +#define ASF1 (0x10 + ALT + SHIFT) +#define ASF2 (0x11 + ALT + SHIFT) +#define ASF3 (0x12 + ALT + SHIFT) +#define ASF4 (0x13 + ALT + SHIFT) +#define ASF5 (0x14 + ALT + SHIFT) +#define ASF6 (0x15 + ALT + SHIFT) +#define ASF7 (0x16 + ALT + SHIFT) +#define ASF8 (0x17 + ALT + SHIFT) +#define ASF9 (0x18 + ALT + SHIFT) +#define ASF10 (0x19 + ALT + SHIFT) +#define ASF11 (0x1A + ALT + SHIFT) +#define ASF12 (0x1B + ALT + SHIFT) + +#define MAP_COLS 6 /* Number of columns in keymap */ +#define NR_SCAN_CODES 0x80 /* Number of scan codes (rows in keymap) */ + +typedef unsigned short keymap_t[NR_SCAN_CODES * MAP_COLS]; + +#define KEY_MAGIC "KMAZ" /* Magic number of keymap file */ + +#endif /* _SYS__KEYMAP_H */ diff --git a/Dump/hybos/include/setjmp.h b/Dump/hybos/include/setjmp.h index b9dda41..ab44eed 100644 --- a/Dump/hybos/include/setjmp.h +++ b/Dump/hybos/include/setjmp.h @@ -1,24 +1,24 @@ -#ifndef __TL_SETJMP_H -#define __TL_SETJMP_H - -#ifdef __cplusplus -extern "C" -{ -#endif - -typedef struct -{ -/* setjmp() and longjmp() rely on the order of these registers, -so do not re-arrange them */ - unsigned edi, esi, ebp, esp, ebx, edx, ecx, eax; - unsigned eip, eflags; -} jmp_buf[1]; - -int setjmp(jmp_buf b); -void longjmp(jmp_buf b, int ret_val); - -#ifdef __cplusplus -} -#endif - -#endif +#ifndef __TL_SETJMP_H +#define __TL_SETJMP_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef struct +{ +/* setjmp() and longjmp() rely on the order of these registers, +so do not re-arrange them */ + unsigned edi, esi, ebp, esp, ebx, edx, ecx, eax; + unsigned eip, eflags; +} jmp_buf[1]; + +int setjmp(jmp_buf b); +void longjmp(jmp_buf b, int ret_val); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/Dump/hybos/include/signal.h b/Dump/hybos/include/signal.h index 6344bb5..178e074 100644 --- a/Dump/hybos/include/signal.h +++ b/Dump/hybos/include/signal.h @@ -1,52 +1,52 @@ -/** - * signal.h - */ - -#ifndef _SIGNAL_H -#define _SIGNAL_H - -typedef int sig_atomic_t; - -#define SIGHUP 1 /* hangup */ -#define SIGINT 2 /* interrupt (DEL) */ -#define SIGQUIT 3 /* quit (ASCII FS) */ -#define SIGILL 4 /* illegal instruction */ -#define SIGTRAP 5 /* trace trap (not reset when caught) */ -#define SIGABRT 6 /* IOT instruction */ -#define SIGBUS 7 -#define SIGEMT 7 -#define SIGFPE 8 /* floating point exception */ -#define SIGKILL 9 /* kill (cannot be caught or ignored) */ -#define SIGUSR1 10 /* user defined signal 1 */ -#define SIGSEGV 11 /* segmentation violation */ -#define SIGUSR2 12 /* user defined signal 2 */ -#define SIGPIPE 13 /* write on a pipe with no one to read it */ -#define SIGALRM 14 /* alarm clock */ -#define SIGTERM 15 /* software termination signal from kill */ - -/** - * For POSIX compliance - */ -#define SIGCHLD 17 /* child process terminated or stopped */ -#define SIGCONT 18 /* continue if stopped */ -#define SIGSTOP 19 /* stop signal */ -#define SIGTSTP 20 /* interactive stop signal */ -#define SIGTTIN 21 /* background process requesting read */ -#define SIGTTOU 22 /* background process requesting write */ - -#if 0 -#define SIG_ERR ((__sighandler_t) -1) /* error return */ -#define SIG_DFL ((__sighandler_t) 0) /* default signal handling */ -#define SIG_IGN ((__sighandler_t) 1) /* ignore signal */ -#endif /* 0 */ - -#define _NSIG 23 - -#if 0 -int raise(int sig); -__sighandler_t signal(int sig, __sighandler_t func); -int kill(pid_t pid, int sig); -#endif /* 0 */ - -#endif /* _SIGNAL_H */ - +/** + * signal.h + */ + +#ifndef _SIGNAL_H +#define _SIGNAL_H + +typedef int sig_atomic_t; + +#define SIGHUP 1 /* hangup */ +#define SIGINT 2 /* interrupt (DEL) */ +#define SIGQUIT 3 /* quit (ASCII FS) */ +#define SIGILL 4 /* illegal instruction */ +#define SIGTRAP 5 /* trace trap (not reset when caught) */ +#define SIGABRT 6 /* IOT instruction */ +#define SIGBUS 7 +#define SIGEMT 7 +#define SIGFPE 8 /* floating point exception */ +#define SIGKILL 9 /* kill (cannot be caught or ignored) */ +#define SIGUSR1 10 /* user defined signal 1 */ +#define SIGSEGV 11 /* segmentation violation */ +#define SIGUSR2 12 /* user defined signal 2 */ +#define SIGPIPE 13 /* write on a pipe with no one to read it */ +#define SIGALRM 14 /* alarm clock */ +#define SIGTERM 15 /* software termination signal from kill */ + +/** + * For POSIX compliance + */ +#define SIGCHLD 17 /* child process terminated or stopped */ +#define SIGCONT 18 /* continue if stopped */ +#define SIGSTOP 19 /* stop signal */ +#define SIGTSTP 20 /* interactive stop signal */ +#define SIGTTIN 21 /* background process requesting read */ +#define SIGTTOU 22 /* background process requesting write */ + +#if 0 +#define SIG_ERR ((__sighandler_t) -1) /* error return */ +#define SIG_DFL ((__sighandler_t) 0) /* default signal handling */ +#define SIG_IGN ((__sighandler_t) 1) /* ignore signal */ +#endif /* 0 */ + +#define _NSIG 23 + +#if 0 +int raise(int sig); +__sighandler_t signal(int sig, __sighandler_t func); +int kill(pid_t pid, int sig); +#endif /* 0 */ + +#endif /* _SIGNAL_H */ + diff --git a/Dump/hybos/include/signal.h~ b/Dump/hybos/include/signal.h~ index 56e3ab5..d70f0a6 100644 --- a/Dump/hybos/include/signal.h~ +++ b/Dump/hybos/include/signal.h~ @@ -1,50 +1,50 @@ -/** - * signal.h - */ - -#ifndef _SIGNAL_H -#define _SIGNAL_H - -typedef int sig_atomic_t; - -#define SIGHUP 1 /* hangup */ -#define SIGINT 2 /* interrupt (DEL) */ -#define SIGQUIT 3 /* quit (ASCII FS) */ -#define SIGILL 4 /* illegal instruction */ -#define SIGTRAP 5 /* trace trap (not reset when caught) */ -#define SIGABRT 6 /* IOT instruction */ -#define SIGBUS 7 -#define SIGEMT 7 -#define SIGFPE 8 /* floating point exception */ -#define SIGKILL 9 /* kill (cannot be caught or ignored) */ -#define SIGUSR1 10 /* user defined signal 1 */ -#define SIGSEGV 11 /* segmentation violation */ -#define SIGUSR2 12 /* user defined signal 2 */ -#define SIGPIPE 13 /* write on a pipe with no one to read it */ -#define SIGALRM 14 /* alarm clock */ -#define SIGTERM 15 /* software termination signal from kill */ - -/** - * For POSIX compliance - */ -#define SIGCHLD 17 /* child process terminated or stopped */ -#define SIGCONT 18 /* continue if stopped */ -#define SIGSTOP 19 /* stop signal */ -#define SIGTSTP 20 /* interactive stop signal */ -#define SIGTTIN 21 /* background process requesting read */ -#define SIGTTOU 22 /* background process requesting write */ - -#if 0 -#define SIG_ERR ((__sighandler_t) -1) /* error return */ -#define SIG_DFL ((__sighandler_t) 0) /* default signal handling */ -#define SIG_IGN ((__sighandler_t) 1) /* ignore signal */ -#endif /* 0 */ - -#define _NSIG 23 - -int raise(int sig); -__sighandler_t signal(int sig, __sighandler_t func); -int kill(pid_t pid, int sig); - -#endif /* _SIGNAL_H */ - +/** + * signal.h + */ + +#ifndef _SIGNAL_H +#define _SIGNAL_H + +typedef int sig_atomic_t; + +#define SIGHUP 1 /* hangup */ +#define SIGINT 2 /* interrupt (DEL) */ +#define SIGQUIT 3 /* quit (ASCII FS) */ +#define SIGILL 4 /* illegal instruction */ +#define SIGTRAP 5 /* trace trap (not reset when caught) */ +#define SIGABRT 6 /* IOT instruction */ +#define SIGBUS 7 +#define SIGEMT 7 +#define SIGFPE 8 /* floating point exception */ +#define SIGKILL 9 /* kill (cannot be caught or ignored) */ +#define SIGUSR1 10 /* user defined signal 1 */ +#define SIGSEGV 11 /* segmentation violation */ +#define SIGUSR2 12 /* user defined signal 2 */ +#define SIGPIPE 13 /* write on a pipe with no one to read it */ +#define SIGALRM 14 /* alarm clock */ +#define SIGTERM 15 /* software termination signal from kill */ + +/** + * For POSIX compliance + */ +#define SIGCHLD 17 /* child process terminated or stopped */ +#define SIGCONT 18 /* continue if stopped */ +#define SIGSTOP 19 /* stop signal */ +#define SIGTSTP 20 /* interactive stop signal */ +#define SIGTTIN 21 /* background process requesting read */ +#define SIGTTOU 22 /* background process requesting write */ + +#if 0 +#define SIG_ERR ((__sighandler_t) -1) /* error return */ +#define SIG_DFL ((__sighandler_t) 0) /* default signal handling */ +#define SIG_IGN ((__sighandler_t) 1) /* ignore signal */ +#endif /* 0 */ + +#define _NSIG 23 + +int raise(int sig); +__sighandler_t signal(int sig, __sighandler_t func); +int kill(pid_t pid, int sig); + +#endif /* _SIGNAL_H */ + diff --git a/Dump/hybos/include/stdarg.h b/Dump/hybos/include/stdarg.h index ea527d4..8394b00 100644 --- a/Dump/hybos/include/stdarg.h +++ b/Dump/hybos/include/stdarg.h @@ -1,35 +1,35 @@ -#ifndef __TL_STDARG_H -#define __TL_STDARG_H - -#ifdef __cplusplus -extern "C" -{ -#endif - -#include <_va_list.h> - -/* width of stack == width of int */ -#define STACKITEM int - -/* round up width of objects pushed on stack. The expression before the -& ensures that we get 0 for objects of size 0. */ -#define VA_SIZE(TYPE) \ - ((sizeof(TYPE) + sizeof(STACKITEM) - 1) \ - & ~(sizeof(STACKITEM) - 1)) - -/* &(LASTARG) points to the LEFTMOST argument of the function call -(before the ...) */ -#define va_start(AP, LASTARG) \ - (AP=((va_list)&(LASTARG) + VA_SIZE(LASTARG))) - -#define va_end(AP) /* nothing */ - -#define va_arg(AP, TYPE) \ - (AP += VA_SIZE(TYPE), *((TYPE *)(AP - VA_SIZE(TYPE)))) - -#ifdef __cplusplus -} -#endif - -#endif - +#ifndef __TL_STDARG_H +#define __TL_STDARG_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +#include <_va_list.h> + +/* width of stack == width of int */ +#define STACKITEM int + +/* round up width of objects pushed on stack. The expression before the +& ensures that we get 0 for objects of size 0. */ +#define VA_SIZE(TYPE) \ + ((sizeof(TYPE) + sizeof(STACKITEM) - 1) \ + & ~(sizeof(STACKITEM) - 1)) + +/* &(LASTARG) points to the LEFTMOST argument of the function call +(before the ...) */ +#define va_start(AP, LASTARG) \ + (AP=((va_list)&(LASTARG) + VA_SIZE(LASTARG))) + +#define va_end(AP) /* nothing */ + +#define va_arg(AP, TYPE) \ + (AP += VA_SIZE(TYPE), *((TYPE *)(AP - VA_SIZE(TYPE)))) + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/Dump/hybos/include/stdbool.h b/Dump/hybos/include/stdbool.h index e3f2b22..05084b9 100644 --- a/Dump/hybos/include/stdbool.h +++ b/Dump/hybos/include/stdbool.h @@ -1,6 +1,6 @@ -#ifndef _STDBOOL_H -#define _STDBOOL_H - -typedef enum {false = 0, true = !0} bool; - -#endif /* !defined(_STDBOOL_H) */ +#ifndef _STDBOOL_H +#define _STDBOOL_H + +typedef enum {false = 0, true = !0} bool; + +#endif /* !defined(_STDBOOL_H) */ diff --git a/Dump/hybos/include/stddef.h b/Dump/hybos/include/stddef.h index f1a5135..049d0e7 100644 --- a/Dump/hybos/include/stddef.h +++ b/Dump/hybos/include/stddef.h @@ -1,11 +1,11 @@ -#ifndef _STDDEF_H -#define _STDDEF_H - -#define NULL ((void *)0) - -#ifndef _SIZE_T -#define _SIZE_T -typedef unsigned int size_t; -#endif - -#endif /* _STDDEF_H */ +#ifndef _STDDEF_H +#define _STDDEF_H + +#define NULL ((void *)0) + +#ifndef _SIZE_T +#define _SIZE_T +typedef unsigned int size_t; +#endif + +#endif /* _STDDEF_H */ diff --git a/Dump/hybos/include/stdint.h b/Dump/hybos/include/stdint.h index 744183f..02e7645 100644 --- a/Dump/hybos/include/stdint.h +++ b/Dump/hybos/include/stdint.h @@ -1,166 +1,166 @@ -#ifndef _STDINT_H -#define _STDINT_H - -/* 7.18.1.1 Exact-width integer types */ -typedef signed char int8_t; -typedef unsigned char uint8_t; -typedef short int16_t; -typedef unsigned short uint16_t; -typedef int int32_t; -typedef unsigned uint32_t; -typedef long long int64_t; -typedef unsigned long long uint64_t; - -/* 7.18.1.2 Minimum-width integer types */ -typedef signed char int_least8_t; -typedef unsigned char uint_least8_t; -typedef short int_least16_t; -typedef unsigned short uint_least16_t; -typedef int int_least32_t; -typedef unsigned uint_least32_t; -typedef long long int_least64_t; -typedef unsigned long long uint_least64_t; - -/* 7.18.1.3 Fastest minimum-width integer types - * Not actually guaranteed to be fastest for all purposes - * Here we use the exact-width types for 8 and 16-bit ints. - */ -typedef char int_fast8_t; -typedef unsigned char uint_fast8_t; -typedef short int_fast16_t; -typedef unsigned short uint_fast16_t; -typedef int int_fast32_t; -typedef unsigned int uint_fast32_t; -typedef long long int_fast64_t; -typedef unsigned long long uint_fast64_t; - -/* 7.18.1.4 Integer types capable of holding object pointers */ -typedef int intptr_t; -typedef unsigned uintptr_t; - -/* 7.18.1.5 Greatest-width integer types */ -typedef long long intmax_t; -typedef unsigned long long uintmax_t; - -/* 7.18.2 Limits of specified-width integer types */ -#if !defined ( __cplusplus) || defined (__STDC_LIMIT_MACROS) - -/* 7.18.2.1 Limits of exact-width integer types */ -#define INT8_MIN (-128) -#define INT16_MIN (-32768) -#define INT32_MIN (-2147483647 - 1) -#define INT64_MIN (-9223372036854775807LL - 1) - -#define INT8_MAX 127 -#define INT16_MAX 32767 -#define INT32_MAX 2147483647 -#define INT64_MAX 9223372036854775807LL - -#define UINT8_MAX 0xff /* 255U */ -#define UINT16_MAX 0xffff /* 65535U */ -#define UINT32_MAX 0xffffffff /* 4294967295U */ -#define UINT64_MAX 0xffffffffffffffffULL /* 18446744073709551615ULL */ - -/* 7.18.2.2 Limits of minimum-width integer types */ -#define INT_LEAST8_MIN INT8_MIN -#define INT_LEAST16_MIN INT16_MIN -#define INT_LEAST32_MIN INT32_MIN -#define INT_LEAST64_MIN INT64_MIN - -#define INT_LEAST8_MAX INT8_MAX -#define INT_LEAST16_MAX INT16_MAX -#define INT_LEAST32_MAX INT32_MAX -#define INT_LEAST64_MAX INT64_MAX - -#define UINT_LEAST8_MAX UINT8_MAX -#define UINT_LEAST16_MAX UINT16_MAX -#define UINT_LEAST32_MAX UINT32_MAX -#define UINT_LEAST64_MAX UINT64_MAX - -/* 7.18.2.3 Limits of fastest minimum-width integer types */ -#define INT_FAST8_MIN INT8_MIN -#define INT_FAST16_MIN INT16_MIN -#define INT_FAST32_MIN INT32_MIN -#define INT_FAST64_MIN INT64_MIN - -#define INT_FAST8_MAX INT8_MAX -#define INT_FAST16_MAX INT16_MAX -#define INT_FAST32_MAX INT32_MAX -#define INT_FAST64_MAX INT64_MAX - -#define UINT_FAST8_MAX UINT8_MAX -#define UINT_FAST16_MAX UINT16_MAX -#define UINT_FAST32_MAX UINT32_MAX -#define UINT_FAST64_MAX UINT64_MAX - -/* 7.18.2.4 Limits of integer types capable of holding - object pointers */ -#define INTPTR_MIN INT32_MIN -#define INTPTR_MAX INT32_MAX -#define UINTPTR_MAX UINT32_MAX - -/* 7.18.2.5 Limits of greatest-width integer types */ -#define INTMAX_MIN INT64_MIN -#define INTMAX_MAX INT64_MAX -#define UINTMAX_MAX UINT64_MAX - -/* 7.18.3 Limits of other integer types */ -#define PTRDIFF_MIN INT32_MIN -#define PTRDIFF_MAX INT32_MAX - -#define SIG_ATOMIC_MIN INT32_MIN -#define SIG_ATOMIC_MAX INT32_MAX - -#define SIZE_MAX UINT32_MAX - -#ifndef WCHAR_MIN /* also in wchar.h */ -#define WCHAR_MIN 0 -#define WCHAR_MAX ((wchar_t)-1) /* UINT16_MAX */ -#endif - -/* - * wint_t is unsigned short for compatibility with MS runtime - */ -#define WINT_MIN 0 -#define WINT_MAX ((wint_t)-1) /* UINT16_MAX */ - -#endif /* !defined ( __cplusplus) || defined __STDC_LIMIT_MACROS */ - - -/* 7.18.4 Macros for integer constants */ -#if !defined ( __cplusplus) || defined (__STDC_CONSTANT_MACROS) - -/* 7.18.4.1 Macros for minimum-width integer constants - - Accoding to Douglas Gwyn : - "This spec was changed in ISO/IEC 9899:1999 TC1; in ISO/IEC - 9899:1999 as initially published, the expansion was required - to be an integer constant of precisely matching type, which - is impossible to accomplish for the shorter types on most - platforms, because C99 provides no standard way to designate - an integer constant with width less than that of type int. - TC1 changed this to require just an integer constant - *expression* with *promoted* type." - - The trick used here is from Clive D W Feather. -*/ - -#define INT8_C(val) (INT_LEAST8_MAX-INT_LEAST8_MAX+(val)) -#define INT16_C(val) (INT_LEAST16_MAX-INT_LEAST16_MAX+(val)) -#define INT32_C(val) (INT_LEAST32_MAX-INT_LEAST32_MAX+(val)) -/* The 'trick' doesn't work in C89 for long long because, without - suffix, (val) will be evaluated as int, not intmax_t */ -#define INT64_C(val) val##LL - -#define UINT8_C(val) (UINT_LEAST8_MAX-UINT_LEAST8_MAX+(val)) -#define UINT16_C(val) (UINT_LEAST16_MAX-UINT_LEAST16_MAX+(val)) -#define UINT32_C(val) (UINT_LEAST32_MAX-UINT_LEAST32_MAX+(val)) -#define UINT64_C(val) val##ULL - -/* 7.18.4.2 Macros for greatest-width integer constants */ -#define INTMAX_C(val) val##LL -#define UINTMAX_C(val) val##ULL - -#endif /* !defined ( __cplusplus) || defined __STDC_CONSTANT_MACROS */ - -#endif /* !defined(_STDINT_H) */ +#ifndef _STDINT_H +#define _STDINT_H + +/* 7.18.1.1 Exact-width integer types */ +typedef signed char int8_t; +typedef unsigned char uint8_t; +typedef short int16_t; +typedef unsigned short uint16_t; +typedef int int32_t; +typedef unsigned uint32_t; +typedef long long int64_t; +typedef unsigned long long uint64_t; + +/* 7.18.1.2 Minimum-width integer types */ +typedef signed char int_least8_t; +typedef unsigned char uint_least8_t; +typedef short int_least16_t; +typedef unsigned short uint_least16_t; +typedef int int_least32_t; +typedef unsigned uint_least32_t; +typedef long long int_least64_t; +typedef unsigned long long uint_least64_t; + +/* 7.18.1.3 Fastest minimum-width integer types + * Not actually guaranteed to be fastest for all purposes + * Here we use the exact-width types for 8 and 16-bit ints. + */ +typedef char int_fast8_t; +typedef unsigned char uint_fast8_t; +typedef short int_fast16_t; +typedef unsigned short uint_fast16_t; +typedef int int_fast32_t; +typedef unsigned int uint_fast32_t; +typedef long long int_fast64_t; +typedef unsigned long long uint_fast64_t; + +/* 7.18.1.4 Integer types capable of holding object pointers */ +typedef int intptr_t; +typedef unsigned uintptr_t; + +/* 7.18.1.5 Greatest-width integer types */ +typedef long long intmax_t; +typedef unsigned long long uintmax_t; + +/* 7.18.2 Limits of specified-width integer types */ +#if !defined ( __cplusplus) || defined (__STDC_LIMIT_MACROS) + +/* 7.18.2.1 Limits of exact-width integer types */ +#define INT8_MIN (-128) +#define INT16_MIN (-32768) +#define INT32_MIN (-2147483647 - 1) +#define INT64_MIN (-9223372036854775807LL - 1) + +#define INT8_MAX 127 +#define INT16_MAX 32767 +#define INT32_MAX 2147483647 +#define INT64_MAX 9223372036854775807LL + +#define UINT8_MAX 0xff /* 255U */ +#define UINT16_MAX 0xffff /* 65535U */ +#define UINT32_MAX 0xffffffff /* 4294967295U */ +#define UINT64_MAX 0xffffffffffffffffULL /* 18446744073709551615ULL */ + +/* 7.18.2.2 Limits of minimum-width integer types */ +#define INT_LEAST8_MIN INT8_MIN +#define INT_LEAST16_MIN INT16_MIN +#define INT_LEAST32_MIN INT32_MIN +#define INT_LEAST64_MIN INT64_MIN + +#define INT_LEAST8_MAX INT8_MAX +#define INT_LEAST16_MAX INT16_MAX +#define INT_LEAST32_MAX INT32_MAX +#define INT_LEAST64_MAX INT64_MAX + +#define UINT_LEAST8_MAX UINT8_MAX +#define UINT_LEAST16_MAX UINT16_MAX +#define UINT_LEAST32_MAX UINT32_MAX +#define UINT_LEAST64_MAX UINT64_MAX + +/* 7.18.2.3 Limits of fastest minimum-width integer types */ +#define INT_FAST8_MIN INT8_MIN +#define INT_FAST16_MIN INT16_MIN +#define INT_FAST32_MIN INT32_MIN +#define INT_FAST64_MIN INT64_MIN + +#define INT_FAST8_MAX INT8_MAX +#define INT_FAST16_MAX INT16_MAX +#define INT_FAST32_MAX INT32_MAX +#define INT_FAST64_MAX INT64_MAX + +#define UINT_FAST8_MAX UINT8_MAX +#define UINT_FAST16_MAX UINT16_MAX +#define UINT_FAST32_MAX UINT32_MAX +#define UINT_FAST64_MAX UINT64_MAX + +/* 7.18.2.4 Limits of integer types capable of holding + object pointers */ +#define INTPTR_MIN INT32_MIN +#define INTPTR_MAX INT32_MAX +#define UINTPTR_MAX UINT32_MAX + +/* 7.18.2.5 Limits of greatest-width integer types */ +#define INTMAX_MIN INT64_MIN +#define INTMAX_MAX INT64_MAX +#define UINTMAX_MAX UINT64_MAX + +/* 7.18.3 Limits of other integer types */ +#define PTRDIFF_MIN INT32_MIN +#define PTRDIFF_MAX INT32_MAX + +#define SIG_ATOMIC_MIN INT32_MIN +#define SIG_ATOMIC_MAX INT32_MAX + +#define SIZE_MAX UINT32_MAX + +#ifndef WCHAR_MIN /* also in wchar.h */ +#define WCHAR_MIN 0 +#define WCHAR_MAX ((wchar_t)-1) /* UINT16_MAX */ +#endif + +/* + * wint_t is unsigned short for compatibility with MS runtime + */ +#define WINT_MIN 0 +#define WINT_MAX ((wint_t)-1) /* UINT16_MAX */ + +#endif /* !defined ( __cplusplus) || defined __STDC_LIMIT_MACROS */ + + +/* 7.18.4 Macros for integer constants */ +#if !defined ( __cplusplus) || defined (__STDC_CONSTANT_MACROS) + +/* 7.18.4.1 Macros for minimum-width integer constants + + Accoding to Douglas Gwyn : + "This spec was changed in ISO/IEC 9899:1999 TC1; in ISO/IEC + 9899:1999 as initially published, the expansion was required + to be an integer constant of precisely matching type, which + is impossible to accomplish for the shorter types on most + platforms, because C99 provides no standard way to designate + an integer constant with width less than that of type int. + TC1 changed this to require just an integer constant + *expression* with *promoted* type." + + The trick used here is from Clive D W Feather. +*/ + +#define INT8_C(val) (INT_LEAST8_MAX-INT_LEAST8_MAX+(val)) +#define INT16_C(val) (INT_LEAST16_MAX-INT_LEAST16_MAX+(val)) +#define INT32_C(val) (INT_LEAST32_MAX-INT_LEAST32_MAX+(val)) +/* The 'trick' doesn't work in C89 for long long because, without + suffix, (val) will be evaluated as int, not intmax_t */ +#define INT64_C(val) val##LL + +#define UINT8_C(val) (UINT_LEAST8_MAX-UINT_LEAST8_MAX+(val)) +#define UINT16_C(val) (UINT_LEAST16_MAX-UINT_LEAST16_MAX+(val)) +#define UINT32_C(val) (UINT_LEAST32_MAX-UINT_LEAST32_MAX+(val)) +#define UINT64_C(val) val##ULL + +/* 7.18.4.2 Macros for greatest-width integer constants */ +#define INTMAX_C(val) val##LL +#define UINTMAX_C(val) val##ULL + +#endif /* !defined ( __cplusplus) || defined __STDC_CONSTANT_MACROS */ + +#endif /* !defined(_STDINT_H) */ diff --git a/Dump/hybos/include/stdio.h b/Dump/hybos/include/stdio.h index 12bbb89..54f5ada 100644 --- a/Dump/hybos/include/stdio.h +++ b/Dump/hybos/include/stdio.h @@ -1,79 +1,79 @@ -/** - * stdio.h - * - * Input/output functions - */ - -#ifndef _STDIO_H -#define _STDIO_H - -#define SEEK_SET 0 -#define SEEK_CUR 1 -#define SEEK_END 2 - -#ifndef _NULL -#define NULL ((void *)0) -#endif -#define EOF (-1) - -#define FOPEN_MAX 20 -#define FILENAME_MAX 14 -#define TMP_MAX 999 - -typedef long int fpos_t; - -#ifndef _SIZE_T -#define _SIZE_T -typedef unsigned int size_t; -#endif - -/*int remove(const char *_filename);*/ -/*int rename(const char *_old, const char *_new);*/ -/*FILE *tmpfile(void);*/ -/*char *tmpnam(char *_s);*/ -/*int fclose(FILE *_stream);*/ -/*int fflush(FILE *_stream);*/ -/*FILE *fopen(const char *_filename, const char *_mode);*/ -/*FILE *freopen(const char *_filename, const char *_mode, FILE *_stream);*/ -/*void setbuf(FILE *_stream, char *_buf);*/ -/*int setvbuf(FILE *_stream, char *_buf, int _mode, size_t _size);*/ -/*int fprintf(FILE *_stream, const char *_format, ...);*/ -/*int printf(const char *fmt, ...);*/ -void printf(const char *format, ...); -int sprintf(char *s, const char *format, ...); -/*int vfprintf(FILE *_stream, const char *_format, char *_arg);*/ -/*int vprintf(const char *_format, char *_arg);*/ -int vsprintf(char *s, const char *format, ...); -/*int fscanf(FILE *_stream, const char *_format, ...);*/ -/*int scanf(const char *_format, ...);*/ -/*int sscanf(const char *_s, const char *_format, ...);*/ -/*#define vfscanf _doscan*/ -/*int vfscanf(FILE *_stream, const char *_format, char *_arg);*/ -/*int vscanf(const char *_format, char *_arg);*/ -/*int vsscanf(const char *_s, const char *_format, char *_arg);*/ -/*int fgetc(FILE *_stream);*/ -/*char *fgets(char *_s, int _n, FILE *_stream);*/ -/*int fputc(int _c, FILE *_stream);*/ -/*int fputs(const char *_s, FILE *_stream);*/ -/*int getc(FILE *_stream);*/ -/*int getchar(void);*/ -/*char *gets(char *_s);*/ -/*int putc(int _c, FILE *_stream);*/ -/*int putchar(int _c);*/ -/*int puts(const char *_s);*/ -/*int ungetc(int _c, FILE *_stream);*/ -/*size_t fread(void *_ptr, size_t _size, size_t _nmemb, FILE *_stream);*/ -/*size_t fwrite(const void *_ptr, size_t _size, size_t _nmemb, FILE *_stream);*/ -/*int fgetpos(FILE *_stream, fpos_t *_pos);*/ -/*int fseek(FILE *_stream, long _offset, int _whence);*/ -/*int fsetpos(FILE *_stream, fpos_t *_pos);*/ -/*long ftell(FILE *_stream);*/ -/*void rewind(FILE *_stream);*/ -/*void clearerr(FILE *_stream);*/ -/*int feof(FILE *_stream);*/ -/*int ferror(FILE *_stream);*/ -/*void perror(const char *_s);*/ -/*int __fillbuf(FILE *_stream);*/ -/*int __flushbuf(int _c, FILE *_stream);*/ - -#endif /* _STDIO_H */ +/** + * stdio.h + * + * Input/output functions + */ + +#ifndef _STDIO_H +#define _STDIO_H + +#define SEEK_SET 0 +#define SEEK_CUR 1 +#define SEEK_END 2 + +#ifndef _NULL +#define NULL ((void *)0) +#endif +#define EOF (-1) + +#define FOPEN_MAX 20 +#define FILENAME_MAX 14 +#define TMP_MAX 999 + +typedef long int fpos_t; + +#ifndef _SIZE_T +#define _SIZE_T +typedef unsigned int size_t; +#endif + +/*int remove(const char *_filename);*/ +/*int rename(const char *_old, const char *_new);*/ +/*FILE *tmpfile(void);*/ +/*char *tmpnam(char *_s);*/ +/*int fclose(FILE *_stream);*/ +/*int fflush(FILE *_stream);*/ +/*FILE *fopen(const char *_filename, const char *_mode);*/ +/*FILE *freopen(const char *_filename, const char *_mode, FILE *_stream);*/ +/*void setbuf(FILE *_stream, char *_buf);*/ +/*int setvbuf(FILE *_stream, char *_buf, int _mode, size_t _size);*/ +/*int fprintf(FILE *_stream, const char *_format, ...);*/ +/*int printf(const char *fmt, ...);*/ +void printf(const char *format, ...); +int sprintf(char *s, const char *format, ...); +/*int vfprintf(FILE *_stream, const char *_format, char *_arg);*/ +/*int vprintf(const char *_format, char *_arg);*/ +int vsprintf(char *s, const char *format, ...); +/*int fscanf(FILE *_stream, const char *_format, ...);*/ +/*int scanf(const char *_format, ...);*/ +/*int sscanf(const char *_s, const char *_format, ...);*/ +/*#define vfscanf _doscan*/ +/*int vfscanf(FILE *_stream, const char *_format, char *_arg);*/ +/*int vscanf(const char *_format, char *_arg);*/ +/*int vsscanf(const char *_s, const char *_format, char *_arg);*/ +/*int fgetc(FILE *_stream);*/ +/*char *fgets(char *_s, int _n, FILE *_stream);*/ +/*int fputc(int _c, FILE *_stream);*/ +/*int fputs(const char *_s, FILE *_stream);*/ +/*int getc(FILE *_stream);*/ +/*int getchar(void);*/ +/*char *gets(char *_s);*/ +/*int putc(int _c, FILE *_stream);*/ +/*int putchar(int _c);*/ +/*int puts(const char *_s);*/ +/*int ungetc(int _c, FILE *_stream);*/ +/*size_t fread(void *_ptr, size_t _size, size_t _nmemb, FILE *_stream);*/ +/*size_t fwrite(const void *_ptr, size_t _size, size_t _nmemb, FILE *_stream);*/ +/*int fgetpos(FILE *_stream, fpos_t *_pos);*/ +/*int fseek(FILE *_stream, long _offset, int _whence);*/ +/*int fsetpos(FILE *_stream, fpos_t *_pos);*/ +/*long ftell(FILE *_stream);*/ +/*void rewind(FILE *_stream);*/ +/*void clearerr(FILE *_stream);*/ +/*int feof(FILE *_stream);*/ +/*int ferror(FILE *_stream);*/ +/*void perror(const char *_s);*/ +/*int __fillbuf(FILE *_stream);*/ +/*int __flushbuf(int _c, FILE *_stream);*/ + +#endif /* _STDIO_H */ diff --git a/Dump/hybos/include/stdlib.h b/Dump/hybos/include/stdlib.h index 477873e..f26dce9 100644 --- a/Dump/hybos/include/stdlib.h +++ b/Dump/hybos/include/stdlib.h @@ -1,58 +1,58 @@ -/** - * stdlib.h - * - * Defines certain common macros, types, and functions - */ - -#ifndef _STDLIB_H -#define _STDLIB_H - -#ifndef _NULL -#define NULL ((void *)0) -#endif - -#define EXIT_FAILURE 1 /* standard error returned from exit() */ -#define EXIT_SUCCESS 0 /* successfull return from exit() */ -#define RAND_MAX 32767 /* largest value generated by rand() */ -#define MB_CUR_MAX 1 /* maximum value of multibyte character */ - -#ifndef _SIZE_T -#define _SIZE_T -typedef unsigned int size_t; -#endif - -#ifndef _WCHAR_T -#define _WCHAR_T -typedef char wchar_t; -#endif - -/*void abort(void);*/ -int abs(int number); -/*int atexit(void (*_func)(void));*/ -/*double atof(const char *_nptr);*/ -int atoi(const char *nptr); -/*long atol(const char *_nptr);*/ -/*void *calloc(size_t _nmemb, size_t _size);*/ -/*div_t div(int _numer, int _denom);*/ -/*void exit(int _status);*/ -void free(void *blk); -/*char *getenv(const char *_name);*/ -/*long labs(long _j);*/ -/*ldiv_t ldiv(long _numer, long _denom);*/ -void *malloc(size_t _size); -/*int mblen(const char *_s, size_t _n);*/ -/*size_t mbstowcs(wchar_t *_pwcs, const char *_s, size_t _n);*/ -/*int mbtowc(wchar_t *_pwc, const char *_s, size_t _n);*/ -void *realloc(void *blk, size_t size); -/*double strtod(const char *_nptr, char **_endptr);*/ -/*long strtol(const char *_nptr, char **_endptr, int _base);*/ -/*int system(const char *_string);*/ -/*size_t wcstombs(char *_s, const wchar_t *_pwcs, size_t _n);*/ -/*int wctomb(char *_s, wchar_t _wchar);*/ -/*void *bsearch(const void *_key, const void *_base, size_t _nmemb, size_t _size, int (*compar) (const void *, const void *));*/ -/*void qsort(void *_base, size_t _nmemb, size_t _size, int (*compar) (const void *, const void *));*/ -int rand(void); -void srand(unsigned int seed); -/*unsigned long int strtoul(const char *_nptr, char **_endptr, int _base);*/ - -#endif /* _STDLIB_H */ +/** + * stdlib.h + * + * Defines certain common macros, types, and functions + */ + +#ifndef _STDLIB_H +#define _STDLIB_H + +#ifndef _NULL +#define NULL ((void *)0) +#endif + +#define EXIT_FAILURE 1 /* standard error returned from exit() */ +#define EXIT_SUCCESS 0 /* successfull return from exit() */ +#define RAND_MAX 32767 /* largest value generated by rand() */ +#define MB_CUR_MAX 1 /* maximum value of multibyte character */ + +#ifndef _SIZE_T +#define _SIZE_T +typedef unsigned int size_t; +#endif + +#ifndef _WCHAR_T +#define _WCHAR_T +typedef char wchar_t; +#endif + +/*void abort(void);*/ +int abs(int number); +/*int atexit(void (*_func)(void));*/ +/*double atof(const char *_nptr);*/ +int atoi(const char *nptr); +/*long atol(const char *_nptr);*/ +/*void *calloc(size_t _nmemb, size_t _size);*/ +/*div_t div(int _numer, int _denom);*/ +/*void exit(int _status);*/ +void free(void *blk); +/*char *getenv(const char *_name);*/ +/*long labs(long _j);*/ +/*ldiv_t ldiv(long _numer, long _denom);*/ +void *malloc(size_t _size); +/*int mblen(const char *_s, size_t _n);*/ +/*size_t mbstowcs(wchar_t *_pwcs, const char *_s, size_t _n);*/ +/*int mbtowc(wchar_t *_pwc, const char *_s, size_t _n);*/ +void *realloc(void *blk, size_t size); +/*double strtod(const char *_nptr, char **_endptr);*/ +/*long strtol(const char *_nptr, char **_endptr, int _base);*/ +/*int system(const char *_string);*/ +/*size_t wcstombs(char *_s, const wchar_t *_pwcs, size_t _n);*/ +/*int wctomb(char *_s, wchar_t _wchar);*/ +/*void *bsearch(const void *_key, const void *_base, size_t _nmemb, size_t _size, int (*compar) (const void *, const void *));*/ +/*void qsort(void *_base, size_t _nmemb, size_t _size, int (*compar) (const void *, const void *));*/ +int rand(void); +void srand(unsigned int seed); +/*unsigned long int strtoul(const char *_nptr, char **_endptr, int _base);*/ + +#endif /* _STDLIB_H */ diff --git a/Dump/hybos/include/string.h b/Dump/hybos/include/string.h index 8fa2767..2637730 100644 --- a/Dump/hybos/include/string.h +++ b/Dump/hybos/include/string.h @@ -1,26 +1,26 @@ -#ifndef __TL_STRING_H -#define __TL_STRING_H - -#ifdef __cplusplus -extern "C" -{ -#endif - -/*#include <_size_t.h>*/ -/*#include <_null.h>*/ -#include - -void *memcpy(void *dst_ptr, const void *src_ptr, size_t count); -void *memsetw(void *dst, int val, size_t count); -size_t strlen(const char *str); -int strcmp(const char * src, const char * dst); -int strncmp(const char * first, const char * last, size_t count); -char *strcpy(char *s, const char *t); -char *strncpy(char * dest, const char * source, size_t count); - -#ifdef __cplusplus -} -#endif - -#endif - +#ifndef __TL_STRING_H +#define __TL_STRING_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +/*#include <_size_t.h>*/ +/*#include <_null.h>*/ +#include + +void *memcpy(void *dst_ptr, const void *src_ptr, size_t count); +void *memsetw(void *dst, int val, size_t count); +size_t strlen(const char *str); +int strcmp(const char * src, const char * dst); +int strncmp(const char * first, const char * last, size_t count); +char *strcpy(char *s, const char *t); +char *strncpy(char * dest, const char * source, size_t count); + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/Dump/hybos/include/sys/dir.h b/Dump/hybos/include/sys/dir.h index 114d2bf..8c9e071 100644 --- a/Dump/hybos/include/sys/dir.h +++ b/Dump/hybos/include/sys/dir.h @@ -1,19 +1,19 @@ -#ifndef _DIR_H -#define _DIR_H - -/** - * Size of directory block - */ -#define DIRBLKSIZE 512 - -#ifndef DIRSIZ -#define DIRSIZ 14 -#endif - -typedef struct __DIR__DIRECT_ -{ - unsigned int d_ino; /* defined as __kernel_ino_t in posix_types.h */ - char d_name[DIRSIZ]; -} direct; - -#endif /* _DIR_H */ +#ifndef _DIR_H +#define _DIR_H + +/** + * Size of directory block + */ +#define DIRBLKSIZE 512 + +#ifndef DIRSIZ +#define DIRSIZ 14 +#endif + +typedef struct __DIR__DIRECT_ +{ + unsigned int d_ino; /* defined as __kernel_ino_t in posix_types.h */ + char d_name[DIRSIZ]; +} direct; + +#endif /* _DIR_H */ diff --git a/Dump/hybos/include/time.h b/Dump/hybos/include/time.h index 96b5c37..efcc0b3 100644 --- a/Dump/hybos/include/time.h +++ b/Dump/hybos/include/time.h @@ -1,52 +1,52 @@ -/** - * time.h - */ - -#ifndef _TIME_H -#define _TIME_H - -#define CLOCKS_PER_SEC 60 /* 60 Hz */ - -#ifndef NULL -#define NULL ((void *) 0) -#endif - -#ifndef _SIZE_T -#define _SIZE_T -typedef unsigned int size_t; -#endif - -#ifndef _TIME_T -#define _TIME_T -typedef long time_t; /* time in seconds since January 1, 1970 0000 GMT */ -#endif - -#ifndef _CLOCK_T -#define _CLOCK_T -typedef long clock_t; /* time in ticks since process started */ -#endif - -typedef struct __TIME_H_TIME -{ - int tm_sec; /* seconds after the minute [0, 59] */ - int tm_min; /* minutes after the hour [0, 59] */ - int tm_hour; /* hours since midnight [0, 23] */ - int tm_mday; /* day of the month [1, 31] */ - int tm_mon; /* months since January [0, 11] */ - int tm_year; /* years since 1900 */ - int tm_wday; /* days since Sunday [0, 6] */ - int tm_yday; /* days since January 1 [0, 365] */ - int tm_isdst; /* Daylight Saving Time flag */ -} dm, TIME; - -clock_t clock(void); -double difftime(time_t time1, time_t time0); -time_t mktime(struct tm *pTime); -time_t time(time_t *pTime); -char *asctime(const struct tm *pTime); -char *ctime(const time_t *pTimer); -struct tm *gmtime(const time_t *pTimer); -size_t strftime(char *s, size_t max, const char *format, const struct tm *pTime); - -#endif /* _TIME_H */ - +/** + * time.h + */ + +#ifndef _TIME_H +#define _TIME_H + +#define CLOCKS_PER_SEC 60 /* 60 Hz */ + +#ifndef NULL +#define NULL ((void *) 0) +#endif + +#ifndef _SIZE_T +#define _SIZE_T +typedef unsigned int size_t; +#endif + +#ifndef _TIME_T +#define _TIME_T +typedef long time_t; /* time in seconds since January 1, 1970 0000 GMT */ +#endif + +#ifndef _CLOCK_T +#define _CLOCK_T +typedef long clock_t; /* time in ticks since process started */ +#endif + +typedef struct __TIME_H_TIME +{ + int tm_sec; /* seconds after the minute [0, 59] */ + int tm_min; /* minutes after the hour [0, 59] */ + int tm_hour; /* hours since midnight [0, 23] */ + int tm_mday; /* day of the month [1, 31] */ + int tm_mon; /* months since January [0, 11] */ + int tm_year; /* years since 1900 */ + int tm_wday; /* days since Sunday [0, 6] */ + int tm_yday; /* days since January 1 [0, 365] */ + int tm_isdst; /* Daylight Saving Time flag */ +} dm, TIME; + +clock_t clock(void); +double difftime(time_t time1, time_t time0); +time_t mktime(struct tm *pTime); +time_t time(time_t *pTime); +char *asctime(const struct tm *pTime); +char *ctime(const time_t *pTimer); +struct tm *gmtime(const time_t *pTimer); +size_t strftime(char *s, size_t max, const char *format, const struct tm *pTime); + +#endif /* _TIME_H */ + diff --git a/Dump/hybos/include/x86.h b/Dump/hybos/include/x86.h index bb68769..4373723 100644 --- a/Dump/hybos/include/x86.h +++ b/Dump/hybos/include/x86.h @@ -1,26 +1,26 @@ -#ifndef __TL_X86_H -#define __TL_X86_H - -#ifdef __cplusplus -extern "C" -{ -#endif - -/** - * 16 bit MSB: segment, 16 bit LSB: offset - */ -//typedef unsigned farptr; - -unsigned inportb(unsigned short port); -void outportb(unsigned port, unsigned val); -unsigned inportw(unsigned short port); -void outportw(unsigned port, unsigned val); -unsigned disable(void); -void enable(void); - -#ifdef __cplusplus -} -#endif - -#endif - +#ifndef __TL_X86_H +#define __TL_X86_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +/** + * 16 bit MSB: segment, 16 bit LSB: offset + */ +//typedef unsigned farptr; + +unsigned inportb(unsigned short port); +void outportb(unsigned port, unsigned val); +unsigned inportw(unsigned short port); +void outportw(unsigned port, unsigned val); +unsigned disable(void); +void enable(void); + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/Dump/hybos/lib/char/isalnum.c b/Dump/hybos/lib/char/isalnum.c index 26b2a3a..b985767 100644 --- a/Dump/hybos/lib/char/isalnum.c +++ b/Dump/hybos/lib/char/isalnum.c @@ -1,6 +1,6 @@ -#include - -bool isalnum(const char c) -{ - return ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '1' && c <= '9')); -} +#include + +bool isalnum(const char c) +{ + return ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '1' && c <= '9')); +} diff --git a/Dump/hybos/lib/char/isalpha.c b/Dump/hybos/lib/char/isalpha.c index 6392de1..7397c02 100644 --- a/Dump/hybos/lib/char/isalpha.c +++ b/Dump/hybos/lib/char/isalpha.c @@ -1,6 +1,6 @@ -#include - -bool isalpha(const char c) -{ - return ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')); -} +#include + +bool isalpha(const char c) +{ + return ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')); +} diff --git a/Dump/hybos/lib/char/isascii.c b/Dump/hybos/lib/char/isascii.c index 4ddcaee..27ed32c 100644 --- a/Dump/hybos/lib/char/isascii.c +++ b/Dump/hybos/lib/char/isascii.c @@ -1,6 +1,6 @@ -#include - -bool isascii(const unsigned char c) -{ - return (c >= 0x00 && c <= 0x7F); -} +#include + +bool isascii(const unsigned char c) +{ + return (c >= 0x00 && c <= 0x7F); +} diff --git a/Dump/hybos/lib/char/iscsym.c b/Dump/hybos/lib/char/iscsym.c index 575bb19..ec3d9a3 100644 --- a/Dump/hybos/lib/char/iscsym.c +++ b/Dump/hybos/lib/char/iscsym.c @@ -1,6 +1,6 @@ -#include - -bool iscsym(const char c) -{ - return ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || (c == '_')); -} +#include + +bool iscsym(const char c) +{ + return ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || (c == '_')); +} diff --git a/Dump/hybos/lib/char/iscsymf.c b/Dump/hybos/lib/char/iscsymf.c index c735f71..b37e422 100644 --- a/Dump/hybos/lib/char/iscsymf.c +++ b/Dump/hybos/lib/char/iscsymf.c @@ -1,6 +1,6 @@ -#include - -bool iscsymf(const char c) -{ - return ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c == '_')); -} +#include + +bool iscsymf(const char c) +{ + return ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c == '_')); +} diff --git a/Dump/hybos/lib/char/isctrl.c b/Dump/hybos/lib/char/isctrl.c index 894df6d..9b9ba01 100644 --- a/Dump/hybos/lib/char/isctrl.c +++ b/Dump/hybos/lib/char/isctrl.c @@ -1,6 +1,6 @@ -#include - -bool isctrl(const char c) -{ - return (!(c >= ' ' && c <= '~')); -} +#include + +bool isctrl(const char c) +{ + return (!(c >= ' ' && c <= '~')); +} diff --git a/Dump/hybos/lib/char/isdigit.c b/Dump/hybos/lib/char/isdigit.c index 6eebe23..dfe5951 100644 --- a/Dump/hybos/lib/char/isdigit.c +++ b/Dump/hybos/lib/char/isdigit.c @@ -1,6 +1,6 @@ -#include - -bool isdigit(const char c) -{ - return (c >= '0' && c <= '9'); -} +#include + +bool isdigit(const char c) +{ + return (c >= '0' && c <= '9'); +} diff --git a/Dump/hybos/lib/char/isgraph.c b/Dump/hybos/lib/char/isgraph.c index f8103ca..5c0a5ed 100644 --- a/Dump/hybos/lib/char/isgraph.c +++ b/Dump/hybos/lib/char/isgraph.c @@ -1,6 +1,6 @@ -#include - -bool isgraph(const unsigned char c) -{ - return (!(c >= 0x00 && c <= 0x7F)); -} +#include + +bool isgraph(const unsigned char c) +{ + return (!(c >= 0x00 && c <= 0x7F)); +} diff --git a/Dump/hybos/lib/char/islower.c b/Dump/hybos/lib/char/islower.c index 5e60bfc..2fee8c8 100644 --- a/Dump/hybos/lib/char/islower.c +++ b/Dump/hybos/lib/char/islower.c @@ -1,6 +1,6 @@ -#include - -bool islowwer(const char c) -{ - return (c >= 'a' && c <= 'z'); -} +#include + +bool islowwer(const char c) +{ + return (c >= 'a' && c <= 'z'); +} diff --git a/Dump/hybos/lib/char/isprint.c b/Dump/hybos/lib/char/isprint.c index 96f5caf..b6be32b 100644 --- a/Dump/hybos/lib/char/isprint.c +++ b/Dump/hybos/lib/char/isprint.c @@ -1,6 +1,6 @@ -#include - -bool isprint(const char c) -{ - return (c >= ' ' && c <= '~'); -} +#include + +bool isprint(const char c) +{ + return (c >= ' ' && c <= '~'); +} diff --git a/Dump/hybos/lib/char/ispunct.c b/Dump/hybos/lib/char/ispunct.c index 72b4d4d..7c826ce 100644 --- a/Dump/hybos/lib/char/ispunct.c +++ b/Dump/hybos/lib/char/ispunct.c @@ -1,6 +1,6 @@ -#include - -bool ispunct(const char c) -{ - return ((c >= '!' && c<= '/') || (c >= ':' && c<= '@') || (c >= '[' && c<= '`') || (c >= '{' && c<= '~')); -} +#include + +bool ispunct(const char c) +{ + return ((c >= '!' && c<= '/') || (c >= ':' && c<= '@') || (c >= '[' && c<= '`') || (c >= '{' && c<= '~')); +} diff --git a/Dump/hybos/lib/char/isspace.c b/Dump/hybos/lib/char/isspace.c index 29c6139..1d9800d 100644 --- a/Dump/hybos/lib/char/isspace.c +++ b/Dump/hybos/lib/char/isspace.c @@ -1,6 +1,6 @@ -#include - -bool isspace(const char c) -{ - return (c == ' ' || (c >= 0x09 && c <= 0x0D)); -} +#include + +bool isspace(const char c) +{ + return (c == ' ' || (c >= 0x09 && c <= 0x0D)); +} diff --git a/Dump/hybos/lib/char/isupper.c b/Dump/hybos/lib/char/isupper.c index e54a05c..5838170 100644 --- a/Dump/hybos/lib/char/isupper.c +++ b/Dump/hybos/lib/char/isupper.c @@ -1,6 +1,6 @@ -#include - -bool isupper(const char c) -{ - return (c >= 'A' && c <= 'Z'); -} +#include + +bool isupper(const char c) +{ + return (c >= 'A' && c <= 'Z'); +} diff --git a/Dump/hybos/lib/char/isxdigit.c b/Dump/hybos/lib/char/isxdigit.c index b67e005..50592fe 100644 --- a/Dump/hybos/lib/char/isxdigit.c +++ b/Dump/hybos/lib/char/isxdigit.c @@ -1,6 +1,6 @@ -#include - -bool isxdigit(const char c) -{ - return ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')); -} +#include + +bool isxdigit(const char c) +{ + return ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')); +} diff --git a/Dump/hybos/lib/config/config.c b/Dump/hybos/lib/config/config.c index 3a46d5b..7c8b764 100644 --- a/Dump/hybos/lib/config/config.c +++ b/Dump/hybos/lib/config/config.c @@ -1,36 +1,36 @@ -/** - * Compiler configuration - */ - -#ifdef __GNUC__ -#define COMPILER "GNU C Compiler " __VERSION__ -typedef enum {false = 0, true = !0} bool; -typedef unsigned size_t; -typedef signed char __int8; -typedef signed short int __int16; -typedef signed int __int32; -typedef signed long long int __int64; - -#define int8 __int8 -#define int16 __int16 -#define int32 __int32 -#define int64 __int64 - -typedef unsigned char uint8; -typedef unsigned short int uint16; -typedef unsigned int uint32; -typedef unsigned long long int uint64; - -#define uint8 __uint8 -#define uint16 __uint16 -#define uint32 __uint32 -#define uint64 __uint64 - -/*typedef void* pointer;*/ -/*typedef unsigned char string;*/ - -#define discardable -#else -#error "Compiler not supported" -#endif /* __GNUC__ */ - +/** + * Compiler configuration + */ + +#ifdef __GNUC__ +#define COMPILER "GNU C Compiler " __VERSION__ +typedef enum {false = 0, true = !0} bool; +typedef unsigned size_t; +typedef signed char __int8; +typedef signed short int __int16; +typedef signed int __int32; +typedef signed long long int __int64; + +#define int8 __int8 +#define int16 __int16 +#define int32 __int32 +#define int64 __int64 + +typedef unsigned char uint8; +typedef unsigned short int uint16; +typedef unsigned int uint32; +typedef unsigned long long int uint64; + +#define uint8 __uint8 +#define uint16 __uint16 +#define uint32 __uint32 +#define uint64 __uint64 + +/*typedef void* pointer;*/ +/*typedef unsigned char string;*/ + +#define discardable +#else +#error "Compiler not supported" +#endif /* __GNUC__ */ + diff --git a/Dump/hybos/lib/convert/atoi.c b/Dump/hybos/lib/convert/atoi.c index 5a0ae8f..7bdc127 100644 --- a/Dump/hybos/lib/convert/atoi.c +++ b/Dump/hybos/lib/convert/atoi.c @@ -1,33 +1,33 @@ -#include - -long atoi(const char *nptr) -{ - int c; /* current char */ - long total; /* current total */ - int sign; /* if '-', then negative, otherwise positive */ - - /* skip whitespace */ - while(isspace((int)(unsigned char)*nptr)) - ++nptr; - - c = (int)(unsigned char)*nptr++; - sign = c; /* save sign indication */ - - /* skip sign */ - if(c == '-' || c == '+') - c = (int)(unsigned char)*nptr++; - - total = 0; - - while(isdigit(c)) - { - total = 10 * total + (c - '0'); /* accumulate digit */ - c = (int)(unsigned char)*nptr++; /* get next char */ - } - - /* return result, negated if necessary */ - if(sign == '-') - return -total; - else - return total; -} +#include + +long atoi(const char *nptr) +{ + int c; /* current char */ + long total; /* current total */ + int sign; /* if '-', then negative, otherwise positive */ + + /* skip whitespace */ + while(isspace((int)(unsigned char)*nptr)) + ++nptr; + + c = (int)(unsigned char)*nptr++; + sign = c; /* save sign indication */ + + /* skip sign */ + if(c == '-' || c == '+') + c = (int)(unsigned char)*nptr++; + + total = 0; + + while(isdigit(c)) + { + total = 10 * total + (c - '0'); /* accumulate digit */ + c = (int)(unsigned char)*nptr++; /* get next char */ + } + + /* return result, negated if necessary */ + if(sign == '-') + return -total; + else + return total; +} diff --git a/Dump/hybos/lib/convert/atoi16.c b/Dump/hybos/lib/convert/atoi16.c index d3f5a12..8b13789 100644 --- a/Dump/hybos/lib/convert/atoi16.c +++ b/Dump/hybos/lib/convert/atoi16.c @@ -1 +1 @@ - + diff --git a/Dump/hybos/lib/convert/atoi32.c b/Dump/hybos/lib/convert/atoi32.c index d3f5a12..8b13789 100644 --- a/Dump/hybos/lib/convert/atoi32.c +++ b/Dump/hybos/lib/convert/atoi32.c @@ -1 +1 @@ - + diff --git a/Dump/hybos/lib/convert/atoi64.c b/Dump/hybos/lib/convert/atoi64.c index d3f5a12..8b13789 100644 --- a/Dump/hybos/lib/convert/atoi64.c +++ b/Dump/hybos/lib/convert/atoi64.c @@ -1 +1 @@ - + diff --git a/Dump/hybos/lib/convert/i16toa.c b/Dump/hybos/lib/convert/i16toa.c index ed88e45..0e31625 100644 --- a/Dump/hybos/lib/convert/i16toa.c +++ b/Dump/hybos/lib/convert/i16toa.c @@ -1,39 +1,39 @@ -#include - -void i16toa(int16_t value, char *string, uint8_t radix) -{ - char *i, *s, t, d; - - i = string; - - if(value < 0) - { - *i++ = '-'; - value = -value; - } - - s = i; - - do - { - d = value % radix; - value /= radix; - - if(d > 9) - *i++ = d + 'A' - 10; - else - *i++ = d + '0'; - } while (value > 0); - - *i-- = '\0'; - - do - { - t = *i; - *i = *s; - *s = t; - - --i; - ++s; - } while (s < i); -} +#include + +void i16toa(int16_t value, char *string, uint8_t radix) +{ + char *i, *s, t, d; + + i = string; + + if(value < 0) + { + *i++ = '-'; + value = -value; + } + + s = i; + + do + { + d = value % radix; + value /= radix; + + if(d > 9) + *i++ = d + 'A' - 10; + else + *i++ = d + '0'; + } while (value > 0); + + *i-- = '\0'; + + do + { + t = *i; + *i = *s; + *s = t; + + --i; + ++s; + } while (s < i); +} diff --git a/Dump/hybos/lib/convert/i32toa.c b/Dump/hybos/lib/convert/i32toa.c index c8115ea..09f65ea 100644 --- a/Dump/hybos/lib/convert/i32toa.c +++ b/Dump/hybos/lib/convert/i32toa.c @@ -1,39 +1,39 @@ -#include - -void i32toa(int32_t value, char *string, uint8_t radix) -{ - char *i, *s, t, d; - - i = string; - - if(value < 0) - { - *i++ = '-'; - value = -value; - } - - s = i; - - do - { - d = value % radix; - value /= radix; - - if (d > 9) - *i++ = d + 'A' - 10; - else - *i++ = d + '0'; - } while (value > 0); - - *i-- = '\0'; - - do - { - t = *i; - *i = *s; - *s = t; - - --i; - ++s; - } while (s < i); -} +#include + +void i32toa(int32_t value, char *string, uint8_t radix) +{ + char *i, *s, t, d; + + i = string; + + if(value < 0) + { + *i++ = '-'; + value = -value; + } + + s = i; + + do + { + d = value % radix; + value /= radix; + + if (d > 9) + *i++ = d + 'A' - 10; + else + *i++ = d + '0'; + } while (value > 0); + + *i-- = '\0'; + + do + { + t = *i; + *i = *s; + *s = t; + + --i; + ++s; + } while (s < i); +} diff --git a/Dump/hybos/lib/convert/i64toa.c b/Dump/hybos/lib/convert/i64toa.c index e75aa87..0f93b27 100644 --- a/Dump/hybos/lib/convert/i64toa.c +++ b/Dump/hybos/lib/convert/i64toa.c @@ -1,39 +1,39 @@ -#include - -void i64toa(int64_t value, char *string, uint8_t radix) -{ - char *i, *s, t, d; - - i = string; - - if(value < 0) - { - *i++ = '-'; - value = -value; - } - - s = i; - - do - { - d = value % radix; - value /= radix; - - if(d > 9) - *i++ = d + 'A' - 10; - else - *i++ = d + '0'; - } while (value > 0); - - *i-- = '\0'; - - do - { - t = *i; - *i = *s; - *s = t; - - --i; - ++s; - } while (s < i); -} +#include + +void i64toa(int64_t value, char *string, uint8_t radix) +{ + char *i, *s, t, d; + + i = string; + + if(value < 0) + { + *i++ = '-'; + value = -value; + } + + s = i; + + do + { + d = value % radix; + value /= radix; + + if(d > 9) + *i++ = d + 'A' - 10; + else + *i++ = d + '0'; + } while (value > 0); + + *i-- = '\0'; + + do + { + t = *i; + *i = *s; + *s = t; + + --i; + ++s; + } while (s < i); +} diff --git a/Dump/hybos/lib/convert/u16toa.c b/Dump/hybos/lib/convert/u16toa.c index 4998340..e9075ab 100644 --- a/Dump/hybos/lib/convert/u16toa.c +++ b/Dump/hybos/lib/convert/u16toa.c @@ -1,29 +1,29 @@ -void u16toa(unt16 value, char *string, unt8 radix) -{ - char *i, *s, t, d; - - s = i = string; - - do - { - d = value % radix; - value /= radix; - - if(d > 9) - *i++ = d + 'A' - 10; - else - *i++ = d + '0'; - } while (value > 0); - - *i-- = '\0'; - - do - { - t = *i; - *i = *s; - *s = t; - - --i; - ++s; - } while (s < i); -} +void u16toa(unt16 value, char *string, unt8 radix) +{ + char *i, *s, t, d; + + s = i = string; + + do + { + d = value % radix; + value /= radix; + + if(d > 9) + *i++ = d + 'A' - 10; + else + *i++ = d + '0'; + } while (value > 0); + + *i-- = '\0'; + + do + { + t = *i; + *i = *s; + *s = t; + + --i; + ++s; + } while (s < i); +} diff --git a/Dump/hybos/lib/convert/u32toa.c b/Dump/hybos/lib/convert/u32toa.c index 3145cd8..06a34f7 100644 --- a/Dump/hybos/lib/convert/u32toa.c +++ b/Dump/hybos/lib/convert/u32toa.c @@ -1,29 +1,29 @@ -void u32toa(unt32 value, char *string, unt8 radix) -{ - char *i, *s, t, d; - - s = i = string; - - do - { - d = value % radix; - value /= radix; - - if(d > 9) - *i++ = d + 'A' - 10; - else - *i++ = d + '0'; - } while (value > 0); - - *i-- = '\0'; - - do - { - t = *i; - *i = *s; - *s = t; - - --i; - ++s; - } while (s < i); -} +void u32toa(unt32 value, char *string, unt8 radix) +{ + char *i, *s, t, d; + + s = i = string; + + do + { + d = value % radix; + value /= radix; + + if(d > 9) + *i++ = d + 'A' - 10; + else + *i++ = d + '0'; + } while (value > 0); + + *i-- = '\0'; + + do + { + t = *i; + *i = *s; + *s = t; + + --i; + ++s; + } while (s < i); +} diff --git a/Dump/hybos/lib/convert/u64toa.c b/Dump/hybos/lib/convert/u64toa.c index 9ec5fa1..d41fe9d 100644 --- a/Dump/hybos/lib/convert/u64toa.c +++ b/Dump/hybos/lib/convert/u64toa.c @@ -1,29 +1,29 @@ -void u64toa(unt64 value, char *string, unt8 radix) -{ - char *i, *s, t, d; - - s = i = string; - - do - { - d = value % radix; - value /= radix; - - if(d > 9) - *i++ = d + 'A' - 10; - else - *i++ = d + '0'; - } while (value > 0); - - *i-- = '\0'; - - do - { - t = *i; - *i = *s; - *s = t; - - --i; - ++s; - } while (s < i); -} +void u64toa(unt64 value, char *string, unt8 radix) +{ + char *i, *s, t, d; + + s = i = string; + + do + { + d = value % radix; + value /= radix; + + if(d > 9) + *i++ = d + 'A' - 10; + else + *i++ = d + '0'; + } while (value > 0); + + *i-- = '\0'; + + do + { + t = *i; + *i = *s; + *s = t; + + --i; + ++s; + } while (s < i); +} diff --git a/Dump/hybos/lib/ctype/ctype.c b/Dump/hybos/lib/ctype/ctype.c index acf64e3..0bf4150 100644 --- a/Dump/hybos/lib/ctype/ctype.c +++ b/Dump/hybos/lib/ctype/ctype.c @@ -1,46 +1,46 @@ -#include - -char _ctype[] = -{ - 0x00, -/* 0 */ CT_CTL, CT_CTL, CT_CTL, CT_CTL, - CT_CTL, CT_CTL, CT_CTL, CT_CTL, -/* 8 */ CT_CTL, CT_CTL | CT_WHT, CT_CTL | CT_WHT, CT_CTL | CT_WHT, - CT_CTL | CT_WHT, CT_CTL | CT_WHT, CT_CTL, CT_CTL, -/* 16 */CT_CTL, CT_CTL, CT_CTL, CT_CTL, - CT_CTL, CT_CTL, CT_CTL, CT_CTL, -/* 24 */CT_CTL, CT_CTL, CT_CTL, CT_CTL, - CT_CTL, CT_CTL, CT_CTL, CT_CTL, -/* ' ' */CT_WHT | CT_SP, CT_PUN, CT_PUN, CT_PUN, - CT_PUN, CT_PUN, CT_PUN, CT_PUN, -/* '(' */CT_PUN, CT_PUN, CT_PUN, CT_PUN, - CT_PUN, CT_PUN, CT_PUN, CT_PUN, -/* '0' */CT_DIG, CT_DIG, CT_DIG, CT_DIG, - CT_DIG, CT_DIG, CT_DIG, CT_DIG, -/* '8' */CT_DIG, CT_DIG, CT_PUN, CT_PUN, - CT_PUN, CT_PUN, CT_PUN, CT_PUN, -/* '@' */CT_PUN, CT_UP | CT_HEX, CT_UP | CT_HEX, CT_UP | CT_HEX, - CT_UP | CT_HEX, CT_UP | CT_HEX, CT_UP | CT_HEX, CT_UP, -/* 'H' */CT_UP, CT_UP, CT_UP, CT_UP, - CT_UP, CT_UP, CT_UP, CT_UP, -/* 'P' */CT_UP, CT_UP, CT_UP, CT_UP, - CT_UP, CT_UP, CT_UP, CT_UP, -/* 'X' */CT_UP, CT_UP, CT_UP, CT_PUN, - CT_PUN, CT_PUN, CT_PUN, CT_PUN, -/* '`' */CT_PUN, CT_LOW | CT_HEX, CT_LOW | CT_HEX, CT_LOW | CT_HEX, - CT_LOW | CT_HEX, CT_LOW | CT_HEX, CT_LOW | CT_HEX, CT_LOW, -/* h' */CT_LOW, CT_LOW, CT_LOW, CT_LOW, - CT_LOW, CT_LOW, CT_LOW, CT_LOW, -/* 'p' */CT_LOW, CT_LOW, CT_LOW, CT_LOW, - CT_LOW, CT_LOW, CT_LOW, CT_LOW, -/* 'x' */CT_LOW, CT_LOW, CT_LOW, CT_PUN, - CT_PUN, CT_PUN, CT_PUN, CT_CTL, -/* 128 */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/* 144 */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/* 160 */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/* 176 */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/* 192 */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/* 208 */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/* 224 */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/* 240 */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -}; +#include + +char _ctype[] = +{ + 0x00, +/* 0 */ CT_CTL, CT_CTL, CT_CTL, CT_CTL, + CT_CTL, CT_CTL, CT_CTL, CT_CTL, +/* 8 */ CT_CTL, CT_CTL | CT_WHT, CT_CTL | CT_WHT, CT_CTL | CT_WHT, + CT_CTL | CT_WHT, CT_CTL | CT_WHT, CT_CTL, CT_CTL, +/* 16 */CT_CTL, CT_CTL, CT_CTL, CT_CTL, + CT_CTL, CT_CTL, CT_CTL, CT_CTL, +/* 24 */CT_CTL, CT_CTL, CT_CTL, CT_CTL, + CT_CTL, CT_CTL, CT_CTL, CT_CTL, +/* ' ' */CT_WHT | CT_SP, CT_PUN, CT_PUN, CT_PUN, + CT_PUN, CT_PUN, CT_PUN, CT_PUN, +/* '(' */CT_PUN, CT_PUN, CT_PUN, CT_PUN, + CT_PUN, CT_PUN, CT_PUN, CT_PUN, +/* '0' */CT_DIG, CT_DIG, CT_DIG, CT_DIG, + CT_DIG, CT_DIG, CT_DIG, CT_DIG, +/* '8' */CT_DIG, CT_DIG, CT_PUN, CT_PUN, + CT_PUN, CT_PUN, CT_PUN, CT_PUN, +/* '@' */CT_PUN, CT_UP | CT_HEX, CT_UP | CT_HEX, CT_UP | CT_HEX, + CT_UP | CT_HEX, CT_UP | CT_HEX, CT_UP | CT_HEX, CT_UP, +/* 'H' */CT_UP, CT_UP, CT_UP, CT_UP, + CT_UP, CT_UP, CT_UP, CT_UP, +/* 'P' */CT_UP, CT_UP, CT_UP, CT_UP, + CT_UP, CT_UP, CT_UP, CT_UP, +/* 'X' */CT_UP, CT_UP, CT_UP, CT_PUN, + CT_PUN, CT_PUN, CT_PUN, CT_PUN, +/* '`' */CT_PUN, CT_LOW | CT_HEX, CT_LOW | CT_HEX, CT_LOW | CT_HEX, + CT_LOW | CT_HEX, CT_LOW | CT_HEX, CT_LOW | CT_HEX, CT_LOW, +/* h' */CT_LOW, CT_LOW, CT_LOW, CT_LOW, + CT_LOW, CT_LOW, CT_LOW, CT_LOW, +/* 'p' */CT_LOW, CT_LOW, CT_LOW, CT_LOW, + CT_LOW, CT_LOW, CT_LOW, CT_LOW, +/* 'x' */CT_LOW, CT_LOW, CT_LOW, CT_PUN, + CT_PUN, CT_PUN, CT_PUN, CT_CTL, +/* 128 */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 144 */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 160 */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 176 */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 192 */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 208 */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 224 */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 240 */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; diff --git a/Dump/hybos/lib/math/abs.c b/Dump/hybos/lib/math/abs.c index adf8157..5d91f95 100644 --- a/Dump/hybos/lib/math/abs.c +++ b/Dump/hybos/lib/math/abs.c @@ -1,32 +1,32 @@ -/*** -*abs.c - find absolute value -* -* Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved. -* -*Purpose: -* defines abs() - find the absolute value of an int. -* -*******************************************************************************/ - - -/*** -*int abs(number) - find absolute value of number -* -*Purpose: -* Returns the absolute value of number (if number >= 0, returns number, -* else returns -number). -* -*Entry: -* int number - number to find absolute value of -* -*Exit: -* returns the aboslute value of number -* -*Exceptions: -* -*******************************************************************************/ - -int abs(int number) -{ - return( number>=0 ? number : -number ); -} +/*** +*abs.c - find absolute value +* +* Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved. +* +*Purpose: +* defines abs() - find the absolute value of an int. +* +*******************************************************************************/ + + +/*** +*int abs(number) - find absolute value of number +* +*Purpose: +* Returns the absolute value of number (if number >= 0, returns number, +* else returns -number). +* +*Entry: +* int number - number to find absolute value of +* +*Exit: +* returns the aboslute value of number +* +*Exceptions: +* +*******************************************************************************/ + +int abs(int number) +{ + return( number>=0 ? number : -number ); +} diff --git a/Dump/hybos/lib/math/max.c b/Dump/hybos/lib/math/max.c index 869833a..500e2ae 100644 --- a/Dump/hybos/lib/math/max.c +++ b/Dump/hybos/lib/math/max.c @@ -1,4 +1,4 @@ -int max(int a, int b) -{ - return (a > b) ? a : b; -} +int max(int a, int b) +{ + return (a > b) ? a : b; +} diff --git a/Dump/hybos/lib/math/min.c b/Dump/hybos/lib/math/min.c index 10d4dc5..2d7d2fd 100644 --- a/Dump/hybos/lib/math/min.c +++ b/Dump/hybos/lib/math/min.c @@ -1,4 +1,4 @@ -int min(int a, int b) -{ - return (a < b) ? a : b; -} +int min(int a, int b) +{ + return (a < b) ? a : b; +} diff --git a/Dump/hybos/lib/math/rotl.c b/Dump/hybos/lib/math/rotl.c index 8981329..836d415 100644 --- a/Dump/hybos/lib/math/rotl.c +++ b/Dump/hybos/lib/math/rotl.c @@ -1,49 +1,49 @@ -/*** -*rotl.c - rotate an unsigned integer left -* -* Copyright (c) 1989-1997, Microsoft Corporation. All rights reserved. -* -*Purpose: -* defines _rotl() - performs a rotate left on an unsigned integer. -* -*******************************************************************************/ - - -/*** -*unsigned _rotl(val, shift) - int rotate left -* -*Purpose: -* Performs a rotate left on an unsigned integer. -* -* [Note: The _lrotl entry is based on the assumption -* that sizeof(int) == sizeof(long).] -*Entry: -* unsigned val: value to rotate -* int shift: number of bits to shift by -* -*Exit: -* returns rotated value -* -*Exceptions: -* None. -* -*******************************************************************************/ - -unsigned rotl(unsigned val, int shift) -{ - register unsigned hibit; /* non-zero means hi bit set */ - register unsigned num = val; /* number to rotate */ - - shift &= 0x1f; /* modulo 32 -- this will also make - negative shifts work */ - - while(shift--) - { - hibit = num & 0x80000000; /* get high bit */ - num <<= 1; /* shift left one bit */ - if(hibit) - num |= 1; /* set lo bit if hi bit was set */ - } - - return num; -} +/*** +*rotl.c - rotate an unsigned integer left +* +* Copyright (c) 1989-1997, Microsoft Corporation. All rights reserved. +* +*Purpose: +* defines _rotl() - performs a rotate left on an unsigned integer. +* +*******************************************************************************/ + + +/*** +*unsigned _rotl(val, shift) - int rotate left +* +*Purpose: +* Performs a rotate left on an unsigned integer. +* +* [Note: The _lrotl entry is based on the assumption +* that sizeof(int) == sizeof(long).] +*Entry: +* unsigned val: value to rotate +* int shift: number of bits to shift by +* +*Exit: +* returns rotated value +* +*Exceptions: +* None. +* +*******************************************************************************/ + +unsigned rotl(unsigned val, int shift) +{ + register unsigned hibit; /* non-zero means hi bit set */ + register unsigned num = val; /* number to rotate */ + + shift &= 0x1f; /* modulo 32 -- this will also make + negative shifts work */ + + while(shift--) + { + hibit = num & 0x80000000; /* get high bit */ + num <<= 1; /* shift left one bit */ + if(hibit) + num |= 1; /* set lo bit if hi bit was set */ + } + + return num; +} diff --git a/Dump/hybos/lib/math/rotr.c b/Dump/hybos/lib/math/rotr.c index 10247ff..5b9295f 100644 --- a/Dump/hybos/lib/math/rotr.c +++ b/Dump/hybos/lib/math/rotr.c @@ -1,52 +1,52 @@ -/*** -*rotr.c - rotate an unsigned integer right -* -* Copyright (c) 1989-1997, Microsoft Corporation. All rights reserved. -* -*Purpose: -* defines _rotr() - performs a rotate right on an unsigned integer. -* -*******************************************************************************/ - - - - -/*** -*unsigned _rotr(val, shift) - int rotate right -* -*Purpose: -* Performs a rotate right on an unsigned integer. -* -* [Note: The _lrotl entry is based on the assumption -* that sizeof(int) == sizeof(long).] -*Entry: -* unsigned val: value to rotate -* int shift: number of bits to shift by -* -*Exit: -* returns rotated value -* -*Exceptions: -* None. -* -*******************************************************************************/ - - -unsigned rotr(unsigned val, int shift) -{ - register unsigned lobit; /* non-zero means lo bit set */ - register unsigned num = val; /* number to rotate */ - - shift &= 0x1f; /* modulo 32 -- this will also make - negative shifts work */ - - while(shift--) - { - lobit = num & 1; /* get high bit */ - num >>= 1; /* shift right one bit */ - if(lobit) - num |= 0x80000000; /* set hi bit if lo bit was set */ - } - - return num; -} +/*** +*rotr.c - rotate an unsigned integer right +* +* Copyright (c) 1989-1997, Microsoft Corporation. All rights reserved. +* +*Purpose: +* defines _rotr() - performs a rotate right on an unsigned integer. +* +*******************************************************************************/ + + + + +/*** +*unsigned _rotr(val, shift) - int rotate right +* +*Purpose: +* Performs a rotate right on an unsigned integer. +* +* [Note: The _lrotl entry is based on the assumption +* that sizeof(int) == sizeof(long).] +*Entry: +* unsigned val: value to rotate +* int shift: number of bits to shift by +* +*Exit: +* returns rotated value +* +*Exceptions: +* None. +* +*******************************************************************************/ + + +unsigned rotr(unsigned val, int shift) +{ + register unsigned lobit; /* non-zero means lo bit set */ + register unsigned num = val; /* number to rotate */ + + shift &= 0x1f; /* modulo 32 -- this will also make + negative shifts work */ + + while(shift--) + { + lobit = num & 1; /* get high bit */ + num >>= 1; /* shift right one bit */ + if(lobit) + num |= 0x80000000; /* set hi bit if lo bit was set */ + } + + return num; +} diff --git a/Dump/hybos/lib/mem/memccpy.c b/Dump/hybos/lib/mem/memccpy.c index 287057b..2cd7167 100644 --- a/Dump/hybos/lib/mem/memccpy.c +++ b/Dump/hybos/lib/mem/memccpy.c @@ -1,41 +1,41 @@ -/*** -*memccpy.c - copy bytes until a character is found -* -* Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved. -* -*Purpose: -* defines _memccpy() - copies bytes until a specifed character -* is found, or a maximum number of characters have been copied. -* -*******************************************************************************/ - - -/*** -*char *_memccpy(dest, src, c, count) - copy bytes until character found -* -*Purpose: -* Copies bytes from src to dest until count bytes have been -* copied, or up to and including the character c, whichever -* comes first. -* -*Entry: -* void *dest - pointer to memory to receive copy -* void *src - source of bytes -* int c - character to stop copy at -* unsigned int count - max number of bytes to copy -* -*Exit: -* returns pointer to byte immediately after c in dest -* returns NULL if c was never found -* -*Exceptions: -* -*******************************************************************************/ - -void *memccpy(void *dest, const void *src, int c, unsigned count) -{ - while(count && (*((char *)(dest = (char *)dest + 1) - 1) = *((char *)(src = (char *)src + 1) - 1)) != (char)c ) - count--; - - return count ? dest : 0; -} +/*** +*memccpy.c - copy bytes until a character is found +* +* Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved. +* +*Purpose: +* defines _memccpy() - copies bytes until a specifed character +* is found, or a maximum number of characters have been copied. +* +*******************************************************************************/ + + +/*** +*char *_memccpy(dest, src, c, count) - copy bytes until character found +* +*Purpose: +* Copies bytes from src to dest until count bytes have been +* copied, or up to and including the character c, whichever +* comes first. +* +*Entry: +* void *dest - pointer to memory to receive copy +* void *src - source of bytes +* int c - character to stop copy at +* unsigned int count - max number of bytes to copy +* +*Exit: +* returns pointer to byte immediately after c in dest +* returns NULL if c was never found +* +*Exceptions: +* +*******************************************************************************/ + +void *memccpy(void *dest, const void *src, int c, unsigned count) +{ + while(count && (*((char *)(dest = (char *)dest + 1) - 1) = *((char *)(src = (char *)src + 1) - 1)) != (char)c ) + count--; + + return count ? dest : 0; +} diff --git a/Dump/hybos/lib/mem/memchr.c b/Dump/hybos/lib/mem/memchr.c index ccf6e3b..e2ead5c 100644 --- a/Dump/hybos/lib/mem/memchr.c +++ b/Dump/hybos/lib/mem/memchr.c @@ -1,43 +1,43 @@ -/*** -*memchr.c - search block of memory for a given character -* -* Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved. -* -*Purpose: -* defines memchr() - search memory until a character is -* found or a limit is reached. -* -*******************************************************************************/ - - -/*** -*char *memchr(buf, chr, cnt) - search memory for given character. -* -*Purpose: -* Searches at buf for the given character, stopping when chr is -* first found or cnt bytes have been searched through. -* -*Entry: -* void *buf - memory buffer to be searched -* int chr - character to search for -* size_t cnt - max number of bytes to search -* -*Exit: -* returns pointer to first occurence of chr in buf -* returns NULL if chr not found in the first cnt bytes -* -*Exceptions: -* -*******************************************************************************/ -#include <_size_t.h> - -void *memchr(const void * buf, int chr, size_t cnt) -{ - while( cnt && (*(unsigned char *)buf != (unsigned char)chr)) - { - buf = (unsigned char *)buf + 1; - cnt--; - } - - return cnt ? (void *)buf : 0; -} +/*** +*memchr.c - search block of memory for a given character +* +* Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved. +* +*Purpose: +* defines memchr() - search memory until a character is +* found or a limit is reached. +* +*******************************************************************************/ + + +/*** +*char *memchr(buf, chr, cnt) - search memory for given character. +* +*Purpose: +* Searches at buf for the given character, stopping when chr is +* first found or cnt bytes have been searched through. +* +*Entry: +* void *buf - memory buffer to be searched +* int chr - character to search for +* size_t cnt - max number of bytes to search +* +*Exit: +* returns pointer to first occurence of chr in buf +* returns NULL if chr not found in the first cnt bytes +* +*Exceptions: +* +*******************************************************************************/ +#include <_size_t.h> + +void *memchr(const void * buf, int chr, size_t cnt) +{ + while( cnt && (*(unsigned char *)buf != (unsigned char)chr)) + { + buf = (unsigned char *)buf + 1; + cnt--; + } + + return cnt ? (void *)buf : 0; +} diff --git a/Dump/hybos/lib/mem/memcmp.c b/Dump/hybos/lib/mem/memcmp.c index f4d498d..c05d451 100644 --- a/Dump/hybos/lib/mem/memcmp.c +++ b/Dump/hybos/lib/mem/memcmp.c @@ -1,46 +1,46 @@ -/*** -*memcmp.c - compare two blocks of memory -* -* Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved. -* -*Purpose: -* defines memcmp() - compare two memory blocks lexically and -* find their order. -* -*******************************************************************************/ - - -/*** -*int memcmp(buf1, buf2, count) - compare memory for lexical order -* -*Purpose: -* Compares count bytes of memory starting at buf1 and buf2 -* and find if equal or which one is first in lexical order. -* -*Entry: -* void *buf1, *buf2 - pointers to memory sections to compare -* size_t count - length of sections to compare -* -*Exit: -* returns < 0 if buf1 < buf2 -* returns 0 if buf1 == buf2 -* returns > 0 if buf1 > buf2 -* -*Exceptions: -* -*******************************************************************************/ -#include <_size_t.h> - -int memcmp(const void *buf1, const void *buf2, size_t count) -{ - if(!count) - return(0); - - while(--count && *(char *)buf1 == *(char *)buf2) - { - buf1 = (char *)buf1 + 1; - buf2 = (char *)buf2 + 1; - } - - return *((unsigned char *)buf1) - *((unsigned char *)buf2); -} +/*** +*memcmp.c - compare two blocks of memory +* +* Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved. +* +*Purpose: +* defines memcmp() - compare two memory blocks lexically and +* find their order. +* +*******************************************************************************/ + + +/*** +*int memcmp(buf1, buf2, count) - compare memory for lexical order +* +*Purpose: +* Compares count bytes of memory starting at buf1 and buf2 +* and find if equal or which one is first in lexical order. +* +*Entry: +* void *buf1, *buf2 - pointers to memory sections to compare +* size_t count - length of sections to compare +* +*Exit: +* returns < 0 if buf1 < buf2 +* returns 0 if buf1 == buf2 +* returns > 0 if buf1 > buf2 +* +*Exceptions: +* +*******************************************************************************/ +#include <_size_t.h> + +int memcmp(const void *buf1, const void *buf2, size_t count) +{ + if(!count) + return(0); + + while(--count && *(char *)buf1 == *(char *)buf2) + { + buf1 = (char *)buf1 + 1; + buf2 = (char *)buf2 + 1; + } + + return *((unsigned char *)buf1) - *((unsigned char *)buf2); +} diff --git a/Dump/hybos/lib/mem/memcpy.c b/Dump/hybos/lib/mem/memcpy.c index bb86792..39b3383 100644 --- a/Dump/hybos/lib/mem/memcpy.c +++ b/Dump/hybos/lib/mem/memcpy.c @@ -1,13 +1,13 @@ -void *memcpy(void *s, const void *t, unsigned n) -{ - void *ret = s; - - while(n--) - { - *(char *)s = *(char *)t; - s = (char *)s + 1; - t = (char *)t + 1; - } - - return ret; -} +void *memcpy(void *s, const void *t, unsigned n) +{ + void *ret = s; + + while(n--) + { + *(char *)s = *(char *)t; + s = (char *)s + 1; + t = (char *)t + 1; + } + + return ret; +} diff --git a/Dump/hybos/lib/mem/memcpybw.c b/Dump/hybos/lib/mem/memcpybw.c index 3db51f3..9f3d2b0 100644 --- a/Dump/hybos/lib/mem/memcpybw.c +++ b/Dump/hybos/lib/mem/memcpybw.c @@ -1,13 +1,13 @@ -void *memcpybw(void *s, void *t, unsigned n) -{ - void *ret = s; - - while(n--) - { - *(char *)s = *(char *)t; - s = (char *)s + 2; - t = (char *)t + 1; - } - - return ret; -} +void *memcpybw(void *s, void *t, unsigned n) +{ + void *ret = s; + + while(n--) + { + *(char *)s = *(char *)t; + s = (char *)s + 2; + t = (char *)t + 1; + } + + return ret; +} diff --git a/Dump/hybos/lib/mem/memicmp.c b/Dump/hybos/lib/mem/memicmp.c index 74f2888..38e4a49 100644 --- a/Dump/hybos/lib/mem/memicmp.c +++ b/Dump/hybos/lib/mem/memicmp.c @@ -1,58 +1,58 @@ -/*** -*memicmp.c - compare memory, ignore case -* -* Copyright (c) 1988-1997, Microsoft Corporation. All rights reserved. -* -*Purpose: -* defines _memicmp() - compare two blocks of memory for lexical -* order. Case is ignored in the comparison. -* -*******************************************************************************/ - - -#define _TOLOWER(c) ( ((c) >= 'A') && ((c) <= 'Z') ? ((c) - 'A' + 'a') :\ - (c) ) - -/*** -*int _memicmp(first, last, count) - compare two blocks of memory, ignore case -* -*Purpose: -* Compares count bytes of the two blocks of memory stored at first -* and last. The characters are converted to lowercase before -* comparing (not permanently), so case is ignored in the search. -* -*Entry: -* char *first, *last - memory buffers to compare -* unsigned count - maximum length to compare -* -*Exit: -* returns < 0 if first < last -* returns 0 if first == last -* returns > 0 if first > last -* -*Uses: -* -*Exceptions: -* -*******************************************************************************/ - -int _memicmp(const void * first, const void * last, unsigned int count) -{ - int f = 0; - int l = 0; - - while(count--) - { - if((*(unsigned char *)first == *(unsigned char *)last) || - ((f = _TOLOWER( *(unsigned char *)first)) == - (l = _TOLOWER( *(unsigned char *)last)))) - { - first = (char *)first + 1; - last = (char *)last + 1; - } - else - break; - } - - return (f - l); -} +/*** +*memicmp.c - compare memory, ignore case +* +* Copyright (c) 1988-1997, Microsoft Corporation. All rights reserved. +* +*Purpose: +* defines _memicmp() - compare two blocks of memory for lexical +* order. Case is ignored in the comparison. +* +*******************************************************************************/ + + +#define _TOLOWER(c) ( ((c) >= 'A') && ((c) <= 'Z') ? ((c) - 'A' + 'a') :\ + (c) ) + +/*** +*int _memicmp(first, last, count) - compare two blocks of memory, ignore case +* +*Purpose: +* Compares count bytes of the two blocks of memory stored at first +* and last. The characters are converted to lowercase before +* comparing (not permanently), so case is ignored in the search. +* +*Entry: +* char *first, *last - memory buffers to compare +* unsigned count - maximum length to compare +* +*Exit: +* returns < 0 if first < last +* returns 0 if first == last +* returns > 0 if first > last +* +*Uses: +* +*Exceptions: +* +*******************************************************************************/ + +int _memicmp(const void * first, const void * last, unsigned int count) +{ + int f = 0; + int l = 0; + + while(count--) + { + if((*(unsigned char *)first == *(unsigned char *)last) || + ((f = _TOLOWER( *(unsigned char *)first)) == + (l = _TOLOWER( *(unsigned char *)last)))) + { + first = (char *)first + 1; + last = (char *)last + 1; + } + else + break; + } + + return (f - l); +} diff --git a/Dump/hybos/lib/mem/memmove.c b/Dump/hybos/lib/mem/memmove.c index 8c0266a..32bfad3 100644 --- a/Dump/hybos/lib/mem/memmove.c +++ b/Dump/hybos/lib/mem/memmove.c @@ -1,68 +1,68 @@ -/*** -*memmove.c - contains memmove routine -* -* Copyright (c) 1988-1997, Microsoft Corporation. All right reserved. -* -*Purpose: -* memmove() copies a source memory buffer to a destination buffer. -* Overlapping buffers are treated specially, to avoid propogation. -* -*******************************************************************************/ - -/*** -*memmove - Copy source buffer to destination buffer -* -*Purpose: -* memmove() copies a source memory buffer to a destination memory buffer. -* This routine recognize overlapping buffers to avoid propogation. -* For cases where propogation is not a problem, memcpy() can be used. -* -*Entry: -* void *dst = pointer to destination buffer -* const void *src = pointer to source buffer -* size_t count = number of bytes to copy -* -*Exit: -* Returns a pointer to the destination buffer -* -*Exceptions: -*******************************************************************************/ -#include <_size_t.h> - -void *memmove(void *dst, const void *src, size_t count) -{ - void *ret = dst; - - - if(dst <= src || (char *)dst >= ((char *)src + count)) - { - /* - * Non-Overlapping Buffers - * copy from lower addresses to higher addresses - */ - while(count--) - { - *(char *)dst = *(char *)src; - dst = (char *)dst + 1; - src = (char *)src + 1; - } - } - else - { - /* - * Overlapping Buffers - * copy from higher addresses to lower addresses - */ - dst = (char *)dst + count - 1; - src = (char *)src + count - 1; - - while(count--) - { - *(char *)dst = *(char *)src; - dst = (char *)dst - 1; - src = (char *)src - 1; - } - } - - return ret; -} +/*** +*memmove.c - contains memmove routine +* +* Copyright (c) 1988-1997, Microsoft Corporation. All right reserved. +* +*Purpose: +* memmove() copies a source memory buffer to a destination buffer. +* Overlapping buffers are treated specially, to avoid propogation. +* +*******************************************************************************/ + +/*** +*memmove - Copy source buffer to destination buffer +* +*Purpose: +* memmove() copies a source memory buffer to a destination memory buffer. +* This routine recognize overlapping buffers to avoid propogation. +* For cases where propogation is not a problem, memcpy() can be used. +* +*Entry: +* void *dst = pointer to destination buffer +* const void *src = pointer to source buffer +* size_t count = number of bytes to copy +* +*Exit: +* Returns a pointer to the destination buffer +* +*Exceptions: +*******************************************************************************/ +#include <_size_t.h> + +void *memmove(void *dst, const void *src, size_t count) +{ + void *ret = dst; + + + if(dst <= src || (char *)dst >= ((char *)src + count)) + { + /* + * Non-Overlapping Buffers + * copy from lower addresses to higher addresses + */ + while(count--) + { + *(char *)dst = *(char *)src; + dst = (char *)dst + 1; + src = (char *)src + 1; + } + } + else + { + /* + * Overlapping Buffers + * copy from higher addresses to lower addresses + */ + dst = (char *)dst + count - 1; + src = (char *)src + count - 1; + + while(count--) + { + *(char *)dst = *(char *)src; + dst = (char *)dst - 1; + src = (char *)src - 1; + } + } + + return ret; +} diff --git a/Dump/hybos/lib/mem/memset.c b/Dump/hybos/lib/mem/memset.c index 0dfd884..f385108 100644 --- a/Dump/hybos/lib/mem/memset.c +++ b/Dump/hybos/lib/mem/memset.c @@ -1,12 +1,12 @@ -void *memset(void *s, int i, unsigned n) -{ - void *start = s; - - while(n--) - { - *(char *)s = (char)i; - s = (char *)s + 1; - } - - return start; -} +void *memset(void *s, int i, unsigned n) +{ + void *start = s; + + while(n--) + { + *(char *)s = (char)i; + s = (char *)s + 1; + } + + return start; +} diff --git a/Dump/hybos/lib/mem/memsetw.c b/Dump/hybos/lib/mem/memsetw.c index a81ad7a..2c55f1d 100644 --- a/Dump/hybos/lib/mem/memsetw.c +++ b/Dump/hybos/lib/mem/memsetw.c @@ -1,13 +1,13 @@ - -void *memsetw(void *s, short i, unsigned n) -{ - void *start = s; - - while(n--) - { - *(short *)s = (short)i; - s = (short *)s + 1; - } - - return(start); -} + +void *memsetw(void *s, short i, unsigned n) +{ + void *start = s; + + while(n--) + { + *(short *)s = (short)i; + s = (short *)s + 1; + } + + return(start); +} diff --git a/Dump/hybos/lib/mem/swab.c b/Dump/hybos/lib/mem/swab.c index 3220a4a..3a7eb8e 100644 --- a/Dump/hybos/lib/mem/swab.c +++ b/Dump/hybos/lib/mem/swab.c @@ -1,44 +1,44 @@ -/*** -*swab.c - block copy, while swapping even/odd bytes -* -* Copyright (c) 1989-1997, Microsoft Corporation. All rights reserved. -* -*Purpose: -* This module contains the routine _swab() which swaps the odd/even -* bytes of words during a block copy. -* -*******************************************************************************/ - -/*** -*void _swab(srcptr, dstptr, nbytes) - swap ODD/EVEN bytes during word move -* -*Purpose: -* This routine copys a block of words and swaps the odd and even -* bytes. nbytes must be > 0, otherwise nothing is copied. If -* nbytes is odd, then only (nbytes-1) bytes are copied. -* -*Entry: -* srcptr = pointer to the source block -* dstptr = pointer to the destination block -* nbytes = number of bytes to swap -* -*Returns: -* None. -* -*Exceptions: -* -*******************************************************************************/ - -void swab(char *src, char *dest, int nbytes) -{ - char b1, b2; - - while(nbytes > 1) - { - b1 = *src++; - b2 = *src++; - *dest++ = b2; - *dest++ = b1; - nbytes -= 2; - } -} +/*** +*swab.c - block copy, while swapping even/odd bytes +* +* Copyright (c) 1989-1997, Microsoft Corporation. All rights reserved. +* +*Purpose: +* This module contains the routine _swab() which swaps the odd/even +* bytes of words during a block copy. +* +*******************************************************************************/ + +/*** +*void _swab(srcptr, dstptr, nbytes) - swap ODD/EVEN bytes during word move +* +*Purpose: +* This routine copys a block of words and swaps the odd and even +* bytes. nbytes must be > 0, otherwise nothing is copied. If +* nbytes is odd, then only (nbytes-1) bytes are copied. +* +*Entry: +* srcptr = pointer to the source block +* dstptr = pointer to the destination block +* nbytes = number of bytes to swap +* +*Returns: +* None. +* +*Exceptions: +* +*******************************************************************************/ + +void swab(char *src, char *dest, int nbytes) +{ + char b1, b2; + + while(nbytes > 1) + { + b1 = *src++; + b2 = *src++; + *dest++ = b2; + *dest++ = b1; + nbytes -= 2; + } +} diff --git a/Dump/hybos/lib/setjmp/longjmp.c b/Dump/hybos/lib/setjmp/longjmp.c index af06310..0f40418 100644 --- a/Dump/hybos/lib/setjmp/longjmp.c +++ b/Dump/hybos/lib/setjmp/longjmp.c @@ -1,78 +1,78 @@ -#include /* jmp_buf */ -/***************************************************************************** -To use setjmp() and longjmp() for asynchronous (interrupt-driven; -pre-emptive) task-switching, we want to enable interrupts simultaneous -with jumping to the task. In other words, we want the EFLAGS and EIP -registers loaded at the same time. - -The only instruction that can do this is IRET, which also loads the CS -register. Changing CS is done in code that uses far pointers, and it's -also done when changing address spaces, and when changing privilege levels. -We're not interested in any of those, so just push the current CS value -on the stack and let IRET use that. - -Three distinct stack pointer (ESP) values are used in this routine: -- 'Old' or 'current' stack pointer value, which is discarded by - this routine (use setjmp() to save it) -- ESP is made to point, briefly, to the jmp_buf struct itself -- 'New' ESP value; stored in jmp_buf.esp - -Register values are restored from the jmp_buf as follows: -1. Push jmp_buf.eflags, the current CS value, and jmp_buf.eip - onto the 'new' stack -2. Make ESP point to the jmp_buf struct itself, then use the POPA - instruction to pop the 7 general purpose registers (ESP is not - loaded by POPA). The use of POPA means that registers in the - jmp_buf MUST be stored in the order that POPA expects. - (Maybe use MOVs instead, to eliminate this restriction? - Might have to rewrite entire function in asm, instead of C.) -3. Load ESP with the 'new' stack pointer, from jmp_buf.esp -4. Use IRET to pop EIP, CS, and EFLAGS from the 'new' stack -5. ??? -6. Profit! <--- obligatory Slashdot joke - -This code does NOT save the floating-point state of the CPU. Either: -1. Don't use floating point, or -2. Don't use floating point in more than one thread, or -3. Rewrite this code so it DOES save the floating-point state, or -4. Save/restore the floating-point state when entering/leaving - the kernel (protected OS only) -*****************************************************************************/ -void longjmp(jmp_buf buf, int ret_val) -{ - unsigned *esp; - -/* make sure return value is not 0 */ - if(ret_val == 0) - ret_val++; -/* EAX is used for return values, so store it in jmp_buf.EAX */ - buf->eax = ret_val; -/* get ESP for new stack */ - esp = (unsigned *)buf->esp; -/* push EFLAGS on the new stack */ - esp--; - *esp = buf->eflags; -/* push current CS on the new stack */ - esp--; - __asm__ __volatile__( - "mov %%cs,%0\n" - : "=m"(*esp)); -/* push EIP on the new stack */ - esp--; - *esp = buf->eip; -/* new ESP is 12 bytes lower; update jmp_buf.ESP */ - buf->esp = (unsigned)esp; -/* now, briefly, make the jmp_buf struct our stack */ - __asm__ __volatile__( - "movl %0,%%esp\n" -/* ESP now points to 8 general-purpose registers stored in jmp_buf -Pop them */ - "popa\n" -/* load new stack pointer from jmp_buf */ - "movl -20(%%esp),%%esp\n" -/* ESP now points to new stack, with the IRET frame (EIP, CS, EFLAGS) -we created just above. Pop these registers: */ - "iret\n" - : - : "m"(buf)); -} +#include /* jmp_buf */ +/***************************************************************************** +To use setjmp() and longjmp() for asynchronous (interrupt-driven; +pre-emptive) task-switching, we want to enable interrupts simultaneous +with jumping to the task. In other words, we want the EFLAGS and EIP +registers loaded at the same time. + +The only instruction that can do this is IRET, which also loads the CS +register. Changing CS is done in code that uses far pointers, and it's +also done when changing address spaces, and when changing privilege levels. +We're not interested in any of those, so just push the current CS value +on the stack and let IRET use that. + +Three distinct stack pointer (ESP) values are used in this routine: +- 'Old' or 'current' stack pointer value, which is discarded by + this routine (use setjmp() to save it) +- ESP is made to point, briefly, to the jmp_buf struct itself +- 'New' ESP value; stored in jmp_buf.esp + +Register values are restored from the jmp_buf as follows: +1. Push jmp_buf.eflags, the current CS value, and jmp_buf.eip + onto the 'new' stack +2. Make ESP point to the jmp_buf struct itself, then use the POPA + instruction to pop the 7 general purpose registers (ESP is not + loaded by POPA). The use of POPA means that registers in the + jmp_buf MUST be stored in the order that POPA expects. + (Maybe use MOVs instead, to eliminate this restriction? + Might have to rewrite entire function in asm, instead of C.) +3. Load ESP with the 'new' stack pointer, from jmp_buf.esp +4. Use IRET to pop EIP, CS, and EFLAGS from the 'new' stack +5. ??? +6. Profit! <--- obligatory Slashdot joke + +This code does NOT save the floating-point state of the CPU. Either: +1. Don't use floating point, or +2. Don't use floating point in more than one thread, or +3. Rewrite this code so it DOES save the floating-point state, or +4. Save/restore the floating-point state when entering/leaving + the kernel (protected OS only) +*****************************************************************************/ +void longjmp(jmp_buf buf, int ret_val) +{ + unsigned *esp; + +/* make sure return value is not 0 */ + if(ret_val == 0) + ret_val++; +/* EAX is used for return values, so store it in jmp_buf.EAX */ + buf->eax = ret_val; +/* get ESP for new stack */ + esp = (unsigned *)buf->esp; +/* push EFLAGS on the new stack */ + esp--; + *esp = buf->eflags; +/* push current CS on the new stack */ + esp--; + __asm__ __volatile__( + "mov %%cs,%0\n" + : "=m"(*esp)); +/* push EIP on the new stack */ + esp--; + *esp = buf->eip; +/* new ESP is 12 bytes lower; update jmp_buf.ESP */ + buf->esp = (unsigned)esp; +/* now, briefly, make the jmp_buf struct our stack */ + __asm__ __volatile__( + "movl %0,%%esp\n" +/* ESP now points to 8 general-purpose registers stored in jmp_buf +Pop them */ + "popa\n" +/* load new stack pointer from jmp_buf */ + "movl -20(%%esp),%%esp\n" +/* ESP now points to new stack, with the IRET frame (EIP, CS, EFLAGS) +we created just above. Pop these registers: */ + "iret\n" + : + : "m"(buf)); +} diff --git a/Dump/hybos/lib/setjmp/setjmp.asm b/Dump/hybos/lib/setjmp/setjmp.asm index dc0ae60..e56d3b1 100644 --- a/Dump/hybos/lib/setjmp/setjmp.asm +++ b/Dump/hybos/lib/setjmp/setjmp.asm @@ -1,35 +1,35 @@ -%include "asm.inc" - -SECTION .text - -EXP setjmp - push ebx - mov ebx,[8 + esp] - - mov [0 + ebx],edi ; buf->edi == 0(ebx) == EDI - mov [4 + ebx],esi ; buf->esi == 4(ebx) == ESI - mov [8 + ebx],ebp ; buf->ebp == 8(ebx) == EBP - - mov [20 + ebx],edx ; buf->edx == 20(ebx) == EDX - mov [24 + ebx],ecx ; buf->ecx == 24(ebx) == ECX - mov [28 + ebx],eax ; buf->eax == 28(ebx) == EAX - -; use EBX value saved on stack; not the current value - mov eax,[esp] - mov [16 + ebx],eax ; buf->ebx == 16(ebx) == EBX - -; use ESP value after RET; not the current value - lea eax,[8 + esp] - mov [12 + ebx],eax ; buf->esp == 32(ebx) == ESP - -; use return address of this routine (EIP value saved on stack); -; not the current value - mov eax,[4 + esp] - mov [32 + ebx],eax ; buf->eip == 36(ebx) == EIP - -; none of the PUSH or MOV instructions changed EFLAGS! - pushf - pop dword [36 + ebx] ; buf->eflags == 40(ebx) == EFLAGS - pop ebx - xor eax,eax - ret +%include "asm.inc" + +SECTION .text + +EXP setjmp + push ebx + mov ebx,[8 + esp] + + mov [0 + ebx],edi ; buf->edi == 0(ebx) == EDI + mov [4 + ebx],esi ; buf->esi == 4(ebx) == ESI + mov [8 + ebx],ebp ; buf->ebp == 8(ebx) == EBP + + mov [20 + ebx],edx ; buf->edx == 20(ebx) == EDX + mov [24 + ebx],ecx ; buf->ecx == 24(ebx) == ECX + mov [28 + ebx],eax ; buf->eax == 28(ebx) == EAX + +; use EBX value saved on stack; not the current value + mov eax,[esp] + mov [16 + ebx],eax ; buf->ebx == 16(ebx) == EBX + +; use ESP value after RET; not the current value + lea eax,[8 + esp] + mov [12 + ebx],eax ; buf->esp == 32(ebx) == ESP + +; use return address of this routine (EIP value saved on stack); +; not the current value + mov eax,[4 + esp] + mov [32 + ebx],eax ; buf->eip == 36(ebx) == EIP + +; none of the PUSH or MOV instructions changed EFLAGS! + pushf + pop dword [36 + ebx] ; buf->eflags == 40(ebx) == EFLAGS + pop ebx + xor eax,eax + ret diff --git a/Dump/hybos/lib/stdio/doprintf.c b/Dump/hybos/lib/stdio/doprintf.c index dc9e8ac..5f281da 100644 --- a/Dump/hybos/lib/stdio/doprintf.c +++ b/Dump/hybos/lib/stdio/doprintf.c @@ -1,357 +1,357 @@ -#include <_printf.h> /* fnptr_t */ -#include /* strlen() */ -#include /* va_list, va_arg() */ -/***************************************************************************** -Revised Jan 28, 2002 -- changes to make characters 0x80-0xFF display properly - -Revised June 10, 2001 -- changes to make vsprintf() terminate string with '\0' - -Revised May 12, 2000 -- math in DO_NUM is now unsigned, as it should be -- %0 flag (pad left with zeroes) now works -- actually did some TESTING, maybe fixed some other bugs - - name: do_printf - action: minimal subfunction for ?printf, calls function - 'fn' with arg 'ptr' for each character to be output - returns:total number of characters output - - %[flag][width][.prec][mod][conv] - flag: - left justify, pad right w/ blanks DONE - 0 pad left w/ 0 for numerics DONE - + always print sign, + or - no - ' ' (blank) no - # (???) no - - width: (field width) DONE - - prec: (precision) no - - conv: d,i decimal int DONE - u decimal unsigned DONE - o octal DONE - x,X hex DONE - f,e,g,E,G float no - c char DONE - s string DONE - p ptr DONE - - mod: N near ptr DONE - F far ptr no - h short (16-bit) int DONE - l long (32-bit) int DONE - L long long (64-bit) int no -*****************************************************************************/ -/* flags used in processing format string */ -#define PR_LJ 0x01 /* left justify */ -#define PR_CA 0x02 /* use A-F instead of a-f for hex */ -#define PR_SG 0x04 /* signed numeric conversion (%d vs. %u) */ -#define PR_32 0x08 /* long (32-bit) numeric conversion */ -#define PR_16 0x10 /* short (16-bit) numeric conversion */ -#define PR_WS 0x20 /* PR_SG set and num was < 0 */ -#define PR_LZ 0x40 /* pad left with '0' instead of ' ' */ -#define PR_FP 0x80 /* pointers are far */ - -/* largest number handled is 2^32-1, lowest radix handled is 8. -2^32-1 in base 8 has 11 digits (add 5 for trailing NUL and for slop) */ -#define PR_BUFLEN 16 - -int do_printf(const char *fmt, va_list args, fnptr_t fn, void *ptr) -{ - unsigned state, flags, radix, actual_wd, count, given_wd; - unsigned char *where, buf[PR_BUFLEN]; - long num; - - state = flags = count = given_wd = 0; -/* begin scanning format specifier list */ - for(; *fmt; fmt++) - { - switch(state) - { -/* STATE 0: AWAITING % */ - case 0: - if(*fmt != '%') /* not %... */ - { - fn(*fmt, &ptr); /* ...just echo it */ - count++; - break; - } -/* found %, get next char and advance state to check if next char is a flag */ - state++; - fmt++; - /* FALL THROUGH */ -/* STATE 1: AWAITING FLAGS (%-0) */ - case 1: - if(*fmt == '%') /* %% */ - { - fn(*fmt, &ptr); - count++; - state = flags = given_wd = 0; - break; - } - if(*fmt == '-') - { - if(flags & PR_LJ)/* %-- is illegal */ - state = flags = given_wd = 0; - else - flags |= PR_LJ; - break; - } -/* not a flag char: advance state to check if it's field width */ - state++; -/* check now for '%0...' */ - if(*fmt == '0') - { - flags |= PR_LZ; - fmt++; - } - /* FALL THROUGH */ -/* STATE 2: AWAITING (NUMERIC) FIELD WIDTH */ - case 2: - if(*fmt >= '0' && *fmt <= '9') - { - given_wd = 10 * given_wd + - (*fmt - '0'); - break; - } -/* not field width: advance state to check if it's a modifier */ - state++; - /* FALL THROUGH */ -/* STATE 3: AWAITING MODIFIER CHARS (FNlh) */ - case 3: - if(*fmt == 'F') - { - flags |= PR_FP; - break; - } - if(*fmt == 'N') - break; - if(*fmt == 'l') - { - flags |= PR_32; - break; - } - if(*fmt == 'h') - { - flags |= PR_16; - break; - } -/* not modifier: advance state to check if it's a conversion char */ - state++; - /* FALL THROUGH */ -/* STATE 4: AWAITING CONVERSION CHARS (Xxpndiuocs) */ - case 4: - where = buf + PR_BUFLEN - 1; - *where = '\0'; - switch(*fmt) - { - case 'X': - flags |= PR_CA; - /* FALL THROUGH */ -/* xxx - far pointers (%Fp, %Fn) not yet supported */ - case 'x': - case 'p': - case 'n': - radix = 16; - goto DO_NUM; - case 'd': - case 'i': - flags |= PR_SG; - /* FALL THROUGH */ - case 'u': - radix = 10; - goto DO_NUM; - case 'o': - radix = 8; -/* load the value to be printed. l=long=32 bits: */ -DO_NUM: if(flags & PR_32) - num = va_arg(args, unsigned long); -/* h=short=16 bits (signed or unsigned) */ - else if(flags & PR_16) - { - if(flags & PR_SG) - num = va_arg(args, short); - else - num = va_arg(args, unsigned short); - } -/* no h nor l: sizeof(int) bits (signed or unsigned) */ - else - { - if(flags & PR_SG) - num = va_arg(args, int); - else - num = va_arg(args, unsigned int); - } -/* take care of sign */ - if(flags & PR_SG) - { - if(num < 0) - { - flags |= PR_WS; - num = -num; - } - } -/* convert binary to octal/decimal/hex ASCII -OK, I found my mistake. The math here is _always_ unsigned */ - do - { - unsigned long temp; - - temp = (unsigned long)num % radix; - where--; - if(temp < 10) - *where = temp + '0'; - else if(flags & PR_CA) - *where = temp - 10 + 'A'; - else - *where = temp - 10 + 'a'; - num = (unsigned long)num / radix; - } - while(num != 0); - goto EMIT; - case 'c': -/* disallow pad-left-with-zeroes for %c */ - flags &= ~PR_LZ; - where--; - *where = (unsigned char)va_arg(args, - unsigned char); - actual_wd = 1; - goto EMIT2; - case 's': -/* disallow pad-left-with-zeroes for %s */ - flags &= ~PR_LZ; - where = va_arg(args, unsigned char *); -EMIT: - actual_wd = strlen(where); - if(flags & PR_WS) - actual_wd++; -/* if we pad left with ZEROES, do the sign now */ - if((flags & (PR_WS | PR_LZ)) == - (PR_WS | PR_LZ)) - { - fn('-', &ptr); - count++; - } -/* pad on left with spaces or zeroes (for right justify) */ -EMIT2: if((flags & PR_LJ) == 0) - { - while(given_wd > actual_wd) - { - fn(flags & PR_LZ ? '0' : - ' ', &ptr); - count++; - given_wd--; - } - } -/* if we pad left with SPACES, do the sign now */ - if((flags & (PR_WS | PR_LZ)) == PR_WS) - { - fn('-', &ptr); - count++; - } -/* emit string/char/converted number */ - while(*where != '\0') - { - fn(*where++, &ptr); - count++; - } -/* pad on right with spaces (for left justify) */ - if(given_wd < actual_wd) - given_wd = 0; - else given_wd -= actual_wd; - for(; given_wd; given_wd--) - { - fn(' ', &ptr); - count++; - } - break; - default: - break; - } - default: - state = flags = given_wd = 0; - break; - } - } - return count; -} -#if 0 /* testing */ -/***************************************************************************** -SPRINTF -*****************************************************************************/ -int vsprintf_help(unsigned c, void **ptr) -{ - char *dst; - - dst = *ptr; - *dst++ = c; - *ptr = dst; - return 0 ; -} -/***************************************************************************** -*****************************************************************************/ -int vsprintf(char *buffer, const char *fmt, va_list args) -{ - int ret_val; - - ret_val = do_printf(fmt, args, vsprintf_help, (void *)buffer); - buffer[ret_val] = '\0'; - return ret_val; -} -/***************************************************************************** -*****************************************************************************/ -int sprintf(char *buffer, const char *fmt, ...) -{ - va_list args; - int ret_val; - - va_start(args, fmt); - ret_val = vsprintf(buffer, fmt, args); - va_end(args); - return ret_val; -} -/***************************************************************************** -PRINTF -You must write your own putchar() -*****************************************************************************/ -int vprintf_help(unsigned c, void **ptr) -{ - putchar(c); - return 0 ; -} -/***************************************************************************** -*****************************************************************************/ -int vprintf(const char *fmt, va_list args) -{ - return do_printf(fmt, args, vprintf_help, NULL); -} -/***************************************************************************** -*****************************************************************************/ -int printf(const char *fmt, ...) -{ - va_list args; - int ret_val; - - va_start(args, fmt); - ret_val = vprintf(fmt, args); - va_end(args); - return ret_val; -} -/***************************************************************************** -*****************************************************************************/ -int main(void) -{ - char buf[64]; - - sprintf(buf, "%u score and %i years ago...\n", 4, -7); - puts(buf); - - sprintf(buf, "-1L == 0x%lX == octal %lo\n", -1L, -1L); - puts(buf); - - printf("<%-08s> and <%08s> justified strings\n", "left", "right"); - return 0; -} -#endif +#include <_printf.h> /* fnptr_t */ +#include /* strlen() */ +#include /* va_list, va_arg() */ +/***************************************************************************** +Revised Jan 28, 2002 +- changes to make characters 0x80-0xFF display properly + +Revised June 10, 2001 +- changes to make vsprintf() terminate string with '\0' + +Revised May 12, 2000 +- math in DO_NUM is now unsigned, as it should be +- %0 flag (pad left with zeroes) now works +- actually did some TESTING, maybe fixed some other bugs + + name: do_printf + action: minimal subfunction for ?printf, calls function + 'fn' with arg 'ptr' for each character to be output + returns:total number of characters output + + %[flag][width][.prec][mod][conv] + flag: - left justify, pad right w/ blanks DONE + 0 pad left w/ 0 for numerics DONE + + always print sign, + or - no + ' ' (blank) no + # (???) no + + width: (field width) DONE + + prec: (precision) no + + conv: d,i decimal int DONE + u decimal unsigned DONE + o octal DONE + x,X hex DONE + f,e,g,E,G float no + c char DONE + s string DONE + p ptr DONE + + mod: N near ptr DONE + F far ptr no + h short (16-bit) int DONE + l long (32-bit) int DONE + L long long (64-bit) int no +*****************************************************************************/ +/* flags used in processing format string */ +#define PR_LJ 0x01 /* left justify */ +#define PR_CA 0x02 /* use A-F instead of a-f for hex */ +#define PR_SG 0x04 /* signed numeric conversion (%d vs. %u) */ +#define PR_32 0x08 /* long (32-bit) numeric conversion */ +#define PR_16 0x10 /* short (16-bit) numeric conversion */ +#define PR_WS 0x20 /* PR_SG set and num was < 0 */ +#define PR_LZ 0x40 /* pad left with '0' instead of ' ' */ +#define PR_FP 0x80 /* pointers are far */ + +/* largest number handled is 2^32-1, lowest radix handled is 8. +2^32-1 in base 8 has 11 digits (add 5 for trailing NUL and for slop) */ +#define PR_BUFLEN 16 + +int do_printf(const char *fmt, va_list args, fnptr_t fn, void *ptr) +{ + unsigned state, flags, radix, actual_wd, count, given_wd; + unsigned char *where, buf[PR_BUFLEN]; + long num; + + state = flags = count = given_wd = 0; +/* begin scanning format specifier list */ + for(; *fmt; fmt++) + { + switch(state) + { +/* STATE 0: AWAITING % */ + case 0: + if(*fmt != '%') /* not %... */ + { + fn(*fmt, &ptr); /* ...just echo it */ + count++; + break; + } +/* found %, get next char and advance state to check if next char is a flag */ + state++; + fmt++; + /* FALL THROUGH */ +/* STATE 1: AWAITING FLAGS (%-0) */ + case 1: + if(*fmt == '%') /* %% */ + { + fn(*fmt, &ptr); + count++; + state = flags = given_wd = 0; + break; + } + if(*fmt == '-') + { + if(flags & PR_LJ)/* %-- is illegal */ + state = flags = given_wd = 0; + else + flags |= PR_LJ; + break; + } +/* not a flag char: advance state to check if it's field width */ + state++; +/* check now for '%0...' */ + if(*fmt == '0') + { + flags |= PR_LZ; + fmt++; + } + /* FALL THROUGH */ +/* STATE 2: AWAITING (NUMERIC) FIELD WIDTH */ + case 2: + if(*fmt >= '0' && *fmt <= '9') + { + given_wd = 10 * given_wd + + (*fmt - '0'); + break; + } +/* not field width: advance state to check if it's a modifier */ + state++; + /* FALL THROUGH */ +/* STATE 3: AWAITING MODIFIER CHARS (FNlh) */ + case 3: + if(*fmt == 'F') + { + flags |= PR_FP; + break; + } + if(*fmt == 'N') + break; + if(*fmt == 'l') + { + flags |= PR_32; + break; + } + if(*fmt == 'h') + { + flags |= PR_16; + break; + } +/* not modifier: advance state to check if it's a conversion char */ + state++; + /* FALL THROUGH */ +/* STATE 4: AWAITING CONVERSION CHARS (Xxpndiuocs) */ + case 4: + where = buf + PR_BUFLEN - 1; + *where = '\0'; + switch(*fmt) + { + case 'X': + flags |= PR_CA; + /* FALL THROUGH */ +/* xxx - far pointers (%Fp, %Fn) not yet supported */ + case 'x': + case 'p': + case 'n': + radix = 16; + goto DO_NUM; + case 'd': + case 'i': + flags |= PR_SG; + /* FALL THROUGH */ + case 'u': + radix = 10; + goto DO_NUM; + case 'o': + radix = 8; +/* load the value to be printed. l=long=32 bits: */ +DO_NUM: if(flags & PR_32) + num = va_arg(args, unsigned long); +/* h=short=16 bits (signed or unsigned) */ + else if(flags & PR_16) + { + if(flags & PR_SG) + num = va_arg(args, short); + else + num = va_arg(args, unsigned short); + } +/* no h nor l: sizeof(int) bits (signed or unsigned) */ + else + { + if(flags & PR_SG) + num = va_arg(args, int); + else + num = va_arg(args, unsigned int); + } +/* take care of sign */ + if(flags & PR_SG) + { + if(num < 0) + { + flags |= PR_WS; + num = -num; + } + } +/* convert binary to octal/decimal/hex ASCII +OK, I found my mistake. The math here is _always_ unsigned */ + do + { + unsigned long temp; + + temp = (unsigned long)num % radix; + where--; + if(temp < 10) + *where = temp + '0'; + else if(flags & PR_CA) + *where = temp - 10 + 'A'; + else + *where = temp - 10 + 'a'; + num = (unsigned long)num / radix; + } + while(num != 0); + goto EMIT; + case 'c': +/* disallow pad-left-with-zeroes for %c */ + flags &= ~PR_LZ; + where--; + *where = (unsigned char)va_arg(args, + unsigned char); + actual_wd = 1; + goto EMIT2; + case 's': +/* disallow pad-left-with-zeroes for %s */ + flags &= ~PR_LZ; + where = va_arg(args, unsigned char *); +EMIT: + actual_wd = strlen(where); + if(flags & PR_WS) + actual_wd++; +/* if we pad left with ZEROES, do the sign now */ + if((flags & (PR_WS | PR_LZ)) == + (PR_WS | PR_LZ)) + { + fn('-', &ptr); + count++; + } +/* pad on left with spaces or zeroes (for right justify) */ +EMIT2: if((flags & PR_LJ) == 0) + { + while(given_wd > actual_wd) + { + fn(flags & PR_LZ ? '0' : + ' ', &ptr); + count++; + given_wd--; + } + } +/* if we pad left with SPACES, do the sign now */ + if((flags & (PR_WS | PR_LZ)) == PR_WS) + { + fn('-', &ptr); + count++; + } +/* emit string/char/converted number */ + while(*where != '\0') + { + fn(*where++, &ptr); + count++; + } +/* pad on right with spaces (for left justify) */ + if(given_wd < actual_wd) + given_wd = 0; + else given_wd -= actual_wd; + for(; given_wd; given_wd--) + { + fn(' ', &ptr); + count++; + } + break; + default: + break; + } + default: + state = flags = given_wd = 0; + break; + } + } + return count; +} +#if 0 /* testing */ +/***************************************************************************** +SPRINTF +*****************************************************************************/ +int vsprintf_help(unsigned c, void **ptr) +{ + char *dst; + + dst = *ptr; + *dst++ = c; + *ptr = dst; + return 0 ; +} +/***************************************************************************** +*****************************************************************************/ +int vsprintf(char *buffer, const char *fmt, va_list args) +{ + int ret_val; + + ret_val = do_printf(fmt, args, vsprintf_help, (void *)buffer); + buffer[ret_val] = '\0'; + return ret_val; +} +/***************************************************************************** +*****************************************************************************/ +int sprintf(char *buffer, const char *fmt, ...) +{ + va_list args; + int ret_val; + + va_start(args, fmt); + ret_val = vsprintf(buffer, fmt, args); + va_end(args); + return ret_val; +} +/***************************************************************************** +PRINTF +You must write your own putchar() +*****************************************************************************/ +int vprintf_help(unsigned c, void **ptr) +{ + putchar(c); + return 0 ; +} +/***************************************************************************** +*****************************************************************************/ +int vprintf(const char *fmt, va_list args) +{ + return do_printf(fmt, args, vprintf_help, NULL); +} +/***************************************************************************** +*****************************************************************************/ +int printf(const char *fmt, ...) +{ + va_list args; + int ret_val; + + va_start(args, fmt); + ret_val = vprintf(fmt, args); + va_end(args); + return ret_val; +} +/***************************************************************************** +*****************************************************************************/ +int main(void) +{ + char buf[64]; + + sprintf(buf, "%u score and %i years ago...\n", 4, -7); + puts(buf); + + sprintf(buf, "-1L == 0x%lX == octal %lo\n", -1L, -1L); + puts(buf); + + printf("<%-08s> and <%08s> justified strings\n", "left", "right"); + return 0; +} +#endif diff --git a/Dump/hybos/lib/stdio/printf.c b/Dump/hybos/lib/stdio/printf.c index 39b1647..9265c3c 100644 --- a/Dump/hybos/lib/stdio/printf.c +++ b/Dump/hybos/lib/stdio/printf.c @@ -1,32 +1,32 @@ -/** - * printf.c - * - */ - -#include /* va_* */ -#include <_printf.h> /* fnptr_t */ -#include - -int do_printf(const char *fmt, va_list args, fnptr_t fn, void *ptr); -void putch(unsigned c); - -int printf_help(unsigned c, void **ptr) -{ - /** - * Leave this for now - */ - ptr = ptr; - - putch(c); - return 0; -} - -void printf(const char *fmt, ...) -{ - va_list args; - - va_start(args, fmt); - (void)do_printf(fmt, args, printf_help, NULL); - va_end(args); -} - +/** + * printf.c + * + */ + +#include /* va_* */ +#include <_printf.h> /* fnptr_t */ +#include + +int do_printf(const char *fmt, va_list args, fnptr_t fn, void *ptr); +void putch(unsigned c); + +int printf_help(unsigned c, void **ptr) +{ + /** + * Leave this for now + */ + ptr = ptr; + + putch(c); + return 0; +} + +void printf(const char *fmt, ...) +{ + va_list args; + + va_start(args, fmt); + (void)do_printf(fmt, args, printf_help, NULL); + va_end(args); +} + diff --git a/Dump/hybos/lib/stdio/sprintf.c b/Dump/hybos/lib/stdio/sprintf.c index 586bb6a..358cc4d 100644 --- a/Dump/hybos/lib/stdio/sprintf.c +++ b/Dump/hybos/lib/stdio/sprintf.c @@ -1,19 +1,19 @@ -/** - * sprintf.c - * - */ - -#include /* va_* */ - -int vsprintf_help(unsigned c, void **ptr); - -int sprintf(char *buffer, const char *fmt, ...) -{ - va_list args; - int ret_val; - - va_start(args, fmt); - ret_val = vsprintf(buffer, fmt, args); - va_end(args); - return ret_val; -} +/** + * sprintf.c + * + */ + +#include /* va_* */ + +int vsprintf_help(unsigned c, void **ptr); + +int sprintf(char *buffer, const char *fmt, ...) +{ + va_list args; + int ret_val; + + va_start(args, fmt); + ret_val = vsprintf(buffer, fmt, args); + va_end(args); + return ret_val; +} diff --git a/Dump/hybos/lib/string/strcat.c b/Dump/hybos/lib/string/strcat.c index 9b87dc5..04cc832 100644 --- a/Dump/hybos/lib/string/strcat.c +++ b/Dump/hybos/lib/string/strcat.c @@ -1,90 +1,90 @@ -/*** -*strncat.c - append n chars of string to new string -* -* Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved. -* -*Purpose: -* defines strncat() - appends n characters of string onto -* end of other string -* -*******************************************************************************/ - - -/*** -*char *strncat(front, back, count) - append count chars of back onto front -* -*Purpose: -* Appends at most count characters of the string back onto the -* end of front, and ALWAYS terminates with a null character. -* If count is greater than the length of back, the length of back -* is used instead. (Unlike strncpy, this routine does not pad out -* to count characters). -* -*Entry: -* char *front - string to append onto -* char *back - string to append -* unsigned count - count of max characters to append -* -*Exit: -* returns a pointer to string appended onto (front). -* -*Uses: -* -*Exceptions: -* -*******************************************************************************/ -#include <_size_t.h> - -/******************************************************************************/ -/* strcat - Concatenate String */ -/* */ -/* This fuction concatenates two strings (add the source string to the end of */ -/* the destination string. It assumes there is enough space in the */ -/* destination to add the source string to it. */ -/* */ -/* s The destination string. */ -/* t The source string. */ -/* @ The destination string. */ -/******************************************************************************/ -char *strcat(char *s, const char *t) -{ - char *c = s; - - /* Find the end of the destination string. */ - while (*s) s++; - - /* Copy the source sting to the destination string. */ - while ((*s++ = *t++)); - - return (c); -} - -/******************************************************************************/ -/* strncat - Concatenate String up to n Characters */ -/* */ -/* This fuction concatenates two strings (add the source string to the end of */ -/* the destination string. It assumes there is enough space in the */ -/* destination to add the source string to it. The total lenght of the */ -/* concatened string may not be larger than n characters. This includes the */ -/* NULL charecter. */ -/* */ -/* s The destination string. */ -/* t The source string. */ -/* n The maximum lenght of the concatednated string. */ -/* @ The destination string. */ -/******************************************************************************/ - -char *strncat(char *front, const char *back, size_t count) -{ - char *start = front; - - while(*front++); - front--; - - while(count--) - if(!(*front++ = *back++)) - return(start); - - *front = '\0'; - return(start); -} +/*** +*strncat.c - append n chars of string to new string +* +* Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved. +* +*Purpose: +* defines strncat() - appends n characters of string onto +* end of other string +* +*******************************************************************************/ + + +/*** +*char *strncat(front, back, count) - append count chars of back onto front +* +*Purpose: +* Appends at most count characters of the string back onto the +* end of front, and ALWAYS terminates with a null character. +* If count is greater than the length of back, the length of back +* is used instead. (Unlike strncpy, this routine does not pad out +* to count characters). +* +*Entry: +* char *front - string to append onto +* char *back - string to append +* unsigned count - count of max characters to append +* +*Exit: +* returns a pointer to string appended onto (front). +* +*Uses: +* +*Exceptions: +* +*******************************************************************************/ +#include <_size_t.h> + +/******************************************************************************/ +/* strcat - Concatenate String */ +/* */ +/* This fuction concatenates two strings (add the source string to the end of */ +/* the destination string. It assumes there is enough space in the */ +/* destination to add the source string to it. */ +/* */ +/* s The destination string. */ +/* t The source string. */ +/* @ The destination string. */ +/******************************************************************************/ +char *strcat(char *s, const char *t) +{ + char *c = s; + + /* Find the end of the destination string. */ + while (*s) s++; + + /* Copy the source sting to the destination string. */ + while ((*s++ = *t++)); + + return (c); +} + +/******************************************************************************/ +/* strncat - Concatenate String up to n Characters */ +/* */ +/* This fuction concatenates two strings (add the source string to the end of */ +/* the destination string. It assumes there is enough space in the */ +/* destination to add the source string to it. The total lenght of the */ +/* concatened string may not be larger than n characters. This includes the */ +/* NULL charecter. */ +/* */ +/* s The destination string. */ +/* t The source string. */ +/* n The maximum lenght of the concatednated string. */ +/* @ The destination string. */ +/******************************************************************************/ + +char *strncat(char *front, const char *back, size_t count) +{ + char *start = front; + + while(*front++); + front--; + + while(count--) + if(!(*front++ = *back++)) + return(start); + + *front = '\0'; + return(start); +} diff --git a/Dump/hybos/lib/string/strcat.c~ b/Dump/hybos/lib/string/strcat.c~ index c46d321..a05385e 100644 --- a/Dump/hybos/lib/string/strcat.c~ +++ b/Dump/hybos/lib/string/strcat.c~ @@ -1,90 +1,90 @@ -/*** -*strncat.c - append n chars of string to new string -* -* Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved. -* -*Purpose: -* defines strncat() - appends n characters of string onto -* end of other string -* -*******************************************************************************/ - - -/*** -*char *strncat(front, back, count) - append count chars of back onto front -* -*Purpose: -* Appends at most count characters of the string back onto the -* end of front, and ALWAYS terminates with a null character. -* If count is greater than the length of back, the length of back -* is used instead. (Unlike strncpy, this routine does not pad out -* to count characters). -* -*Entry: -* char *front - string to append onto -* char *back - string to append -* unsigned count - count of max characters to append -* -*Exit: -* returns a pointer to string appended onto (front). -* -*Uses: -* -*Exceptions: -* -*******************************************************************************/ -#include <_size_t.h> - -/******************************************************************************/ -/* strcat - Concatenate String */ -/* */ -/* This fuction concatenates two strings (add the source string to the end of */ -/* the destination string. It assumes there is enough space in the */ -/* destination to add the source string to it. */ -/* */ -/* s The destination string. */ -/* t The source string. */ -/* @ The destination string. */ -/******************************************************************************/ -char *strcat(char *s, const char *t) -{ - char *c = s; - - /* Find the end of the destination string. */ - while (*s) s++; - - /* Copy the source sting to the destination string. */ - while (*s++ = *t++); - - return (c); -} - -/******************************************************************************/ -/* strncat - Concatenate String up to n Characters */ -/* */ -/* This fuction concatenates two strings (add the source string to the end of */ -/* the destination string. It assumes there is enough space in the */ -/* destination to add the source string to it. The total lenght of the */ -/* concatened string may not be larger than n characters. This includes the */ -/* NULL charecter. */ -/* */ -/* s The destination string. */ -/* t The source string. */ -/* n The maximum lenght of the concatednated string. */ -/* @ The destination string. */ -/******************************************************************************/ - -char *strncat(char *front, const char *back, size_t count) -{ - char *start = front; - - while(*front++); - front--; - - while(count--) - if(!(*front++ = *back++)) - return(start); - - *front = '\0'; - return(start); -} +/*** +*strncat.c - append n chars of string to new string +* +* Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved. +* +*Purpose: +* defines strncat() - appends n characters of string onto +* end of other string +* +*******************************************************************************/ + + +/*** +*char *strncat(front, back, count) - append count chars of back onto front +* +*Purpose: +* Appends at most count characters of the string back onto the +* end of front, and ALWAYS terminates with a null character. +* If count is greater than the length of back, the length of back +* is used instead. (Unlike strncpy, this routine does not pad out +* to count characters). +* +*Entry: +* char *front - string to append onto +* char *back - string to append +* unsigned count - count of max characters to append +* +*Exit: +* returns a pointer to string appended onto (front). +* +*Uses: +* +*Exceptions: +* +*******************************************************************************/ +#include <_size_t.h> + +/******************************************************************************/ +/* strcat - Concatenate String */ +/* */ +/* This fuction concatenates two strings (add the source string to the end of */ +/* the destination string. It assumes there is enough space in the */ +/* destination to add the source string to it. */ +/* */ +/* s The destination string. */ +/* t The source string. */ +/* @ The destination string. */ +/******************************************************************************/ +char *strcat(char *s, const char *t) +{ + char *c = s; + + /* Find the end of the destination string. */ + while (*s) s++; + + /* Copy the source sting to the destination string. */ + while (*s++ = *t++); + + return (c); +} + +/******************************************************************************/ +/* strncat - Concatenate String up to n Characters */ +/* */ +/* This fuction concatenates two strings (add the source string to the end of */ +/* the destination string. It assumes there is enough space in the */ +/* destination to add the source string to it. The total lenght of the */ +/* concatened string may not be larger than n characters. This includes the */ +/* NULL charecter. */ +/* */ +/* s The destination string. */ +/* t The source string. */ +/* n The maximum lenght of the concatednated string. */ +/* @ The destination string. */ +/******************************************************************************/ + +char *strncat(char *front, const char *back, size_t count) +{ + char *start = front; + + while(*front++); + front--; + + while(count--) + if(!(*front++ = *back++)) + return(start); + + *front = '\0'; + return(start); +} diff --git a/Dump/hybos/lib/string/strchr.c b/Dump/hybos/lib/string/strchr.c index 9a0ca0b..881fbff 100644 --- a/Dump/hybos/lib/string/strchr.c +++ b/Dump/hybos/lib/string/strchr.c @@ -1,39 +1,39 @@ -/*** -*strchr.c - search a string for a given character -* -* Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved. -* -*Purpose: -* defines strchr() - search a string for a character -* -*******************************************************************************/ - -/*** -*char *strchr(string, c) - search a string for a character -* -*Purpose: -* Searches a string for a given character, which may be the -* null character '\0'. -* -*Entry: -* char *string - string to search in -* char c - character to search for -* -*Exit: -* returns pointer to the first occurence of c in string -* returns NULL if c does not occur in string -* -*Exceptions: -* -*******************************************************************************/ - -char *strchr(const char * string, int ch) -{ - while(*string && *string != (char)ch) - string++; - - if(*string == (char)ch) - return((char *)string); - - return(0); -} +/*** +*strchr.c - search a string for a given character +* +* Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved. +* +*Purpose: +* defines strchr() - search a string for a character +* +*******************************************************************************/ + +/*** +*char *strchr(string, c) - search a string for a character +* +*Purpose: +* Searches a string for a given character, which may be the +* null character '\0'. +* +*Entry: +* char *string - string to search in +* char c - character to search for +* +*Exit: +* returns pointer to the first occurence of c in string +* returns NULL if c does not occur in string +* +*Exceptions: +* +*******************************************************************************/ + +char *strchr(const char * string, int ch) +{ + while(*string && *string != (char)ch) + string++; + + if(*string == (char)ch) + return((char *)string); + + return(0); +} diff --git a/Dump/hybos/lib/string/strcmp.c b/Dump/hybos/lib/string/strcmp.c index 518bb64..39f5432 100644 --- a/Dump/hybos/lib/string/strcmp.c +++ b/Dump/hybos/lib/string/strcmp.c @@ -1,14 +1,14 @@ -int strcmp(const char * src, const char * dst) -{ - int ret = 0 ; - - while(!(ret = *(unsigned char *)src - *(unsigned char *)dst) && *dst) - ++src, ++dst; - - if(ret < 0) - ret = -1 ; - else if(ret > 0) - ret = 1 ; - - return(ret); -} +int strcmp(const char * src, const char * dst) +{ + int ret = 0 ; + + while(!(ret = *(unsigned char *)src - *(unsigned char *)dst) && *dst) + ++src, ++dst; + + if(ret < 0) + ret = -1 ; + else if(ret > 0) + ret = 1 ; + + return(ret); +} diff --git a/Dump/hybos/lib/string/strcpy.c b/Dump/hybos/lib/string/strcpy.c index 8922e3b..379519a 100644 --- a/Dump/hybos/lib/string/strcpy.c +++ b/Dump/hybos/lib/string/strcpy.c @@ -1,7 +1,7 @@ - -char *strcpy(char *s, const char *t) -{ - while((*(s++) = *(t++))); - - return s; -} + +char *strcpy(char *s, const char *t) +{ + while((*(s++) = *(t++))); + + return s; +} diff --git a/Dump/hybos/lib/string/strcspn.c b/Dump/hybos/lib/string/strcspn.c index 95dd844..c6ac9d9 100644 --- a/Dump/hybos/lib/string/strcspn.c +++ b/Dump/hybos/lib/string/strcspn.c @@ -1,69 +1,69 @@ -/*** -*strspn.c - find length of initial substring of chars from a control string -* -* Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved. -* -*Purpose: -* defines strspn() - finds the length of the initial substring of -* a string consisting entirely of characters from a control string. -* -* defines strcspn()- finds the length of the initial substring of -* a string consisting entirely of characters not in a control string. -* -* defines strpbrk()- finds the index of the first character in a string -* that is not in a control string -* -*******************************************************************************/ -#include -/*** -*int strcspn(string, control) - search for init substring w/o control chars -* -*Purpose: -* returns the index of the first character in string that belongs -* to the set of characters specified by control. This is equivalent -* to the length of the length of the initial substring of string -* composed entirely of characters not in control. Null chars not -* considered. -* -*Entry: -* char *string - string to search -* char *control - set of characters not allowed in init substring -* -*Exit: -* returns the index of the first char in string -* that is in the set of characters specified by control. -* -*Exceptions: -* -*******************************************************************************/ - -size_t strcspn(const char * string, const char * control) -{ - const unsigned char *str = (unsigned char *)string; - const unsigned char *ctrl = (unsigned char *)control; - - unsigned char map[32]; - int count; - - /* Clear out bit map */ - for(count=0; count<32; count++) - map[count] = 0; - - /* Set bits in control map */ - while(*ctrl) - { - map[*ctrl >> 3] |= (1 << (*ctrl & 7)); - ctrl++; - } - - /* 1st char in control map stops search */ - count=0; - map[0] |= 1; /* null chars not considered */ - while(!(map[*str >> 3] & (1 << (*str & 7)))) - { - count++; - str++; - } - - return count; -} +/*** +*strspn.c - find length of initial substring of chars from a control string +* +* Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved. +* +*Purpose: +* defines strspn() - finds the length of the initial substring of +* a string consisting entirely of characters from a control string. +* +* defines strcspn()- finds the length of the initial substring of +* a string consisting entirely of characters not in a control string. +* +* defines strpbrk()- finds the index of the first character in a string +* that is not in a control string +* +*******************************************************************************/ +#include +/*** +*int strcspn(string, control) - search for init substring w/o control chars +* +*Purpose: +* returns the index of the first character in string that belongs +* to the set of characters specified by control. This is equivalent +* to the length of the length of the initial substring of string +* composed entirely of characters not in control. Null chars not +* considered. +* +*Entry: +* char *string - string to search +* char *control - set of characters not allowed in init substring +* +*Exit: +* returns the index of the first char in string +* that is in the set of characters specified by control. +* +*Exceptions: +* +*******************************************************************************/ + +size_t strcspn(const char * string, const char * control) +{ + const unsigned char *str = (unsigned char *)string; + const unsigned char *ctrl = (unsigned char *)control; + + unsigned char map[32]; + int count; + + /* Clear out bit map */ + for(count=0; count<32; count++) + map[count] = 0; + + /* Set bits in control map */ + while(*ctrl) + { + map[*ctrl >> 3] |= (1 << (*ctrl & 7)); + ctrl++; + } + + /* 1st char in control map stops search */ + count=0; + map[0] |= 1; /* null chars not considered */ + while(!(map[*str >> 3] & (1 << (*str & 7)))) + { + count++; + str++; + } + + return count; +} diff --git a/Dump/hybos/lib/string/stricmp.c b/Dump/hybos/lib/string/stricmp.c index 50d64b4..5413b7f 100644 --- a/Dump/hybos/lib/string/stricmp.c +++ b/Dump/hybos/lib/string/stricmp.c @@ -1,49 +1,49 @@ -/*** -*stricmp.c - contains case-insensitive string comp routine _stricmp/_strcmpi -* -* Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved. -* -*Purpose: -* contains _stricmp(), also known as _strcmpi() -* -*******************************************************************************/ - - -/*** -*int _stricmp(dst, src), _strcmpi(dst, src) - compare strings, ignore case -* -*Purpose: -* _stricmp/_strcmpi perform a case-insensitive string comparision. -* For differences, upper case letters are mapped to lower case. -* Thus, "abc_" < "ABCD" since "_" < "d". -* -*Entry: -* char *dst, *src - strings to compare -* -*Return: -* <0 if dst < src -* 0 if dst = src -* >0 if dst > src -* -*Exceptions: -* -*******************************************************************************/ - -/* strcmpi */ - -int stricmp(const char *dst, const char *src) -{ - int f,l; - - do - { - if(((f = (unsigned char)(*(dst++))) >= 'A') && (f <= 'Z')) - f -= ('A' - 'a'); - - if(((l = (unsigned char)(*(src++))) >= 'A') && (l <= 'Z')) - l -= ('A' - 'a'); - } while ( f && (f == l) ); - - - return (f - l); -} +/*** +*stricmp.c - contains case-insensitive string comp routine _stricmp/_strcmpi +* +* Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved. +* +*Purpose: +* contains _stricmp(), also known as _strcmpi() +* +*******************************************************************************/ + + +/*** +*int _stricmp(dst, src), _strcmpi(dst, src) - compare strings, ignore case +* +*Purpose: +* _stricmp/_strcmpi perform a case-insensitive string comparision. +* For differences, upper case letters are mapped to lower case. +* Thus, "abc_" < "ABCD" since "_" < "d". +* +*Entry: +* char *dst, *src - strings to compare +* +*Return: +* <0 if dst < src +* 0 if dst = src +* >0 if dst > src +* +*Exceptions: +* +*******************************************************************************/ + +/* strcmpi */ + +int stricmp(const char *dst, const char *src) +{ + int f,l; + + do + { + if(((f = (unsigned char)(*(dst++))) >= 'A') && (f <= 'Z')) + f -= ('A' - 'a'); + + if(((l = (unsigned char)(*(src++))) >= 'A') && (l <= 'Z')) + l -= ('A' - 'a'); + } while ( f && (f == l) ); + + + return (f - l); +} diff --git a/Dump/hybos/lib/string/strlen.c b/Dump/hybos/lib/string/strlen.c index d37eb21..5245a59 100644 --- a/Dump/hybos/lib/string/strlen.c +++ b/Dump/hybos/lib/string/strlen.c @@ -1,11 +1,11 @@ -#include /* size_t */ -/***************************************************************************** -*****************************************************************************/ -size_t strlen(const char *str) -{ - size_t ret_val; - - for(ret_val = 0; *str != '\0'; str++) - ret_val++; - return ret_val; -} +#include /* size_t */ +/***************************************************************************** +*****************************************************************************/ +size_t strlen(const char *str) +{ + size_t ret_val; + + for(ret_val = 0; *str != '\0'; str++) + ret_val++; + return ret_val; +} diff --git a/Dump/hybos/lib/string/strncmp.c b/Dump/hybos/lib/string/strncmp.c index ab61fd3..50a3ab3 100644 --- a/Dump/hybos/lib/string/strncmp.c +++ b/Dump/hybos/lib/string/strncmp.c @@ -1,15 +1,15 @@ -#include - -int strncmp(const char * first, const char * last, size_t count) -{ - if(!count) - return(0); - - while(--count && *first && *first == *last) - { - first++; - last++; - } - - return( *(unsigned char *)first - *(unsigned char *)last ); -} +#include + +int strncmp(const char * first, const char * last, size_t count) +{ + if(!count) + return(0); + + while(--count && *first && *first == *last) + { + first++; + last++; + } + + return( *(unsigned char *)first - *(unsigned char *)last ); +} diff --git a/Dump/hybos/lib/string/strncpy.c b/Dump/hybos/lib/string/strncpy.c index 1de4174..81ef428 100644 --- a/Dump/hybos/lib/string/strncpy.c +++ b/Dump/hybos/lib/string/strncpy.c @@ -1,15 +1,15 @@ -#include /* size_t */ - -char *strncpy(char * dest, const char * source, size_t count) -{ - char *start = dest; - - while(count && (*dest++ = *source++)) /* copy string */ - count--; - - if(count) /* pad out with zeroes */ - while(--count) - *dest++ = '\0'; - - return(start); -} +#include /* size_t */ + +char *strncpy(char * dest, const char * source, size_t count) +{ + char *start = dest; + + while(count && (*dest++ = *source++)) /* copy string */ + count--; + + if(count) /* pad out with zeroes */ + while(--count) + *dest++ = '\0'; + + return(start); +} diff --git a/Dump/hybos/lib/string/strnicmp.c b/Dump/hybos/lib/string/strnicmp.c index 39204c6..c2a26f4 100644 --- a/Dump/hybos/lib/string/strnicmp.c +++ b/Dump/hybos/lib/string/strnicmp.c @@ -1,56 +1,56 @@ -/*** -*strnicmp.c - compare n chars of strings, ignoring case -* -* Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved. -* -*Purpose: -* defines _strnicmp() - Compares at most n characters of two strings, -* without regard to case. -* -*******************************************************************************/ - -/*** -*int _strnicmp(first, last, count) - compares count char of strings, ignore case -* -*Purpose: -* Compare the two strings for lexical order. Stops the comparison -* when the following occurs: (1) strings differ, (2) the end of the -* strings is reached, or (3) count characters have been compared. -* For the purposes of the comparison, upper case characters are -* converted to lower case. -* -*Entry: -* char *first, *last - strings to compare -* size_t count - maximum number of characters to compare -* -*Exit: -* returns <0 if first < last -* returns 0 if first == last -* returns >0 if first > last -* -*Exceptions: -* -*******************************************************************************/ - -#include <_size_t.h> /* size_t */ - -int strnicmp(const char *first, const char *last, size_t count) -{ - int f,l; - - if(!count) - return 0; - - do - { - if(((f = (unsigned char)(*(first++))) >= 'A') && (f <= 'Z')) - f -= 'A' - 'a'; - - if(((l = (unsigned char)(*(last++))) >= 'A') && (l <= 'Z')) - l -= 'A' - 'a'; - - } while ( --count && f && (f == l) ); - - - return (f - l); -} +/*** +*strnicmp.c - compare n chars of strings, ignoring case +* +* Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved. +* +*Purpose: +* defines _strnicmp() - Compares at most n characters of two strings, +* without regard to case. +* +*******************************************************************************/ + +/*** +*int _strnicmp(first, last, count) - compares count char of strings, ignore case +* +*Purpose: +* Compare the two strings for lexical order. Stops the comparison +* when the following occurs: (1) strings differ, (2) the end of the +* strings is reached, or (3) count characters have been compared. +* For the purposes of the comparison, upper case characters are +* converted to lower case. +* +*Entry: +* char *first, *last - strings to compare +* size_t count - maximum number of characters to compare +* +*Exit: +* returns <0 if first < last +* returns 0 if first == last +* returns >0 if first > last +* +*Exceptions: +* +*******************************************************************************/ + +#include <_size_t.h> /* size_t */ + +int strnicmp(const char *first, const char *last, size_t count) +{ + int f,l; + + if(!count) + return 0; + + do + { + if(((f = (unsigned char)(*(first++))) >= 'A') && (f <= 'Z')) + f -= 'A' - 'a'; + + if(((l = (unsigned char)(*(last++))) >= 'A') && (l <= 'Z')) + l -= 'A' - 'a'; + + } while ( --count && f && (f == l) ); + + + return (f - l); +} diff --git a/Dump/hybos/lib/string/strnpst.c b/Dump/hybos/lib/string/strnpst.c index 6911536..c8a971d 100644 --- a/Dump/hybos/lib/string/strnpst.c +++ b/Dump/hybos/lib/string/strnpst.c @@ -1,11 +1,11 @@ - -char *strnpst(char *s, const char *t, unsigned n) -{ - while(*t && n) - { - *(s++) = *(t++); - n--; - }; - - return s; -} + +char *strnpst(char *s, const char *t, unsigned n) +{ + while(*t && n) + { + *(s++) = *(t++); + n--; + }; + + return s; +} diff --git a/Dump/hybos/lib/string/strnset.c b/Dump/hybos/lib/string/strnset.c index f1edada..51ee8b6 100644 --- a/Dump/hybos/lib/string/strnset.c +++ b/Dump/hybos/lib/string/strnset.c @@ -1,11 +1,11 @@ -#include /* size_t */ - -char *_strnset(char * string, int val, size_t count) -{ - char *start = string; - - while(count-- && *string) - *string++ = (char)val; - - return start; -} +#include /* size_t */ + +char *_strnset(char * string, int val, size_t count) +{ + char *start = string; + + while(count-- && *string) + *string++ = (char)val; + + return start; +} diff --git a/Dump/hybos/lib/string/strpbrk.c b/Dump/hybos/lib/string/strpbrk.c index 26071e2..b277061 100644 --- a/Dump/hybos/lib/string/strpbrk.c +++ b/Dump/hybos/lib/string/strpbrk.c @@ -1,70 +1,70 @@ -/*** -*strspn.c - find length of initial substring of chars from a control string -* -* Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved. -* -*Purpose: -* defines strspn() - finds the length of the initial substring of -* a string consisting entirely of characters from a control string. -* -* defines strcspn()- finds the length of the initial substring of -* a string consisting entirely of characters not in a control string. -* -* defines strpbrk()- finds the index of the first character in a string -* that is not in a control string -* -*******************************************************************************/ - - - -/*** -*char *strpbrk(string, control) - scans string for a character from control -* -*Purpose: -* Finds the first occurence in string of any character from -* the control string. -* -*Entry: -* char *string - string to search in -* char *control - string containing characters to search for -* -*Exit: -* returns a pointer to the first character from control found -* in string. -* returns NULL if string and control have no characters in common. -* -*Exceptions: -* -*******************************************************************************/ - - -char *strpbrk(const char * string, const char * control) -{ - const unsigned char *str = (unsigned char *)string; - const unsigned char *ctrl = (unsigned char *)control; - - unsigned char map[32]; - int count; - - /* Clear out bit map */ - for(count=0; count<32; count++) - map[count] = 0; - - /* Set bits in control map */ - while(*ctrl) - { - map[*ctrl >> 3] |= (1 << (*ctrl & 7)); - ctrl++; - } - - /* 1st char in control map stops search */ - while(*str) - { - if(map[*str >> 3] & (1 << (*str & 7))) - return((char *)str); - - str++; - } - - return 0; -} +/*** +*strspn.c - find length of initial substring of chars from a control string +* +* Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved. +* +*Purpose: +* defines strspn() - finds the length of the initial substring of +* a string consisting entirely of characters from a control string. +* +* defines strcspn()- finds the length of the initial substring of +* a string consisting entirely of characters not in a control string. +* +* defines strpbrk()- finds the index of the first character in a string +* that is not in a control string +* +*******************************************************************************/ + + + +/*** +*char *strpbrk(string, control) - scans string for a character from control +* +*Purpose: +* Finds the first occurence in string of any character from +* the control string. +* +*Entry: +* char *string - string to search in +* char *control - string containing characters to search for +* +*Exit: +* returns a pointer to the first character from control found +* in string. +* returns NULL if string and control have no characters in common. +* +*Exceptions: +* +*******************************************************************************/ + + +char *strpbrk(const char * string, const char * control) +{ + const unsigned char *str = (unsigned char *)string; + const unsigned char *ctrl = (unsigned char *)control; + + unsigned char map[32]; + int count; + + /* Clear out bit map */ + for(count=0; count<32; count++) + map[count] = 0; + + /* Set bits in control map */ + while(*ctrl) + { + map[*ctrl >> 3] |= (1 << (*ctrl & 7)); + ctrl++; + } + + /* 1st char in control map stops search */ + while(*str) + { + if(map[*str >> 3] & (1 << (*str & 7))) + return((char *)str); + + str++; + } + + return 0; +} diff --git a/Dump/hybos/lib/string/strpst.c b/Dump/hybos/lib/string/strpst.c index a571764..051cd3a 100644 --- a/Dump/hybos/lib/string/strpst.c +++ b/Dump/hybos/lib/string/strpst.c @@ -1,10 +1,10 @@ - -char *strpst(char *s, const char *t) -{ - while(*t) - { - *(s++) = *(t++); - }; - - return s; -} + +char *strpst(char *s, const char *t) +{ + while(*t) + { + *(s++) = *(t++); + }; + + return s; +} diff --git a/Dump/hybos/lib/string/strrchr.c b/Dump/hybos/lib/string/strrchr.c index 0a888d7..c1c1b65 100644 --- a/Dump/hybos/lib/string/strrchr.c +++ b/Dump/hybos/lib/string/strrchr.c @@ -1,46 +1,46 @@ -/*** -*strrchr.c - find last occurrence of character in string -* -* Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved. -* -*Purpose: -* defines strrchr() - find the last occurrence of a given character -* in a string. -* -*******************************************************************************/ - - -/*** -*char *strrchr(string, ch) - find last occurrence of ch in string -* -*Purpose: -* Finds the last occurrence of ch in string. The terminating -* null character is used as part of the search. -* -*Entry: -* char *string - string to search in -* char ch - character to search for -* -*Exit: -* returns a pointer to the last occurrence of ch in the given -* string -* returns NULL if ch does not occurr in the string -* -*Exceptions: -* -*******************************************************************************/ - -char *strrchr(const char * string, int ch) -{ - char *start = (char *)string; - - while(*string++); /* find end of string */ - - /* search towards front */ - while(--string != start && *string != (char)ch); - - if(*string == (char)ch) /* char found ? */ - return (char *)string; - - return 0; -} +/*** +*strrchr.c - find last occurrence of character in string +* +* Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved. +* +*Purpose: +* defines strrchr() - find the last occurrence of a given character +* in a string. +* +*******************************************************************************/ + + +/*** +*char *strrchr(string, ch) - find last occurrence of ch in string +* +*Purpose: +* Finds the last occurrence of ch in string. The terminating +* null character is used as part of the search. +* +*Entry: +* char *string - string to search in +* char ch - character to search for +* +*Exit: +* returns a pointer to the last occurrence of ch in the given +* string +* returns NULL if ch does not occurr in the string +* +*Exceptions: +* +*******************************************************************************/ + +char *strrchr(const char * string, int ch) +{ + char *start = (char *)string; + + while(*string++); /* find end of string */ + + /* search towards front */ + while(--string != start && *string != (char)ch); + + if(*string == (char)ch) /* char found ? */ + return (char *)string; + + return 0; +} diff --git a/Dump/hybos/lib/string/strrev.c b/Dump/hybos/lib/string/strrev.c index 6c564ab..aaa84d1 100644 --- a/Dump/hybos/lib/string/strrev.c +++ b/Dump/hybos/lib/string/strrev.c @@ -1,47 +1,47 @@ -/*** -*strrev.c - reverse a string in place -* -* Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved. -* -*Purpose: -* defines _strrev() - reverse a string in place (not including -* '\0' character) -* -*******************************************************************************/ - -/*** -*char *_strrev(string) - reverse a string in place -* -*Purpose: -* Reverses the order of characters in the string. The terminating -* null character remains in place. -* -*Entry: -* char *string - string to reverse -* -*Exit: -* returns string - now with reversed characters -* -*Exceptions: -* -*******************************************************************************/ - -char *_strrev(char *string) -{ - char *start = string; - char *left = string; - char ch; - - while(*string++); /* find end of string */ - - string -= 2; - - while(left < string) - { - ch = *left; - *left++ = *string; - *string-- = ch; - } - - return start; -} +/*** +*strrev.c - reverse a string in place +* +* Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved. +* +*Purpose: +* defines _strrev() - reverse a string in place (not including +* '\0' character) +* +*******************************************************************************/ + +/*** +*char *_strrev(string) - reverse a string in place +* +*Purpose: +* Reverses the order of characters in the string. The terminating +* null character remains in place. +* +*Entry: +* char *string - string to reverse +* +*Exit: +* returns string - now with reversed characters +* +*Exceptions: +* +*******************************************************************************/ + +char *_strrev(char *string) +{ + char *start = string; + char *left = string; + char ch; + + while(*string++); /* find end of string */ + + string -= 2; + + while(left < string) + { + ch = *left; + *left++ = *string; + *string-- = ch; + } + + return start; +} diff --git a/Dump/hybos/lib/string/strset.c b/Dump/hybos/lib/string/strset.c index 4202021..6a338c3 100644 --- a/Dump/hybos/lib/string/strset.c +++ b/Dump/hybos/lib/string/strset.c @@ -1,10 +1,10 @@ - -char *_strset(char *string, int val) -{ - char *start = string; - - while(*string) - *string++ = (char)val; - - return start; -} + +char *_strset(char *string, int val) +{ + char *start = string; + + while(*string) + *string++ = (char)val; + + return start; +} diff --git a/Dump/hybos/lib/string/strspn.c b/Dump/hybos/lib/string/strspn.c index 7298b5d..86a6889 100644 --- a/Dump/hybos/lib/string/strspn.c +++ b/Dump/hybos/lib/string/strspn.c @@ -1,75 +1,75 @@ -/*** -*strspn.c - find length of initial substring of chars from a control string -* -* Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved. -* -*Purpose: -* defines strspn() - finds the length of the initial substring of -* a string consisting entirely of characters from a control string. -* -* defines strcspn()- finds the length of the initial substring of -* a string consisting entirely of characters not in a control string. -* -* defines strpbrk()- finds the index of the first character in a string -* that is not in a control string -* -*******************************************************************************/ - - -/*** -*int strspn(string, control) - find init substring of control chars -* -*Purpose: -* Finds the index of the first character in string that does belong -* to the set of characters specified by control. This is -* equivalent to the length of the initial substring of string that -* consists entirely of characters from control. The '\0' character -* that terminates control is not considered in the matching process. -* -*Entry: -* char *string - string to search -* char *control - string containing characters not to search for -* -*Exit: -* returns index of first char in string not in control -* -*Exceptions: -* -*******************************************************************************/ - -#include /* size_t */ - -size_t strspn(const char *string, const char *control) -{ - const unsigned char *str = (unsigned char *)string; - const unsigned char *ctrl = (unsigned char *)control; - - unsigned char map[32]; - int count; - - /* Clear out bit map */ - for(count=0; count<32; count++) - map[count] = 0; - - /* Set bits in control map */ - while(*ctrl) - { - map[*ctrl >> 3] |= (1 << (*ctrl & 7)); - ctrl++; - } - - /* 1st char NOT in control map stops search */ - if(*str) - { - count=0; - while(map[*str >> 3] & (1 << (*str & 7))) - { - count++; - str++; - } - - return count; - } - - return 0; -} +/*** +*strspn.c - find length of initial substring of chars from a control string +* +* Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved. +* +*Purpose: +* defines strspn() - finds the length of the initial substring of +* a string consisting entirely of characters from a control string. +* +* defines strcspn()- finds the length of the initial substring of +* a string consisting entirely of characters not in a control string. +* +* defines strpbrk()- finds the index of the first character in a string +* that is not in a control string +* +*******************************************************************************/ + + +/*** +*int strspn(string, control) - find init substring of control chars +* +*Purpose: +* Finds the index of the first character in string that does belong +* to the set of characters specified by control. This is +* equivalent to the length of the initial substring of string that +* consists entirely of characters from control. The '\0' character +* that terminates control is not considered in the matching process. +* +*Entry: +* char *string - string to search +* char *control - string containing characters not to search for +* +*Exit: +* returns index of first char in string not in control +* +*Exceptions: +* +*******************************************************************************/ + +#include /* size_t */ + +size_t strspn(const char *string, const char *control) +{ + const unsigned char *str = (unsigned char *)string; + const unsigned char *ctrl = (unsigned char *)control; + + unsigned char map[32]; + int count; + + /* Clear out bit map */ + for(count=0; count<32; count++) + map[count] = 0; + + /* Set bits in control map */ + while(*ctrl) + { + map[*ctrl >> 3] |= (1 << (*ctrl & 7)); + ctrl++; + } + + /* 1st char NOT in control map stops search */ + if(*str) + { + count=0; + while(map[*str >> 3] & (1 << (*str & 7))) + { + count++; + str++; + } + + return count; + } + + return 0; +} diff --git a/Dump/hybos/lib/string/strstr.c b/Dump/hybos/lib/string/strstr.c index bc34107..3bd097b 100644 --- a/Dump/hybos/lib/string/strstr.c +++ b/Dump/hybos/lib/string/strstr.c @@ -1,54 +1,54 @@ -/*** -*strstr.c - search for one string inside another -* -* Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved. -* -*Purpose: -* defines strstr() - search for one string inside another -* -*******************************************************************************/ - -/*** -*char *strstr(string1, string2) - search for string2 in string1 -* -*Purpose: -* finds the first occurrence of string2 in string1 -* -*Entry: -* char *string1 - string to search in -* char *string2 - string to search for -* -*Exit: -* returns a pointer to the first occurrence of string2 in -* string1, or NULL if string2 does not occur in string1 -* -*Uses: -* -*Exceptions: -* -*******************************************************************************/ - -char *strstr(const char * str1, const char * str2) -{ - char *cp = (char *)str1; - char *s1, *s2; - - if(!*str2 ) - return (char *)str1; - - while(*cp) - { - s1 = cp; - s2 = (char *)str2; - - while(*s1 && *s2 && !(*s1-*s2)) - s1++, s2++; - - if(!*s2) - return cp; - - cp++; - } - - return 0; -} +/*** +*strstr.c - search for one string inside another +* +* Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved. +* +*Purpose: +* defines strstr() - search for one string inside another +* +*******************************************************************************/ + +/*** +*char *strstr(string1, string2) - search for string2 in string1 +* +*Purpose: +* finds the first occurrence of string2 in string1 +* +*Entry: +* char *string1 - string to search in +* char *string2 - string to search for +* +*Exit: +* returns a pointer to the first occurrence of string2 in +* string1, or NULL if string2 does not occur in string1 +* +*Uses: +* +*Exceptions: +* +*******************************************************************************/ + +char *strstr(const char * str1, const char * str2) +{ + char *cp = (char *)str1; + char *s1, *s2; + + if(!*str2 ) + return (char *)str1; + + while(*cp) + { + s1 = cp; + s2 = (char *)str2; + + while(*s1 && *s2 && !(*s1-*s2)) + s1++, s2++; + + if(!*s2) + return cp; + + cp++; + } + + return 0; +} diff --git a/Dump/hybos/lib/string/tolower.c b/Dump/hybos/lib/string/tolower.c index afc2c0e..3cdd733 100644 --- a/Dump/hybos/lib/string/tolower.c +++ b/Dump/hybos/lib/string/tolower.c @@ -1,9 +1,9 @@ - -char *tolower(char* s) -{ - while(*s++) - if(*s >= 'A' && *s <= 'Z') - *s += 'a' - 'A'; - - return s; -} + +char *tolower(char* s) +{ + while(*s++) + if(*s >= 'A' && *s <= 'Z') + *s += 'a' - 'A'; + + return s; +} diff --git a/Dump/hybos/lib/string/toupper.c b/Dump/hybos/lib/string/toupper.c index 344820b..b5e3395 100644 --- a/Dump/hybos/lib/string/toupper.c +++ b/Dump/hybos/lib/string/toupper.c @@ -1,10 +1,10 @@ - -char *toupper(char *s) -{ - char *c = '\0'; - while(*s++) - if(*s >= 'a' && *s <= 'z') - *s += 'A' - 'a'; - - return c; -} + +char *toupper(char *s) +{ + char *c = '\0'; + while(*s++) + if(*s >= 'a' && *s <= 'z') + *s += 'A' - 'a'; + + return c; +} diff --git a/Dump/hybos/lib/util/rand.c b/Dump/hybos/lib/util/rand.c index c9188a7..b81e73f 100644 --- a/Dump/hybos/lib/util/rand.c +++ b/Dump/hybos/lib/util/rand.c @@ -1,56 +1,56 @@ -/*** -*rand.c - random number generator -* -* Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved. -* -*Purpose: -* defines rand(), srand() - random number generator -* -*******************************************************************************/ - -static long holdrand = 1L; - - -/*** -*void srand(seed) - seed the random number generator -* -*Purpose: -* Seeds the random number generator with the int given. Adapted from the -* BASIC random number generator. -* -*Entry: -* unsigned seed - seed to seed rand # generator with -* -*Exit: -* None. -* -*Exceptions: -* -*******************************************************************************/ - -void srand(unsigned int seed) -{ - holdrand = (long)seed; -} - - -/*** -*int rand() - returns a random number -* -*Purpose: -* returns a pseudo-random number 0 through 32767. -* -*Entry: -* None. -* -*Exit: -* Returns a pseudo-random number 0 through 32767. -* -*Exceptions: -* -*******************************************************************************/ - -int rand(void) -{ - return (((holdrand = holdrand * 214013L + 2531011L) >> 16) & 0x7fff); -} +/*** +*rand.c - random number generator +* +* Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved. +* +*Purpose: +* defines rand(), srand() - random number generator +* +*******************************************************************************/ + +static long holdrand = 1L; + + +/*** +*void srand(seed) - seed the random number generator +* +*Purpose: +* Seeds the random number generator with the int given. Adapted from the +* BASIC random number generator. +* +*Entry: +* unsigned seed - seed to seed rand # generator with +* +*Exit: +* None. +* +*Exceptions: +* +*******************************************************************************/ + +void srand(unsigned int seed) +{ + holdrand = (long)seed; +} + + +/*** +*int rand() - returns a random number +* +*Purpose: +* returns a pseudo-random number 0 through 32767. +* +*Entry: +* None. +* +*Exit: +* Returns a pseudo-random number 0 through 32767. +* +*Exceptions: +* +*******************************************************************************/ + +int rand(void) +{ + return (((holdrand = holdrand * 214013L + 2531011L) >> 16) & 0x7fff); +} diff --git a/Dump/hybos/lib/x86/disable.c b/Dump/hybos/lib/x86/disable.c index b31ef49..bd6cd30 100644 --- a/Dump/hybos/lib/x86/disable.c +++ b/Dump/hybos/lib/x86/disable.c @@ -1,13 +1,13 @@ -/***************************************************************************** -*****************************************************************************/ -unsigned disable(void) -{ - unsigned ret_val; - - __asm__ __volatile__("pushfl\n" - "popl %0\n" - "cli" - : "=a"(ret_val) - :); - return ret_val; -} +/***************************************************************************** +*****************************************************************************/ +unsigned disable(void) +{ + unsigned ret_val; + + __asm__ __volatile__("pushfl\n" + "popl %0\n" + "cli" + : "=a"(ret_val) + :); + return ret_val; +} diff --git a/Dump/hybos/lib/x86/enable.c b/Dump/hybos/lib/x86/enable.c index bc98632..54f88f3 100644 --- a/Dump/hybos/lib/x86/enable.c +++ b/Dump/hybos/lib/x86/enable.c @@ -1,9 +1,9 @@ -/***************************************************************************** -*****************************************************************************/ -void enable(void) -{ - __asm__ __volatile__("sti" - : - : - ); -} +/***************************************************************************** +*****************************************************************************/ +void enable(void) +{ + __asm__ __volatile__("sti" + : + : + ); +} diff --git a/Dump/hybos/lib/x86/inportb.c b/Dump/hybos/lib/x86/inportb.c index f3088fe..6ba4ea9 100644 --- a/Dump/hybos/lib/x86/inportb.c +++ b/Dump/hybos/lib/x86/inportb.c @@ -1,11 +1,11 @@ -/***************************************************************************** -*****************************************************************************/ -unsigned inportb(unsigned short port) -{ - unsigned char ret_val; - - __asm__ __volatile__("inb %1,%0" - : "=a"(ret_val) - : "d"(port)); - return ret_val; -} +/***************************************************************************** +*****************************************************************************/ +unsigned inportb(unsigned short port) +{ + unsigned char ret_val; + + __asm__ __volatile__("inb %1,%0" + : "=a"(ret_val) + : "d"(port)); + return ret_val; +} diff --git a/Dump/hybos/lib/x86/inportw.c b/Dump/hybos/lib/x86/inportw.c index b541d59..796e319 100644 --- a/Dump/hybos/lib/x86/inportw.c +++ b/Dump/hybos/lib/x86/inportw.c @@ -1,13 +1,13 @@ -unsigned short inportw(int port) -{ - register unsigned short r; - - __asm__ __volatile__ - ( - "inw %%dx, %%ax\n" - : "=a" (r) - : "d" (port) - ); - - return r; -} +unsigned short inportw(int port) +{ + register unsigned short r; + + __asm__ __volatile__ + ( + "inw %%dx, %%ax\n" + : "=a" (r) + : "d" (port) + ); + + return r; +} diff --git a/Dump/hybos/lib/x86/outportb.c b/Dump/hybos/lib/x86/outportb.c index 8346d67..a429606 100644 --- a/Dump/hybos/lib/x86/outportb.c +++ b/Dump/hybos/lib/x86/outportb.c @@ -1,8 +1,8 @@ -/***************************************************************************** -*****************************************************************************/ -void outportb(unsigned port, unsigned val) -{ - __asm__ __volatile__("outb %b0,%w1" - : - : "a"(val), "d"(port)); -} +/***************************************************************************** +*****************************************************************************/ +void outportb(unsigned port, unsigned val) +{ + __asm__ __volatile__("outb %b0,%w1" + : + : "a"(val), "d"(port)); +} diff --git a/Dump/hybos/lib/x86/outportw.c b/Dump/hybos/lib/x86/outportw.c index 5985172..b55a822 100644 --- a/Dump/hybos/lib/x86/outportw.c +++ b/Dump/hybos/lib/x86/outportw.c @@ -1,9 +1,9 @@ -void outportw(int port, unsigned short data) -{ - __asm__ __volatile__ - ( - "outw %%ax, %%dx\n\t" - : - : "a" (data), "d" (port) - ); -} +void outportw(int port, unsigned short data) +{ + __asm__ __volatile__ + ( + "outw %%ax, %%dx\n\t" + : + : "a" (data), "d" (port) + ); +} diff --git a/Dump/hybos/src/README b/Dump/hybos/src/README index dfca7af..ed86715 100644 --- a/Dump/hybos/src/README +++ b/Dump/hybos/src/README @@ -1,20 +1,20 @@ -Directory structure layout for HybOS - -kernel - HybOS kernel source -keymaps - Keyboard keymaps -objects - .o files -fs - Filesystem source -etc - /etc entries for installed system -test - Various system tests -mm - Memory management source -osh - OpenSHell source -esh - ESHell (HybOS Emergency Shell) source +Directory structure layout for HybOS + +kernel + HybOS kernel source +keymaps + Keyboard keymaps +objects + .o files +fs + Filesystem source +etc + /etc entries for installed system +test + Various system tests +mm + Memory management source +osh + OpenSHell source +esh + ESHell (HybOS Emergency Shell) source diff --git a/Dump/hybos/src/esh/esh.c b/Dump/hybos/src/esh/esh.c index 5df2ced..bebce77 100644 --- a/Dump/hybos/src/esh/esh.c +++ b/Dump/hybos/src/esh/esh.c @@ -1,372 +1,372 @@ -/** - * esh.c - * - * Error SHell for HybOS - * - * Exports: - * None. - * - * Imports: - * None. - * - * Description: - * Since esh is called on a new thread in user-space and not in - * kernel-space, imports and exports are not necessary. All the - * kernel needs to know is what functions to call when the - * keyboard buffer has been filled (this even happens when the - * user presses the EOL key, which is the ENTER key on either - * the keypad or the "normal" keyboard). - */ - -#include -#include -#include -#include -#include - -void dumpheapk(void); - -ESHCOMMANDS eshCommands[COMMAND_COUNT]; - - -/** - * keyDown() - * - * This function is called when a key is pressed and is called - * on a new thread which resides in user-space so that esh - * cannot lock up the kernel. - * - * @param unsigned Which key was pressed. See keyboard.h - * - * @return void - */ -void keyDown(unsigned key) -{ - key = key; /* to shut gcc up */ -} - -/** - * keyUp() - * - * This function is called when a key is released. - * - * @param unsigned Which key was released. See keyboard.h - * - * @return void - */ -void keyUp(unsigned key) -{ - key = key; /* to shut gcc up */ -} - -void initCommands(void) -{ - eshCommands[0].minparams = 0; - eshCommands[0].maxparams = 0; - strcpy(eshCommands[0].command, "dumpheap\0"); - strcpy(eshCommands[0].params[0], "-h\0"); - strcpy(eshCommands[0].description, "Print listing of heap usage and status.\0"); - - eshCommands[1].minparams = 1; - eshCommands[1].maxparams = MAX_PARAMS; - strcpy(eshCommands[1].params[0], "-h\0"); - strcpy(eshCommands[1].command, "echo\0"); - strcpy(eshCommands[1].description, "Echo a line of text to the terminal.\0"); - - /*this will be called with either "help" or "help command" */ - eshCommands[2].minparams = 0; - eshCommands[2].maxparams = 1; - strcpy(eshCommands[2].params[0], "-h\0"); - strcpy(eshCommands[2].command, "help\0"); - strcpy(eshCommands[2].description, "Displays general help menu or help on specific command.\0"); - - /* -r|-h [time] */ - eshCommands[3].minparams = 1; - eshCommands[3].maxparams = 2; - strcpy(eshCommands[3].command, "shutdown\0"); - strcpy(eshCommands[3].params[0], "-r\0"); - strcpy(eshCommands[3].params[1], "-h\0"); - strcpy(eshCommands[3].params[2], "NOW\0"); - strcpy(eshCommands[3].description, "Halt or restart the system.\0"); - - /* clear screen */ - eshCommands[4].minparams = 0; - eshCommands[4].maxparams = 0; - strcpy(eshCommands[4].params[0], "-h\0"); - strcpy(eshCommands[4].command, "cls\0"); - strcpy(eshCommands[4].description, "Clears the terminal of all output.\0"); - - /* print working directory */ - eshCommands[5].minparams = 0; - eshCommands[5].maxparams = 0; - strcpy(eshCommands[5].params[0], "-h\0"); - strcpy(eshCommands[5].command, "pwd\0"); - strcpy(eshCommands[5].description, "Prints the current working directory.\0"); -} - -/** - * mapCommand() - * - * Used internally by esh to map a command to it's zero-based - * index of commands. - * - * @param char * the entire line of the command - * - * @return int index of command entry if found, otherwise -1 - */ -int mapCommand(char *cmd) -{ - int i; /* for our loops */ - int params; /* number of parameters found for the command */ - int previdx; /* previous index */ - char cmdName[MAX_LEN]; /* name of the command */ - - i = 0; - previdx = 0; - params = 0; - - /** - * Loop while cmd[i] is not a space - */ - i = 0; - for(i = 0; i < (int)strlen(cmd); i++) - { - if(cmd[i] == ' ') - break; - } - - strncpy(cmdName, cmd, i); - cmdName[i] = '\0'; - - for(i = 0; i < COMMAND_COUNT; i++) - { - if(!strcmp(eshCommands[i].command, cmdName)) - return i; - } - - return -1; -} - -/** - * isParam() - * - * Determines if the supplied parameter is valid for the - * given command. - * - * @param int index of command - * @param char * command string - * - * @return bool true if parameter is valid, false otherwise - */ -bool isParam(int argc, char *argv) -{ - int i; - - for(i = 0; i < MAX_PARAMS; i++) - { - if(!strcmp(eshCommands[argc].params[i], argv)) - return true; - } - - return false; -} - -/** - * mapParams() - * - * Maps each parameter to the pars struct - * - * @param char * Buffer from the command line - * @param struct Parameter structure - * - * @return int Number of command line parameters (arguments) parsed - */ -int mapParams(char *buf, ESHCURRCOMMAND *pars) -{ - int i; /* for our loops */ - int previdx; /* previous index */ - int idx; /* current index */ - int j; /* loops */ - - i = 0; - j = 0; - previdx = 0; - pars->count = 0; - - previdx = mapCommand(buf); - - if(previdx == -1) - return 0; - - strcpy(pars->param[0], eshCommands[previdx].command); - j++; - pars->count++; - - i = 0; - idx = 0; - - for(i = 0; i < (int)strlen(buf); i++) - { - /* we have encountered a seperator */ - if(buf[i] == ' ') - { - if(j > MAX_PARAMS) - break; - - i++; /* skip one space */ - - idx = i; - - if(buf[i] == '"') - { - i++; - idx++; - - while(buf[i] != '"' && i != (int)strlen(buf)) - i++; - - strncpy(pars->param[j], &buf[idx], (i - idx)); - pars->param[j][i - idx] = '\0'; - - idx = i; - j++; - pars->count++; - } - else - { - while(buf[i] != ' ' && i != (int)strlen(buf)) - i++; - - strncpy(pars->param[j], &buf[idx], i - idx); - pars->param[j][i - idx] = '\0'; - i = idx; - j++; - pars->count++; - } - } - } - - return pars->count; -} - -/** - * processCommand() - * - * This function is called when the user has pressed - * the ENTER key. - * - * @param char * The contents of the current buffer or NULL if empty - * @param int Size of the buffer (number of characters) - * - * @return void - */ -void processCommand(char *line, int count) -{ - int i; - int cmd; /* stores the numeric index of the command */ - ESHCURRCOMMAND params; - - count = count; /* to shut gcc up */ - - /*for(i = 0; i < MAX_PARAMS; i++) - params.param[i][0] = '\0';*/ - params.param[0][0] = '\0'; - - initCommands(); - - cmd = mapCommand(line); - mapParams(line, ¶ms); - - switch(cmd) - { - case 0: /* dumpheap */ - dumpheapk(); - //testheap(); - break; - case 1: /* echo */ - for(i = 1; i < params.count; i++) - printf("%s", params.param[i]); - - printf("\n"); - break; - case 2: /* help */ - if(params.count == 1) - { - printf("HybOS EShell Commands:\n"); - for(i = 0; i < COMMAND_COUNT; i++) - if(strlen(eshCommands[i].command) > 0) - printf("%10s %-s\n", eshCommands[i].command, eshCommands[i].description); - } - else - { - cmd = mapCommand(params.param[0]); - mapParams(params.param[1], ¶ms); - - //if(isParam(cmd, params.param[1])) - if(cmd != -1) - { - printf("Usage: %s %s\n", params.param[0], eshCommands[cmd].params[1]); - } - else - printf("esh: '%s' not found.\n", params.param[1]); - } - break; - default: - if(strlen(params.param[0]) > 0 && strcmp(params.param[0], "help")) - printf("esh: '%s' not found.\n", params.param[0]); - else - printf("esh: '%s' not found.\n", &line[0]); - break; - } - - /*for(i = 0; i < params.count; i++) - printf("param[%i]: %s\n", i, params.param[i]);*/ - - //if(isParam(3, ¶ms.param[1])) - // printf("valid parameter\n"); - //else - // printf("invalid parameter\n"); - - return; - - if(!strcmp(line, "dumpheap")) - dumpheapk(); - else if(!strncmp(line, "echo", 4)) - printf("%s\n", line[4] == ' ' ? &line[5] : &line[4]); - else if(!strcmp(line, "help")) - { - printf("HybOS EShell Commands:\n"); - printf("dumpheap\tPrint listing of heap usage and status\n"); - printf("testheap\tTest the heap and print out results\n"); - printf("shutdown -r\tRestart the system.\n"); - printf("pwd\t\tPrint the current working directory.\n"); - } - else if(!strncmp(line, "shutdown", 8)) - { - if(strlen(line) > 9 && !strncmp(&line[9], "-r", 2)) - { - printf("\nSystem shutdown from vtty%u\n", get_current_vc()); - printf("Restarting..."); - //reboot(); - } - else - { - if((strlen(line) > 9) && (strlen(&line[9]) > 0)) - printf("shutdown: Invalid argument \"%s\".\n", &line[9]); - else - printf("Usage: shutdown -r\n"); - } - } - else if((strlen(line) > 0) && (!strcmp(line, "cls"))) - { - printf("\x1B[2J"); - } - else if((strlen(line) >= 8) && (!strcmp(line, "testheap"))) - { - //testheap(); - } - else if((strlen(line) > 0) && (!strcmp(line, "pwd"))) - printf("/\n"); - else if(strlen(line) > 0) - printf("eshell: \"%s\" not found.\n", line); -} +/** + * esh.c + * + * Error SHell for HybOS + * + * Exports: + * None. + * + * Imports: + * None. + * + * Description: + * Since esh is called on a new thread in user-space and not in + * kernel-space, imports and exports are not necessary. All the + * kernel needs to know is what functions to call when the + * keyboard buffer has been filled (this even happens when the + * user presses the EOL key, which is the ENTER key on either + * the keypad or the "normal" keyboard). + */ + +#include +#include +#include +#include +#include + +void dumpheapk(void); + +ESHCOMMANDS eshCommands[COMMAND_COUNT]; + + +/** + * keyDown() + * + * This function is called when a key is pressed and is called + * on a new thread which resides in user-space so that esh + * cannot lock up the kernel. + * + * @param unsigned Which key was pressed. See keyboard.h + * + * @return void + */ +void keyDown(unsigned key) +{ + key = key; /* to shut gcc up */ +} + +/** + * keyUp() + * + * This function is called when a key is released. + * + * @param unsigned Which key was released. See keyboard.h + * + * @return void + */ +void keyUp(unsigned key) +{ + key = key; /* to shut gcc up */ +} + +void initCommands(void) +{ + eshCommands[0].minparams = 0; + eshCommands[0].maxparams = 0; + strcpy(eshCommands[0].command, "dumpheap\0"); + strcpy(eshCommands[0].params[0], "-h\0"); + strcpy(eshCommands[0].description, "Print listing of heap usage and status.\0"); + + eshCommands[1].minparams = 1; + eshCommands[1].maxparams = MAX_PARAMS; + strcpy(eshCommands[1].params[0], "-h\0"); + strcpy(eshCommands[1].command, "echo\0"); + strcpy(eshCommands[1].description, "Echo a line of text to the terminal.\0"); + + /*this will be called with either "help" or "help command" */ + eshCommands[2].minparams = 0; + eshCommands[2].maxparams = 1; + strcpy(eshCommands[2].params[0], "-h\0"); + strcpy(eshCommands[2].command, "help\0"); + strcpy(eshCommands[2].description, "Displays general help menu or help on specific command.\0"); + + /* -r|-h [time] */ + eshCommands[3].minparams = 1; + eshCommands[3].maxparams = 2; + strcpy(eshCommands[3].command, "shutdown\0"); + strcpy(eshCommands[3].params[0], "-r\0"); + strcpy(eshCommands[3].params[1], "-h\0"); + strcpy(eshCommands[3].params[2], "NOW\0"); + strcpy(eshCommands[3].description, "Halt or restart the system.\0"); + + /* clear screen */ + eshCommands[4].minparams = 0; + eshCommands[4].maxparams = 0; + strcpy(eshCommands[4].params[0], "-h\0"); + strcpy(eshCommands[4].command, "cls\0"); + strcpy(eshCommands[4].description, "Clears the terminal of all output.\0"); + + /* print working directory */ + eshCommands[5].minparams = 0; + eshCommands[5].maxparams = 0; + strcpy(eshCommands[5].params[0], "-h\0"); + strcpy(eshCommands[5].command, "pwd\0"); + strcpy(eshCommands[5].description, "Prints the current working directory.\0"); +} + +/** + * mapCommand() + * + * Used internally by esh to map a command to it's zero-based + * index of commands. + * + * @param char * the entire line of the command + * + * @return int index of command entry if found, otherwise -1 + */ +int mapCommand(char *cmd) +{ + int i; /* for our loops */ + int params; /* number of parameters found for the command */ + int previdx; /* previous index */ + char cmdName[MAX_LEN]; /* name of the command */ + + i = 0; + previdx = 0; + params = 0; + + /** + * Loop while cmd[i] is not a space + */ + i = 0; + for(i = 0; i < (int)strlen(cmd); i++) + { + if(cmd[i] == ' ') + break; + } + + strncpy(cmdName, cmd, i); + cmdName[i] = '\0'; + + for(i = 0; i < COMMAND_COUNT; i++) + { + if(!strcmp(eshCommands[i].command, cmdName)) + return i; + } + + return -1; +} + +/** + * isParam() + * + * Determines if the supplied parameter is valid for the + * given command. + * + * @param int index of command + * @param char * command string + * + * @return bool true if parameter is valid, false otherwise + */ +bool isParam(int argc, char *argv) +{ + int i; + + for(i = 0; i < MAX_PARAMS; i++) + { + if(!strcmp(eshCommands[argc].params[i], argv)) + return true; + } + + return false; +} + +/** + * mapParams() + * + * Maps each parameter to the pars struct + * + * @param char * Buffer from the command line + * @param struct Parameter structure + * + * @return int Number of command line parameters (arguments) parsed + */ +int mapParams(char *buf, ESHCURRCOMMAND *pars) +{ + int i; /* for our loops */ + int previdx; /* previous index */ + int idx; /* current index */ + int j; /* loops */ + + i = 0; + j = 0; + previdx = 0; + pars->count = 0; + + previdx = mapCommand(buf); + + if(previdx == -1) + return 0; + + strcpy(pars->param[0], eshCommands[previdx].command); + j++; + pars->count++; + + i = 0; + idx = 0; + + for(i = 0; i < (int)strlen(buf); i++) + { + /* we have encountered a seperator */ + if(buf[i] == ' ') + { + if(j > MAX_PARAMS) + break; + + i++; /* skip one space */ + + idx = i; + + if(buf[i] == '"') + { + i++; + idx++; + + while(buf[i] != '"' && i != (int)strlen(buf)) + i++; + + strncpy(pars->param[j], &buf[idx], (i - idx)); + pars->param[j][i - idx] = '\0'; + + idx = i; + j++; + pars->count++; + } + else + { + while(buf[i] != ' ' && i != (int)strlen(buf)) + i++; + + strncpy(pars->param[j], &buf[idx], i - idx); + pars->param[j][i - idx] = '\0'; + i = idx; + j++; + pars->count++; + } + } + } + + return pars->count; +} + +/** + * processCommand() + * + * This function is called when the user has pressed + * the ENTER key. + * + * @param char * The contents of the current buffer or NULL if empty + * @param int Size of the buffer (number of characters) + * + * @return void + */ +void processCommand(char *line, int count) +{ + int i; + int cmd; /* stores the numeric index of the command */ + ESHCURRCOMMAND params; + + count = count; /* to shut gcc up */ + + /*for(i = 0; i < MAX_PARAMS; i++) + params.param[i][0] = '\0';*/ + params.param[0][0] = '\0'; + + initCommands(); + + cmd = mapCommand(line); + mapParams(line, ¶ms); + + switch(cmd) + { + case 0: /* dumpheap */ + dumpheapk(); + //testheap(); + break; + case 1: /* echo */ + for(i = 1; i < params.count; i++) + printf("%s", params.param[i]); + + printf("\n"); + break; + case 2: /* help */ + if(params.count == 1) + { + printf("HybOS EShell Commands:\n"); + for(i = 0; i < COMMAND_COUNT; i++) + if(strlen(eshCommands[i].command) > 0) + printf("%10s %-s\n", eshCommands[i].command, eshCommands[i].description); + } + else + { + cmd = mapCommand(params.param[0]); + mapParams(params.param[1], ¶ms); + + //if(isParam(cmd, params.param[1])) + if(cmd != -1) + { + printf("Usage: %s %s\n", params.param[0], eshCommands[cmd].params[1]); + } + else + printf("esh: '%s' not found.\n", params.param[1]); + } + break; + default: + if(strlen(params.param[0]) > 0 && strcmp(params.param[0], "help")) + printf("esh: '%s' not found.\n", params.param[0]); + else + printf("esh: '%s' not found.\n", &line[0]); + break; + } + + /*for(i = 0; i < params.count; i++) + printf("param[%i]: %s\n", i, params.param[i]);*/ + + //if(isParam(3, ¶ms.param[1])) + // printf("valid parameter\n"); + //else + // printf("invalid parameter\n"); + + return; + + if(!strcmp(line, "dumpheap")) + dumpheapk(); + else if(!strncmp(line, "echo", 4)) + printf("%s\n", line[4] == ' ' ? &line[5] : &line[4]); + else if(!strcmp(line, "help")) + { + printf("HybOS EShell Commands:\n"); + printf("dumpheap\tPrint listing of heap usage and status\n"); + printf("testheap\tTest the heap and print out results\n"); + printf("shutdown -r\tRestart the system.\n"); + printf("pwd\t\tPrint the current working directory.\n"); + } + else if(!strncmp(line, "shutdown", 8)) + { + if(strlen(line) > 9 && !strncmp(&line[9], "-r", 2)) + { + printf("\nSystem shutdown from vtty%u\n", get_current_vc()); + printf("Restarting..."); + //reboot(); + } + else + { + if((strlen(line) > 9) && (strlen(&line[9]) > 0)) + printf("shutdown: Invalid argument \"%s\".\n", &line[9]); + else + printf("Usage: shutdown -r\n"); + } + } + else if((strlen(line) > 0) && (!strcmp(line, "cls"))) + { + printf("\x1B[2J"); + } + else if((strlen(line) >= 8) && (!strcmp(line, "testheap"))) + { + //testheap(); + } + else if((strlen(line) > 0) && (!strcmp(line, "pwd"))) + printf("/\n"); + else if(strlen(line) > 0) + printf("eshell: \"%s\" not found.\n", line); +} diff --git a/Dump/hybos/src/etc/fstab b/Dump/hybos/src/etc/fstab index 5de9431..8df5be8 100644 --- a/Dump/hybos/src/etc/fstab +++ b/Dump/hybos/src/etc/fstab @@ -1,4 +1,4 @@ -# Poor man's File System Table. - -root=/dev/ROOT -usr=/dev/USR +# Poor man's File System Table. + +root=/dev/ROOT +usr=/dev/USR diff --git a/Dump/hybos/src/etc/group b/Dump/hybos/src/etc/group index 4c7996a..fed5047 100644 --- a/Dump/hybos/src/etc/group +++ b/Dump/hybos/src/etc/group @@ -1,10 +1,10 @@ -operator:*:0: -daemon:*:1: -bin:*:2: -other:*:3: -tty:*:4: -uucp:*:5: -news:*:6: -ftp:*:7: -kmem:*:8: -nogroup:*:99: +operator:*:0: +daemon:*:1: +bin:*:2: +other:*:3: +tty:*:4: +uucp:*:5: +news:*:6: +ftp:*:7: +kmem:*:8: +nogroup:*:99: diff --git a/Dump/hybos/src/etc/passwd b/Dump/hybos/src/etc/passwd index 1560b30..1855a55 100644 --- a/Dump/hybos/src/etc/passwd +++ b/Dump/hybos/src/etc/passwd @@ -1,8 +1,8 @@ -root:##root:0:0::/: -daemon:*:1:1::/etc: -bin:##root:2:0:Binaries:/usr/src:/usr/bin/ash -uucp:*:5:5:UNIX to UNIX copy:/usr/spool/uucp:/usr/bin/uucico -news:*:6:6:Usenet news:/usr/spool/news: -ftp:*:7:7:Anonymous FTP:/usr/ftp: -nobody:*:9999:99::/tmp: -ast:*:8:3:Andrew S. Tanenbaum:/usr/ast: +root:##root:0:0::/: +daemon:*:1:1::/etc: +bin:##root:2:0:Binaries:/usr/src:/usr/bin/ash +uucp:*:5:5:UNIX to UNIX copy:/usr/spool/uucp:/usr/bin/uucico +news:*:6:6:Usenet news:/usr/spool/news: +ftp:*:7:7:Anonymous FTP:/usr/ftp: +nobody:*:9999:99::/tmp: +ast:*:8:3:Andrew S. Tanenbaum:/usr/ast: diff --git a/Dump/hybos/src/etc/profile b/Dump/hybos/src/etc/profile index 741e407..dd8f13d 100644 --- a/Dump/hybos/src/etc/profile +++ b/Dump/hybos/src/etc/profile @@ -1,3 +1,3 @@ -# Set timezone for Middle European Time. - -TZ='MET-1MET DST,M3.5.0/2,M9.5.0/3' export TZ +# Set timezone for Middle European Time. + +TZ='MET-1MET DST,M3.5.0/2,M9.5.0/3' export TZ diff --git a/Dump/hybos/src/etc/protocols b/Dump/hybos/src/etc/protocols index 313d915..1726ef5 100644 --- a/Dump/hybos/src/etc/protocols +++ b/Dump/hybos/src/etc/protocols @@ -1,19 +1,19 @@ -# -# Internet (IP) protocols -# -# @(#)protocols 8.1 (Berkeley) 6/9/93 -# -ip 0 IP # internet protocol, pseudo protocol number -icmp 1 ICMP # internet control message protocol -igmp 2 IGMP # internet group management protocol -ggp 3 GGP # gateway-gateway protocol -tcp 6 TCP # transmission control protocol -egp 8 EGP # exterior gateway protocol -pup 12 PUP # PARC universal packet protocol -udp 17 UDP # user datagram protocol -hmp 20 HMP # host monitoring protocol -xns-idp 22 XNS-IDP # Xerox NS IDP -rdp 27 RDP # reliable data protocol -iso-tp4 29 ISO-TP4 # ISO Transport Protocol Class 4 -iso-ip 80 ISO-IP # ISO Internet Protocol -encap 98 ENCAP # RFC1241 encapsulation +# +# Internet (IP) protocols +# +# @(#)protocols 8.1 (Berkeley) 6/9/93 +# +ip 0 IP # internet protocol, pseudo protocol number +icmp 1 ICMP # internet control message protocol +igmp 2 IGMP # internet group management protocol +ggp 3 GGP # gateway-gateway protocol +tcp 6 TCP # transmission control protocol +egp 8 EGP # exterior gateway protocol +pup 12 PUP # PARC universal packet protocol +udp 17 UDP # user datagram protocol +hmp 20 HMP # host monitoring protocol +xns-idp 22 XNS-IDP # Xerox NS IDP +rdp 27 RDP # reliable data protocol +iso-tp4 29 ISO-TP4 # ISO Transport Protocol Class 4 +iso-ip 80 ISO-IP # ISO Internet Protocol +encap 98 ENCAP # RFC1241 encapsulation diff --git a/Dump/hybos/src/etc/rc b/Dump/hybos/src/etc/rc index d9a3a1d..ee3adc5 100644 --- a/Dump/hybos/src/etc/rc +++ b/Dump/hybos/src/etc/rc @@ -1,24 +1,24 @@ -# This file performs various system initializations. - -umask 022 -PATH=/usr/local/bin:/bin:/usr/bin -export PATH - -# National keyboard? -test -f /etc/keymap && loadkeys /etc/keymap - -# Set timezone. (If the clock tells GMT then put this after 'date'.) -. /etc/profile - -# Try to read the hardware real-time clock, if there is one, to set the date -date `readclock` - -# Initialize files. -printroot >/etc/mtab # /etc/mtab keeps track of mounts ->/etc/utmp # /etc/utmp keeps track of logins - -# /etc/fstab lists the root, tmp and usr devices. -. /etc/fstab - -# Any messages? -test -f /etc/issue && cat /etc/issue +# This file performs various system initializations. + +umask 022 +PATH=/usr/local/bin:/bin:/usr/bin +export PATH + +# National keyboard? +test -f /etc/keymap && loadkeys /etc/keymap + +# Set timezone. (If the clock tells GMT then put this after 'date'.) +. /etc/profile + +# Try to read the hardware real-time clock, if there is one, to set the date +date `readclock` + +# Initialize files. +printroot >/etc/mtab # /etc/mtab keeps track of mounts +>/etc/utmp # /etc/utmp keeps track of logins + +# /etc/fstab lists the root, tmp and usr devices. +. /etc/fstab + +# Any messages? +test -f /etc/issue && cat /etc/issue diff --git a/Dump/hybos/src/etc/services b/Dump/hybos/src/etc/services index 9bcd523..0407095 100644 --- a/Dump/hybos/src/etc/services +++ b/Dump/hybos/src/etc/services @@ -1,85 +1,85 @@ -# -# Network services, Internet style -# -# @(#)services 8.1 (Berkeley) 6/9/93 -# -tcpmux 1/tcp # TCP port multiplexer (RFC1078) -echo 7/tcp -echo 7/udp -discard 9/tcp sink null -discard 9/udp sink null -systat 11/tcp users -daytime 13/tcp -daytime 13/udp -netstat 15/tcp -qotd 17/tcp quote -chargen 19/tcp ttytst source -chargen 19/udp ttytst source -ftp 21/tcp -telnet 23/tcp -smtp 25/tcp mail -time 37/tcp timserver -time 37/udp timserver -rlp 39/udp resource # resource location -nameserver 42/tcp name # IEN 116 -whois 43/tcp nicname -domain 53/tcp nameserver # name-domain server -domain 53/udp nameserver -mtp 57/tcp # deprecated -# Bootp experimental (sellgren@vangogh) -bootp 67/udp # bootp server -#bootpc 68/udp # bootp client -# -tftp 69/udp -rje 77/tcp netrjs -finger 79/tcp -http 80/tcp # World Wide Web -link 87/tcp ttylink -supdup 95/tcp -hostnames 101/tcp hostname # usually from sri-nic -tsap 102/tcp # part of ISODE. -#csnet-cs 105/? -pop 110/tcp postoffice -sunrpc 111/tcp -sunrpc 111/udp -auth 113/tcp authentication -sftp 115/tcp -uucp-path 117/tcp -nntp 119/tcp readnews untp # USENET News Transfer Protocol -ntp 123/udp -snmp 161/udp -snmp-trap 162/udp -# -# UNIX specific services -# -exec 512/tcp -biff 512/udp comsat -login 513/tcp -who 513/udp whod -shell 514/tcp cmd # no passwords used -syslog 514/udp -printer 515/tcp spooler # line printer spooler -talk 517/udp -ntalk 518/udp -route 520/udp router routed -timed 525/udp timeserver -tempo 526/tcp newdate -courier 530/tcp rpc -conference 531/tcp chat -netnews 532/tcp readnews -netwall 533/udp # -for emergency broadcasts -uucp 540/tcp uucpd # uucp daemon -rdist 541/tcp rdistd # rdist daemon -remotefs 556/tcp rfs_server rfs # Brunhoff remote filesystem - -ingreslock 1524/tcp -# -# Kerberos (Project Athena/MIT) services -# -kerberos 750/udp kdc # Kerberos (server) udp -kerberos 750/tcp kdc # Kerberos (server) tcp -krbupdate 760/tcp kreg # Kerberos registration -kpasswd 761/tcp kpwd # Kerberos "passwd" -klogin 543/tcp # Kerberos rlogin -eklogin 2105/tcp # Kerberos encrypted rlogin -kshell 544/tcp krcmd # Kerberos remote shell +# +# Network services, Internet style +# +# @(#)services 8.1 (Berkeley) 6/9/93 +# +tcpmux 1/tcp # TCP port multiplexer (RFC1078) +echo 7/tcp +echo 7/udp +discard 9/tcp sink null +discard 9/udp sink null +systat 11/tcp users +daytime 13/tcp +daytime 13/udp +netstat 15/tcp +qotd 17/tcp quote +chargen 19/tcp ttytst source +chargen 19/udp ttytst source +ftp 21/tcp +telnet 23/tcp +smtp 25/tcp mail +time 37/tcp timserver +time 37/udp timserver +rlp 39/udp resource # resource location +nameserver 42/tcp name # IEN 116 +whois 43/tcp nicname +domain 53/tcp nameserver # name-domain server +domain 53/udp nameserver +mtp 57/tcp # deprecated +# Bootp experimental (sellgren@vangogh) +bootp 67/udp # bootp server +#bootpc 68/udp # bootp client +# +tftp 69/udp +rje 77/tcp netrjs +finger 79/tcp +http 80/tcp # World Wide Web +link 87/tcp ttylink +supdup 95/tcp +hostnames 101/tcp hostname # usually from sri-nic +tsap 102/tcp # part of ISODE. +#csnet-cs 105/? +pop 110/tcp postoffice +sunrpc 111/tcp +sunrpc 111/udp +auth 113/tcp authentication +sftp 115/tcp +uucp-path 117/tcp +nntp 119/tcp readnews untp # USENET News Transfer Protocol +ntp 123/udp +snmp 161/udp +snmp-trap 162/udp +# +# UNIX specific services +# +exec 512/tcp +biff 512/udp comsat +login 513/tcp +who 513/udp whod +shell 514/tcp cmd # no passwords used +syslog 514/udp +printer 515/tcp spooler # line printer spooler +talk 517/udp +ntalk 518/udp +route 520/udp router routed +timed 525/udp timeserver +tempo 526/tcp newdate +courier 530/tcp rpc +conference 531/tcp chat +netnews 532/tcp readnews +netwall 533/udp # -for emergency broadcasts +uucp 540/tcp uucpd # uucp daemon +rdist 541/tcp rdistd # rdist daemon +remotefs 556/tcp rfs_server rfs # Brunhoff remote filesystem + +ingreslock 1524/tcp +# +# Kerberos (Project Athena/MIT) services +# +kerberos 750/udp kdc # Kerberos (server) udp +kerberos 750/tcp kdc # Kerberos (server) tcp +krbupdate 760/tcp kreg # Kerberos registration +kpasswd 761/tcp kpwd # Kerberos "passwd" +klogin 543/tcp # Kerberos rlogin +eklogin 2105/tcp # Kerberos encrypted rlogin +kshell 544/tcp krcmd # Kerberos remote shell diff --git a/Dump/hybos/src/etc/shadow b/Dump/hybos/src/etc/shadow index 15fa36d..3895e9e 100644 --- a/Dump/hybos/src/etc/shadow +++ b/Dump/hybos/src/etc/shadow @@ -1 +1 @@ -root::0:0::: +root::0:0::: diff --git a/Dump/hybos/src/etc/termcap b/Dump/hybos/src/etc/termcap index c5f89b4..b9bde3b 100644 --- a/Dump/hybos/src/etc/termcap +++ b/Dump/hybos/src/etc/termcap @@ -1,64 +1,64 @@ -mx|minix|minix console:\ - :am:xn:bs:\ - :co#80:li#25:\ - :is=\E[0m:\ - :cd=\E[0J:cl=\E[H\E[0J:\ - :so=\E[7m:se=\E[0m:\ - :us=\E[4m:ue=\E[0m:\ - :mb=\E[5m:md=\E[1m:\ - :mr=\E[7m:me=\E[0m:\ - :sr=\EM:\ - :cm=\E[%i%d;%dH:\ - :ho=\E[H:\ - :al=\E[L:AL=\E[%dL:\ - :ce=\E[K:\ - :DC=\E[%dP:dc=\E[P:\ - :DL=\E[%dM:dl=\E[M:\ - :DO=\E[%dB:do=\E[B:\ - :IC=\E[%d@:ic=\E[@:\ - :it#8:\ - :le=^H:LE=\E[%dD:nd=\E[C:\ - :ri=\E[C:RI=\E[%dC:\ - :up=\E[A:UP=\E[%dA:\ - :ku=\E[A:kd=\E[B:\ - :kl=\E[D:kr=\E[C:\ - :kh=\E[H:\ - :k0=\E[Y:l0=End:\ - :k1=\E[V:l1=PgUp:\ - :k2=\E[U:l2=PgDn:\ - :k3=\E[T:l3=Num +:\ - :k4=\E[S:l4=Num -:\ - :k5=\E[G:l5=Num 5: -du|dialup|Dialup line:\ - :bs:co#80:li#24: -db|dumb|Really dumb terminal:\ - :bs:co#80:li#24: -lp|lp|Line Printer:\ - :co#80:li#66: -li|ansi|Ansi standard crt:\ - :am:bs:cd=\E[J:ce=\E[K:cl=\E[2J\E[H:cm=\E[%i%d;%dH:co#80:\ - :dn=\E[B:me=\E[0m:mb=\E[5m:mr=\E[7m:md=\E[1m:ho=\E[H:li#24:\ - :nd=\E[C:ms:pt:so=\E[7m:se=\E[0m:us=\E[4m:ue=\E[0m:up=\E[A:\ - :kb=^h:ku=\E[A:kd=\E[B:kl=\E[D:kr=\E[C: -vs|xterm|xterms|vs100|xterm terminal emulator (X window system):\ - :am:cr=^M:do=^J:nl=^J:bl=^G:le=^H:ho=\E[H:\ - :co#80:li#24:cl=\E[H\E[2J:bs:cm=\E[%i%d;%dH:nd=\E[C:up=\E[A:\ - :ce=\E[K:cd=\E[J:so=\E[7m:se=\E[m:us=\E[4m:ue=\E[m:\ - :md=\E[1m:mr=\E[7m:me=\E[m:\ - :ku=\E[A:kd=\E[B:kr=\E[C:kl=\E[D:kb=^H:\ - :k1=\E[P:k2=\E[Q:k3=\E[R:k4=\E[S:ta=^I:pt:sf=\n:sr=\EM:\ - :al=\E[L:dl=\E[M:ic=\E[@:dc=\E[P:\ - :MT:ks=\E[?1h\E=:ke=\E[?1l\E>:\ - :is=\E[r\E[m\E[2J\E[H\E[?7h\E[?1;3;4;6l:\ - :rs=\E[r\E<\E[m\E[2J\E[H\E[?7h\E[?1;3;4;6l:xn:\ - :AL=\E[%dL:DL=\E[%dM:IC=\E[%d@:DC=\E[%dP:\ - :hs:ts=\E]2;:fs=^G:ds=\E]2;^G: -d0|vt100|vt100-am|vt100am|dec-vt100|dec vt100:\ - :do=^J:co#80:li#24:cl=\E[;H\E[2J:sf=\ED:\ - :le=^H:bs:am:cm=\E[%i%d;%dH:nd=\E[C:up=\E[A:\ - :ce=\E[K:cd=\E[J:so=\E[7m:se=\E[m:us=\E[4m:ue=\E[m:\ - :md=\E[1m:mr=\E[7m:mb=\E[5m:me=\E[m:is=\E[1;24r\E[24;1H:\ - :rs=\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h:ks=\E[?1h\E=:ke=\E[?1l\E>:\ - :ku=\EOA:kd=\EOB:kr=\EOC:kl=\EOD:kb=^H:\ - :ho=\E[H:k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:pt:sr=\EM:vt#3:xn:\ - :sc=\E7:rc=\E8:cs=\E[%i%d;%dr: +mx|minix|minix console:\ + :am:xn:bs:\ + :co#80:li#25:\ + :is=\E[0m:\ + :cd=\E[0J:cl=\E[H\E[0J:\ + :so=\E[7m:se=\E[0m:\ + :us=\E[4m:ue=\E[0m:\ + :mb=\E[5m:md=\E[1m:\ + :mr=\E[7m:me=\E[0m:\ + :sr=\EM:\ + :cm=\E[%i%d;%dH:\ + :ho=\E[H:\ + :al=\E[L:AL=\E[%dL:\ + :ce=\E[K:\ + :DC=\E[%dP:dc=\E[P:\ + :DL=\E[%dM:dl=\E[M:\ + :DO=\E[%dB:do=\E[B:\ + :IC=\E[%d@:ic=\E[@:\ + :it#8:\ + :le=^H:LE=\E[%dD:nd=\E[C:\ + :ri=\E[C:RI=\E[%dC:\ + :up=\E[A:UP=\E[%dA:\ + :ku=\E[A:kd=\E[B:\ + :kl=\E[D:kr=\E[C:\ + :kh=\E[H:\ + :k0=\E[Y:l0=End:\ + :k1=\E[V:l1=PgUp:\ + :k2=\E[U:l2=PgDn:\ + :k3=\E[T:l3=Num +:\ + :k4=\E[S:l4=Num -:\ + :k5=\E[G:l5=Num 5: +du|dialup|Dialup line:\ + :bs:co#80:li#24: +db|dumb|Really dumb terminal:\ + :bs:co#80:li#24: +lp|lp|Line Printer:\ + :co#80:li#66: +li|ansi|Ansi standard crt:\ + :am:bs:cd=\E[J:ce=\E[K:cl=\E[2J\E[H:cm=\E[%i%d;%dH:co#80:\ + :dn=\E[B:me=\E[0m:mb=\E[5m:mr=\E[7m:md=\E[1m:ho=\E[H:li#24:\ + :nd=\E[C:ms:pt:so=\E[7m:se=\E[0m:us=\E[4m:ue=\E[0m:up=\E[A:\ + :kb=^h:ku=\E[A:kd=\E[B:kl=\E[D:kr=\E[C: +vs|xterm|xterms|vs100|xterm terminal emulator (X window system):\ + :am:cr=^M:do=^J:nl=^J:bl=^G:le=^H:ho=\E[H:\ + :co#80:li#24:cl=\E[H\E[2J:bs:cm=\E[%i%d;%dH:nd=\E[C:up=\E[A:\ + :ce=\E[K:cd=\E[J:so=\E[7m:se=\E[m:us=\E[4m:ue=\E[m:\ + :md=\E[1m:mr=\E[7m:me=\E[m:\ + :ku=\E[A:kd=\E[B:kr=\E[C:kl=\E[D:kb=^H:\ + :k1=\E[P:k2=\E[Q:k3=\E[R:k4=\E[S:ta=^I:pt:sf=\n:sr=\EM:\ + :al=\E[L:dl=\E[M:ic=\E[@:dc=\E[P:\ + :MT:ks=\E[?1h\E=:ke=\E[?1l\E>:\ + :is=\E[r\E[m\E[2J\E[H\E[?7h\E[?1;3;4;6l:\ + :rs=\E[r\E<\E[m\E[2J\E[H\E[?7h\E[?1;3;4;6l:xn:\ + :AL=\E[%dL:DL=\E[%dM:IC=\E[%d@:DC=\E[%dP:\ + :hs:ts=\E]2;:fs=^G:ds=\E]2;^G: +d0|vt100|vt100-am|vt100am|dec-vt100|dec vt100:\ + :do=^J:co#80:li#24:cl=\E[;H\E[2J:sf=\ED:\ + :le=^H:bs:am:cm=\E[%i%d;%dH:nd=\E[C:up=\E[A:\ + :ce=\E[K:cd=\E[J:so=\E[7m:se=\E[m:us=\E[4m:ue=\E[m:\ + :md=\E[1m:mr=\E[7m:mb=\E[5m:me=\E[m:is=\E[1;24r\E[24;1H:\ + :rs=\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h:ks=\E[?1h\E=:ke=\E[?1l\E>:\ + :ku=\EOA:kd=\EOB:kr=\EOC:kl=\EOD:kb=^H:\ + :ho=\E[H:k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:pt:sr=\EM:vt#3:xn:\ + :sc=\E7:rc=\E8:cs=\E[%i%d;%dr: diff --git a/Dump/hybos/src/etc/ttytab b/Dump/hybos/src/etc/ttytab index cd566f5..791c116 100644 --- a/Dump/hybos/src/etc/ttytab +++ b/Dump/hybos/src/etc/ttytab @@ -1,13 +1,13 @@ -# ttytab - terminals -# -# Device Type Program Init -console hybos getty -ttyc1 hybos getty -ttyc2 hybos getty -ttyc3 hybos getty -tty00 unknown -tty01 unknown -ttyp0 network -ttyp1 network -ttyp2 network -ttyp3 network +# ttytab - terminals +# +# Device Type Program Init +console hybos getty +ttyc1 hybos getty +ttyc2 hybos getty +ttyc3 hybos getty +tty00 unknown +tty01 unknown +ttyp0 network +ttyp1 network +ttyp2 network +ttyp3 network diff --git a/Dump/hybos/src/fs/buf.h b/Dump/hybos/src/fs/buf.h index 0de78da..5e66342 100644 --- a/Dump/hybos/src/fs/buf.h +++ b/Dump/hybos/src/fs/buf.h @@ -1,31 +1,31 @@ -#ifndef _BUF_H -#define _BUF_H - -#include - -typedef struct buf -{ - union - { - char b__data[BLOCK_SIZE]; /* ordinary user data */ - direct b__dir[NR_DIR_ENTRIES]; /* directory block */ - zone1_t b__v1_ind[V1_INDIRECTS]; /* V1 indirect block */ - zone_t b__v2_ind[V2_INDIRECTS]; /* V2 indirect block */ - d1_inode b__v1_ino[V1_INODES_PER_BLOCK]; /* V1 inode block */ - d2_inode b__v2_ino[V2_INODES_PER_BLOCK]; /* V2 inode block */ - bitchunk_t b__bitmap[BITMAP_CHUNKS]; /* bit map block */ - } b; - - /** - * Header portion of the buffer - */ - struct buf *b_next; /* used to link all free bufs in a chain */ - struct buf *b_prev; /* used to link all free bufs the other way */ - struct buf *b_hash; /* used to link all bufs on hash chains */ - block_t b_blocknr; /* block number of its (minor) device */ - dev_t b_dev; /* major | minor device where block resides */ - char b_dirt; /* CLEAN or DIRTY */ - char b_count; /* number of users of this buffer */ -} buf[NR_BUFFS]; - -#endif /* _BUF_H */ +#ifndef _BUF_H +#define _BUF_H + +#include + +typedef struct buf +{ + union + { + char b__data[BLOCK_SIZE]; /* ordinary user data */ + direct b__dir[NR_DIR_ENTRIES]; /* directory block */ + zone1_t b__v1_ind[V1_INDIRECTS]; /* V1 indirect block */ + zone_t b__v2_ind[V2_INDIRECTS]; /* V2 indirect block */ + d1_inode b__v1_ino[V1_INODES_PER_BLOCK]; /* V1 inode block */ + d2_inode b__v2_ino[V2_INODES_PER_BLOCK]; /* V2 inode block */ + bitchunk_t b__bitmap[BITMAP_CHUNKS]; /* bit map block */ + } b; + + /** + * Header portion of the buffer + */ + struct buf *b_next; /* used to link all free bufs in a chain */ + struct buf *b_prev; /* used to link all free bufs the other way */ + struct buf *b_hash; /* used to link all bufs on hash chains */ + block_t b_blocknr; /* block number of its (minor) device */ + dev_t b_dev; /* major | minor device where block resides */ + char b_dirt; /* CLEAN or DIRTY */ + char b_count; /* number of users of this buffer */ +} buf[NR_BUFFS]; + +#endif /* _BUF_H */ diff --git a/Dump/hybos/src/kernel/_krnl.h b/Dump/hybos/src/kernel/_krnl.h index 8354cca..e268bd9 100644 --- a/Dump/hybos/src/kernel/_krnl.h +++ b/Dump/hybos/src/kernel/_krnl.h @@ -1,131 +1,131 @@ -#ifndef __TL__KRNL_H -#define __TL__KRNL_H - -//#ifdef __cplusplus -//extern "C" -//{ -//#endif - -#include /* jmp_buf */ - -#define MAX_VC 12 /* maximum number of virtual terminals */ - -/** - * CPU error codes - */ -#define _K_CPU_DBZ 0 /* Divide by zero */ -#define _K_CPU_SS 1 /* Single Step */ -#define _K_CPU_NMI 2 /* Non-maskable (NMI) */ -#define _K_CPU_BPX 3 /* Breakpoint */ -#define _K_CPU_OFT 4 /* Overflow trap */ -#define _K_CPU_BND 5 /* BOUND range exceeded */ -#define _K_CPU_IOP 6 /* Invalid opcode */ -#define _K_CPU_CNA 7 /* Coprocessor not available */ -#define _K_CPU_DFE 8 /* Double fault exception */ -#define _K_CPU_CSO 9 /* Coprocessor segment overrun */ -#define _K_CPU_CPE 10 /* Coprocessor error */ -#define _K_CPU_ITS 0x0A /* Invalid task state management */ -#define _K_CPU_SNP 0x0B /* Segment not present */ -#define _K_CPU_SEX 0x0C /* Stack exception (or illicit sex) */ -#define _K_CPU_GPF 0x0D /* General protection exception */ -#define _K_CPU_PGF 0x0E /* Page fault */ - -/** - * Interrupt table - */ -#define _K_IRQ_TIMER 0x08 /* timer (55ms intervals, 18.21590/sec) */ -#define _K_IRQ_KEYBOARD 0x09 /* keyboard service required */ -#define _K_IRQ_S8259 0x0A /* slave 8259 or EGA/VGA vertical retrace */ -#define _K_IRQ_COM2 0x0B /* COM2 service required (PS/2 MCA COM3-COM8) */ -#define _K_IRQ_COM1 0x0C /* COM1 service required */ -#define _K_IRQ_HDDREQ 0x0D /* fixed disk or data request from LPT2 */ -#define _K_IRQ_FDDSERV 0x0E /* floppy disk service required */ -#define _K_IRQ_LPT1REQ 0x0F /* data request from LPT1 */ -#define _K_IRQ_VIDEO 0x10 /* video (int 10h) */ -#define _K_IRQ_EQPDET 0x11 /* equipment determination (int 11h) */ -#define _K_IRQ_MEMORY 0x12 /* memory size (int 12h) */ -#define _K_IRQ_DIO 0x13 /* disk I/O service (int 13h) */ -#define _K_IRQ_SERIAL 0x14 /* serial communications (int 14h) */ -#define _K_IRQ_SYSTEM 0x15 /* system services, cassette (int 15h) */ -#define _K_IRQ_KBDSERV 0x16 /* keyboard services (int 16h) */ -#define _K_IRQ_LPT 0x17 /* parallel printer (int 17h) */ -#define _K_IRQ_ROM 0x18 /* ROM BASIC loader */ -#define _K_IRQ_BTSTRAP 0x19 /* bootstrap loader (unreliable, int 19h) */ -#define _K_IRQ_TOD 0x1A /* time of day (int 1A) */ -#define _K_IRQ_CBREAK 0x1B /* user defined ctrl-break handler (int 1B) */ -#define _K_IRQ_TICK 0x1C /* user defined clock tick handler (int 1C) */ -#define _K_IRQ_VIDEOP 0x1D /* 6845 video parameter pointer */ -#define _K_IRQ_DISKPARAM 0x1E /* diskette parameter pointer (base table) */ -#define _K_IRQ_GCHTBL 0x1F /* graphics character table */ -#define _K_IRQ_HDD 0x40 /* hard disk */ -#define _K_IRQ_FIXEDD0 0x41 /* fixed disk 0 parameters pointer (int 13h, int 9h) */ -#define _K_IRQ_RELVID 0x42 /* relocated video handler (EGA/VGA/PS) */ -#define _K_IRQ_UFT 0x43 /* user font table (EGA/VGA/PS) */ -#define _K_IRQ_GRAPH 0x44 /* first 128 graphics characters (also Netware) */ -#define _K_IRQ_FIXED1 0x46 /* fixed disk 1 parameters ptr (int 13h, int 9h/int 41h) */ -#define _K_IRQ_PCJR 0x48 /* PCjr cordless keyboard translation */ -#define _K_IRQ_PCJRSCAN 0x49 /* PCjr non-keyboard scancode translation table */ -#define _K_IRQ_USERALARM 0x4A /* user alarm (int 4A) */ -#define _K_IRQ_PALARM 0x50 /* periodic alarm timer (PS/2) */ -#define _K_IRQ_GSS 0x59 /* GSS computer graphics interface */ -#define _K_IRQ_BIOSEP 0x5A /* cluster adapter BIOS entry point */ -#define _K_IRQ_CADAPBT 0x5B /* cluster adapter boot */ -#define _K_IRQ_NETBIOS 0x5C /* NETBIOS interface, TOPS interface */ -#define _K_IRQ_EMS 0x67 /* LIM/EMS specifications (int 67h) */ -#define _K_IRQ_APPC 0x68 /* APPC */ -#define _K_IRQ_RTC 0x70 /* real time clock (int 15h) */ -#define _K_IRQ_REDIRIRQ2 0x71 /* software redirected to IRQ2 */ -#define _K_IRQ_MOUSE 0x74 /* mouse interrupt */ -#define _K_IRQ_HDC 0x76 /* fixed disk controller */ - -/* the code for setvect() and getvect() in -KSTART.ASM depends on the layout of this structure */ -typedef struct -{ - unsigned access_byte, eip; -} vector_t; - -/* the layout of this structure must match the order of registers -pushed and popped by the exception handlers in KSTART.ASM */ -typedef struct -{ -/* pushed by pusha */ - unsigned edi, esi, ebp, esp, ebx, edx, ecx, eax; -/* pushed separately */ - unsigned ds, es, fs, gs; - unsigned which_int, err_code; -/* pushed by exception. Exception may also push err_code. -user_esp and user_ss are pushed only if a privilege change occurs. */ - unsigned eip, cs, eflags, user_esp, user_ss; -} regs_t; - -typedef struct /* circular queue */ -{ - unsigned char *data; - unsigned size, in_base, in_ptr/*, out_base*/, out_ptr; -} queue_t; - -typedef struct -{ -/* virtual console input */ - queue_t keystrokes; -/* virtual console output */ - unsigned esc, attrib, csr_x, csr_y, esc1, esc2, esc3; - unsigned short *fb_adr; -} console_t; - -typedef struct -{ - console_t *vc; - jmp_buf state; - enum - { - TS_RUNNABLE = 1, TS_BLOCKED = 2, TS_ZOMBIE = 3 - } status; -} task_t; - -#ifdef __cplusplus -} -#endif - -#endif +#ifndef __TL__KRNL_H +#define __TL__KRNL_H + +//#ifdef __cplusplus +//extern "C" +//{ +//#endif + +#include /* jmp_buf */ + +#define MAX_VC 12 /* maximum number of virtual terminals */ + +/** + * CPU error codes + */ +#define _K_CPU_DBZ 0 /* Divide by zero */ +#define _K_CPU_SS 1 /* Single Step */ +#define _K_CPU_NMI 2 /* Non-maskable (NMI) */ +#define _K_CPU_BPX 3 /* Breakpoint */ +#define _K_CPU_OFT 4 /* Overflow trap */ +#define _K_CPU_BND 5 /* BOUND range exceeded */ +#define _K_CPU_IOP 6 /* Invalid opcode */ +#define _K_CPU_CNA 7 /* Coprocessor not available */ +#define _K_CPU_DFE 8 /* Double fault exception */ +#define _K_CPU_CSO 9 /* Coprocessor segment overrun */ +#define _K_CPU_CPE 10 /* Coprocessor error */ +#define _K_CPU_ITS 0x0A /* Invalid task state management */ +#define _K_CPU_SNP 0x0B /* Segment not present */ +#define _K_CPU_SEX 0x0C /* Stack exception (or illicit sex) */ +#define _K_CPU_GPF 0x0D /* General protection exception */ +#define _K_CPU_PGF 0x0E /* Page fault */ + +/** + * Interrupt table + */ +#define _K_IRQ_TIMER 0x08 /* timer (55ms intervals, 18.21590/sec) */ +#define _K_IRQ_KEYBOARD 0x09 /* keyboard service required */ +#define _K_IRQ_S8259 0x0A /* slave 8259 or EGA/VGA vertical retrace */ +#define _K_IRQ_COM2 0x0B /* COM2 service required (PS/2 MCA COM3-COM8) */ +#define _K_IRQ_COM1 0x0C /* COM1 service required */ +#define _K_IRQ_HDDREQ 0x0D /* fixed disk or data request from LPT2 */ +#define _K_IRQ_FDDSERV 0x0E /* floppy disk service required */ +#define _K_IRQ_LPT1REQ 0x0F /* data request from LPT1 */ +#define _K_IRQ_VIDEO 0x10 /* video (int 10h) */ +#define _K_IRQ_EQPDET 0x11 /* equipment determination (int 11h) */ +#define _K_IRQ_MEMORY 0x12 /* memory size (int 12h) */ +#define _K_IRQ_DIO 0x13 /* disk I/O service (int 13h) */ +#define _K_IRQ_SERIAL 0x14 /* serial communications (int 14h) */ +#define _K_IRQ_SYSTEM 0x15 /* system services, cassette (int 15h) */ +#define _K_IRQ_KBDSERV 0x16 /* keyboard services (int 16h) */ +#define _K_IRQ_LPT 0x17 /* parallel printer (int 17h) */ +#define _K_IRQ_ROM 0x18 /* ROM BASIC loader */ +#define _K_IRQ_BTSTRAP 0x19 /* bootstrap loader (unreliable, int 19h) */ +#define _K_IRQ_TOD 0x1A /* time of day (int 1A) */ +#define _K_IRQ_CBREAK 0x1B /* user defined ctrl-break handler (int 1B) */ +#define _K_IRQ_TICK 0x1C /* user defined clock tick handler (int 1C) */ +#define _K_IRQ_VIDEOP 0x1D /* 6845 video parameter pointer */ +#define _K_IRQ_DISKPARAM 0x1E /* diskette parameter pointer (base table) */ +#define _K_IRQ_GCHTBL 0x1F /* graphics character table */ +#define _K_IRQ_HDD 0x40 /* hard disk */ +#define _K_IRQ_FIXEDD0 0x41 /* fixed disk 0 parameters pointer (int 13h, int 9h) */ +#define _K_IRQ_RELVID 0x42 /* relocated video handler (EGA/VGA/PS) */ +#define _K_IRQ_UFT 0x43 /* user font table (EGA/VGA/PS) */ +#define _K_IRQ_GRAPH 0x44 /* first 128 graphics characters (also Netware) */ +#define _K_IRQ_FIXED1 0x46 /* fixed disk 1 parameters ptr (int 13h, int 9h/int 41h) */ +#define _K_IRQ_PCJR 0x48 /* PCjr cordless keyboard translation */ +#define _K_IRQ_PCJRSCAN 0x49 /* PCjr non-keyboard scancode translation table */ +#define _K_IRQ_USERALARM 0x4A /* user alarm (int 4A) */ +#define _K_IRQ_PALARM 0x50 /* periodic alarm timer (PS/2) */ +#define _K_IRQ_GSS 0x59 /* GSS computer graphics interface */ +#define _K_IRQ_BIOSEP 0x5A /* cluster adapter BIOS entry point */ +#define _K_IRQ_CADAPBT 0x5B /* cluster adapter boot */ +#define _K_IRQ_NETBIOS 0x5C /* NETBIOS interface, TOPS interface */ +#define _K_IRQ_EMS 0x67 /* LIM/EMS specifications (int 67h) */ +#define _K_IRQ_APPC 0x68 /* APPC */ +#define _K_IRQ_RTC 0x70 /* real time clock (int 15h) */ +#define _K_IRQ_REDIRIRQ2 0x71 /* software redirected to IRQ2 */ +#define _K_IRQ_MOUSE 0x74 /* mouse interrupt */ +#define _K_IRQ_HDC 0x76 /* fixed disk controller */ + +/* the code for setvect() and getvect() in +KSTART.ASM depends on the layout of this structure */ +typedef struct +{ + unsigned access_byte, eip; +} vector_t; + +/* the layout of this structure must match the order of registers +pushed and popped by the exception handlers in KSTART.ASM */ +typedef struct +{ +/* pushed by pusha */ + unsigned edi, esi, ebp, esp, ebx, edx, ecx, eax; +/* pushed separately */ + unsigned ds, es, fs, gs; + unsigned which_int, err_code; +/* pushed by exception. Exception may also push err_code. +user_esp and user_ss are pushed only if a privilege change occurs. */ + unsigned eip, cs, eflags, user_esp, user_ss; +} regs_t; + +typedef struct /* circular queue */ +{ + unsigned char *data; + unsigned size, in_base, in_ptr/*, out_base*/, out_ptr; +} queue_t; + +typedef struct +{ +/* virtual console input */ + queue_t keystrokes; +/* virtual console output */ + unsigned esc, attrib, csr_x, csr_y, esc1, esc2, esc3; + unsigned short *fb_adr; +} console_t; + +typedef struct +{ + console_t *vc; + jmp_buf state; + enum + { + TS_RUNNABLE = 1, TS_BLOCKED = 2, TS_ZOMBIE = 3 + } status; +} task_t; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/Dump/hybos/src/kernel/bootlog.c b/Dump/hybos/src/kernel/bootlog.c index c03200a..18f87fd 100644 --- a/Dump/hybos/src/kernel/bootlog.c +++ b/Dump/hybos/src/kernel/bootlog.c @@ -1,78 +1,78 @@ -#include -#include -#include -#include -#include <_printf.h> /* do_printf() */ -#include "_krnl.h" -#include "bootlog.h" - -void klog(char *proc, char *entry, KLOGRESULT result, console_t *vtty0) -{ - unsigned oldattrib; - int i = 0; - int offset = 69; /* -4 for the "[ ]" part, -2 for the ": " part, -1 for space at end, and -4 for the status */ - char status[4]; - va_list args; - - args = args; - status[0] = '\0'; - - /** - * Save our old color attributes - */ - oldattrib = vtty0->attrib; - - if(result == K_KLOG_SUCCESS) - { - /** - * Successfull initialization of something. - * Write "..Ok" then leave - */ - vtty0->attrib = 8; - printf("\b\b\b\b.."); - vtty0->attrib = 2; - printf("Ok\n"); - vtty0->attrib = oldattrib; - - return; - } - else if(result == K_KLOG_FAILURE) - { - /** - * Unsuccessfull initialization of something. - * Write "Fail" then leave - */ - vtty0->attrib = 4; - printf("\b\b\b\bFail\n"); - vtty0->attrib = oldattrib; - - return; - } - - /** - * FIXME - * - * Should "wrap" the line instead - */ - if(strlen(entry) + 8 > 80) - return; - - vtty0->attrib = 8; - printf("[ "); - vtty0->attrib = 15; - printf("%s: %s", proc, entry); - vtty0->attrib = 8; - printf(" ]"); - - offset -= strlen(proc); - offset -= strlen(entry); - - for(i = 0; i < offset; i++) - printf("."); - - vtty0->attrib = 8; - printf("Wait"); - - vtty0->attrib = oldattrib; -} - +#include +#include +#include +#include +#include <_printf.h> /* do_printf() */ +#include "_krnl.h" +#include "bootlog.h" + +void klog(char *proc, char *entry, KLOGRESULT result, console_t *vtty0) +{ + unsigned oldattrib; + int i = 0; + int offset = 69; /* -4 for the "[ ]" part, -2 for the ": " part, -1 for space at end, and -4 for the status */ + char status[4]; + va_list args; + + args = args; + status[0] = '\0'; + + /** + * Save our old color attributes + */ + oldattrib = vtty0->attrib; + + if(result == K_KLOG_SUCCESS) + { + /** + * Successfull initialization of something. + * Write "..Ok" then leave + */ + vtty0->attrib = 8; + printf("\b\b\b\b.."); + vtty0->attrib = 2; + printf("Ok\n"); + vtty0->attrib = oldattrib; + + return; + } + else if(result == K_KLOG_FAILURE) + { + /** + * Unsuccessfull initialization of something. + * Write "Fail" then leave + */ + vtty0->attrib = 4; + printf("\b\b\b\bFail\n"); + vtty0->attrib = oldattrib; + + return; + } + + /** + * FIXME + * + * Should "wrap" the line instead + */ + if(strlen(entry) + 8 > 80) + return; + + vtty0->attrib = 8; + printf("[ "); + vtty0->attrib = 15; + printf("%s: %s", proc, entry); + vtty0->attrib = 8; + printf(" ]"); + + offset -= strlen(proc); + offset -= strlen(entry); + + for(i = 0; i < offset; i++) + printf("."); + + vtty0->attrib = 8; + printf("Wait"); + + vtty0->attrib = oldattrib; +} + diff --git a/Dump/hybos/src/kernel/bootlog.h b/Dump/hybos/src/kernel/bootlog.h index 83c3b86..4acee94 100644 --- a/Dump/hybos/src/kernel/bootlog.h +++ b/Dump/hybos/src/kernel/bootlog.h @@ -1,15 +1,15 @@ -#ifndef _BOOTLOG_H -#define _BOOTLOG_H -#include -#include -#include "_krnl.h" - -typedef unsigned KLOGRESULT; - -#define K_KLOG_SUCCESS 0x00 /* successfull completion of task, finish log message */ -#define K_KLOG_PENDING 0x01 /* task hasn't completed yet, delay logging status */ -#define K_KLOG_FAILURE 0x02 /* unsuccessfull completion of task, finish log message */ - -void klog(char *proc, char *entry, KLOGRESULT result, console_t *vtty0); - -#endif /* !defined(_BOOTLOG_H) */ +#ifndef _BOOTLOG_H +#define _BOOTLOG_H +#include +#include +#include "_krnl.h" + +typedef unsigned KLOGRESULT; + +#define K_KLOG_SUCCESS 0x00 /* successfull completion of task, finish log message */ +#define K_KLOG_PENDING 0x01 /* task hasn't completed yet, delay logging status */ +#define K_KLOG_FAILURE 0x02 /* unsuccessfull completion of task, finish log message */ + +void klog(char *proc, char *entry, KLOGRESULT result, console_t *vtty0); + +#endif /* !defined(_BOOTLOG_H) */ diff --git a/Dump/hybos/src/kernel/cpu.c b/Dump/hybos/src/kernel/cpu.c index 4675fda..f559d9c 100644 --- a/Dump/hybos/src/kernel/cpu.c +++ b/Dump/hybos/src/kernel/cpu.c @@ -1,1351 +1,1351 @@ -/** - * Processor Management - */ - -/** - * Processor Identification - */ - -/** - * Name Title Revision - * ---------------------------------------------------------------------------------------------------- - * AMD AMD-K6 Processor Model 6 Revision Guide G 1998 August - * AMD AMD-K6 Processor Model 7 Revision Guide H 1999 June - * AMD AMD-K6-2 Processor Model 8 Revision Guide F 1999 June - * AMD AMD-K6-III Processor Model 9 Revision Guide C 1999 July - * AMD AMD Athlon Processor Model 1 & Model 2 Revision Guide D 2000 August - * AMD AMD Duron Processor Model 3 Revision Guide I 2002 December - * AMD AMD Athlon Processor Model 4 Revision Guide I 2002 December - * AMD AMD Athlon Processor Model 6 Revision Guide E 2002 December - * AMD AMD Duron Processor Model 7 Revision Guide C 2002 December - * AMD AMD Athlon Processor Model 8 Revision Guide C 2002 December - * - * Intel Intel386 CX/SXSA Microprocessor Specification Update 002 1997 January - * Intel Intel386 DX Processor Specification Update 002 1997 January - * Intel Intel386 EX Embedded Processor Specification Update 010 1998 October - * Intel 60- and 66-MHz Pentium Processor Specification Update 001 1997 February - * Intel Pentium Processor Specification Update 041 1999 January - * Intel Pentium Pro Processor Specification Update 039 1999 January - * Intel Mobile Intel Celeron Processor at 466 MHz, ... Specification Update 038 2002 November - * Intel Mobile Intel Pentium II Processor Specification Update 046 2002 November - * Intel Intel Pentium II Xeon Processor Specification Update 032 2002 January - * Intel Intel Pentium II Processor Specification Update 049 2002 July - * Intel Intel Celeron Processor Specification Update 047 2002 October - * Intel Intel Pentium III Processor Specification Update 045 2002 November - * Intel Mobile Intel Celeron Processor (0.18� and 0.13�) Specification Update 030 2002 August - * Intel Mobile Intel Pentium III Processor and ... Specification Update 036 2002 November - * Intel Intel Pentium III Xeon Processor Specification Update 037 2002 July - * Intel Intel Pentium 4 Processor Specification Update 029 2002 November - * Intel Mobile Intel Pentium 4 Processor-M Specification Update 008 2002 November - * Intel Intel Celeron Processor in the 478-Pin Package Specification Update 005 2002 November - * Intel Mobile Intel Celeron Processor on .13 Micron ... Specification Update 002 2002 August - * Intel Intel Xeon Processor Specification Update 020 2002 November - * Intel Intel Xeon Processor MP Specification Updata 009 2002 November - * Intel Low Voltage Intel Xeon Processor Specification Update 003 2002 November - * Intel Intel Pentium M Processor 001 2003 March - * Intel Intel Itanium Processor Specification Update 008 2003 January - * Intel Intel Itanium 2 Processor Specification Update 007 2003 January - * AMD AMD Processor Recognition W-1 2002 November - * Intel Intel Processor Identification and the CPUID Instruction 023 2003 March - * Intel Intel Processor Serial Number 001 1999 March - * IDT IDT WinChip C6 Data Sheet 1.10 1998 March - */ - -/** - * Mobile Athlon Detection - * - * Problems with CPU identication: - * 1) How much information? - * 2) Getting the information - * - * CPU identification has two purposes: OS information and user information. Since this module wil be - * used in TriOS we'll only need OS information (ident upto stepping for erratas) No process size, - * packaging or voltage info. I can be found withofficial name and codename. To prevent user confusion - * we need to show the diff between Celeron / Pentium / Xeon. Cache info is important for some memory - * defragmentation and alignment algorithms, perhaps. - * - * OLD CPUS: - * - * i4004 / i4040 - * i8008 / i8080 / i8080A / Zilog Z80 / i8085A / i8085AH - * - * 2.13 Contemporary CPUs - * Contemporary 16 bit CPUs to 8086/8088 were Zilog Z8000 CPU, Fairchild 9445 CPU, Texas Instruments TI9900 CPU and Mil-Std 1750A CPU. Last is reason DOD (Department Of Defence) contractors were not interested in 8086/8088. Mil-Std 1750A CPU was specified in all contracts of 1979 - 1984 period. - * Texas Instruments TI9900 CPU was probably the best of the lot, but Texas Instruments considered it a closed architecture, so no-one used it. - * - * 8086 - 80368 Intel Only - * 80486 Lots of manufacturers, almost no stpping info - * 80586 Lots of incorrect information and processors that were never sold, no stepping info - * 80686 Celeron / Pentium / Xeon // !Mobile! (Inel realy srewed up the names here) - * 80786 VERY WELL DONE BY INTEL (at least names are a bit more consistant) - * 80886 Not officialy realeasd at the moment - * - * Intel detection: AAA xxh doesn't #UD - * Cyrix Detection: Read the chipset data, but I heard there was a better one - * AMD Detection If there not TI, IBM, UMC, Cyrix or Intel, must be AMD, need sometin' better - * UMC Detection support CPUID I believe - * Texas Detection Models do not real conflic (aren't those things the same as IBM have to check) - * IBM Detection Ax or 8x as family (but there are exceptions) and models do not conflict - * - * CYRIX/TI/IBM Identificaton through Chipset Data (I/O 22h and 23h) - * - * Not about the use of stepping and revision: - * - * Stepping is used always. I try to change this into: Stepping = A0 / Revision = 3h - * Intel also calls the revion Stepping ID - * - * 386 Reset Data - * 0- 3 Minor Stepping Revision - * 4- 7 Major Stepping Model - * 8-11 Family Family - * 12-15 Type DX/SX/SL and TI/IBM/Intel - * - * 486+ Reset Data - * 0- 3 Revision - * 4- 7 Model - * 8-11 Family - * 12-13 Type 0 = Normal, 1 = OverDrive, 2 = Second Processor, 3 = Reserved - * 14-15 Reserved - * 16-19 Extended Model - * 20-27 Extended Family - * 28-30 Reserved - * 31 Reserved Has Serial Number - * - * All over drives could also have type 0 if they are an errata (whatever that means) - * - * Legal Mumbo Jumbo: In the CPUID Documentation, Intel says the PSN could be reported wrongly, for - * example if the voltage or frequency is wrong. It doesn't say it's corec when the processor is - * working on the correct voltage and frequency... - * - * IF HighetExtened CPUID Fucntion > 0x80000000 Brand String is supported, even if 0x800000001 or 2 ??? - * - * Should OverDrives just be ignored? According to Intel internal caches or execution times may vary - * According to Intel CPUID is unreliable in V86 Mode - * According to Intel MSRs vary between different Models of the Pentium (P5 that is) - * PSN is not guaranteed to be unique - * Intel PSN Style: XXXX-XXXX-XXXX-XXXX-XXXX-XXXX (96 bit) - * Transmeta PSN S: XXXXXXXX:XXXXXXXX:XXXXXXXX:XXXXXXXX (128 bit) - * - * Intel says apps need to use the BRAND STRING to identify the processor (ARE THEY CRAZY???) - * Intel says apps need to use the BRAND ID to identify the processor (not crazy, but useless) - * - * DAZ DAZ DAZ DAZ DAZ DAZ DAZ - * - * 11 DENORMALS ARE ZERO - * With the introduction of the SSE2 extensions, some Intel Architecture processors have the ability to convert SSE - * and SSE2 source operand denormal numbers to zero. This feature is referred to as Denormals -Are-Zero (DAZ). The - * DAZ mode is not compatible with IEEE Standard 754. The DAZ mode is provided to improve processor - * performance for applications such as streaming media processing, where rounding a denormal operand to zero does - * not appreciably affect the quality of the processed data. - * Some processor steppings support SSE2 but do not support the DAZ mode. To determine if a processor supports the - * DAZ mode, software must perform the following steps. - * 1. Execute the CPUID instruction with an input value of EAX=0 and ensure the vendor-ID string returned is �GenuineIntel�. - * 2. Execute the CPUID instruction with EAX=1. This will load the EDX register with the feature flags. - * 3. Ensure that the FXSR feature flag (EDX bit 24) is set. This indicates the processor supports the FXSAVE and FXRSTOR - * instructions. - * 4. Ensure that the XMM feature flag (EDX bit 25) or the EMM feature flag (EDX bit 26) is set. This indicates that the - * processor supports at least one of the SSE/SSE2 instruction sets and its MXCSR control register. - * 5. Zero a 16-byte aligned, 512-byte area of memory. This is necessary since some implementations of FXSAVE do not modify - * reserved areas within the image. - * 6. Execute an FXSAVE into the cleared area. - * 7. Bytes 28-31 of the FXSAVE image are defined to contain the MXCSR_MASK. If this value is 0, then the processor's - * MXCSR_MASK is 0xFFBF, otherwise MXCSR_MASK is the value of this dword. - * 8. If bit 6 of the MXCSR_MASK is set, then DAZ is supported. - * After completing this algorithm, if DAZ is supported, software can enable DAZ mode by setting bit 6 in the - * MXCSR register save area and executing the FXRSTOR instruction. Alternately software can enable DAZ mode by - * setting bit 6 in the MXCSR by executing the LDMXCSR instruction. Refer to the chapter titled �Programming with - * the Streaming SIMD Extensions (SSE)� in the Intel Architecture Software Developer�s Manual volume 1: Basic - * Architecture. - * - * DAZ DAZ DAZ DAZ DAZ DAZ DAZ - * - * Legacy detecyion - * 8086 EFLAGS 12-15 are always set - * 80286 EFLAGS 12-15 are clear in RM - * 80366 EFLAGS 18 Cant be set, if it can it a 486+ - * 80848 EFLAGS 21 Can't be set, if it can use CPUID - * - * FPU If control/status word can be saved it's present - * 27/387 Infinity control Rounding Stuff - * 487 486 with coproc - * - * What about the Xeon DP???? - * - * CMXCHG8B Disabled because of Stuoid MSWinNT bug (studpid. Microsft not diabling. stupid) - * - * sAVE bRAND sTRING BEFRORE s3 POWER DOWN - * - * NSC Geode!!!! - * - * "The iAPX 286 will push a different value on the stack for PUSH SP than the iAPX 86/88." - * "When a word write is performed at offset FFFFh in a segment, the 8086 will write one byte at offset - * FFFFh, and the other at offset 0, while an 80186 family processor will write one byte at offset - * FFFFh, and the other at offset 10000h (one byte beyond the end of the segment)." - * - * A finalty note: I'm looking for some information on the Intel Timna (Intel's MediaGX). The project - * was abandonned so Intel never published any useful material on this. It was based on the P-III. - * Also some info in the Microsoft X-Box' special P-III would help - */ - -#include -#include "bootlog.h" - -typedef struct { - unsigned n; - char* i; - char* v; -} VENDORLIST; - -VENDORLIST VendorList[] = -{ - {0x0001, "ThinkTrinary", "Trinary Technologies"}, - {0x0002, "GenuineIntel", "Intel"}, - {0x0003, "AuthenticAMD", "AMD"}, - {0x0003, "AMD ISBETTER", "AMD"}, - {0x0004, "CentaurHauls", "Centaur (IDT / VIA)"}, - {0x0005, "CyrixInstead", "Cyrix (VIA)"}, - {0x0006, "GenuineTMx86", "Transmeta"}, - {0x0007, "Geode by NSC", "National Semiconductor"}, - {0x0008, "NexGenDriven", "NexGen"}, - {0x0009, "RiseRiseRise", "Rise"}, - {0x000A, "SiS SiS SiS ", "SiS"}, - {0x000B, "UMC UMC UMC ", "UMC"}, -}; - -typedef struct { - long long id; - bool verified; - char* name; -} PROCLIST; - - - -PROCLIST ProcessorList[] = -{ - {0x00FFFFFF, false, "Unknown x86 Processor"}, - {0x0000FFFF, false, "Unknown 8086 Compatible Processor"}, - {0x0001FFFF, false, "Unknown 186 Compatible Processor"}, - {0x0002FFFF, false, "Unknown 286 Compatible Processor"}, - {0x0003FFFF, false, "Unknown 386 Compatible Processor"}, - {0x0004FFFF, false, "Unknown 486 Compatible Processor"}, - {0x0005FFFF, false, "Unknown 586 Compatible Processor"}, - {0x0006FFFF, false, "Unknown 686 Compatible Processor"}, - {0x02FFFFFF, false, "Unknown Intel Processor"}, - {0x0203FFFF, false, "Unknown Intel i386 Processor"}, - {0x0204FFFF, false, "Unknown Intel i486 Processor"}, - {0x0205FFFF, false, "Unknown Intel Pentium Processor"}, - {0x020501FF, false, "Intel Pentium Classic"}, - {0x020502FF, false, "Intel Pentium"}, - {0x020503FF, false, "Intel Pentium OverDrive"}, - {0x020504FF, false, "Intel Pentium MMX"}, - {0x020507FF, false, "Intel Pentium Mobile"}, - {0x020508FF, false, "Intel Pentium MMX Mobile 'Tillamook'"}, - {0x0206FFFF, false, "Unknown Intel P6 Processor"}, - {0x020601FF, false, "Intel Pentium Pro"}, - {0x020603FF, false, "Unknown Intel Pentium II"}, - {0x02060301, false, "Intel Pentium II 'Klamath'"}, /* 0512 - 0512 */ - {0x02060305, false, "Intel Pentium II OverDrive"}, /* OVERDRIVE */ - {0x020605FF, false, "Unknown Intel Pentium II"}, - {0x02060500, false, "Intel Celeron II 'Covington'"}, /* 0000 - 0000 */ - {0x02060501, false, "Intel Pentium II 'Deschutes'"}, /* 0512 - 0512 */ - {0x02060502, false, "Intel Xeon II 'Drake'"}, /* 0512 - 2048 */ - {0x02060504, false, "Intel Pentium II Mobile 'Tonga'"}, /* 0512 - 0512 */ - {0x020606FF, false, "Unknown Intel Pentium II"}, - {0x02060600, false, "Intel Celeron II 'Mendocino'"}, /* 0128 - 0128 */ -/**/ {0x02060603, false, "Intel Celeron II Mobile"}, /* 0128 - 0128 (A) */ - {0x02060604, false, "Intel Pentium II Mobile 'Dixon'"}, /* 0256 - 0256 (A) */ - {0x020607FF, false, "Unknown Intel Pentium III"}, - {0x02060701, false, "Intel Pentium III 'Katmai'"}, /* 0512 - 0512 */ - {0x02060702, false, "Intel Xeon III 'Tanner'"}, /* 0512 - 2048 */ - {0x020608FF, false, "Unknown Intel Pentium III"}, - {0x02060801, false, "Intel Celeron III 'Coppermine'"}, - {0x02060802, false, "Intel Pentium III (Mobile) 'Coppermine'"}, - {0x02060803, false, "Intel Xeon III 'Cascades'"}, - {0x020609FF, false, "Unknown Intel Pentium M"}, - {0x02060916, false, "Intel Pentium M 'Banias'"}, - {0x02060AFF, false, "Unknown Intel Pentium III"}, - {0x02060A03, false, "Intel Xeon III 'Cascades'"}, - {0x02060BFF, false, "Unknown Intel Pentium III"}, - {0x02060B03, false, "Intel Celeron III 'Tualatin'"}, - {0x02060B04, false, "Intel Pentium III 'Coppermine'"}, - {0x02060B06, false, "Intel Pentium III Mobile 'Geyserville'"}, - {0x02060B07, false, "Intel Celeron III Mobile 'Geyserville'"}, - {0x0207FFFF, false, "Unknown Intel Itanium"}, - {0x020FFFFF, false, "Unknown Intel NetBurst Processor"}, - {0x020F0008, false, "Intel Pentium 4 'Willamette'"}, - {0x020F000E, false, "Intel Xeon 4 'Foster'"}, - {0x020F0108, false, "Intel Pentium 4 'Willamette'"}, - {0x020F0109, false, "Intel Pentium 4 'Willamette'"}, - {0x020F010A, false, "Intel Celeron 4 'Willamette'"}, - {0x020F010B, false, "Intel Xeon 4 MP 'Foster'"}, - {0x020F010E, false, "Intel Xeon 4 'Foster'"}, - {0x020F020C, false, "Intel Xeon 4 MP 'Gallatin'"}, - {0x020F0208, false, "Intel Celeron 4 Mobile 'Northwood'"}, - {0x020F0209, false, "Intel Pentium 4 'Northwood'"}, - {0x020F020B, false, "Intel Xeon 4 'Prestonia'"}, - {0x020F020E, false, "Intel Pentium 4 Mobile 'Northwood'"}, - {0x020F020A, false, "Intel Celeron 4 'Northwood'"}, - {0x0210FFFF, false, "Unknown Intel Itanium 2"}, - {0x03FFFFFF, false, "Unknown AMD Processor"}, - {0x0306FFFF, false, "Unknown AMD Athlon Processor"}, - {0x030601FF, false, "AMD Athlon 'Pluto'"}, - {0x030602FF, false, "AMD Athlon 'Argon'"}, - {0x030603FF, false, "AMD Duron 'Spitfire'"}, - {0x030604FF, false, "AMD Athlon 'Thunderbird'"}, - {0x030605FF, false, "AMD Athlon Ultra 'Mustang'"}, - {0x030606FF, false, "AMD Athlon MP 'Palomino'"}, - {0x030606FF, false, "AMD Athlon XP/MP 'Palomino'"}, - {0x030606FF, false, "AMD Athlon 4 Mobile 'Palomino'"}, - {0x030607FF, false, "AMD Duron 'Morgan'"}, - {0x030607FF, false, "AMD Duron MP 'Morgan'"}, - {0x030607FF, false, "AMD Duron Mobile 'Morgan'"}, - {0x030608FF, false, "AMD Athlon XP 'Thoroughbred'"}, - {0x030608FF, false, "AMD Athlon MP 'Thoroughbred'"}, - {0x030608FF, false, "AMD Athlon XP Mobile 'Thoroughbred'"}, - {0x030609FF, false, "AMD Duron 'Appaloosa'"}, - {0x030609FF, false, "AMD Duron MP 'Appaloosa'"}, - {0x030609FF, false, "AMD Duron Mobile 'Appaloosa'"}, - {0x03060AFF, false, "AMD Athlon XP 'Barton'"}, - {0x03060AFF, false, "AMD Athlon MP 'Barton'"}, - {0x04FFFFFF, false, "Unknown IDT / VIA Processor"}, - {0x0405FFFF, false, "Unknown IDT WinChip"}, - {0x040504FF, false, "IDT WinChip C6"}, - {0x040508FF, false, "IDT WinChip 2"}, - {0x040509FF, false, "IDT WinChip 3"}, - {0x0406FFFF, false, "Unknown VIA C3"}, - {0x040606FF, false, "VIA C3 'Samuel 1' / VIA Eden 4000"}, - {0x040607FF, false, "VIA C3 'Samuel 2 / Ezra' / VIA Eden 5000 / VIA Eden 6000"}, /* 0-7 / 8-F */ - {0x040608FF, false, "VIA C3 'Ezra-T' (VIA Eden 7000)"}, -// {0x040609FF, false, "VIA C3 'Nehalem VIA Eden 8000"}, - {0x05FFFFFF, false, "Unknown Cyrix Processor"}, - {0x0506FFFF, false, "Unknown VIA Cyrix III"}, - {0x050605FF, false, "VIA Cyrix III 'Joshua'"}, - {0x06FFFFFF, false, "Unknown Transmeta Processor"}, - {0x0604FFFF, false, "Transmeta Crusoe 3x00 / 5x00 Processor"}, - {0x08FFFFFF, false, "Unknown NexGen Processor"}, - {0x0805FFFF, false, "Unknown NexGen Nx586 / Nx686 Processor"}, - {0x080500FF, false, "Unknown NexGen Nx586"}, - {0x08050000, false, "NexGen Nx586"}, - {0x08050001, false, "NexGen Nx586FP"}, - //{0x0805??FF, false, "Unknown NexGen Nx686"}, - {0x0CFFFFFF, false, "Unknown UMC Processor"}, - {0x0C04FFFF, false, "Unknown UMC 486 Processor"}, - {0x0C0401FF, false, "UMC U5SD"}, - {0x0C0402FF, false, "UMC U5S"}, - {0x0C0403FF, false, "UMC U486DX2"}, - {0x0C0405FF, false, "UMC U486SX2"}, - - - - - - - - - {0xABCDABCD, false, "XXX"} -}; - - -#if 0 - /**********************************************************************************************/ -// {"GenuineIntel", 0x05, 0x00, 0x0?, 0, false, "Intel Pentium Classic (A*)"}, -// {"GenuineIntel", 0x05, 0x01, 0x02, 0, false, "Intel Pentium Classic (B*)"}, -// {"GenuineIntel", 0x05, 0x01, 0x04, 0, false, "Intel Pentium Classic (B2)"}, -// {"GenuineIntel", 0x05, 0x04, 0x01, 0, false, "Intel Pentium MMX (A1)"}, -// {"GenuineIntel", 0x05, 0x04, 0x02, 0, false, "Intel Pentium MMX (A2)"}, -// {"GenuineIntel", 0x05, 0x05, 0x0?, 0, false, "Intel Pentium MMX OverDrive"}, -// {"GenuineIntel", 0x05, 0x06, 0x0?, 0, false, "Intel Pentium MMX OverDrive"}, -// {"GenuineIntel", 0x06, 0x00, 0x0?, 0, false, "Intel Pentium Pro (A0)"}, -// {"GenuineIntel", 0x06, 0x04, 0x0?, 0, false, "Intel Pentium II OverDrive (?)"}, -// {"GenuineIntel", 0x0F, 0x02, 0x07, 0x0E, false, "Intel Pentium 4 Mobile (C1)"}, -// {"AuthenticAMD", 0x06, 4, 4, 0, false, "AMD Athlon 'Thunderbird' Model 4 (B0)"}, //??Grzegorz -// {"AuthenticAMD", 0x06,5?, ?, 0, false, "AMD Athlon Ultra 'Mustang' Model 5? (??)"}, /* CANCELED */ - -// {"GenuineIntel",F?,3?, ?, ?, "Intel Pentium 4 'Prescott' (??)"}, //.09 -// {"GenuineIntel",F?,3?, ?, ?, "Intel Xeon 4 'Nocona' (??)"}, //.09 -// {"GenuineIntel",F?,4?, ?, ?, "Intel Pentium 4 'Tyler' (??)"}, -// {"GenuineIntel",F?,4?, ?, ?, "Intel Pentium 4 'Tejas' (??)"}, -// {"GenuineIntel",F?,4?, ?, ?, "Intel Xeon 4 'Potomac' (??)"}, - -//GI Nehalem Pentium 5 - - -// {"GenuineIntel", ?,?, ?, ?, "Intel Mobillium 'Banias' (??)"}, -// {"GenuineIntel", ?,?, ?, ?, "Intel Mobillium 'Dothan' (??)"}, -// {"GenuineIntel", ?,?, ?, ?, "Intel Mobillium 'Morem' (??)"}, /* Next GEN!!!! */ -// {"GenuineIntel", ?,?, ?, ?, "Intel Mobillium 'Gilo' (??)"}, /* Next GEN!!!! */ -// Intel's truly mobile processor. Intel says this is a completly new processor. Sources say it's just -// a rework of the PIII or P4. I don't believe this, beacause it has SSE2 (not in PIII) and is faster -// than the P4. I guess they just shortened the enormous 20 stage P4 pipeline a bit, which is too long -// to be used effecivly. More backup is provided for the fact that the Pentium 5 will be based upon -// this chip. And another thing many sources will tell you this chip will be called 'Intel Banias', -// didn't Intel call the Pentium III, Intel Katmai for a very long time. With this in mind it wouldn't -// even surprise me if this processor is goin to be called Pentium 5. Sorry but I have to go one now -// I'm brainstorming. The mobile part of it might not even be used for mobile computers, but for -// desktops and servers as well, because cooling has become almost impossible today. If speeds are -// going to get even higher the next couple of years, the processor cores will just melt. Because -// AMD's processors get even hotter and isn't working on a similar project Intel might even regain -// it's market monopoly (wheter this is good or bad, I don't know?) -// {"GenuineIntel",F?,?, ?, ?, "Intel Pentium 5 'Nehalem' (??)"}, -// This is just a rumor. It's supposed to come out in 2006, run at 6Ghz and have a bus speed of -// 1.5Ghz. It COULD be using the Intel Banias core. Suggesting the Banias is a Pentium 5 and that it -// IS completely new. IF you read the note above this could also be the Pentium 6 or something. -// {"GenuineIntel", 7, 6, 4, 0, "Intel Itanium 'Merced' (C0)"}, //0007000604 -// {"GenuineIntel", 7, 7, 4, 0, "Intel Itanium 'Merced' (C1)"}, //0007000704 -// {"GenuineIntel", 7, 7, 4, 0, "Intel Itanium 'Merced' (C2)"}, //0007000804 -// {"GenuineIntel", 0x10, 0, ?, 0, "Intel Itanium 2 'McKinley' (B3)"}, //001F000704 -// {"GenuineIntel",A?, ?, ?, ?, ???, "Intel Itanium 2 'Madison' (??)"}, -// {"GenuineIntel",A?, ?, ?, ?, ???, "Intel Itanium 2 'Deerfield' (??)"},XXX -// {"GenuineIntel",A?, ?, ?, ?, ???, "Intel Itanium 2 'Montecito' (??)"} -// {"GenuineIntel",A?, ?, ?, ?, ???, "Intel Itanium 2 'Shavano' (??)"}, -// {"GenuineIntel",A?, ?, ?, ?, ???, "Intel Itanium 2? 'Yosemite' (??)"}, -// {"GenuineIntel",A?, ?, ?, ?, ???, "Intel Itanium 2? 'Tanglewood' (??)"}, - -// {"AuthenticAMD", ?, ?, ?, ?, "AMD Athlon XP64 / Hammer 'Clawhammer' (??)"}, -// {"AuthenticAMD", ?, ?, ?, ?, "AMD Athlon XP64 / Hammer 'San Diego' (??)"}, -// {"AuthenticAMD", ?, ?, ?, ?, "AMD Athlon XP64 / Hammer Mobile 'Odessa' (??)"}, -// {"AuthenticAMD", ?, ?, ?, ?, "AMD Opteron 'Sledgehammer' (??)"}, -// {"AuthenticAMD", ?, ?, ?, ?, "AMD Opteron 'Athens' (??)"}, -// {"CentaurHauls", 0x05, 0x08, 0x01, 0x00, false, "IDT WinChip 2"}, -// {"CentaurHauls", 6, 0xA, ?, 0, "IDT WinChip 4"}, //PROBABLY DOESN'T EXIST! -> Is a VIA C3!!! - - /** Intel 8086 / 8088 (Includes model manufactured by AMD, Harris, Siemens, Hitachi) ************/ - - //I belive there an alroithm to identify the diff between HMOS and CMOS models - {"GenuineIntel", 1, 0, 0, 0, false, "Intel 8088"}, - {"GenuineIntel", 1, 0, 0, 1, false, "Intel 8086"}, - {"GenuineIntel", 1, 0, 0, 2, false, "Intel 80C88"}, - {"GenuineIntel", 1, 0, 0, 3, false, "Intel 80C86"}, - {"GenuineIntel", 1, 0, 0, 4, false, "Intel 80188"}, //XL/EA/EB/EC AMD/Siemens - {"GenuineIntel", 1, 0, 0, 5, false, "Intel 80186"}, //XL/EA/EB/EC AMD/Siemens - {"GenuineIntel", 1, 0, 0, 6, false, "NEC V20"}, //V20H/V25/V25 Plus/V25 Softwae Guard/V40/V40H//V45 - {"GenuineIntel", 1, 0, 0, 7, false, "NEC V30"}, //V30H/V35/V35 Plus/V35 Softwae Guard/V50/V50H//V55 - //Intel 80886??? - - {"GenuineIntel", 2, 0, 0, 0, false, "Intel 80286"},//amd/harris/siemens/fujitsu/kruger - - - /** Intel 386 ***********************************************************************************/ - - - //The 386 use a very different format: Family (8-bits!) + Revision (8-bits! Model+Stepping) - //Not to myself: The high four bits of the family should coume in the extra field - //These chips were also munufactured by AMD!!! They are affected by the POPAD bug???? - //Old (sigma-pi) i386 have 32-bit multipy bug - //C&T 38600DX do not have POPAD bug. IBM 386SLC unknwon - //AMD 386DX & DXL hav Intel microcode - //AMD 386DXLV & SXLV hav UMOV??? - //Nx586 has no AC has 386 instr set - - //Erly modles (A stepping) as Famuly: 0, Revision: ??? (In Intel Docs! Support the 'Bit Instrucs') - //0300 - // * Intel i386DX : F0 - {"GenuineIntel", 3, 0, 3, 0, false, "Intel i386DX (B0/B1/B2/B3/B4/B5/B6/B7/B8/B9/B10)"}, - {"GenuineIntel", 3, 0, 4, 0, false, "Intel i386DX (C???)"}, // Stepping not confiremed - {"GenuineIntel", 3, 0, 5, 0, false, "Intel i386DX (D0)"}, - {"GenuineIntel", 3, 0, 8, 0, false, "Intel i386DX (D1/D2/E0/E1/F0)"}, //E0/E1/F0 coulld also be 9!!! - - //The family 23 could also simply be 3 (I don't know were the 2 stands for???) Officialy not part - //Difference between DX and SX perhaps (I hope so) - // * Intel i386CX/SXSA : A2 / B - // * Intel i386EX : A0 / B1 / B2 - {"GenuineIntel",23, 0, 4, 0, false, "Intel i386SX (A0)"}, - {"GenuineIntel",23, 0, 5, 0, false, "Intel i386SX (B)"}, - {"GenuineIntel",23, 0, 8, 0, false, "Intel i386SX (C/D/E)"}, - {"GenuineIntel",23, 0, 8, 0, false, "Intel i386CXSA/B (A) / i386EX (A) / i386SXSA (?)"}, //A || B - {"GenuineIntel",23, 0, 9, 0, false, "Intel i386SX (?)"}, //EMBEDDED (CX/FX - {"GenuineIntel",23, 0, 9, 0, false, "Intel i386EX (A0/B1/C1)"}, - - //Dito for 33 (376 perhaps) - {"GenuineIntel",33, 0, 5, 0, false, "Intel i376 (A0)"}, //Never used in PC because they only work in PM - {"GenuineIntel",33, 0, 8, 0, false, "Intel i376 (B)"}, //... - - //And againt for 43 (386SL) - //have a signatur register @ 30e - //step level A0: 0x4300, - //step level A1: 0x4300, - //step level A2: 0x4301, - //step level A3: 0x4302, - //step level B0: 0x4310, - //step level B1: 0x4311. -// {"GenuineIntel",43, 0, 5, ?, false, "Intel i386SL (B)"}, -// {"GenuineIntel",43, 0, 5, ?, false, "Intel i386SL (A0/A1/A2/A3)"}, //Not sure about this -// {"GenuineIntel",43, 1, 0, 0, false, "Intel i386SL (A0/A1/A2/A3)"}, -// {"GenuineIntel",43, 1, 1, 0, false, "Intel i386SL (B0/B1)"}, - - //RapidCADs are not so familiar to me, where they ever used in PCs??? - {"GenuineIntel", 3, 4, 0, 0, false, "Intel RapidCAD (A)"}, - {"GenuineIntel", 3, 4, 1, 0, false, "Intel RapidCAD (B)"}, - - - /** Intel 486 ***********************************************************************************/ - - //According to Intel only SL Enhanced and WB Enhanced processors support CPUID - - {"GenuineIntel", 4, 0, 0, 0, false, "Intel i486DX (A0/A1)"}, - {"GenuineIntel", 4, 0, 1, 0, false, "Intel i486DX (B2/B3/B4/B5/B6)"}, - {"GenuineIntel", 4, 0, 2, 0, false, "Intel i486DX (C0)"}, - {"GenuineIntel", 4, 0, 3, 0, false, "Intel i486DX (C1)"}, - {"GenuineIntel", 4, 0, 4, 0, false, "Intel i486DX (D0)"}, -// {"GenuineIntel", 4, 0, ?, 0, false, "Intel i486DX"}, - - {"GenuineIntel", 4, 1, 0, 0, false, "Intel i486DX (cA2/cA3)"}, - {"GenuineIntel", 4, 1, 1, 0, false, "Intel i486DX (cB0/cB1)"}, - {"GenuineIntel", 4, 1, 3, 0, false, "Intel i486DX (cC0)"}, - {"GenuineIntel", 4, 1, 4, 0, false, "Intel i486DX (aA0/aA1)"}, //SL Enhanced - {"GenuineIntel", 4, 1, 5, 0, false, "Intel i486DX (aB0)"}, //SL Enhanced -// {"GenuineIntel", 4, 1, ?, 0, false, "Intel i486DX"}, - - {"GenuineIntel", 4, 2, 0, 0, false, "Intel i486SX / i487SX (A0)"}, //Should 487 be model 3 - {"GenuineIntel", 4, 2, 1, 0, false, "Intel i487SX (B0)"}, //Should 487 be model 3 - {"GenuineIntel", 4, 2, 2, 0, false, "Intel i486SX (B0)"}, - {"GenuineIntel", 4, 2, 3, 0, false, "Intel i486SX (bBx)"}, //SL Enhanced and... CPUID - {"GenuineIntel", 4, 2, 4, 0, false, "Intel i486SX (gAx)"}, - {"GenuineIntel", 4, 2, 7, 0, false, "Intel i486SX (cA0)"}, - {"GenuineIntel", 4, 2, 8, 0, false, "Intel i486SX (cB0)"}, - {"GenuineIntel", 4, 2, 0xA, 0, false, "Intel i486SX (aA0/aA1)"}, //SL Enhanced - {"GenuineIntel", 4, 2, 0xB, 0, false, "Intel i486SX (aB0/aC0)"}, //SL Enhanced - {"GenuineIntel", 4, 2, 0xE, 0, false, "Intel i486SX (E)"}, //SL Enhanced??? Grzegorz -// {"GenuineIntel", 4, 2, ?, 0, false, "Intel i486SX"}, - -// {"GenuineIntel", 4, 3, ?, 0, false, "Intel i486DX2 / i486DX2 OverDrive / i487"}, - {"GenuineIntel", 4, 3, 2, 0, false, "Intel i486DX2 (A0/A1/A2)"}, - {"GenuineIntel", 4, 3, 3, 0, false, "Intel i486DX2 (B1)"}, - {"GenuineIntel", 4, 3, 4, 0, false, "Intel i486DX2 (aA0/aA1)"}, //SL Enhanced - {"GenuineIntel", 4, 3, 5, 0, false, "Intel i486DX2 (aB0/aC0)"}, //SL Enhanced - {"GenuineIntel", 4, 3, 6, 0, false, "Intel i486DX2"}, //Possibly as WB in WT Mode - - {"GenuineIntel", 4, 4, 0, 0, false, "Intel i486SL (A)"}, - {"GenuineIntel", 4, 4, 1, 0, false, "Intel i486SL (?)"}, - {"GenuineIntel", 4, 4, 3, 0, false, "Intel i486SL (?)"}, //In Intel Docs, saupoosed to support CPUID -// {"GenuineIntel", 4, 4, ?, 0, false, "Intel i486SL"}, - -// {"GenuineIntel", 4, 5, ?, 0, false, "Intel i486SX2"}, - {"GenuineIntel", 4, 5, 0xB, 0, false, "Intel i486SX2 (aC0)"}, //SL Enhanced - - {"GenuineIntel", 4, 7, 0, 0, false, "Intel i486DX2-WB (A)"}, - {"GenuineIntel", 4, 7, 3, 0, false, "Intel i486DX2-WB (?)"}, //In Intel Docs, saupoosed to support CPUID -// {"GenuineIntel", 4, 7, ?, 0, false, "Intel i486DX2-WB"}, - - {"GenuineIntel", 4, 8, 0, 0, false, "Intel i486DX4 (A)"}, - {"GenuineIntel", 4, 8, 0, 1, false, "Intel i486DX4 OverDrive (A)"}, - {"GenuineIntel", 4, 8, 3, 0, false, "Intel i486DX4 (A)"}, //Possibly as WB in WT Mode, Support CPUID -// {"GenuineIntel", 4, 8, ?, 0, false, "Intel i486DX4 / i486DX4 OverDrive"}, - - {"GenuineIntel", 4, 9, 0, 0, false, "Intel i486DX4-WB (A)"}, //(Do not exist according to Intel CPUID Inf) -// {"GenuineIntel", 4, 9, ?, 0, false, "Intel i486DX4-WB"}, - - - /** AMD *****************************************************************************************/ - - {"AuthenticAMD", 4, 1, 2, 0, false, "AMD 486DX"}, - {"AuthenticAMD", 4, 3, 2, 0, false, "AMD 486DX/2"}, //DX4 (WT2x) toooo && DXL2 / DX4NV8T - {"AuthenticAMD", 4, 3, 4, 0, false, "AMD 486DX/2"}, //DX4 (WT2x) toooo && DXL2 / DX4SV8B -// {"AuthenticAMD", 4, 7, ?, 0, false, "AMD 486DX/2-WB"}, //DX4 (WB2x) - {"AuthenticAMD", 4, 7, 4, 0, false, "AMD SV8B (WT)"}, -// {"AuthenticAMD", 4, 8, ?, 0, false, "AMD 486DX/4"}, //5x86 toooo - {"AuthenticAMD", 4, 8, 4, 0, false, "AMD 486DX/4"}, //3xWT - {"AuthenticAMD", 4, 9, 4, 0, false, "AMD 486DX/4-WB"}, //3xWB - {"AuthenticAMD", 4, 0xE, 4, 0, false, "AMD Am5x86-WT"}, //AMD Enhanced 486 - {"AuthenticAMD", 4, 0xF, 4, 0, false, "AMD Am5x86-WB (4)"}, //AMD Enhanced 486 - - //cores: 5.0 / 5.0 (MMX) / 5.1 / 5.2 - {"AuthenticAMD", 5, 0, 0, 0, false, "AMD K5 SSA/5 (E)"}, //??? Stepping Name - {"AuthenticAMD", 5, 0, 1, 0, false, "AMD K5 SSA/5 (F)"}, //??? Stepping Name -// {"AuthenticAMD", 5, 0, ?, 0, false, "AMD K5 SSA/5 (?)"}, //??? Stepping Name -// {"AuthenticAMD", 5, 1, ?, 0, false, "AMD K5 5k86 Model 1 (?)"}, //??? Stepping Name - {"AuthenticAMD", 5, 1, 1, 0, false, "AMD K5 5k86 Model 1 (?)"}, //??? Stepping Name - {"AuthenticAMD", 5, 1, 2, 0, false, "AMD K5 5k86 Model 1 (?)"}, //??? Stepping Name - {"AuthenticAMD", 5, 1, 4, 0, false, "AMD K5 5k86 Model 1 (?)"}, //CLKMUL=1.5 -// {"AuthenticAMD", 5, 2, ?, 0, false, "AMD K5 5k86 Model 1 (?)"}, //??? Stepping Name - {"AuthenticAMD", 5, 2, 4, 0, false, "AMD K5 5k86 Model 2 (?)"}, //CLKMUL=1.75 -// {"AuthenticAMD", 5, 3, ?, 0, false, "AMD K5 5k86 Model 3 (?)"}, //??? Stepping Name (NOT RELEASED) - {"AuthenticAMD", 5, 3, 4, 0, false, "AMD K5 5k86 Model 1 (?)"}, //CLKMUL=2.0 - - - //Missing: MobileS (= k6-7!!!) / K6-2+ n/ K6-III+ - {"AuthenticAMD", 5, 6, 1, 0, false, "AMD-K6 Model 6 (B)"}, - {"AuthenticAMD", 5, 6, 2, 0, false, "AMD-K6 Model 6 (C)"}, - {"AuthenticAMD", 5, 7, 0, 0, false, "AMD-K6 Model 7 'Little Foot' (A)"}, - {"AuthenticAMD", 5, 8, 0, 0, false, "AMD-K6-2 Model 8 'Chomper' (A0)"}, //doesnt CXT stnd fr Chomber XT -// {"AuthenticAMD", 5, 8, 8, 0, false, "AMD-K6-2 Model 8 'Chomper' (AC)"}, //In Recognition < CXT - {"AuthenticAMD", 5, 8, 0xC, 0, false, "AMD-K6-2 Model 8 'Chomper' (AC)"}, //CXT Core (Write COmbining) I believe YES!!! avvording to Chase - {"AuthenticAMD", 5, 9, 1, 0, false, "AMD-K6-III 'Sharptooth' Model 9 (B)"}, -// {"AuthenticAMD", 5, 0xD, ?, 0, false, "AMD-K6-2+ / K6-III+ 'Sharptooth' (?)"}, //Not doced by AMD (3DNow!+) - -//* {"AuthenticAMD", 6, 0, ?, 0, "AMD K7 [ES]"}, //UNDOCUMENTED!?! - - - /* Cyrix **************************************************************************************/ - - //My sources are unreliable at best for these suckers, so I list them all - //Also I belive the names aren't entire ly correct, confused codename/ actualt name and extensions - - {"CyrixInstead", 0, 0, 5, 0, false, "Cyrix M5 Cx486S/D"}, //No CPUID I believe (is family correct?) - {"CyrixInstead", 0, 0, 6, 0, false, "Cyrix M6 Cx486DX"}, //... - {"CyrixInstead", 0, 0, 7, 0, false, "Cyrix M7 Cx486DX2"}, //... - {"CyrixInstead", 0, 0, 8, 0, false, "Cyrix M8 Cx486DX4"}, - //... - - {"CyrixInstead", 4, 1, 0, 0, false, "Cyrix 4x86SLC"}, -// {"CyrixInstead", 4, 2, ?, 0, false, "Cyrix 5x86"}, - {"CyrixInstead", 4, 2, 9, 0, false, "Cyrix 5x86 (Rev 1-)"}, //Bus *2 - {"CyrixInstead", 4, 2, 0xB, 0, false, "Cyrix 5x86 (Rev 1-)"}, //Bus *2 - {"CyrixInstead", 4, 2, 0xD, 0, false, "Cyrix 5x86 (Rev 1-)"}, //Bus *3 - {"CyrixInstead", 4, 2, 0xF, 0, false, "Cyrix 5x86 (Rev 1-)"}, //Bus *3 -// {"CyrixInstead", 4, 4, ?, 0, false, "Cyrix MediaGX"}, - {"CyrixInstead", 4, 9, 0, 0, false, "Cyrix 5x86 (Rev 2+)"}, -// {"CyrixInstead", 4, 9, ?, 0, false, "Cyrix 5x86"}, - - -// IBM ID=15h Top (65 KB JPG) and Bottom (104 KB JPG) -// IBM ID=17h Top (71 KB JPG) and Bottom (110 KB JPG) -// Cyrix ID=17h Top (63 KB JPG) and Bottom (102 KB JPG) -// IBM ID=22h Top (82 KB JPG) and Bottom (99 KB JPG) -// {"CyrixInstead", 5, 0, ?, 0, false, "Cyrix M1 (6x86)"}, //Grzegorz - {"CyrixInstead", 5, 2, 0, 0, false, "Cyrix M1 (6x86)"}, //Early Models (L / non-L versions???? (LV too)) -// {"CyrixInstead", 5, 2, ?, 0, false, "Cyrix M1 (6x86)"}, //Early Models (L / non-L versions???? (LV too)) - {"CyrixInstead", 5, 3, 0, 0, false, "Cyrix M1 (6x86)"}, //1.0x Bus Ratio - {"CyrixInstead", 5, 3, 1, 0, false, "Cyrix M1 (6x86)"}, //2.0x Bus Ratio - {"CyrixInstead", 5, 3, 2, 0, false, "Cyrix M1 (6x86)"}, //1.0x Bus Ratio - {"CyrixInstead", 5, 3, 3, 0, false, "Cyrix M1 (6x86)"}, //2.0x Bus Ratio - {"CyrixInstead", 5, 3, 4, 0, false, "Cyrix M1 (6x86)"}, //3.0x Bus Ratio - {"CyrixInstead", 5, 3, 5, 0, false, "Cyrix M1 (6x86)"}, //4.0x Bus Ratio - {"CyrixInstead", 5, 3, 6, 0, false, "Cyrix M1 (6x86)"}, //3.0x Bus Ratio - {"CyrixInstead", 5, 3, 7, 0, false, "Cyrix M1 (6x86)"}, //4.0x Bus Ratio -// {"CyrixInstead", 5, 4, ?, 0, false, "Cyrix MediaGX MMX"}, - - -// ID=02h Top (73 KB JPG) and Bottom (100 KB JPG) -// ID=04h Top (79 KB JPG) and Bottom (106 KB JPG) -// ID=08h Top (66 KB JPG) and Bottom (101 KB JPG) -// ID=53 07 - {"CyrixInstead", 6, 0, 0, 0, false, "Cyrix MII (6x86MX)"}, -// {"CyrixInstead", 6, 0, ?, 0, "Cyrix MII (6x86MX)"}, - - //These guys are actualy a Cyrix M2 with minor enhancemets (3DNow! / better FPU), but who cares, - //they were never taken into procuvtion. Although VIA C3 probalby stands for Cyrix M3 and not, - //Centaur WinChip 3. THey got a WinChip 4 core. Josua was nOT released! Start with samual and Samual 2 then Ezra and Ezra-T - // {"CyrixInstead", 6, 5, 1, 0, false, "VIA Cyrix III 'Joshua'"}, //2.0x Bus Ratio - - //Other names heard: Cyrix M-III 'Mojave' (Chase, so reliable never produced!) - // Cayenne / Gobi / Jalapeno - // Cayenne, then Gobi, then Joshua - - //THE VIA Series!!!!! - //New models : C4 'Nehemia' Has SSE instead of #dnOW! newer modles will be Esther - // CZA is a P4 clone - - /************************************************************************************************/ - - - - - -// I'm not sure about the CNs -// {"RiseRiseRise", 5, 0, ?, 0, "Rise mP6 iDragon '6401?' (Model 0)"}, //0.25 -// {"RiseRiseRise", 5, 0, 4, 0, "Rise mP6 iDragon '6401?' (Model 0)"}, //0.25 -// {"RiseRiseRise", 5, 1, ?, 0, "Rise mP6 iDragon 'Kirin?' (Model 1)"}, -// {"RiseRiseRise", 5, 2, ?, 0, "Rise mP6 iDragon 'Lynx?' (Model 2)"}, //0.18 -// {"RiseRiseRise", 5, 8, ?, 0, "Rise mP6 iDragon II"}, -// {"RiseRiseRise", 5, 9, ?, 0, "Rise mP6 iDragon II"}, -// Rise Tiger = MMX+SSE Unknown Nmae - - -#endif /* 0 */ - -typedef struct __CPU___PROCINFORMATION__ -{ - bool pCertified; - char *pName; - - uint32_t vFamily; - uint32_t vModel; - uint32_t vStepping; - uint32_t vType; - uint32_t vBrand; - char vVendor[13]; - char *vName; - - bool iFloatingPoint; - bool iTranscedental; - bool iCompareExchange64; - bool iConditionalMove; - bool iCLFLUSH; - bool iMMX; - bool iSSE; - bool iSSE2; - bool iSSE3; - bool iMonitor; - bool iFastSystemCall; - bool iFXSR; - bool fVirtualModeExtensions; - bool fDebuggingExtensions; - bool fPageSizeExtensions; - bool fTimeStampCounter; - bool fModelSpecificRegisters; - bool fPhysicalAddressExtension; - bool fMachineCheckException; - bool fLocalAPIC; - bool fMemoryTypeRangeRegisters; - bool fPageGlobalEnable; - bool fMachineCheckArchitecture; - bool fPageAttributeTable; - bool fPageSizeExtension; - bool fProcessorSerialNumber; - bool fDebugStore; - bool fACPI; - bool fSelfSnoop; - bool fHyperThreading; - bool fThermalMonitor; - bool fIA64; - bool fSignalBreakOnFERR; - bool fQualifiedDebugStore; - bool fThermalMonitor2; - bool fContextID; - - uint32_t cLineSize; - uint32_t cL1CodeCacheSize; - uint32_t cL1CodeCacheAssociativity; - uint32_t cL1CodeCacheLineSize; - uint32_t cL1CodeCacheLinesPerTag; - uint32_t cL1DataCacheSize; - uint32_t cL1DataCacheAssociativity; - uint32_t cL1DataCacheLineSize; - uint32_t cL1DataCacheLinesPerTag; - uint32_t cL1UnifiedCacheSize; - uint32_t cL1UnifiedCacheAssociativity; - uint32_t cL1UnifiedCacheLineSize; - uint32_t cL1UnifiedCacheLinesPerTag; - uint32_t cL1CodeTLB4KEntries; - uint32_t cL1CodeTLB2MEntries; - uint32_t cL1DataTLB2MEntries; - uint32_t cL1CodeTLB4MEntries; - uint32_t cL1DataTLB4KEntries; - uint32_t cL1DataTLB4MEntries; - uint32_t cL2UnifiedCacheSize; - uint32_t cL2UnifiedCacheAssociativity; - uint32_t cL2UnifiedCacheLineSize; - uint32_t cL2UnifiedCacheLinesPerTag; - uint32_t cL2CodeTLB4KEntries; - uint32_t cL2CodeTLB2MEntries; - uint32_t cL2CodeTLB4MEntries; - uint32_t cL2DataTLB4KEntries; - uint32_t cL2DataTLB2MEntries; - uint32_t cL2DataTLB4MEntries; - uint32_t cL2UnifiedTLB4KEntries; - uint32_t cL2UnifiedTLB2MEntries; - uint32_t cL2UnifiedTLB4MEntries; - uint32_t cL3UnifiedCacheSize; - uint32_t cL3UnifiedCacheAssociativity; - uint32_t cL3UnifiedCacheLineSize; - uint32_t cL3UnifiedCacheLinesPerTag; - - int32_t cL1CodeTLB4KAssociativity; - int32_t cL1CodeTLB2MAssociativity; - int32_t cL1CodeTLB4MAssociativity; - int32_t cL1DataTLB4KAssociativity; - int32_t cL1DataTLB2MAssocitivity; - int32_t cL1DataTLB4MAssociativity; - int32_t cL2CodeTLB4KAssociativity; - int32_t cL2CodeTLB2MAssociativity; - int32_t cL2CodeTLB4MAssociativity; - int32_t cL2DataTLB4KAssociativity; - int32_t cL2DataTLB2MAssociativity; - int32_t cL2DataTLB4MAssociativity; - int32_t cL2UnifiedTLB4KAssociativity; - int32_t cL2UnifiedTLB2MAssociativity; - int32_t cL2UnifiedTLB4MAssociativity; - - bool cTraceCachePresent; - - uint32_t cTraceCacheMicroOps; - uint32_t cTraceCacheAssociativity; - uint32_t uOnChipFPU; - uint32_t uLogicalProcessorCount; - uint32_t uAPICID; - - bool rFeature10; - bool rFeature20; - bool rFeature33; - bool rFeature34; - bool rFeature37; - bool rFeature38; - bool rFeature39; - bool rFeature41; - bool rFeature42; - bool rFeature43; - bool rFeature44; - bool rFeature45; - bool rFeature46; - bool rFeature47; - bool rFeature48; - bool rFeature49; - bool rFeature50; - bool rFeature51; - bool rFeature52; - bool rFeature53; - bool rFeature54; - bool rFeature55; - bool rFeature56; - bool rFeature57; - bool rFeature58; - bool rFeature59; - bool rFeature60; - bool rFeature61; - bool rFeature62; - bool rFeature63; - -} prcInformation; - -void prcInit(void); -void prcIdentify(uint64_t processor, prcInformation* information); -void prcCPUID(uint64_t processor, uint32_t function, uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d); -void IdentifyIntelCache(prcInformation* information, int descriptor); -void IdentifyProcessor(prcInformation* information, int Extra); - -typedef union __CPU___PROCINFORMATIONDATA__ -{ - unsigned int d; - unsigned short w[2]; - unsigned char b[4]; -} prcIdentificationData; - -void printf(const char *fmt, ...); - -void init_cpu(void) -{ - prcInformation information; - prcIdentify(0, &information); - //logStatus(logSuccess); - //logSubItem("Processor #0", information.pName); - //logSubItem("MMX", information.iMMX ? "Yes" : "No"); - printf("Proccessor: %s MMX %s", information.pName, information.iMMX ? "Yes" : "No"); -} - -void prcIdentify(uint64_t processor, prcInformation* information) -{ - uint32_t a, b, c, d; - uint32_t highestStandard, highestExtended; - int i, n, Extra; - - /*** 0x00000000 - Vendor **********************/ - prcCPUID(processor, 0x00000000, &a, &b, &c, &d); - - highestStandard = a; - - *((uint32_t*)(information->vVendor + 0)) = b; - *((uint32_t*)(information->vVendor + 4)) = d; - *((uint32_t*)(information->vVendor + 8)) = c; - information->vVendor[12] = '\0'; - - - /*** 0x00000001 - Version and Features ********/ - prcCPUID(processor, 0x00000001, &a, &b, &c, &d); - - information->vStepping = (a & 0x0000000F) >> 0; - information->vModel = (a & 0x000000F0) >> 4; - information->vFamily = (a & 0x00000F00) >> 8; - information->vType = (a & 0x00003000) >> 12; - - if(information->vModel == 0xF) information->vModel += (a & 0x000F0000) >> 16; - if(information->vFamily == 0xF) information->vFamily += (a & 0x0FF00000) >> 20; - - information->uOnChipFPU = (d >> 0) & 0x00000001; - information->fVirtualModeExtensions = (d >> 1) & 0x00000001; - information->fDebuggingExtensions = (d >> 2) & 0x00000001; - information->fPageSizeExtension = (d >> 3) & 0x00000001; - information->fTimeStampCounter = (d >> 4) & 0x00000001; - information->fModelSpecificRegisters = (d >> 5) & 0x00000001; - information->fPhysicalAddressExtension = (d >> 6) & 0x00000001; - information->fMachineCheckException = (d >> 7) & 0x00000001; - information->iCompareExchange64 = (d >> 8) & 0x00000001; - information->fLocalAPIC = (d >> 9) & 0x00000001; - information->rFeature10 = (d >> 10) & 0x00000001; - information->iFastSystemCall = (d >> 11) & 0x00000001; - information->fMemoryTypeRangeRegisters = (d >> 12) & 0x00000001; - information->fPageGlobalEnable = (d >> 13) & 0x00000001; - information->fMachineCheckArchitecture = (d >> 14) & 0x00000001; - information->iConditionalMove = (d >> 15) & 0x00000001; - information->fPageAttributeTable = (d >> 16) & 0x00000001; - information->fPageSizeExtension = (d >> 17) & 0x00000001; - information->fProcessorSerialNumber = (d >> 18) & 0x00000001; - information->iCLFLUSH = (d >> 19) & 0x00000001; - information->rFeature20 = (d >> 20) & 0x00000001; - information->fDebugStore = (d >> 21) & 0x00000001; - information->fACPI = (d >> 22) & 0x00000001; - information->iMMX = (d >> 23) & 0x00000001; - information->iFXSR = (d >> 24) & 0x00000001; - information->iSSE = (d >> 25) & 0x00000001; - information->iSSE2 = (d >> 26) & 0x00000001; - information->fSelfSnoop = (d >> 27) & 0x00000001; - information->fHyperThreading = (d >> 28) & 0x00000001; - information->fThermalMonitor = (d >> 29) & 0x00000001; - information->fIA64 = (d >> 30) & 0x00000001; - information->fSignalBreakOnFERR = (d >> 31) & 0x00000001; - - information->iSSE3 = (c >> 0) & 0x00000001; - information->rFeature33 = (c >> 1) & 0x00000001; - information->rFeature34 = (c >> 2) & 0x00000001; - information->iMonitor = (c >> 3) & 0x00000001; - information->fQualifiedDebugStore = (c >> 4) & 0x00000001; - information->rFeature37 = (c >> 5) & 0x00000001; - information->rFeature38 = (c >> 6) & 0x00000001; - information->rFeature39 = (c >> 7) & 0x00000001; - information->fThermalMonitor2 = (c >> 8) & 0x00000001; - information->rFeature41 = (c >> 9) & 0x00000001; - information->fContextID = (c >> 10) & 0x00000001; - information->rFeature43 = (c >> 11) & 0x00000001; - information->rFeature44 = (c >> 12) & 0x00000001; - information->rFeature45 = (c >> 13) & 0x00000001; - information->rFeature46 = (c >> 14) & 0x00000001; - information->rFeature47 = (c >> 15) & 0x00000001; - information->rFeature48 = (c >> 16) & 0x00000001; - information->rFeature49 = (c >> 17) & 0x00000001; - information->rFeature50 = (c >> 18) & 0x00000001; - information->rFeature51 = (c >> 19) & 0x00000001; - information->rFeature52 = (c >> 20) & 0x00000001; - information->rFeature53 = (c >> 21) & 0x00000001; - information->rFeature54 = (c >> 22) & 0x00000001; - information->rFeature55 = (c >> 23) & 0x00000001; - information->rFeature56 = (c >> 24) & 0x00000001; - information->rFeature57 = (c >> 25) & 0x00000001; - information->rFeature58 = (c >> 26) & 0x00000001; - information->rFeature59 = (c >> 27) & 0x00000001; - information->rFeature60 = (c >> 28) & 0x00000001; - information->rFeature61 = (c >> 29) & 0x00000001; - information->rFeature62 = (c >> 30) & 0x00000001; - information->rFeature63 = (c >> 31) & 0x00000001; - - information->vBrand = (b & 0x000000FF) >> 0; - if(information->iCLFLUSH) - information->cLineSize = (b & 0x0000FF00) >> 8; - if(information->fHyperThreading) - information->uLogicalProcessorCount = (b & 0x00FF0000) >> 16; - if(information->vFamily >= 0xF) - information->uAPICID = (b & 0xFF000000) >> 24; - - /*** 0x00000002 - Cache Descriptors ***********/ - n = 1; - - for(i = 0; i < n; i++) - { - prcCPUID(processor, 0x00000002, &a, &b, &c, &d); - - n = a & 0x000000FF; - - if(!(a & 0x80000000)) - { - IdentifyIntelCache(information, (a >> 8) & 0x000000FF); - IdentifyIntelCache(information, (a >> 16) & 0x000000FF); - IdentifyIntelCache(information, (a >> 24) & 0x000000FF); - } - - if(!(b & 0x80000000)) - { - IdentifyIntelCache(information, (b >> 0) & 0x000000FF); - IdentifyIntelCache(information, (b >> 8) & 0x000000FF); - IdentifyIntelCache(information, (b >> 16) & 0x000000FF); - IdentifyIntelCache(information, (b >> 24) & 0x000000FF); - } - - if(!(c & 0x80000000)) - { - IdentifyIntelCache(information, (c >> 0) & 0x000000FF); - IdentifyIntelCache(information, (c >> 8) & 0x000000FF); - IdentifyIntelCache(information, (c >> 16) & 0x000000FF); - IdentifyIntelCache(information, (c >> 24) & 0x000000FF); - } - - if(!(d & 0x80000000)) - { - IdentifyIntelCache(information, (d >> 0) & 0x000000FF); - IdentifyIntelCache(information, (d >> 8) & 0x000000FF); - IdentifyIntelCache(information, (d >> 16) & 0x000000FF); - IdentifyIntelCache(information, (d >> 24) & 0x000000FF); - } - } - - /*** 0x00000003 - Serial Number ***************/ - - /*** 0x00000004 - Cache Parameters ************/ - - /*** 0x00000005 - Monitor *********************/ - - /** - * THE EXTRA NUMBER - * Type - * Pentium II + III Cache - * Pentium III + 4 Brand ID - * Athlon Multi Processing / Cache - */ - - Extra = information->vType; - - if(!strcmp(information->vVendor, "GenuineIntel") - && information->vFamily == 6 - && information->vModel >= 3 - && information->vModel <= 7) - { - Extra = information->cL2UnifiedCacheSize; - } - - if(!strcmp(information->vVendor, "GenuineIntel") - && information->vFamily == 6 - && information->vModel >= 8) - { - Extra = information->vBrand; - } - - if(!strcmp(information->vVendor, "GenuineIntel") - && information->vFamily == 0xF) - { - Extra = information->vBrand; - } - - if(!strcmp(information->vVendor, "AuthenticAMD") - && information->vFamily == 6) - { - Extra = 0; - } - - IdentifyProcessor(information, Extra); -} - -void prcCPUID(uint64_t processor, uint32_t function, uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d) -{ - asm - ( - "cpuid" - : "=a" (*a), "=b" (*b), "=c" (*c), "=d" (*d) - : "a" (function) - ); -} - -void IdentifyIntelCache(prcInformation* information, int descriptor) -{ - switch(descriptor) - { - case 0x00: - return; - case 0x40: - return; - case 0x01: - information->cL1CodeTLB4KEntries = 32; - information->cL1CodeTLB4KAssociativity = 4; - return; - case 0x02: - information->cL1CodeTLB4MEntries = 2; - information->cL1CodeTLB4MAssociativity = -1; - return; - case 0x03: - information->cL1DataTLB4KEntries = 64; - information->cL1DataTLB4KAssociativity = 4; - return; - case 0x04: - information->cL1DataTLB4MEntries = 8; - information->cL1DataTLB4MAssociativity = 4; - return; - case 0x06: - information->cL1CodeCacheSize = 8; - information->cL1CodeCacheAssociativity = 4; - information->cL1CodeCacheLineSize = 32; - information->cL1CodeCacheLinesPerTag = -1; - return; - case 0x08: - information->cL1CodeCacheSize = 16; - information->cL1CodeCacheAssociativity = 4; - information->cL1CodeCacheLineSize = 32; - information->cL1CodeCacheLinesPerTag = -1; - return; - case 0x0A: - information->cL1DataCacheSize = 8; - information->cL1DataCacheAssociativity = 2; - information->cL1DataCacheLineSize = 32; - information->cL1DataCacheLinesPerTag = -1; - return; - case 0x0C: - information->cL1DataCacheSize = 16; - information->cL1DataCacheAssociativity = 4; - information->cL1DataCacheLineSize = 32; - information->cL1DataCacheLinesPerTag = -1; - return; - case 0x22: - information->cL3UnifiedCacheSize = 512; - information->cL3UnifiedCacheAssociativity = 4; - information->cL3UnifiedCacheLineSize = 64; - information->cL3UnifiedCacheLinesPerTag = -1; - return; - case 0x23: - information->cL3UnifiedCacheSize = 1024; - information->cL3UnifiedCacheAssociativity = 8; - information->cL3UnifiedCacheLineSize = 64; - information->cL3UnifiedCacheLinesPerTag = -1; - return; - case 0x25: - information->cL3UnifiedCacheSize = 2048; - information->cL3UnifiedCacheAssociativity = 8; - information->cL3UnifiedCacheLineSize = 64; - information->cL3UnifiedCacheLinesPerTag = -1; - return; - case 0x29: - information->cL3UnifiedCacheSize = 4096; - information->cL3UnifiedCacheAssociativity = 8; - information->cL3UnifiedCacheLineSize = 64; - information->cL3UnifiedCacheLinesPerTag = -1; - return; - case 0x39: - information->cL2UnifiedCacheSize = 128; - information->cL2UnifiedCacheAssociativity = 4; - information->cL2UnifiedCacheLineSize = 64; - information->cL2UnifiedCacheLinesPerTag = -1; - return; - case 0x3B: - information->cL2UnifiedCacheSize = 128; - information->cL2UnifiedCacheAssociativity = 2; - information->cL2UnifiedCacheLineSize = 64; - information->cL2UnifiedCacheLinesPerTag = -1; - return; - case 0x3C: - information->cL2UnifiedCacheSize = 256; - information->cL2UnifiedCacheAssociativity = 4; - information->cL2UnifiedCacheLineSize = 64; - information->cL2UnifiedCacheLinesPerTag = -1; - return; - case 0x41: - information->cL2UnifiedCacheSize = 128; - information->cL2UnifiedCacheAssociativity = 4; - information->cL2UnifiedCacheLineSize = 32; - information->cL2UnifiedCacheLinesPerTag = -1; - return; - case 0x42: - information->cL2UnifiedCacheSize = 256; - information->cL2UnifiedCacheAssociativity = 4; - information->cL2UnifiedCacheLineSize = 32; - information->cL2UnifiedCacheLinesPerTag = -1; - return; - case 0x43: - information->cL2UnifiedCacheSize = 512; - information->cL2UnifiedCacheAssociativity = 4; - information->cL2UnifiedCacheLineSize = 32; - information->cL2UnifiedCacheLinesPerTag = -1; - return; - case 0x44: - information->cL2UnifiedCacheSize = 1024; - information->cL2UnifiedCacheAssociativity = 4; - information->cL2UnifiedCacheLineSize = 32; - information->cL2UnifiedCacheLinesPerTag = -1; - return; - case 0x45: - information->cL2UnifiedCacheSize = 2048; - information->cL2UnifiedCacheAssociativity = 4; - information->cL2UnifiedCacheLineSize = 32; - information->cL2UnifiedCacheLinesPerTag = -1; - return; - case 0x50: - information->cL1CodeTLB4KEntries = 64; - information->cL1CodeTLB4KAssociativity = -1; - information->cL1CodeTLB2MEntries = 64; - information->cL1CodeTLB2MAssociativity = -1; - information->cL1CodeTLB4MEntries = 64; - information->cL1CodeTLB4MAssociativity = -1; - return; - case 0x51: - information->cL1CodeTLB4KEntries = 128; - information->cL1CodeTLB4KAssociativity = -1; - information->cL1CodeTLB2MEntries = 128; - information->cL1CodeTLB2MAssociativity = -1; - information->cL1CodeTLB4MEntries = 128; - information->cL1CodeTLB4MAssociativity = -1; - return; - case 0x52: - information->cL1CodeTLB4KEntries = 256; - information->cL1CodeTLB4KAssociativity = -1; - information->cL1CodeTLB2MEntries = 256; - information->cL1CodeTLB2MAssociativity = -1; - information->cL1CodeTLB4MEntries = 256; - information->cL1CodeTLB4MAssociativity = -1; - return; - case 0x5B: - information->cL1DataTLB4KEntries = 64; - information->cL1DataTLB4KAssociativity = -1; - information->cL1DataTLB4MEntries = 64; - information->cL1DataTLB4MAssociativity = -1; - return; - case 0x5C: - information->cL1DataTLB4KEntries = 128; - information->cL1DataTLB4KAssociativity = -1; - information->cL1DataTLB4MEntries = 128; - information->cL1DataTLB4MAssociativity = -1; - return; - case 0x5D: - information->cL1DataTLB4KEntries = 256; - information->cL1DataTLB4KAssociativity = -1; - information->cL1DataTLB4MEntries = 256; - information->cL1DataTLB4MAssociativity = -1; - return; - case 0x66: - information->cL1DataCacheSize = 8; - information->cL1DataCacheAssociativity = 4; - information->cL1DataCacheLineSize = 64; - information->cL1DataCacheLinesPerTag = -1; - return; - case 0x67: - information->cL1DataCacheSize = 16; - information->cL1DataCacheAssociativity = 4; - information->cL1DataCacheLineSize = 64; - information->cL1DataCacheLinesPerTag = -1; - return; - case 0x68: - information->cL1DataCacheSize = 32; - information->cL1DataCacheAssociativity = 4; - information->cL1DataCacheLineSize = 64; - information->cL1DataCacheLinesPerTag = -1; - return; - case 0x70: - information->cTraceCacheMicroOps = 12; - information->cTraceCacheAssociativity = 8; - return; - case 0x71: - information->cTraceCacheMicroOps = 16; - information->cTraceCacheAssociativity = 8; - return; - case 0x72: - information->cTraceCacheMicroOps = 32; - information->cTraceCacheAssociativity = 8; - return; - case 0x77: - information->cL1CodeCacheSize = 16; - information->cL1CodeCacheAssociativity = 4; - information->cL1CodeCacheLineSize = 64; - information->cL1CodeCacheLinesPerTag = -1; - return; - case 0x79: - information->cL2UnifiedCacheSize = 128; - information->cL2UnifiedCacheAssociativity = 8; - information->cL2UnifiedCacheLineSize = 64; - information->cL2UnifiedCacheLinesPerTag = -1; - return; - case 0x7A: - information->cL2UnifiedCacheSize = 256; - information->cL2UnifiedCacheAssociativity = 8; - information->cL2UnifiedCacheLineSize = 64; - information->cL2UnifiedCacheLinesPerTag = -1; - return; - case 0x7B: - information->cL2UnifiedCacheSize = 512; - information->cL2UnifiedCacheAssociativity = 8; - information->cL2UnifiedCacheLineSize = 64; - information->cL2UnifiedCacheLinesPerTag = -1; - return; - case 0x7C: - information->cL2UnifiedCacheSize = 1024; - information->cL2UnifiedCacheAssociativity = 8; - information->cL2UnifiedCacheLineSize = 64; - information->cL2UnifiedCacheLinesPerTag = -1; - return; - case 0x7E: - information->cL2UnifiedCacheSize = 256; - information->cL2UnifiedCacheAssociativity = 8; - information->cL2UnifiedCacheLineSize = 128; - information->cL2UnifiedCacheLinesPerTag = -1; - return; - case 0x82: - information->cL2UnifiedCacheSize = 128; - information->cL2UnifiedCacheAssociativity = 8; - information->cL2UnifiedCacheLineSize = 32; - information->cL2UnifiedCacheLinesPerTag = -1; - return; - case 0x83: - information->cL2UnifiedCacheSize = 256; - information->cL2UnifiedCacheAssociativity = 8; - information->cL2UnifiedCacheLineSize = 32; - information->cL2UnifiedCacheLinesPerTag = -1; - return; - case 0x84: - information->cL2UnifiedCacheSize = 512; - information->cL2UnifiedCacheAssociativity = 8; - information->cL2UnifiedCacheLineSize = 32; - information->cL2UnifiedCacheLinesPerTag = -1; - return; - case 0x85: - information->cL2UnifiedCacheSize = 1024; - information->cL2UnifiedCacheAssociativity = 8; - information->cL2UnifiedCacheLineSize = 32; - information->cL2UnifiedCacheLinesPerTag = -1; - return; - case 0x8D: - information->cL3UnifiedCacheSize = 3072; - information->cL3UnifiedCacheAssociativity = 12; - information->cL3UnifiedCacheLineSize = 128; - information->cL3UnifiedCacheLinesPerTag = -1; - return; - } - - /*printf("Unknown Intel Cache Descriptor: %x\n", CacheDescriptor);*/ -} - -int AMDAssociativity(int Value) -{ - switch (Value) - { - case 0x00: return 0; - case 0x01: return 1; - case 0x02: return 2; - case 0x04: return 4; - case 0x06: return 8; - case 0x08: return 16; - case 0x0F: return -1; - } - - /*puts("Unknown AMD Cache Descriptor");*/ - return -1; -} - -void IdentifyProcessor(prcInformation* information, int Extra) -{ - int i; - - for(i = 0; i < (sizeof(ProcessorList) / sizeof(PROCLIST)); i++) - { - if(ProcessorList[i].id == 0x02000000 + (information->vFamily << 16) + (information->vModel << 8) + Extra) - { - information->pName = ProcessorList[i].name; - information->pCertified = ProcessorList[i].verified; - return; - } - } - - for(i = 0; i < (sizeof(ProcessorList) / sizeof(PROCLIST)); i++) - { - if(ProcessorList[i].id == 0x020000FF + (information->vFamily << 16) + (information->vModel << 8)) - { - information->pName = ProcessorList[i].name; - information->pCertified = ProcessorList[i].verified; - return; - } - } - - for(i = 0; i < (sizeof(ProcessorList) / sizeof(PROCLIST)); i++) - { - if(ProcessorList[i].id == 0x0200FFFF + (information->vFamily << 16)) - { - information->pName = ProcessorList[i].name; - information->pCertified = ProcessorList[i].verified; - return; - } - } - - for(i = 0; i < (sizeof(ProcessorList) / sizeof(PROCLIST)); i++) - { - if(ProcessorList[i].id == 0x02FFFFFF) - { - information->pName = ProcessorList[i].name; - information->pCertified = ProcessorList[i].verified; - return; - } - } - - information->pName = "Unknown Processor"; - information->pCertified = false; -} +/** + * Processor Management + */ + +/** + * Processor Identification + */ + +/** + * Name Title Revision + * ---------------------------------------------------------------------------------------------------- + * AMD AMD-K6 Processor Model 6 Revision Guide G 1998 August + * AMD AMD-K6 Processor Model 7 Revision Guide H 1999 June + * AMD AMD-K6-2 Processor Model 8 Revision Guide F 1999 June + * AMD AMD-K6-III Processor Model 9 Revision Guide C 1999 July + * AMD AMD Athlon Processor Model 1 & Model 2 Revision Guide D 2000 August + * AMD AMD Duron Processor Model 3 Revision Guide I 2002 December + * AMD AMD Athlon Processor Model 4 Revision Guide I 2002 December + * AMD AMD Athlon Processor Model 6 Revision Guide E 2002 December + * AMD AMD Duron Processor Model 7 Revision Guide C 2002 December + * AMD AMD Athlon Processor Model 8 Revision Guide C 2002 December + * + * Intel Intel386 CX/SXSA Microprocessor Specification Update 002 1997 January + * Intel Intel386 DX Processor Specification Update 002 1997 January + * Intel Intel386 EX Embedded Processor Specification Update 010 1998 October + * Intel 60- and 66-MHz Pentium Processor Specification Update 001 1997 February + * Intel Pentium Processor Specification Update 041 1999 January + * Intel Pentium Pro Processor Specification Update 039 1999 January + * Intel Mobile Intel Celeron Processor at 466 MHz, ... Specification Update 038 2002 November + * Intel Mobile Intel Pentium II Processor Specification Update 046 2002 November + * Intel Intel Pentium II Xeon Processor Specification Update 032 2002 January + * Intel Intel Pentium II Processor Specification Update 049 2002 July + * Intel Intel Celeron Processor Specification Update 047 2002 October + * Intel Intel Pentium III Processor Specification Update 045 2002 November + * Intel Mobile Intel Celeron Processor (0.18� and 0.13�) Specification Update 030 2002 August + * Intel Mobile Intel Pentium III Processor and ... Specification Update 036 2002 November + * Intel Intel Pentium III Xeon Processor Specification Update 037 2002 July + * Intel Intel Pentium 4 Processor Specification Update 029 2002 November + * Intel Mobile Intel Pentium 4 Processor-M Specification Update 008 2002 November + * Intel Intel Celeron Processor in the 478-Pin Package Specification Update 005 2002 November + * Intel Mobile Intel Celeron Processor on .13 Micron ... Specification Update 002 2002 August + * Intel Intel Xeon Processor Specification Update 020 2002 November + * Intel Intel Xeon Processor MP Specification Updata 009 2002 November + * Intel Low Voltage Intel Xeon Processor Specification Update 003 2002 November + * Intel Intel Pentium M Processor 001 2003 March + * Intel Intel Itanium Processor Specification Update 008 2003 January + * Intel Intel Itanium 2 Processor Specification Update 007 2003 January + * AMD AMD Processor Recognition W-1 2002 November + * Intel Intel Processor Identification and the CPUID Instruction 023 2003 March + * Intel Intel Processor Serial Number 001 1999 March + * IDT IDT WinChip C6 Data Sheet 1.10 1998 March + */ + +/** + * Mobile Athlon Detection + * + * Problems with CPU identication: + * 1) How much information? + * 2) Getting the information + * + * CPU identification has two purposes: OS information and user information. Since this module wil be + * used in TriOS we'll only need OS information (ident upto stepping for erratas) No process size, + * packaging or voltage info. I can be found withofficial name and codename. To prevent user confusion + * we need to show the diff between Celeron / Pentium / Xeon. Cache info is important for some memory + * defragmentation and alignment algorithms, perhaps. + * + * OLD CPUS: + * + * i4004 / i4040 + * i8008 / i8080 / i8080A / Zilog Z80 / i8085A / i8085AH + * + * 2.13 Contemporary CPUs + * Contemporary 16 bit CPUs to 8086/8088 were Zilog Z8000 CPU, Fairchild 9445 CPU, Texas Instruments TI9900 CPU and Mil-Std 1750A CPU. Last is reason DOD (Department Of Defence) contractors were not interested in 8086/8088. Mil-Std 1750A CPU was specified in all contracts of 1979 - 1984 period. + * Texas Instruments TI9900 CPU was probably the best of the lot, but Texas Instruments considered it a closed architecture, so no-one used it. + * + * 8086 - 80368 Intel Only + * 80486 Lots of manufacturers, almost no stpping info + * 80586 Lots of incorrect information and processors that were never sold, no stepping info + * 80686 Celeron / Pentium / Xeon // !Mobile! (Inel realy srewed up the names here) + * 80786 VERY WELL DONE BY INTEL (at least names are a bit more consistant) + * 80886 Not officialy realeasd at the moment + * + * Intel detection: AAA xxh doesn't #UD + * Cyrix Detection: Read the chipset data, but I heard there was a better one + * AMD Detection If there not TI, IBM, UMC, Cyrix or Intel, must be AMD, need sometin' better + * UMC Detection support CPUID I believe + * Texas Detection Models do not real conflic (aren't those things the same as IBM have to check) + * IBM Detection Ax or 8x as family (but there are exceptions) and models do not conflict + * + * CYRIX/TI/IBM Identificaton through Chipset Data (I/O 22h and 23h) + * + * Not about the use of stepping and revision: + * + * Stepping is used always. I try to change this into: Stepping = A0 / Revision = 3h + * Intel also calls the revion Stepping ID + * + * 386 Reset Data + * 0- 3 Minor Stepping Revision + * 4- 7 Major Stepping Model + * 8-11 Family Family + * 12-15 Type DX/SX/SL and TI/IBM/Intel + * + * 486+ Reset Data + * 0- 3 Revision + * 4- 7 Model + * 8-11 Family + * 12-13 Type 0 = Normal, 1 = OverDrive, 2 = Second Processor, 3 = Reserved + * 14-15 Reserved + * 16-19 Extended Model + * 20-27 Extended Family + * 28-30 Reserved + * 31 Reserved Has Serial Number + * + * All over drives could also have type 0 if they are an errata (whatever that means) + * + * Legal Mumbo Jumbo: In the CPUID Documentation, Intel says the PSN could be reported wrongly, for + * example if the voltage or frequency is wrong. It doesn't say it's corec when the processor is + * working on the correct voltage and frequency... + * + * IF HighetExtened CPUID Fucntion > 0x80000000 Brand String is supported, even if 0x800000001 or 2 ??? + * + * Should OverDrives just be ignored? According to Intel internal caches or execution times may vary + * According to Intel CPUID is unreliable in V86 Mode + * According to Intel MSRs vary between different Models of the Pentium (P5 that is) + * PSN is not guaranteed to be unique + * Intel PSN Style: XXXX-XXXX-XXXX-XXXX-XXXX-XXXX (96 bit) + * Transmeta PSN S: XXXXXXXX:XXXXXXXX:XXXXXXXX:XXXXXXXX (128 bit) + * + * Intel says apps need to use the BRAND STRING to identify the processor (ARE THEY CRAZY???) + * Intel says apps need to use the BRAND ID to identify the processor (not crazy, but useless) + * + * DAZ DAZ DAZ DAZ DAZ DAZ DAZ + * + * 11 DENORMALS ARE ZERO + * With the introduction of the SSE2 extensions, some Intel Architecture processors have the ability to convert SSE + * and SSE2 source operand denormal numbers to zero. This feature is referred to as Denormals -Are-Zero (DAZ). The + * DAZ mode is not compatible with IEEE Standard 754. The DAZ mode is provided to improve processor + * performance for applications such as streaming media processing, where rounding a denormal operand to zero does + * not appreciably affect the quality of the processed data. + * Some processor steppings support SSE2 but do not support the DAZ mode. To determine if a processor supports the + * DAZ mode, software must perform the following steps. + * 1. Execute the CPUID instruction with an input value of EAX=0 and ensure the vendor-ID string returned is �GenuineIntel�. + * 2. Execute the CPUID instruction with EAX=1. This will load the EDX register with the feature flags. + * 3. Ensure that the FXSR feature flag (EDX bit 24) is set. This indicates the processor supports the FXSAVE and FXRSTOR + * instructions. + * 4. Ensure that the XMM feature flag (EDX bit 25) or the EMM feature flag (EDX bit 26) is set. This indicates that the + * processor supports at least one of the SSE/SSE2 instruction sets and its MXCSR control register. + * 5. Zero a 16-byte aligned, 512-byte area of memory. This is necessary since some implementations of FXSAVE do not modify + * reserved areas within the image. + * 6. Execute an FXSAVE into the cleared area. + * 7. Bytes 28-31 of the FXSAVE image are defined to contain the MXCSR_MASK. If this value is 0, then the processor's + * MXCSR_MASK is 0xFFBF, otherwise MXCSR_MASK is the value of this dword. + * 8. If bit 6 of the MXCSR_MASK is set, then DAZ is supported. + * After completing this algorithm, if DAZ is supported, software can enable DAZ mode by setting bit 6 in the + * MXCSR register save area and executing the FXRSTOR instruction. Alternately software can enable DAZ mode by + * setting bit 6 in the MXCSR by executing the LDMXCSR instruction. Refer to the chapter titled �Programming with + * the Streaming SIMD Extensions (SSE)� in the Intel Architecture Software Developer�s Manual volume 1: Basic + * Architecture. + * + * DAZ DAZ DAZ DAZ DAZ DAZ DAZ + * + * Legacy detecyion + * 8086 EFLAGS 12-15 are always set + * 80286 EFLAGS 12-15 are clear in RM + * 80366 EFLAGS 18 Cant be set, if it can it a 486+ + * 80848 EFLAGS 21 Can't be set, if it can use CPUID + * + * FPU If control/status word can be saved it's present + * 27/387 Infinity control Rounding Stuff + * 487 486 with coproc + * + * What about the Xeon DP???? + * + * CMXCHG8B Disabled because of Stuoid MSWinNT bug (studpid. Microsft not diabling. stupid) + * + * sAVE bRAND sTRING BEFRORE s3 POWER DOWN + * + * NSC Geode!!!! + * + * "The iAPX 286 will push a different value on the stack for PUSH SP than the iAPX 86/88." + * "When a word write is performed at offset FFFFh in a segment, the 8086 will write one byte at offset + * FFFFh, and the other at offset 0, while an 80186 family processor will write one byte at offset + * FFFFh, and the other at offset 10000h (one byte beyond the end of the segment)." + * + * A finalty note: I'm looking for some information on the Intel Timna (Intel's MediaGX). The project + * was abandonned so Intel never published any useful material on this. It was based on the P-III. + * Also some info in the Microsoft X-Box' special P-III would help + */ + +#include +#include "bootlog.h" + +typedef struct { + unsigned n; + char* i; + char* v; +} VENDORLIST; + +VENDORLIST VendorList[] = +{ + {0x0001, "ThinkTrinary", "Trinary Technologies"}, + {0x0002, "GenuineIntel", "Intel"}, + {0x0003, "AuthenticAMD", "AMD"}, + {0x0003, "AMD ISBETTER", "AMD"}, + {0x0004, "CentaurHauls", "Centaur (IDT / VIA)"}, + {0x0005, "CyrixInstead", "Cyrix (VIA)"}, + {0x0006, "GenuineTMx86", "Transmeta"}, + {0x0007, "Geode by NSC", "National Semiconductor"}, + {0x0008, "NexGenDriven", "NexGen"}, + {0x0009, "RiseRiseRise", "Rise"}, + {0x000A, "SiS SiS SiS ", "SiS"}, + {0x000B, "UMC UMC UMC ", "UMC"}, +}; + +typedef struct { + long long id; + bool verified; + char* name; +} PROCLIST; + + + +PROCLIST ProcessorList[] = +{ + {0x00FFFFFF, false, "Unknown x86 Processor"}, + {0x0000FFFF, false, "Unknown 8086 Compatible Processor"}, + {0x0001FFFF, false, "Unknown 186 Compatible Processor"}, + {0x0002FFFF, false, "Unknown 286 Compatible Processor"}, + {0x0003FFFF, false, "Unknown 386 Compatible Processor"}, + {0x0004FFFF, false, "Unknown 486 Compatible Processor"}, + {0x0005FFFF, false, "Unknown 586 Compatible Processor"}, + {0x0006FFFF, false, "Unknown 686 Compatible Processor"}, + {0x02FFFFFF, false, "Unknown Intel Processor"}, + {0x0203FFFF, false, "Unknown Intel i386 Processor"}, + {0x0204FFFF, false, "Unknown Intel i486 Processor"}, + {0x0205FFFF, false, "Unknown Intel Pentium Processor"}, + {0x020501FF, false, "Intel Pentium Classic"}, + {0x020502FF, false, "Intel Pentium"}, + {0x020503FF, false, "Intel Pentium OverDrive"}, + {0x020504FF, false, "Intel Pentium MMX"}, + {0x020507FF, false, "Intel Pentium Mobile"}, + {0x020508FF, false, "Intel Pentium MMX Mobile 'Tillamook'"}, + {0x0206FFFF, false, "Unknown Intel P6 Processor"}, + {0x020601FF, false, "Intel Pentium Pro"}, + {0x020603FF, false, "Unknown Intel Pentium II"}, + {0x02060301, false, "Intel Pentium II 'Klamath'"}, /* 0512 - 0512 */ + {0x02060305, false, "Intel Pentium II OverDrive"}, /* OVERDRIVE */ + {0x020605FF, false, "Unknown Intel Pentium II"}, + {0x02060500, false, "Intel Celeron II 'Covington'"}, /* 0000 - 0000 */ + {0x02060501, false, "Intel Pentium II 'Deschutes'"}, /* 0512 - 0512 */ + {0x02060502, false, "Intel Xeon II 'Drake'"}, /* 0512 - 2048 */ + {0x02060504, false, "Intel Pentium II Mobile 'Tonga'"}, /* 0512 - 0512 */ + {0x020606FF, false, "Unknown Intel Pentium II"}, + {0x02060600, false, "Intel Celeron II 'Mendocino'"}, /* 0128 - 0128 */ +/**/ {0x02060603, false, "Intel Celeron II Mobile"}, /* 0128 - 0128 (A) */ + {0x02060604, false, "Intel Pentium II Mobile 'Dixon'"}, /* 0256 - 0256 (A) */ + {0x020607FF, false, "Unknown Intel Pentium III"}, + {0x02060701, false, "Intel Pentium III 'Katmai'"}, /* 0512 - 0512 */ + {0x02060702, false, "Intel Xeon III 'Tanner'"}, /* 0512 - 2048 */ + {0x020608FF, false, "Unknown Intel Pentium III"}, + {0x02060801, false, "Intel Celeron III 'Coppermine'"}, + {0x02060802, false, "Intel Pentium III (Mobile) 'Coppermine'"}, + {0x02060803, false, "Intel Xeon III 'Cascades'"}, + {0x020609FF, false, "Unknown Intel Pentium M"}, + {0x02060916, false, "Intel Pentium M 'Banias'"}, + {0x02060AFF, false, "Unknown Intel Pentium III"}, + {0x02060A03, false, "Intel Xeon III 'Cascades'"}, + {0x02060BFF, false, "Unknown Intel Pentium III"}, + {0x02060B03, false, "Intel Celeron III 'Tualatin'"}, + {0x02060B04, false, "Intel Pentium III 'Coppermine'"}, + {0x02060B06, false, "Intel Pentium III Mobile 'Geyserville'"}, + {0x02060B07, false, "Intel Celeron III Mobile 'Geyserville'"}, + {0x0207FFFF, false, "Unknown Intel Itanium"}, + {0x020FFFFF, false, "Unknown Intel NetBurst Processor"}, + {0x020F0008, false, "Intel Pentium 4 'Willamette'"}, + {0x020F000E, false, "Intel Xeon 4 'Foster'"}, + {0x020F0108, false, "Intel Pentium 4 'Willamette'"}, + {0x020F0109, false, "Intel Pentium 4 'Willamette'"}, + {0x020F010A, false, "Intel Celeron 4 'Willamette'"}, + {0x020F010B, false, "Intel Xeon 4 MP 'Foster'"}, + {0x020F010E, false, "Intel Xeon 4 'Foster'"}, + {0x020F020C, false, "Intel Xeon 4 MP 'Gallatin'"}, + {0x020F0208, false, "Intel Celeron 4 Mobile 'Northwood'"}, + {0x020F0209, false, "Intel Pentium 4 'Northwood'"}, + {0x020F020B, false, "Intel Xeon 4 'Prestonia'"}, + {0x020F020E, false, "Intel Pentium 4 Mobile 'Northwood'"}, + {0x020F020A, false, "Intel Celeron 4 'Northwood'"}, + {0x0210FFFF, false, "Unknown Intel Itanium 2"}, + {0x03FFFFFF, false, "Unknown AMD Processor"}, + {0x0306FFFF, false, "Unknown AMD Athlon Processor"}, + {0x030601FF, false, "AMD Athlon 'Pluto'"}, + {0x030602FF, false, "AMD Athlon 'Argon'"}, + {0x030603FF, false, "AMD Duron 'Spitfire'"}, + {0x030604FF, false, "AMD Athlon 'Thunderbird'"}, + {0x030605FF, false, "AMD Athlon Ultra 'Mustang'"}, + {0x030606FF, false, "AMD Athlon MP 'Palomino'"}, + {0x030606FF, false, "AMD Athlon XP/MP 'Palomino'"}, + {0x030606FF, false, "AMD Athlon 4 Mobile 'Palomino'"}, + {0x030607FF, false, "AMD Duron 'Morgan'"}, + {0x030607FF, false, "AMD Duron MP 'Morgan'"}, + {0x030607FF, false, "AMD Duron Mobile 'Morgan'"}, + {0x030608FF, false, "AMD Athlon XP 'Thoroughbred'"}, + {0x030608FF, false, "AMD Athlon MP 'Thoroughbred'"}, + {0x030608FF, false, "AMD Athlon XP Mobile 'Thoroughbred'"}, + {0x030609FF, false, "AMD Duron 'Appaloosa'"}, + {0x030609FF, false, "AMD Duron MP 'Appaloosa'"}, + {0x030609FF, false, "AMD Duron Mobile 'Appaloosa'"}, + {0x03060AFF, false, "AMD Athlon XP 'Barton'"}, + {0x03060AFF, false, "AMD Athlon MP 'Barton'"}, + {0x04FFFFFF, false, "Unknown IDT / VIA Processor"}, + {0x0405FFFF, false, "Unknown IDT WinChip"}, + {0x040504FF, false, "IDT WinChip C6"}, + {0x040508FF, false, "IDT WinChip 2"}, + {0x040509FF, false, "IDT WinChip 3"}, + {0x0406FFFF, false, "Unknown VIA C3"}, + {0x040606FF, false, "VIA C3 'Samuel 1' / VIA Eden 4000"}, + {0x040607FF, false, "VIA C3 'Samuel 2 / Ezra' / VIA Eden 5000 / VIA Eden 6000"}, /* 0-7 / 8-F */ + {0x040608FF, false, "VIA C3 'Ezra-T' (VIA Eden 7000)"}, +// {0x040609FF, false, "VIA C3 'Nehalem VIA Eden 8000"}, + {0x05FFFFFF, false, "Unknown Cyrix Processor"}, + {0x0506FFFF, false, "Unknown VIA Cyrix III"}, + {0x050605FF, false, "VIA Cyrix III 'Joshua'"}, + {0x06FFFFFF, false, "Unknown Transmeta Processor"}, + {0x0604FFFF, false, "Transmeta Crusoe 3x00 / 5x00 Processor"}, + {0x08FFFFFF, false, "Unknown NexGen Processor"}, + {0x0805FFFF, false, "Unknown NexGen Nx586 / Nx686 Processor"}, + {0x080500FF, false, "Unknown NexGen Nx586"}, + {0x08050000, false, "NexGen Nx586"}, + {0x08050001, false, "NexGen Nx586FP"}, + //{0x0805??FF, false, "Unknown NexGen Nx686"}, + {0x0CFFFFFF, false, "Unknown UMC Processor"}, + {0x0C04FFFF, false, "Unknown UMC 486 Processor"}, + {0x0C0401FF, false, "UMC U5SD"}, + {0x0C0402FF, false, "UMC U5S"}, + {0x0C0403FF, false, "UMC U486DX2"}, + {0x0C0405FF, false, "UMC U486SX2"}, + + + + + + + + + {0xABCDABCD, false, "XXX"} +}; + + +#if 0 + /**********************************************************************************************/ +// {"GenuineIntel", 0x05, 0x00, 0x0?, 0, false, "Intel Pentium Classic (A*)"}, +// {"GenuineIntel", 0x05, 0x01, 0x02, 0, false, "Intel Pentium Classic (B*)"}, +// {"GenuineIntel", 0x05, 0x01, 0x04, 0, false, "Intel Pentium Classic (B2)"}, +// {"GenuineIntel", 0x05, 0x04, 0x01, 0, false, "Intel Pentium MMX (A1)"}, +// {"GenuineIntel", 0x05, 0x04, 0x02, 0, false, "Intel Pentium MMX (A2)"}, +// {"GenuineIntel", 0x05, 0x05, 0x0?, 0, false, "Intel Pentium MMX OverDrive"}, +// {"GenuineIntel", 0x05, 0x06, 0x0?, 0, false, "Intel Pentium MMX OverDrive"}, +// {"GenuineIntel", 0x06, 0x00, 0x0?, 0, false, "Intel Pentium Pro (A0)"}, +// {"GenuineIntel", 0x06, 0x04, 0x0?, 0, false, "Intel Pentium II OverDrive (?)"}, +// {"GenuineIntel", 0x0F, 0x02, 0x07, 0x0E, false, "Intel Pentium 4 Mobile (C1)"}, +// {"AuthenticAMD", 0x06, 4, 4, 0, false, "AMD Athlon 'Thunderbird' Model 4 (B0)"}, //??Grzegorz +// {"AuthenticAMD", 0x06,5?, ?, 0, false, "AMD Athlon Ultra 'Mustang' Model 5? (??)"}, /* CANCELED */ + +// {"GenuineIntel",F?,3?, ?, ?, "Intel Pentium 4 'Prescott' (??)"}, //.09 +// {"GenuineIntel",F?,3?, ?, ?, "Intel Xeon 4 'Nocona' (??)"}, //.09 +// {"GenuineIntel",F?,4?, ?, ?, "Intel Pentium 4 'Tyler' (??)"}, +// {"GenuineIntel",F?,4?, ?, ?, "Intel Pentium 4 'Tejas' (??)"}, +// {"GenuineIntel",F?,4?, ?, ?, "Intel Xeon 4 'Potomac' (??)"}, + +//GI Nehalem Pentium 5 + + +// {"GenuineIntel", ?,?, ?, ?, "Intel Mobillium 'Banias' (??)"}, +// {"GenuineIntel", ?,?, ?, ?, "Intel Mobillium 'Dothan' (??)"}, +// {"GenuineIntel", ?,?, ?, ?, "Intel Mobillium 'Morem' (??)"}, /* Next GEN!!!! */ +// {"GenuineIntel", ?,?, ?, ?, "Intel Mobillium 'Gilo' (??)"}, /* Next GEN!!!! */ +// Intel's truly mobile processor. Intel says this is a completly new processor. Sources say it's just +// a rework of the PIII or P4. I don't believe this, beacause it has SSE2 (not in PIII) and is faster +// than the P4. I guess they just shortened the enormous 20 stage P4 pipeline a bit, which is too long +// to be used effecivly. More backup is provided for the fact that the Pentium 5 will be based upon +// this chip. And another thing many sources will tell you this chip will be called 'Intel Banias', +// didn't Intel call the Pentium III, Intel Katmai for a very long time. With this in mind it wouldn't +// even surprise me if this processor is goin to be called Pentium 5. Sorry but I have to go one now +// I'm brainstorming. The mobile part of it might not even be used for mobile computers, but for +// desktops and servers as well, because cooling has become almost impossible today. If speeds are +// going to get even higher the next couple of years, the processor cores will just melt. Because +// AMD's processors get even hotter and isn't working on a similar project Intel might even regain +// it's market monopoly (wheter this is good or bad, I don't know?) +// {"GenuineIntel",F?,?, ?, ?, "Intel Pentium 5 'Nehalem' (??)"}, +// This is just a rumor. It's supposed to come out in 2006, run at 6Ghz and have a bus speed of +// 1.5Ghz. It COULD be using the Intel Banias core. Suggesting the Banias is a Pentium 5 and that it +// IS completely new. IF you read the note above this could also be the Pentium 6 or something. +// {"GenuineIntel", 7, 6, 4, 0, "Intel Itanium 'Merced' (C0)"}, //0007000604 +// {"GenuineIntel", 7, 7, 4, 0, "Intel Itanium 'Merced' (C1)"}, //0007000704 +// {"GenuineIntel", 7, 7, 4, 0, "Intel Itanium 'Merced' (C2)"}, //0007000804 +// {"GenuineIntel", 0x10, 0, ?, 0, "Intel Itanium 2 'McKinley' (B3)"}, //001F000704 +// {"GenuineIntel",A?, ?, ?, ?, ???, "Intel Itanium 2 'Madison' (??)"}, +// {"GenuineIntel",A?, ?, ?, ?, ???, "Intel Itanium 2 'Deerfield' (??)"},XXX +// {"GenuineIntel",A?, ?, ?, ?, ???, "Intel Itanium 2 'Montecito' (??)"} +// {"GenuineIntel",A?, ?, ?, ?, ???, "Intel Itanium 2 'Shavano' (??)"}, +// {"GenuineIntel",A?, ?, ?, ?, ???, "Intel Itanium 2? 'Yosemite' (??)"}, +// {"GenuineIntel",A?, ?, ?, ?, ???, "Intel Itanium 2? 'Tanglewood' (??)"}, + +// {"AuthenticAMD", ?, ?, ?, ?, "AMD Athlon XP64 / Hammer 'Clawhammer' (??)"}, +// {"AuthenticAMD", ?, ?, ?, ?, "AMD Athlon XP64 / Hammer 'San Diego' (??)"}, +// {"AuthenticAMD", ?, ?, ?, ?, "AMD Athlon XP64 / Hammer Mobile 'Odessa' (??)"}, +// {"AuthenticAMD", ?, ?, ?, ?, "AMD Opteron 'Sledgehammer' (??)"}, +// {"AuthenticAMD", ?, ?, ?, ?, "AMD Opteron 'Athens' (??)"}, +// {"CentaurHauls", 0x05, 0x08, 0x01, 0x00, false, "IDT WinChip 2"}, +// {"CentaurHauls", 6, 0xA, ?, 0, "IDT WinChip 4"}, //PROBABLY DOESN'T EXIST! -> Is a VIA C3!!! + + /** Intel 8086 / 8088 (Includes model manufactured by AMD, Harris, Siemens, Hitachi) ************/ + + //I belive there an alroithm to identify the diff between HMOS and CMOS models + {"GenuineIntel", 1, 0, 0, 0, false, "Intel 8088"}, + {"GenuineIntel", 1, 0, 0, 1, false, "Intel 8086"}, + {"GenuineIntel", 1, 0, 0, 2, false, "Intel 80C88"}, + {"GenuineIntel", 1, 0, 0, 3, false, "Intel 80C86"}, + {"GenuineIntel", 1, 0, 0, 4, false, "Intel 80188"}, //XL/EA/EB/EC AMD/Siemens + {"GenuineIntel", 1, 0, 0, 5, false, "Intel 80186"}, //XL/EA/EB/EC AMD/Siemens + {"GenuineIntel", 1, 0, 0, 6, false, "NEC V20"}, //V20H/V25/V25 Plus/V25 Softwae Guard/V40/V40H//V45 + {"GenuineIntel", 1, 0, 0, 7, false, "NEC V30"}, //V30H/V35/V35 Plus/V35 Softwae Guard/V50/V50H//V55 + //Intel 80886??? + + {"GenuineIntel", 2, 0, 0, 0, false, "Intel 80286"},//amd/harris/siemens/fujitsu/kruger + + + /** Intel 386 ***********************************************************************************/ + + + //The 386 use a very different format: Family (8-bits!) + Revision (8-bits! Model+Stepping) + //Not to myself: The high four bits of the family should coume in the extra field + //These chips were also munufactured by AMD!!! They are affected by the POPAD bug???? + //Old (sigma-pi) i386 have 32-bit multipy bug + //C&T 38600DX do not have POPAD bug. IBM 386SLC unknwon + //AMD 386DX & DXL hav Intel microcode + //AMD 386DXLV & SXLV hav UMOV??? + //Nx586 has no AC has 386 instr set + + //Erly modles (A stepping) as Famuly: 0, Revision: ??? (In Intel Docs! Support the 'Bit Instrucs') + //0300 + // * Intel i386DX : F0 + {"GenuineIntel", 3, 0, 3, 0, false, "Intel i386DX (B0/B1/B2/B3/B4/B5/B6/B7/B8/B9/B10)"}, + {"GenuineIntel", 3, 0, 4, 0, false, "Intel i386DX (C???)"}, // Stepping not confiremed + {"GenuineIntel", 3, 0, 5, 0, false, "Intel i386DX (D0)"}, + {"GenuineIntel", 3, 0, 8, 0, false, "Intel i386DX (D1/D2/E0/E1/F0)"}, //E0/E1/F0 coulld also be 9!!! + + //The family 23 could also simply be 3 (I don't know were the 2 stands for???) Officialy not part + //Difference between DX and SX perhaps (I hope so) + // * Intel i386CX/SXSA : A2 / B + // * Intel i386EX : A0 / B1 / B2 + {"GenuineIntel",23, 0, 4, 0, false, "Intel i386SX (A0)"}, + {"GenuineIntel",23, 0, 5, 0, false, "Intel i386SX (B)"}, + {"GenuineIntel",23, 0, 8, 0, false, "Intel i386SX (C/D/E)"}, + {"GenuineIntel",23, 0, 8, 0, false, "Intel i386CXSA/B (A) / i386EX (A) / i386SXSA (?)"}, //A || B + {"GenuineIntel",23, 0, 9, 0, false, "Intel i386SX (?)"}, //EMBEDDED (CX/FX + {"GenuineIntel",23, 0, 9, 0, false, "Intel i386EX (A0/B1/C1)"}, + + //Dito for 33 (376 perhaps) + {"GenuineIntel",33, 0, 5, 0, false, "Intel i376 (A0)"}, //Never used in PC because they only work in PM + {"GenuineIntel",33, 0, 8, 0, false, "Intel i376 (B)"}, //... + + //And againt for 43 (386SL) + //have a signatur register @ 30e + //step level A0: 0x4300, + //step level A1: 0x4300, + //step level A2: 0x4301, + //step level A3: 0x4302, + //step level B0: 0x4310, + //step level B1: 0x4311. +// {"GenuineIntel",43, 0, 5, ?, false, "Intel i386SL (B)"}, +// {"GenuineIntel",43, 0, 5, ?, false, "Intel i386SL (A0/A1/A2/A3)"}, //Not sure about this +// {"GenuineIntel",43, 1, 0, 0, false, "Intel i386SL (A0/A1/A2/A3)"}, +// {"GenuineIntel",43, 1, 1, 0, false, "Intel i386SL (B0/B1)"}, + + //RapidCADs are not so familiar to me, where they ever used in PCs??? + {"GenuineIntel", 3, 4, 0, 0, false, "Intel RapidCAD (A)"}, + {"GenuineIntel", 3, 4, 1, 0, false, "Intel RapidCAD (B)"}, + + + /** Intel 486 ***********************************************************************************/ + + //According to Intel only SL Enhanced and WB Enhanced processors support CPUID + + {"GenuineIntel", 4, 0, 0, 0, false, "Intel i486DX (A0/A1)"}, + {"GenuineIntel", 4, 0, 1, 0, false, "Intel i486DX (B2/B3/B4/B5/B6)"}, + {"GenuineIntel", 4, 0, 2, 0, false, "Intel i486DX (C0)"}, + {"GenuineIntel", 4, 0, 3, 0, false, "Intel i486DX (C1)"}, + {"GenuineIntel", 4, 0, 4, 0, false, "Intel i486DX (D0)"}, +// {"GenuineIntel", 4, 0, ?, 0, false, "Intel i486DX"}, + + {"GenuineIntel", 4, 1, 0, 0, false, "Intel i486DX (cA2/cA3)"}, + {"GenuineIntel", 4, 1, 1, 0, false, "Intel i486DX (cB0/cB1)"}, + {"GenuineIntel", 4, 1, 3, 0, false, "Intel i486DX (cC0)"}, + {"GenuineIntel", 4, 1, 4, 0, false, "Intel i486DX (aA0/aA1)"}, //SL Enhanced + {"GenuineIntel", 4, 1, 5, 0, false, "Intel i486DX (aB0)"}, //SL Enhanced +// {"GenuineIntel", 4, 1, ?, 0, false, "Intel i486DX"}, + + {"GenuineIntel", 4, 2, 0, 0, false, "Intel i486SX / i487SX (A0)"}, //Should 487 be model 3 + {"GenuineIntel", 4, 2, 1, 0, false, "Intel i487SX (B0)"}, //Should 487 be model 3 + {"GenuineIntel", 4, 2, 2, 0, false, "Intel i486SX (B0)"}, + {"GenuineIntel", 4, 2, 3, 0, false, "Intel i486SX (bBx)"}, //SL Enhanced and... CPUID + {"GenuineIntel", 4, 2, 4, 0, false, "Intel i486SX (gAx)"}, + {"GenuineIntel", 4, 2, 7, 0, false, "Intel i486SX (cA0)"}, + {"GenuineIntel", 4, 2, 8, 0, false, "Intel i486SX (cB0)"}, + {"GenuineIntel", 4, 2, 0xA, 0, false, "Intel i486SX (aA0/aA1)"}, //SL Enhanced + {"GenuineIntel", 4, 2, 0xB, 0, false, "Intel i486SX (aB0/aC0)"}, //SL Enhanced + {"GenuineIntel", 4, 2, 0xE, 0, false, "Intel i486SX (E)"}, //SL Enhanced??? Grzegorz +// {"GenuineIntel", 4, 2, ?, 0, false, "Intel i486SX"}, + +// {"GenuineIntel", 4, 3, ?, 0, false, "Intel i486DX2 / i486DX2 OverDrive / i487"}, + {"GenuineIntel", 4, 3, 2, 0, false, "Intel i486DX2 (A0/A1/A2)"}, + {"GenuineIntel", 4, 3, 3, 0, false, "Intel i486DX2 (B1)"}, + {"GenuineIntel", 4, 3, 4, 0, false, "Intel i486DX2 (aA0/aA1)"}, //SL Enhanced + {"GenuineIntel", 4, 3, 5, 0, false, "Intel i486DX2 (aB0/aC0)"}, //SL Enhanced + {"GenuineIntel", 4, 3, 6, 0, false, "Intel i486DX2"}, //Possibly as WB in WT Mode + + {"GenuineIntel", 4, 4, 0, 0, false, "Intel i486SL (A)"}, + {"GenuineIntel", 4, 4, 1, 0, false, "Intel i486SL (?)"}, + {"GenuineIntel", 4, 4, 3, 0, false, "Intel i486SL (?)"}, //In Intel Docs, saupoosed to support CPUID +// {"GenuineIntel", 4, 4, ?, 0, false, "Intel i486SL"}, + +// {"GenuineIntel", 4, 5, ?, 0, false, "Intel i486SX2"}, + {"GenuineIntel", 4, 5, 0xB, 0, false, "Intel i486SX2 (aC0)"}, //SL Enhanced + + {"GenuineIntel", 4, 7, 0, 0, false, "Intel i486DX2-WB (A)"}, + {"GenuineIntel", 4, 7, 3, 0, false, "Intel i486DX2-WB (?)"}, //In Intel Docs, saupoosed to support CPUID +// {"GenuineIntel", 4, 7, ?, 0, false, "Intel i486DX2-WB"}, + + {"GenuineIntel", 4, 8, 0, 0, false, "Intel i486DX4 (A)"}, + {"GenuineIntel", 4, 8, 0, 1, false, "Intel i486DX4 OverDrive (A)"}, + {"GenuineIntel", 4, 8, 3, 0, false, "Intel i486DX4 (A)"}, //Possibly as WB in WT Mode, Support CPUID +// {"GenuineIntel", 4, 8, ?, 0, false, "Intel i486DX4 / i486DX4 OverDrive"}, + + {"GenuineIntel", 4, 9, 0, 0, false, "Intel i486DX4-WB (A)"}, //(Do not exist according to Intel CPUID Inf) +// {"GenuineIntel", 4, 9, ?, 0, false, "Intel i486DX4-WB"}, + + + /** AMD *****************************************************************************************/ + + {"AuthenticAMD", 4, 1, 2, 0, false, "AMD 486DX"}, + {"AuthenticAMD", 4, 3, 2, 0, false, "AMD 486DX/2"}, //DX4 (WT2x) toooo && DXL2 / DX4NV8T + {"AuthenticAMD", 4, 3, 4, 0, false, "AMD 486DX/2"}, //DX4 (WT2x) toooo && DXL2 / DX4SV8B +// {"AuthenticAMD", 4, 7, ?, 0, false, "AMD 486DX/2-WB"}, //DX4 (WB2x) + {"AuthenticAMD", 4, 7, 4, 0, false, "AMD SV8B (WT)"}, +// {"AuthenticAMD", 4, 8, ?, 0, false, "AMD 486DX/4"}, //5x86 toooo + {"AuthenticAMD", 4, 8, 4, 0, false, "AMD 486DX/4"}, //3xWT + {"AuthenticAMD", 4, 9, 4, 0, false, "AMD 486DX/4-WB"}, //3xWB + {"AuthenticAMD", 4, 0xE, 4, 0, false, "AMD Am5x86-WT"}, //AMD Enhanced 486 + {"AuthenticAMD", 4, 0xF, 4, 0, false, "AMD Am5x86-WB (4)"}, //AMD Enhanced 486 + + //cores: 5.0 / 5.0 (MMX) / 5.1 / 5.2 + {"AuthenticAMD", 5, 0, 0, 0, false, "AMD K5 SSA/5 (E)"}, //??? Stepping Name + {"AuthenticAMD", 5, 0, 1, 0, false, "AMD K5 SSA/5 (F)"}, //??? Stepping Name +// {"AuthenticAMD", 5, 0, ?, 0, false, "AMD K5 SSA/5 (?)"}, //??? Stepping Name +// {"AuthenticAMD", 5, 1, ?, 0, false, "AMD K5 5k86 Model 1 (?)"}, //??? Stepping Name + {"AuthenticAMD", 5, 1, 1, 0, false, "AMD K5 5k86 Model 1 (?)"}, //??? Stepping Name + {"AuthenticAMD", 5, 1, 2, 0, false, "AMD K5 5k86 Model 1 (?)"}, //??? Stepping Name + {"AuthenticAMD", 5, 1, 4, 0, false, "AMD K5 5k86 Model 1 (?)"}, //CLKMUL=1.5 +// {"AuthenticAMD", 5, 2, ?, 0, false, "AMD K5 5k86 Model 1 (?)"}, //??? Stepping Name + {"AuthenticAMD", 5, 2, 4, 0, false, "AMD K5 5k86 Model 2 (?)"}, //CLKMUL=1.75 +// {"AuthenticAMD", 5, 3, ?, 0, false, "AMD K5 5k86 Model 3 (?)"}, //??? Stepping Name (NOT RELEASED) + {"AuthenticAMD", 5, 3, 4, 0, false, "AMD K5 5k86 Model 1 (?)"}, //CLKMUL=2.0 + + + //Missing: MobileS (= k6-7!!!) / K6-2+ n/ K6-III+ + {"AuthenticAMD", 5, 6, 1, 0, false, "AMD-K6 Model 6 (B)"}, + {"AuthenticAMD", 5, 6, 2, 0, false, "AMD-K6 Model 6 (C)"}, + {"AuthenticAMD", 5, 7, 0, 0, false, "AMD-K6 Model 7 'Little Foot' (A)"}, + {"AuthenticAMD", 5, 8, 0, 0, false, "AMD-K6-2 Model 8 'Chomper' (A0)"}, //doesnt CXT stnd fr Chomber XT +// {"AuthenticAMD", 5, 8, 8, 0, false, "AMD-K6-2 Model 8 'Chomper' (AC)"}, //In Recognition < CXT + {"AuthenticAMD", 5, 8, 0xC, 0, false, "AMD-K6-2 Model 8 'Chomper' (AC)"}, //CXT Core (Write COmbining) I believe YES!!! avvording to Chase + {"AuthenticAMD", 5, 9, 1, 0, false, "AMD-K6-III 'Sharptooth' Model 9 (B)"}, +// {"AuthenticAMD", 5, 0xD, ?, 0, false, "AMD-K6-2+ / K6-III+ 'Sharptooth' (?)"}, //Not doced by AMD (3DNow!+) + +//* {"AuthenticAMD", 6, 0, ?, 0, "AMD K7 [ES]"}, //UNDOCUMENTED!?! + + + /* Cyrix **************************************************************************************/ + + //My sources are unreliable at best for these suckers, so I list them all + //Also I belive the names aren't entire ly correct, confused codename/ actualt name and extensions + + {"CyrixInstead", 0, 0, 5, 0, false, "Cyrix M5 Cx486S/D"}, //No CPUID I believe (is family correct?) + {"CyrixInstead", 0, 0, 6, 0, false, "Cyrix M6 Cx486DX"}, //... + {"CyrixInstead", 0, 0, 7, 0, false, "Cyrix M7 Cx486DX2"}, //... + {"CyrixInstead", 0, 0, 8, 0, false, "Cyrix M8 Cx486DX4"}, + //... + + {"CyrixInstead", 4, 1, 0, 0, false, "Cyrix 4x86SLC"}, +// {"CyrixInstead", 4, 2, ?, 0, false, "Cyrix 5x86"}, + {"CyrixInstead", 4, 2, 9, 0, false, "Cyrix 5x86 (Rev 1-)"}, //Bus *2 + {"CyrixInstead", 4, 2, 0xB, 0, false, "Cyrix 5x86 (Rev 1-)"}, //Bus *2 + {"CyrixInstead", 4, 2, 0xD, 0, false, "Cyrix 5x86 (Rev 1-)"}, //Bus *3 + {"CyrixInstead", 4, 2, 0xF, 0, false, "Cyrix 5x86 (Rev 1-)"}, //Bus *3 +// {"CyrixInstead", 4, 4, ?, 0, false, "Cyrix MediaGX"}, + {"CyrixInstead", 4, 9, 0, 0, false, "Cyrix 5x86 (Rev 2+)"}, +// {"CyrixInstead", 4, 9, ?, 0, false, "Cyrix 5x86"}, + + +// IBM ID=15h Top (65 KB JPG) and Bottom (104 KB JPG) +// IBM ID=17h Top (71 KB JPG) and Bottom (110 KB JPG) +// Cyrix ID=17h Top (63 KB JPG) and Bottom (102 KB JPG) +// IBM ID=22h Top (82 KB JPG) and Bottom (99 KB JPG) +// {"CyrixInstead", 5, 0, ?, 0, false, "Cyrix M1 (6x86)"}, //Grzegorz + {"CyrixInstead", 5, 2, 0, 0, false, "Cyrix M1 (6x86)"}, //Early Models (L / non-L versions???? (LV too)) +// {"CyrixInstead", 5, 2, ?, 0, false, "Cyrix M1 (6x86)"}, //Early Models (L / non-L versions???? (LV too)) + {"CyrixInstead", 5, 3, 0, 0, false, "Cyrix M1 (6x86)"}, //1.0x Bus Ratio + {"CyrixInstead", 5, 3, 1, 0, false, "Cyrix M1 (6x86)"}, //2.0x Bus Ratio + {"CyrixInstead", 5, 3, 2, 0, false, "Cyrix M1 (6x86)"}, //1.0x Bus Ratio + {"CyrixInstead", 5, 3, 3, 0, false, "Cyrix M1 (6x86)"}, //2.0x Bus Ratio + {"CyrixInstead", 5, 3, 4, 0, false, "Cyrix M1 (6x86)"}, //3.0x Bus Ratio + {"CyrixInstead", 5, 3, 5, 0, false, "Cyrix M1 (6x86)"}, //4.0x Bus Ratio + {"CyrixInstead", 5, 3, 6, 0, false, "Cyrix M1 (6x86)"}, //3.0x Bus Ratio + {"CyrixInstead", 5, 3, 7, 0, false, "Cyrix M1 (6x86)"}, //4.0x Bus Ratio +// {"CyrixInstead", 5, 4, ?, 0, false, "Cyrix MediaGX MMX"}, + + +// ID=02h Top (73 KB JPG) and Bottom (100 KB JPG) +// ID=04h Top (79 KB JPG) and Bottom (106 KB JPG) +// ID=08h Top (66 KB JPG) and Bottom (101 KB JPG) +// ID=53 07 + {"CyrixInstead", 6, 0, 0, 0, false, "Cyrix MII (6x86MX)"}, +// {"CyrixInstead", 6, 0, ?, 0, "Cyrix MII (6x86MX)"}, + + //These guys are actualy a Cyrix M2 with minor enhancemets (3DNow! / better FPU), but who cares, + //they were never taken into procuvtion. Although VIA C3 probalby stands for Cyrix M3 and not, + //Centaur WinChip 3. THey got a WinChip 4 core. Josua was nOT released! Start with samual and Samual 2 then Ezra and Ezra-T + // {"CyrixInstead", 6, 5, 1, 0, false, "VIA Cyrix III 'Joshua'"}, //2.0x Bus Ratio + + //Other names heard: Cyrix M-III 'Mojave' (Chase, so reliable never produced!) + // Cayenne / Gobi / Jalapeno + // Cayenne, then Gobi, then Joshua + + //THE VIA Series!!!!! + //New models : C4 'Nehemia' Has SSE instead of #dnOW! newer modles will be Esther + // CZA is a P4 clone + + /************************************************************************************************/ + + + + + +// I'm not sure about the CNs +// {"RiseRiseRise", 5, 0, ?, 0, "Rise mP6 iDragon '6401?' (Model 0)"}, //0.25 +// {"RiseRiseRise", 5, 0, 4, 0, "Rise mP6 iDragon '6401?' (Model 0)"}, //0.25 +// {"RiseRiseRise", 5, 1, ?, 0, "Rise mP6 iDragon 'Kirin?' (Model 1)"}, +// {"RiseRiseRise", 5, 2, ?, 0, "Rise mP6 iDragon 'Lynx?' (Model 2)"}, //0.18 +// {"RiseRiseRise", 5, 8, ?, 0, "Rise mP6 iDragon II"}, +// {"RiseRiseRise", 5, 9, ?, 0, "Rise mP6 iDragon II"}, +// Rise Tiger = MMX+SSE Unknown Nmae + + +#endif /* 0 */ + +typedef struct __CPU___PROCINFORMATION__ +{ + bool pCertified; + char *pName; + + uint32_t vFamily; + uint32_t vModel; + uint32_t vStepping; + uint32_t vType; + uint32_t vBrand; + char vVendor[13]; + char *vName; + + bool iFloatingPoint; + bool iTranscedental; + bool iCompareExchange64; + bool iConditionalMove; + bool iCLFLUSH; + bool iMMX; + bool iSSE; + bool iSSE2; + bool iSSE3; + bool iMonitor; + bool iFastSystemCall; + bool iFXSR; + bool fVirtualModeExtensions; + bool fDebuggingExtensions; + bool fPageSizeExtensions; + bool fTimeStampCounter; + bool fModelSpecificRegisters; + bool fPhysicalAddressExtension; + bool fMachineCheckException; + bool fLocalAPIC; + bool fMemoryTypeRangeRegisters; + bool fPageGlobalEnable; + bool fMachineCheckArchitecture; + bool fPageAttributeTable; + bool fPageSizeExtension; + bool fProcessorSerialNumber; + bool fDebugStore; + bool fACPI; + bool fSelfSnoop; + bool fHyperThreading; + bool fThermalMonitor; + bool fIA64; + bool fSignalBreakOnFERR; + bool fQualifiedDebugStore; + bool fThermalMonitor2; + bool fContextID; + + uint32_t cLineSize; + uint32_t cL1CodeCacheSize; + uint32_t cL1CodeCacheAssociativity; + uint32_t cL1CodeCacheLineSize; + uint32_t cL1CodeCacheLinesPerTag; + uint32_t cL1DataCacheSize; + uint32_t cL1DataCacheAssociativity; + uint32_t cL1DataCacheLineSize; + uint32_t cL1DataCacheLinesPerTag; + uint32_t cL1UnifiedCacheSize; + uint32_t cL1UnifiedCacheAssociativity; + uint32_t cL1UnifiedCacheLineSize; + uint32_t cL1UnifiedCacheLinesPerTag; + uint32_t cL1CodeTLB4KEntries; + uint32_t cL1CodeTLB2MEntries; + uint32_t cL1DataTLB2MEntries; + uint32_t cL1CodeTLB4MEntries; + uint32_t cL1DataTLB4KEntries; + uint32_t cL1DataTLB4MEntries; + uint32_t cL2UnifiedCacheSize; + uint32_t cL2UnifiedCacheAssociativity; + uint32_t cL2UnifiedCacheLineSize; + uint32_t cL2UnifiedCacheLinesPerTag; + uint32_t cL2CodeTLB4KEntries; + uint32_t cL2CodeTLB2MEntries; + uint32_t cL2CodeTLB4MEntries; + uint32_t cL2DataTLB4KEntries; + uint32_t cL2DataTLB2MEntries; + uint32_t cL2DataTLB4MEntries; + uint32_t cL2UnifiedTLB4KEntries; + uint32_t cL2UnifiedTLB2MEntries; + uint32_t cL2UnifiedTLB4MEntries; + uint32_t cL3UnifiedCacheSize; + uint32_t cL3UnifiedCacheAssociativity; + uint32_t cL3UnifiedCacheLineSize; + uint32_t cL3UnifiedCacheLinesPerTag; + + int32_t cL1CodeTLB4KAssociativity; + int32_t cL1CodeTLB2MAssociativity; + int32_t cL1CodeTLB4MAssociativity; + int32_t cL1DataTLB4KAssociativity; + int32_t cL1DataTLB2MAssocitivity; + int32_t cL1DataTLB4MAssociativity; + int32_t cL2CodeTLB4KAssociativity; + int32_t cL2CodeTLB2MAssociativity; + int32_t cL2CodeTLB4MAssociativity; + int32_t cL2DataTLB4KAssociativity; + int32_t cL2DataTLB2MAssociativity; + int32_t cL2DataTLB4MAssociativity; + int32_t cL2UnifiedTLB4KAssociativity; + int32_t cL2UnifiedTLB2MAssociativity; + int32_t cL2UnifiedTLB4MAssociativity; + + bool cTraceCachePresent; + + uint32_t cTraceCacheMicroOps; + uint32_t cTraceCacheAssociativity; + uint32_t uOnChipFPU; + uint32_t uLogicalProcessorCount; + uint32_t uAPICID; + + bool rFeature10; + bool rFeature20; + bool rFeature33; + bool rFeature34; + bool rFeature37; + bool rFeature38; + bool rFeature39; + bool rFeature41; + bool rFeature42; + bool rFeature43; + bool rFeature44; + bool rFeature45; + bool rFeature46; + bool rFeature47; + bool rFeature48; + bool rFeature49; + bool rFeature50; + bool rFeature51; + bool rFeature52; + bool rFeature53; + bool rFeature54; + bool rFeature55; + bool rFeature56; + bool rFeature57; + bool rFeature58; + bool rFeature59; + bool rFeature60; + bool rFeature61; + bool rFeature62; + bool rFeature63; + +} prcInformation; + +void prcInit(void); +void prcIdentify(uint64_t processor, prcInformation* information); +void prcCPUID(uint64_t processor, uint32_t function, uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d); +void IdentifyIntelCache(prcInformation* information, int descriptor); +void IdentifyProcessor(prcInformation* information, int Extra); + +typedef union __CPU___PROCINFORMATIONDATA__ +{ + unsigned int d; + unsigned short w[2]; + unsigned char b[4]; +} prcIdentificationData; + +void printf(const char *fmt, ...); + +void init_cpu(void) +{ + prcInformation information; + prcIdentify(0, &information); + //logStatus(logSuccess); + //logSubItem("Processor #0", information.pName); + //logSubItem("MMX", information.iMMX ? "Yes" : "No"); + printf("Proccessor: %s MMX %s", information.pName, information.iMMX ? "Yes" : "No"); +} + +void prcIdentify(uint64_t processor, prcInformation* information) +{ + uint32_t a, b, c, d; + uint32_t highestStandard, highestExtended; + int i, n, Extra; + + /*** 0x00000000 - Vendor **********************/ + prcCPUID(processor, 0x00000000, &a, &b, &c, &d); + + highestStandard = a; + + *((uint32_t*)(information->vVendor + 0)) = b; + *((uint32_t*)(information->vVendor + 4)) = d; + *((uint32_t*)(information->vVendor + 8)) = c; + information->vVendor[12] = '\0'; + + + /*** 0x00000001 - Version and Features ********/ + prcCPUID(processor, 0x00000001, &a, &b, &c, &d); + + information->vStepping = (a & 0x0000000F) >> 0; + information->vModel = (a & 0x000000F0) >> 4; + information->vFamily = (a & 0x00000F00) >> 8; + information->vType = (a & 0x00003000) >> 12; + + if(information->vModel == 0xF) information->vModel += (a & 0x000F0000) >> 16; + if(information->vFamily == 0xF) information->vFamily += (a & 0x0FF00000) >> 20; + + information->uOnChipFPU = (d >> 0) & 0x00000001; + information->fVirtualModeExtensions = (d >> 1) & 0x00000001; + information->fDebuggingExtensions = (d >> 2) & 0x00000001; + information->fPageSizeExtension = (d >> 3) & 0x00000001; + information->fTimeStampCounter = (d >> 4) & 0x00000001; + information->fModelSpecificRegisters = (d >> 5) & 0x00000001; + information->fPhysicalAddressExtension = (d >> 6) & 0x00000001; + information->fMachineCheckException = (d >> 7) & 0x00000001; + information->iCompareExchange64 = (d >> 8) & 0x00000001; + information->fLocalAPIC = (d >> 9) & 0x00000001; + information->rFeature10 = (d >> 10) & 0x00000001; + information->iFastSystemCall = (d >> 11) & 0x00000001; + information->fMemoryTypeRangeRegisters = (d >> 12) & 0x00000001; + information->fPageGlobalEnable = (d >> 13) & 0x00000001; + information->fMachineCheckArchitecture = (d >> 14) & 0x00000001; + information->iConditionalMove = (d >> 15) & 0x00000001; + information->fPageAttributeTable = (d >> 16) & 0x00000001; + information->fPageSizeExtension = (d >> 17) & 0x00000001; + information->fProcessorSerialNumber = (d >> 18) & 0x00000001; + information->iCLFLUSH = (d >> 19) & 0x00000001; + information->rFeature20 = (d >> 20) & 0x00000001; + information->fDebugStore = (d >> 21) & 0x00000001; + information->fACPI = (d >> 22) & 0x00000001; + information->iMMX = (d >> 23) & 0x00000001; + information->iFXSR = (d >> 24) & 0x00000001; + information->iSSE = (d >> 25) & 0x00000001; + information->iSSE2 = (d >> 26) & 0x00000001; + information->fSelfSnoop = (d >> 27) & 0x00000001; + information->fHyperThreading = (d >> 28) & 0x00000001; + information->fThermalMonitor = (d >> 29) & 0x00000001; + information->fIA64 = (d >> 30) & 0x00000001; + information->fSignalBreakOnFERR = (d >> 31) & 0x00000001; + + information->iSSE3 = (c >> 0) & 0x00000001; + information->rFeature33 = (c >> 1) & 0x00000001; + information->rFeature34 = (c >> 2) & 0x00000001; + information->iMonitor = (c >> 3) & 0x00000001; + information->fQualifiedDebugStore = (c >> 4) & 0x00000001; + information->rFeature37 = (c >> 5) & 0x00000001; + information->rFeature38 = (c >> 6) & 0x00000001; + information->rFeature39 = (c >> 7) & 0x00000001; + information->fThermalMonitor2 = (c >> 8) & 0x00000001; + information->rFeature41 = (c >> 9) & 0x00000001; + information->fContextID = (c >> 10) & 0x00000001; + information->rFeature43 = (c >> 11) & 0x00000001; + information->rFeature44 = (c >> 12) & 0x00000001; + information->rFeature45 = (c >> 13) & 0x00000001; + information->rFeature46 = (c >> 14) & 0x00000001; + information->rFeature47 = (c >> 15) & 0x00000001; + information->rFeature48 = (c >> 16) & 0x00000001; + information->rFeature49 = (c >> 17) & 0x00000001; + information->rFeature50 = (c >> 18) & 0x00000001; + information->rFeature51 = (c >> 19) & 0x00000001; + information->rFeature52 = (c >> 20) & 0x00000001; + information->rFeature53 = (c >> 21) & 0x00000001; + information->rFeature54 = (c >> 22) & 0x00000001; + information->rFeature55 = (c >> 23) & 0x00000001; + information->rFeature56 = (c >> 24) & 0x00000001; + information->rFeature57 = (c >> 25) & 0x00000001; + information->rFeature58 = (c >> 26) & 0x00000001; + information->rFeature59 = (c >> 27) & 0x00000001; + information->rFeature60 = (c >> 28) & 0x00000001; + information->rFeature61 = (c >> 29) & 0x00000001; + information->rFeature62 = (c >> 30) & 0x00000001; + information->rFeature63 = (c >> 31) & 0x00000001; + + information->vBrand = (b & 0x000000FF) >> 0; + if(information->iCLFLUSH) + information->cLineSize = (b & 0x0000FF00) >> 8; + if(information->fHyperThreading) + information->uLogicalProcessorCount = (b & 0x00FF0000) >> 16; + if(information->vFamily >= 0xF) + information->uAPICID = (b & 0xFF000000) >> 24; + + /*** 0x00000002 - Cache Descriptors ***********/ + n = 1; + + for(i = 0; i < n; i++) + { + prcCPUID(processor, 0x00000002, &a, &b, &c, &d); + + n = a & 0x000000FF; + + if(!(a & 0x80000000)) + { + IdentifyIntelCache(information, (a >> 8) & 0x000000FF); + IdentifyIntelCache(information, (a >> 16) & 0x000000FF); + IdentifyIntelCache(information, (a >> 24) & 0x000000FF); + } + + if(!(b & 0x80000000)) + { + IdentifyIntelCache(information, (b >> 0) & 0x000000FF); + IdentifyIntelCache(information, (b >> 8) & 0x000000FF); + IdentifyIntelCache(information, (b >> 16) & 0x000000FF); + IdentifyIntelCache(information, (b >> 24) & 0x000000FF); + } + + if(!(c & 0x80000000)) + { + IdentifyIntelCache(information, (c >> 0) & 0x000000FF); + IdentifyIntelCache(information, (c >> 8) & 0x000000FF); + IdentifyIntelCache(information, (c >> 16) & 0x000000FF); + IdentifyIntelCache(information, (c >> 24) & 0x000000FF); + } + + if(!(d & 0x80000000)) + { + IdentifyIntelCache(information, (d >> 0) & 0x000000FF); + IdentifyIntelCache(information, (d >> 8) & 0x000000FF); + IdentifyIntelCache(information, (d >> 16) & 0x000000FF); + IdentifyIntelCache(information, (d >> 24) & 0x000000FF); + } + } + + /*** 0x00000003 - Serial Number ***************/ + + /*** 0x00000004 - Cache Parameters ************/ + + /*** 0x00000005 - Monitor *********************/ + + /** + * THE EXTRA NUMBER + * Type + * Pentium II + III Cache + * Pentium III + 4 Brand ID + * Athlon Multi Processing / Cache + */ + + Extra = information->vType; + + if(!strcmp(information->vVendor, "GenuineIntel") + && information->vFamily == 6 + && information->vModel >= 3 + && information->vModel <= 7) + { + Extra = information->cL2UnifiedCacheSize; + } + + if(!strcmp(information->vVendor, "GenuineIntel") + && information->vFamily == 6 + && information->vModel >= 8) + { + Extra = information->vBrand; + } + + if(!strcmp(information->vVendor, "GenuineIntel") + && information->vFamily == 0xF) + { + Extra = information->vBrand; + } + + if(!strcmp(information->vVendor, "AuthenticAMD") + && information->vFamily == 6) + { + Extra = 0; + } + + IdentifyProcessor(information, Extra); +} + +void prcCPUID(uint64_t processor, uint32_t function, uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d) +{ + asm + ( + "cpuid" + : "=a" (*a), "=b" (*b), "=c" (*c), "=d" (*d) + : "a" (function) + ); +} + +void IdentifyIntelCache(prcInformation* information, int descriptor) +{ + switch(descriptor) + { + case 0x00: + return; + case 0x40: + return; + case 0x01: + information->cL1CodeTLB4KEntries = 32; + information->cL1CodeTLB4KAssociativity = 4; + return; + case 0x02: + information->cL1CodeTLB4MEntries = 2; + information->cL1CodeTLB4MAssociativity = -1; + return; + case 0x03: + information->cL1DataTLB4KEntries = 64; + information->cL1DataTLB4KAssociativity = 4; + return; + case 0x04: + information->cL1DataTLB4MEntries = 8; + information->cL1DataTLB4MAssociativity = 4; + return; + case 0x06: + information->cL1CodeCacheSize = 8; + information->cL1CodeCacheAssociativity = 4; + information->cL1CodeCacheLineSize = 32; + information->cL1CodeCacheLinesPerTag = -1; + return; + case 0x08: + information->cL1CodeCacheSize = 16; + information->cL1CodeCacheAssociativity = 4; + information->cL1CodeCacheLineSize = 32; + information->cL1CodeCacheLinesPerTag = -1; + return; + case 0x0A: + information->cL1DataCacheSize = 8; + information->cL1DataCacheAssociativity = 2; + information->cL1DataCacheLineSize = 32; + information->cL1DataCacheLinesPerTag = -1; + return; + case 0x0C: + information->cL1DataCacheSize = 16; + information->cL1DataCacheAssociativity = 4; + information->cL1DataCacheLineSize = 32; + information->cL1DataCacheLinesPerTag = -1; + return; + case 0x22: + information->cL3UnifiedCacheSize = 512; + information->cL3UnifiedCacheAssociativity = 4; + information->cL3UnifiedCacheLineSize = 64; + information->cL3UnifiedCacheLinesPerTag = -1; + return; + case 0x23: + information->cL3UnifiedCacheSize = 1024; + information->cL3UnifiedCacheAssociativity = 8; + information->cL3UnifiedCacheLineSize = 64; + information->cL3UnifiedCacheLinesPerTag = -1; + return; + case 0x25: + information->cL3UnifiedCacheSize = 2048; + information->cL3UnifiedCacheAssociativity = 8; + information->cL3UnifiedCacheLineSize = 64; + information->cL3UnifiedCacheLinesPerTag = -1; + return; + case 0x29: + information->cL3UnifiedCacheSize = 4096; + information->cL3UnifiedCacheAssociativity = 8; + information->cL3UnifiedCacheLineSize = 64; + information->cL3UnifiedCacheLinesPerTag = -1; + return; + case 0x39: + information->cL2UnifiedCacheSize = 128; + information->cL2UnifiedCacheAssociativity = 4; + information->cL2UnifiedCacheLineSize = 64; + information->cL2UnifiedCacheLinesPerTag = -1; + return; + case 0x3B: + information->cL2UnifiedCacheSize = 128; + information->cL2UnifiedCacheAssociativity = 2; + information->cL2UnifiedCacheLineSize = 64; + information->cL2UnifiedCacheLinesPerTag = -1; + return; + case 0x3C: + information->cL2UnifiedCacheSize = 256; + information->cL2UnifiedCacheAssociativity = 4; + information->cL2UnifiedCacheLineSize = 64; + information->cL2UnifiedCacheLinesPerTag = -1; + return; + case 0x41: + information->cL2UnifiedCacheSize = 128; + information->cL2UnifiedCacheAssociativity = 4; + information->cL2UnifiedCacheLineSize = 32; + information->cL2UnifiedCacheLinesPerTag = -1; + return; + case 0x42: + information->cL2UnifiedCacheSize = 256; + information->cL2UnifiedCacheAssociativity = 4; + information->cL2UnifiedCacheLineSize = 32; + information->cL2UnifiedCacheLinesPerTag = -1; + return; + case 0x43: + information->cL2UnifiedCacheSize = 512; + information->cL2UnifiedCacheAssociativity = 4; + information->cL2UnifiedCacheLineSize = 32; + information->cL2UnifiedCacheLinesPerTag = -1; + return; + case 0x44: + information->cL2UnifiedCacheSize = 1024; + information->cL2UnifiedCacheAssociativity = 4; + information->cL2UnifiedCacheLineSize = 32; + information->cL2UnifiedCacheLinesPerTag = -1; + return; + case 0x45: + information->cL2UnifiedCacheSize = 2048; + information->cL2UnifiedCacheAssociativity = 4; + information->cL2UnifiedCacheLineSize = 32; + information->cL2UnifiedCacheLinesPerTag = -1; + return; + case 0x50: + information->cL1CodeTLB4KEntries = 64; + information->cL1CodeTLB4KAssociativity = -1; + information->cL1CodeTLB2MEntries = 64; + information->cL1CodeTLB2MAssociativity = -1; + information->cL1CodeTLB4MEntries = 64; + information->cL1CodeTLB4MAssociativity = -1; + return; + case 0x51: + information->cL1CodeTLB4KEntries = 128; + information->cL1CodeTLB4KAssociativity = -1; + information->cL1CodeTLB2MEntries = 128; + information->cL1CodeTLB2MAssociativity = -1; + information->cL1CodeTLB4MEntries = 128; + information->cL1CodeTLB4MAssociativity = -1; + return; + case 0x52: + information->cL1CodeTLB4KEntries = 256; + information->cL1CodeTLB4KAssociativity = -1; + information->cL1CodeTLB2MEntries = 256; + information->cL1CodeTLB2MAssociativity = -1; + information->cL1CodeTLB4MEntries = 256; + information->cL1CodeTLB4MAssociativity = -1; + return; + case 0x5B: + information->cL1DataTLB4KEntries = 64; + information->cL1DataTLB4KAssociativity = -1; + information->cL1DataTLB4MEntries = 64; + information->cL1DataTLB4MAssociativity = -1; + return; + case 0x5C: + information->cL1DataTLB4KEntries = 128; + information->cL1DataTLB4KAssociativity = -1; + information->cL1DataTLB4MEntries = 128; + information->cL1DataTLB4MAssociativity = -1; + return; + case 0x5D: + information->cL1DataTLB4KEntries = 256; + information->cL1DataTLB4KAssociativity = -1; + information->cL1DataTLB4MEntries = 256; + information->cL1DataTLB4MAssociativity = -1; + return; + case 0x66: + information->cL1DataCacheSize = 8; + information->cL1DataCacheAssociativity = 4; + information->cL1DataCacheLineSize = 64; + information->cL1DataCacheLinesPerTag = -1; + return; + case 0x67: + information->cL1DataCacheSize = 16; + information->cL1DataCacheAssociativity = 4; + information->cL1DataCacheLineSize = 64; + information->cL1DataCacheLinesPerTag = -1; + return; + case 0x68: + information->cL1DataCacheSize = 32; + information->cL1DataCacheAssociativity = 4; + information->cL1DataCacheLineSize = 64; + information->cL1DataCacheLinesPerTag = -1; + return; + case 0x70: + information->cTraceCacheMicroOps = 12; + information->cTraceCacheAssociativity = 8; + return; + case 0x71: + information->cTraceCacheMicroOps = 16; + information->cTraceCacheAssociativity = 8; + return; + case 0x72: + information->cTraceCacheMicroOps = 32; + information->cTraceCacheAssociativity = 8; + return; + case 0x77: + information->cL1CodeCacheSize = 16; + information->cL1CodeCacheAssociativity = 4; + information->cL1CodeCacheLineSize = 64; + information->cL1CodeCacheLinesPerTag = -1; + return; + case 0x79: + information->cL2UnifiedCacheSize = 128; + information->cL2UnifiedCacheAssociativity = 8; + information->cL2UnifiedCacheLineSize = 64; + information->cL2UnifiedCacheLinesPerTag = -1; + return; + case 0x7A: + information->cL2UnifiedCacheSize = 256; + information->cL2UnifiedCacheAssociativity = 8; + information->cL2UnifiedCacheLineSize = 64; + information->cL2UnifiedCacheLinesPerTag = -1; + return; + case 0x7B: + information->cL2UnifiedCacheSize = 512; + information->cL2UnifiedCacheAssociativity = 8; + information->cL2UnifiedCacheLineSize = 64; + information->cL2UnifiedCacheLinesPerTag = -1; + return; + case 0x7C: + information->cL2UnifiedCacheSize = 1024; + information->cL2UnifiedCacheAssociativity = 8; + information->cL2UnifiedCacheLineSize = 64; + information->cL2UnifiedCacheLinesPerTag = -1; + return; + case 0x7E: + information->cL2UnifiedCacheSize = 256; + information->cL2UnifiedCacheAssociativity = 8; + information->cL2UnifiedCacheLineSize = 128; + information->cL2UnifiedCacheLinesPerTag = -1; + return; + case 0x82: + information->cL2UnifiedCacheSize = 128; + information->cL2UnifiedCacheAssociativity = 8; + information->cL2UnifiedCacheLineSize = 32; + information->cL2UnifiedCacheLinesPerTag = -1; + return; + case 0x83: + information->cL2UnifiedCacheSize = 256; + information->cL2UnifiedCacheAssociativity = 8; + information->cL2UnifiedCacheLineSize = 32; + information->cL2UnifiedCacheLinesPerTag = -1; + return; + case 0x84: + information->cL2UnifiedCacheSize = 512; + information->cL2UnifiedCacheAssociativity = 8; + information->cL2UnifiedCacheLineSize = 32; + information->cL2UnifiedCacheLinesPerTag = -1; + return; + case 0x85: + information->cL2UnifiedCacheSize = 1024; + information->cL2UnifiedCacheAssociativity = 8; + information->cL2UnifiedCacheLineSize = 32; + information->cL2UnifiedCacheLinesPerTag = -1; + return; + case 0x8D: + information->cL3UnifiedCacheSize = 3072; + information->cL3UnifiedCacheAssociativity = 12; + information->cL3UnifiedCacheLineSize = 128; + information->cL3UnifiedCacheLinesPerTag = -1; + return; + } + + /*printf("Unknown Intel Cache Descriptor: %x\n", CacheDescriptor);*/ +} + +int AMDAssociativity(int Value) +{ + switch (Value) + { + case 0x00: return 0; + case 0x01: return 1; + case 0x02: return 2; + case 0x04: return 4; + case 0x06: return 8; + case 0x08: return 16; + case 0x0F: return -1; + } + + /*puts("Unknown AMD Cache Descriptor");*/ + return -1; +} + +void IdentifyProcessor(prcInformation* information, int Extra) +{ + int i; + + for(i = 0; i < (sizeof(ProcessorList) / sizeof(PROCLIST)); i++) + { + if(ProcessorList[i].id == 0x02000000 + (information->vFamily << 16) + (information->vModel << 8) + Extra) + { + information->pName = ProcessorList[i].name; + information->pCertified = ProcessorList[i].verified; + return; + } + } + + for(i = 0; i < (sizeof(ProcessorList) / sizeof(PROCLIST)); i++) + { + if(ProcessorList[i].id == 0x020000FF + (information->vFamily << 16) + (information->vModel << 8)) + { + information->pName = ProcessorList[i].name; + information->pCertified = ProcessorList[i].verified; + return; + } + } + + for(i = 0; i < (sizeof(ProcessorList) / sizeof(PROCLIST)); i++) + { + if(ProcessorList[i].id == 0x0200FFFF + (information->vFamily << 16)) + { + information->pName = ProcessorList[i].name; + information->pCertified = ProcessorList[i].verified; + return; + } + } + + for(i = 0; i < (sizeof(ProcessorList) / sizeof(PROCLIST)); i++) + { + if(ProcessorList[i].id == 0x02FFFFFF) + { + information->pName = ProcessorList[i].name; + information->pCertified = ProcessorList[i].verified; + return; + } + } + + information->pName = "Unknown Processor"; + information->pCertified = false; +} diff --git a/Dump/hybos/src/kernel/debug.c b/Dump/hybos/src/kernel/debug.c index c253857..3e74795 100644 --- a/Dump/hybos/src/kernel/debug.c +++ b/Dump/hybos/src/kernel/debug.c @@ -1,54 +1,54 @@ -/*============================================================================ -DEBUG FUNCTIONS - -EXPORTS: -void dump_regs(regs_t *regs); -============================================================================*/ -#include "_krnl.h" - -/* IMPORTS -from MAIN.C */ -void printf(const char *fmt, ...); -/***************************************************************************** -*****************************************************************************/ -#define BPERL 16 /* byte/line for dump */ - -void dump(unsigned char *data, unsigned count) -{ - unsigned char byte1, byte2; - - while(count != 0) - { - for(byte1 = 0; byte1 < BPERL; byte1++) - { - if(count == 0) - break; - printf("%02X ", data[byte1]); - count--; - } - printf("\t"); - for(byte2 = 0; byte2 < byte1; byte2++) - { - if(data[byte2] < ' ') - printf("%c", '.'); - else - printf("%c", data[byte2]); - } - printf("\n"); - data += BPERL; - } -} -/***************************************************************************** -*****************************************************************************/ -void dump_regs(regs_t *regs) -{ - printf("EDI=%08X ESI=%08X EBP=%08X ESP=%08X\n", - regs->edi, regs->esi, regs->ebp, regs->esp); - printf("EBX=%08X EDX=%08X ECX=%08X EAX=%08X\n", - regs->ebx, regs->edx, regs->ecx, regs->eax); - printf(" DS=%08X ES=%08X FS=%08X GS=%08X\n", - regs->ds, regs->es, regs->fs, regs->gs); - printf("int=%08X err=%08X EIP=%08X CS=%08X\n", - regs->which_int, regs->err_code, regs->eip, regs->cs); - printf("uSP=%08X uSS=%08X\n", regs->user_esp, regs->user_ss); -} +/*============================================================================ +DEBUG FUNCTIONS + +EXPORTS: +void dump_regs(regs_t *regs); +============================================================================*/ +#include "_krnl.h" + +/* IMPORTS +from MAIN.C */ +void printf(const char *fmt, ...); +/***************************************************************************** +*****************************************************************************/ +#define BPERL 16 /* byte/line for dump */ + +void dump(unsigned char *data, unsigned count) +{ + unsigned char byte1, byte2; + + while(count != 0) + { + for(byte1 = 0; byte1 < BPERL; byte1++) + { + if(count == 0) + break; + printf("%02X ", data[byte1]); + count--; + } + printf("\t"); + for(byte2 = 0; byte2 < byte1; byte2++) + { + if(data[byte2] < ' ') + printf("%c", '.'); + else + printf("%c", data[byte2]); + } + printf("\n"); + data += BPERL; + } +} +/***************************************************************************** +*****************************************************************************/ +void dump_regs(regs_t *regs) +{ + printf("EDI=%08X ESI=%08X EBP=%08X ESP=%08X\n", + regs->edi, regs->esi, regs->ebp, regs->esp); + printf("EBX=%08X EDX=%08X ECX=%08X EAX=%08X\n", + regs->ebx, regs->edx, regs->ecx, regs->eax); + printf(" DS=%08X ES=%08X FS=%08X GS=%08X\n", + regs->ds, regs->es, regs->fs, regs->gs); + printf("int=%08X err=%08X EIP=%08X CS=%08X\n", + regs->which_int, regs->err_code, regs->eip, regs->cs); + printf("uSP=%08X uSS=%08X\n", regs->user_esp, regs->user_ss); +} diff --git a/Dump/hybos/src/kernel/keyboard.c b/Dump/hybos/src/kernel/keyboard.c index 495f98a..cd03cdf 100644 --- a/Dump/hybos/src/kernel/keyboard.c +++ b/Dump/hybos/src/kernel/keyboard.c @@ -1,585 +1,585 @@ -/** - * keyboard.c - * - * Main keyboard handling routines. - * - * Exports: - * keyboard_irq(); - * init_keyboard(); - * - * Imports: - * video.c console_t _vc[]; - * video.c select_vc(); - * video.c putch(); - * main.c printf(); - * main.c printk(); - */ - -//#include /* key scancode definitions */ -#include -#include /* outportb, inportb(), etc */ -#include -#include /* shell commands */ -#include "_krnl.h" /* MAX_VC */ -#include "bootlog.h" /* klog() */ - -#define KBD_BUF_SIZE 64 - -/** - * Imports - */ -extern console_t _vc[]; -void select_vc(unsigned which_vc); -void putch(unsigned c); -void printf(const char *fmt, ...); -void printk(int type, const char *fmt, ...); -void dumpheapk(void); -void testheap(void); - -unsigned get_current_vc(); - -static int rawkey, keys[128]; -static int numkeysbuffer; - -static char szInBuf[KBD_BUF_SIZE]; - -/** - * 0 if not set - * 1 if make code - * 2 if break code - */ -static int makebreak; - -/** - * reboot() - * - */ -static void reboot(void) -{ - unsigned temp; - - disable(); - - /** - * flush the keyboard controller - */ - do - { - temp = inportb(0x64); - if((temp & 0x01) != 0) - { - (void)inportb(0x60); - continue; - } - } while((temp & 0x02) != 0); - - /** - * now pulse the cpu reset line - */ - outportb(0x64, 0xFE); - - /** - * if that didn't work, just halt - */ - while(1); -} - -/** - * XXX - * - * I'm not even sure if we need the following functions yet, - * however they are here just in case. Leave them alone. - */ - -/** - * _write_kb() - * - */ -static void _write_kb(unsigned adr, unsigned d) -{ - unsigned long t; - unsigned s; - - for(t = 5000000L; t != 0; t--) - { - s = inportb(0x64); - - /** - * loop until 8042 input buffer is empty - */ - if((s & 0x02) == 0) - break; - } - - if(t != 0) - outportb(adr, d); -} - -/** - * _kb_wait() - * - */ -static inline void _kb_wait(void) -{ - int i; - - for(i = 0; i < 0x1000000; i++) - if((inportb(0x64) & 0x02) == 0) - return; - - printk(0, "Keyboard timeout\n"); -} - -/** - * _kb_send() - * - */ -static inline void _kb_send(unsigned char c) -{ - _kb_wait(); - outportb(c, 0x64); -} - -/** - * _translate_sc() - * - * Translates a scancode from the keyboard - */ -unsigned _translate_sc(unsigned k) -{ - unsigned c; - static unsigned altk; - unsigned donefirst = 0; - - if(k == KEY_BKSPACE) - { - if(numkeysbuffer - 1 < 0) - { - numkeysbuffer = 0; - return 0; - } - } - - switch(k) - { - case 0xE0: - altk = 1; c = 0; donefirst = 1; break; - case KEY_TILDA: /* ` or ~ */ - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 126 : 126; break; - case KEY_END: c = 0; if(keys[KEYP_NUMLCK] && altk == 0) c = 49; break; - case KEY_1: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 33 : 49; break; - case KEY_DOWN: c = 0; if(keys[KEYP_NUMLCK] && altk == 0) c = 50; break; - case KEY_2: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 64 : 50; break; - case KEY_PGDOWN: c = 0; if(keys[KEYP_NUMLCK] && altk == 0) c = 51; break; - case KEY_3: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 35 : 51; break; - case KEY_LEFT: c = 0; if(keys[KEYP_NUMLCK] && altk == 0) c = 52; break; - case KEY_4: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 36 : 52; break; - case KEYP_5: c = 0; if(keys[KEYP_NUMLCK] && altk == 0) c = 53; break; - case KEY_5: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 35 : 53; break; - case KEY_RIGHT: c = 0; if(keys[KEYP_NUMLCK] && altk == 0) c = 54; break; - case KEY_6: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 94 : 54; break; - case KEY_HOME: c = 0; if(keys[KEYP_NUMLCK] && altk == 0) c = 55; break; - case KEY_7: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 38 : 55; break; - case KEY_UP: c = 0; if(keys[KEYP_NUMLCK] && altk == 0) c = 56; break; - case KEYP_ASTERISK: c = 42; break; - case KEY_8: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 42 : 56; break; - case KEY_PGUP: c = 0; if(keys[KEYP_NUMLCK] && altk == 0) c = 57; break; - case KEY_9: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 40 : 57; break; - case KEY_INSERT: c = 0; if(keys[KEYP_NUMLCK] && altk == 0) c = 48; break; - case KEY_0: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 41 : 48; break; - case KEYP_MINUS: c = 45; break; - case KEY_MINUS: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 95 : 45; break; - case KEYP_PLUS: c = 43; break; - case KEY_PLUS: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 61 : 43; break; - case KEY_BKSLASH: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 124 : 92; break; - case KEY_Q: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 81 : 113; break; - case KEY_W: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 87 : 119; break; - case KEY_E: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 69 : 101; break; - case KEY_R: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 82 : 114; break; - case KEY_T: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 84 : 116; break; - case KEY_Y: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 89 : 121; break; - case KEY_U: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 85 : 117; break; - case KEY_I: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 73 : 105; break; - case KEY_O: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 79 : 111; break; - case KEY_P: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 80 : 112; break; - case KEY_LBRACKET: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 123 : 91; break; - case KEY_RBRACKET: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 125 : 93; break; - case KEY_ENTER: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 10 : 10; break; - case KEY_A: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 65 : 97; break; - case KEY_S: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 83 : 115; break; - case KEY_D: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 68 : 100; break; - case KEY_F: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 70 : 102; break; - case KEY_G: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 71 : 103; break; - case KEY_H: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 72 : 104; break; - case KEY_J: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 74 : 106; break; - case KEY_K: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 75 : 107; break; - case KEY_L: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 76 : 108; break; - case KEY_SEMICOLON: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 58 : 59; break; - case KEY_QUOTE: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 34 : 39; break; - case KEY_Z: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 90 : 122; break; - case KEY_X: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 88 : 120; break; - case KEY_C: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 67 : 99; break; - case KEY_V: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 86 : 118; break; - case KEY_B: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 66 : 98; break; - case KEY_N: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 78 : 110; break; - case KEY_M: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 77 : 109; break; - case KEY_COMMA: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 60 : 44; break; - case KEY_DEL: c = 0; if(keys[KEYP_NUMLCK] && altk == 0) c = 46; break; - case KEY_PERIOD: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 62 : 46; break; - case KEY_SLASH: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 63 : 47; break; - case KEY_SPACE: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 32 : 32; break; - case KEY_BKSPACE: c = '\b'; break; /* just for now */ - default: - c = 0; - } - - if(donefirst == 0) - altk = 0; - - if(keys[KEY_CAPS]) - { - if(keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) - { - if(c >= 'A' && c <= 'Z') - c += 32; - } - else - { - if(c >= 'a' && c <= 'z') - c -= 32; - } - } - - /** - * Simple shell for now - */ - if(c != 0 && c != '\n' && c != '\b') - { - if((numkeysbuffer - 1) == KBD_BUF_SIZE) - { - numkeysbuffer = 0; - szInBuf[0] = '\0'; - - szInBuf[numkeysbuffer] = c; - numkeysbuffer++; - } - else - { - szInBuf[numkeysbuffer] = c; - numkeysbuffer++; - } - } - else if(c == '\n') - { - printf("\n"); - /** - * Make it a real string - */ - szInBuf[numkeysbuffer] = '\0'; - - /** - * Process command - */ - processCommand(&szInBuf[0], numkeysbuffer - 1); - - /** - * Clear buffer - */ - numkeysbuffer = 0; - szInBuf[0] = '\0'; - - /** - * Print "line" - */ - printf("$ "); - - c = 0; - } - else if(c == '\b') - { - szInBuf[numkeysbuffer] = '\0'; - numkeysbuffer--; - printf("\b \b"); - - c = 0; - } - - return c; -} - -/** - * handle_meta_key() - * - * I'll pretty this up later - */ -void handle_meta_key(unsigned k) -{ - int i; - k = k; /* to shut gcc up */ - - /** - * Check for the infamous three finger salute - */ - if((keys[KEY_RCTRL] || keys[KEY_LCTRL]) && - (keys[KEY_RALT] || keys[KEY_LALT]) && - keys[KEY_DEL]) - { - /** - * FIXME - * - * This should call _send_signal() - */ - reboot(); - } - - /** - * Check for Alt + F1-F12 for virtual terminals - */ - for(i = 0; i < 10; i++) - { - if((keys[KEY_LALT] || keys[KEY_RALT]) && keys[i + KEY_F1]) - { - select_vc(i); - return; - } - } - - if((keys[KEY_LALT] || keys[KEY_RALT]) && keys[KEY_F11]) - { - select_vc(10); - return; - } - - if((keys[KEY_LALT] || keys[KEY_RALT]) && keys[KEY_F12]) - { - select_vc(11); - return; - } -} - -/** - * keyboard_irq() - * - * Called when a keyboard interrupt is generated. - */ -void keyboard_irq(void) -{ - register char a; - unsigned c; - unsigned short kbdstat; - - rawkey = inportb(0x60); - outportb(0x61, (a=inportb(0x61)|0x82)); - outportb(0x61, a & 0x7F); - - /** - * If it's less than 0x80 then it's definatelly - * a make code or a repeat code - */ - if(rawkey < 0x80) - { - /** - * We don't want to gunk up the numlock key - * because we will define it's state in the - * break code a bit later - */ - if((rawkey != KEYP_NUMLCK) && (rawkey != KEY_SCRLCK) && (rawkey != KEY_CAPS)) - keys[rawkey] = 1; - - keyDown(rawkey); - } - else /* rawkey >= 0x80 */ - { - if(rawkey == 0xE0) - { - /** - * It's either a make code, break code, or repeat code - */ - rawkey = inportb(0x60); - outportb(0x61, (a=inportb(0x61)|0x82)); - outportb(0x61, a & 0x7F); - - if(rawkey < 0x80) - { - /** - * Ok, it's a make code or repeat code for the numeric - * keypad (gray keys) - */ - - keys[rawkey] = 1; - - keyDown(rawkey); - } - else /* rawkey >= 0x80 */ - { - /** - * It's either a make code for the numeric keypad or - * a break code for the numeric keypad. - */ - if(rawkey == 0x2A) - { - /** - * Ok, we have a make code for the numeric keypad - * and NUMLOCK is on. The second byte is what we - * want since what we have so far is this: - * - * 0xE0 0x2A - */ - rawkey = inportb(0x60); - outportb(0x61, (a=inportb(0x61)|0x82)); - outportb(0x61, a & 0x7F); - - rawkey = inportb(0x60); - outportb(0x61, (a=inportb(0x61)|0x82)); - outportb(0x61, a & 0x7F); - - keys[rawkey] = 1; - - keyDown(rawkey); - } - else - { - /** - * It's a break code from the numeric keypad. - */ - keys[rawkey] = 0; - - keyUp(rawkey); - } - } - } - else /* rawkey != 0xE0 */ - { - /** - * It's a break code - * - * Make sure we toggle the numlock, scroll lock, and caps lock key. - */ - if(((rawkey - 0x80) == KEYP_NUMLCK) || - ((rawkey - 0x80) == KEY_SCRLCK) || - ((rawkey - 0x80) == KEY_CAPS)) - { - keys[rawkey - 0x80] = !keys[rawkey - 0x80]; - - kbdstat = 0; - if(keys[KEY_SCRLCK]) - kbdstat |= 1; - if(keys[KEYP_NUMLCK]) - kbdstat |= 2; - if(keys[KEY_CAPS]) - kbdstat |= 4; - - _write_kb(0x60, 0xED); - _write_kb(0x60, kbdstat); - outportb(0x20, 0x20); - - keyUp(rawkey); - return; - } - - keys[rawkey - 0x80] = 0; - - keyUp(rawkey); - } - } - - c = _translate_sc(rawkey); - - if(c != 0) - printf("%c", c); - else - { - /** - * We need to check for meta-key-crap here - */ - handle_meta_key(rawkey); - } - - //enable(); - outportb(0x20, 0x20); -} - -/** - * init_keyboard() - * - */ -void init_keyboard(void) -{ - static unsigned char buffers[KBD_BUF_SIZE * MAX_VC]; - - int i; - - //klog("init", "keyboard %2u buf, %2ub each", K_KLOG_PENDING, &_vc[0]); - for(i = 0; i < MAX_VC; i++) - { - _vc[i].keystrokes.data = buffers + KBD_BUF_SIZE * i; - _vc[i].keystrokes.size = KBD_BUF_SIZE; - } - - for(i = 0; i < 128; i++) - keys[i] = 0; - - makebreak = 0; - //klog(NULL, K_KLOG_SUCCESS, &_vc[0], NULL); - //kprintf("init_kbd: %u buffers, %u bytes each\n", - // MAX_VC, KBD_BUF_SIZE); - - //kprintf("[ Entering Runlevel 0 ].......................................................Ok"); - _vc[0].attrib = 8; - printf("[ "); - _vc[0].attrib = 15; - printf("init: keyboard %2u buf, %2ub each ", MAX_VC, KBD_BUF_SIZE); - _vc[0].attrib = 8; - printf("]..........................................."); - _vc[0].attrib = 2; - printf("Ok"); - _vc[0].attrib = 7; -} +/** + * keyboard.c + * + * Main keyboard handling routines. + * + * Exports: + * keyboard_irq(); + * init_keyboard(); + * + * Imports: + * video.c console_t _vc[]; + * video.c select_vc(); + * video.c putch(); + * main.c printf(); + * main.c printk(); + */ + +//#include /* key scancode definitions */ +#include +#include /* outportb, inportb(), etc */ +#include +#include /* shell commands */ +#include "_krnl.h" /* MAX_VC */ +#include "bootlog.h" /* klog() */ + +#define KBD_BUF_SIZE 64 + +/** + * Imports + */ +extern console_t _vc[]; +void select_vc(unsigned which_vc); +void putch(unsigned c); +void printf(const char *fmt, ...); +void printk(int type, const char *fmt, ...); +void dumpheapk(void); +void testheap(void); + +unsigned get_current_vc(); + +static int rawkey, keys[128]; +static int numkeysbuffer; + +static char szInBuf[KBD_BUF_SIZE]; + +/** + * 0 if not set + * 1 if make code + * 2 if break code + */ +static int makebreak; + +/** + * reboot() + * + */ +static void reboot(void) +{ + unsigned temp; + + disable(); + + /** + * flush the keyboard controller + */ + do + { + temp = inportb(0x64); + if((temp & 0x01) != 0) + { + (void)inportb(0x60); + continue; + } + } while((temp & 0x02) != 0); + + /** + * now pulse the cpu reset line + */ + outportb(0x64, 0xFE); + + /** + * if that didn't work, just halt + */ + while(1); +} + +/** + * XXX + * + * I'm not even sure if we need the following functions yet, + * however they are here just in case. Leave them alone. + */ + +/** + * _write_kb() + * + */ +static void _write_kb(unsigned adr, unsigned d) +{ + unsigned long t; + unsigned s; + + for(t = 5000000L; t != 0; t--) + { + s = inportb(0x64); + + /** + * loop until 8042 input buffer is empty + */ + if((s & 0x02) == 0) + break; + } + + if(t != 0) + outportb(adr, d); +} + +/** + * _kb_wait() + * + */ +static inline void _kb_wait(void) +{ + int i; + + for(i = 0; i < 0x1000000; i++) + if((inportb(0x64) & 0x02) == 0) + return; + + printk(0, "Keyboard timeout\n"); +} + +/** + * _kb_send() + * + */ +static inline void _kb_send(unsigned char c) +{ + _kb_wait(); + outportb(c, 0x64); +} + +/** + * _translate_sc() + * + * Translates a scancode from the keyboard + */ +unsigned _translate_sc(unsigned k) +{ + unsigned c; + static unsigned altk; + unsigned donefirst = 0; + + if(k == KEY_BKSPACE) + { + if(numkeysbuffer - 1 < 0) + { + numkeysbuffer = 0; + return 0; + } + } + + switch(k) + { + case 0xE0: + altk = 1; c = 0; donefirst = 1; break; + case KEY_TILDA: /* ` or ~ */ + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 126 : 126; break; + case KEY_END: c = 0; if(keys[KEYP_NUMLCK] && altk == 0) c = 49; break; + case KEY_1: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 33 : 49; break; + case KEY_DOWN: c = 0; if(keys[KEYP_NUMLCK] && altk == 0) c = 50; break; + case KEY_2: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 64 : 50; break; + case KEY_PGDOWN: c = 0; if(keys[KEYP_NUMLCK] && altk == 0) c = 51; break; + case KEY_3: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 35 : 51; break; + case KEY_LEFT: c = 0; if(keys[KEYP_NUMLCK] && altk == 0) c = 52; break; + case KEY_4: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 36 : 52; break; + case KEYP_5: c = 0; if(keys[KEYP_NUMLCK] && altk == 0) c = 53; break; + case KEY_5: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 35 : 53; break; + case KEY_RIGHT: c = 0; if(keys[KEYP_NUMLCK] && altk == 0) c = 54; break; + case KEY_6: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 94 : 54; break; + case KEY_HOME: c = 0; if(keys[KEYP_NUMLCK] && altk == 0) c = 55; break; + case KEY_7: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 38 : 55; break; + case KEY_UP: c = 0; if(keys[KEYP_NUMLCK] && altk == 0) c = 56; break; + case KEYP_ASTERISK: c = 42; break; + case KEY_8: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 42 : 56; break; + case KEY_PGUP: c = 0; if(keys[KEYP_NUMLCK] && altk == 0) c = 57; break; + case KEY_9: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 40 : 57; break; + case KEY_INSERT: c = 0; if(keys[KEYP_NUMLCK] && altk == 0) c = 48; break; + case KEY_0: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 41 : 48; break; + case KEYP_MINUS: c = 45; break; + case KEY_MINUS: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 95 : 45; break; + case KEYP_PLUS: c = 43; break; + case KEY_PLUS: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 61 : 43; break; + case KEY_BKSLASH: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 124 : 92; break; + case KEY_Q: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 81 : 113; break; + case KEY_W: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 87 : 119; break; + case KEY_E: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 69 : 101; break; + case KEY_R: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 82 : 114; break; + case KEY_T: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 84 : 116; break; + case KEY_Y: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 89 : 121; break; + case KEY_U: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 85 : 117; break; + case KEY_I: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 73 : 105; break; + case KEY_O: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 79 : 111; break; + case KEY_P: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 80 : 112; break; + case KEY_LBRACKET: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 123 : 91; break; + case KEY_RBRACKET: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 125 : 93; break; + case KEY_ENTER: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 10 : 10; break; + case KEY_A: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 65 : 97; break; + case KEY_S: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 83 : 115; break; + case KEY_D: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 68 : 100; break; + case KEY_F: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 70 : 102; break; + case KEY_G: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 71 : 103; break; + case KEY_H: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 72 : 104; break; + case KEY_J: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 74 : 106; break; + case KEY_K: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 75 : 107; break; + case KEY_L: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 76 : 108; break; + case KEY_SEMICOLON: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 58 : 59; break; + case KEY_QUOTE: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 34 : 39; break; + case KEY_Z: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 90 : 122; break; + case KEY_X: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 88 : 120; break; + case KEY_C: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 67 : 99; break; + case KEY_V: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 86 : 118; break; + case KEY_B: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 66 : 98; break; + case KEY_N: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 78 : 110; break; + case KEY_M: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 77 : 109; break; + case KEY_COMMA: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 60 : 44; break; + case KEY_DEL: c = 0; if(keys[KEYP_NUMLCK] && altk == 0) c = 46; break; + case KEY_PERIOD: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 62 : 46; break; + case KEY_SLASH: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 63 : 47; break; + case KEY_SPACE: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 32 : 32; break; + case KEY_BKSPACE: c = '\b'; break; /* just for now */ + default: + c = 0; + } + + if(donefirst == 0) + altk = 0; + + if(keys[KEY_CAPS]) + { + if(keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) + { + if(c >= 'A' && c <= 'Z') + c += 32; + } + else + { + if(c >= 'a' && c <= 'z') + c -= 32; + } + } + + /** + * Simple shell for now + */ + if(c != 0 && c != '\n' && c != '\b') + { + if((numkeysbuffer - 1) == KBD_BUF_SIZE) + { + numkeysbuffer = 0; + szInBuf[0] = '\0'; + + szInBuf[numkeysbuffer] = c; + numkeysbuffer++; + } + else + { + szInBuf[numkeysbuffer] = c; + numkeysbuffer++; + } + } + else if(c == '\n') + { + printf("\n"); + /** + * Make it a real string + */ + szInBuf[numkeysbuffer] = '\0'; + + /** + * Process command + */ + processCommand(&szInBuf[0], numkeysbuffer - 1); + + /** + * Clear buffer + */ + numkeysbuffer = 0; + szInBuf[0] = '\0'; + + /** + * Print "line" + */ + printf("$ "); + + c = 0; + } + else if(c == '\b') + { + szInBuf[numkeysbuffer] = '\0'; + numkeysbuffer--; + printf("\b \b"); + + c = 0; + } + + return c; +} + +/** + * handle_meta_key() + * + * I'll pretty this up later + */ +void handle_meta_key(unsigned k) +{ + int i; + k = k; /* to shut gcc up */ + + /** + * Check for the infamous three finger salute + */ + if((keys[KEY_RCTRL] || keys[KEY_LCTRL]) && + (keys[KEY_RALT] || keys[KEY_LALT]) && + keys[KEY_DEL]) + { + /** + * FIXME + * + * This should call _send_signal() + */ + reboot(); + } + + /** + * Check for Alt + F1-F12 for virtual terminals + */ + for(i = 0; i < 10; i++) + { + if((keys[KEY_LALT] || keys[KEY_RALT]) && keys[i + KEY_F1]) + { + select_vc(i); + return; + } + } + + if((keys[KEY_LALT] || keys[KEY_RALT]) && keys[KEY_F11]) + { + select_vc(10); + return; + } + + if((keys[KEY_LALT] || keys[KEY_RALT]) && keys[KEY_F12]) + { + select_vc(11); + return; + } +} + +/** + * keyboard_irq() + * + * Called when a keyboard interrupt is generated. + */ +void keyboard_irq(void) +{ + register char a; + unsigned c; + unsigned short kbdstat; + + rawkey = inportb(0x60); + outportb(0x61, (a=inportb(0x61)|0x82)); + outportb(0x61, a & 0x7F); + + /** + * If it's less than 0x80 then it's definatelly + * a make code or a repeat code + */ + if(rawkey < 0x80) + { + /** + * We don't want to gunk up the numlock key + * because we will define it's state in the + * break code a bit later + */ + if((rawkey != KEYP_NUMLCK) && (rawkey != KEY_SCRLCK) && (rawkey != KEY_CAPS)) + keys[rawkey] = 1; + + keyDown(rawkey); + } + else /* rawkey >= 0x80 */ + { + if(rawkey == 0xE0) + { + /** + * It's either a make code, break code, or repeat code + */ + rawkey = inportb(0x60); + outportb(0x61, (a=inportb(0x61)|0x82)); + outportb(0x61, a & 0x7F); + + if(rawkey < 0x80) + { + /** + * Ok, it's a make code or repeat code for the numeric + * keypad (gray keys) + */ + + keys[rawkey] = 1; + + keyDown(rawkey); + } + else /* rawkey >= 0x80 */ + { + /** + * It's either a make code for the numeric keypad or + * a break code for the numeric keypad. + */ + if(rawkey == 0x2A) + { + /** + * Ok, we have a make code for the numeric keypad + * and NUMLOCK is on. The second byte is what we + * want since what we have so far is this: + * + * 0xE0 0x2A + */ + rawkey = inportb(0x60); + outportb(0x61, (a=inportb(0x61)|0x82)); + outportb(0x61, a & 0x7F); + + rawkey = inportb(0x60); + outportb(0x61, (a=inportb(0x61)|0x82)); + outportb(0x61, a & 0x7F); + + keys[rawkey] = 1; + + keyDown(rawkey); + } + else + { + /** + * It's a break code from the numeric keypad. + */ + keys[rawkey] = 0; + + keyUp(rawkey); + } + } + } + else /* rawkey != 0xE0 */ + { + /** + * It's a break code + * + * Make sure we toggle the numlock, scroll lock, and caps lock key. + */ + if(((rawkey - 0x80) == KEYP_NUMLCK) || + ((rawkey - 0x80) == KEY_SCRLCK) || + ((rawkey - 0x80) == KEY_CAPS)) + { + keys[rawkey - 0x80] = !keys[rawkey - 0x80]; + + kbdstat = 0; + if(keys[KEY_SCRLCK]) + kbdstat |= 1; + if(keys[KEYP_NUMLCK]) + kbdstat |= 2; + if(keys[KEY_CAPS]) + kbdstat |= 4; + + _write_kb(0x60, 0xED); + _write_kb(0x60, kbdstat); + outportb(0x20, 0x20); + + keyUp(rawkey); + return; + } + + keys[rawkey - 0x80] = 0; + + keyUp(rawkey); + } + } + + c = _translate_sc(rawkey); + + if(c != 0) + printf("%c", c); + else + { + /** + * We need to check for meta-key-crap here + */ + handle_meta_key(rawkey); + } + + //enable(); + outportb(0x20, 0x20); +} + +/** + * init_keyboard() + * + */ +void init_keyboard(void) +{ + static unsigned char buffers[KBD_BUF_SIZE * MAX_VC]; + + int i; + + //klog("init", "keyboard %2u buf, %2ub each", K_KLOG_PENDING, &_vc[0]); + for(i = 0; i < MAX_VC; i++) + { + _vc[i].keystrokes.data = buffers + KBD_BUF_SIZE * i; + _vc[i].keystrokes.size = KBD_BUF_SIZE; + } + + for(i = 0; i < 128; i++) + keys[i] = 0; + + makebreak = 0; + //klog(NULL, K_KLOG_SUCCESS, &_vc[0], NULL); + //kprintf("init_kbd: %u buffers, %u bytes each\n", + // MAX_VC, KBD_BUF_SIZE); + + //kprintf("[ Entering Runlevel 0 ].......................................................Ok"); + _vc[0].attrib = 8; + printf("[ "); + _vc[0].attrib = 15; + printf("init: keyboard %2u buf, %2ub each ", MAX_VC, KBD_BUF_SIZE); + _vc[0].attrib = 8; + printf("]..........................................."); + _vc[0].attrib = 2; + printf("Ok"); + _vc[0].attrib = 7; +} diff --git a/Dump/hybos/src/kernel/main.c b/Dump/hybos/src/kernel/main.c index 4965644..a92ee9b 100644 --- a/Dump/hybos/src/kernel/main.c +++ b/Dump/hybos/src/kernel/main.c @@ -1,728 +1,728 @@ -/** - * main.c - * - * Main code for HybOS. - * - * I spent a lot of time cleaning this damned thing up, so if you - * are even REMOTELY thinking of modifying it, you better make - * sure you follow the same design pattern as you see now. I am sick - * of cleaning up c-style comments because some dumbass is too fucking - * lazy to use the PROPER c89-style comments. This is C people, not C++. - * - * Exports: - * void printf(const char *fmt, ...); - * int main(void); - * - * Imports: - * kstart.asm getvect(); - * kstart.asm setvect(); - * video.c console_t _vc[]; - * video.c blink(); - * video.c init_video(); - * kbd.c keyboard_irq(); - * kbd.c kbd_hw_init(); - * kbd.c init_keyboard(); - * sched.c schedule(); - * sched.c init_tasks(); - * debug.c dump_regs(); - * - * FIXME: - * needs to be renamed to kernel.c - */ -#include /* va_list, va_start(), va_end() */ -/*#include */ /* NULL */ -#include /* NULL */ -#include /* disable() */ -#include <_printf.h> /* do_printf() */ -#include <_malloc.h> -#include -#include -#include -#include "_krnl.h" /* regs_t */ -#include "bootlog.h" /* klog() */ - -/** - * FIXME - * - * These externs and declares are a fucking mess and - * need to be ported to their own headers for portability - */ - -/** - * Imports - */ -void getvect(vector_t *v, unsigned vect_num); -void setvect(vector_t *v, unsigned vect_num); -extern console_t _vc[]; -void blink(void); -void putch(unsigned c); -void init_video(void); -void keyboard_irq(void); -//void kbd_hw_int(void); -void init_keyboard(void); -void schedule(void); -void init_tasks(void); -void dump_regs(regs_t *regs); - -void _mm_physical_init(void); -unsigned _mm_physical_alloc(void); -void _mm_physical_free(unsigned page); -void _mm_page_copy_byte(uint32_t dest, uint32_t src); -void _mm_page_copy_word(uint32_t dest, uint32_t src); -void _mm_page_copy_dword(uint32_t dest, uint32_t src); - -/*void init_cpu(void);*/ - -/** - * printf/kprintf helper - */ -static int kprintf_help(unsigned c, void **ptr) -{ - /** - * Leave this for now - */ - ptr = ptr; - - putch(c); - return 0; -} - -/** - * Format output and print it to stdout (vtty0) - * Just like on any other operating system - */ -/*void printf(const char *fmt, ...) -{ - va_list args; - - va_start(args, fmt); - (void)do_printf(fmt, args, kprintf_help, NULL); - va_end(args); -}*/ - -void kprintf(const char *fmt, ...) -{ - va_list args; - - va_start(args, fmt); - (void)do_printf(fmt, args, kprintf_help, NULL); - va_end(args); -} - -/** - * Format output and print it to stdout (vtty0) - * Just like on any other operating system - */ -void printk(const char *fmt, ...) -{ - va_list args; - - /** - * TODO - * - * Select vtty0 - */ - va_start(args, fmt); - (void)do_printf(fmt, args, kprintf_help, NULL); - va_end(args); -} - -/** - * Oh yeah, the fun function ;) - */ -void panic(const char *fmt, ...) -{ - va_list args; - - disable(); /* interrupts off */ - va_start(args, fmt); - _vc[0].attrib = 15; - printf("\n\npanic: "); - (void)do_printf(fmt, args, kprintf_help, NULL); - - printf("\n\nSystem halted."); - __asm__ __volatile__ ("hlt"); - - while(1) - /* freeze */; -} - -/** - * Called when a kernel fault is detected. This does not - * (normally) get called when something goes awry in - * user-space, therefore it is designed for kernel-space - */ -void fault(regs_t *regs) -{ - struct exception - { - char *message; - int signal; - int processor; - }; - - static const struct exception ex[] = - { - {"Divide error", SIGFPE, 86}, - {"Debug exception", SIGTRAP, 86}, - {"Nonmaskable interrupt (NMI)", SIGBUS, 86}, - {"Breakpoint (INT3)", SIGEMT, 86}, - {"Overflow (INTO)", SIGFPE, 186}, - {"Bounds check", SIGFPE, 186}, - {"Invalid opcode", SIGILL, 186}, - {"Coprocessor not available", SIGFPE, 186}, - {"Double fault", SIGBUS, 286}, - {"Coprocessor segment overrun", SIGSEGV, 286}, - {"Invalid TSS", SIGSEGV, 286}, - {"Segment not present", SIGSEGV, 286}, - {"Stack exception", SIGSEGV, 286}, - {"General Protection Fault", SIGSEGV, 286}, - {"Page fault", SIGSEGV, 386}, - {NULL, SIGILL, 0}, - {"Coprocessor error", SIGFPE, 386}, - {"Alignment check",0,0}, - {"??",0,0}, - {"??",0,0}, - {"??",0,0}, - {"??",0,0}, - {"??",0,0}, - {"??",0,0}, - {"??",0,0}, - {"??",0,0}, - {"??",0,0}, - {"??",0,0}, - {"??",0,0}, - {"??",0,0}, - {"??",0,0}, - {"??",0,0}, - {"IRQ0",0,0}, - {"IRQ1",0,0}, - {"IRQ2",0,0}, - {"IRQ3",0,0}, - {"IRQ4",0,0}, - {"IRQ5",0,0}, - {"IRQ6",0,0}, - {"IRQ7",0,0}, - {"IRQ8",0,0}, - {"IRQ9",0,0}, - {"IRQ10",0,0}, - {"IRQ11",0,0}, - {"IRQ12",0,0}, - {"IRQ13",0,0}, - {"IRQ14",0,0}, - {"IRQ15",0,0}, - {"syscall",0,0} - }; - - - switch(regs->which_int) - { - /** - * this handler installed at compile-time - * Keyboard handler is installed at run-time (see below) - */ - case 0x20: /* timer IRQ 0 */ - //blink(); - /** - * reset hardware interrupt at 8259 chip - */ - outportb(0x20, 0x20); - break; - default: - _vc[0].attrib = 15; - printf("\n\npanic: Exception 0x%08X", regs->which_int); - if(regs->which_int <= sizeof(ex) / sizeof(ex[0].message)) - printf(" (%s)", ex[regs->which_int].message); - printf("\n"); - dump_regs(regs); - printf("\n\nSystem halted."); - __asm__ __volatile__ ("hlt"); - break; - } -} - -/** - * ?? - */ -static void init_8259s(void) -{ - static const unsigned irq0_int = 0x20, irq8_int = 0x28; - - /** - * Initialization Control Word #1 (ICW1) - */ - outportb(0x20, 0x11); - outportb(0xA0, 0x11); - - /** - * ICW2: - * route IRQs 0-7 to INTs 20h-27h - */ - outportb(0x21, irq0_int); - - /** - * route IRQs 8-15 to INTs 28h-2Fh - */ - outportb(0xA1, irq8_int); - - /** - * ICW3 - */ - outportb(0x21, 0x04); - outportb(0xA1, 0x02); - - /** - * ICW4 - */ - outportb(0x21, 0x01); - outportb(0xA1, 0x01); - - /** - * enable IRQ0 (timer) and IRQ1 (keyboard) - */ - outportb(0x21, ~0x03); - outportb(0xA1, ~0x00); -} - -/** - * MinGW32 - */ -#ifdef __WIN32__ -#if __GNUC__<3 -#error Do not use MinGW GCC 2.x with NASM -#endif - int __main(void) { return 0; } - void _alloca(void) { } -#endif - -/** - * malloc, realloc, free, etc - */ -static char *g_heap_bot, *g_kbrk, *g_heap_top; -static void dump_heap(void) -{ - unsigned blks_used = 0, blks_free = 0; - size_t bytes_used = 0, bytes_free = 0; - malloc_t *m; - int total; - - kprintf("===============================================\n"); - for(m = (malloc_t *)g_heap_bot; m != NULL; m = m->next) - { - printk("block %5p: %6u bytes %s\n", m, - m->size, m->used ? "used" : "free"); - if(m->used) - { - blks_used++; - bytes_used += m->size; - } - else - { - blks_free++; - bytes_free += m->size; - } - } - kprintf("blocks: %6u used, %6u free, %6u total\n", blks_used, - blks_free, blks_used + blks_free); - kprintf(" bytes: %6u used, %6u free, %6u total\n", bytes_used, - bytes_free, bytes_used + bytes_free); - kprintf("g_heap_bot=0x%p, g_kbrk=0x%p, g_heap_top=0x%p\n", - g_heap_bot, g_kbrk, g_heap_top); - total = (bytes_used + bytes_free) + - (blks_used + blks_free) * sizeof(malloc_t); - if(total != g_kbrk - g_heap_bot) - kprintf("*** some heap memory is not accounted for\n"); - kprintf("===============================================\n"); -} - -void dumpheapk(void) -{ - dump_heap(); -} - -/** - * POSIX sbrk() looks like this - * void *sbrk(int incr); - * - * Mine is a bit different so I can signal the calling function - * if more memory than desired was allocated (e.g. in a system with paging) - * If your kbrk()/sbrk() always allocates the amount of memory you ask for, - * this code can be easily changed. - * - * int brk( void *sbrk( void *kbrk( - * function void *adr); int delta); int *delta); - * ---------------------- ------------ ------------ ------------- - * POSIX? yes yes NO - * return value if error -1 -1 NULL - * get break value . sbrk(0) int x=0; kbrk(&x); - * set break value to X brk(X) sbrk(X - sbrk(0)) int x=X, y=0; kbrk(&x) - kbrk(&y); - * enlarge heap by N bytes . sbrk(+N) int x=N; kbrk(&x); - * shrink heap by N bytes . sbrk(-N) int x=-N; kbrk(&x); - * can you tell if you're - * given more memory - * than you wanted? no no yes - */ -static void *kbrk(int *delta) -{ - static char heap[HEAP_SIZE]; - char *new_brk, *old_brk; - - /** - * heap doesn't exist yet - */ - if(g_heap_bot == NULL) - { - g_heap_bot = g_kbrk = heap; - g_heap_top = g_heap_bot + HEAP_SIZE; - } - new_brk = g_kbrk + (*delta); - - /** - * too low: return NULL - */ - if(new_brk < g_heap_bot) - return NULL; - - /** - * too high: return NULL - */ - if(new_brk >= g_heap_top) - return NULL; - - /** - * success: adjust brk value... - */ - old_brk = g_kbrk; - g_kbrk = new_brk; - - /** - * ...return actual delta... (for this sbrk(), they are the same) - * (*delta) = (*delta); - * ...return old brk value - */ - return old_brk; -} - -/** - * malloc() and free() use g_heap_bot, but not g_kbrk nor g_heap_top - */ -void *kmalloc(size_t size) -{ - unsigned total_size; - malloc_t *m, *n; - int delta; - - if(size == 0) - return NULL; - total_size = size + sizeof(malloc_t); - - /** - * search heap for free block (FIRST FIT) - */ - m = (malloc_t *)g_heap_bot; - - /** - * g_heap_bot == 0 == NULL if heap does not yet exist - */ - if(m != NULL) - { - if(m->magic != MALLOC_MAGIC) - { - /*printf("*** kernel heap is corrupt in kmalloc()\n");*/ - panic("kernel heap is corrupt in malloc()"); - return NULL; - } - for(; m->next != NULL; m = m->next) - { - if(m->used) - continue; - - /** - * size == m->size is a perfect fit - */ - if(size == m->size) - m->used = 1; - else - { - /** - * otherwise, we need an extra sizeof(malloc_t) bytes for the header - * of a second, free block - */ - if(total_size > m->size) - continue; - - /** - * create a new, smaller free block after this one - */ - n = (malloc_t *)((char *)m + total_size); - n->size = m->size - total_size; - n->next = m->next; - n->magic = MALLOC_MAGIC; - n->used = 0; - - /** - * reduce the size of this block and mark it used - */ - m->size = size; - m->next = n; - m->used = 1; - } - return (char *)m + sizeof(malloc_t); - } - } - - /** - * use kbrk() to enlarge (or create!) heap - */ - delta = total_size; - n = kbrk(&delta); - - /** - * uh-oh - */ - if(n == NULL) - return NULL; - - if(m != NULL) - m->next = n; - - n->size = size; - n->magic = MALLOC_MAGIC; - n->used = 1; - - /** - * did kbrk() return the exact amount of memory we wanted? - * cast to make "gcc -Wall -W ..." shut the hell up - */ - if((int)total_size == delta) - n->next = NULL; - else - { - - /** - * it returned more than we wanted (it will never return less): - * create a new, free block - */ - m = (malloc_t *)((char *)n + total_size); - m->size = delta - total_size - sizeof(malloc_t); - m->next = NULL; - m->magic = MALLOC_MAGIC; - m->used = 0; - - n->next = m; - } - return (char *)n + sizeof(malloc_t); -} - -void kfree(void *blk) -{ - malloc_t *m, *n; - - /** - * get address of header - */ - m = (malloc_t *)((char *)blk - sizeof(malloc_t)); - if(m->magic != MALLOC_MAGIC) - { - /*printf("*** attempt to kfree() block at 0x%p with bad magic value\n", blk);*/ - panic("attempt to free() block at 0x%p with bad magic value", blk); - return; - } - - /** - * find this block in the heap - */ - n = (malloc_t *)g_heap_bot; - if(n->magic != MALLOC_MAGIC) - { - /*printf("*** kernel heap is corrupt in kfree()\n");*/ - panic("kernel heap is corrupt in free()"); - return; - } - for(; n != NULL; n = n->next) - { - if(n == m) - break; - } - - /** - * not found? bad pointer or no heap or something else? - */ - if(n == NULL) - { - /*printf("*** attempt to kfree() block at 0x%p that is not in the heap\n", blk);*/ - panic("attempt to free() block at 0x%p that is not in the heap", blk); - return; - } - - /** - * free the block - */ - m->used = 0; - - /** - * coalesce adjacent free blocks - * Hard to spell, hard to do - */ - for(m = (malloc_t *)g_heap_bot; m != NULL; m = m->next) - { - while(!m->used && m->next != NULL && !m->next->used) - { - /** - * resize this block - */ - m->size += sizeof(malloc_t) + m->next->size; - - /** - * merge with next block - */ - m->next = m->next->next; - } - } -} - -void testheap(void) -{ - //int i; - //char *t; - //kprintf("before char *t = kmalloc((size_t *)25):\n"); - //dump_heap(); - //t = kmalloc(25); - //strcpy(t, "123456789012345678901234"); - //kprintf("after char *t = kmalloc((size_t *)25):\n"); - //dump_heap(); - //kfree(t); - //kprintf("after kfree(t):\n"); - //dump_heap(); - //kprintf("before char *t = kmalloc((size_t *)25):\n"); - - kprintf("Unable to run testheap -- kmalloc() is broken.\n"); -} - -void *krealloc(void *blk, size_t size) -{ - void *new_blk; - malloc_t *m; - - /** - * size == 0: free block - */ - if(size == 0) - { - if(blk != NULL) - kfree(blk); - new_blk = NULL; - } - else - { - /** - * allocate new block - */ - new_blk = kmalloc(size); - - /** - * if allocation OK, and if old block exists, copy old block to new - */ - if(new_blk != NULL && blk != NULL) - { - m = (malloc_t *)((char *)blk - sizeof(malloc_t)); - if(m->magic != MALLOC_MAGIC) - { - /*printf("*** attempt to krealloc() block at 0x%p with bad magic value\n", blk);*/ - panic("attempt to realloc() block at 0x%p with bad magic value", blk); - return NULL; - } - - /** - * copy minimum of old and new block sizes - */ - if(size > m->size) - size = m->size; - memcpy(new_blk, blk, size); - - /** - * free the old block - */ - kfree(blk); - } - } - return new_blk; -} - -void keyboardISR(void); - -int main(void) -{ - /** - * keyboard interrupt init - */ - vector_t v; - unsigned i; - - init_video(); - init_keyboard(); - init_8259s(); - - /** - * XXX: - * i know this is a very ugly way of doing this, - * however it is the only way it can be done for now. - * in the future, i will implement a kprintf function - * whose sole purpose will be writing boot messages. - * - * Also, the color codes need to be mapped to constants - * in order to make using them a hell of a lot easier. - */ - - klog("init", "Installing keyboard interrupt handler", K_KLOG_PENDING, &_vc[0]); - /* we don't save the old vector */ - v.eip = (unsigned)keyboard_irq; - v.access_byte = 0x8E; /* present, ring 0, '386 interrupt gate */ - setvect(&v, 0x21); - klog(NULL, NULL, K_KLOG_SUCCESS, &_vc[0]); - - /*init_tasks();*/ - - klog("init", "Enabling hardware interrupts", K_KLOG_PENDING, &_vc[0]); - enable(); - /*for(i = 0; i < 0xFFFFFFF; i++);*/ - klog(NULL, NULL, K_KLOG_SUCCESS, &_vc[0]); - - /** - * Initialize memory management - */ - /*_mm_init();*/ - - /** - * finished init, time for some gooey ;) - */ - printf(" _ _ _ _ ____ _____ ___ "); - printf(" ( )_( )( \\/ )( _ \\( _ )/ __) "); - printf(" ) _ ( \\ / ) _ < )(_)( \\__ \\ "); - printf(" (_) (_) (__) (____/(_____)(___/ \n"); - - printf(" Hybrid Operating System (HybOS) \n"); - - /** - * XXX: debug only - */ - printf("ALT + F1 - F8 for virtual terminals\n"); - printf("Three finger salute to restart\n"); - printf("More work needs to be done\n"); - printf("$ "); - - /** - * fork (kfork()) control over to a shell - */ - /*init_shell();*/ - - /** - * idle task/thread - */ - while(1) - { - schedule(); - } - - return 0; -} +/** + * main.c + * + * Main code for HybOS. + * + * I spent a lot of time cleaning this damned thing up, so if you + * are even REMOTELY thinking of modifying it, you better make + * sure you follow the same design pattern as you see now. I am sick + * of cleaning up c-style comments because some dumbass is too fucking + * lazy to use the PROPER c89-style comments. This is C people, not C++. + * + * Exports: + * void printf(const char *fmt, ...); + * int main(void); + * + * Imports: + * kstart.asm getvect(); + * kstart.asm setvect(); + * video.c console_t _vc[]; + * video.c blink(); + * video.c init_video(); + * kbd.c keyboard_irq(); + * kbd.c kbd_hw_init(); + * kbd.c init_keyboard(); + * sched.c schedule(); + * sched.c init_tasks(); + * debug.c dump_regs(); + * + * FIXME: + * needs to be renamed to kernel.c + */ +#include /* va_list, va_start(), va_end() */ +/*#include */ /* NULL */ +#include /* NULL */ +#include /* disable() */ +#include <_printf.h> /* do_printf() */ +#include <_malloc.h> +#include +#include +#include +#include "_krnl.h" /* regs_t */ +#include "bootlog.h" /* klog() */ + +/** + * FIXME + * + * These externs and declares are a fucking mess and + * need to be ported to their own headers for portability + */ + +/** + * Imports + */ +void getvect(vector_t *v, unsigned vect_num); +void setvect(vector_t *v, unsigned vect_num); +extern console_t _vc[]; +void blink(void); +void putch(unsigned c); +void init_video(void); +void keyboard_irq(void); +//void kbd_hw_int(void); +void init_keyboard(void); +void schedule(void); +void init_tasks(void); +void dump_regs(regs_t *regs); + +void _mm_physical_init(void); +unsigned _mm_physical_alloc(void); +void _mm_physical_free(unsigned page); +void _mm_page_copy_byte(uint32_t dest, uint32_t src); +void _mm_page_copy_word(uint32_t dest, uint32_t src); +void _mm_page_copy_dword(uint32_t dest, uint32_t src); + +/*void init_cpu(void);*/ + +/** + * printf/kprintf helper + */ +static int kprintf_help(unsigned c, void **ptr) +{ + /** + * Leave this for now + */ + ptr = ptr; + + putch(c); + return 0; +} + +/** + * Format output and print it to stdout (vtty0) + * Just like on any other operating system + */ +/*void printf(const char *fmt, ...) +{ + va_list args; + + va_start(args, fmt); + (void)do_printf(fmt, args, kprintf_help, NULL); + va_end(args); +}*/ + +void kprintf(const char *fmt, ...) +{ + va_list args; + + va_start(args, fmt); + (void)do_printf(fmt, args, kprintf_help, NULL); + va_end(args); +} + +/** + * Format output and print it to stdout (vtty0) + * Just like on any other operating system + */ +void printk(const char *fmt, ...) +{ + va_list args; + + /** + * TODO + * + * Select vtty0 + */ + va_start(args, fmt); + (void)do_printf(fmt, args, kprintf_help, NULL); + va_end(args); +} + +/** + * Oh yeah, the fun function ;) + */ +void panic(const char *fmt, ...) +{ + va_list args; + + disable(); /* interrupts off */ + va_start(args, fmt); + _vc[0].attrib = 15; + printf("\n\npanic: "); + (void)do_printf(fmt, args, kprintf_help, NULL); + + printf("\n\nSystem halted."); + __asm__ __volatile__ ("hlt"); + + while(1) + /* freeze */; +} + +/** + * Called when a kernel fault is detected. This does not + * (normally) get called when something goes awry in + * user-space, therefore it is designed for kernel-space + */ +void fault(regs_t *regs) +{ + struct exception + { + char *message; + int signal; + int processor; + }; + + static const struct exception ex[] = + { + {"Divide error", SIGFPE, 86}, + {"Debug exception", SIGTRAP, 86}, + {"Nonmaskable interrupt (NMI)", SIGBUS, 86}, + {"Breakpoint (INT3)", SIGEMT, 86}, + {"Overflow (INTO)", SIGFPE, 186}, + {"Bounds check", SIGFPE, 186}, + {"Invalid opcode", SIGILL, 186}, + {"Coprocessor not available", SIGFPE, 186}, + {"Double fault", SIGBUS, 286}, + {"Coprocessor segment overrun", SIGSEGV, 286}, + {"Invalid TSS", SIGSEGV, 286}, + {"Segment not present", SIGSEGV, 286}, + {"Stack exception", SIGSEGV, 286}, + {"General Protection Fault", SIGSEGV, 286}, + {"Page fault", SIGSEGV, 386}, + {NULL, SIGILL, 0}, + {"Coprocessor error", SIGFPE, 386}, + {"Alignment check",0,0}, + {"??",0,0}, + {"??",0,0}, + {"??",0,0}, + {"??",0,0}, + {"??",0,0}, + {"??",0,0}, + {"??",0,0}, + {"??",0,0}, + {"??",0,0}, + {"??",0,0}, + {"??",0,0}, + {"??",0,0}, + {"??",0,0}, + {"??",0,0}, + {"IRQ0",0,0}, + {"IRQ1",0,0}, + {"IRQ2",0,0}, + {"IRQ3",0,0}, + {"IRQ4",0,0}, + {"IRQ5",0,0}, + {"IRQ6",0,0}, + {"IRQ7",0,0}, + {"IRQ8",0,0}, + {"IRQ9",0,0}, + {"IRQ10",0,0}, + {"IRQ11",0,0}, + {"IRQ12",0,0}, + {"IRQ13",0,0}, + {"IRQ14",0,0}, + {"IRQ15",0,0}, + {"syscall",0,0} + }; + + + switch(regs->which_int) + { + /** + * this handler installed at compile-time + * Keyboard handler is installed at run-time (see below) + */ + case 0x20: /* timer IRQ 0 */ + //blink(); + /** + * reset hardware interrupt at 8259 chip + */ + outportb(0x20, 0x20); + break; + default: + _vc[0].attrib = 15; + printf("\n\npanic: Exception 0x%08X", regs->which_int); + if(regs->which_int <= sizeof(ex) / sizeof(ex[0].message)) + printf(" (%s)", ex[regs->which_int].message); + printf("\n"); + dump_regs(regs); + printf("\n\nSystem halted."); + __asm__ __volatile__ ("hlt"); + break; + } +} + +/** + * ?? + */ +static void init_8259s(void) +{ + static const unsigned irq0_int = 0x20, irq8_int = 0x28; + + /** + * Initialization Control Word #1 (ICW1) + */ + outportb(0x20, 0x11); + outportb(0xA0, 0x11); + + /** + * ICW2: + * route IRQs 0-7 to INTs 20h-27h + */ + outportb(0x21, irq0_int); + + /** + * route IRQs 8-15 to INTs 28h-2Fh + */ + outportb(0xA1, irq8_int); + + /** + * ICW3 + */ + outportb(0x21, 0x04); + outportb(0xA1, 0x02); + + /** + * ICW4 + */ + outportb(0x21, 0x01); + outportb(0xA1, 0x01); + + /** + * enable IRQ0 (timer) and IRQ1 (keyboard) + */ + outportb(0x21, ~0x03); + outportb(0xA1, ~0x00); +} + +/** + * MinGW32 + */ +#ifdef __WIN32__ +#if __GNUC__<3 +#error Do not use MinGW GCC 2.x with NASM +#endif + int __main(void) { return 0; } + void _alloca(void) { } +#endif + +/** + * malloc, realloc, free, etc + */ +static char *g_heap_bot, *g_kbrk, *g_heap_top; +static void dump_heap(void) +{ + unsigned blks_used = 0, blks_free = 0; + size_t bytes_used = 0, bytes_free = 0; + malloc_t *m; + int total; + + kprintf("===============================================\n"); + for(m = (malloc_t *)g_heap_bot; m != NULL; m = m->next) + { + printk("block %5p: %6u bytes %s\n", m, + m->size, m->used ? "used" : "free"); + if(m->used) + { + blks_used++; + bytes_used += m->size; + } + else + { + blks_free++; + bytes_free += m->size; + } + } + kprintf("blocks: %6u used, %6u free, %6u total\n", blks_used, + blks_free, blks_used + blks_free); + kprintf(" bytes: %6u used, %6u free, %6u total\n", bytes_used, + bytes_free, bytes_used + bytes_free); + kprintf("g_heap_bot=0x%p, g_kbrk=0x%p, g_heap_top=0x%p\n", + g_heap_bot, g_kbrk, g_heap_top); + total = (bytes_used + bytes_free) + + (blks_used + blks_free) * sizeof(malloc_t); + if(total != g_kbrk - g_heap_bot) + kprintf("*** some heap memory is not accounted for\n"); + kprintf("===============================================\n"); +} + +void dumpheapk(void) +{ + dump_heap(); +} + +/** + * POSIX sbrk() looks like this + * void *sbrk(int incr); + * + * Mine is a bit different so I can signal the calling function + * if more memory than desired was allocated (e.g. in a system with paging) + * If your kbrk()/sbrk() always allocates the amount of memory you ask for, + * this code can be easily changed. + * + * int brk( void *sbrk( void *kbrk( + * function void *adr); int delta); int *delta); + * ---------------------- ------------ ------------ ------------- + * POSIX? yes yes NO + * return value if error -1 -1 NULL + * get break value . sbrk(0) int x=0; kbrk(&x); + * set break value to X brk(X) sbrk(X - sbrk(0)) int x=X, y=0; kbrk(&x) - kbrk(&y); + * enlarge heap by N bytes . sbrk(+N) int x=N; kbrk(&x); + * shrink heap by N bytes . sbrk(-N) int x=-N; kbrk(&x); + * can you tell if you're + * given more memory + * than you wanted? no no yes + */ +static void *kbrk(int *delta) +{ + static char heap[HEAP_SIZE]; + char *new_brk, *old_brk; + + /** + * heap doesn't exist yet + */ + if(g_heap_bot == NULL) + { + g_heap_bot = g_kbrk = heap; + g_heap_top = g_heap_bot + HEAP_SIZE; + } + new_brk = g_kbrk + (*delta); + + /** + * too low: return NULL + */ + if(new_brk < g_heap_bot) + return NULL; + + /** + * too high: return NULL + */ + if(new_brk >= g_heap_top) + return NULL; + + /** + * success: adjust brk value... + */ + old_brk = g_kbrk; + g_kbrk = new_brk; + + /** + * ...return actual delta... (for this sbrk(), they are the same) + * (*delta) = (*delta); + * ...return old brk value + */ + return old_brk; +} + +/** + * malloc() and free() use g_heap_bot, but not g_kbrk nor g_heap_top + */ +void *kmalloc(size_t size) +{ + unsigned total_size; + malloc_t *m, *n; + int delta; + + if(size == 0) + return NULL; + total_size = size + sizeof(malloc_t); + + /** + * search heap for free block (FIRST FIT) + */ + m = (malloc_t *)g_heap_bot; + + /** + * g_heap_bot == 0 == NULL if heap does not yet exist + */ + if(m != NULL) + { + if(m->magic != MALLOC_MAGIC) + { + /*printf("*** kernel heap is corrupt in kmalloc()\n");*/ + panic("kernel heap is corrupt in malloc()"); + return NULL; + } + for(; m->next != NULL; m = m->next) + { + if(m->used) + continue; + + /** + * size == m->size is a perfect fit + */ + if(size == m->size) + m->used = 1; + else + { + /** + * otherwise, we need an extra sizeof(malloc_t) bytes for the header + * of a second, free block + */ + if(total_size > m->size) + continue; + + /** + * create a new, smaller free block after this one + */ + n = (malloc_t *)((char *)m + total_size); + n->size = m->size - total_size; + n->next = m->next; + n->magic = MALLOC_MAGIC; + n->used = 0; + + /** + * reduce the size of this block and mark it used + */ + m->size = size; + m->next = n; + m->used = 1; + } + return (char *)m + sizeof(malloc_t); + } + } + + /** + * use kbrk() to enlarge (or create!) heap + */ + delta = total_size; + n = kbrk(&delta); + + /** + * uh-oh + */ + if(n == NULL) + return NULL; + + if(m != NULL) + m->next = n; + + n->size = size; + n->magic = MALLOC_MAGIC; + n->used = 1; + + /** + * did kbrk() return the exact amount of memory we wanted? + * cast to make "gcc -Wall -W ..." shut the hell up + */ + if((int)total_size == delta) + n->next = NULL; + else + { + + /** + * it returned more than we wanted (it will never return less): + * create a new, free block + */ + m = (malloc_t *)((char *)n + total_size); + m->size = delta - total_size - sizeof(malloc_t); + m->next = NULL; + m->magic = MALLOC_MAGIC; + m->used = 0; + + n->next = m; + } + return (char *)n + sizeof(malloc_t); +} + +void kfree(void *blk) +{ + malloc_t *m, *n; + + /** + * get address of header + */ + m = (malloc_t *)((char *)blk - sizeof(malloc_t)); + if(m->magic != MALLOC_MAGIC) + { + /*printf("*** attempt to kfree() block at 0x%p with bad magic value\n", blk);*/ + panic("attempt to free() block at 0x%p with bad magic value", blk); + return; + } + + /** + * find this block in the heap + */ + n = (malloc_t *)g_heap_bot; + if(n->magic != MALLOC_MAGIC) + { + /*printf("*** kernel heap is corrupt in kfree()\n");*/ + panic("kernel heap is corrupt in free()"); + return; + } + for(; n != NULL; n = n->next) + { + if(n == m) + break; + } + + /** + * not found? bad pointer or no heap or something else? + */ + if(n == NULL) + { + /*printf("*** attempt to kfree() block at 0x%p that is not in the heap\n", blk);*/ + panic("attempt to free() block at 0x%p that is not in the heap", blk); + return; + } + + /** + * free the block + */ + m->used = 0; + + /** + * coalesce adjacent free blocks + * Hard to spell, hard to do + */ + for(m = (malloc_t *)g_heap_bot; m != NULL; m = m->next) + { + while(!m->used && m->next != NULL && !m->next->used) + { + /** + * resize this block + */ + m->size += sizeof(malloc_t) + m->next->size; + + /** + * merge with next block + */ + m->next = m->next->next; + } + } +} + +void testheap(void) +{ + //int i; + //char *t; + //kprintf("before char *t = kmalloc((size_t *)25):\n"); + //dump_heap(); + //t = kmalloc(25); + //strcpy(t, "123456789012345678901234"); + //kprintf("after char *t = kmalloc((size_t *)25):\n"); + //dump_heap(); + //kfree(t); + //kprintf("after kfree(t):\n"); + //dump_heap(); + //kprintf("before char *t = kmalloc((size_t *)25):\n"); + + kprintf("Unable to run testheap -- kmalloc() is broken.\n"); +} + +void *krealloc(void *blk, size_t size) +{ + void *new_blk; + malloc_t *m; + + /** + * size == 0: free block + */ + if(size == 0) + { + if(blk != NULL) + kfree(blk); + new_blk = NULL; + } + else + { + /** + * allocate new block + */ + new_blk = kmalloc(size); + + /** + * if allocation OK, and if old block exists, copy old block to new + */ + if(new_blk != NULL && blk != NULL) + { + m = (malloc_t *)((char *)blk - sizeof(malloc_t)); + if(m->magic != MALLOC_MAGIC) + { + /*printf("*** attempt to krealloc() block at 0x%p with bad magic value\n", blk);*/ + panic("attempt to realloc() block at 0x%p with bad magic value", blk); + return NULL; + } + + /** + * copy minimum of old and new block sizes + */ + if(size > m->size) + size = m->size; + memcpy(new_blk, blk, size); + + /** + * free the old block + */ + kfree(blk); + } + } + return new_blk; +} + +void keyboardISR(void); + +int main(void) +{ + /** + * keyboard interrupt init + */ + vector_t v; + unsigned i; + + init_video(); + init_keyboard(); + init_8259s(); + + /** + * XXX: + * i know this is a very ugly way of doing this, + * however it is the only way it can be done for now. + * in the future, i will implement a kprintf function + * whose sole purpose will be writing boot messages. + * + * Also, the color codes need to be mapped to constants + * in order to make using them a hell of a lot easier. + */ + + klog("init", "Installing keyboard interrupt handler", K_KLOG_PENDING, &_vc[0]); + /* we don't save the old vector */ + v.eip = (unsigned)keyboard_irq; + v.access_byte = 0x8E; /* present, ring 0, '386 interrupt gate */ + setvect(&v, 0x21); + klog(NULL, NULL, K_KLOG_SUCCESS, &_vc[0]); + + /*init_tasks();*/ + + klog("init", "Enabling hardware interrupts", K_KLOG_PENDING, &_vc[0]); + enable(); + /*for(i = 0; i < 0xFFFFFFF; i++);*/ + klog(NULL, NULL, K_KLOG_SUCCESS, &_vc[0]); + + /** + * Initialize memory management + */ + /*_mm_init();*/ + + /** + * finished init, time for some gooey ;) + */ + printf(" _ _ _ _ ____ _____ ___ "); + printf(" ( )_( )( \\/ )( _ \\( _ )/ __) "); + printf(" ) _ ( \\ / ) _ < )(_)( \\__ \\ "); + printf(" (_) (_) (__) (____/(_____)(___/ \n"); + + printf(" Hybrid Operating System (HybOS) \n"); + + /** + * XXX: debug only + */ + printf("ALT + F1 - F8 for virtual terminals\n"); + printf("Three finger salute to restart\n"); + printf("More work needs to be done\n"); + printf("$ "); + + /** + * fork (kfork()) control over to a shell + */ + /*init_shell();*/ + + /** + * idle task/thread + */ + while(1) + { + schedule(); + } + + return 0; +} diff --git a/Dump/hybos/src/kernel/tasks.c b/Dump/hybos/src/kernel/tasks.c index 12f6ac3..624d142 100644 --- a/Dump/hybos/src/kernel/tasks.c +++ b/Dump/hybos/src/kernel/tasks.c @@ -1,136 +1,136 @@ -/** - * tasks.c - * - * ?? - * - * Exports: - * task1() - * task2() - * task3() - * task4() - * - * Imports: - * video.c putch_help(); - * sched.c task_t *_curr_task; - */ - -#include "_krnl.h" - -/** - * Imports - */ -void putch_help(console_t *con, unsigned c); -extern task_t *_curr_task; -void schedule(void); - -/** - * write() - * - */ -static int write(const unsigned char *str, unsigned len) -{ - unsigned i; - - for(i = 0; i < len; i++) - { - putch_help(_curr_task->vc, *str); - str++; - } - return i; -} - -/** - * yield() - * - */ -static void yield(void) -{ - schedule(); -} - -#define WAIT 0xFFFFFL - -/** - * wait() - */ -static void wait(void) -{ - unsigned long wait; - - for(wait = WAIT; wait != 0; wait--) - /* nothing */; -} - -/** - * task1() - * - */ -void task1(void) -{ - //static const unsigned char msg_a[] = "root@hybos $ "; -/**/ - - //write(msg_a, sizeof(msg_a)); - wait(); - while(1) - { - /* so we can process other events */ - yield(); - wait(); - } -} - -/** - * task2() - * - */ -void task2(void) -{ - //static const unsigned char msg_a[] = "root@hybos $ "; -/**/ - - //write(msg_a, sizeof(msg_a)); - wait(); - while(1) - { - yield(); - wait(); - } -} - -/** - * task3() - * - */ -void task3(void) -{ - //static const unsigned char msg_a[] = "root@hybos $ "; -/**/ - - //write(msg_a, sizeof(msg_a)); - wait(); - while(1) - { - yield(); - wait(); - } -} - -/** - * task4() - * - */ -void task4(void) -{ - //static const unsigned char msg_a[] = "root@hybos $ "; -/**/ - - //write(msg_a, sizeof(msg_a)); - wait(); - while(1) - { - yield(); - wait(); - } -} - +/** + * tasks.c + * + * ?? + * + * Exports: + * task1() + * task2() + * task3() + * task4() + * + * Imports: + * video.c putch_help(); + * sched.c task_t *_curr_task; + */ + +#include "_krnl.h" + +/** + * Imports + */ +void putch_help(console_t *con, unsigned c); +extern task_t *_curr_task; +void schedule(void); + +/** + * write() + * + */ +static int write(const unsigned char *str, unsigned len) +{ + unsigned i; + + for(i = 0; i < len; i++) + { + putch_help(_curr_task->vc, *str); + str++; + } + return i; +} + +/** + * yield() + * + */ +static void yield(void) +{ + schedule(); +} + +#define WAIT 0xFFFFFL + +/** + * wait() + */ +static void wait(void) +{ + unsigned long wait; + + for(wait = WAIT; wait != 0; wait--) + /* nothing */; +} + +/** + * task1() + * + */ +void task1(void) +{ + //static const unsigned char msg_a[] = "root@hybos $ "; +/**/ + + //write(msg_a, sizeof(msg_a)); + wait(); + while(1) + { + /* so we can process other events */ + yield(); + wait(); + } +} + +/** + * task2() + * + */ +void task2(void) +{ + //static const unsigned char msg_a[] = "root@hybos $ "; +/**/ + + //write(msg_a, sizeof(msg_a)); + wait(); + while(1) + { + yield(); + wait(); + } +} + +/** + * task3() + * + */ +void task3(void) +{ + //static const unsigned char msg_a[] = "root@hybos $ "; +/**/ + + //write(msg_a, sizeof(msg_a)); + wait(); + while(1) + { + yield(); + wait(); + } +} + +/** + * task4() + * + */ +void task4(void) +{ + //static const unsigned char msg_a[] = "root@hybos $ "; +/**/ + + //write(msg_a, sizeof(msg_a)); + wait(); + while(1) + { + yield(); + wait(); + } +} + diff --git a/Dump/hybos/src/kernel/video.c b/Dump/hybos/src/kernel/video.c index b192ebc..1cde91e 100644 --- a/Dump/hybos/src/kernel/video.c +++ b/Dump/hybos/src/kernel/video.c @@ -1,445 +1,445 @@ -/** - * video.c - * - * Text video routines - * - * Exports: - * blink(); - * select_vc() - * putch_help() - * putch() - * init_video(); - * - * Imports: - * main.c printf(); - */ - -/** - * TODO - * - * Fuck me with a blind melon...when the screen scrolls - * too much, it generates a panic of type invalid opcode. - */ - -#include /* memcpy(), memsetw() */ -#include /* isdigit() */ -#include /* outportb(), inportb() */ -#include -#include "_krnl.h" /* MAX_VC, console_t */ - -/** - * Imports - */ -void printf(const char *fmt, ...); - -#define VGA_MISC_READ 0x3CC - -console_t _vc[MAX_VC]; -static unsigned _num_vcs; -static console_t *_curr_vc; - -static unsigned short *_vga_fb_adr; -static unsigned _crtc_io_adr, _vc_width, _vc_height; - -unsigned curr_vtty; - -/** - * blink() - * - */ -void blink(void) -{ - (*(unsigned char *)_vga_fb_adr)++; -} - -/** - * get_current_vc() - * - */ -unsigned get_current_vc() -{ - return curr_vtty; -} - -/** - * scroll() - * - */ -static void scroll(console_t *con) -{ - unsigned short *fb_adr; - unsigned blank, temp; - - blank = 0x20 | ((unsigned)con->attrib << 8); - fb_adr = con->fb_adr; - - /** - * scroll up - */ - if(con->csr_y >= _vc_height) - { - temp = con->csr_y - _vc_height + 1; - memcpy(fb_adr, fb_adr + temp * _vc_width, - (_vc_height - temp) * _vc_width * 2); - - /** - * blank bottom line of screen - */ - memsetw(fb_adr + (_vc_height - temp) * _vc_width, - blank, _vc_width); - con->csr_y = _vc_height - 1; - } - - //for(i = 0; i < 0x1000000; i++) ; -} - -/** - * set_attrib() - * - */ -static void set_attrib(console_t *con, unsigned att) -{ - static const unsigned ansi_to_vga[] = - { - 0, 4, 2, 6, 1, 5, 3, 7 - }; - - unsigned new_att; - - new_att = con->attrib; - if(att == 0) - new_att &= ~0x08; /* bold off */ - else if(att == 1) - new_att |= 0x08; /* bold on */ - else if(att >= 30 && att <= 37) - { - att = ansi_to_vga[att - 30]; - new_att = (new_att & ~0x07) | att;/* fg color */ - } - else if(att >= 40 && att <= 47) - { - att = ansi_to_vga[att - 40] << 4; - new_att = (new_att & ~0x70) | att;/* bg color */ - } - con->attrib = new_att; -} - -/** - * move_csr() - * - */ -static void move_csr(void) -{ - unsigned temp; - - temp = (_curr_vc->csr_y * _vc_width + _curr_vc->csr_x) + - (_curr_vc->fb_adr - _vga_fb_adr); - outportb(_crtc_io_adr + 0, 14); - outportb(_crtc_io_adr + 1, temp >> 8); - outportb(_crtc_io_adr + 0, 15); - outportb(_crtc_io_adr + 1, temp); -} - - -/** - * select_vc() - * - */ -void select_vc(unsigned which_vc) -{ - unsigned i; - - if(which_vc >= _num_vcs) - return; - _curr_vc = _vc + which_vc; - i = _curr_vc->fb_adr - _vga_fb_adr; - outportb(_crtc_io_adr + 0, 12); - outportb(_crtc_io_adr + 1, i >> 8); - outportb(_crtc_io_adr + 0, 13); - outportb(_crtc_io_adr + 1, i); - - curr_vtty = which_vc; - - move_csr(); -} - -/** - * putch_help() - * - */ -void putch_help(console_t *con, unsigned c) -{ - unsigned short *fb_adr; - unsigned att; - - att = (unsigned)con->attrib << 8; - fb_adr = con->fb_adr; - - /** - * state machine to handle escape sequences - * - * ESC - */ - if(con->esc == 1) - { - if(c == '[') - { - con->esc++; - con->esc1 = 0; - return; - } - /* else fall-through: zero esc and print c */ - } - - /** - * ESC[ - */ - else if(con->esc == 2) - { - if(isdigit(c)) - { - con->esc1 = con->esc1 * 10 + c - '0'; - return; - } - else if(c == ';') - { - con->esc++; - con->esc2 = 0; - return; - } - - /** - * ESC[2J (clear screen) - */ - else if(c == 'J') - { - if(con->esc1 == 2) - { - memsetw(fb_adr, ' ' | att, - _vc_height * _vc_width); - con->csr_x = con->csr_y = 0; - } - } - - /** - * ESC[num1m (set attribute num1) - */ - else if(c == 'm') - set_attrib(con, con->esc1); - con->esc = 0; /* anything else with one numeric arg */ - return; - } - - /** - * ESC[num1 - */ - else if(con->esc == 3) - { - if(isdigit(c)) - { - con->esc2 = con->esc2 * 10 + c - '0'; - return; - } - else if(c == ';') - { - con->esc++; /* ESC[num1;num2; */ - con->esc3 = 0; - return; - } - - /** - * ESC[num1;num2H (move cursor to num1,num2) - */ - else if(c == 'H') - { - if(con->esc2 < _vc_width) - con->csr_x = con->esc2; - if(con->esc1 < _vc_height) - con->csr_y = con->esc1; - } - - /** - * ESC[num1;num2m (set attributes num1,num2) - */ - else if(c == 'm') - { - set_attrib(con, con->esc1); - set_attrib(con, con->esc2); - } - con->esc = 0; - return; - } - /** - * ESC[num1;num2;num3 - */ - else if(con->esc == 4) - { - if(isdigit(c)) - { - con->esc3 = con->esc3 * 10 + c - '0'; - return; - } - /** - * ESC[num1;num2;num3m (set attributes num1,num2,num3) - */ - else if(c == 'm') - { - set_attrib(con, con->esc1); - set_attrib(con, con->esc2); - set_attrib(con, con->esc3); - } - con->esc = 0; - return; - } - con->esc = 0; - - /** - * escape character - */ - if(c == 0x1B) - { - con->esc = 1; - return; - } - /** - * backspace - */ - if(c == 0x08) - { - if(con->csr_x != 0) - con->csr_x--; - } - /** - * tab - */ - else if(c == 0x09) - con->csr_x = (con->csr_x + 8) & ~(8 - 1); - /** - * carriage return - */ - else if(c == '\r') /* 0x0D */ - con->csr_x = 0; - /** - * line feed - */ -/* else if(c == '\n') *//* 0x0A */ -/* con->csr_y++;*/ - /** - * CR/LF - */ - else if(c == '\n') /* ### - 0x0A again */ - { - con->csr_x = 0; - con->csr_y++; - } - /** - * printable ASCII - */ - else if(c >= ' ') - { - unsigned short *where; - - where = fb_adr + (con->csr_y * _vc_width + con->csr_x); - *where = (c | att); - con->csr_x++; - } - if(con->csr_x >= _vc_width) - { - con->csr_x = 0; - con->csr_y++; - } - scroll(con); - - /** - * move cursor only if the VC we're writing is the current VC - */ - if(_curr_vc == con) - move_csr(); -} - -/** - * putch() - * - */ -void putch(unsigned c) -{ -/* all kernel messages to VC #0 */ -// putch_help(_vc + 0, c); -/* all kernel messages to current VC */ - putch_help(_curr_vc, c); -} - -/** - * init_video() - * - */ -void init_video(void) -{ - unsigned i; - - /** - * check for monochrome or color VGA emulation - */ - if((inportb(VGA_MISC_READ) & 0x01) != 0) - { - _vga_fb_adr = (unsigned short *)0xB8000L; - _crtc_io_adr = 0x3D4; - } - else - { - _vga_fb_adr = (unsigned short *)0xB0000L; - _crtc_io_adr = 0x3B4; - } - - /** - * read current screen size from BIOS data segment (addresses 400-4FF) - */ - _vc_width = *(unsigned short *)0x44A; - _vc_height = *(unsigned char *)0x484 + 1; - - /** - * figure out how many VCs we can have with 32K of display memory. - * Use INTEGER division to round down. - */ - _num_vcs = 32768L / (_vc_width * _vc_height * 2); - if(_num_vcs > MAX_VC) - _num_vcs = MAX_VC; - - /** - * init VCs, with a different foreground color for each - */ - for(i = 0; i < _num_vcs; i++) - { - _curr_vc = _vc + i; - //_curr_vc->attrib = i + 1; - - /* terminal foreground color */ - _curr_vc->attrib = 7; - _curr_vc->fb_adr = _vga_fb_adr + - _vc_width * _vc_height * i; - - /** - * ESC[2J clears the screen - */ - //kprintf("\x1B[2J this is VC#%u (of 0-%u)\n", - // i, _num_vcs - 1); - printf("\x1B[2J"); - - if(i != 0) - printf("$ "); - } - select_vc(0); - curr_vtty = 0; - - _curr_vc->attrib = 8; - printf("[ "); - _curr_vc->attrib = 15; - printf("init: video %5s emulation, %2ux%2u, framebuffer at 0x%1X ", - (_crtc_io_adr == 0x3D4) ? "color" : "mono", - _vc_width, _vc_height, _vga_fb_adr); - _curr_vc->attrib = 8; - printf("]................"); - _curr_vc->attrib = 2; - printf("Ok"); - _curr_vc->attrib = 7; -} +/** + * video.c + * + * Text video routines + * + * Exports: + * blink(); + * select_vc() + * putch_help() + * putch() + * init_video(); + * + * Imports: + * main.c printf(); + */ + +/** + * TODO + * + * Fuck me with a blind melon...when the screen scrolls + * too much, it generates a panic of type invalid opcode. + */ + +#include /* memcpy(), memsetw() */ +#include /* isdigit() */ +#include /* outportb(), inportb() */ +#include +#include "_krnl.h" /* MAX_VC, console_t */ + +/** + * Imports + */ +void printf(const char *fmt, ...); + +#define VGA_MISC_READ 0x3CC + +console_t _vc[MAX_VC]; +static unsigned _num_vcs; +static console_t *_curr_vc; + +static unsigned short *_vga_fb_adr; +static unsigned _crtc_io_adr, _vc_width, _vc_height; + +unsigned curr_vtty; + +/** + * blink() + * + */ +void blink(void) +{ + (*(unsigned char *)_vga_fb_adr)++; +} + +/** + * get_current_vc() + * + */ +unsigned get_current_vc() +{ + return curr_vtty; +} + +/** + * scroll() + * + */ +static void scroll(console_t *con) +{ + unsigned short *fb_adr; + unsigned blank, temp; + + blank = 0x20 | ((unsigned)con->attrib << 8); + fb_adr = con->fb_adr; + + /** + * scroll up + */ + if(con->csr_y >= _vc_height) + { + temp = con->csr_y - _vc_height + 1; + memcpy(fb_adr, fb_adr + temp * _vc_width, + (_vc_height - temp) * _vc_width * 2); + + /** + * blank bottom line of screen + */ + memsetw(fb_adr + (_vc_height - temp) * _vc_width, + blank, _vc_width); + con->csr_y = _vc_height - 1; + } + + //for(i = 0; i < 0x1000000; i++) ; +} + +/** + * set_attrib() + * + */ +static void set_attrib(console_t *con, unsigned att) +{ + static const unsigned ansi_to_vga[] = + { + 0, 4, 2, 6, 1, 5, 3, 7 + }; + + unsigned new_att; + + new_att = con->attrib; + if(att == 0) + new_att &= ~0x08; /* bold off */ + else if(att == 1) + new_att |= 0x08; /* bold on */ + else if(att >= 30 && att <= 37) + { + att = ansi_to_vga[att - 30]; + new_att = (new_att & ~0x07) | att;/* fg color */ + } + else if(att >= 40 && att <= 47) + { + att = ansi_to_vga[att - 40] << 4; + new_att = (new_att & ~0x70) | att;/* bg color */ + } + con->attrib = new_att; +} + +/** + * move_csr() + * + */ +static void move_csr(void) +{ + unsigned temp; + + temp = (_curr_vc->csr_y * _vc_width + _curr_vc->csr_x) + + (_curr_vc->fb_adr - _vga_fb_adr); + outportb(_crtc_io_adr + 0, 14); + outportb(_crtc_io_adr + 1, temp >> 8); + outportb(_crtc_io_adr + 0, 15); + outportb(_crtc_io_adr + 1, temp); +} + + +/** + * select_vc() + * + */ +void select_vc(unsigned which_vc) +{ + unsigned i; + + if(which_vc >= _num_vcs) + return; + _curr_vc = _vc + which_vc; + i = _curr_vc->fb_adr - _vga_fb_adr; + outportb(_crtc_io_adr + 0, 12); + outportb(_crtc_io_adr + 1, i >> 8); + outportb(_crtc_io_adr + 0, 13); + outportb(_crtc_io_adr + 1, i); + + curr_vtty = which_vc; + + move_csr(); +} + +/** + * putch_help() + * + */ +void putch_help(console_t *con, unsigned c) +{ + unsigned short *fb_adr; + unsigned att; + + att = (unsigned)con->attrib << 8; + fb_adr = con->fb_adr; + + /** + * state machine to handle escape sequences + * + * ESC + */ + if(con->esc == 1) + { + if(c == '[') + { + con->esc++; + con->esc1 = 0; + return; + } + /* else fall-through: zero esc and print c */ + } + + /** + * ESC[ + */ + else if(con->esc == 2) + { + if(isdigit(c)) + { + con->esc1 = con->esc1 * 10 + c - '0'; + return; + } + else if(c == ';') + { + con->esc++; + con->esc2 = 0; + return; + } + + /** + * ESC[2J (clear screen) + */ + else if(c == 'J') + { + if(con->esc1 == 2) + { + memsetw(fb_adr, ' ' | att, + _vc_height * _vc_width); + con->csr_x = con->csr_y = 0; + } + } + + /** + * ESC[num1m (set attribute num1) + */ + else if(c == 'm') + set_attrib(con, con->esc1); + con->esc = 0; /* anything else with one numeric arg */ + return; + } + + /** + * ESC[num1 + */ + else if(con->esc == 3) + { + if(isdigit(c)) + { + con->esc2 = con->esc2 * 10 + c - '0'; + return; + } + else if(c == ';') + { + con->esc++; /* ESC[num1;num2; */ + con->esc3 = 0; + return; + } + + /** + * ESC[num1;num2H (move cursor to num1,num2) + */ + else if(c == 'H') + { + if(con->esc2 < _vc_width) + con->csr_x = con->esc2; + if(con->esc1 < _vc_height) + con->csr_y = con->esc1; + } + + /** + * ESC[num1;num2m (set attributes num1,num2) + */ + else if(c == 'm') + { + set_attrib(con, con->esc1); + set_attrib(con, con->esc2); + } + con->esc = 0; + return; + } + /** + * ESC[num1;num2;num3 + */ + else if(con->esc == 4) + { + if(isdigit(c)) + { + con->esc3 = con->esc3 * 10 + c - '0'; + return; + } + /** + * ESC[num1;num2;num3m (set attributes num1,num2,num3) + */ + else if(c == 'm') + { + set_attrib(con, con->esc1); + set_attrib(con, con->esc2); + set_attrib(con, con->esc3); + } + con->esc = 0; + return; + } + con->esc = 0; + + /** + * escape character + */ + if(c == 0x1B) + { + con->esc = 1; + return; + } + /** + * backspace + */ + if(c == 0x08) + { + if(con->csr_x != 0) + con->csr_x--; + } + /** + * tab + */ + else if(c == 0x09) + con->csr_x = (con->csr_x + 8) & ~(8 - 1); + /** + * carriage return + */ + else if(c == '\r') /* 0x0D */ + con->csr_x = 0; + /** + * line feed + */ +/* else if(c == '\n') *//* 0x0A */ +/* con->csr_y++;*/ + /** + * CR/LF + */ + else if(c == '\n') /* ### - 0x0A again */ + { + con->csr_x = 0; + con->csr_y++; + } + /** + * printable ASCII + */ + else if(c >= ' ') + { + unsigned short *where; + + where = fb_adr + (con->csr_y * _vc_width + con->csr_x); + *where = (c | att); + con->csr_x++; + } + if(con->csr_x >= _vc_width) + { + con->csr_x = 0; + con->csr_y++; + } + scroll(con); + + /** + * move cursor only if the VC we're writing is the current VC + */ + if(_curr_vc == con) + move_csr(); +} + +/** + * putch() + * + */ +void putch(unsigned c) +{ +/* all kernel messages to VC #0 */ +// putch_help(_vc + 0, c); +/* all kernel messages to current VC */ + putch_help(_curr_vc, c); +} + +/** + * init_video() + * + */ +void init_video(void) +{ + unsigned i; + + /** + * check for monochrome or color VGA emulation + */ + if((inportb(VGA_MISC_READ) & 0x01) != 0) + { + _vga_fb_adr = (unsigned short *)0xB8000L; + _crtc_io_adr = 0x3D4; + } + else + { + _vga_fb_adr = (unsigned short *)0xB0000L; + _crtc_io_adr = 0x3B4; + } + + /** + * read current screen size from BIOS data segment (addresses 400-4FF) + */ + _vc_width = *(unsigned short *)0x44A; + _vc_height = *(unsigned char *)0x484 + 1; + + /** + * figure out how many VCs we can have with 32K of display memory. + * Use INTEGER division to round down. + */ + _num_vcs = 32768L / (_vc_width * _vc_height * 2); + if(_num_vcs > MAX_VC) + _num_vcs = MAX_VC; + + /** + * init VCs, with a different foreground color for each + */ + for(i = 0; i < _num_vcs; i++) + { + _curr_vc = _vc + i; + //_curr_vc->attrib = i + 1; + + /* terminal foreground color */ + _curr_vc->attrib = 7; + _curr_vc->fb_adr = _vga_fb_adr + + _vc_width * _vc_height * i; + + /** + * ESC[2J clears the screen + */ + //kprintf("\x1B[2J this is VC#%u (of 0-%u)\n", + // i, _num_vcs - 1); + printf("\x1B[2J"); + + if(i != 0) + printf("$ "); + } + select_vc(0); + curr_vtty = 0; + + _curr_vc->attrib = 8; + printf("[ "); + _curr_vc->attrib = 15; + printf("init: video %5s emulation, %2ux%2u, framebuffer at 0x%1X ", + (_crtc_io_adr == 0x3D4) ? "color" : "mono", + _vc_width, _vc_height, _vga_fb_adr); + _curr_vc->attrib = 8; + printf("]................"); + _curr_vc->attrib = 2; + printf("Ok"); + _curr_vc->attrib = 7; +} diff --git a/Dump/hybos/src/keymaps/us-std.h b/Dump/hybos/src/keymaps/us-std.h index 2ee2ccf..f5f2e4a 100644 --- a/Dump/hybos/src/keymaps/us-std.h +++ b/Dump/hybos/src/keymaps/us-std.h @@ -1,136 +1,136 @@ -/* Keymap for US MF-2 keyboard. */ -#include - -uint16_t keymap[NR_SCAN_CODES * MAP_COLS] = { - -/* scan-code !Shift Shift Alt1 Alt2 Alt+Sh Ctrl */ -/* ==================================================================== */ -/* 00 - none */ 0, 0, 0, 0, 0, 0, -/* 01 - ESC */ C('['), C('['), CA('['),CA('['),CA('['),C('['), -/* 02 - '1' */ '1', '!', A('1'), A('1'), A('!'), C('A'), -/* 03 - '2' */ '2', '@', A('2'), A('2'), A('@'), C('@'), -/* 04 - '3' */ '3', '#', A('3'), A('3'), A('#'), C('C'), -/* 05 - '4' */ '4', '$', A('4'), A('4'), A('$'), C('D'), -/* 06 - '5' */ '5', '%', A('5'), A('5'), A('%'), C('E'), -/* 07 - '6' */ '6', '^', A('6'), A('6'), A('^'), C('^'), -/* 08 - '7' */ '7', '&', A('7'), A('7'), A('&'), C('G'), -/* 09 - '8' */ '8', '*', A('8'), A('8'), A('*'), C('H'), -/* 10 - '9' */ '9', '(', A('9'), A('9'), A('('), C('I'), -/* 11 - '0' */ '0', ')', A('0'), A('0'), A(')'), C('@'), -/* 12 - '-' */ '-', '_', A('-'), A('-'), A('_'), C('_'), -/* 13 - '=' */ '=', '+', A('='), A('='), A('+'), C('@'), -/* 14 - BS */ C('H'), C('H'), CA('H'),CA('H'),CA('H'),0177, -/* 15 - TAB */ C('I'), C('I'), CA('I'),CA('I'),CA('I'),C('I'), -/* 16 - 'q' */ L('q'), 'Q', A('q'), A('q'), A('Q'), C('Q'), -/* 17 - 'w' */ L('w'), 'W', A('w'), A('w'), A('W'), C('W'), -/* 18 - 'e' */ L('e'), 'E', A('e'), A('e'), A('E'), C('E'), -/* 19 - 'r' */ L('r'), 'R', A('r'), A('r'), A('R'), C('R'), -/* 20 - 't' */ L('t'), 'T', A('t'), A('t'), A('T'), C('T'), -/* 21 - 'y' */ L('y'), 'Y', A('y'), A('y'), A('Y'), C('Y'), -/* 22 - 'u' */ L('u'), 'U', A('u'), A('u'), A('U'), C('U'), -/* 23 - 'i' */ L('i'), 'I', A('i'), A('i'), A('I'), C('I'), -/* 24 - 'o' */ L('o'), 'O', A('o'), A('o'), A('O'), C('O'), -/* 25 - 'p' */ L('p'), 'P', A('p'), A('p'), A('P'), C('P'), -/* 26 - '[' */ '[', '{', A('['), A('['), A('{'), C('['), -/* 27 - ']' */ ']', '}', A(']'), A(']'), A('}'), C(']'), -/* 28 - CR/LF */ C('M'), C('M'), CA('M'),CA('M'),CA('M'),C('J'), -/* 29 - Ctrl */ CTRL, CTRL, CTRL, CTRL, CTRL, CTRL, -/* 30 - 'a' */ L('a'), 'A', A('a'), A('a'), A('A'), C('A'), -/* 31 - 's' */ L('s'), 'S', A('s'), A('s'), A('S'), C('S'), -/* 32 - 'd' */ L('d'), 'D', A('d'), A('d'), A('D'), C('D'), -/* 33 - 'f' */ L('f'), 'F', A('f'), A('f'), A('F'), C('F'), -/* 34 - 'g' */ L('g'), 'G', A('g'), A('g'), A('G'), C('G'), -/* 35 - 'h' */ L('h'), 'H', A('h'), A('h'), A('H'), C('H'), -/* 36 - 'j' */ L('j'), 'J', A('j'), A('j'), A('J'), C('J'), -/* 37 - 'k' */ L('k'), 'K', A('k'), A('k'), A('K'), C('K'), -/* 38 - 'l' */ L('l'), 'L', A('l'), A('l'), A('L'), C('L'), -/* 39 - ';' */ ';', ':', A(';'), A(';'), A(':'), C('@'), -/* 40 - '\'' */ '\'', '"', A('\''),A('\''),A('"'), C('@'), -/* 41 - '`' */ '`', '~', A('`'), A('`'), A('~'), C('@'), -/* 42 - l. SHIFT*/ SHIFT, SHIFT, SHIFT, SHIFT, SHIFT, SHIFT, -/* 43 - '\\' */ '\\', '|', A('\\'),A('\\'),A('|'), C('\\'), -/* 44 - 'z' */ L('z'), 'Z', A('z'), A('z'), A('Z'), C('Z'), -/* 45 - 'x' */ L('x'), 'X', A('x'), A('x'), A('X'), C('X'), -/* 46 - 'c' */ L('c'), 'C', A('c'), A('c'), A('C'), C('C'), -/* 47 - 'v' */ L('v'), 'V', A('v'), A('v'), A('V'), C('V'), -/* 48 - 'b' */ L('b'), 'B', A('b'), A('b'), A('B'), C('B'), -/* 49 - 'n' */ L('n'), 'N', A('n'), A('n'), A('N'), C('N'), -/* 50 - 'm' */ L('m'), 'M', A('m'), A('m'), A('M'), C('M'), -/* 51 - ',' */ ',', '<', A(','), A(','), A('<'), C('@'), -/* 52 - '.' */ '.', '>', A('.'), A('.'), A('>'), C('@'), -/* 53 - '/' */ '/', '?', A('/'), A('/'), A('?'), C('@'), -/* 54 - r. SHIFT*/ SHIFT, SHIFT, SHIFT, SHIFT, SHIFT, SHIFT, -/* 55 - '*' */ '*', '*', A('*'), A('*'), A('*'), C('@'), -/* 56 - ALT */ ALT, ALT, ALT, ALT, ALT, ALT, -/* 57 - ' ' */ ' ', ' ', A(' '), A(' '), A(' '), C('@'), -/* 58 - CapsLck */ CALOCK, CALOCK, CALOCK, CALOCK, CALOCK, CALOCK, -/* 59 - F1 */ F1, SF1, AF1, AF1, ASF1, CF1, -/* 60 - F2 */ F2, SF2, AF2, AF2, ASF2, CF2, -/* 61 - F3 */ F3, SF3, AF3, AF3, ASF3, CF3, -/* 62 - F4 */ F4, SF4, AF4, AF4, ASF4, CF4, -/* 63 - F5 */ F5, SF5, AF5, AF5, ASF5, CF5, -/* 64 - F6 */ F6, SF6, AF6, AF6, ASF6, CF6, -/* 65 - F7 */ F7, SF7, AF7, AF7, ASF7, CF7, -/* 66 - F8 */ F8, SF8, AF8, AF8, ASF8, CF8, -/* 67 - F9 */ F9, SF9, AF9, AF9, ASF9, CF9, -/* 68 - F10 */ F10, SF10, AF10, AF10, ASF10, CF10, -/* 69 - NumLock */ NLOCK, NLOCK, NLOCK, NLOCK, NLOCK, NLOCK, -/* 70 - ScrLock */ SLOCK, SLOCK, SLOCK, SLOCK, SLOCK, SLOCK, -/* 71 - Home */ HOME, '7', AHOME, AHOME, A('7'), CHOME, -/* 72 - CurUp */ UP, '8', AUP, AUP, A('8'), CUP, -/* 73 - PgUp */ PGUP, '9', APGUP, APGUP, A('9'), CPGUP, -/* 74 - '-' */ NMIN, '-', ANMIN, ANMIN, A('-'), CNMIN, -/* 75 - Left */ LEFT, '4', ALEFT, ALEFT, A('4'), CLEFT, -/* 76 - MID */ MID, '5', AMID, AMID, A('5'), CMID, -/* 77 - Right */ RIGHT, '6', ARIGHT, ARIGHT, A('6'), CRIGHT, -/* 78 - '+' */ PLUS, '+', APLUS, APLUS, A('+'), CPLUS, -/* 79 - End */ END, '1', AEND, AEND, A('1'), CEND, -/* 80 - Down */ DOWN, '2', ADOWN, ADOWN, A('2'), CDOWN, -/* 81 - PgDown */ PGDN, '3', APGDN, APGDN, A('3'), CPGDN, -/* 82 - Insert */ INSRT, '0', AINSRT, AINSRT, A('0'), CINSRT, -/* 83 - Delete */ 0177, '.', A(0177),A(0177),A('.'), 0177, -/* 84 - Enter */ C('M'), C('M'), CA('M'),CA('M'),CA('M'),C('J'), -/* 85 - ??? */ 0, 0, 0, 0, 0, 0, -/* 86 - ??? */ '<', '>', A('<'), A('|'), A('>'), C('@'), -/* 87 - F11 */ F11, SF11, AF11, AF11, ASF11, CF11, -/* 88 - F12 */ F12, SF12, AF12, AF12, ASF12, CF12, -/* 89 - ??? */ 0, 0, 0, 0, 0, 0, -/* 90 - ??? */ 0, 0, 0, 0, 0, 0, -/* 91 - ??? */ 0, 0, 0, 0, 0, 0, -/* 92 - ??? */ 0, 0, 0, 0, 0, 0, -/* 93 - ??? */ 0, 0, 0, 0, 0, 0, -/* 94 - ??? */ 0, 0, 0, 0, 0, 0, -/* 95 - ??? */ 0, 0, 0, 0, 0, 0, -/* 96 - EXT_KEY */ EXTKEY, EXTKEY, EXTKEY, EXTKEY, EXTKEY, EXTKEY, -/* 97 - ??? */ 0, 0, 0, 0, 0, 0, -/* 98 - ??? */ 0, 0, 0, 0, 0, 0, -/* 99 - ??? */ 0, 0, 0, 0, 0, 0, -/*100 - ??? */ 0, 0, 0, 0, 0, 0, -/*101 - ??? */ 0, 0, 0, 0, 0, 0, -/*102 - ??? */ 0, 0, 0, 0, 0, 0, -/*103 - ??? */ 0, 0, 0, 0, 0, 0, -/*104 - ??? */ 0, 0, 0, 0, 0, 0, -/*105 - ??? */ 0, 0, 0, 0, 0, 0, -/*106 - ??? */ 0, 0, 0, 0, 0, 0, -/*107 - ??? */ 0, 0, 0, 0, 0, 0, -/*108 - ??? */ 0, 0, 0, 0, 0, 0, -/*109 - ??? */ 0, 0, 0, 0, 0, 0, -/*110 - ??? */ 0, 0, 0, 0, 0, 0, -/*111 - ??? */ 0, 0, 0, 0, 0, 0, -/*112 - ??? */ 0, 0, 0, 0, 0, 0, -/*113 - ??? */ 0, 0, 0, 0, 0, 0, -/*114 - ??? */ 0, 0, 0, 0, 0, 0, -/*115 - ??? */ 0, 0, 0, 0, 0, 0, -/*116 - ??? */ 0, 0, 0, 0, 0, 0, -/*117 - ??? */ 0, 0, 0, 0, 0, 0, -/*118 - ??? */ 0, 0, 0, 0, 0, 0, -/*119 - ??? */ 0, 0, 0, 0, 0, 0, -/*120 - ??? */ 0, 0, 0, 0, 0, 0, -/*121 - ??? */ 0, 0, 0, 0, 0, 0, -/*122 - ??? */ 0, 0, 0, 0, 0, 0, -/*123 - ??? */ 0, 0, 0, 0, 0, 0, -/*124 - ??? */ 0, 0, 0, 0, 0, 0, -/*125 - ??? */ 0, 0, 0, 0, 0, 0, -/*126 - ??? */ 0, 0, 0, 0, 0, 0, -/*127 - ??? */ 0, 0, 0, 0, 0, 0 -}; +/* Keymap for US MF-2 keyboard. */ +#include + +uint16_t keymap[NR_SCAN_CODES * MAP_COLS] = { + +/* scan-code !Shift Shift Alt1 Alt2 Alt+Sh Ctrl */ +/* ==================================================================== */ +/* 00 - none */ 0, 0, 0, 0, 0, 0, +/* 01 - ESC */ C('['), C('['), CA('['),CA('['),CA('['),C('['), +/* 02 - '1' */ '1', '!', A('1'), A('1'), A('!'), C('A'), +/* 03 - '2' */ '2', '@', A('2'), A('2'), A('@'), C('@'), +/* 04 - '3' */ '3', '#', A('3'), A('3'), A('#'), C('C'), +/* 05 - '4' */ '4', '$', A('4'), A('4'), A('$'), C('D'), +/* 06 - '5' */ '5', '%', A('5'), A('5'), A('%'), C('E'), +/* 07 - '6' */ '6', '^', A('6'), A('6'), A('^'), C('^'), +/* 08 - '7' */ '7', '&', A('7'), A('7'), A('&'), C('G'), +/* 09 - '8' */ '8', '*', A('8'), A('8'), A('*'), C('H'), +/* 10 - '9' */ '9', '(', A('9'), A('9'), A('('), C('I'), +/* 11 - '0' */ '0', ')', A('0'), A('0'), A(')'), C('@'), +/* 12 - '-' */ '-', '_', A('-'), A('-'), A('_'), C('_'), +/* 13 - '=' */ '=', '+', A('='), A('='), A('+'), C('@'), +/* 14 - BS */ C('H'), C('H'), CA('H'),CA('H'),CA('H'),0177, +/* 15 - TAB */ C('I'), C('I'), CA('I'),CA('I'),CA('I'),C('I'), +/* 16 - 'q' */ L('q'), 'Q', A('q'), A('q'), A('Q'), C('Q'), +/* 17 - 'w' */ L('w'), 'W', A('w'), A('w'), A('W'), C('W'), +/* 18 - 'e' */ L('e'), 'E', A('e'), A('e'), A('E'), C('E'), +/* 19 - 'r' */ L('r'), 'R', A('r'), A('r'), A('R'), C('R'), +/* 20 - 't' */ L('t'), 'T', A('t'), A('t'), A('T'), C('T'), +/* 21 - 'y' */ L('y'), 'Y', A('y'), A('y'), A('Y'), C('Y'), +/* 22 - 'u' */ L('u'), 'U', A('u'), A('u'), A('U'), C('U'), +/* 23 - 'i' */ L('i'), 'I', A('i'), A('i'), A('I'), C('I'), +/* 24 - 'o' */ L('o'), 'O', A('o'), A('o'), A('O'), C('O'), +/* 25 - 'p' */ L('p'), 'P', A('p'), A('p'), A('P'), C('P'), +/* 26 - '[' */ '[', '{', A('['), A('['), A('{'), C('['), +/* 27 - ']' */ ']', '}', A(']'), A(']'), A('}'), C(']'), +/* 28 - CR/LF */ C('M'), C('M'), CA('M'),CA('M'),CA('M'),C('J'), +/* 29 - Ctrl */ CTRL, CTRL, CTRL, CTRL, CTRL, CTRL, +/* 30 - 'a' */ L('a'), 'A', A('a'), A('a'), A('A'), C('A'), +/* 31 - 's' */ L('s'), 'S', A('s'), A('s'), A('S'), C('S'), +/* 32 - 'd' */ L('d'), 'D', A('d'), A('d'), A('D'), C('D'), +/* 33 - 'f' */ L('f'), 'F', A('f'), A('f'), A('F'), C('F'), +/* 34 - 'g' */ L('g'), 'G', A('g'), A('g'), A('G'), C('G'), +/* 35 - 'h' */ L('h'), 'H', A('h'), A('h'), A('H'), C('H'), +/* 36 - 'j' */ L('j'), 'J', A('j'), A('j'), A('J'), C('J'), +/* 37 - 'k' */ L('k'), 'K', A('k'), A('k'), A('K'), C('K'), +/* 38 - 'l' */ L('l'), 'L', A('l'), A('l'), A('L'), C('L'), +/* 39 - ';' */ ';', ':', A(';'), A(';'), A(':'), C('@'), +/* 40 - '\'' */ '\'', '"', A('\''),A('\''),A('"'), C('@'), +/* 41 - '`' */ '`', '~', A('`'), A('`'), A('~'), C('@'), +/* 42 - l. SHIFT*/ SHIFT, SHIFT, SHIFT, SHIFT, SHIFT, SHIFT, +/* 43 - '\\' */ '\\', '|', A('\\'),A('\\'),A('|'), C('\\'), +/* 44 - 'z' */ L('z'), 'Z', A('z'), A('z'), A('Z'), C('Z'), +/* 45 - 'x' */ L('x'), 'X', A('x'), A('x'), A('X'), C('X'), +/* 46 - 'c' */ L('c'), 'C', A('c'), A('c'), A('C'), C('C'), +/* 47 - 'v' */ L('v'), 'V', A('v'), A('v'), A('V'), C('V'), +/* 48 - 'b' */ L('b'), 'B', A('b'), A('b'), A('B'), C('B'), +/* 49 - 'n' */ L('n'), 'N', A('n'), A('n'), A('N'), C('N'), +/* 50 - 'm' */ L('m'), 'M', A('m'), A('m'), A('M'), C('M'), +/* 51 - ',' */ ',', '<', A(','), A(','), A('<'), C('@'), +/* 52 - '.' */ '.', '>', A('.'), A('.'), A('>'), C('@'), +/* 53 - '/' */ '/', '?', A('/'), A('/'), A('?'), C('@'), +/* 54 - r. SHIFT*/ SHIFT, SHIFT, SHIFT, SHIFT, SHIFT, SHIFT, +/* 55 - '*' */ '*', '*', A('*'), A('*'), A('*'), C('@'), +/* 56 - ALT */ ALT, ALT, ALT, ALT, ALT, ALT, +/* 57 - ' ' */ ' ', ' ', A(' '), A(' '), A(' '), C('@'), +/* 58 - CapsLck */ CALOCK, CALOCK, CALOCK, CALOCK, CALOCK, CALOCK, +/* 59 - F1 */ F1, SF1, AF1, AF1, ASF1, CF1, +/* 60 - F2 */ F2, SF2, AF2, AF2, ASF2, CF2, +/* 61 - F3 */ F3, SF3, AF3, AF3, ASF3, CF3, +/* 62 - F4 */ F4, SF4, AF4, AF4, ASF4, CF4, +/* 63 - F5 */ F5, SF5, AF5, AF5, ASF5, CF5, +/* 64 - F6 */ F6, SF6, AF6, AF6, ASF6, CF6, +/* 65 - F7 */ F7, SF7, AF7, AF7, ASF7, CF7, +/* 66 - F8 */ F8, SF8, AF8, AF8, ASF8, CF8, +/* 67 - F9 */ F9, SF9, AF9, AF9, ASF9, CF9, +/* 68 - F10 */ F10, SF10, AF10, AF10, ASF10, CF10, +/* 69 - NumLock */ NLOCK, NLOCK, NLOCK, NLOCK, NLOCK, NLOCK, +/* 70 - ScrLock */ SLOCK, SLOCK, SLOCK, SLOCK, SLOCK, SLOCK, +/* 71 - Home */ HOME, '7', AHOME, AHOME, A('7'), CHOME, +/* 72 - CurUp */ UP, '8', AUP, AUP, A('8'), CUP, +/* 73 - PgUp */ PGUP, '9', APGUP, APGUP, A('9'), CPGUP, +/* 74 - '-' */ NMIN, '-', ANMIN, ANMIN, A('-'), CNMIN, +/* 75 - Left */ LEFT, '4', ALEFT, ALEFT, A('4'), CLEFT, +/* 76 - MID */ MID, '5', AMID, AMID, A('5'), CMID, +/* 77 - Right */ RIGHT, '6', ARIGHT, ARIGHT, A('6'), CRIGHT, +/* 78 - '+' */ PLUS, '+', APLUS, APLUS, A('+'), CPLUS, +/* 79 - End */ END, '1', AEND, AEND, A('1'), CEND, +/* 80 - Down */ DOWN, '2', ADOWN, ADOWN, A('2'), CDOWN, +/* 81 - PgDown */ PGDN, '3', APGDN, APGDN, A('3'), CPGDN, +/* 82 - Insert */ INSRT, '0', AINSRT, AINSRT, A('0'), CINSRT, +/* 83 - Delete */ 0177, '.', A(0177),A(0177),A('.'), 0177, +/* 84 - Enter */ C('M'), C('M'), CA('M'),CA('M'),CA('M'),C('J'), +/* 85 - ??? */ 0, 0, 0, 0, 0, 0, +/* 86 - ??? */ '<', '>', A('<'), A('|'), A('>'), C('@'), +/* 87 - F11 */ F11, SF11, AF11, AF11, ASF11, CF11, +/* 88 - F12 */ F12, SF12, AF12, AF12, ASF12, CF12, +/* 89 - ??? */ 0, 0, 0, 0, 0, 0, +/* 90 - ??? */ 0, 0, 0, 0, 0, 0, +/* 91 - ??? */ 0, 0, 0, 0, 0, 0, +/* 92 - ??? */ 0, 0, 0, 0, 0, 0, +/* 93 - ??? */ 0, 0, 0, 0, 0, 0, +/* 94 - ??? */ 0, 0, 0, 0, 0, 0, +/* 95 - ??? */ 0, 0, 0, 0, 0, 0, +/* 96 - EXT_KEY */ EXTKEY, EXTKEY, EXTKEY, EXTKEY, EXTKEY, EXTKEY, +/* 97 - ??? */ 0, 0, 0, 0, 0, 0, +/* 98 - ??? */ 0, 0, 0, 0, 0, 0, +/* 99 - ??? */ 0, 0, 0, 0, 0, 0, +/*100 - ??? */ 0, 0, 0, 0, 0, 0, +/*101 - ??? */ 0, 0, 0, 0, 0, 0, +/*102 - ??? */ 0, 0, 0, 0, 0, 0, +/*103 - ??? */ 0, 0, 0, 0, 0, 0, +/*104 - ??? */ 0, 0, 0, 0, 0, 0, +/*105 - ??? */ 0, 0, 0, 0, 0, 0, +/*106 - ??? */ 0, 0, 0, 0, 0, 0, +/*107 - ??? */ 0, 0, 0, 0, 0, 0, +/*108 - ??? */ 0, 0, 0, 0, 0, 0, +/*109 - ??? */ 0, 0, 0, 0, 0, 0, +/*110 - ??? */ 0, 0, 0, 0, 0, 0, +/*111 - ??? */ 0, 0, 0, 0, 0, 0, +/*112 - ??? */ 0, 0, 0, 0, 0, 0, +/*113 - ??? */ 0, 0, 0, 0, 0, 0, +/*114 - ??? */ 0, 0, 0, 0, 0, 0, +/*115 - ??? */ 0, 0, 0, 0, 0, 0, +/*116 - ??? */ 0, 0, 0, 0, 0, 0, +/*117 - ??? */ 0, 0, 0, 0, 0, 0, +/*118 - ??? */ 0, 0, 0, 0, 0, 0, +/*119 - ??? */ 0, 0, 0, 0, 0, 0, +/*120 - ??? */ 0, 0, 0, 0, 0, 0, +/*121 - ??? */ 0, 0, 0, 0, 0, 0, +/*122 - ??? */ 0, 0, 0, 0, 0, 0, +/*123 - ??? */ 0, 0, 0, 0, 0, 0, +/*124 - ??? */ 0, 0, 0, 0, 0, 0, +/*125 - ??? */ 0, 0, 0, 0, 0, 0, +/*126 - ??? */ 0, 0, 0, 0, 0, 0, +/*127 - ??? */ 0, 0, 0, 0, 0, 0 +}; diff --git a/Dump/hybos/src/krnl1m.ld b/Dump/hybos/src/krnl1m.ld index 8f957cb..36aa3bb 100644 --- a/Dump/hybos/src/krnl1m.ld +++ b/Dump/hybos/src/krnl1m.ld @@ -1,55 +1,55 @@ -/* let the linker use its 'native' format (ELF/COFF/PE) -OUTPUT_FORMAT("coff-go32") */ -/* no leading underscore for symbols handled in asm: */ -ENTRY(entry) -LS_Phys = 0x100000; /* 1 meg = load (physical) address */ -LS_Virt = 0x100000; /* 1 meg = virtual address */ -/*LS_Phys = 0x300000;*/ /* 3 meg = load (physical) address */ -/*LS_Virt = 0x300000;*/ /* 3 meg = virtual address */ - -SECTIONS -{ - .text LS_Virt : AT(LS_Phys) - { - LS_Code = .; -/* symbols to mark start of code segment */ - code = .; _code = .; -/* kernel code */ - *(.text) -/* .rodata is the ELF constant data section */ - *(.rodata*) - . = ALIGN(4096); - } - .data : AT(LS_Phys + (LS_Data - LS_Code)) - { - LS_Data = .; -/* symbols to mark start of data segment */ - data = .; _data = .; -/* kernel data */ -/* OLD: . = ALIGN(4096) */ - *(.data) - . = ALIGN(4096); - } - .bss : AT(LS_Phys + (LS_Bss - LS_Code)) - { - LS_Bss = .; -/* symbols to mark start of BSS segment */ - bss = .; _bss = .; -/* kernel BSS */ - *(.bss) - *(COMMON) /* "common" variables */ - . = ALIGN(4096); - } -/* bug in MinGW? I get a bad executable file unless these -sections are here... */ - .stab : - { - *(.stab) - } - .stabstr : - { - *(.stabstr) - } -/* symbols to mark end of kernel */ - end = .; _end = .; -} +/* let the linker use its 'native' format (ELF/COFF/PE) +OUTPUT_FORMAT("coff-go32") */ +/* no leading underscore for symbols handled in asm: */ +ENTRY(entry) +LS_Phys = 0x100000; /* 1 meg = load (physical) address */ +LS_Virt = 0x100000; /* 1 meg = virtual address */ +/*LS_Phys = 0x300000;*/ /* 3 meg = load (physical) address */ +/*LS_Virt = 0x300000;*/ /* 3 meg = virtual address */ + +SECTIONS +{ + .text LS_Virt : AT(LS_Phys) + { + LS_Code = .; +/* symbols to mark start of code segment */ + code = .; _code = .; +/* kernel code */ + *(.text) +/* .rodata is the ELF constant data section */ + *(.rodata*) + . = ALIGN(4096); + } + .data : AT(LS_Phys + (LS_Data - LS_Code)) + { + LS_Data = .; +/* symbols to mark start of data segment */ + data = .; _data = .; +/* kernel data */ +/* OLD: . = ALIGN(4096) */ + *(.data) + . = ALIGN(4096); + } + .bss : AT(LS_Phys + (LS_Bss - LS_Code)) + { + LS_Bss = .; +/* symbols to mark start of BSS segment */ + bss = .; _bss = .; +/* kernel BSS */ + *(.bss) + *(COMMON) /* "common" variables */ + . = ALIGN(4096); + } +/* bug in MinGW? I get a bad executable file unless these +sections are here... */ + .stab : + { + *(.stab) + } + .stabstr : + { + *(.stabstr) + } +/* symbols to mark end of kernel */ + end = .; _end = .; +} diff --git a/Dump/hybos/src/mm/memory.c b/Dump/hybos/src/mm/memory.c index 921531d..d533fd7 100644 --- a/Dump/hybos/src/mm/memory.c +++ b/Dump/hybos/src/mm/memory.c @@ -1,118 +1,118 @@ -#include -#include "../kernel/bootlog.h" - -extern console_t _vc[]; - -unsigned *buffer; -unsigned *bufferIterator; - -#define PAGESIZE 4096 - -char ts[4096*3]; -char td[4096*3]; - -void _mm_physical_init(void); -unsigned _mm_physical_alloc(void); -void _mm_physical_free(unsigned page); -void _mm_page_copy_byte(uint32_t dest, uint32_t src); -void _mm_page_copy_word(uint32_t dest, uint32_t src); -void _mm_page_copy_dword(uint32_t dest, uint32_t src); -void _mm_virtual_init(void); - -void _mm_init(void) -{ - klog("init", "Initializing memory management", K_KLOG_PENDING, &_vc[0]); - _mm_physical_init(); - _mm_virtual_init(); - klog((void *)0, (void *)0, K_KLOG_SUCCESS, &_vc[0]); -} - -void _mm_physical_init(void) -{ - unsigned i; - unsigned size = 16 * 1024 * 1024; - - size /= PAGESIZE; - size++; - size /= 32; - - buffer = (unsigned *)0x40000; - bufferIterator = (unsigned *)0x40000; - - for(i = 0; i < 72; i++) - buffer[i] = 0xFFFFFFFF; - - for(i = 72; i < size; i++) - buffer[i] = 0x00000000; -} - -unsigned _mm_physical_alloc(void) -{ - unsigned mask = 0x00000001; - unsigned bit = 0; - - /** - * Search for a free space - */ - while(*bufferIterator == 0xFFFFFFFF) - bufferIterator++; - - /** - * Search for a bit that indicates a free page - */ - while(*bufferIterator & mask) - { - mask <<= 1; - bit++; - } - - *bufferIterator |= mask; - - return 32 * (bufferIterator - buffer) + bit; -} - -void _mm_physical_free(unsigned page) -{ - buffer[page >> 5] &= ~(1 << (page & 0x1F)); /* confused yet?!? */ -} - -void _mm_virtual_init(void) -{ -} - -void _mm_page_copy_byte(uint32_t dest, uint32_t src) -{ - __asm__ __volatile__ - ( - "cld;" - "rep; movsb;" - : - : "c" (1024*1024), "D" (dest), "S" (src) - : "memory" - ); -} - -void _mm_page_copy_word(uint32_t dest, uint32_t src) -{ - __asm__ __volatile__ - ( - "cld;" - "rep; movsw;" - : - : "c" (512*1024), "D" (dest), "S" (src) - : "memory" - ); -} - -void _mm_page_copy_dword(uint32_t dest, uint32_t src) -{ - __asm__ __volatile__ - ( - "cld;" - "rep; movsl;" - : - : "c" (256*1024), "D" (dest), "S" (src) - : "memory" - ); -} - +#include +#include "../kernel/bootlog.h" + +extern console_t _vc[]; + +unsigned *buffer; +unsigned *bufferIterator; + +#define PAGESIZE 4096 + +char ts[4096*3]; +char td[4096*3]; + +void _mm_physical_init(void); +unsigned _mm_physical_alloc(void); +void _mm_physical_free(unsigned page); +void _mm_page_copy_byte(uint32_t dest, uint32_t src); +void _mm_page_copy_word(uint32_t dest, uint32_t src); +void _mm_page_copy_dword(uint32_t dest, uint32_t src); +void _mm_virtual_init(void); + +void _mm_init(void) +{ + klog("init", "Initializing memory management", K_KLOG_PENDING, &_vc[0]); + _mm_physical_init(); + _mm_virtual_init(); + klog((void *)0, (void *)0, K_KLOG_SUCCESS, &_vc[0]); +} + +void _mm_physical_init(void) +{ + unsigned i; + unsigned size = 16 * 1024 * 1024; + + size /= PAGESIZE; + size++; + size /= 32; + + buffer = (unsigned *)0x40000; + bufferIterator = (unsigned *)0x40000; + + for(i = 0; i < 72; i++) + buffer[i] = 0xFFFFFFFF; + + for(i = 72; i < size; i++) + buffer[i] = 0x00000000; +} + +unsigned _mm_physical_alloc(void) +{ + unsigned mask = 0x00000001; + unsigned bit = 0; + + /** + * Search for a free space + */ + while(*bufferIterator == 0xFFFFFFFF) + bufferIterator++; + + /** + * Search for a bit that indicates a free page + */ + while(*bufferIterator & mask) + { + mask <<= 1; + bit++; + } + + *bufferIterator |= mask; + + return 32 * (bufferIterator - buffer) + bit; +} + +void _mm_physical_free(unsigned page) +{ + buffer[page >> 5] &= ~(1 << (page & 0x1F)); /* confused yet?!? */ +} + +void _mm_virtual_init(void) +{ +} + +void _mm_page_copy_byte(uint32_t dest, uint32_t src) +{ + __asm__ __volatile__ + ( + "cld;" + "rep; movsb;" + : + : "c" (1024*1024), "D" (dest), "S" (src) + : "memory" + ); +} + +void _mm_page_copy_word(uint32_t dest, uint32_t src) +{ + __asm__ __volatile__ + ( + "cld;" + "rep; movsw;" + : + : "c" (512*1024), "D" (dest), "S" (src) + : "memory" + ); +} + +void _mm_page_copy_dword(uint32_t dest, uint32_t src) +{ + __asm__ __volatile__ + ( + "cld;" + "rep; movsl;" + : + : "c" (256*1024), "D" (dest), "S" (src) + : "memory" + ); +} + diff --git a/Dump/hybos/src/objects/kernel.dis b/Dump/hybos/src/objects/kernel.dis index 0152ca3..2ad6eb5 100644 --- a/Dump/hybos/src/objects/kernel.dis +++ b/Dump/hybos/src/objects/kernel.dis @@ -4,11 +4,11 @@ Disassembly of section .text: 00100000 : -#include "_krnl.h" -#include "bootlog.h" - -void klog(char *proc, char *entry, KLOGRESULT result, console_t *vtty0) -{ +#include "_krnl.h" +#include "bootlog.h" + +void klog(char *proc, char *entry, KLOGRESULT result, console_t *vtty0) +{ 100000: 55 push %ebp 100001: 89 e5 mov %esp,%ebp 100003: 57 push %edi @@ -17,60 +17,60 @@ 100006: 83 ec 0c sub $0xc,%esp 100009: 8b 45 10 mov 0x10(%ebp),%eax 10000c: 8b 5d 14 mov 0x14(%ebp),%ebx - unsigned oldattrib; - int i = 0; + unsigned oldattrib; + int i = 0; 10000f: 31 f6 xor %esi,%esi - int offset = 69; /* -4 for the "[ ]" part, -2 for the ": " part, -1 for space at end, and -4 for the status */ - char status[4]; - va_list args; - - args = args; - status[0] = '\0'; - - /** - * Save our old color attributes - */ - oldattrib = vtty0->attrib; - - if(result == K_KLOG_SUCCESS) + int offset = 69; /* -4 for the "[ ]" part, -2 for the ": " part, -1 for space at end, and -4 for the status */ + char status[4]; + va_list args; + + args = args; + status[0] = '\0'; + + /** + * Save our old color attributes + */ + oldattrib = vtty0->attrib; + + if(result == K_KLOG_SUCCESS) 100011: 85 c0 test %eax,%eax 100013: c7 45 f0 45 00 00 00 movl $0x45,0xfffffff0(%ebp) 10001a: 8b 7b 18 mov 0x18(%ebx),%edi 10001d: 0f 84 d5 00 00 00 je 1000f8 - { - /** - * Successfull initialization of something. - * Write "..Ok" then leave - */ - vtty0->attrib = 8; - printf("\b\b\b\b.."); - vtty0->attrib = 2; - printf("Ok\n"); - vtty0->attrib = oldattrib; - - return; - } - else if(result == K_KLOG_FAILURE) + { + /** + * Successfull initialization of something. + * Write "..Ok" then leave + */ + vtty0->attrib = 8; + printf("\b\b\b\b.."); + vtty0->attrib = 2; + printf("Ok\n"); + vtty0->attrib = oldattrib; + + return; + } + else if(result == K_KLOG_FAILURE) 100023: 83 f8 02 cmp $0x2,%eax 100026: 0f 84 b8 00 00 00 je 1000e4 - { - /** - * Unsuccessfull initialization of something. - * Write "Fail" then leave - */ - vtty0->attrib = 4; - printf("\b\b\b\bFail\n"); - vtty0->attrib = oldattrib; - - return; - } - - /** - * FIXME - * - * Should "wrap" the line instead - */ - if(strlen(entry) + 8 > 80) + { + /** + * Unsuccessfull initialization of something. + * Write "Fail" then leave + */ + vtty0->attrib = 4; + printf("\b\b\b\bFail\n"); + vtty0->attrib = oldattrib; + + return; + } + + /** + * FIXME + * + * Should "wrap" the line instead + */ + if(strlen(entry) + 8 > 80) 10002c: 83 ec 0c sub $0xc,%esp 10002f: ff 75 0c pushl 0xc(%ebp) 100032: e8 21 51 00 00 call 105158 @@ -78,26 +78,26 @@ 10003a: 83 c4 10 add $0x10,%esp 10003d: 83 f8 50 cmp $0x50,%eax 100040: 76 0a jbe 10004c - return; - - vtty0->attrib = 8; - printf("[ "); - vtty0->attrib = 15; - printf("%s: %s", proc, entry); - vtty0->attrib = 8; - printf(" ]"); - - offset -= strlen(proc); - offset -= strlen(entry); - - for(i = 0; i < offset; i++) - printf("."); - - vtty0->attrib = 8; - printf("Wait"); - - vtty0->attrib = oldattrib; -} + return; + + vtty0->attrib = 8; + printf("[ "); + vtty0->attrib = 15; + printf("%s: %s", proc, entry); + vtty0->attrib = 8; + printf(" ]"); + + offset -= strlen(proc); + offset -= strlen(entry); + + for(i = 0; i < offset; i++) + printf("."); + + vtty0->attrib = 8; + printf("Wait"); + + vtty0->attrib = oldattrib; +} 100042: 8d 65 f4 lea 0xfffffff4(%ebp),%esp 100045: 5b pop %ebx 100046: 5e pop %esi @@ -158,11 +158,11 @@ 10011a: eb b8 jmp 1000d4 0010011c : -*****************************************************************************/ -#define BPERL 16 /* byte/line for dump */ - -void dump(unsigned char *data, unsigned count) -{ +*****************************************************************************/ +#define BPERL 16 /* byte/line for dump */ + +void dump(unsigned char *data, unsigned count) +{ 10011c: 55 push %ebp 10011d: 89 e5 mov %esp,%ebp 10011f: 57 push %edi @@ -170,22 +170,22 @@ 100121: 53 push %ebx 100122: 83 ec 0c sub $0xc,%esp 100125: 8b 75 0c mov 0xc(%ebp),%esi - unsigned char byte1, byte2; - - while(count != 0) + unsigned char byte1, byte2; + + while(count != 0) 100128: 85 f6 test %esi,%esi 10012a: 0f 84 86 00 00 00 je 1001b6 - { - for(byte1 = 0; byte1 < BPERL; byte1++) + { + for(byte1 = 0; byte1 < BPERL; byte1++) 100130: 31 ff xor %edi,%edi 100132: 8b 5d 08 mov 0x8(%ebp),%ebx 100135: 8d 76 00 lea 0x0(%esi),%esi - { - if(count == 0) + { + if(count == 0) 100138: 85 f6 test %esi,%esi 10013a: 74 1d je 100159 - break; - printf("%02X ", data[byte1]); + break; + printf("%02X ", data[byte1]); 10013c: 83 ec 08 sub $0x8,%esp 10013f: 0f b6 03 movzbl (%ebx),%eax 100142: 50 push %eax @@ -193,55 +193,55 @@ 100148: 47 inc %edi 100149: e8 86 4f 00 00 call 1050d4 10014e: 89 f8 mov %edi,%eax - count--; + count--; 100150: 4e dec %esi 100151: 83 c4 10 add $0x10,%esp 100154: 43 inc %ebx 100155: 3c 0f cmp $0xf,%al 100157: 76 df jbe 100138 - } - printf("\t"); + } + printf("\t"); 100159: 83 ec 0c sub $0xc,%esp 10015c: 68 e3 51 10 00 push $0x1051e3 100161: e8 6e 4f 00 00 call 1050d4 - for(byte2 = 0; byte2 < byte1; byte2++) + for(byte2 = 0; byte2 < byte1; byte2++) 100166: 31 db xor %ebx,%ebx 100168: 89 fa mov %edi,%edx 10016a: 83 c4 10 add $0x10,%esp 10016d: 38 d3 cmp %dl,%bl 10016f: 73 29 jae 10019a 100171: 8d 76 00 lea 0x0(%esi),%esi - { - if(data[byte2] < ' ') + { + if(data[byte2] < ' ') 100174: 0f b6 c3 movzbl %bl,%eax 100177: 8b 55 08 mov 0x8(%ebp),%edx 10017a: 8a 04 10 mov (%eax,%edx,1),%al 10017d: 3c 1f cmp $0x1f,%al 10017f: 77 3f ja 1001c0 - printf("%c", '.'); + printf("%c", '.'); 100181: 83 ec 08 sub $0x8,%esp 100184: 6a 2e push $0x2e 100186: 68 e5 51 10 00 push $0x1051e5 10018b: e8 44 4f 00 00 call 1050d4 100190: 43 inc %ebx 100191: 89 f8 mov %edi,%eax - else - printf("%c", data[byte2]); + else + printf("%c", data[byte2]); 100193: 83 c4 10 add $0x10,%esp 100196: 38 c3 cmp %al,%bl 100198: 72 da jb 100174 - } - printf("\n"); + } + printf("\n"); 10019a: 83 ec 0c sub $0xc,%esp 10019d: 68 f8 5a 10 00 push $0x105af8 1001a2: e8 2d 4f 00 00 call 1050d4 - data += BPERL; + data += BPERL; 1001a7: 83 45 08 10 addl $0x10,0x8(%ebp) 1001ab: 83 c4 10 add $0x10,%esp 1001ae: 85 f6 test %esi,%esi 1001b0: 0f 85 7a ff ff ff jne 100130 - } -} + } +} 1001b6: 8d 65 f4 lea 0xfffffff4(%ebp),%esp 1001b9: 5b pop %ebx 1001ba: 5e pop %esi @@ -256,24 +256,24 @@ 1001c9: 8d 76 00 lea 0x0(%esi),%esi 001001cc : -/***************************************************************************** -*****************************************************************************/ -void dump_regs(regs_t *regs) -{ +/***************************************************************************** +*****************************************************************************/ +void dump_regs(regs_t *regs) +{ 1001cc: 55 push %ebp 1001cd: 89 e5 mov %esp,%ebp 1001cf: 53 push %ebx 1001d0: 83 ec 10 sub $0x10,%esp 1001d3: 8b 5d 08 mov 0x8(%ebp),%ebx - printf("EDI=%08X ESI=%08X EBP=%08X ESP=%08X\n", + printf("EDI=%08X ESI=%08X EBP=%08X ESP=%08X\n", 1001d6: ff 73 0c pushl 0xc(%ebx) 1001d9: ff 73 08 pushl 0x8(%ebx) 1001dc: ff 73 04 pushl 0x4(%ebx) 1001df: ff 33 pushl (%ebx) 1001e1: 68 00 52 10 00 push $0x105200 1001e6: e8 e9 4e 00 00 call 1050d4 - regs->edi, regs->esi, regs->ebp, regs->esp); - printf("EBX=%08X EDX=%08X ECX=%08X EAX=%08X\n", + regs->edi, regs->esi, regs->ebp, regs->esp); + printf("EBX=%08X EDX=%08X ECX=%08X EAX=%08X\n", 1001eb: 83 c4 14 add $0x14,%esp 1001ee: ff 73 1c pushl 0x1c(%ebx) 1001f1: ff 73 18 pushl 0x18(%ebx) @@ -281,8 +281,8 @@ 1001f7: ff 73 10 pushl 0x10(%ebx) 1001fa: 68 40 52 10 00 push $0x105240 1001ff: e8 d0 4e 00 00 call 1050d4 - regs->ebx, regs->edx, regs->ecx, regs->eax); - printf(" DS=%08X ES=%08X FS=%08X GS=%08X\n", + regs->ebx, regs->edx, regs->ecx, regs->eax); + printf(" DS=%08X ES=%08X FS=%08X GS=%08X\n", 100204: 83 c4 14 add $0x14,%esp 100207: ff 73 2c pushl 0x2c(%ebx) 10020a: ff 73 28 pushl 0x28(%ebx) @@ -290,8 +290,8 @@ 100210: ff 73 20 pushl 0x20(%ebx) 100213: 68 80 52 10 00 push $0x105280 100218: e8 b7 4e 00 00 call 1050d4 - regs->ds, regs->es, regs->fs, regs->gs); - printf("int=%08X err=%08X EIP=%08X CS=%08X\n", + regs->ds, regs->es, regs->fs, regs->gs); + printf("int=%08X err=%08X EIP=%08X CS=%08X\n", 10021d: 83 c4 14 add $0x14,%esp 100220: ff 73 3c pushl 0x3c(%ebx) 100223: ff 73 38 pushl 0x38(%ebx) @@ -299,64 +299,64 @@ 100229: ff 73 30 pushl 0x30(%ebx) 10022c: 68 c0 52 10 00 push $0x1052c0 100231: e8 9e 4e 00 00 call 1050d4 - regs->which_int, regs->err_code, regs->eip, regs->cs); - printf("uSP=%08X uSS=%08X\n", regs->user_esp, regs->user_ss); + regs->which_int, regs->err_code, regs->eip, regs->cs); + printf("uSP=%08X uSS=%08X\n", regs->user_esp, regs->user_ss); 100236: 83 c4 1c add $0x1c,%esp 100239: ff 73 48 pushl 0x48(%ebx) 10023c: ff 73 44 pushl 0x44(%ebx) 10023f: 68 e8 51 10 00 push $0x1051e8 100244: e8 8b 4e 00 00 call 1050d4 -} +} 100249: 8b 5d fc mov 0xfffffffc(%ebp),%ebx 10024c: c9 leave 10024d: c3 ret ... 00100250 : - * - * @return void - */ -void keyDown(unsigned key) -{ + * + * @return void + */ +void keyDown(unsigned key) +{ 100250: 55 push %ebp 100251: 89 e5 mov %esp,%ebp - key = key; /* to shut gcc up */ -} + key = key; /* to shut gcc up */ +} 100253: c9 leave 100254: c3 ret 100255: 8d 76 00 lea 0x0(%esi),%esi 00100258 : - -/** - * keyUp() - * - * This function is called when a key is released. - * - * @param unsigned Which key was released. See keyboard.h - * - * @return void - */ -void keyUp(unsigned key) -{ + +/** + * keyUp() + * + * This function is called when a key is released. + * + * @param unsigned Which key was released. See keyboard.h + * + * @return void + */ +void keyUp(unsigned key) +{ 100258: 55 push %ebp 100259: 89 e5 mov %esp,%ebp - key = key; /* to shut gcc up */ -} + key = key; /* to shut gcc up */ +} 10025b: c9 leave 10025c: c3 ret 10025d: 8d 76 00 lea 0x0(%esi),%esi 00100260 : - -void initCommands(void) -{ + +void initCommands(void) +{ 100260: 55 push %ebp 100261: 89 e5 mov %esp,%ebp 100263: 83 ec 10 sub $0x10,%esp - eshCommands[0].minparams = 0; - eshCommands[0].maxparams = 0; - strcpy(eshCommands[0].command, "dumpheap\0"); + eshCommands[0].minparams = 0; + eshCommands[0].maxparams = 0; + strcpy(eshCommands[0].command, "dumpheap\0"); 100266: 68 00 53 10 00 push $0x105300 10026b: 68 48 3a 18 00 push $0x183a48 100270: c7 05 40 3a 18 00 00 movl $0x0,0x183a40 @@ -364,22 +364,22 @@ 10027a: c7 05 44 3a 18 00 00 movl $0x0,0x183a44 100281: 00 00 00 100284: e8 b3 4e 00 00 call 10513c - strcpy(eshCommands[0].params[0], "-h\0"); + strcpy(eshCommands[0].params[0], "-h\0"); 100289: 58 pop %eax 10028a: 5a pop %edx 10028b: 68 0a 53 10 00 push $0x10530a 100290: 68 48 3c 18 00 push $0x183c48 100295: e8 a2 4e 00 00 call 10513c - strcpy(eshCommands[0].description, "Print listing of heap usage and status.\0"); + strcpy(eshCommands[0].description, "Print listing of heap usage and status.\0"); 10029a: 59 pop %ecx 10029b: 58 pop %eax 10029c: 68 20 53 10 00 push $0x105320 1002a1: 68 48 64 18 00 push $0x186448 1002a6: e8 91 4e 00 00 call 10513c - - eshCommands[1].minparams = 1; - eshCommands[1].maxparams = MAX_PARAMS; - strcpy(eshCommands[1].params[0], "-h\0"); + + eshCommands[1].minparams = 1; + eshCommands[1].maxparams = MAX_PARAMS; + strcpy(eshCommands[1].params[0], "-h\0"); 1002ab: 58 pop %eax 1002ac: 5a pop %edx 1002ad: 68 0a 53 10 00 push $0x10530a @@ -389,23 +389,23 @@ 1002c1: c7 05 4c 66 18 00 14 movl $0x14,0x18664c 1002c8: 00 00 00 1002cb: e8 6c 4e 00 00 call 10513c - strcpy(eshCommands[1].command, "echo\0"); + strcpy(eshCommands[1].command, "echo\0"); 1002d0: 59 pop %ecx 1002d1: 58 pop %eax 1002d2: 68 49 53 10 00 push $0x105349 1002d7: 68 50 66 18 00 push $0x186650 1002dc: e8 5b 4e 00 00 call 10513c - strcpy(eshCommands[1].description, "Echo a line of text to the terminal.\0"); + strcpy(eshCommands[1].description, "Echo a line of text to the terminal.\0"); 1002e1: 58 pop %eax 1002e2: 5a pop %edx 1002e3: 68 60 53 10 00 push $0x105360 1002e8: 68 50 90 18 00 push $0x189050 1002ed: e8 4a 4e 00 00 call 10513c - - /*this will be called with either "help" or "help command" */ - eshCommands[2].minparams = 0; - eshCommands[2].maxparams = 1; - strcpy(eshCommands[2].params[0], "-h\0"); + + /*this will be called with either "help" or "help command" */ + eshCommands[2].minparams = 0; + eshCommands[2].maxparams = 1; + strcpy(eshCommands[2].params[0], "-h\0"); 1002f2: 59 pop %ecx 1002f3: 58 pop %eax 1002f4: 68 0a 53 10 00 push $0x10530a @@ -415,23 +415,23 @@ 100308: c7 05 54 92 18 00 01 movl $0x1,0x189254 10030f: 00 00 00 100312: e8 25 4e 00 00 call 10513c - strcpy(eshCommands[2].command, "help\0"); + strcpy(eshCommands[2].command, "help\0"); 100317: 58 pop %eax 100318: 5a pop %edx 100319: 68 86 53 10 00 push $0x105386 10031e: 68 58 92 18 00 push $0x189258 100323: e8 14 4e 00 00 call 10513c - strcpy(eshCommands[2].description, "Displays general help menu or help on specific command.\0"); + strcpy(eshCommands[2].description, "Displays general help menu or help on specific command.\0"); 100328: 59 pop %ecx 100329: 58 pop %eax 10032a: 68 a0 53 10 00 push $0x1053a0 10032f: 68 58 bc 18 00 push $0x18bc58 100334: e8 03 4e 00 00 call 10513c - - /* -r|-h [time] */ - eshCommands[3].minparams = 1; - eshCommands[3].maxparams = 2; - strcpy(eshCommands[3].command, "shutdown\0"); + + /* -r|-h [time] */ + eshCommands[3].minparams = 1; + eshCommands[3].maxparams = 2; + strcpy(eshCommands[3].command, "shutdown\0"); 100339: 58 pop %eax 10033a: 5a pop %edx 10033b: 68 d9 53 10 00 push $0x1053d9 @@ -441,35 +441,35 @@ 10034f: c7 05 5c be 18 00 02 movl $0x2,0x18be5c 100356: 00 00 00 100359: e8 de 4d 00 00 call 10513c - strcpy(eshCommands[3].params[0], "-r\0"); + strcpy(eshCommands[3].params[0], "-r\0"); 10035e: 59 pop %ecx 10035f: 58 pop %eax 100360: 68 e3 53 10 00 push $0x1053e3 100365: 68 60 c0 18 00 push $0x18c060 10036a: e8 cd 4d 00 00 call 10513c - strcpy(eshCommands[3].params[1], "-h\0"); + strcpy(eshCommands[3].params[1], "-h\0"); 10036f: 58 pop %eax 100370: 5a pop %edx 100371: 68 0a 53 10 00 push $0x10530a 100376: 68 60 c2 18 00 push $0x18c260 10037b: e8 bc 4d 00 00 call 10513c - strcpy(eshCommands[3].params[2], "NOW\0"); + strcpy(eshCommands[3].params[2], "NOW\0"); 100380: 59 pop %ecx 100381: 58 pop %eax 100382: 68 e7 53 10 00 push $0x1053e7 100387: 68 60 c4 18 00 push $0x18c460 10038c: e8 ab 4d 00 00 call 10513c - strcpy(eshCommands[3].description, "Halt or restart the system.\0"); + strcpy(eshCommands[3].description, "Halt or restart the system.\0"); 100391: 58 pop %eax 100392: 5a pop %edx 100393: 68 ec 53 10 00 push $0x1053ec 100398: 68 60 e8 18 00 push $0x18e860 10039d: e8 9a 4d 00 00 call 10513c - - /* clear screen */ - eshCommands[4].minparams = 0; - eshCommands[4].maxparams = 0; - strcpy(eshCommands[4].params[0], "-h\0"); + + /* clear screen */ + eshCommands[4].minparams = 0; + eshCommands[4].maxparams = 0; + strcpy(eshCommands[4].params[0], "-h\0"); 1003a2: 59 pop %ecx 1003a3: 58 pop %eax 1003a4: 68 0a 53 10 00 push $0x10530a @@ -479,23 +479,23 @@ 1003b8: c7 05 64 ea 18 00 00 movl $0x0,0x18ea64 1003bf: 00 00 00 1003c2: e8 75 4d 00 00 call 10513c - strcpy(eshCommands[4].command, "cls\0"); + strcpy(eshCommands[4].command, "cls\0"); 1003c7: 58 pop %eax 1003c8: 5a pop %edx 1003c9: 68 09 54 10 00 push $0x105409 1003ce: 68 68 ea 18 00 push $0x18ea68 1003d3: e8 64 4d 00 00 call 10513c - strcpy(eshCommands[4].description, "Clears the terminal of all output.\0"); + strcpy(eshCommands[4].description, "Clears the terminal of all output.\0"); 1003d8: 59 pop %ecx 1003d9: 58 pop %eax 1003da: 68 20 54 10 00 push $0x105420 1003df: 68 68 14 19 00 push $0x191468 1003e4: e8 53 4d 00 00 call 10513c - - /* print working directory */ - eshCommands[5].minparams = 0; - eshCommands[5].maxparams = 0; - strcpy(eshCommands[5].params[0], "-h\0"); + + /* print working directory */ + eshCommands[5].minparams = 0; + eshCommands[5].maxparams = 0; + strcpy(eshCommands[5].params[0], "-h\0"); 1003e9: 58 pop %eax 1003ea: 5a pop %edx 1003eb: 68 0a 53 10 00 push $0x10530a @@ -505,37 +505,37 @@ 1003ff: c7 05 6c 16 19 00 00 movl $0x0,0x19166c 100406: 00 00 00 100409: e8 2e 4d 00 00 call 10513c - strcpy(eshCommands[5].command, "pwd\0"); + strcpy(eshCommands[5].command, "pwd\0"); 10040e: 59 pop %ecx 10040f: 58 pop %eax 100410: 68 44 54 10 00 push $0x105444 100415: 68 70 16 19 00 push $0x191670 10041a: e8 1d 4d 00 00 call 10513c - strcpy(eshCommands[5].description, "Prints the current working directory.\0"); + strcpy(eshCommands[5].description, "Prints the current working directory.\0"); 10041f: 58 pop %eax 100420: 5a pop %edx 100421: 68 60 54 10 00 push $0x105460 100426: 68 70 40 19 00 push $0x194070 10042b: e8 0c 4d 00 00 call 10513c -} +} 100430: c9 leave 100431: c3 ret 100432: 89 f6 mov %esi,%esi 00100434 : - -/** - * mapCommand() - * - * Used internally by esh to map a command to it's zero-based - * index of commands. - * - * @param char * the entire line of the command - * - * @return int index of command entry if found, otherwise -1 - */ -int mapCommand(char *cmd) -{ + +/** + * mapCommand() + * + * Used internally by esh to map a command to it's zero-based + * index of commands. + * + * @param char * the entire line of the command + * + * @return int index of command entry if found, otherwise -1 + */ +int mapCommand(char *cmd) +{ 100434: 55 push %ebp 100435: 89 e5 mov %esp,%ebp 100437: 57 push %edi @@ -543,55 +543,55 @@ 100439: 53 push %ebx 10043a: 81 ec 0c 02 00 00 sub $0x20c,%esp 100440: 8b 75 08 mov 0x8(%ebp),%esi - int i; /* for our loops */ - int params; /* number of parameters found for the command */ - int previdx; /* previous index */ - char cmdName[MAX_LEN]; /* name of the command */ - - i = 0; + int i; /* for our loops */ + int params; /* number of parameters found for the command */ + int previdx; /* previous index */ + char cmdName[MAX_LEN]; /* name of the command */ + + i = 0; 100443: 31 db xor %ebx,%ebx 100445: 8d 76 00 lea 0x0(%esi),%esi - previdx = 0; - params = 0; - - /** - * Loop while cmd[i] is not a space - */ - i = 0; - for(i = 0; i < (int)strlen(cmd); i++) + previdx = 0; + params = 0; + + /** + * Loop while cmd[i] is not a space + */ + i = 0; + for(i = 0; i < (int)strlen(cmd); i++) 100448: 83 ec 0c sub $0xc,%esp 10044b: 56 push %esi 10044c: e8 07 4d 00 00 call 105158 100451: 83 c4 10 add $0x10,%esp 100454: 39 c3 cmp %eax,%ebx 100456: 7d 09 jge 100461 - { - if(cmd[i] == ' ') + { + if(cmd[i] == ' ') 100458: 80 3c 33 20 cmpb $0x20,(%ebx,%esi,1) 10045c: 74 03 je 100461 10045e: 43 inc %ebx 10045f: eb e7 jmp 100448 - break; - } - - strncpy(cmdName, cmd, i); + break; + } + + strncpy(cmdName, cmd, i); 100461: 51 push %ecx 100462: 53 push %ebx 100463: 56 push %esi 100464: 8d bd e8 fd ff ff lea 0xfffffde8(%ebp),%edi 10046a: 57 push %edi 10046b: e8 04 4d 00 00 call 105174 - cmdName[i] = '\0'; - - for(i = 0; i < COMMAND_COUNT; i++) + cmdName[i] = '\0'; + + for(i = 0; i < COMMAND_COUNT; i++) 100470: be 48 3a 18 00 mov $0x183a48,%esi 100475: c6 84 2b e8 fd ff ff movb $0x0,0xfffffde8(%ebx,%ebp,1) 10047c: 00 10047d: 83 c4 10 add $0x10,%esp 100480: 31 db xor %ebx,%ebx 100482: 89 f6 mov %esi,%esi - { - if(!strcmp(eshCommands[i].command, cmdName)) + { + if(!strcmp(eshCommands[i].command, cmdName)) 100484: 83 ec 08 sub $0x8,%esp 100487: 57 push %edi 100488: 56 push %esi @@ -604,12 +604,12 @@ 100498: 81 c6 08 2c 00 00 add $0x2c08,%esi 10049e: 83 fb 05 cmp $0x5,%ebx 1004a1: 7e e1 jle 100484 - return i; - } - - return -1; + return i; + } + + return -1; 1004a3: ba ff ff ff ff mov $0xffffffff,%edx -} +} 1004a8: 8d 65 f4 lea 0xfffffff4(%ebp),%esp 1004ab: 5b pop %ebx 1004ac: 5e pop %esi @@ -620,20 +620,20 @@ 1004b2: 89 f6 mov %esi,%esi 001004b4 : - -/** - * isParam() - * - * Determines if the supplied parameter is valid for the - * given command. - * - * @param int index of command - * @param char * command string - * - * @return bool true if parameter is valid, false otherwise - */ -bool isParam(int argc, char *argv) -{ + +/** + * isParam() + * + * Determines if the supplied parameter is valid for the + * given command. + * + * @param int index of command + * @param char * command string + * + * @return bool true if parameter is valid, false otherwise + */ +bool isParam(int argc, char *argv) +{ 1004b4: 55 push %ebp 1004b5: 89 e5 mov %esp,%ebp 1004b7: 57 push %edi @@ -641,9 +641,9 @@ 1004b9: 53 push %ebx 1004ba: 83 ec 0c sub $0xc,%esp 1004bd: 8b 55 08 mov 0x8(%ebp),%edx - int i; - - for(i = 0; i < MAX_PARAMS; i++) + int i; + + for(i = 0; i < MAX_PARAMS; i++) 1004c0: 8d 04 92 lea (%edx,%edx,4),%eax 1004c3: 8d 04 42 lea (%edx,%eax,2),%eax 1004c6: c1 e0 07 shl $0x7,%eax @@ -652,8 +652,8 @@ 1004ce: 31 f6 xor %esi,%esi 1004d0: 8d 1c c5 48 3c 18 00 lea 0x183c48(,%eax,8),%ebx 1004d7: 90 nop - { - if(!strcmp(eshCommands[argc].params[i], argv)) + { + if(!strcmp(eshCommands[argc].params[i], argv)) 1004d8: 83 ec 08 sub $0x8,%esp 1004db: 57 push %edi 1004dc: 53 push %ebx @@ -666,12 +666,12 @@ 1004ef: 81 c3 00 02 00 00 add $0x200,%ebx 1004f5: 83 fe 13 cmp $0x13,%esi 1004f8: 7e de jle 1004d8 - return true; - } - - return false; + return true; + } + + return false; 1004fa: 31 d2 xor %edx,%edx -} +} 1004fc: 8d 65 f4 lea 0xfffffff4(%ebp),%esp 1004ff: 5b pop %ebx 100500: 5e pop %esi @@ -682,19 +682,19 @@ 100506: 89 f6 mov %esi,%esi 00100508 : - -/** - * mapParams() - * - * Maps each parameter to the pars struct - * - * @param char * Buffer from the command line - * @param struct Parameter structure - * - * @return int Number of command line parameters (arguments) parsed - */ -int mapParams(char *buf, ESHCURRCOMMAND *pars) -{ + +/** + * mapParams() + * + * Maps each parameter to the pars struct + * + * @param char * Buffer from the command line + * @param struct Parameter structure + * + * @return int Number of command line parameters (arguments) parsed + */ +int mapParams(char *buf, ESHCURRCOMMAND *pars) +{ 100508: 55 push %ebp 100509: 89 e5 mov %esp,%ebp 10050b: 57 push %edi @@ -702,32 +702,32 @@ 10050d: 53 push %ebx 10050e: 83 ec 18 sub $0x18,%esp 100511: 8b 7d 08 mov 0x8(%ebp),%edi - int i; /* for our loops */ - int previdx; /* previous index */ - int idx; /* current index */ - int j; /* loops */ - - i = 0; - j = 0; - previdx = 0; - pars->count = 0; + int i; /* for our loops */ + int previdx; /* previous index */ + int idx; /* current index */ + int j; /* loops */ + + i = 0; + j = 0; + previdx = 0; + pars->count = 0; 100514: 8b 45 0c mov 0xc(%ebp),%eax 100517: c7 00 00 00 00 00 movl $0x0,(%eax) - - previdx = mapCommand(buf); + + previdx = mapCommand(buf); 10051d: 57 push %edi 10051e: e8 11 ff ff ff call 100434 100523: 89 c2 mov %eax,%edx 100525: 31 f6 xor %esi,%esi - - if(previdx == -1) + + if(previdx == -1) 100527: 83 c4 10 add $0x10,%esp 10052a: 31 c0 xor %eax,%eax 10052c: 83 fa ff cmp $0xffffffff,%edx 10052f: 0f 84 0d 01 00 00 je 100642 - return 0; - - strcpy(pars->param[0], eshCommands[previdx].command); + return 0; + + strcpy(pars->param[0], eshCommands[previdx].command); 100535: 8d 04 92 lea (%edx,%edx,4),%eax 100538: 8d 04 42 lea (%edx,%eax,2),%eax 10053b: c1 e0 07 shl $0x7,%eax @@ -739,15 +739,15 @@ 10054e: 83 c0 04 add $0x4,%eax 100551: 50 push %eax 100552: e8 e5 4b 00 00 call 10513c - j++; - pars->count++; + j++; + pars->count++; 100557: 8b 55 0c mov 0xc(%ebp),%edx 10055a: ff 02 incl (%edx) - - i = 0; - idx = 0; - - for(i = 0; i < (int)strlen(buf); i++) + + i = 0; + idx = 0; + + for(i = 0; i < (int)strlen(buf); i++) 10055c: 83 c4 10 add $0x10,%esp 10055f: 81 c2 00 02 00 00 add $0x200,%edx 100565: c7 45 ec 01 00 00 00 movl $0x1,0xffffffec(%ebp) @@ -759,27 +759,27 @@ 100579: 83 c4 10 add $0x10,%esp 10057c: 39 c6 cmp %eax,%esi 10057e: 0f 8d b9 00 00 00 jge 10063d - { - /* we have encountered a seperator */ - if(buf[i] == ' ') + { + /* we have encountered a seperator */ + if(buf[i] == ' ') 100584: 80 3c 3e 20 cmpb $0x20,(%esi,%edi,1) 100588: 74 06 je 100590 10058a: 46 inc %esi 10058b: eb e3 jmp 100570 10058d: 8d 76 00 lea 0x0(%esi),%esi - { - if(j > MAX_PARAMS) + { + if(j > MAX_PARAMS) 100590: 83 7d ec 14 cmpl $0x14,0xffffffec(%ebp) 100594: 0f 8f a3 00 00 00 jg 10063d - break; - - i++; /* skip one space */ + break; + + i++; /* skip one space */ 10059a: 46 inc %esi - - idx = i; + + idx = i; 10059b: 89 75 f0 mov %esi,0xfffffff0(%ebp) - - if(buf[i] == '"') + + if(buf[i] == '"') 10059e: 8a 04 3e mov (%esi,%edi,1),%al 1005a1: 3c 22 cmp $0x22,%al 1005a3: 74 57 je 1005fc @@ -792,29 +792,29 @@ 1005b5: 83 c4 10 add $0x10,%esp 1005b8: 39 c6 cmp %eax,%esi 1005ba: 74 06 je 1005c2 - { - i++; - idx++; - - while(buf[i] != '"' && i != (int)strlen(buf)) - i++; - - strncpy(pars->param[j], &buf[idx], (i - idx)); - pars->param[j][i - idx] = '\0'; - - idx = i; - j++; - pars->count++; - } - else - { - while(buf[i] != ' ' && i != (int)strlen(buf)) - i++; + { + i++; + idx++; + + while(buf[i] != '"' && i != (int)strlen(buf)) + i++; + + strncpy(pars->param[j], &buf[idx], (i - idx)); + pars->param[j][i - idx] = '\0'; + + idx = i; + j++; + pars->count++; + } + else + { + while(buf[i] != ' ' && i != (int)strlen(buf)) + i++; 1005bc: 46 inc %esi 1005bd: 8a 04 3e mov (%esi,%edi,1),%al 1005c0: eb e6 jmp 1005a8 - - strncpy(pars->param[j], &buf[idx], i - idx); + + strncpy(pars->param[j], &buf[idx], i - idx); 1005c2: 53 push %ebx 1005c3: 89 f3 mov %esi,%ebx 1005c5: 2b 5d f0 sub 0xfffffff0(%ebp),%ebx @@ -826,14 +826,14 @@ 1005d3: 83 c0 04 add $0x4,%eax 1005d6: 50 push %eax 1005d7: e8 98 4b 00 00 call 105174 - pars->param[j][i - idx] = '\0'; + pars->param[j][i - idx] = '\0'; 1005dc: 8b 45 e8 mov 0xffffffe8(%ebp),%eax 1005df: c6 44 03 04 00 movb $0x0,0x4(%ebx,%eax,1) - i = idx; + i = idx; 1005e4: 8b 75 f0 mov 0xfffffff0(%ebp),%esi - j++; + j++; 1005e7: 05 00 02 00 00 add $0x200,%eax - pars->count++; + pars->count++; 1005ec: 8b 55 0c mov 0xc(%ebp),%edx 1005ef: ff 45 ec incl 0xffffffec(%ebp) 1005f2: 89 45 e8 mov %eax,0xffffffe8(%ebp) @@ -866,14 +866,14 @@ 100633: 8b 45 e8 mov 0xffffffe8(%ebp),%eax 100636: c6 44 03 04 00 movb $0x0,0x4(%ebx,%eax,1) 10063b: eb aa jmp 1005e7 - } - } - } - - return pars->count; + } + } + } + + return pars->count; 10063d: 8b 55 0c mov 0xc(%ebp),%edx 100640: 8b 02 mov (%edx),%eax -} +} 100642: 8d 65 f4 lea 0xfffffff4(%ebp),%esp 100645: 5b pop %ebx 100646: 5e pop %esi @@ -883,20 +883,20 @@ 10064a: 89 f6 mov %esi,%esi 0010064c : - -/** - * processCommand() - * - * This function is called when the user has pressed - * the ENTER key. - * - * @param char * The contents of the current buffer or NULL if empty - * @param int Size of the buffer (number of characters) - * - * @return void - */ -void processCommand(char *line, int count) -{ + +/** + * processCommand() + * + * This function is called when the user has pressed + * the ENTER key. + * + * @param char * The contents of the current buffer or NULL if empty + * @param int Size of the buffer (number of characters) + * + * @return void + */ +void processCommand(char *line, int count) +{ 10064c: 55 push %ebp 10064d: 89 e5 mov %esp,%ebp 10064f: 57 push %edi @@ -904,25 +904,25 @@ 100651: 53 push %ebx 100652: 81 ec 1c 50 00 00 sub $0x501c,%esp 100658: 8b 75 08 mov 0x8(%ebp),%esi - int i; - int cmd; /* stores the numeric index of the command */ - ESHCURRCOMMAND params; - - count = count; /* to shut gcc up */ - - /*for(i = 0; i < MAX_PARAMS; i++) - params.param[i][0] = '\0';*/ - params.param[0][0] = '\0'; + int i; + int cmd; /* stores the numeric index of the command */ + ESHCURRCOMMAND params; + + count = count; /* to shut gcc up */ + + /*for(i = 0; i < MAX_PARAMS; i++) + params.param[i][0] = '\0';*/ + params.param[0][0] = '\0'; 10065b: c6 85 dc af ff ff 00 movb $0x0,0xffffafdc(%ebp) - - initCommands(); + + initCommands(); 100662: e8 f9 fb ff ff call 100260 - - cmd = mapCommand(line); + + cmd = mapCommand(line); 100667: 83 ec 0c sub $0xc,%esp 10066a: 56 push %esi 10066b: e8 c4 fd ff ff call 100434 - mapParams(line, ¶ms); + mapParams(line, ¶ms); 100670: 5f pop %edi 100671: 89 c3 mov %eax,%ebx 100673: 8d bd d8 af ff ff lea 0xffffafd8(%ebp),%edi @@ -930,8 +930,8 @@ 10067a: 57 push %edi 10067b: 56 push %esi 10067c: e8 87 fe ff ff call 100508 - - switch(cmd) + + switch(cmd) 100681: 83 c4 10 add $0x10,%esp 100684: 83 fb 01 cmp $0x1,%ebx 100687: 0f 84 13 01 00 00 je 1007a0 @@ -939,41 +939,41 @@ 100690: 0f 8e f6 00 00 00 jle 10078c 100696: 83 fb 02 cmp $0x2,%ebx 100699: 74 4a je 1006e5 - { - case 0: /* dumpheap */ - dumpheapk(); - //testheap(); - break; - case 1: /* echo */ - for(i = 1; i < params.count; i++) - printf("%s", params.param[i]); - - printf("\n"); - break; - case 2: /* help */ - if(params.count == 1) - { - printf("HybOS EShell Commands:\n"); - for(i = 0; i < COMMAND_COUNT; i++) - if(strlen(eshCommands[i].command) > 0) - printf("%10s %-s\n", eshCommands[i].command, eshCommands[i].description); - } - else - { - cmd = mapCommand(params.param[0]); - mapParams(params.param[1], ¶ms); - - //if(isParam(cmd, params.param[1])) - if(cmd != -1) - { - printf("Usage: %s %s\n", params.param[0], eshCommands[cmd].params[1]); - } - else - printf("esh: '%s' not found.\n", params.param[1]); - } - break; - default: - if(strlen(params.param[0]) > 0 && strcmp(params.param[0], "help")) + { + case 0: /* dumpheap */ + dumpheapk(); + //testheap(); + break; + case 1: /* echo */ + for(i = 1; i < params.count; i++) + printf("%s", params.param[i]); + + printf("\n"); + break; + case 2: /* help */ + if(params.count == 1) + { + printf("HybOS EShell Commands:\n"); + for(i = 0; i < COMMAND_COUNT; i++) + if(strlen(eshCommands[i].command) > 0) + printf("%10s %-s\n", eshCommands[i].command, eshCommands[i].description); + } + else + { + cmd = mapCommand(params.param[0]); + mapParams(params.param[1], ¶ms); + + //if(isParam(cmd, params.param[1])) + if(cmd != -1) + { + printf("Usage: %s %s\n", params.param[0], eshCommands[cmd].params[1]); + } + else + printf("esh: '%s' not found.\n", params.param[1]); + } + break; + default: + if(strlen(params.param[0]) > 0 && strcmp(params.param[0], "help")) 10069b: 83 ec 0c sub $0xc,%esp 10069e: 8d 9d dc af ff ff lea 0xffffafdc(%ebp),%ebx 1006a4: 53 push %ebx @@ -988,68 +988,68 @@ 1006bf: 83 c4 10 add $0x10,%esp 1006c2: 85 c0 test %eax,%eax 1006c4: 75 19 jne 1006df - printf("esh: '%s' not found.\n", params.param[0]); - else - printf("esh: '%s' not found.\n", &line[0]); + printf("esh: '%s' not found.\n", params.param[0]); + else + printf("esh: '%s' not found.\n", &line[0]); 1006c6: 83 ec 08 sub $0x8,%esp 1006c9: 56 push %esi 1006ca: 68 8c 54 10 00 push $0x10548c 1006cf: e8 00 4a 00 00 call 1050d4 1006d4: 83 c4 10 add $0x10,%esp - break; - } - - /*for(i = 0; i < params.count; i++) - printf("param[%i]: %s\n", i, params.param[i]);*/ - - //if(isParam(3, ¶ms.param[1])) - // printf("valid parameter\n"); - //else - // printf("invalid parameter\n"); - - return; - - if(!strcmp(line, "dumpheap")) - dumpheapk(); - else if(!strncmp(line, "echo", 4)) - printf("%s\n", line[4] == ' ' ? &line[5] : &line[4]); - else if(!strcmp(line, "help")) - { - printf("HybOS EShell Commands:\n"); - printf("dumpheap\tPrint listing of heap usage and status\n"); - printf("testheap\tTest the heap and print out results\n"); - printf("shutdown -r\tRestart the system.\n"); - printf("pwd\t\tPrint the current working directory.\n"); - } - else if(!strncmp(line, "shutdown", 8)) - { - if(strlen(line) > 9 && !strncmp(&line[9], "-r", 2)) - { - printf("\nSystem shutdown from vtty%u\n", get_current_vc()); - printf("Restarting..."); - //reboot(); - } - else - { - if((strlen(line) > 9) && (strlen(&line[9]) > 0)) - printf("shutdown: Invalid argument \"%s\".\n", &line[9]); - else - printf("Usage: shutdown -r\n"); - } - } - else if((strlen(line) > 0) && (!strcmp(line, "cls"))) - { - printf("\x1B[2J"); - } - else if((strlen(line) >= 8) && (!strcmp(line, "testheap"))) - { - //testheap(); - } - else if((strlen(line) > 0) && (!strcmp(line, "pwd"))) - printf("/\n"); - else if(strlen(line) > 0) - printf("eshell: \"%s\" not found.\n", line); -} + break; + } + + /*for(i = 0; i < params.count; i++) + printf("param[%i]: %s\n", i, params.param[i]);*/ + + //if(isParam(3, ¶ms.param[1])) + // printf("valid parameter\n"); + //else + // printf("invalid parameter\n"); + + return; + + if(!strcmp(line, "dumpheap")) + dumpheapk(); + else if(!strncmp(line, "echo", 4)) + printf("%s\n", line[4] == ' ' ? &line[5] : &line[4]); + else if(!strcmp(line, "help")) + { + printf("HybOS EShell Commands:\n"); + printf("dumpheap\tPrint listing of heap usage and status\n"); + printf("testheap\tTest the heap and print out results\n"); + printf("shutdown -r\tRestart the system.\n"); + printf("pwd\t\tPrint the current working directory.\n"); + } + else if(!strncmp(line, "shutdown", 8)) + { + if(strlen(line) > 9 && !strncmp(&line[9], "-r", 2)) + { + printf("\nSystem shutdown from vtty%u\n", get_current_vc()); + printf("Restarting..."); + //reboot(); + } + else + { + if((strlen(line) > 9) && (strlen(&line[9]) > 0)) + printf("shutdown: Invalid argument \"%s\".\n", &line[9]); + else + printf("Usage: shutdown -r\n"); + } + } + else if((strlen(line) > 0) && (!strcmp(line, "cls"))) + { + printf("\x1B[2J"); + } + else if((strlen(line) >= 8) && (!strcmp(line, "testheap"))) + { + //testheap(); + } + else if((strlen(line) > 0) && (!strcmp(line, "pwd"))) + printf("/\n"); + else if(strlen(line) > 0) + printf("eshell: \"%s\" not found.\n", line); +} 1006d7: 8d 65 f4 lea 0xfffffff4(%ebp),%esp 1006da: 5b pop %ebx 1006db: 5e pop %esi @@ -1138,55 +1138,55 @@ ... 001007e4 : - * reboot() - * - */ -static void reboot(void) -{ + * reboot() + * + */ +static void reboot(void) +{ 1007e4: 55 push %ebp 1007e5: 89 e5 mov %esp,%ebp 1007e7: 53 push %ebx 1007e8: 50 push %eax - unsigned temp; - - disable(); + unsigned temp; + + disable(); 1007e9: e8 da 44 00 00 call 104cc8 - - /** - * flush the keyboard controller - */ - do - { - temp = inportb(0x64); + + /** + * flush the keyboard controller + */ + do + { + temp = inportb(0x64); 1007ee: 83 ec 0c sub $0xc,%esp 1007f1: 6a 64 push $0x64 1007f3: e8 1c 48 00 00 call 105014 - if((temp & 0x01) != 0) + if((temp & 0x01) != 0) 1007f8: 83 c4 10 add $0x10,%esp 1007fb: a8 01 test $0x1,%al 1007fd: 89 c3 mov %eax,%ebx 1007ff: 75 19 jne 10081a - { - (void)inportb(0x60); - continue; - } - } while((temp & 0x02) != 0); + { + (void)inportb(0x60); + continue; + } + } while((temp & 0x02) != 0); 100801: 83 e3 02 and $0x2,%ebx 100804: 75 e8 jne 1007ee - - /** - * now pulse the cpu reset line - */ - outportb(0x64, 0xFE); + + /** + * now pulse the cpu reset line + */ + outportb(0x64, 0xFE); 100806: 83 ec 08 sub $0x8,%esp 100809: 68 fe 00 00 00 push $0xfe 10080e: 6a 64 push $0x64 100810: e8 9f 48 00 00 call 1050b4 - - /** - * if that didn't work, just halt - */ - while(1); + + /** + * if that didn't work, just halt + */ + while(1); 100815: 83 c4 10 add $0x10,%esp 100818: eb fe jmp 100818 10081a: 83 ec 0c sub $0xc,%esp @@ -1197,21 +1197,21 @@ 100829: 8d 76 00 lea 0x0(%esi),%esi 0010082c <_write_kb>: -} - -/** - * XXX - * - * I'm not even sure if we need the following functions yet, - * however they are here just in case. Leave them alone. - */ - -/** - * _write_kb() - * - */ -static void _write_kb(unsigned adr, unsigned d) -{ +} + +/** + * XXX + * + * I'm not even sure if we need the following functions yet, + * however they are here just in case. Leave them alone. + */ + +/** + * _write_kb() + * + */ +static void _write_kb(unsigned adr, unsigned d) +{ 10082c: 55 push %ebp 10082d: 89 e5 mov %esp,%ebp 10082f: 57 push %edi @@ -1220,32 +1220,32 @@ 100832: 83 ec 0c sub $0xc,%esp 100835: 8b 7d 08 mov 0x8(%ebp),%edi 100838: 8b 75 0c mov 0xc(%ebp),%esi - unsigned long t; - unsigned s; - - for(t = 5000000L; t != 0; t--) + unsigned long t; + unsigned s; + + for(t = 5000000L; t != 0; t--) 10083b: bb 40 4b 4c 00 mov $0x4c4b40,%ebx - { - s = inportb(0x64); + { + s = inportb(0x64); 100840: 83 ec 0c sub $0xc,%esp 100843: 6a 64 push $0x64 100845: e8 ca 47 00 00 call 105014 - - /** - * loop until 8042 input buffer is empty - */ - if((s & 0x02) == 0) + + /** + * loop until 8042 input buffer is empty + */ + if((s & 0x02) == 0) 10084a: 83 c4 10 add $0x10,%esp 10084d: a8 02 test $0x2,%al 10084f: 74 0b je 10085c <_write_kb+0x30> 100851: 4b dec %ebx 100852: 75 ec jne 100840 <_write_kb+0x14> - break; - } - - if(t != 0) - outportb(adr, d); -} + break; + } + + if(t != 0) + outportb(adr, d); +} 100854: 8d 65 f4 lea 0xfffffff4(%ebp),%esp 100857: 5b pop %ebx 100858: 5e pop %esi @@ -1265,285 +1265,285 @@ 100872: 89 f6 mov %esi,%esi 00100874 <_translate_sc>: - -/** - * _kb_wait() - * - */ -static inline void _kb_wait(void) -{ - int i; - - for(i = 0; i < 0x1000000; i++) - if((inportb(0x64) & 0x02) == 0) - return; - - printk(0, "Keyboard timeout\n"); -} - -/** - * _kb_send() - * - */ -static inline void _kb_send(unsigned char c) -{ - _kb_wait(); - outportb(c, 0x64); -} - -/** - * _translate_sc() - * - * Translates a scancode from the keyboard - */ -unsigned _translate_sc(unsigned k) -{ + +/** + * _kb_wait() + * + */ +static inline void _kb_wait(void) +{ + int i; + + for(i = 0; i < 0x1000000; i++) + if((inportb(0x64) & 0x02) == 0) + return; + + printk(0, "Keyboard timeout\n"); +} + +/** + * _kb_send() + * + */ +static inline void _kb_send(unsigned char c) +{ + _kb_wait(); + outportb(c, 0x64); +} + +/** + * _translate_sc() + * + * Translates a scancode from the keyboard + */ +unsigned _translate_sc(unsigned k) +{ 100874: 55 push %ebp 100875: 89 e5 mov %esp,%ebp 100877: 83 ec 08 sub $0x8,%esp 10087a: 8b 45 08 mov 0x8(%ebp),%eax - unsigned c; - static unsigned altk; - unsigned donefirst = 0; - - if(k == KEY_BKSPACE) + unsigned c; + static unsigned altk; + unsigned donefirst = 0; + + if(k == KEY_BKSPACE) 10087d: 83 f8 0e cmp $0xe,%eax 100880: 0f 84 f2 09 00 00 je 101278 <_translate_sc+0xa04> - { - if(numkeysbuffer - 1 < 0) - { - numkeysbuffer = 0; - return 0; - } - } - - switch(k) + { + if(numkeysbuffer - 1 < 0) + { + numkeysbuffer = 0; + return 0; + } + } + + switch(k) 100886: 3d e0 00 00 00 cmp $0xe0,%eax 10088b: 0f 87 d3 09 00 00 ja 101264 <_translate_sc+0x9f0> 100891: ff 24 85 dc 54 10 00 jmp *0x1054dc(,%eax,4) - { - case 0xE0: - altk = 1; c = 0; donefirst = 1; break; + { + case 0xE0: + altk = 1; c = 0; donefirst = 1; break; 100898: 31 d2 xor %edx,%edx 10089a: c7 05 00 80 10 00 01 movl $0x1,0x108000 1008a1: 00 00 00 - case KEY_TILDA: /* ` or ~ */ - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 126 : 126; break; - case KEY_END: c = 0; if(keys[KEYP_NUMLCK] && altk == 0) c = 49; break; - case KEY_1: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 33 : 49; break; - case KEY_DOWN: c = 0; if(keys[KEYP_NUMLCK] && altk == 0) c = 50; break; - case KEY_2: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 64 : 50; break; - case KEY_PGDOWN: c = 0; if(keys[KEYP_NUMLCK] && altk == 0) c = 51; break; - case KEY_3: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 35 : 51; break; - case KEY_LEFT: c = 0; if(keys[KEYP_NUMLCK] && altk == 0) c = 52; break; - case KEY_4: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 36 : 52; break; - case KEYP_5: c = 0; if(keys[KEYP_NUMLCK] && altk == 0) c = 53; break; - case KEY_5: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 35 : 53; break; - case KEY_RIGHT: c = 0; if(keys[KEYP_NUMLCK] && altk == 0) c = 54; break; - case KEY_6: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 94 : 54; break; - case KEY_HOME: c = 0; if(keys[KEYP_NUMLCK] && altk == 0) c = 55; break; - case KEY_7: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 38 : 55; break; - case KEY_UP: c = 0; if(keys[KEYP_NUMLCK] && altk == 0) c = 56; break; - case KEYP_ASTERISK: c = 42; break; - case KEY_8: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 42 : 56; break; - case KEY_PGUP: c = 0; if(keys[KEYP_NUMLCK] && altk == 0) c = 57; break; - case KEY_9: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 40 : 57; break; - case KEY_INSERT: c = 0; if(keys[KEYP_NUMLCK] && altk == 0) c = 48; break; - case KEY_0: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 41 : 48; break; - case KEYP_MINUS: c = 45; break; - case KEY_MINUS: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 95 : 45; break; - case KEYP_PLUS: c = 43; break; - case KEY_PLUS: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 61 : 43; break; - case KEY_BKSLASH: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 124 : 92; break; - case KEY_Q: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 81 : 113; break; - case KEY_W: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 87 : 119; break; - case KEY_E: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 69 : 101; break; - case KEY_R: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 82 : 114; break; - case KEY_T: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 84 : 116; break; - case KEY_Y: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 89 : 121; break; - case KEY_U: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 85 : 117; break; - case KEY_I: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 73 : 105; break; - case KEY_O: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 79 : 111; break; - case KEY_P: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 80 : 112; break; - case KEY_LBRACKET: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 123 : 91; break; - case KEY_RBRACKET: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 125 : 93; break; - case KEY_ENTER: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 10 : 10; break; - case KEY_A: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 65 : 97; break; - case KEY_S: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 83 : 115; break; - case KEY_D: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 68 : 100; break; - case KEY_F: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 70 : 102; break; - case KEY_G: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 71 : 103; break; - case KEY_H: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 72 : 104; break; - case KEY_J: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 74 : 106; break; - case KEY_K: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 75 : 107; break; - case KEY_L: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 76 : 108; break; - case KEY_SEMICOLON: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 58 : 59; break; - case KEY_QUOTE: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 34 : 39; break; - case KEY_Z: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 90 : 122; break; - case KEY_X: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 88 : 120; break; - case KEY_C: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 67 : 99; break; - case KEY_V: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 86 : 118; break; - case KEY_B: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 66 : 98; break; - case KEY_N: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 78 : 110; break; - case KEY_M: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 77 : 109; break; - case KEY_COMMA: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 60 : 44; break; - case KEY_DEL: c = 0; if(keys[KEYP_NUMLCK] && altk == 0) c = 46; break; - case KEY_PERIOD: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 62 : 46; break; - case KEY_SLASH: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 63 : 47; break; - case KEY_SPACE: - c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 32 : 32; break; - case KEY_BKSPACE: c = '\b'; break; /* just for now */ - default: - c = 0; - } - - if(donefirst == 0) - altk = 0; - - if(keys[KEY_CAPS]) + case KEY_TILDA: /* ` or ~ */ + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 126 : 126; break; + case KEY_END: c = 0; if(keys[KEYP_NUMLCK] && altk == 0) c = 49; break; + case KEY_1: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 33 : 49; break; + case KEY_DOWN: c = 0; if(keys[KEYP_NUMLCK] && altk == 0) c = 50; break; + case KEY_2: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 64 : 50; break; + case KEY_PGDOWN: c = 0; if(keys[KEYP_NUMLCK] && altk == 0) c = 51; break; + case KEY_3: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 35 : 51; break; + case KEY_LEFT: c = 0; if(keys[KEYP_NUMLCK] && altk == 0) c = 52; break; + case KEY_4: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 36 : 52; break; + case KEYP_5: c = 0; if(keys[KEYP_NUMLCK] && altk == 0) c = 53; break; + case KEY_5: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 35 : 53; break; + case KEY_RIGHT: c = 0; if(keys[KEYP_NUMLCK] && altk == 0) c = 54; break; + case KEY_6: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 94 : 54; break; + case KEY_HOME: c = 0; if(keys[KEYP_NUMLCK] && altk == 0) c = 55; break; + case KEY_7: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 38 : 55; break; + case KEY_UP: c = 0; if(keys[KEYP_NUMLCK] && altk == 0) c = 56; break; + case KEYP_ASTERISK: c = 42; break; + case KEY_8: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 42 : 56; break; + case KEY_PGUP: c = 0; if(keys[KEYP_NUMLCK] && altk == 0) c = 57; break; + case KEY_9: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 40 : 57; break; + case KEY_INSERT: c = 0; if(keys[KEYP_NUMLCK] && altk == 0) c = 48; break; + case KEY_0: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 41 : 48; break; + case KEYP_MINUS: c = 45; break; + case KEY_MINUS: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 95 : 45; break; + case KEYP_PLUS: c = 43; break; + case KEY_PLUS: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 61 : 43; break; + case KEY_BKSLASH: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 124 : 92; break; + case KEY_Q: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 81 : 113; break; + case KEY_W: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 87 : 119; break; + case KEY_E: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 69 : 101; break; + case KEY_R: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 82 : 114; break; + case KEY_T: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 84 : 116; break; + case KEY_Y: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 89 : 121; break; + case KEY_U: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 85 : 117; break; + case KEY_I: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 73 : 105; break; + case KEY_O: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 79 : 111; break; + case KEY_P: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 80 : 112; break; + case KEY_LBRACKET: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 123 : 91; break; + case KEY_RBRACKET: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 125 : 93; break; + case KEY_ENTER: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 10 : 10; break; + case KEY_A: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 65 : 97; break; + case KEY_S: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 83 : 115; break; + case KEY_D: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 68 : 100; break; + case KEY_F: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 70 : 102; break; + case KEY_G: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 71 : 103; break; + case KEY_H: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 72 : 104; break; + case KEY_J: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 74 : 106; break; + case KEY_K: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 75 : 107; break; + case KEY_L: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 76 : 108; break; + case KEY_SEMICOLON: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 58 : 59; break; + case KEY_QUOTE: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 34 : 39; break; + case KEY_Z: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 90 : 122; break; + case KEY_X: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 88 : 120; break; + case KEY_C: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 67 : 99; break; + case KEY_V: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 86 : 118; break; + case KEY_B: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 66 : 98; break; + case KEY_N: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 78 : 110; break; + case KEY_M: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 77 : 109; break; + case KEY_COMMA: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 60 : 44; break; + case KEY_DEL: c = 0; if(keys[KEYP_NUMLCK] && altk == 0) c = 46; break; + case KEY_PERIOD: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 62 : 46; break; + case KEY_SLASH: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 63 : 47; break; + case KEY_SPACE: + c = (keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) ? 32 : 32; break; + case KEY_BKSPACE: c = '\b'; break; /* just for now */ + default: + c = 0; + } + + if(donefirst == 0) + altk = 0; + + if(keys[KEY_CAPS]) 1008a4: a1 28 84 10 00 mov 0x108428,%eax 1008a9: 85 c0 test %eax,%eax 1008ab: 74 23 je 1008d0 <_translate_sc+0x5c> - { - if(keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) + { + if(keys[KEY_LSHIFT] || keys[KEY_RSHIFT]) 1008ad: a1 e8 83 10 00 mov 0x1083e8,%eax 1008b2: 85 c0 test %eax,%eax 1008b4: 75 0d jne 1008c3 <_translate_sc+0x4f> 1008b6: a1 18 84 10 00 mov 0x108418,%eax 1008bb: 85 c0 test %eax,%eax 1008bd: 0f 84 bd 00 00 00 je 100980 <_translate_sc+0x10c> - { - if(c >= 'A' && c <= 'Z') + { + if(c >= 'A' && c <= 'Z') 1008c3: 8d 42 bf lea 0xffffffbf(%edx),%eax 1008c6: 83 f8 19 cmp $0x19,%eax 1008c9: 77 05 ja 1008d0 <_translate_sc+0x5c> - c += 32; + c += 32; 1008cb: 83 c2 20 add $0x20,%edx 1008ce: 89 f6 mov %esi,%esi - } - else - { - if(c >= 'a' && c <= 'z') - c -= 32; - } - } - - /** - * Simple shell for now - */ - if(c != 0 && c != '\n' && c != '\b') + } + else + { + if(c >= 'a' && c <= 'z') + c -= 32; + } + } + + /** + * Simple shell for now + */ + if(c != 0 && c != '\n' && c != '\b') 1008d0: 85 d2 test %edx,%edx 1008d2: 74 38 je 10090c <_translate_sc+0x98> 1008d4: 83 fa 0a cmp $0xa,%edx 1008d7: 74 63 je 10093c <_translate_sc+0xc8> 1008d9: 83 fa 08 cmp $0x8,%edx 1008dc: 74 2e je 10090c <_translate_sc+0x98> - { - if((numkeysbuffer - 1) == KBD_BUF_SIZE) + { + if((numkeysbuffer - 1) == KBD_BUF_SIZE) 1008de: a1 40 85 10 00 mov 0x108540,%eax 1008e3: 83 f8 41 cmp $0x41,%eax 1008e6: 74 10 je 1008f8 <_translate_sc+0x84> - { - numkeysbuffer = 0; - szInBuf[0] = '\0'; - - szInBuf[numkeysbuffer] = c; - numkeysbuffer++; - } - else - { - szInBuf[numkeysbuffer] = c; + { + numkeysbuffer = 0; + szInBuf[0] = '\0'; + + szInBuf[numkeysbuffer] = c; + numkeysbuffer++; + } + else + { + szInBuf[numkeysbuffer] = c; 1008e8: 88 90 60 85 10 00 mov %dl,0x108560(%eax) - numkeysbuffer++; + numkeysbuffer++; 1008ee: 40 inc %eax 1008ef: a3 40 85 10 00 mov %eax,0x108540 - } - } - else if(c == '\n') - { - printf("\n"); - /** - * Make it a real string - */ - szInBuf[numkeysbuffer] = '\0'; - - /** - * Process command - */ - processCommand(&szInBuf[0], numkeysbuffer - 1); - - /** - * Clear buffer - */ - numkeysbuffer = 0; - szInBuf[0] = '\0'; - - /** - * Print "line" - */ - printf("$ "); - - c = 0; - } - else if(c == '\b') - { - szInBuf[numkeysbuffer] = '\0'; - numkeysbuffer--; - printf("\b \b"); - - c = 0; - } - - return c; + } + } + else if(c == '\n') + { + printf("\n"); + /** + * Make it a real string + */ + szInBuf[numkeysbuffer] = '\0'; + + /** + * Process command + */ + processCommand(&szInBuf[0], numkeysbuffer - 1); + + /** + * Clear buffer + */ + numkeysbuffer = 0; + szInBuf[0] = '\0'; + + /** + * Print "line" + */ + printf("$ "); + + c = 0; + } + else if(c == '\b') + { + szInBuf[numkeysbuffer] = '\0'; + numkeysbuffer--; + printf("\b \b"); + + c = 0; + } + + return c; 1008f4: 89 d0 mov %edx,%eax -} +} 1008f6: c9 leave 1008f7: c3 ret 1008f8: 88 15 60 85 10 00 mov %dl,0x108560 @@ -2180,24 +2180,24 @@ 101296: 89 f6 mov %esi,%esi 00101298 : - -/** - * handle_meta_key() - * - * I'll pretty this up later - */ -void handle_meta_key(unsigned k) -{ + +/** + * handle_meta_key() + * + * I'll pretty this up later + */ +void handle_meta_key(unsigned k) +{ 101298: 55 push %ebp 101299: 89 e5 mov %esp,%ebp 10129b: 83 ec 08 sub $0x8,%esp - int i; - k = k; /* to shut gcc up */ - - /** - * Check for the infamous three finger salute - */ - if((keys[KEY_RCTRL] || keys[KEY_LCTRL]) && + int i; + k = k; /* to shut gcc up */ + + /** + * Check for the infamous three finger salute + */ + if((keys[KEY_RCTRL] || keys[KEY_LCTRL]) && 10129e: 8b 15 b4 83 10 00 mov 0x1083b4,%edx 1012a4: 85 d2 test %edx,%edx 1012a6: 74 69 je 101311 @@ -2208,26 +2208,26 @@ 1012b7: 85 c0 test %eax,%eax 1012b9: 75 51 jne 10130c 1012bb: 90 nop - (keys[KEY_RALT] || keys[KEY_LALT]) && - keys[KEY_DEL]) - { - /** - * FIXME - * - * This should call _send_signal() - */ - reboot(); - } - - /** - * Check for Alt + F1-F12 for virtual terminals - */ - for(i = 0; i < 10; i++) + (keys[KEY_RALT] || keys[KEY_LALT]) && + keys[KEY_DEL]) + { + /** + * FIXME + * + * This should call _send_signal() + */ + reboot(); + } + + /** + * Check for Alt + F1-F12 for virtual terminals + */ + for(i = 0; i < 10; i++) 1012bc: 31 c0 xor %eax,%eax 1012be: b9 40 83 10 00 mov $0x108340,%ecx 1012c3: 90 nop - { - if((keys[KEY_LALT] || keys[KEY_RALT]) && keys[i + KEY_F1]) + { + if((keys[KEY_LALT] || keys[KEY_RALT]) && keys[i + KEY_F1]) 1012c4: 85 d2 test %edx,%edx 1012c6: 74 0a je 1012d2 1012c8: 83 bc 81 ec 00 00 00 cmpl $0x0,0xec(%ecx,%eax,4) @@ -2236,32 +2236,32 @@ 1012d2: 40 inc %eax 1012d3: 83 f8 09 cmp $0x9,%eax 1012d6: 7e ec jle 1012c4 - { - select_vc(i); - return; - } - } - - if((keys[KEY_LALT] || keys[KEY_RALT]) && keys[KEY_F11]) + { + select_vc(i); + return; + } + } + + if((keys[KEY_LALT] || keys[KEY_RALT]) && keys[KEY_F11]) 1012d8: 85 d2 test %edx,%edx 1012da: 74 13 je 1012ef 1012dc: 8b 15 9c 84 10 00 mov 0x10849c,%edx 1012e2: 85 d2 test %edx,%edx 1012e4: 75 18 jne 1012fe - { - select_vc(10); - return; - } - - if((keys[KEY_LALT] || keys[KEY_RALT]) && keys[KEY_F12]) + { + select_vc(10); + return; + } + + if((keys[KEY_LALT] || keys[KEY_RALT]) && keys[KEY_F12]) 1012e6: a1 a0 84 10 00 mov 0x1084a0,%eax 1012eb: 85 c0 test %eax,%eax 1012ed: 75 02 jne 1012f1 - { - select_vc(11); - return; - } -} + { + select_vc(11); + return; + } +} 1012ef: c9 leave 1012f0: c3 ret 1012f1: c7 45 08 0b 00 00 00 movl $0xb,0x8(%ebp) @@ -2277,27 +2277,27 @@ 101319: 8d 76 00 lea 0x0(%esi),%esi 0010131c : - -/** - * keyboard_irq() - * - * Called when a keyboard interrupt is generated. - */ -void keyboard_irq(void) -{ + +/** + * keyboard_irq() + * + * Called when a keyboard interrupt is generated. + */ +void keyboard_irq(void) +{ 10131c: 55 push %ebp 10131d: 89 e5 mov %esp,%ebp 10131f: 53 push %ebx 101320: 83 ec 10 sub $0x10,%esp - register char a; - unsigned c; - unsigned short kbdstat; - - rawkey = inportb(0x60); + register char a; + unsigned c; + unsigned short kbdstat; + + rawkey = inportb(0x60); 101323: 6a 60 push $0x60 101325: e8 ea 3c 00 00 call 105014 10132a: a3 20 83 10 00 mov %eax,0x108320 - outportb(0x61, (a=inportb(0x61)|0x82)); + outportb(0x61, (a=inportb(0x61)|0x82)); 10132f: c7 04 24 61 00 00 00 movl $0x61,(%esp,1) 101336: e8 d9 3c 00 00 call 105014 10133b: 83 c8 82 or $0xffffff82,%eax @@ -2307,169 +2307,169 @@ 101343: 53 push %ebx 101344: 6a 61 push $0x61 101346: e8 69 3d 00 00 call 1050b4 - outportb(0x61, a & 0x7F); + outportb(0x61, a & 0x7F); 10134b: 58 pop %eax 10134c: 5a pop %edx 10134d: 83 e3 7f and $0x7f,%ebx 101350: 53 push %ebx 101351: 6a 61 push $0x61 101353: e8 5c 3d 00 00 call 1050b4 - - /** - * If it's less than 0x80 then it's definatelly - * a make code or a repeat code - */ - if(rawkey < 0x80) + + /** + * If it's less than 0x80 then it's definatelly + * a make code or a repeat code + */ + if(rawkey < 0x80) 101358: 8b 0d 20 83 10 00 mov 0x108320,%ecx 10135e: 83 c4 10 add $0x10,%esp 101361: 83 f9 7f cmp $0x7f,%ecx 101364: 7f 6a jg 1013d0 - { - /** - * We don't want to gunk up the numlock key - * because we will define it's state in the - * break code a bit later - */ - if((rawkey != KEYP_NUMLCK) && (rawkey != KEY_SCRLCK) && (rawkey != KEY_CAPS)) + { + /** + * We don't want to gunk up the numlock key + * because we will define it's state in the + * break code a bit later + */ + if((rawkey != KEYP_NUMLCK) && (rawkey != KEY_SCRLCK) && (rawkey != KEY_CAPS)) 101366: 8d 41 bb lea 0xffffffbb(%ecx),%eax 101369: 83 f8 01 cmp $0x1,%eax 10136c: 76 10 jbe 10137e 10136e: 83 f9 3a cmp $0x3a,%ecx 101371: 74 0b je 10137e - keys[rawkey] = 1; + keys[rawkey] = 1; 101373: c7 04 8d 40 83 10 00 movl $0x1,0x108340(,%ecx,4) 10137a: 01 00 00 00 - - keyDown(rawkey); + + keyDown(rawkey); 10137e: 83 ec 0c sub $0xc,%esp 101381: ff 35 20 83 10 00 pushl 0x108320 101387: e8 c4 ee ff ff call 100250 10138c: 58 pop %eax - } - else /* rawkey >= 0x80 */ - { - if(rawkey == 0xE0) - { - /** - * It's either a make code, break code, or repeat code - */ - rawkey = inportb(0x60); - outportb(0x61, (a=inportb(0x61)|0x82)); - outportb(0x61, a & 0x7F); - - if(rawkey < 0x80) - { - /** - * Ok, it's a make code or repeat code for the numeric - * keypad (gray keys) - */ - - keys[rawkey] = 1; - - keyDown(rawkey); - } - else /* rawkey >= 0x80 */ - { - /** - * It's either a make code for the numeric keypad or - * a break code for the numeric keypad. - */ - if(rawkey == 0x2A) - { - /** - * Ok, we have a make code for the numeric keypad - * and NUMLOCK is on. The second byte is what we - * want since what we have so far is this: - * - * 0xE0 0x2A - */ - rawkey = inportb(0x60); - outportb(0x61, (a=inportb(0x61)|0x82)); - outportb(0x61, a & 0x7F); - - rawkey = inportb(0x60); - outportb(0x61, (a=inportb(0x61)|0x82)); - outportb(0x61, a & 0x7F); - - keys[rawkey] = 1; - - keyDown(rawkey); - } - else - { - /** - * It's a break code from the numeric keypad. - */ - keys[rawkey] = 0; - - keyUp(rawkey); - } - } - } - else /* rawkey != 0xE0 */ - { - /** - * It's a break code - * - * Make sure we toggle the numlock, scroll lock, and caps lock key. - */ - if(((rawkey - 0x80) == KEYP_NUMLCK) || - ((rawkey - 0x80) == KEY_SCRLCK) || - ((rawkey - 0x80) == KEY_CAPS)) - { - keys[rawkey - 0x80] = !keys[rawkey - 0x80]; - - kbdstat = 0; - if(keys[KEY_SCRLCK]) - kbdstat |= 1; - if(keys[KEYP_NUMLCK]) - kbdstat |= 2; - if(keys[KEY_CAPS]) - kbdstat |= 4; - - _write_kb(0x60, 0xED); - _write_kb(0x60, kbdstat); - outportb(0x20, 0x20); - - keyUp(rawkey); - return; - } - - keys[rawkey - 0x80] = 0; - - keyUp(rawkey); - } - } - - c = _translate_sc(rawkey); + } + else /* rawkey >= 0x80 */ + { + if(rawkey == 0xE0) + { + /** + * It's either a make code, break code, or repeat code + */ + rawkey = inportb(0x60); + outportb(0x61, (a=inportb(0x61)|0x82)); + outportb(0x61, a & 0x7F); + + if(rawkey < 0x80) + { + /** + * Ok, it's a make code or repeat code for the numeric + * keypad (gray keys) + */ + + keys[rawkey] = 1; + + keyDown(rawkey); + } + else /* rawkey >= 0x80 */ + { + /** + * It's either a make code for the numeric keypad or + * a break code for the numeric keypad. + */ + if(rawkey == 0x2A) + { + /** + * Ok, we have a make code for the numeric keypad + * and NUMLOCK is on. The second byte is what we + * want since what we have so far is this: + * + * 0xE0 0x2A + */ + rawkey = inportb(0x60); + outportb(0x61, (a=inportb(0x61)|0x82)); + outportb(0x61, a & 0x7F); + + rawkey = inportb(0x60); + outportb(0x61, (a=inportb(0x61)|0x82)); + outportb(0x61, a & 0x7F); + + keys[rawkey] = 1; + + keyDown(rawkey); + } + else + { + /** + * It's a break code from the numeric keypad. + */ + keys[rawkey] = 0; + + keyUp(rawkey); + } + } + } + else /* rawkey != 0xE0 */ + { + /** + * It's a break code + * + * Make sure we toggle the numlock, scroll lock, and caps lock key. + */ + if(((rawkey - 0x80) == KEYP_NUMLCK) || + ((rawkey - 0x80) == KEY_SCRLCK) || + ((rawkey - 0x80) == KEY_CAPS)) + { + keys[rawkey - 0x80] = !keys[rawkey - 0x80]; + + kbdstat = 0; + if(keys[KEY_SCRLCK]) + kbdstat |= 1; + if(keys[KEYP_NUMLCK]) + kbdstat |= 2; + if(keys[KEY_CAPS]) + kbdstat |= 4; + + _write_kb(0x60, 0xED); + _write_kb(0x60, kbdstat); + outportb(0x20, 0x20); + + keyUp(rawkey); + return; + } + + keys[rawkey - 0x80] = 0; + + keyUp(rawkey); + } + } + + c = _translate_sc(rawkey); 10138d: ff 35 20 83 10 00 pushl 0x108320 101393: e8 dc f4 ff ff call 100874 <_translate_sc> - - if(c != 0) + + if(c != 0) 101398: 83 c4 10 add $0x10,%esp 10139b: 85 c0 test %eax,%eax 10139d: 74 21 je 1013c0 - printf("%c", c); + printf("%c", c); 10139f: 83 ec 08 sub $0x8,%esp 1013a2: 50 push %eax 1013a3: 68 e5 51 10 00 push $0x1051e5 1013a8: e8 27 3d 00 00 call 1050d4 1013ad: 59 pop %ecx 1013ae: 5b pop %ebx - else - { - /** - * We need to check for meta-key-crap here - */ - handle_meta_key(rawkey); - } - - //enable(); - outportb(0x20, 0x20); + else + { + /** + * We need to check for meta-key-crap here + */ + handle_meta_key(rawkey); + } + + //enable(); + outportb(0x20, 0x20); 1013af: 6a 20 push $0x20 1013b1: 6a 20 push $0x20 1013b3: e8 fc 3c 00 00 call 1050b4 -} +} 1013b8: 8b 5d fc mov 0xfffffffc(%ebp),%ebx 1013bb: c9 leave 1013bc: c3 ret @@ -2609,55 +2609,55 @@ 10157a: eb ea jmp 101566 0010157c : - -/** - * init_keyboard() - * - */ -void init_keyboard(void) -{ + +/** + * init_keyboard() + * + */ +void init_keyboard(void) +{ 10157c: 55 push %ebp 10157d: 89 e5 mov %esp,%ebp - static unsigned char buffers[KBD_BUF_SIZE * MAX_VC]; - - int i; - - //klog("init", "keyboard %2u buf, %2ub each", K_KLOG_PENDING, &_vc[0]); - for(i = 0; i < MAX_VC; i++) + static unsigned char buffers[KBD_BUF_SIZE * MAX_VC]; + + int i; + + //klog("init", "keyboard %2u buf, %2ub each", K_KLOG_PENDING, &_vc[0]); + for(i = 0; i < MAX_VC; i++) 10157f: b9 20 80 10 00 mov $0x108020,%ecx 101584: 83 ec 08 sub $0x8,%esp 101587: 31 d2 xor %edx,%edx 101589: b8 0b 00 00 00 mov $0xb,%eax - { - _vc[i].keystrokes.data = buffers + KBD_BUF_SIZE * i; + { + _vc[i].keystrokes.data = buffers + KBD_BUF_SIZE * i; 10158e: 89 8a e0 a2 19 00 mov %ecx,0x19a2e0(%edx) - _vc[i].keystrokes.size = KBD_BUF_SIZE; + _vc[i].keystrokes.size = KBD_BUF_SIZE; 101594: c7 82 e4 a2 19 00 40 movl $0x40,0x19a2e4(%edx) 10159b: 00 00 00 10159e: 83 c1 40 add $0x40,%ecx 1015a1: 83 c2 34 add $0x34,%edx 1015a4: 48 dec %eax 1015a5: 79 e7 jns 10158e - } - - for(i = 0; i < 128; i++) + } + + for(i = 0; i < 128; i++) 1015a7: 31 c0 xor %eax,%eax 1015a9: 8d 76 00 lea 0x0(%esi),%esi - keys[i] = 0; + keys[i] = 0; 1015ac: c7 04 85 40 83 10 00 movl $0x0,0x108340(,%eax,4) 1015b3: 00 00 00 00 1015b7: 40 inc %eax 1015b8: 83 f8 7f cmp $0x7f,%eax 1015bb: 7e ef jle 1015ac - - makebreak = 0; - //klog(NULL, K_KLOG_SUCCESS, &_vc[0], NULL); - //kprintf("init_kbd: %u buffers, %u bytes each\n", - // MAX_VC, KBD_BUF_SIZE); - - //kprintf("[ Entering Runlevel 0 ].......................................................Ok"); - _vc[0].attrib = 8; - printf("[ "); + + makebreak = 0; + //klog(NULL, K_KLOG_SUCCESS, &_vc[0], NULL); + //kprintf("init_kbd: %u buffers, %u bytes each\n", + // MAX_VC, KBD_BUF_SIZE); + + //kprintf("[ Entering Runlevel 0 ].......................................................Ok"); + _vc[0].attrib = 8; + printf("[ "); 1015bd: 83 ec 0c sub $0xc,%esp 1015c0: 68 b6 51 10 00 push $0x1051b6 1015c5: c7 05 a0 85 10 00 00 movl $0x0,0x1085a0 @@ -2665,8 +2665,8 @@ 1015cf: c7 05 f8 a2 19 00 08 movl $0x8,0x19a2f8 1015d6: 00 00 00 1015d9: e8 f6 3a 00 00 call 1050d4 - _vc[0].attrib = 15; - printf("init: keyboard %2u buf, %2ub each ", MAX_VC, KBD_BUF_SIZE); + _vc[0].attrib = 15; + printf("init: keyboard %2u buf, %2ub each ", MAX_VC, KBD_BUF_SIZE); 1015de: 83 c4 0c add $0xc,%esp 1015e1: 6a 40 push $0x40 1015e3: 6a 0c push $0xc @@ -2674,22 +2674,22 @@ 1015ea: c7 05 f8 a2 19 00 0f movl $0xf,0x19a2f8 1015f1: 00 00 00 1015f4: e8 db 3a 00 00 call 1050d4 - _vc[0].attrib = 8; - printf("]..........................................."); + _vc[0].attrib = 8; + printf("]..........................................."); 1015f9: c7 04 24 a0 58 10 00 movl $0x1058a0,(%esp,1) 101600: c7 05 f8 a2 19 00 08 movl $0x8,0x19a2f8 101607: 00 00 00 10160a: e8 c5 3a 00 00 call 1050d4 - _vc[0].attrib = 2; - printf("Ok"); + _vc[0].attrib = 2; + printf("Ok"); 10160f: c7 04 24 d9 54 10 00 movl $0x1054d9,(%esp,1) 101616: c7 05 f8 a2 19 00 02 movl $0x2,0x19a2f8 10161d: 00 00 00 101620: e8 af 3a 00 00 call 1050d4 - _vc[0].attrib = 7; + _vc[0].attrib = 7; 101625: c7 05 f8 a2 19 00 07 movl $0x7,0x19a2f8 10162c: 00 00 00 -} +} 10162f: c9 leave 101630: c3 ret ... @@ -8197,264 +8197,264 @@ ... 00103d6c : -/** - * printf/kprintf helper - */ -static int kprintf_help(unsigned c, void **ptr) -{ +/** + * printf/kprintf helper + */ +static int kprintf_help(unsigned c, void **ptr) +{ 103d6c: 55 push %ebp 103d6d: 89 e5 mov %esp,%ebp 103d6f: 83 ec 14 sub $0x14,%esp - /** - * Leave this for now - */ - ptr = ptr; - - putch(c); + /** + * Leave this for now + */ + ptr = ptr; + + putch(c); 103d72: ff 75 08 pushl 0x8(%ebp) 103d75: e8 86 0d 00 00 call 104b00 - return 0; -} + return 0; +} 103d7a: 31 c0 xor %eax,%eax 103d7c: c9 leave 103d7d: c3 ret 103d7e: 89 f6 mov %esi,%esi 00103d80 : - -/** - * Format output and print it to stdout (vtty0) - * Just like on any other operating system - */ -/*void printf(const char *fmt, ...) -{ - va_list args; - - va_start(args, fmt); - (void)do_printf(fmt, args, kprintf_help, NULL); - va_end(args); -}*/ - -void kprintf(const char *fmt, ...) -{ + +/** + * Format output and print it to stdout (vtty0) + * Just like on any other operating system + */ +/*void printf(const char *fmt, ...) +{ + va_list args; + + va_start(args, fmt); + (void)do_printf(fmt, args, kprintf_help, NULL); + va_end(args); +}*/ + +void kprintf(const char *fmt, ...) +{ 103d80: 55 push %ebp 103d81: 89 e5 mov %esp,%ebp 103d83: 83 ec 08 sub $0x8,%esp - va_list args; - - va_start(args, fmt); - (void)do_printf(fmt, args, kprintf_help, NULL); + va_list args; + + va_start(args, fmt); + (void)do_printf(fmt, args, kprintf_help, NULL); 103d86: 6a 00 push $0x0 103d88: 68 6c 3d 10 00 push $0x103d6c 103d8d: 8d 45 0c lea 0xc(%ebp),%eax 103d90: 50 push %eax 103d91: ff 75 08 pushl 0x8(%ebp) 103d94: e8 37 0f 00 00 call 104cd0 - va_end(args); -} + va_end(args); +} 103d99: c9 leave 103d9a: c3 ret 103d9b: 90 nop 00103d9c : - -/** - * Format output and print it to stdout (vtty0) - * Just like on any other operating system - */ -void printk(const char *fmt, ...) -{ + +/** + * Format output and print it to stdout (vtty0) + * Just like on any other operating system + */ +void printk(const char *fmt, ...) +{ 103d9c: 55 push %ebp 103d9d: 89 e5 mov %esp,%ebp 103d9f: 83 ec 08 sub $0x8,%esp - va_list args; - - /** - * TODO - * - * Select vtty0 - */ - va_start(args, fmt); - (void)do_printf(fmt, args, kprintf_help, NULL); + va_list args; + + /** + * TODO + * + * Select vtty0 + */ + va_start(args, fmt); + (void)do_printf(fmt, args, kprintf_help, NULL); 103da2: 6a 00 push $0x0 103da4: 68 6c 3d 10 00 push $0x103d6c 103da9: 8d 45 0c lea 0xc(%ebp),%eax 103dac: 50 push %eax 103dad: ff 75 08 pushl 0x8(%ebp) 103db0: e8 1b 0f 00 00 call 104cd0 - va_end(args); -} + va_end(args); +} 103db5: c9 leave 103db6: c3 ret 103db7: 90 nop 00103db8 : - -/** - * Oh yeah, the fun function ;) - */ -void panic(const char *fmt, ...) -{ + +/** + * Oh yeah, the fun function ;) + */ +void panic(const char *fmt, ...) +{ 103db8: 55 push %ebp 103db9: 89 e5 mov %esp,%ebp 103dbb: 53 push %ebx 103dbc: 50 push %eax - va_list args; - - disable(); /* interrupts off */ + va_list args; + + disable(); /* interrupts off */ 103dbd: e8 06 0f 00 00 call 104cc8 - va_start(args, fmt); - _vc[0].attrib = 15; - printf("\n\npanic: "); + va_start(args, fmt); + _vc[0].attrib = 15; + printf("\n\npanic: "); 103dc2: 83 ec 0c sub $0xc,%esp 103dc5: 68 cd 58 10 00 push $0x1058cd 103dca: c7 05 f8 a2 19 00 0f movl $0xf,0x19a2f8 103dd1: 00 00 00 103dd4: e8 fb 12 00 00 call 1050d4 - (void)do_printf(fmt, args, kprintf_help, NULL); + (void)do_printf(fmt, args, kprintf_help, NULL); 103dd9: 6a 00 push $0x0 103ddb: 68 6c 3d 10 00 push $0x103d6c 103de0: 8d 5d 0c lea 0xc(%ebp),%ebx 103de3: 53 push %ebx 103de4: ff 75 08 pushl 0x8(%ebp) 103de7: e8 e4 0e 00 00 call 104cd0 - - printf("\n\nSystem halted."); + + printf("\n\nSystem halted."); 103dec: 83 c4 14 add $0x14,%esp 103def: 68 d7 58 10 00 push $0x1058d7 103df4: e8 db 12 00 00 call 1050d4 - __asm__ __volatile__ ("hlt"); + __asm__ __volatile__ ("hlt"); 103df9: f4 hlt - - while(1) + + while(1) 103dfa: 83 c4 10 add $0x10,%esp 103dfd: 8d 76 00 lea 0x0(%esi),%esi 103e00: eb fe jmp 103e00 103e02: 89 f6 mov %esi,%esi 00103e04 : - /* freeze */; -} - -/** - * Called when a kernel fault is detected. This does not - * (normally) get called when something goes awry in - * user-space, therefore it is designed for kernel-space - */ -void fault(regs_t *regs) -{ + /* freeze */; +} + +/** + * Called when a kernel fault is detected. This does not + * (normally) get called when something goes awry in + * user-space, therefore it is designed for kernel-space + */ +void fault(regs_t *regs) +{ 103e04: 55 push %ebp 103e05: 89 e5 mov %esp,%ebp 103e07: 53 push %ebx 103e08: 52 push %edx 103e09: 8b 5d 08 mov 0x8(%ebp),%ebx - struct exception - { - char *message; - int signal; - int processor; - }; - - static const struct exception ex[] = - { - {"Divide error", SIGFPE, 86}, - {"Debug exception", SIGTRAP, 86}, - {"Nonmaskable interrupt (NMI)", SIGBUS, 86}, - {"Breakpoint (INT3)", SIGEMT, 86}, - {"Overflow (INTO)", SIGFPE, 186}, - {"Bounds check", SIGFPE, 186}, - {"Invalid opcode", SIGILL, 186}, - {"Coprocessor not available", SIGFPE, 186}, - {"Double fault", SIGBUS, 286}, - {"Coprocessor segment overrun", SIGSEGV, 286}, - {"Invalid TSS", SIGSEGV, 286}, - {"Segment not present", SIGSEGV, 286}, - {"Stack exception", SIGSEGV, 286}, - {"General Protection Fault", SIGSEGV, 286}, - {"Page fault", SIGSEGV, 386}, - {NULL, SIGILL, 0}, - {"Coprocessor error", SIGFPE, 386}, - {"Alignment check",0,0}, - {"??",0,0}, - {"??",0,0}, - {"??",0,0}, - {"??",0,0}, - {"??",0,0}, - {"??",0,0}, - {"??",0,0}, - {"??",0,0}, - {"??",0,0}, - {"??",0,0}, - {"??",0,0}, - {"??",0,0}, - {"??",0,0}, - {"??",0,0}, - {"IRQ0",0,0}, - {"IRQ1",0,0}, - {"IRQ2",0,0}, - {"IRQ3",0,0}, - {"IRQ4",0,0}, - {"IRQ5",0,0}, - {"IRQ6",0,0}, - {"IRQ7",0,0}, - {"IRQ8",0,0}, - {"IRQ9",0,0}, - {"IRQ10",0,0}, - {"IRQ11",0,0}, - {"IRQ12",0,0}, - {"IRQ13",0,0}, - {"IRQ14",0,0}, - {"IRQ15",0,0}, - {"syscall",0,0} - }; - - - switch(regs->which_int) + struct exception + { + char *message; + int signal; + int processor; + }; + + static const struct exception ex[] = + { + {"Divide error", SIGFPE, 86}, + {"Debug exception", SIGTRAP, 86}, + {"Nonmaskable interrupt (NMI)", SIGBUS, 86}, + {"Breakpoint (INT3)", SIGEMT, 86}, + {"Overflow (INTO)", SIGFPE, 186}, + {"Bounds check", SIGFPE, 186}, + {"Invalid opcode", SIGILL, 186}, + {"Coprocessor not available", SIGFPE, 186}, + {"Double fault", SIGBUS, 286}, + {"Coprocessor segment overrun", SIGSEGV, 286}, + {"Invalid TSS", SIGSEGV, 286}, + {"Segment not present", SIGSEGV, 286}, + {"Stack exception", SIGSEGV, 286}, + {"General Protection Fault", SIGSEGV, 286}, + {"Page fault", SIGSEGV, 386}, + {NULL, SIGILL, 0}, + {"Coprocessor error", SIGFPE, 386}, + {"Alignment check",0,0}, + {"??",0,0}, + {"??",0,0}, + {"??",0,0}, + {"??",0,0}, + {"??",0,0}, + {"??",0,0}, + {"??",0,0}, + {"??",0,0}, + {"??",0,0}, + {"??",0,0}, + {"??",0,0}, + {"??",0,0}, + {"??",0,0}, + {"??",0,0}, + {"IRQ0",0,0}, + {"IRQ1",0,0}, + {"IRQ2",0,0}, + {"IRQ3",0,0}, + {"IRQ4",0,0}, + {"IRQ5",0,0}, + {"IRQ6",0,0}, + {"IRQ7",0,0}, + {"IRQ8",0,0}, + {"IRQ9",0,0}, + {"IRQ10",0,0}, + {"IRQ11",0,0}, + {"IRQ12",0,0}, + {"IRQ13",0,0}, + {"IRQ14",0,0}, + {"IRQ15",0,0}, + {"syscall",0,0} + }; + + + switch(regs->which_int) 103e0c: 83 7b 30 20 cmpl $0x20,0x30(%ebx) 103e10: 74 6e je 103e80 - { - /** - * this handler installed at compile-time - * Keyboard handler is installed at run-time (see below) - */ - case 0x20: /* timer IRQ 0 */ - //blink(); - /** - * reset hardware interrupt at 8259 chip - */ - outportb(0x20, 0x20); - break; - default: - _vc[0].attrib = 15; - printf("\n\npanic: Exception 0x%08X", regs->which_int); + { + /** + * this handler installed at compile-time + * Keyboard handler is installed at run-time (see below) + */ + case 0x20: /* timer IRQ 0 */ + //blink(); + /** + * reset hardware interrupt at 8259 chip + */ + outportb(0x20, 0x20); + break; + default: + _vc[0].attrib = 15; + printf("\n\npanic: Exception 0x%08X", regs->which_int); 103e12: 83 ec 08 sub $0x8,%esp 103e15: c7 05 f8 a2 19 00 0f movl $0xf,0x19a2f8 103e1c: 00 00 00 103e1f: ff 73 30 pushl 0x30(%ebx) 103e22: 68 79 5a 10 00 push $0x105a79 103e27: e8 a8 12 00 00 call 1050d4 - if(regs->which_int <= sizeof(ex) / sizeof(ex[0].message)) + if(regs->which_int <= sizeof(ex) / sizeof(ex[0].message)) 103e2c: 8b 43 30 mov 0x30(%ebx),%eax 103e2f: 83 c4 10 add $0x10,%esp 103e32: 3d 93 00 00 00 cmp $0x93,%eax 103e37: 76 2b jbe 103e64 - printf(" (%s)", ex[regs->which_int].message); - printf("\n"); + printf(" (%s)", ex[regs->which_int].message); + printf("\n"); 103e39: 83 ec 0c sub $0xc,%esp 103e3c: 68 f8 5a 10 00 push $0x105af8 103e41: e8 8e 12 00 00 call 1050d4 - dump_regs(regs); + dump_regs(regs); 103e46: 89 1c 24 mov %ebx,(%esp,1) 103e49: e8 7e c3 ff ff call 1001cc - printf("\n\nSystem halted."); + printf("\n\nSystem halted."); 103e4e: c7 04 24 d7 58 10 00 movl $0x1058d7,(%esp,1) 103e55: e8 7a 12 00 00 call 1050d4 - __asm__ __volatile__ ("hlt"); + __asm__ __volatile__ ("hlt"); 103e5a: f4 hlt - break; + break; 103e5b: 83 c4 10 add $0x10,%esp - } -} + } +} 103e5e: 8b 5d fc mov 0xfffffffc(%ebp),%ebx 103e61: c9 leave 103e62: c3 ret @@ -8474,140 +8474,140 @@ 103e8e: 89 f6 mov %esi,%esi 00103e90 : - -/** - * ?? - */ -static void init_8259s(void) -{ + +/** + * ?? + */ +static void init_8259s(void) +{ 103e90: 55 push %ebp 103e91: 89 e5 mov %esp,%ebp 103e93: 83 ec 10 sub $0x10,%esp - static const unsigned irq0_int = 0x20, irq8_int = 0x28; - - /** - * Initialization Control Word #1 (ICW1) - */ - outportb(0x20, 0x11); + static const unsigned irq0_int = 0x20, irq8_int = 0x28; + + /** + * Initialization Control Word #1 (ICW1) + */ + outportb(0x20, 0x11); 103e96: 6a 11 push $0x11 103e98: 6a 20 push $0x20 103e9a: e8 15 12 00 00 call 1050b4 - outportb(0xA0, 0x11); + outportb(0xA0, 0x11); 103e9f: 59 pop %ecx 103ea0: 58 pop %eax 103ea1: 6a 11 push $0x11 103ea3: 68 a0 00 00 00 push $0xa0 103ea8: e8 07 12 00 00 call 1050b4 - - /** - * ICW2: - * route IRQs 0-7 to INTs 20h-27h - */ - outportb(0x21, irq0_int); + + /** + * ICW2: + * route IRQs 0-7 to INTs 20h-27h + */ + outportb(0x21, irq0_int); 103ead: 58 pop %eax 103eae: 5a pop %edx 103eaf: 6a 20 push $0x20 103eb1: 6a 21 push $0x21 103eb3: e8 fc 11 00 00 call 1050b4 - - /** - * route IRQs 8-15 to INTs 28h-2Fh - */ - outportb(0xA1, irq8_int); + + /** + * route IRQs 8-15 to INTs 28h-2Fh + */ + outportb(0xA1, irq8_int); 103eb8: 59 pop %ecx 103eb9: 58 pop %eax 103eba: 6a 28 push $0x28 103ebc: 68 a1 00 00 00 push $0xa1 103ec1: e8 ee 11 00 00 call 1050b4 - - /** - * ICW3 - */ - outportb(0x21, 0x04); + + /** + * ICW3 + */ + outportb(0x21, 0x04); 103ec6: 58 pop %eax 103ec7: 5a pop %edx 103ec8: 6a 04 push $0x4 103eca: 6a 21 push $0x21 103ecc: e8 e3 11 00 00 call 1050b4 - outportb(0xA1, 0x02); + outportb(0xA1, 0x02); 103ed1: 59 pop %ecx 103ed2: 58 pop %eax 103ed3: 6a 02 push $0x2 103ed5: 68 a1 00 00 00 push $0xa1 103eda: e8 d5 11 00 00 call 1050b4 - - /** - * ICW4 - */ - outportb(0x21, 0x01); + + /** + * ICW4 + */ + outportb(0x21, 0x01); 103edf: 58 pop %eax 103ee0: 5a pop %edx 103ee1: 6a 01 push $0x1 103ee3: 6a 21 push $0x21 103ee5: e8 ca 11 00 00 call 1050b4 - outportb(0xA1, 0x01); + outportb(0xA1, 0x01); 103eea: 59 pop %ecx 103eeb: 58 pop %eax 103eec: 6a 01 push $0x1 103eee: 68 a1 00 00 00 push $0xa1 103ef3: e8 bc 11 00 00 call 1050b4 - - /** - * enable IRQ0 (timer) and IRQ1 (keyboard) - */ - outportb(0x21, ~0x03); + + /** + * enable IRQ0 (timer) and IRQ1 (keyboard) + */ + outportb(0x21, ~0x03); 103ef8: 58 pop %eax 103ef9: 5a pop %edx 103efa: 6a fc push $0xfffffffc 103efc: 6a 21 push $0x21 103efe: e8 b1 11 00 00 call 1050b4 - outportb(0xA1, ~0x00); + outportb(0xA1, ~0x00); 103f03: 59 pop %ecx 103f04: 58 pop %eax 103f05: 6a ff push $0xffffffff 103f07: 68 a1 00 00 00 push $0xa1 103f0c: e8 a3 11 00 00 call 1050b4 -} +} 103f11: c9 leave 103f12: c3 ret 103f13: 90 nop 00103f14 : - -/** - * MinGW32 - */ -#ifdef __WIN32__ -#if __GNUC__<3 -#error Do not use MinGW GCC 2.x with NASM -#endif - int __main(void) { return 0; } - void _alloca(void) { } -#endif - -/** - * malloc, realloc, free, etc - */ -static char *g_heap_bot, *g_kbrk, *g_heap_top; -static void dump_heap(void) -{ + +/** + * MinGW32 + */ +#ifdef __WIN32__ +#if __GNUC__<3 +#error Do not use MinGW GCC 2.x with NASM +#endif + int __main(void) { return 0; } + void _alloca(void) { } +#endif + +/** + * malloc, realloc, free, etc + */ +static char *g_heap_bot, *g_kbrk, *g_heap_top; +static void dump_heap(void) +{ 103f14: 55 push %ebp 103f15: 89 e5 mov %esp,%ebp 103f17: 57 push %edi 103f18: 56 push %esi 103f19: 53 push %ebx 103f1a: 83 ec 18 sub $0x18,%esp - unsigned blks_used = 0, blks_free = 0; - size_t bytes_used = 0, bytes_free = 0; - malloc_t *m; - int total; - - kprintf("===============================================\n"); + unsigned blks_used = 0, blks_free = 0; + size_t bytes_used = 0, bytes_free = 0; + malloc_t *m; + int total; + + kprintf("===============================================\n"); 103f1d: 68 60 5d 10 00 push $0x105d60 103f22: c7 45 f0 00 00 00 00 movl $0x0,0xfffffff0(%ebp) 103f29: c7 45 ec 00 00 00 00 movl $0x0,0xffffffec(%ebp) 103f30: e8 4b fe ff ff call 103d80 - for(m = (malloc_t *)g_heap_bot; m != NULL; m = m->next) + for(m = (malloc_t *)g_heap_bot; m != NULL; m = m->next) 103f35: 8b 1d e0 36 18 00 mov 0x1836e0,%ebx 103f3b: 31 ff xor %edi,%edi 103f3d: 31 f6 xor %esi,%esi @@ -8615,8 +8615,8 @@ 103f42: 85 db test %ebx,%ebx 103f44: 74 39 je 103f7f 103f46: 89 f6 mov %esi,%esi - { - printk("block %5p: %6u bytes %s\n", m, + { + printk("block %5p: %6u bytes %s\n", m, 103f48: f6 43 09 80 testb $0x80,0x9(%ebx) 103f4c: 0f 84 be 00 00 00 je 104010 103f52: b8 99 5a 10 00 mov $0x105a99,%eax @@ -8625,36 +8625,36 @@ 103f5a: 53 push %ebx 103f5b: 68 9e 5a 10 00 push $0x105a9e 103f60: e8 37 fe ff ff call 103d9c - m->size, m->used ? "used" : "free"); - if(m->used) + m->size, m->used ? "used" : "free"); + if(m->used) 103f65: 83 c4 10 add $0x10,%esp 103f68: f6 43 09 80 testb $0x80,0x9(%ebx) 103f6c: 0f 84 92 00 00 00 je 104004 - { - blks_used++; - bytes_used += m->size; + { + blks_used++; + bytes_used += m->size; 103f72: 8b 03 mov (%ebx),%eax 103f74: 47 inc %edi 103f75: 01 45 f0 add %eax,0xfffffff0(%ebp) 103f78: 8b 5b 04 mov 0x4(%ebx),%ebx 103f7b: 85 db test %ebx,%ebx 103f7d: 75 c9 jne 103f48 - } - else - { - blks_free++; - bytes_free += m->size; - } - } - kprintf("blocks: %6u used, %6u free, %6u total\n", blks_used, + } + else + { + blks_free++; + bytes_free += m->size; + } + } + kprintf("blocks: %6u used, %6u free, %6u total\n", blks_used, 103f7f: 8d 1c 3e lea (%esi,%edi,1),%ebx 103f82: 53 push %ebx 103f83: 56 push %esi 103f84: 57 push %edi 103f85: 68 a0 5d 10 00 push $0x105da0 103f8a: e8 f1 fd ff ff call 103d80 - blks_free, blks_used + blks_free); - kprintf(" bytes: %6u used, %6u free, %6u total\n", bytes_used, + blks_free, blks_used + blks_free); + kprintf(" bytes: %6u used, %6u free, %6u total\n", bytes_used, 103f8f: 8b 75 f0 mov 0xfffffff0(%ebp),%esi 103f92: 03 75 ec add 0xffffffec(%ebp),%esi 103f95: 56 push %esi @@ -8662,35 +8662,35 @@ 103f99: ff 75 f0 pushl 0xfffffff0(%ebp) 103f9c: 68 e0 5d 10 00 push $0x105de0 103fa1: e8 da fd ff ff call 103d80 - bytes_free, bytes_used + bytes_free); - kprintf("g_heap_bot=0x%p, g_kbrk=0x%p, g_heap_top=0x%p\n", + bytes_free, bytes_used + bytes_free); + kprintf("g_heap_bot=0x%p, g_kbrk=0x%p, g_heap_top=0x%p\n", 103fa6: 83 c4 20 add $0x20,%esp 103fa9: ff 35 e8 36 18 00 pushl 0x1836e8 103faf: ff 35 e4 36 18 00 pushl 0x1836e4 103fb5: ff 35 e0 36 18 00 pushl 0x1836e0 103fbb: 68 20 5e 10 00 push $0x105e20 103fc0: e8 bb fd ff ff call 103d80 - g_heap_bot, g_kbrk, g_heap_top); - total = (bytes_used + bytes_free) + + g_heap_bot, g_kbrk, g_heap_top); + total = (bytes_used + bytes_free) + 103fc5: 8d 1c 5b lea (%ebx,%ebx,2),%ebx - (blks_used + blks_free) * sizeof(malloc_t); - if(total != g_kbrk - g_heap_bot) + (blks_used + blks_free) * sizeof(malloc_t); + if(total != g_kbrk - g_heap_bot) 103fc8: a1 e4 36 18 00 mov 0x1836e4,%eax 103fcd: 8d 1c 9e lea (%esi,%ebx,4),%ebx 103fd0: 2b 05 e0 36 18 00 sub 0x1836e0,%eax 103fd6: 83 c4 10 add $0x10,%esp 103fd9: 39 c3 cmp %eax,%ebx 103fdb: 74 10 je 103fed - kprintf("*** some heap memory is not accounted for\n"); + kprintf("*** some heap memory is not accounted for\n"); 103fdd: 83 ec 0c sub $0xc,%esp 103fe0: 68 60 5e 10 00 push $0x105e60 103fe5: e8 96 fd ff ff call 103d80 103fea: 83 c4 10 add $0x10,%esp - kprintf("===============================================\n"); + kprintf("===============================================\n"); 103fed: 83 ec 0c sub $0xc,%esp 103ff0: 68 60 5d 10 00 push $0x105d60 103ff5: e8 86 fd ff ff call 103d80 -} +} 103ffa: 8d 65 f4 lea 0xfffffff4(%ebp),%esp 103ffd: 5b pop %ebx 103ffe: 5e pop %esi @@ -8708,116 +8708,116 @@ 10401a: 89 f6 mov %esi,%esi 0010401c : - -void dumpheapk(void) -{ + +void dumpheapk(void) +{ 10401c: 55 push %ebp 10401d: 89 e5 mov %esp,%ebp - dump_heap(); + dump_heap(); 10401f: c9 leave 104020: e9 ef fe ff ff jmp 103f14 104025: 8d 76 00 lea 0x0(%esi),%esi 00104028 : -} - -/** - * POSIX sbrk() looks like this - * void *sbrk(int incr); - * - * Mine is a bit different so I can signal the calling function - * if more memory than desired was allocated (e.g. in a system with paging) - * If your kbrk()/sbrk() always allocates the amount of memory you ask for, - * this code can be easily changed. - * - * int brk( void *sbrk( void *kbrk( - * function void *adr); int delta); int *delta); - * ---------------------- ------------ ------------ ------------- - * POSIX? yes yes NO - * return value if error -1 -1 NULL - * get break value . sbrk(0) int x=0; kbrk(&x); - * set break value to X brk(X) sbrk(X - sbrk(0)) int x=X, y=0; kbrk(&x) - kbrk(&y); - * enlarge heap by N bytes . sbrk(+N) int x=N; kbrk(&x); - * shrink heap by N bytes . sbrk(-N) int x=-N; kbrk(&x); - * can you tell if you're - * given more memory - * than you wanted? no no yes - */ -static void *kbrk(int *delta) -{ - static char heap[HEAP_SIZE]; - char *new_brk, *old_brk; - - /** - * heap doesn't exist yet - */ - if(g_heap_bot == NULL) +} + +/** + * POSIX sbrk() looks like this + * void *sbrk(int incr); + * + * Mine is a bit different so I can signal the calling function + * if more memory than desired was allocated (e.g. in a system with paging) + * If your kbrk()/sbrk() always allocates the amount of memory you ask for, + * this code can be easily changed. + * + * int brk( void *sbrk( void *kbrk( + * function void *adr); int delta); int *delta); + * ---------------------- ------------ ------------ ------------- + * POSIX? yes yes NO + * return value if error -1 -1 NULL + * get break value . sbrk(0) int x=0; kbrk(&x); + * set break value to X brk(X) sbrk(X - sbrk(0)) int x=X, y=0; kbrk(&x) - kbrk(&y); + * enlarge heap by N bytes . sbrk(+N) int x=N; kbrk(&x); + * shrink heap by N bytes . sbrk(-N) int x=-N; kbrk(&x); + * can you tell if you're + * given more memory + * than you wanted? no no yes + */ +static void *kbrk(int *delta) +{ + static char heap[HEAP_SIZE]; + char *new_brk, *old_brk; + + /** + * heap doesn't exist yet + */ + if(g_heap_bot == NULL) 104028: 8b 0d e0 36 18 00 mov 0x1836e0,%ecx 10402e: 55 push %ebp 10402f: 85 c9 test %ecx,%ecx 104031: 89 e5 mov %esp,%ebp 104033: 53 push %ebx 104034: 75 1f jne 104055 - { - g_heap_bot = g_kbrk = heap; + { + g_heap_bot = g_kbrk = heap; 104036: b9 c0 95 10 00 mov $0x1095c0,%ecx 10403b: c7 05 e4 36 18 00 c0 movl $0x1095c0,0x1836e4 104042: 95 10 00 104045: 89 0d e0 36 18 00 mov %ecx,0x1836e0 - g_heap_top = g_heap_bot + HEAP_SIZE; + g_heap_top = g_heap_bot + HEAP_SIZE; 10404b: c7 05 e8 36 18 00 e0 movl $0x1836e0,0x1836e8 104052: 36 18 00 - } - new_brk = g_kbrk + (*delta); + } + new_brk = g_kbrk + (*delta); 104055: 8b 1d e4 36 18 00 mov 0x1836e4,%ebx 10405b: 8b 45 08 mov 0x8(%ebp),%eax 10405e: 89 da mov %ebx,%edx 104060: 03 10 add (%eax),%edx - - /** - * too low: return NULL - */ - if(new_brk < g_heap_bot) + + /** + * too low: return NULL + */ + if(new_brk < g_heap_bot) 104062: 31 c0 xor %eax,%eax 104064: 39 ca cmp %ecx,%edx 104066: 72 10 jb 104078 - return NULL; - - /** - * too high: return NULL - */ - if(new_brk >= g_heap_top) + return NULL; + + /** + * too high: return NULL + */ + if(new_brk >= g_heap_top) 104068: 3b 15 e8 36 18 00 cmp 0x1836e8,%edx 10406e: 73 08 jae 104078 - return NULL; - - /** - * success: adjust brk value... - */ - old_brk = g_kbrk; - g_kbrk = new_brk; + return NULL; + + /** + * success: adjust brk value... + */ + old_brk = g_kbrk; + g_kbrk = new_brk; 104070: 89 15 e4 36 18 00 mov %edx,0x1836e4 - - /** - * ...return actual delta... (for this sbrk(), they are the same) - * (*delta) = (*delta); - * ...return old brk value - */ - return old_brk; + + /** + * ...return actual delta... (for this sbrk(), they are the same) + * (*delta) = (*delta); + * ...return old brk value + */ + return old_brk; 104076: 89 d8 mov %ebx,%eax -} +} 104078: 8b 1c 24 mov (%esp,1),%ebx 10407b: c9 leave 10407c: c3 ret 10407d: 8d 76 00 lea 0x0(%esi),%esi 00104080 : - -/** - * malloc() and free() use g_heap_bot, but not g_kbrk nor g_heap_top - */ -void *kmalloc(size_t size) -{ + +/** + * malloc() and free() use g_heap_bot, but not g_kbrk nor g_heap_top + */ +void *kmalloc(size_t size) +{ 104080: 55 push %ebp 104081: 89 e5 mov %esp,%ebp 104083: 57 push %edi @@ -8825,48 +8825,48 @@ 104085: 53 push %ebx 104086: 83 ec 0c sub $0xc,%esp 104089: 8b 7d 08 mov 0x8(%ebp),%edi - unsigned total_size; - malloc_t *m, *n; - int delta; - - if(size == 0) + unsigned total_size; + malloc_t *m, *n; + int delta; + + if(size == 0) 10408c: 31 c0 xor %eax,%eax 10408e: 85 ff test %edi,%edi 104090: 0f 84 af 00 00 00 je 104145 - return NULL; - total_size = size + sizeof(malloc_t); - - /** - * search heap for free block (FIRST FIT) - */ - m = (malloc_t *)g_heap_bot; + return NULL; + total_size = size + sizeof(malloc_t); + + /** + * search heap for free block (FIRST FIT) + */ + m = (malloc_t *)g_heap_bot; 104096: 8b 1d e0 36 18 00 mov 0x1836e0,%ebx - - /** - * g_heap_bot == 0 == NULL if heap does not yet exist - */ - if(m != NULL) + + /** + * g_heap_bot == 0 == NULL if heap does not yet exist + */ + if(m != NULL) 10409c: 85 db test %ebx,%ebx 10409e: 8d 77 0c lea 0xc(%edi),%esi 1040a1: 74 35 je 1040d8 - { - if(m->magic != MALLOC_MAGIC) + { + if(m->magic != MALLOC_MAGIC) 1040a3: 0f b7 43 08 movzwl 0x8(%ebx),%eax 1040a7: 25 ff 7f 00 00 and $0x7fff,%eax 1040ac: 3d 92 6d 00 00 cmp $0x6d92,%eax 1040b1: 0f 85 e5 00 00 00 jne 10419c - { - /*printf("*** kernel heap is corrupt in kmalloc()\n");*/ - panic("kernel heap is corrupt in malloc()"); - return NULL; - } - for(; m->next != NULL; m = m->next) + { + /*printf("*** kernel heap is corrupt in kmalloc()\n");*/ + panic("kernel heap is corrupt in malloc()"); + return NULL; + } + for(; m->next != NULL; m = m->next) 1040b7: 8b 43 04 mov 0x4(%ebx),%eax 1040ba: 85 c0 test %eax,%eax 1040bc: 74 1a je 1040d8 1040be: 89 f6 mov %esi,%esi - { - if(m->used) + { + if(m->used) 1040c0: 8a 53 09 mov 0x9(%ebx),%dl 1040c3: f6 c2 80 test $0x80,%dl 1040c6: 0f 84 8c 00 00 00 je 104158 @@ -8875,118 +8875,118 @@ 1040d1: 85 c0 test %eax,%eax 1040d3: 75 eb jne 1040c0 1040d5: 8d 76 00 lea 0x0(%esi),%esi - continue; - - /** - * size == m->size is a perfect fit - */ - if(size == m->size) - m->used = 1; - else - { - /** - * otherwise, we need an extra sizeof(malloc_t) bytes for the header - * of a second, free block - */ - if(total_size > m->size) - continue; - - /** - * create a new, smaller free block after this one - */ - n = (malloc_t *)((char *)m + total_size); - n->size = m->size - total_size; - n->next = m->next; - n->magic = MALLOC_MAGIC; - n->used = 0; - - /** - * reduce the size of this block and mark it used - */ - m->size = size; - m->next = n; - m->used = 1; - } - return (char *)m + sizeof(malloc_t); - } - } - - /** - * use kbrk() to enlarge (or create!) heap - */ - delta = total_size; - n = kbrk(&delta); + continue; + + /** + * size == m->size is a perfect fit + */ + if(size == m->size) + m->used = 1; + else + { + /** + * otherwise, we need an extra sizeof(malloc_t) bytes for the header + * of a second, free block + */ + if(total_size > m->size) + continue; + + /** + * create a new, smaller free block after this one + */ + n = (malloc_t *)((char *)m + total_size); + n->size = m->size - total_size; + n->next = m->next; + n->magic = MALLOC_MAGIC; + n->used = 0; + + /** + * reduce the size of this block and mark it used + */ + m->size = size; + m->next = n; + m->used = 1; + } + return (char *)m + sizeof(malloc_t); + } + } + + /** + * use kbrk() to enlarge (or create!) heap + */ + delta = total_size; + n = kbrk(&delta); 1040d8: 83 ec 0c sub $0xc,%esp 1040db: 8d 45 f0 lea 0xfffffff0(%ebp),%eax 1040de: 50 push %eax 1040df: 89 75 f0 mov %esi,0xfffffff0(%ebp) 1040e2: e8 41 ff ff ff call 104028 1040e7: 89 c2 mov %eax,%edx - - /** - * uh-oh - */ - if(n == NULL) + + /** + * uh-oh + */ + if(n == NULL) 1040e9: 83 c4 10 add $0x10,%esp 1040ec: 31 c0 xor %eax,%eax 1040ee: 85 d2 test %edx,%edx 1040f0: 74 53 je 104145 - return NULL; - - if(m != NULL) + return NULL; + + if(m != NULL) 1040f2: 85 db test %ebx,%ebx 1040f4: 74 03 je 1040f9 - m->next = n; + m->next = n; 1040f6: 89 53 04 mov %edx,0x4(%ebx) - - n->size = size; - n->magic = MALLOC_MAGIC; + + n->size = size; + n->magic = MALLOC_MAGIC; 1040f9: 66 8b 42 08 mov 0x8(%edx),%ax 1040fd: 25 00 80 ff ff and $0xffff8000,%eax 104102: 0d 92 6d 00 00 or $0x6d92,%eax 104107: 66 89 42 08 mov %ax,0x8(%edx) - n->used = 1; + n->used = 1; 10410b: 80 4a 09 80 orb $0x80,0x9(%edx) - - /** - * did kbrk() return the exact amount of memory we wanted? - * cast to make "gcc -Wall -W ..." shut the hell up - */ - if((int)total_size == delta) + + /** + * did kbrk() return the exact amount of memory we wanted? + * cast to make "gcc -Wall -W ..." shut the hell up + */ + if((int)total_size == delta) 10410f: 8b 45 f0 mov 0xfffffff0(%ebp),%eax 104112: 39 c6 cmp %eax,%esi 104114: 89 3a mov %edi,(%edx) 104116: 74 35 je 10414d - n->next = NULL; - else - { - - /** - * it returned more than we wanted (it will never return less): - * create a new, free block - */ - m = (malloc_t *)((char *)n + total_size); - m->size = delta - total_size - sizeof(malloc_t); + n->next = NULL; + else + { + + /** + * it returned more than we wanted (it will never return less): + * create a new, free block + */ + m = (malloc_t *)((char *)n + total_size); + m->size = delta - total_size - sizeof(malloc_t); 104118: 29 f0 sub %esi,%eax 10411a: 8d 1c 16 lea (%esi,%edx,1),%ebx 10411d: 83 e8 0c sub $0xc,%eax 104120: 89 03 mov %eax,(%ebx) - m->next = NULL; - m->magic = MALLOC_MAGIC; + m->next = NULL; + m->magic = MALLOC_MAGIC; 104122: 66 8b 43 08 mov 0x8(%ebx),%ax 104126: 25 00 80 ff ff and $0xffff8000,%eax 10412b: 0d 92 6d 00 00 or $0x6d92,%eax 104130: 66 89 43 08 mov %ax,0x8(%ebx) 104134: c7 43 04 00 00 00 00 movl $0x0,0x4(%ebx) - m->used = 0; + m->used = 0; 10413b: 80 63 09 7f andb $0x7f,0x9(%ebx) - - n->next = m; + + n->next = m; 10413f: 89 5a 04 mov %ebx,0x4(%edx) - } - return (char *)n + sizeof(malloc_t); + } + return (char *)n + sizeof(malloc_t); 104142: 8d 42 0c lea 0xc(%edx),%eax -} +} 104145: 8d 65 f4 lea 0xfffffff4(%ebp),%esp 104148: 5b pop %ebx 104149: 5e pop %esi @@ -9026,87 +9026,87 @@ 1041ad: 8d 76 00 lea 0x0(%esi),%esi 001041b0 : - -void kfree(void *blk) -{ + +void kfree(void *blk) +{ 1041b0: 55 push %ebp 1041b1: 89 e5 mov %esp,%ebp 1041b3: 56 push %esi 1041b4: 53 push %ebx 1041b5: 8b 5d 08 mov 0x8(%ebp),%ebx - malloc_t *m, *n; - - /** - * get address of header - */ - m = (malloc_t *)((char *)blk - sizeof(malloc_t)); + malloc_t *m, *n; + + /** + * get address of header + */ + m = (malloc_t *)((char *)blk - sizeof(malloc_t)); 1041b8: 8d 4b f4 lea 0xfffffff4(%ebx),%ecx - if(m->magic != MALLOC_MAGIC) + if(m->magic != MALLOC_MAGIC) 1041bb: 0f b7 41 08 movzwl 0x8(%ecx),%eax 1041bf: 25 ff 7f 00 00 and $0x7fff,%eax 1041c4: 3d 92 6d 00 00 cmp $0x6d92,%eax 1041c9: 74 15 je 1041e0 - { - /*printf("*** attempt to kfree() block at 0x%p with bad magic value\n", blk);*/ - panic("attempt to free() block at 0x%p with bad magic value", blk); + { + /*printf("*** attempt to kfree() block at 0x%p with bad magic value\n", blk);*/ + panic("attempt to free() block at 0x%p with bad magic value", blk); 1041cb: 83 ec 08 sub $0x8,%esp 1041ce: 53 push %ebx 1041cf: 68 e0 5e 10 00 push $0x105ee0 1041d4: e8 df fb ff ff call 103db8 - return; - } - - /** - * find this block in the heap - */ - n = (malloc_t *)g_heap_bot; - if(n->magic != MALLOC_MAGIC) - { - /*printf("*** kernel heap is corrupt in kfree()\n");*/ - panic("kernel heap is corrupt in free()"); - return; - } - for(; n != NULL; n = n->next) - { - if(n == m) - break; - } - - /** - * not found? bad pointer or no heap or something else? - */ - if(n == NULL) - { - /*printf("*** attempt to kfree() block at 0x%p that is not in the heap\n", blk);*/ - panic("attempt to free() block at 0x%p that is not in the heap", blk); - return; - } - - /** - * free the block - */ - m->used = 0; - - /** - * coalesce adjacent free blocks - * Hard to spell, hard to do - */ - for(m = (malloc_t *)g_heap_bot; m != NULL; m = m->next) - { - while(!m->used && m->next != NULL && !m->next->used) - { - /** - * resize this block - */ - m->size += sizeof(malloc_t) + m->next->size; - - /** - * merge with next block - */ - m->next = m->next->next; - } - } -} + return; + } + + /** + * find this block in the heap + */ + n = (malloc_t *)g_heap_bot; + if(n->magic != MALLOC_MAGIC) + { + /*printf("*** kernel heap is corrupt in kfree()\n");*/ + panic("kernel heap is corrupt in free()"); + return; + } + for(; n != NULL; n = n->next) + { + if(n == m) + break; + } + + /** + * not found? bad pointer or no heap or something else? + */ + if(n == NULL) + { + /*printf("*** attempt to kfree() block at 0x%p that is not in the heap\n", blk);*/ + panic("attempt to free() block at 0x%p that is not in the heap", blk); + return; + } + + /** + * free the block + */ + m->used = 0; + + /** + * coalesce adjacent free blocks + * Hard to spell, hard to do + */ + for(m = (malloc_t *)g_heap_bot; m != NULL; m = m->next) + { + while(!m->used && m->next != NULL && !m->next->used) + { + /** + * resize this block + */ + m->size += sizeof(malloc_t) + m->next->size; + + /** + * merge with next block + */ + m->next = m->next->next; + } + } +} 1041d9: 8d 65 f8 lea 0xfffffff8(%ebp),%esp 1041dc: 5b pop %ebx 1041dd: 5e pop %esi @@ -9177,37 +9177,37 @@ 104285: 8d 76 00 lea 0x0(%esi),%esi 00104288 : - -void testheap(void) -{ + +void testheap(void) +{ 104288: 55 push %ebp 104289: 89 e5 mov %esp,%ebp 10428b: 83 ec 14 sub $0x14,%esp - //int i; - //char *t; - //kprintf("before char *t = kmalloc((size_t *)25):\n"); - //dump_heap(); - //t = kmalloc(25); - //strcpy(t, "123456789012345678901234"); - //kprintf("after char *t = kmalloc((size_t *)25):\n"); - //dump_heap(); - //kfree(t); - //kprintf("after kfree(t):\n"); - //dump_heap(); - //kprintf("before char *t = kmalloc((size_t *)25):\n"); - - kprintf("Unable to run testheap -- kmalloc() is broken.\n"); + //int i; + //char *t; + //kprintf("before char *t = kmalloc((size_t *)25):\n"); + //dump_heap(); + //t = kmalloc(25); + //strcpy(t, "123456789012345678901234"); + //kprintf("after char *t = kmalloc((size_t *)25):\n"); + //dump_heap(); + //kfree(t); + //kprintf("after kfree(t):\n"); + //dump_heap(); + //kprintf("before char *t = kmalloc((size_t *)25):\n"); + + kprintf("Unable to run testheap -- kmalloc() is broken.\n"); 10428e: 68 a0 5f 10 00 push $0x105fa0 104293: e8 e8 fa ff ff call 103d80 -} +} 104298: c9 leave 104299: c3 ret 10429a: 89 f6 mov %esi,%esi 0010429c : - -void *krealloc(void *blk, size_t size) -{ + +void *krealloc(void *blk, size_t size) +{ 10429c: 55 push %ebp 10429d: 89 e5 mov %esp,%ebp 10429f: 57 push %edi @@ -9215,64 +9215,64 @@ 1042a1: 53 push %ebx 1042a2: 83 ec 0c sub $0xc,%esp 1042a5: 8b 5d 0c mov 0xc(%ebp),%ebx - void *new_blk; - malloc_t *m; - - /** - * size == 0: free block - */ - if(size == 0) + void *new_blk; + malloc_t *m; + + /** + * size == 0: free block + */ + if(size == 0) 1042a8: 85 db test %ebx,%ebx 1042aa: 8b 75 08 mov 0x8(%ebp),%esi 1042ad: 75 1d jne 1042cc - { - if(blk != NULL) + { + if(blk != NULL) 1042af: 85 f6 test %esi,%esi 1042b1: 74 0c je 1042bf - kfree(blk); + kfree(blk); 1042b3: 83 ec 0c sub $0xc,%esp 1042b6: 56 push %esi 1042b7: e8 f4 fe ff ff call 1041b0 1042bc: 83 c4 10 add $0x10,%esp - new_blk = NULL; + new_blk = NULL; 1042bf: 31 ff xor %edi,%edi - } - else - { - /** - * allocate new block - */ - new_blk = kmalloc(size); - - /** - * if allocation OK, and if old block exists, copy old block to new - */ - if(new_blk != NULL && blk != NULL) - { - m = (malloc_t *)((char *)blk - sizeof(malloc_t)); - if(m->magic != MALLOC_MAGIC) - { - /*printf("*** attempt to krealloc() block at 0x%p with bad magic value\n", blk);*/ - panic("attempt to realloc() block at 0x%p with bad magic value", blk); - return NULL; - } - - /** - * copy minimum of old and new block sizes - */ - if(size > m->size) - size = m->size; - memcpy(new_blk, blk, size); - - /** - * free the old block - */ - kfree(blk); - } - } - return new_blk; + } + else + { + /** + * allocate new block + */ + new_blk = kmalloc(size); + + /** + * if allocation OK, and if old block exists, copy old block to new + */ + if(new_blk != NULL && blk != NULL) + { + m = (malloc_t *)((char *)blk - sizeof(malloc_t)); + if(m->magic != MALLOC_MAGIC) + { + /*printf("*** attempt to krealloc() block at 0x%p with bad magic value\n", blk);*/ + panic("attempt to realloc() block at 0x%p with bad magic value", blk); + return NULL; + } + + /** + * copy minimum of old and new block sizes + */ + if(size > m->size) + size = m->size; + memcpy(new_blk, blk, size); + + /** + * free the old block + */ + kfree(blk); + } + } + return new_blk; 1042c1: 89 f8 mov %edi,%eax -} +} 1042c3: 8d 65 f4 lea 0xfffffff4(%ebp),%esp 1042c6: 5b pop %ebx 1042c7: 5e pop %esi @@ -9315,49 +9315,49 @@ 104323: 90 nop 00104324
: - -void keyboardISR(void); - -int main(void) -{ + +void keyboardISR(void); + +int main(void) +{ 104324: 55 push %ebp 104325: 89 e5 mov %esp,%ebp 104327: 83 ec 08 sub $0x8,%esp 10432a: 83 e4 f0 and $0xfffffff0,%esp - /** - * keyboard interrupt init - */ - vector_t v; - unsigned i; - - init_video(); + /** + * keyboard interrupt init + */ + vector_t v; + unsigned i; + + init_video(); 10432d: e8 e6 07 00 00 call 104b18 - init_keyboard(); + init_keyboard(); 104332: e8 45 d2 ff ff call 10157c - init_8259s(); + init_8259s(); 104337: e8 54 fb ff ff call 103e90 - - /** - * XXX: - * i know this is a very ugly way of doing this, - * however it is the only way it can be done for now. - * in the future, i will implement a kprintf function - * whose sole purpose will be writing boot messages. - * - * Also, the color codes need to be mapped to constants - * in order to make using them a hell of a lot easier. - */ - - klog("init", "Installing keyboard interrupt handler", K_KLOG_PENDING, &_vc[0]); + + /** + * XXX: + * i know this is a very ugly way of doing this, + * however it is the only way it can be done for now. + * in the future, i will implement a kprintf function + * whose sole purpose will be writing boot messages. + * + * Also, the color codes need to be mapped to constants + * in order to make using them a hell of a lot easier. + */ + + klog("init", "Installing keyboard interrupt handler", K_KLOG_PENDING, &_vc[0]); 10433c: 68 e0 a2 19 00 push $0x19a2e0 104341: 6a 01 push $0x1 104343: 68 20 60 10 00 push $0x106020 104348: 68 bc 5a 10 00 push $0x105abc 10434d: e8 ae bc ff ff call 100000 - /* we don't save the old vector */ - v.eip = (unsigned)keyboard_irq; - v.access_byte = 0x8E; /* present, ring 0, '386 interrupt gate */ - setvect(&v, 0x21); + /* we don't save the old vector */ + v.eip = (unsigned)keyboard_irq; + v.access_byte = 0x8E; /* present, ring 0, '386 interrupt gate */ + setvect(&v, 0x21); 104352: 58 pop %eax 104353: 5a pop %edx 104354: 8d 45 f8 lea 0xfffffff8(%ebp),%eax @@ -9366,207 +9366,207 @@ 10435a: c7 45 fc 1c 13 10 00 movl $0x10131c,0xfffffffc(%ebp) 104361: c7 45 f8 8e 00 00 00 movl $0x8e,0xfffffff8(%ebp) 104368: e8 c4 d3 ff ff call 101731 <_setvect> - klog(NULL, NULL, K_KLOG_SUCCESS, &_vc[0]); + klog(NULL, NULL, K_KLOG_SUCCESS, &_vc[0]); 10436d: 68 e0 a2 19 00 push $0x19a2e0 104372: 6a 00 push $0x0 104374: 6a 00 push $0x0 104376: 6a 00 push $0x0 104378: e8 83 bc ff ff call 100000 - - /*init_tasks();*/ - - klog("init", "Enabling hardware interrupts", K_KLOG_PENDING, &_vc[0]); + + /*init_tasks();*/ + + klog("init", "Enabling hardware interrupts", K_KLOG_PENDING, &_vc[0]); 10437d: 83 c4 20 add $0x20,%esp 104380: 68 e0 a2 19 00 push $0x19a2e0 104385: 6a 01 push $0x1 104387: 68 c1 5a 10 00 push $0x105ac1 10438c: 68 bc 5a 10 00 push $0x105abc 104391: e8 6a bc ff ff call 100000 - enable(); + enable(); 104396: e8 71 0c 00 00 call 10500c - /*for(i = 0; i < 0xFFFFFFF; i++);*/ - klog(NULL, NULL, K_KLOG_SUCCESS, &_vc[0]); + /*for(i = 0; i < 0xFFFFFFF; i++);*/ + klog(NULL, NULL, K_KLOG_SUCCESS, &_vc[0]); 10439b: 68 e0 a2 19 00 push $0x19a2e0 1043a0: 6a 00 push $0x0 1043a2: 6a 00 push $0x0 1043a4: 6a 00 push $0x0 1043a6: e8 55 bc ff ff call 100000 - - /** - * Initialize memory management - */ - /*_mm_init();*/ - - /** - * finished init, time for some gooey ;) - */ - printf(" _ _ _ _ ____ _____ ___ "); + + /** + * Initialize memory management + */ + /*_mm_init();*/ + + /** + * finished init, time for some gooey ;) + */ + printf(" _ _ _ _ ____ _____ ___ "); 1043ab: 83 c4 14 add $0x14,%esp 1043ae: 68 60 60 10 00 push $0x106060 1043b3: e8 1c 0d 00 00 call 1050d4 - printf(" ( )_( )( \\/ )( _ \\( _ )/ __) "); + printf(" ( )_( )( \\/ )( _ \\( _ )/ __) "); 1043b8: c7 04 24 c0 60 10 00 movl $0x1060c0,(%esp,1) 1043bf: e8 10 0d 00 00 call 1050d4 - printf(" ) _ ( \\ / ) _ < )(_)( \\__ \\ "); + printf(" ) _ ( \\ / ) _ < )(_)( \\__ \\ "); 1043c4: c7 04 24 20 61 10 00 movl $0x106120,(%esp,1) 1043cb: e8 04 0d 00 00 call 1050d4 - printf(" (_) (_) (__) (____/(_____)(___/ \n"); + printf(" (_) (_) (__) (____/(_____)(___/ \n"); 1043d0: c7 04 24 80 61 10 00 movl $0x106180,(%esp,1) 1043d7: e8 f8 0c 00 00 call 1050d4 - - printf(" Hybrid Operating System (HybOS) \n"); + + printf(" Hybrid Operating System (HybOS) \n"); 1043dc: c7 04 24 e0 61 10 00 movl $0x1061e0,(%esp,1) 1043e3: e8 ec 0c 00 00 call 1050d4 - - /** - * XXX: debug only - */ - printf("ALT + F1 - F8 for virtual terminals\n"); + + /** + * XXX: debug only + */ + printf("ALT + F1 - F8 for virtual terminals\n"); 1043e8: c7 04 24 40 62 10 00 movl $0x106240,(%esp,1) 1043ef: e8 e0 0c 00 00 call 1050d4 - printf("Three finger salute to restart\n"); + printf("Three finger salute to restart\n"); 1043f4: c7 04 24 80 62 10 00 movl $0x106280,(%esp,1) 1043fb: e8 d4 0c 00 00 call 1050d4 - printf("More work needs to be done\n"); + printf("More work needs to be done\n"); 104400: c7 04 24 de 5a 10 00 movl $0x105ade,(%esp,1) 104407: e8 c8 0c 00 00 call 1050d4 - printf("$ "); + printf("$ "); 10440c: c7 04 24 d6 54 10 00 movl $0x1054d6,(%esp,1) 104413: e8 bc 0c 00 00 call 1050d4 - - /** - * fork (kfork()) control over to a shell - */ - /*init_shell();*/ - - /** - * idle task/thread - */ - while(1) + + /** + * fork (kfork()) control over to a shell + */ + /*init_shell();*/ + + /** + * idle task/thread + */ + while(1) 104418: 83 c4 10 add $0x10,%esp 10441b: 90 nop - { - schedule(); + { + schedule(); 10441c: e8 47 01 00 00 call 104568 104421: eb f9 jmp 10441c ... 00104424 <_mm_init>: -void _mm_page_copy_dword(uint32_t dest, uint32_t src); -void _mm_virtual_init(void); - -void _mm_init(void) -{ +void _mm_page_copy_dword(uint32_t dest, uint32_t src); +void _mm_virtual_init(void); + +void _mm_init(void) +{ 104424: 55 push %ebp 104425: 89 e5 mov %esp,%ebp 104427: 83 ec 08 sub $0x8,%esp - klog("init", "Initializing memory management", K_KLOG_PENDING, &_vc[0]); + klog("init", "Initializing memory management", K_KLOG_PENDING, &_vc[0]); 10442a: 68 e0 a2 19 00 push $0x19a2e0 10442f: 6a 01 push $0x1 104431: 68 a0 62 10 00 push $0x1062a0 104436: 68 bc 5a 10 00 push $0x105abc 10443b: e8 c0 bb ff ff call 100000 - _mm_physical_init(); + _mm_physical_init(); 104440: e8 17 00 00 00 call 10445c <_mm_physical_init> - _mm_virtual_init(); + _mm_virtual_init(); 104445: e8 ce 00 00 00 call 104518 <_mm_virtual_init> - klog((void *)0, (void *)0, K_KLOG_SUCCESS, &_vc[0]); + klog((void *)0, (void *)0, K_KLOG_SUCCESS, &_vc[0]); 10444a: 68 e0 a2 19 00 push $0x19a2e0 10444f: 6a 00 push $0x0 104451: 6a 00 push $0x0 104453: 6a 00 push $0x0 104455: e8 a6 bb ff ff call 100000 -} +} 10445a: c9 leave 10445b: c3 ret 0010445c <_mm_physical_init>: - -void _mm_physical_init(void) -{ + +void _mm_physical_init(void) +{ 10445c: 55 push %ebp 10445d: 89 e5 mov %esp,%ebp - unsigned i; - unsigned size = 16 * 1024 * 1024; - - size /= PAGESIZE; - size++; - size /= 32; - - buffer = (unsigned *)0x40000; + unsigned i; + unsigned size = 16 * 1024 * 1024; + + size /= PAGESIZE; + size++; + size /= 32; + + buffer = (unsigned *)0x40000; 10445f: ba 00 00 04 00 mov $0x40000,%edx 104464: c7 05 84 72 19 00 00 movl $0x40000,0x197284 10446b: 00 04 00 - bufferIterator = (unsigned *)0x40000; + bufferIterator = (unsigned *)0x40000; 10446e: c7 05 80 72 19 00 00 movl $0x40000,0x197280 104475: 00 04 00 - - for(i = 0; i < 72; i++) + + for(i = 0; i < 72; i++) 104478: 31 c0 xor %eax,%eax 10447a: 89 f6 mov %esi,%esi - buffer[i] = 0xFFFFFFFF; + buffer[i] = 0xFFFFFFFF; 10447c: c7 04 82 ff ff ff ff movl $0xffffffff,(%edx,%eax,4) 104483: 40 inc %eax 104484: 83 f8 47 cmp $0x47,%eax 104487: 76 f3 jbe 10447c <_mm_physical_init+0x20> 104489: b8 48 00 00 00 mov $0x48,%eax 10448e: 89 f6 mov %esi,%esi - - for(i = 72; i < size; i++) - buffer[i] = 0x00000000; + + for(i = 72; i < size; i++) + buffer[i] = 0x00000000; 104490: c7 04 82 00 00 00 00 movl $0x0,(%edx,%eax,4) 104497: 40 inc %eax 104498: 3d 80 00 00 00 cmp $0x80,%eax 10449d: 72 f1 jb 104490 <_mm_physical_init+0x34> -} +} 10449f: c9 leave 1044a0: c3 ret 1044a1: 8d 76 00 lea 0x0(%esi),%esi 001044a4 <_mm_physical_alloc>: - -unsigned _mm_physical_alloc(void) -{ + +unsigned _mm_physical_alloc(void) +{ 1044a4: 55 push %ebp 1044a5: 89 e5 mov %esp,%ebp 1044a7: 56 push %esi 1044a8: 53 push %ebx - unsigned mask = 0x00000001; - unsigned bit = 0; - - /** - * Search for a free space - */ - while(*bufferIterator == 0xFFFFFFFF) + unsigned mask = 0x00000001; + unsigned bit = 0; + + /** + * Search for a free space + */ + while(*bufferIterator == 0xFFFFFFFF) 1044a9: 8b 15 80 72 19 00 mov 0x197280,%edx 1044af: 31 f6 xor %esi,%esi 1044b1: 83 3a ff cmpl $0xffffffff,(%edx) 1044b4: b9 01 00 00 00 mov $0x1,%ecx 1044b9: 74 1f je 1044da <_mm_physical_alloc+0x36> - bufferIterator++; - - /** - * Search for a bit that indicates a free page - */ - while(*bufferIterator & mask) + bufferIterator++; + + /** + * Search for a bit that indicates a free page + */ + while(*bufferIterator & mask) 1044bb: 8b 02 mov (%edx),%eax 1044bd: a8 01 test $0x1,%al 1044bf: 74 0a je 1044cb <_mm_physical_alloc+0x27> 1044c1: 8d 76 00 lea 0x0(%esi),%esi - { - mask <<= 1; + { + mask <<= 1; 1044c4: d1 e1 shl %ecx - bit++; + bit++; 1044c6: 46 inc %esi 1044c7: 85 c1 test %eax,%ecx 1044c9: 75 f9 jne 1044c4 <_mm_physical_alloc+0x20> - } - - *bufferIterator |= mask; + } + + *bufferIterator |= mask; 1044cb: 09 0a or %ecx,(%edx) - - return 32 * (bufferIterator - buffer) + bit; -} + + return 32 * (bufferIterator - buffer) + bit; +} 1044cd: 5b pop %ebx 1044ce: 2b 15 84 72 19 00 sub 0x197284,%edx 1044d4: 8d 04 d6 lea (%esi,%edx,8),%eax @@ -9584,14 +9584,14 @@ 1044f3: 90 nop 001044f4 <_mm_physical_free>: - -void _mm_physical_free(unsigned page) -{ + +void _mm_physical_free(unsigned page) +{ 1044f4: 55 push %ebp 1044f5: 89 e5 mov %esp,%ebp 1044f7: 8b 4d 08 mov 0x8(%ebp),%ecx 1044fa: 53 push %ebx - buffer[page >> 5] &= ~(1 << (page & 0x1F)); /* confused yet?!? */ + buffer[page >> 5] &= ~(1 << (page & 0x1F)); /* confused yet?!? */ 1044fb: b8 fe ff ff ff mov $0xfffffffe,%eax 104500: 89 cb mov %ecx,%ebx 104502: 83 e1 1f and $0x1f,%ecx @@ -9599,15 +9599,15 @@ 104508: 8b 15 84 72 19 00 mov 0x197284,%edx 10450e: d3 c0 rol %cl,%eax 104510: 21 04 9a and %eax,(%edx,%ebx,4) -} +} 104513: 8b 1c 24 mov (%esp,1),%ebx 104516: c9 leave 104517: c3 ret 00104518 <_mm_virtual_init>: - -void _mm_virtual_init(void) -{ + +void _mm_virtual_init(void) +{ 104518: 55 push %ebp 104519: 89 e5 mov %esp,%ebp 10451b: c9 leave @@ -9615,28 +9615,28 @@ 10451d: 8d 76 00 lea 0x0(%esi),%esi 00104520 <_mm_page_copy_byte>: -} - -void _mm_page_copy_byte(uint32_t dest, uint32_t src) -{ +} + +void _mm_page_copy_byte(uint32_t dest, uint32_t src) +{ 104520: 55 push %ebp 104521: 89 e5 mov %esp,%ebp 104523: 57 push %edi 104524: 56 push %esi 104525: 8b 7d 08 mov 0x8(%ebp),%edi 104528: 8b 75 0c mov 0xc(%ebp),%esi - __asm__ __volatile__ + __asm__ __volatile__ 10452b: b9 00 00 10 00 mov $0x100000,%ecx 104530: fc cld 104531: f3 a4 repz movsb %ds:(%esi),%es:(%edi) - ( - "cld;" - "rep; movsb;" - : - : "c" (1024*1024), "D" (dest), "S" (src) - : "memory" - ); -} + ( + "cld;" + "rep; movsb;" + : + : "c" (1024*1024), "D" (dest), "S" (src) + : "memory" + ); +} 104533: 5e pop %esi 104534: 5f pop %edi 104535: c9 leave @@ -9644,54 +9644,54 @@ 104537: 90 nop 00104538 <_mm_page_copy_word>: - -void _mm_page_copy_word(uint32_t dest, uint32_t src) -{ + +void _mm_page_copy_word(uint32_t dest, uint32_t src) +{ 104538: 55 push %ebp 104539: 89 e5 mov %esp,%ebp 10453b: 57 push %edi 10453c: 56 push %esi 10453d: 8b 7d 08 mov 0x8(%ebp),%edi 104540: 8b 75 0c mov 0xc(%ebp),%esi - __asm__ __volatile__ + __asm__ __volatile__ 104543: b9 00 00 08 00 mov $0x80000,%ecx 104548: fc cld 104549: f3 66 a5 repz movsw %ds:(%esi),%es:(%edi) - ( - "cld;" - "rep; movsw;" - : - : "c" (512*1024), "D" (dest), "S" (src) - : "memory" - ); -} + ( + "cld;" + "rep; movsw;" + : + : "c" (512*1024), "D" (dest), "S" (src) + : "memory" + ); +} 10454c: 5e pop %esi 10454d: 5f pop %edi 10454e: c9 leave 10454f: c3 ret 00104550 <_mm_page_copy_dword>: - -void _mm_page_copy_dword(uint32_t dest, uint32_t src) -{ + +void _mm_page_copy_dword(uint32_t dest, uint32_t src) +{ 104550: 55 push %ebp 104551: 89 e5 mov %esp,%ebp 104553: 57 push %edi 104554: 56 push %esi 104555: 8b 7d 08 mov 0x8(%ebp),%edi 104558: 8b 75 0c mov 0xc(%ebp),%esi - __asm__ __volatile__ + __asm__ __volatile__ 10455b: b9 00 00 04 00 mov $0x40000,%ecx 104560: fc cld 104561: f3 a5 repz movsl %ds:(%esi),%es:(%edi) - ( - "cld;" - "rep; movsl;" - : - : "c" (256*1024), "D" (dest), "S" (src) - : "memory" - ); -} + ( + "cld;" + "rep; movsl;" + : + : "c" (256*1024), "D" (dest), "S" (src) + : "memory" + ); +} 104563: 5e pop %esi 104564: 5f pop %edi 104565: c9 leave @@ -9850,11 +9850,11 @@ ... 001045f4 : - * write() - * - */ -static int write(const unsigned char *str, unsigned len) -{ + * write() + * + */ +static int write(const unsigned char *str, unsigned len) +{ 1045f4: 55 push %ebp 1045f5: 89 e5 mov %esp,%ebp 1045f7: 57 push %edi @@ -9862,19 +9862,19 @@ 1045f9: 53 push %ebx 1045fa: 83 ec 0c sub $0xc,%esp 1045fd: 8b 7d 0c mov 0xc(%ebp),%edi - unsigned i; - - for(i = 0; i < len; i++) + unsigned i; + + for(i = 0; i < len; i++) 104600: 31 f6 xor %esi,%esi 104602: 39 fe cmp %edi,%esi 104604: 8b 5d 08 mov 0x8(%ebp),%ebx 104607: 72 0b jb 104614 - { - putch_help(_curr_task->vc, *str); - str++; - } - return i; -} + { + putch_help(_curr_task->vc, *str); + str++; + } + return i; +} 104609: 8d 65 f4 lea 0xfffffff4(%ebp),%esp 10460c: 5b pop %ebx 10460d: 89 f0 mov %esi,%eax @@ -9898,231 +9898,231 @@ 104632: 89 f6 mov %esi,%esi 00104634 : - -/** - * yield() - * - */ -static void yield(void) -{ + +/** + * yield() + * + */ +static void yield(void) +{ 104634: 55 push %ebp 104635: 89 e5 mov %esp,%ebp - schedule(); + schedule(); 104637: c9 leave 104638: e9 2b ff ff ff jmp 104568 10463d: 8d 76 00 lea 0x0(%esi),%esi 00104640 : -} - -#define WAIT 0xFFFFFL - -/** - * wait() - */ -static void wait(void) -{ +} + +#define WAIT 0xFFFFFL + +/** + * wait() + */ +static void wait(void) +{ 104640: 55 push %ebp 104641: 89 e5 mov %esp,%ebp - unsigned long wait; - - for(wait = WAIT; wait != 0; wait--) + unsigned long wait; + + for(wait = WAIT; wait != 0; wait--) 104643: b8 ff ff 0f 00 mov $0xfffff,%eax 104648: 48 dec %eax 104649: 75 fd jne 104648 - /* nothing */; -} + /* nothing */; +} 10464b: c9 leave 10464c: c3 ret 10464d: 8d 76 00 lea 0x0(%esi),%esi 00104650 : - -/** - * task1() - * - */ -void task1(void) -{ + +/** + * task1() + * + */ +void task1(void) +{ 104650: 55 push %ebp 104651: 89 e5 mov %esp,%ebp 104653: 83 ec 08 sub $0x8,%esp 104656: 89 f6 mov %esi,%esi - //static const unsigned char msg_a[] = "root@hybos $ "; -/**/ - - //write(msg_a, sizeof(msg_a)); - wait(); + //static const unsigned char msg_a[] = "root@hybos $ "; +/**/ + + //write(msg_a, sizeof(msg_a)); + wait(); 104658: e8 e3 ff ff ff call 104640 - while(1) - { - /* so we can process other events */ - yield(); + while(1) + { + /* so we can process other events */ + yield(); 10465d: e8 d2 ff ff ff call 104634 - wait(); + wait(); 104662: eb f4 jmp 104658 00104664 : - } -} - -/** - * task2() - * - */ -void task2(void) -{ + } +} + +/** + * task2() + * + */ +void task2(void) +{ 104664: 55 push %ebp 104665: 89 e5 mov %esp,%ebp 104667: 83 ec 08 sub $0x8,%esp 10466a: 89 f6 mov %esi,%esi - //static const unsigned char msg_a[] = "root@hybos $ "; -/**/ - - //write(msg_a, sizeof(msg_a)); - wait(); + //static const unsigned char msg_a[] = "root@hybos $ "; +/**/ + + //write(msg_a, sizeof(msg_a)); + wait(); 10466c: e8 cf ff ff ff call 104640 - while(1) - { - yield(); + while(1) + { + yield(); 104671: e8 be ff ff ff call 104634 - wait(); + wait(); 104676: eb f4 jmp 10466c 00104678 : - } -} - -/** - * task3() - * - */ -void task3(void) -{ + } +} + +/** + * task3() + * + */ +void task3(void) +{ 104678: 55 push %ebp 104679: 89 e5 mov %esp,%ebp 10467b: 83 ec 08 sub $0x8,%esp 10467e: 89 f6 mov %esi,%esi - //static const unsigned char msg_a[] = "root@hybos $ "; -/**/ - - //write(msg_a, sizeof(msg_a)); - wait(); + //static const unsigned char msg_a[] = "root@hybos $ "; +/**/ + + //write(msg_a, sizeof(msg_a)); + wait(); 104680: e8 bb ff ff ff call 104640 - while(1) - { - yield(); + while(1) + { + yield(); 104685: e8 aa ff ff ff call 104634 - wait(); + wait(); 10468a: eb f4 jmp 104680 0010468c : - } -} - -/** - * task4() - * - */ -void task4(void) -{ + } +} + +/** + * task4() + * + */ +void task4(void) +{ 10468c: 55 push %ebp 10468d: 89 e5 mov %esp,%ebp 10468f: 83 ec 08 sub $0x8,%esp 104692: 89 f6 mov %esi,%esi - //static const unsigned char msg_a[] = "root@hybos $ "; -/**/ - - //write(msg_a, sizeof(msg_a)); - wait(); + //static const unsigned char msg_a[] = "root@hybos $ "; +/**/ + + //write(msg_a, sizeof(msg_a)); + wait(); 104694: e8 a7 ff ff ff call 104640 - while(1) - { - yield(); + while(1) + { + yield(); 104699: e8 96 ff ff ff call 104634 - wait(); + wait(); 10469e: eb f4 jmp 104694 001046a0 : - * blink() - * - */ -void blink(void) -{ + * blink() + * + */ +void blink(void) +{ 1046a0: 55 push %ebp - (*(unsigned char *)_vga_fb_adr)++; + (*(unsigned char *)_vga_fb_adr)++; 1046a1: a1 28 3a 18 00 mov 0x183a28,%eax 1046a6: 89 e5 mov %esp,%ebp 1046a8: fe 00 incb (%eax) -} +} 1046aa: c9 leave 1046ab: c3 ret 001046ac : - -/** - * get_current_vc() - * - */ -unsigned get_current_vc() -{ + +/** + * get_current_vc() + * + */ +unsigned get_current_vc() +{ 1046ac: 55 push %ebp 1046ad: 89 e5 mov %esp,%ebp - return curr_vtty; + return curr_vtty; 1046af: a1 c0 a2 19 00 mov 0x19a2c0,%eax -} +} 1046b4: c9 leave 1046b5: c3 ret 1046b6: 89 f6 mov %esi,%esi 001046b8 : - -/** - * scroll() - * - */ -static void scroll(console_t *con) -{ + +/** + * scroll() + * + */ +static void scroll(console_t *con) +{ 1046b8: 55 push %ebp 1046b9: 89 e5 mov %esp,%ebp 1046bb: 57 push %edi 1046bc: 56 push %esi 1046bd: 53 push %ebx 1046be: 83 ec 0c sub $0xc,%esp - unsigned short *fb_adr; - unsigned blank, temp; - - blank = 0x20 | ((unsigned)con->attrib << 8); + unsigned short *fb_adr; + unsigned blank, temp; + + blank = 0x20 | ((unsigned)con->attrib << 8); 1046c1: 8b 45 08 mov 0x8(%ebp),%eax 1046c4: 8b 70 18 mov 0x18(%eax),%esi 1046c7: c1 e6 08 shl $0x8,%esi - fb_adr = con->fb_adr; + fb_adr = con->fb_adr; 1046ca: 8b 78 30 mov 0x30(%eax),%edi - - /** - * scroll up - */ - if(con->csr_y >= _vc_height) + + /** + * scroll up + */ + if(con->csr_y >= _vc_height) 1046cd: 8b 15 34 3a 18 00 mov 0x183a34,%edx 1046d3: 8b 40 20 mov 0x20(%eax),%eax 1046d6: 83 ce 20 or $0x20,%esi 1046d9: 39 d0 cmp %edx,%eax 1046db: 73 0b jae 1046e8 - { - temp = con->csr_y - _vc_height + 1; - memcpy(fb_adr, fb_adr + temp * _vc_width, - (_vc_height - temp) * _vc_width * 2); - - /** - * blank bottom line of screen - */ - memsetw(fb_adr + (_vc_height - temp) * _vc_width, - blank, _vc_width); - con->csr_y = _vc_height - 1; - } - - //for(i = 0; i < 0x1000000; i++) ; -} + { + temp = con->csr_y - _vc_height + 1; + memcpy(fb_adr, fb_adr + temp * _vc_width, + (_vc_height - temp) * _vc_width * 2); + + /** + * blank bottom line of screen + */ + memsetw(fb_adr + (_vc_height - temp) * _vc_width, + blank, _vc_width); + con->csr_y = _vc_height - 1; + } + + //for(i = 0; i < 0x1000000; i++) ; +} 1046dd: 8d 65 f4 lea 0xfffffff4(%ebp),%esp 1046e0: 5b pop %ebx 1046e1: 5e pop %esi @@ -10161,47 +10161,47 @@ 10473a: 89 f6 mov %esi,%esi 0010473c : - -/** - * set_attrib() - * - */ -static void set_attrib(console_t *con, unsigned att) -{ + +/** + * set_attrib() + * + */ +static void set_attrib(console_t *con, unsigned att) +{ 10473c: 55 push %ebp 10473d: 89 e5 mov %esp,%ebp 10473f: 8b 4d 0c mov 0xc(%ebp),%ecx 104742: 53 push %ebx - static const unsigned ansi_to_vga[] = - { - 0, 4, 2, 6, 1, 5, 3, 7 - }; - - unsigned new_att; - - new_att = con->attrib; - if(att == 0) + static const unsigned ansi_to_vga[] = + { + 0, 4, 2, 6, 1, 5, 3, 7 + }; + + unsigned new_att; + + new_att = con->attrib; + if(att == 0) 104743: 85 c9 test %ecx,%ecx 104745: 8b 5d 08 mov 0x8(%ebp),%ebx 104748: 8b 53 18 mov 0x18(%ebx),%edx 10474b: 75 0b jne 104758 - new_att &= ~0x08; /* bold off */ + new_att &= ~0x08; /* bold off */ 10474d: 83 e2 f7 and $0xfffffff7,%edx - else if(att == 1) - new_att |= 0x08; /* bold on */ - else if(att >= 30 && att <= 37) - { - att = ansi_to_vga[att - 30]; - new_att = (new_att & ~0x07) | att;/* fg color */ - } - else if(att >= 40 && att <= 47) - { - att = ansi_to_vga[att - 40] << 4; - new_att = (new_att & ~0x70) | att;/* bg color */ - } - con->attrib = new_att; + else if(att == 1) + new_att |= 0x08; /* bold on */ + else if(att >= 30 && att <= 37) + { + att = ansi_to_vga[att - 30]; + new_att = (new_att & ~0x07) | att;/* fg color */ + } + else if(att >= 40 && att <= 47) + { + att = ansi_to_vga[att - 40] << 4; + new_att = (new_att & ~0x70) | att;/* bg color */ + } + con->attrib = new_att; 104750: 89 53 18 mov %edx,0x18(%ebx) -} +} 104753: 8b 1c 24 mov (%esp,1),%ebx 104756: c9 leave 104757: c3 ret @@ -10228,34 +10228,34 @@ 104795: 8d 76 00 lea 0x0(%esi),%esi 00104798 : - -/** - * move_csr() - * - */ -static void move_csr(void) -{ + +/** + * move_csr() + * + */ +static void move_csr(void) +{ 104798: 55 push %ebp 104799: 89 e5 mov %esp,%ebp 10479b: 53 push %ebx 10479c: 83 ec 0c sub $0xc,%esp - unsigned temp; - - temp = (_curr_vc->csr_y * _vc_width + _curr_vc->csr_x) + + unsigned temp; + + temp = (_curr_vc->csr_y * _vc_width + _curr_vc->csr_x) + 10479f: a1 24 3a 18 00 mov 0x183a24,%eax 1047a4: 8b 1d 30 3a 18 00 mov 0x183a30,%ebx 1047aa: 0f af 58 20 imul 0x20(%eax),%ebx 1047ae: 03 58 1c add 0x1c(%eax),%ebx 1047b1: 8b 40 30 mov 0x30(%eax),%eax 1047b4: 2b 05 28 3a 18 00 sub 0x183a28,%eax - (_curr_vc->fb_adr - _vga_fb_adr); - outportb(_crtc_io_adr + 0, 14); + (_curr_vc->fb_adr - _vga_fb_adr); + outportb(_crtc_io_adr + 0, 14); 1047ba: 6a 0e push $0xe 1047bc: d1 f8 sar %eax 1047be: ff 35 2c 3a 18 00 pushl 0x183a2c 1047c4: 01 c3 add %eax,%ebx 1047c6: e8 e9 08 00 00 call 1050b4 - outportb(_crtc_io_adr + 1, temp >> 8); + outportb(_crtc_io_adr + 1, temp >> 8); 1047cb: 59 pop %ecx 1047cc: 58 pop %eax 1047cd: 89 d8 mov %ebx,%eax @@ -10265,13 +10265,13 @@ 1047d8: 40 inc %eax 1047d9: 50 push %eax 1047da: e8 d5 08 00 00 call 1050b4 - outportb(_crtc_io_adr + 0, 15); + outportb(_crtc_io_adr + 0, 15); 1047df: 58 pop %eax 1047e0: 5a pop %edx 1047e1: 6a 0f push $0xf 1047e3: ff 35 2c 3a 18 00 pushl 0x183a2c 1047e9: e8 c6 08 00 00 call 1050b4 - outportb(_crtc_io_adr + 1, temp); + outportb(_crtc_io_adr + 1, temp); 1047ee: 5a pop %edx 1047ef: 59 pop %ecx 1047f0: a1 2c 3a 18 00 mov 0x183a2c,%eax @@ -10279,43 +10279,43 @@ 1047f6: 40 inc %eax 1047f7: 50 push %eax 1047f8: e8 b7 08 00 00 call 1050b4 -} +} 1047fd: 8b 5d fc mov 0xfffffffc(%ebp),%ebx 104800: c9 leave 104801: c3 ret 104802: 89 f6 mov %esi,%esi 00104804 : - - -/** - * select_vc() - * - */ -void select_vc(unsigned which_vc) -{ + + +/** + * select_vc() + * + */ +void select_vc(unsigned which_vc) +{ 104804: 55 push %ebp 104805: 89 e5 mov %esp,%ebp 104807: 56 push %esi 104808: 53 push %ebx 104809: 8b 75 08 mov 0x8(%ebp),%esi - unsigned i; - - if(which_vc >= _num_vcs) + unsigned i; + + if(which_vc >= _num_vcs) 10480c: 3b 35 20 3a 18 00 cmp 0x183a20,%esi 104812: 72 08 jb 10481c - return; - _curr_vc = _vc + which_vc; - i = _curr_vc->fb_adr - _vga_fb_adr; - outportb(_crtc_io_adr + 0, 12); - outportb(_crtc_io_adr + 1, i >> 8); - outportb(_crtc_io_adr + 0, 13); - outportb(_crtc_io_adr + 1, i); - - curr_vtty = which_vc; - - move_csr(); -} + return; + _curr_vc = _vc + which_vc; + i = _curr_vc->fb_adr - _vga_fb_adr; + outportb(_crtc_io_adr + 0, 12); + outportb(_crtc_io_adr + 1, i >> 8); + outportb(_crtc_io_adr + 0, 13); + outportb(_crtc_io_adr + 1, i); + + curr_vtty = which_vc; + + move_csr(); +} 104814: 8d 65 f8 lea 0xfffffff8(%ebp),%esp 104817: 5b pop %ebx 104818: 5e pop %esi @@ -10364,13 +10364,13 @@ 10488f: 90 nop 00104890 : - -/** - * putch_help() - * - */ -void putch_help(console_t *con, unsigned c) -{ + +/** + * putch_help() + * + */ +void putch_help(console_t *con, unsigned c) +{ 104890: 55 push %ebp 104891: 89 e5 mov %esp,%ebp 104893: 57 push %edi @@ -10378,240 +10378,240 @@ 104895: 53 push %ebx 104896: 83 ec 0c sub $0xc,%esp 104899: 8b 5d 08 mov 0x8(%ebp),%ebx - unsigned short *fb_adr; - unsigned att; - - att = (unsigned)con->attrib << 8; + unsigned short *fb_adr; + unsigned att; + + att = (unsigned)con->attrib << 8; 10489c: 8b 73 18 mov 0x18(%ebx),%esi - fb_adr = con->fb_adr; - - /** - * state machine to handle escape sequences - * - * ESC - */ - if(con->esc == 1) + fb_adr = con->fb_adr; + + /** + * state machine to handle escape sequences + * + * ESC + */ + if(con->esc == 1) 10489f: 8b 43 14 mov 0x14(%ebx),%eax 1048a2: c1 e6 08 shl $0x8,%esi 1048a5: 83 f8 01 cmp $0x1,%eax 1048a8: 8b 4d 0c mov 0xc(%ebp),%ecx 1048ab: 8b 7b 30 mov 0x30(%ebx),%edi 1048ae: 0f 84 30 02 00 00 je 104ae4 - { - if(c == '[') - { - con->esc++; - con->esc1 = 0; - return; - } - /* else fall-through: zero esc and print c */ - } - - /** - * ESC[ - */ - else if(con->esc == 2) + { + if(c == '[') + { + con->esc++; + con->esc1 = 0; + return; + } + /* else fall-through: zero esc and print c */ + } + + /** + * ESC[ + */ + else if(con->esc == 2) 1048b4: 83 f8 02 cmp $0x2,%eax 1048b7: 0f 84 a3 01 00 00 je 104a60 - { - if(isdigit(c)) - { - con->esc1 = con->esc1 * 10 + c - '0'; - return; - } - else if(c == ';') - { - con->esc++; - con->esc2 = 0; - return; - } - - /** - * ESC[2J (clear screen) - */ - else if(c == 'J') - { - if(con->esc1 == 2) - { - memsetw(fb_adr, ' ' | att, - _vc_height * _vc_width); - con->csr_x = con->csr_y = 0; - } - } - - /** - * ESC[num1m (set attribute num1) - */ - else if(c == 'm') - set_attrib(con, con->esc1); - con->esc = 0; /* anything else with one numeric arg */ - return; - } - - /** - * ESC[num1 - */ - else if(con->esc == 3) + { + if(isdigit(c)) + { + con->esc1 = con->esc1 * 10 + c - '0'; + return; + } + else if(c == ';') + { + con->esc++; + con->esc2 = 0; + return; + } + + /** + * ESC[2J (clear screen) + */ + else if(c == 'J') + { + if(con->esc1 == 2) + { + memsetw(fb_adr, ' ' | att, + _vc_height * _vc_width); + con->csr_x = con->csr_y = 0; + } + } + + /** + * ESC[num1m (set attribute num1) + */ + else if(c == 'm') + set_attrib(con, con->esc1); + con->esc = 0; /* anything else with one numeric arg */ + return; + } + + /** + * ESC[num1 + */ + else if(con->esc == 3) 1048bd: 83 f8 03 cmp $0x3,%eax 1048c0: 0f 84 22 01 00 00 je 1049e8 - { - if(isdigit(c)) - { - con->esc2 = con->esc2 * 10 + c - '0'; - return; - } - else if(c == ';') - { - con->esc++; /* ESC[num1;num2; */ - con->esc3 = 0; - return; - } - - /** - * ESC[num1;num2H (move cursor to num1,num2) - */ - else if(c == 'H') - { - if(con->esc2 < _vc_width) - con->csr_x = con->esc2; - if(con->esc1 < _vc_height) - con->csr_y = con->esc1; - } - - /** - * ESC[num1;num2m (set attributes num1,num2) - */ - else if(c == 'm') - { - set_attrib(con, con->esc1); - set_attrib(con, con->esc2); - } - con->esc = 0; - return; - } - /** - * ESC[num1;num2;num3 - */ - else if(con->esc == 4) + { + if(isdigit(c)) + { + con->esc2 = con->esc2 * 10 + c - '0'; + return; + } + else if(c == ';') + { + con->esc++; /* ESC[num1;num2; */ + con->esc3 = 0; + return; + } + + /** + * ESC[num1;num2H (move cursor to num1,num2) + */ + else if(c == 'H') + { + if(con->esc2 < _vc_width) + con->csr_x = con->esc2; + if(con->esc1 < _vc_height) + con->csr_y = con->esc1; + } + + /** + * ESC[num1;num2m (set attributes num1,num2) + */ + else if(c == 'm') + { + set_attrib(con, con->esc1); + set_attrib(con, con->esc2); + } + con->esc = 0; + return; + } + /** + * ESC[num1;num2;num3 + */ + else if(con->esc == 4) 1048c6: 83 f8 04 cmp $0x4,%eax 1048c9: 0f 84 c9 00 00 00 je 104998 - { - if(isdigit(c)) - { - con->esc3 = con->esc3 * 10 + c - '0'; - return; - } - /** - * ESC[num1;num2;num3m (set attributes num1,num2,num3) - */ - else if(c == 'm') - { - set_attrib(con, con->esc1); - set_attrib(con, con->esc2); - set_attrib(con, con->esc3); - } - con->esc = 0; - return; - } - con->esc = 0; - - /** - * escape character - */ - if(c == 0x1B) + { + if(isdigit(c)) + { + con->esc3 = con->esc3 * 10 + c - '0'; + return; + } + /** + * ESC[num1;num2;num3m (set attributes num1,num2,num3) + */ + else if(c == 'm') + { + set_attrib(con, con->esc1); + set_attrib(con, con->esc2); + set_attrib(con, con->esc3); + } + con->esc = 0; + return; + } + con->esc = 0; + + /** + * escape character + */ + if(c == 0x1B) 1048cf: 83 f9 1b cmp $0x1b,%ecx 1048d2: c7 43 14 00 00 00 00 movl $0x0,0x14(%ebx) 1048d9: 0f 84 ad 00 00 00 je 10498c - { - con->esc = 1; - return; - } - /** - * backspace - */ - if(c == 0x08) + { + con->esc = 1; + return; + } + /** + * backspace + */ + if(c == 0x08) 1048df: 83 f9 08 cmp $0x8,%ecx 1048e2: 0f 84 9a 00 00 00 je 104982 - { - if(con->csr_x != 0) - con->csr_x--; - } - /** - * tab - */ - else if(c == 0x09) + { + if(con->csr_x != 0) + con->csr_x--; + } + /** + * tab + */ + else if(c == 0x09) 1048e8: 83 f9 09 cmp $0x9,%ecx 1048eb: 0f 84 83 00 00 00 je 104974 - con->csr_x = (con->csr_x + 8) & ~(8 - 1); - /** - * carriage return - */ - else if(c == '\r') /* 0x0D */ + con->csr_x = (con->csr_x + 8) & ~(8 - 1); + /** + * carriage return + */ + else if(c == '\r') /* 0x0D */ 1048f1: 83 f9 0d cmp $0xd,%ecx 1048f4: 74 75 je 10496b - con->csr_x = 0; - /** - * line feed - */ -/* else if(c == '\n') *//* 0x0A */ -/* con->csr_y++;*/ - /** - * CR/LF - */ - else if(c == '\n') /* ### - 0x0A again */ + con->csr_x = 0; + /** + * line feed + */ +/* else if(c == '\n') *//* 0x0A */ +/* con->csr_y++;*/ + /** + * CR/LF + */ + else if(c == '\n') /* ### - 0x0A again */ 1048f6: 83 f9 0a cmp $0xa,%ecx 1048f9: 74 62 je 10495d - { - con->csr_x = 0; - con->csr_y++; - } - /** - * printable ASCII - */ - else if(c >= ' ') + { + con->csr_x = 0; + con->csr_y++; + } + /** + * printable ASCII + */ + else if(c >= ' ') 1048fb: 83 f9 1f cmp $0x1f,%ecx 1048fe: 76 58 jbe 104958 - { - unsigned short *where; - - where = fb_adr + (con->csr_y * _vc_width + con->csr_x); + { + unsigned short *where; + + where = fb_adr + (con->csr_y * _vc_width + con->csr_x); 104900: a1 30 3a 18 00 mov 0x183a30,%eax 104905: 8b 53 1c mov 0x1c(%ebx),%edx 104908: 0f af 43 20 imul 0x20(%ebx),%eax 10490c: 01 d0 add %edx,%eax - *where = (c | att); + *where = (c | att); 10490e: 09 f1 or %esi,%ecx - con->csr_x++; + con->csr_x++; 104910: 42 inc %edx 104911: 66 89 0c 47 mov %cx,(%edi,%eax,2) 104915: 89 d0 mov %edx,%eax 104917: 89 53 1c mov %edx,0x1c(%ebx) 10491a: 89 f6 mov %esi,%esi - } - if(con->csr_x >= _vc_width) + } + if(con->csr_x >= _vc_width) 10491c: 3b 05 30 3a 18 00 cmp 0x183a30,%eax 104922: 72 0a jb 10492e - { - con->csr_x = 0; + { + con->csr_x = 0; 104924: c7 43 1c 00 00 00 00 movl $0x0,0x1c(%ebx) - con->csr_y++; + con->csr_y++; 10492b: ff 43 20 incl 0x20(%ebx) - } - scroll(con); + } + scroll(con); 10492e: 83 ec 0c sub $0xc,%esp 104931: 53 push %ebx 104932: e8 81 fd ff ff call 1046b8 - - /** - * move cursor only if the VC we're writing is the current VC - */ - if(_curr_vc == con) + + /** + * move cursor only if the VC we're writing is the current VC + */ + if(_curr_vc == con) 104937: 83 c4 10 add $0x10,%esp 10493a: 39 1d 24 3a 18 00 cmp %ebx,0x183a24 104940: 74 0a je 10494c 104942: 89 f6 mov %esi,%esi - move_csr(); -} + move_csr(); +} 104944: 8d 65 f4 lea 0xfffffff4(%ebp),%esp 104947: 5b pop %ebx 104948: 5e pop %esi @@ -10748,81 +10748,81 @@ 104afb: e9 44 fe ff ff jmp 104944 00104b00 : - -/** - * putch() - * - */ -void putch(unsigned c) -{ + +/** + * putch() + * + */ +void putch(unsigned c) +{ 104b00: 55 push %ebp 104b01: 89 e5 mov %esp,%ebp 104b03: 83 ec 10 sub $0x10,%esp -/* all kernel messages to VC #0 */ -// putch_help(_vc + 0, c); -/* all kernel messages to current VC */ - putch_help(_curr_vc, c); +/* all kernel messages to VC #0 */ +// putch_help(_vc + 0, c); +/* all kernel messages to current VC */ + putch_help(_curr_vc, c); 104b06: ff 75 08 pushl 0x8(%ebp) 104b09: ff 35 24 3a 18 00 pushl 0x183a24 104b0f: e8 7c fd ff ff call 104890 -} +} 104b14: c9 leave 104b15: c3 ret 104b16: 89 f6 mov %esi,%esi 00104b18 : - -/** - * init_video() - * - */ -void init_video(void) -{ + +/** + * init_video() + * + */ +void init_video(void) +{ 104b18: 55 push %ebp 104b19: 89 e5 mov %esp,%ebp 104b1b: 56 push %esi 104b1c: 53 push %ebx - unsigned i; - - /** - * check for monochrome or color VGA emulation - */ - if((inportb(VGA_MISC_READ) & 0x01) != 0) + unsigned i; + + /** + * check for monochrome or color VGA emulation + */ + if((inportb(VGA_MISC_READ) & 0x01) != 0) 104b1d: 83 ec 0c sub $0xc,%esp 104b20: 68 cc 03 00 00 push $0x3cc 104b25: e8 ea 04 00 00 call 105014 104b2a: 83 c4 10 add $0x10,%esp 104b2d: a8 01 test $0x1,%al 104b2f: 0f 84 78 01 00 00 je 104cad - { - _vga_fb_adr = (unsigned short *)0xB8000L; + { + _vga_fb_adr = (unsigned short *)0xB8000L; 104b35: c7 05 28 3a 18 00 00 movl $0xb8000,0x183a28 104b3c: 80 0b 00 - _crtc_io_adr = 0x3D4; + _crtc_io_adr = 0x3D4; 104b3f: c7 05 2c 3a 18 00 d4 movl $0x3d4,0x183a2c 104b46: 03 00 00 - } - else - { - _vga_fb_adr = (unsigned short *)0xB0000L; - _crtc_io_adr = 0x3B4; - } - - /** - * read current screen size from BIOS data segment (addresses 400-4FF) - */ - _vc_width = *(unsigned short *)0x44A; - _vc_height = *(unsigned char *)0x484 + 1; + } + else + { + _vga_fb_adr = (unsigned short *)0xB0000L; + _crtc_io_adr = 0x3B4; + } + + /** + * read current screen size from BIOS data segment (addresses 400-4FF) + */ + _vc_width = *(unsigned short *)0x44A; + _vc_height = *(unsigned char *)0x484 + 1; 104b49: 0f b6 05 84 04 00 00 movzbl 0x484,%eax 104b50: 40 inc %eax 104b51: 0f b7 15 4a 04 00 00 movzwl 0x44a,%edx 104b58: 89 15 30 3a 18 00 mov %edx,0x183a30 - - /** - * figure out how many VCs we can have with 32K of display memory. - * Use INTEGER division to round down. - */ - _num_vcs = 32768L / (_vc_width * _vc_height * 2); + + /** + * figure out how many VCs we can have with 32K of display memory. + * Use INTEGER division to round down. + */ + _num_vcs = 32768L / (_vc_width * _vc_height * 2); 104b5e: 0f af d0 imul %eax,%edx 104b61: d1 e2 shl %edx 104b63: 89 d1 mov %edx,%ecx @@ -10830,42 +10830,42 @@ 104b6a: 31 d2 xor %edx,%edx 104b6c: b8 00 80 00 00 mov $0x8000,%eax 104b71: f7 f1 div %ecx - if(_num_vcs > MAX_VC) + if(_num_vcs > MAX_VC) 104b73: 83 f8 0c cmp $0xc,%eax 104b76: a3 20 3a 18 00 mov %eax,0x183a20 104b7b: 76 0a jbe 104b87 - _num_vcs = MAX_VC; + _num_vcs = MAX_VC; 104b7d: c7 05 20 3a 18 00 0c movl $0xc,0x183a20 104b84: 00 00 00 - - /** - * init VCs, with a different foreground color for each - */ - for(i = 0; i < _num_vcs; i++) + + /** + * init VCs, with a different foreground color for each + */ + for(i = 0; i < _num_vcs; i++) 104b87: 31 f6 xor %esi,%esi 104b89: 3b 35 20 3a 18 00 cmp 0x183a20,%esi 104b8f: 73 53 jae 104be4 104b91: bb e0 a2 19 00 mov $0x19a2e0,%ebx 104b96: 89 f6 mov %esi,%esi - { - _curr_vc = _vc + i; - //_curr_vc->attrib = i + 1; - - /* terminal foreground color */ - _curr_vc->attrib = 7; - _curr_vc->fb_adr = _vga_fb_adr + + { + _curr_vc = _vc + i; + //_curr_vc->attrib = i + 1; + + /* terminal foreground color */ + _curr_vc->attrib = 7; + _curr_vc->fb_adr = _vga_fb_adr + 104b98: a1 34 3a 18 00 mov 0x183a34,%eax 104b9d: 0f af 05 30 3a 18 00 imul 0x183a30,%eax 104ba4: 8b 15 28 3a 18 00 mov 0x183a28,%edx 104baa: 0f af c6 imul %esi,%eax - _vc_width * _vc_height * i; - - /** - * ESC[2J clears the screen - */ - //kprintf("\x1B[2J this is VC#%u (of 0-%u)\n", - // i, _num_vcs - 1); - printf("\x1B[2J"); + _vc_width * _vc_height * i; + + /** + * ESC[2J clears the screen + */ + //kprintf("\x1B[2J this is VC#%u (of 0-%u)\n", + // i, _num_vcs - 1); + printf("\x1B[2J"); 104bad: 83 ec 0c sub $0xc,%esp 104bb0: 8d 04 42 lea (%edx,%eax,2),%eax 104bb3: c7 43 18 07 00 00 00 movl $0x7,0x18(%ebx) @@ -10873,8 +10873,8 @@ 104bbd: 68 00 63 10 00 push $0x106300 104bc2: 89 1d 24 3a 18 00 mov %ebx,0x183a24 104bc8: e8 07 05 00 00 call 1050d4 - - if(i != 0) + + if(i != 0) 104bcd: 83 c4 10 add $0x10,%esp 104bd0: 85 f6 test %esi,%esi 104bd2: 0f 85 c0 00 00 00 jne 104c98 @@ -10882,26 +10882,26 @@ 104bd9: 83 c3 34 add $0x34,%ebx 104bdc: 3b 35 20 3a 18 00 cmp 0x183a20,%esi 104be2: 72 b4 jb 104b98 - printf("$ "); - } - select_vc(0); + printf("$ "); + } + select_vc(0); 104be4: 83 ec 0c sub $0xc,%esp 104be7: 6a 00 push $0x0 104be9: e8 16 fc ff ff call 104804 - curr_vtty = 0; - - _curr_vc->attrib = 8; + curr_vtty = 0; + + _curr_vc->attrib = 8; 104bee: a1 24 3a 18 00 mov 0x183a24,%eax 104bf3: c7 05 c0 a2 19 00 00 movl $0x0,0x19a2c0 104bfa: 00 00 00 104bfd: c7 40 18 08 00 00 00 movl $0x8,0x18(%eax) - printf("[ "); + printf("[ "); 104c04: c7 04 24 b6 51 10 00 movl $0x1051b6,(%esp,1) 104c0b: e8 c4 04 00 00 call 1050d4 - _curr_vc->attrib = 15; + _curr_vc->attrib = 15; 104c10: a1 24 3a 18 00 mov 0x183a24,%eax 104c15: c7 40 18 0f 00 00 00 movl $0xf,0x18(%eax) - printf("init: video %5s emulation, %2ux%2u, framebuffer at 0x%1X ", + printf("init: video %5s emulation, %2ux%2u, framebuffer at 0x%1X ", 104c1c: 5b pop %ebx 104c1d: ff 35 28 3a 18 00 pushl 0x183a28 104c23: ff 35 34 3a 18 00 pushl 0x183a34 @@ -10913,25 +10913,25 @@ 104c40: 50 push %eax 104c41: 68 40 63 10 00 push $0x106340 104c46: e8 89 04 00 00 call 1050d4 - (_crtc_io_adr == 0x3D4) ? "color" : "mono", - _vc_width, _vc_height, _vga_fb_adr); - _curr_vc->attrib = 8; - printf("]................"); + (_crtc_io_adr == 0x3D4) ? "color" : "mono", + _vc_width, _vc_height, _vga_fb_adr); + _curr_vc->attrib = 8; + printf("]................"); 104c4b: 83 c4 14 add $0x14,%esp 104c4e: a1 24 3a 18 00 mov 0x183a24,%eax 104c53: c7 40 18 08 00 00 00 movl $0x8,0x18(%eax) 104c5a: 68 0a 63 10 00 push $0x10630a 104c5f: e8 70 04 00 00 call 1050d4 - _curr_vc->attrib = 2; + _curr_vc->attrib = 2; 104c64: a1 24 3a 18 00 mov 0x183a24,%eax 104c69: c7 40 18 02 00 00 00 movl $0x2,0x18(%eax) - printf("Ok"); + printf("Ok"); 104c70: c7 04 24 d9 54 10 00 movl $0x1054d9,(%esp,1) 104c77: e8 58 04 00 00 call 1050d4 - _curr_vc->attrib = 7; + _curr_vc->attrib = 7; 104c7c: a1 24 3a 18 00 mov 0x183a24,%eax 104c81: c7 40 18 07 00 00 00 movl $0x7,0x18(%eax) -} +} 104c88: 8d 65 f8 lea 0xfffffff8(%ebp),%esp 104c8b: 5b pop %ebx 104c8c: 5e pop %esi @@ -10953,33 +10953,33 @@ ... 00104cc8 : -/***************************************************************************** -*****************************************************************************/ -unsigned disable(void) -{ +/***************************************************************************** +*****************************************************************************/ +unsigned disable(void) +{ 104cc8: 55 push %ebp 104cc9: 89 e5 mov %esp,%ebp - unsigned ret_val; - - __asm__ __volatile__("pushfl\n" + unsigned ret_val; + + __asm__ __volatile__("pushfl\n" 104ccb: 9c pushf 104ccc: 58 pop %eax 104ccd: fa cli - "popl %0\n" - "cli" - : "=a"(ret_val) - :); - return ret_val; -} + "popl %0\n" + "cli" + : "=a"(ret_val) + :); + return ret_val; +} 104cce: c9 leave 104ccf: c3 ret 00104cd0 : -2^32-1 in base 8 has 11 digits (add 5 for trailing NUL and for slop) */ -#define PR_BUFLEN 16 - -int do_printf(const char *fmt, va_list args, fnptr_t fn, void *ptr) -{ +2^32-1 in base 8 has 11 digits (add 5 for trailing NUL and for slop) */ +#define PR_BUFLEN 16 + +int do_printf(const char *fmt, va_list args, fnptr_t fn, void *ptr) +{ 104cd0: 55 push %ebp 104cd1: 89 e5 mov %esp,%ebp 104cd3: 57 push %edi @@ -10987,56 +10987,56 @@ 104cd5: 53 push %ebx 104cd6: 83 ec 2c sub $0x2c,%esp 104cd9: 8b 75 08 mov 0x8(%ebp),%esi - unsigned state, flags, radix, actual_wd, count, given_wd; - unsigned char *where, buf[PR_BUFLEN]; - long num; - - state = flags = count = given_wd = 0; + unsigned state, flags, radix, actual_wd, count, given_wd; + unsigned char *where, buf[PR_BUFLEN]; + long num; + + state = flags = count = given_wd = 0; 104cdc: c7 45 cc 00 00 00 00 movl $0x0,0xffffffcc(%ebp) 104ce3: c7 45 d0 00 00 00 00 movl $0x0,0xffffffd0(%ebp) 104cea: c7 45 d4 00 00 00 00 movl $0x0,0xffffffd4(%ebp) -/* begin scanning format specifier list */ - for(; *fmt; fmt++) +/* begin scanning format specifier list */ + for(; *fmt; fmt++) 104cf1: 8a 0e mov (%esi),%cl 104cf3: 31 db xor %ebx,%ebx 104cf5: 84 c9 test %cl,%cl 104cf7: 74 38 je 104d31 104cf9: 8d 76 00 lea 0x0(%esi),%esi - { - switch(state) + { + switch(state) 104cfc: 83 fb 04 cmp $0x4,%ebx 104cff: 0f 87 d7 01 00 00 ja 104edc 104d05: ff 24 9d 7c 63 10 00 jmp *0x10637c(,%ebx,4) - { -/* STATE 0: AWAITING % */ - case 0: - if(*fmt != '%') /* not %... */ + { +/* STATE 0: AWAITING % */ + case 0: + if(*fmt != '%') /* not %... */ 104d0c: 80 f9 25 cmp $0x25,%cl 104d0f: 74 2b je 104d3c - { - fn(*fmt, &ptr); /* ...just echo it */ + { + fn(*fmt, &ptr); /* ...just echo it */ 104d11: 83 ec 08 sub $0x8,%esp 104d14: 8d 45 14 lea 0x14(%ebp),%eax 104d17: 50 push %eax 104d18: 0f be c1 movsbl %cl,%eax 104d1b: 50 push %eax 104d1c: ff 55 10 call *0x10(%ebp) - count++; + count++; 104d1f: ff 45 d0 incl 0xffffffd0(%ebp) - break; - } -/* found %, get next char and advance state to check if next char is a flag */ - state++; - fmt++; - /* FALL THROUGH */ -/* STATE 1: AWAITING FLAGS (%-0) */ - case 1: - if(*fmt == '%') /* %% */ - { - fn(*fmt, &ptr); - count++; - state = flags = given_wd = 0; - break; + break; + } +/* found %, get next char and advance state to check if next char is a flag */ + state++; + fmt++; + /* FALL THROUGH */ +/* STATE 1: AWAITING FLAGS (%-0) */ + case 1: + if(*fmt == '%') /* %% */ + { + fn(*fmt, &ptr); + count++; + state = flags = given_wd = 0; + break; 104d22: 83 c4 10 add $0x10,%esp 104d25: 8d 76 00 lea 0x0(%esi),%esi 104d28: 46 inc %esi @@ -11044,193 +11044,193 @@ 104d2b: 84 c0 test %al,%al 104d2d: 88 c1 mov %al,%cl 104d2f: 75 cb jne 104cfc - } - if(*fmt == '-') - { - if(flags & PR_LJ)/* %-- is illegal */ - state = flags = given_wd = 0; - else - flags |= PR_LJ; - break; - } -/* not a flag char: advance state to check if it's field width */ - state++; -/* check now for '%0...' */ - if(*fmt == '0') - { - flags |= PR_LZ; - fmt++; - } - /* FALL THROUGH */ -/* STATE 2: AWAITING (NUMERIC) FIELD WIDTH */ - case 2: - if(*fmt >= '0' && *fmt <= '9') - { - given_wd = 10 * given_wd + - (*fmt - '0'); - break; - } -/* not field width: advance state to check if it's a modifier */ - state++; - /* FALL THROUGH */ -/* STATE 3: AWAITING MODIFIER CHARS (FNlh) */ - case 3: - if(*fmt == 'F') - { - flags |= PR_FP; - break; - } - if(*fmt == 'N') - break; - if(*fmt == 'l') - { - flags |= PR_32; - break; - } - if(*fmt == 'h') - { - flags |= PR_16; - break; - } -/* not modifier: advance state to check if it's a conversion char */ - state++; - /* FALL THROUGH */ -/* STATE 4: AWAITING CONVERSION CHARS (Xxpndiuocs) */ - case 4: - where = buf + PR_BUFLEN - 1; - *where = '\0'; - switch(*fmt) - { - case 'X': - flags |= PR_CA; - /* FALL THROUGH */ -/* xxx - far pointers (%Fp, %Fn) not yet supported */ - case 'x': - case 'p': - case 'n': - radix = 16; - goto DO_NUM; - case 'd': - case 'i': - flags |= PR_SG; - /* FALL THROUGH */ - case 'u': - radix = 10; - goto DO_NUM; - case 'o': - radix = 8; -/* load the value to be printed. l=long=32 bits: */ -DO_NUM: if(flags & PR_32) - num = va_arg(args, unsigned long); -/* h=short=16 bits (signed or unsigned) */ - else if(flags & PR_16) - { - if(flags & PR_SG) - num = va_arg(args, short); - else - num = va_arg(args, unsigned short); - } -/* no h nor l: sizeof(int) bits (signed or unsigned) */ - else - { - if(flags & PR_SG) - num = va_arg(args, int); - else - num = va_arg(args, unsigned int); - } -/* take care of sign */ - if(flags & PR_SG) - { - if(num < 0) - { - flags |= PR_WS; - num = -num; - } - } -/* convert binary to octal/decimal/hex ASCII -OK, I found my mistake. The math here is _always_ unsigned */ - do - { - unsigned long temp; - - temp = (unsigned long)num % radix; - where--; - if(temp < 10) - *where = temp + '0'; - else if(flags & PR_CA) - *where = temp - 10 + 'A'; - else - *where = temp - 10 + 'a'; - num = (unsigned long)num / radix; - } - while(num != 0); - goto EMIT; - case 'c': -/* disallow pad-left-with-zeroes for %c */ - flags &= ~PR_LZ; - where--; - *where = (unsigned char)va_arg(args, - unsigned char); - actual_wd = 1; - goto EMIT2; - case 's': -/* disallow pad-left-with-zeroes for %s */ - flags &= ~PR_LZ; - where = va_arg(args, unsigned char *); -EMIT: - actual_wd = strlen(where); - if(flags & PR_WS) - actual_wd++; -/* if we pad left with ZEROES, do the sign now */ - if((flags & (PR_WS | PR_LZ)) == - (PR_WS | PR_LZ)) - { - fn('-', &ptr); - count++; - } -/* pad on left with spaces or zeroes (for right justify) */ -EMIT2: if((flags & PR_LJ) == 0) - { - while(given_wd > actual_wd) - { - fn(flags & PR_LZ ? '0' : - ' ', &ptr); - count++; - given_wd--; - } - } -/* if we pad left with SPACES, do the sign now */ - if((flags & (PR_WS | PR_LZ)) == PR_WS) - { - fn('-', &ptr); - count++; - } -/* emit string/char/converted number */ - while(*where != '\0') - { - fn(*where++, &ptr); - count++; - } -/* pad on right with spaces (for left justify) */ - if(given_wd < actual_wd) - given_wd = 0; - else given_wd -= actual_wd; - for(; given_wd; given_wd--) - { - fn(' ', &ptr); - count++; - } - break; - default: - break; - } - default: - state = flags = given_wd = 0; - break; - } - } - return count; -} + } + if(*fmt == '-') + { + if(flags & PR_LJ)/* %-- is illegal */ + state = flags = given_wd = 0; + else + flags |= PR_LJ; + break; + } +/* not a flag char: advance state to check if it's field width */ + state++; +/* check now for '%0...' */ + if(*fmt == '0') + { + flags |= PR_LZ; + fmt++; + } + /* FALL THROUGH */ +/* STATE 2: AWAITING (NUMERIC) FIELD WIDTH */ + case 2: + if(*fmt >= '0' && *fmt <= '9') + { + given_wd = 10 * given_wd + + (*fmt - '0'); + break; + } +/* not field width: advance state to check if it's a modifier */ + state++; + /* FALL THROUGH */ +/* STATE 3: AWAITING MODIFIER CHARS (FNlh) */ + case 3: + if(*fmt == 'F') + { + flags |= PR_FP; + break; + } + if(*fmt == 'N') + break; + if(*fmt == 'l') + { + flags |= PR_32; + break; + } + if(*fmt == 'h') + { + flags |= PR_16; + break; + } +/* not modifier: advance state to check if it's a conversion char */ + state++; + /* FALL THROUGH */ +/* STATE 4: AWAITING CONVERSION CHARS (Xxpndiuocs) */ + case 4: + where = buf + PR_BUFLEN - 1; + *where = '\0'; + switch(*fmt) + { + case 'X': + flags |= PR_CA; + /* FALL THROUGH */ +/* xxx - far pointers (%Fp, %Fn) not yet supported */ + case 'x': + case 'p': + case 'n': + radix = 16; + goto DO_NUM; + case 'd': + case 'i': + flags |= PR_SG; + /* FALL THROUGH */ + case 'u': + radix = 10; + goto DO_NUM; + case 'o': + radix = 8; +/* load the value to be printed. l=long=32 bits: */ +DO_NUM: if(flags & PR_32) + num = va_arg(args, unsigned long); +/* h=short=16 bits (signed or unsigned) */ + else if(flags & PR_16) + { + if(flags & PR_SG) + num = va_arg(args, short); + else + num = va_arg(args, unsigned short); + } +/* no h nor l: sizeof(int) bits (signed or unsigned) */ + else + { + if(flags & PR_SG) + num = va_arg(args, int); + else + num = va_arg(args, unsigned int); + } +/* take care of sign */ + if(flags & PR_SG) + { + if(num < 0) + { + flags |= PR_WS; + num = -num; + } + } +/* convert binary to octal/decimal/hex ASCII +OK, I found my mistake. The math here is _always_ unsigned */ + do + { + unsigned long temp; + + temp = (unsigned long)num % radix; + where--; + if(temp < 10) + *where = temp + '0'; + else if(flags & PR_CA) + *where = temp - 10 + 'A'; + else + *where = temp - 10 + 'a'; + num = (unsigned long)num / radix; + } + while(num != 0); + goto EMIT; + case 'c': +/* disallow pad-left-with-zeroes for %c */ + flags &= ~PR_LZ; + where--; + *where = (unsigned char)va_arg(args, + unsigned char); + actual_wd = 1; + goto EMIT2; + case 's': +/* disallow pad-left-with-zeroes for %s */ + flags &= ~PR_LZ; + where = va_arg(args, unsigned char *); +EMIT: + actual_wd = strlen(where); + if(flags & PR_WS) + actual_wd++; +/* if we pad left with ZEROES, do the sign now */ + if((flags & (PR_WS | PR_LZ)) == + (PR_WS | PR_LZ)) + { + fn('-', &ptr); + count++; + } +/* pad on left with spaces or zeroes (for right justify) */ +EMIT2: if((flags & PR_LJ) == 0) + { + while(given_wd > actual_wd) + { + fn(flags & PR_LZ ? '0' : + ' ', &ptr); + count++; + given_wd--; + } + } +/* if we pad left with SPACES, do the sign now */ + if((flags & (PR_WS | PR_LZ)) == PR_WS) + { + fn('-', &ptr); + count++; + } +/* emit string/char/converted number */ + while(*where != '\0') + { + fn(*where++, &ptr); + count++; + } +/* pad on right with spaces (for left justify) */ + if(given_wd < actual_wd) + given_wd = 0; + else given_wd -= actual_wd; + for(; given_wd; given_wd--) + { + fn(' ', &ptr); + count++; + } + break; + default: + break; + } + default: + state = flags = given_wd = 0; + break; + } + } + return count; +} 104d31: 8b 45 d0 mov 0xffffffd0(%ebp),%eax 104d34: 8d 65 f4 lea 0xfffffff4(%ebp),%esp 104d37: 5b pop %ebx @@ -11461,118 +11461,118 @@ ... 0010500c : -/***************************************************************************** -*****************************************************************************/ -void enable(void) -{ +/***************************************************************************** +*****************************************************************************/ +void enable(void) +{ 10500c: 55 push %ebp 10500d: 89 e5 mov %esp,%ebp - __asm__ __volatile__("sti" + __asm__ __volatile__("sti" 10500f: fb sti - : - : - ); -} + : + : + ); +} 105010: c9 leave 105011: c3 ret ... 00105014 : -/***************************************************************************** -*****************************************************************************/ -unsigned inportb(unsigned short port) -{ +/***************************************************************************** +*****************************************************************************/ +unsigned inportb(unsigned short port) +{ 105014: 55 push %ebp 105015: 89 e5 mov %esp,%ebp 105017: 8b 55 08 mov 0x8(%ebp),%edx - unsigned char ret_val; - - __asm__ __volatile__("inb %1,%0" + unsigned char ret_val; + + __asm__ __volatile__("inb %1,%0" 10501a: ec in (%dx),%al - : "=a"(ret_val) - : "d"(port)); - return ret_val; + : "=a"(ret_val) + : "d"(port)); + return ret_val; 10501b: 0f b6 c0 movzbl %al,%eax -} +} 10501e: c9 leave 10501f: c3 ret 00105020 : -4. Save/restore the floating-point state when entering/leaving - the kernel (protected OS only) -*****************************************************************************/ -void longjmp(jmp_buf buf, int ret_val) -{ +4. Save/restore the floating-point state when entering/leaving + the kernel (protected OS only) +*****************************************************************************/ +void longjmp(jmp_buf buf, int ret_val) +{ 105020: 55 push %ebp 105021: 89 e5 mov %esp,%ebp 105023: 8b 45 0c mov 0xc(%ebp),%eax - unsigned *esp; - -/* make sure return value is not 0 */ - if(ret_val == 0) + unsigned *esp; + +/* make sure return value is not 0 */ + if(ret_val == 0) 105026: 85 c0 test %eax,%eax 105028: 75 05 jne 10502f - ret_val++; + ret_val++; 10502a: b8 01 00 00 00 mov $0x1,%eax -/* EAX is used for return values, so store it in jmp_buf.EAX */ - buf->eax = ret_val; +/* EAX is used for return values, so store it in jmp_buf.EAX */ + buf->eax = ret_val; 10502f: 8b 4d 08 mov 0x8(%ebp),%ecx 105032: 89 41 1c mov %eax,0x1c(%ecx) -/* get ESP for new stack */ - esp = (unsigned *)buf->esp; -/* push EFLAGS on the new stack */ - esp--; +/* get ESP for new stack */ + esp = (unsigned *)buf->esp; +/* push EFLAGS on the new stack */ + esp--; 105035: 8b 41 0c mov 0xc(%ecx),%eax 105038: 83 e8 04 sub $0x4,%eax - *esp = buf->eflags; + *esp = buf->eflags; 10503b: 8b 51 24 mov 0x24(%ecx),%edx 10503e: 89 10 mov %edx,(%eax) -/* push current CS on the new stack */ - esp--; +/* push current CS on the new stack */ + esp--; 105040: 83 e8 04 sub $0x4,%eax - __asm__ __volatile__( + __asm__ __volatile__( 105043: 8c 08 movl %cs,(%eax) - "mov %%cs,%0\n" - : "=m"(*esp)); -/* push EIP on the new stack */ - esp--; + "mov %%cs,%0\n" + : "=m"(*esp)); +/* push EIP on the new stack */ + esp--; 105045: 83 e8 04 sub $0x4,%eax - *esp = buf->eip; + *esp = buf->eip; 105048: 8b 51 20 mov 0x20(%ecx),%edx 10504b: 89 10 mov %edx,(%eax) -/* new ESP is 12 bytes lower; update jmp_buf.ESP */ - buf->esp = (unsigned)esp; +/* new ESP is 12 bytes lower; update jmp_buf.ESP */ + buf->esp = (unsigned)esp; 10504d: 89 41 0c mov %eax,0xc(%ecx) -/* now, briefly, make the jmp_buf struct our stack */ - __asm__ __volatile__( +/* now, briefly, make the jmp_buf struct our stack */ + __asm__ __volatile__( 105050: 8b 65 08 mov 0x8(%ebp),%esp 105053: 61 popa 105054: 8b 64 24 ec mov 0xffffffec(%esp,1),%esp 105058: cf iret - "movl %0,%%esp\n" -/* ESP now points to 8 general-purpose registers stored in jmp_buf -Pop them */ - "popa\n" -/* load new stack pointer from jmp_buf */ - "movl -20(%%esp),%%esp\n" -/* ESP now points to new stack, with the IRET frame (EIP, CS, EFLAGS) -we created just above. Pop these registers: */ - "iret\n" - : - : "m"(buf)); -} + "movl %0,%%esp\n" +/* ESP now points to 8 general-purpose registers stored in jmp_buf +Pop them */ + "popa\n" +/* load new stack pointer from jmp_buf */ + "movl -20(%%esp),%%esp\n" +/* ESP now points to new stack, with the IRET frame (EIP, CS, EFLAGS) +we created just above. Pop these registers: */ + "iret\n" + : + : "m"(buf)); +} 105059: c9 leave 10505a: c3 ret ... 0010505c : -void *memcpy(void *s, const void *t, unsigned n) -{ +void *memcpy(void *s, const void *t, unsigned n) +{ 10505c: 55 push %ebp 10505d: 89 e5 mov %esp,%ebp - void *ret = s; - - while(n--) + void *ret = s; + + while(n--) 10505f: 8b 55 10 mov 0x10(%ebp),%edx 105062: 56 push %esi 105063: 4a dec %edx @@ -11583,21 +11583,21 @@ 10506e: 89 de mov %ebx,%esi 105070: 74 0e je 105080 105072: 89 f6 mov %esi,%esi - { - *(char *)s = *(char *)t; + { + *(char *)s = *(char *)t; 105074: 8a 01 mov (%ecx),%al - s = (char *)s + 1; - t = (char *)t + 1; + s = (char *)s + 1; + t = (char *)t + 1; 105076: 4a dec %edx 105077: 88 03 mov %al,(%ebx) 105079: 41 inc %ecx 10507a: 43 inc %ebx 10507b: 83 fa ff cmp $0xffffffff,%edx 10507e: 75 f4 jne 105074 - } - - return ret; -} + } + + return ret; +} 105080: 5b pop %ebx 105081: 89 f0 mov %esi,%eax 105083: 5e pop %esi @@ -11606,14 +11606,14 @@ ... 00105088 : - -void *memsetw(void *s, short i, unsigned n) -{ + +void *memsetw(void *s, short i, unsigned n) +{ 105088: 55 push %ebp 105089: 89 e5 mov %esp,%ebp - void *start = s; - - while(n--) + void *start = s; + + while(n--) 10508b: 8b 55 10 mov 0x10(%ebp),%edx 10508e: 4a dec %edx 10508f: 8b 4d 08 mov 0x8(%ebp),%ecx @@ -11623,18 +11623,18 @@ 105099: 89 cb mov %ecx,%ebx 10509b: 74 0f je 1050ac 10509d: 8d 76 00 lea 0x0(%esi),%esi - { - *(short *)s = (short)i; - s = (short *)s + 1; + { + *(short *)s = (short)i; + s = (short *)s + 1; 1050a0: 4a dec %edx 1050a1: 66 89 01 mov %ax,(%ecx) 1050a4: 83 c1 02 add $0x2,%ecx 1050a7: 83 fa ff cmp $0xffffffff,%edx 1050aa: 75 f4 jne 1050a0 - } - - return(start); -} + } + + return(start); +} 1050ac: 89 d8 mov %ebx,%eax 1050ae: 5b pop %ebx 1050af: c9 leave @@ -11643,81 +11643,81 @@ ... 001050b4 : -/***************************************************************************** -*****************************************************************************/ -void outportb(unsigned port, unsigned val) -{ +/***************************************************************************** +*****************************************************************************/ +void outportb(unsigned port, unsigned val) +{ 1050b4: 55 push %ebp 1050b5: 89 e5 mov %esp,%ebp 1050b7: 8b 55 08 mov 0x8(%ebp),%edx 1050ba: 8b 45 0c mov 0xc(%ebp),%eax - __asm__ __volatile__("outb %b0,%w1" + __asm__ __volatile__("outb %b0,%w1" 1050bd: ee out %al,(%dx) - : - : "a"(val), "d"(port)); -} + : + : "a"(val), "d"(port)); +} 1050be: c9 leave 1050bf: c3 ret 001050c0 : -int do_printf(const char *fmt, va_list args, fnptr_t fn, void *ptr); -void putch(unsigned c); - -int printf_help(unsigned c, void **ptr) -{ +int do_printf(const char *fmt, va_list args, fnptr_t fn, void *ptr); +void putch(unsigned c); + +int printf_help(unsigned c, void **ptr) +{ 1050c0: 55 push %ebp 1050c1: 89 e5 mov %esp,%ebp 1050c3: 83 ec 14 sub $0x14,%esp - /** - * Leave this for now - */ - ptr = ptr; - - putch(c); + /** + * Leave this for now + */ + ptr = ptr; + + putch(c); 1050c6: ff 75 08 pushl 0x8(%ebp) 1050c9: e8 32 fa ff ff call 104b00 - return 0; -} + return 0; +} 1050ce: 31 c0 xor %eax,%eax 1050d0: c9 leave 1050d1: c3 ret 1050d2: 89 f6 mov %esi,%esi 001050d4 : - -void printf(const char *fmt, ...) -{ + +void printf(const char *fmt, ...) +{ 1050d4: 55 push %ebp 1050d5: 89 e5 mov %esp,%ebp 1050d7: 83 ec 08 sub $0x8,%esp - va_list args; - - va_start(args, fmt); - (void)do_printf(fmt, args, printf_help, NULL); + va_list args; + + va_start(args, fmt); + (void)do_printf(fmt, args, printf_help, NULL); 1050da: 6a 00 push $0x0 1050dc: 68 c0 50 10 00 push $0x1050c0 1050e1: 8d 45 0c lea 0xc(%ebp),%eax 1050e4: 50 push %eax 1050e5: ff 75 08 pushl 0x8(%ebp) 1050e8: e8 e3 fb ff ff call 104cd0 - va_end(args); -} + va_end(args); +} 1050ed: c9 leave 1050ee: c3 ret ... 001050f0 : -int strcmp(const char * src, const char * dst) -{ +int strcmp(const char * src, const char * dst) +{ 1050f0: 55 push %ebp 1050f1: 89 e5 mov %esp,%ebp 1050f3: 56 push %esi 1050f4: 53 push %ebx 1050f5: 8b 5d 0c mov 0xc(%ebp),%ebx 1050f8: 8b 75 08 mov 0x8(%ebp),%esi - int ret = 0 ; - - while(!(ret = *(unsigned char *)src - *(unsigned char *)dst) && *dst) + int ret = 0 ; + + while(!(ret = *(unsigned char *)src - *(unsigned char *)dst) && *dst) 1050fb: 8a 0b mov (%ebx),%cl 1050fd: 0f b6 c1 movzbl %cl,%eax 105100: 0f b6 16 movzbl (%esi),%edx @@ -11727,7 +11727,7 @@ 105109: 84 c9 test %cl,%cl 10510b: 74 17 je 105124 10510d: 8d 76 00 lea 0x0(%esi),%esi - ++src, ++dst; + ++src, ++dst; 105110: 43 inc %ebx 105111: 46 inc %esi 105112: 8a 0b mov (%ebx),%cl @@ -11738,19 +11738,19 @@ 10511e: 75 04 jne 105124 105120: 84 c9 test %cl,%cl 105122: 75 ec jne 105110 - - if(ret < 0) + + if(ret < 0) 105124: 85 c0 test %eax,%eax 105126: 78 0d js 105135 - ret = -1 ; - else if(ret > 0) + ret = -1 ; + else if(ret > 0) 105128: 85 c0 test %eax,%eax 10512a: 7e 05 jle 105131 - ret = 1 ; + ret = 1 ; 10512c: b8 01 00 00 00 mov $0x1,%eax - - return(ret); -} + + return(ret); +} 105131: 5b pop %ebx 105132: 5e pop %esi 105133: c9 leave @@ -11759,69 +11759,69 @@ 10513a: eb f5 jmp 105131 0010513c : - -char *strcpy(char *s, const char *t) -{ + +char *strcpy(char *s, const char *t) +{ 10513c: 55 push %ebp 10513d: 89 e5 mov %esp,%ebp 10513f: 8b 4d 08 mov 0x8(%ebp),%ecx 105142: 8b 55 0c mov 0xc(%ebp),%edx 105145: 8d 76 00 lea 0x0(%esi),%esi - while((*(s++) = *(t++))); + while((*(s++) = *(t++))); 105148: 8a 02 mov (%edx),%al 10514a: 88 01 mov %al,(%ecx) 10514c: 42 inc %edx 10514d: 41 inc %ecx 10514e: 84 c0 test %al,%al 105150: 75 f6 jne 105148 - - return s; -} + + return s; +} 105152: 89 c8 mov %ecx,%eax 105154: c9 leave 105155: c3 ret ... 00105158 : -#include /* size_t */ -/***************************************************************************** -*****************************************************************************/ -size_t strlen(const char *str) -{ +#include /* size_t */ +/***************************************************************************** +*****************************************************************************/ +size_t strlen(const char *str) +{ 105158: 55 push %ebp 105159: 89 e5 mov %esp,%ebp 10515b: 8b 55 08 mov 0x8(%ebp),%edx - size_t ret_val; - - for(ret_val = 0; *str != '\0'; str++) + size_t ret_val; + + for(ret_val = 0; *str != '\0'; str++) 10515e: 31 c0 xor %eax,%eax 105160: 80 3a 00 cmpb $0x0,(%edx) 105163: 74 0a je 10516f 105165: 8d 76 00 lea 0x0(%esi),%esi 105168: 42 inc %edx - ret_val++; + ret_val++; 105169: 40 inc %eax 10516a: 80 3a 00 cmpb $0x0,(%edx) 10516d: 75 f9 jne 105168 - return ret_val; -} + return ret_val; +} 10516f: c9 leave 105170: c3 ret 105171: 00 00 add %al,(%eax) ... 00105174 : -#include /* size_t */ - -char *strncpy(char * dest, const char * source, size_t count) -{ +#include /* size_t */ + +char *strncpy(char * dest, const char * source, size_t count) +{ 105174: 55 push %ebp 105175: 89 e5 mov %esp,%ebp 105177: 8b 55 10 mov 0x10(%ebp),%edx 10517a: 56 push %esi - char *start = dest; - - while(count && (*dest++ = *source++)) /* copy string */ + char *start = dest; + + while(count && (*dest++ = *source++)) /* copy string */ 10517b: 85 d2 test %edx,%edx 10517d: 53 push %ebx 10517e: 8b 75 08 mov 0x8(%ebp),%esi @@ -11834,7 +11834,7 @@ 10518d: 8d 4e 01 lea 0x1(%esi),%ecx 105190: 74 0f je 1051a1 105192: 89 f6 mov %esi,%esi - count--; + count--; 105194: 4a dec %edx 105195: 74 19 je 1051b0 105197: 8a 03 mov (%ebx),%al @@ -11843,22 +11843,22 @@ 10519c: 41 inc %ecx 10519d: 84 c0 test %al,%al 10519f: 75 f3 jne 105194 - - if(count) /* pad out with zeroes */ + + if(count) /* pad out with zeroes */ 1051a1: 85 d2 test %edx,%edx 1051a3: 74 0b je 1051b0 - while(--count) + while(--count) 1051a5: 4a dec %edx 1051a6: 74 08 je 1051b0 - *dest++ = '\0'; + *dest++ = '\0'; 1051a8: c6 01 00 movb $0x0,(%ecx) 1051ab: 41 inc %ecx 1051ac: 4a dec %edx 1051ad: 75 f9 jne 1051a8 1051af: 90 nop - - return(start); -} + + return(start); +} 1051b0: 5b pop %ebx 1051b1: 89 f0 mov %esi,%eax 1051b3: 5e pop %esi diff --git a/Makefile b/Makefile index 2c0089b..c87d58e 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ CURDIR=${.CURDIR} -OBJ_DIR?= ${CURDIR}/obj +OBJ_DIR?= ${CURDIR}/build CLEANDIR=clean @@ -13,14 +13,12 @@ WORLD_INC="-I${CURDIR}/include_old -I${CURDIR}/lib/objgfx40/ -I${CURDIR}/lib/libcpp/include" WORLD_FLAGS=_ARCH=${_ARCH} CC="cc" CXX="c++" AS="as" AR="ar" LD="ld" NM=nm OBJDUMP= OBJCOPY="objcopy" RANLIB=ranlib -WMAKE= ${MAKE} ${WORLD_FLAGS} INCLUDE=${WORLD_INC} BUILD_DIR=${CURDIR}/build +WMAKE=${MAKE} ${WORLD_FLAGS} INCLUDE=${WORLD_INC} BUILD_DIR=${CURDIR}/build TMP_PATH=${PATH} ROOT=/ubixos all: kernel world install-kernel install-world -# csu ubix_api libc_old libc ubix libcpp bin tools -# depend kernel tools kernel: @cd sys;make diff --git a/Makefile.incl b/Makefile.incl index 30939ec..cd34834 100644 --- a/Makefile.incl +++ b/Makefile.incl @@ -1,4 +1,4 @@ -# $Id: Makefile.inc 89 2016-01-12 00:20:40Z reddawg $ +# The System Makefile (C) 2002, 2017 The UbixOS Project # Global 'Source' Options # allow you to change your default compiler without affecting your other work diff --git a/bin/Makefile b/bin/Makefile index 7a2f8e9..7fb5afb 100644 --- a/bin/Makefile +++ b/bin/Makefile @@ -1,5 +1,4 @@ -# $Id: Makefile 121 2016-01-14 03:18:20Z reddawg $ -# The System Makefile (C) 2002 The UbixOS Project +# System Makefile (C) 2002 The UbixOS Project all: init-bin login-bin shell-bin clock-bin cp-bin fdisk-bin format-bin disklabel-bin ubistry-bin ttyd-bin stat-bin muffin-bin # cat-bin diff --git a/bin/sh/mkbuiltins b/bin/sh/mkbuiltins old mode 100644 new mode 100755 diff --git a/bin/sh/tests/functional_test.sh b/bin/sh/tests/functional_test.sh old mode 100644 new mode 100755 diff --git a/contrib/jemalloc/FREEBSD-upgrade b/contrib/jemalloc/FREEBSD-upgrade old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/bin/cat/t_cat.sh b/contrib/netbsd-tests/bin/cat/t_cat.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/bin/cp/t_cp.sh b/contrib/netbsd-tests/bin/cp/t_cp.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/bin/dd/t_dd.sh b/contrib/netbsd-tests/bin/dd/t_dd.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/bin/df/t_df.sh b/contrib/netbsd-tests/bin/df/t_df.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/bin/expr/t_expr.sh b/contrib/netbsd-tests/bin/expr/t_expr.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/bin/pax/t_pax.sh b/contrib/netbsd-tests/bin/pax/t_pax.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/bin/ps/t_ps.sh b/contrib/netbsd-tests/bin/ps/t_ps.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/bin/sh/dotcmd/scoped_command b/contrib/netbsd-tests/bin/sh/dotcmd/scoped_command old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/bin/sh/dotcmd/t_dotcmd.sh b/contrib/netbsd-tests/bin/sh/dotcmd/t_dotcmd.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/bin/sh/t_arith.sh b/contrib/netbsd-tests/bin/sh/t_arith.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/bin/sh/t_cmdsub.sh b/contrib/netbsd-tests/bin/sh/t_cmdsub.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/bin/sh/t_evaltested.sh b/contrib/netbsd-tests/bin/sh/t_evaltested.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/bin/sh/t_exit.sh b/contrib/netbsd-tests/bin/sh/t_exit.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/bin/sh/t_expand.sh b/contrib/netbsd-tests/bin/sh/t_expand.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/bin/sh/t_fsplit.sh b/contrib/netbsd-tests/bin/sh/t_fsplit.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/bin/sh/t_here.sh b/contrib/netbsd-tests/bin/sh/t_here.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/bin/sh/t_option.sh b/contrib/netbsd-tests/bin/sh/t_option.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/bin/sh/t_redir.sh b/contrib/netbsd-tests/bin/sh/t_redir.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/bin/sh/t_redircloexec.sh b/contrib/netbsd-tests/bin/sh/t_redircloexec.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/bin/sh/t_set_e.sh b/contrib/netbsd-tests/bin/sh/t_set_e.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/bin/sh/t_shift.sh b/contrib/netbsd-tests/bin/sh/t_shift.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/bin/sh/t_ulimit.sh b/contrib/netbsd-tests/bin/sh/t_ulimit.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/bin/sh/t_varquote.sh b/contrib/netbsd-tests/bin/sh/t_varquote.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/bin/sh/t_varval.sh b/contrib/netbsd-tests/bin/sh/t_varval.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/bin/sh/t_wait.sh b/contrib/netbsd-tests/bin/sh/t_wait.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/bin/sleep/t_sleep.sh b/contrib/netbsd-tests/bin/sleep/t_sleep.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/bin/tar/t_tar.sh b/contrib/netbsd-tests/bin/tar/t_tar.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/crypto/libcrypto/t_certs.sh b/contrib/netbsd-tests/crypto/libcrypto/t_certs.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/crypto/libcrypto/t_ciphers.sh b/contrib/netbsd-tests/crypto/libcrypto/t_ciphers.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/crypto/libcrypto/t_hashes.sh b/contrib/netbsd-tests/crypto/libcrypto/t_hashes.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/crypto/libcrypto/t_libcrypto.sh b/contrib/netbsd-tests/crypto/libcrypto/t_libcrypto.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/crypto/libcrypto/t_pubkey.sh b/contrib/netbsd-tests/crypto/libcrypto/t_pubkey.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/crypto/opencrypto/t_opencrypto.sh b/contrib/netbsd-tests/crypto/opencrypto/t_opencrypto.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/dev/audio/t_pad.sh b/contrib/netbsd-tests/dev/audio/t_pad.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/dev/cgd/t_cgd.sh b/contrib/netbsd-tests/dev/cgd/t_cgd.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/dev/clock_subr/clock_subr_test_data_gen.sh b/contrib/netbsd-tests/dev/clock_subr/clock_subr_test_data_gen.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/dev/dm/t_dm.sh b/contrib/netbsd-tests/dev/dm/t_dm.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/dev/fss/t_fss.sh b/contrib/netbsd-tests/dev/fss/t_fss.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/dev/md/t_md.sh b/contrib/netbsd-tests/dev/md/t_md.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/dev/raidframe/t_raid.sh b/contrib/netbsd-tests/dev/raidframe/t_raid.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/dev/sysmon/t_swsensor.sh b/contrib/netbsd-tests/dev/sysmon/t_swsensor.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/fs/cd9660/t_high_ino_big_file.sh b/contrib/netbsd-tests/fs/cd9660/t_high_ino_big_file.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/fs/ffs/ffs_common.sh b/contrib/netbsd-tests/fs/ffs/ffs_common.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/fs/ffs/quotas_common.sh b/contrib/netbsd-tests/fs/ffs/quotas_common.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/fs/ffs/t_clearquota.sh b/contrib/netbsd-tests/fs/ffs/t_clearquota.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/fs/ffs/t_getquota.sh b/contrib/netbsd-tests/fs/ffs/t_getquota.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/fs/ffs/t_miscquota.sh b/contrib/netbsd-tests/fs/ffs/t_miscquota.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/fs/ffs/t_quotalimit.sh b/contrib/netbsd-tests/fs/ffs/t_quotalimit.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/fs/ffs/t_setquota.sh b/contrib/netbsd-tests/fs/ffs/t_setquota.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/fs/nfs/t_rquotad.sh b/contrib/netbsd-tests/fs/nfs/t_rquotad.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/fs/psshfs/t_psshfs.sh b/contrib/netbsd-tests/fs/psshfs/t_psshfs.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/fs/tmpfs/t_create.sh b/contrib/netbsd-tests/fs/tmpfs/t_create.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/fs/tmpfs/t_devices.sh b/contrib/netbsd-tests/fs/tmpfs/t_devices.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/fs/tmpfs/t_dots.sh b/contrib/netbsd-tests/fs/tmpfs/t_dots.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/fs/tmpfs/t_exec.sh b/contrib/netbsd-tests/fs/tmpfs/t_exec.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/fs/tmpfs/t_link.sh b/contrib/netbsd-tests/fs/tmpfs/t_link.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/fs/tmpfs/t_mkdir.sh b/contrib/netbsd-tests/fs/tmpfs/t_mkdir.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/fs/tmpfs/t_mknod.sh b/contrib/netbsd-tests/fs/tmpfs/t_mknod.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/fs/tmpfs/t_mount.sh b/contrib/netbsd-tests/fs/tmpfs/t_mount.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/fs/tmpfs/t_pipes.sh b/contrib/netbsd-tests/fs/tmpfs/t_pipes.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/fs/tmpfs/t_read_write.sh b/contrib/netbsd-tests/fs/tmpfs/t_read_write.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/fs/tmpfs/t_readdir.sh b/contrib/netbsd-tests/fs/tmpfs/t_readdir.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/fs/tmpfs/t_remove.sh b/contrib/netbsd-tests/fs/tmpfs/t_remove.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/fs/tmpfs/t_rename.sh b/contrib/netbsd-tests/fs/tmpfs/t_rename.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/fs/tmpfs/t_rmdir.sh b/contrib/netbsd-tests/fs/tmpfs/t_rmdir.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/fs/tmpfs/t_setattr.sh b/contrib/netbsd-tests/fs/tmpfs/t_setattr.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/fs/tmpfs/t_sizes.sh b/contrib/netbsd-tests/fs/tmpfs/t_sizes.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/fs/tmpfs/t_sockets.sh b/contrib/netbsd-tests/fs/tmpfs/t_sockets.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/fs/tmpfs/t_statvfs.sh b/contrib/netbsd-tests/fs/tmpfs/t_statvfs.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/fs/tmpfs/t_symlink.sh b/contrib/netbsd-tests/fs/tmpfs/t_symlink.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/fs/tmpfs/t_times.sh b/contrib/netbsd-tests/fs/tmpfs/t_times.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/fs/tmpfs/t_trail_slash.sh b/contrib/netbsd-tests/fs/tmpfs/t_trail_slash.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/fs/tmpfs/t_truncate.sh b/contrib/netbsd-tests/fs/tmpfs/t_truncate.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/fs/tmpfs/t_vnd.sh b/contrib/netbsd-tests/fs/tmpfs/t_vnd.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/fs/tmpfs/t_vnode_leak.sh b/contrib/netbsd-tests/fs/tmpfs/t_vnode_leak.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/fs/zfs/t_zpool.sh b/contrib/netbsd-tests/fs/zfs/t_zpool.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/games/t_factor.sh b/contrib/netbsd-tests/games/t_factor.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/ipf/h_common.sh b/contrib/netbsd-tests/ipf/h_common.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/ipf/t_bpf.sh b/contrib/netbsd-tests/ipf/t_bpf.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/ipf/t_filter_exec.sh b/contrib/netbsd-tests/ipf/t_filter_exec.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/ipf/t_filter_parse.sh b/contrib/netbsd-tests/ipf/t_filter_parse.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/ipf/t_logging.sh b/contrib/netbsd-tests/ipf/t_logging.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/ipf/t_nat_exec.sh b/contrib/netbsd-tests/ipf/t_nat_exec.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/ipf/t_nat_ipf_exec.sh b/contrib/netbsd-tests/ipf/t_nat_ipf_exec.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/ipf/t_nat_parse.sh b/contrib/netbsd-tests/ipf/t_nat_parse.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/ipf/t_pools.sh b/contrib/netbsd-tests/ipf/t_pools.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/kernel/gen_t_subr_prf b/contrib/netbsd-tests/kernel/gen_t_subr_prf old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/kernel/t_ps_strings.sh b/contrib/netbsd-tests/kernel/t_ps_strings.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/kernel/t_umount.sh b/contrib/netbsd-tests/kernel/t_umount.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/kernel/t_umountstress.sh b/contrib/netbsd-tests/kernel/t_umountstress.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/lib/csu/t_crt0.sh b/contrib/netbsd-tests/lib/csu/t_crt0.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/lib/libc/db/t_db.sh b/contrib/netbsd-tests/lib/libc/db/t_db.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/lib/libc/gen/posix_spawn/h_nonexec.sh b/contrib/netbsd-tests/lib/libc/gen/posix_spawn/h_nonexec.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/lib/libc/hash/t_hash.sh b/contrib/netbsd-tests/lib/libc/hash/t_hash.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/lib/libc/net/gen_ether_subr b/contrib/netbsd-tests/lib/libc/net/gen_ether_subr old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/lib/libc/net/getaddrinfo/t_getaddrinfo.sh b/contrib/netbsd-tests/lib/libc/net/getaddrinfo/t_getaddrinfo.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/lib/libc/net/t_hostent.sh b/contrib/netbsd-tests/lib/libc/net/t_hostent.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/lib/libc/net/t_nsdispatch.sh b/contrib/netbsd-tests/lib/libc/net/t_nsdispatch.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/lib/libc/net/t_protoent.sh b/contrib/netbsd-tests/lib/libc/net/t_protoent.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/lib/libc/net/t_servent.sh b/contrib/netbsd-tests/lib/libc/net/t_servent.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/lib/libc/regex/t_regex.sh b/contrib/netbsd-tests/lib/libc/regex/t_regex.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/lib/libc/ssp/t_ssp.sh b/contrib/netbsd-tests/lib/libc/ssp/t_ssp.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/lib/libc/stdlib/t_atexit.sh b/contrib/netbsd-tests/lib/libc/stdlib/t_atexit.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/lib/libc/stdlib/t_getopt.sh b/contrib/netbsd-tests/lib/libc/stdlib/t_getopt.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/lib/libcurses/t_curses.sh b/contrib/netbsd-tests/lib/libcurses/t_curses.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/lib/libevent/t_event.sh b/contrib/netbsd-tests/lib/libevent/t_event.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/lib/libppath/plist_to_c b/contrib/netbsd-tests/lib/libppath/plist_to_c old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/lib/libpthread/t_atexit.sh b/contrib/netbsd-tests/lib/libpthread/t_atexit.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/lib/libpthread/t_cancel.sh b/contrib/netbsd-tests/lib/libpthread/t_cancel.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/lib/libpthread/t_exit.sh b/contrib/netbsd-tests/lib/libpthread/t_exit.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/lib/libpthread/t_resolv.sh b/contrib/netbsd-tests/lib/libpthread/t_resolv.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/lib/librumpclient/t_exec.sh b/contrib/netbsd-tests/lib/librumpclient/t_exec.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/lib/librumphijack/t_asyncio.sh b/contrib/netbsd-tests/lib/librumphijack/t_asyncio.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/lib/librumphijack/t_config.sh b/contrib/netbsd-tests/lib/librumphijack/t_config.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/lib/librumphijack/t_cwd.sh b/contrib/netbsd-tests/lib/librumphijack/t_cwd.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/lib/librumphijack/t_sh.sh b/contrib/netbsd-tests/lib/librumphijack/t_sh.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/lib/librumphijack/t_tcpip.sh b/contrib/netbsd-tests/lib/librumphijack/t_tcpip.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/lib/librumphijack/t_vfs.sh b/contrib/netbsd-tests/lib/librumphijack/t_vfs.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/lib/libsljit/t_sljit.sh b/contrib/netbsd-tests/lib/libsljit/t_sljit.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/libexec/ld.elf_so/t_df_1_noopen.sh b/contrib/netbsd-tests/libexec/ld.elf_so/t_df_1_noopen.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/libexec/ld.elf_so/t_dl_symver.sh b/contrib/netbsd-tests/libexec/ld.elf_so/t_dl_symver.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/modules/t_abi_uvm.sh b/contrib/netbsd-tests/modules/t_abi_uvm.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/modules/t_modload.sh b/contrib/netbsd-tests/modules/t_modload.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/net/arp/t_arp.sh b/contrib/netbsd-tests/net/arp/t_arp.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/net/arp/t_dad.sh b/contrib/netbsd-tests/net/arp/t_dad.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/net/carp/t_basic.sh b/contrib/netbsd-tests/net/carp/t_basic.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/net/fdpass/t_fdpass.sh b/contrib/netbsd-tests/net/fdpass/t_fdpass.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/net/icmp/t_icmp6_redirect.sh b/contrib/netbsd-tests/net/icmp/t_icmp6_redirect.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/net/icmp/t_icmp_redirect.sh b/contrib/netbsd-tests/net/icmp/t_icmp_redirect.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/net/icmp/t_ping2.sh b/contrib/netbsd-tests/net/icmp/t_ping2.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/net/if/t_ifconf.sh b/contrib/netbsd-tests/net/if/t_ifconf.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/net/if/t_ifconfig.sh b/contrib/netbsd-tests/net/if/t_ifconfig.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/net/if_bridge/t_bridge.sh b/contrib/netbsd-tests/net/if_bridge/t_bridge.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/net/if_gif/t_gif.sh b/contrib/netbsd-tests/net/if_gif/t_gif.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/net/if_pppoe/t_pppoe.sh b/contrib/netbsd-tests/net/if_pppoe/t_pppoe.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/net/if_tap/t_tap.sh b/contrib/netbsd-tests/net/if_tap/t_tap.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/net/if_tun/t_tun.sh b/contrib/netbsd-tests/net/if_tun/t_tun.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/net/if_vlan/t_vlan.sh b/contrib/netbsd-tests/net/if_vlan/t_vlan.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/net/in_cksum/t_in_cksum.sh b/contrib/netbsd-tests/net/in_cksum/t_in_cksum.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/net/mcast/t_mcast.sh b/contrib/netbsd-tests/net/mcast/t_mcast.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/net/mpls/t_ldp_regen.sh b/contrib/netbsd-tests/net/mpls/t_ldp_regen.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/net/mpls/t_mpls_fw.sh b/contrib/netbsd-tests/net/mpls/t_mpls_fw.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/net/mpls/t_mpls_fw6.sh b/contrib/netbsd-tests/net/mpls/t_mpls_fw6.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/net/mpls/t_mpls_fw64.sh b/contrib/netbsd-tests/net/mpls/t_mpls_fw64.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/net/mpls/t_rfc4182.sh b/contrib/netbsd-tests/net/mpls/t_rfc4182.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/net/ndp/t_dad.sh b/contrib/netbsd-tests/net/ndp/t_dad.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/net/ndp/t_ndp.sh b/contrib/netbsd-tests/net/ndp/t_ndp.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/net/ndp/t_ra.sh b/contrib/netbsd-tests/net/ndp/t_ra.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/net/net/t_forwarding.sh b/contrib/netbsd-tests/net/net/t_forwarding.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/net/net/t_ipaddress.sh b/contrib/netbsd-tests/net/net/t_ipaddress.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/net/net/t_ipv6_lifetime.sh b/contrib/netbsd-tests/net/net/t_ipv6_lifetime.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/net/net/t_ipv6address.sh b/contrib/netbsd-tests/net/net/t_ipv6address.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/net/net/t_mtudisc.sh b/contrib/netbsd-tests/net/net/t_mtudisc.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/net/net/t_mtudisc6.sh b/contrib/netbsd-tests/net/net/t_mtudisc6.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/net/net/t_ping6_opts.sh b/contrib/netbsd-tests/net/net/t_ping6_opts.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/net/net_common.sh b/contrib/netbsd-tests/net/net_common.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/net/npf/t_npf.sh b/contrib/netbsd-tests/net/npf/t_npf.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/net/route/t_change.sh b/contrib/netbsd-tests/net/route/t_change.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/net/route/t_flags.sh b/contrib/netbsd-tests/net/route/t_flags.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/net/route/t_flags6.sh b/contrib/netbsd-tests/net/route/t_flags6.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/net/route/t_route.sh b/contrib/netbsd-tests/net/route/t_route.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/rump/rumpkern/t_sp.sh b/contrib/netbsd-tests/rump/rumpkern/t_sp.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/rump/rumpnet/t_shmif.sh b/contrib/netbsd-tests/rump/rumpnet/t_shmif.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/sbin/fsck_ffs/quotas_common.sh b/contrib/netbsd-tests/sbin/fsck_ffs/quotas_common.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/sbin/fsck_ffs/t_check_quotas.sh b/contrib/netbsd-tests/sbin/fsck_ffs/t_check_quotas.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/sbin/fsck_ffs/t_enable_quotas.sh b/contrib/netbsd-tests/sbin/fsck_ffs/t_enable_quotas.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/sbin/gpt/t_gpt.sh b/contrib/netbsd-tests/sbin/gpt/t_gpt.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/sbin/ifconfig/t_nonexistent.sh b/contrib/netbsd-tests/sbin/ifconfig/t_nonexistent.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/sbin/newfs/quotas_common.sh b/contrib/netbsd-tests/sbin/newfs/quotas_common.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/sbin/newfs/t_enable_quotas.sh b/contrib/netbsd-tests/sbin/newfs/t_enable_quotas.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/sbin/newfs_msdos/t_create.sh b/contrib/netbsd-tests/sbin/newfs_msdos/t_create.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/sbin/resize_ffs/common.sh b/contrib/netbsd-tests/sbin/resize_ffs/common.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/sbin/resize_ffs/t_check.sh b/contrib/netbsd-tests/sbin/resize_ffs/t_check.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/sbin/resize_ffs/t_grow.sh b/contrib/netbsd-tests/sbin/resize_ffs/t_grow.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/sbin/resize_ffs/t_grow_swapped.sh b/contrib/netbsd-tests/sbin/resize_ffs/t_grow_swapped.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/sbin/resize_ffs/t_shrink.sh b/contrib/netbsd-tests/sbin/resize_ffs/t_shrink.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/sbin/resize_ffs/t_shrink_swapped.sh b/contrib/netbsd-tests/sbin/resize_ffs/t_shrink_swapped.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/sbin/route/t_missing.sh b/contrib/netbsd-tests/sbin/route/t_missing.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/sbin/sysctl/t_perm.sh b/contrib/netbsd-tests/sbin/sysctl/t_perm.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/sbin/sysctl/t_sysctl.sh b/contrib/netbsd-tests/sbin/sysctl/t_sysctl.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/share/examples/t_asm.sh b/contrib/netbsd-tests/share/examples/t_asm.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/share/mk/t_lib.sh b/contrib/netbsd-tests/share/mk/t_lib.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/share/mk/t_own.sh b/contrib/netbsd-tests/share/mk/t_own.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/share/mk/t_prog.sh b/contrib/netbsd-tests/share/mk/t_prog.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/share/mk/t_test.sh b/contrib/netbsd-tests/share/mk/t_test.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/sys/rc/h_args.sh b/contrib/netbsd-tests/sys/rc/h_args.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/sys/rc/h_simple.sh b/contrib/netbsd-tests/sys/rc/h_simple.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/sys/rc/t_rc_d_cli.sh b/contrib/netbsd-tests/sys/rc/t_rc_d_cli.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/usr.bin/awk/t_awk.sh b/contrib/netbsd-tests/usr.bin/awk/t_awk.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/usr.bin/basename/t_basename.sh b/contrib/netbsd-tests/usr.bin/basename/t_basename.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/usr.bin/bzip2/t_bzip2.sh b/contrib/netbsd-tests/usr.bin/bzip2/t_bzip2.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/usr.bin/cc/t_hello.sh b/contrib/netbsd-tests/usr.bin/cc/t_hello.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/usr.bin/cmp/t_cmp.sh b/contrib/netbsd-tests/usr.bin/cmp/t_cmp.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/usr.bin/config/t_config.sh b/contrib/netbsd-tests/usr.bin/config/t_config.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/usr.bin/cut/t_cut.sh b/contrib/netbsd-tests/usr.bin/cut/t_cut.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/usr.bin/diff/t_diff.sh b/contrib/netbsd-tests/usr.bin/diff/t_diff.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/usr.bin/dirname/t_dirname.sh b/contrib/netbsd-tests/usr.bin/dirname/t_dirname.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/usr.bin/find/t_find.sh b/contrib/netbsd-tests/usr.bin/find/t_find.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/usr.bin/gdb/t_regress.sh b/contrib/netbsd-tests/usr.bin/gdb/t_regress.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/usr.bin/grep/t_grep.sh b/contrib/netbsd-tests/usr.bin/grep/t_grep.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/usr.bin/gzip/t_gzip.sh b/contrib/netbsd-tests/usr.bin/gzip/t_gzip.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/usr.bin/id/t_groups.sh b/contrib/netbsd-tests/usr.bin/id/t_groups.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/usr.bin/id/t_id.sh b/contrib/netbsd-tests/usr.bin/id/t_id.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/usr.bin/id/t_whoami.sh b/contrib/netbsd-tests/usr.bin/id/t_whoami.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/usr.bin/infocmp/t_terminfo.sh b/contrib/netbsd-tests/usr.bin/infocmp/t_terminfo.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/usr.bin/jot/t_jot.sh b/contrib/netbsd-tests/usr.bin/jot/t_jot.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/usr.bin/ld/t_script.sh b/contrib/netbsd-tests/usr.bin/ld/t_script.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/usr.bin/ld/t_section.sh b/contrib/netbsd-tests/usr.bin/ld/t_section.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/usr.bin/m4/t_m4.sh b/contrib/netbsd-tests/usr.bin/m4/t_m4.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/usr.bin/make/t_make.sh b/contrib/netbsd-tests/usr.bin/make/t_make.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/usr.bin/mixerctl/t_mixerctl.sh b/contrib/netbsd-tests/usr.bin/mixerctl/t_mixerctl.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/usr.bin/mkdep/t_mkdep.sh b/contrib/netbsd-tests/usr.bin/mkdep/t_mkdep.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/usr.bin/nbperf/h_nbperf.sh b/contrib/netbsd-tests/usr.bin/nbperf/h_nbperf.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/usr.bin/nbperf/t_nbperf.sh b/contrib/netbsd-tests/usr.bin/nbperf/t_nbperf.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/usr.bin/netpgpverify/t_netpgpverify.sh b/contrib/netbsd-tests/usr.bin/netpgpverify/t_netpgpverify.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/usr.bin/pr/t_basic.sh b/contrib/netbsd-tests/usr.bin/pr/t_basic.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/usr.bin/rump_server/t_disk.sh b/contrib/netbsd-tests/usr.bin/rump_server/t_disk.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/usr.bin/sdiff/t_sdiff.sh b/contrib/netbsd-tests/usr.bin/sdiff/t_sdiff.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/usr.bin/sed/t_sed.sh b/contrib/netbsd-tests/usr.bin/sed/t_sed.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/usr.bin/shmif_dumpbus/t_basic.sh b/contrib/netbsd-tests/usr.bin/shmif_dumpbus/t_basic.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/usr.bin/sort/t_sort.sh b/contrib/netbsd-tests/usr.bin/sort/t_sort.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/usr.bin/tmux/t_tmux.sh b/contrib/netbsd-tests/usr.bin/tmux/t_tmux.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/usr.bin/tr/t_basic.sh b/contrib/netbsd-tests/usr.bin/tr/t_basic.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/usr.bin/unifdef/t_basic.sh b/contrib/netbsd-tests/usr.bin/unifdef/t_basic.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/usr.bin/uniq/t_uniq.sh b/contrib/netbsd-tests/usr.bin/uniq/t_uniq.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/usr.bin/vmstat/t_vmstat.sh b/contrib/netbsd-tests/usr.bin/vmstat/t_vmstat.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/t_integration.sh b/contrib/netbsd-tests/usr.bin/xlint/lint1/t_integration.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/usr.sbin/mtree/t_mtree.sh b/contrib/netbsd-tests/usr.sbin/mtree/t_mtree.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/usr.sbin/tcpdump/t_tcpdump.sh b/contrib/netbsd-tests/usr.sbin/tcpdump/t_tcpdump.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/usr.sbin/traceroute/t_traceroute.sh b/contrib/netbsd-tests/usr.sbin/traceroute/t_traceroute.sh old mode 100644 new mode 100755 diff --git a/contrib/netbsd-tests/usr.sbin/useradd/t_useradd.sh b/contrib/netbsd-tests/usr.sbin/useradd/t_useradd.sh old mode 100644 new mode 100755 diff --git a/debug/sysctl b/debug/sysctl new file mode 100755 index 0000000..1a433dd --- /dev/null +++ b/debug/sysctl Binary files differ diff --git a/debug/sysctl.c b/debug/sysctl.c index 9a3f143..6b73e81 100644 --- a/debug/sysctl.c +++ b/debug/sysctl.c @@ -14,6 +14,9 @@ int main() { printf("SYSCTL\n"); + int i; + u_int32_t *tI; + mib[0] = 1; mib[1] = 1; @@ -49,25 +52,35 @@ p = malloc(len); sysctl(mib, 2, p, &len, NULL, 0); + printf("[len: %i]\n", len); printf("[%s]\n", p); - mib[0] = 6; - mib[1] = 1; + mib[0] = 2;//1;//6; + mib[1] = 12;//37;//2147482988;//1; + printf("2:12\n"); sysctl(mib, 2, NULL, &len, NULL, 0); p = malloc(len); sysctl(mib, 2, p, &len, NULL, 0); - printf("[%s]\n", p); + //printf("[%s]\n", p); + printf("[len: %i]\n", len); + tI = p; + for (i=0;i<(len/4);i++) + printf("Val: [0x%X], Add: [0x%X][0x%X]\n", tI[i], p, p + (4 * i)); + + printf("\nEND\n"); size_t j; j = name2oid("vm.overcommit", mib); + //j = name2oid("hw.pagesizes", mib); printf("j:[%i]\n", j); for (int i = 0; i < j; i++) printf("[%i]", mib[i]); + printf("\n"); } @@ -87,3 +100,4 @@ j /= sizeof(int); return (j); } + diff --git a/include/mk-osreldate.sh b/include/mk-osreldate.sh old mode 100644 new mode 100755 diff --git a/lib/Makefile b/lib/Makefile index 8127688..0f32f5a 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -1,5 +1,4 @@ -# $Id: Makefile 121 2016-01-14 03:18:20Z reddawg $ -# The System Makefile (C) 2002 The UbixOS Project +# Makefile (C) 2002 The UbixOS Project all: csu-code ubix_api-code libc_old-code ubix-code libcpp-code objgfx-code #libc-code# libcpp-code # bin tools diff --git a/lib/libc/regex/grot/mkh b/lib/libc/regex/grot/mkh old mode 100644 new mode 100755 diff --git a/lib/objgfx/objgfx40.so b/lib/objgfx/objgfx40.so deleted file mode 100644 index 963e03b..0000000 --- a/lib/objgfx/objgfx40.so +++ /dev/null Binary files differ diff --git a/lib/objgfx40/ROMAN1.DPF b/lib/objgfx40/ROMAN1.DPF old mode 100644 new mode 100755 Binary files differ diff --git a/lib/objgfx40/SCRIPT.DPF b/lib/objgfx40/SCRIPT.DPF old mode 100644 new mode 100755 Binary files differ diff --git a/lib/objgfx40/ogDisplay_UbixOS.cc b/lib/objgfx40/ogDisplay_UbixOS.cc old mode 100644 new mode 100755 diff --git a/libexec/Makefile b/libexec/Makefile index 96e6538..1a9cdaa 100644 --- a/libexec/Makefile +++ b/libexec/Makefile @@ -1,4 +1,4 @@ -# The System Makefile (C) 2017 The UbixOS Project +# Makefile (C) 2017 The UbixOS Project all: ld-bin #rtld-elf-bin diff --git a/sys/Makefile b/sys/Makefile index 929246e..549a24b 100644 --- a/sys/Makefile +++ b/sys/Makefile @@ -1,5 +1,4 @@ -# $Id: Makefile 134 2016-01-15 14:50:24Z reddawg $ -# Kernel Makefile (C) 2002 The UbixOS Project +# Makefile (C) 2002 The UbixOS Project include ../Makefile.incl include Makefile.incl @@ -37,8 +36,8 @@ init-code: init (cd init;make) -arch-code: ${_ARCH} - (cd ${_ARCH};make) +arch-code: arch/${_ARCH} + (cd arch/${_ARCH};make) kernel-code: kernel (cd kernel;make) @@ -110,7 +109,7 @@ clean: (cd init;make clean) - (cd ${_ARCH};make clean) + (cd arch/${_ARCH};make clean) (cd sys;make clean) (cd kernel;make clean) (cd vmm;make clean) @@ -121,10 +120,10 @@ (cd pci;make clean) (cd net;make clean) (cd compile;make clean) - #(cd vfs;make clean) - #(cd sde;make clean) - #(cd devfs;make clean) - #(cd net;make clean) - #(cd kmods;make clean) - #(cd ufs;make clean) + (cd fs/vfs;make clean) + (cd sde;make clean) + (cd fs/devfs;make clean) + (cd net;make clean) + (cd kmods;make clean) + (cd fs/ufs;make clean) #(cd ../tools/;make clean) diff --git a/sys/arch/armv6/Makefile b/sys/arch/armv6/Makefile new file mode 100644 index 0000000..de38484 --- /dev/null +++ b/sys/arch/armv6/Makefile @@ -0,0 +1,28 @@ +# (C) 2002 The UbixOS Project +# $Id: Makefile 134 2016-01-15 14:50:24Z reddawg $ + +# Include Global 'Source' Options +include ../../Makefile.incl +include ../Makefile.incl + +# Objects +OBJS = schedyield.o kpanic.o timer.o spinlock.o i386_exec.o sys_call_new.o sys_call.o bioscall.o fork.o syscall.o systemtask.o sched.o cpu.o +# ap-boot.o smp.o vitals.o(obsolete) + +all: $(OBJS) + +# Compile Types +.cc.o: + $(CXX) -DNOBOOL $(CFLAGS) $(INCLUDES) -c -o $@ $< +.cc.s: + $(CXX) -DNOBOOL $(CFLAGS) $(INCLUDES) -S -o $@ $< +.c.o: + $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $< +.c.s: + $(CC) $(CFLAGS) $(INCLUDES) -S -o $@ $< +.S.o: + $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) diff --git a/sys/arch/armv6/ap-boot.S b/sys/arch/armv6/ap-boot.S new file mode 100644 index 0000000..c08bd1e --- /dev/null +++ b/sys/arch/armv6/ap-boot.S @@ -0,0 +1,133 @@ +/*- + * Copyright (c) 2002-2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Okay, this file contains the code that's going to bootstrap the AP cpus + */ + + + .globl ap_trampoline_start,ap_trampoline_end + .text + .code16 +ap_trampoline_start: + cli + cld + + movw %cs,%ax // The CPU knows its CS already, so lets use it for the other segments + movw %ax,%ds + movw %ax,%es + movw %ax,%ss + + // Do some bochs-specific bullshit + mov $0x31,%al // '1' + mov $0xe9,%dx + outb %al,%dx + //lgdt ap_gdt; + lgdt ap_trampoline_gdt_limit - ap_trampoline_start + movl %cr0,%eax + orl $0x1,%eax + movl %eax,%cr0 // PMODE! + +.code32 + .byte 0x66 + ljmp $0x08,$(ap_trampoline_32 - ap_trampoline_start) // 0x08 == KERNEL_CS + +ap_trampoline_32: + mov $0x32,%al // '2' + mov $0xe9,%dx + outb %al,%dx + + mov $0x10,%ax + mov %ax,%ds + mov %ax,%es + mov %ax,%fs + mov %ax,%gs + mov %ax,%ss + + // Spinlock + mov ap_trampoline_spl - ap_trampoline_start,%edi +ap_spl: + //cmp $1,(%edi) + //je ap_spl + + mov $1,%eax // Value to be set + xchgl (%edi),%eax + cmp $0,%eax + je ap_spl + // /Spinlock + + mov $0x30,%al // '0' + mov $0xe9,%dx + outb %al,%dx + + mov ap_trampoline_stackptr - ap_trampoline_start,%ebx + mov %ebx,%esp + add $0x1000,%ebx + mov %ebx,ap_trampoline_stackptr - ap_trampoline_start + + mov $0x31,%al // '1' + mov $0xe9,%dx + outb %al,%dx + + // spinunlock + mov $0,%eax + mov ap_trampoline_spl - ap_trampoline_start,%edi + xchgl (%edi),%eax + // /spinunlock + + mov $0x33,%al // '3' + mov $0xe9,%dx + outb %al,%dx + + mov ap_trampoline_epoint,%eax + call *%eax +1: + hlt + jmp 1b // Halt if we ever get here somehow + + // Stack.. This sucks, since CPU initialization isn't serialized +ap_trampoline_stackptr: + .long 0x10000 // 256KB +ap_trampoline_epoint: + .long c_ap_boot + +ap_trampoline_spl: + .long 0 +ap_gdt: + .long ubixGDT + + // GDT +ap_trampoline_gdt: + .word 0 +ap_trampoline_gdt_limit: + .word 128 // Room for 32 descriptors +ap_trampoline_gdt_base: + .long 0x20000 // 128KB (move this later) + + +ap_trampoline_end: diff --git a/sys/arch/armv6/bioscall.c b/sys/arch/armv6/bioscall.c new file mode 100644 index 0000000..c27a8db --- /dev/null +++ b/sys/arch/armv6/bioscall.c @@ -0,0 +1,101 @@ +/*- + * Copyright (c) 2002-2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + + +asm( + ".globl bios16Code\n" + ".code16 \n" + "bios16Code: \n" + "int $0x10 \n" + "int $0x69 \n" + ".code32 \n" + ); + + +void biosCall(int biosInt,int eax,int ebx,int ecx,int edx,int esi,int edi,int es,int ds) { + short segment = 0x0,offset = 0x0; + uInt32 tmpAddr = (uInt32)&bios16Code; + kTask_t *newProcess = 0x0; + + offset = tmpAddr & 0xF; // lower 4 bits + segment = tmpAddr >> 4; + + newProcess = schedNewTask(); + assert(newProcess); + + + newProcess->tss.back_link = 0x0; + newProcess->tss.esp0 = (uInt32)kmalloc(0x2000)+0x2000; + newProcess->tss.ss0 = 0x10; + newProcess->tss.esp1 = 0x0; + newProcess->tss.ss1 = 0x0; + newProcess->tss.esp2 = 0x0; + newProcess->tss.ss2 = 0x0; + newProcess->tss.cr3 = (uInt32)_current->tss.cr3;//(uInt32)vmmCreateVirtualSpace(newProcess->id); + newProcess->tss.eip = offset & 0xFFFF; + newProcess->tss.eflags = 2 | EFLAG_IF | EFLAG_VM; + newProcess->tss.eax = eax & 0xFFFF; + newProcess->tss.ebx = ebx & 0xFFFF; + newProcess->tss.ecx = ecx & 0xFFFF; + newProcess->tss.edx = edx & 0xFFFF; + newProcess->tss.esp = 0x1000 & 0xFFFF; + newProcess->tss.ebp = 0x1000 & 0xFFFF; + newProcess->tss.esi = esi & 0xFFFF; + newProcess->tss.edi = edi & 0xFFFF; + newProcess->tss.es = es & 0xFFFF; + newProcess->tss.cs = segment & 0xFFFF; + newProcess->tss.ss = 0x1000 & 0xFFFF; + newProcess->tss.ds = ds & 0xFFFF; + newProcess->tss.fs = 0x0 & 0xFFFF; + newProcess->tss.gs = 0x0 & 0xFFFF; + newProcess->tss.ldt = 0x0 & 0xFFFF; + newProcess->tss.trace_bitmap = 0x0 & 0xFFFF; + newProcess->tss.io_map = 0x0 & 0xFFFF; + newProcess->tss.io_map = sizeof(struct tssStruct)-8192; + newProcess->oInfo.v86Task = 0x1; + + newProcess->state = READY; + + while (newProcess->state > 0); + + return; + } + +/*** + END + ***/ + diff --git a/sys/arch/armv6/exec.c b/sys/arch/armv6/exec.c new file mode 100644 index 0000000..3af2f28 --- /dev/null +++ b/sys/arch/armv6/exec.c @@ -0,0 +1,750 @@ +/*- + * Copyright (c) 2002-2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define STACK_ADDR 0xC800000 + +#define AT_NULL 0 /* Terminates the vector. */ +#define AT_IGNORE 1 /* Ignored entry. */ +#define AT_EXECFD 2 /* File descriptor of program to load. */ +#define AT_PHDR 3 /* Program header of program already loaded. */ +#define AT_PHENT 4 /* Size of each program header entry. */ +#define AT_PHNUM 5 /* Number of program header entries. */ +#define AT_PAGESZ 6 /* Page size in bytes. */ +#define AT_BASE 7 /* Interpreter's base address. */ +#define AT_FLAGS 8 /* Flags (unused for i386). */ +#define AT_ENTRY 9 /* Where interpreter should transfer control. */ + +//#define AUXARGS_ENTRY(pos, id, val) {memcpy((void *)pos++,(void *)id,sizeof(long)); memcpy((void *)pos++,(void *)val,sizeof(long));} +#define AUXARGS_ENTRY(pos, id, val) {*pos = id;pos++; *pos = val;pos++;} + +/***************************************************************************************** + + Function: execThread(void (*)(void),int,char *); + Description: This function will create a thread from code in the current memory space + + Notes: + + 05/19/04 - This does not work the way I want it to it still makes a copy of kernel space + so do not use out side of kernel space + + *****************************************************************************************/ +uInt32 execThread(void (*tproc)(void), uInt32 stack, char *arg) { + kTask_t * newProcess = 0x0; + /* Find A New Thread */ + newProcess = schedNewTask(); + assert(newProcess); + if (stack < 0x100000) + kpanic("exec: stack not in valid area: [0x%X]\n", stack); + + /* Set All The Correct Thread Attributes */ + newProcess->tss.back_link = 0x0; + newProcess->tss.esp0 = 0x0; + newProcess->tss.ss0 = 0x0; + newProcess->tss.esp1 = 0x0; + newProcess->tss.ss1 = 0x0; + newProcess->tss.esp2 = 0x0; + newProcess->tss.ss2 = 0x0; + newProcess->tss.cr3 = (unsigned int) kernelPageDirectory; + newProcess->tss.eip = (unsigned int) tproc; + newProcess->tss.eflags = 0x206; + newProcess->tss.esp = stack; + newProcess->tss.ebp = stack; + newProcess->tss.esi = 0x0; + newProcess->tss.edi = 0x0; + + /* Set these up to be ring 3 tasks */ + /* + newProcess->tss.es = 0x30+3; + newProcess->tss.cs = 0x28+3; + newProcess->tss.ss = 0x30+3; + newProcess->tss.ds = 0x30+3; + newProcess->tss.fs = 0x30+3; + newProcess->tss.gs = 0x30+3; + */ + + newProcess->tss.es = 0x10; + newProcess->tss.cs = 0x08; + newProcess->tss.ss = 0x10; + newProcess->tss.ds = 0x10; + newProcess->tss.fs = 0x10; + newProcess->tss.gs = 0x10; + + newProcess->tss.ldt = 0x18; + newProcess->tss.trace_bitmap = 0x0000; + newProcess->tss.io_map = 0x8000; + newProcess->oInfo.vmStart = 0x6400000; + + //newProcess->imageFd = 0x0; + + /* Set up default stack for thread here filled with arg list 3 times */ + asm volatile( + "pusha \n" + "movl %%esp,%%ecx \n" + "movl %1,%%eax \n" + "movl %%eax,%%esp \n" + "pushl %%ebx \n" + "pushl %%ebx \n" + "pushl %%ebx \n" + "movl %%esp,%%eax \n" + "movl %%eax,%1 \n" + "movl %%ecx,%%esp \n" + "popa \n" + : + : "b" (arg),"m" (newProcess->tss.esp) + ); + + /* Put new thread into the READY state */ + sched_setStatus(newProcess->id, READY); + + /* Return with the new process ID */ + return ((uInt32) newProcess); +} + +/***************************************************************************************** + + Function: void execFile(char *file); + Description: This Function Executes A Kile Into A New VM Space With Out + Having To Fork + Notes: + + 07/30/02 - I Have Made Some Heavy Changes To This As Well As Fixed A Few + Memory Leaks The Memory Allocated To Load The Binary Into Is + Now Unmapped So It Can Be Used Again And Not Held Onto Until + The Program Exits + + 07/30/02 - Now I Have To Make A Better Memory Allocator So We Can Set Up + The Freshly Allocated Pages With The Correct Permissions + + *****************************************************************************************/ +void execFile(char *file, int argc, char **argv, int console) { + + int i = 0x0; + int x = 0x0; + uint32_t *tmp = 0x0; + + fileDescriptor *tmpFd = 0x0; + elfHeader *binaryHeader = 0x0; + elfProgramHeader *programHeader = 0x0; + + /* Get A New Task For This Proccess */ + _current = schedNewTask(); + assert(_current); + _current->gid = 0x0; + _current->uid = 0x0; + _current->term = tty_find(console); + if (_current->term == 0x0) + kprintf("Error: invalid console\n"); + + /* Set tty ownership */ + _current->term->owner = _current->id; + + /* Now We Must Create A Virtual Space For This Proccess To Run In */ + _current->tss.cr3 = (uInt32) vmmCreateVirtualSpace(_current->id); + + /* To Better Load This Application We Will Switch Over To Its VM Space */ + asm volatile( + "movl %0,%%eax \n" + "movl %%eax,%%cr3 \n" + : : "d" ((uInt32 *)(_current->tss.cr3)) + ); + + /* Lets Find The File */ + tmpFd = fopen(file, "r"); + + /* If We Dont Find the File Return */ + if (tmpFd == 0x0) { + kprintf("Exec Format Error: Binary File Not Executable.\n"); + fclose(tmpFd); + return; + } + if (tmpFd->perms == 0x0) { + kprintf("Exec Format Error: Binary File Not Executable.\n"); + fclose(tmpFd); + return; + } + + /* Load ELF Header */ + binaryHeader = (elfHeader *) kmalloc(sizeof(elfHeader)); + + //kprintf(">a:%i:0x%X:0x%X<",sizeof(elfHeader),binaryHeader,tmpFd); + fread(binaryHeader, sizeof(elfHeader), 1, tmpFd); + + /* Check If App Is A Real Application */ + if ((binaryHeader->eIdent[1] != 'E') && (binaryHeader->eIdent[2] != 'L') && (binaryHeader->eIdent[3] != 'F')) { + kprintf("Exec Format Error: Binary File Not Executable.\n"); + kfree(binaryHeader); + fclose(tmpFd); + return; + } + else if (binaryHeader->eType != 2) { + kprintf("Exec Format Error: Binary File Not Executable.\n"); + kfree(binaryHeader); + fclose(tmpFd); + return; + } + else if (binaryHeader->eEntry == 0x300000) { + kprintf("Exec Format Error: Binary File Not Executable.\n"); + kfree(binaryHeader); + fclose(tmpFd); + return; + } + + /* Load The Program Header(s) */ + programHeader = (elfProgramHeader *) kmalloc(sizeof(elfProgramHeader) * binaryHeader->ePhnum); + fseek(tmpFd, binaryHeader->ePhoff, 0); + + //kprintf(">c:%i:0x%X:0x%X<",sizeof(elfProgramHeader)*binaryHeader->ePhnum,programHeader,tmpFd); + fread(programHeader, (sizeof(elfProgramHeader) * binaryHeader->ePhnum), 1, tmpFd); + //kprintf(">d<"); + + /* Loop Through The Header And Load Sections Which Need To Be Loaded */ + for (i = 0; i < binaryHeader->ePhnum; i++) { + if (programHeader[i].phType == 1) { + /* + Allocate Memory Im Going To Have To Make This Load Memory With Correct + Settings so it helps us in the future + */ + for (x = 0x0; x < (programHeader[i].phMemsz); x += 0x1000) { + /* Make readonly and read/write !!! */ + if (vmm_remapPage(vmm_findFreePage(_current->id), ((programHeader[i].phVaddr & 0xFFFFF000) + x), PAGE_DEFAULT) == 0x0) + K_PANIC("Remap Page Failed"); + + memset((void *) ((programHeader[i].phVaddr & 0xFFFFF000) + x), 0x0, 0x1000); + } + _current->oInfo.vmStart = 0x80000000; + _current->td.vm_daddr = (char *) (programHeader[i].phVaddr & 0xFFFFF000); + /* Now Load Section To Memory */ + fseek(tmpFd, programHeader[i].phOffset, 0); + fread((void *) programHeader[i].phVaddr, programHeader[i].phFilesz, 1, tmpFd); + if ((programHeader[i].phFlags & 0x2) != 0x2) { + kprintf("pH: [0x%X]\n", programHeader[i].phMemsz); + for (x = 0x0; x < (programHeader[i].phMemsz); x += 0x1000) { + if ((vmm_setPageAttributes((programHeader[i].phVaddr & 0xFFFFF000) + x, PAGE_PRESENT | PAGE_USER)) != 0x0) + kpanic("Error: vmm_setPageAttributes failed, File: %s, Line: %i\n", __FILE__, __LINE__); + } + } + } + } + + /* Set Virtual Memory Start */ + _current->oInfo.vmStart = 0x80000000; + _current->td.vm_daddr = (char *) (programHeader[i].phVaddr & 0xFFFFF000); + + /* Set Up Stack Space */ + for (x = 1; x < 100; x++) { + vmm_remapPage(vmm_findFreePage(_current->id), STACK_ADDR - (x * 0x1000), PAGE_DEFAULT | PAGE_STACK); + } + + /* Kernel Stack 0x2000 bytes long */ + vmm_remapPage(vmm_findFreePage(_current->id), 0x5BC000, KERNEL_PAGE_DEFAULT | PAGE_STACK); + vmm_remapPage(vmm_findFreePage(_current->id), 0x5BB000, KERNEL_PAGE_DEFAULT | PAGE_STACK); + + /* Set All The Proper Information For The Task */ + _current->tss.back_link = 0x0; + _current->tss.esp0 = 0x5BC000; + _current->tss.ss0 = 0x10; + _current->tss.esp1 = 0x0; + _current->tss.ss1 = 0x0; + _current->tss.esp2 = 0x0; + _current->tss.ss2 = 0x0; + _current->tss.eip = (long) binaryHeader->eEntry; + _current->tss.eflags = 0x206; + _current->tss.esp = STACK_ADDR - 12; + _current->tss.ebp = STACK_ADDR; + _current->tss.esi = 0x0; + _current->tss.edi = 0x0; + + /* Set these up to be ring 3 tasks */ + _current->tss.es = 0x30 + 3; + _current->tss.cs = 0x28 + 3; + _current->tss.ss = 0x30 + 3; + _current->tss.ds = 0x30 + 3; + _current->tss.fs = 0x30 + 3; + _current->tss.gs = 0x30 + 3; + + _current->tss.ldt = 0x18; + _current->tss.trace_bitmap = 0x0000; + _current->tss.io_map = 0x8000; + + sched_setStatus(_current->id, READY); + + kfree(binaryHeader); + kfree(programHeader); + fclose(tmpFd); + + tmp = (uInt32 *) _current->tss.esp0 - 5; + tmp[0] = binaryHeader->eEntry; + tmp[3] = STACK_ADDR - 12; + + tmp = (uInt32 *) STACK_ADDR - 2; + + if (_current->id > 4) + kprintf("argv[0]: [%s]\n", argv[0]); + kprintf("argv: [0x%X]\n", argv); + tmp[0] = (uint32_t) argv; + tmp[1] = (uint32_t) argv; + + /* Switch Back To The Kernels VM Space */ + asm volatile( + "movl %0,%%eax \n" + "movl %%eax,%%cr3 \n" + : : "d" ((uInt32 *)(kernelPageDirectory)) + ); + + /* Finally Return */ + return; +} + +/***************************************************************************************** + + Function: void sysExec(); + Description: This Is The System Call To Execute A New Task + + Notes: + 04-22-03 - It Now Loads Sections Not The Full File + + *****************************************************************************************/ +void sysExec(char *file, char *ap) { + int i = 0x0; + int x = 0x0; + int argc = 0x0; + unsigned int *tmp = 0x0; + uInt32 ldAddr = 0x0; + uInt32 seg_size = 0x0; + uInt32 seg_addr = 0x0; + char *interp = 0x0; + char **argv = 0x0; + char **argvNew = 0x0; + char *args = 0x0; + + fileDescriptor *tmpFd = 0x0; + elfHeader *binaryHeader = 0x0; + elfProgramHeader *programHeader = 0x0; + elfSectionHeader *sectionHeader = 0x0; + elfDynamic *elfDynamicS = 0x0; + struct i386_frame *iFrame = 0x0; + + tmpFd = fopen(file, "r"); + _current->files[0] = tmpFd; + /* If We Dont Find the File Return */ + if (tmpFd == 0x0) { + return; + } + if (tmpFd->perms == 0) { + kprintf("Exec Format Error: Binary File Not Executable.\n"); + fclose(tmpFd); + return; + } + + /* Load ELF Header */ + + if ((binaryHeader = (elfHeader *) kmalloc(sizeof(elfHeader))) == 0x0) + endTask(_current->id); + fread(binaryHeader, sizeof(elfHeader), 1, tmpFd); + /* Set sectionHeader To Point To Loaded Binary To We Can Gather Info */ + + /* Check If App Is A Real Application */ + if ((binaryHeader->eIdent[1] != 'E') && (binaryHeader->eIdent[2] != 'L') && (binaryHeader->eIdent[3] != 'F')) { + kprintf("Exec Format Error: Binary File Not Executable.\n"); + kfree(binaryHeader); + fclose(tmpFd); + + return; + } + else if (binaryHeader->eType != 2) { + kprintf("Exec Format Error: Binary File Not Executable.\n"); + kfree(binaryHeader); + fclose(tmpFd); + return; + } + else if (binaryHeader->eEntry == 0x300000) { + kprintf("Exec Format Error: Binary File Not Executable.\n"); + kfree(binaryHeader); + fclose(tmpFd); + return; + } + + /* Load The Program Header(s) */ + if ((programHeader = (elfProgramHeader *) kmalloc(sizeof(elfProgramHeader) * binaryHeader->ePhnum)) == 0x0) + endTask(_current->id); + + assert(programHeader); + fseek(tmpFd, binaryHeader->ePhoff, 0); + fread(programHeader, (sizeof(elfProgramHeader) * binaryHeader->ePhnum), 1, tmpFd); + + if ((sectionHeader = (elfSectionHeader *) kmalloc(sizeof(elfSectionHeader) * binaryHeader->eShnum)) == 0x0) + endTask(_current->id); + + assert(sectionHeader); + fseek(tmpFd, binaryHeader->eShoff, 0); + fread(sectionHeader, sizeof(elfSectionHeader) * binaryHeader->eShnum, 1, tmpFd); + + /* Loop Through The Header And Load Sections Which Need To Be Loaded */ + for (i = 0; i < binaryHeader->ePhnum; i++) { + switch (programHeader[i].phType) { + case PT_LOAD: + seg_addr = trunc_page(programHeader[i].phVaddr); + seg_size = round_page(programHeader[i].phMemsz + programHeader[i].phVaddr - seg_addr); + + /* + Allocate Memory Im Going To Have To Make This Load Memory With Correct + Settings so it helps us in the future + */ + for (x = 0x0; x < (programHeader[i].phMemsz); x += 0x1000) { + /* Make readonly and read/write !!! */ + if (vmm_remapPage(vmm_findFreePage(_current->id), ((programHeader[i].phVaddr & 0xFFFFF000) + x), PAGE_DEFAULT) == 0x0) + K_PANIC("Error: Remap Page Failed"); + memset((void *) ((programHeader[i].phVaddr & 0xFFFFF000) + x), 0x0, 0x1000); + } + + /* Now Load Section To Memory */ + fseek(tmpFd, programHeader[i].phOffset, 0); + fread((void *) programHeader[i].phVaddr, programHeader[i].phFilesz, 1, tmpFd); + if ((programHeader[i].phFlags & 0x2) != 0x2) { + for (x = 0x0; x < (programHeader[i].phMemsz); x += 0x1000) { + if ((vmm_setPageAttributes((programHeader[i].phVaddr & 0xFFFFF000) + x, PAGE_PRESENT | PAGE_USER)) != 0x0) + kpanic("Error: vmm_setPageAttributes failed, File: %s,Line: %i\n", __FILE__, __LINE__); + } + } + kprintf("setting daddr\n"); + if (binaryHeader->eEntry >= programHeader[i].phVaddr && binaryHeader->eEntry < (programHeader[i].phVaddr + programHeader[i].phMemsz)) { + /* We're suposed to do something here? */ + } + else { + _current->td.vm_dsize = seg_size >> PAGE_SHIFT; + _current->td.vm_daddr = (char *) seg_addr; + } + + _current->oInfo.vmStart = ((programHeader[i].phVaddr & 0xFFFFF000) + 0xA900000); + break; + case PT_DYNAMIC: + //newLoc = (char *)programHeader[i].phVaddr; + elfDynamicS = (elfDynamic *) programHeader[i].phVaddr; + fseek(tmpFd, programHeader[i].phOffset, 0); + fread((void *) programHeader[i].phVaddr, programHeader[i].phFilesz, 1, tmpFd); + break; + case PT_INTERP: + interp = (char *) kmalloc(programHeader[i].phFilesz); + fseek(tmpFd, programHeader[i].phOffset, 0); + fread((void *) interp, programHeader[i].phFilesz, 1, tmpFd); + kprintf("Interp: [%s]\n", interp); + ldAddr = ldEnable(); + break; + default: + break; + } + } + + /* What is this doing? 11/23/06 */ + if (elfDynamicS != 0x0) { + for (i = 0; i < 12; i++) { + if (elfDynamicS[i].dynVal == 0x3) { + tmp = (void *) elfDynamicS[i].dynPtr; + if (tmp == 0x0) + kpanic("tmp: NULL\n"); + tmp[2] = (uInt32) ldAddr; + tmp[1] = (uInt32) tmpFd; + break; + } + /* + else { + kprintf("dyn_val: %i",elfDynamicS[i].dynVal); + } + */ + } + } + + _current->td.vm_dsize = seg_size >> PAGE_SHIFT; + _current->td.vm_daddr = (char *) seg_addr; + + argv = ≈ + + if (argv[1] != 0x0) { + argc = (int) argv[0]; + args = (char *) vmmGetFreeVirtualPage(_current->id, 1, VM_TASK); + memset(args, 0x0, 0x1000); + x = 0x0; + argvNew = (char **) kmalloc(sizeof(char *) * argc); + for (i = 0x0; i < argc; i++) { + strcpy(args + x, argv[i + 1]); + argvNew[i] = args + x; + x += strlen(argv[i + 1]) + 1; + //args[x] = '\0'; + //x++; + } + argv = argvNew; + } + + //! Clean the virtual of COW pages left over from the fork + vmm_cleanVirtualSpace(_current->td.vm_daddr + (_current->td.vm_dsize << PAGE_SIZE)); + + //! Adjust iframe + iFrame = (struct i386_frame *) _current->tss.esp0 - sizeof(struct i386_frame); + iFrame->ebp = STACK_ADDR; + iFrame->eip = binaryHeader->eEntry; + iFrame->user_esp = STACK_ADDR - 12; + + //if (_current->id > 3) { + + iFrame->user_esp = ((uint32_t) STACK_ADDR) - (sizeof(uint32_t) * (argc + 3)); + tmp = (void *) iFrame->user_esp; + + //! build argc and argv[] + tmp[0] = argc; + for (i = 0; i < argc; i++) { + tmp[i + 1] = (u_int) argv[i]; + } + tmp[argc + 1] = 0x0; + tmp[argc + 2] = 0x1; + //} + //else { + //tmp = (uint32_t *)STACK_ADDR - 2; + //tmp[0] = 0x1; + //tmp[1] = 0x0; + //tmp[1] = (uint32_t)argv; + //} + kfree(argvNew); + /* Now That We Relocated The Binary We Can Unmap And Free Header Info */ + kfree(binaryHeader); + kfree(programHeader); + + return; +} + +/*! + * \brief New exec... + * + */ +void sys_exec(char *file, char *ap) { + int error = 0x0; + int i = 0x0; + int x = 0x0; + int argc = 0x0; + uint32_t *tmp = 0x0; + uint32_t seg_size = 0x0; + uint32_t seg_addr = 0x0; + uint32_t addr = 0x0; + uint32_t eip = 0x0; + uint32_t proghdr = 0x0; + char *args = 0x0; + char *interp = 0x0; + char **argv = 0x0; + char **argvNew = 0x0; + elfHeader *binaryHeader = 0x0; + elfProgramHeader *programHeader = 0x0; + struct i386_frame *iFrame = 0x0; + //Elf_Auxargs *auxargs = 0x0; + + _current->files[0] = fopen(file, "r"); + if (_current->files[0] == 0x0) + return; //We Need To Set errno + + /* Load the ELF header */ + if ((binaryHeader = (elfHeader *) kmalloc(sizeof(elfHeader))) == 0x0) + K_PANIC("malloc failed!"); + fread(binaryHeader, sizeof(elfHeader), 1, _current->files[0]); + + /* Check If App Is A Real Application */ + if (((binaryHeader->eIdent[1] != 'E') && (binaryHeader->eIdent[2] != 'L') && (binaryHeader->eIdent[3] != 'F')) || (binaryHeader->eType != ET_EXEC)) { + kfree(binaryHeader); + fclose(_current->files[0]); + return; //We Need To Set errno + } + + /* Load The Program Header(s) */ + if ((programHeader = (elfProgramHeader *) kmalloc(sizeof(elfProgramHeader) * binaryHeader->ePhnum)) == 0x0) + K_PANIC("malloc failed!"); + fseek(_current->files[0], binaryHeader->ePhoff, 0); + fread(programHeader, (sizeof(elfProgramHeader) * binaryHeader->ePhnum), 1, _current->files[0]); + + /* Loop Through The Header And Load Sections Which Need To Be Loaded */ + for (i = 0x0; i < binaryHeader->ePhnum; i++) { + switch (programHeader[i].phType) { + case PT_LOAD: + seg_addr = trunc_page(programHeader[i].phVaddr); + seg_size = round_page(programHeader[i].phMemsz + programHeader[i].phVaddr - seg_addr); + + /* + Allocate Memory Im Going To Have To Make This Load Memory With Correct + Settings so it helps us in the future + */ + for (x = 0x0; x < (programHeader[i].phMemsz); x += 0x1000) { + /* Make readonly and read/write !!! */ + if (vmm_remapPage(vmm_findFreePage(_current->id), ((programHeader[i].phVaddr & 0xFFFFF000) + x), PAGE_DEFAULT) == 0x0) + K_PANIC("Error: Remap Page Failed"); + memset((void *) ((programHeader[i].phVaddr & 0xFFFFF000) + x), 0x0, 0x1000); + } + + /* Now Load Section To Memory */ + fseek(_current->files[0], programHeader[i].phOffset, 0); + fread((void *) programHeader[i].phVaddr, programHeader[i].phFilesz, 1, _current->files[0]); + if ((programHeader[i].phFlags & 0x2) != 0x2) { + for (x = 0x0; x < (programHeader[i].phMemsz); x += 0x1000) { + if ((vmm_setPageAttributes((programHeader[i].phVaddr & 0xFFFFF000) + x, PAGE_PRESENT | PAGE_USER)) != 0x0) + K_PANIC("vmm_setPageAttributes failed"); + } + } + if (binaryHeader->eEntry >= programHeader[i].phVaddr && binaryHeader->eEntry < (programHeader[i].phVaddr + programHeader[i].phMemsz)) { + /* We're suposed to do something here? */ + } + else { + _current->td.vm_dsize = seg_size >> PAGE_SHIFT; + _current->td.vm_daddr = (char *) seg_addr; + } + + _current->oInfo.vmStart = ((programHeader[i].phVaddr & 0xFFFFF000) + 0xA900000); + break; + case PT_INTERP: + interp = (char *) kmalloc(programHeader[i].phFilesz); + if (interp == 0x0) + K_PANIC("malloc failed") + ; + + fseek(_current->files[0], programHeader[i].phOffset, 0); + fread((void *) interp, programHeader[i].phFilesz, 1, _current->files[0]); + kprintf("Interp: [%s]\n", interp); + //ldAddr = ldEnable(); + break; + case PT_PHDR: + proghdr = programHeader[i].phVaddr; + break; + default: + break; + } + } + + addr = LD_START; + + if (interp != 0x0) { + //kprintf("TEST"); + elf_loadfile(_current, interp, &addr, &eip); + } + //kprintf("[0x%X][0x%X]\n",eip,addr); + + _current->td.vm_dsize = seg_size >> PAGE_SHIFT; + _current->td.vm_daddr = (char *) seg_addr; + + //! copy in arg strings + argv = ap; + + if (argv[1] != 0x0) { + argc = argv[0]; + args = (char *) vmmGetFreeVirtualPage(_current->id, 1, VM_TASK); + memset(args, 0x0, 0x1000); + x = 0x0; + argvNew = (char **) kmalloc(sizeof(char *) * argc); + for (i = 0x0; i < argc; i++) { + strcpy(args + x, argv[i + 1]); + argvNew[i] = args + x; + x += strlen(argv[i + 1]) + 1; + } + argv = argvNew; + } + + //! Clean the virtual of COW pages left over from the fork + vmm_cleanVirtualSpace(_current->td.vm_daddr + (_current->td.vm_dsize << PAGE_SIZE)); + + //! Adjust iframe + iFrame = _current->tss.esp0 - sizeof(struct i386_frame); + iFrame->ebp = STACK_ADDR; + iFrame->eip = eip; + + //if (_current->id > 3) { + + iFrame->user_esp = ((uint32_t) STACK_ADDR) - (sizeof(uint32_t) * (argc + 4)); // + (sizeof(Elf_Auxargs) * 2))); + kprintf("\n\n\nuser_esp: [0x%X]\n", iFrame->user_esp); + tmp = iFrame->user_esp; + + //! build argc and argv[] + tmp[0] = argc; + for (i = 0; i < argc; i++) { + tmp[i + 1] = argv[i]; + } + //! Build ENV + args = (char *) vmmGetFreeVirtualPage(_current->id, 1, VM_TASK); + memset(args, 0x0, 0x1000); + strcpy(args, "LIBRARY_PATH=/lib"); + tmp[argc + 2] = args; + kprintf("env: [0x%X][0x%X]\n", (uInt32) tmp + argc + 2, tmp[argc + 2]); + tmp[argc + 3] = 0x0; + kprintf("env: [0x%X][0x%X]\n", (uInt32) tmp + argc + 2, tmp[argc + 2]); + //auxargs = iFrame->user_esp + argc + 3; + tmp = iFrame->user_esp; + tmp += argc + 4; + + /* + auxargs->execfd = -1; + auxargs->phdr = proghdr; + auxargs->phent = binaryHeader->ePhentsize; + auxargs->phnum = binaryHeader->ePhnum; + auxargs->pagesz = PAGE_SIZE; + auxargs->base = addr; + auxargs->flags = 0x0; + auxargs->entry = binaryHeader->eEntry; + auxargs->trace = 0x0; + + AUXARGS_ENTRY(tmp, AT_PHDR, auxargs->phdr); + AUXARGS_ENTRY(tmp, AT_PHENT, auxargs->phent); + AUXARGS_ENTRY(tmp, AT_PHNUM, auxargs->phnum); + AUXARGS_ENTRY(tmp, AT_PAGESZ, auxargs->pagesz); + AUXARGS_ENTRY(tmp, AT_FLAGS, auxargs->flags); + AUXARGS_ENTRY(tmp, AT_ENTRY, auxargs->entry); + AUXARGS_ENTRY(tmp, AT_BASE, auxargs->base); + AUXARGS_ENTRY(tmp, AT_NULL, 0); + + kprintf("AT_BASE: [0x%X]\n",auxargs->base); + */ + + //iFrame->ebx = 0x0; + //iFrame->ebx = 0x0; + //iFrame->eip = binaryHeader->eEntry; + //kprintf("\n\nDOH: [0x%X]\n\n",iFrame->eip); +//while (1); + //while (1); + /* + error = elf_loadfile(_current,file,0x0,0x0); + if (error) + K_PANIC("elf_loadfile failed"); + */ + return; +} + +/*** + END + ***/ diff --git a/sys/arch/armv6/fork.c b/sys/arch/armv6/fork.c new file mode 100644 index 0000000..20fcde6 --- /dev/null +++ b/sys/arch/armv6/fork.c @@ -0,0 +1,128 @@ +/*- + * Copyright (c) 2002-2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +/***************************************************************************************** + Functoin: static int fork_copyProcess(struct taskStruct *newProcess,long ebp,long edi, + long esi, long none,long ebx,long ecx,long edx,long eip,long cs,long eflags, + long esp,long ss) + + Desc: This function will copy a process + + Notes: + + *****************************************************************************************/ +/* Had to remove static though tihs function is only used in this file */ +int fork_copyProcess(struct taskStruct *newProcess, long ebp, long edi, long esi, long none, long ebx, long ecx, long edx, long eip, long cs, long eflags, long esp, long ss) { + volatile struct taskStruct * tmpProcPtr = newProcess; + assert(newProcess); + assert(_current); + + /* Set Up New Tasks Information */ + memcpy(newProcess->oInfo.cwd, _current->oInfo.cwd, 1024); + + newProcess->tss.eip = eip; + newProcess->oInfo.vmStart = _current->oInfo.vmStart; + newProcess->term = _current->term; + newProcess->term->owner = newProcess->id; + newProcess->uid = _current->uid; + newProcess->gid = _current->gid; + newProcess->tss.back_link = 0x0; + newProcess->tss.esp0 = _current->tss.esp0; + newProcess->tss.ss0 = 0x10; + newProcess->tss.esp1 = 0x0; + newProcess->tss.ss1 = 0x0; + newProcess->tss.esp2 = 0x0; + newProcess->tss.ss2 = 0x0; + newProcess->tss.eflags = eflags; + newProcess->tss.eax = 0x0; + newProcess->tss.ebx = ebx; + newProcess->tss.ecx = ecx; + newProcess->tss.edx = edx; + newProcess->tss.esi = esi; + newProcess->tss.edi = edi; + newProcess->tss.ebp = ebp; + newProcess->tss.esp = esp; + newProcess->tss.cs = cs & 0xFF; + newProcess->tss.ss = ss & 0xFF; + newProcess->tss.ds = _current->tss.ds & 0xFF; + newProcess->tss.fs = _current->tss.fs & 0xFF; + newProcess->tss.gs = _current->tss.gs & 0xFF; + newProcess->tss.es = _current->tss.es & 0xFF; + newProcess->tss.ldt = 0x18; + newProcess->tss.trace_bitmap = 0x0000; + newProcess->tss.io_map = 0x8000; + /* Create A Copy Of The VM Space For New Task */ + newProcess->tss.cr3 = (uInt32) vmmCopyVirtualSpace(newProcess->id); + newProcess->state = FORK; + + /* Fix gcc optimization problems */ + while (tmpProcPtr->state == FORK) + sched_yield(); + + /* Return Id of Proccess */ + return (newProcess->id); +} + +/***************************************************************************************** + Functoin: void sysFork(); + + Desc: This function will fork a new task + + Notes: + + 08/01/02 - This Seems To Be Working Fine However I'm Not Sure If I + Chose The Best Path To Impliment It I Guess We Will See + What The Future May Bring + + *****************************************************************************************/ +asm( + ".globl sysFork \n" + "sysFork: \n" + " xor %eax,%eax \n" + " call schedNewTask \n" + " testl %eax,%eax \n" + " je fork_ret \n" + " pushl %esi \n" + " pushl %edi \n" + " pushl %ebp \n" + " pushl %eax \n" + " call fork_copyProcess \n" + " movl %eax,(%ebx) \n" + " addl $16,%esp \n" + "fork_ret: \n" + " ret \n" +); diff --git a/sys/arch/armv6/kpanic.c b/sys/arch/armv6/kpanic.c new file mode 100644 index 0000000..e4b43c7 --- /dev/null +++ b/sys/arch/armv6/kpanic.c @@ -0,0 +1,66 @@ +/*- + * Copyright (c) 2002-2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include + +/*! + * \brief print panic message and halt system + * + * \param fmt panic message + * + */ +void kpanic(const char *fmt, ...) { + char buf[512]; + va_list args; + + vaStart(args, fmt); + vsprintf(buf, fmt, args); + vaEnd(args); + + /* It's important that we print on the current terminal so let's reset foreground */ + tty_foreground = NULL; + kprintf("kPanic: %s", buf); + + /* Halt The System */ + //asm("cli"); + irqDisable(0x0); + + while (1) { + asm("hlt"); + } + +} + +/*** + END + ***/ + diff --git a/sys/arch/armv6/sched.c b/sys/arch/armv6/sched.c new file mode 100644 index 0000000..5f6ffc6 --- /dev/null +++ b/sys/arch/armv6/sched.c @@ -0,0 +1,279 @@ +/*- + * Copyright (c) 2002-2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +static kTask_t *taskList = 0x0; +static kTask_t *delList = 0x0; +static uInt32 nextID = -1; + +kTask_t *_current = 0x0; +kTask_t *_usedMath = 0x0; + +static struct spinLock schedulerSpinLock = SPIN_LOCK_INITIALIZER; + +/************************************************************************ + + Function: int sched_init() + + Description: This function is used to enable the kernel scheduler + + Notes: + + 02/20/2004 - Approved for quality + + ************************************************************************/ + +int sched_init() { + taskList = (kTask_t *) kmalloc(sizeof(kTask_t)); + if (taskList == 0x0) + kpanic("Unable to create task list"); + + taskList->id = nextID++; + + /* Print out information on scheduler */ + kprintf("sched0 - Address: [0x%X]\n", taskList); + + /* Return so we know everything went well */ + return (0x0); +} + +void sched() { + uInt32 memAddr = 0x0; + kTask_t *tmpTask = 0x0; + kTask_t *delTask = 0x0; + + if (!spinTryLock(&schedulerSpinLock)) + return; + + tmpTask = _current->next; + //outportByte(0xE9,_current->id + '0'); + schedStart: + + /* Yield the next task from the current prio queue */ + for (; tmpTask != 0x0; tmpTask = tmpTask->next) { + if (tmpTask->state > 0x0) { + _current = tmpTask; + if (_current->state == FORK) + _current->state = READY; + break; + } + else if (tmpTask->state == DEAD) { + delTask = tmpTask; + tmpTask = tmpTask->next; + sched_deleteTask(delTask->id); + sched_addDelTask(delTask); + goto schedStart; + } + } + + /* Finished all the tasks, restarting the list */ + if (0x0 == tmpTask) { + tmpTask = taskList; + goto schedStart; + } + + if (_current->state > 0x0) { + if (_current->oInfo.v86Task == 0x1) + irqDisable(0x0); + asm("cli"); + memAddr = (uInt32) &(_current->tss); + ubixGDT[4].descriptor.baseLow = (memAddr & 0xFFFF); + ubixGDT[4].descriptor.baseMed = ((memAddr >> 16) & 0xFF); + ubixGDT[4].descriptor.baseHigh = (memAddr >> 24); + ubixGDT[4].descriptor.access = '\x89'; + spinUnlock(&schedulerSpinLock); + asm("sti"); + asm("ljmp $0x20,$0\n"); + } + else { + spinUnlock(&schedulerSpinLock); + } + + return; +} + +kTask_t *schedNewTask() { + int i = 0; + kTask_t *tmpTask = (kTask_t *) kmalloc(sizeof(kTask_t)); + struct file *fp = 0x0; + if (tmpTask == 0x0) + kpanic("Error: schedNewTask() - kmalloc failed trying to initialize a new task struct\n"); + + memset(tmpTask, 0x0, sizeof(kTask_t)); + /* Filling in tasks attrs */ + tmpTask->usedMath = 0x0; + tmpTask->state = NEW; + + /* HACK */ + for (i = 0; i < 3; i++) { + fp = (void *) kmalloc(sizeof(struct file)); + tmpTask->td.o_files[i] = (uint32_t) fp; + fp->f_flag = 0x4; + } + + spinLock(&schedulerSpinLock); + tmpTask->id = nextID++; + tmpTask->next = taskList; + tmpTask->prev = 0x0; + taskList->prev = tmpTask; + taskList = tmpTask; + + spinUnlock(&schedulerSpinLock); + + return (tmpTask); +} + +int sched_deleteTask(pidType id) { + kTask_t *tmpTask = 0x0; + + /* Checking each task from the prio queue */ + for (tmpTask = taskList; tmpTask != 0x0; tmpTask = tmpTask->next) { + if (tmpTask->id == id) { + if (tmpTask->prev != 0x0) + tmpTask->prev->next = tmpTask->next; + if (tmpTask->next != 0x0) + tmpTask->next->prev = tmpTask->prev; + if (taskList == tmpTask) + taskList = tmpTask->next; + + return (0x0); + } + } + return (0x1); +} + +int sched_addDelTask(kTask_t *tmpTask) { + tmpTask->next = delList; + tmpTask->prev = 0x0; + if (delList != 0x0) + delList->prev = tmpTask; + delList = tmpTask; + return (0x0); +} + +kTask_t *sched_getDelTask() { + kTask_t *tmpTask = 0x0; + + if (delList == 0x0) + return (0x0); + + tmpTask = delList; + delList = delList->next; + return (tmpTask); +} + +kTask_t * +schedFindTask(uInt32 id) { + kTask_t *tmpTask = 0x0; + + for (tmpTask = taskList; tmpTask; tmpTask = tmpTask->next) { + if (tmpTask->id == id) + return (tmpTask); + } + + return (0x0); +} + +/************************************************************************ + + Function: void schedEndTask() + + Description: This function will end a task + + Notes: + + 02/20/2004 - Approved for quality + + ************************************************************************/ +void schedEndTask(pidType pid) { + endTask(_current->id); + sched_yield(); +} + +/************************************************************************ + + Function: int schedEndTask() + + Description: This function will yield a task + + Notes: + + 02/20/2004 - Approved for quality + + ************************************************************************/ + +void sched_yield() { + sched(); +} + +/* + asm( + ".globl sched_yield \n" + "sched_yield: \n" + " cli \n" + " call sched \n" + ); + */ + +/************************************************************************ + + Function: int sched_setStatus(pidType pid,tState state) + + Description: Change the tasks status + + Notes: + + ************************************************************************/ +int sched_setStatus(pidType pid, tState state) { + kTask_t *tmpTask = schedFindTask(pid); + if (tmpTask == 0x0) + return (0x1); + tmpTask->state = state; + return (0x0); +} + +/*** + END + ***/ + diff --git a/sys/arch/armv6/schedyield.S b/sys/arch/armv6/schedyield.S new file mode 100644 index 0000000..1072793 --- /dev/null +++ b/sys/arch/armv6/schedyield.S @@ -0,0 +1,51 @@ +/*- + * Copyright (c) 2002-2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +.globl sched_yield_new +.text +.code32 +sched_yield_new: + pusha /* Save all of the registers */ + push %ss + push %ds + push %es + push %fs + push %gs + call sched + mov %eax,%esp + pop %gs + pop %fs + pop %es + pop %ds + pop %ss + popa /* Restore Registers */ + iret + +/*** + END + ***/ diff --git a/sys/arch/armv6/spinlock.c b/sys/arch/armv6/spinlock.c new file mode 100644 index 0000000..790d1fb --- /dev/null +++ b/sys/arch/armv6/spinlock.c @@ -0,0 +1,77 @@ +/*- + * Copyright (c) 2002-2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +void spinLockInit(spinLock_t *lock) { + *lock = SPIN_LOCK_INITIALIZER; + } + +void spinUnlock(spinLock_t *lock) { + *lock = 0x0; + /* + register int unlocked; + asm volatile( + "xchgl %0, %1" + : "=&r" (unlocked), "=m" (*lock) : "0" (0) + ); + */ + } + +int spinTryLock(spinLock_t *lock) { + register int locked; + asm volatile("xchgl %0, %1" + : "=&r" (locked), "=m" (*lock) : "0" (1) + ); + return(!locked); + } + +void spinLock(spinLock_t *lock) { + while (!spinTryLock(lock)) + { + while (*lock == 1) + sched_yield(); + } +} + +void spinLock_scheduler(spinLock_t *lock) { + while (!spinTryLock(lock)) + while (*lock == 1); + } + + +int spinLockLocked(spinLock_t *lock) { + return(*lock != 0); + } + + +/*** + END + ***/ + diff --git a/sys/arch/armv6/sys_call.S b/sys/arch/armv6/sys_call.S new file mode 100644 index 0000000..b4a557e --- /dev/null +++ b/sys/arch/armv6/sys_call.S @@ -0,0 +1,54 @@ +/*- + * Copyright (c) 2002-2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +.globl _sysCall +.text +.code32 +_sysCall: + cmpl totalCalls,%eax + jae invalidSysCall + + cld + pushl %edx + pushl %ecx + pushl %ebx + call *systemCalls(,%eax,4) + popl %ebx + popl %ecx + popl %edx /* Restore Registers */ + + iret + +invalidSysCall: + movl $-1,%eax + iret + +/*** + END + ***/ + diff --git a/sys/arch/armv6/sys_call_new.S b/sys/arch/armv6/sys_call_new.S new file mode 100644 index 0000000..2f73600 --- /dev/null +++ b/sys/arch/armv6/sys_call_new.S @@ -0,0 +1,67 @@ +/*- + * Copyright (c) 2002-2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#define FAKE_MCOUNT(caller) pushl caller ; call __mcount ; popl %ecx + +.globl _sysCall_new +.text +.code32 +_sysCall_new: + pushl $2 /* sizeof "int 0x80" */ + subl $4,%esp /* skip over tf_trapno */ + pushal + pushl %ds + pushl %es + pushl %fs + /* switch to kernel segments */ + movl $0x10,%eax + movl %eax,%ds + movl %eax,%es + movl %eax,%fs + //FAKE_MCOUNT(TF_EIP(%esp)) + call syscall + //MEXITCOUNT + //jmp doreti + popl %fs + popl %es + popl %ds + popal + addl $8,%esp + iret + +invalidSysCall: + push %eax + call invalidCall + pop %eax + movl $-1,%eax + iret + +/*** + END + ***/ + diff --git a/sys/arch/armv6/syscall.c b/sys/arch/armv6/syscall.c new file mode 100644 index 0000000..36a81d8 --- /dev/null +++ b/sys/arch/armv6/syscall.c @@ -0,0 +1,247 @@ +/*- + * Copyright (c) 2002-2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +/* #include */ +#include +#include + +//long fuword(const void *base); + +//void sdeTestThread(); + +asm( + ".globl _sysCallNew \n" + "_sysCallNew: \n" + " pusha \n" + " push %ss \n" + " push %ds \n" + " push %es \n" + " push %fs \n" + " push %gs \n" + " cmpl totalCalls,%eax \n" + " jae invalidSysCallNew \n" + " mov %esp,%ebx \n" + " add $12,%ebx \n" + " push (%ebx) \n" + " call *systemCalls(,%eax,4) \n" + " add $4,%esp \n" + " jmp doneNew \n" + "invalidSysCallNew: \n" + " call InvalidSystemCall \n" + "doneNew: \n" + " pop %gs \n" + " pop %fs \n" + " pop %es \n" + " pop %ds \n" + " pop %ss \n" + " popa \n" + " iret \n" +); + +void InvalidSystemCall() { + kprintf("attempt was made to an invalid system call\n"); + return; +} + +typedef struct _UbixUser UbixUser; +struct _UbixUser { + char *username; + char *password; + int uid; + int gid; + char *home; + char *shell; +}; + +void sysAuth(UbixUser *uu) { + kprintf("authenticating user %s\n", uu->username); + + /* MrOlsen 2016-01-01 uh? + if(uu->username == "root" && uu->password == "user") + { + uu->uid = 0; + uu->gid = 0; + } + */ + uu->uid = -1; + uu->gid = -1; + return; +} + +void sysPasswd(char *passwd) { + kprintf("changing user password for user %d\n", _current->uid); + return; +} + +void sysAddModule() { + return; +} + +void sysRmModule() { + return; +} + +void sysGetpid(int *pid) { + if (pid) + *pid = _current->id; + return; +} + +void sysGetUid(int *uid) { + if (uid) + *uid = _current->uid; + return; +} + +void sysGetGid(int *gid) { + if (gid) + *gid = _current->gid; + return; +} + +void sysSetUid(int uid, int *status) { + if (_current->uid == 0x0) { + _current->uid = uid; + if (status) + *status = 0x0; + } + else { + if (status) + *status = 1; + } + return; +} + +void sysSetGid(int gid, int *status) { + if (_current->gid == 0x0) { + _current->gid = gid; + if (status) + *status = 0x0; + } + else { + if (status) + *status = 1; + } + return; +} + +void sysExit(int status) { + endTask(_current->id); +} + +void sysCheckPid(int pid, int *ptr) { + kTask_t *tmpTask = schedFindTask(pid); + if ((tmpTask != 0x0) && (ptr != 0x0)) + *ptr = tmpTask->state; + else + *ptr = 0x0; + return; +} + +/************************************************************************ + + Function: void sysGetFreePage(); + Description: Allocs A Page To The Users VM Space + Notes: + + ************************************************************************/ +void sysGetFreePage(long *ptr, int count, int type) { + if (ptr) { + if (type == 2) + *ptr = (long) vmmGetFreeVirtualPage(_current->id, count, VM_THRD); + else + *ptr = (long) vmmGetFreeVirtualPage(_current->id, count, VM_TASK); + } + return; +} + +void sysGetDrives(uInt32 *ptr) { + if (ptr) + *ptr = 0x0; //(uInt32)devices; + return; +} + +void sysGetUptime(uInt32 *ptr) { + if (ptr) + *ptr = systemVitals->sysTicks; + return; +} + +void sysGetTime(uInt32 *ptr) { + if (ptr) + *ptr = systemVitals->sysUptime + systemVitals->timeStart; + return; +} + +void sysGetCwd(char *data, int len) { + if (data) + sprintf(data, "%s", _current->oInfo.cwd); + return; +} + +void sysSchedYield() { + sched_yield(); +} + +void sysStartSDE() { + int i = 0x0; + for (i = 0; i < 1400; i++) { + asm("hlt"); + } + //execThread(sdeThread,(uInt32)(kmalloc(0x2000)+0x2000),0x0); + for (i = 0; i < 1400; i++) { + asm("hlt"); + } + return; +} + +void invalidCall(int sys_call) { + kprintf("Invalid System Call #[%i]\n", sys_call); + return; +} + +/*** + END + ***/ + diff --git a/sys/arch/armv6/systemtask.c b/sys/arch/armv6/systemtask.c new file mode 100644 index 0000000..c0a999e --- /dev/null +++ b/sys/arch/armv6/systemtask.c @@ -0,0 +1,122 @@ +/*- + * Copyright (c) 2002-2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static unsigned char *videoBuffer = (char *)0xB8000; + + +void systemTask() { + mpi_message_t myMsg; + uInt32 counter = 0x0; + int i = 0x0; + int *x = 0x0; + kTask_t *tmpTask = 0x0; + + if (mpi_createMbox("system") != 0x0) { + kpanic("Error: Error creating mailbox: system\n"); + } + + while(1) { + if (mpi_fetchMessage("system",&myMsg) == 0x0) { + kprintf("A"); + switch(myMsg.header) { + case 0x69: + x = (int *)&myMsg.data; + kprintf("Switching to term: [%i][%i]\n",*x,myMsg.pid); + schedFindTask(myMsg.pid)->term = tty_find(*x); + break; + case 1000: + kprintf("Restarting the system in 5 seconds\n"); + counter = systemVitals->sysUptime + 5; + while (systemVitals->sysUptime < counter) { + sched_yield(); + } + kprintf("Rebooting NOW!!!\n"); + while(inportByte(0x64) & 0x02); + outportByte(0x64, 0xFE); + break; + case 31337: + kprintf("system: backdoor opened\n"); + break; + case 0x80: + if (!strcmp(myMsg.data,"sdeStart")) { + kprintf("Starting SDE\n"); + //execThread(sdeThread,(uInt32)(kmalloc(0x2000)+0x2000),0x0); + } + else if (!strcmp(myMsg.data,"freePage")) { + kprintf("kkk Free Pages"); + } + else if (!strcmp(myMsg.data,"sdeStop")) { + printOff = 0x0; + biosCall(0x10,0x3,0x0,0x0,0x0,0x0,0x0,0x0,0x0); + for (i=0x0;i<100;i++) asm("hlt"); + } + break; + default: + kprintf("system: Received message %i:%s\n",myMsg.header,myMsg.data); + break; + } + } + + /* + Here we get the next task from the delete task queue + we first check to see if it has an fd attached for the binary and after that + we free the pages for the process and then free the task + */ + tmpTask = sched_getDelTask(); + if (tmpTask != 0x0) { + if (tmpTask->files[0] != 0x0) + fclose(tmpTask->files[0]); + vmmFreeProcessPages(tmpTask->id); + kfree(tmpTask); + } + videoBuffer[0] = systemVitals->sysTicks; + sched_yield(); + } + + return; + } + +/*** + END + ***/ + diff --git a/sys/arch/armv6/timer.S b/sys/arch/armv6/timer.S new file mode 100644 index 0000000..c7aa642 --- /dev/null +++ b/sys/arch/armv6/timer.S @@ -0,0 +1,61 @@ +/*- + * Copyright (c) 2002-2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +.globl timerInt +.text +.code32 +timerInt: + pusha /* Save all of the registers */ + mov $0x20,%dx /* The Following Sends Our EOI To The MPIC */ + mov $0x20,%ax + outb %al,%dx + movl systemVitals,%ecx /* Put Location Of System Vitals Into ECX */ + incl 4(%ecx) /* Increment sysTicks our 1000ms counter */ + movl 4(%ecx),%eax /* Increment our sysUptime by 1S if 1000MS */ + movl $200,%ebx /* Have Passed */ + xor %edx,%edx + div %ebx + test %edx,%edx + jnz next + incl 8(%ecx) +next: + movl 4(%ecx),%eax /* Test If quantum Has Passed If So Then */ + movl 12(%ecx),%ebx /* We Can CALL sched */ + xor %edx,%edx + div %ebx + test %edx,%edx + jnz done + call sched +done: + popa /* Restore Registers */ + iret + +/*** + END + ***/ + diff --git a/sys/arch/i386/Makefile b/sys/arch/i386/Makefile new file mode 100644 index 0000000..97a86c3 --- /dev/null +++ b/sys/arch/i386/Makefile @@ -0,0 +1,28 @@ +# (C) 2002 The UbixOS Project +# $Id: Makefile 202 2016-01-23 15:21:35Z reddawg $ + +# Include Global 'Source' Options +include ../../../Makefile.incl +include ../../Makefile.incl + +# Objects +OBJS = support.o strcpy.o strcmp.o strncmp.o memset.o memcmp.o schedyield.o kpanic.o timer.o spinlock.o i386_exec.o sys_call_posix.o sys_call.o bioscall.o fork.o systemtask.o sched.o cpu.o trap.o bios16code.o +# ap-boot.o smp.o vitals.o(obsolete) + +all: $(OBJS) + +# Compile Types +.cc.o: + $(CXX) -DNOBOOL $(CFLAGS) $(INCLUDES) -c -o $@ $< +.cc.s: + $(CXX) -DNOBOOL $(CFLAGS) $(INCLUDES) -S -o $@ $< +.c.o: + $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $< +.c.s: + $(CC) $(CFLAGS) $(INCLUDES) -S -o $@ $< +.S.o: + $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) diff --git a/sys/arch/i386/ap-boot.S b/sys/arch/i386/ap-boot.S new file mode 100644 index 0000000..c08bd1e --- /dev/null +++ b/sys/arch/i386/ap-boot.S @@ -0,0 +1,133 @@ +/*- + * Copyright (c) 2002-2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Okay, this file contains the code that's going to bootstrap the AP cpus + */ + + + .globl ap_trampoline_start,ap_trampoline_end + .text + .code16 +ap_trampoline_start: + cli + cld + + movw %cs,%ax // The CPU knows its CS already, so lets use it for the other segments + movw %ax,%ds + movw %ax,%es + movw %ax,%ss + + // Do some bochs-specific bullshit + mov $0x31,%al // '1' + mov $0xe9,%dx + outb %al,%dx + //lgdt ap_gdt; + lgdt ap_trampoline_gdt_limit - ap_trampoline_start + movl %cr0,%eax + orl $0x1,%eax + movl %eax,%cr0 // PMODE! + +.code32 + .byte 0x66 + ljmp $0x08,$(ap_trampoline_32 - ap_trampoline_start) // 0x08 == KERNEL_CS + +ap_trampoline_32: + mov $0x32,%al // '2' + mov $0xe9,%dx + outb %al,%dx + + mov $0x10,%ax + mov %ax,%ds + mov %ax,%es + mov %ax,%fs + mov %ax,%gs + mov %ax,%ss + + // Spinlock + mov ap_trampoline_spl - ap_trampoline_start,%edi +ap_spl: + //cmp $1,(%edi) + //je ap_spl + + mov $1,%eax // Value to be set + xchgl (%edi),%eax + cmp $0,%eax + je ap_spl + // /Spinlock + + mov $0x30,%al // '0' + mov $0xe9,%dx + outb %al,%dx + + mov ap_trampoline_stackptr - ap_trampoline_start,%ebx + mov %ebx,%esp + add $0x1000,%ebx + mov %ebx,ap_trampoline_stackptr - ap_trampoline_start + + mov $0x31,%al // '1' + mov $0xe9,%dx + outb %al,%dx + + // spinunlock + mov $0,%eax + mov ap_trampoline_spl - ap_trampoline_start,%edi + xchgl (%edi),%eax + // /spinunlock + + mov $0x33,%al // '3' + mov $0xe9,%dx + outb %al,%dx + + mov ap_trampoline_epoint,%eax + call *%eax +1: + hlt + jmp 1b // Halt if we ever get here somehow + + // Stack.. This sucks, since CPU initialization isn't serialized +ap_trampoline_stackptr: + .long 0x10000 // 256KB +ap_trampoline_epoint: + .long c_ap_boot + +ap_trampoline_spl: + .long 0 +ap_gdt: + .long ubixGDT + + // GDT +ap_trampoline_gdt: + .word 0 +ap_trampoline_gdt_limit: + .word 128 // Room for 32 descriptors +ap_trampoline_gdt_base: + .long 0x20000 // 128KB (move this later) + + +ap_trampoline_end: diff --git a/sys/arch/i386/bios16code.S b/sys/arch/i386/bios16code.S new file mode 100644 index 0000000..b86ee01 --- /dev/null +++ b/sys/arch/i386/bios16code.S @@ -0,0 +1,5 @@ +.globl bios16Code +bios16Code: +.code16 +int $0x10 +int $0x69 diff --git a/sys/arch/i386/bioscall.c b/sys/arch/i386/bioscall.c new file mode 100644 index 0000000..e3d3094 --- /dev/null +++ b/sys/arch/i386/bioscall.c @@ -0,0 +1,90 @@ +/*- + * Copyright (c) 2002-2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +void biosCall(int biosInt, int eax, int ebx, int ecx, int edx, int esi, int edi, int es, int ds) { + short segment = 0x0, offset = 0x0; + uint32_t tmpAddr = (uint32_t) &bios16Code; + kTask_t *newProcess = 0x0; + + offset = tmpAddr & 0xF; // lower 4 bits + segment = tmpAddr >> 4; + + newProcess = schedNewTask(); + assert(newProcess); + + newProcess->tss.back_link = 0x0; + newProcess->tss.esp0 = (uint32_t) vmm_getFreeKernelPage(newProcess->id, 2) + (0x2000 - 0x4); // XXX I had 0xDEADBEEF I'm not sure why + newProcess->tss.ss0 = 0x10; + newProcess->tss.esp1 = 0x0; + newProcess->tss.ss1 = 0x0; + newProcess->tss.esp2 = 0x0; + newProcess->tss.ss2 = 0x0; + newProcess->tss.cr3 = kernelPageDirectory; //vmm_createVirtualSpace(newProcess->id); //(uint32_t)_current->tss.cr3; + newProcess->tss.eip = offset & 0xFFFF; + newProcess->tss.eflags = 2 | EFLAG_IF | EFLAG_VM; + newProcess->tss.eax = eax & 0xFFFF; + newProcess->tss.ebx = ebx & 0xFFFF; + newProcess->tss.ecx = ecx & 0xFFFF; + newProcess->tss.edx = edx & 0xFFFF; + newProcess->tss.esp = 0x1000 & 0xFFFF; + newProcess->tss.ebp = 0x1000 & 0xFFFF; + newProcess->tss.esi = esi & 0xFFFF; + newProcess->tss.edi = edi & 0xFFFF; + newProcess->tss.es = es & 0xFFFF; + newProcess->tss.cs = segment & 0xFFFF; + newProcess->tss.ss = 0x1000 & 0xFFFF; + newProcess->tss.ds = ds & 0xFFFF; + newProcess->tss.fs = 0x0 & 0xFFFF; + newProcess->tss.gs = 0x0 & 0xFFFF; + newProcess->tss.ldt = 0x0 & 0xFFFF; + newProcess->tss.trace_bitmap = 0x0 & 0xFFFF; + newProcess->tss.io_map = 0x0 & 0xFFFF; + newProcess->tss.io_map = sizeof(struct tssStruct) - 8192; + newProcess->oInfo.v86Task = 0x1; + + kprintf("EIP: [0x%X] 0x%X:0x%X", tmpAddr, newProcess->tss.eip, newProcess->tss.cs); + + newProcess->state = READY; + while (newProcess->state > 0) + sched_yield(); + + kprintf("EIP: [0x%X] 0x%X:0x%X!", tmpAddr, newProcess->tss.eip, newProcess->tss.cs); + kprintf("CALL DONE: %i 0x%X 0x%X!", newProcess->state, newProcess->tss.esp, newProcess->tss.ss); + + return; +} diff --git a/sys/arch/i386/cpu.c b/sys/arch/i386/cpu.c new file mode 100644 index 0000000..ef9e0c0 --- /dev/null +++ b/sys/arch/i386/cpu.c @@ -0,0 +1,29 @@ +/*- + * Copyright (c) 2002-2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include diff --git a/sys/arch/i386/fork.c b/sys/arch/i386/fork.c new file mode 100644 index 0000000..3e222f8 --- /dev/null +++ b/sys/arch/i386/fork.c @@ -0,0 +1,228 @@ +/*- + * Copyright (c) 2002-2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int sys_fork(struct thread *td, struct sys_fork_args *args) { + struct taskStruct *newProcess; + + newProcess = schedNewTask(); + + /* + * + * Initalize New Task Information From Parrent + * + */ + + /* Set CWD */ + memcpy(newProcess->oInfo.cwd, _current->oInfo.cwd, 1024); + + /* Set PPID */ + newProcess->ppid = _current->id; + + /* Set PGRP */ + newProcess->pgrp = _current->pgrp; + + /* Set Up Task State */ + newProcess->tss.eip = td->frame->tf_eip; + newProcess->oInfo.vmStart = _current->oInfo.vmStart; + newProcess->term = _current->term; + newProcess->term->owner = newProcess->id; + newProcess->uid = _current->uid; + newProcess->gid = _current->gid; + newProcess->tss.back_link = 0x0; + newProcess->tss.esp0 = _current->tss.esp0; + newProcess->tss.ss0 = 0x10; + newProcess->tss.esp1 = 0x0; + newProcess->tss.ss1 = 0x0; + newProcess->tss.esp2 = 0x0; + newProcess->tss.ss2 = 0x0; + newProcess->tss.eflags = td->frame->tf_eflags; + newProcess->tss.eax = 0x0; + newProcess->tss.ebx = td->frame->tf_ebx; + newProcess->tss.ecx = td->frame->tf_ecx; + newProcess->tss.edx = td->frame->tf_edx; + newProcess->tss.esi = td->frame->tf_esi; + newProcess->tss.edi = td->frame->tf_edi; + newProcess->tss.ebp = td->frame->tf_ebp; + newProcess->tss.esp = td->frame->tf_esp; + newProcess->tss.cs = td->frame->tf_cs; // & 0xFF; + newProcess->tss.ss = td->frame->tf_ss; // & 0xFF; + newProcess->tss.ds = td->frame->tf_ds; //_current->tss.ds & 0xFF; + newProcess->tss.fs = td->frame->tf_fs; //_current->tss.fs & 0xFF; + newProcess->tss.gs = _current->tss.gs & 0xFF; + newProcess->tss.es = td->frame->tf_es; //_current->tss.es & 0xFF; + newProcess->tss.ldt = 0x18; + newProcess->tss.trace_bitmap = 0x0000; + newProcess->tss.io_map = 0x8000; + + newProcess->td.vm_tsize = _current->td.vm_tsize; + newProcess->td.vm_taddr = _current->td.vm_taddr; + newProcess->td.vm_dsize = _current->td.vm_dsize; + newProcess->td.vm_daddr = _current->td.vm_daddr; + + //kprintf("Copying Mem Space! [0x%X:0x%X:0x%X:0x%X:0x%X:%i:%i]\n", newProcess->tss.esp0, newProcess->tss.esp, newProcess->tss.ebp, td->frame->tf_esi, td->frame->tf_eip, newProcess->id, _current->id); + + newProcess->tss.cr3 = (uInt32) vmm_copyVirtualSpace(newProcess->id); + //kprintf( "Copied Mem Space! [0x%X]\n", newProcess->tss.cr3 ); + + newProcess->state = FORK; + /* Fix gcc optimization problems */ + while (newProcess->state == FORK) + sched_yield(); + + newProcess->parent = _current; + _current->children++; + + /* Return Id of Proccess */ + td->td_retval[0] = newProcess->id; + return (0); + +} + +/***************************************************************************************** + Functoin: static int fork_copyProcess(struct taskStruct *newProcess,long ebp,long edi, + long esi, long none,long ebx,long ecx,long edx,long eip,long cs,long eflags, + long esp,long ss) + + Desc: This function will copy a process + + Notes: + + *****************************************************************************************/ + +/* Had to remove static though tihs function is only used in this file */ +int fork_copyProcess(struct taskStruct *newProcess, long ebp, long edi, long esi, long none, long ebx, long ecx, long edx, long eip, long cs, long eflags, long esp, long ss) { + volatile struct taskStruct * tmpProcPtr = newProcess; + assert(newProcess); + assert(_current); + + /* Set Up New Tasks Information */ + memcpy(newProcess->oInfo.cwd, _current->oInfo.cwd, 1024); + //kprintf( "Initializing New CWD!\n" ); + + newProcess->tss.eip = eip; + newProcess->oInfo.vmStart = _current->oInfo.vmStart; + newProcess->term = _current->term; + newProcess->term->owner = newProcess->id; + newProcess->uid = _current->uid; + newProcess->gid = _current->gid; + newProcess->tss.back_link = 0x0; + newProcess->tss.esp0 = _current->tss.esp0; + newProcess->tss.ss0 = 0x10; + newProcess->tss.esp1 = 0x0; + newProcess->tss.ss1 = 0x0; + newProcess->tss.esp2 = 0x0; + newProcess->tss.ss2 = 0x0; + newProcess->tss.eflags = eflags; + newProcess->tss.eax = 0x0; + newProcess->tss.ebx = ebx; + newProcess->tss.ecx = ecx; + newProcess->tss.edx = edx; + newProcess->tss.esi = esi; + newProcess->tss.edi = edi; + newProcess->tss.ebp = ebp; + newProcess->tss.esp = esp; + newProcess->tss.cs = cs & 0xFF; + newProcess->tss.ss = ss & 0xFF; + newProcess->tss.ds = _current->tss.ds & 0xFF; + newProcess->tss.fs = _current->tss.fs & 0xFF; + newProcess->tss.gs = _current->tss.gs & 0xFF; + newProcess->tss.es = _current->tss.es & 0xFF; + newProcess->tss.ldt = 0x18; + newProcess->tss.trace_bitmap = 0x0000; + newProcess->tss.io_map = 0x8000; + + newProcess->td.vm_tsize = _current->td.vm_tsize; + newProcess->td.vm_taddr = _current->td.vm_taddr; + newProcess->td.vm_dsize = _current->td.vm_dsize; + newProcess->td.vm_daddr = _current->td.vm_daddr; + + /* Create A Copy Of The VM Space For New Task */ + //MrOlsen 2018kprintf("Copying Mem Space! [0x%X:0x%X:0x%X:0x%X:0x%X:%i:%i:0x%X]\n", newProcess->tss.esp0, newProcess->tss.esp, newProcess->tss.ebp, esi, eip, newProcess->id, _current->id, newProcess->td.vm_daddr); + newProcess->tss.cr3 = (uInt32) vmm_copyVirtualSpace(newProcess->id); + //kprintf( "Copied Mem Space!\n" ); + + newProcess->state = FORK; + + /* Fix gcc optimization problems */ + while (tmpProcPtr->state == FORK) + sched_yield(); + /* Return Id of Proccess */ + kprintf("Returning! [%i]", _current->id); + + return (newProcess->id); +} + +void qT() { + kprintf("qT\n"); +} + +/***************************************************************************************** + Functoin: void sysFork(); + + Desc: This function will fork a new task + + Notes: + + 08/01/02 - This Seems To Be Working Fine However I'm Not Sure If I + Chose The Best Path To Impliment It I Guess We Will See + What The Future May Bring + + *****************************************************************************************/ +//asm volatile( +__asm( + ".globl sysFork_old \n" + "sysFork_old: \n" + " xor %eax,%eax \n" + " call schedNewTask \n" + " testl %eax,%eax \n" + " je fork_ret \n" + " pushl %esi \n" + " pushl %edi \n" + " pushl %ebp \n" + " pushl %eax \n" + " call fork_copyProcess \n" + " movl %eax,(%ebx) \n" + " addl $16,%esp \n" + "fork_ret: \n" + " ret \n" +); + +/*** + END + ***/ + diff --git a/sys/arch/i386/i386_exec.c b/sys/arch/i386/i386_exec.c new file mode 100644 index 0000000..ae96533 --- /dev/null +++ b/sys/arch/i386/i386_exec.c @@ -0,0 +1,996 @@ +/*- + * Copyright (c) 2002-2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define ENVP_PAGE 0x100 +#define ARGV_PAGE 0x100 +#define ELF_AUX 0x100 +#define STACK_PAD 0x1000 + +#define ENOEXEC -1 + +#define AT_NULL 0 /* Terminates the vector. */ +#define AT_IGNORE 1 /* Ignored entry. */ +#define AT_EXECFD 2 /* File descriptor of program to load. */ +#define AT_PHDR 3 /* Program header of program already loaded. */ +#define AT_PHENT 4 /* Size of each program header entry. */ +#define AT_PHNUM 5 /* Number of program header entries. */ +#define AT_PAGESZ 6 /* Page size in bytes. */ +#define AT_BASE 7 /* Interpreter's base address. */ +#define AT_FLAGS 8 /* Flags (unused for i386). */ +#define AT_ENTRY 9 /* Where interpreter should transfer control. */ + +#define AUXARGS_ENTRY(pos, id, val) {*pos = id;pos++; *pos = val;pos++;} + +static int argv_count(char **argv) { + int i = 0; + + while (*argv++ != 0x0) + i++; + + return (i); +} + +static int envp_count(char **envp) { + int i = 0; + + while (*envp++ != 0x0) + i++; + + return (i); +} + +static int args_copyin(char **argv_in, char **argv_out, char **args_out) { + + int argc = argv_count(argv_in); + + uint32_t *argv_tmp = (uint32_t *) kmalloc(sizeof(char *) * (argc + 2)); // + 1 For ARGC + 1 For NULL TERM + + char *args_tmp = (char *) kmalloc(ARGV_PAGE); + + argv_tmp[0] = argc; + + uint32_t sp = 0x0; + + int i = 0x0; + + for (i = 1; i <= argc; i++) { + argv_tmp[i] = (uint32_t)(args_tmp + sp); + strcpy((char *)argv_tmp[i], argv_in[i - 1]); + sp += strlen(argv_in[i - 1]) + 1; + } + + argv_tmp[i++] = 0x0; + + *argv_out = (char *)argv_tmp; + *args_out = args_tmp; + + return (0); + +} + +static int envs_copyin(char **envp_in, char **envp_out, char **envs_out) { + + int envc = envp_count(envp_in); + + uint32_t *envp_tmp = (uint32_t *) kmalloc(sizeof(char *) * (envc + 1)); // + 1 For NULL TERM + + char *envs_tmp = (char *) kmalloc(ENVP_PAGE); + + uint32_t sp = 0x0; + + int i = 0x0; + + for (i = 0; i < envc; i++) { + envp_tmp[i] = (uint32_t)(envs_tmp + sp); + strcpy((char *)envp_tmp[i], envp_in[i]); + sp += strlen(envp_in[i]) + 1; + } + envp_tmp[i++] = 0x0; + + *envp_out = (char *)envp_tmp; + *envs_out = envs_tmp; + return (0); +} + +static int elf_parse_dynamic(elf_file_t ef); + +/***************************************************************************************** + + Function: execThread(void (*)(void),int,char *); + Description: This function will create a thread from code in the current memory space + + Notes: + + 05/19/04 - This does not work the way I want it to it still makes a copy of kernel space + so do not use out side of kernel space + + *****************************************************************************************/ +uint32_t execThread(void (*tproc)(void), uint32_t stack, char *arg) { + + kTask_t * newProcess = 0x0; + uint32_t stackAddr = 0x0; + + /* Find A New Thread */ + newProcess = schedNewTask(); + assert(newProcess); + + stackAddr = vmm_getFreeKernelPage(newProcess->id, stack / PAGE_SIZE); + + /* Set All The Correct Thread Attributes */ + newProcess->tss.back_link = 0x0; + newProcess->tss.esp0 = 0x0; + newProcess->tss.ss0 = 0x0; + newProcess->tss.esp1 = 0x0; + newProcess->tss.ss1 = 0x0; + newProcess->tss.esp2 = 0x0; + newProcess->tss.ss2 = 0x0; + newProcess->tss.cr3 = (unsigned int) kernelPageDirectory; + newProcess->tss.eip = (unsigned int) tproc; + newProcess->tss.eflags = 0x206; + newProcess->tss.esp = stackAddr + (stack - 0x4); //stack; + newProcess->tss.ebp = 0x0;//stack; + newProcess->tss.esi = 0x0; + newProcess->tss.edi = 0x0; + + /* Ring 3 Selectors */ + /* + newProcess->tss.es = 0x30+3; + newProcess->tss.cs = 0x28+3; + newProcess->tss.ss = 0x30+3; + newProcess->tss.ds = 0x30+3; + newProcess->tss.fs = 0x30+3; + newProcess->tss.gs = 0x30+3; + */ + + /* Ring 0 Selectors */ + newProcess->tss.es = 0x10; + newProcess->tss.cs = 0x08; + newProcess->tss.ss = 0x10; + newProcess->tss.ds = 0x10; + newProcess->tss.fs = 0x10; + newProcess->tss.gs = 0x10; + + newProcess->tss.ldt = 0x18; + newProcess->tss.trace_bitmap = 0x0000; + newProcess->tss.io_map = 0x8000; + newProcess->oInfo.vmStart = 0x6400000; + + if (newProcess->files[0] != 0x0) + kpanic("Problem With File Descriptors"); + + newProcess->files[0] = 0x0; + + //kprintf("EIP: 0x%X(%i)", tproc, newProcess->id); + + /* Set up default stack for thread here filled with arg list 3 times */ + asm volatile( + "pusha \n" + "movl %%esp,%%ecx \n" + "movl %1,%%eax \n" + "movl %%eax,%%esp \n" + "pushl %%ebx \n" + "pushl %%ebx \n" + "pushl %%ebx \n" + "movl %%esp,%%eax \n" + "movl %%eax,%1 \n" + "movl %%ecx,%%esp \n" + "popa \n" + : + : "b" (arg),"m" (newProcess->tss.esp) + ); + + /* Put new thread into the READY state */ + sched_setStatus(newProcess->id, READY); + + /* Return with the new process ID */ + return ((uint32_t) newProcess); +} + +/***************************************************************************************** + + Function: void execFile(char *file); + Description: This Function Executes A Kile Into A New VM Space With Out + Having To Fork + Notes: + + 07/30/02 - I Have Made Some Heavy Changes To This As Well As Fixed A Few + Memory Leaks The Memory Allocated To Load The Binary Into Is + Now Unmapped So It Can Be Used Again And Not Held Onto Until + The Program Exits + + 07/30/02 - Now I Have To Make A Better Memory Allocator So We Can Set Up + The Freshly Allocated Pages With The Correct Permissions + + *****************************************************************************************/ +void execFile(char *file, char **argv, char **envp, int console) { + + kTask_t *newProcess = 0x0; + + int i = 0x0; + int x = 0x0; + + uint32_t *tmp = 0x0; + + Elf_Ehdr *binaryHeader = 0x0; + + Elf_Phdr *programHeader = 0x0; + + int argc = argv_count(argv); + int envc = envp_count(envp); + + /* Get A New Task For This Proccess */ + newProcess = schedNewTask(); + assert(newProcess); + + newProcess->gid = 0x0; + newProcess->uid = 0x0; + newProcess->pgrp = newProcess->id; + newProcess->term = tty_find(console); + + if (newProcess->term == 0x0) + kprintf("Error: invalid console\n"); + + /* Set tty ownership */ + newProcess->term->owner = newProcess->id; + + /* Now We Must Create A Virtual Space For This Proccess To Run In */ + newProcess->tss.cr3 = (uint32_t) vmm_createVirtualSpace(newProcess->id); + + /* To Better Load This Application We Will Switch Over To Its VM Space */ + asm volatile( + "movl %0,%%eax \n" + "movl %%eax,%%cr3 \n" + : : "d" ((uint32_t *)(newProcess->tss.cr3)) + ); + + /* Lets Find The File */ + if (newProcess->files[0] != 0x0) + kpanic("Problem With File Descriptors"); + newProcess->files[0] = fopen(file, "r"); + + /* If We Dont Find the File Return */ + if (newProcess->files[0] == 0x0) { + kprintf("Exec Format Error: Binary File Not Executable.\n"); + fclose(newProcess->files[0]); + return; + } + + if (newProcess->files[0]->perms == 0x0) { + kprintf("Exec Format Error: Binary File Not Executable.\n"); + fclose(newProcess->files[0]); + return; + } + + /* Load ELF Header */ + binaryHeader = (Elf_Ehdr *) kmalloc(sizeof(Elf_Ehdr)); + + fread(binaryHeader, sizeof(Elf_Ehdr), 1, newProcess->files[0]); + + /* Check If App Is A Real Application */ + if ((binaryHeader->e_ident[1] != 'E') && (binaryHeader->e_ident[2] != 'L') && (binaryHeader->e_ident[3] != 'F')) { + kprintf("Exec Format Error: Binary File Not Executable.\n"); + kfree(binaryHeader); + fclose(newProcess->files[0]); + return; + } + else if (binaryHeader->e_type != 2) { + kprintf("Exec Format Error: Binary File Not Executable.\n"); + kfree(binaryHeader); + fclose(newProcess->files[0]); + return; + } + else if (binaryHeader->e_entry == 0x300000) { + kprintf("Exec Format Error: Binary File Not Executable.\n"); + kfree(binaryHeader); + fclose(newProcess->files[0]); + return; + } + + newProcess->td.abi = binaryHeader->e_ident[EI_OSABI]; + + /* Load The Program Header(s) */ + programHeader = (Elf_Phdr *) kmalloc(sizeof(Elf_Phdr) * binaryHeader->e_phnum); + fseek(newProcess->files[0], binaryHeader->e_phoff, 0); + + fread(programHeader, (sizeof(Elf_Phdr) * binaryHeader->e_phnum), 1, newProcess->files[0]); + + /* Loop Through The Header And Load Sections Which Need To Be Loaded */ + for (i = 0; i < binaryHeader->e_phnum; i++) { + if (programHeader[i].p_type == 1) { + /* + Allocate Memory Im Going To Have To Make This Load Memory With Correct + Settings so it helps us in the future + */ + for (x = 0x0; x < (programHeader[i].p_memsz); x += 0x1000) { + /* Make readonly and read/write !!! */ + if (vmm_remapPage(vmm_findFreePage(newProcess->id), ((programHeader[i].p_vaddr & 0xFFFFF000) + x), PAGE_DEFAULT, newProcess->id, 0) == 0x0) + K_PANIC("Remap Page Failed"); + + memset((void *) ((programHeader[i].p_vaddr & 0xFFFFF000) + x), 0x0, 0x1000); + + } + + /* Now Load Section To Memory */ + fseek(newProcess->files[0], programHeader[i].p_offset, 0); + + fread((void *) programHeader[i].p_vaddr, programHeader[i].p_filesz, 1, newProcess->files[0]); + + if ((programHeader[i].p_flags & 0x2) != 0x2) { + for (x = 0x0; x < (programHeader[i].p_memsz); x += 0x1000) { + if ((vmm_setPageAttributes((programHeader[i].p_vaddr & 0xFFFFF000) + x, PAGE_PRESENT | PAGE_USER)) != 0x0) + kpanic("Error: vmm_setPageAttributes failed, File: %s, Line: %i\n", __FILE__, __LINE__); + } + } + } + } + + /* Set Virtual Memory Start */ + newProcess->oInfo.vmStart = 0x80000000; + newProcess->td.vm_daddr = (u_long) (programHeader[i].p_vaddr & 0xFFFFF000); + + /* Set Up Stack Space */ + //MrOlsen (2016-01-14) FIX: is the stack start supposed to be addressable xhcnage x= 1 to x=0 + //x = 0 because GS= stack address not address -1 fix! + for (x = 1; x <= 100; x++) { + vmm_remapPage(vmm_findFreePage(newProcess->id), (STACK_ADDR+1) - (x * PAGE_SIZE), PAGE_DEFAULT | PAGE_STACK, newProcess->id, 0); + bzero((void *)((STACK_ADDR+1) - (x * PAGE_SIZE)), PAGE_SIZE); + } + + /* Kernel Stack 0x2000 bytes long */ + + //vmm_remapPage(vmm_findFreePage(newProcess->id), 0x5BC000, KERNEL_PAGE_DEFAULT | PAGE_STACK, newProcess->id); + //vmm_remapPage(vmm_findFreePage(newProcess->id), 0x5BB000, KERNEL_PAGE_DEFAULT | PAGE_STACK, newProcess->id); + /* + for (x = 0; x < 2; x++) + vmm_remapPage(vmm_findFreePage(newProcess->id), 0xFFFFF000 - (PAGE_SIZE * x), KERNEL_PAGE_DEFAULT | PAGE_STACK, newProcess->id, 0); + */ + + /* Set All The Proper Information For The Task */ + newProcess->tss.back_link = 0x0; + newProcess->tss.esp0 = 0xFFFFFFFF; //0x5BC000; + newProcess->tss.ss0 = 0x10; + newProcess->tss.esp1 = 0x0; + newProcess->tss.ss1 = 0x0; + newProcess->tss.esp2 = 0x0; + newProcess->tss.ss2 = 0x0; + newProcess->tss.eip = (long) binaryHeader->e_entry; + newProcess->tss.eflags = 0x206; + newProcess->tss.esp = STACK_ADDR; + newProcess->tss.ebp = 0x0;//STACK_ADDR; + newProcess->tss.esi = 0x0; + newProcess->tss.edi = 0x0; + + /* Set these up to be ring 3 tasks */ + newProcess->tss.es = 0x30 + 3; + newProcess->tss.cs = 0x28 + 3; + newProcess->tss.ss = 0x30 + 3; + newProcess->tss.ds = 0x30 + 3; + newProcess->tss.fs = 0x30 + 3; + newProcess->tss.gs = 0x8 + 3 + 4;//0x50 + 3; //0x30 + 3; + + newProcess->tss.ldt = 0x18; + newProcess->tss.trace_bitmap = 0x0000; + newProcess->tss.io_map = 0x8000; + + //sched_setStatus(newProcess->id, READY); + + kfree(binaryHeader); + kfree(programHeader); + fclose(newProcess->files[0]); + newProcess->files[0] = 0x0; + + tmp = (uint32_t *) newProcess->tss.esp0 - 5; + + tmp[0] = binaryHeader->e_entry; + tmp[3] = STACK_ADDR - 12; + + newProcess->tss.esp = STACK_ADDR - ARGV_PAGE - ENVP_PAGE - ELF_AUX - (argc + 1) - (envc + 1) - STACK_PAD; + + tmp = (uint32_t *) newProcess->tss.esp; + + tmp[0] = argc; + + uint32_t sp = 0x0; + + for (i = 1; i <= argc; i++) { + tmp[i] = STACK_ADDR - ARGV_PAGE + sp; + strcpy((char *) tmp[i], argv[i - 1]); + sp += strlen(argv[i - 1]) + 1; + } + tmp[i++] = 0x0; + + sp = 0; + + for (int x = 0; x < envc; x++) { + tmp[x + i] = STACK_ADDR - ARGV_PAGE - ENVP_PAGE + sp; + strcpy((char *) tmp[x + i], envp[x]); + sp += strlen(envp[x]) + 1; + } + tmp[i + x] = 0x0; + + /* Build LDT For GS and FS */ + vmm_unmapPage(VMM_USER_LDT, 1); + + if (vmm_remapPage(vmm_findFreePage(newProcess->id), VMM_USER_LDT, PAGE_DEFAULT, newProcess->id, 0) == 0x0) { + K_PANIC("Error: Remap Page Failed"); + } + + struct gdtDescriptor *taskLDT = 0x0; + + taskLDT = (struct gdtDescriptor *)(VMM_USER_LDT + sizeof(struct gdtDescriptor)); + uint32_t data_addr = 0x0; + + taskLDT->limitLow = (0xFFFFF & 0xFFFF); + taskLDT->baseLow = (data_addr & 0xFFFF); + taskLDT->baseMed = ((data_addr >> 16) & 0xFF); + taskLDT->access = ((dData + dWrite + dBig + dBiglim + dDpl3) + dPresent) >> 8; + taskLDT->limitHigh = (0xFFFFF >> 16); + taskLDT->granularity = ((dData + dWrite + dBig + dBiglim + dDpl3) & 0xFF) >> 4; + taskLDT->baseHigh = data_addr >> 24; + + + /* Switch Back To The Kernels VM Space */ + asm volatile( + "movl %0,%%eax \n" + "movl %%eax,%%cr3 \n" + : : "d" ((uint32_t *)(kernelPageDirectory)) + ); + + sprintf(newProcess->oInfo.cwd, "/"); + + //MrOlsen 2018 kprintf("execFile Return: 0x%X - %i\n", newProcess->tss.eip, newProcess->id); + + /* Put new thread into the READY state */ + sched_setStatus(newProcess->id, READY); + + //_current = newProcess; + + /* Finally Return */ + return; +} + +int sys_exec(struct thread *td, char *file, char **argv, char **envp) { + + int i = 0x0; + int x = 0x0; + + int argc = argv_count(argv); + int envc = envp_count(envp); + + uint32_t cr3 = 0x0; + + uint32_t *tmp = 0x0; + + uInt32 seg_size = 0x0; + uInt32 seg_addr = 0x0; + + char *interp = 0x0; + uint32_t ldAddr = 0x0; + + fileDescriptor_t *fd = 0x0; + + Elf_Ehdr *binaryHeader = 0x0; + Elf_Phdr *programHeader = 0x0; + Elf_Shdr *sectionHeader = 0x0; + + elf_file_t ef = 0x0; + + u_long text_addr = 0, text_size = 0; + u_long data_addr = 0, data_size = 0; + + struct i386_frame *iFrame = 0x0; + + asm("movl %%cr3, %0;" : "=r" (cr3)); + + fd = fopen(file, "r"); + + if (fd == 0x0) { + td->td_retval[0] = 2; + return (-1); + } + + /* Test If Executable */ + if (fd->perms == 0) { + kprintf("Exec Format Error: Binary File Not Executable.\n"); + fclose(fd); + return (-1); + } + + /* Set Threads FD to open FD */ + _current->files[0] = fd; + + /* Copy In ARGS & ENVS Before Cleaning Virtual Space */ + uint32_t *argv_out = 0x0; + char *args_out = 0x0; + + args_copyin(argv, (char **)&argv_out, &args_out); + + uint32_t *envp_out = 0x0; + char *envs_out = 0x0; + + envs_copyin(envp, (char **)&envp_out, &envs_out); + + //! Clean the virtual of COW pages left over from the fork + //vmm_cleanVirtualSpace( (uint32_t) _current->td.vm_daddr + (_current->td.vm_dsize << PAGE_SHIFT) ); + //MrOlsen 2017-12-15 - FIX! - This should be done before it was causing a lot of problems why did I free space after loading binary???? + //vmm_cleanVirtualSpace((uint32_t) 0x8048000); + vmm_cleanVirtualSpace((uint32_t) VMM_USER_START); + + /* Clear Stack */ + //bzero(STACK_ADDR - (100 * PAGE_SIZE), (PAGE_SIZE * 100)); + for (x = 1; x <= 100; x++) { + vmm_remapPage(vmm_findFreePage(_current->id), (STACK_ADDR+1) - (x * 0x1000), PAGE_DEFAULT | PAGE_STACK, _current->id, 0); + bzero((void *)((STACK_ADDR+1) - (x * 0x1000)), 0x1000); + } + + /* Load ELF Header */ + if ((binaryHeader = (Elf_Ehdr *) kmalloc(sizeof(Elf_Ehdr))) == 0x0) + K_PANIC("MALLOC FAILED"); + + fread(binaryHeader, sizeof(Elf_Ehdr), 1, fd); + /* Done Loading ELF Header */ + + /* Check If App Is A Real Application */ + if ((binaryHeader->e_ident[1] != 'E') && (binaryHeader->e_ident[2] != 'L') && (binaryHeader->e_ident[3] != 'F')) { + kprintf("Exec Format Error: Binary File Not Executable.\n"); + kfree(binaryHeader); + fclose(fd); + return (-1); + } + else if (binaryHeader->e_type != ET_EXEC) { + kprintf("Exec Format Error: Binary File Not Executable.\n"); + kfree(binaryHeader); + fclose(fd); + return (-1); + } + else if (binaryHeader->e_entry == 0x300000) { + kprintf("Exec Format Error: Binary File Not Executable.\n"); + kfree(binaryHeader); + fclose(fd); + return (-1); + } + + /* Set Thread ABI */ + td->abi = binaryHeader->e_ident[EI_OSABI]; + + /* Load The Program Header(s) */ + if ((programHeader = (Elf_Phdr *) kmalloc(sizeof(Elf_Phdr) * binaryHeader->e_phnum)) == 0x0) + K_PANIC("MALLOC FAILED"); + + assert(programHeader); + + fseek(fd, binaryHeader->e_phoff, 0); + fread(programHeader, (sizeof(Elf_Phdr) * binaryHeader->e_phnum), 1, fd); + /* Done Loading Program Header(s) */ + + /* Load The Section Header(s) */ + if ((sectionHeader = (Elf_Shdr *) kmalloc(sizeof(Elf_Shdr) * binaryHeader->e_shnum)) == 0x0) + K_PANIC("MALLOC FAILED"); + + assert(sectionHeader); + fseek(fd, binaryHeader->e_shoff, 0); + fread(sectionHeader, sizeof(Elf_Shdr) * binaryHeader->e_shnum, 1, fd); + /* Done Loading Section Header(s) */ + + ef = kmalloc(sizeof(struct elf_file)); + memset(ef, 0x0, sizeof(struct elf_file)); + + /* Loop Through The Header And Load Sections Which Need To Be Loaded */ + for (i = 0; i < binaryHeader->e_phnum; i++) { + switch (programHeader[i].p_type) { + case PT_LOAD: + if (programHeader[i].p_memsz == 0x0) + break; + + seg_addr = trunc_page(programHeader[i].p_vaddr); + seg_size = round_page(programHeader[i].p_memsz + programHeader[i].p_vaddr - seg_addr); + + /* + Allocate Memory Im Going To Have To Make This Load Memory With Correct + Settings so it helps us in the future + */ + for (x = 0x0; x < (round_page(programHeader[i].p_memsz)); x += 0x1000) { + /* Make readonly and read/write !!! */ + if (vmm_remapPage(vmm_findFreePage(_current->id), ((programHeader[i].p_vaddr & 0xFFFFF000) + x), PAGE_DEFAULT, _current->id, 0) == 0x0) { + K_PANIC("Error: Remap Page Failed"); + } + else { + //MrOlsen 2018-01-15 kprintf("rP[0x%X]", (programHeader[i].p_vaddr & 0xFFFFF000) + x); + } + + memset((void *) ((programHeader[i].p_vaddr & 0xFFFFF000) + x), 0x0, 0x1000); + + } + + /* Now Load Section To Memory */ + fseek(fd, programHeader[i].p_offset, 0); + fread((void *) programHeader[i].p_vaddr, programHeader[i].p_filesz, 1, fd); + + if ((programHeader[i].p_flags & 0x2) != 0x2) { + for (x = 0x0; x < (round_page(programHeader[i].p_memsz)); x += 0x1000) { + if ((vmm_setPageAttributes((programHeader[i].p_vaddr & 0xFFFFF000) + x, PAGE_PRESENT | PAGE_USER)) != 0x0) + kpanic("Error: vmm_setPageAttributes failed, File: %s,Line: %i\n", __FILE__, __LINE__); + } + } + + if ((programHeader[i].p_flags & PF_X) && text_size < seg_size) { + //MrOlsen 2018kprintf("setting text: 0x%X - 0x%X\n", seg_addr, seg_size); + text_size = seg_size; + text_addr = seg_addr; + } + else { + //MrOlsen 2018kprintf("setting data: 0x%X - 0x%X\n", seg_addr, seg_size); + data_size = seg_size; + data_addr = seg_addr; + /* + _current->td.vm_dsize = seg_size >> PAGE_SHIFT; + _current->td.vm_daddr = (char *) seg_addr; + kprintf( "setting daddr: 0x%X, dsiize: 0x%X\n", _current->td.vm_daddr, _current->td.vm_dsize ); + */ + } + + /* + * MrOlsen (2016-01-19) NOTE: Note Sure, I should Do This Later + * Thjis is for stack space + */ + _current->oInfo.vmStart = ((programHeader[i].p_vaddr & 0xFFFFF000) + 0xA900000); + break; + case PT_DYNAMIC: + //newLoc = (char *)programHeader[i].phVaddr; + //elfDynamicS = (elfDynamic *) programHeader[i].p_vaddr; + ef->dynamic = (Elf_Dyn *) programHeader[i].p_vaddr; + //fseek( fd, programHeader[i].phOffset, 0 ); + //fread( (void *) programHeader[i].phVaddr, programHeader[i].phFilesz, 1, fd ); + break; + case PT_INTERP: + #ifdef DEBUG_EXEC + kprintf("%s:%i>Malloc: %i\n", _FILE_,_LINE_,programHeader[i].p_filesz); + #endif + interp = (char *) kmalloc(programHeader[i].p_filesz); + fseek(fd, programHeader[i].p_offset, 0); + fread((void *) interp, programHeader[i].p_filesz, 1, fd); + #ifdef DEBUG_EXEC + kprintf("Interp: [%s]\n", interp); + #endif + ldAddr = ldEnable(interp); + //ef->ld_addr = ldEnable(); + break; + case PT_GNU_STACK: + asm("nop"); + break; + default: + break; + } + } + + _current->td.vm_tsize = text_size >> PAGE_SHIFT; + _current->td.vm_taddr = text_addr; + _current->td.vm_dsize = data_size >> PAGE_SHIFT; + _current->td.vm_daddr = data_addr; + + //MrOlsen 2018kprintf("Done Looping\n"); + + ef->preloaded = 1; + ef->address = 0x0; + elf_parse_dynamic(ef); + + //asm("cld"); + //irqDisable(0); + iFrame = (struct i386_frame *) (_current->tss.esp0 - sizeof(struct i386_frame)); + + //iFrame->ebp = 0x0; + + if (ldAddr != 0x0) { + iFrame->eip = ldAddr; + } + else { + iFrame->eip = binaryHeader->e_entry; + } + + //iFrame->edx = 0x0; + + iFrame->user_esp = (uint32_t) (STACK_ADDR - ARGV_PAGE - ENVP_PAGE - ELF_AUX - (argc + 1) - (envc + 1) - STACK_PAD) & 0xFFFFF000; + + tmp = (uint32_t *) iFrame->user_esp; + +// memset((char *) tmp, 0x0, ARGV_PAGE + ENVP_PAGE + ELF_AUX + (argc + 1) + (envc + 1) + STACK_PAD); + + tmp[0] = argc; + + uint32_t sp = 0x0; + + char *EXECP = 0x0; + + for (i = 1; i <= argc; i++) { + tmp[i] = (uint32_t) STACK_ADDR - ARGV_PAGE + sp; + if (i == 1) { + EXECP = (char *)tmp[i]; + } + strcpy((char *)tmp[i], (const char *)argv_out[i]); + #ifdef EXEC_DEBUG + kprintf("argv[%i]:%s",i, (const char *)argv_out[i]); + #endif + sp += strlen((const char *)argv_out[i]) + 1; + } + + tmp[i++] = 0x0; + + kfree(argv_out); + kfree(args_out); + + sp = 0; + + x = 0; + + for (x = 0; x < envc; x++) { + tmp[x + i] = (uint32_t) STACK_ADDR - ARGV_PAGE - ENVP_PAGE + sp; + strcpy((char *) tmp[x + i], (const char *)envp_out[x]); + sp += strlen((const char *)envp_out[x]) + 1; + } + + tmp[i + x] = 0x0; + + kfree(envp_out); + kfree(envs_out); + + i = i + x + 1; + + struct file *tFP = 0x0; + int tFD = 0x0; + + fseek(_current->files[0], 0x0, 0x0); // Reset File Position + falloc(&_current->td, &tFP, &tFD); + + tFP->fd = _current->files[0]; + + + tmp[i++] = 2; + tmp[i++] = -1;// tFD; // _current->imageFd; + _current->td.o_files[4] = _current->files[0]; + //MrOlsen 2018kprintf("AT_EXECFD: [%i:%i]", tmp[i - 1], tFD); + + tmp[i++] = 3; + tmp[i++] = binaryHeader->e_phoff + 0x08048000; + //MrOlsen 2018kprintf("AT_PHDR: [0x%X]", tmp[i - 1]); + + tmp[i++] = 4; + tmp[i++] = binaryHeader->e_phentsize; + //MrOlsen 2018kprintf("AT_PHENT: [0x%X]", tmp[i - 1]); + + tmp[i++] = 5; + tmp[i++] = binaryHeader->e_phnum; + //MrOlsen 2018kprintf("AT_PHNUM: [0x%X]", tmp[i - 1]); + + tmp[i++] = 6; + tmp[i++] = 0x1000; + + tmp[i++] = 7; + tmp[i++] = LD_START; + //MrOlsen 2018kprintf("AT_BASE: [0x%X]", tmp[i - 1]); + + tmp[i++] = 8; + tmp[i++] = 0x0; + + tmp[i++] = 9; + tmp[i++] = binaryHeader->e_entry; + + tmp[i++] = 11; + tmp[i++] = 0x0; + + tmp[i++] = 12; + tmp[i++] = 0x0; + + tmp[i++] = 13; + tmp[i++] = 0x0; + + tmp[i++] = 14; + tmp[i++] = 0x0; + + tmp[i++] = 15; //EXEC PATH + tmp[i++] = (uint32_t)EXECP; + + tmp[i++] = 19; //NCPUS + tmp[i++] = 0x1; + + tmp[i++] = 23; //STACKPROT + tmp[i++] = 0x3; + + tmp[i++] = 0; + tmp[i++] = 0; + + /* Now That We Relocated The Binary We Can Unmap And Free Header Info */ + kfree(binaryHeader); + kfree(programHeader); + //irqEnable(0); + //asm("sti"); + + /* + _current->tss.es = 0x30 + 3; + _current->tss.cs = 0x28 + 3; + _current->tss.ss = 0x30 + 3; + _current->tss.ds = 0x30 + 3; + _current->tss.fs = 0x30 + 3; + _current->tss.gs = 0x50 + 3; //0x30 + 3; + + _current->tss.ldt = 0x18; + _current->tss.trace_bitmap = 0x0000; + _current->tss.io_map = 0x8000; + */ + + /* + kfree (iFrameNew); + + memAddr = (uint32_t) & (_current->tss); + ubixGDT[4].descriptor.baseLow = (memAddr & 0xFFFF); + ubixGDT[4].descriptor.baseMed = ((memAddr >> 16) & 0xFF); + ubixGDT[4].descriptor.baseHigh = (memAddr >> 24); + ubixGDT[4].descriptor.access = '\x89'; + + ubixGDT[10].descriptor.baseLow = (STACK_ADDR & 0xFFFF); + ubixGDT[10].descriptor.baseMed = ((STACK_ADDR >> 16) & 0xFF); + ubixGDT[10].descriptor.baseHigh = (STACK_ADDR >> 24); + + */ + + /* Build LDT For GS and FS */ + vmm_unmapPage(VMM_USER_LDT, 1); // Can I Free This? + if (vmm_remapPage(vmm_findFreePage(_current->id), VMM_USER_LDT, PAGE_DEFAULT, _current->id, 0) == 0x0) { + K_PANIC("Error: Remap Page Failed"); + } + + struct gdtDescriptor *taskLDT = 0x0; + + taskLDT = (struct gdtDescriptor *)(VMM_USER_LDT + sizeof(struct gdtDescriptor)); + + //data_addr = 0x0; //TEMP + + taskLDT->limitLow = (0xFFFFF & 0xFFFF); + taskLDT->baseLow = (data_addr & 0xFFFF); + taskLDT->baseMed = ((data_addr >> 16) & 0xFF); + taskLDT->access = ((dData + dWrite + dBig + dBiglim + dDpl3) + dPresent) >> 8; + taskLDT->limitHigh = (0xFFFFF >> 16); + taskLDT->granularity = ((dData + dWrite + dBig + dBiglim + dDpl3) & 0xFF) >> 4; + taskLDT->baseHigh = data_addr >> 24; + + _current->tss.gs = 0xF; //Select 0x8 + Ring 3 + LDT + _current->pgrp = _current->id; + + return (0x0); +} + +static int elf_parse_dynamic(elf_file_t ef) { + Elf32_Dyn *dynp; + int plttype = DT_REL; + + for (dynp = ef->dynamic; dynp->d_tag != 0x0; dynp++) { + switch (dynp->d_tag) { + case DT_NEEDED: + asm("nop"); + break; + case DT_INIT: + asm("nop"); + break; + case DT_FINI: + asm("nop"); + break; + case DT_HASH: + asm("nop"); + /* From src/libexec/rtld-elf/rtld.c */ + const Elf_Hashelt *hashtab = (const Elf_Hashelt *) (ef->address + dynp->d_un.d_ptr); + ef->nbuckets = hashtab[0]; + ef->nchains = hashtab[1]; + ef->buckets = hashtab + 2; + ef->chains = ef->buckets + ef->nbuckets; + break; + case DT_STRTAB: + ef->strtab = (caddr_t) (ef->address + dynp->d_un.d_ptr); + break; + case DT_STRSZ: + ef->strsz = dynp->d_un.d_val; + break; + case DT_SYMTAB: + ef->symtab = (Elf_Sym *) (ef->address + dynp->d_un.d_ptr); + break; + case DT_SYMENT: + if (dynp->d_un.d_val != sizeof(Elf32_Sym)) + return (ENOEXEC); + break; + case DT_REL: + ef->rel = (const Elf_Rel *) (ef->address + dynp->d_un.d_ptr); + break; + case DT_RELSZ: + ef->relsize = dynp->d_un.d_val; + break; + case DT_RELENT: + if (dynp->d_un.d_val != sizeof(Elf_Rel)) + return (ENOEXEC); + break; + case DT_JMPREL: + ef->pltrel = (const Elf_Rel *) (ef->address + dynp->d_un.d_ptr); + break; + case DT_PLTRELSZ: + ef->pltrelsize = dynp->d_un.d_val; + break; + case DT_RELA: + ef->rela = (const Elf_Rela *) (ef->address + dynp->d_un.d_ptr); + break; + case DT_RELASZ: + ef->relasize = dynp->d_un.d_val; + break; + case DT_RELAENT: + if (dynp->d_un.d_val != sizeof(Elf_Rela)) + return (ENOEXEC); + break; + case DT_PLTREL: + plttype = dynp->d_un.d_val; + if (plttype != DT_REL && plttype != DT_RELA) + return (ENOEXEC); + break; + case DT_PLTGOT: + ef->got = (Elf_Addr *) (ef->address + dynp->d_un.d_ptr); + /* + tmp = (void *) dynp->d_un.d_ptr; //elfDynamicS[i].dynPtr; + tmp[2] = (uInt32) ef->ld_addr; + tmp[1] = (uInt32) ef; //0x0;//0xBEEFEAD;//STACK_ADDR - 128;//_current->imageFd;//0xBEEFDEAD;//ef; + */ + break; + default: + asm("nop"); + //kprintf("t_tag: 0x%X>", dynp->d_tag); + break; + } + } + + if (plttype == DT_RELA) { + ef->pltrela = (const Elf_Rela *) ef->pltrel; + ef->pltrel = NULL; + ef->pltrelasize = ef->pltrelsize; + ef->pltrelsize = 0; + } + + ef->ddbsymtab = ef->symtab; + ef->ddbsymcnt = ef->nchains; + ef->ddbstrtab = ef->strtab; + ef->ddbstrcnt = ef->strsz; + return (0); +} diff --git a/sys/arch/i386/kpanic.c b/sys/arch/i386/kpanic.c new file mode 100644 index 0000000..4b6ce22 --- /dev/null +++ b/sys/arch/i386/kpanic.c @@ -0,0 +1,66 @@ +/*- + * Copyright (c) 2002-2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include + +/*! + * \brief print panic message and halt system + * + * \param fmt panic message + * + */ +void kpanic(const char *fmt, ...) { + char buf[512]; + va_list args; + + va_start(args, fmt); + vsprintf(buf, fmt, args); + va_end(args); + + /* It's important that we print on the current terminal so let's reset foreground */ + tty_foreground = NULL; + kprintf("kPanic: %s", buf); + + /* Halt The System */ + //asm("cli"); + irqDisable(0x0); + + while (1) { + asm("hlt"); + } + +} + +/*** + END + ***/ + diff --git a/sys/arch/i386/memcmp.S b/sys/arch/i386/memcmp.S new file mode 100644 index 0000000..c8e68c2 --- /dev/null +++ b/sys/arch/i386/memcmp.S @@ -0,0 +1,66 @@ +/*- + * Copyright (c) 2002-2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + #include + +ENTRY(memcmp) + pushl %edi + pushl %esi + movl 12(%esp),%edi + movl 16(%esp),%esi + cld /* set compare direction forward */ + + movl 20(%esp),%ecx /* compare by words */ + shrl $2,%ecx + repe + cmpsl + jne L5 /* do we match so far? */ + + movl 20(%esp),%ecx /* compare remainder by bytes */ + andl $3,%ecx + repe + cmpsb + jne L6 /* do we match? */ + + xorl %eax,%eax /* we match, return zero */ + popl %esi + popl %edi + ret + +L5: movl $4,%ecx /* We know that one of the next */ + subl %ecx,%edi /* four pairs of bytes do not */ + subl %ecx,%esi /* match. */ + repe + cmpsb +L6: movzbl -1(%edi),%eax /* Perform unsigned comparison */ + movzbl -1(%esi),%edx + subl %edx,%eax + popl %esi + popl %edi + ret +END(memcmp) diff --git a/sys/arch/i386/memset.S b/sys/arch/i386/memset.S new file mode 100644 index 0000000..03bef8d --- /dev/null +++ b/sys/arch/i386/memset.S @@ -0,0 +1,79 @@ +/*- + * Copyright (c) 2002-2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + #include + + +ENTRY(memset) + pushl %edi + pushl %ebx + movl 12(%esp),%edi + movzbl 16(%esp),%eax /* unsigned char, zero extend */ + movl 20(%esp),%ecx + pushl %edi /* push address of buffer */ + + cld /* set fill direction forward */ + + /* + * if the string is too short, it's really not worth the overhead + * of aligning to word boundries, etc. So we jump to a plain + * unaligned set. + */ + cmpl $0x0f,%ecx + jle L1 + + movb %al,%ah /* copy char to all bytes in word */ + movl %eax,%edx + sall $16,%eax + orl %edx,%eax + + movl %edi,%edx /* compute misalignment */ + negl %edx + andl $3,%edx + movl %ecx,%ebx + subl %edx,%ebx + + movl %edx,%ecx /* set until word aligned */ + rep + stosb + + movl %ebx,%ecx + shrl $2,%ecx /* set by words */ + rep + stosl + + movl %ebx,%ecx /* set remainder by bytes */ + andl $3,%ecx +L1: rep + stosb + + popl %eax /* pop address of buffer */ + popl %ebx + popl %edi + ret +END(memset) diff --git a/sys/arch/i386/sched.c b/sys/arch/i386/sched.c new file mode 100644 index 0000000..069868d --- /dev/null +++ b/sys/arch/i386/sched.c @@ -0,0 +1,385 @@ +/*- + * Copyright (c) 2002-2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +static kTask_t *taskList = 0x0; +static kTask_t *delList = 0x0; +static uint32_t nextID = 1; + +kTask_t *_current = 0x0; +kTask_t *_usedMath = 0x0; + +static struct spinLock schedulerSpinLock = SPIN_LOCK_INITIALIZER; + +int need_resched = 0; + +/************************************************************************ + + Function: int sched_init() + + Description: This function is used to enable the kernel scheduler + + Notes: + + 02/20/2004 - Approved for quality + + ************************************************************************/ + +int sched_init() { + taskList = (kTask_t *) kmalloc(sizeof(kTask_t)); + if (taskList == 0x0) + kpanic("Unable to create task list"); + + taskList->id = nextID++; + + /* Print out information on scheduler */ + kprintf("sched0 - Address: [0x%X]\n", taskList); + + /* Return so we know everything went well */ + return (0x0); +} + +void sched() { + uint32_t memAddr = 0x0; + kTask_t *tmpTask = 0x0; + kTask_t *delTask = 0x0; + + if (spinTryLock(&schedulerSpinLock)) + return; + + tmpTask = ((_current == 0) ? 0 : _current->next); + schedStart: + + /* Yield the next task from the current prio queue */ + for (; tmpTask != 0x0; tmpTask = tmpTask->next) { + if (tmpTask->state == FORK) + tmpTask->state = READY; + + if (tmpTask->state == READY) { + _current->state = (_current->state == DEAD) ? DEAD : READY; + _current = tmpTask; + break; + } + else if (tmpTask->state == DEAD) { + delTask = tmpTask; + if (delTask->parent != 0x0) { + delTask->parent->children -= 1; + delTask->parent->last_exit = delTask->id; + delTask->parent->state = READY; + } + + tmpTask = tmpTask->next; + sched_deleteTask(delTask->id); + sched_addDelTask(delTask); + goto schedStart; + } + } + + /* Finished all the tasks, restarting the list */ + if (0x0 == tmpTask) { + tmpTask = taskList; + goto schedStart; + } + + if (_current->state == READY || _current->state == RUNNING) { + + if (_current->oInfo.v86Task == 0x1) { + irqDisable(0x0); + kprintf("IRQD(%i): 0x%X*0x%X:0x%X@, esp: 0x%X:0x%X, ebp: 0x%X:0x%X ds: 0x%X", _current->id, _current->tss.eflags, _current->tss.cs, _current->tss.eip, _current->tss.ss, _current->tss.esp, _current->tss.ss, _current->tss.ebp,_current->tss.ds); + kprintf("ss0: 0x%X, esp0: 0x%X", _current->tss.ss0, _current->tss.esp0); + } + + asm("cli"); + + memAddr = (uint32_t) &(_current->tss); + ubixGDT[4].descriptor.baseLow = (memAddr & 0xFFFF); + ubixGDT[4].descriptor.baseMed = ((memAddr >> 16) & 0xFF); + ubixGDT[4].descriptor.baseHigh = (memAddr >> 24); + ubixGDT[4].descriptor.access = '\x89'; + + _current->state = RUNNING; + + spinUnlock(&schedulerSpinLock); + + asm("sti"); + asm("ljmp $0x20,$0"); + } + else { + spinUnlock(&schedulerSpinLock); + } + + return; +} + +kTask_t *schedNewTask() { + int i = 0; + + kTask_t *tmpTask = (kTask_t *) kmalloc(sizeof(kTask_t)); + + struct file *fp = 0x0; + + if (tmpTask == 0x0) + kpanic("Error: schedNewTask() - kmalloc failed trying to initialize a new task struct\n"); + + memset(tmpTask, 0x0, sizeof(kTask_t)); + + /* Filling in tasks attrs */ + tmpTask->usedMath = 0x0; + tmpTask->state = NEW; + + /* HACK */ + + for (i = 0; i < 3; i++) { + fp = (void *) kmalloc(sizeof(struct file)); + //kprintf("DB: [0x%X]\n", (uint32_t) fp); + tmpTask->td.o_files[i] = (void *) fp; + fp->f_flag = 0x4; + } + + spinLock(&schedulerSpinLock); + tmpTask->id = nextID++; + tmpTask->next = taskList; + tmpTask->prev = 0x0; + taskList->prev = tmpTask; + taskList = tmpTask; + + spinUnlock(&schedulerSpinLock); + + return (tmpTask); +} + +int sched_deleteTask(pidType id) { + kTask_t *tmpTask = 0x0; + + /* Checking each task from the prio queue */ + for (tmpTask = taskList; tmpTask != 0x0; tmpTask = tmpTask->next) { + if (tmpTask->id == id) { + if (tmpTask->prev != 0x0) + tmpTask->prev->next = tmpTask->next; + if (tmpTask->next != 0x0) + tmpTask->next->prev = tmpTask->prev; + if (taskList == tmpTask) + taskList = tmpTask->next; + + return (0x0); + } + } + return (0x1); +} + +int sched_addDelTask(kTask_t *tmpTask) { + tmpTask->next = delList; + tmpTask->prev = 0x0; + if (delList != 0x0) + delList->prev = tmpTask; + delList = tmpTask; + return (0x0); +} + +kTask_t *sched_getDelTask() { + kTask_t *tmpTask = 0x0; + + if (delList == 0x0) + return (0x0); + + tmpTask = delList; + delList = delList->next; + return (tmpTask); +} + +kTask_t *schedFindTask(uint32_t id) { + kTask_t *tmpTask = 0x0; + + for (tmpTask = taskList; tmpTask; tmpTask = tmpTask->next) { + if (tmpTask->id == id) + return (tmpTask); + } + + return (0x0); +} + +/************************************************************************ + + Function: void schedEndTask() + + Description: This function will end a task + + Notes: + + 02/20/2004 - Approved for quality + + ************************************************************************/ +void schedEndTask(pidType pid) { + endTask(_current->id); + sched_yield(); +} + +/************************************************************************ + + Function: int schedEndTask() + + Description: This function will yield a task + + Notes: + + 02/20/2004 - Approved for quality + + ************************************************************************/ + +void sched_yield() { + sched(); +} + +/* + asm( + ".globl sched_yield \n" + "sched_yield: \n" + " cli \n" + " call sched \n" + ); + */ + +/************************************************************************ + + Function: int sched_setStatus(pidType pid,tState state) + + Description: Change the tasks status + + Notes: + + ************************************************************************/ +int sched_setStatus(pidType pid, tState state) { + kTask_t *tmpTask = schedFindTask(pid); + if (tmpTask == 0x0) + return (0x1); + tmpTask->state = state; + return (0x0); +} + +void add_wait_queue(struct wait_queue ** p, struct wait_queue * wait) { + unsigned long flags; + + save_flags(flags); + cli(); + if (!*p) { + wait->next = wait; + *p = wait; + } + else { + wait->next = (*p)->next; + (*p)->next = wait; + } + restore_flags(flags); +} + +void remove_wait_queue(struct wait_queue ** p, struct wait_queue * wait) { + unsigned long flags; + struct wait_queue * tmp; + + save_flags(flags); + cli(); + if ((*p == wait) && ((*p = wait->next) == wait)) { + *p = NULL; + } + else { + tmp = wait; + while (tmp->next != wait) { + tmp = tmp->next; + } + tmp->next = wait->next; + } + wait->next = NULL; + restore_flags(flags); +} + +void wake_up_interruptible(struct wait_queue **q) { + struct wait_queue *tmp; + kTask_t *p; + + if (!q || !(tmp = *q)) + return; + do { + if ((p = tmp->task) != NULL) { + if (p->state == INTERRUPTIBLE) { + p->state = RUNNING; + if (p->counter > _current->counter) + need_resched = 1; + } + } + if (!tmp->next) { + kprintf("wait_queue is bad (eip = %08lx)\n", ((unsigned long *) q)[-1]); + kprintf(" q = %p\n", q); + kprintf(" *q = %p\n", *q); + kprintf(" tmp = %p\n", tmp); + break; + } + tmp = tmp->next; + } while (tmp != *q); +} + +void wake_up(struct wait_queue **q) { + struct wait_queue *tmp; + kTask_t * p; + + if (!q || !(tmp = *q)) + return; + do { + if ((p = tmp->task) != NULL) { + if ((p->state == UNINTERRUPTIBLE) || (p->state == INTERRUPTIBLE)) { + p->state = RUNNING; + if (p->counter > _current->counter) + need_resched = 1; + } + } + if (!tmp->next) { + kprintf("wait_queue is bad (eip = %08lx)\n", ((unsigned long *) q)[-1]); + kprintf(" q = %p\n", q); + kprintf(" *q = %p\n", *q); + kprintf(" tmp = %p\n", tmp); + break; + } + tmp = tmp->next; + } while (tmp != *q); +} diff --git a/sys/arch/i386/schedyield.S b/sys/arch/i386/schedyield.S new file mode 100644 index 0000000..1072793 --- /dev/null +++ b/sys/arch/i386/schedyield.S @@ -0,0 +1,51 @@ +/*- + * Copyright (c) 2002-2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +.globl sched_yield_new +.text +.code32 +sched_yield_new: + pusha /* Save all of the registers */ + push %ss + push %ds + push %es + push %fs + push %gs + call sched + mov %eax,%esp + pop %gs + pop %fs + pop %es + pop %ds + pop %ss + popa /* Restore Registers */ + iret + +/*** + END + ***/ diff --git a/sys/arch/i386/spinlock.c b/sys/arch/i386/spinlock.c new file mode 100644 index 0000000..db6653d --- /dev/null +++ b/sys/arch/i386/spinlock.c @@ -0,0 +1,71 @@ +/*- + * Copyright (c) 2002-2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include + +#define atomic_xadd(P, V) __sync_fetch_and_add((P), (V)) +#define cmpxchg(P, O, N) __sync_val_compare_and_swap((P), (O), (N)) +#define atomic_inc(P) __sync_add_and_fetch((P), 1) +#define atomic_dec(P) __sync_add_and_fetch((P), -1) +#define atomic_add(P, V) __sync_add_and_fetch((P), (V)) +#define atomic_set_bit(P, V) __sync_or_and_fetch((P), 1<<(V)) +#define atomic_clear_bit(P, V) __sync_and_and_fetch((P), ~(1<<(V))) + +#define barrier() asm volatile("": : :"memory") + +/* Pause instruction to prevent excess processor bus usage */ +#define cpu_relax() asm volatile("pause\n": : :"memory") + +void spinLockInit(spinLock_t lock) { + memset(lock, 0x0, sizeof(struct spinLock)); +} + +int spinTryLock(spinLock_t lock) { + if (!cmpxchg(&lock->locked, NULL, LLOCK_FLAG)) + return 0; + + /* Failure! */ + return LOCKED; +} + +void spinUnlock(spinLock_t lock) { + barrier(); + lock->locked = 0x0; +} + +void spinLock(spinLock_t lock) { + while (1) { + if (!xchg_32(&lock->locked, LOCKED)) + return; + while (lock->locked == 1) + sched_yield(); + } +} + diff --git a/sys/arch/i386/strcmp.S b/sys/arch/i386/strcmp.S new file mode 100644 index 0000000..19bb2ff --- /dev/null +++ b/sys/arch/i386/strcmp.S @@ -0,0 +1,98 @@ +/*- + * Copyright (c) 2002-2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + #include + +ENTRY(strcmp) + movl 0x04(%esp),%eax + movl 0x08(%esp),%edx + jmp L2 /* Jump into the loop! */ + + .align 2,0x90 +L1: incl %eax + incl %edx +L2: movb (%eax),%cl + testb %cl,%cl + je L3 + cmpb %cl,(%edx) + jne L3 + incl %eax + incl %edx + movb (%eax),%cl + testb %cl,%cl + je L3 + cmpb %cl,(%edx) + jne L3 + incl %eax + incl %edx + movb (%eax),%cl + testb %cl,%cl + je L3 + cmpb %cl,(%edx) + jne L3 + incl %eax + incl %edx + movb (%eax),%cl + testb %cl,%cl + je L3 + cmpb %cl,(%edx) + jne L3 + incl %eax + incl %edx + movb (%eax),%cl + testb %cl,%cl + je L3 + cmpb %cl,(%edx) + jne L3 + incl %eax + incl %edx + movb (%eax),%cl + testb %cl,%cl + je L3 + cmpb %cl,(%edx) + jne L3 + incl %eax + incl %edx + movb (%eax),%cl + testb %cl,%cl + je L3 + cmpb %cl,(%edx) + jne L3 + incl %eax + incl %edx + movb (%eax),%cl + testb %cl,%cl + je L3 + cmpb %cl,(%edx) + je L1 + .align 2, 0x90 +L3: movzbl (%eax),%eax /* unsigned comparison */ + movzbl (%edx),%edx + subl %edx,%eax + ret +END(strcmp) diff --git a/sys/arch/i386/strcpy.S b/sys/arch/i386/strcpy.S new file mode 100644 index 0000000..e6f6a0c --- /dev/null +++ b/sys/arch/i386/strcpy.S @@ -0,0 +1,73 @@ +/*- + * Copyright (c) 2002-2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + #include + + ENTRY(strcpy) + movl 4(%esp),%ecx /* dst address */ + movl 8(%esp),%edx /* src address */ + pushl %ecx /* push dst address */ + + .align 2,0x90 +L1: movb (%edx),%al /* unroll loop, but not too much */ + movb %al,(%ecx) + testb %al,%al + je L2 + movb 1(%edx),%al + movb %al,1(%ecx) + testb %al,%al + je L2 + movb 2(%edx),%al + movb %al,2(%ecx) + testb %al,%al + je L2 + movb 3(%edx),%al + movb %al,3(%ecx) + testb %al,%al + je L2 + movb 4(%edx),%al + movb %al,4(%ecx) + testb %al,%al + je L2 + movb 5(%edx),%al + movb %al,5(%ecx) + testb %al,%al + je L2 + movb 6(%edx),%al + movb %al,6(%ecx) + testb %al,%al + je L2 + movb 7(%edx),%al + movb %al,7(%ecx) + addl $8,%edx + addl $8,%ecx + testb %al,%al + jne L1 +L2: popl %eax /* pop dst address */ + ret +END(strcpy) diff --git a/sys/arch/i386/strncmp.S b/sys/arch/i386/strncmp.S new file mode 100644 index 0000000..9696281 --- /dev/null +++ b/sys/arch/i386/strncmp.S @@ -0,0 +1,129 @@ +/*- + * Copyright (c) 2002-2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + #include + +ENTRY(strncmp) + pushl %ebx + movl 8(%esp),%eax + movl 12(%esp),%ecx + movl 16(%esp),%edx + testl %edx,%edx + jmp L2 /* Jump into the loop! */ + + .align 2,0x90 +L1: incl %eax + incl %ecx + decl %edx +L2: jz L4 /* strings are equal */ + movb (%eax),%bl + testb %bl,%bl + jz L3 + cmpb %bl,(%ecx) + jne L3 + incl %eax + incl %ecx + decl %edx + jz L4 + movb (%eax),%bl + testb %bl,%bl + jz L3 + cmpb %bl,(%ecx) + jne L3 + + incl %eax + incl %ecx + decl %edx + jz L4 + movb (%eax),%bl + testb %bl,%bl + jz L3 + cmpb %bl,(%ecx) + jne L3 + + incl %eax + incl %ecx + decl %edx + jz L4 + movb (%eax),%bl + testb %bl,%bl + jz L3 + cmpb %bl,(%ecx) + jne L3 + + incl %eax + incl %ecx + decl %edx + jz L4 + movb (%eax),%bl + testb %bl,%bl + jz L3 + cmpb %bl,(%ecx) + jne L3 + + incl %eax + incl %ecx + decl %edx + jz L4 + movb (%eax),%bl + testb %bl,%bl + jz L3 + cmpb %bl,(%ecx) + jne L3 + + incl %eax + incl %ecx + decl %edx + jz L4 + movb (%eax),%bl + testb %bl,%bl + jz L3 + cmpb %bl,(%ecx) + jne L3 + + incl %eax + incl %ecx + decl %edx + jz L4 + movb (%eax),%bl + testb %bl,%bl + jz L3 + cmpb %bl,(%ecx) + je L1 + + .align 2,0x90 +L3: movzbl (%eax),%eax /* unsigned comparison */ + movzbl (%ecx),%ecx + subl %ecx,%eax + popl %ebx + ret + .align 2,0x90 +L4: xorl %eax,%eax + popl %ebx + ret +END(strncmp) diff --git a/sys/arch/i386/support.S b/sys/arch/i386/support.S new file mode 100644 index 0000000..347cdf8 --- /dev/null +++ b/sys/arch/i386/support.S @@ -0,0 +1,120 @@ +/*- + * Copyright (c) 2002-2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + #include +.text + +// void bzero(void *buf, u_int len) +ENTRY(bzero) + pushl %edi + movl 8(%esp),%edi + movl 12(%esp),%ecx + xorl %eax,%eax + shrl $2,%ecx + cld + rep + stosl + movl 12(%esp),%ecx + andl $3,%ecx + rep + stosb + popl %edi + ret +END(bzero) + +// bcopy(src, dst, cnt) +ENTRY(bcopy) + pushl %ebp + movl %esp,%ebp + pushl %esi + pushl %edi + movl 8(%ebp),%esi + movl 12(%ebp),%edi + movl 16(%ebp),%ecx + + movl %edi,%eax + subl %esi,%eax + cmpl %ecx,%eax /* overlapping && src < dst? */ + jb 1f + + shrl $2,%ecx /* copy by 32-bit words */ + cld /* nope, copy forwards */ + rep + movsl + movl 16(%ebp),%ecx + andl $3,%ecx /* any bytes left? */ + rep + movsb + popl %edi + popl %esi + popl %ebp + ret + + ALIGN_TEXT +1: + addl %ecx,%edi /* copy backwards */ + addl %ecx,%esi + decl %edi + decl %esi + andl $3,%ecx /* any fractional bytes? */ + std + rep + movsb + movl 16(%ebp),%ecx /* copy remainder by 32-bit words */ + shrl $2,%ecx + subl $3,%esi + subl $3,%edi + rep + movsl + popl %edi + popl %esi + cld + popl %ebp + ret +END(bcopy) + +// void *memcpy(const void *dst, const void * src, size_t length) +ENTRY(memcpy) + pushl %edi + pushl %esi + movl 12(%esp),%edi + movl 16(%esp),%esi + movl 20(%esp),%ecx + movl %edi,%eax + shrl $2,%ecx /* copy by 32-bit words */ + cld /* nope, copy forwards */ + rep + movsl + movl 20(%esp),%ecx + andl $3,%ecx /* any bytes left? */ + rep + movsb + popl %esi + popl %edi + ret +END(memcpy) diff --git a/sys/arch/i386/sys_call.S b/sys/arch/i386/sys_call.S new file mode 100644 index 0000000..7844128 --- /dev/null +++ b/sys/arch/i386/sys_call.S @@ -0,0 +1,109 @@ +/*- + * Copyright (c) 2002-2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +.globl _sys_call +.text +.code32 + +_B4: +_B3: +nop + +_ast: + +_astRet: + +_sysCall_MrOlsen: +//MrOlsen 2018-01-14 push $0x2 +//MrOlsen 2018-01-14 sub $0x4,%esp +pusha +push %ds +push %es +push %fs +push %gs +mov $0x10,%eax +mov %eax,%ds +mov %eax,%es +mov %eax,%fs +cld +push %esp +call sys_call +add $0x4,%esp +cmpb $0x13,0x38(%esp) +je _B4 +testl $0x2000,0x3c(%esp) /* Test If VM */ +jz _notVM +jmp _isVM +_notVM: +testb $0x3,0x38(%esp) /* See If We're In User CS (GDT Entry 5) */ +jz _popFS +jmp _popFS /* TMP BECAUSE ABOVE ISN'T RIGHT */ +cli +mov %fs:0x0,%eax +testl $0x10800,0x80(%eax) /* Document This */ +je _popFS +sti +push %esp +call _ast +add $0x4,%esp +jmp _astRet +_isVM: +hlt + +_popFS: +pop %gs +pop %fs +pop %es +pop %ds +popa +//MrOlsen 2018-01-14 add $0x8,%esp +iret + +_sys_call: +push $0x0 +push $0x80 +pusha +push %ds +push %es +push %fs +push %gs +mov $0x10,%eax +mov %eax, %ds +mov %eax, %es +mov %eax, %fs +cld +push %esp +call sys_call +add $0x4,%esp /* Remove Stack Pointer From Stack */ +pop %gs +pop %fs +pop %es +pop %ds +popa +add $0x8,%esp //Back Out Error Code & trap_no +iret diff --git a/sys/arch/i386/sys_call_posix.S b/sys/arch/i386/sys_call_posix.S new file mode 100644 index 0000000..d9b082f --- /dev/null +++ b/sys/arch/i386/sys_call_posix.S @@ -0,0 +1,57 @@ +/*- + * Copyright (c) 2002-2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#define FAKE_MCOUNT(caller) pushl caller ; call __mcount ; popl %ecx + +.globl _sys_call_posix +.text +.code32 + +_sys_call_posix: +push $0x0 +push $0x80 +pusha +push %ds +push %es +push %fs +push %gs +mov $0x10,%eax +mov %eax, %ds +mov %eax, %es +mov %eax, %fs +cld +push %esp +call sys_call_posix +add $0x4,%esp /* Remove Stack Pointer From Stack */ +pop %gs +pop %fs +pop %es +pop %ds +popa +add $0x8,%esp //Back Out Error Code & trap_no +iret diff --git a/sys/arch/i386/systemtask.c b/sys/arch/i386/systemtask.c new file mode 100644 index 0000000..952fc06 --- /dev/null +++ b/sys/arch/i386/systemtask.c @@ -0,0 +1,131 @@ +/*- + * Copyright (c) 2002-2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static unsigned char *videoBuffer = (unsigned char *) 0xB8000; + +void systemTask() { + + mpi_message_t myMsg; + uint32_t counter = 0x0; + int i = 0x0; + int *x = 0x0; + kTask_t *tmpTask = 0x0; + + char buf[16] = { "a\n" }; + + if (mpi_createMbox("system") != 0x0) { + kpanic("Error: Error creating mailbox: system\n"); + } + + while (1) { + if (mpi_fetchMessage("system", &myMsg) == 0x0) { + switch (myMsg.header) { + case 0x69: + x = (int *) &myMsg.data; + kprintf("Switching to term: [%i][%i]\n", *x, myMsg.pid); + schedFindTask(myMsg.pid)->term = tty_find(*x); + break; + case 1000: + kprintf("Restarting the system in 5 seconds\n"); + counter = systemVitals->sysUptime + 5; + while (systemVitals->sysUptime < counter) { + sched_yield(); + } + kprintf("Rebooting NOW!!!\n"); + while (inportByte(0x64) & 0x02) + ; + outportByte(0x64, 0xFE); + break; + case 31337: + kprintf("system: backdoor opened\n"); + break; + case 0x80: + if (!strcmp(myMsg.data, "sdeStart")) { + kprintf("Starting SDE\n"); + execThread(sdeThread,0x2000,0x0); + } + else if (!strcmp(myMsg.data, "freePage")) { + kprintf("kkk Free Pages"); + } + else if (!strcmp(myMsg.data, "sdeStop")) { + printOff = 0x0; + biosCall(0x10, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0); + for (i = 0x0; i < 100; i++) + asm("hlt"); + } + break; + default: + kprintf("system: Received message %i:%s\n", myMsg.header, myMsg.data); + break; + } + } + + /* + Here we get the next task from the delete task queue + we first check to see if it has an fd attached for the binary and after that + we free the pages for the process and then free the task + */ + tmpTask = sched_getDelTask(); + + if (tmpTask != 0x0) { + if (tmpTask->files[0] != 0x0) + fclose(tmpTask->files[0]); + vmm_freeProcessPages(tmpTask->id); + kfree(tmpTask); + + } + + if (ogprintOff == 1) { + videoBuffer[0] = systemVitals->sysTicks; + videoBuffer[1] = 'c'; + } + /* + else + ogPrintf(buf); + */ + + sched_yield(); + } + + return; +} diff --git a/sys/arch/i386/timer.S b/sys/arch/i386/timer.S new file mode 100644 index 0000000..1ddfcc1 --- /dev/null +++ b/sys/arch/i386/timer.S @@ -0,0 +1,75 @@ +/*- + * Copyright (c) 2002-2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +.globl timerInt +.text +.code32 +timerInt: + pusha /* Save all of the registers */ + mov $0x20,%dx /* The Following Sends Our EOI To The MPIC */ + mov $0x20,%ax + outb %al,%dx + movl systemVitals,%ecx /* Put Location Of System Vitals Into ECX */ + incl (%ecx) /* Increment sysTicks our 1000ms counter */ + movl (%ecx),%eax /* Increment our sysUptime by 1S if 1000MS */ + movl $200,%ebx /* Have Passed */ + xor %edx,%edx + div %ebx + test %edx,%edx + jnz next + incl 4(%ecx) +next: + movl (%ecx),%eax /* Test If quantum Has Passed If So Then */ + movl 8(%ecx),%ebx /* We Can CALL sched */ + xor %edx,%edx + div %ebx + test %edx,%edx + jnz done +/* +push %ds +push %es +push %fs +push %gs +mov $0x10,%eax +mov %eax, %ds +mov %eax, %es +mov %eax, %fs +cld +*/ +/* push %esp */ + call sched +/* add $0x4,%esp */ /* Remove Stack Pointer From Stack */ +/* +pop %gs +pop %fs +pop %es +pop %ds +*/ +done: + popa /* Restore Registers */ + iret diff --git a/sys/arch/i386/trap.c b/sys/arch/i386/trap.c new file mode 100644 index 0000000..60f0c65 --- /dev/null +++ b/sys/arch/i386/trap.c @@ -0,0 +1,133 @@ +/*- + * Copyright (c) 2002-2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include +#include + +#define FIRST_TSS_ENTRY 6 +#define VM_MASK 0x00020000 + +#define store_TR(n) \ + __asm__("str %%ax\n\t" \ + "subl %2,%%eax\n\t" \ + "shrl $4,%%eax" \ + :"=a" (n) \ + :"0" (0),"i" (FIRST_TSS_ENTRY<<3)) + +#define get_seg_long(seg,addr) ({ \ + register unsigned long __res; \ + __asm__("push %%fs;mov %%ax,%%fs;movl %%fs:%2,%%eax;pop %%fs" \ + :"=a" (__res):"0" (seg),"m" (*(addr))); \ + __res;}) + +#define get_seg_byte(seg,addr) ({ \ +register char __res; \ +__asm__("push %%fs;mov %%ax,%%fs;movb %%fs:%2,%%al;pop %%fs" \ + :"=a" (__res):"0" (seg),"m" (*(addr))); \ +__res;}) + +void die_if_kernel(char *str, struct trapframe *regs, long err) { + int i; + unsigned long esp; + unsigned short ss; + unsigned long *stack; + + esp = (unsigned long) ®s->tf_esp; + + ss = 0x10; //KERNEL_DS + + //if ((regs->tf_eflags & VM_MASK) || (3 & regs->tf_cs) == 3) + // return; + + if ((regs->tf_cs & 3) == 3) { + esp = regs->tf_esp; + ss = regs->tf_ss; + kprintf("USER TASK!"); + } + else { + ss = 0x10; + } + + kprintf("\n%s: 0x%X:%i, CPU %d, EIP: 0x%X, EFLAGS: 0x%X\n", str, regs->tf_err, regs->tf_trapno, 0x0, regs->tf_eip, regs->tf_eflags); + kprintf("eax: %08lx ebx: %08lx ecx: %08lx edx: %08lx\n", regs->tf_eax, regs->tf_ebx, regs->tf_ecx, regs->tf_edx); + kprintf("esi: %08lx edi: %08lx ebp: %08lx esp: %08lx\n", regs->tf_esi, regs->tf_edi, regs->tf_ebp, esp); + kprintf("cs: 0x%X ds: 0x%X es: 0x%X fs: 0x%X gs: 0x%X ss: 0x%X\n", regs->tf_cs, regs->tf_ds, regs->tf_es, regs->tf_fs, regs->tf_gs, ss); + kprintf("cr0: 0x%X, cr2: 0x%X, cr3: 0x%X, cr4: 0x%X\n", rcr0(), rcr2(), rcr3(), rcr4()); + + store_TR(i); + kprintf("Process %s (pid: %i, process nr: %d, stackpage=%08lx)\nStack:", _current->name, _current->id, 0xffff & i, esp); + + stack = (unsigned long *) esp; + + for (i = 0; i < 16; i++) { + if (i && ((i % 8) == 0)) + kprintf("\n "); + kprintf("%08lx ", get_seg_long(ss, stack++)); + } + + endTask(_current->id); +} + +void trap(struct trapframe *frame) { + u_int trap_code; + u_int cr2 = 0; + + trap_code = frame->tf_trapno; + + cr2 = rcr2(); + kprintf("CR2: 0x%X(0x%X)[0x%X]", cr2,_current->tss.eip,_current->tss.ldt); + if (_current->id == 7) + while(1) asm("nop"); + + if ((frame->tf_eflags & PSL_I) == 0) { + if (SEL_GET_PL(frame->tf_cs) == SEL_PL_USER || (frame->tf_eflags & PSL_VM)) { + kpanic( "INT OFF! USER" ); + die_if_kernel("TEST", frame, 0x100); + } + else { + kpanic( "INT OFF! KERN[0x%X]", trap_code ); + die_if_kernel("TEST", frame, 0x200); + } + } + + kprintf("trap_code: %i(0x%X), EIP: 0x%X, CR2: 0x%X\n", frame->tf_trapno, frame->tf_trapno, frame->tf_eip, cr2); + if (frame->tf_trapno == 0xc) { + vmm_pageFault(frame, cr2); + } + else { + kpanic("TRAPCODE"); + die_if_kernel("trapCode", frame, frame->tf_trapno); + endTask(_current->id); + sched_yield(); + } +} diff --git a/sys/armv6/Makefile b/sys/armv6/Makefile deleted file mode 100644 index de38484..0000000 --- a/sys/armv6/Makefile +++ /dev/null @@ -1,28 +0,0 @@ -# (C) 2002 The UbixOS Project -# $Id: Makefile 134 2016-01-15 14:50:24Z reddawg $ - -# Include Global 'Source' Options -include ../../Makefile.incl -include ../Makefile.incl - -# Objects -OBJS = schedyield.o kpanic.o timer.o spinlock.o i386_exec.o sys_call_new.o sys_call.o bioscall.o fork.o syscall.o systemtask.o sched.o cpu.o -# ap-boot.o smp.o vitals.o(obsolete) - -all: $(OBJS) - -# Compile Types -.cc.o: - $(CXX) -DNOBOOL $(CFLAGS) $(INCLUDES) -c -o $@ $< -.cc.s: - $(CXX) -DNOBOOL $(CFLAGS) $(INCLUDES) -S -o $@ $< -.c.o: - $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $< -.c.s: - $(CC) $(CFLAGS) $(INCLUDES) -S -o $@ $< -.S.o: - $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $< - -# Clean up the junk -clean: - $(REMOVE) $(OBJS) diff --git a/sys/armv6/ap-boot.S b/sys/armv6/ap-boot.S deleted file mode 100644 index c08bd1e..0000000 --- a/sys/armv6/ap-boot.S +++ /dev/null @@ -1,133 +0,0 @@ -/*- - * Copyright (c) 2002-2018 The UbixOS Project. - * All rights reserved. - * - * This was developed by Christopher W. Olsen for the UbixOS Project. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors. - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors in the documentation and/or - * other materials provided with the distribution. - * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * Okay, this file contains the code that's going to bootstrap the AP cpus - */ - - - .globl ap_trampoline_start,ap_trampoline_end - .text - .code16 -ap_trampoline_start: - cli - cld - - movw %cs,%ax // The CPU knows its CS already, so lets use it for the other segments - movw %ax,%ds - movw %ax,%es - movw %ax,%ss - - // Do some bochs-specific bullshit - mov $0x31,%al // '1' - mov $0xe9,%dx - outb %al,%dx - //lgdt ap_gdt; - lgdt ap_trampoline_gdt_limit - ap_trampoline_start - movl %cr0,%eax - orl $0x1,%eax - movl %eax,%cr0 // PMODE! - -.code32 - .byte 0x66 - ljmp $0x08,$(ap_trampoline_32 - ap_trampoline_start) // 0x08 == KERNEL_CS - -ap_trampoline_32: - mov $0x32,%al // '2' - mov $0xe9,%dx - outb %al,%dx - - mov $0x10,%ax - mov %ax,%ds - mov %ax,%es - mov %ax,%fs - mov %ax,%gs - mov %ax,%ss - - // Spinlock - mov ap_trampoline_spl - ap_trampoline_start,%edi -ap_spl: - //cmp $1,(%edi) - //je ap_spl - - mov $1,%eax // Value to be set - xchgl (%edi),%eax - cmp $0,%eax - je ap_spl - // /Spinlock - - mov $0x30,%al // '0' - mov $0xe9,%dx - outb %al,%dx - - mov ap_trampoline_stackptr - ap_trampoline_start,%ebx - mov %ebx,%esp - add $0x1000,%ebx - mov %ebx,ap_trampoline_stackptr - ap_trampoline_start - - mov $0x31,%al // '1' - mov $0xe9,%dx - outb %al,%dx - - // spinunlock - mov $0,%eax - mov ap_trampoline_spl - ap_trampoline_start,%edi - xchgl (%edi),%eax - // /spinunlock - - mov $0x33,%al // '3' - mov $0xe9,%dx - outb %al,%dx - - mov ap_trampoline_epoint,%eax - call *%eax -1: - hlt - jmp 1b // Halt if we ever get here somehow - - // Stack.. This sucks, since CPU initialization isn't serialized -ap_trampoline_stackptr: - .long 0x10000 // 256KB -ap_trampoline_epoint: - .long c_ap_boot - -ap_trampoline_spl: - .long 0 -ap_gdt: - .long ubixGDT - - // GDT -ap_trampoline_gdt: - .word 0 -ap_trampoline_gdt_limit: - .word 128 // Room for 32 descriptors -ap_trampoline_gdt_base: - .long 0x20000 // 128KB (move this later) - - -ap_trampoline_end: diff --git a/sys/armv6/bioscall.c b/sys/armv6/bioscall.c deleted file mode 100644 index c27a8db..0000000 --- a/sys/armv6/bioscall.c +++ /dev/null @@ -1,101 +0,0 @@ -/*- - * Copyright (c) 2002-2018 The UbixOS Project. - * All rights reserved. - * - * This was developed by Christopher W. Olsen for the UbixOS Project. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors. - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors in the documentation and/or - * other materials provided with the distribution. - * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - - -asm( - ".globl bios16Code\n" - ".code16 \n" - "bios16Code: \n" - "int $0x10 \n" - "int $0x69 \n" - ".code32 \n" - ); - - -void biosCall(int biosInt,int eax,int ebx,int ecx,int edx,int esi,int edi,int es,int ds) { - short segment = 0x0,offset = 0x0; - uInt32 tmpAddr = (uInt32)&bios16Code; - kTask_t *newProcess = 0x0; - - offset = tmpAddr & 0xF; // lower 4 bits - segment = tmpAddr >> 4; - - newProcess = schedNewTask(); - assert(newProcess); - - - newProcess->tss.back_link = 0x0; - newProcess->tss.esp0 = (uInt32)kmalloc(0x2000)+0x2000; - newProcess->tss.ss0 = 0x10; - newProcess->tss.esp1 = 0x0; - newProcess->tss.ss1 = 0x0; - newProcess->tss.esp2 = 0x0; - newProcess->tss.ss2 = 0x0; - newProcess->tss.cr3 = (uInt32)_current->tss.cr3;//(uInt32)vmmCreateVirtualSpace(newProcess->id); - newProcess->tss.eip = offset & 0xFFFF; - newProcess->tss.eflags = 2 | EFLAG_IF | EFLAG_VM; - newProcess->tss.eax = eax & 0xFFFF; - newProcess->tss.ebx = ebx & 0xFFFF; - newProcess->tss.ecx = ecx & 0xFFFF; - newProcess->tss.edx = edx & 0xFFFF; - newProcess->tss.esp = 0x1000 & 0xFFFF; - newProcess->tss.ebp = 0x1000 & 0xFFFF; - newProcess->tss.esi = esi & 0xFFFF; - newProcess->tss.edi = edi & 0xFFFF; - newProcess->tss.es = es & 0xFFFF; - newProcess->tss.cs = segment & 0xFFFF; - newProcess->tss.ss = 0x1000 & 0xFFFF; - newProcess->tss.ds = ds & 0xFFFF; - newProcess->tss.fs = 0x0 & 0xFFFF; - newProcess->tss.gs = 0x0 & 0xFFFF; - newProcess->tss.ldt = 0x0 & 0xFFFF; - newProcess->tss.trace_bitmap = 0x0 & 0xFFFF; - newProcess->tss.io_map = 0x0 & 0xFFFF; - newProcess->tss.io_map = sizeof(struct tssStruct)-8192; - newProcess->oInfo.v86Task = 0x1; - - newProcess->state = READY; - - while (newProcess->state > 0); - - return; - } - -/*** - END - ***/ - diff --git a/sys/armv6/exec.c b/sys/armv6/exec.c deleted file mode 100644 index 3af2f28..0000000 --- a/sys/armv6/exec.c +++ /dev/null @@ -1,750 +0,0 @@ -/*- - * Copyright (c) 2002-2018 The UbixOS Project. - * All rights reserved. - * - * This was developed by Christopher W. Olsen for the UbixOS Project. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors. - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors in the documentation and/or - * other materials provided with the distribution. - * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define STACK_ADDR 0xC800000 - -#define AT_NULL 0 /* Terminates the vector. */ -#define AT_IGNORE 1 /* Ignored entry. */ -#define AT_EXECFD 2 /* File descriptor of program to load. */ -#define AT_PHDR 3 /* Program header of program already loaded. */ -#define AT_PHENT 4 /* Size of each program header entry. */ -#define AT_PHNUM 5 /* Number of program header entries. */ -#define AT_PAGESZ 6 /* Page size in bytes. */ -#define AT_BASE 7 /* Interpreter's base address. */ -#define AT_FLAGS 8 /* Flags (unused for i386). */ -#define AT_ENTRY 9 /* Where interpreter should transfer control. */ - -//#define AUXARGS_ENTRY(pos, id, val) {memcpy((void *)pos++,(void *)id,sizeof(long)); memcpy((void *)pos++,(void *)val,sizeof(long));} -#define AUXARGS_ENTRY(pos, id, val) {*pos = id;pos++; *pos = val;pos++;} - -/***************************************************************************************** - - Function: execThread(void (*)(void),int,char *); - Description: This function will create a thread from code in the current memory space - - Notes: - - 05/19/04 - This does not work the way I want it to it still makes a copy of kernel space - so do not use out side of kernel space - - *****************************************************************************************/ -uInt32 execThread(void (*tproc)(void), uInt32 stack, char *arg) { - kTask_t * newProcess = 0x0; - /* Find A New Thread */ - newProcess = schedNewTask(); - assert(newProcess); - if (stack < 0x100000) - kpanic("exec: stack not in valid area: [0x%X]\n", stack); - - /* Set All The Correct Thread Attributes */ - newProcess->tss.back_link = 0x0; - newProcess->tss.esp0 = 0x0; - newProcess->tss.ss0 = 0x0; - newProcess->tss.esp1 = 0x0; - newProcess->tss.ss1 = 0x0; - newProcess->tss.esp2 = 0x0; - newProcess->tss.ss2 = 0x0; - newProcess->tss.cr3 = (unsigned int) kernelPageDirectory; - newProcess->tss.eip = (unsigned int) tproc; - newProcess->tss.eflags = 0x206; - newProcess->tss.esp = stack; - newProcess->tss.ebp = stack; - newProcess->tss.esi = 0x0; - newProcess->tss.edi = 0x0; - - /* Set these up to be ring 3 tasks */ - /* - newProcess->tss.es = 0x30+3; - newProcess->tss.cs = 0x28+3; - newProcess->tss.ss = 0x30+3; - newProcess->tss.ds = 0x30+3; - newProcess->tss.fs = 0x30+3; - newProcess->tss.gs = 0x30+3; - */ - - newProcess->tss.es = 0x10; - newProcess->tss.cs = 0x08; - newProcess->tss.ss = 0x10; - newProcess->tss.ds = 0x10; - newProcess->tss.fs = 0x10; - newProcess->tss.gs = 0x10; - - newProcess->tss.ldt = 0x18; - newProcess->tss.trace_bitmap = 0x0000; - newProcess->tss.io_map = 0x8000; - newProcess->oInfo.vmStart = 0x6400000; - - //newProcess->imageFd = 0x0; - - /* Set up default stack for thread here filled with arg list 3 times */ - asm volatile( - "pusha \n" - "movl %%esp,%%ecx \n" - "movl %1,%%eax \n" - "movl %%eax,%%esp \n" - "pushl %%ebx \n" - "pushl %%ebx \n" - "pushl %%ebx \n" - "movl %%esp,%%eax \n" - "movl %%eax,%1 \n" - "movl %%ecx,%%esp \n" - "popa \n" - : - : "b" (arg),"m" (newProcess->tss.esp) - ); - - /* Put new thread into the READY state */ - sched_setStatus(newProcess->id, READY); - - /* Return with the new process ID */ - return ((uInt32) newProcess); -} - -/***************************************************************************************** - - Function: void execFile(char *file); - Description: This Function Executes A Kile Into A New VM Space With Out - Having To Fork - Notes: - - 07/30/02 - I Have Made Some Heavy Changes To This As Well As Fixed A Few - Memory Leaks The Memory Allocated To Load The Binary Into Is - Now Unmapped So It Can Be Used Again And Not Held Onto Until - The Program Exits - - 07/30/02 - Now I Have To Make A Better Memory Allocator So We Can Set Up - The Freshly Allocated Pages With The Correct Permissions - - *****************************************************************************************/ -void execFile(char *file, int argc, char **argv, int console) { - - int i = 0x0; - int x = 0x0; - uint32_t *tmp = 0x0; - - fileDescriptor *tmpFd = 0x0; - elfHeader *binaryHeader = 0x0; - elfProgramHeader *programHeader = 0x0; - - /* Get A New Task For This Proccess */ - _current = schedNewTask(); - assert(_current); - _current->gid = 0x0; - _current->uid = 0x0; - _current->term = tty_find(console); - if (_current->term == 0x0) - kprintf("Error: invalid console\n"); - - /* Set tty ownership */ - _current->term->owner = _current->id; - - /* Now We Must Create A Virtual Space For This Proccess To Run In */ - _current->tss.cr3 = (uInt32) vmmCreateVirtualSpace(_current->id); - - /* To Better Load This Application We Will Switch Over To Its VM Space */ - asm volatile( - "movl %0,%%eax \n" - "movl %%eax,%%cr3 \n" - : : "d" ((uInt32 *)(_current->tss.cr3)) - ); - - /* Lets Find The File */ - tmpFd = fopen(file, "r"); - - /* If We Dont Find the File Return */ - if (tmpFd == 0x0) { - kprintf("Exec Format Error: Binary File Not Executable.\n"); - fclose(tmpFd); - return; - } - if (tmpFd->perms == 0x0) { - kprintf("Exec Format Error: Binary File Not Executable.\n"); - fclose(tmpFd); - return; - } - - /* Load ELF Header */ - binaryHeader = (elfHeader *) kmalloc(sizeof(elfHeader)); - - //kprintf(">a:%i:0x%X:0x%X<",sizeof(elfHeader),binaryHeader,tmpFd); - fread(binaryHeader, sizeof(elfHeader), 1, tmpFd); - - /* Check If App Is A Real Application */ - if ((binaryHeader->eIdent[1] != 'E') && (binaryHeader->eIdent[2] != 'L') && (binaryHeader->eIdent[3] != 'F')) { - kprintf("Exec Format Error: Binary File Not Executable.\n"); - kfree(binaryHeader); - fclose(tmpFd); - return; - } - else if (binaryHeader->eType != 2) { - kprintf("Exec Format Error: Binary File Not Executable.\n"); - kfree(binaryHeader); - fclose(tmpFd); - return; - } - else if (binaryHeader->eEntry == 0x300000) { - kprintf("Exec Format Error: Binary File Not Executable.\n"); - kfree(binaryHeader); - fclose(tmpFd); - return; - } - - /* Load The Program Header(s) */ - programHeader = (elfProgramHeader *) kmalloc(sizeof(elfProgramHeader) * binaryHeader->ePhnum); - fseek(tmpFd, binaryHeader->ePhoff, 0); - - //kprintf(">c:%i:0x%X:0x%X<",sizeof(elfProgramHeader)*binaryHeader->ePhnum,programHeader,tmpFd); - fread(programHeader, (sizeof(elfProgramHeader) * binaryHeader->ePhnum), 1, tmpFd); - //kprintf(">d<"); - - /* Loop Through The Header And Load Sections Which Need To Be Loaded */ - for (i = 0; i < binaryHeader->ePhnum; i++) { - if (programHeader[i].phType == 1) { - /* - Allocate Memory Im Going To Have To Make This Load Memory With Correct - Settings so it helps us in the future - */ - for (x = 0x0; x < (programHeader[i].phMemsz); x += 0x1000) { - /* Make readonly and read/write !!! */ - if (vmm_remapPage(vmm_findFreePage(_current->id), ((programHeader[i].phVaddr & 0xFFFFF000) + x), PAGE_DEFAULT) == 0x0) - K_PANIC("Remap Page Failed"); - - memset((void *) ((programHeader[i].phVaddr & 0xFFFFF000) + x), 0x0, 0x1000); - } - _current->oInfo.vmStart = 0x80000000; - _current->td.vm_daddr = (char *) (programHeader[i].phVaddr & 0xFFFFF000); - /* Now Load Section To Memory */ - fseek(tmpFd, programHeader[i].phOffset, 0); - fread((void *) programHeader[i].phVaddr, programHeader[i].phFilesz, 1, tmpFd); - if ((programHeader[i].phFlags & 0x2) != 0x2) { - kprintf("pH: [0x%X]\n", programHeader[i].phMemsz); - for (x = 0x0; x < (programHeader[i].phMemsz); x += 0x1000) { - if ((vmm_setPageAttributes((programHeader[i].phVaddr & 0xFFFFF000) + x, PAGE_PRESENT | PAGE_USER)) != 0x0) - kpanic("Error: vmm_setPageAttributes failed, File: %s, Line: %i\n", __FILE__, __LINE__); - } - } - } - } - - /* Set Virtual Memory Start */ - _current->oInfo.vmStart = 0x80000000; - _current->td.vm_daddr = (char *) (programHeader[i].phVaddr & 0xFFFFF000); - - /* Set Up Stack Space */ - for (x = 1; x < 100; x++) { - vmm_remapPage(vmm_findFreePage(_current->id), STACK_ADDR - (x * 0x1000), PAGE_DEFAULT | PAGE_STACK); - } - - /* Kernel Stack 0x2000 bytes long */ - vmm_remapPage(vmm_findFreePage(_current->id), 0x5BC000, KERNEL_PAGE_DEFAULT | PAGE_STACK); - vmm_remapPage(vmm_findFreePage(_current->id), 0x5BB000, KERNEL_PAGE_DEFAULT | PAGE_STACK); - - /* Set All The Proper Information For The Task */ - _current->tss.back_link = 0x0; - _current->tss.esp0 = 0x5BC000; - _current->tss.ss0 = 0x10; - _current->tss.esp1 = 0x0; - _current->tss.ss1 = 0x0; - _current->tss.esp2 = 0x0; - _current->tss.ss2 = 0x0; - _current->tss.eip = (long) binaryHeader->eEntry; - _current->tss.eflags = 0x206; - _current->tss.esp = STACK_ADDR - 12; - _current->tss.ebp = STACK_ADDR; - _current->tss.esi = 0x0; - _current->tss.edi = 0x0; - - /* Set these up to be ring 3 tasks */ - _current->tss.es = 0x30 + 3; - _current->tss.cs = 0x28 + 3; - _current->tss.ss = 0x30 + 3; - _current->tss.ds = 0x30 + 3; - _current->tss.fs = 0x30 + 3; - _current->tss.gs = 0x30 + 3; - - _current->tss.ldt = 0x18; - _current->tss.trace_bitmap = 0x0000; - _current->tss.io_map = 0x8000; - - sched_setStatus(_current->id, READY); - - kfree(binaryHeader); - kfree(programHeader); - fclose(tmpFd); - - tmp = (uInt32 *) _current->tss.esp0 - 5; - tmp[0] = binaryHeader->eEntry; - tmp[3] = STACK_ADDR - 12; - - tmp = (uInt32 *) STACK_ADDR - 2; - - if (_current->id > 4) - kprintf("argv[0]: [%s]\n", argv[0]); - kprintf("argv: [0x%X]\n", argv); - tmp[0] = (uint32_t) argv; - tmp[1] = (uint32_t) argv; - - /* Switch Back To The Kernels VM Space */ - asm volatile( - "movl %0,%%eax \n" - "movl %%eax,%%cr3 \n" - : : "d" ((uInt32 *)(kernelPageDirectory)) - ); - - /* Finally Return */ - return; -} - -/***************************************************************************************** - - Function: void sysExec(); - Description: This Is The System Call To Execute A New Task - - Notes: - 04-22-03 - It Now Loads Sections Not The Full File - - *****************************************************************************************/ -void sysExec(char *file, char *ap) { - int i = 0x0; - int x = 0x0; - int argc = 0x0; - unsigned int *tmp = 0x0; - uInt32 ldAddr = 0x0; - uInt32 seg_size = 0x0; - uInt32 seg_addr = 0x0; - char *interp = 0x0; - char **argv = 0x0; - char **argvNew = 0x0; - char *args = 0x0; - - fileDescriptor *tmpFd = 0x0; - elfHeader *binaryHeader = 0x0; - elfProgramHeader *programHeader = 0x0; - elfSectionHeader *sectionHeader = 0x0; - elfDynamic *elfDynamicS = 0x0; - struct i386_frame *iFrame = 0x0; - - tmpFd = fopen(file, "r"); - _current->files[0] = tmpFd; - /* If We Dont Find the File Return */ - if (tmpFd == 0x0) { - return; - } - if (tmpFd->perms == 0) { - kprintf("Exec Format Error: Binary File Not Executable.\n"); - fclose(tmpFd); - return; - } - - /* Load ELF Header */ - - if ((binaryHeader = (elfHeader *) kmalloc(sizeof(elfHeader))) == 0x0) - endTask(_current->id); - fread(binaryHeader, sizeof(elfHeader), 1, tmpFd); - /* Set sectionHeader To Point To Loaded Binary To We Can Gather Info */ - - /* Check If App Is A Real Application */ - if ((binaryHeader->eIdent[1] != 'E') && (binaryHeader->eIdent[2] != 'L') && (binaryHeader->eIdent[3] != 'F')) { - kprintf("Exec Format Error: Binary File Not Executable.\n"); - kfree(binaryHeader); - fclose(tmpFd); - - return; - } - else if (binaryHeader->eType != 2) { - kprintf("Exec Format Error: Binary File Not Executable.\n"); - kfree(binaryHeader); - fclose(tmpFd); - return; - } - else if (binaryHeader->eEntry == 0x300000) { - kprintf("Exec Format Error: Binary File Not Executable.\n"); - kfree(binaryHeader); - fclose(tmpFd); - return; - } - - /* Load The Program Header(s) */ - if ((programHeader = (elfProgramHeader *) kmalloc(sizeof(elfProgramHeader) * binaryHeader->ePhnum)) == 0x0) - endTask(_current->id); - - assert(programHeader); - fseek(tmpFd, binaryHeader->ePhoff, 0); - fread(programHeader, (sizeof(elfProgramHeader) * binaryHeader->ePhnum), 1, tmpFd); - - if ((sectionHeader = (elfSectionHeader *) kmalloc(sizeof(elfSectionHeader) * binaryHeader->eShnum)) == 0x0) - endTask(_current->id); - - assert(sectionHeader); - fseek(tmpFd, binaryHeader->eShoff, 0); - fread(sectionHeader, sizeof(elfSectionHeader) * binaryHeader->eShnum, 1, tmpFd); - - /* Loop Through The Header And Load Sections Which Need To Be Loaded */ - for (i = 0; i < binaryHeader->ePhnum; i++) { - switch (programHeader[i].phType) { - case PT_LOAD: - seg_addr = trunc_page(programHeader[i].phVaddr); - seg_size = round_page(programHeader[i].phMemsz + programHeader[i].phVaddr - seg_addr); - - /* - Allocate Memory Im Going To Have To Make This Load Memory With Correct - Settings so it helps us in the future - */ - for (x = 0x0; x < (programHeader[i].phMemsz); x += 0x1000) { - /* Make readonly and read/write !!! */ - if (vmm_remapPage(vmm_findFreePage(_current->id), ((programHeader[i].phVaddr & 0xFFFFF000) + x), PAGE_DEFAULT) == 0x0) - K_PANIC("Error: Remap Page Failed"); - memset((void *) ((programHeader[i].phVaddr & 0xFFFFF000) + x), 0x0, 0x1000); - } - - /* Now Load Section To Memory */ - fseek(tmpFd, programHeader[i].phOffset, 0); - fread((void *) programHeader[i].phVaddr, programHeader[i].phFilesz, 1, tmpFd); - if ((programHeader[i].phFlags & 0x2) != 0x2) { - for (x = 0x0; x < (programHeader[i].phMemsz); x += 0x1000) { - if ((vmm_setPageAttributes((programHeader[i].phVaddr & 0xFFFFF000) + x, PAGE_PRESENT | PAGE_USER)) != 0x0) - kpanic("Error: vmm_setPageAttributes failed, File: %s,Line: %i\n", __FILE__, __LINE__); - } - } - kprintf("setting daddr\n"); - if (binaryHeader->eEntry >= programHeader[i].phVaddr && binaryHeader->eEntry < (programHeader[i].phVaddr + programHeader[i].phMemsz)) { - /* We're suposed to do something here? */ - } - else { - _current->td.vm_dsize = seg_size >> PAGE_SHIFT; - _current->td.vm_daddr = (char *) seg_addr; - } - - _current->oInfo.vmStart = ((programHeader[i].phVaddr & 0xFFFFF000) + 0xA900000); - break; - case PT_DYNAMIC: - //newLoc = (char *)programHeader[i].phVaddr; - elfDynamicS = (elfDynamic *) programHeader[i].phVaddr; - fseek(tmpFd, programHeader[i].phOffset, 0); - fread((void *) programHeader[i].phVaddr, programHeader[i].phFilesz, 1, tmpFd); - break; - case PT_INTERP: - interp = (char *) kmalloc(programHeader[i].phFilesz); - fseek(tmpFd, programHeader[i].phOffset, 0); - fread((void *) interp, programHeader[i].phFilesz, 1, tmpFd); - kprintf("Interp: [%s]\n", interp); - ldAddr = ldEnable(); - break; - default: - break; - } - } - - /* What is this doing? 11/23/06 */ - if (elfDynamicS != 0x0) { - for (i = 0; i < 12; i++) { - if (elfDynamicS[i].dynVal == 0x3) { - tmp = (void *) elfDynamicS[i].dynPtr; - if (tmp == 0x0) - kpanic("tmp: NULL\n"); - tmp[2] = (uInt32) ldAddr; - tmp[1] = (uInt32) tmpFd; - break; - } - /* - else { - kprintf("dyn_val: %i",elfDynamicS[i].dynVal); - } - */ - } - } - - _current->td.vm_dsize = seg_size >> PAGE_SHIFT; - _current->td.vm_daddr = (char *) seg_addr; - - argv = ≈ - - if (argv[1] != 0x0) { - argc = (int) argv[0]; - args = (char *) vmmGetFreeVirtualPage(_current->id, 1, VM_TASK); - memset(args, 0x0, 0x1000); - x = 0x0; - argvNew = (char **) kmalloc(sizeof(char *) * argc); - for (i = 0x0; i < argc; i++) { - strcpy(args + x, argv[i + 1]); - argvNew[i] = args + x; - x += strlen(argv[i + 1]) + 1; - //args[x] = '\0'; - //x++; - } - argv = argvNew; - } - - //! Clean the virtual of COW pages left over from the fork - vmm_cleanVirtualSpace(_current->td.vm_daddr + (_current->td.vm_dsize << PAGE_SIZE)); - - //! Adjust iframe - iFrame = (struct i386_frame *) _current->tss.esp0 - sizeof(struct i386_frame); - iFrame->ebp = STACK_ADDR; - iFrame->eip = binaryHeader->eEntry; - iFrame->user_esp = STACK_ADDR - 12; - - //if (_current->id > 3) { - - iFrame->user_esp = ((uint32_t) STACK_ADDR) - (sizeof(uint32_t) * (argc + 3)); - tmp = (void *) iFrame->user_esp; - - //! build argc and argv[] - tmp[0] = argc; - for (i = 0; i < argc; i++) { - tmp[i + 1] = (u_int) argv[i]; - } - tmp[argc + 1] = 0x0; - tmp[argc + 2] = 0x1; - //} - //else { - //tmp = (uint32_t *)STACK_ADDR - 2; - //tmp[0] = 0x1; - //tmp[1] = 0x0; - //tmp[1] = (uint32_t)argv; - //} - kfree(argvNew); - /* Now That We Relocated The Binary We Can Unmap And Free Header Info */ - kfree(binaryHeader); - kfree(programHeader); - - return; -} - -/*! - * \brief New exec... - * - */ -void sys_exec(char *file, char *ap) { - int error = 0x0; - int i = 0x0; - int x = 0x0; - int argc = 0x0; - uint32_t *tmp = 0x0; - uint32_t seg_size = 0x0; - uint32_t seg_addr = 0x0; - uint32_t addr = 0x0; - uint32_t eip = 0x0; - uint32_t proghdr = 0x0; - char *args = 0x0; - char *interp = 0x0; - char **argv = 0x0; - char **argvNew = 0x0; - elfHeader *binaryHeader = 0x0; - elfProgramHeader *programHeader = 0x0; - struct i386_frame *iFrame = 0x0; - //Elf_Auxargs *auxargs = 0x0; - - _current->files[0] = fopen(file, "r"); - if (_current->files[0] == 0x0) - return; //We Need To Set errno - - /* Load the ELF header */ - if ((binaryHeader = (elfHeader *) kmalloc(sizeof(elfHeader))) == 0x0) - K_PANIC("malloc failed!"); - fread(binaryHeader, sizeof(elfHeader), 1, _current->files[0]); - - /* Check If App Is A Real Application */ - if (((binaryHeader->eIdent[1] != 'E') && (binaryHeader->eIdent[2] != 'L') && (binaryHeader->eIdent[3] != 'F')) || (binaryHeader->eType != ET_EXEC)) { - kfree(binaryHeader); - fclose(_current->files[0]); - return; //We Need To Set errno - } - - /* Load The Program Header(s) */ - if ((programHeader = (elfProgramHeader *) kmalloc(sizeof(elfProgramHeader) * binaryHeader->ePhnum)) == 0x0) - K_PANIC("malloc failed!"); - fseek(_current->files[0], binaryHeader->ePhoff, 0); - fread(programHeader, (sizeof(elfProgramHeader) * binaryHeader->ePhnum), 1, _current->files[0]); - - /* Loop Through The Header And Load Sections Which Need To Be Loaded */ - for (i = 0x0; i < binaryHeader->ePhnum; i++) { - switch (programHeader[i].phType) { - case PT_LOAD: - seg_addr = trunc_page(programHeader[i].phVaddr); - seg_size = round_page(programHeader[i].phMemsz + programHeader[i].phVaddr - seg_addr); - - /* - Allocate Memory Im Going To Have To Make This Load Memory With Correct - Settings so it helps us in the future - */ - for (x = 0x0; x < (programHeader[i].phMemsz); x += 0x1000) { - /* Make readonly and read/write !!! */ - if (vmm_remapPage(vmm_findFreePage(_current->id), ((programHeader[i].phVaddr & 0xFFFFF000) + x), PAGE_DEFAULT) == 0x0) - K_PANIC("Error: Remap Page Failed"); - memset((void *) ((programHeader[i].phVaddr & 0xFFFFF000) + x), 0x0, 0x1000); - } - - /* Now Load Section To Memory */ - fseek(_current->files[0], programHeader[i].phOffset, 0); - fread((void *) programHeader[i].phVaddr, programHeader[i].phFilesz, 1, _current->files[0]); - if ((programHeader[i].phFlags & 0x2) != 0x2) { - for (x = 0x0; x < (programHeader[i].phMemsz); x += 0x1000) { - if ((vmm_setPageAttributes((programHeader[i].phVaddr & 0xFFFFF000) + x, PAGE_PRESENT | PAGE_USER)) != 0x0) - K_PANIC("vmm_setPageAttributes failed"); - } - } - if (binaryHeader->eEntry >= programHeader[i].phVaddr && binaryHeader->eEntry < (programHeader[i].phVaddr + programHeader[i].phMemsz)) { - /* We're suposed to do something here? */ - } - else { - _current->td.vm_dsize = seg_size >> PAGE_SHIFT; - _current->td.vm_daddr = (char *) seg_addr; - } - - _current->oInfo.vmStart = ((programHeader[i].phVaddr & 0xFFFFF000) + 0xA900000); - break; - case PT_INTERP: - interp = (char *) kmalloc(programHeader[i].phFilesz); - if (interp == 0x0) - K_PANIC("malloc failed") - ; - - fseek(_current->files[0], programHeader[i].phOffset, 0); - fread((void *) interp, programHeader[i].phFilesz, 1, _current->files[0]); - kprintf("Interp: [%s]\n", interp); - //ldAddr = ldEnable(); - break; - case PT_PHDR: - proghdr = programHeader[i].phVaddr; - break; - default: - break; - } - } - - addr = LD_START; - - if (interp != 0x0) { - //kprintf("TEST"); - elf_loadfile(_current, interp, &addr, &eip); - } - //kprintf("[0x%X][0x%X]\n",eip,addr); - - _current->td.vm_dsize = seg_size >> PAGE_SHIFT; - _current->td.vm_daddr = (char *) seg_addr; - - //! copy in arg strings - argv = ap; - - if (argv[1] != 0x0) { - argc = argv[0]; - args = (char *) vmmGetFreeVirtualPage(_current->id, 1, VM_TASK); - memset(args, 0x0, 0x1000); - x = 0x0; - argvNew = (char **) kmalloc(sizeof(char *) * argc); - for (i = 0x0; i < argc; i++) { - strcpy(args + x, argv[i + 1]); - argvNew[i] = args + x; - x += strlen(argv[i + 1]) + 1; - } - argv = argvNew; - } - - //! Clean the virtual of COW pages left over from the fork - vmm_cleanVirtualSpace(_current->td.vm_daddr + (_current->td.vm_dsize << PAGE_SIZE)); - - //! Adjust iframe - iFrame = _current->tss.esp0 - sizeof(struct i386_frame); - iFrame->ebp = STACK_ADDR; - iFrame->eip = eip; - - //if (_current->id > 3) { - - iFrame->user_esp = ((uint32_t) STACK_ADDR) - (sizeof(uint32_t) * (argc + 4)); // + (sizeof(Elf_Auxargs) * 2))); - kprintf("\n\n\nuser_esp: [0x%X]\n", iFrame->user_esp); - tmp = iFrame->user_esp; - - //! build argc and argv[] - tmp[0] = argc; - for (i = 0; i < argc; i++) { - tmp[i + 1] = argv[i]; - } - //! Build ENV - args = (char *) vmmGetFreeVirtualPage(_current->id, 1, VM_TASK); - memset(args, 0x0, 0x1000); - strcpy(args, "LIBRARY_PATH=/lib"); - tmp[argc + 2] = args; - kprintf("env: [0x%X][0x%X]\n", (uInt32) tmp + argc + 2, tmp[argc + 2]); - tmp[argc + 3] = 0x0; - kprintf("env: [0x%X][0x%X]\n", (uInt32) tmp + argc + 2, tmp[argc + 2]); - //auxargs = iFrame->user_esp + argc + 3; - tmp = iFrame->user_esp; - tmp += argc + 4; - - /* - auxargs->execfd = -1; - auxargs->phdr = proghdr; - auxargs->phent = binaryHeader->ePhentsize; - auxargs->phnum = binaryHeader->ePhnum; - auxargs->pagesz = PAGE_SIZE; - auxargs->base = addr; - auxargs->flags = 0x0; - auxargs->entry = binaryHeader->eEntry; - auxargs->trace = 0x0; - - AUXARGS_ENTRY(tmp, AT_PHDR, auxargs->phdr); - AUXARGS_ENTRY(tmp, AT_PHENT, auxargs->phent); - AUXARGS_ENTRY(tmp, AT_PHNUM, auxargs->phnum); - AUXARGS_ENTRY(tmp, AT_PAGESZ, auxargs->pagesz); - AUXARGS_ENTRY(tmp, AT_FLAGS, auxargs->flags); - AUXARGS_ENTRY(tmp, AT_ENTRY, auxargs->entry); - AUXARGS_ENTRY(tmp, AT_BASE, auxargs->base); - AUXARGS_ENTRY(tmp, AT_NULL, 0); - - kprintf("AT_BASE: [0x%X]\n",auxargs->base); - */ - - //iFrame->ebx = 0x0; - //iFrame->ebx = 0x0; - //iFrame->eip = binaryHeader->eEntry; - //kprintf("\n\nDOH: [0x%X]\n\n",iFrame->eip); -//while (1); - //while (1); - /* - error = elf_loadfile(_current,file,0x0,0x0); - if (error) - K_PANIC("elf_loadfile failed"); - */ - return; -} - -/*** - END - ***/ diff --git a/sys/armv6/fork.c b/sys/armv6/fork.c deleted file mode 100644 index 20fcde6..0000000 --- a/sys/armv6/fork.c +++ /dev/null @@ -1,128 +0,0 @@ -/*- - * Copyright (c) 2002-2018 The UbixOS Project. - * All rights reserved. - * - * This was developed by Christopher W. Olsen for the UbixOS Project. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors. - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors in the documentation and/or - * other materials provided with the distribution. - * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -/***************************************************************************************** - Functoin: static int fork_copyProcess(struct taskStruct *newProcess,long ebp,long edi, - long esi, long none,long ebx,long ecx,long edx,long eip,long cs,long eflags, - long esp,long ss) - - Desc: This function will copy a process - - Notes: - - *****************************************************************************************/ -/* Had to remove static though tihs function is only used in this file */ -int fork_copyProcess(struct taskStruct *newProcess, long ebp, long edi, long esi, long none, long ebx, long ecx, long edx, long eip, long cs, long eflags, long esp, long ss) { - volatile struct taskStruct * tmpProcPtr = newProcess; - assert(newProcess); - assert(_current); - - /* Set Up New Tasks Information */ - memcpy(newProcess->oInfo.cwd, _current->oInfo.cwd, 1024); - - newProcess->tss.eip = eip; - newProcess->oInfo.vmStart = _current->oInfo.vmStart; - newProcess->term = _current->term; - newProcess->term->owner = newProcess->id; - newProcess->uid = _current->uid; - newProcess->gid = _current->gid; - newProcess->tss.back_link = 0x0; - newProcess->tss.esp0 = _current->tss.esp0; - newProcess->tss.ss0 = 0x10; - newProcess->tss.esp1 = 0x0; - newProcess->tss.ss1 = 0x0; - newProcess->tss.esp2 = 0x0; - newProcess->tss.ss2 = 0x0; - newProcess->tss.eflags = eflags; - newProcess->tss.eax = 0x0; - newProcess->tss.ebx = ebx; - newProcess->tss.ecx = ecx; - newProcess->tss.edx = edx; - newProcess->tss.esi = esi; - newProcess->tss.edi = edi; - newProcess->tss.ebp = ebp; - newProcess->tss.esp = esp; - newProcess->tss.cs = cs & 0xFF; - newProcess->tss.ss = ss & 0xFF; - newProcess->tss.ds = _current->tss.ds & 0xFF; - newProcess->tss.fs = _current->tss.fs & 0xFF; - newProcess->tss.gs = _current->tss.gs & 0xFF; - newProcess->tss.es = _current->tss.es & 0xFF; - newProcess->tss.ldt = 0x18; - newProcess->tss.trace_bitmap = 0x0000; - newProcess->tss.io_map = 0x8000; - /* Create A Copy Of The VM Space For New Task */ - newProcess->tss.cr3 = (uInt32) vmmCopyVirtualSpace(newProcess->id); - newProcess->state = FORK; - - /* Fix gcc optimization problems */ - while (tmpProcPtr->state == FORK) - sched_yield(); - - /* Return Id of Proccess */ - return (newProcess->id); -} - -/***************************************************************************************** - Functoin: void sysFork(); - - Desc: This function will fork a new task - - Notes: - - 08/01/02 - This Seems To Be Working Fine However I'm Not Sure If I - Chose The Best Path To Impliment It I Guess We Will See - What The Future May Bring - - *****************************************************************************************/ -asm( - ".globl sysFork \n" - "sysFork: \n" - " xor %eax,%eax \n" - " call schedNewTask \n" - " testl %eax,%eax \n" - " je fork_ret \n" - " pushl %esi \n" - " pushl %edi \n" - " pushl %ebp \n" - " pushl %eax \n" - " call fork_copyProcess \n" - " movl %eax,(%ebx) \n" - " addl $16,%esp \n" - "fork_ret: \n" - " ret \n" -); diff --git a/sys/armv6/kpanic.c b/sys/armv6/kpanic.c deleted file mode 100644 index e4b43c7..0000000 --- a/sys/armv6/kpanic.c +++ /dev/null @@ -1,66 +0,0 @@ -/*- - * Copyright (c) 2002-2018 The UbixOS Project. - * All rights reserved. - * - * This was developed by Christopher W. Olsen for the UbixOS Project. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors. - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors in the documentation and/or - * other materials provided with the distribution. - * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include - -/*! - * \brief print panic message and halt system - * - * \param fmt panic message - * - */ -void kpanic(const char *fmt, ...) { - char buf[512]; - va_list args; - - vaStart(args, fmt); - vsprintf(buf, fmt, args); - vaEnd(args); - - /* It's important that we print on the current terminal so let's reset foreground */ - tty_foreground = NULL; - kprintf("kPanic: %s", buf); - - /* Halt The System */ - //asm("cli"); - irqDisable(0x0); - - while (1) { - asm("hlt"); - } - -} - -/*** - END - ***/ - diff --git a/sys/armv6/sched.c b/sys/armv6/sched.c deleted file mode 100644 index 5f6ffc6..0000000 --- a/sys/armv6/sched.c +++ /dev/null @@ -1,279 +0,0 @@ -/*- - * Copyright (c) 2002-2018 The UbixOS Project. - * All rights reserved. - * - * This was developed by Christopher W. Olsen for the UbixOS Project. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors. - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors in the documentation and/or - * other materials provided with the distribution. - * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -static kTask_t *taskList = 0x0; -static kTask_t *delList = 0x0; -static uInt32 nextID = -1; - -kTask_t *_current = 0x0; -kTask_t *_usedMath = 0x0; - -static struct spinLock schedulerSpinLock = SPIN_LOCK_INITIALIZER; - -/************************************************************************ - - Function: int sched_init() - - Description: This function is used to enable the kernel scheduler - - Notes: - - 02/20/2004 - Approved for quality - - ************************************************************************/ - -int sched_init() { - taskList = (kTask_t *) kmalloc(sizeof(kTask_t)); - if (taskList == 0x0) - kpanic("Unable to create task list"); - - taskList->id = nextID++; - - /* Print out information on scheduler */ - kprintf("sched0 - Address: [0x%X]\n", taskList); - - /* Return so we know everything went well */ - return (0x0); -} - -void sched() { - uInt32 memAddr = 0x0; - kTask_t *tmpTask = 0x0; - kTask_t *delTask = 0x0; - - if (!spinTryLock(&schedulerSpinLock)) - return; - - tmpTask = _current->next; - //outportByte(0xE9,_current->id + '0'); - schedStart: - - /* Yield the next task from the current prio queue */ - for (; tmpTask != 0x0; tmpTask = tmpTask->next) { - if (tmpTask->state > 0x0) { - _current = tmpTask; - if (_current->state == FORK) - _current->state = READY; - break; - } - else if (tmpTask->state == DEAD) { - delTask = tmpTask; - tmpTask = tmpTask->next; - sched_deleteTask(delTask->id); - sched_addDelTask(delTask); - goto schedStart; - } - } - - /* Finished all the tasks, restarting the list */ - if (0x0 == tmpTask) { - tmpTask = taskList; - goto schedStart; - } - - if (_current->state > 0x0) { - if (_current->oInfo.v86Task == 0x1) - irqDisable(0x0); - asm("cli"); - memAddr = (uInt32) &(_current->tss); - ubixGDT[4].descriptor.baseLow = (memAddr & 0xFFFF); - ubixGDT[4].descriptor.baseMed = ((memAddr >> 16) & 0xFF); - ubixGDT[4].descriptor.baseHigh = (memAddr >> 24); - ubixGDT[4].descriptor.access = '\x89'; - spinUnlock(&schedulerSpinLock); - asm("sti"); - asm("ljmp $0x20,$0\n"); - } - else { - spinUnlock(&schedulerSpinLock); - } - - return; -} - -kTask_t *schedNewTask() { - int i = 0; - kTask_t *tmpTask = (kTask_t *) kmalloc(sizeof(kTask_t)); - struct file *fp = 0x0; - if (tmpTask == 0x0) - kpanic("Error: schedNewTask() - kmalloc failed trying to initialize a new task struct\n"); - - memset(tmpTask, 0x0, sizeof(kTask_t)); - /* Filling in tasks attrs */ - tmpTask->usedMath = 0x0; - tmpTask->state = NEW; - - /* HACK */ - for (i = 0; i < 3; i++) { - fp = (void *) kmalloc(sizeof(struct file)); - tmpTask->td.o_files[i] = (uint32_t) fp; - fp->f_flag = 0x4; - } - - spinLock(&schedulerSpinLock); - tmpTask->id = nextID++; - tmpTask->next = taskList; - tmpTask->prev = 0x0; - taskList->prev = tmpTask; - taskList = tmpTask; - - spinUnlock(&schedulerSpinLock); - - return (tmpTask); -} - -int sched_deleteTask(pidType id) { - kTask_t *tmpTask = 0x0; - - /* Checking each task from the prio queue */ - for (tmpTask = taskList; tmpTask != 0x0; tmpTask = tmpTask->next) { - if (tmpTask->id == id) { - if (tmpTask->prev != 0x0) - tmpTask->prev->next = tmpTask->next; - if (tmpTask->next != 0x0) - tmpTask->next->prev = tmpTask->prev; - if (taskList == tmpTask) - taskList = tmpTask->next; - - return (0x0); - } - } - return (0x1); -} - -int sched_addDelTask(kTask_t *tmpTask) { - tmpTask->next = delList; - tmpTask->prev = 0x0; - if (delList != 0x0) - delList->prev = tmpTask; - delList = tmpTask; - return (0x0); -} - -kTask_t *sched_getDelTask() { - kTask_t *tmpTask = 0x0; - - if (delList == 0x0) - return (0x0); - - tmpTask = delList; - delList = delList->next; - return (tmpTask); -} - -kTask_t * -schedFindTask(uInt32 id) { - kTask_t *tmpTask = 0x0; - - for (tmpTask = taskList; tmpTask; tmpTask = tmpTask->next) { - if (tmpTask->id == id) - return (tmpTask); - } - - return (0x0); -} - -/************************************************************************ - - Function: void schedEndTask() - - Description: This function will end a task - - Notes: - - 02/20/2004 - Approved for quality - - ************************************************************************/ -void schedEndTask(pidType pid) { - endTask(_current->id); - sched_yield(); -} - -/************************************************************************ - - Function: int schedEndTask() - - Description: This function will yield a task - - Notes: - - 02/20/2004 - Approved for quality - - ************************************************************************/ - -void sched_yield() { - sched(); -} - -/* - asm( - ".globl sched_yield \n" - "sched_yield: \n" - " cli \n" - " call sched \n" - ); - */ - -/************************************************************************ - - Function: int sched_setStatus(pidType pid,tState state) - - Description: Change the tasks status - - Notes: - - ************************************************************************/ -int sched_setStatus(pidType pid, tState state) { - kTask_t *tmpTask = schedFindTask(pid); - if (tmpTask == 0x0) - return (0x1); - tmpTask->state = state; - return (0x0); -} - -/*** - END - ***/ - diff --git a/sys/armv6/schedyield.S b/sys/armv6/schedyield.S deleted file mode 100644 index 1072793..0000000 --- a/sys/armv6/schedyield.S +++ /dev/null @@ -1,51 +0,0 @@ -/*- - * Copyright (c) 2002-2018 The UbixOS Project. - * All rights reserved. - * - * This was developed by Christopher W. Olsen for the UbixOS Project. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors. - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors in the documentation and/or - * other materials provided with the distribution. - * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -.globl sched_yield_new -.text -.code32 -sched_yield_new: - pusha /* Save all of the registers */ - push %ss - push %ds - push %es - push %fs - push %gs - call sched - mov %eax,%esp - pop %gs - pop %fs - pop %es - pop %ds - pop %ss - popa /* Restore Registers */ - iret - -/*** - END - ***/ diff --git a/sys/armv6/spinlock.c b/sys/armv6/spinlock.c deleted file mode 100644 index 790d1fb..0000000 --- a/sys/armv6/spinlock.c +++ /dev/null @@ -1,77 +0,0 @@ -/*- - * Copyright (c) 2002-2018 The UbixOS Project. - * All rights reserved. - * - * This was developed by Christopher W. Olsen for the UbixOS Project. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors. - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors in the documentation and/or - * other materials provided with the distribution. - * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include - -void spinLockInit(spinLock_t *lock) { - *lock = SPIN_LOCK_INITIALIZER; - } - -void spinUnlock(spinLock_t *lock) { - *lock = 0x0; - /* - register int unlocked; - asm volatile( - "xchgl %0, %1" - : "=&r" (unlocked), "=m" (*lock) : "0" (0) - ); - */ - } - -int spinTryLock(spinLock_t *lock) { - register int locked; - asm volatile("xchgl %0, %1" - : "=&r" (locked), "=m" (*lock) : "0" (1) - ); - return(!locked); - } - -void spinLock(spinLock_t *lock) { - while (!spinTryLock(lock)) - { - while (*lock == 1) - sched_yield(); - } -} - -void spinLock_scheduler(spinLock_t *lock) { - while (!spinTryLock(lock)) - while (*lock == 1); - } - - -int spinLockLocked(spinLock_t *lock) { - return(*lock != 0); - } - - -/*** - END - ***/ - diff --git a/sys/armv6/sys_call.S b/sys/armv6/sys_call.S deleted file mode 100644 index b4a557e..0000000 --- a/sys/armv6/sys_call.S +++ /dev/null @@ -1,54 +0,0 @@ -/*- - * Copyright (c) 2002-2018 The UbixOS Project. - * All rights reserved. - * - * This was developed by Christopher W. Olsen for the UbixOS Project. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors. - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors in the documentation and/or - * other materials provided with the distribution. - * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -.globl _sysCall -.text -.code32 -_sysCall: - cmpl totalCalls,%eax - jae invalidSysCall - - cld - pushl %edx - pushl %ecx - pushl %ebx - call *systemCalls(,%eax,4) - popl %ebx - popl %ecx - popl %edx /* Restore Registers */ - - iret - -invalidSysCall: - movl $-1,%eax - iret - -/*** - END - ***/ - diff --git a/sys/armv6/sys_call_new.S b/sys/armv6/sys_call_new.S deleted file mode 100644 index 2f73600..0000000 --- a/sys/armv6/sys_call_new.S +++ /dev/null @@ -1,67 +0,0 @@ -/*- - * Copyright (c) 2002-2018 The UbixOS Project. - * All rights reserved. - * - * This was developed by Christopher W. Olsen for the UbixOS Project. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors. - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors in the documentation and/or - * other materials provided with the distribution. - * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#define FAKE_MCOUNT(caller) pushl caller ; call __mcount ; popl %ecx - -.globl _sysCall_new -.text -.code32 -_sysCall_new: - pushl $2 /* sizeof "int 0x80" */ - subl $4,%esp /* skip over tf_trapno */ - pushal - pushl %ds - pushl %es - pushl %fs - /* switch to kernel segments */ - movl $0x10,%eax - movl %eax,%ds - movl %eax,%es - movl %eax,%fs - //FAKE_MCOUNT(TF_EIP(%esp)) - call syscall - //MEXITCOUNT - //jmp doreti - popl %fs - popl %es - popl %ds - popal - addl $8,%esp - iret - -invalidSysCall: - push %eax - call invalidCall - pop %eax - movl $-1,%eax - iret - -/*** - END - ***/ - diff --git a/sys/armv6/syscall.c b/sys/armv6/syscall.c deleted file mode 100644 index 36a81d8..0000000 --- a/sys/armv6/syscall.c +++ /dev/null @@ -1,247 +0,0 @@ -/*- - * Copyright (c) 2002-2018 The UbixOS Project. - * All rights reserved. - * - * This was developed by Christopher W. Olsen for the UbixOS Project. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors. - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors in the documentation and/or - * other materials provided with the distribution. - * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -/* #include */ -#include -#include - -//long fuword(const void *base); - -//void sdeTestThread(); - -asm( - ".globl _sysCallNew \n" - "_sysCallNew: \n" - " pusha \n" - " push %ss \n" - " push %ds \n" - " push %es \n" - " push %fs \n" - " push %gs \n" - " cmpl totalCalls,%eax \n" - " jae invalidSysCallNew \n" - " mov %esp,%ebx \n" - " add $12,%ebx \n" - " push (%ebx) \n" - " call *systemCalls(,%eax,4) \n" - " add $4,%esp \n" - " jmp doneNew \n" - "invalidSysCallNew: \n" - " call InvalidSystemCall \n" - "doneNew: \n" - " pop %gs \n" - " pop %fs \n" - " pop %es \n" - " pop %ds \n" - " pop %ss \n" - " popa \n" - " iret \n" -); - -void InvalidSystemCall() { - kprintf("attempt was made to an invalid system call\n"); - return; -} - -typedef struct _UbixUser UbixUser; -struct _UbixUser { - char *username; - char *password; - int uid; - int gid; - char *home; - char *shell; -}; - -void sysAuth(UbixUser *uu) { - kprintf("authenticating user %s\n", uu->username); - - /* MrOlsen 2016-01-01 uh? - if(uu->username == "root" && uu->password == "user") - { - uu->uid = 0; - uu->gid = 0; - } - */ - uu->uid = -1; - uu->gid = -1; - return; -} - -void sysPasswd(char *passwd) { - kprintf("changing user password for user %d\n", _current->uid); - return; -} - -void sysAddModule() { - return; -} - -void sysRmModule() { - return; -} - -void sysGetpid(int *pid) { - if (pid) - *pid = _current->id; - return; -} - -void sysGetUid(int *uid) { - if (uid) - *uid = _current->uid; - return; -} - -void sysGetGid(int *gid) { - if (gid) - *gid = _current->gid; - return; -} - -void sysSetUid(int uid, int *status) { - if (_current->uid == 0x0) { - _current->uid = uid; - if (status) - *status = 0x0; - } - else { - if (status) - *status = 1; - } - return; -} - -void sysSetGid(int gid, int *status) { - if (_current->gid == 0x0) { - _current->gid = gid; - if (status) - *status = 0x0; - } - else { - if (status) - *status = 1; - } - return; -} - -void sysExit(int status) { - endTask(_current->id); -} - -void sysCheckPid(int pid, int *ptr) { - kTask_t *tmpTask = schedFindTask(pid); - if ((tmpTask != 0x0) && (ptr != 0x0)) - *ptr = tmpTask->state; - else - *ptr = 0x0; - return; -} - -/************************************************************************ - - Function: void sysGetFreePage(); - Description: Allocs A Page To The Users VM Space - Notes: - - ************************************************************************/ -void sysGetFreePage(long *ptr, int count, int type) { - if (ptr) { - if (type == 2) - *ptr = (long) vmmGetFreeVirtualPage(_current->id, count, VM_THRD); - else - *ptr = (long) vmmGetFreeVirtualPage(_current->id, count, VM_TASK); - } - return; -} - -void sysGetDrives(uInt32 *ptr) { - if (ptr) - *ptr = 0x0; //(uInt32)devices; - return; -} - -void sysGetUptime(uInt32 *ptr) { - if (ptr) - *ptr = systemVitals->sysTicks; - return; -} - -void sysGetTime(uInt32 *ptr) { - if (ptr) - *ptr = systemVitals->sysUptime + systemVitals->timeStart; - return; -} - -void sysGetCwd(char *data, int len) { - if (data) - sprintf(data, "%s", _current->oInfo.cwd); - return; -} - -void sysSchedYield() { - sched_yield(); -} - -void sysStartSDE() { - int i = 0x0; - for (i = 0; i < 1400; i++) { - asm("hlt"); - } - //execThread(sdeThread,(uInt32)(kmalloc(0x2000)+0x2000),0x0); - for (i = 0; i < 1400; i++) { - asm("hlt"); - } - return; -} - -void invalidCall(int sys_call) { - kprintf("Invalid System Call #[%i]\n", sys_call); - return; -} - -/*** - END - ***/ - diff --git a/sys/armv6/systemtask.c b/sys/armv6/systemtask.c deleted file mode 100644 index c0a999e..0000000 --- a/sys/armv6/systemtask.c +++ /dev/null @@ -1,122 +0,0 @@ -/*- - * Copyright (c) 2002-2018 The UbixOS Project. - * All rights reserved. - * - * This was developed by Christopher W. Olsen for the UbixOS Project. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors. - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors in the documentation and/or - * other materials provided with the distribution. - * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static unsigned char *videoBuffer = (char *)0xB8000; - - -void systemTask() { - mpi_message_t myMsg; - uInt32 counter = 0x0; - int i = 0x0; - int *x = 0x0; - kTask_t *tmpTask = 0x0; - - if (mpi_createMbox("system") != 0x0) { - kpanic("Error: Error creating mailbox: system\n"); - } - - while(1) { - if (mpi_fetchMessage("system",&myMsg) == 0x0) { - kprintf("A"); - switch(myMsg.header) { - case 0x69: - x = (int *)&myMsg.data; - kprintf("Switching to term: [%i][%i]\n",*x,myMsg.pid); - schedFindTask(myMsg.pid)->term = tty_find(*x); - break; - case 1000: - kprintf("Restarting the system in 5 seconds\n"); - counter = systemVitals->sysUptime + 5; - while (systemVitals->sysUptime < counter) { - sched_yield(); - } - kprintf("Rebooting NOW!!!\n"); - while(inportByte(0x64) & 0x02); - outportByte(0x64, 0xFE); - break; - case 31337: - kprintf("system: backdoor opened\n"); - break; - case 0x80: - if (!strcmp(myMsg.data,"sdeStart")) { - kprintf("Starting SDE\n"); - //execThread(sdeThread,(uInt32)(kmalloc(0x2000)+0x2000),0x0); - } - else if (!strcmp(myMsg.data,"freePage")) { - kprintf("kkk Free Pages"); - } - else if (!strcmp(myMsg.data,"sdeStop")) { - printOff = 0x0; - biosCall(0x10,0x3,0x0,0x0,0x0,0x0,0x0,0x0,0x0); - for (i=0x0;i<100;i++) asm("hlt"); - } - break; - default: - kprintf("system: Received message %i:%s\n",myMsg.header,myMsg.data); - break; - } - } - - /* - Here we get the next task from the delete task queue - we first check to see if it has an fd attached for the binary and after that - we free the pages for the process and then free the task - */ - tmpTask = sched_getDelTask(); - if (tmpTask != 0x0) { - if (tmpTask->files[0] != 0x0) - fclose(tmpTask->files[0]); - vmmFreeProcessPages(tmpTask->id); - kfree(tmpTask); - } - videoBuffer[0] = systemVitals->sysTicks; - sched_yield(); - } - - return; - } - -/*** - END - ***/ - diff --git a/sys/armv6/timer.S b/sys/armv6/timer.S deleted file mode 100644 index c7aa642..0000000 --- a/sys/armv6/timer.S +++ /dev/null @@ -1,61 +0,0 @@ -/*- - * Copyright (c) 2002-2018 The UbixOS Project. - * All rights reserved. - * - * This was developed by Christopher W. Olsen for the UbixOS Project. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors. - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors in the documentation and/or - * other materials provided with the distribution. - * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -.globl timerInt -.text -.code32 -timerInt: - pusha /* Save all of the registers */ - mov $0x20,%dx /* The Following Sends Our EOI To The MPIC */ - mov $0x20,%ax - outb %al,%dx - movl systemVitals,%ecx /* Put Location Of System Vitals Into ECX */ - incl 4(%ecx) /* Increment sysTicks our 1000ms counter */ - movl 4(%ecx),%eax /* Increment our sysUptime by 1S if 1000MS */ - movl $200,%ebx /* Have Passed */ - xor %edx,%edx - div %ebx - test %edx,%edx - jnz next - incl 8(%ecx) -next: - movl 4(%ecx),%eax /* Test If quantum Has Passed If So Then */ - movl 12(%ecx),%ebx /* We Can CALL sched */ - xor %edx,%edx - div %ebx - test %edx,%edx - jnz done - call sched -done: - popa /* Restore Registers */ - iret - -/*** - END - ***/ - diff --git a/sys/compile/Makefile b/sys/compile/Makefile index 341c4c1..4f28ac4 100644 --- a/sys/compile/Makefile +++ b/sys/compile/Makefile @@ -9,7 +9,7 @@ OBJS = null.o #Kernel Parts -KPARTS = ../${_ARCH}/*.o ../init/*.o ../sys/*.o ../vmm/*.o ../lib/*.o ../kernel/*.o ../isa/*.o ../fs/vfs/*.o ../pci/*.o ../fs/devfs/*.o ../mpi/*.o ../fs/ufs/*.o ../fs/common/*.o ../net/net/*.o ../net/netif/*.o ../net/api/*.o ../net/core/*.o ../net/core/ipv4/*.o ../sde/*.o +KPARTS = ../arch/${_ARCH}/*.o ../init/*.o ../sys/*.o ../vmm/*.o ../lib/*.o ../kernel/*.o ../isa/*.o ../fs/vfs/*.o ../pci/*.o ../fs/devfs/*.o ../mpi/*.o ../fs/ufs/*.o ../fs/common/*.o ../net/net/*.o ../net/netif/*.o ../net/api/*.o ../net/core/*.o ../net/core/ipv4/*.o ../sde/*.o # ../net/core/ipv6/*.o # ../fs/ubixfs/*.o # ../sde/*.o ../graphics/*.o ../ld/*.o -Ttext 0x30000 -Tdata 0x34000 ../ubixfs/*.o diff --git a/sys/fs/ubixfs/thread.c b/sys/fs/ubixfs/thread.c old mode 100644 new mode 100755 diff --git a/sys/i386/Makefile b/sys/i386/Makefile deleted file mode 100644 index 0ce7291..0000000 --- a/sys/i386/Makefile +++ /dev/null @@ -1,28 +0,0 @@ -# (C) 2002 The UbixOS Project -# $Id: Makefile 202 2016-01-23 15:21:35Z reddawg $ - -# Include Global 'Source' Options -include ../../Makefile.incl -include ../Makefile.incl - -# Objects -OBJS = support.o strcpy.o strcmp.o strncmp.o memset.o memcmp.o schedyield.o kpanic.o timer.o spinlock.o i386_exec.o sys_call_posix.o sys_call.o bioscall.o fork.o systemtask.o sched.o cpu.o trap.o bios16code.o -# ap-boot.o smp.o vitals.o(obsolete) - -all: $(OBJS) - -# Compile Types -.cc.o: - $(CXX) -DNOBOOL $(CFLAGS) $(INCLUDES) -c -o $@ $< -.cc.s: - $(CXX) -DNOBOOL $(CFLAGS) $(INCLUDES) -S -o $@ $< -.c.o: - $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $< -.c.s: - $(CC) $(CFLAGS) $(INCLUDES) -S -o $@ $< -.S.o: - $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $< - -# Clean up the junk -clean: - $(REMOVE) $(OBJS) diff --git a/sys/i386/ap-boot.S b/sys/i386/ap-boot.S deleted file mode 100644 index c08bd1e..0000000 --- a/sys/i386/ap-boot.S +++ /dev/null @@ -1,133 +0,0 @@ -/*- - * Copyright (c) 2002-2018 The UbixOS Project. - * All rights reserved. - * - * This was developed by Christopher W. Olsen for the UbixOS Project. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors. - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors in the documentation and/or - * other materials provided with the distribution. - * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * Okay, this file contains the code that's going to bootstrap the AP cpus - */ - - - .globl ap_trampoline_start,ap_trampoline_end - .text - .code16 -ap_trampoline_start: - cli - cld - - movw %cs,%ax // The CPU knows its CS already, so lets use it for the other segments - movw %ax,%ds - movw %ax,%es - movw %ax,%ss - - // Do some bochs-specific bullshit - mov $0x31,%al // '1' - mov $0xe9,%dx - outb %al,%dx - //lgdt ap_gdt; - lgdt ap_trampoline_gdt_limit - ap_trampoline_start - movl %cr0,%eax - orl $0x1,%eax - movl %eax,%cr0 // PMODE! - -.code32 - .byte 0x66 - ljmp $0x08,$(ap_trampoline_32 - ap_trampoline_start) // 0x08 == KERNEL_CS - -ap_trampoline_32: - mov $0x32,%al // '2' - mov $0xe9,%dx - outb %al,%dx - - mov $0x10,%ax - mov %ax,%ds - mov %ax,%es - mov %ax,%fs - mov %ax,%gs - mov %ax,%ss - - // Spinlock - mov ap_trampoline_spl - ap_trampoline_start,%edi -ap_spl: - //cmp $1,(%edi) - //je ap_spl - - mov $1,%eax // Value to be set - xchgl (%edi),%eax - cmp $0,%eax - je ap_spl - // /Spinlock - - mov $0x30,%al // '0' - mov $0xe9,%dx - outb %al,%dx - - mov ap_trampoline_stackptr - ap_trampoline_start,%ebx - mov %ebx,%esp - add $0x1000,%ebx - mov %ebx,ap_trampoline_stackptr - ap_trampoline_start - - mov $0x31,%al // '1' - mov $0xe9,%dx - outb %al,%dx - - // spinunlock - mov $0,%eax - mov ap_trampoline_spl - ap_trampoline_start,%edi - xchgl (%edi),%eax - // /spinunlock - - mov $0x33,%al // '3' - mov $0xe9,%dx - outb %al,%dx - - mov ap_trampoline_epoint,%eax - call *%eax -1: - hlt - jmp 1b // Halt if we ever get here somehow - - // Stack.. This sucks, since CPU initialization isn't serialized -ap_trampoline_stackptr: - .long 0x10000 // 256KB -ap_trampoline_epoint: - .long c_ap_boot - -ap_trampoline_spl: - .long 0 -ap_gdt: - .long ubixGDT - - // GDT -ap_trampoline_gdt: - .word 0 -ap_trampoline_gdt_limit: - .word 128 // Room for 32 descriptors -ap_trampoline_gdt_base: - .long 0x20000 // 128KB (move this later) - - -ap_trampoline_end: diff --git a/sys/i386/bios16code.S b/sys/i386/bios16code.S deleted file mode 100644 index b86ee01..0000000 --- a/sys/i386/bios16code.S +++ /dev/null @@ -1,5 +0,0 @@ -.globl bios16Code -bios16Code: -.code16 -int $0x10 -int $0x69 diff --git a/sys/i386/bioscall.c b/sys/i386/bioscall.c deleted file mode 100644 index e3d3094..0000000 --- a/sys/i386/bioscall.c +++ /dev/null @@ -1,90 +0,0 @@ -/*- - * Copyright (c) 2002-2018 The UbixOS Project. - * All rights reserved. - * - * This was developed by Christopher W. Olsen for the UbixOS Project. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors. - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors in the documentation and/or - * other materials provided with the distribution. - * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -void biosCall(int biosInt, int eax, int ebx, int ecx, int edx, int esi, int edi, int es, int ds) { - short segment = 0x0, offset = 0x0; - uint32_t tmpAddr = (uint32_t) &bios16Code; - kTask_t *newProcess = 0x0; - - offset = tmpAddr & 0xF; // lower 4 bits - segment = tmpAddr >> 4; - - newProcess = schedNewTask(); - assert(newProcess); - - newProcess->tss.back_link = 0x0; - newProcess->tss.esp0 = (uint32_t) vmm_getFreeKernelPage(newProcess->id, 2) + (0x2000 - 0x4); // XXX I had 0xDEADBEEF I'm not sure why - newProcess->tss.ss0 = 0x10; - newProcess->tss.esp1 = 0x0; - newProcess->tss.ss1 = 0x0; - newProcess->tss.esp2 = 0x0; - newProcess->tss.ss2 = 0x0; - newProcess->tss.cr3 = kernelPageDirectory; //vmm_createVirtualSpace(newProcess->id); //(uint32_t)_current->tss.cr3; - newProcess->tss.eip = offset & 0xFFFF; - newProcess->tss.eflags = 2 | EFLAG_IF | EFLAG_VM; - newProcess->tss.eax = eax & 0xFFFF; - newProcess->tss.ebx = ebx & 0xFFFF; - newProcess->tss.ecx = ecx & 0xFFFF; - newProcess->tss.edx = edx & 0xFFFF; - newProcess->tss.esp = 0x1000 & 0xFFFF; - newProcess->tss.ebp = 0x1000 & 0xFFFF; - newProcess->tss.esi = esi & 0xFFFF; - newProcess->tss.edi = edi & 0xFFFF; - newProcess->tss.es = es & 0xFFFF; - newProcess->tss.cs = segment & 0xFFFF; - newProcess->tss.ss = 0x1000 & 0xFFFF; - newProcess->tss.ds = ds & 0xFFFF; - newProcess->tss.fs = 0x0 & 0xFFFF; - newProcess->tss.gs = 0x0 & 0xFFFF; - newProcess->tss.ldt = 0x0 & 0xFFFF; - newProcess->tss.trace_bitmap = 0x0 & 0xFFFF; - newProcess->tss.io_map = 0x0 & 0xFFFF; - newProcess->tss.io_map = sizeof(struct tssStruct) - 8192; - newProcess->oInfo.v86Task = 0x1; - - kprintf("EIP: [0x%X] 0x%X:0x%X", tmpAddr, newProcess->tss.eip, newProcess->tss.cs); - - newProcess->state = READY; - while (newProcess->state > 0) - sched_yield(); - - kprintf("EIP: [0x%X] 0x%X:0x%X!", tmpAddr, newProcess->tss.eip, newProcess->tss.cs); - kprintf("CALL DONE: %i 0x%X 0x%X!", newProcess->state, newProcess->tss.esp, newProcess->tss.ss); - - return; -} diff --git a/sys/i386/cpu.c b/sys/i386/cpu.c deleted file mode 100644 index ef9e0c0..0000000 --- a/sys/i386/cpu.c +++ /dev/null @@ -1,29 +0,0 @@ -/*- - * Copyright (c) 2002-2018 The UbixOS Project. - * All rights reserved. - * - * This was developed by Christopher W. Olsen for the UbixOS Project. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors. - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors in the documentation and/or - * other materials provided with the distribution. - * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include diff --git a/sys/i386/fork.c b/sys/i386/fork.c deleted file mode 100644 index 3e222f8..0000000 --- a/sys/i386/fork.c +++ /dev/null @@ -1,228 +0,0 @@ -/*- - * Copyright (c) 2002-2018 The UbixOS Project. - * All rights reserved. - * - * This was developed by Christopher W. Olsen for the UbixOS Project. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors. - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors in the documentation and/or - * other materials provided with the distribution. - * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -int sys_fork(struct thread *td, struct sys_fork_args *args) { - struct taskStruct *newProcess; - - newProcess = schedNewTask(); - - /* - * - * Initalize New Task Information From Parrent - * - */ - - /* Set CWD */ - memcpy(newProcess->oInfo.cwd, _current->oInfo.cwd, 1024); - - /* Set PPID */ - newProcess->ppid = _current->id; - - /* Set PGRP */ - newProcess->pgrp = _current->pgrp; - - /* Set Up Task State */ - newProcess->tss.eip = td->frame->tf_eip; - newProcess->oInfo.vmStart = _current->oInfo.vmStart; - newProcess->term = _current->term; - newProcess->term->owner = newProcess->id; - newProcess->uid = _current->uid; - newProcess->gid = _current->gid; - newProcess->tss.back_link = 0x0; - newProcess->tss.esp0 = _current->tss.esp0; - newProcess->tss.ss0 = 0x10; - newProcess->tss.esp1 = 0x0; - newProcess->tss.ss1 = 0x0; - newProcess->tss.esp2 = 0x0; - newProcess->tss.ss2 = 0x0; - newProcess->tss.eflags = td->frame->tf_eflags; - newProcess->tss.eax = 0x0; - newProcess->tss.ebx = td->frame->tf_ebx; - newProcess->tss.ecx = td->frame->tf_ecx; - newProcess->tss.edx = td->frame->tf_edx; - newProcess->tss.esi = td->frame->tf_esi; - newProcess->tss.edi = td->frame->tf_edi; - newProcess->tss.ebp = td->frame->tf_ebp; - newProcess->tss.esp = td->frame->tf_esp; - newProcess->tss.cs = td->frame->tf_cs; // & 0xFF; - newProcess->tss.ss = td->frame->tf_ss; // & 0xFF; - newProcess->tss.ds = td->frame->tf_ds; //_current->tss.ds & 0xFF; - newProcess->tss.fs = td->frame->tf_fs; //_current->tss.fs & 0xFF; - newProcess->tss.gs = _current->tss.gs & 0xFF; - newProcess->tss.es = td->frame->tf_es; //_current->tss.es & 0xFF; - newProcess->tss.ldt = 0x18; - newProcess->tss.trace_bitmap = 0x0000; - newProcess->tss.io_map = 0x8000; - - newProcess->td.vm_tsize = _current->td.vm_tsize; - newProcess->td.vm_taddr = _current->td.vm_taddr; - newProcess->td.vm_dsize = _current->td.vm_dsize; - newProcess->td.vm_daddr = _current->td.vm_daddr; - - //kprintf("Copying Mem Space! [0x%X:0x%X:0x%X:0x%X:0x%X:%i:%i]\n", newProcess->tss.esp0, newProcess->tss.esp, newProcess->tss.ebp, td->frame->tf_esi, td->frame->tf_eip, newProcess->id, _current->id); - - newProcess->tss.cr3 = (uInt32) vmm_copyVirtualSpace(newProcess->id); - //kprintf( "Copied Mem Space! [0x%X]\n", newProcess->tss.cr3 ); - - newProcess->state = FORK; - /* Fix gcc optimization problems */ - while (newProcess->state == FORK) - sched_yield(); - - newProcess->parent = _current; - _current->children++; - - /* Return Id of Proccess */ - td->td_retval[0] = newProcess->id; - return (0); - -} - -/***************************************************************************************** - Functoin: static int fork_copyProcess(struct taskStruct *newProcess,long ebp,long edi, - long esi, long none,long ebx,long ecx,long edx,long eip,long cs,long eflags, - long esp,long ss) - - Desc: This function will copy a process - - Notes: - - *****************************************************************************************/ - -/* Had to remove static though tihs function is only used in this file */ -int fork_copyProcess(struct taskStruct *newProcess, long ebp, long edi, long esi, long none, long ebx, long ecx, long edx, long eip, long cs, long eflags, long esp, long ss) { - volatile struct taskStruct * tmpProcPtr = newProcess; - assert(newProcess); - assert(_current); - - /* Set Up New Tasks Information */ - memcpy(newProcess->oInfo.cwd, _current->oInfo.cwd, 1024); - //kprintf( "Initializing New CWD!\n" ); - - newProcess->tss.eip = eip; - newProcess->oInfo.vmStart = _current->oInfo.vmStart; - newProcess->term = _current->term; - newProcess->term->owner = newProcess->id; - newProcess->uid = _current->uid; - newProcess->gid = _current->gid; - newProcess->tss.back_link = 0x0; - newProcess->tss.esp0 = _current->tss.esp0; - newProcess->tss.ss0 = 0x10; - newProcess->tss.esp1 = 0x0; - newProcess->tss.ss1 = 0x0; - newProcess->tss.esp2 = 0x0; - newProcess->tss.ss2 = 0x0; - newProcess->tss.eflags = eflags; - newProcess->tss.eax = 0x0; - newProcess->tss.ebx = ebx; - newProcess->tss.ecx = ecx; - newProcess->tss.edx = edx; - newProcess->tss.esi = esi; - newProcess->tss.edi = edi; - newProcess->tss.ebp = ebp; - newProcess->tss.esp = esp; - newProcess->tss.cs = cs & 0xFF; - newProcess->tss.ss = ss & 0xFF; - newProcess->tss.ds = _current->tss.ds & 0xFF; - newProcess->tss.fs = _current->tss.fs & 0xFF; - newProcess->tss.gs = _current->tss.gs & 0xFF; - newProcess->tss.es = _current->tss.es & 0xFF; - newProcess->tss.ldt = 0x18; - newProcess->tss.trace_bitmap = 0x0000; - newProcess->tss.io_map = 0x8000; - - newProcess->td.vm_tsize = _current->td.vm_tsize; - newProcess->td.vm_taddr = _current->td.vm_taddr; - newProcess->td.vm_dsize = _current->td.vm_dsize; - newProcess->td.vm_daddr = _current->td.vm_daddr; - - /* Create A Copy Of The VM Space For New Task */ - //MrOlsen 2018kprintf("Copying Mem Space! [0x%X:0x%X:0x%X:0x%X:0x%X:%i:%i:0x%X]\n", newProcess->tss.esp0, newProcess->tss.esp, newProcess->tss.ebp, esi, eip, newProcess->id, _current->id, newProcess->td.vm_daddr); - newProcess->tss.cr3 = (uInt32) vmm_copyVirtualSpace(newProcess->id); - //kprintf( "Copied Mem Space!\n" ); - - newProcess->state = FORK; - - /* Fix gcc optimization problems */ - while (tmpProcPtr->state == FORK) - sched_yield(); - /* Return Id of Proccess */ - kprintf("Returning! [%i]", _current->id); - - return (newProcess->id); -} - -void qT() { - kprintf("qT\n"); -} - -/***************************************************************************************** - Functoin: void sysFork(); - - Desc: This function will fork a new task - - Notes: - - 08/01/02 - This Seems To Be Working Fine However I'm Not Sure If I - Chose The Best Path To Impliment It I Guess We Will See - What The Future May Bring - - *****************************************************************************************/ -//asm volatile( -__asm( - ".globl sysFork_old \n" - "sysFork_old: \n" - " xor %eax,%eax \n" - " call schedNewTask \n" - " testl %eax,%eax \n" - " je fork_ret \n" - " pushl %esi \n" - " pushl %edi \n" - " pushl %ebp \n" - " pushl %eax \n" - " call fork_copyProcess \n" - " movl %eax,(%ebx) \n" - " addl $16,%esp \n" - "fork_ret: \n" - " ret \n" -); - -/*** - END - ***/ - diff --git a/sys/i386/i386_exec.c b/sys/i386/i386_exec.c deleted file mode 100644 index ae96533..0000000 --- a/sys/i386/i386_exec.c +++ /dev/null @@ -1,996 +0,0 @@ -/*- - * Copyright (c) 2002-2018 The UbixOS Project. - * All rights reserved. - * - * This was developed by Christopher W. Olsen for the UbixOS Project. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors. - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors in the documentation and/or - * other materials provided with the distribution. - * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define ENVP_PAGE 0x100 -#define ARGV_PAGE 0x100 -#define ELF_AUX 0x100 -#define STACK_PAD 0x1000 - -#define ENOEXEC -1 - -#define AT_NULL 0 /* Terminates the vector. */ -#define AT_IGNORE 1 /* Ignored entry. */ -#define AT_EXECFD 2 /* File descriptor of program to load. */ -#define AT_PHDR 3 /* Program header of program already loaded. */ -#define AT_PHENT 4 /* Size of each program header entry. */ -#define AT_PHNUM 5 /* Number of program header entries. */ -#define AT_PAGESZ 6 /* Page size in bytes. */ -#define AT_BASE 7 /* Interpreter's base address. */ -#define AT_FLAGS 8 /* Flags (unused for i386). */ -#define AT_ENTRY 9 /* Where interpreter should transfer control. */ - -#define AUXARGS_ENTRY(pos, id, val) {*pos = id;pos++; *pos = val;pos++;} - -static int argv_count(char **argv) { - int i = 0; - - while (*argv++ != 0x0) - i++; - - return (i); -} - -static int envp_count(char **envp) { - int i = 0; - - while (*envp++ != 0x0) - i++; - - return (i); -} - -static int args_copyin(char **argv_in, char **argv_out, char **args_out) { - - int argc = argv_count(argv_in); - - uint32_t *argv_tmp = (uint32_t *) kmalloc(sizeof(char *) * (argc + 2)); // + 1 For ARGC + 1 For NULL TERM - - char *args_tmp = (char *) kmalloc(ARGV_PAGE); - - argv_tmp[0] = argc; - - uint32_t sp = 0x0; - - int i = 0x0; - - for (i = 1; i <= argc; i++) { - argv_tmp[i] = (uint32_t)(args_tmp + sp); - strcpy((char *)argv_tmp[i], argv_in[i - 1]); - sp += strlen(argv_in[i - 1]) + 1; - } - - argv_tmp[i++] = 0x0; - - *argv_out = (char *)argv_tmp; - *args_out = args_tmp; - - return (0); - -} - -static int envs_copyin(char **envp_in, char **envp_out, char **envs_out) { - - int envc = envp_count(envp_in); - - uint32_t *envp_tmp = (uint32_t *) kmalloc(sizeof(char *) * (envc + 1)); // + 1 For NULL TERM - - char *envs_tmp = (char *) kmalloc(ENVP_PAGE); - - uint32_t sp = 0x0; - - int i = 0x0; - - for (i = 0; i < envc; i++) { - envp_tmp[i] = (uint32_t)(envs_tmp + sp); - strcpy((char *)envp_tmp[i], envp_in[i]); - sp += strlen(envp_in[i]) + 1; - } - envp_tmp[i++] = 0x0; - - *envp_out = (char *)envp_tmp; - *envs_out = envs_tmp; - return (0); -} - -static int elf_parse_dynamic(elf_file_t ef); - -/***************************************************************************************** - - Function: execThread(void (*)(void),int,char *); - Description: This function will create a thread from code in the current memory space - - Notes: - - 05/19/04 - This does not work the way I want it to it still makes a copy of kernel space - so do not use out side of kernel space - - *****************************************************************************************/ -uint32_t execThread(void (*tproc)(void), uint32_t stack, char *arg) { - - kTask_t * newProcess = 0x0; - uint32_t stackAddr = 0x0; - - /* Find A New Thread */ - newProcess = schedNewTask(); - assert(newProcess); - - stackAddr = vmm_getFreeKernelPage(newProcess->id, stack / PAGE_SIZE); - - /* Set All The Correct Thread Attributes */ - newProcess->tss.back_link = 0x0; - newProcess->tss.esp0 = 0x0; - newProcess->tss.ss0 = 0x0; - newProcess->tss.esp1 = 0x0; - newProcess->tss.ss1 = 0x0; - newProcess->tss.esp2 = 0x0; - newProcess->tss.ss2 = 0x0; - newProcess->tss.cr3 = (unsigned int) kernelPageDirectory; - newProcess->tss.eip = (unsigned int) tproc; - newProcess->tss.eflags = 0x206; - newProcess->tss.esp = stackAddr + (stack - 0x4); //stack; - newProcess->tss.ebp = 0x0;//stack; - newProcess->tss.esi = 0x0; - newProcess->tss.edi = 0x0; - - /* Ring 3 Selectors */ - /* - newProcess->tss.es = 0x30+3; - newProcess->tss.cs = 0x28+3; - newProcess->tss.ss = 0x30+3; - newProcess->tss.ds = 0x30+3; - newProcess->tss.fs = 0x30+3; - newProcess->tss.gs = 0x30+3; - */ - - /* Ring 0 Selectors */ - newProcess->tss.es = 0x10; - newProcess->tss.cs = 0x08; - newProcess->tss.ss = 0x10; - newProcess->tss.ds = 0x10; - newProcess->tss.fs = 0x10; - newProcess->tss.gs = 0x10; - - newProcess->tss.ldt = 0x18; - newProcess->tss.trace_bitmap = 0x0000; - newProcess->tss.io_map = 0x8000; - newProcess->oInfo.vmStart = 0x6400000; - - if (newProcess->files[0] != 0x0) - kpanic("Problem With File Descriptors"); - - newProcess->files[0] = 0x0; - - //kprintf("EIP: 0x%X(%i)", tproc, newProcess->id); - - /* Set up default stack for thread here filled with arg list 3 times */ - asm volatile( - "pusha \n" - "movl %%esp,%%ecx \n" - "movl %1,%%eax \n" - "movl %%eax,%%esp \n" - "pushl %%ebx \n" - "pushl %%ebx \n" - "pushl %%ebx \n" - "movl %%esp,%%eax \n" - "movl %%eax,%1 \n" - "movl %%ecx,%%esp \n" - "popa \n" - : - : "b" (arg),"m" (newProcess->tss.esp) - ); - - /* Put new thread into the READY state */ - sched_setStatus(newProcess->id, READY); - - /* Return with the new process ID */ - return ((uint32_t) newProcess); -} - -/***************************************************************************************** - - Function: void execFile(char *file); - Description: This Function Executes A Kile Into A New VM Space With Out - Having To Fork - Notes: - - 07/30/02 - I Have Made Some Heavy Changes To This As Well As Fixed A Few - Memory Leaks The Memory Allocated To Load The Binary Into Is - Now Unmapped So It Can Be Used Again And Not Held Onto Until - The Program Exits - - 07/30/02 - Now I Have To Make A Better Memory Allocator So We Can Set Up - The Freshly Allocated Pages With The Correct Permissions - - *****************************************************************************************/ -void execFile(char *file, char **argv, char **envp, int console) { - - kTask_t *newProcess = 0x0; - - int i = 0x0; - int x = 0x0; - - uint32_t *tmp = 0x0; - - Elf_Ehdr *binaryHeader = 0x0; - - Elf_Phdr *programHeader = 0x0; - - int argc = argv_count(argv); - int envc = envp_count(envp); - - /* Get A New Task For This Proccess */ - newProcess = schedNewTask(); - assert(newProcess); - - newProcess->gid = 0x0; - newProcess->uid = 0x0; - newProcess->pgrp = newProcess->id; - newProcess->term = tty_find(console); - - if (newProcess->term == 0x0) - kprintf("Error: invalid console\n"); - - /* Set tty ownership */ - newProcess->term->owner = newProcess->id; - - /* Now We Must Create A Virtual Space For This Proccess To Run In */ - newProcess->tss.cr3 = (uint32_t) vmm_createVirtualSpace(newProcess->id); - - /* To Better Load This Application We Will Switch Over To Its VM Space */ - asm volatile( - "movl %0,%%eax \n" - "movl %%eax,%%cr3 \n" - : : "d" ((uint32_t *)(newProcess->tss.cr3)) - ); - - /* Lets Find The File */ - if (newProcess->files[0] != 0x0) - kpanic("Problem With File Descriptors"); - newProcess->files[0] = fopen(file, "r"); - - /* If We Dont Find the File Return */ - if (newProcess->files[0] == 0x0) { - kprintf("Exec Format Error: Binary File Not Executable.\n"); - fclose(newProcess->files[0]); - return; - } - - if (newProcess->files[0]->perms == 0x0) { - kprintf("Exec Format Error: Binary File Not Executable.\n"); - fclose(newProcess->files[0]); - return; - } - - /* Load ELF Header */ - binaryHeader = (Elf_Ehdr *) kmalloc(sizeof(Elf_Ehdr)); - - fread(binaryHeader, sizeof(Elf_Ehdr), 1, newProcess->files[0]); - - /* Check If App Is A Real Application */ - if ((binaryHeader->e_ident[1] != 'E') && (binaryHeader->e_ident[2] != 'L') && (binaryHeader->e_ident[3] != 'F')) { - kprintf("Exec Format Error: Binary File Not Executable.\n"); - kfree(binaryHeader); - fclose(newProcess->files[0]); - return; - } - else if (binaryHeader->e_type != 2) { - kprintf("Exec Format Error: Binary File Not Executable.\n"); - kfree(binaryHeader); - fclose(newProcess->files[0]); - return; - } - else if (binaryHeader->e_entry == 0x300000) { - kprintf("Exec Format Error: Binary File Not Executable.\n"); - kfree(binaryHeader); - fclose(newProcess->files[0]); - return; - } - - newProcess->td.abi = binaryHeader->e_ident[EI_OSABI]; - - /* Load The Program Header(s) */ - programHeader = (Elf_Phdr *) kmalloc(sizeof(Elf_Phdr) * binaryHeader->e_phnum); - fseek(newProcess->files[0], binaryHeader->e_phoff, 0); - - fread(programHeader, (sizeof(Elf_Phdr) * binaryHeader->e_phnum), 1, newProcess->files[0]); - - /* Loop Through The Header And Load Sections Which Need To Be Loaded */ - for (i = 0; i < binaryHeader->e_phnum; i++) { - if (programHeader[i].p_type == 1) { - /* - Allocate Memory Im Going To Have To Make This Load Memory With Correct - Settings so it helps us in the future - */ - for (x = 0x0; x < (programHeader[i].p_memsz); x += 0x1000) { - /* Make readonly and read/write !!! */ - if (vmm_remapPage(vmm_findFreePage(newProcess->id), ((programHeader[i].p_vaddr & 0xFFFFF000) + x), PAGE_DEFAULT, newProcess->id, 0) == 0x0) - K_PANIC("Remap Page Failed"); - - memset((void *) ((programHeader[i].p_vaddr & 0xFFFFF000) + x), 0x0, 0x1000); - - } - - /* Now Load Section To Memory */ - fseek(newProcess->files[0], programHeader[i].p_offset, 0); - - fread((void *) programHeader[i].p_vaddr, programHeader[i].p_filesz, 1, newProcess->files[0]); - - if ((programHeader[i].p_flags & 0x2) != 0x2) { - for (x = 0x0; x < (programHeader[i].p_memsz); x += 0x1000) { - if ((vmm_setPageAttributes((programHeader[i].p_vaddr & 0xFFFFF000) + x, PAGE_PRESENT | PAGE_USER)) != 0x0) - kpanic("Error: vmm_setPageAttributes failed, File: %s, Line: %i\n", __FILE__, __LINE__); - } - } - } - } - - /* Set Virtual Memory Start */ - newProcess->oInfo.vmStart = 0x80000000; - newProcess->td.vm_daddr = (u_long) (programHeader[i].p_vaddr & 0xFFFFF000); - - /* Set Up Stack Space */ - //MrOlsen (2016-01-14) FIX: is the stack start supposed to be addressable xhcnage x= 1 to x=0 - //x = 0 because GS= stack address not address -1 fix! - for (x = 1; x <= 100; x++) { - vmm_remapPage(vmm_findFreePage(newProcess->id), (STACK_ADDR+1) - (x * PAGE_SIZE), PAGE_DEFAULT | PAGE_STACK, newProcess->id, 0); - bzero((void *)((STACK_ADDR+1) - (x * PAGE_SIZE)), PAGE_SIZE); - } - - /* Kernel Stack 0x2000 bytes long */ - - //vmm_remapPage(vmm_findFreePage(newProcess->id), 0x5BC000, KERNEL_PAGE_DEFAULT | PAGE_STACK, newProcess->id); - //vmm_remapPage(vmm_findFreePage(newProcess->id), 0x5BB000, KERNEL_PAGE_DEFAULT | PAGE_STACK, newProcess->id); - /* - for (x = 0; x < 2; x++) - vmm_remapPage(vmm_findFreePage(newProcess->id), 0xFFFFF000 - (PAGE_SIZE * x), KERNEL_PAGE_DEFAULT | PAGE_STACK, newProcess->id, 0); - */ - - /* Set All The Proper Information For The Task */ - newProcess->tss.back_link = 0x0; - newProcess->tss.esp0 = 0xFFFFFFFF; //0x5BC000; - newProcess->tss.ss0 = 0x10; - newProcess->tss.esp1 = 0x0; - newProcess->tss.ss1 = 0x0; - newProcess->tss.esp2 = 0x0; - newProcess->tss.ss2 = 0x0; - newProcess->tss.eip = (long) binaryHeader->e_entry; - newProcess->tss.eflags = 0x206; - newProcess->tss.esp = STACK_ADDR; - newProcess->tss.ebp = 0x0;//STACK_ADDR; - newProcess->tss.esi = 0x0; - newProcess->tss.edi = 0x0; - - /* Set these up to be ring 3 tasks */ - newProcess->tss.es = 0x30 + 3; - newProcess->tss.cs = 0x28 + 3; - newProcess->tss.ss = 0x30 + 3; - newProcess->tss.ds = 0x30 + 3; - newProcess->tss.fs = 0x30 + 3; - newProcess->tss.gs = 0x8 + 3 + 4;//0x50 + 3; //0x30 + 3; - - newProcess->tss.ldt = 0x18; - newProcess->tss.trace_bitmap = 0x0000; - newProcess->tss.io_map = 0x8000; - - //sched_setStatus(newProcess->id, READY); - - kfree(binaryHeader); - kfree(programHeader); - fclose(newProcess->files[0]); - newProcess->files[0] = 0x0; - - tmp = (uint32_t *) newProcess->tss.esp0 - 5; - - tmp[0] = binaryHeader->e_entry; - tmp[3] = STACK_ADDR - 12; - - newProcess->tss.esp = STACK_ADDR - ARGV_PAGE - ENVP_PAGE - ELF_AUX - (argc + 1) - (envc + 1) - STACK_PAD; - - tmp = (uint32_t *) newProcess->tss.esp; - - tmp[0] = argc; - - uint32_t sp = 0x0; - - for (i = 1; i <= argc; i++) { - tmp[i] = STACK_ADDR - ARGV_PAGE + sp; - strcpy((char *) tmp[i], argv[i - 1]); - sp += strlen(argv[i - 1]) + 1; - } - tmp[i++] = 0x0; - - sp = 0; - - for (int x = 0; x < envc; x++) { - tmp[x + i] = STACK_ADDR - ARGV_PAGE - ENVP_PAGE + sp; - strcpy((char *) tmp[x + i], envp[x]); - sp += strlen(envp[x]) + 1; - } - tmp[i + x] = 0x0; - - /* Build LDT For GS and FS */ - vmm_unmapPage(VMM_USER_LDT, 1); - - if (vmm_remapPage(vmm_findFreePage(newProcess->id), VMM_USER_LDT, PAGE_DEFAULT, newProcess->id, 0) == 0x0) { - K_PANIC("Error: Remap Page Failed"); - } - - struct gdtDescriptor *taskLDT = 0x0; - - taskLDT = (struct gdtDescriptor *)(VMM_USER_LDT + sizeof(struct gdtDescriptor)); - uint32_t data_addr = 0x0; - - taskLDT->limitLow = (0xFFFFF & 0xFFFF); - taskLDT->baseLow = (data_addr & 0xFFFF); - taskLDT->baseMed = ((data_addr >> 16) & 0xFF); - taskLDT->access = ((dData + dWrite + dBig + dBiglim + dDpl3) + dPresent) >> 8; - taskLDT->limitHigh = (0xFFFFF >> 16); - taskLDT->granularity = ((dData + dWrite + dBig + dBiglim + dDpl3) & 0xFF) >> 4; - taskLDT->baseHigh = data_addr >> 24; - - - /* Switch Back To The Kernels VM Space */ - asm volatile( - "movl %0,%%eax \n" - "movl %%eax,%%cr3 \n" - : : "d" ((uint32_t *)(kernelPageDirectory)) - ); - - sprintf(newProcess->oInfo.cwd, "/"); - - //MrOlsen 2018 kprintf("execFile Return: 0x%X - %i\n", newProcess->tss.eip, newProcess->id); - - /* Put new thread into the READY state */ - sched_setStatus(newProcess->id, READY); - - //_current = newProcess; - - /* Finally Return */ - return; -} - -int sys_exec(struct thread *td, char *file, char **argv, char **envp) { - - int i = 0x0; - int x = 0x0; - - int argc = argv_count(argv); - int envc = envp_count(envp); - - uint32_t cr3 = 0x0; - - uint32_t *tmp = 0x0; - - uInt32 seg_size = 0x0; - uInt32 seg_addr = 0x0; - - char *interp = 0x0; - uint32_t ldAddr = 0x0; - - fileDescriptor_t *fd = 0x0; - - Elf_Ehdr *binaryHeader = 0x0; - Elf_Phdr *programHeader = 0x0; - Elf_Shdr *sectionHeader = 0x0; - - elf_file_t ef = 0x0; - - u_long text_addr = 0, text_size = 0; - u_long data_addr = 0, data_size = 0; - - struct i386_frame *iFrame = 0x0; - - asm("movl %%cr3, %0;" : "=r" (cr3)); - - fd = fopen(file, "r"); - - if (fd == 0x0) { - td->td_retval[0] = 2; - return (-1); - } - - /* Test If Executable */ - if (fd->perms == 0) { - kprintf("Exec Format Error: Binary File Not Executable.\n"); - fclose(fd); - return (-1); - } - - /* Set Threads FD to open FD */ - _current->files[0] = fd; - - /* Copy In ARGS & ENVS Before Cleaning Virtual Space */ - uint32_t *argv_out = 0x0; - char *args_out = 0x0; - - args_copyin(argv, (char **)&argv_out, &args_out); - - uint32_t *envp_out = 0x0; - char *envs_out = 0x0; - - envs_copyin(envp, (char **)&envp_out, &envs_out); - - //! Clean the virtual of COW pages left over from the fork - //vmm_cleanVirtualSpace( (uint32_t) _current->td.vm_daddr + (_current->td.vm_dsize << PAGE_SHIFT) ); - //MrOlsen 2017-12-15 - FIX! - This should be done before it was causing a lot of problems why did I free space after loading binary???? - //vmm_cleanVirtualSpace((uint32_t) 0x8048000); - vmm_cleanVirtualSpace((uint32_t) VMM_USER_START); - - /* Clear Stack */ - //bzero(STACK_ADDR - (100 * PAGE_SIZE), (PAGE_SIZE * 100)); - for (x = 1; x <= 100; x++) { - vmm_remapPage(vmm_findFreePage(_current->id), (STACK_ADDR+1) - (x * 0x1000), PAGE_DEFAULT | PAGE_STACK, _current->id, 0); - bzero((void *)((STACK_ADDR+1) - (x * 0x1000)), 0x1000); - } - - /* Load ELF Header */ - if ((binaryHeader = (Elf_Ehdr *) kmalloc(sizeof(Elf_Ehdr))) == 0x0) - K_PANIC("MALLOC FAILED"); - - fread(binaryHeader, sizeof(Elf_Ehdr), 1, fd); - /* Done Loading ELF Header */ - - /* Check If App Is A Real Application */ - if ((binaryHeader->e_ident[1] != 'E') && (binaryHeader->e_ident[2] != 'L') && (binaryHeader->e_ident[3] != 'F')) { - kprintf("Exec Format Error: Binary File Not Executable.\n"); - kfree(binaryHeader); - fclose(fd); - return (-1); - } - else if (binaryHeader->e_type != ET_EXEC) { - kprintf("Exec Format Error: Binary File Not Executable.\n"); - kfree(binaryHeader); - fclose(fd); - return (-1); - } - else if (binaryHeader->e_entry == 0x300000) { - kprintf("Exec Format Error: Binary File Not Executable.\n"); - kfree(binaryHeader); - fclose(fd); - return (-1); - } - - /* Set Thread ABI */ - td->abi = binaryHeader->e_ident[EI_OSABI]; - - /* Load The Program Header(s) */ - if ((programHeader = (Elf_Phdr *) kmalloc(sizeof(Elf_Phdr) * binaryHeader->e_phnum)) == 0x0) - K_PANIC("MALLOC FAILED"); - - assert(programHeader); - - fseek(fd, binaryHeader->e_phoff, 0); - fread(programHeader, (sizeof(Elf_Phdr) * binaryHeader->e_phnum), 1, fd); - /* Done Loading Program Header(s) */ - - /* Load The Section Header(s) */ - if ((sectionHeader = (Elf_Shdr *) kmalloc(sizeof(Elf_Shdr) * binaryHeader->e_shnum)) == 0x0) - K_PANIC("MALLOC FAILED"); - - assert(sectionHeader); - fseek(fd, binaryHeader->e_shoff, 0); - fread(sectionHeader, sizeof(Elf_Shdr) * binaryHeader->e_shnum, 1, fd); - /* Done Loading Section Header(s) */ - - ef = kmalloc(sizeof(struct elf_file)); - memset(ef, 0x0, sizeof(struct elf_file)); - - /* Loop Through The Header And Load Sections Which Need To Be Loaded */ - for (i = 0; i < binaryHeader->e_phnum; i++) { - switch (programHeader[i].p_type) { - case PT_LOAD: - if (programHeader[i].p_memsz == 0x0) - break; - - seg_addr = trunc_page(programHeader[i].p_vaddr); - seg_size = round_page(programHeader[i].p_memsz + programHeader[i].p_vaddr - seg_addr); - - /* - Allocate Memory Im Going To Have To Make This Load Memory With Correct - Settings so it helps us in the future - */ - for (x = 0x0; x < (round_page(programHeader[i].p_memsz)); x += 0x1000) { - /* Make readonly and read/write !!! */ - if (vmm_remapPage(vmm_findFreePage(_current->id), ((programHeader[i].p_vaddr & 0xFFFFF000) + x), PAGE_DEFAULT, _current->id, 0) == 0x0) { - K_PANIC("Error: Remap Page Failed"); - } - else { - //MrOlsen 2018-01-15 kprintf("rP[0x%X]", (programHeader[i].p_vaddr & 0xFFFFF000) + x); - } - - memset((void *) ((programHeader[i].p_vaddr & 0xFFFFF000) + x), 0x0, 0x1000); - - } - - /* Now Load Section To Memory */ - fseek(fd, programHeader[i].p_offset, 0); - fread((void *) programHeader[i].p_vaddr, programHeader[i].p_filesz, 1, fd); - - if ((programHeader[i].p_flags & 0x2) != 0x2) { - for (x = 0x0; x < (round_page(programHeader[i].p_memsz)); x += 0x1000) { - if ((vmm_setPageAttributes((programHeader[i].p_vaddr & 0xFFFFF000) + x, PAGE_PRESENT | PAGE_USER)) != 0x0) - kpanic("Error: vmm_setPageAttributes failed, File: %s,Line: %i\n", __FILE__, __LINE__); - } - } - - if ((programHeader[i].p_flags & PF_X) && text_size < seg_size) { - //MrOlsen 2018kprintf("setting text: 0x%X - 0x%X\n", seg_addr, seg_size); - text_size = seg_size; - text_addr = seg_addr; - } - else { - //MrOlsen 2018kprintf("setting data: 0x%X - 0x%X\n", seg_addr, seg_size); - data_size = seg_size; - data_addr = seg_addr; - /* - _current->td.vm_dsize = seg_size >> PAGE_SHIFT; - _current->td.vm_daddr = (char *) seg_addr; - kprintf( "setting daddr: 0x%X, dsiize: 0x%X\n", _current->td.vm_daddr, _current->td.vm_dsize ); - */ - } - - /* - * MrOlsen (2016-01-19) NOTE: Note Sure, I should Do This Later - * Thjis is for stack space - */ - _current->oInfo.vmStart = ((programHeader[i].p_vaddr & 0xFFFFF000) + 0xA900000); - break; - case PT_DYNAMIC: - //newLoc = (char *)programHeader[i].phVaddr; - //elfDynamicS = (elfDynamic *) programHeader[i].p_vaddr; - ef->dynamic = (Elf_Dyn *) programHeader[i].p_vaddr; - //fseek( fd, programHeader[i].phOffset, 0 ); - //fread( (void *) programHeader[i].phVaddr, programHeader[i].phFilesz, 1, fd ); - break; - case PT_INTERP: - #ifdef DEBUG_EXEC - kprintf("%s:%i>Malloc: %i\n", _FILE_,_LINE_,programHeader[i].p_filesz); - #endif - interp = (char *) kmalloc(programHeader[i].p_filesz); - fseek(fd, programHeader[i].p_offset, 0); - fread((void *) interp, programHeader[i].p_filesz, 1, fd); - #ifdef DEBUG_EXEC - kprintf("Interp: [%s]\n", interp); - #endif - ldAddr = ldEnable(interp); - //ef->ld_addr = ldEnable(); - break; - case PT_GNU_STACK: - asm("nop"); - break; - default: - break; - } - } - - _current->td.vm_tsize = text_size >> PAGE_SHIFT; - _current->td.vm_taddr = text_addr; - _current->td.vm_dsize = data_size >> PAGE_SHIFT; - _current->td.vm_daddr = data_addr; - - //MrOlsen 2018kprintf("Done Looping\n"); - - ef->preloaded = 1; - ef->address = 0x0; - elf_parse_dynamic(ef); - - //asm("cld"); - //irqDisable(0); - iFrame = (struct i386_frame *) (_current->tss.esp0 - sizeof(struct i386_frame)); - - //iFrame->ebp = 0x0; - - if (ldAddr != 0x0) { - iFrame->eip = ldAddr; - } - else { - iFrame->eip = binaryHeader->e_entry; - } - - //iFrame->edx = 0x0; - - iFrame->user_esp = (uint32_t) (STACK_ADDR - ARGV_PAGE - ENVP_PAGE - ELF_AUX - (argc + 1) - (envc + 1) - STACK_PAD) & 0xFFFFF000; - - tmp = (uint32_t *) iFrame->user_esp; - -// memset((char *) tmp, 0x0, ARGV_PAGE + ENVP_PAGE + ELF_AUX + (argc + 1) + (envc + 1) + STACK_PAD); - - tmp[0] = argc; - - uint32_t sp = 0x0; - - char *EXECP = 0x0; - - for (i = 1; i <= argc; i++) { - tmp[i] = (uint32_t) STACK_ADDR - ARGV_PAGE + sp; - if (i == 1) { - EXECP = (char *)tmp[i]; - } - strcpy((char *)tmp[i], (const char *)argv_out[i]); - #ifdef EXEC_DEBUG - kprintf("argv[%i]:%s",i, (const char *)argv_out[i]); - #endif - sp += strlen((const char *)argv_out[i]) + 1; - } - - tmp[i++] = 0x0; - - kfree(argv_out); - kfree(args_out); - - sp = 0; - - x = 0; - - for (x = 0; x < envc; x++) { - tmp[x + i] = (uint32_t) STACK_ADDR - ARGV_PAGE - ENVP_PAGE + sp; - strcpy((char *) tmp[x + i], (const char *)envp_out[x]); - sp += strlen((const char *)envp_out[x]) + 1; - } - - tmp[i + x] = 0x0; - - kfree(envp_out); - kfree(envs_out); - - i = i + x + 1; - - struct file *tFP = 0x0; - int tFD = 0x0; - - fseek(_current->files[0], 0x0, 0x0); // Reset File Position - falloc(&_current->td, &tFP, &tFD); - - tFP->fd = _current->files[0]; - - - tmp[i++] = 2; - tmp[i++] = -1;// tFD; // _current->imageFd; - _current->td.o_files[4] = _current->files[0]; - //MrOlsen 2018kprintf("AT_EXECFD: [%i:%i]", tmp[i - 1], tFD); - - tmp[i++] = 3; - tmp[i++] = binaryHeader->e_phoff + 0x08048000; - //MrOlsen 2018kprintf("AT_PHDR: [0x%X]", tmp[i - 1]); - - tmp[i++] = 4; - tmp[i++] = binaryHeader->e_phentsize; - //MrOlsen 2018kprintf("AT_PHENT: [0x%X]", tmp[i - 1]); - - tmp[i++] = 5; - tmp[i++] = binaryHeader->e_phnum; - //MrOlsen 2018kprintf("AT_PHNUM: [0x%X]", tmp[i - 1]); - - tmp[i++] = 6; - tmp[i++] = 0x1000; - - tmp[i++] = 7; - tmp[i++] = LD_START; - //MrOlsen 2018kprintf("AT_BASE: [0x%X]", tmp[i - 1]); - - tmp[i++] = 8; - tmp[i++] = 0x0; - - tmp[i++] = 9; - tmp[i++] = binaryHeader->e_entry; - - tmp[i++] = 11; - tmp[i++] = 0x0; - - tmp[i++] = 12; - tmp[i++] = 0x0; - - tmp[i++] = 13; - tmp[i++] = 0x0; - - tmp[i++] = 14; - tmp[i++] = 0x0; - - tmp[i++] = 15; //EXEC PATH - tmp[i++] = (uint32_t)EXECP; - - tmp[i++] = 19; //NCPUS - tmp[i++] = 0x1; - - tmp[i++] = 23; //STACKPROT - tmp[i++] = 0x3; - - tmp[i++] = 0; - tmp[i++] = 0; - - /* Now That We Relocated The Binary We Can Unmap And Free Header Info */ - kfree(binaryHeader); - kfree(programHeader); - //irqEnable(0); - //asm("sti"); - - /* - _current->tss.es = 0x30 + 3; - _current->tss.cs = 0x28 + 3; - _current->tss.ss = 0x30 + 3; - _current->tss.ds = 0x30 + 3; - _current->tss.fs = 0x30 + 3; - _current->tss.gs = 0x50 + 3; //0x30 + 3; - - _current->tss.ldt = 0x18; - _current->tss.trace_bitmap = 0x0000; - _current->tss.io_map = 0x8000; - */ - - /* - kfree (iFrameNew); - - memAddr = (uint32_t) & (_current->tss); - ubixGDT[4].descriptor.baseLow = (memAddr & 0xFFFF); - ubixGDT[4].descriptor.baseMed = ((memAddr >> 16) & 0xFF); - ubixGDT[4].descriptor.baseHigh = (memAddr >> 24); - ubixGDT[4].descriptor.access = '\x89'; - - ubixGDT[10].descriptor.baseLow = (STACK_ADDR & 0xFFFF); - ubixGDT[10].descriptor.baseMed = ((STACK_ADDR >> 16) & 0xFF); - ubixGDT[10].descriptor.baseHigh = (STACK_ADDR >> 24); - - */ - - /* Build LDT For GS and FS */ - vmm_unmapPage(VMM_USER_LDT, 1); // Can I Free This? - if (vmm_remapPage(vmm_findFreePage(_current->id), VMM_USER_LDT, PAGE_DEFAULT, _current->id, 0) == 0x0) { - K_PANIC("Error: Remap Page Failed"); - } - - struct gdtDescriptor *taskLDT = 0x0; - - taskLDT = (struct gdtDescriptor *)(VMM_USER_LDT + sizeof(struct gdtDescriptor)); - - //data_addr = 0x0; //TEMP - - taskLDT->limitLow = (0xFFFFF & 0xFFFF); - taskLDT->baseLow = (data_addr & 0xFFFF); - taskLDT->baseMed = ((data_addr >> 16) & 0xFF); - taskLDT->access = ((dData + dWrite + dBig + dBiglim + dDpl3) + dPresent) >> 8; - taskLDT->limitHigh = (0xFFFFF >> 16); - taskLDT->granularity = ((dData + dWrite + dBig + dBiglim + dDpl3) & 0xFF) >> 4; - taskLDT->baseHigh = data_addr >> 24; - - _current->tss.gs = 0xF; //Select 0x8 + Ring 3 + LDT - _current->pgrp = _current->id; - - return (0x0); -} - -static int elf_parse_dynamic(elf_file_t ef) { - Elf32_Dyn *dynp; - int plttype = DT_REL; - - for (dynp = ef->dynamic; dynp->d_tag != 0x0; dynp++) { - switch (dynp->d_tag) { - case DT_NEEDED: - asm("nop"); - break; - case DT_INIT: - asm("nop"); - break; - case DT_FINI: - asm("nop"); - break; - case DT_HASH: - asm("nop"); - /* From src/libexec/rtld-elf/rtld.c */ - const Elf_Hashelt *hashtab = (const Elf_Hashelt *) (ef->address + dynp->d_un.d_ptr); - ef->nbuckets = hashtab[0]; - ef->nchains = hashtab[1]; - ef->buckets = hashtab + 2; - ef->chains = ef->buckets + ef->nbuckets; - break; - case DT_STRTAB: - ef->strtab = (caddr_t) (ef->address + dynp->d_un.d_ptr); - break; - case DT_STRSZ: - ef->strsz = dynp->d_un.d_val; - break; - case DT_SYMTAB: - ef->symtab = (Elf_Sym *) (ef->address + dynp->d_un.d_ptr); - break; - case DT_SYMENT: - if (dynp->d_un.d_val != sizeof(Elf32_Sym)) - return (ENOEXEC); - break; - case DT_REL: - ef->rel = (const Elf_Rel *) (ef->address + dynp->d_un.d_ptr); - break; - case DT_RELSZ: - ef->relsize = dynp->d_un.d_val; - break; - case DT_RELENT: - if (dynp->d_un.d_val != sizeof(Elf_Rel)) - return (ENOEXEC); - break; - case DT_JMPREL: - ef->pltrel = (const Elf_Rel *) (ef->address + dynp->d_un.d_ptr); - break; - case DT_PLTRELSZ: - ef->pltrelsize = dynp->d_un.d_val; - break; - case DT_RELA: - ef->rela = (const Elf_Rela *) (ef->address + dynp->d_un.d_ptr); - break; - case DT_RELASZ: - ef->relasize = dynp->d_un.d_val; - break; - case DT_RELAENT: - if (dynp->d_un.d_val != sizeof(Elf_Rela)) - return (ENOEXEC); - break; - case DT_PLTREL: - plttype = dynp->d_un.d_val; - if (plttype != DT_REL && plttype != DT_RELA) - return (ENOEXEC); - break; - case DT_PLTGOT: - ef->got = (Elf_Addr *) (ef->address + dynp->d_un.d_ptr); - /* - tmp = (void *) dynp->d_un.d_ptr; //elfDynamicS[i].dynPtr; - tmp[2] = (uInt32) ef->ld_addr; - tmp[1] = (uInt32) ef; //0x0;//0xBEEFEAD;//STACK_ADDR - 128;//_current->imageFd;//0xBEEFDEAD;//ef; - */ - break; - default: - asm("nop"); - //kprintf("t_tag: 0x%X>", dynp->d_tag); - break; - } - } - - if (plttype == DT_RELA) { - ef->pltrela = (const Elf_Rela *) ef->pltrel; - ef->pltrel = NULL; - ef->pltrelasize = ef->pltrelsize; - ef->pltrelsize = 0; - } - - ef->ddbsymtab = ef->symtab; - ef->ddbsymcnt = ef->nchains; - ef->ddbstrtab = ef->strtab; - ef->ddbstrcnt = ef->strsz; - return (0); -} diff --git a/sys/i386/kpanic.c b/sys/i386/kpanic.c deleted file mode 100644 index 4b6ce22..0000000 --- a/sys/i386/kpanic.c +++ /dev/null @@ -1,66 +0,0 @@ -/*- - * Copyright (c) 2002-2018 The UbixOS Project. - * All rights reserved. - * - * This was developed by Christopher W. Olsen for the UbixOS Project. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors. - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors in the documentation and/or - * other materials provided with the distribution. - * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include - -/*! - * \brief print panic message and halt system - * - * \param fmt panic message - * - */ -void kpanic(const char *fmt, ...) { - char buf[512]; - va_list args; - - va_start(args, fmt); - vsprintf(buf, fmt, args); - va_end(args); - - /* It's important that we print on the current terminal so let's reset foreground */ - tty_foreground = NULL; - kprintf("kPanic: %s", buf); - - /* Halt The System */ - //asm("cli"); - irqDisable(0x0); - - while (1) { - asm("hlt"); - } - -} - -/*** - END - ***/ - diff --git a/sys/i386/memcmp.S b/sys/i386/memcmp.S deleted file mode 100644 index c8e68c2..0000000 --- a/sys/i386/memcmp.S +++ /dev/null @@ -1,66 +0,0 @@ -/*- - * Copyright (c) 2002-2018 The UbixOS Project. - * All rights reserved. - * - * This was developed by Christopher W. Olsen for the UbixOS Project. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors. - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors in the documentation and/or - * other materials provided with the distribution. - * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - #include - -ENTRY(memcmp) - pushl %edi - pushl %esi - movl 12(%esp),%edi - movl 16(%esp),%esi - cld /* set compare direction forward */ - - movl 20(%esp),%ecx /* compare by words */ - shrl $2,%ecx - repe - cmpsl - jne L5 /* do we match so far? */ - - movl 20(%esp),%ecx /* compare remainder by bytes */ - andl $3,%ecx - repe - cmpsb - jne L6 /* do we match? */ - - xorl %eax,%eax /* we match, return zero */ - popl %esi - popl %edi - ret - -L5: movl $4,%ecx /* We know that one of the next */ - subl %ecx,%edi /* four pairs of bytes do not */ - subl %ecx,%esi /* match. */ - repe - cmpsb -L6: movzbl -1(%edi),%eax /* Perform unsigned comparison */ - movzbl -1(%esi),%edx - subl %edx,%eax - popl %esi - popl %edi - ret -END(memcmp) diff --git a/sys/i386/memset.S b/sys/i386/memset.S deleted file mode 100644 index 03bef8d..0000000 --- a/sys/i386/memset.S +++ /dev/null @@ -1,79 +0,0 @@ -/*- - * Copyright (c) 2002-2018 The UbixOS Project. - * All rights reserved. - * - * This was developed by Christopher W. Olsen for the UbixOS Project. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors. - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors in the documentation and/or - * other materials provided with the distribution. - * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - #include - - -ENTRY(memset) - pushl %edi - pushl %ebx - movl 12(%esp),%edi - movzbl 16(%esp),%eax /* unsigned char, zero extend */ - movl 20(%esp),%ecx - pushl %edi /* push address of buffer */ - - cld /* set fill direction forward */ - - /* - * if the string is too short, it's really not worth the overhead - * of aligning to word boundries, etc. So we jump to a plain - * unaligned set. - */ - cmpl $0x0f,%ecx - jle L1 - - movb %al,%ah /* copy char to all bytes in word */ - movl %eax,%edx - sall $16,%eax - orl %edx,%eax - - movl %edi,%edx /* compute misalignment */ - negl %edx - andl $3,%edx - movl %ecx,%ebx - subl %edx,%ebx - - movl %edx,%ecx /* set until word aligned */ - rep - stosb - - movl %ebx,%ecx - shrl $2,%ecx /* set by words */ - rep - stosl - - movl %ebx,%ecx /* set remainder by bytes */ - andl $3,%ecx -L1: rep - stosb - - popl %eax /* pop address of buffer */ - popl %ebx - popl %edi - ret -END(memset) diff --git a/sys/i386/sched.c b/sys/i386/sched.c deleted file mode 100644 index 069868d..0000000 --- a/sys/i386/sched.c +++ /dev/null @@ -1,385 +0,0 @@ -/*- - * Copyright (c) 2002-2018 The UbixOS Project. - * All rights reserved. - * - * This was developed by Christopher W. Olsen for the UbixOS Project. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors. - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors in the documentation and/or - * other materials provided with the distribution. - * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -static kTask_t *taskList = 0x0; -static kTask_t *delList = 0x0; -static uint32_t nextID = 1; - -kTask_t *_current = 0x0; -kTask_t *_usedMath = 0x0; - -static struct spinLock schedulerSpinLock = SPIN_LOCK_INITIALIZER; - -int need_resched = 0; - -/************************************************************************ - - Function: int sched_init() - - Description: This function is used to enable the kernel scheduler - - Notes: - - 02/20/2004 - Approved for quality - - ************************************************************************/ - -int sched_init() { - taskList = (kTask_t *) kmalloc(sizeof(kTask_t)); - if (taskList == 0x0) - kpanic("Unable to create task list"); - - taskList->id = nextID++; - - /* Print out information on scheduler */ - kprintf("sched0 - Address: [0x%X]\n", taskList); - - /* Return so we know everything went well */ - return (0x0); -} - -void sched() { - uint32_t memAddr = 0x0; - kTask_t *tmpTask = 0x0; - kTask_t *delTask = 0x0; - - if (spinTryLock(&schedulerSpinLock)) - return; - - tmpTask = ((_current == 0) ? 0 : _current->next); - schedStart: - - /* Yield the next task from the current prio queue */ - for (; tmpTask != 0x0; tmpTask = tmpTask->next) { - if (tmpTask->state == FORK) - tmpTask->state = READY; - - if (tmpTask->state == READY) { - _current->state = (_current->state == DEAD) ? DEAD : READY; - _current = tmpTask; - break; - } - else if (tmpTask->state == DEAD) { - delTask = tmpTask; - if (delTask->parent != 0x0) { - delTask->parent->children -= 1; - delTask->parent->last_exit = delTask->id; - delTask->parent->state = READY; - } - - tmpTask = tmpTask->next; - sched_deleteTask(delTask->id); - sched_addDelTask(delTask); - goto schedStart; - } - } - - /* Finished all the tasks, restarting the list */ - if (0x0 == tmpTask) { - tmpTask = taskList; - goto schedStart; - } - - if (_current->state == READY || _current->state == RUNNING) { - - if (_current->oInfo.v86Task == 0x1) { - irqDisable(0x0); - kprintf("IRQD(%i): 0x%X*0x%X:0x%X@, esp: 0x%X:0x%X, ebp: 0x%X:0x%X ds: 0x%X", _current->id, _current->tss.eflags, _current->tss.cs, _current->tss.eip, _current->tss.ss, _current->tss.esp, _current->tss.ss, _current->tss.ebp,_current->tss.ds); - kprintf("ss0: 0x%X, esp0: 0x%X", _current->tss.ss0, _current->tss.esp0); - } - - asm("cli"); - - memAddr = (uint32_t) &(_current->tss); - ubixGDT[4].descriptor.baseLow = (memAddr & 0xFFFF); - ubixGDT[4].descriptor.baseMed = ((memAddr >> 16) & 0xFF); - ubixGDT[4].descriptor.baseHigh = (memAddr >> 24); - ubixGDT[4].descriptor.access = '\x89'; - - _current->state = RUNNING; - - spinUnlock(&schedulerSpinLock); - - asm("sti"); - asm("ljmp $0x20,$0"); - } - else { - spinUnlock(&schedulerSpinLock); - } - - return; -} - -kTask_t *schedNewTask() { - int i = 0; - - kTask_t *tmpTask = (kTask_t *) kmalloc(sizeof(kTask_t)); - - struct file *fp = 0x0; - - if (tmpTask == 0x0) - kpanic("Error: schedNewTask() - kmalloc failed trying to initialize a new task struct\n"); - - memset(tmpTask, 0x0, sizeof(kTask_t)); - - /* Filling in tasks attrs */ - tmpTask->usedMath = 0x0; - tmpTask->state = NEW; - - /* HACK */ - - for (i = 0; i < 3; i++) { - fp = (void *) kmalloc(sizeof(struct file)); - //kprintf("DB: [0x%X]\n", (uint32_t) fp); - tmpTask->td.o_files[i] = (void *) fp; - fp->f_flag = 0x4; - } - - spinLock(&schedulerSpinLock); - tmpTask->id = nextID++; - tmpTask->next = taskList; - tmpTask->prev = 0x0; - taskList->prev = tmpTask; - taskList = tmpTask; - - spinUnlock(&schedulerSpinLock); - - return (tmpTask); -} - -int sched_deleteTask(pidType id) { - kTask_t *tmpTask = 0x0; - - /* Checking each task from the prio queue */ - for (tmpTask = taskList; tmpTask != 0x0; tmpTask = tmpTask->next) { - if (tmpTask->id == id) { - if (tmpTask->prev != 0x0) - tmpTask->prev->next = tmpTask->next; - if (tmpTask->next != 0x0) - tmpTask->next->prev = tmpTask->prev; - if (taskList == tmpTask) - taskList = tmpTask->next; - - return (0x0); - } - } - return (0x1); -} - -int sched_addDelTask(kTask_t *tmpTask) { - tmpTask->next = delList; - tmpTask->prev = 0x0; - if (delList != 0x0) - delList->prev = tmpTask; - delList = tmpTask; - return (0x0); -} - -kTask_t *sched_getDelTask() { - kTask_t *tmpTask = 0x0; - - if (delList == 0x0) - return (0x0); - - tmpTask = delList; - delList = delList->next; - return (tmpTask); -} - -kTask_t *schedFindTask(uint32_t id) { - kTask_t *tmpTask = 0x0; - - for (tmpTask = taskList; tmpTask; tmpTask = tmpTask->next) { - if (tmpTask->id == id) - return (tmpTask); - } - - return (0x0); -} - -/************************************************************************ - - Function: void schedEndTask() - - Description: This function will end a task - - Notes: - - 02/20/2004 - Approved for quality - - ************************************************************************/ -void schedEndTask(pidType pid) { - endTask(_current->id); - sched_yield(); -} - -/************************************************************************ - - Function: int schedEndTask() - - Description: This function will yield a task - - Notes: - - 02/20/2004 - Approved for quality - - ************************************************************************/ - -void sched_yield() { - sched(); -} - -/* - asm( - ".globl sched_yield \n" - "sched_yield: \n" - " cli \n" - " call sched \n" - ); - */ - -/************************************************************************ - - Function: int sched_setStatus(pidType pid,tState state) - - Description: Change the tasks status - - Notes: - - ************************************************************************/ -int sched_setStatus(pidType pid, tState state) { - kTask_t *tmpTask = schedFindTask(pid); - if (tmpTask == 0x0) - return (0x1); - tmpTask->state = state; - return (0x0); -} - -void add_wait_queue(struct wait_queue ** p, struct wait_queue * wait) { - unsigned long flags; - - save_flags(flags); - cli(); - if (!*p) { - wait->next = wait; - *p = wait; - } - else { - wait->next = (*p)->next; - (*p)->next = wait; - } - restore_flags(flags); -} - -void remove_wait_queue(struct wait_queue ** p, struct wait_queue * wait) { - unsigned long flags; - struct wait_queue * tmp; - - save_flags(flags); - cli(); - if ((*p == wait) && ((*p = wait->next) == wait)) { - *p = NULL; - } - else { - tmp = wait; - while (tmp->next != wait) { - tmp = tmp->next; - } - tmp->next = wait->next; - } - wait->next = NULL; - restore_flags(flags); -} - -void wake_up_interruptible(struct wait_queue **q) { - struct wait_queue *tmp; - kTask_t *p; - - if (!q || !(tmp = *q)) - return; - do { - if ((p = tmp->task) != NULL) { - if (p->state == INTERRUPTIBLE) { - p->state = RUNNING; - if (p->counter > _current->counter) - need_resched = 1; - } - } - if (!tmp->next) { - kprintf("wait_queue is bad (eip = %08lx)\n", ((unsigned long *) q)[-1]); - kprintf(" q = %p\n", q); - kprintf(" *q = %p\n", *q); - kprintf(" tmp = %p\n", tmp); - break; - } - tmp = tmp->next; - } while (tmp != *q); -} - -void wake_up(struct wait_queue **q) { - struct wait_queue *tmp; - kTask_t * p; - - if (!q || !(tmp = *q)) - return; - do { - if ((p = tmp->task) != NULL) { - if ((p->state == UNINTERRUPTIBLE) || (p->state == INTERRUPTIBLE)) { - p->state = RUNNING; - if (p->counter > _current->counter) - need_resched = 1; - } - } - if (!tmp->next) { - kprintf("wait_queue is bad (eip = %08lx)\n", ((unsigned long *) q)[-1]); - kprintf(" q = %p\n", q); - kprintf(" *q = %p\n", *q); - kprintf(" tmp = %p\n", tmp); - break; - } - tmp = tmp->next; - } while (tmp != *q); -} diff --git a/sys/i386/schedyield.S b/sys/i386/schedyield.S deleted file mode 100644 index 1072793..0000000 --- a/sys/i386/schedyield.S +++ /dev/null @@ -1,51 +0,0 @@ -/*- - * Copyright (c) 2002-2018 The UbixOS Project. - * All rights reserved. - * - * This was developed by Christopher W. Olsen for the UbixOS Project. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors. - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors in the documentation and/or - * other materials provided with the distribution. - * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -.globl sched_yield_new -.text -.code32 -sched_yield_new: - pusha /* Save all of the registers */ - push %ss - push %ds - push %es - push %fs - push %gs - call sched - mov %eax,%esp - pop %gs - pop %fs - pop %es - pop %ds - pop %ss - popa /* Restore Registers */ - iret - -/*** - END - ***/ diff --git a/sys/i386/spinlock.c b/sys/i386/spinlock.c deleted file mode 100644 index db6653d..0000000 --- a/sys/i386/spinlock.c +++ /dev/null @@ -1,71 +0,0 @@ -/*- - * Copyright (c) 2002-2018 The UbixOS Project. - * All rights reserved. - * - * This was developed by Christopher W. Olsen for the UbixOS Project. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors. - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors in the documentation and/or - * other materials provided with the distribution. - * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include - -#define atomic_xadd(P, V) __sync_fetch_and_add((P), (V)) -#define cmpxchg(P, O, N) __sync_val_compare_and_swap((P), (O), (N)) -#define atomic_inc(P) __sync_add_and_fetch((P), 1) -#define atomic_dec(P) __sync_add_and_fetch((P), -1) -#define atomic_add(P, V) __sync_add_and_fetch((P), (V)) -#define atomic_set_bit(P, V) __sync_or_and_fetch((P), 1<<(V)) -#define atomic_clear_bit(P, V) __sync_and_and_fetch((P), ~(1<<(V))) - -#define barrier() asm volatile("": : :"memory") - -/* Pause instruction to prevent excess processor bus usage */ -#define cpu_relax() asm volatile("pause\n": : :"memory") - -void spinLockInit(spinLock_t lock) { - memset(lock, 0x0, sizeof(struct spinLock)); -} - -int spinTryLock(spinLock_t lock) { - if (!cmpxchg(&lock->locked, NULL, LLOCK_FLAG)) - return 0; - - /* Failure! */ - return LOCKED; -} - -void spinUnlock(spinLock_t lock) { - barrier(); - lock->locked = 0x0; -} - -void spinLock(spinLock_t lock) { - while (1) { - if (!xchg_32(&lock->locked, LOCKED)) - return; - while (lock->locked == 1) - sched_yield(); - } -} - diff --git a/sys/i386/strcmp.S b/sys/i386/strcmp.S deleted file mode 100644 index 19bb2ff..0000000 --- a/sys/i386/strcmp.S +++ /dev/null @@ -1,98 +0,0 @@ -/*- - * Copyright (c) 2002-2018 The UbixOS Project. - * All rights reserved. - * - * This was developed by Christopher W. Olsen for the UbixOS Project. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors. - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors in the documentation and/or - * other materials provided with the distribution. - * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - #include - -ENTRY(strcmp) - movl 0x04(%esp),%eax - movl 0x08(%esp),%edx - jmp L2 /* Jump into the loop! */ - - .align 2,0x90 -L1: incl %eax - incl %edx -L2: movb (%eax),%cl - testb %cl,%cl - je L3 - cmpb %cl,(%edx) - jne L3 - incl %eax - incl %edx - movb (%eax),%cl - testb %cl,%cl - je L3 - cmpb %cl,(%edx) - jne L3 - incl %eax - incl %edx - movb (%eax),%cl - testb %cl,%cl - je L3 - cmpb %cl,(%edx) - jne L3 - incl %eax - incl %edx - movb (%eax),%cl - testb %cl,%cl - je L3 - cmpb %cl,(%edx) - jne L3 - incl %eax - incl %edx - movb (%eax),%cl - testb %cl,%cl - je L3 - cmpb %cl,(%edx) - jne L3 - incl %eax - incl %edx - movb (%eax),%cl - testb %cl,%cl - je L3 - cmpb %cl,(%edx) - jne L3 - incl %eax - incl %edx - movb (%eax),%cl - testb %cl,%cl - je L3 - cmpb %cl,(%edx) - jne L3 - incl %eax - incl %edx - movb (%eax),%cl - testb %cl,%cl - je L3 - cmpb %cl,(%edx) - je L1 - .align 2, 0x90 -L3: movzbl (%eax),%eax /* unsigned comparison */ - movzbl (%edx),%edx - subl %edx,%eax - ret -END(strcmp) diff --git a/sys/i386/strcpy.S b/sys/i386/strcpy.S deleted file mode 100644 index e6f6a0c..0000000 --- a/sys/i386/strcpy.S +++ /dev/null @@ -1,73 +0,0 @@ -/*- - * Copyright (c) 2002-2018 The UbixOS Project. - * All rights reserved. - * - * This was developed by Christopher W. Olsen for the UbixOS Project. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors. - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors in the documentation and/or - * other materials provided with the distribution. - * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - #include - - ENTRY(strcpy) - movl 4(%esp),%ecx /* dst address */ - movl 8(%esp),%edx /* src address */ - pushl %ecx /* push dst address */ - - .align 2,0x90 -L1: movb (%edx),%al /* unroll loop, but not too much */ - movb %al,(%ecx) - testb %al,%al - je L2 - movb 1(%edx),%al - movb %al,1(%ecx) - testb %al,%al - je L2 - movb 2(%edx),%al - movb %al,2(%ecx) - testb %al,%al - je L2 - movb 3(%edx),%al - movb %al,3(%ecx) - testb %al,%al - je L2 - movb 4(%edx),%al - movb %al,4(%ecx) - testb %al,%al - je L2 - movb 5(%edx),%al - movb %al,5(%ecx) - testb %al,%al - je L2 - movb 6(%edx),%al - movb %al,6(%ecx) - testb %al,%al - je L2 - movb 7(%edx),%al - movb %al,7(%ecx) - addl $8,%edx - addl $8,%ecx - testb %al,%al - jne L1 -L2: popl %eax /* pop dst address */ - ret -END(strcpy) diff --git a/sys/i386/strncmp.S b/sys/i386/strncmp.S deleted file mode 100644 index 9696281..0000000 --- a/sys/i386/strncmp.S +++ /dev/null @@ -1,129 +0,0 @@ -/*- - * Copyright (c) 2002-2018 The UbixOS Project. - * All rights reserved. - * - * This was developed by Christopher W. Olsen for the UbixOS Project. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors. - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors in the documentation and/or - * other materials provided with the distribution. - * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - #include - -ENTRY(strncmp) - pushl %ebx - movl 8(%esp),%eax - movl 12(%esp),%ecx - movl 16(%esp),%edx - testl %edx,%edx - jmp L2 /* Jump into the loop! */ - - .align 2,0x90 -L1: incl %eax - incl %ecx - decl %edx -L2: jz L4 /* strings are equal */ - movb (%eax),%bl - testb %bl,%bl - jz L3 - cmpb %bl,(%ecx) - jne L3 - incl %eax - incl %ecx - decl %edx - jz L4 - movb (%eax),%bl - testb %bl,%bl - jz L3 - cmpb %bl,(%ecx) - jne L3 - - incl %eax - incl %ecx - decl %edx - jz L4 - movb (%eax),%bl - testb %bl,%bl - jz L3 - cmpb %bl,(%ecx) - jne L3 - - incl %eax - incl %ecx - decl %edx - jz L4 - movb (%eax),%bl - testb %bl,%bl - jz L3 - cmpb %bl,(%ecx) - jne L3 - - incl %eax - incl %ecx - decl %edx - jz L4 - movb (%eax),%bl - testb %bl,%bl - jz L3 - cmpb %bl,(%ecx) - jne L3 - - incl %eax - incl %ecx - decl %edx - jz L4 - movb (%eax),%bl - testb %bl,%bl - jz L3 - cmpb %bl,(%ecx) - jne L3 - - incl %eax - incl %ecx - decl %edx - jz L4 - movb (%eax),%bl - testb %bl,%bl - jz L3 - cmpb %bl,(%ecx) - jne L3 - - incl %eax - incl %ecx - decl %edx - jz L4 - movb (%eax),%bl - testb %bl,%bl - jz L3 - cmpb %bl,(%ecx) - je L1 - - .align 2,0x90 -L3: movzbl (%eax),%eax /* unsigned comparison */ - movzbl (%ecx),%ecx - subl %ecx,%eax - popl %ebx - ret - .align 2,0x90 -L4: xorl %eax,%eax - popl %ebx - ret -END(strncmp) diff --git a/sys/i386/support.S b/sys/i386/support.S deleted file mode 100644 index 347cdf8..0000000 --- a/sys/i386/support.S +++ /dev/null @@ -1,120 +0,0 @@ -/*- - * Copyright (c) 2002-2018 The UbixOS Project. - * All rights reserved. - * - * This was developed by Christopher W. Olsen for the UbixOS Project. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors. - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors in the documentation and/or - * other materials provided with the distribution. - * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - #include -.text - -// void bzero(void *buf, u_int len) -ENTRY(bzero) - pushl %edi - movl 8(%esp),%edi - movl 12(%esp),%ecx - xorl %eax,%eax - shrl $2,%ecx - cld - rep - stosl - movl 12(%esp),%ecx - andl $3,%ecx - rep - stosb - popl %edi - ret -END(bzero) - -// bcopy(src, dst, cnt) -ENTRY(bcopy) - pushl %ebp - movl %esp,%ebp - pushl %esi - pushl %edi - movl 8(%ebp),%esi - movl 12(%ebp),%edi - movl 16(%ebp),%ecx - - movl %edi,%eax - subl %esi,%eax - cmpl %ecx,%eax /* overlapping && src < dst? */ - jb 1f - - shrl $2,%ecx /* copy by 32-bit words */ - cld /* nope, copy forwards */ - rep - movsl - movl 16(%ebp),%ecx - andl $3,%ecx /* any bytes left? */ - rep - movsb - popl %edi - popl %esi - popl %ebp - ret - - ALIGN_TEXT -1: - addl %ecx,%edi /* copy backwards */ - addl %ecx,%esi - decl %edi - decl %esi - andl $3,%ecx /* any fractional bytes? */ - std - rep - movsb - movl 16(%ebp),%ecx /* copy remainder by 32-bit words */ - shrl $2,%ecx - subl $3,%esi - subl $3,%edi - rep - movsl - popl %edi - popl %esi - cld - popl %ebp - ret -END(bcopy) - -// void *memcpy(const void *dst, const void * src, size_t length) -ENTRY(memcpy) - pushl %edi - pushl %esi - movl 12(%esp),%edi - movl 16(%esp),%esi - movl 20(%esp),%ecx - movl %edi,%eax - shrl $2,%ecx /* copy by 32-bit words */ - cld /* nope, copy forwards */ - rep - movsl - movl 20(%esp),%ecx - andl $3,%ecx /* any bytes left? */ - rep - movsb - popl %esi - popl %edi - ret -END(memcpy) diff --git a/sys/i386/sys_call.S b/sys/i386/sys_call.S deleted file mode 100644 index 7844128..0000000 --- a/sys/i386/sys_call.S +++ /dev/null @@ -1,109 +0,0 @@ -/*- - * Copyright (c) 2002-2018 The UbixOS Project. - * All rights reserved. - * - * This was developed by Christopher W. Olsen for the UbixOS Project. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors. - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors in the documentation and/or - * other materials provided with the distribution. - * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -.globl _sys_call -.text -.code32 - -_B4: -_B3: -nop - -_ast: - -_astRet: - -_sysCall_MrOlsen: -//MrOlsen 2018-01-14 push $0x2 -//MrOlsen 2018-01-14 sub $0x4,%esp -pusha -push %ds -push %es -push %fs -push %gs -mov $0x10,%eax -mov %eax,%ds -mov %eax,%es -mov %eax,%fs -cld -push %esp -call sys_call -add $0x4,%esp -cmpb $0x13,0x38(%esp) -je _B4 -testl $0x2000,0x3c(%esp) /* Test If VM */ -jz _notVM -jmp _isVM -_notVM: -testb $0x3,0x38(%esp) /* See If We're In User CS (GDT Entry 5) */ -jz _popFS -jmp _popFS /* TMP BECAUSE ABOVE ISN'T RIGHT */ -cli -mov %fs:0x0,%eax -testl $0x10800,0x80(%eax) /* Document This */ -je _popFS -sti -push %esp -call _ast -add $0x4,%esp -jmp _astRet -_isVM: -hlt - -_popFS: -pop %gs -pop %fs -pop %es -pop %ds -popa -//MrOlsen 2018-01-14 add $0x8,%esp -iret - -_sys_call: -push $0x0 -push $0x80 -pusha -push %ds -push %es -push %fs -push %gs -mov $0x10,%eax -mov %eax, %ds -mov %eax, %es -mov %eax, %fs -cld -push %esp -call sys_call -add $0x4,%esp /* Remove Stack Pointer From Stack */ -pop %gs -pop %fs -pop %es -pop %ds -popa -add $0x8,%esp //Back Out Error Code & trap_no -iret diff --git a/sys/i386/sys_call_posix.S b/sys/i386/sys_call_posix.S deleted file mode 100644 index d9b082f..0000000 --- a/sys/i386/sys_call_posix.S +++ /dev/null @@ -1,57 +0,0 @@ -/*- - * Copyright (c) 2002-2018 The UbixOS Project. - * All rights reserved. - * - * This was developed by Christopher W. Olsen for the UbixOS Project. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors. - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors in the documentation and/or - * other materials provided with the distribution. - * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#define FAKE_MCOUNT(caller) pushl caller ; call __mcount ; popl %ecx - -.globl _sys_call_posix -.text -.code32 - -_sys_call_posix: -push $0x0 -push $0x80 -pusha -push %ds -push %es -push %fs -push %gs -mov $0x10,%eax -mov %eax, %ds -mov %eax, %es -mov %eax, %fs -cld -push %esp -call sys_call_posix -add $0x4,%esp /* Remove Stack Pointer From Stack */ -pop %gs -pop %fs -pop %es -pop %ds -popa -add $0x8,%esp //Back Out Error Code & trap_no -iret diff --git a/sys/i386/systemtask.c b/sys/i386/systemtask.c deleted file mode 100644 index 952fc06..0000000 --- a/sys/i386/systemtask.c +++ /dev/null @@ -1,131 +0,0 @@ -/*- - * Copyright (c) 2002-2018 The UbixOS Project. - * All rights reserved. - * - * This was developed by Christopher W. Olsen for the UbixOS Project. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors. - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors in the documentation and/or - * other materials provided with the distribution. - * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static unsigned char *videoBuffer = (unsigned char *) 0xB8000; - -void systemTask() { - - mpi_message_t myMsg; - uint32_t counter = 0x0; - int i = 0x0; - int *x = 0x0; - kTask_t *tmpTask = 0x0; - - char buf[16] = { "a\n" }; - - if (mpi_createMbox("system") != 0x0) { - kpanic("Error: Error creating mailbox: system\n"); - } - - while (1) { - if (mpi_fetchMessage("system", &myMsg) == 0x0) { - switch (myMsg.header) { - case 0x69: - x = (int *) &myMsg.data; - kprintf("Switching to term: [%i][%i]\n", *x, myMsg.pid); - schedFindTask(myMsg.pid)->term = tty_find(*x); - break; - case 1000: - kprintf("Restarting the system in 5 seconds\n"); - counter = systemVitals->sysUptime + 5; - while (systemVitals->sysUptime < counter) { - sched_yield(); - } - kprintf("Rebooting NOW!!!\n"); - while (inportByte(0x64) & 0x02) - ; - outportByte(0x64, 0xFE); - break; - case 31337: - kprintf("system: backdoor opened\n"); - break; - case 0x80: - if (!strcmp(myMsg.data, "sdeStart")) { - kprintf("Starting SDE\n"); - execThread(sdeThread,0x2000,0x0); - } - else if (!strcmp(myMsg.data, "freePage")) { - kprintf("kkk Free Pages"); - } - else if (!strcmp(myMsg.data, "sdeStop")) { - printOff = 0x0; - biosCall(0x10, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0); - for (i = 0x0; i < 100; i++) - asm("hlt"); - } - break; - default: - kprintf("system: Received message %i:%s\n", myMsg.header, myMsg.data); - break; - } - } - - /* - Here we get the next task from the delete task queue - we first check to see if it has an fd attached for the binary and after that - we free the pages for the process and then free the task - */ - tmpTask = sched_getDelTask(); - - if (tmpTask != 0x0) { - if (tmpTask->files[0] != 0x0) - fclose(tmpTask->files[0]); - vmm_freeProcessPages(tmpTask->id); - kfree(tmpTask); - - } - - if (ogprintOff == 1) { - videoBuffer[0] = systemVitals->sysTicks; - videoBuffer[1] = 'c'; - } - /* - else - ogPrintf(buf); - */ - - sched_yield(); - } - - return; -} diff --git a/sys/i386/timer.S b/sys/i386/timer.S deleted file mode 100644 index 1ddfcc1..0000000 --- a/sys/i386/timer.S +++ /dev/null @@ -1,75 +0,0 @@ -/*- - * Copyright (c) 2002-2018 The UbixOS Project. - * All rights reserved. - * - * This was developed by Christopher W. Olsen for the UbixOS Project. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors. - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors in the documentation and/or - * other materials provided with the distribution. - * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -.globl timerInt -.text -.code32 -timerInt: - pusha /* Save all of the registers */ - mov $0x20,%dx /* The Following Sends Our EOI To The MPIC */ - mov $0x20,%ax - outb %al,%dx - movl systemVitals,%ecx /* Put Location Of System Vitals Into ECX */ - incl (%ecx) /* Increment sysTicks our 1000ms counter */ - movl (%ecx),%eax /* Increment our sysUptime by 1S if 1000MS */ - movl $200,%ebx /* Have Passed */ - xor %edx,%edx - div %ebx - test %edx,%edx - jnz next - incl 4(%ecx) -next: - movl (%ecx),%eax /* Test If quantum Has Passed If So Then */ - movl 8(%ecx),%ebx /* We Can CALL sched */ - xor %edx,%edx - div %ebx - test %edx,%edx - jnz done -/* -push %ds -push %es -push %fs -push %gs -mov $0x10,%eax -mov %eax, %ds -mov %eax, %es -mov %eax, %fs -cld -*/ -/* push %esp */ - call sched -/* add $0x4,%esp */ /* Remove Stack Pointer From Stack */ -/* -pop %gs -pop %fs -pop %es -pop %ds -*/ -done: - popa /* Restore Registers */ - iret diff --git a/sys/i386/trap.c b/sys/i386/trap.c deleted file mode 100644 index 60f0c65..0000000 --- a/sys/i386/trap.c +++ /dev/null @@ -1,133 +0,0 @@ -/*- - * Copyright (c) 2002-2018 The UbixOS Project. - * All rights reserved. - * - * This was developed by Christopher W. Olsen for the UbixOS Project. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors. - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors in the documentation and/or - * other materials provided with the distribution. - * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include - -#define FIRST_TSS_ENTRY 6 -#define VM_MASK 0x00020000 - -#define store_TR(n) \ - __asm__("str %%ax\n\t" \ - "subl %2,%%eax\n\t" \ - "shrl $4,%%eax" \ - :"=a" (n) \ - :"0" (0),"i" (FIRST_TSS_ENTRY<<3)) - -#define get_seg_long(seg,addr) ({ \ - register unsigned long __res; \ - __asm__("push %%fs;mov %%ax,%%fs;movl %%fs:%2,%%eax;pop %%fs" \ - :"=a" (__res):"0" (seg),"m" (*(addr))); \ - __res;}) - -#define get_seg_byte(seg,addr) ({ \ -register char __res; \ -__asm__("push %%fs;mov %%ax,%%fs;movb %%fs:%2,%%al;pop %%fs" \ - :"=a" (__res):"0" (seg),"m" (*(addr))); \ -__res;}) - -void die_if_kernel(char *str, struct trapframe *regs, long err) { - int i; - unsigned long esp; - unsigned short ss; - unsigned long *stack; - - esp = (unsigned long) ®s->tf_esp; - - ss = 0x10; //KERNEL_DS - - //if ((regs->tf_eflags & VM_MASK) || (3 & regs->tf_cs) == 3) - // return; - - if ((regs->tf_cs & 3) == 3) { - esp = regs->tf_esp; - ss = regs->tf_ss; - kprintf("USER TASK!"); - } - else { - ss = 0x10; - } - - kprintf("\n%s: 0x%X:%i, CPU %d, EIP: 0x%X, EFLAGS: 0x%X\n", str, regs->tf_err, regs->tf_trapno, 0x0, regs->tf_eip, regs->tf_eflags); - kprintf("eax: %08lx ebx: %08lx ecx: %08lx edx: %08lx\n", regs->tf_eax, regs->tf_ebx, regs->tf_ecx, regs->tf_edx); - kprintf("esi: %08lx edi: %08lx ebp: %08lx esp: %08lx\n", regs->tf_esi, regs->tf_edi, regs->tf_ebp, esp); - kprintf("cs: 0x%X ds: 0x%X es: 0x%X fs: 0x%X gs: 0x%X ss: 0x%X\n", regs->tf_cs, regs->tf_ds, regs->tf_es, regs->tf_fs, regs->tf_gs, ss); - kprintf("cr0: 0x%X, cr2: 0x%X, cr3: 0x%X, cr4: 0x%X\n", rcr0(), rcr2(), rcr3(), rcr4()); - - store_TR(i); - kprintf("Process %s (pid: %i, process nr: %d, stackpage=%08lx)\nStack:", _current->name, _current->id, 0xffff & i, esp); - - stack = (unsigned long *) esp; - - for (i = 0; i < 16; i++) { - if (i && ((i % 8) == 0)) - kprintf("\n "); - kprintf("%08lx ", get_seg_long(ss, stack++)); - } - - endTask(_current->id); -} - -void trap(struct trapframe *frame) { - u_int trap_code; - u_int cr2 = 0; - - trap_code = frame->tf_trapno; - - cr2 = rcr2(); - kprintf("CR2: 0x%X(0x%X)[0x%X]", cr2,_current->tss.eip,_current->tss.ldt); - if (_current->id == 7) - while(1) asm("nop"); - - if ((frame->tf_eflags & PSL_I) == 0) { - if (SEL_GET_PL(frame->tf_cs) == SEL_PL_USER || (frame->tf_eflags & PSL_VM)) { - kpanic( "INT OFF! USER" ); - die_if_kernel("TEST", frame, 0x100); - } - else { - kpanic( "INT OFF! KERN[0x%X]", trap_code ); - die_if_kernel("TEST", frame, 0x200); - } - } - - kprintf("trap_code: %i(0x%X), EIP: 0x%X, CR2: 0x%X\n", frame->tf_trapno, frame->tf_trapno, frame->tf_eip, cr2); - if (frame->tf_trapno == 0xc) { - vmm_pageFault(frame, cr2); - } - else { - kpanic("TRAPCODE"); - die_if_kernel("trapCode", frame, frame->tf_trapno); - endTask(_current->id); - sched_yield(); - } -} diff --git a/sys/include/lib/kern_trie.h b/sys/include/lib/kern_trie.h new file mode 100644 index 0000000..07e8171 --- /dev/null +++ b/sys/include/lib/kern_trie.h @@ -0,0 +1,51 @@ +/*- + * Copyright (c) 2002-2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LIB_KERN_TRIE_H_ +#define _LIB_KERN_TRIE_H_ + +#include + +#define CHAR_SIZE 26 + +struct Trie { + u_int8_t isLeaf; + struct Trie *character[CHAR_SIZE]; + void *e; +}; + + +struct Trie *new_trieNode(); + +void insert_trieNode(struct Trie **, char *, void *); + +struct Trie *search_trieNode(struct Trie *, char *); + +int delete_trieNode(struct Trie **, char *); + +#endif _LIB_LKERN_TRIE_H_ diff --git a/sys/include/objgfx/ogDisplay_VESA.h b/sys/include/objgfx/ogDisplay_VESA.h old mode 100644 new mode 100755 diff --git a/sys/include/sde/ogDisplay_UbixOS.h b/sys/include/sde/ogDisplay_UbixOS.h old mode 100644 new mode 100755 diff --git a/sys/include/sys/kern_sysctl.h b/sys/include/sys/kern_sysctl.h index 9aeb258..2820992 100644 --- a/sys/include/sys/kern_sysctl.h +++ b/sys/include/sys/kern_sysctl.h @@ -61,6 +61,8 @@ int id; void *value; int val_len; + int full_name[CTL_MAXNAME]; + int namelen; }; int kern_sysctl(int *name,u_int namelen,void *old,size_t *oldlenp,void *new,size_t newlen,size_t *retval,int flags); diff --git a/sys/init/main.c b/sys/init/main.c index 8b4ebbe..46c78f5 100644 --- a/sys/init/main.c +++ b/sys/init/main.c @@ -109,8 +109,17 @@ union descriptorTableUnion *gdt __attribute__ ((packed)); } loadGDT = { (11 * sizeof(union descriptorTableUnion) - 1), ubixGDT }; -static char *argv_init[2] = { "init", NULL, }; // ARGV For Initial Proccess -static char *envp_init[6] = { "HOME=/", "PWD=/", "PATH=/bin:/sbin:/usr/bin:/usr/sbin", "USER=root", "GROUP=admin", NULL, }; //ENVP For Initial Proccess +static char *argv_init[2] = { + "init", + NULL, }; /* ARGV For Initial Process */ + +static char *envp_init[6] = { + "HOME=/", + "PWD=/", + "PATH=/bin:/sbin:/usr/bin:/usr/sbin", + "USER=root", + "GROUP=admin", + NULL, }; /* ENVP For Initial Process */ struct bootinfo _bootinfo; char _kernelname[512]; @@ -136,9 +145,9 @@ } /* New Root Mount Point */ - //Old 2 new 10 + /* Old 2 new 10 */ kprintf("[0x%X][0x%X:0x%X:0x%X:0x%X:0x%X:0x%X]\n", B_ADAPTOR(rootdev), B_CONTROLLER(rootdev), B_SLICE(rootdev), B_UNIT(rootdev), B_PARTITION(rootdev), B_TYPE(rootdev)); - //if ( vfs_mount( B_UNIT(_bootdev), B_PARTITION(_bootdev), 0x0, 0xAA, "sys", "rw" ) != 0x0 ) { + /* if ( vfs_mount( B_UNIT(_bootdev), B_PARTITION(_bootdev), 0x0, 0xAA, "sys", "rw" ) != 0x0 ) { */ if (vfs_mount(0x1, 0x2, 0x0, 0xAA, "sys", "rw") != 0x0) { kprintf("Problem Mounting sys Mount Point\n"); } @@ -162,8 +171,8 @@ - //kprintf("SDE Thread Start! [0x%X]\n", &sdeThread); - //execThread(&sdeThread, 0x2000,0x0); + /* kprintf("SDE Thread Start! [0x%X]\n", &sdeThread); */ + /* execThread(&sdeThread, 0x2000,0x0); */ kprintf("Kernel Name: [%s], Boot How To [0x%X], Boot Dev: [0x%X]\n", _kernelname, _boothowto, _bootdev); kprintf("B_TYPE(0x%X), B_SLICE(0x%X), B_UNIT(0x%X), B_PARTITION(0x%X)\n", B_TYPE(_bootdev), B_SLICE(_bootdev), B_UNIT(_bootdev), B_PARTITION(_bootdev)); diff --git a/sys/kernel/kern_sysctl.c b/sys/kernel/kern_sysctl.c index 0ab8ae8..1fed190 100644 --- a/sys/kernel/kern_sysctl.c +++ b/sys/kernel/kern_sysctl.c @@ -36,12 +36,15 @@ #include #include #include +#include static struct sysctl_entry *ctls = 0x0; static struct sysctl_entry *sysctl_find(int *, int); static struct sysctl_entry *sysctl_findMib(char *name, int namelen); +struct Trie *sysctl_headTrie = 0x0; + /* This is a cheat for now */ static void def_ctls() { int name[CTL_MAXNAME], name_len; @@ -116,21 +119,38 @@ char s61[4] = "i386"; sysctl_add(name, name_len, "kern.hostname", &s61, 4); + /* XXX 6, 2147482988 */ + name[0] = 6; + name[1] = 2147482988; + page_val = 4096; + sysctl_add(name, name_len, "hw.pagesizes", &page_val, sizeof(u_int32_t)); + + name[0] = 2; + name[1] = 12; + page_val = 0; + sysctl_add(name, name_len, "vm.overcommit", &page_val, sizeof(u_int32_t)); + } int sysctl_init() { + struct sysctl_entry *tmpCtl = 0x0; + if (ctls != 0x0) { kprintf("sysctl already Initialized\n"); while (1) ; } + /* Initialize Head Trie */ + sysctl_headTrie = (struct Trie *) kmalloc(sizeof(struct Trie)); + ctls = (struct sysctl_entry *) kmalloc(sizeof(struct sysctl_entry)); ctls->prev = 0x0; ctls->id = CTL_UNSPEC; ctls->children = 0x0; sprintf(ctls->name, "unspec"); + insert_trieNode(&sysctl_headTrie, &ctls->name, ctls); tmpCtl = (struct sysctl_entry *) kmalloc(sizeof(struct sysctl_entry)); tmpCtl->prev = ctls; @@ -138,6 +158,7 @@ tmpCtl->children = 0x0; sprintf(tmpCtl->name, "kern"); ctls->next = tmpCtl; + insert_trieNode(&sysctl_headTrie, &ctls->name, ctls); tmpCtl->next = (struct sysctl_entry *) kmalloc(sizeof(struct sysctl_entry)); tmpCtl->next->prev = tmpCtl; @@ -145,6 +166,7 @@ tmpCtl->id = CTL_VM; tmpCtl->children = 0x0; sprintf(tmpCtl->name, "vm"); + insert_trieNode(&sysctl_headTrie, &ctls->name, ctls); tmpCtl->next = (struct sysctl_entry *) kmalloc(sizeof(struct sysctl_entry)); tmpCtl->next->prev = tmpCtl; @@ -152,6 +174,7 @@ tmpCtl->id = CTL_VFS; tmpCtl->children = 0x0; sprintf(tmpCtl->name, "vfs"); + insert_trieNode(&sysctl_headTrie, &ctls->name, ctls); tmpCtl->next = (struct sysctl_entry *) kmalloc(sizeof(struct sysctl_entry)); tmpCtl->next->prev = tmpCtl; @@ -159,6 +182,7 @@ tmpCtl->id = CTL_NET; tmpCtl->children = 0x0; sprintf(tmpCtl->name, "net"); + insert_trieNode(&sysctl_headTrie, &ctls->name, ctls); tmpCtl->next = (struct sysctl_entry *) kmalloc(sizeof(struct sysctl_entry)); tmpCtl->next->prev = tmpCtl; @@ -166,6 +190,7 @@ tmpCtl->id = CTL_DEBUG; tmpCtl->children = 0x0; sprintf(tmpCtl->name, "debug"); + insert_trieNode(&sysctl_headTrie, &ctls->name, ctls); tmpCtl->next = (struct sysctl_entry *) kmalloc(sizeof(struct sysctl_entry)); tmpCtl->next->prev = tmpCtl; @@ -173,6 +198,7 @@ tmpCtl->id = CTL_HW; tmpCtl->children = 0x0; sprintf(tmpCtl->name, "hw"); + insert_trieNode(&sysctl_headTrie, &ctls->name, ctls); tmpCtl->next = (struct sysctl_entry *) kmalloc(sizeof(struct sysctl_entry)); tmpCtl->next->prev = tmpCtl; @@ -180,6 +206,7 @@ tmpCtl->id = CTL_MACHDEP; tmpCtl->children = 0x0; sprintf(tmpCtl->name, "machdep"); + insert_trieNode(&sysctl_headTrie, &ctls->name, ctls); tmpCtl->next = (struct sysctl_entry *) kmalloc(sizeof(struct sysctl_entry)); tmpCtl->next->prev = tmpCtl; @@ -187,6 +214,7 @@ tmpCtl->id = CTL_USER; tmpCtl->children = 0x0; sprintf(tmpCtl->name, "user"); + insert_trieNode(&sysctl_headTrie, &ctls->name, ctls); tmpCtl->next = (struct sysctl_entry *) kmalloc(sizeof(struct sysctl_entry)); tmpCtl->next->prev = tmpCtl; @@ -194,6 +222,7 @@ tmpCtl->id = CTL_P1003_1B; tmpCtl->children = 0x0; sprintf(tmpCtl->name, "p1003_1b"); + insert_trieNode(&sysctl_headTrie, &ctls->name, ctls); tmpCtl->next = (struct sysctl_entry *) kmalloc(sizeof(struct sysctl_entry)); tmpCtl->next->prev = tmpCtl; @@ -201,6 +230,7 @@ tmpCtl->id = CTL_UBIX; tmpCtl->children = 0x0; sprintf(tmpCtl->name, "ubix"); + insert_trieNode(&sysctl_headTrie, &ctls->name, ctls); def_ctls(); @@ -240,6 +270,7 @@ int sys_sysctl(struct thread *td, struct sys_sysctl_args *args) { struct sysctl_entry *tmpCtl = 0x0; + struct Trie *tmpTrie = 0x0; int i = 0; if (ctls == 0x0) @@ -250,26 +281,60 @@ endTask(_current->id); } + /* XXX - Handle search by name */ if (args->namelen == 2 && args->name[0] == 0 && args->name[1] == 3) { - #ifdef DEBUG_SYSCTL - kprintf("%s:%i>name_to_mib: %s", __FILE__,__LINE__,args->newp); - #endif - // tmpCtl = sysctl_findMib(args->newp, args->namelen); - td->td_retval[0] = ENOENT; - return(-1); + + tmpTrie = search_trieNode(sysctl_headTrie, args->newp); + + if (tmpTrie != 0x0) { + tmpCtl = (struct sysctl_entry *)tmpTrie->e; + + //kprintf("\n", tmpCtl->name,tmpCtl->namelen); + + // tmpCtl = sysctl_findMib(args->newp, args->namelen); + *args->oldlenp = tmpCtl->namelen *4; + u_int32_t *oldp = args->oldp; + + for (i=0;inamelen;i++) + oldp[i] = tmpCtl->full_name[i]; + + td->td_retval[0] = 0; /* XXX - Very Bad need to store namelen in the struct */ + + return(0x0); + } + else { + + #ifdef DEBUG_SYSCTL + kprintf("%s:%i>name_to_mib: %s\n", __FILE__,__LINE__,args->newp); + #endif + + td->td_retval[0] = ENOENT; + return(-1); + } } else { - tmpCtl = sysctl_find(args->name, args->namelen); + tmpCtl = sysctl_find(args->name, args->namelen); } if (tmpCtl == 0x0) { - kprintf("Invalid CTL: "); + kprintf("Invalid CTL(%i): ", args->namelen); for (i = 0x0; i < args->namelen; i++) kprintf("(%i)", (int) args->name[i]); kprintf("\n"); td->td_retval[0] = -1; return (-1); } + /* + else { + kprintf("Valid CTL(%i): ", args->namelen); + for (i = 0x0; i < args->namelen; i++) + kprintf("(%i)", (int) args->name[i]); + kprintf("\n"); + } + + kprintf("{%i:%i}\n",args->oldlenp, tmpCtl->val_len); + +*/ if ((uint32_t) args->oldlenp < tmpCtl->val_len) memcpy(args->oldp, tmpCtl->value, (uInt32) args->oldlenp); @@ -312,6 +377,10 @@ kprintf("FMIB: %s", mib); + + lCtl = (struct sysctl_entry *) search_trieNode(sysctl_headTrie, mib)->e; + kprintf("FT: %s", lCtl->name); + /* Loop Name Len */ for (i = 0x0; i < namelen; i++) { for (tmpCtl = lCtl; tmpCtl != 0x0; tmpCtl = tmpCtl->next) { @@ -334,6 +403,7 @@ int sysctl_add(int *name, int namelen, char *str_name, void *buf, int buf_size) { struct sysctl_entry *tmpCtl = 0x0; struct sysctl_entry *newCtl = 0x0; + int i = 0; /* Check if it exists */ tmpCtl = sysctl_find(name, namelen); @@ -351,22 +421,38 @@ } if (tmpCtl->children == 0x0) { tmpCtl->children = (struct sysctl_entry *) kmalloc(sizeof(struct sysctl_entry)); + memset(tmpCtl->children, 0x0, sizeof(struct sysctl_entry)); tmpCtl->children->children = 0x0; tmpCtl->children->prev = 0x0; tmpCtl->children->next = 0x0; tmpCtl->children->id = name[namelen - 1]; + for (i = 0; i < namelen;i++) + tmpCtl->children->full_name[i] = name[i]; + + tmpCtl->children->namelen = namelen; + sprintf(tmpCtl->children->name, str_name); + + insert_trieNode(&sysctl_headTrie, &tmpCtl->children->name, tmpCtl->children); tmpCtl->children->value = (void *) kmalloc(buf_size); memcpy(tmpCtl->children->value, buf, buf_size); tmpCtl->children->val_len = buf_size; } else { newCtl = (struct sysctl_entry *) kmalloc(sizeof(struct sysctl_entry)); + memset(newCtl, 0x0, sizeof(struct sysctl_entry)); newCtl->prev = 0x0; newCtl->next = tmpCtl->children; newCtl->children = 0x0; newCtl->id = name[namelen - 1]; + + for (i = 0; ifull_name[i] = name[i]; + + newCtl->namelen = namelen; + sprintf(newCtl->name, str_name); + insert_trieNode(&sysctl_headTrie, &newCtl->name, newCtl); newCtl->value = (void *) kmalloc(buf_size); memcpy(newCtl->value, buf, buf_size); newCtl->val_len = buf_size; diff --git a/sys/lib/kern_trie.c b/sys/lib/kern_trie.c new file mode 100644 index 0000000..d07ec03 --- /dev/null +++ b/sys/lib/kern_trie.c @@ -0,0 +1,149 @@ +/*- + * Copyright (c) 2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include + +struct Trie *new_trieNode() { + + struct Trie *node = (struct Trie *) kmalloc(sizeof(struct Trie)); + + node->isLeaf = 0; + + for (int i = 0; i < CHAR_SIZE; i++) + node->character[i] = NULL; + + return (node); +} + +// Insert Trie +void insert_trieNode(struct Trie **head, char* str, void *e) { + + // start from root node + struct Trie* curr = *head; + + while (*str) { + + // create a new node if path doesn't exists + if (curr->character[*str - 'a'] == NULL) { + curr->character[*str - 'a'] = new_trieNode(); + } + + // go to next node + curr = curr->character[*str - 'a']; + // move to next character + str++; + } + + curr->e = e; + // mark current node as leaf + curr->isLeaf = 1; +} + + +struct Trie *search_trieNode(struct Trie *head, char *str) { + + // return 0 if Trie is empty + if (head == NULL || str == NULL) + return (0); + + struct Trie *curr = head; + + while (*str) { + + // go to next node + curr = curr->character[*str - 'a']; + + // if string is invalid (reached end of path in Trie) + if (curr == NULL) + return (0); + + // move to next character + str++; + } + + // if current node is a leaf and we have reached the + // end of the string, return 1 + return (curr); +} + + + +// Recursive function to delete a string in Trie +int delete_trieNode(struct Trie **curr, char *str) { + + // return if Trie is empty + if (*curr == NULL) + return (0); + + // if we have not reached the end of the string + if (*str) { + // recurse for the node corresponding to next character in + // the string and if it returns 1, delete current node + // (if it is non-leaf) + if (*curr != NULL && (*curr)->character[*str - 'a'] != NULL && deletion(&((*curr)->character[*str - 'a']), str + 1) && (*curr)->isLeaf == 0) { + if (!haveChildren(*curr)) { + free(*curr); + (*curr) = NULL; + return (1); + } + else { + return (0); + } + } + } + + // if we have reached the end of the string + if (*str == '\0' && (*curr)->isLeaf) { + // if current node is a leaf node and don't have any children + if (!haveChildren(*curr)) { + free(*curr); // delete current node + (*curr) = NULL; + return (1); // delete non-leaf parent nodes + } + + // if current node is a leaf node and have children + else { + // mark current node as non-leaf node (DON'T DELETE IT) + (*curr)->isLeaf = 0; + return (0); // don't delete its parent nodes + } + } + + return (0); +} + +// returns 1 if given node has any children +int haveChildren(struct Trie* curr) { + for (int i = 0; i < CHAR_SIZE; i++) + if (curr->character[i]) + return (1); // child found + + return (0); +} diff --git a/sys/lib/kprintf.c b/sys/lib/kprintf.c index 66d096a..6d0c8a4 100644 --- a/sys/lib/kprintf.c +++ b/sys/lib/kprintf.c @@ -279,7 +279,7 @@ va_list args; int i; va_start(args, fmt); -//i = vsprintf( buf, fmt, args ); + /* i = vsprintf( buf, fmt, args ); */ i = kvprintf(fmt, NULL, buf, 10, args); va_end(args); return (i); diff --git a/sys/net/core/def.c b/sys/net/core/def.c index bfa98af..3d5469f 100644 --- a/sys/net/core/def.c +++ b/sys/net/core/def.c @@ -11,7 +11,7 @@ * \#define lwip_htonl(x) your_htonl * * Note lwip_ntohs() and lwip_ntohl() are merely references to the htonx counterparts. - * + * * If you \#define them to htons() and htonl(), you should * \#define LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS to prevent lwIP from * defining htonx/ntohx compatibility macros. @@ -72,10 +72,8 @@ * @param n u16_t in host byte order * @return n in network byte order */ -u16_t -lwip_htons(u16_t n) -{ - return (u16_t)PP_HTONS(n); +u16_t lwip_htons(u16_t n) { + return ((u16_t) PP_HTONS(n)); } #endif /* lwip_htons */ @@ -89,7 +87,7 @@ u32_t lwip_htonl(u32_t n) { - return (u32_t)PP_HTONL(n); + return ((u32_t) PP_HTONL(n)); } #endif /* lwip_htonl */ @@ -114,7 +112,7 @@ return LWIP_CONST_CAST(char *, p); } } - return NULL; + return (NULL); } #endif @@ -141,15 +139,15 @@ if (c1_upc != c2_upc) { /* still not equal */ /* don't care for < or > */ - return 1; + return (1); } } else { /* characters are not equal but none is in the alphabet range */ - return 1; + return (1); } } } while (c1 != 0); - return 0; + return (0); } #endif @@ -176,15 +174,15 @@ if (c1_upc != c2_upc) { /* still not equal */ /* don't care for < or > */ - return 1; + return (1); } } else { /* characters are not equal but none is in the alphabet range */ - return 1; + return (1); } } } while (len-- && c1 != 0); - return 0; + return (0); } #endif diff --git a/sys/net/netif/Makefile b/sys/net/netif/Makefile old mode 100644 new mode 100755 diff --git a/sys/sde/ogDisplay_UbixOS.cc b/sys/sde/ogDisplay_UbixOS.cc old mode 100644 new mode 100755 diff --git a/sys/vmm/vmm_memory.c b/sys/vmm/vmm_memory.c index 56e2ac8..6139d61 100644 --- a/sys/vmm/vmm_memory.c +++ b/sys/vmm/vmm_memory.c @@ -40,7 +40,7 @@ static uint32_t freePages = 0; static struct spinLock vmmSpinLock = SPIN_LOCK_INITIALIZER; -static struct spinLock vmmCowSpinLock = SPIN_LOCK_INITIALIZER; +//static struct spinLock vmmCowSpinLock = SPIN_LOCK_INITIALIZER; int numPages = 0x0; @@ -344,7 +344,7 @@ ************************************************************************/ -/* TODO: This can be greatly immproved for performance but it gets the job done */ +/* TODO: This can be greatly improved for performance but it gets the job done */ void vmm_freeProcessPages(pidType pid) { int i = 0, x = 0; uint32_t *tmpPageTable = 0x0; @@ -353,7 +353,7 @@ spinLock(&vmmSpinLock); /* Check Page Directory For An Avail Page Table */ - //NOTE: Thie cleans all memory space up to kernel space + //NOTE: This cleans all memory space up to kernel space #ifdef _IGNORE for (i = 0; i < (PAGE_SIZE - (PAGE_SIZE / 4)); i++) { diff --git a/tools/SCRIPT.DPF b/tools/SCRIPT.DPF old mode 100644 new mode 100755 Binary files differ diff --git a/tools/mbr b/tools/mbr old mode 100644 new mode 100755 Binary files differ diff --git a/tools/stat b/tools/stat old mode 100644 new mode 100755 Binary files differ