From 8a8a744341df513d00d2e60adf5e88636856e65b Mon Sep 17 00:00:00 2001 From: John Hodge Date: Thu, 24 Mar 2011 21:49:39 +0800 Subject: [PATCH] More work on x86_64 port of usermode - Some slight changes to the build system too --- Kernel/Makefile.BuildNum.x86_64 | 2 +- Kernel/arch/x86/proc.c | 2 +- Usermode/Applications/Makefile.tpl | 2 +- Usermode/Applications/axwin2_src/Makefile | 13 ++++- Usermode/Libraries/Makefile.tpl | 2 +- .../Libraries/acess.ld_src/acess_x86_64.ld.h | 4 +- Usermode/Libraries/crt0.o_src/Makefile | 1 - .../Libraries/ld-acess.so_src/arch/x86.asm.h | 1 + .../ld-acess.so_src/arch/x86_64.asm.h | 2 +- Usermode/Libraries/libc.so_src/heap.c | 58 +++++++++---------- Usermode/include/stdint.h | 9 +++ 11 files changed, 56 insertions(+), 40 deletions(-) diff --git a/Kernel/Makefile.BuildNum.x86_64 b/Kernel/Makefile.BuildNum.x86_64 index 446c8f59..8ac93bcd 100644 --- a/Kernel/Makefile.BuildNum.x86_64 +++ b/Kernel/Makefile.BuildNum.x86_64 @@ -1 +1 @@ -BUILD_NUM = 234 +BUILD_NUM = 235 diff --git a/Kernel/arch/x86/proc.c b/Kernel/arch/x86/proc.c index 4ab40398..a204b49c 100644 --- a/Kernel/arch/x86/proc.c +++ b/Kernel/arch/x86/proc.c @@ -450,7 +450,7 @@ void Proc_Start(void) for(;;) HALT(); // Just yeilds } gaCPUs[i].IdleThread = Threads_GetThread(tid); - gaCPUs[i].IdleThread->ThreadName = "Idle Thread"; + gaCPUs[i].IdleThread->ThreadName = (char*)"Idle Thread"; Threads_SetPriority( gaCPUs[i].IdleThread, -1 ); // Never called randomly gaCPUs[i].IdleThread->Quantum = 1; // 1 slice quantum diff --git a/Usermode/Applications/Makefile.tpl b/Usermode/Applications/Makefile.tpl index f16ae112..9d479314 100644 --- a/Usermode/Applications/Makefile.tpl +++ b/Usermode/Applications/Makefile.tpl @@ -32,7 +32,7 @@ ifneq ($(_DBGMAKEFILE),) else @$(LD) -g $(LDFLAGS) -o $@ $(OBJ) -Map Map.txt endif - @objdump -d -S $(_BIN) > $(BIN).dsm + @$(DISASM) $(_BIN) > $(BIN).dsm $(OBJ): $(_OBJPREFIX)%.o: %.c @echo --- GCC -o $@ diff --git a/Usermode/Applications/axwin2_src/Makefile b/Usermode/Applications/axwin2_src/Makefile index e47c829d..74a9d25f 100644 --- a/Usermode/Applications/axwin2_src/Makefile +++ b/Usermode/Applications/axwin2_src/Makefile @@ -1,4 +1,11 @@ -%: - $(MAKE) -C WM/ $@ - $(MAKE) -C Shell_src/ $@ +NAME = AxWin2 +DIRS = WM Shell_src + +SUBMAKE = $(MAKE) --no-print-directory + +all install: + @$(foreach DIR,$(DIRS), echo --- $(NAME)/$(DIR); $(SUBMAKE) -C $(DIR) $@ ;) + +clean: + @$(foreach DIR,$(DIRS), $(SUBMAKE) -C $(DIR) $@ ;) diff --git a/Usermode/Libraries/Makefile.tpl b/Usermode/Libraries/Makefile.tpl index e7dd73c5..1bb96a21 100644 --- a/Usermode/Libraries/Makefile.tpl +++ b/Usermode/Libraries/Makefile.tpl @@ -26,7 +26,7 @@ $(_BIN): $(OBJ) @mkdir -p $(dir $(_BIN)) @echo [LD] -o $(BIN) $(OBJ) @$(LD) $(LDFLAGS) -o $(_BIN) $(OBJ) - @$(OBJDUMP) -d -S $(_BIN) > $(_BIN).dsm + @$(DISASM) $(_BIN) > $(_BIN).dsm $(_OBJPREFIX)%.o: %.c @echo [CC] -o $@ diff --git a/Usermode/Libraries/acess.ld_src/acess_x86_64.ld.h b/Usermode/Libraries/acess.ld_src/acess_x86_64.ld.h index 05302a39..469e4afd 100644 --- a/Usermode/Libraries/acess.ld_src/acess_x86_64.ld.h +++ b/Usermode/Libraries/acess.ld_src/acess_x86_64.ld.h @@ -1,5 +1,5 @@ -OUTPUT_FORMAT("elf64-x86_64") -OUTPUT_ARCH(x86_64) +OUTPUT_FORMAT("elf64-x86-64") +/* OUTPUT_ARCH(x86_64) */ ENTRY(start) SEARCH_DIR(__LIBDIR) INPUT(crt0.o) diff --git a/Usermode/Libraries/crt0.o_src/Makefile b/Usermode/Libraries/crt0.o_src/Makefile index 36ce011b..fc41f757 100644 --- a/Usermode/Libraries/crt0.o_src/Makefile +++ b/Usermode/Libraries/crt0.o_src/Makefile @@ -4,7 +4,6 @@ -include ../Makefile.cfg -ASFLAGS = -felf BIN = $(OUTPUTDIR)Libs/crt0.o .PHONY: all clean install diff --git a/Usermode/Libraries/ld-acess.so_src/arch/x86.asm.h b/Usermode/Libraries/ld-acess.so_src/arch/x86.asm.h index 282ff40e..9e452734 100644 --- a/Usermode/Libraries/ld-acess.so_src/arch/x86.asm.h +++ b/Usermode/Libraries/ld-acess.so_src/arch/x86.asm.h @@ -6,6 +6,7 @@ [bits 32] [section .data] +[global _errno:data 4] _errno: dw 0 [section .text] diff --git a/Usermode/Libraries/ld-acess.so_src/arch/x86_64.asm.h b/Usermode/Libraries/ld-acess.so_src/arch/x86_64.asm.h index a21bf180..081e3004 100644 --- a/Usermode/Libraries/ld-acess.so_src/arch/x86_64.asm.h +++ b/Usermode/Libraries/ld-acess.so_src/arch/x86_64.asm.h @@ -25,7 +25,7 @@ _memcpy: pop rbp ret -[global _errno] +[global _errno:data 4] _errno: dw 0 ; Placed in .text, to allow use of relative addressing #define SYSCALL0(_name,_num) SYSCALL0 _name, _num diff --git a/Usermode/Libraries/libc.so_src/heap.c b/Usermode/Libraries/libc.so_src/heap.c index 14066e9e..7ce6bca8 100644 --- a/Usermode/Libraries/libc.so_src/heap.c +++ b/Usermode/Libraries/libc.so_src/heap.c @@ -17,12 +17,12 @@ typedef unsigned int Uint; // === TYPES === typedef struct { - Uint magic; - Uint size; + uint32_t magic; + size_t size; } heap_head; typedef struct { heap_head *header; - Uint magic; + uint32_t magic; } heap_foot; // === LOCAL VARIABLES === @@ -33,11 +33,11 @@ static void *_heap_end = NULL; EXPORT void *malloc(size_t bytes); EXPORT void *calloc(size_t bytes, size_t count); EXPORT void free(void *mem); -EXPORT void *realloc(void *mem, Uint bytes); +EXPORT void *realloc(void *mem, size_t bytes); EXPORT void *sbrk(int increment); LOCAL void *extendHeap(int bytes); -static void *FindHeapBase(); -LOCAL uint brk(Uint newpos); +static void *FindHeapBase(); +LOCAL uint brk(uintptr_t newpos); //Code @@ -49,9 +49,9 @@ LOCAL uint brk(Uint newpos); */ EXPORT void *malloc(size_t bytes) { - Uint bestSize; - Uint closestMatch = 0; - Uint bestMatchAddr = 0; + size_t bestSize; + size_t closestMatch = 0; + void *bestMatchAddr = 0; heap_head *curBlock; // Initialise Heap @@ -67,7 +67,7 @@ EXPORT void *malloc(size_t bytes) bestSize = bytes + sizeof(heap_head) + sizeof(heap_foot) + BLOCK_SIZE - 1; bestSize = (bestSize/BLOCK_SIZE)*BLOCK_SIZE; //Round up to block size - while((Uint)curBlock < (Uint)_heap_end) + while( (uintptr_t)curBlock < (uintptr_t)_heap_end) { //_SysDebug(" malloc: curBlock = 0x%x, curBlock->magic = 0x%x\n", curBlock, curBlock->magic); if(curBlock->magic == MAGIC_FREE) @@ -76,7 +76,7 @@ EXPORT void *malloc(size_t bytes) break; if(bestSize < curBlock->size && (curBlock->size < closestMatch || closestMatch == 0)) { closestMatch = curBlock->size; - bestMatchAddr = (Uint)curBlock; + bestMatchAddr = curBlock; } } else if(curBlock->magic != MAGIC) @@ -85,18 +85,18 @@ EXPORT void *malloc(size_t bytes) _SysDebug("malloc: Corrupt Heap\n"); return NULL; } - curBlock = (heap_head*)((Uint)curBlock + curBlock->size); + curBlock = (heap_head*)((uintptr_t)curBlock + curBlock->size); } - if((Uint)curBlock < (Uint)_heap_start) { + if((uintptr_t)curBlock < (uintptr_t)_heap_start) { _SysDebug("malloc: Heap underrun for some reason\n"); return NULL; } //Found a perfect match - if((Uint)curBlock < (Uint)_heap_end) { + if((uintptr_t)curBlock < (uintptr_t)_heap_end) { curBlock->magic = MAGIC; - return (void*)((Uint)curBlock + sizeof(heap_head)); + return (void*)((uintptr_t)curBlock + sizeof(heap_head)); } //Out of Heap Space @@ -107,7 +107,7 @@ EXPORT void *malloc(size_t bytes) return NULL; } curBlock->magic = MAGIC; - return (void*)((Uint)curBlock + sizeof(heap_head)); + return (void*)((uintptr_t)curBlock + sizeof(heap_head)); } //Split Block? @@ -208,7 +208,7 @@ EXPORT void *realloc(void *oldPos, size_t bytes) } //Check for free space after block - head = (heap_head*)((Uint)oldPos-sizeof(heap_head)); + head = (heap_head*)((uintptr_t)oldPos-sizeof(heap_head)); //Hack to used free's amagamating algorithym and malloc's splitting free(oldPos); @@ -219,7 +219,7 @@ EXPORT void *realloc(void *oldPos, size_t bytes) return NULL; //Copy Old Data - if((Uint)ret != (Uint)oldPos) { + if(ret != oldPos) { memcpy(ret, oldPos, head->size-sizeof(heap_head)-sizeof(heap_foot)); } @@ -254,8 +254,8 @@ LOCAL void *extendHeap(int bytes) foot->magic = MAGIC; //Combine with previous block if nessasary - if(_heap_end != _heap_start && ((heap_foot*)((Uint)_heap_end-sizeof(heap_foot)))->magic == MAGIC) { - heap_head *tmpHead = ((heap_foot*)((Uint)_heap_end-sizeof(heap_foot)))->header; + if(_heap_end != _heap_start && ((heap_foot*)((uintptr_t)_heap_end-sizeof(heap_foot)))->magic == MAGIC) { + heap_head *tmpHead = ((heap_foot*)((uintptr_t)_heap_end-sizeof(heap_foot)))->header; if(tmpHead->magic == MAGIC_FREE) { tmpHead->size += bytes; foot->header = tmpHead; @@ -263,7 +263,7 @@ LOCAL void *extendHeap(int bytes) } } - _heap_end = (void*) ((Uint)foot+sizeof(heap_foot)); + _heap_end = (void*) ((uintptr_t)foot+sizeof(heap_foot)); return head; } @@ -275,13 +275,13 @@ LOCAL void *extendHeap(int bytes) */ EXPORT void *sbrk(int increment) { - static size_t oldEnd = 0; - static size_t curEnd = 0; + static uintptr_t oldEnd = 0; + static uintptr_t curEnd = 0; //_SysDebug("sbrk: (increment=%i)", increment); if (curEnd == 0) { - oldEnd = curEnd = (size_t)FindHeapBase(); + oldEnd = curEnd = (uintptr_t)FindHeapBase(); //_SysAllocate(curEnd); // Allocate the first page } @@ -333,8 +333,8 @@ EXPORT int IsHeap(void *ptr) heap_head *head; heap_foot *foot; #endif - if( (Uint)ptr < (Uint)_heap_start ) return 0; - if( (Uint)ptr > (Uint)_heap_end ) return 0; + if( (uintptr_t)ptr < (uintptr_t)_heap_start ) return 0; + if( (uintptr_t)ptr > (uintptr_t)_heap_end ) return 0; #if 0 head = (void*)((Uint)ptr - 4); @@ -385,9 +385,9 @@ static void *FindHeapBase() #endif } -LOCAL uint brk(Uint newpos) +LOCAL uint brk(uintptr_t newpos) { - static uint curpos; + static uintptr_t curpos; uint pages; uint ret = curpos; int delta; @@ -395,7 +395,7 @@ LOCAL uint brk(Uint newpos) _SysDebug("brk: (newpos=0x%x)", newpos); // Find initial position - if(curpos == 0) curpos = (uint)FindHeapBase(); + if(curpos == 0) curpos = (uintptr_t)FindHeapBase(); // Get Current Position if(newpos == 0) return curpos; diff --git a/Usermode/include/stdint.h b/Usermode/include/stdint.h index ea837ba8..c7ff8fc2 100644 --- a/Usermode/include/stdint.h +++ b/Usermode/include/stdint.h @@ -14,6 +14,15 @@ typedef signed short int16_t; typedef signed long int32_t; typedef signed long long int64_t; +#if __LP64__ +typedef uint64_t intptr_t; +typedef uint64_t uintptr_t; +#else typedef uint32_t intptr_t; +typedef uint32_t uintptr_t; +#endif +#if 0 +# error "Unknown pointer size" +#endif #endif -- 2.20.1