1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 21:47:43 +00:00

Make bash-2.05b build with minimal changes.

This is really neat. :^)
This commit is contained in:
Andreas Kling 2018-11-17 00:11:08 +01:00
parent 2cf477a151
commit 9d05f6b7a7
35 changed files with 326 additions and 176 deletions

11
Base/etc/motd Normal file
View file

@ -0,0 +1,11 @@
 ____ _ __
/ __/__ _______ ___ (_) /___ __
 _\ \/ -_) __/ -_) _ \/ / __/ // /
/___/\__/_/ \__/_//_/_/\__/\_, /
/___/

Welcome to Serenity OS.
Copyright (C) Andreas Kling, 2018
All rights reserved.

View file

@ -3,13 +3,13 @@
namespace CMOS { namespace CMOS {
BYTE read(BYTE index) byte read(byte index)
{ {
IO::out8(0x70, index); IO::out8(0x70, index);
return IO::in8(0x71); return IO::in8(0x71);
} }
void write(BYTE index, BYTE data) void write(byte index, byte data)
{ {
IO::out8(0x70, index); IO::out8(0x70, index);
IO::out8(0x71, data); IO::out8(0x71, data);

View file

@ -4,7 +4,7 @@
namespace CMOS { namespace CMOS {
BYTE read(BYTE index); byte read(byte index);
void write(BYTE index, BYTE data); void write(byte index, byte data);
} }

View file

@ -50,7 +50,7 @@ void Keyboard::emit(byte ch)
void Keyboard::handleIRQ() void Keyboard::handleIRQ()
{ {
while (IO::in8(0x64) & 1) { while (IO::in8(0x64) & 1) {
BYTE ch = IO::in8(0x60); byte ch = IO::in8(0x60);
switch (ch) { switch (ch) {
case 0x38: m_modifiers |= Mod_Alt; break; case 0x38: m_modifiers |= Mod_Alt; break;
case 0xB8: m_modifiers &= ~Mod_Alt; break; case 0xB8: m_modifiers &= ~Mod_Alt; break;

View file

@ -19,9 +19,9 @@ static bool initialized;
namespace PIC { namespace PIC {
void disable(BYTE irq) void disable(byte irq)
{ {
BYTE imr; byte imr;
if (irq & 8) { if (irq & 8) {
imr = IO::in8(PIC1_CMD); imr = IO::in8(PIC1_CMD);
imr |= 1 << (irq - 8); imr |= 1 << (irq - 8);
@ -33,9 +33,9 @@ void disable(BYTE irq)
} }
} }
void enable(BYTE irq) void enable(byte irq)
{ {
BYTE imr; byte imr;
if (irq & 8) { if (irq & 8) {
imr = IO::in8(PIC1_CMD); imr = IO::in8(PIC1_CMD);
imr &= ~(1 << (irq - 8)); imr &= ~(1 << (irq - 8));
@ -47,7 +47,7 @@ void enable(BYTE irq)
} }
} }
void eoi(BYTE irq) void eoi(byte irq)
{ {
if (irq & 8) if (irq & 8)
IO::out8(PIC1_CTL, 0x20); IO::out8(PIC1_CTL, 0x20);

View file

@ -4,9 +4,9 @@
namespace PIC { namespace PIC {
void enable(BYTE number); void enable(byte number);
void disable(BYTE number); void disable(byte number);
void eoi(BYTE number); void eoi(byte number);
void initialize(); void initialize();
word getISR(); word getISR();
word get_irr(); word get_irr();
@ -15,9 +15,9 @@ word get_irr();
class IRQHandlerScope { class IRQHandlerScope {
public: public:
explicit IRQHandlerScope(BYTE irq) : m_irq(irq) { } explicit IRQHandlerScope(byte irq) : m_irq(irq) { }
~IRQHandlerScope() { PIC::eoi(m_irq); } ~IRQHandlerScope() { PIC::eoi(m_irq); }
private: private:
BYTE m_irq { 0 }; byte m_irq { 0 };
}; };

View file

@ -24,7 +24,7 @@
#define SIGNAL_DEBUG #define SIGNAL_DEBUG
#define MAX_PROCESS_GIDS 32 #define MAX_PROCESS_GIDS 32
static const DWORD defaultStackSize = 16384; static const dword defaultStackSize = 16384;
static pid_t next_pid; static pid_t next_pid;
InlineLinkedList<Process>* g_processes; InlineLinkedList<Process>* g_processes;
@ -663,7 +663,7 @@ Process::Process(String&& name, uid_t uid, gid_t gid, pid_t ppid, RingLevel ring
if (isRing3()) { if (isRing3()) {
// Ring3 processes need a separate stack for Ring0. // Ring3 processes need a separate stack for Ring0.
m_kernelStack = kmalloc(defaultStackSize); m_kernelStack = kmalloc(defaultStackSize);
m_stackTop0 = ((DWORD)m_kernelStack + defaultStackSize) & 0xffffff8; m_stackTop0 = ((dword)m_kernelStack + defaultStackSize) & 0xffffff8;
m_tss.ss0 = 0x10; m_tss.ss0 = 0x10;
m_tss.esp0 = m_stackTop0; m_tss.esp0 = m_stackTop0;
} }
@ -1414,7 +1414,7 @@ void Process::reap(Process& process)
pid_t Process::sys$waitpid(pid_t waitee, int* wstatus, int options) pid_t Process::sys$waitpid(pid_t waitee, int* wstatus, int options)
{ {
//kprintf("sys$waitpid(%d, %p, %d)\n", waitee, wstatus, options); dbgprintf("sys$waitpid(%d, %p, %d)\n", waitee, wstatus, options);
// FIXME: Respect options // FIXME: Respect options
(void) options; (void) options;
if (wstatus) if (wstatus)
@ -1426,6 +1426,31 @@ pid_t Process::sys$waitpid(pid_t waitee, int* wstatus, int options)
if (waitee != -1 && !Process::from_pid(waitee)) if (waitee != -1 && !Process::from_pid(waitee))
return -ECHILD; return -ECHILD;
} }
if (options & WNOHANG) {
if (waitee == -1) {
pid_t reaped_pid = 0;
InterruptDisabler disabler;
for_each_child([&reaped_pid] (Process& process) {
if (process.state() == Dead) {
reaped_pid = process.pid();
reap(process);
}
return true;
});
return reaped_pid;
} else {
auto* waitee_process = Process::from_pid(waitee);
if (!waitee_process)
return -ECHILD;
if (waitee_process->state() == Dead) {
reap(*waitee_process);
return waitee;
}
return 0;
}
}
m_waitee = waitee; m_waitee = waitee;
m_waitee_status = 0; m_waitee_status = 0;
block(BlockedWait); block(BlockedWait);
@ -1470,7 +1495,7 @@ void block(Process::State state)
sched_yield(); sched_yield();
} }
void sleep(DWORD ticks) void sleep(dword ticks)
{ {
ASSERT(current->state() == Process::Running); ASSERT(current->state() == Process::Running);
current->setWakeupTime(system.uptime + ticks); current->setWakeupTime(system.uptime + ticks);

View file

@ -80,8 +80,8 @@ public:
pid_t pid() const { return m_pid; } pid_t pid() const { return m_pid; }
pid_t sid() const { return m_sid; } pid_t sid() const { return m_sid; }
pid_t pgid() const { return m_pgid; } pid_t pgid() const { return m_pgid; }
DWORD ticks() const { return m_ticks; } dword ticks() const { return m_ticks; }
WORD selector() const { return m_farPtr.selector; } word selector() const { return m_farPtr.selector; }
TSS32& tss() { return m_tss; } TSS32& tss() { return m_tss; }
State state() const { return m_state; } State state() const { return m_state; }
uid_t uid() const { return m_uid; } uid_t uid() const { return m_uid; }
@ -98,8 +98,8 @@ public:
void block(Process::State); void block(Process::State);
void unblock(); void unblock();
void setWakeupTime(DWORD t) { m_wakeupTime = t; } void setWakeupTime(dword t) { m_wakeupTime = t; }
DWORD wakeupTime() const { return m_wakeupTime; } dword wakeupTime() const { return m_wakeupTime; }
template<typename Callback> static void for_each(Callback); template<typename Callback> static void for_each(Callback);
template<typename Callback> static void for_each_in_pgrp(pid_t, Callback); template<typename Callback> static void for_each_in_pgrp(pid_t, Callback);
@ -110,7 +110,7 @@ public:
bool tick() { ++m_ticks; return --m_ticksLeft; } bool tick() { ++m_ticks; return --m_ticksLeft; }
void set_ticks_left(dword t) { m_ticksLeft = t; } void set_ticks_left(dword t) { m_ticksLeft = t; }
void setSelector(WORD s) { m_farPtr.selector = s; } void setSelector(word s) { m_farPtr.selector = s; }
void set_state(State s) { m_state = s; } void set_state(State s) { m_state = s; }
pid_t sys$setsid(); pid_t sys$setsid();
@ -244,13 +244,13 @@ private:
gid_t m_egid { 0 }; gid_t m_egid { 0 };
pid_t m_sid { 0 }; pid_t m_sid { 0 };
pid_t m_pgid { 0 }; pid_t m_pgid { 0 };
DWORD m_ticks { 0 }; dword m_ticks { 0 };
DWORD m_ticksLeft { 0 }; dword m_ticksLeft { 0 };
DWORD m_stackTop0 { 0 }; dword m_stackTop0 { 0 };
DWORD m_stackTop3 { 0 }; dword m_stackTop3 { 0 };
FarPtr m_farPtr; FarPtr m_farPtr;
State m_state { Invalid }; State m_state { Invalid };
DWORD m_wakeupTime { 0 }; dword m_wakeupTime { 0 };
TSS32 m_tss; TSS32 m_tss;
TSS32 m_tss_to_resume_kernel; TSS32 m_tss_to_resume_kernel;
struct FileDescriptorAndFlags { struct FileDescriptorAndFlags {
@ -358,7 +358,7 @@ static inline const char* toString(Process::State state)
} }
extern void block(Process::State); extern void block(Process::State);
extern void sleep(DWORD ticks); extern void sleep(dword ticks);
extern InlineLinkedList<Process>* g_processes; extern InlineLinkedList<Process>* g_processes;

View file

@ -5,10 +5,10 @@
extern "C" { extern "C" {
void memcpy(void *dest, const void *src, DWORD n) void memcpy(void *dest, const void *src, dword n)
{ {
BYTE* bdest = (BYTE*)dest; byte* bdest = (byte*)dest;
const BYTE* bsrc = (const BYTE*)src; const byte* bsrc = (const byte*)src;
for (; n; --n) for (; n; --n)
*(bdest++) = *(bsrc++); *(bdest++) = *(bsrc++);
} }
@ -18,9 +18,9 @@ void strcpy(char* dest, const char *src)
while ((*dest++ = *src++) != '\0'); while ((*dest++ = *src++) != '\0');
} }
void* memset(void* dest, BYTE c, DWORD n) void* memset(void* dest, byte c, dword n)
{ {
BYTE *bdest = (BYTE *)dest; byte *bdest = (byte *)dest;
for (; n; --n) for (; n; --n)
*(bdest++) = c; *(bdest++) = c;
return dest; return dest;
@ -37,9 +37,9 @@ char* strrchr(const char* str, int ch)
return last; return last;
} }
DWORD strlen(const char* str) dword strlen(const char* str)
{ {
DWORD len = 0; dword len = 0;
while (*(str++)) while (*(str++))
++len; ++len;
return len; return len;
@ -51,12 +51,12 @@ int strcmp(const char *s1, const char *s2)
if (*s1 == 0) if (*s1 == 0)
return 0; return 0;
} }
return *(const BYTE*)s1 < *(const BYTE*)s2 ? -1 : 1; return *(const byte*)s1 < *(const byte*)s2 ? -1 : 1;
} }
char* strdup(const char *str) char* strdup(const char *str)
{ {
DWORD len = strlen(str); dword len = strlen(str);
char *s = (char*)kmalloc(len); char *s = (char*)kmalloc(len);
memcpy(s, str, len); memcpy(s, str, len);
return s; return s;

View file

@ -4,11 +4,11 @@
extern "C" { extern "C" {
void memcpy(void*, const void*, DWORD); void memcpy(void*, const void*, dword);
void strcpy(char*, const char*); void strcpy(char*, const char*);
int strcmp(char const*, const char*); int strcmp(char const*, const char*);
DWORD strlen(const char*); dword strlen(const char*);
void *memset(void*, BYTE, DWORD); void *memset(void*, byte, dword);
char *strdup(const char*); char *strdup(const char*);
int memcmp(const void*, const void*, size_t); int memcmp(const void*, const void*, size_t);
char* strrchr(const char* str, int ch); char* strrchr(const char* str, int ch);

View file

@ -44,7 +44,7 @@ void initialize()
kprintf("syscall: int 0x80 handler installed\n"); kprintf("syscall: int 0x80 handler installed\n");
} }
static DWORD handle(RegisterDump& regs, DWORD function, DWORD arg1, DWORD arg2, DWORD arg3) static dword handle(RegisterDump& regs, dword function, dword arg1, dword arg2, dword arg3)
{ {
ASSERT_INTERRUPTS_ENABLED(); ASSERT_INTERRUPTS_ENABLED();
switch (function) { switch (function) {
@ -184,10 +184,10 @@ static DWORD handle(RegisterDump& regs, DWORD function, DWORD arg1, DWORD arg2,
void syscall_entry(RegisterDump& regs) void syscall_entry(RegisterDump& regs)
{ {
DWORD function = regs.eax; dword function = regs.eax;
DWORD arg1 = regs.edx; dword arg1 = regs.edx;
DWORD arg2 = regs.ecx; dword arg2 = regs.ecx;
DWORD arg3 = regs.ebx; dword arg3 = regs.ebx;
regs.eax = Syscall::handle(regs, function, arg1, arg2, arg3); regs.eax = Syscall::handle(regs, function, arg1, arg2, arg3);
} }

View file

@ -10,7 +10,7 @@
//#define PAGE_FAULT_DEBUG //#define PAGE_FAULT_DEBUG
struct DescriptorTablePointer { struct DescriptorTablePointer {
WORD size; word size;
void* address; void* address;
} PACKED; } PACKED;
@ -23,7 +23,7 @@ static IRQHandler** s_irqHandler;
static Vector<word, KmallocEternalAllocator>* s_gdt_freelist; static Vector<word, KmallocEternalAllocator>* s_gdt_freelist;
static WORD s_gdtLength; static word s_gdtLength;
word gdt_alloc_entry() word gdt_alloc_entry()
{ {
@ -262,7 +262,7 @@ void exception_14_handler(RegisterDumpWithExceptionCode& regs)
static void _exception ## i () \ static void _exception ## i () \
{ \ { \
kprintf(msg"\n"); \ kprintf(msg"\n"); \
DWORD cr0, cr2, cr3, cr4; \ dword cr0, cr2, cr3, cr4; \
asm ("movl %%cr0, %%eax":"=a"(cr0)); \ asm ("movl %%cr0, %%eax":"=a"(cr0)); \
asm ("movl %%cr2, %%eax":"=a"(cr2)); \ asm ("movl %%cr2, %%eax":"=a"(cr2)); \
asm ("movl %%cr3, %%eax":"=a"(cr3)); \ asm ("movl %%cr3, %%eax":"=a"(cr3)); \
@ -286,9 +286,9 @@ EH(12, "Stack exception")
EH(15, "Unknown error") EH(15, "Unknown error")
EH(16, "Coprocessor error") EH(16, "Coprocessor error")
static void writeRawGDTEntry(WORD selector, DWORD low, DWORD high) static void writeRawGDTEntry(word selector, dword low, dword high)
{ {
WORD i = (selector & 0xfffc) >> 3; word i = (selector & 0xfffc) >> 3;
s_gdt[i].low = low; s_gdt[i].low = low;
s_gdt[i].high = high; s_gdt[i].high = high;
@ -297,14 +297,14 @@ static void writeRawGDTEntry(WORD selector, DWORD low, DWORD high)
} }
} }
void writeGDTEntry(WORD selector, Descriptor& descriptor) void writeGDTEntry(word selector, Descriptor& descriptor)
{ {
writeRawGDTEntry(selector, descriptor.low, descriptor.high); writeRawGDTEntry(selector, descriptor.low, descriptor.high);
} }
Descriptor& getGDTEntry(WORD selector) Descriptor& getGDTEntry(word selector)
{ {
WORD i = (selector & 0xfffc) >> 3; word i = (selector & 0xfffc) >> 3;
return *(Descriptor*)(&s_gdt[i]); return *(Descriptor*)(&s_gdt[i]);
} }
@ -357,17 +357,17 @@ void unregisterIRQHandler(byte irq, IRQHandler& handler)
s_irqHandler[irq] = nullptr; s_irqHandler[irq] = nullptr;
} }
void registerInterruptHandler(BYTE index, void (*f)()) void registerInterruptHandler(byte index, void (*f)())
{ {
s_idt[index].low = 0x00080000 | LSW((f)); s_idt[index].low = 0x00080000 | LSW((f));
s_idt[index].high = ((DWORD)(f) & 0xffff0000) | 0x8e00; s_idt[index].high = ((dword)(f) & 0xffff0000) | 0x8e00;
flushIDT(); flushIDT();
} }
void registerUserCallableInterruptHandler(BYTE index, void (*f)()) void registerUserCallableInterruptHandler(byte index, void (*f)())
{ {
s_idt[index].low = 0x00080000 | LSW((f)); s_idt[index].low = 0x00080000 | LSW((f));
s_idt[index].high = ((DWORD)(f) & 0xffff0000) | 0xef00; s_idt[index].high = ((dword)(f) & 0xffff0000) | 0xef00;
flushIDT(); flushIDT();
} }
@ -395,7 +395,7 @@ void idt_init()
s_idtr.address = s_idt; s_idtr.address = s_idt;
s_idtr.size = 0x100 * 8; s_idtr.size = 0x100 * 8;
for (BYTE i = 0xff; i > 0x10; --i) for (byte i = 0xff; i > 0x10; --i)
registerInterruptHandler(i, unimp_trap); registerInterruptHandler(i, unimp_trap);
registerInterruptHandler(0x00, _exception0); registerInterruptHandler(0x00, _exception0);
@ -426,14 +426,14 @@ void idt_init()
flushIDT(); flushIDT();
} }
void load_task_register(WORD selector) void load_task_register(word selector)
{ {
asm("ltr %0"::"r"(selector)); asm("ltr %0"::"r"(selector));
} }
void handle_irq() void handle_irq()
{ {
WORD isr = PIC::getISR(); word isr = PIC::getISR();
if (!isr) { if (!isr) {
kprintf("Spurious IRQ\n"); kprintf("Spurious IRQ\n");
return; return;

View file

@ -8,23 +8,23 @@
union Descriptor { union Descriptor {
struct { struct {
WORD limit_lo; word limit_lo;
WORD base_lo; word base_lo;
BYTE base_hi; byte base_hi;
BYTE type : 4; byte type : 4;
BYTE descriptor_type : 1; byte descriptor_type : 1;
BYTE dpl : 2; byte dpl : 2;
BYTE segment_present : 1; byte segment_present : 1;
BYTE limit_hi : 4; byte limit_hi : 4;
BYTE : 1; byte : 1;
BYTE zero : 1; byte zero : 1;
BYTE operation_size : 1; byte operation_size : 1;
BYTE granularity : 1; byte granularity : 1;
BYTE base_hi2; byte base_hi2;
}; };
struct { struct {
DWORD low; dword low;
DWORD high; dword high;
}; };
enum Type { enum Type {
@ -45,15 +45,15 @@ union Descriptor {
void setBase(void* b) void setBase(void* b)
{ {
base_lo = (DWORD)(b) & 0xffff; base_lo = (dword)(b) & 0xffff;
base_hi = ((DWORD)(b) >> 16) & 0xff; base_hi = ((dword)(b) >> 16) & 0xff;
base_hi2 = ((DWORD)(b) >> 24) & 0xff; base_hi2 = ((dword)(b) >> 24) & 0xff;
} }
void setLimit(DWORD l) void setLimit(dword l)
{ {
limit_lo = (DWORD)l & 0xffff; limit_lo = (dword)l & 0xffff;
limit_hi = ((DWORD)l >> 16) & 0xff; limit_hi = ((dword)l >> 16) & 0xff;
} }
} PACKED; } PACKED;
@ -61,21 +61,21 @@ class IRQHandler;
void gdt_init(); void gdt_init();
void idt_init(); void idt_init();
void registerInterruptHandler(BYTE number, void (*f)()); void registerInterruptHandler(byte number, void (*f)());
void registerUserCallableInterruptHandler(BYTE number, void (*f)()); void registerUserCallableInterruptHandler(byte number, void (*f)());
void registerIRQHandler(BYTE number, IRQHandler&); void registerIRQHandler(byte number, IRQHandler&);
void unregisterIRQHandler(BYTE number, IRQHandler&); void unregisterIRQHandler(byte number, IRQHandler&);
void flushIDT(); void flushIDT();
void flushGDT(); void flushGDT();
void load_task_register(WORD selector); void load_task_register(word selector);
word gdt_alloc_entry(); word gdt_alloc_entry();
void gdt_free_entry(word); void gdt_free_entry(word);
Descriptor& getGDTEntry(WORD selector); Descriptor& getGDTEntry(word selector);
void writeGDTEntry(WORD selector, Descriptor&); void writeGDTEntry(word selector, Descriptor&);
#define HANG asm volatile( "cli; hlt" ); #define HANG asm volatile( "cli; hlt" );
#define LSW(x) ((DWORD)(x) & 0xFFFF) #define LSW(x) ((dword)(x) & 0xFFFF)
#define MSW(x) (((DWORD)(x) >> 16) & 0xFFFF) #define MSW(x) (((dword)(x) >> 16) & 0xFFFF)
#define LSB(x) ((x) & 0xFF) #define LSB(x) ((x) & 0xFF)
#define MSB(x) (((x)>>8) & 0xFF) #define MSB(x) (((x)>>8) & 0xFF)
@ -156,49 +156,49 @@ private:
}; };
struct RegisterDump { struct RegisterDump {
WORD ss; word ss;
WORD gs; word gs;
WORD fs; word fs;
WORD es; word es;
WORD ds; word ds;
DWORD edi; dword edi;
DWORD esi; dword esi;
DWORD ebp; dword ebp;
DWORD esp; dword esp;
DWORD ebx; dword ebx;
DWORD edx; dword edx;
DWORD ecx; dword ecx;
DWORD eax; dword eax;
DWORD eip; dword eip;
WORD cs; word cs;
WORD __csPadding; word __csPadding;
DWORD eflags; dword eflags;
DWORD esp_if_crossRing; dword esp_if_crossRing;
WORD ss_if_crossRing; word ss_if_crossRing;
} PACKED; } PACKED;
struct RegisterDumpWithExceptionCode { struct RegisterDumpWithExceptionCode {
WORD ss; word ss;
WORD gs; word gs;
WORD fs; word fs;
WORD es; word es;
WORD ds; word ds;
DWORD edi; dword edi;
DWORD esi; dword esi;
DWORD ebp; dword ebp;
DWORD esp; dword esp;
DWORD ebx; dword ebx;
DWORD edx; dword edx;
DWORD ecx; dword ecx;
DWORD eax; dword eax;
WORD exception_code; word exception_code;
WORD __exception_code_padding; word __exception_code_padding;
DWORD eip; dword eip;
WORD cs; word cs;
WORD __csPadding; word __csPadding;
DWORD eflags; dword eflags;
DWORD esp_if_crossRing; dword esp_if_crossRing;
WORD ss_if_crossRing; word ss_if_crossRing;
} PACKED; } PACKED;
inline constexpr dword pageBaseOf(dword address) inline constexpr dword pageBaseOf(dword address)

View file

@ -53,7 +53,7 @@ asm(
#define MODE_RATE 0x04 #define MODE_RATE 0x04
#define MODE_SQUARE_WAVE 0x06 #define MODE_SQUARE_WAVE 0x06
#define WRITE_WORD 0x30 #define WRITE_word 0x30
/* Miscellaneous */ /* Miscellaneous */
#define BASE_FREQUENCY 1193182 #define BASE_FREQUENCY 1193182
@ -68,9 +68,9 @@ namespace PIT {
void initialize() void initialize()
{ {
WORD timer_reload; word timer_reload;
IO::out8(PIT_CTL, TIMER0_SELECT | WRITE_WORD | MODE_SQUARE_WAVE); IO::out8(PIT_CTL, TIMER0_SELECT | WRITE_word | MODE_SQUARE_WAVE);
timer_reload = (BASE_FREQUENCY / TICKS_PER_SECOND); timer_reload = (BASE_FREQUENCY / TICKS_PER_SECOND);

View file

@ -274,8 +274,8 @@ void init()
memset(&system, 0, sizeof(system)); memset(&system, 0, sizeof(system));
WORD base_memory = (CMOS::read(0x16) << 8) | CMOS::read(0x15); word base_memory = (CMOS::read(0x16) << 8) | CMOS::read(0x15);
WORD ext_memory = (CMOS::read(0x18) << 8) | CMOS::read(0x17); word ext_memory = (CMOS::read(0x18) << 8) | CMOS::read(0x17);
kprintf("%u kB base memory\n", base_memory); kprintf("%u kB base memory\n", base_memory);
kprintf("%u kB extended memory\n", ext_memory); kprintf("%u kB extended memory\n", ext_memory);

View file

@ -14,8 +14,8 @@
typedef struct typedef struct
{ {
DWORD start; dword start;
DWORD nchunk; dword nchunk;
} PACKED allocation_t; } PACKED allocation_t;
#define CHUNK_SIZE 128 #define CHUNK_SIZE 128
@ -29,8 +29,8 @@ typedef struct
static byte alloc_map[POOL_SIZE / CHUNK_SIZE / 8]; static byte alloc_map[POOL_SIZE / CHUNK_SIZE / 8];
volatile DWORD sum_alloc = 0; volatile dword sum_alloc = 0;
volatile DWORD sum_free = POOL_SIZE; volatile dword sum_free = POOL_SIZE;
volatile size_t kmalloc_sum_eternal = 0; volatile size_t kmalloc_sum_eternal = 0;
volatile size_t kmalloc_sum_page_aligned = 0; volatile size_t kmalloc_sum_page_aligned = 0;
@ -90,9 +90,9 @@ void* kmalloc(dword size)
{ {
InterruptDisabler disabler; InterruptDisabler disabler;
DWORD chunks_needed, chunks_here, first_chunk; dword chunks_needed, chunks_here, first_chunk;
DWORD real_size; dword real_size;
DWORD i, j, k; dword i, j, k;
/* We need space for the allocation_t structure at the head of the block. */ /* We need space for the allocation_t structure at the head of the block. */
real_size = size + sizeof(allocation_t); real_size = size + sizeof(allocation_t);
@ -133,7 +133,7 @@ void* kmalloc(dword size)
if( chunks_here == chunks_needed ) if( chunks_here == chunks_needed )
{ {
auto* a = (allocation_t *)(BASE_PHYS + (first_chunk * CHUNK_SIZE)); auto* a = (allocation_t *)(BASE_PHYS + (first_chunk * CHUNK_SIZE));
BYTE *ptr = (BYTE *)a; byte *ptr = (byte *)a;
ptr += sizeof(allocation_t); ptr += sizeof(allocation_t);
a->nchunk = chunks_needed; a->nchunk = chunks_needed;
a->start = first_chunk; a->start = first_chunk;
@ -172,16 +172,16 @@ void kfree(void *ptr)
InterruptDisabler disabler; InterruptDisabler disabler;
allocation_t *a = (allocation_t *)((((BYTE *)ptr) - sizeof(allocation_t))); allocation_t *a = (allocation_t *)((((byte *)ptr) - sizeof(allocation_t)));
#if 0 #if 0
DWORD hdr = (DWORD)a; dword hdr = (dword)a;
DWORD mhdr = hdr & ~0x7; dword mhdr = hdr & ~0x7;
kprintf("hdr / mhdr %p / %p\n", hdr, mhdr); kprintf("hdr / mhdr %p / %p\n", hdr, mhdr);
ASSERT(hdr == mhdr); ASSERT(hdr == mhdr);
#endif #endif
for (DWORD k = a->start; k < (a->start + a->nchunk); ++k) { for (dword k = a->start; k < (a->start + a->nchunk); ++k) {
alloc_map[k / 8] &= ~(1 << (k % 8)); alloc_map[k / 8] &= ~(1 << (k % 8));
} }

View file

@ -1,15 +1,15 @@
#pragma once #pragma once
void kmalloc_init(); void kmalloc_init();
void *kmalloc(DWORD size) __attribute__ ((malloc)); void *kmalloc(dword size) __attribute__ ((malloc));
void* kmalloc_eternal(size_t) __attribute__ ((malloc)); void* kmalloc_eternal(size_t) __attribute__ ((malloc));
void* kmalloc_page_aligned(size_t) __attribute__ ((malloc)); void* kmalloc_page_aligned(size_t) __attribute__ ((malloc));
void kfree(void*); void kfree(void*);
bool is_kmalloc_address(void*); bool is_kmalloc_address(void*);
extern volatile DWORD sum_alloc; extern volatile dword sum_alloc;
extern volatile DWORD sum_free; extern volatile dword sum_free;
extern volatile dword kmalloc_sum_eternal; extern volatile dword kmalloc_sum_eternal;
extern volatile dword kmalloc_sum_page_aligned; extern volatile dword kmalloc_sum_page_aligned;

View file

@ -6,5 +6,5 @@ cp ../../figlet-2.2.5/fonts/big.flf mnt/$FIGLET_FONTDIR
cp ../../figlet-2.2.5/fonts/slant.flf mnt/$FIGLET_FONTDIR cp ../../figlet-2.2.5/fonts/slant.flf mnt/$FIGLET_FONTDIR
cp ../../figlet-2.2.5/fonts/lean.flf mnt/$FIGLET_FONTDIR cp ../../figlet-2.2.5/fonts/lean.flf mnt/$FIGLET_FONTDIR
cp ../../bash-1.14.7/bash2 mnt/bin/bash cp ../../bash-2.05b/bash mnt/bin/bash

View file

@ -15,8 +15,8 @@ const KSym* ksymbolicate(dword address) PURE;
struct system_t struct system_t
{ {
time_t uptime; time_t uptime;
DWORD nprocess; dword nprocess;
DWORD nblocked; dword nblocked;
}; };
extern system_t system; extern system_t system;

View file

@ -6,22 +6,18 @@
#define PACKED __attribute__ ((packed)) #define PACKED __attribute__ ((packed))
#define PURE __attribute__ ((pure)) #define PURE __attribute__ ((pure))
typedef unsigned char BYTE; typedef dword __u32;
typedef unsigned short WORD; typedef word __u16;
typedef unsigned int DWORD; typedef byte __u8;
typedef DWORD __u32;
typedef WORD __u16;
typedef BYTE __u8;
typedef int __s32; typedef int __s32;
typedef short __s16; typedef short __s16;
typedef DWORD uid_t; typedef dword uid_t;
typedef DWORD gid_t; typedef dword gid_t;
typedef int pid_t; typedef int pid_t;
typedef DWORD time_t; typedef dword time_t;
typedef DWORD suseconds_t; typedef dword suseconds_t;
typedef DWORD size_t; typedef dword size_t;
struct timeval { struct timeval {
time_t tv_sec; time_t tv_sec;
@ -50,8 +46,8 @@ typedef dword time_t;
typedef dword suseconds_t; typedef dword suseconds_t;
struct FarPtr { struct FarPtr {
DWORD offset { 0 }; dword offset { 0 };
WORD selector { 0 }; word selector { 0 };
} PACKED; } PACKED;
class PhysicalAddress { class PhysicalAddress {

View file

@ -31,6 +31,7 @@ LIBC_OBJS = \
ulimit.o \ ulimit.o \
qsort.o \ qsort.o \
ioctl.o \ ioctl.o \
math.o \
entry.o entry.o
OBJS = $(AK_OBJS) $(LIBC_OBJS) OBJS = $(AK_OBJS) $(LIBC_OBJS)

View file

@ -11,3 +11,18 @@ int isprint(int c)
{ {
return isdigit(c) || isupper(c) || islower(c) || ispunct(c) || isspace(c); return isdigit(c) || isupper(c) || islower(c) || ispunct(c) || isspace(c);
} }
int isalnum(int c)
{
return isalpha(c) || isdigit(c);
}
int isalpha(int c)
{
return isupper(c) || islower(c);
}
int iscntrl(int c)
{
return (c >= 0 && c <= 0x1f) || c == 0x7f;
}

View file

@ -43,7 +43,10 @@ ALWAYS_INLINE int isdigit(int c)
return c >= '0' && c <= '9'; return c >= '0' && c <= '9';
} }
int isalpha(int c);
int isalnum(int c);
int ispunct(int c); int ispunct(int c);
int isprint(int c); int isprint(int c);
int iscntrl(int c);
__END_DECLS __END_DECLS

View file

@ -7,3 +7,8 @@
#define INT_MAX INT32_MAX #define INT_MAX INT32_MAX
#define INT_MIN INT32_MIN #define INT_MIN INT32_MIN
#define CHAR_BIT 8
#define SCHAR_MIN (-128)
#define SCHAR_MAX 127
#define UCHAR_MAX 255

14
LibC/math.cpp Normal file
View file

@ -0,0 +1,14 @@
#include <math.h>
#include <assert.h>
extern "C" {
double pow(double x, double y)
{
(void) x;
(void) y;
assert(false);
}
}

12
LibC/math.h Normal file
View file

@ -0,0 +1,12 @@
#pragma once
#include <sys/cdefs.h>
__BEGIN_DECLS
#define HUGE_VAL 1e10000
double pow(double x, double y);
__END_DECLS

View file

@ -235,12 +235,17 @@ static void stream_putch(char*&, char ch)
fputc(ch, __current_stream); fputc(ch, __current_stream);
} }
int fprintf(FILE* fp, const char* fmt, ...) int vfprintf(FILE* stream, const char* fmt, va_list ap)
{
__current_stream = stream;
return printfInternal(stream_putch, nullptr, fmt, ap);
}
int fprintf(FILE* stream, const char* fmt, ...)
{ {
__current_stream = fp;
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
int ret = printfInternal(stream_putch, nullptr, fmt, ap); int ret = vfprintf(stream, fmt, ap);
va_end(ap); va_end(ap);
return ret; return ret;
} }
@ -259,11 +264,18 @@ static void buffer_putch(char*& bufptr, char ch)
*bufptr++ = ch; *bufptr++ = ch;
} }
int vsprintf(char* buffer, const char* fmt, va_list ap)
{
int ret = printfInternal(buffer_putch, buffer, fmt, ap);
buffer[ret] = '\0';
return ret;
}
int sprintf(char* buffer, const char* fmt, ...) int sprintf(char* buffer, const char* fmt, ...)
{ {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
int ret = printfInternal(buffer_putch, buffer, fmt, ap); int ret = vsprintf(buffer, fmt, ap);
buffer[ret] = '\0'; buffer[ret] = '\0';
va_end(ap); va_end(ap);
return ret; return ret;

View file

@ -2,6 +2,7 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#include <sys/types.h> #include <sys/types.h>
#include <stdarg.h>
#include <limits.h> #include <limits.h>
__BEGIN_DECLS __BEGIN_DECLS
@ -49,6 +50,8 @@ int feof(FILE*);
int fflush(FILE*); int fflush(FILE*);
size_t fread(void* ptr, size_t size, size_t nmemb, FILE*); size_t fread(void* ptr, size_t size, size_t nmemb, FILE*);
size_t fwrite(const void* ptr, size_t size, size_t nmemb, FILE*); size_t fwrite(const void* ptr, size_t size, size_t nmemb, FILE*);
int vfprintf(FILE*, const char* fmt, va_list);
int vsprintf(char* buffer, const char* fmt, va_list);
int fprintf(FILE*, const char* fmt, ...); int fprintf(FILE*, const char* fmt, ...);
int printf(const char* fmt, ...); int printf(const char* fmt, ...);
int sprintf(char* buffer, const char* fmt, ...); int sprintf(char* buffer, const char* fmt, ...);

View file

@ -5,6 +5,14 @@
__BEGIN_DECLS __BEGIN_DECLS
typedef unsigned int u_int;
typedef unsigned long u_long;
typedef int ptrdiff_t;
typedef unsigned long int __uintmax_t;
typedef __uintmax_t uintmax_t;
typedef long int __intmax_t;
typedef __intmax_t intmax_t;
typedef uint32_t uid_t; typedef uint32_t uid_t;
typedef uint32_t gid_t; typedef uint32_t gid_t;
typedef int pid_t; typedef int pid_t;

View file

@ -56,6 +56,12 @@ void ensure_caps()
caps->set("up", "\033[A"); caps->set("up", "\033[A");
caps->set("vb", ""); caps->set("vb", "");
caps->set("am", ""); caps->set("am", "");
caps->set("@7", "");
caps->set("kH", "");
caps->set("kI", "\033[L");
caps->set("kh", "\033[H");
caps->set("vs", "");
caps->set("ve", "");
caps->set("co", "80"); caps->set("co", "80");
caps->set("li", "25"); caps->set("li", "25");
@ -75,7 +81,8 @@ char* tgetstr(char* id, char** area)
*area += strlen(val) + 1; *area += strlen(val) + 1;
return ret; return ret;
} }
assert(false); fprintf(stderr, "tgetstr: missing cap id='%s'\n", id);
return nullptr;
} }
int tgetflag(char* id) int tgetflag(char* id)

View file

@ -1,5 +1,6 @@
#include "time.h" #include <time.h>
#include "errno.h" #include <errno.h>
#include <assert.h>
#include <Kernel/Syscall.h> #include <Kernel/Syscall.h>
extern "C" { extern "C" {
@ -26,4 +27,16 @@ char* ctime(const time_t*)
return const_cast<char*>("ctime() not implemented"); return const_cast<char*>("ctime() not implemented");
} }
struct tm* localtime(const time_t*)
{
assert(false);
}
long timezone = 0;
void tzset()
{
assert(false);
}
} }

View file

@ -10,9 +10,25 @@ struct timezone {
int tz_dsttime; int tz_dsttime;
}; };
struct tm {
int tm_sec; /* Seconds (0-60) */
int tm_min; /* Minutes (0-59) */
int tm_hour; /* Hours (0-23) */
int tm_mday; /* Day of the month (1-31) */
int tm_mon; /* Month (0-11) */
int tm_year; /* Year - 1900 */
int tm_wday; /* Day of the week (0-6, Sunday = 0) */
int tm_yday; /* Day in the year (0-365, 1 Jan = 0) */
int tm_isdst; /* Daylight saving time */
};
extern long timezone;
int gettimeofday(struct timeval*, struct timezone* tz); int gettimeofday(struct timeval*, struct timezone* tz);
struct tm* localtime(const time_t*);
time_t time(time_t*); time_t time(time_t*);
char* ctime(const time_t*); char* ctime(const time_t*);
void tzset();
__END_DECLS __END_DECLS

View file

@ -268,4 +268,10 @@ int access(const char* pathname, int mode)
__RETURN_WITH_ERRNO(rc, rc, -1); __RETURN_WITH_ERRNO(rc, rc, -1);
} }
int mknod(const char* pathname, mode_t, dev_t)
{
(void) pathname;
assert(false);
}
} }

View file

@ -51,6 +51,7 @@ int pipe(int pipefd[2]);
unsigned int alarm(unsigned int seconds); unsigned int alarm(unsigned int seconds);
int access(const char* pathname, int mode); int access(const char* pathname, int mode);
int isatty(int fd); int isatty(int fd);
int mknod(const char* pathname, mode_t, dev_t);
#define WEXITSTATUS(status) (((status) & 0xff00) >> 8) #define WEXITSTATUS(status) (((status) & 0xff00) >> 8)
#define WTERMSIG(status) ((status) & 0x7f) #define WTERMSIG(status) ((status) & 0x7f)

View file

@ -4,6 +4,8 @@ extern "C" {
namespace Unix { namespace Unix {
#define WNOHANG 1
#define SIG_DFL ((void*)0) #define SIG_DFL ((void*)0)
#define SIG_ERR ((void*)-1) #define SIG_ERR ((void*)-1)
#define SIG_IGN ((void*)1) #define SIG_IGN ((void*)1)