chore: sync repo
This commit is contained in:
		
							parent
							
								
									e2ce2c52d2
								
							
						
					
					
						commit
						ffd7be38f8
					
				
					 18 changed files with 279 additions and 55 deletions
				
			
		
							
								
								
									
										3
									
								
								Makefile
									
										
									
									
									
								
							
							
						
						
									
										3
									
								
								Makefile
									
										
									
									
									
								
							|  | @ -15,7 +15,10 @@ export ASMDIR = /usr/asm | |||
| 
 | ||||
| export AS = fasm | ||||
| export CC ?= gcc | ||||
| export LD = $(TOOLSDIR)/ld | ||||
| export RM = rm -f | ||||
| export TOOL_CC ?= gcc | ||||
| export TOOL_LD ?= ld | ||||
| 
 | ||||
| export MK_BUGREPORT := \"https://git.cute.engineering/d0p1/StupidOS/issues\" | ||||
| export MK_COMMIT    := \"$(shell git rev-parse --short HEAD)\" | ||||
|  |  | |||
							
								
								
									
										5
									
								
								bin/ar/main.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								bin/ar/main.c
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,5 @@ | |||
| int | ||||
| main(void) | ||||
| { | ||||
| 	return 0; | ||||
| } | ||||
							
								
								
									
										35
									
								
								bin/ld/coff.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								bin/ld/coff.c
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,35 @@ | |||
| #include <stdlib.h> | ||||
| #include <stdio.h> | ||||
| 
 | ||||
| #include "coff.h" | ||||
| #include "ld.h" | ||||
| 
 | ||||
| int | ||||
| coff_output(LDState *state, FILE *fp) | ||||
| { | ||||
| 	FILHDR file_header; | ||||
| 	AOUTHDR opt_header; | ||||
| 
 | ||||
| 	file_header.f_magic = F_MACH_I386; | ||||
| 	file_header.f_timdat = 0; | ||||
| 	file_header.f_opthdr = AOUTHSZ; | ||||
| 	file_header.f_flags = F_RELFLG | F_EXEC | F_LNNO | F_LSYMS | F_LITTLE; | ||||
| 
 | ||||
| 	opt_header.magic = ZMAGIC; | ||||
| 	opt_header.vstamp = 0; | ||||
| 
 | ||||
| 	fwrite(&file_header, FILHSZ, 1, fp); | ||||
| 	fwrite(&opt_header, AOUTHSZ, 1, fp); | ||||
| 
 | ||||
| 	return (0); | ||||
| } | ||||
| 
 | ||||
| int coff_load(LDState *state, FILE *fp) | ||||
| { | ||||
| 	FILHDR file_header; | ||||
| 	AOUTHDR opt_header; | ||||
| 
 | ||||
| 	fread(&file_header, FILHSZ, 1, fp); | ||||
| 	 | ||||
| 	return (0); | ||||
| } | ||||
							
								
								
									
										13
									
								
								bin/ld/ld.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								bin/ld/ld.h
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,13 @@ | |||
| #ifndef LD_H | ||||
| # define LD_H | ||||
| 
 | ||||
| # include <stdio.h> | ||||
| 
 | ||||
| typedef struct { | ||||
| 
 | ||||
| } LDState; | ||||
| 
 | ||||
| int coff_output(LDState *state, FILE *fp); | ||||
| int coff_load(LDState *state, FILE *fp); | ||||
| 
 | ||||
| #endif /* !LD_H */ | ||||
|  | @ -87,7 +87,5 @@ main(int argc, char **argv) | |||
| 
 | ||||
| 	if (argc <= 1) usage(EXIT_FAILURE); | ||||
| 
 | ||||
| 	 | ||||
| 
 | ||||
| 	return (EXIT_SUCCESS); | ||||
| } | ||||
|  |  | |||
							
								
								
									
										5
									
								
								bin/ranlib/main.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								bin/ranlib/main.c
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,5 @@ | |||
| int | ||||
| main(void) | ||||
| { | ||||
| 	return 0; | ||||
| } | ||||
|  | @ -24,9 +24,38 @@ static const struct { | |||
| 	{F_MACH_UNKNOWN, "unknown"} | ||||
| }; | ||||
| 
 | ||||
| static const struct { | ||||
| 	int flag; | ||||
| 	char *str; | ||||
| } FLAGS[] = { | ||||
| 	{F_RELFLG,   "F_RELFLG"}, | ||||
| 	{F_EXEC,     "F_EXEC"}, | ||||
| 	{F_LNNO,     "F_LNNO"}, | ||||
| 	{F_LSYMS,    "F_LSYMS"}, | ||||
| 	{F_LITTLE,   "F_LITTLE"}, | ||||
| 	{F_BIG,      "F_BIG"}, | ||||
| 	{F_SYMMERGE, "F_SYMMERGE"}, | ||||
| 
 | ||||
| 	{0, NULL} | ||||
| }; | ||||
| 
 | ||||
| static const struct { | ||||
| 	int16_t mag; | ||||
| 	char *str; | ||||
| } AOUTMAG[] = { | ||||
| 	{OMAGIC,  "OMAGIC"}, | ||||
| 	{NMAGIC,  "NMAGIC"}, | ||||
| 	{ZMAGIC,  "ZMAGIC"}, | ||||
| 	{STMAGIC, "STMAGIC"}, | ||||
| 	{SHMAGIC, "SHMAGIC"}, | ||||
| 
 | ||||
| 	{0, NULL} | ||||
| }; | ||||
| 
 | ||||
| /* */ | ||||
| static const char *prg_name; | ||||
| static const char *mach = NULL; | ||||
| static const char *aoutmag = NULL; | ||||
| 
 | ||||
| /* */ | ||||
| static int display_header = 0; | ||||
|  | @ -138,7 +167,15 @@ main(int argc, char **argv) | |||
| 		printf("  Start of Symbol Table:     %d (bytes into file)\n", file_header.f_symptr); | ||||
| 		printf("  Number of Symbols:         %d\n", file_header.f_nsyms); | ||||
| 		printf("  Size of optional header:   %hu\n", file_header.f_opthdr); | ||||
| 		printf("  Flags:                     0x%hx\n\n", file_header.f_flags); | ||||
| 		printf("  Flags:                     "); | ||||
| 		for (idx = 0; FLAGS[idx].str != NULL; idx++) | ||||
| 		{ | ||||
| 			if (file_header.f_flags & FLAGS[idx].flag) | ||||
| 			{ | ||||
| 				printf("%s ", FLAGS[idx].str); | ||||
| 			} | ||||
| 		} | ||||
| 		printf("\n\n"); | ||||
| 	} | ||||
| 
 | ||||
| 	if (display_optional_header) | ||||
|  | @ -146,8 +183,16 @@ main(int argc, char **argv) | |||
| 		if (file_header.f_opthdr) | ||||
| 		{ | ||||
| 			fread(&aout_header, 1, AOUTHSZ, fp); | ||||
| 			for (idx = 0; AOUTMAG[idx].str != NULL; idx++) | ||||
| 			{ | ||||
| 				if (aout_header.magic == AOUTMAG[idx].mag) | ||||
| 				{ | ||||
| 					aoutmag = AOUTMAG[idx].str; | ||||
| 					break; | ||||
| 				}  | ||||
| 			} | ||||
| 			printf("A.out header\n"); | ||||
| 			printf("  Magic: %hx\n", aout_header.magic); | ||||
| 			printf("  Magic: %s\n", aoutmag); | ||||
| 			printf("  Entry: 0x%08X\n", aout_header.entry); | ||||
| 			printf("\n"); | ||||
| 		} | ||||
|  |  | |||
|  | @ -13,6 +13,30 @@ efi_memory_init: | |||
| 	mov ecx, [eax + EFI_BOOT_SERVICES.GetMemoryMap] | ||||
| 	mov [fnGetMemoryMap], ecx | ||||
| 
 | ||||
| 	call efi_get_memory_map | ||||
| 
 | ||||
| 	ret | ||||
| 
 | ||||
| efi_get_memory_map: | ||||
| 	push ebp | ||||
| 	mov ebp, esp | ||||
| 
 | ||||
| 	sub esp, 4 | ||||
| 
 | ||||
| 	lea eax, [ebp - 4] | ||||
| 	EFI_CALL [fnGetMemoryMap], uMemMapSize, 0, eax, uDescSize, uDescVer | ||||
| 
 | ||||
| 	add dword [uMemMapSize], 4096 | ||||
| 
 | ||||
| 	EFI_CALL [fnAllocatePool], EFI_LOADER_DATA, [uMemMapSize], pMemMap | ||||
| 
 | ||||
| 	LOG szRes2, eax | ||||
| 
 | ||||
| 	EFI_CALL [fnGetMemoryMap], uMemMapSize, [pMemMap], eax, uDescSize, uDescVer | ||||
| 
 | ||||
| 	LOG szRes, eax | ||||
| 
 | ||||
| 	leave | ||||
| 	ret | ||||
| 
 | ||||
| 	section '.data' data readable writeable | ||||
|  | @ -23,3 +47,11 @@ fnAllocatePool  dd ? | |||
| fnFreePool      dd ? | ||||
| 	;; Variable: fnGetMemoryMap | ||||
| fnGetMemoryMap  dd ? | ||||
| 
 | ||||
| uMemMapSize dd 0 | ||||
| uDescSize   dd 0 | ||||
| uDescVer    dd 0 | ||||
| pMemMap     dd 0 | ||||
| 
 | ||||
| szRes du "Result: %x", 0 | ||||
| szRes2 du "Result: %x", 0 | ||||
|  |  | |||
|  | @ -287,6 +287,24 @@ struc EFI_BOOT_SERVICES | |||
| } | ||||
| DEFN EFI_BOOT_SERVICES | ||||
| 
 | ||||
| EFI_RESERVED_MEMORY_TYPE        = 0 | ||||
| EFI_LOADER_CODE                 = 1 | ||||
| EFI_LOADER_DATA                 = 2 | ||||
| EFI_BOOT_SERVICES_CODE          = 3 | ||||
| EFI_BOOT_SERVICES_DATA          = 4 | ||||
| EFI_RUNTIME_SERVICES_CODE       = 5 | ||||
| EFI_RUNTIME_SERVICES_DATA       = 6 | ||||
| EFI_CONVENTIONAL_MEMORY         = 7 | ||||
| EFI_UNUSABLE_MEMORY             = 8 | ||||
| EFI_ACPI_RECLAIM_MEMORY         = 9 | ||||
| EFI_ACPI_MEMORY_NVS             = 10 | ||||
| EFI_MEMORY_MAPPED_IO            = 11 | ||||
| EFI_MEMORY_MAPPED_IO_PORT_SPACE = 12 | ||||
| EFI_PAL_CODE                    = 13 | ||||
| EFI_PERSISTENT_MEMORY           = 14 | ||||
| EFI_UNACCEPTED_MEMORY_TYPE      = 15 | ||||
| EFI_MAX_MEMORY_TYPE             = 16 | ||||
| 
 | ||||
| EFI_LOCATE_SEARCH_ALL_HANDLES        = 0x0 | ||||
| EFI_LOCATE_SEARCH_BY_REGISTER_NOTIFY = 0x1 | ||||
| EFI_LOCATE_SEARCH_BY_PROTOCOL        = 0x2 | ||||
|  | @ -298,6 +316,30 @@ EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER = 0x00000008 | |||
| EFI_OPEN_PROTOCOL_BY_DRIVER           = 0x00000010 | ||||
| EFI_OPEN_PROTOCOL_EXCLUSIVE           = 0x00000020 | ||||
| 
 | ||||
| struc EFI_MEMORY_DESCRIPTOR { | ||||
| 	.type UINT32 | ||||
| 	.physical_start UINT64 | ||||
| 	.virtual_start  UINT64 | ||||
| 	.number_of_pages UINT64 | ||||
| 	.attribute UINT64 | ||||
| } | ||||
| 
 | ||||
| EFI_MEMORY_DESCRIPTOR_VERSION = 1 | ||||
| 
 | ||||
| EFI_MEMORY_UC            = 0x0000000000000001 | ||||
| EFI_MEMORY_WC            = 0x0000000000000002 | ||||
| EFI_MEMORY_WT            = 0x0000000000000004 | ||||
| EFI_MEMORY_WB            = 0x0000000000000008 | ||||
| EFI_MEMORY_UCE           = 0x0000000000000010 | ||||
| EFI_MEMORY_WP            = 0x0000000000001000 | ||||
| EFI_MEMORY_RP            = 0x0000000000002000 | ||||
| EFI_MEMORY_XP            = 0x0000000000004000 | ||||
| EFI_MEMORY_NV            = 0x0000000000008000 | ||||
| EFI_MEMORY_MORE_RELIABLE = 0x0000000000010000 | ||||
| EFI_MEMORY_RO            = 0x0000000000020000 | ||||
| EFI_MEMORY_SP            = 0x0000000000040000 | ||||
| EFI_MEMORY_CPU_CRYPTO    = 0x0000000000080000 | ||||
| EFI_MEMORY_RUNTIME       = 0x8000000000000000  | ||||
| 	;; ======================================================================== | ||||
| 	;; EFI_RUNTIMES_SERVICES | ||||
| 	;; ======================================================================== | ||||
|  |  | |||
|  | @ -1,4 +1,4 @@ | |||
| SYSINCS = errno.h | ||||
| INCS = coff.h elf.h $(addprefix sys/, $(SYSINCS)) | ||||
| INCS = coff.h elf.h ar.h ranlib.h $(addprefix sys/, $(SYSINCS)) | ||||
| 
 | ||||
| include $(TOPDIR)/rules.mk | ||||
|  |  | |||
							
								
								
									
										26
									
								
								include/ar.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								include/ar.h
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,26 @@ | |||
| #ifndef AR_H | ||||
| # define AR_H | ||||
| 
 | ||||
| #include <stdint.h> | ||||
| 
 | ||||
| # define ARMAG "!<arch>\n" | ||||
| # define SARMAG 8 | ||||
| 
 | ||||
| # define ARFMAG "`\n" | ||||
| 
 | ||||
| # define AR_SYMTAB_NAME "__.SYMDEF" | ||||
| 
 | ||||
| typedef struct arhdr { | ||||
| 	uint8_t ar_name[16]; | ||||
| 	uint8_t ar_date[12]; | ||||
| 	uint8_t ar_uid[6]; | ||||
| 	uint8_t ar_gid[6]; | ||||
| 	uint8_t ar_mode[8]; | ||||
| 	uint8_t ar_size[10]; | ||||
| 	uint8_t ar_fmag[2]; | ||||
| } AR_HDR; | ||||
| 
 | ||||
| # define SAR_HDR 60 | ||||
| 
 | ||||
| 
 | ||||
| #endif /* !AR_H */ | ||||
|  | @ -64,6 +64,7 @@ typedef struct aouthdr | |||
| # define AOUTHSZ sizeof(AOUTHDR) | ||||
| 
 | ||||
| # define OMAGIC  0404 | ||||
| # define NMAGIC  0410 | ||||
| # define ZMAGIC  0413 | ||||
| # define STMAGIC 0401 | ||||
| # define SHMAGIC 0443 | ||||
|  |  | |||
							
								
								
									
										11
									
								
								include/ranlib.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								include/ranlib.h
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,11 @@ | |||
| #ifndef RANLIB_H | ||||
| # define RANLIB_H 1 | ||||
| 
 | ||||
| # define SYNTAB "__.SYMDEF" | ||||
| 
 | ||||
| struct ranlib { | ||||
| 	int ran_strx; | ||||
| 	int ran_off; | ||||
| }; | ||||
| 
 | ||||
| #endif /* !RANLIB_H */ | ||||
|  | @ -13,6 +13,8 @@ | |||
| 
 | ||||
| 	jmp short kmain | ||||
| 
 | ||||
| 	;; XXX: kernel header | ||||
| 
 | ||||
| 	;; Function: kmain | ||||
| 	;; Kernel entry point | ||||
| 	;; | ||||
|  | @ -132,7 +134,6 @@ kmain: | |||
| szMsgKernelAlive db "Kernel (", VERSION_FULL , ") is alive", 0 | ||||
| szMsgBuildDate db "Built ", BUILD_DATE, 0 | ||||
| szErrorBootProtocol db "Error: wrong magic number", 0 | ||||
| szKernelHeapStr db "KERNEL-HEAP", 0 | ||||
| 	;; Variable: stBootInfo | ||||
| 	;; <BootInfo> | ||||
| stBootInfo BootInfo | ||||
|  |  | |||
|  | @ -1,22 +1,29 @@ | |||
| TARGET	= coff-ld$(EXEXT) parted$(EXEXT) readcoff$(EXEXT) elf2coff$(EXEXT) | ||||
| TARGET	= ld$(EXEXT) parted$(EXEXT) readcoff$(EXEXT) elf2coff$(EXEXT) ar$(EXEXT) ranlib$(EXEXT) | ||||
| 
 | ||||
| .PHONY: all | ||||
| all: $(TARGET) | ||||
| 
 | ||||
| coff-ld$(EXEXT): ../bin/ld/main.c | ||||
| 	$(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS) | ||||
| ld$(EXEXT): ../bin/ld/main.c | ||||
| 	$(TOOL_CC) -o $@ $^ $(CFLAGS) $(LDFLAGS) | ||||
| 
 | ||||
| readcoff$(EXEXT): ../bin/readcoff/main.c | ||||
| 	$(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS) | ||||
| 	$(TOOL_CC) -o $@ $^ $(CFLAGS) $(LDFLAGS) | ||||
| 
 | ||||
| elf2coff$(EXEXT): ../bin/elf2coff/main.c | ||||
| 	$(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS) | ||||
| 	$(TOOL_CC) -o $@ $^ $(CFLAGS) $(LDFLAGS) | ||||
| 
 | ||||
| parted$(EXEXT): ../sbin/parted/main.c | ||||
| 	$(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS) | ||||
| 	$(TOOL_CC) -o $@ $^ $(CFLAGS) $(LDFLAGS) | ||||
| 
 | ||||
| ranlib$(EXEXT): ../bin/ranlib/main.c | ||||
| 	$(TOOL_CC) -o $@ $^ $(CFLAGS) $(LDFLAGS) | ||||
| 
 | ||||
| ar$(EXEXT): ../bin/ar/main.c | ||||
| 	$(TOOL_CC) -o $@ $^ $(CFLAGS) $(LDFLAGS) | ||||
| 
 | ||||
| .PHONY: install | ||||
| install: $(TARGET) | ||||
| 
 | ||||
| .PHONY: clean | ||||
| clean: | ||||
| 	$(RM) $(TARGET) | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue