Add: libc
This commit is contained in:
		
							
								
								
									
										10
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								Makefile
									
									
									
									
									
								
							| @@ -1,6 +1,6 @@ | ||||
| include Makefile.common | ||||
|  | ||||
| all: k.iso | ||||
| all: bin k.iso | ||||
|  | ||||
| k.iso: install | ||||
| 	./tools/create_iso.sh | ||||
| @@ -9,8 +9,16 @@ install: | ||||
| 	mkdir -p $(GRUBDIR) | ||||
| 	$(MAKE) -C $(SOURCEDIR) $@ | ||||
|  | ||||
| bin: | ||||
| 	$(MAKE) -C $(LIB) | ||||
| 	gcc -c test.c -Ilibk -Llibk -lk -m32 | ||||
| 	ld -m elf_i386 -Ttext=0x6000000 --entry=main test.o -L./libk/ -lk | ||||
| 	objcopy --input binary --output elf32-i386 --binary-architecture i386 --rename-section .data=.rodata,CONTENTS,ALLOC,LOAD,READONLY,DATA a.out myfile.o | ||||
| 	cp myfile.o $(SOURCEDIR)/myfile.o | ||||
|  | ||||
| clean: | ||||
| 	$(MAKE) -C $(SOURCEDIR) $@ | ||||
| 	$(MAKE) -C $(LIB) $@ | ||||
| 	$(RM) kernel.iso | ||||
| 	$(RM) -r iso | ||||
|  | ||||
|   | ||||
| @@ -4,3 +4,4 @@ ASFLAGS = -m32 | ||||
| GRUBDIR = iso | ||||
| SOURCEDIR = src | ||||
| TARGET = kernel | ||||
| LIB=libk | ||||
|   | ||||
							
								
								
									
										20
									
								
								libk/Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								libk/Makefile
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,20 @@ | ||||
| include ../Makefile.common | ||||
|  | ||||
|  | ||||
| OBJS	= \ | ||||
| 	  syscall.o \ | ||||
|  | ||||
| DEPS = $(OBJS:.o=.d) | ||||
|  | ||||
| CPPFLAGS += -MMD -Iinclude | ||||
| CFLAGS += $(K_EXTRA_CFLAGS) -g -nostdlib | ||||
| LDFLAGS += -Wl,-Tkernel.lds | ||||
| LDLIBS = | ||||
|  | ||||
| all: $(TARGET) | ||||
| 	ar -rcs $(LIB).a *.o | ||||
|  | ||||
| $(TARGET): $(OBJS) | ||||
|  | ||||
| clean: | ||||
| 	$(RM) $(OBJS) $(DEPS) $(TARGET) $(LIB).a | ||||
							
								
								
									
										27
									
								
								libk/syscall.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								libk/syscall.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,27 @@ | ||||
| #include "syscall.h" | ||||
|  | ||||
| int __syscall(int num, void *a0, void *a1, void *a2, void *a3, void *a4) | ||||
| { | ||||
|     int ret; | ||||
|     asm volatile("      \n \ | ||||
|         mov %1, %%eax;  \n \ | ||||
|         mov %2, %%ebx;  \n \ | ||||
|         mov %3, %%ecx;  \n \ | ||||
|         mov %4, %%edx;  \n \ | ||||
|         mov %5, %%edi;  \n \ | ||||
|         mov %6, %%esi;  \n \ | ||||
|         int $48;        \n \ | ||||
|         mov %%eax, %0" : "=m" (ret), | ||||
|                          "+m" (num), | ||||
|                          "+m" (a0), | ||||
|                          "+m" (a1), | ||||
|                          "+m" (a2), | ||||
|                          "+m" (a3), | ||||
|                          "+m" (a4)); | ||||
|     return ret; | ||||
| } | ||||
|  | ||||
| int write(int fd, char *buf, int count) | ||||
| { | ||||
|     return __syscall(1, (void *) fd, (void *) buf, (void *) count, (void *) 0, (void *) 0); | ||||
| } | ||||
							
								
								
									
										7
									
								
								libk/syscall.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								libk/syscall.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,7 @@ | ||||
| #ifndef SYSCALL_H | ||||
| #define SYSCALL_H | ||||
|  | ||||
| int __syscall(int num, void *a0, void *a1, void *a2, void *a3, void *a4); | ||||
| int write(int fd, char *buf, int count); | ||||
|  | ||||
| #endif  /*  !SYSCALL_H */ | ||||
| @@ -87,11 +87,19 @@ _asm_sycall_handler: | ||||
| 	mov $0x10,%bx | ||||
| 	mov %bx,%ds | ||||
| 	pop %ebx | ||||
| 	push %esi | ||||
| 	push %edi | ||||
| 	push %edx | ||||
| 	push %ecx | ||||
| 	push %ebx | ||||
| 	push %eax | ||||
|     call syscall_handler | ||||
| 	pop %ebx | ||||
| 	pop %ebx | ||||
| 	pop %ecx | ||||
| 	pop %edx | ||||
| 	pop %edi | ||||
| 	pop %esi | ||||
|     pop %gs | ||||
| 	pop %fs | ||||
| 	pop %es | ||||
|   | ||||
							
								
								
									
										11
									
								
								src/isr.c
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								src/isr.c
									
									
									
									
									
								
							| @@ -28,16 +28,17 @@ void isr_kbd_int(void) | ||||
|     DEBUG_INFO("Keyboard input: %d", x); | ||||
| } | ||||
|  | ||||
| void syscall_handler(int eax, int ebx) | ||||
| int syscall_handler(int eax, void *ebx, void *ecx, void *edx, void *edi, void *esi) | ||||
| { | ||||
|     DEBUG_INFO("Syscall %d has been called from the userland with parameter %d", eax, ebx); | ||||
|     DEBUG_INFO("Syscall %d has been called from the userland with parameters: %d, %d, %d, %d, %d", eax, ebx, ecx, edx, edi, esi); | ||||
|  | ||||
|     switch (eax) | ||||
|     { | ||||
|     case 1: | ||||
|         char t = *((char *) ebx); | ||||
|         DEBUG_INFO("Syscall write : %d", (int) t); | ||||
|         return write(1, (u32) ebx); | ||||
|         int fd = (int) ebx; | ||||
|         char *buf = (char *) ecx; | ||||
|         int size = (int) edx; | ||||
|         return write(fd, buf, size); | ||||
|         break; | ||||
|     case 2: | ||||
|         DEBUG_INFO("Syscall keyboard"); | ||||
|   | ||||
| @@ -24,7 +24,7 @@ void launch_process(u16 tss, int memory_start, int userland_stack, int userland_ | ||||
|         movw %%ax, %%gs         \n \ | ||||
|         mov %%esp, %%eax         \n \ | ||||
|         push $0x23                 \n \ | ||||
|         push $0x7FFFFFFF         \n \ | ||||
|         push $0x7FFFEFFF         \n \ | ||||
|         pushfl                  \n \ | ||||
|         push $0x1B                 \n \ | ||||
|         push $0x6000000         \n \ | ||||
|   | ||||
							
								
								
									
										
											BIN
										
									
								
								src/myfile.o
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								src/myfile.o
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							| @@ -6,9 +6,9 @@ | ||||
|  *  Syscall handler for write, currently only serial write is supported. | ||||
|  *  Use the fd 1, to make a serial write. | ||||
|  */ | ||||
| int write(int fd, void *buf) | ||||
| int write(int fd, void *buf, int size) | ||||
| { | ||||
|     if (fd != 1) | ||||
|     if (fd != 1 || size < 0) | ||||
|         return -1; | ||||
|  | ||||
|     if (write_serial(buf)) | ||||
|   | ||||
| @@ -1,7 +1,7 @@ | ||||
| #ifndef SYSCALL_H | ||||
| #define SYSCALL_H | ||||
|  | ||||
| int write(int fd, void *buf); | ||||
| int write(int fd, void *buf, int size); | ||||
| int keyboard(void); | ||||
|  | ||||
| #endif /*   !SYSCALL_H */ | ||||
| @@ -20,6 +20,8 @@ int create_process(int uid, char *data_start) | ||||
|  | ||||
|     // Allocate stack | ||||
|     allocate_new_page(uid, 0x7FFFF000); | ||||
|     allocate_new_page(uid, 0x7FFFE000); | ||||
|     allocate_new_page(uid, 0x7FFFD000); | ||||
|  | ||||
|     // TODO : create data seg by process | ||||
|     // load elf | ||||
|   | ||||
		Reference in New Issue
	
	Block a user