From 570c811d635be7924b3e7bfc3cdfdf0e6e865bce Mon Sep 17 00:00:00 2001 From: Tomas 'ZeXx86' Jedrzejek Date: Thu, 29 Nov 2007 17:07:53 +0100 Subject: [PATCH] Added two next system calls, fixed sys_sleep, added usleep to glibc, modified some scripts --- apps/xmasring/Makefile | 45 ++++++++++++++++++++ apps/xmasring/README | 5 +++ apps/xmasring/link.ld | 32 ++++++++++++++ glibc/unistd/sleep.c => apps/xmasring/main.c | 63 +++++++++++++++++++++------- apps/xmasring/make_img.sh | 16 +++++++ apps/xmasring/start.asm | 53 +++++++++++++++++++++++ glibc/AUTHORS | 2 +- glibc/Makefile | 3 +- glibc/VERSION | 2 +- glibc/include/stdio.h | 1 + glibc/include/unistd.h | 1 + glibc/{unistd/sleep.c => stdio/beep.c} | 19 ++++----- glibc/unistd/sleep.c | 21 +++++++++- kernel/core/system_call.c | 9 +++- make_iso.sh | 13 ++++++ 15 files changed, 253 insertions(+), 32 deletions(-) create mode 100644 apps/xmasring/Makefile create mode 100644 apps/xmasring/README create mode 100644 apps/xmasring/link.ld copy glibc/unistd/sleep.c => apps/xmasring/main.c (55%) create mode 100755 apps/xmasring/make_img.sh create mode 100755 apps/xmasring/start.asm copy glibc/{unistd/sleep.c => stdio/beep.c} (83%) mode change 100755 => 100644 diff --git a/apps/xmasring/Makefile b/apps/xmasring/Makefile new file mode 100644 index 0000000..ac22e34 --- /dev/null +++ b/apps/xmasring/Makefile @@ -0,0 +1,45 @@ +.SUFFIXES: .asm + +# defines +MAKEFILE=Makefile +MAKEDEP=$(MAKEFILE) +NASM =nasm -f elf +GLIBC =../../glibc +LSCRIPT =./link.ld +LFLAGS =-g -T$(LSCRIPT) +INCDIR =$(GLIBC)/include +CC =gcc -m32 -g -O2 -Wall -W -c -nostdinc -fno-builtin -I$(INCDIR) +#-Wall -W +LD =ld -m elf_i386 -s -nostdlib +LIBC =$(GLIBC)/libc.a +OBJS =start.o main.o + +# targets +all: xmasring + +install: xmasring + mkdir mnt + mount /dev/fd0 mnt + cp -f xmasring ./mnt/xmasring + umount mnt + rmdir mnt + +clean: + rm -f *.o xmasring $(OBJS) +# implicit rules +.asm.o: + $(NASM) -o$@ $< + +.c.o: + $(CC) -c -o$@ $< + +#: dependencies +# boot +start.o: start.asm $(MAKEDEP) +# kernel +main.o: main.c $(MAKEDEP) + + +# explicit rules +xmasring: $(OBJS) $(LIBC) $(MAKEDEP) + $(LD) $(LFLAGS) -o$@ $(OBJS) $(LIBC) \ No newline at end of file diff --git a/apps/xmasring/README b/apps/xmasring/README new file mode 100644 index 0000000..82fd56b --- /dev/null +++ b/apps/xmasring/README @@ -0,0 +1,5 @@ +Description: Play Christmas song +Info: Listen music + +License: GNU/GPL3 +Author: ZeXx86 \ No newline at end of file diff --git a/apps/xmasring/link.ld b/apps/xmasring/link.ld new file mode 100644 index 0000000..44f524c --- /dev/null +++ b/apps/xmasring/link.ld @@ -0,0 +1,32 @@ +OUTPUT_FORMAT("elf32-i386") +ENTRY(entry) +SECTIONS +{ + .text : /* 1 gig */ + { + code = .; _code = .; __code = .; + *(.text) + . = ALIGN(4096); + } + .data : + { + data = .; _data = .; __data = .; + *(.data) + . = ALIGN(4096); + } + .bss : + { + bss = .; _bss = .; __bss = .; + *(.bss) + *(COMMON) + . = ALIGN(4096); + } + .rodata 0x2000 : + { + rodata = .; _rodata = .; __rodata = .; + *(.rodata) + *(.rodata.*) + . = ALIGN(4096); + } + end = .; _end = .; +} diff --git a/glibc/unistd/sleep.c b/apps/xmasring/main.c similarity index 55% copy from glibc/unistd/sleep.c copy to apps/xmasring/main.c index be02f62..4b9b488 100755 --- a/glibc/unistd/sleep.c +++ b/apps/xmasring/main.c @@ -17,20 +17,51 @@ */ -unsigned int sleep (unsigned int s) +#include +#include +#include +#include + +#define ESC 1 + +unsigned key_pressed (int keycode) { - asm volatile ( - "pushl %%eax;" - "pushl %%ebx;" - "pushl %%ecx;" - "pushl %%edx;" - "movl $3, %%eax;" - "movl %0, %%ebx;" - "int $0x80;" - "popl %%edx;" - "popl %%ecx;" - "popl %%ebx;" - "popl %%eax;" :: "g" (s)); - - return 0; -} + int scancode = getkey (); + + if (scancode == keycode) + return 1; + + if (scancode == keycode+128) + return 2; + else + return 0; +} + +void play_sound (unsigned freq, unsigned time) +{ + beep (freq); + usleep (time); + beep (0); +} + +int main (char *arg, int argl) +{ + beep (); + + while (1) { + play_sound (750, 500); + play_sound (1000, 500); + play_sound (500, 500); + play_sound (100, 500); + + if (key_pressed (ESC)) + break; + + schedule (); + } + + exit (1); + + return 1; +} + diff --git a/apps/xmasring/make_img.sh b/apps/xmasring/make_img.sh new file mode 100755 index 0000000..dd02be5 --- /dev/null +++ b/apps/xmasring/make_img.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# Folder name of your application +APPNAME="nc" + +# Compile source +make + +# Optimized for 1,4MB floppy +dd if=/dev/zero of=$APPNAME.img bs=1440k count=1 +mkfs.vfat $APPNAME.img + +mkdir floppy +mount -oloop $APPNAME.img floppy +cp $APPNAME floppy +umount floppy +rmdir floppy \ No newline at end of file diff --git a/apps/xmasring/start.asm b/apps/xmasring/start.asm new file mode 100755 index 0000000..1fd15d5 --- /dev/null +++ b/apps/xmasring/start.asm @@ -0,0 +1,53 @@ +; ZeX/OS +; Copyright (C) 2007 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com) +; +; 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 3 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, see . + + +; This is the kernel's entry point. We could either call main here, +; or we can use this to setup the stack or other nice stuff, like +; perhaps setting up the GDT and segments. Please note that interrupts +; are disabled at this point: More on interrupts later! +%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 + + +; IMPORTS +IMP main + +[SECTION .text] +[BITS 32] + +EXP entry + push eax ; lenght + push ebx ; argument + + call main ; call our program + + pop ebx + pop eax + ret \ No newline at end of file diff --git a/glibc/AUTHORS b/glibc/AUTHORS index c5941c8..e8da681 100755 --- a/glibc/AUTHORS +++ b/glibc/AUTHORS @@ -1,4 +1,4 @@ -* Developer: Tomas 'ZeXx86' Jedrzejek +* Developer: Tomas 'ZeXx86' Jedrzejek * Contact: zexx86@gmail.com Thanks for all helpful friends \ No newline at end of file diff --git a/glibc/Makefile b/glibc/Makefile index ebfb1ca..1190a9a 100755 --- a/glibc/Makefile +++ b/glibc/Makefile @@ -7,7 +7,7 @@ INCDIR =./include NASM =nasm -f elf -i$(INCDIR)/ CC =gcc -m32 -g -Wall -W -O2 -nostdinc -fno-builtin -I$(INCDIR) -STDIO =stdio/doprintf.o stdio/delay.o stdio/printf.o stdio/sprintf.o stdio/puts.o stdio/putch.o stdio/cls.o stdio/getch.o stdio/getkey.o stdio/gotoxy.o stdio/setcolor.o +STDIO =stdio/doprintf.o stdio/delay.o stdio/printf.o stdio/sprintf.o stdio/puts.o stdio/putch.o stdio/cls.o stdio/getch.o stdio/getkey.o stdio/gotoxy.o stdio/setcolor.o stdio/beep.o STRING =string/memsetw.o string/memcpy.o string/strlen.o string/strcpy.o string/strncpy.o string/strcat.o string/memset.o string/strcmp.o string/strdup.o @@ -46,6 +46,7 @@ stdio/getch.o: stdio/getch.c $(MAKEDEP) stdio/getkey.o: stdio/getkey.c $(MAKEDEP) stdio/gotoxy.o: stdio/gotoxy.c $(MAKEDEP) stdio/setcolor.o: stdio/setcolor.c $(MAKEDEP) +stdio/beep.o: stdio/beep.c $(MAKEDEP) stdlib/memory.o: stdlib/memory.c $(MAKEDEP) stdlib/exit.o: stdlib/exit.c $(MAKEDEP) stdlib/schedule.o: stdlib/schedule.c $(MAKEDEP) diff --git a/glibc/VERSION b/glibc/VERSION index 4d15fff..0666df9 100755 --- a/glibc/VERSION +++ b/glibc/VERSION @@ -1 +1 @@ -glibc 0.0.8 +glibc 0.0.9 diff --git a/glibc/include/stdio.h b/glibc/include/stdio.h index b6a6439..e3c6a94 100755 --- a/glibc/include/stdio.h +++ b/glibc/include/stdio.h @@ -29,5 +29,6 @@ extern unsigned char getkey (); extern void gotoxy (int x, int y); extern void setcolor (int t, int f); extern int sprintf (char *buffer, const char *fmt, ...); +extern void beep (unsigned freq); #endif diff --git a/glibc/include/unistd.h b/glibc/include/unistd.h index 7eb6960..976c827 100755 --- a/glibc/include/unistd.h +++ b/glibc/include/unistd.h @@ -21,5 +21,6 @@ #define _UNISTD_H extern unsigned int sleep (unsigned int s); +extern unsigned int usleep (unsigned int s); #endif diff --git a/glibc/unistd/sleep.c b/glibc/stdio/beep.c old mode 100755 new mode 100644 similarity index 83% copy from glibc/unistd/sleep.c copy to glibc/stdio/beep.c index be02f62..831e669 --- a/glibc/unistd/sleep.c +++ b/glibc/stdio/beep.c @@ -17,20 +17,19 @@ */ -unsigned int sleep (unsigned int s) +void beep (unsigned freq) { asm volatile ( - "pushl %%eax;" + /*"pushl %%eax;" "pushl %%ebx;" "pushl %%ecx;" - "pushl %%edx;" - "movl $3, %%eax;" + "pushl %%edx;"*/ + "movl $19, %%eax;" "movl %0, %%ebx;" - "int $0x80;" - "popl %%edx;" + "int $0x80;" :: "g" (freq)); + /*"popl %%edx;" "popl %%ecx;" "popl %%ebx;" - "popl %%eax;" :: "g" (s)); - - return 0; -} + "popl %%eax;"*/ +} + diff --git a/glibc/unistd/sleep.c b/glibc/unistd/sleep.c index be02f62..c808912 100755 --- a/glibc/unistd/sleep.c +++ b/glibc/unistd/sleep.c @@ -16,7 +16,6 @@ * along with this program. If not, see . */ - unsigned int sleep (unsigned int s) { asm volatile ( @@ -33,4 +32,22 @@ unsigned int sleep (unsigned int s) "popl %%eax;" :: "g" (s)); return 0; -} +} + +unsigned int usleep (unsigned int s) +{ + asm volatile ( + "pushl %%eax;" + "pushl %%ebx;" + "pushl %%ecx;" + "pushl %%edx;" + "movl $20, %%eax;" + "movl %0, %%ebx;" + "int $0x80;" + "popl %%edx;" + "popl %%ecx;" + "popl %%ebx;" + "popl %%eax;" :: "g" (s)); + + return 0; +} \ No newline at end of file diff --git a/kernel/core/system_call.c b/kernel/core/system_call.c index 038750f..9cb0d8d 100755 --- a/kernel/core/system_call.c +++ b/kernel/core/system_call.c @@ -56,7 +56,7 @@ void sys_getch (struct regs *r) void sys_sleep (struct regs *r) { - usleep (1000); + usleep (1000 * (unsigned) r->ebx); } void sys_putch (struct regs *r) @@ -230,6 +230,11 @@ void sys_pcspk (struct regs *r) dev->handler (DEV_ACT_PLAY, (unsigned) r->ebx); } +void sys_usleep (struct regs *r) +{ + usleep ((unsigned) r->ebx); +} + void syscall_handler (struct regs *r) { switch (r->eax) { @@ -271,5 +276,7 @@ void syscall_handler (struct regs *r) return sys_open (r); case 19: return sys_pcspk (r); + case 20: + return sys_usleep (r); } } diff --git a/make_iso.sh b/make_iso.sh index 301b46a..dca99b4 100755 --- a/make_iso.sh +++ b/make_iso.sh @@ -1,6 +1,19 @@ #!/bin/bash VERSION="0.5.3" + +if [ "$1" = "clean" ] ; then + echo "Cleaning source from object files .." + make clean -C kernel/lib && + make clean -C kernel && + make clean -C glibc && + rm iso/boot/kernel.bin ; + rm iso/libc.a ; + rm zexos-$VERSION-i386.iso ; + echo "OK" + exit 1 +fi + make -C kernel/lib && make -C kernel && make -C glibc && -- 2.11.4.GIT