Skip to content

Commit

Permalink
Merge branch 'libs' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
evilbinary committed Dec 24, 2022
2 parents d4f9d43 + 7e8170d commit 6a54264
Show file tree
Hide file tree
Showing 33 changed files with 927 additions and 94 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1 @@
image/disk.img filter=lfs diff=lfs merge=lfs -text
image/disk.img filter=lfs diff=lfs merge=lfs -text
153 changes: 148 additions & 5 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,82 @@
"configurations": [

{
"name": "hello with GDB",
"name": "cmd with GDB",
"type": "cppdbg",
"request": "launch",
"miDebuggerServerAddress": "localhost:1234",
// "program": "${workspaceRoot}/app/hello/hello",
"program": "${workspaceRoot}/app/cmd/ls",
"cwd": "${workspaceRoot}",
"args": [],
"sourceFileMap": {
"<source-path>": "<target-path>"
},
"targetArchitecture": "x86",
"MIMode": "gdb",
"miDebuggerPath": "/opt/local/bin/ggdb",
"miDebuggerArgs": "",
"customLaunchSetupCommands": [
// {
// "text": "target remote localhost:1234",
// "description": "Connect to QEMU remote debugger"
// }
],
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"text": "set architecture i386:intel ",
"description": "set architecture i386"
},

],
"preLaunchTask": "Build and run"
},
{
"name": "launcher with GDB",
"type": "cppdbg",
"request": "launch",
"miDebuggerServerAddress": "localhost:1234",
// "program": "${workspaceRoot}/app/hello/hello",
"program": "${workspaceRoot}/app/launcher/launcher",
"cwd": "${workspaceRoot}",
"args": [],
"sourceFileMap": {
"<source-path>": "<target-path>"
},
"targetArchitecture": "x86",
"MIMode": "gdb",
"miDebuggerPath": "/opt/local/bin/ggdb",
"miDebuggerArgs": "",
"customLaunchSetupCommands": [
// {
// "text": "target remote localhost:1234",
// "description": "Connect to QEMU remote debugger"
// }
],
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"text": "set architecture i386:intel ",
"description": "set architecture i386"
},

],
"preLaunchTask": "Build and run"
},
{
"name": "hello with GDB",
"type": "cppdbg",
"request": "launch",
"miDebuggerServerAddress": "localhost:1234",
"program": "${workspaceRoot}/app/hello/hello",
"cwd": "${workspaceRoot}",
"args": [],
Expand Down Expand Up @@ -41,6 +112,42 @@
],
"preLaunchTask": "Build and run"
},
{
"name": "gnuboy with GDB",
"type": "cppdbg",
"request": "launch",
"miDebuggerServerAddress": "localhost:1234",
// "program": "${workspaceRoot}/app/hello/hello",
"program": "${workspaceRoot}/app/gnuboy/gnuboy",
"cwd": "${workspaceRoot}",
"args": [],
"sourceFileMap": {
"<source-path>": "<target-path>"
},
"targetArchitecture": "x86",
"MIMode": "gdb",
"miDebuggerPath": "/opt/local/bin/ggdb",
"miDebuggerArgs": "",
"customLaunchSetupCommands": [
// {
// "text": "target remote localhost:1234",
// "description": "Connect to QEMU remote debugger"
// }
],
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"text": "set architecture i386:intel ",
"description": "set architecture i386"
},

],
"preLaunchTask": "Build and run"
},
{
"name": "gui with GDB",
"type": "cppdbg",
Expand Down Expand Up @@ -187,7 +294,7 @@
"request": "launch",
"miDebuggerServerAddress": "localhost:1234",
// "program": "${workspaceRoot}/app/hello/hello",
"program": "${workspaceRoot}/app/test/test",
"program": "${workspaceRoot}/app/test/test-mem",
"cwd": "${workspaceRoot}",
"args": [],
"sourceFileMap": {
Expand Down Expand Up @@ -324,6 +431,42 @@
],
"preLaunchTask": "Build and run"
},
{
"name": "sdl2 with GDB",
"type": "cppdbg",
"request": "launch",
"miDebuggerServerAddress": "localhost:1234",
// "program": "${workspaceRoot}/app/hello/hello",
"program": "${workspaceRoot}/app/sdl2/sdl2",
"cwd": "${workspaceRoot}",
"args": [],
"sourceFileMap": {
"<source-path>": "<target-path>"
},
"targetArchitecture": "x86",
"MIMode": "gdb",
"miDebuggerPath": "/opt/local/bin/ggdb",
"miDebuggerArgs": "",
"customLaunchSetupCommands": [
// {
// "text": "target remote localhost:1234",
// "description": "Connect to QEMU remote debugger"
// }
],
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"text": "set architecture i386:intel ",
"description": "set architecture i386"
},

],
"preLaunchTask": "Build and run"
},
{
"name": "file with GDB",
"type": "cppdbg",
Expand Down Expand Up @@ -444,7 +587,7 @@
"request": "launch",
"miDebuggerServerAddress": "localhost:1234",
// "program": "${workspaceRoot}/app/hello/hello",
"program": "${workspaceRoot}/init/kernel.elf",
"program": "${workspaceRoot}/duck/init/kernel.elf",
"cwd": "${workspaceRoot}",
"args": [],
"sourceFileMap": {
Expand Down Expand Up @@ -477,7 +620,7 @@
"type": "cppdbg",
"request": "launch",
"miDebuggerServerAddress": "localhost:1234",
"program": "${workspaceRoot}/boot/x86/init",
"program": "${workspaceRoot}/boot/x86/init.elf",
"cwd": "${workspaceRoot}",
"args": [],
"sourceFileMap": {
Expand Down Expand Up @@ -972,7 +1115,7 @@
"type": "cppdbg",
"request": "launch",
"miDebuggerServerAddress": "localhost:1234",
"program": "${workspaceRoot}/init/kernel.elf",
"program": "${workspaceRoot}/duck/init/kernel.elf",
// "program": "${workspaceRoot}/app/launcher/launcher",

// "program": "${workspaceRoot}/app/hello/hello",
Expand Down
10 changes: 5 additions & 5 deletions Sconstruct
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ from xenv.env import *

Import('env')

duck=SConscript(dirs=['duck'], exports='env')
boot=SConscript(dirs=['boot'], exports='env')
image=SConscript(dirs=['image'], exports='env')
duck=SConscript(dirs=['duck'])
boot=SConscript(dirs=['boot'])
image=SConscript(dirs=['image'])

Depends(boot, duck)
Depends(image, boot)
Depends(image, duck)


if default_apps:
eggs=SConscript(dirs=['eggs'], exports='env')
app=SConscript(dirs=['app'], exports='env')
eggs=SConscript(dirs=['eggs'])
app=SConscript(dirs=['app'])
Depends(app, eggs)


2 changes: 1 addition & 1 deletion boot/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ if arch_type in 'arm':
elif arch_type in 'xtensa':
boot=SConscript(dirs=['xtensa'], exports='env')
else:
boot=SConscript(dirs=[arch], exports='env')
boot=SConscript(dirs=[arch_type], exports='env')
4 changes: 2 additions & 2 deletions boot/arm/config.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef BOOT_ARM_CONFIG_H
#define BOOT_ARM_CONFIG_H
#define KERNEL_BLOCK_SIZE 169
#define KERNEL_SIZE 172996
#define KERNEL_BLOCK_SIZE 208
#define KERNEL_SIZE 212932
#endif
45 changes: 36 additions & 9 deletions boot/arm/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,14 @@ char uart_getc() {
void init_uart() {}

void uart_send(unsigned int c) {
while (((io_read32(0x20000000 + 0x60014)) & 0x20) == 0);
io_write32(0x20000000 + 0x60000,c);
while (((io_read32(0x20000000 + 0x60014)) & 0x20) == 0)
;
io_write32(0x20000000 + 0x60000, c);
}

char uart_getc() {
if((io_read32(0x20000000 + 0x60014) & 0x01) == 0)
return 0;
return io_read32(0x20000000 + 0x60000);
if ((io_read32(0x20000000 + 0x60014) & 0x01) == 0) return 0;
return io_read32(0x20000000 + 0x60000);
}

#endif
Expand Down Expand Up @@ -249,6 +249,8 @@ void printf(const char* format, ...) {
}
}

extern void* _stack_svc;

void init_boot_info() {
boot_info = &boot_data;
boot_info->version = BOOT_VERSION;
Expand All @@ -257,6 +259,8 @@ void init_boot_info() {
boot_info->kernel_size = KERNEL_BLOCK_SIZE * READ_BLOCK_SIZE * 2;
boot_info->tss_number = MAX_CPU;
boot_info->second_boot_entry = SECOND_BOOT_ENTRY;
boot_info->segments_number = 0;
boot_info->kernel_stack = _stack_svc;
}

void init_disk() {
Expand Down Expand Up @@ -294,7 +298,7 @@ void init_memory() {
count++;
#elif defined(CUBIEBOARD2)
ptr->base = 0x40000000;
ptr->length = 0x10000000*4;//256m*4
ptr->length = 0x10000000 * 4; // 256m*4
ptr->type = 1;
boot_info->total_memory += ptr->length;
ptr++;
Expand All @@ -316,7 +320,7 @@ void init_memory() {
count++;

ptr->type = 1;
ptr->base = (u32)boot_info->kernel_base+ (u32)boot_info->kernel_size;
ptr->base = (u32)boot_info->kernel_base + (u32)boot_info->kernel_size;
ptr->length = 0xf000000;
boot_info->total_memory += ptr->length;
ptr++;
Expand Down Expand Up @@ -403,11 +407,17 @@ void load_elf(Elf32_Ehdr* elf_header) {
for (int i = 0; i < elf_header->e_phnum; i++) {
printf("type:%d\n\r", phdr[i].p_type);
switch (phdr[i].p_type) {
case PT_NULL:
case PT_NULL:{
char* vaddr = phdr[i].p_vaddr;
// printf(" %s %x %x %x %s %x %x \r\n", "NULL", phdr[i].p_offset,
// phdr[i].p_vaddr, phdr[i].p_paddr, "", phdr[i].p_filesz,
// phdr[i].p_memsz);
break;

// int num = boot_data.segments_number++;
// boot_data.segments[num].start = vaddr;
// boot_data.segments[num].size = phdr[i].p_memsz;
// boot_data.segments[num].type = 1;
} break;
case PT_LOAD: {
// printf(" %s %x %x %x %s %x %x \r\n", "LOAD", phdr[i].p_offset,
// phdr[i].p_vaddr, phdr[i].p_paddr, "", phdr[i].p_filesz,
Expand All @@ -419,6 +429,12 @@ void load_elf(Elf32_Ehdr* elf_header) {
phdr[i].p_filesz);
memmove32(vaddr, start, phdr[i].p_memsz);
printf("move end\n\r");

int num = boot_data.segments_number++;
boot_data.segments[num].start = vaddr;
boot_data.segments[num].size = phdr[i].p_memsz;
boot_data.segments[num].type = 1;

} break;
default:
break;
Expand All @@ -431,6 +447,12 @@ void load_elf(Elf32_Ehdr* elf_header) {
if (SHT_NOBITS == shdr[i].sh_type) {
char* vaddr = shdr[i].sh_addr;
memset(vaddr, 0, shdr[i].sh_size);

// int num = boot_data.segments_number++;
// boot_data.segments[num].start = vaddr;
// boot_data.segments[num].size = phdr[i].p_memsz;
// boot_data.segments[num].type = 1;

// map_alignment(page,vaddr,buf,shdr[i].sh_size);
} else if (entry != shdr[i].sh_addr && SHT_PROGBITS == shdr[i].sh_type &&
shdr[i].sh_flags & SHF_ALLOC && shdr[i].sh_flags) {
Expand All @@ -441,6 +463,11 @@ void load_elf(Elf32_Ehdr* elf_header) {
u32* phstart = (u32)elf + shdr[i].sh_offset;
memset(vaddr, 0, shdr->sh_size);
memmove32(phstart, vaddr, shdr[i].sh_size);

// int num = boot_data.segments_number++;
// boot_data.segments[num].start = vaddr;
// boot_data.segments[num].size = phdr[i].p_memsz;
// boot_data.segments[num].type = 1;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion boot/x86-duck/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Import('env')

gcc_env = Environment(CC='gcc-mp-8',tools=['default'],ENV=os.environ)

env.GenerateKernelSize('config.h', ['../../init/kernel'])
env.GenerateKernelSize('config.h',['../../duck/init/kernel'])

gcc_env.ParseConfig('sdl2-config --cflags --libs')

Expand Down
Loading

0 comments on commit 6a54264

Please sign in to comment.