Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Pixelsuft committed Jul 1, 2024
1 parent e6d6e95 commit d54f205
Show file tree
Hide file tree
Showing 18 changed files with 167 additions and 58 deletions.
14 changes: 13 additions & 1 deletion include/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#ifdef SDL2_BUILD
#if defined(_WIN32) && !defined(_MSC_VER)
#define SDL_MAIN_HANDLED
Expand All @@ -25,7 +26,6 @@
#if !defined(_WIN32)
#define PREFER_SDL2
#endif
#define NOSTDLIB
// #define PREFER_STD
// #define FILES_WIN32_USE_ANSI

Expand Down Expand Up @@ -95,6 +95,18 @@ void* h_memcpy(void* dst, const void* src, size_t n);
void* h_strcpy(void* dst, const void* src);
void* h_memmove(void* dst, const void* src, size_t n);
void* h_memset(void* dst, int ch, size_t n);
size_t h_strlen(const char* str);
int h_strcmp(const char* str1, const char* str2);

#ifdef NOSTDLIB
int puts(const char* str);
void perror(const char* str);
void exit(int code);

time_t time(time_t* timer);
time_t mktime(struct tm* tp);
struct tm* localtime(const time_t* time);
#endif

// Functions that mess around with timing
void add_now(itick_t a);
Expand Down
8 changes: 4 additions & 4 deletions src/cpu/libcpu-stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
// In Halfix, it releases the mouse from SDL before aborting, which makes debugging in GDB infinitely easier.
void util_abort(void)
{
abort();
// abort();
}

// Convert a pointer p to a physical address that the code cache can work with
uint32_t cpulib_ptr_to_phys(void* p)
{
UNUSED(p);
abort();
// abort();
}

// Set to 1 if the APIC is enabled.
Expand Down Expand Up @@ -47,7 +47,7 @@ void io_register_reset(void* cb)
void* get_phys_ram_ptr(uint32_t addr, int write)
{
UNUSED(addr | write);
abort();
// abort();
}

// Given a linear address, convert to a physical address (useful for process emulators and mmap).
Expand All @@ -72,7 +72,7 @@ void* get_lin_ram_ptr(uint32_t addr, int flags, int* fault)
*fault = 0;
UNUSED(addr | flags);
UNUSED(fault);
abort();
// abort();
}

// Handle a MMIO read. Possible sizes are 0 (byte), 1 (word), and 2 (dword).
Expand Down
2 changes: 1 addition & 1 deletion src/cpu/libcpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ void util_abort(void)
{
// Notify host and then abort
onabort();
abort();
// abort();
}

// pic.c
Expand Down
6 changes: 4 additions & 2 deletions src/cpu/ops/simd.c
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,8 @@ static uint32_t cmpps(float32 dest, float32 src, int cmp)
case 7:
return -float32_ordered_quiet(dest, src, &status);
}
abort();
return 0;
// abort();
}
static uint64_t cmppd(float64 dest, float64 src, int cmp)
{
Expand All @@ -773,7 +774,8 @@ static uint64_t cmppd(float64 dest, float64 src, int cmp)
case 7:
return -float64_ordered_quiet(dest, src, &status);
}
abort();
return 0;
// abort();
}
static void shufps(void* dest, void* src, int imm)
{
Expand Down
6 changes: 3 additions & 3 deletions src/display-tui.c
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ static void display_blit_statusbar(void)

static int make_menu_item(int index, int pos, char* name, topmenu_cb_t cbclick, struct menubar_listing* menulist)
{
int len = strlen(name);
int len = h_strlen(name);
menubar[index].name = name;
menubar[index].cbclick = cbclick;
menubar[index].cpos = pos;
Expand Down Expand Up @@ -654,7 +654,7 @@ static void realloc_bar_sizes(int width)
for (int i = 0; i < MAX_MENUBAR_ITEMS; i++) {
if (!menubar[i].name)
continue;
int rpos = menubar[i].cpos << 1, len = strlen(menubar[i].name);
int rpos = menubar[i].cpos << 1, len = h_strlen(menubar[i].name);
// Add spacer before
menubar_textbuffer[rpos++] = ' ';
menubar_textbuffer[rpos++] = 0x70;
Expand Down Expand Up @@ -797,7 +797,7 @@ static struct menubar_listing* init_menubar_listing(int sz)

static int add_menu_entry(struct menubar_listing* mbl, int idx, char* value, menu_click_cb cb)
{
int width = strlen(value);
int width = h_strlen(value);
if (width > mbl->max_width)
mbl->max_width = width;
mbl->entries[idx] = value;
Expand Down
2 changes: 1 addition & 1 deletion src/display-win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ void display_set_resolution(int width, int height)
ReleaseDC(hWnd, hdc);
if (!hBmp) {
// h_printf("Failed to create DIB section: %p [%dx%d]\n", dc_dest, width, height);
abort();
// abort();
}
pixels = pvBits;

Expand Down
18 changes: 12 additions & 6 deletions src/drive.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ static void drive_get_path(char* dest, char* pathbase, uint32_t x)
{
char temp[16];
h_sprintf(temp, "blk%08x.bin", x);
join_path(dest, (int)strlen(pathbase), pathbase, temp);
join_path(dest, (int)h_strlen(pathbase), pathbase, temp);
}

// ============================================================================
Expand Down Expand Up @@ -624,7 +624,7 @@ static void drive_internal_state(void* this_ptr, char* pn)
int existing_add = 1;
for (unsigned int i = 0; i < this->path_count; i++) {
h_printf("%s %s\n", pathname, this->paths[i]);
if (!strcmp(pathname, this->paths[i])) {
if (!h_strcmp(pathname, this->paths[i])) {
existing_add = 0;
break;
}
Expand All @@ -634,7 +634,7 @@ static void drive_internal_state(void* this_ptr, char* pn)

int pwdindex = 0, pwdinc = 1;
for (unsigned int i = 0; i < this->path_count; i++) {
if (!strcmp(pathname, this->paths[i]))
if (!h_strcmp(pathname, this->paths[i]))
pwdinc = 0; // Stop counting
pwdindex += pwdinc;
h_sprintf(temp, "path%d", i);
Expand Down Expand Up @@ -668,7 +668,7 @@ static
{
struct drive_internal_info* drv = h_malloc(sizeof(struct drive_internal_info));

int len = (int)strlen(filename);
int len = (int)h_strlen(filename);
void* pathbase = h_malloc(len + 1);
h_strcpy(pathbase, filename);

Expand Down Expand Up @@ -737,7 +737,7 @@ function join_path(a, b) {
int drive_init(struct drive_info* info, char* filename)
{
char buf[1024];
int filelen = (int)strlen(filename);
int filelen = (int)h_strlen(filename);
if (filelen > 1000)
return -1;
join_path(buf, filelen, filename, "info.dat");
Expand Down Expand Up @@ -959,15 +959,21 @@ int drive_autodetect_type(char* path)
{
struct stat statbuf;
// Check for URL
#ifndef NOSTDLIB
if (strstr(path, "http://") != NULL || strstr(path, "https://") != NULL)
return 2;
#endif
void* fh = h_fopen(path, "r");
if (!fh)
return -1;
if(stat(path, &statbuf)){
#ifdef NOSTDLIB
return -1;
#else
if(stat(path, &statbuf)) {
h_fclose(fh);
return -1;
}
#endif
h_fclose(fh);
if(S_ISDIR(statbuf.st_mode))
return 0; // Chunked file
Expand Down
3 changes: 2 additions & 1 deletion src/hardware/dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,8 @@ static void* dma_get_buf(int line)
default:
DMA_FATAL("Unknown line: %d\n", line);
}
abort();
return NULL;
// abort();
}
static void dma_done(int line)
{
Expand Down
3 changes: 2 additions & 1 deletion src/hardware/pit.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ static int pit_get_out(struct pit_channel* pit)
case 5:
return current_counter != 0;
}
abort();
return 0;
// abort();
}

static int pit_get_count(struct pit_channel* pit)
Expand Down
2 changes: 1 addition & 1 deletion src/hardware/vga.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#define VGA_FATAL(x, ...) \
do { \
VGA_LOG(x, ##__VA_ARGS__); \
abort(); \
} while (0)

#define VBE_LFB_BASE 0xE0000000
Expand Down Expand Up @@ -948,6 +947,7 @@ static
VGA_LOG("Unknown read: 0x%x\n", port);
return -1;
}
return 0;
}

static inline uint8_t bpp4_to_offset(uint8_t i, uint8_t j, uint8_t k)
Expand Down
2 changes: 1 addition & 1 deletion src/host/net-pcap.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ int net_init(char* netarg)

for (temp = devlist; temp; temp = temp->next) {
if (netarg) {
if (strcmp(temp->name, netarg) == 0) {
if (h_strcmp(temp->name, netarg) == 0) {
intf = temp->name;
break;
}
Expand Down
10 changes: 5 additions & 5 deletions src/ini.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static inline char* slice_string(char* y, int start, int end)
static struct ini_section* ini_parse(char* x)
{
int state = STATE_DEFAULT,
length = (int)strlen(x),
length = (int)h_strlen(x),
i = 0, strstart = 0, strend = 0, include_whitespace = 0;
struct ini_section *result = h_calloc(1, sizeof(struct ini_section)), *head = result;
h_memset(result, 0, sizeof(struct ini_section));
Expand Down Expand Up @@ -156,7 +156,7 @@ static struct ini_section* get_section(struct ini_section* sect, char* name)
{
while (sect) {
if (sect->name) {
if (!strcmp(sect->name, name))
if (!h_strcmp(sect->name, name))
return sect;
}
sect = sect->next;
Expand All @@ -167,7 +167,7 @@ static char* get_field_string(struct ini_section* sect, char* name)
{
struct ini_field* f = sect->fields;
while (f) {
if (!strcmp(f->name, name))
if (!h_strcmp(f->name, name))
return f->data;
f = f->next;
}
Expand All @@ -180,7 +180,7 @@ static int get_field_enum(struct ini_section* sect, char* name, const struct ini
return def;
int i = 0;
while (vals[i].name) {
if (!strcmp(vals[i].name, x))
if (!h_strcmp(vals[i].name, x))
return vals[i].value;
i++;
}
Expand Down Expand Up @@ -349,7 +349,7 @@ static char* dupstr(char* src)
{
if (!src)
return NULL;
int len = (int)strlen(src);
int len = (int)h_strlen(src);
char* res = h_malloc(len + 1);
h_strcpy(res, src);
return res;
Expand Down
11 changes: 6 additions & 5 deletions src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void io_register_reset(io_reset cb)
{
if (io_reset_ptr == MAX_RESETS) {
IO_LOG("Too many I/O reset callbacks registered\n");
abort();
// abort();
}
resets[io_reset_ptr++] = cb;
}
Expand Down Expand Up @@ -238,7 +238,7 @@ void io_register_mmio_read(uint32_t start, uint32_t length, io_read b, io_read w
{
if (tf && mmio_pos[0] == MAX_MMIO) {
IO_LOG("Too many read areas\n");
abort();
// abort();
}
mmio[mmio_pos[0]].begin = start;
mmio[mmio_pos[0]].end = start + length;
Expand All @@ -252,7 +252,7 @@ void io_register_mmio_write(uint32_t start, uint32_t length, io_write b, io_writ
{
if (tf && mmio_pos[1] == MAX_MMIO) {
IO_LOG("Too many write areas\n");
abort();
// abort();
}

mmio[mmio_pos[1]].begin = start;
Expand Down Expand Up @@ -284,7 +284,7 @@ void io_handle_mmio_write(uint32_t addr, uint32_t data, int size)
return;
}
}
abort();
// abort();
}
uint32_t io_handle_mmio_read(uint32_t addr, int size)
{
Expand All @@ -296,7 +296,8 @@ uint32_t io_handle_mmio_read(uint32_t addr, int size)
}
}
IO_LOG(" ??? should not be here ??? Unknown mmio read: %08x\n", addr);
abort();
return 0;
// abort();
}

// Checks if address is mmapped for reading
Expand Down
4 changes: 2 additions & 2 deletions src/kvm/kvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ int cpu_run(int cycles)
CPU_FATAL("Failed to enter: %llx\n", kvm_run->fail_entry.hardware_entry_failure_reason);
default:
h_printf("todo: exit reason %d\n", kvm_run->exit_reason);
abort();
// abort();
break;
}
goto top;
Expand All @@ -365,7 +365,7 @@ uint32_t cpu_read_phys(uint32_t addr)
void cpu_init_dma(uint32_t x)
{
UNUSED(x);
abort();
// abort();
}

void cpu_write_mem(uint32_t addr, void* data, uint32_t length)
Expand Down
15 changes: 9 additions & 6 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,8 @@ static void generic_help(const struct option* options)
}
}

int main(int argc, char** argv)
int main(int argc, char* argv[])
{
UNUSED(argc);
UNUSED(argv);

char* configfile = "default.conf";
int filesz, realtime = 0;
void* f;
Expand All @@ -90,7 +87,7 @@ int main(int argc, char** argv)

if (!o->name)
break;
if (!strcmp(long_ver ? o->name : o->alias, arg + (long_ver + 1))) {
if (!h_strcmp(long_ver ? o->name : o->alias, arg + (long_ver + 1))) {
char* data;
if (o->flags & HASARG) {
if (!(data = argv[++i])) {
Expand Down Expand Up @@ -178,4 +175,10 @@ int main(int argc, char** argv)
//display_sleep(5);
}
#endif
}
}

#if defined(NOSTDLIB) && 0
void _start(void) {
main(0, NULL);
}
#endif
Loading

0 comments on commit d54f205

Please sign in to comment.